sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "tbitbltmaskedbase.h" sl@0: sl@0: sl@0: CTBitBltMaskedBase::CTBitBltMaskedBase() sl@0: { sl@0: sl@0: } sl@0: sl@0: CTBitBltMaskedBase::~CTBitBltMaskedBase() sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Write target output. sl@0: Call method from base class with test case name and combined source pixel format and mask type string. sl@0: @param aTestCaseName Name of test case. sl@0: @return KErrNone if successful, otherwise one of the system-wide error codes. sl@0: */ sl@0: TInt CTBitBltMaskedBase::WriteTargetOutput(TPtrC aTestCaseName) sl@0: { sl@0: TBuf postfix; sl@0: postfix.Append(KSourceString); sl@0: postfix.Append(KSeparator); sl@0: postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString( sl@0: iTestParams.iSourcePixelFormat)); sl@0: sl@0: postfix.Append(KSeparator); sl@0: if(iInvertMask) sl@0: { sl@0: postfix.Append(_L16("Invert")); sl@0: } sl@0: postfix.Append(_L16("M")); sl@0: sl@0: if(iMaskPixelFormat == EUidPixelFormatL_8) sl@0: { sl@0: postfix.Append(_L16("L8")); sl@0: } sl@0: else if(iMaskPixelFormat == EUidPixelFormatL_1) sl@0: { sl@0: postfix.Append(_L16("L1")); sl@0: } sl@0: sl@0: return CTDirectGdiStepBase::WriteTargetOutput(iTestParams, aTestCaseName, &postfix); sl@0: } sl@0: sl@0: /** sl@0: Create set of bitmaps needed for tests. sl@0: @param aPixelFormat Source pixel format of bitmap. sl@0: */ sl@0: void CTBitBltMaskedBase::CreateBitmapsL(TUidPixelFormat aPixelFormat) sl@0: { sl@0: CTBitBltBase::CreateBitmapsL(aPixelFormat); sl@0: iNotInitialisedMask = new (ELeave)CFbsBitmap(); sl@0: iZeroSizeMask = new (ELeave)CFbsBitmap(); sl@0: TESTL(KErrNone == iZeroSizeMask->Create(TSize(0,0), TDisplayModeMapping::MapPixelFormatToDisplayMode(EUidPixelFormatL_1))); sl@0: iMask1L1 = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, KBitmap1Size, TSize(4, 4)); sl@0: iMask2L1 = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, KBitmap2Size, TSize(8, 8)); sl@0: iMask1L8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap1Size); sl@0: iMask2L8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap2Size); sl@0: iCompressedMaskL8 = CreateMaskingPixmapL(EUidPixelFormatL_8, KBitmap2Size); sl@0: iCompressedMaskL8->Compress(); sl@0: iBlackWhiteBitmap = CreateBlackWhiteBitmapL(aPixelFormat, KBitmap2Size, TSize(8, 8)); sl@0: } sl@0: sl@0: /** sl@0: Delete set of test bitmaps. sl@0: */ sl@0: void CTBitBltMaskedBase::DeleteBitmaps() sl@0: { sl@0: delete iNotInitialisedMask; sl@0: iNotInitialisedMask = NULL; sl@0: delete iZeroSizeMask; sl@0: iZeroSizeMask = NULL; sl@0: delete iMask1L1; sl@0: iMask1L1 = NULL; sl@0: delete iMask2L1; sl@0: iMask2L1 = NULL; sl@0: delete iMask1L8; sl@0: iMask1L8 = NULL; sl@0: delete iMask2L8; sl@0: iMask2L8 = NULL; sl@0: delete iCompressedMaskL8; sl@0: iCompressedMaskL8 = NULL; sl@0: delete iBlackWhiteBitmap; sl@0: iBlackWhiteBitmap = NULL; sl@0: CTBitBltBase::DeleteBitmaps(); sl@0: } sl@0: sl@0: /** sl@0: Begin iteration through mask types. sl@0: All needed variables are initialized to start iteration. sl@0: */ sl@0: void CTBitBltMaskedBase::BeginMaskIteration() sl@0: { sl@0: iMaskType = EMaskL1; sl@0: iMaskPixelFormat = EUidPixelFormatL_1; sl@0: iInvertMask = EFalse; sl@0: iCurrentMask1 = iMask1L1; sl@0: iCurrentMask2 = iMask2L1; sl@0: } sl@0: sl@0: /** sl@0: Next iteration of mask types. sl@0: Generates next mask type. sl@0: @return EFalse is returned if end of iterations else ETrue. sl@0: */ sl@0: TBool CTBitBltMaskedBase::NextMaskIteration() sl@0: { sl@0: iMaskType++; sl@0: switch(iMaskType) sl@0: { sl@0: case EMaskL1: sl@0: { sl@0: iMaskPixelFormat = EUidPixelFormatL_1; sl@0: iInvertMask = EFalse; sl@0: iCurrentMask1 = iMask1L1; sl@0: iCurrentMask2 = iMask2L1; sl@0: break; sl@0: } sl@0: sl@0: case EMaskL1Inv: sl@0: { sl@0: iMaskPixelFormat = EUidPixelFormatL_1; sl@0: iInvertMask = ETrue; sl@0: iCurrentMask1 = iMask1L1; sl@0: iCurrentMask2 = iMask2L1; sl@0: break; sl@0: } sl@0: sl@0: case EMaskL8: sl@0: { sl@0: iMaskPixelFormat = EUidPixelFormatL_8; sl@0: iInvertMask = EFalse; sl@0: iCurrentMask1 = iMask1L8; sl@0: iCurrentMask2 = iMask2L8; sl@0: break; sl@0: } sl@0: sl@0: case EMaskIterationEnd: sl@0: { sl@0: return EFalse; sl@0: } sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Common positioning test function for BitBltMasked() and DrawBitmapMasked() tests. sl@0: The test iterates positions over whole target, outside target and on the target boundaries sl@0: and call tested function for those positions. sl@0: @param aTestName Name of test case. sl@0: @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported. sl@0: */ sl@0: void CTBitBltMaskedBase::TestPositioningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc) sl@0: { sl@0: if (iRunningOomTests) sl@0: { sl@0: // OOM tests take too long if this test is run. Doesn't test anything new for OOM over other tests. sl@0: return; sl@0: } sl@0: CFbsBitmap* bitmap; sl@0: if(iTestParams.iDoCompressed) sl@0: { sl@0: bitmap = iCompressedBitmap; sl@0: } sl@0: else sl@0: { sl@0: bitmap = iConcentricRectsBitmap1; sl@0: } sl@0: sl@0: TInt width = iGdiTarget->SizeInPixels().iWidth; sl@0: TInt height = iGdiTarget->SizeInPixels().iHeight; sl@0: TInt bmpWidth = bitmap->SizeInPixels().iWidth; sl@0: TInt bmpHeight = bitmap->SizeInPixels().iHeight; sl@0: TSize bmpSize(bmpWidth, bmpHeight); sl@0: sl@0: ResetGc(); sl@0: sl@0: TPositionIterator posIterator(-30, width+30, bmpWidth, -30, height+30, bmpHeight); sl@0: posIterator.Begin(); sl@0: sl@0: do sl@0: { sl@0: TPoint pos(posIterator.iPosX+posIterator.iIndexY, posIterator.iPosY+posIterator.iIndexX); sl@0: sl@0: if(aFunc == EBitBltMasked) sl@0: { sl@0: if(iMaskPixelFormat == EUidPixelFormatL_1) sl@0: { sl@0: iGc->BitBltMasked(pos, *bitmap, sl@0: TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, iInvertMask); sl@0: } sl@0: else sl@0: { sl@0: // additionaly mask position is iterated sl@0: iGc->BitBltMasked(pos, *bitmap, sl@0: TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, TPoint(posIterator.iIndexX, posIterator.iIndexY)); sl@0: } sl@0: } sl@0: else // (aFunc == EDrawBitmapMasked) sl@0: { sl@0: iGc->DrawBitmapMasked(TRect(pos, bmpSize), *bitmap, sl@0: TRect(TPoint(0, 0), bmpSize), *iCurrentMask1, iInvertMask); sl@0: } sl@0: } sl@0: while(posIterator.Next()); sl@0: sl@0: // WORKAROUND: sl@0: // It looks like AlphaBlendBitmaps() (which is mapped on DrawBitmapMasked() with alpha for BitGDI) sl@0: // do not support clipping and returns KErrArgument for destination rect (partialy) outside the target. sl@0: if(aFunc == EBitBltMasked) sl@0: { sl@0: if(iUseDirectGdi || (iMaskPixelFormat == EUidPixelFormatL_1) || (iGc->GetError() != KErrArgument)) sl@0: { sl@0: TESTNOERROR(iGc->GetError()); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TESTNOERROR(iGc->GetError()); sl@0: } sl@0: if(!iTestParams.iDoCompressed) sl@0: TESTNOERRORL(WriteTargetOutput(aTestName)); sl@0: } sl@0: sl@0: /** sl@0: Common invalid parameters test function for BitBltMasked() and DrawBitmapMasked() tests. sl@0: The function tests against invalid source rectangle, zero size source bitmap (both should sl@0: return KErrArgument) and not initialised source bitmap (should return KErrBadHandle). sl@0: @param aTestName Name of test case. sl@0: @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported. sl@0: */ sl@0: void CTBitBltMaskedBase::TestInvalidParametersBaseL(const TDesC& aTestName, TBitBltFuncType aFunc) sl@0: { sl@0: ResetGc(); sl@0: sl@0: CFbsBitmap* bitmap = iConcentricRectsBitmap2; sl@0: sl@0: TInt bmpWidth = bitmap->SizeInPixels().iWidth; sl@0: TInt bmpHeight = bitmap->SizeInPixels().iHeight; sl@0: TSize bmpSize(bmpWidth, bmpHeight); sl@0: sl@0: // invalid source rectangle sl@0: RArray rectArray; sl@0: CleanupClosePushL(rectArray); sl@0: TInt err = KErrNone; sl@0: err |= rectArray.Append(TRect(-30, -30, -10, -10)); sl@0: err |= rectArray.Append(TRect(bmpWidth+10, bmpHeight+10, bmpWidth+20, bmpHeight+20)); sl@0: err |= rectArray.Append(TRect(bmpWidth, bmpHeight, 0, 0)); sl@0: err |= rectArray.Append(TRect(-10, -10, -30, -30)); sl@0: err |= rectArray.Append(TRect(0, 0, 0, 0)); sl@0: TESTL(KErrNone == err); sl@0: sl@0: for(TInt i = 0; i < rectArray.Count(); i++) sl@0: { sl@0: if(aFunc == EBitBltMasked) sl@0: { sl@0: iGc->BitBltMasked(TPoint(i*20, 0), *bitmap, rectArray[i], *iMask1L1, EFalse); sl@0: } sl@0: else // (aFunc == EDrawBitmapMasked) sl@0: { sl@0: iGc->DrawBitmapMasked(TRect(TPoint(i*20, 0), bmpSize), *bitmap, rectArray[i], *iMask1L1, EFalse); sl@0: } sl@0: } sl@0: sl@0: TESTNOERRORL(iGc->GetError()); sl@0: sl@0: CleanupStack::PopAndDestroy(&rectArray); sl@0: sl@0: TRect zeroRect(TPoint(0, 0), TSize(0, 0)); sl@0: sl@0: if(aFunc == EBitBltMasked) sl@0: { sl@0: // invalid source bitmap, zero size bitmap sl@0: iGc->BitBltMasked(TPoint(0, 20), *iZeroSizeBitmap, zeroRect, *iMask1L1, EFalse); sl@0: CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: iGc->BitBltMasked(TPoint(20, 20), *iZeroSizeBitmap, zeroRect, *iMask1L8, TPoint(0, 0)); sl@0: TESTL(iGc->GetError() == KErrArgument); sl@0: sl@0: iGc->BitBltMasked(TPoint(20, 20), *iZeroSizeBitmap, zeroRect, *iMask1L8, TPoint(0, 0)); sl@0: TESTL(iGc->GetError() == KErrArgument); sl@0: sl@0: // invalid source bitmap, not initialised bitmap sl@0: iGc->BitBltMasked(TPoint(0, 40), *iNotInitialisedBitmap, zeroRect, *iMask1L1, EFalse); sl@0: CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: iGc->BitBltMasked(TPoint(20, 40), *iNotInitialisedBitmap, zeroRect, *iMask1L8, TPoint(0, 0)); sl@0: TESTL(iGc->GetError() == iUseDirectGdi ? KErrBadHandle : KErrArgument); sl@0: sl@0: TRect bmpRect(TPoint(0, 0), bmpSize); sl@0: sl@0: // BitGDI performs drawing when mask is zero sized or not initialised sl@0: // so we test only in DirectGDI sl@0: if(iUseDirectGdi) sl@0: { sl@0: // invalid mask, zero size mask sl@0: iGc->BitBltMasked(TPoint(0, 60), *bitmap, bmpRect, *iZeroSizeMask, EFalse); sl@0: TESTL(iGc->GetError() == KErrArgument); sl@0: sl@0: iGc->BitBltMasked(TPoint(20, 60), *bitmap, bmpRect, *iZeroSizeMask, TPoint(0, 0)); sl@0: TESTL(iGc->GetError() == KErrArgument); sl@0: sl@0: // invalid mask, not initialised mask sl@0: iGc->BitBltMasked(TPoint(0, 80), *bitmap, bmpRect, *iNotInitialisedMask, EFalse); sl@0: TESTL(iGc->GetError() == KErrBadHandle); sl@0: sl@0: iGc->BitBltMasked(TPoint(20, 80), *bitmap, bmpRect, *iNotInitialisedMask, TPoint(0, 0)); sl@0: TESTL(iGc->GetError() == KErrBadHandle); sl@0: } sl@0: } sl@0: else // (aFunc == EDrawBitmapMasked) sl@0: { sl@0: // invalid source bitmap, zero size bitmap sl@0: iGc->DrawBitmapMasked(TRect(TPoint(0, 20), TSize(0, 0)), *iZeroSizeBitmap, zeroRect, *iMask1L1, EFalse); sl@0: CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: // invalid source bitmap, not initialised bitmap sl@0: iGc->DrawBitmapMasked(TRect(TPoint(0, 40), TSize(0, 0)), *iNotInitialisedBitmap, zeroRect, *iMask1L1, EFalse); sl@0: CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: // invalid mask, zero size mask sl@0: TRect bmpRect(TPoint(0, 0), bmpSize); sl@0: iGc->DrawBitmapMasked(TRect(TPoint(0, 60), bmpSize), *bitmap, bmpRect, *iZeroSizeMask, EFalse); sl@0: CheckErrorsL(KErrArgument, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: sl@0: // invalid mask, not initialised mask sl@0: iGc->DrawBitmapMasked(TRect(TPoint(0, 80), bmpSize), *bitmap, bmpRect, *iNotInitialisedMask, EFalse); sl@0: CheckErrorsL(KErrBadHandle, KErrNone, (TText8*)__FILE__, __LINE__); sl@0: } sl@0: sl@0: // Test if target is clear. By definition, images rendered using any invalid parameter, sl@0: // should result in no change in the target. sl@0: //This test is not valid for BitGDI as it generates an output if mask size is zero. sl@0: if(iUseDirectGdi) sl@0: { sl@0: TBool res = TestTargetL(KRgbWhite); sl@0: TEST(res); sl@0: // output the bitmap if there was an error to assist with debugging sl@0: if (res == EFalse) sl@0: { sl@0: TESTNOERRORL(WriteTargetOutput(aTestName)); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: /** sl@0: Common source bitmap cloning test function for BitBltMasked() and DrawBitmapMasked() tests. sl@0: @param aTestName Name of test case. sl@0: @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported. sl@0: */ sl@0: void CTBitBltMaskedBase::TestSourceBitmapCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc) sl@0: { sl@0: ResetGc(); sl@0: sl@0: TInt width = iGdiTarget->SizeInPixels().iWidth; sl@0: TInt height = iGdiTarget->SizeInPixels().iHeight; sl@0: sl@0: TSize bmpSize(KBitmap2Size); sl@0: sl@0: for(TInt i = 0; i < 5; i++) sl@0: { sl@0: CFbsBitmap* bitmap = CreateConcentricRectsBitmapL(iTestParams.iSourcePixelFormat, bmpSize); sl@0: if(iTestParams.iDoCompressed) sl@0: bitmap->Compress(); sl@0: sl@0: if(aFunc == EBitBltMasked) sl@0: { sl@0: iGc->BitBltMasked(TPoint(55-35+i*10+1, -60+80+i*7+1), *bitmap, sl@0: TRect(TPoint(0, 0), bmpSize), *iCurrentMask2, iInvertMask); sl@0: } sl@0: else // (aFunc == EDrawBitmapMasked) sl@0: { sl@0: iGc->DrawBitmapMasked(TRect(TPoint(55-35+i*10+1, -60+80+i*7+1), bmpSize), *bitmap, sl@0: TRect(TPoint(0, 0), bmpSize), *iCurrentMask2, iInvertMask); sl@0: } sl@0: sl@0: delete bitmap; sl@0: bitmap = NULL; sl@0: sl@0: bmpSize -= TSize(10, 15); sl@0: } sl@0: sl@0: TESTNOERRORL(iGc->GetError()); sl@0: if(!iTestParams.iDoCompressed) sl@0: TESTNOERRORL(WriteTargetOutput(aTestName)); sl@0: } sl@0: sl@0: /** sl@0: Common mask cloning test function for BitBltMasked() and DrawBitmapMasked() tests. sl@0: @param aTestName Name of test case. sl@0: @param aFunc Tested function. EBitBltMasked and EDrawBitmapMasked are supported. sl@0: */ sl@0: void CTBitBltMaskedBase::TestMaskCloningBaseL(const TDesC& aTestName, TBitBltFuncType aFunc) sl@0: { sl@0: ResetGc(); sl@0: sl@0: TSize maskSize(KBitmap2Size); sl@0: sl@0: for(TInt i = 0; i < 5; i++) sl@0: { sl@0: CFbsBitmap* mask = CreateCheckedBoardBitmapL(EUidPixelFormatL_1, maskSize, TSize(8, 8)); sl@0: if(iTestParams.iDoCompressed) sl@0: mask->Compress(); sl@0: sl@0: if(aFunc == EBitBltMasked) sl@0: { sl@0: iGc->BitBltMasked(TPoint(55-35+i*10+1, -60+80+i*7+1), *iConcentricRectsBitmap2, sl@0: TRect(TPoint(0, 0), KBitmap2Size), *mask, iInvertMask); sl@0: } sl@0: else // (aFunc == EDrawBitmapMasked) sl@0: { sl@0: iGc->DrawBitmapMasked(TRect(TPoint(55-35+i*10+1, -60+80+i*7+1), iConcentricRectsBitmap2->SizeInPixels()), sl@0: *iConcentricRectsBitmap2, TRect(TPoint(0, 0), KBitmap2Size), *mask, iInvertMask); sl@0: } sl@0: sl@0: delete mask; sl@0: mask = NULL; sl@0: sl@0: maskSize -= TSize(10, 15); sl@0: } sl@0: sl@0: TESTNOERRORL(iGc->GetError()); sl@0: sl@0: if(!iTestParams.iDoCompressed) sl@0: TESTNOERRORL(WriteTargetOutput(aTestName)); sl@0: }