|
1 /* |
|
2 * Copyright (c) 2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <bitstd.h> |
|
19 #include <ecam.h> |
|
20 #include <ecam/mcameradirectviewfinder.h> |
|
21 |
|
22 #include "mccscreen.h" |
|
23 #include "mcccontrollerlogs.h" |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 |
|
27 // EXTERNAL FUNCTION PROTOTYPES |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 _LIT(KMccWindowGroupName,"32MccVideoWindow"); |
|
32 |
|
33 // MACROS |
|
34 |
|
35 // LOCAL CONSTANTS AND MACROS |
|
36 |
|
37 // MODULE DATA STRUCTURES |
|
38 |
|
39 // LOCAL FUNCTION PROTOTYPES |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 |
|
43 // ============================= LOCAL FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CMccScreen::NewL |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CMccScreen* CMccScreen::NewL( CCamera* aCamera, |
|
50 TPoint aPos, |
|
51 TSize aArea, |
|
52 TInt aIndex, |
|
53 TInt aWindowOrdinalPosition, |
|
54 TInt aWindowOrdinalPriority ) |
|
55 { |
|
56 // Resolve screen type based on ecam capabilities, asssume direct vf |
|
57 // to be available if camera not present yet. |
|
58 CMccScreen* screen = NULL; |
|
59 TBool useDirectVf = ETrue; |
|
60 |
|
61 if ( aCamera ) |
|
62 { |
|
63 TCameraInfo info; |
|
64 aCamera->CameraInfo( info ); |
|
65 useDirectVf = ( info.iOptionsSupported & TCameraInfo::EViewFinderDirectSupported ); |
|
66 } |
|
67 |
|
68 if ( useDirectVf ) |
|
69 { |
|
70 TRAPD( err, screen = CMccScreenDirect::NewL( |
|
71 aCamera, aPos, aArea, aIndex, |
|
72 aWindowOrdinalPosition, aWindowOrdinalPriority ) ); |
|
73 // If creation failes for some reason, bitmap vf is tried to be |
|
74 // created as a fallback |
|
75 if ( err == KErrNoMemory ) |
|
76 { |
|
77 User::Leave( err ); |
|
78 } |
|
79 if ( err ) |
|
80 { |
|
81 __CONTROLLER_INT1( "CMccScreen::NewL, direct screen creation failed:", err ) |
|
82 } |
|
83 } |
|
84 |
|
85 if ( !screen ) |
|
86 { |
|
87 screen = CMccScreenBitmap::NewL( |
|
88 aCamera, aPos, aArea, aIndex, |
|
89 aWindowOrdinalPosition, aWindowOrdinalPriority ); |
|
90 } |
|
91 return screen; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CMccScreen::~CMccScreen |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CMccScreen::~CMccScreen() |
|
99 { |
|
100 __CONTROLLER( "CMccScreen::~CMccScreen" ) |
|
101 |
|
102 StopCamera(); |
|
103 |
|
104 delete iGraphicsContext; |
|
105 delete iDev; |
|
106 delete iRw; |
|
107 delete iRwGroup; |
|
108 iRwSession.Close(); |
|
109 |
|
110 __CONTROLLER( "CMccScreen::~CMccScreen, exit" ) |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CMccScreen::StartL |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CMccScreen::StartL() |
|
118 { |
|
119 |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CMccScreen::Stop |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CMccScreen::Stop() |
|
127 { |
|
128 |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CMccScreen::Draw |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CMccScreen::Draw( CFbsBitmap& /*aFrame*/ ) |
|
136 { |
|
137 |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CMccScreen::SetCamera |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 TInt CMccScreen::SetCamera( CCamera* aCamera ) |
|
145 { |
|
146 if ( !aCamera ) |
|
147 { |
|
148 StopCamera(); |
|
149 } |
|
150 |
|
151 iCamera = aCamera; |
|
152 |
|
153 return KErrNone; |
|
154 } |
|
155 |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CMccScreen::StopCamera |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CMccScreen::StopCamera() |
|
162 { |
|
163 __CONTROLLER( "CMccScreen::StopCamera" ) |
|
164 |
|
165 if ( iCamera ) |
|
166 { |
|
167 iCamera->StopViewFinder(); |
|
168 } |
|
169 |
|
170 __CONTROLLER( "CMccScreen::StopCamera, exit" ) |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CMccScreen::VfStartPossible |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TBool CMccScreen::VfStartPossible() |
|
178 { |
|
179 return ( iCamera && !iCamera->ViewFinderActive() && |
|
180 iArea.iWidth > 0 && |
|
181 iArea.iHeight > 0 ); |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CMccScreen::ConstructL |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CMccScreen::ConstructL() |
|
189 { |
|
190 __CONTROLLER( "CMccScreen::ConstructL" ) |
|
191 User::LeaveIfError( iRwSession.Connect() ); |
|
192 |
|
193 // Create window group |
|
194 TInt groupId = iRwSession.GetFocusWindowGroup(); |
|
195 iRwGroup = new (ELeave) RWindowGroup( iRwSession ) ; |
|
196 |
|
197 __CONTROLLER_INT1( "CMccScreen::ConstructL, window ordinal pos", |
|
198 iWindowOrdinalPosition ) |
|
199 __CONTROLLER_INT1( "CMccScreen::ConstructL, window ordinal priority", |
|
200 iWindowOrdinalPriority ) |
|
201 |
|
202 User::LeaveIfError( iRwGroup->Construct( groupId, EFalse ) ); |
|
203 iRwGroup->SetName( KMccWindowGroupName ); |
|
204 |
|
205 iRwGroup->SetOrdinalPosition( iWindowOrdinalPosition, iWindowOrdinalPriority ); |
|
206 |
|
207 // Create screen device |
|
208 iDev = new (ELeave) CWsScreenDevice( iRwSession ); |
|
209 iDev->Construct( iDeviceIndex ); |
|
210 |
|
211 TInt currMode = iDev->CurrentScreenMode(); |
|
212 __CONTROLLER_INT1( "CMccScreen::ConstructL, screen device mode", currMode ) |
|
213 |
|
214 TPixelsTwipsAndRotation sizeAndRotation; |
|
215 iDev->GetScreenModeSizeAndRotation( currMode, sizeAndRotation ); |
|
216 __CONTROLLER_INT2( "CMccScreen::ConstructL, screen device size", |
|
217 sizeAndRotation.iPixelSize.iWidth, |
|
218 sizeAndRotation.iPixelSize.iHeight ) |
|
219 |
|
220 __CONTROLLER_INT1( "CMccScreen::ConstructL, screen device orientation", |
|
221 sizeAndRotation.iRotation ) |
|
222 |
|
223 // Create window |
|
224 iRw = new (ELeave) RWindow( iRwSession ); |
|
225 |
|
226 User::LeaveIfError( iRw->Construct( *iRwGroup, (TUint32)iRw ) ); |
|
227 |
|
228 __CONTROLLER_INT2( "CMccScreen::ConstructL, window pos", iPosition.iX, iPosition.iY ) |
|
229 __CONTROLLER_INT2( "CMccScreen::ConstructL, window size", iArea.iWidth, iArea.iHeight ) |
|
230 |
|
231 iRw->SetPosition( iPosition ); |
|
232 //iRw->SetBackgroundColor( KRgbBlack ); |
|
233 iRw->SetSize( iArea ); |
|
234 iRw->SetOrdinalPosition( iWindowOrdinalPosition ); |
|
235 |
|
236 __CONTROLLER( "CMccScreen: creating graphics context ..." ) |
|
237 User::LeaveIfError( iDev->CreateContext( iGraphicsContext ) ); |
|
238 __CONTROLLER( "CMccScreen: graphics context created!" ) |
|
239 |
|
240 iRw->Activate(); |
|
241 iRwSession.Flush(); |
|
242 |
|
243 __CONTROLLER( "CMccScreen::ConstructL, exit" ) |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CMccScreen::CMccScreen |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 CMccScreen::CMccScreen( |
|
251 TMccScreenType aScreenType, |
|
252 CCamera* aCamera, |
|
253 TPoint aPos, |
|
254 TSize aArea, |
|
255 TInt aIndex, |
|
256 TInt aWindowOrdinalPosition, |
|
257 TInt aWindowOrdinalPriority ) : |
|
258 iCamera( aCamera ), |
|
259 iDeviceIndex( aIndex ), |
|
260 iPosition( aPos ), |
|
261 iArea( aArea ), |
|
262 iWindowOrdinalPosition( aWindowOrdinalPosition ), |
|
263 iWindowOrdinalPriority( aWindowOrdinalPriority ), |
|
264 iScreenType( aScreenType ) |
|
265 { |
|
266 |
|
267 } |
|
268 |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CMccScreenBitmap::CMccScreenBitmap |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 CMccScreenBitmap* CMccScreenBitmap::NewL( |
|
275 CCamera* aCamera, |
|
276 TPoint aPos, |
|
277 TSize aArea, |
|
278 TInt aIndex, |
|
279 TInt aWindowOrdinalPosition, |
|
280 TInt aWindowOrdinalPriority ) |
|
281 { |
|
282 CMccScreenBitmap* self = new ( ELeave ) CMccScreenBitmap( aCamera, |
|
283 aPos, |
|
284 aArea, |
|
285 aIndex, |
|
286 aWindowOrdinalPosition, |
|
287 aWindowOrdinalPriority ); |
|
288 CleanupStack::PushL( self ); |
|
289 self->ConstructL(); |
|
290 CleanupStack::Pop( self ); |
|
291 return self; |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CMccScreenBitmap::CMccScreenBitmap |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 CMccScreenBitmap::CMccScreenBitmap( |
|
299 CCamera* aCamera, |
|
300 TPoint aPos, |
|
301 TSize aArea, |
|
302 TInt aIndex, |
|
303 TInt aWindowOrdinalPosition, |
|
304 TInt aWindowOrdinalPriority ) : |
|
305 CMccScreen( EBitmapScreen, aCamera, aPos, aArea, aIndex, |
|
306 aWindowOrdinalPosition, aWindowOrdinalPriority ), |
|
307 iAborted( ETrue ) |
|
308 { |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CMccScreenBitmap::CMccScreenBitmap |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 CMccScreenBitmap::~CMccScreenBitmap() |
|
316 { |
|
317 __CONTROLLER( "CMccScreenBitmap::~CMccScreenBitmap" ) |
|
318 |
|
319 DetachFrame(); // Must do bitmap detach before releasing window resources |
|
320 delete iDirectScreenAccess; |
|
321 |
|
322 delete iPausedFrameData; |
|
323 |
|
324 __CONTROLLER( "CMccScreenBitmap::~CMccScreenBitmap, exit" ) |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CMccScreenBitmap::ConstructL |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 void CMccScreenBitmap::ConstructL() |
|
332 { |
|
333 __CONTROLLER( "CMccScreenBitmap::ConstructL" ) |
|
334 |
|
335 CMccScreen::ConstructL(); |
|
336 |
|
337 // Create direct screen access |
|
338 iDirectScreenAccess = CDirectScreenAccess::NewL( iRwSession, *iDev, *iRw, *this ); |
|
339 |
|
340 UpdateViewFinderArea( iArea ); |
|
341 |
|
342 __CONTROLLER_INT2( "CMccScreenBitmap::ConstructL, viewfinder pos", |
|
343 iViewFinderImageRect.iTl.iX, iViewFinderImageRect.iTl.iY ) |
|
344 __CONTROLLER_INT2( "CMccScreenBitmap::ConstructL, viewfinder size", |
|
345 iViewFinderImageRect.Width(), iViewFinderImageRect.Height() ) |
|
346 |
|
347 __CONTROLLER( "CMccScreenBitmap::ConstructL, exit" ) |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CMccScreenBitmap::StartL |
|
352 // ----------------------------------------------------------------------------- |
|
353 // |
|
354 void CMccScreenBitmap::StartL() |
|
355 { |
|
356 iStopped = EFalse; |
|
357 |
|
358 if ( iCamera ) |
|
359 { |
|
360 StartCameraL(); |
|
361 } |
|
362 else if ( iPausedFrameData ) |
|
363 { |
|
364 __CONTROLLER( "CMccScreenBitmap::StartL, using paused frame" ) |
|
365 |
|
366 CFbsBitmap* frame = RestoreFrameLC(); |
|
367 AttachFrameL( frame ); |
|
368 CleanupStack::Pop( frame ); |
|
369 } |
|
370 else |
|
371 { |
|
372 // NOP |
|
373 } |
|
374 |
|
375 StartDsaL(); |
|
376 |
|
377 __CONTROLLER( "CMccScreenBitmap::StartL, exit" ) |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CMccScreenBitmap::StartCameraL |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 void CMccScreenBitmap::StartCameraL() |
|
385 { |
|
386 __CONTROLLER( "CMccScreenBitmap::StartCameraL" ) |
|
387 |
|
388 __ASSERT_ALWAYS( iCamera, User::Leave( KErrNotReady ) ); |
|
389 |
|
390 // Camera may modify the size |
|
391 TSize vfBitmapSize = iArea; |
|
392 __CONTROLLER_INT2( "CMccScreenBitmap::StartL, size before", |
|
393 vfBitmapSize.iWidth, |
|
394 vfBitmapSize.iHeight ) |
|
395 if ( VfStartPossible() ) |
|
396 { |
|
397 iCamera->StartViewFinderBitmapsL( vfBitmapSize ); |
|
398 } |
|
399 |
|
400 __CONTROLLER_INT2( "CMccScreenBitmap::StartL, size after", |
|
401 vfBitmapSize.iWidth, |
|
402 vfBitmapSize.iHeight ) |
|
403 |
|
404 UpdateViewFinderArea( vfBitmapSize ); |
|
405 |
|
406 __CONTROLLER( "CMccScreenBitmap::StartCameraL, exit" ) |
|
407 } |
|
408 |
|
409 // ----------------------------------------------------------------------------- |
|
410 // CMccScreenBitmap::StartDsaL |
|
411 // ----------------------------------------------------------------------------- |
|
412 // |
|
413 void CMccScreenBitmap::StartDsaL() |
|
414 { |
|
415 __CONTROLLER( "CMccScreenBitmap::StartDsaL" ) |
|
416 |
|
417 iAborted = EFalse; |
|
418 iDirectScreenAccess->Cancel(); |
|
419 iDirectScreenAccess->StartL(); |
|
420 iGc = iDirectScreenAccess->Gc(); |
|
421 iFbsDev = iDirectScreenAccess->ScreenDevice(); |
|
422 iRegion = iDirectScreenAccess->DrawingRegion(); |
|
423 |
|
424 #ifdef __MCC_CONTROLLER |
|
425 if ( iRegion && !iRegion->IsEmpty() ) |
|
426 { |
|
427 for ( TInt i = 0; i < iRegion->Count(); i++ ) |
|
428 { |
|
429 const TRect& regionRect = (*iRegion)[ i ]; |
|
430 __CONTROLLER_INT2( "CMccScreenBitmap::StartDsaL, rect tl", |
|
431 regionRect.iTl.iX, regionRect.iTl.iY ) |
|
432 __CONTROLLER_INT2( "CMccScreenBitmap::StartDsaL, rect br", |
|
433 regionRect.iBr.iX, regionRect.iBr.iY ) |
|
434 } |
|
435 } |
|
436 #endif |
|
437 |
|
438 iGc->SetClippingRegion( iRegion ); |
|
439 |
|
440 // Fill with black areas which are not covered by viewfinder image. |
|
441 // If viewfinder image has not been yet received and drawn, fill whole area. |
|
442 // |
|
443 |
|
444 if ( !iFirstImageDrawn ) |
|
445 { |
|
446 // Whole area |
|
447 iGc->SetBrushColor( KRgbBlack ); |
|
448 iGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
449 TPoint pointTl( 0, 0 ); |
|
450 TRect rect( pointTl, iArea ); |
|
451 iGc->DrawRect( rect ); |
|
452 } |
|
453 else |
|
454 { |
|
455 DrawBlackBorders(); |
|
456 } |
|
457 |
|
458 if ( iAttachedFrame ) |
|
459 { |
|
460 __CONTROLLER( "CMccScreenBitmap::StartDsaL, draw attached frame" ) |
|
461 |
|
462 TSize viewFinderImageSize = iAttachedFrame->SizeInPixels(); |
|
463 |
|
464 TPoint corner = UpdateViewFinderArea( viewFinderImageSize ); |
|
465 |
|
466 iGc->BitBlt( corner, iAttachedFrame ); |
|
467 } |
|
468 |
|
469 DoScreenDeviceUpdate(); |
|
470 |
|
471 //iGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
472 |
|
473 __CONTROLLER( "CMccScreen::StartL, exit" ) |
|
474 } |
|
475 |
|
476 // ----------------------------------------------------------------------------- |
|
477 // CMccScreenBitmap::Stop |
|
478 // ----------------------------------------------------------------------------- |
|
479 // |
|
480 void CMccScreenBitmap::Stop() |
|
481 { |
|
482 __CONTROLLER( "CMccScreenBitmap::Stop" ) |
|
483 |
|
484 // Don't do anything yet, wait for next frame and then stop camera |
|
485 iStopped = ETrue; |
|
486 |
|
487 __CONTROLLER( "CMccScreenBitmap::Stop, exit" ) |
|
488 } |
|
489 |
|
490 // ----------------------------------------------------------------------------- |
|
491 // CMccScreenBitmap::Restart |
|
492 // ----------------------------------------------------------------------------- |
|
493 // |
|
494 void CMccScreenBitmap::Restart( RDirectScreenAccess::TTerminationReasons /*aReason*/ ) |
|
495 { |
|
496 __CONTROLLER( "CMccScreenBitmap::Restart" ) |
|
497 |
|
498 TRAP_IGNORE( StartDsaL() ); |
|
499 } |
|
500 |
|
501 // ----------------------------------------------------------------------------- |
|
502 // CMccScreenBitmap::AbortNow |
|
503 // ----------------------------------------------------------------------------- |
|
504 // |
|
505 void CMccScreenBitmap::AbortNow( RDirectScreenAccess::TTerminationReasons /*aReason*/ ) |
|
506 { |
|
507 __CONTROLLER( "CMccScreenBitmap::AbortNow" ) |
|
508 iDirectScreenAccess->Cancel(); |
|
509 |
|
510 iAborted = ETrue; |
|
511 } |
|
512 |
|
513 // ----------------------------------------------------------------------------- |
|
514 // CMccScreenBitmap::Draw |
|
515 // ----------------------------------------------------------------------------- |
|
516 // |
|
517 void CMccScreenBitmap::Draw( CFbsBitmap& aFrame ) |
|
518 { |
|
519 if ( iStopped ) |
|
520 { |
|
521 __CONTROLLER( "CMccScreenBitmap::Draw, store last frame and stop camera" ) |
|
522 |
|
523 // Screen was waiting for freeze frame from camera, inform observer |
|
524 // that camera is not needed anymore |
|
525 StoreFrameDataL( aFrame ); |
|
526 CFbsBitmap* frame = RestoreFrameLC(); |
|
527 AttachFrameL( frame ); |
|
528 CleanupStack::Pop( frame ); |
|
529 |
|
530 StopCamera(); |
|
531 __CONTROLLER( "CMccScreenBitmap::Draw, exit" ) |
|
532 } |
|
533 else |
|
534 { |
|
535 // When normal frame draw is requested, attached frame is not anymore drawn |
|
536 DetachFrame(); |
|
537 |
|
538 DoDraw( aFrame ); |
|
539 } |
|
540 } |
|
541 |
|
542 // ----------------------------------------------------------------------------- |
|
543 // CMccScreenBitmap::AttachFrameL |
|
544 // ----------------------------------------------------------------------------- |
|
545 // |
|
546 void CMccScreenBitmap::AttachFrameL( CFbsBitmap* aFrame ) |
|
547 { |
|
548 __CONTROLLER( "CMccScreenBitmap::AttachFrameL" ) |
|
549 |
|
550 __ASSERT_ALWAYS( aFrame, User::Leave( KErrArgument ) ); |
|
551 |
|
552 DetachFrame(); |
|
553 |
|
554 iAttachedFrame = aFrame; |
|
555 |
|
556 DoDraw( *iAttachedFrame ); |
|
557 |
|
558 __CONTROLLER( "CMccScreenBitmap::AttachFrameL, exit" ) |
|
559 } |
|
560 |
|
561 // ----------------------------------------------------------------------------- |
|
562 // CMccScreenBitmap::DetachFrame |
|
563 // ----------------------------------------------------------------------------- |
|
564 // |
|
565 void CMccScreenBitmap::DetachFrame() |
|
566 { |
|
567 if ( iAttachedFrame ) |
|
568 { |
|
569 __CONTROLLER( "CMccScreenBitmap::DetachFrame, detaching" ) |
|
570 iAttachedFrame->Reset(); |
|
571 delete iAttachedFrame; |
|
572 } |
|
573 |
|
574 iAttachedFrame = NULL; |
|
575 } |
|
576 |
|
577 // ----------------------------------------------------------------------------- |
|
578 // CMccScreenBitmap::UpdateViewFinderArea |
|
579 // ----------------------------------------------------------------------------- |
|
580 // |
|
581 TPoint CMccScreenBitmap::UpdateViewFinderArea( TSize aViewFinderImageSize ) |
|
582 { |
|
583 TPoint corner( 0, 0 ); |
|
584 if ( aViewFinderImageSize.iWidth < iArea.iWidth ) |
|
585 { |
|
586 // Divide the subtraction by two (i.e. do centering) |
|
587 corner.iX = ( iArea.iWidth - aViewFinderImageSize.iWidth ) >> 1; |
|
588 } |
|
589 |
|
590 if ( aViewFinderImageSize.iHeight < iArea.iHeight ) |
|
591 { |
|
592 // Divide the subtraction by two (i.e. do centering) |
|
593 corner.iY = ( iArea.iHeight - aViewFinderImageSize.iHeight ) >> 1; |
|
594 } |
|
595 |
|
596 iViewFinderImageRect = TRect( corner, aViewFinderImageSize ); |
|
597 |
|
598 return corner; |
|
599 } |
|
600 |
|
601 // ----------------------------------------------------------------------------- |
|
602 // CMccScreenBitmap::DoDraw |
|
603 // ----------------------------------------------------------------------------- |
|
604 // |
|
605 void CMccScreenBitmap::DoDraw( CFbsBitmap& aFrame ) |
|
606 { |
|
607 if ( !iAborted && iGc ) |
|
608 { |
|
609 iFirstImageDrawn = ETrue; |
|
610 |
|
611 TSize viewFinderImageSize = aFrame.SizeInPixels(); |
|
612 |
|
613 TBool imageSizeChanged = ( viewFinderImageSize != iViewFinderImageRect.Size() ); |
|
614 |
|
615 TPoint corner = UpdateViewFinderArea( viewFinderImageSize ); |
|
616 |
|
617 if ( imageSizeChanged ) |
|
618 { |
|
619 // Size of bitmap changed suddenly, borders need to be redrawn |
|
620 DrawBlackBorders(); |
|
621 } |
|
622 |
|
623 iGc->BitBlt( corner, &aFrame ); |
|
624 |
|
625 DoScreenDeviceUpdate(); |
|
626 } |
|
627 } |
|
628 |
|
629 // ----------------------------------------------------------------------------- |
|
630 // CMccScreenBitmap::DoScreenDeviceUpdate |
|
631 // ----------------------------------------------------------------------------- |
|
632 // |
|
633 void CMccScreenBitmap::DoScreenDeviceUpdate() |
|
634 { |
|
635 if ( iFbsDev ) |
|
636 { |
|
637 iFbsDev->Update(); |
|
638 } |
|
639 } |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // CMccScreenBitmap::StoreFrameDataL |
|
643 // ----------------------------------------------------------------------------- |
|
644 // |
|
645 void CMccScreenBitmap::StoreFrameDataL( CFbsBitmap& aFrame ) |
|
646 { |
|
647 __CONTROLLER( "CMccScreenBitmap::StoreFrameDataL" ) |
|
648 |
|
649 iPausedFrameSize = aFrame.SizeInPixels(); |
|
650 iPausedFrameDisplayMode = aFrame.DisplayMode(); |
|
651 TInt bitmapSizeInBytes = |
|
652 CFbsBitmap::ScanLineLength( iPausedFrameSize.iWidth, iPausedFrameDisplayMode ) * |
|
653 iPausedFrameSize.iHeight; |
|
654 HBufC8* pausedFrameData = HBufC8::NewLC( bitmapSizeInBytes ); |
|
655 aFrame.LockHeap(); |
|
656 pausedFrameData->Des().Copy( (TUint8*)aFrame.DataAddress(), bitmapSizeInBytes ); |
|
657 aFrame.UnlockHeap(); |
|
658 delete iPausedFrameData; |
|
659 iPausedFrameData = pausedFrameData; |
|
660 CleanupStack::Pop( pausedFrameData ); |
|
661 |
|
662 __CONTROLLER( "CMccScreenBitmap::StoreFrameDataL, exit" ) |
|
663 } |
|
664 |
|
665 // ----------------------------------------------------------------------------- |
|
666 // CMccScreenBitmap::RestoreFrameLC |
|
667 // ----------------------------------------------------------------------------- |
|
668 // |
|
669 CFbsBitmap* CMccScreenBitmap::RestoreFrameLC() |
|
670 { |
|
671 __CONTROLLER( "CMccScreenBitmap::RestoreFrameLC" ) |
|
672 |
|
673 __ASSERT_ALWAYS( iPausedFrameData, User::Leave( KErrNotReady ) ); |
|
674 |
|
675 CFbsBitmap* tempFrame = new ( ELeave ) CFbsBitmap; |
|
676 CleanupStack::PushL( tempFrame ); |
|
677 |
|
678 User::LeaveIfError( tempFrame->Create( iPausedFrameSize, iPausedFrameDisplayMode ) ); |
|
679 TInt bitmapSizeInBytes = |
|
680 CFbsBitmap::ScanLineLength( iPausedFrameSize.iWidth, iPausedFrameDisplayMode ) * |
|
681 iPausedFrameSize.iHeight; |
|
682 |
|
683 tempFrame->LockHeap(); |
|
684 Mem::Copy( tempFrame->DataAddress(), |
|
685 iPausedFrameData->Des().Ptr(), |
|
686 bitmapSizeInBytes ); |
|
687 tempFrame->UnlockHeap(); |
|
688 |
|
689 __CONTROLLER( "CMccScreenBitmap::RestoreFrameLC, exit" ) |
|
690 |
|
691 return tempFrame; |
|
692 } |
|
693 |
|
694 // ----------------------------------------------------------------------------- |
|
695 // CMccScreenBitmap::DrawBlackBorders |
|
696 // ----------------------------------------------------------------------------- |
|
697 // |
|
698 void CMccScreenBitmap::DrawBlackBorders() |
|
699 { |
|
700 iGc->SetBrushColor( KRgbBlack ); |
|
701 iGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
702 |
|
703 // Upper area |
|
704 TPoint pointTl( 0, 0 ); |
|
705 TPoint pointBr( iArea.iWidth, iViewFinderImageRect.iTl.iY ); |
|
706 TRect rect( pointTl, pointBr ); |
|
707 iGc->DrawRect( rect ); |
|
708 |
|
709 // Lower area |
|
710 pointTl.SetXY( 0, iViewFinderImageRect.iBr.iY ); |
|
711 pointBr.SetXY( iArea.iWidth, iArea.iHeight ); |
|
712 rect.SetRect( pointTl, pointBr ); |
|
713 iGc->DrawRect( rect ); |
|
714 |
|
715 // Left area |
|
716 pointTl.SetXY( 0, iViewFinderImageRect.iTl.iY ); |
|
717 pointBr.SetXY( iViewFinderImageRect.iTl.iX, iViewFinderImageRect.iBr.iY ); |
|
718 rect.SetRect( pointTl, pointBr ); |
|
719 iGc->DrawRect( rect ); |
|
720 |
|
721 // Right area |
|
722 pointTl.SetXY( iViewFinderImageRect.iBr.iX, iViewFinderImageRect.iTl.iY ); |
|
723 pointBr.SetXY( iArea.iWidth, iViewFinderImageRect.iBr.iY ); |
|
724 rect.SetRect( pointTl, pointBr ); |
|
725 iGc->DrawRect( rect ); |
|
726 } |
|
727 |
|
728 // ----------------------------------------------------------------------------- |
|
729 // CMccScreenDirect::NewL |
|
730 // ----------------------------------------------------------------------------- |
|
731 // |
|
732 CMccScreenDirect* CMccScreenDirect::NewL( CCamera* aCamera, |
|
733 TPoint aPos, |
|
734 TSize aArea, |
|
735 TInt aIndex, |
|
736 TInt aWindowOrdinalPosition, |
|
737 TInt aWindowOrdinalPriority ) |
|
738 { |
|
739 __CONTROLLER( "CMccScreenDirect::NewL, v2" ) |
|
740 |
|
741 CMccScreenDirect* self = new ( ELeave ) CMccScreenDirect( aCamera, |
|
742 aPos, |
|
743 aArea, |
|
744 aIndex, |
|
745 aWindowOrdinalPosition, |
|
746 aWindowOrdinalPriority ); |
|
747 CleanupStack::PushL( self ); |
|
748 self->ConstructL(); |
|
749 CleanupStack::Pop( self ); |
|
750 |
|
751 __CONTROLLER( "CMccScreenDirect::NewL, exit" ) |
|
752 |
|
753 return self; |
|
754 } |
|
755 |
|
756 // ----------------------------------------------------------------------------- |
|
757 // CMccScreenDirect::~CMccScreenDirect |
|
758 // ----------------------------------------------------------------------------- |
|
759 // |
|
760 CMccScreenDirect::~CMccScreenDirect() |
|
761 { |
|
762 __CONTROLLER( "CMccScreenDirect::~CMccScreenDirect" ) |
|
763 |
|
764 if ( iDirectViewFinder ) |
|
765 { |
|
766 iDirectViewFinder->Release(); |
|
767 iDirectViewFinder = NULL; |
|
768 } |
|
769 |
|
770 __CONTROLLER( "CMccScreenDirect::~CMccScreenDirect, exit" ) |
|
771 } |
|
772 |
|
773 // ----------------------------------------------------------------------------- |
|
774 // CMccScreenDirect::StartL |
|
775 // ----------------------------------------------------------------------------- |
|
776 // |
|
777 void CMccScreenDirect::StartL() |
|
778 { |
|
779 __CONTROLLER( "CMccScreenDirect::StartL" ) |
|
780 |
|
781 if ( iDirectViewFinder && iDirectViewFinder->ViewFinderState() == |
|
782 CCamera::CCameraDirectViewFinder::EViewFinderPause ) |
|
783 { |
|
784 __CONTROLLER( "CMccScreenDirect::StartL, resuming" ) |
|
785 |
|
786 iDirectViewFinder->ResumeViewFinderDirectL(); |
|
787 } |
|
788 else if ( VfStartPossible() ) |
|
789 { |
|
790 __CONTROLLER( "CMccScreenDirect::StartL, starting" ) |
|
791 |
|
792 StartDirectViewFinderL(); |
|
793 } |
|
794 else |
|
795 { |
|
796 // NOP |
|
797 } |
|
798 __CONTROLLER( "CMccScreenDirect::StartL, exit" ) |
|
799 } |
|
800 |
|
801 // ----------------------------------------------------------------------------- |
|
802 // CMccScreenDirect::Stop |
|
803 // ----------------------------------------------------------------------------- |
|
804 // |
|
805 void CMccScreenDirect::Stop() |
|
806 { |
|
807 __CONTROLLER( "CMccScreenDirect::Stop" ) |
|
808 |
|
809 if ( iDirectViewFinder ) |
|
810 { |
|
811 __CONTROLLER( "CMccScreenDirect::Stop, pausing disabled" ) |
|
812 // TBD: pausing disabled temporarily due problems in it |
|
813 TRAP_IGNORE( iDirectViewFinder->PauseViewFinderDirectL() ) |
|
814 } |
|
815 |
|
816 __CONTROLLER( "CMccScreenDirect::Stop, exit" ) |
|
817 } |
|
818 |
|
819 // ----------------------------------------------------------------------------- |
|
820 // CMccScreenDirect::SetCamera |
|
821 // ----------------------------------------------------------------------------- |
|
822 // |
|
823 TInt CMccScreenDirect::SetCamera( CCamera* aCamera ) |
|
824 { |
|
825 CMccScreen::SetCamera( aCamera ); |
|
826 |
|
827 return HandleDirectViewFinder(); |
|
828 } |
|
829 |
|
830 // ----------------------------------------------------------------------------- |
|
831 // CMccScreenDirect::ConstructL |
|
832 // ----------------------------------------------------------------------------- |
|
833 // |
|
834 void CMccScreenDirect::ConstructL() |
|
835 { |
|
836 __CONTROLLER( "CMccScreenDirect::ConstructL" ) |
|
837 |
|
838 CMccScreen::ConstructL(); |
|
839 |
|
840 User::LeaveIfError( HandleDirectViewFinder() ); |
|
841 |
|
842 __CONTROLLER( "CMccScreenDirect::ConstructL, exit" ) |
|
843 } |
|
844 |
|
845 // ----------------------------------------------------------------------------- |
|
846 // CMccScreenDirect::CMccScreenDirect |
|
847 // ----------------------------------------------------------------------------- |
|
848 // |
|
849 CMccScreenDirect::CMccScreenDirect( |
|
850 CCamera* aCamera, |
|
851 TPoint aPos, |
|
852 TSize aArea, |
|
853 TInt aIndex, |
|
854 TInt aWindowOrdinalPosition, |
|
855 TInt aWindowOrdinalPriority ) : |
|
856 CMccScreen( EDirectScreen, aCamera, aPos, aArea, aIndex, |
|
857 aWindowOrdinalPosition, aWindowOrdinalPriority ) |
|
858 { |
|
859 |
|
860 } |
|
861 |
|
862 // ----------------------------------------------------------------------------- |
|
863 // CMccScreenDirect::StartDirectViewFinderL |
|
864 // ----------------------------------------------------------------------------- |
|
865 // |
|
866 void CMccScreenDirect::StartDirectViewFinderL() |
|
867 { |
|
868 if ( VfStartPossible() ) |
|
869 { |
|
870 // Camera may modify the size |
|
871 TSize vfBitmapSize = iArea; |
|
872 __CONTROLLER_INT2( "CMccScreenDirect::StartDirectViewFinderL, size before", |
|
873 vfBitmapSize.iWidth, |
|
874 vfBitmapSize.iHeight ) |
|
875 |
|
876 TPoint point( 0, 0 ); |
|
877 TRect vfRect( point, vfBitmapSize ); |
|
878 iCamera->StartViewFinderDirectL( iRwSession, *iDev, *iRw, vfRect ); |
|
879 |
|
880 __CONTROLLER_INT2( "CMccScreenDirect::StartDirectViewFinderL, size after", |
|
881 vfRect.Width(), |
|
882 vfRect.Height() ) |
|
883 } |
|
884 } |
|
885 |
|
886 // ----------------------------------------------------------------------------- |
|
887 // CMccScreenDirect::HandleDirectViewFinder |
|
888 // ----------------------------------------------------------------------------- |
|
889 // |
|
890 TInt CMccScreenDirect::HandleDirectViewFinder() |
|
891 { |
|
892 TInt err( KErrNone ); |
|
893 if ( iCamera ) |
|
894 { |
|
895 if ( !iDirectViewFinder ) |
|
896 { |
|
897 __CONTROLLER( "CMccScreenDirect::HandleDirectViewFinder, create dvf" ) |
|
898 |
|
899 iDirectViewFinder = static_cast<MCameraDirectViewFinder*>( |
|
900 iCamera->CustomInterface( TUid::Uid( KECamMCameraDirectViewFinderUidValue ) ) ); |
|
901 |
|
902 if ( !iDirectViewFinder ) |
|
903 { |
|
904 err = KErrNotSupported; |
|
905 } |
|
906 __CONTROLLER_INT1( "CMccScreenDirect::HandleDirectViewFinder, err:", err ) |
|
907 } |
|
908 } |
|
909 else if ( iDirectViewFinder ) |
|
910 { |
|
911 __CONTROLLER( "CMccScreenDirect::HandleDirectViewFinder, release dvf" ) |
|
912 iDirectViewFinder->Release(); |
|
913 iDirectViewFinder = NULL; |
|
914 } |
|
915 else |
|
916 { |
|
917 // NOP |
|
918 } |
|
919 return err; |
|
920 } |
|
921 |
|
922 // End of file |
|
923 |