graphicsapitest/graphicssvs/bitgdi/src/T_DataFbsBitmapDevice.cpp
changeset 103 2717213c588a
parent 98 bf7481649c98
child 116 171fae344dd4
child 121 d72fc2aace31
child 187 9f66f99ee56f
equal deleted inserted replaced
98:bf7481649c98 103:2717213c588a
     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 "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 @test
       
    20 @internalComponent
       
    21 
       
    22 This contains CT_DataFbsBitmapDevice
       
    23 */
       
    24 
       
    25 //	User includes
       
    26 #include "T_DataFbsBitmapDevice.h"
       
    27 #include "T_GraphicsUtil.h"
       
    28 
       
    29 /*@{*/
       
    30 ///	Commands
       
    31 _LIT(KCmdNewL,							"NewL");
       
    32 _LIT(KCmdDestructor,					"~");
       
    33 _LIT(KCmdDrawingBegin, 					"DrawingBegin");
       
    34 _LIT(KCmdDrawingEnd,					"DrawingEnd");
       
    35 _LIT(KCmdResize,						"Resize");
       
    36 _LIT(KCmdSwapWidthAndHeight,			"SwapWidthAndHeight");
       
    37 
       
    38 ///	Parameters
       
    39 _LIT(KFldBitmap,						"bitmap");
       
    40 _LIT(KFldLibName,						"libname");
       
    41 _LIT(KFldSize,							"size");
       
    42 _LIT(KFldResize,						"resize");
       
    43 _LIT(KFldAlways,						"Always");
       
    44 
       
    45 // Logs
       
    46 _LIT(KLogMissingParameter,				"Missing parameter '%S'");
       
    47 _LIT(KLogErrNum,						"Execute failed with error = %d!");	
       
    48 /*@}*/
       
    49 
       
    50 
       
    51 /**
       
    52 * Two phase constructor
       
    53 */
       
    54 CT_DataFbsBitmapDevice* CT_DataFbsBitmapDevice::NewL()
       
    55 	{
       
    56 	CT_DataFbsBitmapDevice*	ret = new (ELeave) CT_DataFbsBitmapDevice();
       
    57 	CleanupStack::PushL(ret);
       
    58 	ret->ConstructL();
       
    59 	CleanupStack::Pop(ret);
       
    60 	return ret;
       
    61 	}
       
    62 
       
    63 /**
       
    64 * Protected constructor. First phase construction
       
    65 */
       
    66 CT_DataFbsBitmapDevice::CT_DataFbsBitmapDevice()
       
    67 :	CT_DataFbsDevice()
       
    68 ,	iFbsBitmapDevice(NULL)
       
    69 	{
       
    70 	}
       
    71 
       
    72 /**
       
    73 * Protected second phase construction
       
    74 */
       
    75 void CT_DataFbsBitmapDevice::ConstructL()
       
    76 	{
       
    77 	}
       
    78 
       
    79 /**
       
    80 * Destructor.
       
    81 */
       
    82 CT_DataFbsBitmapDevice::~CT_DataFbsBitmapDevice()
       
    83 	{
       
    84 	DestroyData();
       
    85 	}
       
    86 
       
    87 void CT_DataFbsBitmapDevice::DestroyData()
       
    88 	{
       
    89 	delete iFbsBitmapDevice;
       
    90 	iFbsBitmapDevice=NULL;
       
    91 	}
       
    92 
       
    93 MGraphicsDeviceMap* CT_DataFbsBitmapDevice::GetGraphicsDeviceMap() const
       
    94 	{
       
    95 	return iFbsBitmapDevice;
       
    96 	}
       
    97 
       
    98 CGraphicsDevice* CT_DataFbsBitmapDevice::GetGraphicsDevice() const
       
    99 	{
       
   100 	return iFbsBitmapDevice;
       
   101 	}
       
   102 
       
   103 CBitmapDevice* CT_DataFbsBitmapDevice::GetBitmapDevice() const
       
   104 	{
       
   105 	return iFbsBitmapDevice;
       
   106 	}
       
   107 
       
   108 CFbsDevice* CT_DataFbsBitmapDevice::GetFbsDevice() const
       
   109 	{
       
   110 	return iFbsBitmapDevice;
       
   111 	}
       
   112 /**
       
   113 * Return a pointer to the object that the data wraps
       
   114 *
       
   115 * @return pointer to the object that the data wraps
       
   116 */
       
   117 TAny* CT_DataFbsBitmapDevice::GetObject()
       
   118 	{
       
   119 	return iFbsBitmapDevice;
       
   120 	}
       
   121 
       
   122 void CT_DataFbsBitmapDevice::SetObjectL(TAny* aObject)
       
   123 	{
       
   124 	DestroyData();
       
   125 	iFbsBitmapDevice = static_cast<CFbsBitmapDevice*> (aObject);
       
   126 	}
       
   127 
       
   128 void CT_DataFbsBitmapDevice::DisownObjectL() 
       
   129 	{
       
   130 	iFbsBitmapDevice = NULL;
       
   131 	}
       
   132 
       
   133 /**
       
   134 * Process a command read from the ini file
       
   135 *
       
   136 * @param aDataWrapper	test step requiring command to be processed
       
   137 * @param aCommand	the command to process
       
   138 * @param aSection		the entry in the ini file requiring the command to be processed
       
   139 *
       
   140 * @return ETrue if the command is processed
       
   141 */
       
   142 TBool CT_DataFbsBitmapDevice::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   143 	{
       
   144 	/* Another work package will complete the implement of this */
       
   145 	TBool	retVal = ETrue;
       
   146 
       
   147 	if ( aCommand == KCmdNewL )
       
   148 		{
       
   149 		DoCmdNewL(aSection);
       
   150 		}
       
   151 	else if (aCommand == KCmdDestructor)
       
   152 		{
       
   153 		DoCmdDestructor();
       
   154 		}
       
   155 	else if (aCommand == KCmdDrawingBegin)
       
   156 		{
       
   157 		DoCmdDrawingBegin(aSection);
       
   158 		}
       
   159 	else if (aCommand == KCmdDrawingEnd)
       
   160 		{
       
   161 		DoCmdDrawingEnd(aSection);
       
   162 		}
       
   163 	else if (aCommand == KCmdResize)
       
   164 		{
       
   165 		DoCmdResize(aSection);
       
   166 		}
       
   167 	else if (aCommand == KCmdSwapWidthAndHeight)
       
   168 		{
       
   169 		DoCmdSwapWidthAndHeight();
       
   170 		}
       
   171 	else
       
   172 		{
       
   173 		retVal=CT_DataFbsDevice::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
       
   174 		}
       
   175 	return retVal;
       
   176 	}
       
   177 
       
   178 void CT_DataFbsBitmapDevice::DoCmdNewL(const TDesC& aSection)
       
   179 	{
       
   180 	DestroyData();
       
   181 	CFbsBitmap*	bitmap = NULL;
       
   182 	
       
   183 	if (!CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KFldBitmap, bitmap))
       
   184 		{
       
   185 		ERR_PRINTF2(KLogMissingParameter, &KFldBitmap);
       
   186 		SetBlockResult(EFail);
       
   187 		return;
       
   188 		}
       
   189 	TInt	err = KErrNone;
       
   190 	TPtrC	libName;
       
   191 	if ( GetStringFromConfig(aSection, KFldLibName(), libName) )
       
   192 		{
       
   193 		INFO_PRINTF1(_L("execute NewL(CFbsBitmap*, const TDesC&)."));
       
   194 		TRAP(err, iFbsBitmapDevice=CFbsBitmapDevice::NewL(bitmap, libName));
       
   195 		}
       
   196 	else
       
   197 		{
       
   198 		INFO_PRINTF1(_L("execute NewL(CFbsBitmap*)."));
       
   199 		TRAP(err, iFbsBitmapDevice=CFbsBitmapDevice::NewL(bitmap));
       
   200 		}
       
   201 	
       
   202 	if ( err != KErrNone )
       
   203 		{
       
   204 		ERR_PRINTF2(KLogErrNum, err);
       
   205 		SetError(err);
       
   206 		}
       
   207 	}
       
   208 
       
   209 void CT_DataFbsBitmapDevice::DoCmdDestructor()
       
   210 	{
       
   211 	DestroyData();
       
   212 	}
       
   213 
       
   214 void CT_DataFbsBitmapDevice::DoCmdDrawingBegin(const TDesC& aSection)
       
   215 	{
       
   216 	TBool Always = EFalse;
       
   217 	GetBoolFromConfig(aSection, KFldAlways, Always);
       
   218 	INFO_PRINTF2(_L("execute DrawingBegin function with the Always parameter=%d."), Always);
       
   219 	iFbsBitmapDevice->DrawingBegin(Always);
       
   220 	}
       
   221 
       
   222 void CT_DataFbsBitmapDevice::DoCmdDrawingEnd(const TDesC& aSection)
       
   223 	{
       
   224 	TBool Always = EFalse;
       
   225 	GetBoolFromConfig(aSection, KFldAlways, Always);
       
   226 	INFO_PRINTF2(_L("execute DrawingEnd function with the Always parameter=%d."), Always);
       
   227 	iFbsBitmapDevice->DrawingEnd(Always);
       
   228 	}
       
   229 
       
   230 void CT_DataFbsBitmapDevice::DoCmdResize(const TDesC& aSection)
       
   231 	{
       
   232 	TSize	datSize;
       
   233 	TInt 	err = KErrNone;
       
   234 	INFO_PRINTF1(_L("execute Resize(const TSize&)"));
       
   235 	if (!GetSizeFromConfig(aSection, KFldResize, datSize))
       
   236 		{
       
   237 		ERR_PRINTF2(KLogMissingParameter, &KFldResize);
       
   238 		SetBlockResult(EFail);
       
   239 		}
       
   240 	else
       
   241 		{
       
   242 		err = iFbsBitmapDevice->Resize(datSize);
       
   243 		if (KErrNone != err)
       
   244 			{
       
   245 			ERR_PRINTF2(KLogErrNum, err);
       
   246 			SetError(err);
       
   247 			}
       
   248 		}
       
   249 	}
       
   250 
       
   251 void CT_DataFbsBitmapDevice::DoCmdSwapWidthAndHeight()
       
   252 	{
       
   253 	INFO_PRINTF1(_L("execute SwapWidthAndHeight()"));
       
   254 	TInt err = iFbsBitmapDevice->SwapWidthAndHeight();
       
   255 	if (KErrNone != err)
       
   256 		{
       
   257 		ERR_PRINTF2(KLogErrNum, err);
       
   258 		SetError(err);
       
   259 		}
       
   260 	}
       
   261