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