mmsharing/livecommsui/lcui/tsrc/mustester/Stubs/mceclientstub/src/mccscreen.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     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 
       
    19 
       
    20 
       
    21 #include <bitstd.h>
       
    22 #include <w32std.h>
       
    23 #include <gdi.h>
       
    24 
       
    25 #include "MccScreen.h"
       
    26 #include "muslogger.h"
       
    27 
       
    28 // EXTERNAL DATA STRUCTURES
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 _LIT(KMccWindowGroupName,"32MccVideoWindow");
       
    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 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CMccScreen::CMccScreen
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CMccScreen* CMccScreen::NewL( 
       
    56     TPoint aPos, 
       
    57     TSize aArea, 
       
    58     TInt aIndex, 
       
    59     TInt aWindowOrdinalPosition,
       
    60 	TInt aWindowOrdinalPriority,
       
    61 	TSize aViewFinderImageSize )
       
    62 	{
       
    63 	CMccScreen* self = new ( ELeave ) CMccScreen( aPos, 
       
    64 	                                              aArea, 
       
    65 	                                              aIndex,
       
    66 	                                              aWindowOrdinalPosition,
       
    67 	                                              aWindowOrdinalPriority );
       
    68 	CleanupStack::PushL( self );
       
    69 	self->ConstructL( aViewFinderImageSize );
       
    70 	CleanupStack::Pop( self );	
       
    71 	return self;
       
    72 	}
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CMccScreen::CMccScreen
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CMccScreen::CMccScreen( 
       
    79     TPoint aPos, 
       
    80     TSize aArea, 
       
    81     TInt aIndex, 
       
    82     TInt aWindowOrdinalPosition,
       
    83 	TInt aWindowOrdinalPriority ) :
       
    84 	iDeviceIndex( aIndex ), 
       
    85 	iPosition( aPos ), 
       
    86 	iArea( aArea ),
       
    87 	iWindowOrdinalPosition( aWindowOrdinalPosition ),
       
    88 	iWindowOrdinalPriority( aWindowOrdinalPriority ),
       
    89 	iAborted( ETrue )
       
    90 	{
       
    91 	}
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CMccScreen::CMccScreen
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CMccScreen::~CMccScreen()
       
    98 	{
       
    99 	MUS_LOG( "CMccScreen::~CMccScreen" )
       
   100 	
       
   101 	DetachFrame(); // Must do bitmap detach before releasing window resources
       
   102 	delete iDirectScreenAccess;
       
   103 	delete iDev;
       
   104 	delete iRw;
       
   105     delete iRwGroup;
       
   106     iRwSession.Close();
       
   107     
       
   108 	MUS_LOG( "CMccScreen::~CMccScreen, exit" )
       
   109 	}
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CMccScreen::CMccScreen
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CMccScreen::ConstructL( TSize aViewFinderImageSize )
       
   116 	{
       
   117 	MUS_LOG( "CMccScreen::ConstructL" )
       
   118     User::LeaveIfError( iRwSession.Connect() );
       
   119 	
       
   120 	// Create window group
       
   121 	TInt groupId = iRwSession.GetFocusWindowGroup();
       
   122     iRwGroup = new (ELeave) RWindowGroup( iRwSession ) ;	
       
   123 	//TInt handle = iRwSession.GetWindowGroupHandle( groupId );
       
   124 
       
   125     MUS_LOG1( "CMccScreen::ConstructL, window ordinal pos", iWindowOrdinalPosition )
       
   126     MUS_LOG1( "CMccScreen::ConstructL, window ordinal priority", iWindowOrdinalPriority )
       
   127     
       
   128     iRwGroup->Construct( groupId, EFalse );
       
   129 	iRwGroup->SetName( KMccWindowGroupName );
       
   130     
       
   131     iRwGroup->SetOrdinalPosition( iWindowOrdinalPosition, iWindowOrdinalPriority );
       
   132          
       
   133     // Create screen device
       
   134 	iDev = new (ELeave) CWsScreenDevice( iRwSession );
       
   135 	iDev->Construct( iDeviceIndex ); 
       
   136 	
       
   137 	TInt currMode = iDev->CurrentScreenMode();
       
   138 	MUS_LOG1( "CMccScreen::ConstructL, screen device mode = %d", currMode )
       
   139 	                   
       
   140 	TPixelsTwipsAndRotation sizeAndRotation;
       
   141     iDev->GetScreenModeSizeAndRotation( currMode, sizeAndRotation );
       
   142 	MUS_LOG2( "CMccScreen::ConstructL, screen device size  %d %d", 
       
   143 	                   sizeAndRotation.iPixelSize.iWidth, 
       
   144 	                   sizeAndRotation.iPixelSize.iHeight )
       
   145 
       
   146 	MUS_LOG1( "CMccScreen::ConstructL, screen device orientation %d", 
       
   147 	                   sizeAndRotation.iRotation )
       
   148 	
       
   149 	// Create window
       
   150 	iRw = new (ELeave) RWindow( iRwSession );
       
   151 	
       
   152 	iRw->Construct( *iRwGroup, (TUint32) this + 2 );
       
   153     
       
   154     MUS_LOG2( "CMccScreen::ConstructL, window pos %d %d", iPosition.iX, iPosition.iY )
       
   155 	MUS_LOG2( "CMccScreen::ConstructL, window size %d %d", iArea.iWidth, iArea.iHeight )
       
   156 
       
   157     iRw->SetPosition( iPosition );
       
   158 	iRw->SetBackgroundColor( KRgbBlack );
       
   159     iRw->SetSize( iArea );    
       
   160     iRw->SetOrdinalPosition( iWindowOrdinalPosition );
       
   161     iRw->Activate();
       
   162     iRwSession.Flush();
       
   163 	
       
   164 	// Create direct screen access                                	
       
   165 	iDirectScreenAccess = CDirectScreenAccess::NewL( iRwSession, *iDev, *iRw, *this );   
       
   166 	
       
   167 	UpdateViewFinderArea( aViewFinderImageSize );
       
   168 	
       
   169 	MUS_LOG2( "CMccScreen::ConstructL, viewfinder pos %d %d", 
       
   170 	                   iViewFinderImageRect.iTl.iX, iViewFinderImageRect.iTl.iY )
       
   171 	MUS_LOG2( "CMccScreen::ConstructL, viewfinder size %d %d", 
       
   172 	                   iViewFinderImageRect.Width(), iViewFinderImageRect.Height() )
       
   173 	
       
   174 	MUS_LOG( "CMccScreen::ConstructL, exit" )
       
   175 	}
       
   176     
       
   177 // -----------------------------------------------------------------------------
       
   178 // CMccScreen::CMccScreen
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CMccScreen::StartL()
       
   182 	{
       
   183 	MUS_LOG( "CMccScreen::StartL" )	
       
   184 	
       
   185 	iAborted = EFalse;
       
   186 	
       
   187 	iDirectScreenAccess->StartL();
       
   188 	iGc = iDirectScreenAccess->Gc();	
       
   189 	iFbsDev = iDirectScreenAccess->ScreenDevice();
       
   190 	iRegion = iDirectScreenAccess->DrawingRegion();		
       
   191 
       
   192 #ifdef __MCC_CONTROLLER	
       
   193 	if ( iRegion && !iRegion->IsEmpty() )
       
   194 	    {
       
   195         for ( TInt i = 0; i < iRegion->Count(); i++ )
       
   196             {
       
   197             const TRect& regionRect = (*iRegion)[ i ];
       
   198             MUS_LOG_INT2( "CMccScreen::StartL, rect tl", regionRect.iTl.iX, regionRect.iTl.iY )
       
   199             MUS_LOG_INT2( "CMccScreen::StartL, rect br", regionRect.iBr.iX, regionRect.iBr.iY )
       
   200             }
       
   201 	    }
       
   202 #endif	        
       
   203 
       
   204     iGc->SetClippingRegion( iRegion );
       
   205     
       
   206     // Fill with black areas which are not covered by viewfinder image.
       
   207     // If viewfinder image has not been yet received and drawn, fill whole area.
       
   208     //
       
   209     iGc->SetBrushColor( KRgbBlack );
       
   210     iGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   211     
       
   212     if ( !iFirstImageDrawn )
       
   213         {
       
   214         // Whole area
       
   215         TPoint pointTl( 0, 0 );
       
   216         TRect rect( pointTl, iArea );
       
   217         iGc->DrawRect( rect );
       
   218         }
       
   219     else
       
   220         {
       
   221         // Upper area
       
   222         TPoint pointTl( 0, 0 );
       
   223         TPoint pointBr( iArea.iWidth, iViewFinderImageRect.iTl.iY );
       
   224         TRect rect( pointTl, pointBr );
       
   225         iGc->DrawRect( rect );
       
   226 
       
   227         // Lower area
       
   228         pointTl.SetXY( 0, iViewFinderImageRect.iBr.iY );
       
   229         pointBr.SetXY( iArea.iWidth, iArea.iHeight );
       
   230         rect.SetRect( pointTl, pointBr );
       
   231         iGc->DrawRect( rect );
       
   232         
       
   233         // Left area
       
   234         pointTl.SetXY( 0, iViewFinderImageRect.iTl.iY );
       
   235         pointBr.SetXY( iViewFinderImageRect.iTl.iX, iViewFinderImageRect.iBr.iY );
       
   236         rect.SetRect( pointTl, pointBr );
       
   237         iGc->DrawRect( rect );
       
   238         
       
   239         // Right area
       
   240         pointTl.SetXY( iViewFinderImageRect.iBr.iX, iViewFinderImageRect.iTl.iY );
       
   241         pointBr.SetXY( iArea.iWidth, iViewFinderImageRect.iBr.iY );
       
   242         rect.SetRect( pointTl, pointBr );
       
   243         iGc->DrawRect( rect );
       
   244         }
       
   245         
       
   246     if ( iAttachedFrame )
       
   247         {
       
   248         MUS_LOG( "CMccScreen::StartL, draw attached frame" )
       
   249         
       
   250         TSize viewFinderImageSize = iAttachedFrame->SizeInPixels();
       
   251     	
       
   252     	TPoint corner = UpdateViewFinderArea( viewFinderImageSize );
       
   253         
       
   254         iGc->BitBlt( corner, iAttachedFrame );
       
   255         }
       
   256         
       
   257     DoScreenDeviceUpdate();
       
   258     
       
   259     iGc->SetBrushStyle( CGraphicsContext::ENullBrush );
       
   260         		
       
   261 	MUS_LOG( "CMccScreen::StartL, exit" )
       
   262 	}
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CMccScreen::CMccScreen
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 void CMccScreen::Stop()
       
   269 	{
       
   270 	MUS_LOG( "CMccScreen::Stop" )
       
   271 	iDirectScreenAccess->Cancel();
       
   272 	MUS_LOG( "CMccScreen::Stop, exit" )	
       
   273 	}
       
   274 	
       
   275 // -----------------------------------------------------------------------------
       
   276 // CMccScreen::CMccScreen
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 void CMccScreen::Restart( RDirectScreenAccess::TTerminationReasons /*aReason*/ )
       
   280 	{
       
   281 	MUS_LOG( "CMccScreen::Restart" )	
       
   282 	
       
   283 	TRAP_IGNORE( StartL() );
       
   284 	}
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CMccScreen::CMccScreen
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CMccScreen::AbortNow( RDirectScreenAccess::TTerminationReasons /*aReason*/ )
       
   291 	{
       
   292 	MUS_LOG( "CMccScreen::AbortNow" )	
       
   293 	iDirectScreenAccess->Cancel();
       
   294 	
       
   295 	iAborted = ETrue;
       
   296 	}
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CMccScreen::CMccScreen
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 void CMccScreen::Draw( CFbsBitmap& aFrame )
       
   303 	{
       
   304 	// When frame draw is requested, attached frame is not anymore drawn
       
   305 	DetachFrame();
       
   306 	
       
   307 	DoDraw( aFrame );
       
   308 	}
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CMccScreen::AttachFrameL
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CMccScreen::AttachFrameL( CFbsBitmap* aFrame )
       
   315     {
       
   316     MUS_LOG( "CMccScreen::AttachFrameL" )	
       
   317     
       
   318     __ASSERT_ALWAYS( aFrame, User::Leave( KErrArgument ) );
       
   319     
       
   320     DetachFrame();
       
   321     
       
   322     iAttachedFrame = aFrame;
       
   323     
       
   324     DoDraw( *iAttachedFrame );
       
   325 
       
   326     MUS_LOG( "CMccScreen::AttachFrameL, exit" )
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CMccScreen::DetachFrame
       
   331 // -----------------------------------------------------------------------------
       
   332 //		
       
   333 void CMccScreen::DetachFrame()
       
   334     {	
       
   335     if ( iAttachedFrame )
       
   336         {
       
   337         MUS_LOG( "CMccScreen::DetachFrame, detaching" )
       
   338         iAttachedFrame->Reset();
       
   339         delete iAttachedFrame;
       
   340         }
       
   341         
       
   342     iAttachedFrame = NULL;
       
   343     }
       
   344     
       
   345 // -----------------------------------------------------------------------------
       
   346 // CMccScreen::UpdateViewFinderArea
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 TPoint CMccScreen::UpdateViewFinderArea( TSize aViewFinderImageSize )
       
   350     {
       
   351     TPoint corner( 0, 0 );
       
   352 	if ( aViewFinderImageSize.iWidth < iArea.iWidth )
       
   353 	    {
       
   354 	    // Divide the subtraction by two (i.e. do centering)
       
   355 	    corner.iX = ( iArea.iWidth - aViewFinderImageSize.iWidth ) >> 1;
       
   356 	    }
       
   357 	    
       
   358     if ( aViewFinderImageSize.iHeight < iArea.iHeight )
       
   359 	    {
       
   360 	    // Divide the subtraction by two (i.e. do centering)
       
   361 	    corner.iY = ( iArea.iHeight - aViewFinderImageSize.iHeight ) >> 1;
       
   362 	    }
       
   363 	    
       
   364 	iViewFinderImageRect = TRect( corner, aViewFinderImageSize );
       
   365 	
       
   366 	return corner;
       
   367     }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // CMccScreen::DoDraw
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 void CMccScreen::DoDraw( CFbsBitmap& aFrame )
       
   374     {	
       
   375     if ( !iAborted && iGc )
       
   376         {
       
   377         iFirstImageDrawn = ETrue;
       
   378         	
       
   379        	TSize viewFinderImageSize = aFrame.SizeInPixels();
       
   380       
       
   381     	TPoint corner = UpdateViewFinderArea( viewFinderImageSize );
       
   382 
       
   383         iGc->BitBlt( corner, &aFrame );
       
   384         
       
   385         DoScreenDeviceUpdate();
       
   386         }
       
   387     }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // CMccScreen::DoScreenDeviceUpdate
       
   391 // -----------------------------------------------------------------------------
       
   392 //
       
   393 void CMccScreen::DoScreenDeviceUpdate()
       
   394     {
       
   395     if ( iFbsDev )
       
   396         {
       
   397         iFbsDev->Update();
       
   398         }
       
   399     }
       
   400     
       
   401 // End of file
       
   402