|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class implements MMMADisplayWindow functionality |
|
15 * for Camera viewfinder usage. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // Include Files |
|
21 #include <eikenv.h> |
|
22 #include <gdi.h> |
|
23 #include <logger.h> |
|
24 #include <AknsUtils.h> |
|
25 #include <AknsDrawUtils.h> |
|
26 #include "cmmacanvasdisplay.h" |
|
27 #include "logger.h" |
|
28 |
|
29 class CMMACanvasDisplay; |
|
30 |
|
31 //#include <cameraapp.mbg> |
|
32 |
|
33 // Used for iDisplay member |
|
34 |
|
35 #include "cmmacamerawindow.h" |
|
36 |
|
37 // Camera viewfinder start delay |
|
38 const TInt KStarterTimeout = 100000; //100 msecs |
|
39 |
|
40 // Margin of icon displayed instead of viewfinder in case of error |
|
41 const TInt KErrorIconMargin = 5; //5 pixels |
|
42 |
|
43 |
|
44 //_LIT(KCameraAppBitmapFile, "z:\\resource\\apps\\cameraapp.mif"); |
|
45 |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CMMACameraWindow::NewL |
|
49 // Two-phased constructor. |
|
50 // Use this method to create a CMMACameraWindow instance. |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CMMACameraWindow* CMMACameraWindow::NewL(TInt aCameraHandle) |
|
54 { |
|
55 CMMACameraWindow* self = new(ELeave)CMMACameraWindow(aCameraHandle); |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CMMACameraWindow::~CMMACameraWindow |
|
62 // Destructor. |
|
63 // NOTE: iUICamera have to be deleted by ReleaseUiResources() called |
|
64 // from UI thread |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CMMACameraWindow::~CMMACameraWindow() |
|
68 { |
|
69 // It's not allowed to delete any nonsharable object here. |
|
70 // This must be done in Destroy(). |
|
71 // If the iDisplay is set, |
|
72 // instance should be deleted by sending |
|
73 // event from UI to be received by MUiEventConsumer. |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CMMACameraWindow::ViewFinderActive |
|
79 // Gets an information if the viewfinder is started. |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 TBool CMMACameraWindow::ViewFinderActive() |
|
83 { |
|
84 return iUICamera && iViewFinderVisible; |
|
85 } |
|
86 |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CMMACameraWindow::SetStarted |
|
90 // Notifies window about Started state change. |
|
91 // If started, tries to start viewfinder. |
|
92 // If not started, stops viewfinder. |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 void CMMACameraWindow::SetStarted(TBool aStarted) |
|
96 { |
|
97 iStarted = aStarted; |
|
98 if (iDisplay) |
|
99 { |
|
100 if (iStarted) |
|
101 { |
|
102 // iDisplay->UIGetCallback( |
|
103 // *this, CMMACameraWindow::EShowViewFinder); |
|
104 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetStarted : before GetCallbackInUiThread + EShowViewFinder"); |
|
105 iDisplay->GetCallbackInUiThread((TInt)CMMACameraWindow::EShowViewFinder); |
|
106 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetStarted : after GetCallbackInUiThread - EShowViewFinder"); |
|
107 } |
|
108 else |
|
109 { |
|
110 // iDisplay->UIGetCallback( |
|
111 // *this, CMMACameraWindow::EHideViewFinder); |
|
112 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetStarted : before GetCallbackInUiThread + EHideViewFinder"); |
|
113 iDisplay->GetCallbackInUiThread((TInt)CMMACameraWindow::EHideViewFinder); |
|
114 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetStarted : after GetCallbackInUiThread - EHideViewFinder"); |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CMMACameraWindow::SetDisplay |
|
122 // Sets iDisplay used to invoke callbacks from UI thread. |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CMMACameraWindow::SetDisplay(MMMADisplay *aDisplay) |
|
126 { |
|
127 if (iDisplay != aDisplay) |
|
128 { |
|
129 if (iDisplay) |
|
130 { |
|
131 // Clear the resources created within the old Display |
|
132 //iDisplay->UIGetCallback( |
|
133 // *this, CMMACameraWindow::EDeleteViewFinder); |
|
134 |
|
135 |
|
136 // instead make a call to java, shift to ui thread and call ReleaseUiResources() method in UI thread |
|
137 |
|
138 // here jobject and jclass is valid since the flow is first creat CMMACanvasDisplay and then |
|
139 // call setdeisplay of cameraplayer |
|
140 /*iJavaDisplayObject = iDisplay->GetJavaDisplayObject(); |
|
141 iJavaDisplayClass = iDisplay->GetJavaDisplayClass(); |
|
142 iJni = iDisplay->GetJNIEnv(); |
|
143 |
|
144 jmethodID releaseUiResourceID = iJni->GetMethodID( |
|
145 iJavaDisplayClass, |
|
146 "releaseUiResource", |
|
147 "()I"); |
|
148 |
|
149 iJni->CallIntMethod(iJavaDisplayObject,releaseUiResourceID);*/ |
|
150 //MMAPI UI 3.x req. |
|
151 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetDisplay : before GetCallbackInUiThread +"); |
|
152 iDisplay->GetCallbackInUiThread((TInt)CMMACameraWindow::EDeleteViewFinder); |
|
153 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetDisplay : after GetCallbackInUiThread -"); |
|
154 } |
|
155 |
|
156 // Set the new Display |
|
157 iDisplay = aDisplay; |
|
158 |
|
159 if (iDisplay) |
|
160 { |
|
161 // Get a DSA resources for the new Display |
|
162 // iDisplay->UIGetDSAResources(*this, MMMADisplay::EMmaThread); |
|
163 |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // From class MMMADisplayWindow |
|
171 // CMMACameraWindow::SetDestinationBitmapL |
|
172 // |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 void CMMACameraWindow::SetDestinationBitmapL(CFbsBitmap* /*aBitmap*/) |
|
176 { |
|
177 // Ignored, this window will not be used for actual drawing |
|
178 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetDestinationBitmapL"); |
|
179 } |
|
180 |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // From class MMMADisplayWindow |
|
184 // CMMACameraWindow::DrawFrameL |
|
185 // |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 void CMMACameraWindow::DrawFrameL(const CFbsBitmap* /*aBitmap*/) |
|
189 { |
|
190 // Ignored, this window will not be used for actual drawing |
|
191 } |
|
192 |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // From class MMMADisplayWindow |
|
196 // CMMACameraWindow::SetDrawRect |
|
197 // |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CMMACameraWindow::SetDrawRect(const TRect& aRect) |
|
201 { |
|
202 // MMAPI thread |
|
203 LOG2(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::SetDrawRect TL:%d,%d", |
|
204 aRect.iTl.iX, aRect.iTl.iY); |
|
205 LOG2(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::SetDrawRect BR:%d,%d", |
|
206 aRect.iBr.iX, aRect.iBr.iY); |
|
207 |
|
208 iDrawRect = aRect; |
|
209 |
|
210 if (iDisplay) |
|
211 { |
|
212 //iDisplay->UIGetCallback(*this, CMMACameraWindow::EResetViewFinder); |
|
213 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetDisplay : before GetCallbackInUiThread + EResetViewFinder"); |
|
214 iDisplay->GetCallbackInUiThread((TInt)CMMACameraWindow::EResetViewFinder); |
|
215 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetDisplay : after GetCallbackInUiThread - EResetViewFinder"); |
|
216 |
|
217 } |
|
218 } |
|
219 |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // From class MMMADisplayWindow |
|
223 // CMMACameraWindow::SetDrawRectThread |
|
224 // |
|
225 // --------------------------------------------------------------------------- |
|
226 // |
|
227 void CMMACameraWindow::SetDrawRectThread(const TRect& aRect) |
|
228 { |
|
229 LOG2(EJavaMMAPI, EInfo, "MMA::CMMACameraWindow::SetDrawRectThread TL:%d,%d", |
|
230 aRect.iTl.iX, aRect.iTl.iY); |
|
231 LOG2(EJavaMMAPI, EInfo, "MMA::CMMACameraWindow::SetDrawRectThread BR:%d,%d", |
|
232 aRect.iBr.iX, aRect.iBr.iY); |
|
233 |
|
234 // Note: Runs in UI thread only |
|
235 |
|
236 // Bitmap window's rect can be set in any thread. |
|
237 if (iDrawRect != aRect) |
|
238 { |
|
239 iDrawRect = aRect; |
|
240 |
|
241 // Stop and start ViewFinder to update position |
|
242 ResetViewFinder(); |
|
243 } |
|
244 |
|
245 } |
|
246 |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // From class MMMADisplayWindow |
|
250 // CMMACameraWindow::DrawRect |
|
251 // |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 const TRect& CMMACameraWindow::DrawRect() |
|
255 { |
|
256 return iDrawRect; |
|
257 } |
|
258 |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // From class MMMADisplayWindow |
|
262 // CMMACameraWindow::WindowSize |
|
263 // |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 TSize CMMACameraWindow::WindowSize() |
|
267 { |
|
268 return iDrawRect.Size(); |
|
269 } |
|
270 |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // From class MMMADisplayWindow |
|
274 // CMMACameraWindow::SetPosition |
|
275 // |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void CMMACameraWindow::SetPosition(const TPoint& aPosition) |
|
279 { |
|
280 // Note: Runs in UI thread only |
|
281 SetDrawRectThread(TRect(aPosition, iDrawRect.Size())); |
|
282 } |
|
283 |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // From class MMMADisplayWindow |
|
287 // CMMACameraWindow::SetVisible |
|
288 // |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 void CMMACameraWindow::SetVisible(TBool aVisible, TBool aUseEventServer) |
|
292 { |
|
293 iVisible = aVisible; |
|
294 |
|
295 if (aUseEventServer) |
|
296 { |
|
297 // We are in UI thread now. |
|
298 SetViewFinderVisibility(aVisible); |
|
299 } |
|
300 else |
|
301 { |
|
302 // MMAPI thread |
|
303 if (iDisplay) |
|
304 { |
|
305 if (aVisible) |
|
306 { |
|
307 // iDisplay->UIGetCallback( |
|
308 // *this, CMMACameraWindow::EShowViewFinder); |
|
309 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetVisible : before GetCallbackInUiThread - EShowViewFinder"); |
|
310 iDisplay->GetCallbackInUiThread((TInt)CMMACameraWindow::EShowViewFinder); |
|
311 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetVisible : after GetCallbackInUiThread - EShowViewFinder"); |
|
312 } |
|
313 else |
|
314 { |
|
315 // iDisplay->UIGetCallback( |
|
316 // *this, CMMACameraWindow::EHideViewFinder); |
|
317 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetVisible : before GetCallbackInUiThread - EHideViewFinder"); |
|
318 iDisplay->GetCallbackInUiThread((TInt)CMMACameraWindow::EHideViewFinder); |
|
319 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetVisible : after GetCallbackInUiThread - EHideViewFinder"); |
|
320 } |
|
321 } |
|
322 } |
|
323 } |
|
324 |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // From class MMMADisplayWindow |
|
328 // CMMACameraWindow::SetWindowRect |
|
329 // |
|
330 // --------------------------------------------------------------------------- |
|
331 // |
|
332 void CMMACameraWindow::SetWindowRect( |
|
333 const TRect& aRect, |
|
334 MMMADisplay::TThreadType aThreadType) |
|
335 { |
|
336 LOG2(EJavaMMAPI, EInfo, "MMA::CMMACameraWindow::SetWindowRect TL:%d,%d", |
|
337 aRect.iTl.iX, aRect.iTl.iY); |
|
338 LOG2(EJavaMMAPI, EInfo, "MMA::CMMACameraWindow::SetWindowRect BR:%d,%d", |
|
339 aRect.iBr.iX, aRect.iBr.iY); |
|
340 |
|
341 if (iClientRect != aRect) |
|
342 { |
|
343 iClientRect = aRect; |
|
344 |
|
345 if (aThreadType == MMMADisplay::EUiThread) |
|
346 { |
|
347 ResetViewFinder(); |
|
348 } |
|
349 else |
|
350 { |
|
351 // iDisplay->UIGetCallback( |
|
352 // *this, CMMACameraWindow::EResetViewFinder); |
|
353 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetWindowRect : before GetCallbackInUiThread + EResetViewFinder"); |
|
354 iDisplay->GetCallbackInUiThread((TInt)CMMACameraWindow::EHideViewFinder); |
|
355 LOG(EJavaMMAPI,EInfo,"CMMACameraWindow::SetWindowRect : after GetCallbackInUiThread - EResetViewFinder"); |
|
356 } |
|
357 } |
|
358 |
|
359 |
|
360 } |
|
361 |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // From class MMMADisplayWindow |
|
365 // CMMACameraWindow::WindowRect |
|
366 // |
|
367 // --------------------------------------------------------------------------- |
|
368 // |
|
369 const TRect& CMMACameraWindow::WindowRect() |
|
370 { |
|
371 return iClientRect; |
|
372 } |
|
373 |
|
374 |
|
375 // --------------------------------------------------------------------------- |
|
376 // From class MMMADisplayWindow |
|
377 // CMMACameraWindow::GetDisplayWindowType |
|
378 // |
|
379 // --------------------------------------------------------------------------- |
|
380 // |
|
381 MMMADisplayWindow::TDisplayWindowType |
|
382 CMMACameraWindow::GetDisplayWindowType() const |
|
383 { |
|
384 return EDisplayWindowTypeIsCamera; |
|
385 } |
|
386 |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // From class MMMADisplayWindow |
|
390 // CMMACameraWindow::IsVisible |
|
391 // |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 TBool CMMACameraWindow::IsVisible() const |
|
395 { |
|
396 return iVisible; |
|
397 } |
|
398 |
|
399 |
|
400 // --------------------------------------------------------------------------- |
|
401 // From class MMMADisplayWindow |
|
402 // CMMACameraWindow::ContainerSet |
|
403 // |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void CMMACameraWindow::ContainerSet() |
|
407 { |
|
408 // We are in UI thread now |
|
409 |
|
410 // Container was probably not set when |
|
411 // iDisplay was set, |
|
412 // we can now try get the DSA stuff again |
|
413 if (!iUICamera && iDisplay) |
|
414 { |
|
415 // Get a DSA stuff for the new Display |
|
416 // iDisplay->UIGetDSAResources(*this, MMMADisplay::EUiThread); |
|
417 } |
|
418 } |
|
419 |
|
420 |
|
421 // --------------------------------------------------------------------------- |
|
422 // From class MMMADisplayWindow |
|
423 // CMMACameraWindow::ContainerDestroyed |
|
424 // |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 void CMMACameraWindow::ContainerDestroyed() |
|
428 { |
|
429 // We are in UI thread now |
|
430 ReleaseUiResources(); |
|
431 } |
|
432 |
|
433 |
|
434 // --------------------------------------------------------------------------- |
|
435 // From class MCameraObserver |
|
436 // CMMACameraWindow::ReserveComplete |
|
437 // |
|
438 // --------------------------------------------------------------------------- |
|
439 // |
|
440 void CMMACameraWindow::ReserveComplete(TInt aError) |
|
441 { |
|
442 LOG1(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::ReserveComplete %d", aError); |
|
443 |
|
444 if (aError == KErrNone) |
|
445 { |
|
446 // camera will notify completion with PowerOnComplete method. |
|
447 iUICamera->PowerOn(); |
|
448 } |
|
449 } |
|
450 |
|
451 |
|
452 // --------------------------------------------------------------------------- |
|
453 // From class MCameraObserver |
|
454 // CMMACameraWindow::PowerOnComplete |
|
455 // |
|
456 // --------------------------------------------------------------------------- |
|
457 // |
|
458 void CMMACameraWindow::PowerOnComplete(TInt aError) |
|
459 { |
|
460 ELOG1(EJavaMMAPI, "MMA::CMMACameraWindow::PowerOnComplete %d", aError); |
|
461 |
|
462 if (aError == KErrNone) |
|
463 { |
|
464 iCameraPowerOn = ETrue; |
|
465 SetViewFinderVisibility(ETrue); |
|
466 } |
|
467 } |
|
468 |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // From class MCameraObserver |
|
472 // CMMACameraWindow::ViewFinderFrameReady |
|
473 // |
|
474 // --------------------------------------------------------------------------- |
|
475 // |
|
476 void CMMACameraWindow::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/) |
|
477 { |
|
478 // Empty implementation of the interface method |
|
479 LOG(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::ViewFinderFrameReady"); |
|
480 } |
|
481 |
|
482 |
|
483 // --------------------------------------------------------------------------- |
|
484 // From class MCameraObserver |
|
485 // CMMACameraWindow::ImageReady |
|
486 // |
|
487 // --------------------------------------------------------------------------- |
|
488 // |
|
489 void CMMACameraWindow::ImageReady(CFbsBitmap* /*aBitmap*/, |
|
490 HBufC8* /*aData*/, |
|
491 TInt /*aError*/) |
|
492 { |
|
493 // Empty implementation of the interface method |
|
494 LOG(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::ImageReady"); |
|
495 } |
|
496 |
|
497 |
|
498 // --------------------------------------------------------------------------- |
|
499 // From class MCameraObserver |
|
500 // CMMACameraWindow::FrameBufferReady |
|
501 // |
|
502 // --------------------------------------------------------------------------- |
|
503 // |
|
504 void CMMACameraWindow::FrameBufferReady(MFrameBuffer* /*aFrameBuffer*/, |
|
505 TInt /*aError*/) |
|
506 { |
|
507 // Empty implementation of the interface method |
|
508 LOG(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::FrameBufferReady"); |
|
509 } |
|
510 |
|
511 |
|
512 // --------------------------------------------------------------------------- |
|
513 // From class MDirectScreenAccess. |
|
514 // CMMACameraWindow::AbortNow |
|
515 // |
|
516 // --------------------------------------------------------------------------- |
|
517 // |
|
518 void CMMACameraWindow::AbortNow( |
|
519 RDirectScreenAccess::TTerminationReasons /*aReasons*/) |
|
520 { |
|
521 SetViewFinderVisibility(EFalse); |
|
522 } |
|
523 |
|
524 |
|
525 // --------------------------------------------------------------------------- |
|
526 // From class MDirectScreenAccess. |
|
527 // CMMACameraWindow::Restart |
|
528 // |
|
529 // --------------------------------------------------------------------------- |
|
530 // |
|
531 void CMMACameraWindow::Restart( |
|
532 RDirectScreenAccess::TTerminationReasons /*aReasons*/) |
|
533 { |
|
534 SetViewFinderVisibility(ETrue); |
|
535 } |
|
536 |
|
537 |
|
538 // --------------------------------------------------------------------------- |
|
539 // CMMACameraWindow::CMMACameraWindow |
|
540 // C++ constructor. |
|
541 // --------------------------------------------------------------------------- |
|
542 // |
|
543 CMMACameraWindow::CMMACameraWindow(TInt aCameraHandle): |
|
544 iVisible(EFalse), |
|
545 iStarted(EFalse), |
|
546 iViewFinderVisible(EFalse), |
|
547 iCameraPowerOn(EFalse), |
|
548 iDrawRect(0, 0, 0, 0), |
|
549 iClientRect(0, 0, 0, 0), |
|
550 iCameraHandle(aCameraHandle), |
|
551 iUICamera(NULL), |
|
552 iDisplay(NULL), |
|
553 iStarterTimer(NULL), |
|
554 iDirectAccess(NULL), |
|
555 iErrorIconBitmap(NULL), |
|
556 iErrorIconMaskBitmap(NULL), |
|
557 iRWindowRect(0, 0, 0, 0) |
|
558 { |
|
559 } |
|
560 |
|
561 |
|
562 // --------------------------------------------------------------------------- |
|
563 // CMMACameraWindow::UIStartViewFinder |
|
564 // Creates UI Camera. |
|
565 // This CCamera instance is duplicated from handle given to the constructor. |
|
566 // Have to be called from the thread which UI Camera will be controlled from. |
|
567 // --------------------------------------------------------------------------- |
|
568 // |
|
569 void CMMACameraWindow::UIStartViewFinder( |
|
570 RWsSession &aWs, |
|
571 CWsScreenDevice &aScreenDevice, |
|
572 RWindowBase &aWindow) |
|
573 { |
|
574 LOG(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::UIStartViewFinder"); |
|
575 |
|
576 iWs = &aWs; |
|
577 iScreenDevice = &aScreenDevice; |
|
578 iWindow = &aWindow; |
|
579 |
|
580 if (!iUICamera) |
|
581 { |
|
582 TRAPD(error, iUICamera = |
|
583 CCamera::NewDuplicateL(*this, iCameraHandle)); |
|
584 |
|
585 ELOG1(EJavaMMAPI, |
|
586 "MMA::CMMACameraWindow::UIStartViewFinder - NewDuplicateL %d", |
|
587 error); |
|
588 |
|
589 if (error == KErrNone) |
|
590 { |
|
591 iUICamera->Reserve(); |
|
592 } |
|
593 } |
|
594 } |
|
595 |
|
596 |
|
597 // --------------------------------------------------------------------------- |
|
598 // CMMACameraWindow::SetViewFinderVisibility |
|
599 // If UI Camera have been created, it starts/hides the DirectViewFinder. |
|
600 // Have to be called from UI thread in which iUICamera instance was created. |
|
601 // --------------------------------------------------------------------------- |
|
602 // |
|
603 void CMMACameraWindow::SetViewFinderVisibility(TBool aVisible) |
|
604 { |
|
605 LOG1(EJavaMMAPI, EInfo, "MMA::CMMACameraWindow::SetViewFinderVisibility - %d", |
|
606 aVisible); |
|
607 |
|
608 if (!iUICamera || !iCameraPowerOn || iViewFinderVisible == aVisible) |
|
609 { |
|
610 return; |
|
611 } |
|
612 |
|
613 if (aVisible) |
|
614 { |
|
615 // Viewfinder is going to start |
|
616 if (!iVisible || !iStarted) |
|
617 { |
|
618 return; |
|
619 } |
|
620 |
|
621 iViewFinderVisible = ETrue; |
|
622 |
|
623 if (!iStarterTimer) |
|
624 { |
|
625 // If starter timer haven't been created yet, create an instance |
|
626 TRAPD( |
|
627 timerErr, |
|
628 iStarterTimer = CPeriodic::NewL(CActive::EPriorityIdle)); |
|
629 |
|
630 if (timerErr != KErrNone) |
|
631 { |
|
632 ELOG1(EJavaMMAPI, |
|
633 "MMA::CMMACameraWindow::SetViewFinderVisibility - timer error = %d", |
|
634 timerErr); |
|
635 __ASSERT_DEBUG(EFalse, User::Invariant()); |
|
636 } |
|
637 } |
|
638 |
|
639 if (!iStarterTimer->IsActive()) |
|
640 { |
|
641 iStarterTimer->Start( |
|
642 KStarterTimeout, |
|
643 0, |
|
644 TCallBack(StarterTimerCallback, this)); |
|
645 } |
|
646 } |
|
647 else |
|
648 { |
|
649 // Viewfinder is going to be cancelled |
|
650 LOG(EJavaMMAPI,EInfo, |
|
651 "MMA::CMMACameraWindow::SetViewFinderVisibility - Stopping VF"); |
|
652 |
|
653 if (iStarterTimer && iStarterTimer->IsActive()) |
|
654 { |
|
655 // Cancel the running starter timer |
|
656 iStarterTimer->Cancel(); |
|
657 } |
|
658 |
|
659 if (iUICamera->ViewFinderActive()) |
|
660 { |
|
661 iUICamera->StopViewFinder(); |
|
662 } |
|
663 if (iDirectAccess->IsActive()) |
|
664 { |
|
665 iDirectAccess->Cancel(); |
|
666 } |
|
667 |
|
668 iViewFinderVisible = EFalse; |
|
669 } |
|
670 } |
|
671 |
|
672 |
|
673 // --------------------------------------------------------------------------- |
|
674 // CMMACameraWindow::StarterTimerCallback |
|
675 // Executed at the expiry of the iStartedTimer. |
|
676 // --------------------------------------------------------------------------- |
|
677 // |
|
678 TInt CMMACameraWindow::StarterTimerCallback(TAny* aThis) |
|
679 { |
|
680 CMMACameraWindow* self = static_cast<CMMACameraWindow*>(aThis); |
|
681 ASSERT(self); |
|
682 |
|
683 self->StartViewFinder(); |
|
684 |
|
685 // We don't want to run the callback again |
|
686 return EFalse; |
|
687 } |
|
688 |
|
689 |
|
690 // --------------------------------------------------------------------------- |
|
691 // From class MMMADisplayWindow |
|
692 // CMMACameraWindow::SetRWindowRect |
|
693 // |
|
694 // --------------------------------------------------------------------------- |
|
695 // |
|
696 void CMMACameraWindow::SetRWindowRect(const TRect& aRect, |
|
697 MMMADisplay::TThreadType aThreadType) |
|
698 { |
|
699 ELOG2(EJavaMMAPI, |
|
700 "MID::CMMACameraWindow::SetRWindowRect TL %d %d", |
|
701 aRect.iTl.iX, aRect.iTl.iY); |
|
702 ELOG2(EJavaMMAPI, |
|
703 "MID::CMMACameraWindow::SetRWindowRect BR %d %d", |
|
704 aRect.iBr.iX, aRect.iBr.iY); |
|
705 iRWindowRect = aRect; |
|
706 |
|
707 if (MMMADisplay::EMmaThread == aThreadType) |
|
708 { |
|
709 if (iDisplay) |
|
710 { |
|
711 //iDisplay->UIGetCallback(*this, |
|
712 // CMMACameraWindow::EResetViewFinder); |
|
713 } |
|
714 } |
|
715 else if (MMMADisplay::EUiThread == aThreadType) |
|
716 { |
|
717 ResetViewFinder(); |
|
718 } |
|
719 } |
|
720 |
|
721 |
|
722 // --------------------------------------------------------------------------- |
|
723 // CMMACameraWindow::StartViewFinder |
|
724 // Starts viewfinder. |
|
725 // --------------------------------------------------------------------------- |
|
726 // |
|
727 void CMMACameraWindow::StartViewFinder() |
|
728 { |
|
729 LOG(EJavaMMAPI,EInfo," < StartViewFinder"); |
|
730 |
|
731 ASSERT(iUICamera); |
|
732 ASSERT(iCameraPowerOn); |
|
733 ASSERT(iStarted); |
|
734 |
|
735 iStarterTimer->Cancel(); |
|
736 |
|
737 // align client rect to RWindow, viewfinder |
|
738 // display co-ordinates is w.r.t to RWindow |
|
739 TRect relativeClientRect; |
|
740 relativeClientRect = iClientRect; |
|
741 relativeClientRect.Move(-iRWindowRect.iTl); |
|
742 |
|
743 // Set the drawing area |
|
744 TRect drawRect(iDrawRect); |
|
745 drawRect.Move(relativeClientRect.iTl); |
|
746 |
|
747 LOG2(EJavaMMAPI, EInfo, |
|
748 "MMA::CMMACameraWindow::StartViewFinder - Starting VF TL:%d,%d", |
|
749 drawRect.iTl.iX, |
|
750 drawRect.iTl.iY); |
|
751 LOG2(EJavaMMAPI, EInfo, |
|
752 "MMA::CMMACameraWindow::StartViewFinder - Starting VF BR:%d,%d", |
|
753 drawRect.iBr.iX, |
|
754 drawRect.iBr.iY); |
|
755 |
|
756 TRAPD(vfError, iUICamera->StartViewFinderDirectL( |
|
757 *iWs, *iScreenDevice, *iWindow, drawRect)); |
|
758 |
|
759 if (vfError == KErrNone) |
|
760 { |
|
761 LOG(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::StartViewFinder - Start OK"); |
|
762 } |
|
763 else |
|
764 { |
|
765 LOG1(EJavaMMAPI, EInfo, |
|
766 "MMA::CMMACameraWindow::StartViewFinder() - \ |
|
767 StartViewFinderDirectL error=%d", vfError); |
|
768 |
|
769 TRAP_IGNORE(DrawViewFinderErrorL(vfError, drawRect)); |
|
770 } |
|
771 |
|
772 LOG(EJavaMMAPI,EInfo," > StartViewFinder"); |
|
773 } |
|
774 |
|
775 |
|
776 // --------------------------------------------------------------------------- |
|
777 // CMMACameraWindow::DrawViewFinderError() |
|
778 // Draws the error message to specified area. |
|
779 // Used in cases when viewfinder is unable to start. |
|
780 // --------------------------------------------------------------------------- |
|
781 // |
|
782 void CMMACameraWindow::DrawViewFinderErrorL( |
|
783 const TInt /*aError*/, |
|
784 const TRect& aDrawRect) |
|
785 { |
|
786 |
|
787 ASSERT(iDirectAccess); |
|
788 TInt dcError = KErrNone; |
|
789 if (!iDirectAccess->IsActive()) |
|
790 { |
|
791 TRAP(dcError, iDirectAccess->StartL()); |
|
792 } |
|
793 |
|
794 TRect drawRect(aDrawRect); |
|
795 |
|
796 if (dcError == KErrNone) |
|
797 { |
|
798 drawRect.Intersection(iClientRect); |
|
799 drawRect.Move(-iWindow->AbsPosition()); |
|
800 |
|
801 CFbsBitGc* directGc = iDirectAccess->Gc(); |
|
802 directGc->SetClippingRect(drawRect); |
|
803 directGc->SetBrushColor(TRgb(128,128,128)); |
|
804 directGc->SetPenColor(TRgb(128,0,0)); |
|
805 directGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
806 directGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
807 directGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); |
|
808 directGc->DrawRect(drawRect); |
|
809 |
|
810 if (!iErrorIconBitmap || !iErrorIconMaskBitmap) |
|
811 { |
|
812 if (iErrorIconBitmap) |
|
813 { |
|
814 delete iErrorIconBitmap; |
|
815 iErrorIconBitmap = NULL; |
|
816 } |
|
817 |
|
818 if (iErrorIconMaskBitmap) |
|
819 { |
|
820 delete iErrorIconMaskBitmap; |
|
821 iErrorIconMaskBitmap = NULL; |
|
822 } |
|
823 /* |
|
824 AknsUtils::CreateIconL( |
|
825 AknsUtils::SkinInstance(), |
|
826 KAknsIIDQgnIndiCam4Camera, |
|
827 iErrorIconBitmap, |
|
828 iErrorIconMaskBitmap, |
|
829 KCameraAppBitmapFile, |
|
830 EMbmCameraappQgn_indi_cam4_camera, |
|
831 EMbmCameraappQgn_indi_cam4_camera_mask |
|
832 ); |
|
833 */ |
|
834 } |
|
835 |
|
836 //TRect iconRect |
|
837 drawRect.iTl.iX += KErrorIconMargin; |
|
838 drawRect.iTl.iY += KErrorIconMargin; |
|
839 drawRect.iBr.iX -= KErrorIconMargin; |
|
840 drawRect.iBr.iY -= KErrorIconMargin; |
|
841 |
|
842 if (iErrorIconBitmap->SizeInPixels() != drawRect.Size()) |
|
843 { |
|
844 AknIconUtils::SetSize(iErrorIconBitmap, drawRect.Size()); |
|
845 AknIconUtils::SetSize(iErrorIconMaskBitmap, drawRect.Size()); |
|
846 } |
|
847 |
|
848 directGc->BitBltMasked( |
|
849 drawRect.iTl, iErrorIconBitmap, |
|
850 TRect(iErrorIconBitmap->SizeInPixels()), |
|
851 iErrorIconMaskBitmap, EFalse); |
|
852 |
|
853 iDirectAccess->ScreenDevice()->Update(); |
|
854 } |
|
855 |
|
856 } |
|
857 |
|
858 |
|
859 // --------------------------------------------------------------------------- |
|
860 // CMMACameraWindow::ReleaseUiResources() |
|
861 // Stops the DirectViewFinder and deletes UI Camera instance |
|
862 // Have to be called from UI thread in which UI Camera |
|
863 // have been created before the CMMACameraWindow instance |
|
864 // is deleted. |
|
865 // --------------------------------------------------------------------------- |
|
866 // |
|
867 void CMMACameraWindow::ReleaseUiResources() |
|
868 { |
|
869 if (iUICamera) |
|
870 { |
|
871 SetViewFinderVisibility(EFalse); |
|
872 // iStarterTimer is cancelled by previous call |
|
873 // it can be deleted now |
|
874 delete iStarterTimer; |
|
875 iStarterTimer = NULL; |
|
876 iUICamera->Release(); |
|
877 delete iUICamera; |
|
878 iUICamera = NULL; |
|
879 iCameraPowerOn = EFalse; |
|
880 iDirectAccess->Cancel(); |
|
881 delete iDirectAccess; |
|
882 iDirectAccess = NULL; |
|
883 delete iErrorIconBitmap; |
|
884 iErrorIconBitmap = NULL; |
|
885 delete iErrorIconMaskBitmap; |
|
886 iErrorIconMaskBitmap = NULL; |
|
887 } |
|
888 } |
|
889 |
|
890 |
|
891 // --------------------------------------------------------------------------- |
|
892 // CMMACameraWindow::ResetViewFinder |
|
893 // Resets (stops and starts) viewfinder |
|
894 // --------------------------------------------------------------------------- |
|
895 // |
|
896 void CMMACameraWindow::ResetViewFinder() |
|
897 { |
|
898 |
|
899 if (iStarterTimer && !iStarterTimer->IsActive() && iStarted) |
|
900 { |
|
901 SetViewFinderVisibility(EFalse); |
|
902 SetViewFinderVisibility(ETrue); |
|
903 } |
|
904 } |
|
905 |
|
906 |
|
907 // --------------------------------------------------------------------------- |
|
908 // CMMACameraWindow::Destroy |
|
909 // Deletes this object. |
|
910 // --------------------------------------------------------------------------- |
|
911 // |
|
912 void CMMACameraWindow::Destroy() |
|
913 { |
|
914 // Delete itself |
|
915 delete this; |
|
916 } |
|
917 |
|
918 |
|
919 // --------------------------------------------------------------------------- |
|
920 // From class MUiEventConsumer. |
|
921 // CMMACameraWindow::MdcDSAResourcesCallback |
|
922 // Callback to iDisplay->UIGetDSAResources(). |
|
923 // Invoked asynchronously from UI Event Server thread. |
|
924 // --------------------------------------------------------------------------- |
|
925 // |
|
926 /*void CMMACameraWindow::MdcDSAResourcesCallback( |
|
927 RWsSession &aWs, |
|
928 CWsScreenDevice &aScreenDevice, |
|
929 RWindowBase &aWindow) |
|
930 { |
|
931 TRAPD(error, iDirectAccess = CDirectScreenAccess::NewL(aWs, |
|
932 aScreenDevice, |
|
933 aWindow, |
|
934 *this)); |
|
935 LOG1(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::MdcDSAResourcesCallback, error = %d", error); |
|
936 if (KErrNone != error) |
|
937 { |
|
938 return; |
|
939 } |
|
940 this->UIStartViewFinder(aWs, aScreenDevice, aWindow); |
|
941 } |
|
942 */ |
|
943 |
|
944 // --------------------------------------------------------------------------- |
|
945 // From class MUiEventConsumer. |
|
946 // CMMACameraWindow::MdcUICallback |
|
947 // Callback to iDisplay->UIGetCallback(). |
|
948 // Invoked asynchronously from UI Event Server thread. |
|
949 // --------------------------------------------------------------------------- |
|
950 // |
|
951 |
|
952 void CMMACameraWindow::UICallback(TInt aCallbackId) |
|
953 { |
|
954 LOG(EJavaMMAPI,EInfo,"MMA::CMMACameraWindow::MdcUICallback"); |
|
955 |
|
956 switch (aCallbackId) |
|
957 { |
|
958 case EDeleteViewFinder: |
|
959 ReleaseUiResources(); |
|
960 break; |
|
961 case EHideViewFinder: |
|
962 SetViewFinderVisibility(EFalse); |
|
963 break; |
|
964 case EShowViewFinder: |
|
965 SetViewFinderVisibility(ETrue); |
|
966 break; |
|
967 case EResetViewFinder: |
|
968 ResetViewFinder(); |
|
969 break; |
|
970 case EDestroyWindow: |
|
971 Destroy(); |
|
972 break; |
|
973 } |
|
974 } |
|
975 |
|
976 |
|
977 // END OF FILE |