os/graphics/fbs/fontandbitmapserver/tfbs/textendedbitmap.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "textendedbitmapcommon.h"
sl@0
    23
#include "textendedbitmap.h"
sl@0
    24
#include "examplerasterizer.h"
sl@0
    25
#include <graphics/fbsrasterizerclearcache.h>
sl@0
    26
#include <s32mem.h>
sl@0
    27
sl@0
    28
const TUint8 KRepeatTestData[] = "(This pattern is 32 bytes long!)";
sl@0
    29
const TInt KRepeatTestDataSize = 32;
sl@0
    30
const TInt KLargeDataSize = 0x8000 * KRepeatTestDataSize;
sl@0
    31
sl@0
    32
CTExtendedBitmap::CTExtendedBitmap(CTestStep* aStep):
sl@0
    33
	CTFbsBase(aStep, ETrue)
sl@0
    34
	{
sl@0
    35
	}
sl@0
    36
sl@0
    37
CTExtendedBitmap::~CTExtendedBitmap()
sl@0
    38
	{
sl@0
    39
	((CTExtendedBitmapStep*)iStep)->CloseTMSGraphicsStep();
sl@0
    40
	User::Free(iLargeData);
sl@0
    41
	}
sl@0
    42
sl@0
    43
void CTExtendedBitmap::ConstructL()
sl@0
    44
	{	
sl@0
    45
	TRAPD(err, iLargeData = static_cast<TUint8*>(User::AllocL(KLargeDataSize)));
sl@0
    46
	if (err != KErrNone)
sl@0
    47
		{
sl@0
    48
		INFO_PRINTF3(_L("Error allocating large data buffer (size %d) in CTExtendedBitmap::ConstructL(), %d"), KLargeDataSize, err);
sl@0
    49
		User::Leave(err);
sl@0
    50
		}
sl@0
    51
	for (TInt i = 0; i < KLargeDataSize; i += KRepeatTestDataSize)
sl@0
    52
		{
sl@0
    53
		Mem::Copy(PtrAdd(iLargeData, i), KRepeatTestData, KRepeatTestDataSize);
sl@0
    54
		}
sl@0
    55
	
sl@0
    56
	// Save a pointer to the example rasterizer's MFbsRasterizerClearCache interface
sl@0
    57
	if (CFbsRasterizer* rasterizer = CFbsBitmap::Rasterizer())
sl@0
    58
		{		
sl@0
    59
		err = rasterizer->GetInterface(TUid::Uid(KUidFbsRasterizerClearCache), (TAny*&)iRasterizerClearCache);
sl@0
    60
		if (err != KErrNone) 
sl@0
    61
			{
sl@0
    62
			WARN_PRINTF1(_L("Failed to get a MFbsRasterizerClearCache interface for the current rasterizer, tests will panic during OOM testing due to the rasterizer cache not being cleared"));
sl@0
    63
			}
sl@0
    64
		}
sl@0
    65
	}
sl@0
    66
sl@0
    67
