graphics/bitgdi/src/T_DataFbsScreenDevice.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 //
       
     2 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 // All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the License "Symbian Foundation License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 //
       
     9 // Initial Contributors:
       
    10 // Nokia Corporation - initial contribution.
       
    11 //
       
    12 // Contributors:
       
    13 //
       
    14 // Description:
       
    15 //
       
    16 
       
    17 //	User includes
       
    18 #include "T_DataFbsScreenDevice.h"
       
    19 #include "T_GraphicsUtil.h"
       
    20 
       
    21 /*@{*/
       
    22 //Commands
       
    23 _LIT(KCmdNewL,						"NewL");
       
    24 _LIT(KCmdDestructor,				"~");
       
    25 
       
    26 _LIT(KCmdChangeScreenDevice,		"ChangeScreenDevice");
       
    27 _LIT(KCmdDrawSpriteBegin,		 	"DrawSpriteBegin");
       
    28 _LIT(KCmdDrawSpriteEnd,		 		"DrawSpriteEnd");
       
    29 _LIT(KCmdHardwareBitmap,		 	"HardwareBitmap");
       
    30 _LIT(KCmdScreenNo,		 			"ScreenNo");
       
    31 _LIT(KCmdSetAutoUpdate,		 		"SetAutoUpdate");
       
    32 _LIT(KCmdUpdate,           			"Update");
       
    33 _LIT(KCmdCancelSprite,				"CancelSprite");
       
    34 _LIT(KCmdHideSprite,		 		"HideSprite");
       
    35 _LIT(KCmdShowSprite,		 		"ShowSprite");
       
    36 
       
    37 _LIT(KCmdDisown,           			"disown");
       
    38 
       
    39 //Fields
       
    40 _LIT(KFldExpected,					"expected");
       
    41 _LIT(KLibName,						"libname");
       
    42 _LIT(KScreenNumber,					"screen_number");
       
    43 _LIT(KRgbColorRed,					"rgb_red");
       
    44 _LIT(KRgbColorGreen,				"rgb_green");
       
    45 _LIT(KRgbColorBlue,					"rgb_blue");
       
    46 _LIT(KDisplayMode,					"displaymode");
       
    47 _LIT(KAutoUpdate,					"autoupdate");
       
    48 _LIT(KRegion,						"region");	
       
    49 _LIT(KFbsScreenDevice, 				"FbsScrDevName");
       
    50 _LIT(KFldRect,						"rect");
       
    51 _LIT(KFldRegion,					"region");
       
    52 _LIT(KSpriteBase,					"spritebase");
       
    53 
       
    54 //Logging
       
    55 _LIT(KLogMissingParameter,			"Missing parameter '%S'");
       
    56 
       
    57 /*@}*/
       
    58 /**
       
    59 * Two phase constructor
       
    60 */
       
    61 CT_DataFbsScreenDevice* CT_DataFbsScreenDevice::NewL()
       
    62 	{
       
    63 	CT_DataFbsScreenDevice*	ret = new (ELeave) CT_DataFbsScreenDevice();
       
    64 	CleanupStack::PushL(ret);
       
    65 	ret->ConstructL();
       
    66 	CleanupStack::Pop(ret);
       
    67 	return ret;
       
    68 	}
       
    69 
       
    70 /**
       
    71 * Protected constructor. First phase construction
       
    72 */
       
    73 CT_DataFbsScreenDevice::CT_DataFbsScreenDevice()
       
    74 :	CT_DataFbsDevice()
       
    75 ,	iFbsScreenDevice(NULL)
       
    76 	{
       
    77 	}
       
    78 
       
    79 /**
       
    80 * Protected second phase construction
       
    81 */
       
    82 void CT_DataFbsScreenDevice::ConstructL()
       
    83 	{
       
    84 	}
       
    85 
       
    86 /**
       
    87  * Set the object that the data wraps
       
    88  *
       
    89  * @param    aObject object that the wrapper is testing
       
    90  *
       
    91  */
       
    92 void CT_DataFbsScreenDevice::SetObjectL(TAny* aAny)
       
    93 	{
       
    94 	DestroyData();
       
    95 	iFbsScreenDevice = static_cast<CFbsScreenDevice*> (aAny);
       
    96 	}
       
    97 
       
    98 void CT_DataFbsScreenDevice::DisownObjectL()
       
    99 	{
       
   100 	iFbsScreenDevice = NULL;
       
   101 	}
       
   102 
       
   103 /**
       
   104 * Destructor. 
       
   105 */
       
   106 CT_DataFbsScreenDevice::~CT_DataFbsScreenDevice()
       
   107 	{
       
   108 	DestroyData();
       
   109 	}
       
   110 
       
   111 void CT_DataFbsScreenDevice::DestroyData()
       
   112 	{
       
   113 	delete iFbsScreenDevice;
       
   114 	iFbsScreenDevice=NULL;
       
   115 	}
       
   116 
       
   117 MGraphicsDeviceMap* CT_DataFbsScreenDevice::GetGraphicsDeviceMap() const
       
   118 	{
       
   119 	return iFbsScreenDevice;
       
   120 	}
       
   121 
       
   122 CGraphicsDevice* CT_DataFbsScreenDevice::GetGraphicsDevice() const
       
   123 	{
       
   124 	return iFbsScreenDevice;
       
   125 	}
       
   126 
       
   127 CBitmapDevice* CT_DataFbsScreenDevice::GetBitmapDevice() const
       
   128 	{
       
   129 	return iFbsScreenDevice;
       
   130 	}
       
   131 
       
   132 CFbsDevice* CT_DataFbsScreenDevice::GetFbsDevice() const
       
   133 	{
       
   134 	return iFbsScreenDevice;
       
   135 	}
       
   136 
       
   137 /**
       
   138 * Return a pointer to the object that the data wraps
       
   139 *
       
   140 * @return pointer to the object that the data wraps
       
   141 */
       
   142 TAny* CT_DataFbsScreenDevice::GetObject()
       
   143 	{
       
   144 	return iFbsScreenDevice;
       
   145 	}
       
   146 
       
   147 /**
       
   148 * Process a command read from the ini file
       
   149 *
       
   150 * @param aDataWrapper	test step requiring command to be processed
       
   151 * @param aCommand	the command to process
       
   152 * @param aSection		the entry in the ini file requiring the command to be processed
       
   153 *
       
   154 * @return ETrue if the command is processed
       
   155 */
       
   156 TBool CT_DataFbsScreenDevice::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   157 	{
       
   158 	/* Another work package will complete the implement of this */
       
   159 	TBool	retVal = ETrue;
       
   160 
       
   161 	if ( aCommand == KCmdNewL )
       
   162 		{
       
   163 		DoCmdNew(aSection);
       
   164 		}
       
   165 	else if (aCommand == KCmdDestructor)
       
   166 		{
       
   167 		DoCmdDestructor();
       
   168 		}
       
   169 	else if (aCommand == KCmdChangeScreenDevice)
       
   170 		{
       
   171 		DoCmdChangeScreenDeviceL(aSection);
       
   172 		}
       
   173 	else if (aCommand == KCmdDrawSpriteBegin)
       
   174 		{
       
   175 		DoCmdDrawSpriteBegin();
       
   176 		}
       
   177 	else if (aCommand == KCmdDrawSpriteEnd)
       
   178 		{
       
   179 		DoCmdDrawSpriteEnd();
       
   180 		}
       
   181 	else if (aCommand == KCmdHardwareBitmap)
       
   182 		{
       
   183 		DoCmdHardwareBitmap();
       
   184 		}
       
   185 	else if (aCommand == KCmdScreenNo)
       
   186 		{
       
   187 		DoCmdScreenNo(aSection);
       
   188 		}
       
   189 	else if (aCommand == KCmdSetAutoUpdate)
       
   190 		{
       
   191 		DoCmdSetAutoUpdate(aSection);
       
   192 		}
       
   193 	else if (aCommand == KCmdUpdate)
       
   194 		{
       
   195 		DoCmdUpdateL(aSection);
       
   196 		}
       
   197 	else if (aCommand == KCmdCancelSprite)
       
   198 		{
       
   199 		DoCmdCancelSprite();
       
   200 		}
       
   201 	else if (aCommand == KCmdHideSprite)
       
   202 		{
       
   203 		DoCmdHideSpriteL(aSection);
       
   204 		}
       
   205 	else if (aCommand == KCmdShowSprite)
       
   206 		{
       
   207 		DoCmdShowSpriteL(aSection);
       
   208 		}
       
   209 	else if (aCommand == KCmdDisown)
       
   210 		{
       
   211 		DisownObjectL();
       
   212 		}
       
   213 	else
       
   214 		{
       
   215 		retVal = CT_DataFbsDevice::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
       
   216 		}
       
   217 
       
   218 	return retVal;
       
   219 	}
       
   220 
       
   221 void CT_DataFbsScreenDevice::DoCmdNew(const TDesC& aSection)
       
   222 	{
       
   223 	DestroyData();
       
   224 
       
   225 	// get display mode from parameters
       
   226 	TDisplayMode	displayMode=ENone;
       
   227 	TBool			hasDisplayMode=CT_GraphicsUtil::ReadDisplayMode(*this, aSection, KDisplayMode(), displayMode);
       
   228 
       
   229 	// get lib name from parameters
       
   230 
       
   231 	TPtrC	libName;
       
   232 	TBool	hasLibName=GetStringFromConfig(aSection, KLibName(), libName);
       
   233 
       
   234 	TBool	useRgb = EFalse;
       
   235 
       
   236 	TInt	red = 0;
       
   237 	if(GetIntFromConfig(aSection, KRgbColorRed(), red))
       
   238 		{
       
   239 		useRgb=ETrue;
       
   240 		}
       
   241 
       
   242 	TInt	green = 0;
       
   243 	if(GetIntFromConfig(aSection, KRgbColorGreen(), green))
       
   244 		{
       
   245 		useRgb=ETrue;
       
   246 		}
       
   247 
       
   248 	TInt	blue = 0;
       
   249 	if(GetIntFromConfig(aSection, KRgbColorBlue(), blue))
       
   250 		{
       
   251 		useRgb = ETrue;
       
   252 		}
       
   253 
       
   254 	// get screen number from parameters
       
   255 	TInt	screenNumber = 0;
       
   256 	GetIntFromConfig(aSection, KScreenNumber(), screenNumber);
       
   257 
       
   258 	TInt	err=KErrNone;
       
   259 	if ( !hasDisplayMode )
       
   260 		{
       
   261 		//	Find the best display mode
       
   262 		for ( TDisplayMode testMode=TDisplayMode(ENone+1); testMode<EColorLast; testMode=TDisplayMode(testMode+1) )
       
   263 			{
       
   264 			if ( hasLibName ) // if lib name is given
       
   265 				{		
       
   266 				if ( useRgb )
       
   267 					{
       
   268 					TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(libName, testMode, TRgb(red, green, blue)));
       
   269 					}
       
   270 				else
       
   271 					{
       
   272 					TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(libName, testMode));
       
   273 					}
       
   274 				}
       
   275 			else // if lib name is not given
       
   276 				{		
       
   277 				TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(screenNumber, testMode));
       
   278 				}
       
   279 
       
   280 			//	Test if Mode OK
       
   281 			if ( err==KErrNone )
       
   282 				{
       
   283 				displayMode=testMode;
       
   284 				hasDisplayMode=ETrue;
       
   285 				delete iFbsScreenDevice;
       
   286 				iFbsScreenDevice=NULL;
       
   287 				INFO_PRINTF2(_L("Mode %d supported"), testMode);
       
   288 				}
       
   289 			}
       
   290 		}
       
   291 
       
   292 	if ( hasDisplayMode )
       
   293 		{
       
   294 		if ( hasLibName ) // if lib name is given
       
   295 			{		
       
   296 			if ( useRgb )
       
   297 				{
       
   298 				TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(libName, displayMode, TRgb(red, green, blue)));
       
   299 				}
       
   300 			else
       
   301 				{
       
   302 				TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(libName, displayMode));
       
   303 				}
       
   304 			}
       
   305 		else // if lib name is not given
       
   306 			{		
       
   307 			TRAP(err, iFbsScreenDevice=CFbsScreenDevice::NewL(screenNumber, displayMode));
       
   308 			}
       
   309 
       
   310 		if ( err!=KErrNone )
       
   311 			{
       
   312 			ERR_PRINTF2(_L("NewL failed with error %d"), err);
       
   313 			SetError(err);
       
   314 			}
       
   315 		}
       
   316 	else
       
   317 		{
       
   318 		ERR_PRINTF1(_L("No Display Mode"));
       
   319 		SetBlockResult(EFail);
       
   320 		}
       
   321 	}
       
   322 
       
   323 void CT_DataFbsScreenDevice::DoCmdDestructor()
       
   324 	{
       
   325 	DestroyData();
       
   326 	}
       
   327 
       
   328 void CT_DataFbsScreenDevice::DoCmdChangeScreenDeviceL(const TDesC& aSection)
       
   329 	{
       
   330 	TPtrC	FbsScreenDevNameOld;
       
   331 	CFbsScreenDevice*	FbsScreenDevOld = NULL;
       
   332 	
       
   333 	if (GetStringFromConfig(aSection, KFbsScreenDevice, FbsScreenDevNameOld))
       
   334 		{
       
   335 		FbsScreenDevOld = static_cast<CFbsScreenDevice*>(GetDataObjectL(FbsScreenDevNameOld));
       
   336 		INFO_PRINTF1(_L("FbsScreenDevice::ChangeScreenDevice(CFbsScreenDevice *aOldDevice) is called!"));
       
   337 		iFbsScreenDevice->ChangeScreenDevice(FbsScreenDevOld);
       
   338 		}
       
   339 	else
       
   340 		{
       
   341 		INFO_PRINTF2(KLogMissingParameter, &KFbsScreenDevice);
       
   342 		SetBlockResult(EFail);
       
   343 		}
       
   344 	}
       
   345 
       
   346 void CT_DataFbsScreenDevice::DoCmdDrawSpriteBegin()
       
   347 	{
       
   348 	INFO_PRINTF1(_L("FbsScreenDevice::DrawSpriteBegin() is called!"));
       
   349 	iFbsScreenDevice->DrawSpriteBegin();
       
   350 	}
       
   351 
       
   352 void CT_DataFbsScreenDevice::DoCmdDrawSpriteEnd()
       
   353 	{
       
   354 	INFO_PRINTF1(_L("FbsScreenDevice::DrawSpriteEnd() is called!"));
       
   355 	iFbsScreenDevice->DrawSpriteEnd();
       
   356 	}
       
   357 
       
   358 void CT_DataFbsScreenDevice::DoCmdHardwareBitmap()
       
   359 	{	
       
   360 	INFO_PRINTF1(_L("FbsScreenDevice::HardwareBitmap() is called!"));
       
   361 	RHardwareBitmap handle = iFbsScreenDevice->HardwareBitmap();
       
   362 	INFO_PRINTF2(_L("The actual handle from HardwareBitmap() is %d"), handle.iHandle);
       
   363 	}
       
   364 
       
   365 void CT_DataFbsScreenDevice::DoCmdScreenNo(const TDesC& aSection)
       
   366 	{
       
   367 	// Execute command and log parameters
       
   368 	INFO_PRINTF1(_L("FbsScreenDevice::ScreenNo() is called!"));
       
   369 	TInt actual = iFbsScreenDevice->ScreenNo();
       
   370 	INFO_PRINTF2(_L("The actual result of ScreenNo() is %d"), actual);
       
   371 
       
   372 	// Diaplay command return value, check if it matches the expected value
       
   373 	TInt expected;
       
   374 	if (!GetIntFromConfig(aSection, KFldExpected, expected))
       
   375 		{
       
   376 		ERR_PRINTF2(KLogMissingParameter, &KFldExpected);
       
   377 		SetBlockResult(EFail);
       
   378 		}
       
   379 	else
       
   380 		{
       
   381 		if (actual!=expected)
       
   382 			{
       
   383 			ERR_PRINTF3(_L("The expected result %d is not equal to the actual result %d!"), expected, actual);
       
   384 			SetBlockResult(EFail);
       
   385 			}
       
   386 		}
       
   387 	}
       
   388 
       
   389 void CT_DataFbsScreenDevice::DoCmdSetAutoUpdate(const TDesC& aSection)
       
   390 	{
       
   391 	TBool autoupdate;
       
   392 	if (!GetBoolFromConfig(aSection, KAutoUpdate, autoupdate))
       
   393 		{
       
   394 		ERR_PRINTF2(KLogMissingParameter, &KAutoUpdate);
       
   395 		SetBlockResult(EFail);
       
   396 		}
       
   397 	else
       
   398 		{
       
   399 		iFbsScreenDevice->SetAutoUpdate(autoupdate);
       
   400 		INFO_PRINTF2(_L("FbsScreenDevice::SetAutoUpdate(%d) has been called."), autoupdate);
       
   401 		}
       
   402 	}
       
   403 
       
   404 void CT_DataFbsScreenDevice::DoCmdUpdateL(const TDesC& aSection)
       
   405 	{
       
   406 	RRegion region(1);
       
   407 	CleanupClosePushL(region);
       
   408 	
       
   409 	if (GetRegionFromConfig(aSection, KRegion(), region))
       
   410 		{
       
   411 		INFO_PRINTF1(_L("FbsScreenDevice::Update(const TRegion &aRegion) has been called."));
       
   412 		iFbsScreenDevice->Update(region);
       
   413 		}
       
   414 	else
       
   415 		{
       
   416 		INFO_PRINTF1(_L("FbsScreenDevice::Update() has been called."));
       
   417 		iFbsScreenDevice->Update();
       
   418 		}
       
   419 	CleanupStack::PopAndDestroy(&region);
       
   420 	}
       
   421 
       
   422 void CT_DataFbsScreenDevice::DoCmdCancelSprite()
       
   423 	{
       
   424 	INFO_PRINTF1(_L("execute CancelSprite()!"));
       
   425 	iFbsScreenDevice->CancelSprite();
       
   426 	}
       
   427 
       
   428 void CT_DataFbsScreenDevice::DoCmdHideSpriteL(const TDesC& aSection)
       
   429 	{
       
   430 	TSpriteBase* spritebase = NULL;
       
   431 	TRect datRect;
       
   432 	RRegion	datRegion(1);
       
   433 	CleanupClosePushL(datRegion);
       
   434 
       
   435 	if (GetRectFromConfig(aSection, KFldRect, datRect))
       
   436 		{
       
   437 		if (GetRegionFromConfig(aSection, KFldRegion, datRegion))
       
   438 			{
       
   439 			INFO_PRINTF1(_L("execute HideSprite(const TRect &aRect, const TRegion *aClippingRegion)!"));
       
   440 			spritebase = iFbsScreenDevice->HideSprite(datRect, &datRegion);
       
   441 			}
       
   442 		else
       
   443 			{
       
   444 			ERR_PRINTF2(KLogMissingParameter, &KFldRegion);
       
   445 			SetBlockResult(EFail);
       
   446 			}
       
   447 		}
       
   448 	else
       
   449 		{
       
   450 		INFO_PRINTF1(_L("execute HideSprite(void)!"));
       
   451 		spritebase = iFbsScreenDevice->HideSprite();
       
   452 		}
       
   453 	
       
   454 	CleanupStack::PopAndDestroy(&datRegion);
       
   455 	}
       
   456 
       
   457 
       
   458 void CT_DataFbsScreenDevice::DoCmdShowSpriteL(const TDesC& aSection)
       
   459 	{
       
   460 	TSpriteBase* spritebase = NULL;
       
   461 	TPtrC SpriteBase;
       
   462 	TRect datRect;
       
   463 	RRegion	datRegion(1);
       
   464 	CleanupClosePushL(datRegion);
       
   465 			
       
   466 	if (GetStringFromConfig(aSection, KSpriteBase, SpriteBase))
       
   467 		{
       
   468 		spritebase = static_cast<TSpriteBase*>(GetDataObjectL(SpriteBase));
       
   469 		}
       
   470 	else
       
   471 		{
       
   472 		ERR_PRINTF2(KLogMissingParameter, &KSpriteBase);
       
   473 		SetBlockResult(EFail);
       
   474 		}
       
   475 
       
   476 	if (GetRectFromConfig(aSection, KFldRect, datRect))
       
   477 		{
       
   478 		if (GetRegionFromConfig(aSection, KFldRegion, datRegion))
       
   479 			{
       
   480 			INFO_PRINTF1(_L("execute ShowSprite(TSpriteBase*, const TRect&, const TRegion*)!"));
       
   481 			iFbsScreenDevice->ShowSprite(spritebase, datRect, &datRegion);
       
   482 			}
       
   483 		else
       
   484 			{
       
   485 			ERR_PRINTF2(KLogMissingParameter, &KFldRegion);
       
   486 			SetBlockResult(EFail);
       
   487 			}
       
   488 		}
       
   489 	else
       
   490 		{
       
   491 		INFO_PRINTF1(_L("execute ShowSprite(TSpriteBase*)!"));
       
   492 		iFbsScreenDevice->ShowSprite(spritebase);
       
   493 		}
       
   494 	CleanupStack::PopAndDestroy(&datRegion);
       
   495 	}