diff -r 000000000000 -r bde4ae8d615e os/graphics/fbs/fontandbitmapserver/tfbs/tcompressed.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/graphics/fbs/fontandbitmapserver/tfbs/tcompressed.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,770 @@ +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#include +#include +#include "tcompressed.h" + +CTCompressed::CTCompressed(CTestStep* aStep) : + CTGraphicsBase(aStep) + { + } + +void CTCompressed::BlankBitmap(CFbsBitmapEx& aBitmap) + { + TSize size = aBitmap.SizeInPixels(); + TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight; + aBitmap.LockHeap(); + Mem::FillZ((TUint8*)aBitmap.DataAddress(),dataLength); + aBitmap.UnlockHeap(); + } + +void CTCompressed::RunTestCaseL(TInt aCurTestCase) + { + ((CTCompressedStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); + switch(aCurTestCase) + { + case 1: + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0571")); + TRAPD(err, RunTestL()); + TEST(err == KErrNone); + break; + case 2: + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0572")); + TRAP(err, DefectFix_EXT5DXGK6_L()); + TEST(err == KErrNone); + break; + case 3: + { + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0500")); + // Set size of bitmap large enough to warrant compression + const TSize KBitmapSize(200,200); + INFO_PRINTF1(_L("Test case for INC082713\r\n")); + TRAP(err, DefectFix_INC082713_L(EColor16MU, KBitmapSize)); + TEST(err == KErrNone); + TRAP(err, DefectFix_INC082713_L(EColor16MA, KBitmapSize)); + TEST(err == KErrNone); + } + break; + case 4: + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0573")); + TRAPD(err1, INC088856_TestL()); + TEST(err1 == KErrNone); + break; + case 5: + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0615")); + TestDestroyBitmapWhileBeingBackgroundCompressedL(); + break; + case 6: + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0616")); + TestBackgroundCompressionThreadPriorityInheritanceL(); + break; + case 7: + ((CTCompressedStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); + ((CTCompressedStep*)iStep)->CloseTMSGraphicsStep(); + TestComplete(); + break; + } + ((CTCompressedStep*)iStep)->RecordTestResultL(); + } + +/** + @SYMTestCaseID + GRAPHICS-FBSERV-0571 + + @SYMTestCaseDesc + Tests compression of bitmaps in RAM and ROM. + + @SYMTestActions + Four bitmaps are loaded. One compressed and one + uncompressed from ROM and from RAM. The bitmap + in RAM is tested if it can be compressed successfully. + The bitmap in ROM should fail when tried to be compressed. + All of the bitmaps are then tried to be BitBlt. + + @SYMTestExpectedResults + Test should pass +*/ +void CTCompressed::RunTestL() + { + TInt skipRomBitmapTests = EFalse; + TUint32* romAddress = NULL; + if(!CFbsBitmap::IsFileInRom(KRomNotCompressed, romAddress)) //any ROM bitmap + { + INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."), + &KRomNotCompressed); + INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported.")); + skipRomBitmapTests = ETrue; + } + + TBuf<64> romNotCompressed(KRomNotCompressed); + TBuf<64> romCompressed(KRomCompressed); + TBuf<64> fileNotCompressed(KFileNotCompressed); + TBuf<64> fileCompressed(KFileCompressed); + + TInt ret = KErrNone; + CFbsBitmap rom; + CFbsBitmap romcomp; + + if(!skipRomBitmapTests) + { + TEST(rom.Load(romNotCompressed, 0, EFalse)== KErrNone); + TEST(romcomp.Load(romCompressed, 0, EFalse)== KErrNone); + + INFO_PRINTF1(_L("Check compressing of ROM bitmaps causes error.\r\n")); + ret = rom.Compress(); + TEST(ret == KErrAccessDenied); //cannot compress bitmaps in ROM + TEST(rom.IsCompressedInRAM()); + } + + CFbsBitmap file; + CFbsBitmap filecomp; + TEST(file.Load(fileNotCompressed, 0, EFalse)== KErrNone); + TEST(filecomp.Load(fileCompressed, 0, EFalse)== KErrNone); + + INFO_PRINTF1(_L("Check compressing of RAM files is OK.\r\n")); + CFbsBitmap ram; + ret=ram.Load(fileNotCompressed,0,EFalse); + TEST(ret == KErrNone); + ret = ram.Compress(); + TEST(ret == KErrNone); //can compress bitmaps in RAM + TEST(ram.IsCompressedInRAM()); + + INFO_PRINTF1(_L("Check compressing a created EColor256 bitmap.\r\n")); + CFbsBitmapEx created; + ret=created.Create(TSize(200,200),EColor256); + TEST(ret==KErrNone); + + // This makes sure we can compress it... + BlankBitmap(created); + + ret = created.Compress(); + TEST(ret==KErrNone); + TEST(created.IsCompressedInRAM()); + + INFO_PRINTF1(_L("Check compressing a created EColor24MU bitmap.\r\n")); + CFbsBitmapEx created24MU; + ret=created24MU.Create(TSize(200,200),EColor16MU); + TEST(ret==KErrNone); + + // This makes sure we can compress it... + BlankBitmap(created24MU); + + ret = created24MU.Compress(); + TEST(ret==KErrNone); + TEST(created24MU.IsCompressedInRAM()); + + INFO_PRINTF1(_L("Try bitblt on all bitmaps")); + for (TInt mode = EGray2; mode < EColorLast; mode++) + { + if(!skipRomBitmapTests) + { + INFO_PRINTF2(_L("BitBlt rom with %d display mode.\r\n"), mode); + TestBitBltL(rom, TDisplayMode(mode)); + INFO_PRINTF2(_L("BitBlt romcomp with %d display mode.\r\n"), mode); + TestBitBltL(romcomp, TDisplayMode(mode)); + } + INFO_PRINTF2(_L("BitBlt file with %d display mode.\r\n"), mode); + TestBitBltL(file, TDisplayMode(mode)); + INFO_PRINTF2(_L("BitBlt filecomp with %d display mode.\r\n"), mode); + TestBitBltL(filecomp, TDisplayMode(mode)); + INFO_PRINTF2(_L("BitBlt ram with %d display mode.\r\n"), mode); + TestBitBltL(ram, TDisplayMode(mode)); + INFO_PRINTF2(_L("BitBlt created with %d display mode.\r\n"), mode); + TestBitBltL(created, TDisplayMode(mode)); + INFO_PRINTF2(_L("BitBlt 24MU created bitmap with %d display mode.\r\n"), mode); + TestBitBltL(created24MU, TDisplayMode(mode)); + } + } + + + +/** + @SYMTestCaseID + GRAPHICS-FBSERV-0572 + + @SYMTestCaseDesc + Testcode to check for fix to defect EXT-5DXGK6 Bitmap + compression causes crash when loading skins. + Its not a conclusive test as it depends on where the + bitmap is loaded into memory and if there is + memory allocated at the end of the bitmap. + + @SYMTestActions + + @SYMTestExpectedResults + Test should pass +*/ +void CTCompressed::DefectFix_EXT5DXGK6_L() + { + CFbsBitmapEx bmp1; + TSize size(1000,1); + TInt ret=bmp1.Create(size,EGray2); + TEST(ret==KErrNone); + BlankBitmap(bmp1); +// + // calculate the size of the destination scan line in bytes + // + 31 to pad to 4 byte boundary; 8 bits in a byte + TInt source_buffer_size = (size.iWidth + 31) / 8 ; + TUint8* buffer = new(ELeave) TUint8[source_buffer_size]; + TPtr8 source_ptr(buffer,source_buffer_size,source_buffer_size); + + for(TInt ii = 0; iiChangeScreenDevice(NULL); + CFbsBitGc* sgc; + if (scd->CreateContext((CGraphicsContext*&)sgc)==KErrNone) + { + CleanupStack::PushL(sgc); + + TSize halfScreen = scd->SizeInPixels(); + halfScreen.iWidth /= 2; + + INFO_PRINTF1(_L("BitBlt...")); + sgc->BitBlt(TPoint(halfScreen.iWidth,0),&aBmp); + INFO_PRINTF1(_L("worked\r\n")); + + CleanupStack::PopAndDestroy(sgc); + } + else + { + INFO_PRINTF2(_L("Could not create context in %d mode.\r\n"), aDispMode); + } + CleanupStack::PopAndDestroy(scd); + } + +/** + @SYMTestCaseID + GRAPHICS-FBSERV-0573 + + @SYMDEF INC088856 + + @SYMTestCaseDesc + Verifies defect INC088856. Checks the + updated padding value before compression for + 256 gray scale and 64k colour. + + @SYMTestActions + Creates a bitmap. Gets the bitmaps scanline length. + Locks the heap. Retrieves the bitmaps data address. + Unlocks the heap. Then for both 256 gray scale and 64k colour + it checks the padding after compression matches before compression. + + + @SYMTestExpectedResults + Test should pass +*/ +void CTCompressed::INC088856_TestL() + { + INFO_PRINTF1(_L("Check updated Padding value in before compression \r\n")); + + INFO_PRINTF1(_L("Check updated Padding value for EGray256 \r\n")); + DoUpdateOnPadding(TSize(5,3),EGray256); + DoUpdateOnPadding(TSize(25,43),EGray256); + + INFO_PRINTF1(_L("Check updated Padding value for EColor64K \r\n")); + DoUpdateOnPadding(TSize(5,3),EColor64K); + DoUpdateOnPadding(TSize(25,43),EColor64K); + } + +void CTCompressed::DoUpdateOnPadding(const TSize aSize, const TDisplayMode aDispMode) + { + CFbsBitmapEx bmp1; + TInt ret=bmp1.Create(aSize,aDispMode); + TEST(ret==KErrNone); + + TInt dataLength = CFbsBitmap::ScanLineLength(aSize.iWidth, bmp1.DisplayMode()) * aSize.iHeight; + + bmp1.LockHeap(); + TUint8* srcBits = (TUint8*)bmp1.DataAddress(); + bmp1.UnlockHeap(); + TInt val=1,pos=0; + switch (aDispMode) + { + case EGray256: + { + TUint8* bmpBits = srcBits; + TUint8* bmpBitsLimit = srcBits + dataLength; + while(bmpBitsCreate(KSize, KMode)); + } + + for (TInt idx=0; idxCompressInBackground()); + } + + // Delete bitmaps in reverse order + CleanupStack::PopAndDestroy(KNumOfBitmaps, bitmaps[0]); + + // TestCase #2 + // Create N bitmap instances, compress them in background and destroy them in the compression order + // without waiting compression to complete + INFO_PRINTF2(_L("Create %d bitmaps,compress them in background and destroy in forward order"), KNumOfBitmaps); + + for (TInt idx=0; idxCreate(KSize, KMode)); + } + + for (TInt idx=0; idxCompressInBackground()); + } + + // Delete bitmaps in compression order + CleanupStack::Pop(KNumOfBitmaps, bitmaps[0]); + for (TInt idx=0; idxCreate(KSize, KMode)); + randomOrder[idx] = idx; + } + // Randomise deletion order + for (TInt idx=0; idxCompressInBackground()); + } + + // Delete bitmaps in random order + CleanupStack::Pop(KNumOfBitmaps, bitmaps[0]); + for (TInt idx=0; idxCreate(KSize, KMode)); + User::LeaveIfError(bitmap->CompressInBackground()); + CleanupStack::PopAndDestroy(bitmap); + } + + // TestCase #5 + // Similar from #4 but executed from two different threads + INFO_PRINTF2(_L("Create bitmap,compress in background and immediately destroyed from 2 different threads. Repeat %d times"), KNumOfBitmaps); + + const TInt KStackSize = 4096; + const TInt KMinHeapSize = 4096; + const TInt KMaxHeapSize = 1024*1024; + RThread t1; + User::LeaveIfError(t1.Create(_L("bgCompThreadFunc#1"), CTCompressed::BgCompThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL)); + RThread t2; + User::LeaveIfError(t2.Create(_L("bgCompThreadFunc#2"), CTCompressed::BgCompThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL)); + + TRequestStatus s1; + TRequestStatus s2; + t1.Logon(s1); + t2.Logon(s2); + + t1.Resume(); + t2.Resume(); + User::WaitForRequest(s1); + User::WaitForRequest(s2); + + t1.Close(); + t2.Close(); + } + +TInt CTCompressed::BgCompThreadFunc(TAny*) + { + const TInt KNumOfBitmaps = 1000; + const TSize KSize(1,1); + const TDisplayMode KMode = EColor64K; + + // No need to worries with cleanup stack and trap as resources will be freed if the thread + // running this functions dies, panics or leaves. + + RFbsSession::Connect(); + + for (TInt idx=0; idxCreate(KSize, KMode)); + User::LeaveIfError(bitmap->CompressInBackground()); + delete bitmap; + } + + RFbsSession::Disconnect(); + return KErrNone; + } + + +/** + * @SYMTestCaseID GRAPHICS-FBSERV-0616 + * + * @SYMDEF INC123238 + * + * @SYMTestCaseDesc + * Test Fbserv bitmap's priority inversion when we use background compression against a long running thread + * + * @SYMTestPriority High + * + * @SYMTestStatus Implemented + * + * @SYMTestActions + * Create a thread which creates a bitmap and makes a call to background compression. Once this thread resumed, + * make the current thread as busy by doing some long running task and test the exit status of the bitmap compression thread. + * + * @SYMTestExpectedResults + * Fbserv does priority inheritance and therefore protect against priority inversion, so the thread function will + * do backgroud compression and the thread will exit successfully, which will pass the test. If it is not protect + * against priority inversion with in 30 seconds(approximately) the test will fail without doing background compression. + */ +void CTCompressed::TestBackgroundCompressionThreadPriorityInheritanceL() + { + const TInt KStackSize = 4096; + const TInt KMinHeapSize = 4096; + const TInt KMaxHeapSize = 1024*1024; + const TInt KMaxViewChangeTime = 2000; + + INFO_PRINTF1(_L("Test case for Background Compression Thread Priority Inheritance\r\n")); + //Create and start a thread which create a bitmap and calls CompressInBackground + RThread thread1; + User::LeaveIfError(thread1.Create(_L("CompressBgThreadFunc"), CTCompressed::CompressBgThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL)); + thread1.Resume(); + TUint startTime = User::TickCount(); + + //Start a infinite running loop to make current thread as a busy and long running thread... + for (;;) + { + TExitType exitType = thread1.ExitType(); + if(exitType != EExitPending) + { + TInt exitReason = thread1.ExitReason(); + TEST(exitType == EExitKill); + TEST(exitReason == KErrNone); + break; + } + TUint stopTime = User::TickCount(); + if((stopTime - startTime) > KMaxViewChangeTime) //Check for the busy task is running for more than 30 seconds... + { + TEST(EFalse); + thread1.Terminate(KErrGeneral); + break; + } + } + thread1.Close(); + } + +/* + Thread function used from the test case TestBackgroundCompressionThreadPriorityInheritanceL + */ +TInt CTCompressed::CompressBgThreadFunc(TAny*) + { + const TSize KSize(100, 100); + const TDisplayMode KMode = EColor64K; + + TInt err = RFbsSession::Connect(); + if (err != KErrNone) + return err; + CFbsBitmap* bitmap = new CFbsBitmap; + if (!bitmap) + return KErrNoMemory; + err = bitmap->Create(KSize, KMode); + if (err != KErrNone) + return err; + err = bitmap->CompressInBackground(); + if (err != KErrNone) + return err; + delete bitmap; + + RFbsSession::Disconnect(); + return KErrNone; + } + +//-------------- +__CONSTRUCT_STEP__(Compressed)