void CTExtendedBitmap::RunFbsTestL(TInt aCurTestCase)
sl@0
    68
    {    
sl@0
    69
    ((CTExtendedBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
    70
	switch(aCurTestCase)
sl@0
    71
		{
sl@0
    72
	case 1:
sl@0
    73
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0001"));
sl@0
    74
		CreateExtendedBitmapL();
sl@0
    75
		break;
sl@0
    76
	case 2:
sl@0
    77
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0002"));
sl@0
    78
		CreateLargeExtendedBitmapL();
sl@0
    79
		break;
sl@0
    80
	case 3:
sl@0
    81
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0003"));
sl@0
    82
		CreateUsingInitializerL();
sl@0
    83
		break;
sl@0
    84
	case 4:
sl@0
    85
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0004"));
sl@0
    86
		ScanLineL(EFalse);
sl@0
    87
		break;
sl@0
    88
	case 5:
sl@0
    89
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0004"));
sl@0
    90
		ScanLineL(ETrue);
sl@0
    91
		break;
sl@0
    92
	case 6:
sl@0
    93
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0040"));
sl@0
    94
		TestGetPixelL(EFalse);
sl@0
    95
		break;
sl@0
    96
	case 7:
sl@0
    97
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0040"));
sl@0
    98
		TestGetPixelL(ETrue);
sl@0
    99
		break;
sl@0
   100
	case 8:
sl@0
   101
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0042"));
sl@0
   102
		TestGetVerticalScanLineL(EFalse);
sl@0
   103
		break;
sl@0
   104
	case 9:
sl@0
   105
		((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0042"));
sl@0
   106
		TestGetVerticalScanLineL(ETrue);
sl@0
   107
sl@0
   108
		// Fall through as last test case
sl@0
   109
	default:
sl@0
   110
		SetLastTestCase();		
sl@0
   111
		break;
sl@0
   112
		}
sl@0
   113
	((CTExtendedBitmapStep*)iStep)->RecordTestResultL();
sl@0
   114
    }
sl@0
   115
sl@0
   116
sl@0
   117
/**
sl@0
   118
	@SYMTestCaseID
sl@0
   119
	GRAPHICS-FBSERV-EXTENDEDBITMAP-0001
sl@0
   120
sl@0
   121
	@SYMTestCaseDesc
sl@0
   122
	Create an extended bitmap and retrieve data
sl@0
   123
sl@0
   124
	@SYMPREQ 
sl@0
   125
	PREQ2096
sl@0
   126
	
sl@0
   127
	@SYMREQ
sl@0
   128
	REQ10847
sl@0
   129
	REQ10849
sl@0
   130
	REQ10850
sl@0
   131
	REQ10851
sl@0
   132
	REQ10852
sl@0
   133
	REQ10853
sl@0
   134
	REQ10854
sl@0
   135
	REQ10855
sl@0
   136
sl@0
   137
	@SYMTestPriority  
sl@0
   138
	High
sl@0
   139
	
sl@0
   140
	@SYMTestStatus 
sl@0
   141
	Implemented
sl@0
   142
	
sl@0
   143
	@SYMTestActions
sl@0
   144
	Creates an extended bitmap using test data and test Uid;
sl@0
   145
	Retrieves and validates the data size, data and Uid.
sl@0
   146
		
sl@0
   147
	@SYMTestExpectedResults
sl@0
   148
	Extended bitmap created and information correctly retrieved.
sl@0
   149
*/
sl@0
   150
void CTExtendedBitmap::CreateExtendedBitmapL()
sl@0
   151
	{
sl@0
   152
	INFO_PRINTF1(_L("Create an extended bitmap"));
sl@0
   153
sl@0
   154
	const TUint8 KTestData[]		= "Extended bitmap test data 123456";
sl@0
   155
	const TInt KTestDataSize		= sizeof(KTestData);
sl@0
   156
	const TSize KSizeInPixels 		= TSize(50,50);
sl@0
   157
	const TDisplayMode KDisplayMode	= EColor64K;
sl@0
   158
sl@0
   159
	CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
sl@0
   160
	CleanupStack::PushL(bmp);
sl@0
   161
	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, KTestData, KTestDataSize);
sl@0
   162
	TESTNOERRORL(res);
sl@0
   163
sl@0
   164
	bmp->BeginDataAccess();
sl@0
   165
	
sl@0
   166
	TInt returnedDataSize = bmp->DataSize();
sl@0
   167
	TESTEQUALL(KTestDataSize, returnedDataSize);
sl@0
   168
	INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KTestDataSize, returnedDataSize);
sl@0
   169
	
sl@0
   170
	const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
sl@0
   171
	res = Mem::Compare(returnedDataAddress,returnedDataSize, KTestData, KTestDataSize);
sl@0
   172
	TESTEQUALL(0, res);
sl@0
   173
	
sl@0
   174
	TUid returnedUid = bmp->ExtendedBitmapType();
sl@0
   175
	TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
sl@0
   176
sl@0
   177
	bmp->EndDataAccess(ETrue);
sl@0
   178
	
sl@0
   179
	CleanupStack::PopAndDestroy(bmp);
sl@0
   180
	}
sl@0
   181
sl@0
   182
sl@0
   183
/**
sl@0
   184
	@SYMTestCaseID
sl@0
   185
	GRAPHICS-FBSERV-EXTENDEDBITMAP-0002
sl@0
   186
sl@0
   187
	@SYMTestCaseDesc
sl@0
   188
	Create an extended bitmap with data sized 1MB
sl@0
   189
sl@0
   190
	@SYMPREQ 
sl@0
   191
	PREQ2096
sl@0
   192
	
sl@0
   193
	@SYMREQ
sl@0
   194
	REQ10847
sl@0
   195
	REQ10863
sl@0
   196
sl@0
   197
	@SYMTestPriority  
sl@0
   198
	High
sl@0
   199
	
sl@0
   200
	@SYMTestStatus 
sl@0
   201
	Implemented
sl@0
   202
	
sl@0
   203
	@SYMTestActions
sl@0
   204
	Create an extended bitmap with a buffer that is 1MB.
sl@0
   205
		
sl@0
   206
	@SYMTestExpectedResults
sl@0
   207
	No errors or panics should occur.
sl@0
   208
*/
sl@0
   209
void CTExtendedBitmap::CreateLargeExtendedBitmapL()
sl@0
   210
	{
sl@0
   211
	INFO_PRINTF1(_L("Create an extended bitmap with data size 1MB"));	
sl@0
   212
	
sl@0
   213
	const TSize KSizeInPixels = TSize(50,50);
sl@0
   214
	const TDisplayMode KDisplayMode	= EColor64K;	
sl@0
   215
	
sl@0
   216
	CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
sl@0
   217
	CleanupStack::PushL(bmp);
sl@0
   218
	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, iLargeData, KLargeDataSize);
sl@0
   219
	TESTNOERRORL(res);
sl@0
   220
sl@0
   221
	bmp->BeginDataAccess();
sl@0
   222
	
sl@0
   223
	TInt returnedDataSize = bmp->DataSize();
sl@0
   224
	TESTEQUALL(KLargeDataSize, returnedDataSize);
sl@0
   225
	INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KLargeDataSize, returnedDataSize);
sl@0
   226
	
sl@0
   227
	const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
sl@0
   228
	res = Mem::Compare(returnedDataAddress, returnedDataSize, iLargeData, KLargeDataSize);
sl@0
   229
	TESTEQUALL(0, res);
sl@0
   230
	
sl@0
   231
	TUid returnedUid = bmp->ExtendedBitmapType();
sl@0
   232
	TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
sl@0
   233
sl@0
   234
	bmp->EndDataAccess(ETrue);
sl@0
   235
	
sl@0
   236
	CleanupStack::PopAndDestroy(bmp);
sl@0
   237
	}
