os/graphics/graphicsdeviceinterface/bitgdi/tbit/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
#include "textendedbitmap.h"
sl@0
    17
sl@0
    18
const TDisplayMode KDisplayMode[] = {EColor16MAP, EColor16MA, EColor16MU, EColor16M, EColor64K, 
sl@0
    19
						   EColor4K, EColor256, EColor16, EGray256, EGray16, EGray4, EGray2};
sl@0
    20
// The only display modes supported by the example rasterizer are EGray256, EColor64K,
sl@0
    21
// EColor16MU and EColor16MAP, these tests will fail if KBitmapMode is changed to a
sl@0
    22
// display mode that is not one of these modes.
sl@0
    23
const TDisplayMode KBitmapMode = EColor16MAP;
sl@0
    24
const TSize KBitmapSize(640,240);
sl@0
    25
sl@0
    26
const TInt KNumColors = 3;
sl@0
    27
const TRgb KColors[KNumColors] = {TRgb(0,255,255), TRgb(255,0,255), TRgb(255,255,0)};
sl@0
    28
const TUid KUidExampleExtendedBitmap = {0x10285A78};
sl@0
    29
sl@0
    30
//----------------------------------------------------------------------------
sl@0
    31
// Positive Extended Bitmap Tests
sl@0
    32
//----------------------------------------------------------------------------
sl@0
    33
CTExtendedBitmap::CTExtendedBitmap(CTestStep* aStep) :
sl@0
    34
	CTGraphicsBase(aStep)
sl@0
    35
	{
sl@0
    36
	}
sl@0
    37
sl@0
    38
void CTExtendedBitmap::ConstructL()
sl@0
    39
	{
sl@0
    40
#ifdef USE_SCREEN_DEVICE
sl@0
    41
	// Create a screen device
sl@0
    42
	TInt ii = 0;
sl@0
    43
	TInt err = KErrNotSupported;
sl@0
    44
	for(;(ii<TInt(sizeof(KDisplayMode)/sizeof(KDisplayMode[0]))) && (err == KErrNotSupported);++ii)
sl@0
    45
		{
sl@0
    46
		TRAP(err, iDevice = CFbsScreenDevice::NewL(_L("scdv"),KDisplayMode[ii]));
sl@0
    47
		}
sl@0
    48
	if (err != KErrNone)
sl@0
    49
		{
sl@0
    50
		_LIT(KLog,"Failed to create screen device %S return value %d");
sl@0
    51
		INFO_PRINTF3(KLog,&ColorModeName(KDisplayMode[ii]),err);
sl@0
    52
		User::Leave(err);
sl@0
    53
		}
sl@0
    54
	else
sl@0
    55
		{
sl@0
    56
		_LIT(KLog,"Created Screen Device with mode %S");
sl@0
    57
		INFO_PRINTF2(KLog,&ColorModeName(KDisplayMode[ii]));
sl@0
    58
		}
sl@0
    59
	static_cast<CFbsScreenDevice*>(iDevice)->SetAutoUpdate(ETrue);
sl@0
    60
#else
sl@0
    61
	// Create a standard bitmap, bitmap device
sl@0
    62
	iBitmap = new(ELeave) CFbsBitmap;
sl@0
    63
	User::LeaveIfError(iBitmap->Create(KBitmapSize, KBitmapMode));
sl@0
    64
	iDevice = CFbsBitmapDevice::NewL(iBitmap);
sl@0
    65
#endif
sl@0
    66
sl@0
    67
	INFO_PRINTF2(_L("Testing CFbsBitGc with an extended bitmap, display mode %d"), KBitmapMode);
sl@0
    68
sl@0
    69
	// Create a graphics context from chosen device
sl@0
    70
	User::LeaveIfError(iDevice->CreateContext(iBitGc));
sl@0
    71
	
sl@0
    72
	// Check to see if the example rasterizer is available
sl@0
    73
	CTExtendedBitmapGc::TDrawMode drawMode = CTExtendedBitmapGc::EDrawFlag;
sl@0
    74
	if (CFbsBitmap::Rasterizer() == NULL)
sl@0
    75
		drawMode = CTExtendedBitmapGc::EDrawWhite;
sl@0
    76
	
sl@0
    77
	switch (drawMode)
sl@0
    78
		{
sl@0
    79
		case CTExtendedBitmapGc::EDrawFlag:
sl@0
    80
			INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));
