os/graphics/graphicsdeviceinterface/screendriver/tsrc/TScdvTest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 //
    15 
    16 #include <hal.h>
    17 #include <bitdraw.h>
    18 #include "TScdvTest.h"
    19 
    20 GLREF_C TInt ByteSize(TDisplayMode aDisplayMode,TInt aWidth);
    21 
    22 //===================================================================
    23 //In order to test multiple screens creation process on the Emulator, 
    24 //you have to extend your epoc.ini file with the following lines
    25 //_NewScreen_
    26 //ScreenWidth 200
    27 //ScreenHeight 300
    28 //===================================================================
    29 
    30 CTScdv::CTScdv(CTestStep* aStep) :
    31 	CTGraphicsBase(aStep)
    32 	{
    33 	
    34 	}
    35 
    36 //The method calculates the memory (in bytes) needed for a screen 
    37 //device with aSize size and aDisplayMode mode.
    38 inline TInt CTScdv::ByteSize(const TSize& aSize, TDisplayMode aDisplayMode)
    39 	{
    40 	return ::ByteSize(aDisplayMode,aSize.iWidth) * aSize.iHeight;
    41 	}
    42 
    43 //The method creates a screen device for aScreenNo screen number .
    44 //Possible leaving error codes: KErrNoMemory.
    45 //Return result: ETrue - the device was created successfully, EFalse - not supported.
    46 //Successfully created device will be pushed on the cleanup stack.
    47 TBool CTScdv::CreateScreenDeviceLC(TInt aScreenNo, 
    48 								  TDisplayMode aDisplayMode,
    49 								  CFbsDrawDevice*& aScreenDevice)
    50 	{
    51 	__ASSERT_ALWAYS(aScreenDevice == NULL, User::Invariant());
    52 	TBool res = EFalse;
    53 	TRAPD(err, aScreenDevice = CFbsDrawDevice::NewScreenDeviceL(aScreenNo, aDisplayMode));
    54 	if(err == KErrNone)
    55 		{
    56 		CleanupStack::PushL(aScreenDevice);
    57 		res = ETrue;
    58 		}
    59 	else
    60 		{
    61 		if(err != KErrNotSupported)
    62 			{
    63 			User::LeaveIfError(err);
    64 			}
    65 		}
    66 	return res;
    67 	}
    68 
    69 //The method initializes aScreenDevice screen device and allocates.
    70 //a block of memory for it.
    71 //Possible leaving error codes: KErrNoMemory.
    72 //The allocated bock of memory will be pushed on the cleanup stack.
    73 TAny* CTScdv::InitScreenDeviceLC(CFbsDrawDevice* aScreenDevice,
    74 							   TDisplayMode aDisplayMode)
    75 	{
    76 	__ASSERT_ALWAYS(aScreenDevice != NULL, User::Invariant());
    77 
    78 	TSize size = aScreenDevice->SizeInPixels();
    79 	TInt bytesToAllocate=ByteSize(size, aDisplayMode);
    80 	const TInt bytesRequire=bytesToAllocate;
    81 	TUint8* devMemory = new TUint8[bytesToAllocate];
    82 	if (!devMemory)
    83 		{
    84 		do	{
    85 			bytesToAllocate/=2;
    86 			devMemory=new TUint8[bytesToAllocate];
    87 			} while (devMemory==NULL && bytesToAllocate>0);
    88 		if (devMemory)
    89 			{
    90 			_LIT(KLog1,"Not enought memory!!  Allocated %d (0x%x) bytes when %d (0x%x) bytes required.");
    91 			INFO_PRINTF5(KLog1,bytesToAllocate,bytesToAllocate,bytesRequire,bytesRequire);
    92 			_LIT(KLog2,"Display Mode: %S,  Screen Size: %d,%d");
    93 			INFO_PRINTF4(KLog2,&ColorModeName(aDisplayMode),size.iWidth,size.iHeight);
    94 			}
    95 		else
    96 			{
    97 			_LIT(KLog,"Failed to Allocate memory!!  %d (0x%x) bytes required,  Display Mode: %S,  Screen Size: %d,%d");
    98 			INFO_PRINTF6(KLog,bytesRequire,bytesRequire,&ColorModeName(aDisplayMode),size.iWidth,size.iHeight);
    99 			User::Leave(KErrNoMemory);
   100 			}
   101 		}
   102 	CleanupStack::PushL(devMemory);
   103 
   104 	aScreenDevice->SetUserDisplayMode(aDisplayMode);
   105 	aScreenDevice->SetAutoUpdate(EFalse);
   106 	aScreenDevice->SetBits(devMemory);
   107 	return devMemory;
   108 	}
   109 
   110 //Mutltiple screen devices creation test
   111 void CTScdv::TestScreenDeviceCreationL()
   112 	{
   113 	TDisplayMode mode[] = {	EColor256, EColor4K, EColor64K, EColor16,
   114 							EColor16MU,	EColor16MA,	EColor16MAP	};
   115 
   116 	const TInt KTestedDevCnt = 2;
   117 
   118 	for(TInt ii=0;ii<TInt(sizeof(mode)/sizeof(mode[0]));++ii)
   119 		{
   120 		//create
   121 		CFbsDrawDevice* dev[KTestedDevCnt];
   122 		Mem::FillZ(dev, sizeof(dev));
   123 		TInt cnt = 0;
   124 		for(cnt=0;cnt<KTestedDevCnt;++cnt)
   125 			{
   126 			TBool res = CreateScreenDeviceLC(cnt, mode[ii], dev[cnt]);
   127 			if(res)
   128 				{
   129 				InitScreenDeviceLC(dev[cnt], mode[ii]);
   130 				_LIT(KLog,"Created Screen Device with mode %S on screen %d");
   131 				INFO_PRINTF3(KLog,&ColorModeName(mode[ii]),cnt);
   132 				//destroy
   133 				CleanupStack::PopAndDestroy(2,dev[cnt]);
   134 				}
   135 			else
   136 				{
   137 				_LIT(KLog,"No support for display mode %S on screen %d");
   138 				const TDesC* name=&ColorModeName(mode[ii]);
   139 				INFO_PRINTF3(KLog, name, cnt);
   140 				RDebug::Print(KLog, name, cnt);
   141 				break;
   142 				}
   143 			}
   144 		}
   145 	}
   146 
   147 //Bitmap device creation test
   148 void CTScdv::TestBitmapDeviceCreationL()
   149 	{
   150 	TDisplayMode mode[] = {EColor256, EColor4K, EColor16M, EColor16MU, EColor16MA, EColor16MAP, EColor64K, 
   151 						   EGray256, EGray16, EGray4, EGray2, EColor16};
   152 	for(TInt ii=0;ii<TInt(sizeof(mode)/sizeof(mode[0]));++ii)
   153 		{
   154 		//create
   155 		TSize size(10, 20);
   156 		TUint8* bitmapMem = new (ELeave) TUint8[ByteSize(size, mode[ii])];
   157 		CleanupStack::PushL(bitmapMem);
   158 		CFbsDrawDevice* bitmapDev = CFbsDrawDevice::NewBitmapDeviceL(size, mode[ii], ByteSize(size, mode[ii]) / size.iHeight);
   159 		CleanupStack::PushL(bitmapDev);
   160 		//initialize
   161 		bitmapDev->SetAutoUpdate(EFalse);
   162 		bitmapDev->SetBits(bitmapMem);
   163 		//destroy
   164 		CleanupStack::PopAndDestroy(2);//bitmapMem, bitmapDev
   165 		}
   166 	}
   167 
   168 void CTScdv::RunTestCaseL(TInt aCurTestCase)
   169 	{
   170     ((CTScdvStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   171 	switch(aCurTestCase)
   172 		{
   173 	case 1:
   174 		INFO_PRINTF1(_L("Mutiple screen devices creation test"));
   175 /**
   176 	@SYMTestCaseID GRAPHICS-SCREENDRIVER-0033
   177 */
   178 		((CTScdvStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0033"));
   179 		TestScreenDeviceCreationL();
   180 		break;
   181 	case 2:
   182 		INFO_PRINTF1(_L("Bitmap device creation test"));
   183 /**
   184 	@SYMTestCaseID GRAPHICS-SCREENDRIVER-0034
   185 */
   186 		((CTScdvStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0034"));
   187 		TestBitmapDeviceCreationL();
   188 		break;
   189 	case 3:
   190 		((CTScdvStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   191 		((CTScdvStep*)iStep)->CloseTMSGraphicsStep();
   192  		TestComplete();
   193  		break;
   194 		}
   195 	((CTScdvStep*)iStep)->RecordTestResultL();
   196 	}
   197 
   198 //--------------
   199 __CONSTRUCT_STEP__(Scdv)
   200 
   201 
   202 void CTScdvStep::TestSetupL()
   203 	{
   204 	TInt temp = 0;
   205 	HAL::Get(HALData::EDisplayColors, temp);//force HAL memory allocation
   206 	}