|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 |
|
15 #include <e32std.h> |
|
16 #include <w32std.h> |
|
17 #include <e32math.h> |
|
18 #include <e32keys.h> |
|
19 #include "eglrendering.h" |
|
20 |
|
21 #define KDefaultScreenNo 0 |
|
22 |
|
23 class CWsRedrawHandler; |
|
24 |
|
25 class CWsCanvas: public CBase |
|
26 { |
|
27 public: |
|
28 static CWsCanvas* NewL(TInt, const TPoint&); |
|
29 ~CWsCanvas(); |
|
30 |
|
31 void DrawNow(); |
|
32 void Redraw(); |
|
33 void Draw(const TRect&); |
|
34 |
|
35 RWsSession& Session() {return iWs;} |
|
36 RWindow& Window() {return iWin;} |
|
37 RWindowGroup& Group() {return iGrp;} |
|
38 CWindowGc* Gc() {return iGc;} |
|
39 CWsScreenDevice* Screen() {return iScr;} |
|
40 inline TSize ScreenSize() const; |
|
41 |
|
42 private: |
|
43 CWsCanvas(TInt, const TPoint&); |
|
44 void ConstructL(); |
|
45 |
|
46 private: |
|
47 TInt iScrId; |
|
48 TPoint iPos; |
|
49 TSize iSz; |
|
50 RWsSession iWs; |
|
51 RWindowGroup iGrp; |
|
52 RWindow iWin; |
|
53 CWsScreenDevice* iScr; |
|
54 CWindowGc* iGc; |
|
55 CWsRedrawHandler* iRedrawHandler; |
|
56 }; |
|
57 |
|
58 class CWsRedrawHandler: public CActive |
|
59 { |
|
60 public: |
|
61 CWsRedrawHandler(CWsCanvas&); |
|
62 ~CWsRedrawHandler(); |
|
63 |
|
64 void RunL(); |
|
65 void DoCancel(); |
|
66 |
|
67 private: |
|
68 CWsCanvas& iCanvas; |
|
69 }; |
|
70 |
|
71 class CWsApp: public CBase |
|
72 { |
|
73 public: |
|
74 static CWsApp* NewL(); |
|
75 ~CWsApp(); |
|
76 void Start(); |
|
77 void Stop(); |
|
78 |
|
79 private: |
|
80 CWsApp(); |
|
81 void ConstructL(); |
|
82 |
|
83 CWsCanvas* iAppView; |
|
84 CEGLRendering* iDemo; |
|
85 TBool iCallWindow; |
|
86 |
|
87 TPoint iQvgaPos; |
|
88 TPoint iQhdPos; |
|
89 TBool iQhd; |
|
90 TPoint iPos; |
|
91 TSize iSz; |
|
92 TInt iScrId; |
|
93 }; |
|
94 |
|
95 /** |
|
96 * Create a canvas to draw to. |
|
97 * |
|
98 * @param aScrId Screen number to use |
|
99 * @param aPos Position on screen to use |
|
100 */ |
|
101 CWsCanvas* CWsCanvas::NewL(TInt aScrId, const TPoint& aPos) |
|
102 { |
|
103 CWsCanvas* c = new(ELeave) CWsCanvas(aScrId, aPos); |
|
104 CleanupStack::PushL(c); |
|
105 c->ConstructL(); |
|
106 CleanupStack::Pop(c); |
|
107 |
|
108 return c; |
|
109 } |
|
110 |
|
111 CWsCanvas::CWsCanvas(TInt aScrId, const TPoint& aPos): |
|
112 iScrId(aScrId), iPos(aPos) |
|
113 { |
|
114 } |
|
115 |
|
116 CWsCanvas::~CWsCanvas() |
|
117 { |
|
118 delete iGc; |
|
119 delete iScr; |
|
120 iGrp.Close(); |
|
121 iWin.Close(); |
|
122 delete iRedrawHandler; |
|
123 iWs.Close(); |
|
124 } |
|
125 |
|
126 /** |
|
127 * Construct the application canvas. |
|
128 * |
|
129 * Here we setup the collaboration with the Window Server. We want to get a window |
|
130 * on the appropriate screen, and setup a redraw handler so we can re-paint our window |
|
131 * when the Window Server wants us to. |
|
132 */ |
|
133 void CWsCanvas::ConstructL() |
|
134 { |
|
135 TInt err = iWs.Connect(); |
|
136 User::LeaveIfError(err); |
|
137 |
|
138 iScr = new(ELeave) CWsScreenDevice(iWs); |
|
139 err = iScr->Construct(iScrId); |
|
140 User::LeaveIfError(err); |
|
141 |
|
142 err = iScr->CreateContext(iGc); |
|
143 User::LeaveIfError(err); |
|
144 |
|
145 iGrp = RWindowGroup(iWs); |
|
146 err = iGrp.Construct(0xbadf00d, ETrue, iScr); |
|
147 User::LeaveIfError(err); |
|
148 |
|
149 iWin = RWindow(iWs); |
|
150 err = iWin.Construct(iGrp, (TUint32)this); |
|
151 User::LeaveIfError(err); |
|
152 |
|
153 iSz = iScr->SizeInPixels(); |
|
154 iWin.SetExtent(iPos, iSz); |
|
155 iWin.SetBackgroundColor(); |
|
156 iWin.Activate(); |
|
157 |
|
158 iWs.Flush(); |
|
159 |
|
160 iRedrawHandler = new(ELeave) CWsRedrawHandler(*this); |
|
161 iWs.SetFocusScreen(iScrId); |
|
162 } |
|
163 |
|
164 void CWsCanvas::DrawNow() |
|
165 { |
|
166 iWin.Invalidate(); |
|
167 Redraw(); |
|
168 } |
|
169 |
|
170 void CWsCanvas::Redraw() |
|
171 { |
|
172 iWin.BeginRedraw(); |
|
173 iGc->Activate(iWin); |
|
174 Draw(TRect(TPoint(), iSz)); |
|
175 iGc->Deactivate(); |
|
176 iWin.EndRedraw(); |
|
177 |
|
178 iWs.Flush(); |
|
179 } |
|
180 |
|
181 void CWsCanvas::Draw(const TRect& /*aRect*/) |
|
182 { |
|
183 } |
|
184 |
|
185 inline TSize CWsCanvas::ScreenSize() const |
|
186 { |
|
187 return iSz; |
|
188 } |
|
189 |
|
190 CWsRedrawHandler::CWsRedrawHandler(CWsCanvas& aCanvas): |
|
191 CActive(CActive::EPriorityStandard), |
|
192 iCanvas(aCanvas) |
|
193 { |
|
194 CActiveScheduler::Add(this); |
|
195 |
|
196 iStatus = KRequestPending; |
|
197 iCanvas.Session().RedrawReady(&iStatus); |
|
198 SetActive(); |
|
199 } |
|
200 |
|
201 CWsRedrawHandler::~CWsRedrawHandler() |
|
202 { |
|
203 Cancel(); |
|
204 } |
|
205 |
|
206 void CWsRedrawHandler::RunL() |
|
207 { |
|
208 TWsRedrawEvent e; |
|
209 iCanvas.Session().GetRedraw(e); |
|
210 if (e.Handle() == (TInt) &iCanvas) |
|
211 { |
|
212 iCanvas.Redraw(); |
|
213 } |
|
214 |
|
215 iStatus = KRequestPending; |
|
216 iCanvas.Session().RedrawReady(&iStatus); |
|
217 SetActive(); |
|
218 } |
|
219 |
|
220 void CWsRedrawHandler::DoCancel() |
|
221 { |
|
222 iCanvas.Session().RedrawReadyCancel(); |
|
223 } |
|
224 |
|
225 |
|
226 CWsApp::CWsApp(): |
|
227 iQvgaPos(160,60), |
|
228 iQhdPos(0,0), |
|
229 iQhd(ETrue) |
|
230 { |
|
231 } |
|
232 |
|
233 CWsApp* CWsApp::NewL() |
|
234 { |
|
235 RDebug::Printf("CWsApp::NewL()"); |
|
236 CWsApp* app = new(ELeave) CWsApp; |
|
237 CleanupStack::PushL(app); |
|
238 app->ConstructL(); |
|
239 CleanupStack::Pop(app); |
|
240 |
|
241 return app; |
|
242 } |
|
243 |
|
244 /** |
|
245 * Constructor for CWsApp |
|
246 * |
|
247 * @note This constructor looks at the command line argument, if any, supplied when |
|
248 * launching the application. If specified, its used as the screen number to |
|
249 * target the output of the program. By default, screen 0 is used. |
|
250 */ |
|
251 void CWsApp::ConstructL() |
|
252 { |
|
253 RDebug::Printf("CWsApp::ConstructL()"); |
|
254 iPos = iQhd? iQhdPos : iQvgaPos; |
|
255 |
|
256 iScrId = KDefaultScreenNo; |
|
257 if (User::CommandLineLength() > 0) |
|
258 { |
|
259 TBuf<1> arg; |
|
260 User::CommandLine(arg); |
|
261 iScrId = (TInt)(arg[0]-'0'); |
|
262 } |
|
263 RDebug::Printf("CWsApp::ConstructL() 1"); |
|
264 iAppView = CWsCanvas::NewL(iScrId, iPos); |
|
265 RDebug::Printf("CWsApp::ConstructL() 2"); |
|
266 iDemo = CEGLRendering::NewL(iAppView->Window(), iQhd); |
|
267 RDebug::Printf("CWsApp::ConstructL() 3"); |
|
268 iDemo->Start(); |
|
269 RDebug::Printf("CWsApp::ConstructL() 4"); |
|
270 |
|
271 iSz = iAppView->ScreenSize(); |
|
272 RDebug::Printf("CWsApp::ConstructL() 5"); |
|
273 |
|
274 //Connstruct dialog Box |
|
275 // Get a 212x76 pixel box in the centre of the window. |
|
276 TRect rcDialog(TRect(iPos, iSz)); |
|
277 |
|
278 #ifdef PORTRAIT_MODE |
|
279 rcDialog.Shrink((rcDialog.Width() - 76) / 2, (rcDialog.Height() - 212) / 2); |
|
280 #else |
|
281 rcDialog.Shrink((rcDialog.Width() - 212) / 2, (rcDialog.Height() - 76) / 2); |
|
282 #endif |
|
283 |
|
284 iCallWindow = EFalse; |
|
285 } |
|
286 |
|
287 void CWsApp::Start() |
|
288 { |
|
289 RDebug::Printf("CWsApp::Start"); |
|
290 CActiveScheduler::Start(); |
|
291 } |
|
292 |
|
293 void CWsApp::Stop() |
|
294 { |
|
295 CActiveScheduler::Stop(); |
|
296 } |
|
297 |
|
298 CWsApp::~CWsApp() |
|
299 { |
|
300 delete iDemo; |
|
301 delete iAppView; |
|
302 } |
|
303 |
|
304 /** |
|
305 * Application second level entry point. |
|
306 * |
|
307 * Launches the application specific class CWsApp and calls Start() on it. |
|
308 * |
|
309 * @pre Active scheduler established. |
|
310 */ |
|
311 void MainL() |
|
312 { |
|
313 RDebug::Printf("ebt ::MainL"); |
|
314 CWsApp* app = CWsApp::NewL(); |
|
315 CleanupStack::PushL(app); |
|
316 |
|
317 app->Start(); |
|
318 |
|
319 CleanupStack::PopAndDestroy(1, app); |
|
320 } |
|
321 |
|
322 /** |
|
323 * Application entry point. |
|
324 * |
|
325 * This sets up the application environment active scheduler and runs MainL under a trap |
|
326 * harness. |
|
327 */ |
|
328 GLDEF_C TInt E32Main() |
|
329 { |
|
330 RDebug::Printf("ebt ::E32Main"); |
|
331 |
|
332 CTrapCleanup* tc = CTrapCleanup::New(); |
|
333 if (!tc) |
|
334 { |
|
335 return KErrNoMemory; |
|
336 } |
|
337 |
|
338 CActiveScheduler* as = new CActiveScheduler; |
|
339 if (!as) |
|
340 { |
|
341 delete tc; |
|
342 return KErrNoMemory; |
|
343 } |
|
344 |
|
345 CActiveScheduler::Install(as); |
|
346 TRAPD(err, MainL()); |
|
347 |
|
348 delete as; |
|
349 delete tc; |
|
350 return err; |
|
351 } |