sl@0
    81
			break;
sl@0
    82
		case CTExtendedBitmapGc::EDrawWhite:
sl@0
    83
			INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
sl@0
    84
			break;
sl@0
    85
		default:
sl@0
    86
			ERR_PRINTF1(_L("Unknown draw mode"));
sl@0
    87
			break;
sl@0
    88
		}				
sl@0
    89
	
sl@0
    90
	
sl@0
    91
	iExtendedBitmapGcTests = CTExtendedBitmapGc::NewL(this, *iBitGc, drawMode, KBitmapMode);
sl@0
    92
	}
sl@0
    93
sl@0
    94
CTExtendedBitmap::~CTExtendedBitmap()
sl@0
    95
	{
sl@0
    96
	((CTExtendedBitmapStep*)iStep)->CloseTMSGraphicsStep();
sl@0
    97
	delete iExtendedBitmapGcTests;
sl@0
    98
	delete iBitGc;
sl@0
    99
	delete iDevice;
sl@0
   100
#ifndef USE_SCREEN_DEVICE
sl@0
   101
	delete iBitmap;
sl@0
   102
#endif
sl@0
   103
	}
sl@0
   104
sl@0
   105
/**
sl@0
   106
@SYMTestCaseID
sl@0
   107
	GRAPHICS-BITGDI-0103
sl@0
   108
sl@0
   109
@SYMTestCaseDesc
sl@0
   110
	Test extended bitmaps are drawn correctly to an offscreen bitmap using CFbsBitGc.
sl@0
   111
	Test that shapes are filled correctly when an extended bitmap is set as the brush pattern 
sl@0
   112
	using CFbsBitGc::UseBrushPattern().
sl@0
   113
sl@0
   114
@SYMPREQ 
sl@0
   115
	PREQ2096
sl@0
   116
sl@0
   117
@SYMREQ
sl@0
   118
	REQ10847
sl@0
   119
	REQ10857
sl@0
   120
	REQ10859
sl@0
   121
sl@0
   122
@SYMTestPriority  
sl@0
   123
	High
sl@0
   124
sl@0
   125
@SYMTestStatus 
sl@0
   126
	Implemented
sl@0
   127
sl@0
   128
@SYMTestActions
sl@0
   129
	Create an extended bitmap with extended data to generate a flag pattern when rendered,
sl@0
   130
	if the example rasterizer is available.	
sl@0
   131
	
sl@0
   132
	Create a matching standard bitmap.
sl@0
   133
sl@0
   134
	Draw the extended bitmap on the left of the screen and the standard bitmap on the right, 
sl@0
   135
	using each of the following CFbsBitGc APIs.
sl@0
   136
	This is done with both vertical and horizonatal flag orientations,
sl@0
   137
	and with and without an active region of interest:	 	
sl@0
   138
		- BitBlt() (one version tested as both versions call through to DoBitBlt())
sl@0
   139
		- BitBltMasked()
sl@0
   140
		- DrawBitmap() (one version tested as both versions call through to DoDrawBitmap())
sl@0
   141
		- DrawBitmapMasked()
sl@0
   142
		- UseBrushPattern()
sl@0
   143
		- AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp1, const CFbsBitmap* aSrcBmp2, const TRect& aSrcRect1, const TPoint& aSrcPt2, 
sl@0
   144
				const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt);
sl@0
   145
		- AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect, const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt);
sl@0
   146
		
sl@0
   147
	To test that shapes are filled correctly using an extended bitmap, an extended bitmap that would generate 
sl@0
   148
	a flag pattern if the example rasterizer is available, and a matching standard bitmap are in turn set as 
sl@0
   149
	the brush pattern using CFbsBitGc::UseBrushPattern(). Each of the following APIs are used to draw a shape,
sl@0
   150
	using the extended bitmap as a brush on the left, and the standard bitmap on the right. Calling each
sl@0
   151
	of these APIs is necessary as each one contains code specific to extended bitmaps.
sl@0
   152
		- DrawPie()
sl@0
   153
		- DrawRoundRect()
sl@0
   154
		- DrawPolygon() (2 versions)
sl@0
   155
		- DrawEllipse()
sl@0
   156
		- DrawRect()
sl@0
   157
		- DrawText()
sl@0
   158
		- DrawTextVertical()
sl@0
   159
		
sl@0
   160
	Note that the test cases are actually run from a separate test DLL that is built as part of the FbServ
sl@0
   161
	tests (textendedbitmapgc.dll). This DLL allows the same extended bitmap tests to be run using different graphics
sl@0
   162
	contexts. 
sl@0
   163
sl@0
   164
@SYMTestExpectedResults
sl@0
   165
	When the rasterizer is available both sides of the test screen should show a horizontally/vertically striped rectangle for every 
sl@0
   166
	test case, when the rasterizer is not present both sides of the test screen should show a white rectangle for each test case.
sl@0
   167
	The left and right side of the test should always match exactly for each test case, i.e. what is drawn using an
sl@0
   168
	extended bitmap on the left of the screen should match what is drawn using a corresponding standard bitmap on the right of
sl@0
   169
	the screen.
sl@0
   170
*/
sl@0
   171
