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