sl@0
   238
sl@0
   239
sl@0
   240
/**
sl@0
   241
	@SYMTestCaseID
sl@0
   242
	GRAPHICS-FBSERV-EXTENDEDBITMAP-0003
sl@0
   243
sl@0
   244
	@SYMTestCaseDesc
sl@0
   245
	Create an extended bitmap using an MFbsExtendedBitmapInitializer
sl@0
   246
sl@0
   247
	@SYMPREQ 
sl@0
   248
	PREQ2096
sl@0
   249
	
sl@0
   250
	@SYMREQ
sl@0
   251
sl@0
   252
	@SYMTestPriority  
sl@0
   253
	High
sl@0
   254
	
sl@0
   255
	@SYMTestStatus 
sl@0
   256
	Implemented
sl@0
   257
	
sl@0
   258
	@SYMTestActions
sl@0
   259
	Create an extended bitmap using an MFbsExtendedBitmapInitializer, with a buffer that is 1MB.
sl@0
   260
		
sl@0
   261
	@SYMTestExpectedResults
sl@0
   262
	Extended bitmap created and information correctly retrieved. 
sl@0
   263
*/
sl@0
   264
void CTExtendedBitmap::CreateUsingInitializerL()
sl@0
   265
	{
sl@0
   266
	INFO_PRINTF1(_L("Create an extended bitmap using an MFbsExtendedBitmapInitializer"));	
sl@0
   267
	
sl@0
   268
	const TSize KSizeInPixels = TSize(50,50);
sl@0
   269
	const TDisplayMode KDisplayMode	= EColor64K;	
sl@0
   270
	
sl@0
   271
	CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
sl@0
   272
	CleanupStack::PushL(bmp);
sl@0
   273
	CTestExtendedBitmapInitializer* initializer = new(ELeave) CTestExtendedBitmapInitializer(iLargeData, KLargeDataSize);
sl@0
   274
	CleanupStack::PushL(initializer);
sl@0
   275
	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, KLargeDataSize, *initializer);
sl@0
   276
	CleanupStack::PopAndDestroy(initializer);
sl@0
   277
	TESTNOERRORL(res);
sl@0
   278
	
sl@0
   279
	bmp->BeginDataAccess();
sl@0
   280
	
sl@0
   281
	TInt returnedDataSize = bmp->DataSize();
sl@0
   282
	TESTEQUALL(KLargeDataSize, returnedDataSize);
