os/graphics/graphicsdeviceinterface/directgdi/test/tbitbltmaskedbase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-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 "tbitbltmaskedbase.h"
    17 
    18 
    19 CTBitBltMaskedBase::CTBitBltMaskedBase()
    20 	{
    21 	
    22 	}
    23 
    24 CTBitBltMaskedBase::~CTBitBltMaskedBase()
    25 	{
    26 
    27 	}
    28 
    29 /**
    30 Write target output.
    31 Call method from base class with test case name and combined source pixel format and mask type string.
    32 @param aTestCaseName Name of test case.
    33 @return KErrNone if successful, otherwise one of the system-wide error codes.
    34 */
    35 TInt CTBitBltMaskedBase::WriteTargetOutput(TPtrC aTestCaseName)
    36 	{
    37 	TBuf<KFileNameLength> postfix;	
    38 	postfix.Append(KSourceString);
    39 	postfix.Append(KSeparator);
    40 	postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(
    41 				iTestParams.iSourcePixelFormat));	
    42 
    43 	postfix.Append(KSeparator);
    44 	if(iInvertMask)
    45 		{
    46 		postfix.Append(_L16("Invert"));
    47 		}
    48 	postfix.Append(_L16("M"));
    49 
    50 	if(iMaskPixelFormat == EUidPixelFormatL_8)
    51 		{
    52 		postfix.Append(_L16("L8"));
    53 		}
    54 	else if(iMaskPixelFormat == EUidPixelFormatL_1)
    55 		{
    56 		postfix.Append(_L16("L1"));
    57 		}
    58 	
    59 	return CTDirectGdiStepBase::WriteTargetOutput(iTestParams, aTestCaseName, &postfix);
    60 	}
    61 
    62 /**
    63 Create set of bitmaps needed for tests.
    64 @param aPixelFormat Source pixel format of bitmap.
    65 */
    66 void CTBitBltMaskedBase::CreateBitmapsL(TUidPixelFormat aPixelFormat)
    67 	{
    68 	CTBitBltBase::CreateBitmapsL(aPixelFormat);
    69 	iNotInitialisedMask = new (ELeave)CFbsBitmap();
    70 	iZeroSizeMask = new (ELeave)CFbsBitmap();
    71 	TESTL(KErrNone == iZeroSizeMask->Create(TSize(0,0), TDisplayModeMapping::MapPixelFormatToDisplayMode(EUidPixelFormatL_1)));
    72 	iMask1L1 = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, KBitmap1Size, TSize(4, 4));
    73 	iMask2L1 = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, KBitmap2Size, TSize(8, 8));
    74 	iMask1L8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap1Size);
    75 	iMask2L8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap2Size);
    76 	iCompressedMaskL8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap2Size);
    77 	iCompressedMaskL8->Compress();
    78 	iBlackWhiteBitmap = CreateBlackWhiteBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8));
    79 	}
    80 
    81 /**
    82 Delete set of test bitmaps.
    83 */
    84 void CTBitBltMaskedBase::DeleteBitmaps()
    85 	{
    86 	delete iNotInitialisedMask;
    87 	iNotInitialisedMask = NULL;
    88 	delete iZeroSizeMask;
    89 	iZeroSizeMask = NULL;
    90 	delete iMask1L1;
    91 	iMask1L1 = NULL;
    92 	delete iMask2L1;
    93 	iMask2L1 = NULL;
    94 	delete iMask1L8;
    95 	iMask1L8 = NULL;
    96 	delete iMask2L8;
    97 	iMask2L8 = NULL;
    98 	delete iCompressedMaskL8;
    99 	iCompressedMaskL8 = NULL;
   100 	delete iBlackWhiteBitmap;
   101 	iBlackWhiteBitmap = NULL;
   102 	CTBitBltBase::DeleteBitmaps();
   103 	}
   104 
   105 /**
   106 Begin iteration through mask types.
   107 All needed variables are initialized to start iteration.
   108 */
   109 void CTBitBltMaskedBase::BeginMaskIteration()
   110 	{
   111 	iMaskType = EMaskL1;
   112 	iMaskPixelFormat = EUidPixelFormatL_1;
   113 	iInvertMask = EFalse;
   114 	iCurrentMask1 = iMask1L1;
   115 	iCurrentMask2 = iMask2L1;
   116 	}
   117 
   118 /**
   119 Next iteration of mask types.
   120 Generates next mask type.
   121 @return EFalse is returned if end of iterations else ETrue.
   122 */
   123 TBool CTBitBltMaskedBase::NextMaskIteration()
   124 	{
   125 	iMaskType++;
   126 	switch(iMaskType)
   127 		{
   128 		case EMaskL1:
   129 			{
   130 			iMaskPixelFormat = EUidPixelFormatL_1;
   131 			iInvertMask = EFalse;
   132 			iCurrentMask1 = iMask1L1;
   133 			iCurrentMask2 = iMask2L1;
   134 			break;
   135 			}
   136 
   137 		case EMaskL1Inv:
   138 			{
   139 			iMaskPixelFormat = EUidPixelFormatL_1;
   140 			iInvertMask = ETrue;
   141 			iCurrentMask1 = iMask1L1;
   142 			iCurrentMask2 = iMask2L1;
   143 			break;
   144 			}
   145 
   146 		case EMaskL8:
   147 			{
   148 			iMaskPixelFormat = EUidPixelFormatL_8;
   149 			iInvertMask = EFalse;
   150 			iCurrentMask1 = iMask1L8;
   151 			iCurrentMask2 = iMask2L8;
   152 			break;
   153 			}
   154 			
   155 		case EMaskIterationEnd:
   156 			{
   157 			return EFalse;
   158 			}
   159 		}
   160 
   161 	return ETrue;
   162 	}
   163 
   164 /**
   165 Common positioning test function for BitBltMasked() and DrawBitmapMasked() tests.
   166 The test iterates positions over whole target, outside target and on the target boundaries
   167 and call tested function for those positions.
   168 @param aTestName Name of test case.
   169 @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported.
   170 */
   171 void CTBitBltMaskedBase::TestPositioningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
   172 	{
   173 	if (iRunningOomTests)
   174 		{
   175 		// OOM tests take too long if this test is run.  Doesn't test anything new for OOM over other tests.
   176 		return;
   177 		}
   178 	CFbsBitmap* bitmap;
   179 	if(iTestParams.iDoCompressed)
   180 		{
   181 		bitmap = iCompressedBitmap;
   182 		}
   183 	else
   184 		{
   185 		bitmap = iConcentricRectsBitmap1;
   186 		}
   187 
   188 	TInt width = iGdiTarget->SizeInPixels().iWidth;
   189 	TInt height = iGdiTarget->SizeInPixels().iHeight;
   190 	TInt bmpWidth = bitmap->SizeInPixels().iWidth;
   191 	TInt bmpHeight = bitmap->SizeInPixels().iHeight;
   192 	TSize bmpSize(bmpWidth, bmpHeight);
   193 
   194 	ResetGc();
   195 
   196 	TPositionIterator posIterator(-30, width+30, bmpWidth, -30, height+30, bmpHeight);
   197 	posIterator.Begin();
   198 
   199 	do
   200 		{
   201 		TPoint pos(posIterator.iPosX+posIterator.iIndexY, posIterator.iPosY+posIterator.iIndexX);
   202 
   203 		if(aFunc == EBitBltMasked)
   204 			{
   205 			if(iMaskPixelFormat == EUidPixelFormatL_1)
   206 				{
   207 				iGc->BitBltMasked(pos, *bitmap,
   208 					TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, iInvertMask);
   209 				}
   210 			else
   211 				{
   212 				// additionaly mask position is iterated
   213 				iGc->BitBltMasked(pos, *bitmap,
   214 					TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, TPoint(posIterator.iIndexX, posIterator.iIndexY));
   215 				}
   216 			}
   217 		else // (aFunc == EDrawBitmapMasked)
   218 			{
   219 			iGc->DrawBitmapMasked(TRect(pos, bmpSize), *bitmap,
   220 					TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, iInvertMask);
   221 			}
   222 		}
   223 	while(posIterator.Next());
   224 
   225 	// WORKAROUND:
   226 	// It looks like AlphaBlendBitmaps() (which is mapped on DrawBitmapMasked() with alpha for BitGDI)
   227 	// do not support clipping and returns KErrArgument for destination rect (partialy) outside the target.
   228 	if(aFunc == EBitBltMasked)
   229 		{
   230 		if(iUseDirectGdi || (iMaskPixelFormat == EUidPixelFormatL_1) || (iGc->GetError() != KErrArgument))
   231 			{
   232 			TESTNOERROR(iGc->GetError());
   233 			}
   234 		}
   235 	else
   236 		{
   237 		TESTNOERROR(iGc->GetError());
   238 		}
   239 	if(!iTestParams.iDoCompressed)
   240 		TESTNOERRORL(WriteTargetOutput(aTestName));
   241 	}
   242 
   243 /**
   244 Common invalid parameters test function for BitBltMasked() and DrawBitmapMasked() tests.
   245 The function tests against invalid source rectangle, zero size source bitmap (both should
   246 return KErrArgument) and not initialised source bitmap (should return KErrBadHandle). 
   247 @param aTestName Name of test case.
   248 @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported.
   249 */
   250 void CTBitBltMaskedBase::TestInvalidParametersBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
   251 	{	
   252 	ResetGc();
   253 
   254 	CFbsBitmap* bitmap = iConcentricRectsBitmap2;
   255 
   256 	TInt bmpWidth = bitmap->SizeInPixels().iWidth;
   257 	TInt bmpHeight = bitmap->SizeInPixels().iHeight;
   258 	TSize bmpSize(bmpWidth, bmpHeight);
   259 
   260 	// invalid source rectangle
   261 	RArray<TRect> rectArray;
   262 	CleanupClosePushL(rectArray);
   263 	TInt err = KErrNone;
   264 	err |= rectArray.Append(TRect(-30, -30, -10, -10));
   265 	err |= rectArray.Append(TRect(bmpWidth+10, bmpHeight+10, bmpWidth+20, bmpHeight+20));
   266 	err |= rectArray.Append(TRect(bmpWidth, bmpHeight, 0, 0));
   267 	err |= rectArray.Append(TRect(-10, -10, -30, -30));
   268 	err |= rectArray.Append(TRect(0, 0, 0, 0));
   269 	TESTL(KErrNone == err);
   270 	
   271 	for(TInt i = 0; i < rectArray.Count(); i++)
   272 		{
   273 		if(aFunc == EBitBltMasked)
   274 			{
   275 			iGc->BitBltMasked(TPoint(i*20, 0), *bitmap, rectArray[i], *iMask1L1, EFalse);
   276 			}
   277 		else // (aFunc == EDrawBitmapMasked)
   278 			{
   279 			iGc->DrawBitmapMasked(TRect(TPoint(i*20, 0), bmpSize), *bitmap, rectArray[i], *iMask1L1, EFalse);
   280 			}
   281 		}
   282 
   283 	TESTNOERRORL(iGc->GetError());
   284 
   285 	CleanupStack::PopAndDestroy(&rectArray);
   286 
   287 	TRect zeroRect(TPoint(0, 0), TSize(0, 0));
   288 
   289 	if(aFunc == EBitBltMasked)
   290 		{
   291 		// invalid source bitmap, zero size bitmap
   292 		iGc->BitBltMasked(TPoint(0, 20), *iZeroSizeBitmap, zeroRect, *iMask1L1, EFalse);
   293 		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   294 		
   295 		iGc->BitBltMasked(TPoint(20, 20), *iZeroSizeBitmap, zeroRect, *iMask1L8, TPoint(0, 0));
   296 		TESTL(iGc->GetError() == KErrArgument);
   297 		
   298 		iGc->BitBltMasked(TPoint(20, 20), *iZeroSizeBitmap, zeroRect, *iMask1L8, TPoint(0, 0));
   299 		TESTL(iGc->GetError() == KErrArgument);
   300 
   301 		// invalid source bitmap, not initialised bitmap
   302 		iGc->BitBltMasked(TPoint(0, 40), *iNotInitialisedBitmap, zeroRect, *iMask1L1, EFalse);
   303 		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
   304 		
   305 		iGc->BitBltMasked(TPoint(20, 40), *iNotInitialisedBitmap, zeroRect, *iMask1L8, TPoint(0, 0));
   306 		TESTL(iGc->GetError() == iUseDirectGdi ? KErrBadHandle : KErrArgument);
   307 
   308 		TRect bmpRect(TPoint(0, 0), bmpSize);
   309 		
   310 		// BitGDI performs drawing when mask is zero sized or not initialised
   311 		// so we test only in DirectGDI
   312 		if(iUseDirectGdi)
   313 			{
   314 			// invalid mask, zero size mask
   315 			iGc->BitBltMasked(TPoint(0, 60), *bitmap, bmpRect, *iZeroSizeMask, EFalse);
   316 			TESTL(iGc->GetError() == KErrArgument);
   317 		
   318 			iGc->BitBltMasked(TPoint(20, 60), *bitmap, bmpRect, *iZeroSizeMask, TPoint(0, 0));
   319 			TESTL(iGc->GetError() == KErrArgument);
   320 		
   321 			// invalid mask, not initialised mask
   322 			iGc->BitBltMasked(TPoint(0, 80), *bitmap, bmpRect, *iNotInitialisedMask, EFalse);
   323 			TESTL(iGc->GetError() == KErrBadHandle);
   324 		
   325 			iGc->BitBltMasked(TPoint(20, 80), *bitmap, bmpRect, *iNotInitialisedMask, TPoint(0, 0));
   326 			TESTL(iGc->GetError() == KErrBadHandle);
   327 			}
   328 		}
   329 	else // (aFunc == EDrawBitmapMasked)
   330 		{
   331 		// invalid source bitmap, zero size bitmap
   332 		iGc->DrawBitmapMasked(TRect(TPoint(0, 20), TSize(0, 0)), *iZeroSizeBitmap, zeroRect, *iMask1L1, EFalse);
   333 		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   334 
   335 		// invalid source bitmap, not initialised bitmap
   336 		iGc->DrawBitmapMasked(TRect(TPoint(0, 40), TSize(0, 0)), *iNotInitialisedBitmap, zeroRect, *iMask1L1, EFalse);
   337 		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
   338 
   339 		// invalid mask, zero size mask
   340 		TRect bmpRect(TPoint(0, 0), bmpSize);
   341 		iGc->DrawBitmapMasked(TRect(TPoint(0, 60), bmpSize), *bitmap, bmpRect, *iZeroSizeMask, EFalse);
   342 		CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__);
   343 
   344 		// invalid mask, not initialised mask
   345 		iGc->DrawBitmapMasked(TRect(TPoint(0, 80), bmpSize), *bitmap, bmpRect, *iNotInitialisedMask, EFalse);
   346 		CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__);
   347 		}
   348 
   349 	// Test if target is clear. By definition, images rendered using any invalid parameter,
   350 	// should result in no change in the target.
   351 	//This test is not valid for BitGDI as it generates an output if mask size is zero.
   352 	if(iUseDirectGdi)
   353 		{
   354 		TBool res = TestTargetL(KRgbWhite);
   355 		TEST(res);
   356 		// output the bitmap if there was an error to assist with debugging
   357 		if (res == EFalse)
   358 			{				
   359 			TESTNOERRORL(WriteTargetOutput(aTestName));
   360 			}
   361 		}
   362 	
   363 	}
   364 
   365 /**
   366 Common source bitmap cloning test function for BitBltMasked() and DrawBitmapMasked() tests.
   367 @param aTestName Name of test case.
   368 @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported.
   369 */
   370 void CTBitBltMaskedBase::TestSourceBitmapCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
   371 	{	
   372 	ResetGc();
   373 
   374 	TInt width = iGdiTarget->SizeInPixels().iWidth;
   375 	TInt height = iGdiTarget->SizeInPixels().iHeight;
   376 
   377 	TSize bmpSize(KBitmap2Size);
   378 
   379 	for(TInt i = 0; i < 5; i++)
   380 		{
   381 		CFbsBitmap* bitmap = CreateConcentricRectsBitmapL(iTestParams.iSourcePixelFormat, bmpSize);
   382 		if(iTestParams.iDoCompressed)
   383 			bitmap->Compress();
   384 			
   385 		if(aFunc == EBitBltMasked)
   386 			{
   387 			iGc->BitBltMasked(TPoint(55-35+i*10+1, -60+80+i*7+1), *bitmap,
   388 				TRect(TPoint(0, 0), bmpSize), *iCurrentMask2, iInvertMask);
   389 			}
   390 		else // (aFunc == EDrawBitmapMasked)
   391 			{
   392 			iGc->DrawBitmapMasked(TRect(TPoint(55-35+i*10+1, -60+80+i*7+1), bmpSize), *bitmap,
   393 					TRect(TPoint(0, 0), bmpSize), *iCurrentMask2, iInvertMask);
   394 			}
   395 
   396 		delete bitmap;
   397 		bitmap = NULL;
   398 
   399 		bmpSize -= TSize(10, 15);
   400 		}
   401 	
   402 	TESTNOERRORL(iGc->GetError());
   403 	if(!iTestParams.iDoCompressed)
   404 		TESTNOERRORL(WriteTargetOutput(aTestName));
   405 	}
   406 
   407 /**
   408 Common mask cloning test function for BitBltMasked() and DrawBitmapMasked() tests.
   409 @param aTestName Name of test case.
   410 @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported.
   411 */
   412 void CTBitBltMaskedBase::TestMaskCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc)
   413 	{	
   414 	ResetGc();
   415 
   416 	TSize maskSize(KBitmap2Size);
   417 
   418 	for(TInt i = 0; i < 5; i++)
   419 		{
   420 		CFbsBitmap* mask = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, maskSize, TSize(8, 8));
   421 		if(iTestParams.iDoCompressed)
   422 			mask->Compress();
   423 			
   424 		if(aFunc == EBitBltMasked)
   425 			{
   426 			iGc->BitBltMasked(TPoint(55-35+i*10+1, -60+80+i*7+1), *iConcentricRectsBitmap2,
   427 					TRect(TPoint(0, 0), KBitmap2Size), *mask, iInvertMask);
   428 			}
   429 		else // (aFunc == EDrawBitmapMasked)
   430 			{
   431 			iGc->DrawBitmapMasked(TRect(TPoint(55-35+i*10+1, -60+80+i*7+1), iConcentricRectsBitmap2->SizeInPixels()),
   432 					*iConcentricRectsBitmap2, TRect(TPoint(0, 0), KBitmap2Size), *mask, iInvertMask);
   433 			}
   434 
   435 		delete mask;
   436 		mask = NULL;
   437 
   438 		maskSize -= TSize(10, 15);
   439 		}
   440 	
   441 	TESTNOERRORL(iGc->GetError());
   442 	
   443 	if(!iTestParams.iDoCompressed)
   444 		TESTNOERRORL(WriteTargetOutput(aTestName));
   445 	}