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