sl@0
   283
	INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KLargeDataSize, returnedDataSize);
sl@0
   284
	
sl@0
   285
	const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
sl@0
   286
	res = Mem::Compare(returnedDataAddress, returnedDataSize, iLargeData, KLargeDataSize);
sl@0
   287
	TESTEQUALL(0, res);
sl@0
   288
	
sl@0
   289
	TUid returnedUid = bmp->ExtendedBitmapType();
sl@0
   290
	TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
sl@0
   291
sl@0
   292
	bmp->EndDataAccess(ETrue);
sl@0
   293
	
sl@0
   294
	CleanupStack::PopAndDestroy(bmp);
sl@0
   295
	}
sl@0
   296
sl@0
   297
/**
sl@0
   298
	@SYMTestCaseID
sl@0
   299
	GRAPHICS-FBSERV-EXTENDEDBITMAP-0004
sl@0
   300
sl@0
   301
	@SYMTestCaseDesc
sl@0
   302
	Create an extended bitmap and retrieve scanline
sl@0
   303
sl@0
   304
	@SYMPREQ 
sl@0
   305
	PREQ2096
sl@0
   306
	
sl@0
   307
	@SYMREQ
sl@0
   308
	REQ10847
sl@0
   309
sl@0
   310
	@SYMTestPriority  
sl@0
   311
	High
sl@0
   312
	
sl@0
   313
	@SYMTestStatus 
sl@0
   314
	Implemented
sl@0
   315
	
sl@0
   316
	@SYMTestActions
sl@0
   317
	Creates an extended bitmap using data compatible with the
sl@0
   318
	example rasterizer.
sl@0
   319
	If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
sl@0
   320
	to create a duplicate of the extended bitmap just created and 
sl@0
   321
	complete the test using the duplicate extended bitmap. 
sl@0
   322
	Get a scanline using CFbsBitmap::GetScanLine() and check if
sl@0
   323
	it is correct, depending on the presence of the rasterizer.
sl@0
   324
		
sl@0
   325
	@SYMTestExpectedResults
sl@0
   326
	Extended bitmap created and scanline correctly retrieved.
sl@0
   327
*/
sl@0
   328
void CTExtendedBitmap::ScanLineL(TBool aUseDuplicateBitmap)
sl@0
   329
	{
sl@0
   330
	INFO_PRINTF1(_L("Get a scanline from an extended bitmap"));	
sl@0
   331
sl@0
   332
	const TRgb KColors[] 	= {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
sl@0
   333
	// Small size needed for this test O(x^2 * y) iterations run every time
sl@0
   334
	const TSize KSizeInPixels 		= TSize(8,5); 
sl@0
   335
	const TDisplayMode KDisplayMode	= EColor64K;
sl@0
   336
	const TUint8 horizontalStripes = 1;
sl@0
   337
sl@0
   338
	// Check to see if we have an example bitmap rasterizer available for this test run	
sl@0
   339
	iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
sl@0
   340
	if (iRasterizerAvailable)
sl@0
   341
		{
sl@0
   342
		INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));	
sl@0
   343
		}
sl@0
   344
	else
sl@0
   345
		{
sl@0
   346
		INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
sl@0
   347
		}
sl@0
   348
	
sl@0
   349
	CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
sl@0
   350
sl@0
   351
	TInt dataSize = sizeof(KColors)+sizeof(horizontalStripes); // estimate the data size
sl@0
   352
	TUint8* data = new(ELeave) TUint8[dataSize];
sl@0
   353
	CleanupStack::PushL(data);	
sl@0
   354
	
sl@0
   355
	// Write the colours to be used in the extended bitmap to the data
sl@0
   356
	RMemWriteStream ws;
sl@0
   357
	ws.Open(data, dataSize);
sl@0
   358
	CleanupClosePushL(ws);
sl@0
   359
	ws << KColors[0] << KColors[1] << KColors[2] << horizontalStripes;
sl@0
   360
	dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
sl@0
   361
	CleanupStack::PopAndDestroy(1, &ws);
sl@0
   362
	
sl@0
   363
	// Create the extended bitmap to be used a a brush
sl@0
   364
	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
sl@0
   365
	CleanupStack::PushL(bmp);
sl@0
   366
	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
sl@0
   367
	TESTNOERRORL(res);
sl@0
   368
		
sl@0
   369
	if (aUseDuplicateBitmap)
