os/graphics/windowing/windowserver/test/tauto/TFADINGBITMAP.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TFADINGBITMAP.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,250 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// The fix enables the fading effect with alpha-blending, which was not applied bofore.
    1.18 +// The test will load a bitmap and two different masks: on/off and alpha-blend.
    1.19 +// The bitmap will be masked with these masks and displayed before and after
    1.20 +// setting the fading effect.
    1.21 +// All different colour modes are being tested for both mask types.
    1.22 +// The test will check the colour of a specific pixel in the scene before and after the
    1.23 +// fading. The higher values in the After circle means that it has been highlighted.
    1.24 +// The result will be printed in wstest log file.
    1.25 +// 
    1.26 +//
    1.27 +
    1.28 +/**
    1.29 + @file
    1.30 + @test
    1.31 + @internalComponent - Internal Symbian test code
    1.32 +*/
    1.33 +
    1.34 +#include "TFADINGBITMAP.H"
    1.35 +
    1.36 +//===================================================
    1.37 +// CBaseWin Declaration
    1.38 +//===================================================
    1.39 +
    1.40 +CBaseWin::CBaseWin(): CTWin()
    1.41 +	{
    1.42 +	}
    1.43 +
    1.44 +CBaseWin::~CBaseWin()
    1.45 +	{
    1.46 +	delete iTempBitmap;
    1.47 +	delete iMaskGray256;
    1.48 +	delete iMaskGray2;
    1.49 +	delete iTempMask;
    1.50 +	delete iBitmap;
    1.51 +	}
    1.52 +
    1.53 +void CBaseWin::ConstructWinL(TPoint aPos, TSize aSize, TBool aVisible)
    1.54 +	{	
    1.55 +	/*** Setting up the window ***/
    1.56 +	iSize = aSize;
    1.57 +	SetUpL(aPos, aSize, TheClient->iGroup, *TheClient->iGc, aVisible);
    1.58 +	Win()->SetBackgroundColor(TRgb(20, 80, 20));	// dark green background
    1.59 +	BaseWin()->SetRequiredDisplayMode(EColor64K);
    1.60 +
    1.61 +	/*** 24 bit bitmap ***/
    1.62 +	// the original 24b bitmap to mask
    1.63 +	iTempBitmap = new (ELeave) CFbsBitmap();
    1.64 +	User::LeaveIfError(iTempBitmap->Load(_L("Z:\\WSTEST\\WSAUTOTEST.MBM"), EMbmWsautotestCircles24b));
    1.65 +	iBitmap = new (ELeave) CFbsBitmap();
    1.66 +
    1.67 +	/*** on/off mask ***/
    1.68 +	iMaskGray2 = new (ELeave) CFbsBitmap();
    1.69 +	User::LeaveIfError(iMaskGray2->Load(_L("Z:\\WSTEST\\WSAUTOTEST.MBM"), EMbmWsautotestCircles_mask2b));
    1.70 +
    1.71 +	/*** alpha-blend mask ***/
    1.72 +	// holds the 24bit copy of the alpha blend mask which will be 
    1.73 +	// copied into the proper Gray256 mask, iMaskGray256.
    1.74 +	iTempMask = new (ELeave) CFbsBitmap();
    1.75 +	User::LeaveIfError(iTempMask->Load(_L("Z:\\WSTEST\\WSAUTOTEST.MBM"), EMbmWsautotestCircles_mask256));	
    1.76 +	// alpha blend mask; copying its data from iTempMask
    1.77 +	iMaskGray256 = new (ELeave) CFbsBitmap();
    1.78 +	User::LeaveIfError(iMaskGray256->Create(iTempBitmap->SizeInPixels(),EGray256));
    1.79 +	CFbsBitmapDevice *dev = CFbsBitmapDevice::NewL(iMaskGray256);
    1.80 +	CleanupStack::PushL(dev);
    1.81 +	CFbsBitGc *gc;
    1.82 +	User::LeaveIfError(dev->CreateContext(gc));
    1.83 +	// performing the copying here
    1.84 +	gc->BitBlt(TPoint(0,0), iTempMask);
    1.85 +	// cleaning up
    1.86 +	CleanupStack::Pop();
    1.87 +	delete gc;
    1.88 +	gc = NULL;	
    1.89 +	delete dev;
    1.90 +	dev = NULL;	
    1.91 +	}
    1.92 +
    1.93 +void CBaseWin::Draw()
    1.94 +	{
    1.95 +	iGc->Clear();
    1.96 +
    1.97 +	// Font intialization
    1.98 +	CFont* myFont;    	
    1.99 +	_LIT(KMyFontName,"Swiss");
   1.100 +	TFontSpec myFontSpec = TFontSpec(KMyFontName,16); // to get smallest Swiss font
   1.101 +	TFontStyle style = TFontStyle (EPostureUpright, EStrokeWeightBold,   EPrintPosNormal);
   1.102 +	myFontSpec.iFontStyle = style;
   1.103 +	User::LeaveIfError(TheClient->iScreen->GetNearestFontInPixels(myFont, myFontSpec));
   1.104 +	iGc->UseFont(myFont);
   1.105 +	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
   1.106 +	iGc->SetPenColor(TRgb(255, 255, 255));
   1.107 +	
   1.108 +	// drawing text
   1.109 +	iGc->DrawText(_L("Fading = OFF"), TPoint(130,15));
   1.110 +	iGc->DrawText(_L("Fading = ON"),  TPoint(275,15));
   1.111 +	iGc->DrawText(_L("Alpha blend"), TPoint(15,90));
   1.112 +	iGc->DrawText(_L("on/off mask"),  TPoint(15,190));
   1.113 +	TBuf <30> displayMode(_L("Display Mode = "));
   1.114 +	displayMode.Append(iMode);	
   1.115 +	iGc->DrawText(displayMode, TPoint(385,100));		
   1.116 +	
   1.117 +	/*** drawing bitmap with its on/off mask and alpha-blending 
   1.118 +		 before and after fading ***/
   1.119 +	iGc->BitBltMasked(TPoint(140,25), iBitmap, 
   1.120 +						   TRect(0,0,100,100), iMaskGray256, EFalse);	
   1.121 +	// Save the pixel colour of a pixel on the outer ring of the circle 
   1.122 +	// before fading enabled.
   1.123 +	TheClient->iScreen->GetPixel(iNonFadedPixel, TPoint(190,30));	
   1.124 +
   1.125 +	iGc->SetFaded(ETrue);
   1.126 +	iGc->BitBltMasked(TPoint(270,25), iBitmap, 
   1.127 +						   TRect(0,0,100,100), iMaskGray256, EFalse);
   1.128 +	// Save the pixel colour of a pixel on the outer ring of the circle 
   1.129 +	// after fading enabled.
   1.130 +	TheClient->iScreen->GetPixel(iFadedPixel, TPoint(320,30));	
   1.131 +
   1.132 +	iGc->SetFaded(EFalse);
   1.133 +	
   1.134 +	iGc->BitBltMasked(TPoint(140,125), iBitmap, 
   1.135 +						   TRect(0,0,100,100), iMaskGray2, EFalse);
   1.136 +	iGc->SetFaded(ETrue);
   1.137 +	iGc->BitBltMasked(TPoint(270,125), iBitmap, 
   1.138 +						   TRect(0,0,100,100), iMaskGray2, EFalse);
   1.139 +	iGc->SetFaded(EFalse);
   1.140 +
   1.141 +	iGc->DiscardFont();
   1.142 +	TheClient->iScreen->ReleaseFont(myFont);
   1.143 +	}
   1.144 +
   1.145 +
   1.146 +//===================================================
   1.147 +// CTFadingBitmap Definition
   1.148 +//===================================================
   1.149 +
   1.150 +CTFadingBitmap::CTFadingBitmap(CTestStep* aStep):
   1.151 +	CTWsGraphicsBase(aStep), iTestResult(ETrue)
   1.152 +	{
   1.153 +	}
   1.154 +
   1.155 +CTFadingBitmap::~CTFadingBitmap()
   1.156 +	{
   1.157 +	delete iBgWin;
   1.158 +	}
   1.159 +
   1.160 +void CTFadingBitmap::TestFadingL()
   1.161 +	{
   1.162 +	// Modes to test
   1.163 +	TDisplayMode modes[] = 
   1.164 +		{
   1.165 +		EGray2, EGray4, EGray16, EGray256, 
   1.166 +		EColor16, EColor256, EColor4K, EColor64K, 
   1.167 +		EColor16M, EColor16MU, EColor16MA, EColor16MAP   
   1.168 +		};
   1.169 +	
   1.170 +	TBuf <12> modesTxt []= 
   1.171 +		{
   1.172 +		_L("EGray2"), _L("EGray4"), _L("EGray16"), _L("EGray256"), 
   1.173 +		_L("EColor16"), _L("EColor256"), _L("EColor4K"), _L("EColor64K"), 
   1.174 +		_L("EColor16M"), _L("EColor16MU"), _L("EColor16MA"), _L("EColor16MAP")
   1.175 +		};
   1.176 +	
   1.177 +	TBuf <100> testTxt;		 
   1.178 +	for( int i = 0; i < 12; i++)
   1.179 +		{
   1.180 +		testTxt.Format(modesTxt[i]);
   1.181 +		INFO_PRINTF1(testTxt);
   1.182 +		// Here we copy the content of the temp bitmap, which holds the test bitmap,
   1.183 +		// into the bitmap created with alternating color depths.
   1.184 +		User::LeaveIfError(iBgWin->iBitmap->Create(iBgWin->iTempBitmap->SizeInPixels(), modes[i]));
   1.185 +		CFbsBitmapDevice *dev = CFbsBitmapDevice::NewL(iBgWin->iBitmap);
   1.186 +		CleanupStack::PushL(dev);
   1.187 +		CFbsBitGc *gc;
   1.188 +		User::LeaveIfError(dev->CreateContext(gc));
   1.189 +		// performing the copying here
   1.190 +		gc->BitBlt(TPoint(0,0), iBgWin->iTempBitmap);
   1.191 +		// setting the mode text to display it
   1.192 +		iBgWin->iMode = modesTxt[i];
   1.193 +		// draws the bitmap on screen 
   1.194 +		iBgWin->DrawNow();
   1.195 +		TheClient->Flush();
   1.196 +		User::After(5000);
   1.197 +		// cleaning up		
   1.198 +		CleanupStack::Pop();
   1.199 +		delete gc;
   1.200 +		gc = NULL;	
   1.201 +		delete dev;
   1.202 +		dev = NULL;		
   1.203 +		
   1.204 +		// Here the colours of pixels before and after fading are printed in wstest log
   1.205 +		testTxt.Format(_L("Nonfaded circle - color of the outside ring: R=%d G=%d B=%d"), iBgWin->iNonFadedPixel.Red(), iBgWin->iNonFadedPixel.Green(), iBgWin->iNonFadedPixel.Blue());
   1.206 +		INFO_PRINTF1(testTxt);
   1.207 +		testTxt.Format(_L("Faded circle  - color of the outside ring: R=%d G=%d B=%d"), iBgWin->iFadedPixel.Red(), iBgWin->iFadedPixel.Green(), iBgWin->iFadedPixel.Blue());
   1.208 +		INFO_PRINTF1(testTxt);
   1.209 +		
   1.210 +		// Checks if the colors are the same before and after the fading.
   1.211 +		// The color will be the same only in EGray2 and EGray4 as there are no enough 
   1.212 +		// color variations to represent the fading and nonfading effects.
   1.213 +		if(iTestResult &&
   1.214 +		   iBgWin->iNonFadedPixel.Red()   == iBgWin->iFadedPixel.Red() &&
   1.215 +		   iBgWin->iNonFadedPixel.Green() == iBgWin->iFadedPixel.Green() &&
   1.216 +		   iBgWin->iNonFadedPixel.Blue()  == iBgWin->iFadedPixel.Blue() &&
   1.217 +		   modes[i] != EGray2 && modes[i] != EGray4)
   1.218 +			iTestResult = EFalse;
   1.219 +		}
   1.220 +	}
   1.221 +
   1.222 +void CTFadingBitmap::ConstructL()
   1.223 +	{
   1.224 +	// construct the base window of the test in the background
   1.225 +	TSize scrSize = TSize(TheClient->iScreen->SizeInPixels());
   1.226 +	iBgWin = new (ELeave) CBaseWin();
   1.227 +	iBgWin->ConstructWinL(TPoint(0,0), scrSize, ETrue);	
   1.228 +	}
   1.229 +
   1.230 +void CTFadingBitmap::RunTestCaseL(TInt aCurTestCase)
   1.231 +	{
   1.232 +    	((CTFadingBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   1.233 +	switch(aCurTestCase)
   1.234 +		{
   1.235 +		case 1:
   1.236 +/**
   1.237 +@SYMTestCaseID		GRAPHICS-WSERV-0566
   1.238 +*/
   1.239 +            		((CTFadingBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0566"));
   1.240 +			TestFadingL();
   1.241 +			// Fails or passes the test
   1.242 +			if(!iTestResult)
   1.243 +				TEST(EFalse);
   1.244 +			break;
   1.245 +		default:
   1.246 +            		((CTFadingBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.247 +			((CTFadingBitmapStep*)iStep)->CloseTMSGraphicsStep();
   1.248 +			TestComplete();
   1.249 +		}
   1.250 +	((CTFadingBitmapStep*)iStep)->RecordTestResultL();
   1.251 +	}
   1.252 +
   1.253 +__WS_CONSTRUCT_STEP__(FadingBitmap)