fbs/fontandbitmapserver/tfbs/tcompressed.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2002-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 <bitdev.h>
       
    17 #include <e32math.h>
       
    18 #include "tcompressed.h"
       
    19 
       
    20 CTCompressed::CTCompressed(CTestStep* aStep) :
       
    21 	CTGraphicsBase(aStep)
       
    22 	{
       
    23 	}
       
    24 
       
    25 void CTCompressed::BlankBitmap(CFbsBitmapEx& aBitmap)
       
    26 	{
       
    27 	TSize size = aBitmap.SizeInPixels();
       
    28 	TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight;
       
    29 	aBitmap.LockHeap();
       
    30 	Mem::FillZ((TUint8*)aBitmap.DataAddress(),dataLength);
       
    31 	aBitmap.UnlockHeap();
       
    32 	}
       
    33 
       
    34 void CTCompressed::RunTestCaseL(TInt aCurTestCase)
       
    35     {
       
    36     ((CTCompressedStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
    37 	switch(aCurTestCase)
       
    38 		{
       
    39 	case 1:
       
    40 		((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0571"));
       
    41 		TRAPD(err, RunTestL());
       
    42 		TEST(err == KErrNone);
       
    43 		break;	
       
    44 	case 2:
       
    45 		((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0572"));
       
    46 		TRAP(err, DefectFix_EXT5DXGK6_L());
       
    47 		TEST(err == KErrNone);
       
    48 		break;	
       
    49 	case 3:
       
    50 		{
       
    51 		((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0500"));
       
    52 		// Set size of bitmap large enough to warrant compression
       
    53 		const TSize KBitmapSize(200,200);
       
    54 		INFO_PRINTF1(_L("Test case for INC082713\r\n"));
       
    55 		TRAP(err, DefectFix_INC082713_L(EColor16MU, KBitmapSize));
       
    56 		TEST(err == KErrNone);		
       
    57 		TRAP(err, DefectFix_INC082713_L(EColor16MA, KBitmapSize));
       
    58 		TEST(err == KErrNone);
       
    59 		}
       
    60 		break;
       
    61 	case 4:
       
    62 		((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0573"));
       
    63 		TRAPD(err1, INC088856_TestL());
       
    64 		TEST(err1 == KErrNone);
       
    65 		break;
       
    66  	case 5:
       
    67  		((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0615"));
       
    68 		TestDestroyBitmapWhileBeingBackgroundCompressedL();
       
    69 		break;
       
    70 	case 6:
       
    71 		((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0616"));
       
    72 		TestBackgroundCompressionThreadPriorityInheritanceL();
       
    73 		break;
       
    74 	case 7:
       
    75 		((CTCompressedStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
       
    76 		((CTCompressedStep*)iStep)->CloseTMSGraphicsStep();
       
    77 		TestComplete();
       
    78 		break;	
       
    79 		}
       
    80 	((CTCompressedStep*)iStep)->RecordTestResultL();
       
    81     }
       
    82 
       
    83 /**
       
    84 	@SYMTestCaseID
       
    85 	GRAPHICS-FBSERV-0571
       
    86 
       
    87 	@SYMTestCaseDesc
       
    88 	Tests compression of bitmaps in RAM and ROM.
       
    89 
       
    90 	@SYMTestActions
       
    91 	Four bitmaps are loaded. One compressed and one
       
    92 	uncompressed from ROM and from RAM. The bitmap
       
    93 	in RAM is tested if it can be compressed successfully.
       
    94 	The bitmap in ROM should fail when tried to be compressed.
       
    95 	All of the bitmaps are then tried to be BitBlt.	
       
    96 	
       
    97 	@SYMTestExpectedResults
       
    98 	Test should pass
       
    99 */
       
   100 void CTCompressed::RunTestL()
       
   101     {
       
   102     TInt skipRomBitmapTests = EFalse;
       
   103 	TUint32* romAddress = NULL;
       
   104 	if(!CFbsBitmap::IsFileInRom(KRomNotCompressed, romAddress)) //any ROM bitmap
       
   105 		{
       
   106 		INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
       
   107 				&KRomNotCompressed);
       
   108 		INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
       
   109 		skipRomBitmapTests = ETrue;
       
   110 		}
       
   111     
       
   112 	TBuf<64> romNotCompressed(KRomNotCompressed);
       
   113 	TBuf<64> romCompressed(KRomCompressed);
       
   114 	TBuf<64> fileNotCompressed(KFileNotCompressed);
       
   115 	TBuf<64> fileCompressed(KFileCompressed);
       
   116 
       
   117 	TInt ret = KErrNone;
       
   118 	CFbsBitmap rom;
       
   119 	CFbsBitmap romcomp;
       
   120 
       
   121 	if(!skipRomBitmapTests)
       
   122 		{
       
   123 		TEST(rom.Load(romNotCompressed, 0, EFalse)== KErrNone);
       
   124 		TEST(romcomp.Load(romCompressed, 0, EFalse)== KErrNone);
       
   125 
       
   126 		INFO_PRINTF1(_L("Check compressing of ROM bitmaps causes error.\r\n"));
       
   127 		ret = rom.Compress();
       
   128 		TEST(ret == KErrAccessDenied); //cannot compress bitmaps in ROM
       
   129 		TEST(rom.IsCompressedInRAM());
       
   130 		}
       
   131 	
       
   132 	CFbsBitmap file;
       
   133 	CFbsBitmap filecomp;
       
   134 	TEST(file.Load(fileNotCompressed, 0, EFalse)== KErrNone);
       
   135 	TEST(filecomp.Load(fileCompressed, 0, EFalse)== KErrNone);
       
   136 	
       
   137 	INFO_PRINTF1(_L("Check compressing of RAM files is OK.\r\n"));
       
   138 	CFbsBitmap ram;
       
   139 	ret=ram.Load(fileNotCompressed,0,EFalse);
       
   140 	TEST(ret == KErrNone);
       
   141 	ret = ram.Compress();
       
   142 	TEST(ret == KErrNone); //can compress bitmaps in RAM
       
   143 	TEST(ram.IsCompressedInRAM());
       
   144 	
       
   145 	INFO_PRINTF1(_L("Check compressing a created EColor256 bitmap.\r\n"));
       
   146 	CFbsBitmapEx created;
       
   147 	ret=created.Create(TSize(200,200),EColor256);
       
   148 	TEST(ret==KErrNone);
       
   149 	
       
   150 	// This makes sure we can compress it...
       
   151 	BlankBitmap(created);
       
   152 
       
   153 	ret = created.Compress();
       
   154 	TEST(ret==KErrNone);
       
   155 	TEST(created.IsCompressedInRAM());
       
   156 
       
   157 	INFO_PRINTF1(_L("Check compressing a created EColor24MU bitmap.\r\n"));
       
   158 	CFbsBitmapEx created24MU;
       
   159 	ret=created24MU.Create(TSize(200,200),EColor16MU);
       
   160 	TEST(ret==KErrNone);
       
   161 	
       
   162 	// This makes sure we can compress it...
       
   163 	BlankBitmap(created24MU);
       
   164 
       
   165 	ret = created24MU.Compress();
       
   166 	TEST(ret==KErrNone);
       
   167 	TEST(created24MU.IsCompressedInRAM());
       
   168 
       
   169 	INFO_PRINTF1(_L("Try bitblt on all bitmaps"));
       
   170 	for (TInt mode = EGray2; mode < EColorLast; mode++)
       
   171 		{
       
   172 		if(!skipRomBitmapTests)
       
   173 			{
       
   174 			INFO_PRINTF2(_L("BitBlt rom with %d display mode.\r\n"), mode);
       
   175 			TestBitBltL(rom,      TDisplayMode(mode));
       
   176 			INFO_PRINTF2(_L("BitBlt romcomp with %d display mode.\r\n"), mode);
       
   177 			TestBitBltL(romcomp,  TDisplayMode(mode));
       
   178 			}
       
   179 		INFO_PRINTF2(_L("BitBlt file with %d display mode.\r\n"), mode);
       
   180 		TestBitBltL(file,     TDisplayMode(mode));
       
   181 		INFO_PRINTF2(_L("BitBlt filecomp with %d display mode.\r\n"), mode);
       
   182 		TestBitBltL(filecomp, TDisplayMode(mode));
       
   183 		INFO_PRINTF2(_L("BitBlt ram with %d display mode.\r\n"), mode);
       
   184 		TestBitBltL(ram,      TDisplayMode(mode));
       
   185 		INFO_PRINTF2(_L("BitBlt created with %d display mode.\r\n"), mode);
       
   186 		TestBitBltL(created,  TDisplayMode(mode));
       
   187 		INFO_PRINTF2(_L("BitBlt 24MU created bitmap with %d display mode.\r\n"), mode);
       
   188 		TestBitBltL(created24MU,  TDisplayMode(mode));
       
   189 		}
       
   190 	}
       
   191 
       
   192 
       
   193 
       
   194 /**
       
   195 	@SYMTestCaseID
       
   196 	GRAPHICS-FBSERV-0572
       
   197 
       
   198 	@SYMTestCaseDesc
       
   199 	Testcode to check for fix to defect EXT-5DXGK6 Bitmap 
       
   200 	compression causes crash when loading skins.
       
   201 	Its not a conclusive test as it depends on where the 
       
   202 	bitmap is loaded into memory and if there is 
       
   203 	memory allocated at the end of the bitmap.
       
   204 
       
   205 	@SYMTestActions
       
   206 	
       
   207 	@SYMTestExpectedResults
       
   208 	Test should pass
       
   209 */
       
   210 void CTCompressed::DefectFix_EXT5DXGK6_L()
       
   211 	{
       
   212 	CFbsBitmapEx bmp1;
       
   213 	TSize size(1000,1);
       
   214 	TInt ret=bmp1.Create(size,EGray2);
       
   215 	TEST(ret==KErrNone);
       
   216 	BlankBitmap(bmp1);
       
   217 //
       
   218 	// calculate the size of the destination scan line in bytes
       
   219 	// + 31 to pad to 4 byte boundary; 8 bits in a byte
       
   220 	TInt source_buffer_size = (size.iWidth + 31) / 8 ;
       
   221 	TUint8* buffer = new(ELeave) TUint8[source_buffer_size];
       
   222 	TPtr8 source_ptr(buffer,source_buffer_size,source_buffer_size);
       
   223 	
       
   224 	for(TInt ii = 0; ii<source_buffer_size; ++ii)
       
   225 		{
       
   226 		if(ii%2)
       
   227 			source_ptr[ii] = 2;
       
   228 		else
       
   229 			source_ptr[ii] = 3;
       
   230 		}
       
   231 
       
   232 	source_ptr[source_buffer_size-1] = 5;
       
   233 	source_ptr[source_buffer_size-2] = 5;
       
   234 	source_ptr[source_buffer_size-3] = 5;
       
   235 	source_ptr[source_buffer_size-4] = 4;
       
   236 	bmp1.SetScanLine(source_ptr,0);
       
   237 
       
   238 	delete [] buffer;
       
   239 	bmp1.Compress();
       
   240 	}
       
   241 
       
   242 /**
       
   243  * @SYMTestCaseID GRAPHICS-FBSERV-0500
       
   244  *
       
   245  * @SYMDEF INC082713
       
   246  *
       
   247  * @SYMTestCaseDesc Test RLE compression algorithm of EColor16MU and EColor16MA bitmaps.
       
   248  *
       
   249  * @SYMTestPriority Critical
       
   250  *
       
   251  * @SYMTestStatus Implemented
       
   252  *
       
   253  * @SYMTestActions The following test checks a corner-case of the algorithm triggered by a specific pixel pattern.
       
   254  *
       
   255  * The corner case is triggered when the input to the compression function ends in a run of equal pixels, 
       
   256  * terminated by a single pixel that is different i.e. ...rrrrrrrrrrrrrrrg 
       
   257  * where we have a run of equal (red) pixels followed by a green pixel, which is the last pixel in the 
       
   258  * bitmap (or the scanline, depending on how the data is being compressed).
       
   259  *
       
   260  * This test case performs the following:
       
   261  * 1) Creates a bitmap in the display mode and of size specified in function args.
       
   262  * This size must be large enough to trigger the compression when requested.
       
   263  * 2) Creates a scanline the width of this bitmap, which is a run of equal pixels, and 
       
   264  * then sets the last pixel to be different.
       
   265  * 3) Sets the last scanline of the bitmap to the scanline we have just created. 
       
   266  * This means that the last scanline of the bitmap conforms to the corner-case pattern.
       
   267  * 4) Compresses the bitmap
       
   268  * 5) Checks the compression has been successful
       
   269  * 6) Retrieves the last scanline of the bitmap and compares it with the original one
       
   270  * to verify that the compression of data has been successful.
       
   271  *
       
   272  * @SYMTestExpectedResults
       
   273  * The compression should occur successfully without panicking.
       
   274  * The scanline retrieved from the compressed version of the bitmap should match
       
   275  * the original scanline created.
       
   276  */
       
   277 void CTCompressed::DefectFix_INC082713_L(const TDisplayMode aDispMode, const TSize aBitmapSize)
       
   278 	{
       
   279 	// *** This function assumes that pixels are stored as 32 bit words ***
       
   280 	// *** for EColor16MU and EColor16MA bitmaps                        ***
       
   281 	switch(aDispMode)
       
   282 		{
       
   283 	case EColor16MU:
       
   284 		INFO_PRINTF1(_L("Check compression algorithm corner case for EColor16MU bitmap.\r\n"));
       
   285 		break;
       
   286 	case EColor16MA:
       
   287 		INFO_PRINTF1(_L("Check compression algorithm corner case for EColor16MA bitmap.\r\n"));
       
   288 		break;
       
   289 	default:
       
   290 		INFO_PRINTF1(_L("Unsupported display mode for test"));
       
   291 		return;
       
   292 		}
       
   293 
       
   294 	CFbsBitmap bitmap;
       
   295 	TInt ret=bitmap.Create(aBitmapSize,aDispMode);
       
   296 	TEST(ret==KErrNone);
       
   297 
       
   298 	TInt widthInPixels = bitmap.SizeInPixels().iWidth;
       
   299 	TInt heightInPixels = bitmap.SizeInPixels().iHeight;
       
   300 	TInt scanLineByteLength = bitmap.ScanLineLength(widthInPixels, aDispMode);
       
   301 	TUint32* buffer = (TUint32*)User::AllocLC(scanLineByteLength);
       
   302 
       
   303 	// Breaking from a run of equal pixels
       
   304 	// i.e. rrrrrrr...rrrrrrrrg
       
   305 	for (TInt ii = 0; ii < widthInPixels; ii++)
       
   306 		{
       
   307 		buffer[ii] = 0xc6ebff;
       
   308 		}
       
   309 	// Last pixel differs - must be able to re-enter loop when at last pixel
       
   310 	buffer[widthInPixels - 1] = 0xcee7ff;
       
   311 
       
   312 	TPtr8 scanline((TUint8*)buffer ,scanLineByteLength,scanLineByteLength);
       
   313 
       
   314 	bitmap.SetScanLine(scanline, heightInPixels - 1);
       
   315 
       
   316 	INFO_PRINTF1(_L("Compressing bitmap"));
       
   317 	ret = bitmap.Compress();
       
   318 	TEST(ret==KErrNone);
       
   319 	TEST(bitmap.IsCompressedInRAM());
       
   320 
       
   321 	// Retrieve the scanline from the compressed bitmap and compare with original
       
   322 	// in order to test whether the scanline is correctly compressed
       
   323 	INFO_PRINTF1(_L("Retrieving scanline from compressed bitmap"));
       
   324 
       
   325 	TUint32* readbackbuffer = (TUint32*)User::AllocLC(scanLineByteLength);
       
   326 	TPtr8 readbackscanline((TUint8*)readbackbuffer ,scanLineByteLength,scanLineByteLength);
       
   327 	readbackscanline.Fill(0xff);
       
   328 	bitmap.GetScanLine(readbackscanline,TPoint(0,heightInPixels - 1),widthInPixels, aDispMode);
       
   329 
       
   330 	INFO_PRINTF1(_L("Comparing scanlines\r\n"));
       
   331 	// Compare the original scanline with the one retrieved from the compressed version
       
   332 	switch(aDispMode)
       
   333 		{
       
   334 	case EColor16MU:
       
   335 		{		
       
   336 		TBool result = ETrue;
       
   337 		for (TInt ii = 0; ii < widthInPixels; ii++)
       
   338 			{
       
   339 			// Must mask off top bits (as we can ignore them, since we have no alpha channel)
       
   340 			TUint32 original = buffer[ii] & 0x00ffffff;
       
   341 			TUint32 readback = readbackbuffer[ii] & 0x00ffffff;
       
   342 			result = result && (original == readback);
       
   343 			}
       
   344 		TEST(result);
       
   345 		}
       
   346 		break;
       
   347 	case EColor16MA:
       
   348 		ret = Mem::Compare((TUint8*)buffer, scanLineByteLength, (TUint8*)readbackbuffer, scanLineByteLength);
       
   349 		// Mem::Compare returns 0 if the two scanlines are equal
       
   350 		TEST(ret == 0);
       
   351 		break;
       
   352 	default:
       
   353 		INFO_PRINTF1(_L("Unsupported display mode for test"));
       
   354 		break;
       
   355 		}
       
   356 
       
   357 	CleanupStack::PopAndDestroy(2, buffer);
       
   358 	}
       
   359 
       
   360 void CTCompressed::TestBitBltL(CFbsBitmap& aBmp, TDisplayMode aDispMode)
       
   361 	{
       
   362 	CFbsScreenDevice* scd = 0;
       
   363 	TRAPD(ret, scd = CFbsScreenDevice::NewL(_L("scdv"),aDispMode));
       
   364 	if (!scd)
       
   365 		{
       
   366 		WARN_PRINTF3(_L("Could not create screen device in %d mode, reason=%d.\r\n"), aDispMode, ret);
       
   367 		return;
       
   368 		}
       
   369 	CleanupStack::PushL(scd);
       
   370 	
       
   371 	scd->ChangeScreenDevice(NULL);
       
   372 	CFbsBitGc* sgc;
       
   373 	if (scd->CreateContext((CGraphicsContext*&)sgc)==KErrNone) 
       
   374 		{
       
   375 		CleanupStack::PushL(sgc);
       
   376 
       
   377 		TSize halfScreen = scd->SizeInPixels();
       
   378 		halfScreen.iWidth /= 2;
       
   379 
       
   380 		INFO_PRINTF1(_L("BitBlt..."));
       
   381 		sgc->BitBlt(TPoint(halfScreen.iWidth,0),&aBmp);
       
   382 		INFO_PRINTF1(_L("worked\r\n"));
       
   383 		
       
   384 		CleanupStack::PopAndDestroy(sgc);
       
   385 		}
       
   386 	else
       
   387 		{
       
   388 		INFO_PRINTF2(_L("Could not create context in %d mode.\r\n"), aDispMode);
       
   389 		}
       
   390 	CleanupStack::PopAndDestroy(scd);
       
   391 	}
       
   392 
       
   393 /**
       
   394 	@SYMTestCaseID
       
   395 	GRAPHICS-FBSERV-0573
       
   396 
       
   397 	@SYMDEF INC088856
       
   398 
       
   399 	@SYMTestCaseDesc
       
   400 	Verifies defect INC088856. Checks the 
       
   401 	updated padding value before compression for
       
   402 	256 gray scale and 64k colour.
       
   403 
       
   404 	@SYMTestActions
       
   405 	Creates a bitmap. Gets the bitmaps scanline length.
       
   406 	Locks the heap. Retrieves the bitmaps data address.
       
   407 	Unlocks the heap. Then for both 256 gray scale and 64k colour
       
   408 	it checks the padding after compression matches before compression.
       
   409 	
       
   410 	
       
   411 	@SYMTestExpectedResults
       
   412 	Test should pass
       
   413 */
       
   414 void CTCompressed::INC088856_TestL()
       
   415 	{
       
   416 	INFO_PRINTF1(_L("Check updated Padding value in before compression \r\n"));
       
   417 	
       
   418 	INFO_PRINTF1(_L("Check updated Padding value for EGray256 \r\n"));
       
   419 	DoUpdateOnPadding(TSize(5,3),EGray256);
       
   420 	DoUpdateOnPadding(TSize(25,43),EGray256);
       
   421 
       
   422 	INFO_PRINTF1(_L("Check updated Padding value for EColor64K \r\n"));
       
   423 	DoUpdateOnPadding(TSize(5,3),EColor64K);
       
   424 	DoUpdateOnPadding(TSize(25,43),EColor64K);
       
   425 	}
       
   426 
       
   427 void CTCompressed::DoUpdateOnPadding(const TSize aSize, const TDisplayMode aDispMode)
       
   428 	{
       
   429 	CFbsBitmapEx bmp1;
       
   430 	TInt ret=bmp1.Create(aSize,aDispMode);
       
   431 	TEST(ret==KErrNone);
       
   432 	
       
   433 	TInt dataLength = CFbsBitmap::ScanLineLength(aSize.iWidth, bmp1.DisplayMode()) * aSize.iHeight;
       
   434 	
       
   435 	bmp1.LockHeap();
       
   436 	TUint8* srcBits = (TUint8*)bmp1.DataAddress();
       
   437 	bmp1.UnlockHeap();
       
   438 	TInt val=1,pos=0;
       
   439 	switch (aDispMode)
       
   440 		{
       
   441 	case EGray256:
       
   442 		{
       
   443 		TUint8* bmpBits = srcBits;
       
   444 		TUint8* bmpBitsLimit = srcBits + dataLength;
       
   445 		while(bmpBits<bmpBitsLimit)
       
   446 			{
       
   447 			if(pos++ < aSize.iWidth)
       
   448 				{
       
   449 				*bmpBits++ = val;
       
   450 				}
       
   451 			else 
       
   452 				{
       
   453 				bmpBits += 3;
       
   454 				val++;
       
   455 				pos=0;
       
   456 				}
       
   457 			}
       
   458 		}
       
   459 		break;
       
   460 	case EColor64K:
       
   461 		{
       
   462 		TUint16* bmpBits = (TUint16*)srcBits;
       
   463 		TUint16* bmpBitsLimit = (TUint16*)(srcBits + dataLength);
       
   464 		while(bmpBits<bmpBitsLimit)
       
   465 			{
       
   466 			if(pos++ < aSize.iWidth)
       
   467 				{
       
   468 				*bmpBits++ = val;
       
   469 				}
       
   470 			else 
       
   471 				{
       
   472 				bmpBits++;
       
   473 				val++;
       
   474 				pos=0;
       
   475 				}
       
   476 			}
       
   477 		}
       
   478 		break;
       
   479 	default:
       
   480 		break;
       
   481 		}
       
   482 
       
   483 	bmp1.Compress();
       
   484 	TInt stride = bmp1.DataStride();
       
   485 	TUint8* dataPtr = (TUint8*)bmp1.DataAddress();
       
   486 	switch(aDispMode)
       
   487 		{
       
   488 	case EGray256:
       
   489 		{
       
   490 		for (TInt row = 0; row < aSize.iHeight - 1; ++row)
       
   491 			{
       
   492 			TEST(*dataPtr++ == stride - 1);
       
   493 			TEST(*dataPtr++ == row + 1);
       
   494 			}
       
   495 		break;
       
   496 		}
       
   497 	case EColor64K:
       
   498 		{
       
   499 		for (TInt row = 0; row < aSize.iHeight - 1; ++row)
       
   500 			{
       
   501 			TEST(*dataPtr++ == stride / 2 - 1);
       
   502 			TEST(*dataPtr++ == row + 1);
       
   503 			TEST(*dataPtr++ == 0);
       
   504 			}
       
   505 		}
       
   506 		break;
       
   507 	default:
       
   508 		break;
       
   509 		}
       
   510 	}
       
   511 
       
   512 /**
       
   513  * @SYMTestCaseID GRAPHICS-FBSERV-0615
       
   514  *
       
   515  * @SYMDEF PDEF115511
       
   516  *
       
   517  * @SYMTestCaseDesc
       
   518  * Test Fbserv robustness when bitmaps are destroyed while they are being background compressed
       
   519  *
       
   520  * @SYMTestPriority High
       
   521  *
       
   522  * @SYMTestStatus Implemented
       
   523  *
       
   524  * @SYMTestActions
       
   525  * Preform various scenarios to create bitmaps, compress them in background and then destroy the 
       
   526  * bitmaps without waiting the compression to complete.
       
   527  *
       
   528  * @SYMTestExpectedResults
       
   529  * Fbserv does not crash because of misfirig its background compression active object
       
   530  */
       
   531 void CTCompressed::TestDestroyBitmapWhileBeingBackgroundCompressedL()
       
   532 	{
       
   533 	const TInt KNumOfBitmaps = 1000;
       
   534 	const TSize KSize(1,1);
       
   535 	const TDisplayMode KMode = EColor64K;
       
   536 	CFbsBitmap* bitmaps[KNumOfBitmaps];
       
   537 
       
   538 	// TestCase #1
       
   539 	// Create N bitmap instances, compress them in background and destroy them in-reverse order
       
   540 	// without waiting compression to complete
       
   541 	INFO_PRINTF2(_L("Create %d bitmaps,compress them in background and destroy in reverse order"), KNumOfBitmaps);
       
   542 
       
   543 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   544 		{
       
   545 		bitmaps[idx] = new(ELeave) CFbsBitmap;
       
   546 		CleanupStack::PushL(bitmaps[idx]);
       
   547 		User::LeaveIfError(bitmaps[idx]->Create(KSize, KMode));
       
   548 		}
       
   549 
       
   550 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   551 		{
       
   552 		User::LeaveIfError(bitmaps[idx]->CompressInBackground());
       
   553 		}
       
   554 
       
   555 	// Delete bitmaps in reverse order
       
   556 	CleanupStack::PopAndDestroy(KNumOfBitmaps, bitmaps[0]);
       
   557 
       
   558 	// TestCase #2
       
   559 	// Create N bitmap instances, compress them in background and destroy them in the compression order
       
   560 	// without waiting compression to complete
       
   561 	INFO_PRINTF2(_L("Create %d bitmaps,compress them in background and destroy in forward order"), KNumOfBitmaps);
       
   562 
       
   563 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   564 		{
       
   565 		bitmaps[idx] = new(ELeave) CFbsBitmap;
       
   566 		CleanupStack::PushL(bitmaps[idx]);
       
   567 		User::LeaveIfError(bitmaps[idx]->Create(KSize, KMode));
       
   568 		}
       
   569 
       
   570 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   571 		{
       
   572 		User::LeaveIfError(bitmaps[idx]->CompressInBackground());
       
   573 		}
       
   574 
       
   575 	// Delete bitmaps in compression order
       
   576 	CleanupStack::Pop(KNumOfBitmaps, bitmaps[0]);	
       
   577 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   578 		{
       
   579 		delete bitmaps[idx];
       
   580 		}
       
   581 	
       
   582 	// TestCase #3
       
   583 	// Create N bitmap instances, compress them in background and destroy them in random order
       
   584 	// without waiting compression to complete
       
   585 	INFO_PRINTF2(_L("Create %d bitmaps,compress them in background and destroy in random order"), KNumOfBitmaps);
       
   586 
       
   587 	TInt randomOrder[KNumOfBitmaps];
       
   588 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   589 		{
       
   590 		bitmaps[idx] = new(ELeave) CFbsBitmap;
       
   591 		CleanupStack::PushL(bitmaps[idx]);
       
   592 		User::LeaveIfError(bitmaps[idx]->Create(KSize, KMode));
       
   593 		randomOrder[idx] = idx;
       
   594 		}
       
   595 	// Randomise deletion order
       
   596 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   597 		{
       
   598 		TInt swap = Math::Random()%KNumOfBitmaps;
       
   599 		TInt tmp = randomOrder[idx];
       
   600 		randomOrder[idx] = randomOrder[swap];
       
   601 		randomOrder[swap] = tmp;
       
   602 		}
       
   603 
       
   604 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   605 		{
       
   606 		User::LeaveIfError(bitmaps[idx]->CompressInBackground());
       
   607 		}
       
   608 
       
   609 	// Delete bitmaps in random order
       
   610 	CleanupStack::Pop(KNumOfBitmaps, bitmaps[0]);	
       
   611 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   612 		{
       
   613 		delete bitmaps[randomOrder[idx]];
       
   614 		bitmaps[randomOrder[idx]] = NULL;
       
   615 		}
       
   616 	// Test all bitmaps has been destroyed
       
   617 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   618 		{
       
   619 		TEST(bitmaps[idx]==NULL);
       
   620 		}
       
   621 
       
   622 	// TestCase #4
       
   623 	// Create bitmap, compress it in background and immediately destroyed without waiting compression
       
   624 	// to complete
       
   625 	INFO_PRINTF2(_L("Create bitmap,compress in background and immediately destroyed. Repeat %d times"), KNumOfBitmaps);
       
   626 
       
   627 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   628 		{
       
   629 		CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
       
   630 		CleanupStack::PushL(bitmap);
       
   631 		User::LeaveIfError(bitmap->Create(KSize, KMode));
       
   632 		User::LeaveIfError(bitmap->CompressInBackground());
       
   633 		CleanupStack::PopAndDestroy(bitmap);
       
   634 		}
       
   635 
       
   636 	// TestCase #5
       
   637 	// Similar from #4 but executed from two different threads
       
   638 	INFO_PRINTF2(_L("Create bitmap,compress in background and immediately destroyed from 2 different threads. Repeat %d times"), KNumOfBitmaps);
       
   639 
       
   640 	const TInt KStackSize = 4096;
       
   641 	const TInt KMinHeapSize = 4096;
       
   642 	const TInt KMaxHeapSize = 1024*1024;
       
   643 	RThread t1;
       
   644 	User::LeaveIfError(t1.Create(_L("bgCompThreadFunc#1"), CTCompressed::BgCompThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL));
       
   645 	RThread t2;
       
   646 	User::LeaveIfError(t2.Create(_L("bgCompThreadFunc#2"), CTCompressed::BgCompThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL));
       
   647 
       
   648 	TRequestStatus s1;
       
   649 	TRequestStatus s2;
       
   650 	t1.Logon(s1);
       
   651 	t2.Logon(s2);
       
   652 
       
   653 	t1.Resume();
       
   654 	t2.Resume();
       
   655 	User::WaitForRequest(s1);
       
   656 	User::WaitForRequest(s2);
       
   657 
       
   658 	t1.Close();
       
   659 	t2.Close();
       
   660 	}
       
   661 
       
   662 TInt CTCompressed::BgCompThreadFunc(TAny*)
       
   663 	{
       
   664 	const TInt KNumOfBitmaps = 1000;
       
   665 	const TSize KSize(1,1);
       
   666 	const TDisplayMode KMode = EColor64K;
       
   667 
       
   668 	// No need to worries with cleanup stack and trap as resources will be freed if the thread
       
   669 	// running this functions dies, panics or leaves.
       
   670 
       
   671 	RFbsSession::Connect();
       
   672 
       
   673 	for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
       
   674 		{
       
   675 		CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
       
   676 		User::LeaveIfError(bitmap->Create(KSize, KMode));
       
   677 		User::LeaveIfError(bitmap->CompressInBackground());
       
   678 		delete bitmap;
       
   679 		}
       
   680 
       
   681 	RFbsSession::Disconnect();
       
   682 	return KErrNone;
       
   683 	}
       
   684 
       
   685 
       
   686 /**
       
   687  * @SYMTestCaseID GRAPHICS-FBSERV-0616
       
   688  *
       
   689  * @SYMDEF INC123238
       
   690  *
       
   691  * @SYMTestCaseDesc
       
   692  * Test Fbserv bitmap's priority inversion when we use background compression against a long running thread
       
   693  *
       
   694  * @SYMTestPriority High
       
   695  *
       
   696  * @SYMTestStatus Implemented
       
   697  *
       
   698  * @SYMTestActions
       
   699  * Create a thread which creates a bitmap and makes a call to background compression. Once this thread resumed,
       
   700  * make the current thread as busy by doing some long running task and test the exit status of the bitmap compression thread.
       
   701  *
       
   702  * @SYMTestExpectedResults
       
   703  * Fbserv does priority inheritance and therefore protect against priority inversion, so the thread function will
       
   704  * do backgroud compression and the thread will exit successfully, which will pass the test. If it is not protect
       
   705  * against priority inversion with in 30 seconds(approximately) the test will fail without doing background compression.
       
   706  */
       
   707 void CTCompressed::TestBackgroundCompressionThreadPriorityInheritanceL()
       
   708 	{
       
   709 	const TInt KStackSize = 4096;
       
   710 	const TInt KMinHeapSize = 4096;
       
   711 	const TInt KMaxHeapSize = 1024*1024;
       
   712 	const TInt KMaxViewChangeTime = 2000;
       
   713 	
       
   714 	INFO_PRINTF1(_L("Test case for Background Compression Thread Priority Inheritance\r\n"));	
       
   715 	//Create and start a thread which create a bitmap and calls CompressInBackground
       
   716 	RThread thread1;
       
   717 	User::LeaveIfError(thread1.Create(_L("CompressBgThreadFunc"), CTCompressed::CompressBgThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL));
       
   718 	thread1.Resume();
       
   719 	TUint startTime = User::TickCount();
       
   720 	
       
   721 	//Start a infinite running loop to make current thread as a busy and long running thread...
       
   722 	for (;;)
       
   723 		{
       
   724 		TExitType exitType = thread1.ExitType();
       
   725 		if(exitType != EExitPending)
       
   726 			{
       
   727 			TInt exitReason = thread1.ExitReason();
       
   728 			TEST(exitType == EExitKill);
       
   729 			TEST(exitReason == KErrNone);
       
   730 			break;
       
   731 			}
       
   732 		TUint stopTime = User::TickCount();
       
   733 		if((stopTime - startTime) > KMaxViewChangeTime) //Check for the busy task is running for more than 30 seconds...
       
   734 			{
       
   735 			TEST(EFalse);
       
   736 			thread1.Terminate(KErrGeneral);
       
   737 			break;
       
   738 			}
       
   739 		}
       
   740 	thread1.Close();
       
   741 	}
       
   742 
       
   743 /*
       
   744  Thread function used from the test case TestBackgroundCompressionThreadPriorityInheritanceL
       
   745  */
       
   746 TInt CTCompressed::CompressBgThreadFunc(TAny*)
       
   747 	{
       
   748 	const TSize KSize(100, 100);
       
   749 	const TDisplayMode KMode = EColor64K;
       
   750 
       
   751 	TInt err = RFbsSession::Connect();
       
   752 	if (err != KErrNone)
       
   753 		return err;
       
   754 	CFbsBitmap* bitmap = new CFbsBitmap;
       
   755 	if (!bitmap)
       
   756 		return KErrNoMemory;
       
   757 	err = bitmap->Create(KSize, KMode);
       
   758 	if (err != KErrNone)
       
   759 		return err;
       
   760 	err = bitmap->CompressInBackground();
       
   761 	if (err != KErrNone)
       
   762 		return err;
       
   763 	delete bitmap;
       
   764 
       
   765 	RFbsSession::Disconnect();
       
   766 	return KErrNone;
       
   767 	}
       
   768 
       
   769 //--------------
       
   770 __CONSTRUCT_STEP__(Compressed)