sl@0
   370
		{
sl@0
   371
		INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
sl@0
   372
		CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
sl@0
   373
		CleanupStack::PushL(duplicateBmp);
sl@0
   374
		res = duplicateBmp->Duplicate(bmp->Handle());
sl@0
   375
		TESTNOERRORL(res);
sl@0
   376
		bmp = duplicateBmp;
sl@0
   377
		}
sl@0
   378
sl@0
   379
	TInt byteWidth = CFbsBitmap::ScanLineLength(KSizeInPixels.iWidth, KDisplayMode);
sl@0
   380
	TUint8* buffer = new(ELeave) TUint8[byteWidth + 1];
sl@0
   381
	CleanupArrayDeletePushL(buffer);
sl@0
   382
sl@0
   383
	const TUint8 KCheckValue = 0x69; // Pixel value used as guard at the end of the buffer used
sl@0
   384
	buffer[byteWidth] = KCheckValue; 
sl@0
   385
	TPtr8 scanLine(buffer,byteWidth,byteWidth);
sl@0
   386
sl@0
   387
	TInt x, y;
sl@0
   388
	TInt firstStripe, lastStripe;
sl@0
   389
	TInt* s;
sl@0
   390
	if(horizontalStripes)
sl@0
   391
		{
sl@0
   392
		firstStripe = KSizeInPixels.iHeight/3;
sl@0
   393
		lastStripe = KSizeInPixels.iHeight - firstStripe;
sl@0
   394
		s = &y;
sl@0
   395
		}
sl@0
   396
	else
sl@0
   397
		{
sl@0
   398
		firstStripe = KSizeInPixels.iWidth/3;
sl@0
   399
		lastStripe = KSizeInPixels.iWidth - firstStripe;
sl@0
   400
		s = &x;
sl@0
   401
		}
sl@0
   402
sl@0
   403
	for(y = 0; y < KSizeInPixels.iHeight; ++y)
sl@0
   404
		{
sl@0
   405
		for(TInt length = 1; length <= KSizeInPixels.iWidth; ++length)
sl@0
   406
			{
sl@0
   407
			for(TInt pos = KSizeInPixels.iWidth - length; pos >= 0; --pos)
sl@0
   408
				{
sl@0
   409
				bmp->GetScanLine(scanLine, TPoint(pos,y), length, KDisplayMode);
sl@0
   410
				for(x = pos + length - 1; x >= pos; --x)
sl@0
   411
					{
sl@0
   412
					TRgb bufferColor = ExtractRgb(buffer, x-pos, KDisplayMode);
sl@0
   413
					
sl@0
   414
					if(!iRasterizerAvailable)
sl@0
   415
						{
sl@0
   416
						TESTCOLOREQUALL(bufferColor, KRgbWhite);
sl@0
   417
						}
sl@0
   418
					else if (*s < firstStripe)
sl@0
   419
						{
sl@0
   420
						// First stripe
sl@0
   421
						TESTCOLOREQUALL(bufferColor, KColors[0]);
sl@0
   422
						}
sl@0
   423
					else if (*s >= lastStripe)
sl@0
   424
						{
sl@0
   425
						// Last stripe
sl@0
   426
						TESTCOLOREQUALL(bufferColor, KColors[2]);
sl@0
   427
						}
sl@0
   428
					else
sl@0
   429
						{
sl@0
   430
						// Middle stripe
sl@0
   431
						TESTCOLOREQUALL(bufferColor, KColors[1]);
sl@0
   432
						}							
sl@0
   433
					}
sl@0
   434
				}
sl@0
   435
			}
sl@0
   436
		}
sl@0
   437
	
sl@0
   438
	// Check that the guard byte is still intact now that the tests have been run
sl@0
   439
	TEST(buffer[byteWidth] == KCheckValue); 
sl@0
   440
	
sl@0
   441
	if (aUseDuplicateBitmap)
sl@0
   442
		{
sl@0
   443
		CleanupStack::PopAndDestroy(1);
sl@0
   444
		}
sl@0
   445
	CleanupStack::PopAndDestroy(4);
sl@0
   446
	}
sl@0
   447
sl@0
   448
sl@0
   449