void CTExtendedBitmap::RunTestCaseL(TInt aCurTestCase)
sl@0
   172
	{
sl@0
   173
	((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0103"));
sl@0
   174
	iExtendedBitmapGcTests->RunTestCaseL(aCurTestCase);
sl@0
   175
	
sl@0
   176
	// Compare the two sides of the screen, they should match exactly
sl@0
   177
	TSize scrSize = iDevice->SizeInPixels();
sl@0
   178
	TEST(iDevice->RectCompare(TRect(0,0,scrSize.iWidth>>1,scrSize.iHeight), *iDevice, TRect(scrSize.iWidth>>1,0,scrSize.iWidth,scrSize.iHeight)));
sl@0
   179
	((CTExtendedBitmapStep*)iStep)->RecordTestResultL();
sl@0
   180
	}
sl@0
   181
sl@0
   182
CTestExecuteLogger& CTExtendedBitmap::Logger()
sl@0
   183
	{
sl@0
   184
	return CTGraphicsBase::Logger();
sl@0
   185
	}
sl@0
   186
sl@0
   187
void CTExtendedBitmap::TestTrue(TBool aCondition)
sl@0
   188
	{
sl@0
   189
	TEST(aCondition);
sl@0
   190
	}
sl@0
   191
sl@0
   192
void CTExtendedBitmap::TestComplete()
sl@0
   193
	{
sl@0
   194
	CTGraphicsBase::TestComplete();
sl@0
   195
	}
sl@0
   196
sl@0
   197
__CONSTRUCT_STEP__(ExtendedBitmap)
sl@0
   198
sl@0
   199
sl@0
   200
//----------------------------------------------------------------------------
sl@0
   201
// Negative Extended Bitmap Tests
sl@0
   202
//----------------------------------------------------------------------------
sl@0
   203
CTExtendedBitmapNegative::CTExtendedBitmapNegative(CTestStep* aStep) :
sl@0
   204
	CTGraphicsBase(aStep)
sl@0
   205
	{
sl@0
   206
	}
sl@0
   207
sl@0
   208
void CTExtendedBitmapNegative::RunTestCaseL(TInt aCurTestCase)
sl@0
   209
	{	
sl@0
   210
	((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   211
	switch(aCurTestCase)
sl@0
   212
		{	
sl@0
   213
	case 1:
sl@0
   214
		((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0104"));
sl@0
   215
		TestCFbsBitmapDeviceNewLLeavesL();
sl@0
   216
		break;
sl@0
   217
	default:
sl@0
   218
		((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   219
		((CTExtendedBitmapNegativeStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   220
		TestComplete();
sl@0
   221
		break;	
sl@0
   222
		}	
sl@0
   223
	((CTExtendedBitmapNegativeStep*)iStep)->RecordTestResultL();
sl@0
   224
	}
sl@0
   225
sl@0
   226
/**
sl@0
   227
@SYMTestCaseID
sl@0
   228
	GRAPHICS-BITGDI-0104
sl@0
   229
sl@0
   230
@SYMTestCaseDesc
sl@0
   231
	Test that passing an extended bitmap to CFbsBitmapDevice::NewL() leaves with error KErrAccessDenied.
sl@0
   232
sl@0
   233
@SYMPREQ 
sl@0
   234
	PREQ2096
sl@0
   235
	
sl@0
   236
@SYMREQ
sl@0
   237
	REQ10847
sl@0
   238
	REQ10856	
sl@0
   239
sl@0
   240
@SYMTestPriority  
sl@0
   241
	High
sl@0
   242
	
sl@0
   243
@SYMTestStatus 
sl@0
   244
	Implemented
sl@0
   245
	
sl@0
   246
@SYMTestActions
sl@0
   247
	Create an extended bitmap using test data and test Uid.
sl@0
   248
	Call CFbsBitmapDevice::NewL() with the extended bitmap as the parameter.
sl@0
   249
		
sl@0
   250
@SYMTestExpectedResults
sl@0
   251
	CFbsBitmapDevice::NewL() leaves with error KErrAccessDenied.
sl@0
   252
*/
sl@0
   253
void CTExtendedBitmapNegative::TestCFbsBitmapDeviceNewLLeavesL()
sl@0
   254
	{
sl@0
   255
	INFO_PRINTF1(_L("Test that CFbsBitmapDevice leaves with KErrAccessDenied when created with an extended bitmap"));			
sl@0
   256
	TInt dataSize = sizeof(KColors)+sizeof(TUint8); // estimate the data size
sl@0
   257
	TUint8* data = new(ELeave) TUint8[dataSize];
sl@0
   258
	CleanupStack::PushL(data);	
sl@0
   259
	
sl@0
   260
	// Write the colours to be used in the extended bitmap to the data	
sl@0
   261
	CTExtendedBitmapGc::WriteExtendedBitmapInfoL(data, dataSize, KColors, CTExtendedBitmapGc::EHorizontalStripe);
sl@0
   262
	
sl@0
   263
	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
sl@0
   264
	CleanupStack::PushL(bmp);
sl@0
   265
	TInt err = bmp->CreateExtendedBitmap(TSize(10,10), KBitmapMode, KUidExampleExtendedBitmap, data, dataSize);
sl@0
   266
	TEST(err == KErrNone);
sl@0
   267
	
sl@0
   268
	// CFbsBitmapDevice::NewL() should leave with KErrAccessDenied
sl@0
   269
	CFbsBitmapDevice* bmpDevice1 = NULL;
sl@0
   270
	TRAPD(error, bmpDevice1 = CFbsBitmapDevice::NewL(bmp));	
sl@0
   271
	TEST(error == KErrAccessDenied);	
sl@0
   272
	
sl@0
   273
	delete bmpDevice1;
sl@0
   274
	CleanupStack::PopAndDestroy(2, data);
sl@0
   275
	}
sl@0
   276
sl@0
   277
__CONSTRUCT_STEP__(ExtendedBitmapNegative)