lafagnosticuifoundation/graphicseffects/ClientSrc/transitionparticipant.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // GFXTRANSEFFECT.CPP
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "TransitionParticipant.h"
       
    19 #include <graphics/remotegc.h>
       
    20 
       
    21 //----------------
       
    22 // Utility function
       
    23 //----------------
       
    24 //#define RECURSIVE_GC_SETTING 
       
    25 
       
    26 #ifdef RECURSIVE_GC_SETTING
       
    27 
       
    28 void DrawControl(const CCoeControl *aControl, CTransitionParticipant::TCaptureType aCaptureType, CRemoteGc* aGc)
       
    29 	{
       
    30 	const TRect rect = aControl->Rect();
       
    31 	if(aControl->Background())
       
    32 		{
       
    33 		aControl->DrawBackground(rect);
       
    34 		}
       
    35 	aControl->DrawForeground(rect);
       
    36 	if(aCaptureType == CTransitionParticipant::EDeep)
       
    37 		{
       
    38 		
       
    39 		TInt count = aControl->CountComponentControls();
       
    40 		for(TInt i = 0 ; i < count; i++)
       
    41 			{
       
    42 			CCoeControl *child = aControl->ComponentControl(i);
       
    43 			if(child->OwnsWindow())
       
    44 			    child->SetGc(aGc); //Set gc for each WO child control.
       
    45 			//Is it correct to check if windowowning? maybe not... :)
       
    46 			if(child->IsVisible()/* && !child->OwnsWindow()*/)
       
    47 				{
       
    48 				DrawControl(child, aCaptureType, aGc);
       
    49 				}
       
    50 			}
       
    51 		}
       
    52 	}
       
    53 
       
    54 #else
       
    55 void DrawControl(const CCoeControl *aControl, CTransitionParticipant::TCaptureType aCaptureType)
       
    56 	{
       
    57 	const TRect rect = aControl->Rect();
       
    58 	if(aControl->Background())
       
    59 		{
       
    60 		aControl->DrawBackground(rect);
       
    61 		}
       
    62 	aControl->DrawForeground(rect);
       
    63 	if(aCaptureType == CTransitionParticipant::EDeep)
       
    64 		{
       
    65 		
       
    66 		TInt count = aControl->CountComponentControls();
       
    67 		for(TInt i = 0 ; i < count; i++)
       
    68 			{
       
    69 			CCoeControl *child = aControl->ComponentControl(i);
       
    70 			//Is it correct to check if windowowning?
       
    71 			if(child->IsVisible() && !child->OwnsWindow())
       
    72 				{
       
    73 				DrawControl(child, aCaptureType);
       
    74 				}
       
    75 			}
       
    76 		}
       
    77 	}
       
    78 #endif
       
    79 
       
    80 void ResetRemoteGc(const CCoeControl* aControl)
       
    81     {
       
    82     aControl->SetGc(NULL);
       
    83 #ifdef RECURSIVE_GC_SETTING
       
    84     for(TInt i = aControl->CountComponentControls() - 1; i >= 0; i--) 
       
    85         {
       
    86         ResetRemoteGc(aControl->ComponentControl(i));
       
    87         }
       
    88 #endif
       
    89     }
       
    90 
       
    91 
       
    92 
       
    93 TInt DrawUptoControlRec(CWindowGc& aGc, const CCoeControl* aCurrent, const TRect& aRect,const CCoeControl* aUpto)
       
    94 	{
       
    95 	TInt err = KErrNone;
       
    96 	if(aCurrent != aUpto)
       
    97 		{
       
    98 		CWindowGc* oldGc = aCurrent->GetGc();
       
    99 		err = aCurrent->SetGc(&aGc);
       
   100 		if(!err)
       
   101 			{
       
   102 			if(aCurrent->Background())
       
   103 				{
       
   104 				//if we have a background, draw it
       
   105 				aCurrent->DrawBackground(aRect);
       
   106 				}
       
   107 			else if(aCurrent->OwnsWindow())
       
   108 				{
       
   109 				// try to find background
       
   110 				const CCoeControl* bgOwningParent = aCurrent;
       
   111 				do
       
   112 					{
       
   113 					if(const MCoeControlBackground* bg = bgOwningParent->Background())
       
   114 						{
       
   115 						bg->Draw(aGc,*aCurrent,aRect);
       
   116 						break; // mission complete
       
   117 						}
       
   118 					bgOwningParent = bgOwningParent->Parent();
       
   119 					} while(bgOwningParent);
       
   120 				}
       
   121 			//draw foreground
       
   122 			aCurrent->DrawForeground(aRect);
       
   123 			
       
   124 			// draw component controls
       
   125 			for(TInt i=0; (i < aCurrent->CountComponentControls()) && !err; i++)
       
   126 				{
       
   127 				const CCoeControl* child = aCurrent->ComponentControl(i);
       
   128 				if(child->IsVisible() && !child->OwnsWindow())
       
   129 					{
       
   130 					TRect childRect = child->Rect();
       
   131 					if(childRect.Intersects(aRect))
       
   132 						{
       
   133 						childRect.Intersection(aRect);
       
   134 						err = DrawUptoControlRec(aGc,child,childRect,aUpto);
       
   135 						}
       
   136 					}
       
   137 				}
       
   138 			//set back the old gc
       
   139 			err = const_cast<CCoeControl*>(aCurrent)->SetGc(oldGc);
       
   140 			}
       
   141 		}
       
   142 	return err;
       
   143 	}
       
   144 
       
   145 TInt DrawUptoControl(CWindowGc& aGc,const CCoeControl* aControl)
       
   146 	{
       
   147 	const CCoeControl* aWindowOwningParent = aControl;
       
   148 	//find the windowowing parent
       
   149 	while(!aWindowOwningParent->OwnsWindow() && aWindowOwningParent->Parent())
       
   150 		{
       
   151 		aWindowOwningParent = aWindowOwningParent->Parent();
       
   152 		}
       
   153 	return DrawUptoControlRec(aGc, aWindowOwningParent, aControl->Rect(), aControl);
       
   154 	}
       
   155 
       
   156 
       
   157 
       
   158 //----------------
       
   159 // Construct/Destruct
       
   160 //----------------
       
   161 CTransitionParticipant *CTransitionParticipant::New(const CCoeControl *aKey, 
       
   162 													CTransitionControl *aTransControl,
       
   163 													TUint aFlags)
       
   164 	{
       
   165 	CTransitionParticipant *participant = new CTransitionParticipant(aTransControl);
       
   166 	if(!participant)
       
   167 		{
       
   168 		return NULL;
       
   169 		}
       
   170 	if(NULL == (participant->iData = new CParticipantData()))
       
   171 		{
       
   172 		delete participant;
       
   173 		return NULL;
       
   174 		}
       
   175 	participant->iData->iKey = aKey;
       
   176 	participant->iData->iBeginZ = -1;
       
   177 	participant->iData->iEndZ = -1;
       
   178 	participant->iData->iBeginCapture = 0;
       
   179 	participant->iData->iEndCapture = 0;
       
   180 	participant->iData->iLayerType = TUid::Uid(0);
       
   181 	participant->iData->iFlags = aFlags;
       
   182 	//create remote gc
       
   183 	TRAPD(err, participant->iRemoteGc = CRemoteGc::NewL(aTransControl->ScreenDevice()));
       
   184 	if(err < KErrNone || !(participant->iRemoteGc))
       
   185 		{
       
   186 		delete participant;
       
   187 		return NULL;
       
   188 		}
       
   189 	participant->iRemoteGc->SetCommandBufferObserver(participant);
       
   190 	
       
   191 	return participant;
       
   192 	}
       
   193 
       
   194 CTransitionParticipant::CTransitionParticipant(CTransitionControl *aTransControl)
       
   195 	{
       
   196 	iTransControl = aTransControl;
       
   197 	iInvalidated = EFalse;
       
   198 	iCaptureState = ENoCapture;
       
   199 	iCaptureEndCalled = EFalse;
       
   200 	iCoordRefBegin = CTransitionParticipant::EWindowOwning;
       
   201 	iCoordRefEnd = CTransitionParticipant::EWindowOwning;
       
   202 	}
       
   203 
       
   204 CTransitionParticipant::~CTransitionParticipant()
       
   205 	{ 		
       
   206 	if(iData)
       
   207 		{
       
   208 		ResetRemoteGc(Control());
       
   209 		delete iData;
       
   210 		}
       
   211 
       
   212 	if(iRemoteGc)
       
   213 		{
       
   214 		delete iRemoteGc;
       
   215 		}
       
   216 	}
       
   217 
       
   218 
       
   219 //----------------
       
   220 // Capture
       
   221 //----------------
       
   222 TInt CTransitionParticipant::CaptureBegin(const CCoeControl *aControl, TCaptureType aCaptureType, TInt aZDepth)
       
   223 	{
       
   224 	if(iTransControl->Policy() == ESupported)
       
   225 		{	
       
   226 		//capture begin
       
   227 		iRemoteGc->ResetCommandBuffer();
       
   228 		if(KErrNone != aControl->SetGc(iRemoteGc))
       
   229 			{
       
   230 			return KErrAbort;
       
   231 			}
       
   232 		iCapturedGc = ETrue;
       
   233 		iInCapture = ETrue;
       
   234 		iRemoteGc->BeginDraw(aControl->Rect());
       
   235 #ifdef RECURSIVE_GC_SETTING
       
   236         DrawControl(aControl, aCaptureType, iRemoteGc);
       
   237 #else
       
   238 		DrawControl(aControl, aCaptureType);
       
   239 #endif		
       
   240 		iRemoteGc->EndDraw();
       
   241 		iInCapture = EFalse;	
       
   242 		if(NULL == (iData->iBeginCapture = new RWsGraphicMsgBuf()))
       
   243 			{
       
   244             ResetRemoteGc(Control());
       
   245 			return KErrAbort;
       
   246 			}
       
   247 			
       
   248 		TRAPD(err, iRemoteGc->ExternalizeL(*(iData->iBeginCapture), ETrue));
       
   249 		if(err < KErrNone)
       
   250 			{
       
   251             ResetRemoteGc(Control());
       
   252 			return err;
       
   253 			}
       
   254 			
       
   255 		iRemoteGc->ResetCommandBuffer();
       
   256 	
       
   257 		}
       
   258 		
       
   259 	//capture begin rect
       
   260 	iData->iBeginRect = aControl->Rect();
       
   261 	iCaptureState = (TCaptureState)(iCaptureState | EBeginCapture);
       
   262 	//set z depth
       
   263 	iData->iBeginZ = aZDepth;
       
   264 	return KErrNone;
       
   265 	}
       
   266 
       
   267 TInt CTransitionParticipant::CaptureEnd(const CCoeControl *aControl, TCaptureType aCaptureType, TInt aZDepth)
       
   268 	{
       
   269 	if(iTransControl->Policy() == ESupported)
       
   270 		{
       
   271 		// check if we need to capture image
       
   272 		if(!HaveImageCapture() || Invalidated())
       
   273 			{
       
   274 			// Capture End image
       
   275 			iRemoteGc->ResetCommandBuffer();
       
   276 			if(KErrNone != aControl->SetGc(iRemoteGc))
       
   277 				{
       
   278 				return KErrAbort;
       
   279 				}
       
   280 			iCapturedGc = ETrue;	
       
   281 			iInCapture = ETrue;
       
   282 			iRemoteGc->BeginDraw(aControl->Rect());
       
   283 #ifdef RECURSIVE_GC_SETTING
       
   284             DrawControl(aControl, aCaptureType, iRemoteGc);
       
   285 #else
       
   286 			DrawControl(aControl, aCaptureType);
       
   287 #endif		
       
   288 			iRemoteGc->EndDraw();
       
   289 			iInCapture = EFalse;
       
   290 			if(NULL == (iData->iEndCapture = new RWsGraphicMsgBuf()))
       
   291 				{
       
   292                 ResetRemoteGc(Control());
       
   293 				return KErrNoMemory;
       
   294 				}
       
   295 			
       
   296 			TRAPD(err, iRemoteGc->ExternalizeL(*(iData->iEndCapture), ETrue));
       
   297 			if(err < KErrNone)
       
   298 				{
       
   299                 ResetRemoteGc(Control());
       
   300 				return err;
       
   301 				}
       
   302 			}
       
   303 		else if(iCommandsReceived)
       
   304 			{
       
   305 			// Draw commands received between begin and end.
       
   306 			if(NULL == (iData->iEndCapture = new RWsGraphicMsgBuf()))
       
   307 				{
       
   308                 ResetRemoteGc(Control());
       
   309 				return KErrNoMemory;
       
   310 				}
       
   311 			
       
   312 			TRAPD(err, iRemoteGc->ExternalizeL(*(iData->iEndCapture), ETrue));
       
   313 			if(err < KErrNone)
       
   314 				{
       
   315                 ResetRemoteGc(Control());
       
   316 				return err;
       
   317 				}
       
   318 			}
       
   319 		else
       
   320 			{
       
   321 			iData->iEndCapture = iData->iBeginCapture;
       
   322 			}
       
   323 		
       
   324 		iRemoteGc->ResetCommandBuffer();
       
   325 		}
       
   326 	//check if we need to capture end rect
       
   327 	if(!(iCaptureState & EEndCapture))
       
   328 		{
       
   329 		iData->iEndRect = aControl->Rect();
       
   330 		iCaptureState = (TCaptureState) (iCaptureState | EEndCapture);
       
   331 		}
       
   332 	iData->iEndZ = aZDepth;
       
   333 	iCaptureEndCalled = ETrue;
       
   334 	return KErrNone;
       
   335 	}
       
   336 
       
   337 //----------------
       
   338 // Demarcations
       
   339 //----------------
       
   340 
       
   341 void CTransitionParticipant::SetBeginDemarcation(TRect& aBeginRect, TCoordinateRef aCoordRef)
       
   342 	{
       
   343 	iCoordRefBegin = aCoordRef;
       
   344 	iData->iBeginRect = aBeginRect;
       
   345 	iCaptureState = (TCaptureState)(iCaptureState | EBeginCapture);
       
   346 	}
       
   347 	
       
   348 void CTransitionParticipant::SetEndDemarcation(TRect& aEndRect, TCoordinateRef aCoordRef)
       
   349 	{
       
   350 	iCoordRefEnd = aCoordRef;
       
   351 	iData->iEndRect = aEndRect;
       
   352 	iCaptureState = (TCaptureState)(iCaptureState | EEndCapture);
       
   353 	}
       
   354 
       
   355 void CTransitionParticipant::ModifyCoordinates(TPoint& aBeginRef, TPoint& aEndRef)
       
   356 	{
       
   357 	if(iCoordRefBegin == CTransitionParticipant::EScreen)
       
   358 		{
       
   359 		iData->iBeginRect.iTl-=aBeginRef;
       
   360 		iData->iBeginRect.iBr-=aBeginRef;
       
   361 		}
       
   362 	if(iCoordRefEnd == CTransitionParticipant::EScreen)
       
   363 		{
       
   364 		iData->iEndRect.iTl-=aEndRef;
       
   365 		iData->iEndRect.iBr-=aEndRef;
       
   366 		}
       
   367 	}
       
   368 
       
   369 //----------------
       
   370 // MCommandBufferObserver functions
       
   371 //----------------
       
   372 
       
   373 void CTransitionParticipant::CommandBufferUpdated(const TRect& aDrawRect, const TRect& aBoundingRect)
       
   374 	{
       
   375 	if(!iInCapture) 
       
   376 		{
       
   377 		if(!iCaptureEndCalled)
       
   378 			{
       
   379 			iCommandsReceived = ETrue;
       
   380 			}
       
   381 		else if(iListensForUpdates)
       
   382 			{
       
   383 			RWsGraphicMsgBuf* commandbuffer = new RWsGraphicMsgBuf;
       
   384 			if(commandbuffer) 
       
   385 				{
       
   386 				TRAPD(err, iRemoteGc->ExternalizeL(*(commandbuffer), ETrue));
       
   387 				if(err == KErrNone)
       
   388 					{
       
   389 					iTransControl->ParticipantUpdated(this, commandbuffer, aDrawRect, aBoundingRect);
       
   390 					}
       
   391 			    commandbuffer->Close();
       
   392 				delete commandbuffer;
       
   393 				}
       
   394 			}
       
   395 		}
       
   396 	}