/**
sl@0
   450
	@SYMTestCaseID
sl@0
   451
	GRAPHICS-FBSERV-EXTENDEDBITMAP-0040
sl@0
   452
sl@0
   453
	@SYMTestCaseDesc
sl@0
   454
	Create an extended bitmap and retrieve pixels
sl@0
   455
sl@0
   456
	@SYMPREQ 
sl@0
   457
	CR1804
sl@0
   458
	
sl@0
   459
	@SYMREQ
sl@0
   460
	REQ10858
sl@0
   461
sl@0
   462
	@SYMTestPriority  
sl@0
   463
	High
sl@0
   464
	
sl@0
   465
	@SYMTestStatus 
sl@0
   466
	Implemented
sl@0
   467
	
sl@0
   468
	@SYMTestActions
sl@0
   469
	Creates an extended bitmap using data compatible with the
sl@0
   470
	example rasterizer.
sl@0
   471
	If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
sl@0
   472
	to create a duplicate of the extended bitmap just created and 
sl@0
   473
	complete the test using the duplicate extended bitmap. 
sl@0
   474
	Get pixel values using CFbsBitmap::GetPixel() and check if
sl@0
   475
	they are correct, depending on the presence of the rasterizer.
sl@0
   476
		
sl@0
   477
	@SYMTestExpectedResults
sl@0
   478
	Extended bitmap created and pixels correctly retrieved.
sl@0
   479
*/
sl@0
   480
void CTExtendedBitmap::TestGetPixelL(TBool aUseDuplicateBitmap)
sl@0
   481
	{
sl@0
   482
	INFO_PRINTF1(_L("Get pixel values from an extended bitmap"));	
sl@0
   483
sl@0
   484
	const TRgb KColors[] 	= {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
sl@0
   485
	const TSize KSizeInPixels 		= TSize(8,5); 
sl@0
   486
	const TDisplayMode KDisplayMode	= EColor64K;
sl@0
   487
	const TUint8 KHorizontalStripes = 1;
sl@0
   488
sl@0
   489
	// Check to see if we have an example bitmap rasterizer available for this test run	
sl@0
   490
	iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
sl@0
   491
	if (iRasterizerAvailable)
sl@0
   492
		{
sl@0
   493
		INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));	
sl@0
   494
		}
sl@0
   495
	else
sl@0
   496
		{
sl@0
   497
		INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
sl@0
   498
		}
sl@0
   499
	
sl@0
   500
	CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
sl@0
   501
sl@0
   502
	TInt dataSize = sizeof(KColors)+sizeof(KHorizontalStripes); // estimate the data size
sl@0
   503
	TUint8* data = new(ELeave) TUint8[dataSize];
sl@0
   504
	CleanupStack::PushL(data);	
sl@0
   505
	
sl@0
   506
	// Write the colours to be used in the extended bitmap to the data
sl@0
   507
	RMemWriteStream ws;
sl@0
   508
	ws.Open(data, dataSize);
sl@0
   509
	CleanupClosePushL(ws);
sl@0
   510
	ws << KColors[0] << KColors[1] << KColors[2] << KHorizontalStripes;
sl@0
   511
	dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
sl@0
   512
	CleanupStack::PopAndDestroy(1, &ws);
sl@0
   513
	
sl@0
   514
	// Create the extended bitmap
sl@0
   515
	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
sl@0
   516
	CleanupStack::PushL(bmp);
sl@0
   517
	TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
sl@0
   518
	TESTNOERRORL(res);
sl@0
   519
		
sl@0
   520
	if (aUseDuplicateBitmap)
sl@0
   521
		{
sl@0
   522
		INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
sl@0
   523
		CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
sl@0
   524
		CleanupStack::PushL(duplicateBmp);
sl@0
   525
		res = duplicateBmp->Duplicate(bmp->Handle());
sl@0
   526
		TESTNOERRORL(res);
sl@0
   527
		bmp = duplicateBmp;
sl@0
   528
		}
sl@0
   529
sl@0
   530
	TInt firstStripe = KSizeInPixels.iHeight/3;
sl@0
   531
	TInt lastStripe = KSizeInPixels.iHeight - firstStripe;
sl@0
   532
	TRgb color;
sl@0
   533
	for(TInt y = 0; y < KSizeInPixels.iHeight; ++y)
sl@0
   534
		{
sl@0
   535
		for(TInt x = 0; x < KSizeInPixels.iWidth; ++x)
sl@0
   536
			{
sl@0
   537
			bmp->GetPixel(color, TPoint(x,y));
sl@0
   538
sl@0
   539
			if(!iRasterizerAvailable)
sl@0
   540
				{
sl@0
   541
				TESTCOLOREQUALL(color, KRgbWhite);
sl@0
   542
				}
sl@0
   543
			else if (y < firstStripe)
sl@0
   544
				{
sl@0
   545
				// First stripe
sl@0
   546
				TESTCOLOREQUALL(color, KColors[0]);
sl@0
   547
				}
sl@0
   548
			else if (y >= lastStripe)
sl@0
   549
				{
sl@0
   550
				// Last stripe
sl@0
   551
				TESTCOLOREQUALL(color, KColors[2]);
sl@0
   552
				}
sl@0
   553
			else
sl@0
   554
				{
sl@0
   555
				// Middle stripe
sl@0
   556
				TESTCOLOREQUALL(color, KColors[1]);
sl@0
   557
				}							
sl@0
   558
			}
sl@0
   559
		}
sl@0
   560
	
sl@0
   561
	if (aUseDuplicateBitmap)
sl@0
   562
		{
sl@0
   563
		CleanupStack::PopAndDestroy(1);
sl@0
   564
		}
sl@0
   565
	CleanupStack::PopAndDestroy(3);
sl@0
   566
	}
sl@0
   567
sl@0
   568
sl@0
   569
sl@0
   570
/**
sl@0
   571
@SYMTestCaseID
sl@0
   572
	GRAPHICS-FBSERV-EXTENDEDBITMAP-0042
sl@0
   573
sl@0
   574
@SYMTestCaseDesc
sl@0
   575
	Create an extended bitmap and retrieve vertical scanline
sl@0
   576
sl@0
   577
@SYMPREQ 
sl@0
   578
	DEF141346
sl@0
   579
	
sl@0
   580
@SYMTestPriority  
sl@0
   581
	High
sl@0
   582
sl@0
   583
@SYMTestStatus 
sl@0
   584
	Implemented
sl@0
   585
sl@0
   586
@SYMTestActions
sl@0
   587
	Create an extended bitmap using data compatible with the
sl@0
   588
	example rasterizer.
sl@0
   589
	If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
sl@0
   590
	to create a duplicate of the extended bitmap just created and 
sl@0
   591
	complete the test using the duplicate extended bitmap. 
sl@0
   592
	Get a vertical scanline using CFbsBitmap::GetVerticalScanLine() and check
sl@0
   593
	if it is correct, depending on the presence of the rasterizer.
sl@0
   594
sl@0
   595
@SYMTestExpectedResults
sl@0
   596
	Extended bitmap created and scanline correctly retrieved.
sl@0
   597
*/
sl@0
   598
void CTExtendedBitmap::TestGetVerticalScanLineL(TBool aUseDuplicateBitmap)
sl@0
   599
	{
sl@0
   600
	INFO_PRINTF1(_L("Get a vertical scanline from an extended bitmap"));	
sl@0
   601
sl@0
   602
		const TRgb KColors[] 	= {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
sl@0
   603
		const TSize KSizeInPixels 		= TSize(5,8); 
sl@0
   604
		const TDisplayMode KDisplayMode	= EColor64K;
sl@0
   605
		const TUint8 KHorizontalStripes = 1;
sl@0
   606
sl@0
   607
		// Check to see if we have an example bitmap rasterizer available for this test run	
sl@0
   608
		iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
sl@0
   609
		if (iRasterizerAvailable)
sl@0
   610
			{
sl@0
   611
			INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));	
sl@0
   612
			}
sl@0
   613
		else
sl@0
   614
			{
sl@0
   615
			INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
sl@0
   616
			}
sl@0
   617
		
sl@0
   618
		CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
sl@0
   619
sl@0
   620
		TInt dataSize = sizeof(KColors)+sizeof(KHorizontalStripes); // estimate the data size
sl@0
   621
		TUint8* data = new(ELeave) TUint8[dataSize];
sl@0
   622
		CleanupStack::PushL(data);	
sl@0
   623
		
sl@0
   624
		// Write the colours to be used in the extended bitmap to the data
sl@0
   625
		RMemWriteStream ws;
sl@0
   626
		ws.Open(data, dataSize);
sl@0
   627
		CleanupClosePushL(ws);
sl@0
   628
		ws << KColors[0] << KColors[1] << KColors[2] << KHorizontalStripes;
sl@0
   629
		dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
sl@0
   630
		CleanupStack::PopAndDestroy(1, &ws);
sl@0
   631
		
sl@0
   632
		// Create the extended bitmap
sl@0
   633
		CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
sl@0
   634
		CleanupStack::PushL(bmp);
sl@0
   635
		TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
sl@0
   636
		TESTNOERRORL(res);
sl@0
   637
			
sl@0
   638
		if (aUseDuplicateBitmap)
sl@0
   639
			{
sl@0
   640
			INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
sl@0
   641
			CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
sl@0
   642
			CleanupStack::PushL(duplicateBmp);
sl@0
   643
			res = duplicateBmp->Duplicate(bmp->Handle());
sl@0
   644
			TESTNOERRORL(res);
sl@0
   645
			bmp = duplicateBmp;
sl@0
   646
			}
sl@0
   647
sl@0
   648
		TInt byteWidth = CFbsBitmap::ScanLineLength(KSizeInPixels.iHeight, KDisplayMode);
sl@0
   649
		TUint8* buffer = new(ELeave) TUint8[byteWidth + 1];
sl@0
   650
		CleanupArrayDeletePushL(buffer);
sl@0
   651
sl@0
   652
		const TUint8 KCheckValue = 0x69; // Pixel value used as guard at the end of the buffer used
sl@0
   653
		buffer[byteWidth] = KCheckValue; 
sl@0
   654
		TPtr8 scanLine(buffer,byteWidth,byteWidth);
sl@0
   655
sl@0
   656
		TInt firstStripe = KSizeInPixels.iHeight/3;
sl@0
   657
		TInt lastStripe = KSizeInPixels.iHeight - firstStripe;
sl@0
   658
		TRgb color;
sl@0
   659
		for(TInt x = 0; x < KSizeInPixels.iWidth; ++x)
sl@0
   660
			{
sl@0
   661
			bmp->GetVerticalScanLine(scanLine, x, KDisplayMode);
sl@0
   662
			for(TInt y = 0; y < KSizeInPixels.iHeight; ++y)
sl@0
   663
				{
sl@0
   664
				TRgb bufferColor = ExtractRgb(buffer, y, KDisplayMode);
sl@0
   665
				if(!iRasterizerAvailable)
sl@0
   666
					{
sl@0
   667
					TESTCOLOREQUALL(bufferColor, KRgbWhite);
sl@0
   668
					}
sl@0
   669
				else if (y < firstStripe)
sl@0
   670
					{
sl@0
   671
					// First stripe
sl@0
   672
					TESTCOLOREQUALL(bufferColor, KColors[0]);
sl@0
   673
					}
sl@0
   674
				else if (y >= lastStripe)
sl@0
   675
					{
sl@0
   676
					// Last stripe
sl@0
   677
					TESTCOLOREQUALL(bufferColor, KColors[2]);
sl@0
   678
					}
sl@0
   679
				else
sl@0
   680
					{
sl@0
   681
					// Middle stripe
sl@0
   682
					TESTCOLOREQUALL(bufferColor, KColors[1]);
sl@0
   683
					}							
sl@0
   684
				}
sl@0
   685
			}
sl@0
   686
sl@0
   687
		// Check that the guard byte is still intact now that the tests have been run
sl@0
   688
		TEST(buffer[byteWidth] == KCheckValue); 
sl@0
   689
sl@0
   690
		if (aUseDuplicateBitmap)
sl@0
   691
			{
sl@0
   692
			CleanupStack::PopAndDestroy(1);
sl@0
   693
			}
sl@0
   694
		CleanupStack::PopAndDestroy(4);
sl@0
   695
	}
sl@0
   696
sl@0
   697
//--------------
sl@0
   698
__CONSTRUCT_STEP__(ExtendedBitmap)
sl@0
   699
sl@0
   700
/** Method to be used with a TCleanupItem for clearing the extended bitmap rasterizer cache
sl@0
   701
from the cleanup stack. Calls the MExampleRasterizerClearCache::ClearCache() method on the
sl@0
   702
passed CFbsRasterizer object if the MExampleRasterizerClearCache extension interface is available
sl@0
   703
for that object.
sl@0
   704
@param aPtr A pointer to the current CFbsRasterizer object, or NULL if no rasterizer
sl@0
   705
object is available.
sl@0
   706
 */
sl@0
   707
void CTExtendedBitmap::ClearRasterizerCache(TAny* aPtr)
sl@0
   708
	{	
sl@0
   709
	if (aPtr)
sl@0
   710
		{
sl@0
   711
		static_cast<MFbsRasterizerClearCache*>(aPtr)->ClearCache();
sl@0
   712
		}
sl@0
   713
	}
sl@0
   714