1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/screendriver/tsrc/TLLD.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,4035 @@
1.4 +// Copyright (c) 1997-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 +//
1.18 +
1.19 +#include <e32math.h>
1.20 +#include <hal.h>
1.21 +#include <bitdraw.h>
1.22 +#include "Tlld.h"
1.23 +#include <bitdrawinterfaceid.h>
1.24 +#include <bmalphablend.h>
1.25 +#include <graphics/lookuptable.h>
1.26 +#include <graphics/blendingalgorithms.h>
1.27 +#include <graphics/gdi/gdiconsts.h>
1.28 +#include "BMDRAW.H"
1.29 +
1.30 +GLREF_C TInt ByteSize(TDisplayMode aDisplayMode,TInt aWidth);
1.31 +
1.32 +TInt KNumberDisplayModes1 = sizeof (TestDisplayMode1) / sizeof (TestDisplayMode1[0]);
1.33 +
1.34 +#if defined(SYMBIAN_USE_FAST_FADING)
1.35 +const TBool KFastFading = ETrue;
1.36 +#else
1.37 +const TBool KFastFading = EFalse;
1.38 +#endif
1.39 +
1.40 +//these are for EColor16MAP testing
1.41 +const TInt KInaccuracyLimit = 15;
1.42 +const TInt KUserDispModes = 2;
1.43 +//The array below is used in CTLowLevel::TestWriteRGBAlpha() to step through display modes,
1.44 +//to ensure adequate test coverage.
1.45 +const TDisplayMode UserDisplayModes[KUserDispModes] =
1.46 + {
1.47 + ENone,
1.48 + EColor16MAP,
1.49 + };
1.50 +const TInt KMaskFill =3;
1.51 +const TUint32 MaskFill[KMaskFill] =
1.52 + {
1.53 + 0x00,
1.54 + 0xff,
1.55 + 0x3A,
1.56 + };
1.57 +
1.58 +TInt DisplayMode2Index(TDisplayMode aMode)
1.59 + {
1.60 + TInt i;
1.61 + for(i=0;i<KNumDispModes;i++)
1.62 + {
1.63 + if(TestDisplayMode[i] == aMode)
1.64 + break;
1.65 + }
1.66 + return i;
1.67 + }
1.68 +
1.69 +inline TInt AbsDiff(TInt aValue1, TInt aValue2)
1.70 + {
1.71 + return (aValue1 < aValue2) ? (aValue2-aValue1) : (aValue1-aValue2);
1.72 + }
1.73 +
1.74 +//CTLowLevel implementation is shared between TLLD and TLLD2 test apps.
1.75 +//The change was made because the original TLLD test app took too much time (over 0.5 hour)
1.76 +//and usually was terminated with a TIMEOUT on LUBBOCK device.
1.77 +CTLowLevel::CTLowLevel(CTestStep* aStep):
1.78 + CTGraphicsBase(aStep),
1.79 + iDrawDevice(NULL),
1.80 + iBits(NULL),
1.81 + iBuf(NULL),
1.82 + iDispMode(ENone),
1.83 + iUserDispMode(ENone),
1.84 + iOrientation(CFbsDrawDevice::EOrientationNormal),
1.85 + iSize(TSize(0,0)),
1.86 + iLongWidth(0),
1.87 + iTestNo(0),
1.88 + iIteration(0),
1.89 + iReportIteration(0),
1.90 + iTotalReportIterations(0),
1.91 + iFuzzyMatch(EFalse),
1.92 + iBlendTestColors(ETrue),
1.93 + iUseFastFade(EFalse)
1.94 + {
1.95 + iColorConvertor[ENone] = &iNullConvertor;
1.96 + iColorConvertor[EGray2] = &iGray2Convertor;
1.97 + iColorConvertor[EGray4] = &iGray4Convertor;
1.98 + iColorConvertor[EGray16] = &iGray16Convertor;
1.99 + iColorConvertor[EGray256] = &iGray256Convertor;
1.100 + iColorConvertor[EColor16] = &iColor16Convertor;
1.101 + iColorConvertor[EColor256] = &iColor256Convertor;
1.102 + iColorConvertor[EColor4K] = &iColor4KConvertor;
1.103 + iColorConvertor[EColor64K] = &iColor64KConvertor;
1.104 + iColorConvertor[EColor16M] = &iColor16MConvertor;
1.105 + iColorConvertor[ERgb] = &iColor16MConvertor;
1.106 + iColorConvertor[EColor16MU] = &iColor16MUConvertor;
1.107 + iColorConvertor[EColor16MA] = &iColor16MAConvertor;
1.108 + iColorConvertor[EColor16MAP] = &iColor16MAPConvertor;
1.109 + iOrientation = CFbsDrawDevice::EOrientationNormal;
1.110 + iOrientationEnd = CFbsDrawDevice::EOrientationRotated90;
1.111 + }
1.112 +
1.113 +CTLowLevel::~CTLowLevel()
1.114 + {
1.115 + Reset();
1.116 + }
1.117 +
1.118 +void CTLowLevel::Reset()
1.119 + {
1.120 + delete iDrawDevice;
1.121 + iDrawDevice = NULL;
1.122 +
1.123 + delete iBits;
1.124 + iBits = NULL;
1.125 + delete iBuf;
1.126 + iBuf = NULL;
1.127 + iDispMode = ENone;
1.128 + iSize.SetSize(0,0);
1.129 + iLongWidth = 0;
1.130 + }
1.131 +
1.132 +void CTLowLevel::RunTestCaseL(TInt aCurTestCase)
1.133 + {
1.134 + ((CTLowLevelStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.135 + switch(aCurTestCase)
1.136 + {
1.137 + case 1:
1.138 + INFO_PRINTF1(_L("Bitmap device EGray2"));
1.139 +/**
1.140 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0004
1.141 +*/
1.142 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0004"));
1.143 + TestBitmapDraw(EGray2,TSize(128,100));
1.144 + break;
1.145 + case 2:
1.146 + INFO_PRINTF1(_L("Bitmap device EGray4"));
1.147 +/**
1.148 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0005
1.149 +*/
1.150 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0005"));
1.151 + TestBitmapDraw(EGray4,TSize(112,100));
1.152 + break;
1.153 + case 3:
1.154 + INFO_PRINTF1(_L("Bitmap device EGray16"));
1.155 +/**
1.156 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0006
1.157 +*/
1.158 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0006"));
1.159 + TestBitmapDraw(EGray16,TSize(104,100));
1.160 + break;
1.161 + case 4:
1.162 + INFO_PRINTF1(_L("Bitmap device EGray256"));
1.163 +/**
1.164 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0007
1.165 +*/
1.166 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0007"));
1.167 + TestBitmapDraw(EGray256,TSize(104,100));
1.168 + break;
1.169 + case 5:
1.170 + INFO_PRINTF1(_L("Bitmap device EColor16"));
1.171 +/**
1.172 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0008
1.173 +*/
1.174 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0008"));
1.175 + TestBitmapDraw(EColor16,TSize(104,100));
1.176 + break;
1.177 + case 6:
1.178 + INFO_PRINTF1(_L("Bitmap device EColor256"));
1.179 +/**
1.180 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0009
1.181 +*/
1.182 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0009"));
1.183 + TestBitmapDraw(EColor256,TSize(102,100));
1.184 + break;
1.185 + case 7:
1.186 + INFO_PRINTF1(_L("Bitmap device EColor4K"));
1.187 +/**
1.188 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0010
1.189 +*/
1.190 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0010"));
1.191 + TestBitmapDraw(EColor4K,TSize(100,100));
1.192 + break;
1.193 + case 8:
1.194 + INFO_PRINTF1(_L("Bitmap device EColor64K"));
1.195 +/**
1.196 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0011
1.197 +*/
1.198 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0011"));
1.199 + TestBitmapDraw(EColor64K,TSize(100,100));
1.200 + break;
1.201 + case 9:
1.202 + INFO_PRINTF1(_L("Bitmap device EColor16M"));
1.203 +/**
1.204 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0012
1.205 +*/
1.206 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0012"));
1.207 + TestBitmapDraw(EColor16M,TSize(102,100));
1.208 + break;
1.209 + case 10:
1.210 + INFO_PRINTF1(_L("Bitmap device EColor16MU"));
1.211 + iFuzzyMatch=ETrue;
1.212 +/**
1.213 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0013
1.214 +*/
1.215 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0013"));
1.216 + TestBitmapDraw(EColor16MU,TSize(102,100));
1.217 + iFuzzyMatch=EFalse;
1.218 + break;
1.219 + case 11:
1.220 + INFO_PRINTF1(_L("Bitmap device EColor16MA"));
1.221 +/**
1.222 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0014
1.223 +*/
1.224 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0014"));
1.225 + TestBitmapDraw(EColor16MA,TSize(102,100));
1.226 + break;
1.227 + case 12:
1.228 + INFO_PRINTF1(_L("Bitmap device EColor16MAP"));
1.229 + iFuzzyMatch=ETrue;
1.230 +/**
1.231 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0015
1.232 +*/
1.233 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0015"));
1.234 + TestBitmapDraw(EColor16MAP,TSize(102,100));
1.235 + iFuzzyMatch=EFalse;
1.236 + break;
1.237 + case 13:
1.238 + INFO_PRINTF1(_L("User display mode mapping"));
1.239 +/**
1.240 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0016
1.241 +*/
1.242 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0016"));
1.243 + TestUserDisplayModeMapping();
1.244 + ((CTLowLevelStep*)iStep)->RecordTestResultL();
1.245 + break;
1.246 + default:
1.247 + if(iOrientation <= iOrientationEnd)
1.248 + {
1.249 +/**
1.250 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0017
1.251 +*/
1.252 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0017"));
1.253 + INFO_PRINTF2(_L("Screen device : %S"), &DisplayModeNames1[iCurScreenDeviceModeIndex]);
1.254 + TDisplayMode display = TestDisplayMode1[iCurScreenDeviceModeIndex++];
1.255 + TestScreenDrawL(display);
1.256 + if(iCurScreenDeviceModeIndex >= KNumberDisplayModes1)
1.257 + {
1.258 + iCurScreenDeviceModeIndex = 0;
1.259 + iOrientation ++;
1.260 + }
1.261 + }
1.262 + else
1.263 + {
1.264 + ((CTLowLevelStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.265 + ((CTLowLevelStep*)iStep)->CloseTMSGraphicsStep();
1.266 + TestComplete();
1.267 + ((CTLowLevelStep*)iStep)->RecordTestResultL();
1.268 + }
1.269 + break;
1.270 + }
1.271 + }
1.272 +
1.273 +/* this function is used for likeness matching, using a fixed inaccuracy */
1.274 +void CTLowLevel::CheckMatch(TUint32 aFirst,TUint32 aSecond)
1.275 + {
1.276 + TBool fail=EFalse;
1.277 + if (iFuzzyMatch==EFalse)
1.278 + fail|=Check(aFirst==aSecond);
1.279 + else
1.280 + {
1.281 + TUint8* val1=static_cast<TUint8*>(static_cast<void*>(&aFirst));
1.282 + TUint8* val2=static_cast<TUint8*>(static_cast<void*>(&aSecond));
1.283 + fail|=Check(AbsDiff(*val1,*val2)<KInaccuracyLimit);
1.284 + fail|=Check(AbsDiff(*(val1+1),*(val2+1))<KInaccuracyLimit);
1.285 + fail|=Check(AbsDiff(*(val1+2),*(val2+2))<KInaccuracyLimit);
1.286 + fail|=Check(AbsDiff(*(val1+3),*(val2+3))<KInaccuracyLimit);
1.287 + }
1.288 + if (fail)
1.289 + {
1.290 + _LIT(KLog,"The values 0x%x and 0x%x don't match, fuzzyMatch=%d (limit=%d)");
1.291 + INFO_PRINTF5(KLog,aFirst,aSecond,iFuzzyMatch,KInaccuracyLimit);
1.292 + }
1.293 + }
1.294 +
1.295 +void CTLowLevel::TestScreenDrawL(TDisplayMode aDisplayMode)
1.296 + {
1.297 + TUint startTime=User::TickCount();
1.298 +
1.299 + Reset();
1.300 +
1.301 + iDispMode = aDisplayMode;
1.302 +
1.303 + INFO_PRINTF1(_L("\n"));
1.304 + INFO_PRINTF2(_L("Testing Screen driver \"%S\""), &(DisplayModeNames[::DisplayMode2Index(aDisplayMode)]));
1.305 + INFO_PRINTF1(_L("\r\n"));
1.306 + TInt address = NULL;
1.307 + TSize size(0,0);
1.308 +
1.309 + User::LeaveIfError(HAL::Get(KDefaultScreenNo, HALData::EDisplayMemoryAddress,address));
1.310 + User::LeaveIfError(HAL::Get(KDefaultScreenNo, HALData::EDisplayXPixels,size.iWidth));
1.311 + User::LeaveIfError(HAL::Get(KDefaultScreenNo, HALData::EDisplayYPixels,size.iHeight));
1.312 + ASSERT(size.iWidth > 0 && size.iHeight > 0 && address != NULL);
1.313 +
1.314 + TPckgBuf<TScreenInfoV01> info;
1.315 + info().iScreenAddressValid = ETrue;
1.316 + info().iScreenAddress = REINTERPRET_CAST(TAny*,address);
1.317 + info().iScreenSize = size;
1.318 +
1.319 + TRAPD(ret,iDrawDevice = CFbsDrawDevice::NewScreenDeviceL(info(),aDisplayMode));
1.320 +
1.321 + if (ret == KErrNotSupported)
1.322 + {
1.323 + INFO_PRINTF1(_L("Not supported\r\n"));
1.324 + return;
1.325 + }
1.326 + else if (ret != KErrNone)
1.327 + User::Panic(_L("Draw device create"),ret);
1.328 +
1.329 + iDrawDevice->InitScreen();
1.330 + iDrawDevice->SetDisplayMode(iDrawDevice);
1.331 + iDrawDevice->SetAutoUpdate(EFalse);
1.332 + TBool orientation[4];
1.333 + iDrawDevice->OrientationsAvailable(orientation);
1.334 +
1.335 + TBool orientationSupported = iDrawDevice->SetOrientation(CFbsDrawDevice::TOrientation(iOrientation));
1.336 + if (orientationSupported)
1.337 + {
1.338 + Check(orientation[iOrientation]);
1.339 + if (iOrientation & 1)
1.340 + iSize = TSize(size.iHeight,size.iWidth);
1.341 + else
1.342 + iSize = size;
1.343 + iLongWidth = LongWidth(iSize.iWidth,aDisplayMode);
1.344 + Test();
1.345 + }
1.346 + else
1.347 + {
1.348 + Check(!orientation[iOrientation]);
1.349 + INFO_PRINTF1(_L("Orientation not supported\r\n"));
1.350 + }
1.351 +
1.352 + INFO_PRINTF2(_L("Testing time=%d"), (User::TickCount() - startTime) * 100 / 64);
1.353 + }
1.354 +
1.355 +void CTLowLevel::TestBitmapDraw(TDisplayMode aDisplayMode,const TSize& aSize)
1.356 + {
1.357 + TUint startTime=User::TickCount();
1.358 + Reset();
1.359 + iDispMode = aDisplayMode;
1.360 + iSize = aSize;
1.361 + iLongWidth = LongWidth(aSize.iWidth,aDisplayMode);
1.362 + TSize size(0,0);
1.363 + INFO_PRINTF1(KNullDesC);
1.364 +
1.365 + const TInt byteSize=ByteSize()*iSize.iHeight;
1.366 + _LIT(KNoMem,"Not enough memory for bitmap bits");
1.367 + iBits = new TUint8[byteSize];
1.368 + if(!iBits)
1.369 + {
1.370 + User::Panic(KNoMem,KErrNoMemory);
1.371 + }
1.372 +
1.373 + iBuf = new TUint32[byteSize];
1.374 + if(!iBuf)
1.375 + {
1.376 + User::Panic(KNoMem,KErrNoMemory);
1.377 + }
1.378 +
1.379 + TPckgBuf<TScreenInfoV01> info;
1.380 + info().iScreenSize = aSize;
1.381 + info().iScreenAddress = NULL;
1.382 + info().iScreenAddressValid = ETrue;
1.383 +
1.384 + TRAPD(ret, iDrawDevice = CFbsDrawDevice::NewBitmapDeviceL(info(), aDisplayMode, ByteSize() ));
1.385 + if (ret == KErrNotSupported)
1.386 + {
1.387 + INFO_PRINTF1(_L("Not supported\r\n"));
1.388 + return;
1.389 + }
1.390 + else if (ret != KErrNone)
1.391 + {
1.392 + User::Panic(_L("Draw device create"),ret);
1.393 + }
1.394 + iDrawDevice->SetAutoUpdate(EFalse);
1.395 + //Initialize the iDrowDevice object, if successful val=KErrNone
1.396 + TInt val=iDrawDevice->InitScreen();
1.397 + TEST(val==KErrNone);
1.398 + iDrawDevice->CFbsDrawDevice::SetBits(iBits);
1.399 + iDrawDevice->CFbsDrawDevice::ShadowBuffer(10,iBuf);
1.400 + iDrawDevice->CFbsDrawDevice::SetUserDisplayMode(iDispMode);
1.401 + iDrawDevice->SetDisplayMode(iDrawDevice);
1.402 + iDrawDevice->Update();
1.403 + iDrawDevice->SetUserDisplayMode(iDispMode);
1.404 + iDrawDevice->SetBits(iBits);
1.405 + Test();
1.406 + TBool orientation[4];
1.407 + iDrawDevice->OrientationsAvailable(orientation);
1.408 + TBool orientationSupported = iDrawDevice->SetOrientation(CFbsDrawDevice::TOrientation(iOrientation));
1.409 + if (orientationSupported)
1.410 + {
1.411 + Check(orientation[iOrientation]);
1.412 + if (iOrientation & 1)
1.413 + iSize = TSize(size.iHeight,size.iWidth);
1.414 + else
1.415 + iSize = size;
1.416 + iLongWidth = LongWidth(iSize.iWidth,aDisplayMode);
1.417 + }
1.418 + else
1.419 + {
1.420 + Check(!orientation[iOrientation]);
1.421 + INFO_PRINTF1(_L("Orientation not supported\r\n"));
1.422 + }
1.423 + INFO_PRINTF2(_L("Testing time=%d"), (User::TickCount() - startTime) * 100 / 64);
1.424 + }
1.425 +
1.426 +TInt RgbComponent(TRgb aRgb, TInt aRgbIndex)
1.427 + {
1.428 + return(aRgbIndex==0?aRgb.Red():(aRgbIndex==1?aRgb.Green():aRgb.Blue()));
1.429 + }
1.430 +
1.431 +TBool CheckNormalizedValue(TRgb aReadCol, TRgb aNormalizedCol1, TRgb aNormalizedCol2, TRgb aNormalizedCol3, TRgb aNormalizedCol4, TInt aRgbIndex)
1.432 + {
1.433 +
1.434 + const TInt KErrorMargin=5;
1.435 + TInt minCol=Min(RgbComponent(aNormalizedCol1,aRgbIndex),
1.436 + Min(RgbComponent(aNormalizedCol2,aRgbIndex),
1.437 + Min(RgbComponent(aNormalizedCol3,aRgbIndex),RgbComponent(aNormalizedCol4,aRgbIndex))))-KErrorMargin;
1.438 + TInt maxCol=Max(RgbComponent(aNormalizedCol1,aRgbIndex),
1.439 + Max(RgbComponent(aNormalizedCol2,aRgbIndex),
1.440 + Max(RgbComponent(aNormalizedCol3,aRgbIndex),RgbComponent(aNormalizedCol4,aRgbIndex))))+KErrorMargin;
1.441 + TInt readComponent=RgbComponent(aReadCol,aRgbIndex);
1.442 + return(readComponent>=minCol && readComponent<=maxCol);
1.443 + }
1.444 +
1.445 +void CTLowLevel::CheckNormalizedRgb(TRgb aReadRgb, TRgb aCheckRgb, TDisplayMode aDevDisplayMode, TDisplayMode aUserDisplayMode, TBool aWriteRgbAlphaLine)
1.446 + {
1.447 + TRgb normalized1=aCheckRgb;
1.448 + Normalize(normalized1,aUserDisplayMode);
1.449 + if (aDevDisplayMode==EColor16MAP)
1.450 + {
1.451 + const TInt KNormalizeErrorMargin=3;
1.452 + TRgb normalizedPMA1=aCheckRgb;
1.453 +// Allow error margin for blending errors before calculating value normalized to user display mode
1.454 + normalizedPMA1.SetRed(Min(0xFF,normalizedPMA1.Red()+KNormalizeErrorMargin));
1.455 + normalizedPMA1.SetGreen(Min(0xFF,normalizedPMA1.Green()+KNormalizeErrorMargin));
1.456 + normalizedPMA1.SetBlue(Min(0xFF,normalizedPMA1.Blue()+KNormalizeErrorMargin));
1.457 +//
1.458 + Normalize(normalizedPMA1,aUserDisplayMode);
1.459 + TRgb normalizedPMA3=normalizedPMA1;
1.460 + normalizedPMA1=TRgb::Color16MAP(normalizedPMA1.Color16MAP());
1.461 + TRgb normalizedPMA2=aCheckRgb;
1.462 + normalizedPMA2=TRgb::Color16MAP(normalizedPMA2.Color16MAP());
1.463 + normalizedPMA2.SetRed(Max(0,normalizedPMA2.Red()-KNormalizeErrorMargin));
1.464 + normalizedPMA2.SetGreen(Max(0,normalizedPMA2.Green()-KNormalizeErrorMargin));
1.465 + normalizedPMA2.SetBlue(Max(0,normalizedPMA2.Blue()-KNormalizeErrorMargin));
1.466 + Normalize(normalizedPMA2,aUserDisplayMode);
1.467 + TEST(CheckNormalizedValue(aReadRgb,normalizedPMA1,normalizedPMA2,normalizedPMA3,normalized1,0) &&
1.468 + CheckNormalizedValue(aReadRgb,normalizedPMA1,normalizedPMA2,normalizedPMA3,normalized1,1) &&
1.469 + CheckNormalizedValue(aReadRgb,normalizedPMA1,normalizedPMA2,normalizedPMA3,normalized1,2));
1.470 + }
1.471 + else
1.472 + {
1.473 + if (aDevDisplayMode==EColor64K && aWriteRgbAlphaLine)
1.474 + {
1.475 + // In EColor64K the WriteRgbAlphaLine code maps to native display mode first, before mapping to
1.476 + // user mode then back again to device display mode. So use normalized2 to check for that case
1.477 + TRgb normalized2=aCheckRgb;
1.478 + Normalize(normalized2,aDevDisplayMode);
1.479 + Normalize(normalized2,aUserDisplayMode);
1.480 + Normalize(normalized2,aDevDisplayMode);
1.481 + TEST(aReadRgb.Color16MU()==normalized2.Color16MU());
1.482 + }
1.483 + else
1.484 + {
1.485 + Normalize(normalized1,aDevDisplayMode);
1.486 + TEST(aReadRgb.Color16MU()==normalized1.Color16MU());
1.487 + }
1.488 + }
1.489 + }
1.490 +
1.491 +void CTLowLevel::PrepareDestPixel(TDisplayMode aDevDisplayMode, TRgb& aRgb, TInt aDstAlpha)
1.492 + {
1.493 + CGraphicsContext::TDrawMode drawMode;
1.494 + if (aDevDisplayMode==EColor16MAP)
1.495 + {
1.496 + aRgb.SetAlpha(aDstAlpha);
1.497 + drawMode=CGraphicsContext::EDrawModeWriteAlpha;
1.498 + }
1.499 + else
1.500 + {
1.501 + aRgb.SetAlpha(0xFF);
1.502 + drawMode=CGraphicsContext::EDrawModePEN;
1.503 + }
1.504 + iDrawDevice->WriteRgbMulti(0,0,1,1,aRgb,drawMode);
1.505 + }
1.506 +
1.507 +void CTLowLevel::CheckMappedRgb(TDisplayMode aDevDisplayMode, TDisplayMode aUserDisplayMode, TRgb aRgb)
1.508 + {
1.509 + const TInt KMaxAlphaModes=5;
1.510 + TInt alphaModeValues[KMaxAlphaModes]={0xFF,0xC0,0x80,0x40,0};
1.511 + TInt dstAlphaModeCount=aDevDisplayMode==EColor16MAP?KMaxAlphaModes:1;
1.512 + for(TInt dstAlphaMode=0;dstAlphaMode<dstAlphaModeCount;dstAlphaMode++)
1.513 + {
1.514 + TInt dstAlpha=alphaModeValues[dstAlphaMode];
1.515 + for(TInt alphaMode=0;alphaMode<KMaxAlphaModes;alphaMode++)
1.516 + {
1.517 + TInt alpha=alphaModeValues[alphaMode];
1.518 + if ((aUserDisplayMode==EColor16 || aUserDisplayMode==EColor256) && (alpha!=0xFF || dstAlpha!=0xFF))
1.519 + continue; // Mapping to EColor16 or EColor256 with fuzzy blends and PMA losses impossible to check for accurately
1.520 + PrepareDestPixel(aDevDisplayMode,aRgb,dstAlpha);
1.521 + aRgb.SetAlpha(alpha);
1.522 + iDrawDevice->WriteRgb(0,0,aRgb,CGraphicsContext::EDrawModePEN);
1.523 + TRgb readRgb=iDrawDevice->ReadPixel(0,0);
1.524 + CheckNormalizedRgb(readRgb,aRgb,aDevDisplayMode,aUserDisplayMode,EFalse);
1.525 +//
1.526 + PrepareDestPixel(aDevDisplayMode,aRgb,dstAlpha);
1.527 + iDrawDevice->WriteRgbMulti(0,0,1,1,aRgb,CGraphicsContext::EDrawModePEN);
1.528 + readRgb=iDrawDevice->ReadPixel(0,0);
1.529 + CheckNormalizedRgb(readRgb,aRgb,aDevDisplayMode,aUserDisplayMode,EFalse);
1.530 +//
1.531 + PrepareDestPixel(aDevDisplayMode,aRgb,dstAlpha);
1.532 + TUint32 writeBuffer[1];
1.533 + writeBuffer[0]=aRgb.Internal();
1.534 + TUint8 mask[1]={0xFF};
1.535 + iDrawDevice->WriteRgbAlphaLine(0,0,1,(TUint8*)writeBuffer,mask,CGraphicsContext::EDrawModePEN);
1.536 + readRgb=iDrawDevice->ReadPixel(0,0);
1.537 + CheckNormalizedRgb(readRgb,aRgb,aDevDisplayMode,aUserDisplayMode,ETrue);
1.538 + }
1.539 + }
1.540 + }
1.541 +
1.542 +void CTLowLevel::TestUserDisplayModeMapping()
1.543 + {
1.544 + TInt address = NULL;
1.545 + TSize size;
1.546 + User::LeaveIfError(HAL::Get(KDefaultScreenNo, HALData::EDisplayMemoryAddress,address));
1.547 + User::LeaveIfError(HAL::Get(KDefaultScreenNo, HALData::EDisplayXPixels,size.iWidth));
1.548 + User::LeaveIfError(HAL::Get(KDefaultScreenNo, HALData::EDisplayYPixels,size.iHeight));
1.549 + ASSERT(size.iWidth > 0 && size.iHeight > 0 && address != NULL);
1.550 +
1.551 + TPckgBuf<TScreenInfoV01> info;
1.552 + info().iScreenAddressValid = ETrue;
1.553 + info().iScreenAddress = REINTERPRET_CAST(TAny*,address);
1.554 + info().iScreenSize = size;
1.555 +//
1.556 + for (TInt nDispModeDev = 0; nDispModeDev < KNumDispModes; nDispModeDev++)
1.557 + {
1.558 + TDisplayMode dispModeDev = TestDisplayMode[nDispModeDev];
1.559 + if (!TDisplayModeUtils::IsDisplayModeColor(dispModeDev) || TDisplayModeUtils::NumDisplayModeColors(dispModeDev)<65536)
1.560 + continue; // Older modes have their quirks we don't want to mess with
1.561 + Reset();
1.562 + TRAPD(ret,iDrawDevice = CFbsDrawDevice::NewScreenDeviceL(info(),dispModeDev));
1.563 + if (ret == KErrNotSupported)
1.564 + continue;
1.565 + for (TInt nDispMode = 0; nDispMode < KNumDispModes; nDispMode++)
1.566 + {
1.567 + TDisplayMode userDispMode = TestDisplayMode[nDispMode];
1.568 + INFO_PRINTF3(_L("Testing devMode=%d, userMode=%d"), dispModeDev, userDispMode);
1.569 + iDrawDevice->SetUserDisplayMode(userDispMode);
1.570 + TUint rgbVal=0;
1.571 + FOREVER
1.572 + {
1.573 + CheckMappedRgb(dispModeDev,userDispMode,rgbVal);
1.574 + if (rgbVal==0xFFFFFF)
1.575 + break;
1.576 + rgbVal+=0x010305;
1.577 + if (rgbVal>0xFFFFFF) // We want to make sure we test 0xFFFFFF as a special case
1.578 + rgbVal=0xFFFFFF;
1.579 + }
1.580 + }
1.581 + }
1.582 + }
1.583 +
1.584 +void CTLowLevel::Test()
1.585 + {
1.586 + _LIT(KOrientation,"Orientation: %S");
1.587 + TBuf<32> buf;
1.588 + buf.Format(KOrientation,&RotationName(iOrientation));
1.589 + INFO_PRINTF1(buf);
1.590 +
1.591 + iTestNo = 1;
1.592 + iIteration = 0;
1.593 + iReportIteration = 1;
1.594 + iTotalReportIterations = 1;
1.595 + TestParams();
1.596 +
1.597 + iTestNo++;
1.598 + iIteration = 0;
1.599 + iReportIteration = 1;
1.600 + iTotalReportIterations = KNumDispModes;
1.601 + TestReadLine();
1.602 +
1.603 + iTestNo++;
1.604 + iIteration = 0;
1.605 + iReportIteration = 1;
1.606 + iTotalReportIterations = KNumShadowModes * KNumDrawModes;
1.607 + if(KFastFading && (iDispMode == EColor64K ||iDispMode == EColor16MU || iDispMode == EColor16MA || iDispMode == EColor16MAP))
1.608 + {
1.609 + iUseFastFade = ETrue;
1.610 + }
1.611 + TestWriteRgb();
1.612 +
1.613 + iTestNo++;
1.614 + iIteration = 0;
1.615 + iReportIteration = 1;
1.616 + TestWriteLine();
1.617 +
1.618 + iTestNo++;
1.619 + iIteration = 0;
1.620 + iReportIteration = 1;
1.621 + TestWriteBinary();
1.622 +
1.623 + iTestNo++;
1.624 + iIteration = 0;
1.625 + iReportIteration = 1;
1.626 + iTotalReportIterations = 4;
1.627 + TestWriteRGBAlpha();
1.628 +
1.629 + iTestNo++;
1.630 + iIteration = 0;
1.631 + iReportIteration = 1;
1.632 + iTotalReportIterations = KNumShadowModes;
1.633 + TestShadow();
1.634 + if(KFastFading && (iDispMode == EColor64K|| iDispMode == EColor16MU || iDispMode == EColor16MA || iDispMode == EColor16MAP))
1.635 + {
1.636 + iUseFastFade = EFalse;
1.637 + }
1.638 +
1.639 + iTestNo++;
1.640 + iIteration = 0;
1.641 + iReportIteration = 1;
1.642 + iTotalReportIterations = 1;
1.643 + TestWriteAlphaLineEx();
1.644 +
1.645 + iTestNo++;
1.646 + iIteration = 0;
1.647 + iReportIteration = 1;
1.648 + iTotalReportIterations = 1;
1.649 + TestWriteAlphaLineNoShadowEx();
1.650 +
1.651 + iTestNo++;
1.652 + iIteration = 0;
1.653 + iReportIteration = 1;
1.654 + iTotalReportIterations = 1;
1.655 + TestWriteMaskLineNoShadowEx();
1.656 +
1.657 + iTestNo++;
1.658 + iIteration = 0;
1.659 + iReportIteration = 1;
1.660 + iTotalReportIterations = 1;
1.661 + TRAPD(err,((CTLowLevelStep*)iStep)->RecordTestResultL(););
1.662 + if (err!=KErrNone)
1.663 + INFO_PRINTF1(_L("Failed to record test result"));
1.664 +
1.665 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0003"));
1.666 + TestFastBlendBitmapMasked();
1.667 + TRAPD(err1,((CTLowLevelStep*)iStep)->RecordTestResultL(););
1.668 + if (err1!=KErrNone)
1.669 + INFO_PRINTF1(_L("Failed to record test result"));
1.670 +
1.671 + iTestNo++;
1.672 + iIteration = 0;
1.673 + iReportIteration = 1;
1.674 + iTotalReportIterations = KNumBlendingColors;
1.675 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0002"));
1.676 + //TestWriteRgbOutlineAndShadow(); // commented out pending case resolution #327407
1.677 + TRAP(err,((CTLowLevelStep*)iStep)->RecordTestResultL(););
1.678 + if (err!=KErrNone)
1.679 + INFO_PRINTF1(_L("Failed to record test result"));
1.680 +/**
1.681 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0001
1.682 +*/
1.683 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0001"));
1.684 + }
1.685 +
1.686 +void CTLowLevel::TestParams()
1.687 + {
1.688 + Check(iDrawDevice->SizeInPixels()==iSize);
1.689 + Check(iDrawDevice->DisplayMode()==iDispMode);
1.690 + Check(iDrawDevice->LongWidth()==iLongWidth);
1.691 + Check(iDrawDevice->ScanLineBuffer()!=NULL);
1.692 + Check(iLongWidth%(iDrawDevice->ScanLineBytes())==0
1.693 + || iDrawDevice->ScanLineBytes() == iLongWidth * 2
1.694 + || iDrawDevice->ScanLineBytes() == iLongWidth * 3
1.695 + || iDrawDevice->ScanLineBytes() == iLongWidth * 4);
1.696 + TInt hT = iDrawDevice->HorzTwipsPerThousandPixels();
1.697 + Check(hT >= 0);
1.698 + TInt vT = iDrawDevice->VertTwipsPerThousandPixels();
1.699 + Check(vT >= 0);
1.700 + Report();
1.701 + }
1.702 +
1.703 +void CTLowLevel::TestReadLine()
1.704 + {
1.705 + TInt byteSize = ByteSize();
1.706 + TUint8* writeBuffer = new TUint8[byteSize];
1.707 + TUint8* readBuffer = new TUint8[iSize.iWidth * sizeof(TRgb)];
1.708 + Check(writeBuffer != NULL);
1.709 + Check(readBuffer != NULL);
1.710 +
1.711 + for (TInt nDispMode = 0; nDispMode < KNumDispModes; nDispMode++)
1.712 + {
1.713 + TDisplayMode dispMode = TestDisplayMode[nDispMode];
1.714 + iDrawDevice->SetUserDisplayMode(dispMode);
1.715 +
1.716 + if (dispMode == EColor16MU || dispMode == EColor16MAP || iDispMode == EColor16MU || iDispMode == EColor16MAP)
1.717 + iFuzzyMatch=ETrue;
1.718 + else
1.719 + iFuzzyMatch=EFalse;
1.720 + for (TInt cnt=0;cnt<2;cnt++)
1.721 + {
1.722 + if (cnt==0) //first time
1.723 + iDrawDevice->SetUserDisplayMode(dispMode);
1.724 + else
1.725 + iDrawDevice->SetUserDisplayMode(iDispMode);
1.726 +
1.727 + for (TInt nRect = 0; nRect < KNumTestRects; nRect++)
1.728 + {
1.729 + TRect rect = TestRect[nRect];
1.730 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.731 + {
1.732 + Clear(KRgbWhite);
1.733 +
1.734 + FillBuffer(writeBuffer, byteSize, iDispMode, ETrue);
1.735 + Mem::FillZ(readBuffer,byteSize);
1.736 +
1.737 + //we select EDrawModeWriteAlpha because do not test blending here
1.738 + iDrawDevice->WriteLine(rect.iTl.iX,yy,rect.Width(),(TUint32*)writeBuffer,CGraphicsContext::EDrawModeWriteAlpha);
1.739 + iDrawDevice->ReadLine(rect.iTl.iX,yy,rect.Width(),(TUint32*)readBuffer,dispMode);
1.740 +
1.741 + CheckBuffer(writeBuffer,iDispMode,readBuffer,dispMode,rect.Width());
1.742 +
1.743 + Mem::FillZ(readBuffer,byteSize);
1.744 +
1.745 + //we select EDrawModeWriteAlpha because do not test blending here
1.746 + iDrawDevice->WriteLine(iSize.iWidth-rect.Width(),yy,rect.Width(),(TUint32*)writeBuffer,CGraphicsContext::EDrawModeWriteAlpha);
1.747 + iDrawDevice->ReadLine(iSize.iWidth-rect.Width(),yy,rect.Width(),(TUint32*)readBuffer,dispMode);
1.748 +
1.749 + CheckBuffer(writeBuffer,iDispMode,readBuffer,dispMode,rect.Width());
1.750 + iIteration++;
1.751 + }
1.752 + }
1.753 + }
1.754 + if (iDispMode != EColor16MU && iDispMode != EColor16MAP)
1.755 + iFuzzyMatch=EFalse;
1.756 + Report();
1.757 + }
1.758 + delete [] writeBuffer;
1.759 + delete [] readBuffer;
1.760 + }
1.761 +
1.762 +void CTLowLevel::TestWriteRgb()
1.763 + {
1.764 + for (TInt shadowMode = 0; shadowMode < KNumShadowModes; shadowMode++)
1.765 + {
1.766 + for (TInt nMode = 0; nMode < KNumDrawModes; nMode++)
1.767 + {
1.768 + for (TInt nRect = 0; nRect < KNumTestRects; nRect++)
1.769 + {
1.770 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.771 + {
1.772 + for (TInt nColor = 0; nColor < KNumTestColors; nColor++)
1.773 + {
1.774 +
1.775 + //for modes other than EColor16MAP skip the new colours which have alpha, and cause
1.776 + //test failures. There are two types of colours which need to be skipped, nColor,
1.777 + //and nBackColor. The additional colours were added specificially to test EColor16MAP mode,
1.778 + //so the test coverage compared to previously is not reduced for non EColor16MAP modes.
1.779 + if (((nColor>=KMaxNon16Colours)|| (nBackColor>=KMaxNon16BackColours)) && (iDispMode!= EColor16MAP))
1.780 + continue;
1.781 +
1.782 + TRgb bakCol = TestBackground[nBackColor];
1.783 + Clear(bakCol);
1.784 +
1.785 + CGraphicsContext::TDrawMode dMode = TestDrawMode[nMode];
1.786 +
1.787 + if ((iDispMode==EColor16MAP)&&(dMode!=CGraphicsContext::EDrawModePEN))
1.788 + continue;
1.789 +
1.790 +
1.791 + TRect rect = TestRect[nRect];
1.792 + TRgb col = TestColor[nColor];
1.793 +
1.794 + iDrawDevice->CFbsDrawDevice::SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.795 + iDrawDevice->CFbsDrawDevice::SetFadingParameters(100,200);
1.796 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.797 + iDrawDevice->WriteRgb(rect.iTl.iX,rect.iTl.iY,col,dMode);
1.798 +
1.799 + CheckRgb(rect.iTl,col,bakCol,dMode,shadowMode);
1.800 + CheckBackground(TRect(rect.iTl,TSize(1,1)),bakCol);
1.801 +
1.802 + Clear(bakCol);
1.803 +
1.804 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.805 + iDrawDevice->WriteRgbMulti(rect.iTl.iX,rect.iTl.iY,rect.Width(),rect.Height(),col,dMode);
1.806 +
1.807 + CheckRgb(rect,col,bakCol,dMode,shadowMode);
1.808 + CheckBackground(rect,bakCol);
1.809 + iIteration++;
1.810 + }
1.811 + }
1.812 + }
1.813 + Report();
1.814 + }
1.815 + }
1.816 + }
1.817 +
1.818 +void CTLowLevel::TestWriteLine()
1.819 + {
1.820 + TInt byteSize = ByteSize();
1.821 + TUint8* backBuffer = new TUint8[byteSize];
1.822 + TUint8* writeBuffer = new TUint8[byteSize];
1.823 + TUint8* copyBuffer = new TUint8[byteSize];
1.824 + TUint8* readBuffer = new TUint8[byteSize];
1.825 + Check(backBuffer != NULL);
1.826 + Check(writeBuffer != NULL);
1.827 + Check(copyBuffer != NULL);
1.828 + Check(readBuffer != NULL);
1.829 +
1.830 + for (TInt shadowMode = 0; shadowMode < KNumShadowModes; shadowMode++)
1.831 + {
1.832 + for (TInt nMode = 0; nMode < KNumDrawModes; nMode++)
1.833 + {
1.834 + CGraphicsContext::TDrawMode dMode = TestDrawMode[nMode];
1.835 + for (TInt nRect = 0; nRect < KNumTestRects; nRect++)
1.836 + {
1.837 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.838 + {
1.839 + //skip over new colours with alpha for modes other than EColor16MAP
1.840 + //these were causing test failures
1.841 + if ((nBackColor>=KMaxNon16BackColours) && (iDispMode!= EColor16MAP))
1.842 + continue;
1.843 +
1.844 + TRgb bakCol = TestBackground[nBackColor];
1.845 + Clear(bakCol);
1.846 + TRect rect = TestRect[nRect];
1.847 + /*TBuf<128> buf; //Some extra logging that might be useful if this test fails
1.848 + _LIT(KLog1,"Shadow=%d, DrawMode=%d, Rect=(%d,%d,%d,%d), Color=%d");
1.849 + buf.Format(KLog1,shadowMode,dMode,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY,nBackColor);
1.850 + INFO_PRINTF1(buf);*/
1.851 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.852 + {
1.853 + iDrawDevice->CFbsDrawDevice::SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.854 + iDrawDevice->CFbsDrawDevice::SetFadingParameters(100,200);
1.855 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.856 + iDrawDevice->ReadLine(rect.iTl.iX,yy,rect.Width(),(TUint32*)backBuffer,iDispMode);
1.857 +
1.858 + if (nRect != 7)
1.859 + {
1.860 + // make sure the alpha value is 0xFF when not blending the buffer into 16MU destination
1.861 + TBool noAlpha16MU = dMode != CGraphicsContext::EDrawModePEN;
1.862 + FillBuffer(writeBuffer, byteSize, iDispMode, noAlpha16MU);
1.863 + }
1.864 + else // Special check for losing leading 0s in 1 bpp mode at 31 pixel offset
1.865 + {
1.866 + Mem::Fill(writeBuffer,byteSize,0xff);
1.867 + writeBuffer[0] = 0xfe;
1.868 + }
1.869 + Mem::Copy(copyBuffer,writeBuffer,byteSize);
1.870 + iDrawDevice->WriteLine(rect.iTl.iX,yy,rect.Width(),(TUint32*)writeBuffer,dMode);
1.871 + Shadow(copyBuffer,byteSize,shadowMode);
1.872 +
1.873 + Mem::FillZ(readBuffer,byteSize);
1.874 + iDrawDevice->ReadLine(rect.iTl.iX,yy,rect.Width(),(TUint32*)readBuffer,iDispMode);
1.875 + CheckLine(copyBuffer,readBuffer,backBuffer,rect.Width(),dMode,iDispMode);
1.876 +
1.877 + iIteration++;
1.878 + }
1.879 + CheckBackground(rect,bakCol);
1.880 + }
1.881 + }
1.882 + Report();
1.883 + }
1.884 + }
1.885 + delete [] backBuffer;
1.886 + delete [] writeBuffer;
1.887 + delete [] copyBuffer;
1.888 + delete [] readBuffer;
1.889 + }
1.890 +
1.891 +void CTLowLevel::TestWriteBinary()
1.892 + {
1.893 + TInt byteSize = ByteSize();
1.894 + TInt wordSize = (byteSize + 3) / 4;
1.895 + TUint32* writeBuffer = new TUint32[wordSize];
1.896 + Check(writeBuffer != NULL);
1.897 +
1.898 + for (TInt shadowMode = 0; shadowMode < KNumShadowModes; shadowMode++)
1.899 + {
1.900 + for (TInt nMode = 0; nMode < KNumDrawModes; nMode++)
1.901 + {
1.902 + for (TInt nRect = 0; nRect < KNumTestRects; nRect++)
1.903 + {
1.904 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.905 + {
1.906 + for (TInt nColor = 0; nColor < KNumTestColors; nColor++)
1.907 + {
1.908 + if (((nColor>=KMaxNon16Colours)|| (nBackColor>=KMaxNon16BackColours)) && (iDispMode!= EColor16MAP))
1.909 + continue;
1.910 +
1.911 + TRect rect = TestRect[nRect];
1.912 + if (rect.Width() > 32)
1.913 + {
1.914 + rect.iBr.iX = rect.iTl.iX + 32;
1.915 + }
1.916 + if (rect.Width() < 1)
1.917 + rect.iBr.iX = rect.iTl.iX + 1;
1.918 +
1.919 + TRgb bakCol = TestBackground[nBackColor];
1.920 + TRgb col = TestColor[nColor];
1.921 + CGraphicsContext::TDrawMode dMode = TestDrawMode[nMode];
1.922 +
1.923 + if ((iDispMode==EColor16MAP)&&(dMode!=CGraphicsContext::EDrawModePEN))
1.924 + continue;
1.925 +
1.926 + Clear(bakCol);
1.927 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.928 + FillBuffer((TUint8*)writeBuffer, byteSize, EGray2);
1.929 + iDrawDevice->WriteBinary(rect.iTl.iX,rect.iTl.iY,writeBuffer,rect.Width(),rect.Height(),col,dMode);
1.930 + CheckBinary(rect,writeBuffer,col,bakCol,dMode,shadowMode,ETrue,EFalse);
1.931 + CheckBackground(rect,bakCol);
1.932 +
1.933 + Clear(bakCol);
1.934 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.935 + FillBuffer((TUint8*)writeBuffer, byteSize, EGray2);
1.936 + iDrawDevice->WriteBinaryLine(rect.iTl.iX,rect.iTl.iY,writeBuffer,rect.Width(),col,dMode);
1.937 + CheckBinary(TRect(rect.iTl,TSize(rect.Width(),1)),writeBuffer,col,bakCol,dMode,shadowMode,EFalse,EFalse);
1.938 + CheckBackground(TRect(rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iTl.iY + 1),bakCol);
1.939 +
1.940 + Clear(bakCol);
1.941 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.942 + FillBuffer((TUint8*)writeBuffer, byteSize, EGray2);
1.943 + iDrawDevice->WriteBinaryLineVertical(rect.iTl.iX,rect.iTl.iY,writeBuffer,rect.Height(),col,dMode,EFalse);
1.944 + CheckBinary(TRect(rect.iTl,TSize(1,rect.Height())),writeBuffer,col,bakCol,dMode,shadowMode,EFalse,EFalse);
1.945 + CheckBackground(TRect(rect.iTl.iX,rect.iTl.iY,rect.iTl.iX + 1,rect.iBr.iY),bakCol);
1.946 +
1.947 + Clear(bakCol);
1.948 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.949 + FillBuffer((TUint8*)writeBuffer, byteSize, EGray2);
1.950 + iDrawDevice->WriteBinaryLineVertical(rect.iTl.iX,rect.iBr.iY - 1,writeBuffer,rect.Height(),col,dMode,ETrue);
1.951 + CheckBinary(TRect(rect.iTl,TSize(1,rect.Height())),writeBuffer,col,bakCol,dMode,shadowMode,EFalse,ETrue);
1.952 + CheckBackground(TRect(rect.iTl.iX,rect.iTl.iY,rect.iTl.iX + 1,rect.iBr.iY),bakCol);
1.953 +
1.954 + iIteration++;
1.955 + }
1.956 + }
1.957 + }
1.958 + Report();
1.959 + }
1.960 + }
1.961 + delete [] writeBuffer;
1.962 + }
1.963 +
1.964 +void CTLowLevel::TestWriteAlphaLineEx()
1.965 + {
1.966 + TAny* interface = NULL;
1.967 + TInt err = iDrawDevice->GetInterface(KFastBlitInterfaceID, interface);
1.968 + if(err == KErrNone)
1.969 + {
1.970 + INFO_PRINTF1(_L("START ---->TestWriteAlphaLineEx"));
1.971 + TSize size = TSize(30,30);
1.972 + TRect rect = TRect(size);
1.973 +
1.974 + TUint16* writeBuffer = new TUint16[size.iWidth];
1.975 + TUint8* maskBuffer = new TUint8[size.iWidth];
1.976 +
1.977 + TInt nOffset = sizeof(TUint16)*size.iWidth/2;
1.978 +
1.979 + Mem::Fill(writeBuffer,nOffset,0xff);
1.980 + Mem::Fill((((TUint8*)writeBuffer)+nOffset),nOffset,0x00);
1.981 + Mem::Fill(maskBuffer,size.iWidth/2,0x00);
1.982 + Mem::Fill((maskBuffer+size.iWidth/2),size.iWidth/2,0xff);
1.983 +
1.984 + MFastBlit* fastBlit = reinterpret_cast<MFastBlit*>(interface);
1.985 + Clear(KRgbFadedBlack);
1.986 + iDrawDevice->SetShadowMode(CFbsDrawDevice::EFade);
1.987 +
1.988 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.989 + {
1.990 + fastBlit->WriteAlphaLineEx(rect.iTl.iX,yy,rect.Width(),0,(TUint32*)writeBuffer,EColor64K,0,(TUint32*)maskBuffer,MAlphaBlend::EShdwBefore);
1.991 + iIteration++;
1.992 + }
1.993 + CheckRgb(rect,KRgbBlack,KRgbFadedBlack,CGraphicsContext::EDrawModePEN,2);
1.994 + CheckBackground(rect,KRgbFadedBlack);
1.995 +
1.996 + Report();
1.997 + INFO_PRINTF1(_L("END ---->TestWriteAlphaLineEx"));
1.998 + delete [] writeBuffer;
1.999 + delete [] maskBuffer;
1.1000 + }
1.1001 + }
1.1002 +
1.1003 +void CTLowLevel::TestWriteAlphaLineNoShadowEx()
1.1004 + {
1.1005 + TAny* interface = NULL;
1.1006 + TInt err = iDrawDevice->GetInterface(KFastBlitInterfaceID, interface);
1.1007 + if(err == KErrNone)
1.1008 + {
1.1009 + INFO_PRINTF1(_L("START ---->TestWriteAlphaLineNoShadowEx"));
1.1010 + TSize size = TSize(30,30);
1.1011 + TRect rect = TRect(size);
1.1012 +
1.1013 + TUint16* writeBuffer = new TUint16[size.iWidth];
1.1014 + Check(writeBuffer != NULL);
1.1015 + TUint8* maskBuffer = new TUint8[size.iWidth];
1.1016 + Check(maskBuffer != NULL);
1.1017 + TInt nOffset = sizeof(TUint16) * size.iWidth;
1.1018 +
1.1019 + Mem::Fill(writeBuffer,nOffset,0xff);
1.1020 + Mem::Fill(maskBuffer,size.iWidth/2,0x8e);
1.1021 + Mem::Fill((maskBuffer+size.iWidth/2),size.iWidth/2,0xff);
1.1022 +
1.1023 + MFastBlit* fastBlit = reinterpret_cast<MFastBlit*>(interface);
1.1024 +
1.1025 + Clear(KRgbWhite);
1.1026 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.1027 + {
1.1028 + fastBlit->WriteAlphaLineEx(rect.iTl.iX,yy,rect.Width(),0,(TUint32*)writeBuffer,EColor64K,0,(TUint32*)maskBuffer,MAlphaBlend::EShdwBefore);
1.1029 + iIteration++;
1.1030 + }
1.1031 + CheckRgb(rect,KRgbWhite,KRgbWhite,CGraphicsContext::EDrawModePEN,0);
1.1032 +
1.1033 + Report();
1.1034 + INFO_PRINTF1(_L("END ---->TestWriteAlphaLineNoShadowEx"));
1.1035 + delete [] writeBuffer;
1.1036 + delete [] maskBuffer;
1.1037 + }
1.1038 + }
1.1039 +
1.1040 +void CTLowLevel::TestWriteMaskLineNoShadowEx()
1.1041 + {
1.1042 + TAny* interface = NULL;
1.1043 + TInt err = iDrawDevice->GetInterface(KFastBlitInterfaceID, interface);
1.1044 + if(err == KErrNone)
1.1045 + {
1.1046 + INFO_PRINTF1(_L("START ---->TestWriteMaskLineNoShadowEx"));
1.1047 + TSize size = TSize(30,30);
1.1048 + TRect rect = TRect(size);
1.1049 +
1.1050 + TUint16* writeBuffer = new TUint16[size.iWidth];
1.1051 + Check(writeBuffer != NULL);
1.1052 + TUint8* maskBuffer = new TUint8[size.iWidth];
1.1053 + Check(maskBuffer != NULL);
1.1054 +
1.1055 + TInt nOffset = sizeof(TUint16) * size.iWidth;
1.1056 +
1.1057 + Mem::Fill(writeBuffer,nOffset,0xff);
1.1058 + Mem::Fill(maskBuffer,size.iWidth/2,0x8e);
1.1059 + Mem::Fill((maskBuffer+size.iWidth/2),size.iWidth/2,0xff);
1.1060 +
1.1061 + MFastBlit* fastBlit = reinterpret_cast<MFastBlit*>(interface);
1.1062 +
1.1063 + Clear(KRgbWhite);
1.1064 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.1065 + {
1.1066 + fastBlit->WriteMaskLineEx(rect.iTl.iX,yy,rect.Width(),0,(TUint32*)writeBuffer,EColor64K,0,(TUint32*)maskBuffer,EFalse);
1.1067 + iIteration++;
1.1068 + }
1.1069 + CheckRgb(rect,KRgbWhite,KRgbWhite,CGraphicsContext::EDrawModePEN,0);
1.1070 +
1.1071 + Report();
1.1072 + INFO_PRINTF1(_L("END ---->TestWriteMaskLineNoShadowEx"));
1.1073 + delete [] writeBuffer;
1.1074 + delete [] maskBuffer;
1.1075 + }
1.1076 + }
1.1077 +
1.1078 +/**
1.1079 +Overwrite the pixel in the buffer with a given mode with a value already in that
1.1080 +mode.
1.1081 +@param aX The offset in pixels from the start of the buffer.
1.1082 +@param aPtr The start of the buffer.
1.1083 +@param aMode The display mode of the buffer.
1.1084 +@param aValue The new pixel value.
1.1085 +*/
1.1086 +void CTLowLevel::WriteBinaryValue(TUint32 aX, TAny* const aPtr,
1.1087 + TDisplayMode aMode, TUint32 aValue) const
1.1088 + {
1.1089 + TUint32* buffer32 = (TUint32*)aPtr;
1.1090 + TInt shift;
1.1091 + TUint32 mask;
1.1092 +
1.1093 + switch (aMode)
1.1094 + {
1.1095 + case EGray2:
1.1096 + buffer32 += aX >> 5;
1.1097 + shift = aX & 0x1F;
1.1098 + mask = 0x1;
1.1099 + break;
1.1100 + case EGray4:
1.1101 + buffer32 += aX >> 4;
1.1102 + shift = (aX & 0xF) << 1;
1.1103 + mask = 0x3;
1.1104 + break;
1.1105 + case EGray16:
1.1106 + case EColor16:
1.1107 + buffer32 += aX >> 3;
1.1108 + shift = (aX & 0x7) << 2;
1.1109 + mask = 0xF;
1.1110 + break;
1.1111 + case EGray256:
1.1112 + case EColor256:
1.1113 + buffer32 += aX >> 2;
1.1114 + shift = (aX & 0x3) << 3;
1.1115 + mask = 0xFF;
1.1116 + break;
1.1117 + case EColor4K:
1.1118 + buffer32 += aX >> 1;
1.1119 + shift = (aX & 0x1) << 4;
1.1120 + mask = 0xFFF;
1.1121 + break;
1.1122 + case EColor64K:
1.1123 + buffer32 += aX >> 1;
1.1124 + shift = (aX & 0x1) << 4;
1.1125 + mask = 0xFFFF;
1.1126 + break;
1.1127 + case EColor16M:
1.1128 + {
1.1129 + // This mode requires special handling, because shifts and masks
1.1130 + // won't work.
1.1131 + TUint8* buffer8 = ((TUint8*)aPtr) + (aX * 3);
1.1132 + *buffer8++ = aValue & 0xFF;
1.1133 + *buffer8++ = (aValue >> 8) & 0xFF;
1.1134 + *buffer8++ = (aValue >> 16) & 0xFF;
1.1135 + // Return early as the buffer has been updated.
1.1136 + return;
1.1137 + }
1.1138 + case EColor16MU:
1.1139 + buffer32 += aX;
1.1140 + shift = 0;
1.1141 + mask = 0xFFFFFFFF;
1.1142 + aValue |= 0xFF000000; // Force alpha to opaque.
1.1143 + break;
1.1144 + default:
1.1145 + buffer32 += aX;
1.1146 + shift = 0;
1.1147 + mask = 0xFFFFFFFF;
1.1148 + break;
1.1149 + };
1.1150 +
1.1151 + // Write pixel value into right part of word.
1.1152 + *buffer32 = (*buffer32 & ~(mask << shift)) | ((aValue & mask) << shift);
1.1153 + }
1.1154 +
1.1155 +/**
1.1156 +Copy contents of one buffer over another, depending on a per-pixel mask bit.
1.1157 +@param aSrc Source pixel buffer
1.1158 +@param aSrcMode Display mode of source
1.1159 +@param aDst Destination pixel buffer
1.1160 +@param aDstMode Display mode of destination
1.1161 +@param aMsk Mask buffer. Must be in EGray2 format
1.1162 +@param aWidth Number of pixels to copy
1.1163 +@param aInvert If ETrue, copy source where mask bit is clear, else copy where
1.1164 + it is set.
1.1165 +*/
1.1166 +void CTLowLevel::MaskedBlendBuffer(TAny* aSrc, TDisplayMode aSrcMode, TAny* aDst,
1.1167 + TDisplayMode aDstMode, TUint32* aMsk, TInt aWidth, TBool aInvert)
1.1168 + {
1.1169 + TColorConvertor& srcConvertor = ColorConvertor(aSrcMode);
1.1170 + TColorConvertor& dstConvertor = ColorConvertor(aDstMode);
1.1171 +
1.1172 + for (TInt xx = 0; xx < aWidth; xx++)
1.1173 + {
1.1174 + TUint32 pixelMask = ExtractBinaryValue(xx, aMsk, EGray2);
1.1175 + if (aInvert)
1.1176 + {
1.1177 + pixelMask = !pixelMask;
1.1178 + }
1.1179 +
1.1180 + if (pixelMask)
1.1181 + {
1.1182 + TUint32 dst32 = ExtractBinaryValue(xx, (TUint32*)aDst, aDstMode);
1.1183 + TUint32 src32 = ExtractBinaryValue(xx, (TUint32*)aSrc, aSrcMode);
1.1184 +
1.1185 + switch (aSrcMode)
1.1186 + {
1.1187 + // Only blend for source modes with alpha
1.1188 + case EColor16MAP:
1.1189 + case EColor16MA:
1.1190 + {
1.1191 + // Convert source and destination pixel values to 16MAP
1.1192 + if (aDstMode != EColor16MAP)
1.1193 + {
1.1194 + dst32 = dstConvertor.Color(dst32).Color16MAP();
1.1195 + }
1.1196 + if (aSrcMode != EColor16MAP)
1.1197 + {
1.1198 + src32 = srcConvertor.Color(src32).Color16MAP();
1.1199 + }
1.1200 + // Both params must be 16MAP, output is likewise
1.1201 + dst32 = PMAPixelBlend(dst32, src32);
1.1202 + // Convert 16MAP to final format
1.1203 + dst32 = dstConvertor.Index(TRgb::Color16MAP(dst32));
1.1204 + }
1.1205 + break;
1.1206 + // Anything else is a copy (with format conversion)
1.1207 + default:
1.1208 + dst32 = dstConvertor.Index(srcConvertor.Color(src32));
1.1209 + break;
1.1210 + }
1.1211 +
1.1212 + WriteBinaryValue(xx, aDst, aDstMode, dst32);
1.1213 + }
1.1214 + }
1.1215 + }
1.1216 +
1.1217 +/**
1.1218 +Returns the minimum number of bytes to hold the given number of pixels,
1.1219 +rounded up to the next word boundary.
1.1220 +@param aPixels Number of pixels
1.1221 +@param aMode Display mode of pixels
1.1222 +@return Number of bytes to hold pixels
1.1223 +*/
1.1224 +TUint32 CTLowLevel::BytesForPixels(TUint32 aPixels, TDisplayMode aMode)
1.1225 + {
1.1226 + TUint32 bytes = LongWidth(aPixels, aMode);
1.1227 +
1.1228 + switch (aMode)
1.1229 + {
1.1230 + case EGray2:
1.1231 + bytes /= 8;
1.1232 + break;
1.1233 + case EGray4:
1.1234 + bytes /= 4;
1.1235 + break;
1.1236 + case EGray16:
1.1237 + case EColor16:
1.1238 + bytes /= 2;
1.1239 + break;
1.1240 + case EColor4K:
1.1241 + case EColor64K:
1.1242 + bytes *= 2;
1.1243 + break;
1.1244 + case EColor16M:
1.1245 + bytes *= 3;
1.1246 + break;
1.1247 + case EColor16MU:
1.1248 + case EColor16MA:
1.1249 + case EColor16MAP:
1.1250 + bytes *= 4;
1.1251 + break;
1.1252 + }
1.1253 + return bytes;
1.1254 + }
1.1255 +
1.1256 +/**
1.1257 +Compare the actual blend results with the expected ones, allowing for some
1.1258 +blending errors. Both buffers must be in aMode format
1.1259 +@param aActual Start of actual results
1.1260 +@param aExpected Start of expected results
1.1261 +@param aWidth Number of pixels to check
1.1262 +@param aMode Display mode of the pixels in the buffers
1.1263 +@param aBlended ETrue if pixels were blended, EFalse if they were opaque
1.1264 +@return ETrue if buffers compared OK, EFalse if there was a mismatch.
1.1265 +*/
1.1266 +TBool CTLowLevel::CompareBlendMaskResults(TAny* aActual, TAny* aExpected,
1.1267 + TUint32 aWidth, TDisplayMode aMode, TBool aBlended, TDisplayMode aSrcMode)
1.1268 + {
1.1269 + if (aBlended)
1.1270 + {
1.1271 + // There can be blending rounding errors, so allow for these. In general
1.1272 + // allow for one bit of error, taking into account the precision of
1.1273 + // each component.
1.1274 + TInt maxRBErr;
1.1275 + TInt maxGErr;
1.1276 + switch (aMode)
1.1277 + {
1.1278 + case EColor4K:
1.1279 + // All components are four bits
1.1280 + maxRBErr = maxGErr = 17;
1.1281 + break;
1.1282 + case EColor64K:
1.1283 + // Six bits for green, five for the others, so error
1.1284 + // varies.
1.1285 + maxRBErr = 9;
1.1286 + maxGErr = 5;
1.1287 + break;
1.1288 + default:
1.1289 + // For 16MAP, it will be dependent on the alpha value.
1.1290 + maxRBErr = maxGErr = 1;
1.1291 + break;
1.1292 + }
1.1293 +
1.1294 + // Compare each pixel, allowing for the error in each component.
1.1295 + for (TInt xx = 0; xx < aWidth; xx++)
1.1296 + {
1.1297 + TRgb exp = ExtractRgbValue(xx, (TUint8*)aExpected, aMode);
1.1298 + TRgb act = ExtractRgbValue(xx, (TUint8*)aActual, aMode);
1.1299 +
1.1300 + if (aMode == EColor16MAP)
1.1301 + {
1.1302 + // Take into account that components have been premultiplied
1.1303 + TInt alpha = exp.Alpha();
1.1304 + if (alpha > 0)
1.1305 + {
1.1306 + maxRBErr = maxGErr = (0xFF + alpha - 1) / alpha;
1.1307 + }
1.1308 + if (aSrcMode == EColor16MA && (maxGErr < 3 || maxRBErr < 3))
1.1309 + {
1.1310 + maxGErr = 3;
1.1311 + maxRBErr = 3;
1.1312 + }
1.1313 + }
1.1314 +
1.1315 + if (AbsDiff(exp.Red(), act.Red()) > maxRBErr ||
1.1316 + AbsDiff(exp.Green(), act.Green()) > maxGErr ||
1.1317 + AbsDiff(exp.Blue(), act.Blue()) > maxRBErr ||
1.1318 + exp.Alpha() != act.Alpha())
1.1319 + {
1.1320 + INFO_PRINTF4(_L("At %d, expected 0x%08.8x, got 0x%08.8x"),
1.1321 + xx, exp.Internal(), act.Internal());
1.1322 + return EFalse;
1.1323 + }
1.1324 + }
1.1325 + return ETrue;
1.1326 + }
1.1327 + else
1.1328 + {
1.1329 + // For non-alpha sources there is no blending, so results
1.1330 + // should be exact.
1.1331 + TUint32 stride = BytesForPixels(aWidth, aMode);
1.1332 + return (Mem::Compare((TUint8*)aActual, stride, (TUint8*)aExpected, stride) == 0);
1.1333 + }
1.1334 + }
1.1335 +
1.1336 +class TFunctionThread
1.1337 + {
1.1338 +protected:
1.1339 + TFunctionThread():iExitHow(ENotStarted)
1.1340 + {}
1.1341 + TInt LaunchThreadFunction(const TDesC& aName);
1.1342 +private:
1.1343 + static TInt TheThreadFunction(TAny*);
1.1344 + virtual TInt ThreadFunctionL()=0;
1.1345 +public:
1.1346 + enum {
1.1347 + ENotStarted,
1.1348 + ERunning, //should never see this
1.1349 + EReturn,
1.1350 + ELeave,
1.1351 + EPanic,
1.1352 + ETerminate,
1.1353 + };
1.1354 + TInt iExitHow;
1.1355 + TInt iExitCode; //Currently don't store the panic category string.
1.1356 + };
1.1357 +
1.1358 +TInt TFunctionThread::LaunchThreadFunction(const TDesC& aName)
1.1359 + {
1.1360 + RThread thrd;
1.1361 + TRequestStatus stat;
1.1362 + enum { //8kb to 2mb
1.1363 + KMinHeapSize=0x2000,
1.1364 + KMaxHeapSize=0x200000
1.1365 + };
1.1366 + TInt created=thrd.Create(aName,TheThreadFunction,KDefaultStackSize,KMinHeapSize,KMaxHeapSize,this);
1.1367 + if (created<KErrNone)
1.1368 + {
1.1369 + iExitCode=created;
1.1370 + return created;
1.1371 + }
1.1372 + thrd.SetPriority(EPriorityMuchMore);
1.1373 + thrd.Logon(stat);
1.1374 + User::SetJustInTime(EFalse);
1.1375 + thrd.Resume();
1.1376 + User::WaitForRequest(stat);
1.1377 + if ( iExitHow!=ENotStarted || iExitHow==ERunning )
1.1378 + {
1.1379 + iExitCode=thrd.ExitReason();
1.1380 + switch (thrd.ExitType())
1.1381 + {
1.1382 + case EExitKill: iExitHow=EReturn; break;
1.1383 + case EExitPanic: iExitHow=EPanic; break;
1.1384 + case EExitTerminate: iExitHow=ETerminate; break;
1.1385 + default:
1.1386 + ASSERT(EFalse);
1.1387 + }
1.1388 + }
1.1389 + thrd.Close();
1.1390 + User::SetJustInTime(ETrue);
1.1391 + return KErrNone;
1.1392 + }
1.1393 +
1.1394 +TInt TFunctionThread::TheThreadFunction(TAny* aThis)
1.1395 + {
1.1396 + TFunctionThread* thisThis=(TFunctionThread*)aThis;
1.1397 + if (thisThis==NULL)
1.1398 + {
1.1399 + User::Panic(_L("NoThis"),0x1);
1.1400 + }
1.1401 + thisThis->iExitHow=thisThis->ERunning;
1.1402 + TInt returnErr = KErrNone;
1.1403 + TRAPD(leaveErr,returnErr=thisThis->ThreadFunctionL());
1.1404 + if (leaveErr)
1.1405 + {
1.1406 + thisThis->iExitHow=ELeave;
1.1407 + thisThis->iExitCode=leaveErr;
1.1408 + return leaveErr;
1.1409 + }
1.1410 + else
1.1411 + {
1.1412 + thisThis->iExitHow=EReturn;
1.1413 + thisThis->iExitCode=returnErr;
1.1414 + return returnErr;
1.1415 + }
1.1416 + }
1.1417 +
1.1418 +/** This thread verifies whether a range of memory is accessible
1.1419 + The range is read sequentially until it panics, or the range is completed.
1.1420 + It is useful to input a range of addresses where some are valid and some fail
1.1421 + in order to demonstrate an edge against which an algorithm that performs illegal reads can subsequently be tested.
1.1422 + The FailOffset() returned index indicates the offset from the start at which the memory access caused a panic.
1.1423 + **/
1.1424 +class TTestMemThread:public TFunctionThread
1.1425 + {
1.1426 +public:
1.1427 + TTestMemThread(TUint32* aStartAddress,TUint32* aEndAddress);
1.1428 + TInt FailOffset();
1.1429 +private:
1.1430 + virtual TInt ThreadFunctionL();
1.1431 +private:
1.1432 + TUint32* iStartAddress;
1.1433 + TUint32* iEndAddress;
1.1434 + volatile TUint32* iLastAddressTried;
1.1435 + volatile TUint32 iCopyValueHere;
1.1436 +
1.1437 + };
1.1438 +
1.1439 +TTestMemThread::TTestMemThread(TUint32* aStartAddress,TUint32* aEndAddress):
1.1440 + iStartAddress(aStartAddress),
1.1441 + iEndAddress(aEndAddress),
1.1442 + iLastAddressTried(NULL)
1.1443 + {
1.1444 + ASSERT(aStartAddress);
1.1445 + ASSERT(aEndAddress);
1.1446 + LaunchThreadFunction(_L("MemTest"));
1.1447 + }
1.1448 +
1.1449 +/**
1.1450 + * Returns the number of successful memory reads before a panic occurred
1.1451 + * Or various error codes if the test didn't run or didn't panic.
1.1452 + *
1.1453 + **/
1.1454 +TInt TTestMemThread::FailOffset()
1.1455 + {
1.1456 + if (iExitHow==EReturn)
1.1457 + {
1.1458 + return KErrCompletion;
1.1459 + }
1.1460 + else
1.1461 + {
1.1462 + if (iExitHow==EPanic)
1.1463 + {
1.1464 + if (iLastAddressTried)
1.1465 + {
1.1466 + TInt retval=iLastAddressTried-iStartAddress;
1.1467 + if (iEndAddress-iStartAddress<0)
1.1468 + {
1.1469 + retval=-retval;
1.1470 + }
1.1471 + if (retval<0)
1.1472 + {
1.1473 + return KErrCorrupt;
1.1474 + }
1.1475 + else
1.1476 + {
1.1477 + return retval;
1.1478 + }
1.1479 + }
1.1480 + else
1.1481 + {
1.1482 + return KErrNotFound;
1.1483 + }
1.1484 + }
1.1485 + else
1.1486 + {
1.1487 + return KErrGeneral;
1.1488 + }
1.1489 + }
1.1490 + }
1.1491 +/*
1.1492 + * This thread function allows a test to verify that a particular address range
1.1493 + * is actually inaccessable.
1.1494 + * I.e. that attempting to read from the given address range causes a panic.
1.1495 + */
1.1496 +TInt TTestMemThread::ThreadFunctionL()
1.1497 + {
1.1498 + if (iStartAddress && iEndAddress)
1.1499 + {
1.1500 + TInt delta=1;
1.1501 + if (iStartAddress>iEndAddress)
1.1502 + {
1.1503 + delta=-1;
1.1504 + }
1.1505 + for (TUint32 volatile* tryAddress=iStartAddress;tryAddress!=iEndAddress;tryAddress+=delta)
1.1506 + {
1.1507 + iLastAddressTried=tryAddress;
1.1508 + iCopyValueHere=*tryAddress;
1.1509 + }
1.1510 + return 0;
1.1511 + }
1.1512 + return KErrArgument;
1.1513 + }
1.1514 +
1.1515 +void CTLowLevel::ClosePanicDialogs()
1.1516 + {
1.1517 + RWsSession session;
1.1518 + TInt err = session.Connect();
1.1519 + TEST(err == KErrNone);
1.1520 + TInt idFocus = session.GetFocusWindowGroup();
1.1521 + TWsEvent event;
1.1522 + event.SetType(EEventKey); //EEventKeyDown
1.1523 + TKeyEvent* keyEvent = event.Key();
1.1524 + keyEvent->iCode = EKeyEscape;
1.1525 + keyEvent->iScanCode = EStdKeyEscape;
1.1526 + keyEvent->iModifiers = 0;
1.1527 + TInt theLimit = 50;
1.1528 + while(idFocus != NULL && (theLimit-- > 0))
1.1529 + {
1.1530 + session.SendEventToAllWindowGroups(event);
1.1531 + TInt idNewFocus = session.GetFocusWindowGroup();
1.1532 + idFocus=idNewFocus;
1.1533 + }
1.1534 + session.Flush();
1.1535 + session.Close();
1.1536 + }
1.1537 +
1.1538 +
1.1539 +/**
1.1540 +@SYMTestCaseID GRAPHICS-SCREENDRIVER-0003
1.1541 +@SYMTestCaseDesc Test that FastBlendBitmapMasked masking works correctly
1.1542 +@SYMDEF INC120146 PDEF120693 PDEF120680 INC120742 PDEF121725
1.1543 +@SYMTestPriority High
1.1544 +@SYMTestActions Test actions are:
1.1545 + Create pseudorandom initial contents, source and mask lines.
1.1546 + Set a line of the screen to the initial contents.
1.1547 + Use FastBlendBitmapMasked, with and without inverted bitmask, to write
1.1548 + source to target.
1.1549 + Read line contents back.
1.1550 + Check each pixel is either the initial value, or the source or a blend,
1.1551 + depending on corresponding mask pixel.
1.1552 + Repeat this whole sequence with supported source display modes.
1.1553 + NOTE - wrapped in memory check for edge case defect INC120742
1.1554 +@SYMTestExpectedResults The correct pixel values are set, based on the mask.
1.1555 +*/
1.1556 +void CTLowLevel::TestFastBlendBitmapMasked(const TInt aRetry)
1.1557 + {
1.1558 + const TInt KRetryAmount = 10;
1.1559 +
1.1560 + TAny* interface = NULL;
1.1561 + TInt err = iDrawDevice->GetInterface(KFastBlendInterfaceID, interface);
1.1562 + if(err == KErrNone)
1.1563 + {
1.1564 + if (aRetry == 0)
1.1565 + {
1.1566 + INFO_PRINTF1(_L("START ---->TestFastBlendBitmapMasked"));
1.1567 + }
1.1568 +
1.1569 + MFastBlend* fastBlend = reinterpret_cast<MFastBlend*>(interface);
1.1570 + TInt yPos = iSize.iHeight / 2;
1.1571 + TPoint pt(0,yPos);
1.1572 + TSize lineSize(iSize.iWidth, 1);
1.1573 + TRect lineRect(lineSize);
1.1574 +
1.1575 + TInt destStride = iDrawDevice->ScanLineBytes();
1.1576 + TInt maskStride = (iSize.iWidth + 7) / 8;
1.1577 + TInt maskPages = (maskStride/4096+1);
1.1578 + maskPages+=20;
1.1579 + // Allocate large enough buffers for all modes
1.1580 + TAny* source = User::Alloc(iSize.iWidth * 4);
1.1581 + TAny* expected = User::Alloc(destStride);
1.1582 + CFbsBitmap testBitmap;
1.1583 + testBitmap.Create(TSize(1024,maskPages),EColor16MA);
1.1584 + TUint32* mask = testBitmap.DataAddress()+1024-(maskStride%4096)/4;
1.1585 + TUint32* slb = iDrawDevice->ScanLineBuffer();
1.1586 +
1.1587 + Check(source != NULL && expected != NULL && mask != NULL);
1.1588 +
1.1589 + TUint32* bitmapData=testBitmap.DataAddress();
1.1590 + SEpocBitmapHeader header1 = testBitmap.Header();
1.1591 + TUint32* pastBitmapData=bitmapData+((header1.iBitmapSize-header1.iStructSize)>>2);
1.1592 + mask = pastBitmapData- (maskStride+3)/4;
1.1593 +
1.1594 + TBool canGenerateDefectScenario = EFalse;
1.1595 + TTestMemThread memThread(pastBitmapData-2,pastBitmapData+2);
1.1596 + TInt failAt=memThread.FailOffset();
1.1597 + if (failAt<0)
1.1598 + {
1.1599 + INFO_PRINTF2(_L("Error generated by test thread! %i - BAD"),failAt);
1.1600 + }
1.1601 + else if (failAt<=1)
1.1602 + {
1.1603 + INFO_PRINTF1(_L("Bitmap memory is inaccessable - BAD"));
1.1604 + }
1.1605 + else if (failAt>2)
1.1606 + {
1.1607 + INFO_PRINTF1(_L("Memory after bitmap is accessable - BAD"));
1.1608 + }
1.1609 + else
1.1610 + {
1.1611 + INFO_PRINTF1(_L("Memory after bitmap is inaccessable - GOOD"));
1.1612 + canGenerateDefectScenario=ETrue;
1.1613 + }
1.1614 + ClosePanicDialogs();
1.1615 +
1.1616 + if (!canGenerateDefectScenario)
1.1617 + {
1.1618 + //if this doesn't work out then the memory allocator is not like it was when the defect was raised!
1.1619 + //so the test is no longer any good.
1.1620 + if (aRetry == KRetryAmount)
1.1621 + {
1.1622 + INFO_PRINTF2(_L("Failed %d times - Overall test failure"),KRetryAmount);
1.1623 + Check(EFalse);
1.1624 + }
1.1625 + else
1.1626 + {
1.1627 + INFO_PRINTF2(_L("RETRYING - attempt %d"),aRetry+2);
1.1628 + TestFastBlendBitmapMasked(aRetry+1);
1.1629 + }
1.1630 + }
1.1631 + else
1.1632 + {
1.1633 + INFO_PRINTF1(_L("Performing test"));
1.1634 + for (TInt sourceModeIndex = 0; sourceModeIndex < KNumberDisplayModes1; sourceModeIndex++)
1.1635 + {
1.1636 + for (TInt invert = 0; invert < 2; invert++)
1.1637 + {
1.1638 + TDisplayMode sourceMode = TestDisplayMode1[sourceModeIndex];
1.1639 + TInt sourceStride = BytesForPixels(iSize.iWidth, sourceMode);
1.1640 + TBool blended = (sourceMode == EColor16MA || sourceMode == EColor16MAP);
1.1641 +
1.1642 + // Initialise (randomise) the buffers for this iteration
1.1643 + FillBuffer((TUint8*)source, sourceStride, sourceMode, ETrue);
1.1644 + FillBuffer((TUint8*)expected, destStride, iDispMode, ETrue);
1.1645 + FillBuffer((TUint8*)mask, maskStride, EGray2, ETrue);
1.1646 +
1.1647 + // Write out the initial contents
1.1648 + iDrawDevice->WriteLine(0, yPos, iSize.iWidth, (TUint32*)expected,
1.1649 + CGraphicsContext::EDrawModeWriteAlpha);
1.1650 +
1.1651 + // Fast, masked overwrite, with or without mask inversion
1.1652 + TInt result = fastBlend->FastBlendBitmapMasked(pt,
1.1653 + (TUint32*)source, sourceStride, lineSize, lineRect,
1.1654 + sourceMode, mask, maskStride, EGray2, lineSize,
1.1655 + TPoint(), invert, CGraphicsContext::EDrawModePEN,
1.1656 + CFbsDrawDevice::ENoShadow);
1.1657 +
1.1658 + if (result == KErrNotSupported)
1.1659 + {
1.1660 + // Unsupported combination of parameters, move on.
1.1661 + continue;
1.1662 + }
1.1663 +
1.1664 + // Use mask to blend source with 'expected' to get the expected
1.1665 + // output
1.1666 + MaskedBlendBuffer(source, sourceMode, expected, iDispMode,
1.1667 + mask, iSize.iWidth, invert);
1.1668 +
1.1669 + // Read back actual output and compare with expected.
1.1670 + iDrawDevice->ReadLine(0, yPos, iSize.iWidth, slb, iDispMode);
1.1671 +
1.1672 + if (!CompareBlendMaskResults(slb, expected, iSize.iWidth,
1.1673 + iDispMode, blended, sourceMode))
1.1674 + {
1.1675 + INFO_PRINTF3(_L("Output mismatch: source mode %S, invert=%d"),
1.1676 + &DisplayModeNames1[sourceModeIndex], invert);
1.1677 + // Report other details, plus fail the overall test.
1.1678 + Check(EFalse);
1.1679 + }
1.1680 + iIteration++;
1.1681 + }
1.1682 +
1.1683 + }
1.1684 + TTestMemThread memThreadAfter(pastBitmapData-2,pastBitmapData+2);
1.1685 + failAt=memThreadAfter.FailOffset();
1.1686 + if (failAt != 2)
1.1687 + {
1.1688 + INFO_PRINTF1(_L("Memory after bitmap is accessable - BAD"));
1.1689 + if (aRetry >= KRetryAmount)
1.1690 + {
1.1691 + INFO_PRINTF2(_L("Failed %d times - Overall test failure"),KRetryAmount);
1.1692 + Check(EFalse);
1.1693 + }
1.1694 + else
1.1695 + {
1.1696 + INFO_PRINTF2(_L("RETRYING - attempt %d"),aRetry+2);
1.1697 + TestFastBlendBitmapMasked(aRetry+1);
1.1698 + }
1.1699 + }
1.1700 + else
1.1701 + {
1.1702 + INFO_PRINTF1(_L("Memory after bitmap is inaccessable - GOOD"));
1.1703 + }
1.1704 + ClosePanicDialogs();
1.1705 + }
1.1706 + if (aRetry == 0)
1.1707 + {
1.1708 + INFO_PRINTF1(_L("END ---->TestFastBlendBitmapMasked"));
1.1709 + Report();
1.1710 + }
1.1711 +
1.1712 + User::Free(source);
1.1713 + User::Free(expected);
1.1714 + testBitmap.Reset();
1.1715 + }
1.1716 + }
1.1717 +
1.1718 +void CTLowLevel::TestWriteRGBAlpha()
1.1719 + {
1.1720 + TUint8* writeBuffer = new TUint8[iSize.iWidth * 4];
1.1721 + TUint8* writeBuffer2 = new TUint8[iSize.iWidth * 4];
1.1722 + TUint8* maskBuffer = new TUint8[iSize.iWidth];
1.1723 + Check(writeBuffer != NULL);
1.1724 + Check(maskBuffer != NULL);
1.1725 +
1.1726 + TInt nRect;
1.1727 +
1.1728 + //special test for EColor16MAP
1.1729 + if (iDispMode == EColor16MAP)
1.1730 + {
1.1731 + //mask fill has vaues 0x00, 0xff, and 0x3A. The mask is used for blending
1.1732 + for (TInt maskFillCount=0; maskFillCount<KMaskFill;maskFillCount++)
1.1733 + {
1.1734 + for (TInt userDispMode=0; userDispMode< KUserDispModes; userDispMode++)
1.1735 + {
1.1736 + for (TInt shadowMode = 0; shadowMode < KNumShadowModes; shadowMode++)
1.1737 + {
1.1738 + for (nRect = 0; nRect < KNumTestRects; nRect++)
1.1739 + {
1.1740 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.1741 + {
1.1742 + for (TInt nColor = 0; nColor < KNumTestColors; nColor++)
1.1743 + {
1.1744 + iDrawDevice->SetUserDisplayMode(UserDisplayModes[userDispMode]);
1.1745 + iUserDispMode = UserDisplayModes[userDispMode];
1.1746 + if (iUserDispMode == EColor16MA)
1.1747 + i16MAUserDispMode = ETrue;
1.1748 + else
1.1749 + i16MAUserDispMode = EFalse;
1.1750 +
1.1751 + TRgb col = TestColor[nColor];
1.1752 + TUint32 internal = col.Internal();
1.1753 + TUint32 *writeBuf32 = (TUint32*)writeBuffer;
1.1754 + TInt cnt;
1.1755 + //fill the buffer with colour
1.1756 + for (cnt=0;cnt<iSize.iWidth;cnt++)
1.1757 + {
1.1758 + *writeBuf32=internal;
1.1759 + writeBuf32++;
1.1760 + }
1.1761 +
1.1762 + Mem::Fill(maskBuffer,iSize.iWidth,MaskFill[maskFillCount]);
1.1763 +
1.1764 + TRgb bakCol = TestBackground[nBackColor];
1.1765 + Clear(bakCol);
1.1766 + TRect rect = TestRect[nRect];
1.1767 +
1.1768 + iDrawDevice->CFbsDrawDevice::SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.1769 + iDrawDevice->CFbsDrawDevice::SetFadingParameters(100,200);
1.1770 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.1771 +
1.1772 + TInt yy;
1.1773 + for (yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.1774 + {
1.1775 + iDrawDevice->WriteRgbAlphaLine(rect.iTl.iX,yy,rect.Width(),writeBuffer,maskBuffer,CGraphicsContext::EDrawModePEN);
1.1776 + iIteration++;
1.1777 + }
1.1778 +
1.1779 + //ensure the colour has the 0xff mask value
1.1780 + TRgb checkColor;
1.1781 + //use a combined alpha for the check colour
1.1782 + TUint32 combinedAlpha = MaskFill[maskFillCount]*((internal&0xff000000)>>24);
1.1783 + combinedAlpha = ((combinedAlpha <<16) & 0xff000000);
1.1784 + checkColor.SetInternal((internal&0x00ffffff)|combinedAlpha);
1.1785 + //check colour is not a PMA colour, but has alpha
1.1786 + CheckRgb(rect,checkColor,bakCol,CGraphicsContext::EDrawModePEN,CFbsDrawDevice::TShadowMode(shadowMode));
1.1787 + CheckBackground(rect,bakCol);
1.1788 +
1.1789 + //the other WriteRgbAlpha line uses the other shadow mode
1.1790 + TUint32 *writeBuf2 = (TUint32*)writeBuffer2;
1.1791 + TUint32 buf2val= NonPMA2PMAPixel(bakCol.Internal());
1.1792 + //fill the buffer with colour
1.1793 + for (cnt=0;cnt<iSize.iWidth;cnt++)
1.1794 + {
1.1795 + *writeBuf2=buf2val;
1.1796 + writeBuf2++;
1.1797 + }
1.1798 +
1.1799 + iDrawDevice->CFbsDrawDevice::SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.1800 + iDrawDevice->CFbsDrawDevice::SetFadingParameters(100,200);
1.1801 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.1802 +
1.1803 + for (yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.1804 + {
1.1805 + iDrawDevice->WriteRgbAlphaLine(rect.iTl.iX,yy,rect.Width(),
1.1806 + writeBuffer,
1.1807 + writeBuffer2,
1.1808 + maskBuffer,
1.1809 + CGraphicsContext::EDrawModeWriteAlpha);
1.1810 + iIteration++;
1.1811 + }
1.1812 + //require to Shadow After the checkColor, no shadow with a zero mask
1.1813 + TBool shadowModeChanged = EFalse;
1.1814 + if (MaskFill[maskFillCount])
1.1815 + {
1.1816 + iPostBlendShadow = (TPostShadowMode) shadowMode;
1.1817 + shadowMode = 0;
1.1818 + shadowModeChanged = ETrue;
1.1819 + }
1.1820 + CheckRgb(rect,checkColor,bakCol,CGraphicsContext::EDrawModePEN,shadowMode);
1.1821 + if(shadowModeChanged) shadowMode = iPostBlendShadow;
1.1822 + iPostBlendShadow = ENoPostShadow;
1.1823 + CheckBackground(rect,bakCol);
1.1824 +
1.1825 + Clear(bakCol);
1.1826 +
1.1827 + iDrawDevice->CFbsDrawDevice::SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.1828 + iDrawDevice->CFbsDrawDevice::SetFadingParameters(100,200);
1.1829 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.1830 +
1.1831 + for (TInt yy2 = rect.iTl.iY; yy2 < rect.iBr.iY; yy2++)
1.1832 + {
1.1833 + iDrawDevice->WriteRgbAlphaMulti(rect.iTl.iX,yy2,rect.Width(),col,maskBuffer);
1.1834 + iIteration++;
1.1835 + }
1.1836 +
1.1837 + CheckRgb(rect,checkColor,bakCol,CGraphicsContext::EDrawModePEN,CFbsDrawDevice::TShadowMode(shadowMode));
1.1838 + CheckBackground(rect,bakCol);
1.1839 + }
1.1840 + }
1.1841 + }
1.1842 + }
1.1843 + }
1.1844 + }
1.1845 + }
1.1846 +
1.1847 + Report();
1.1848 + iDrawDevice->SetUserDisplayMode(iDispMode);
1.1849 + i16MAUserDispMode = EFalse;
1.1850 + iUserDispMode = ENone;
1.1851 + Mem::Fill(writeBuffer,iSize.iWidth * 4,0xff);
1.1852 + Mem::Fill(maskBuffer,iSize.iWidth,0xff);
1.1853 +
1.1854 + for (nRect = 0; nRect < KNumTestRects; nRect++)
1.1855 + {
1.1856 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.1857 + {
1.1858 + if ((nBackColor>=KMaxNon16BackColours) && (iDispMode!= EColor16MAP))
1.1859 + continue;
1.1860 +
1.1861 + TRgb bakCol = TestBackground[nBackColor];
1.1862 + Clear(bakCol);
1.1863 + TRect rect = TestRect[nRect];
1.1864 +
1.1865 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.1866 + {
1.1867 + iDrawDevice->WriteRgbAlphaLine(rect.iTl.iX,yy,rect.Width(),writeBuffer,maskBuffer,CGraphicsContext::EDrawModePEN);
1.1868 + iIteration++;
1.1869 + }
1.1870 +
1.1871 + CheckRgb(rect,KRgbWhite,bakCol,CGraphicsContext::EDrawModePEN,0);
1.1872 + CheckBackground(rect,bakCol);
1.1873 +
1.1874 + Clear(bakCol);
1.1875 +
1.1876 + for (TInt yy2 = rect.iTl.iY; yy2 < rect.iBr.iY; yy2++)
1.1877 + {
1.1878 + iDrawDevice->WriteRgbAlphaMulti(rect.iTl.iX,yy2,rect.Width(),KRgbWhite,maskBuffer);
1.1879 + iIteration++;
1.1880 + }
1.1881 +
1.1882 + CheckRgb(rect,KRgbWhite,bakCol,CGraphicsContext::EDrawModePEN,0);
1.1883 + CheckBackground(rect,bakCol);
1.1884 +
1.1885 + }
1.1886 + }
1.1887 + Report();
1.1888 +
1.1889 + Mem::FillZ(writeBuffer,iSize.iWidth * 3);
1.1890 +
1.1891 + for (nRect = 0; nRect < KNumTestRects; nRect++)
1.1892 + {
1.1893 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.1894 + {
1.1895 + if ((nBackColor>=KMaxNon16BackColours) && (iDispMode!= EColor16MAP))
1.1896 + continue;
1.1897 +
1.1898 + //need to fill with 0xff alpha, so blending takes place
1.1899 + if (iDispMode== EColor16MAP)
1.1900 + {
1.1901 + const TUint32 black = 0xff000000;
1.1902 + TUint32 *writeBuf32 = (TUint32*) writeBuffer;
1.1903 + for (TInt cnt=0;cnt<iSize.iWidth;cnt++)
1.1904 + {
1.1905 + *writeBuf32=black;
1.1906 + writeBuf32++;
1.1907 + }
1.1908 + }
1.1909 +
1.1910 + TRgb bakCol = TestBackground[nBackColor];
1.1911 + Clear(bakCol);
1.1912 + TRect rect = TestRect[nRect];
1.1913 +
1.1914 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.1915 + {
1.1916 + iDrawDevice->WriteRgbAlphaLine(rect.iTl.iX,yy,rect.Width(),writeBuffer,maskBuffer,CGraphicsContext::EDrawModePEN);
1.1917 + iIteration++;
1.1918 + }
1.1919 +
1.1920 + CheckRgb(rect,KRgbBlack,bakCol,CGraphicsContext::EDrawModePEN,0);
1.1921 + CheckBackground(rect,bakCol);
1.1922 +
1.1923 + Clear(bakCol);
1.1924 +
1.1925 + for (TInt yy2 = rect.iTl.iY; yy2 < rect.iBr.iY; yy2++)
1.1926 + {
1.1927 + iDrawDevice->WriteRgbAlphaMulti(rect.iTl.iX,yy2,rect.Width(),KRgbBlack,maskBuffer);
1.1928 + iIteration++;
1.1929 + }
1.1930 +
1.1931 + CheckRgb(rect,KRgbBlack,bakCol,CGraphicsContext::EDrawModePEN,0);
1.1932 + CheckBackground(rect,bakCol);
1.1933 + }
1.1934 + }
1.1935 + Report();
1.1936 +
1.1937 + Mem::FillZ(maskBuffer,iSize.iWidth);
1.1938 +
1.1939 + for (nRect = 0; nRect < KNumTestRects; nRect++)
1.1940 + {
1.1941 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.1942 + {
1.1943 + if ((nBackColor>=KMaxNon16BackColours) && (iDispMode!= EColor16MAP))
1.1944 + continue;
1.1945 +
1.1946 + TRgb bakCol = TestBackground[nBackColor];
1.1947 + Clear(bakCol);
1.1948 + TRect rect = TestRect[nRect];
1.1949 +
1.1950 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.1951 + {
1.1952 + iDrawDevice->WriteRgbAlphaLine(rect.iTl.iX,yy,rect.Width(),writeBuffer,maskBuffer,CGraphicsContext::EDrawModePEN);
1.1953 + iIteration++;
1.1954 + }
1.1955 +
1.1956 + TRgb checkColor2=bakCol;
1.1957 + if (iDispMode == EColor16MAP)
1.1958 + checkColor2.SetInternal (0);
1.1959 +
1.1960 + CheckRgb(rect,checkColor2,bakCol,CGraphicsContext::EDrawModePEN,0);
1.1961 + CheckBackground(rect,bakCol);
1.1962 +
1.1963 + Clear(bakCol);
1.1964 +
1.1965 + for (TInt yy2 = rect.iTl.iY; yy2 < rect.iBr.iY; yy2++)
1.1966 + {
1.1967 + iDrawDevice->WriteRgbAlphaMulti(rect.iTl.iX,yy2,rect.Width(),KRgbBlack,maskBuffer);
1.1968 + iIteration++;
1.1969 + }
1.1970 +
1.1971 + CheckRgb(rect,checkColor2,bakCol,CGraphicsContext::EDrawModePEN,0);
1.1972 + CheckBackground(rect,bakCol);
1.1973 +
1.1974 + }
1.1975 + }
1.1976 + Report();
1.1977 +
1.1978 + Mem::Fill(writeBuffer,iSize.iWidth * 3,0xff);
1.1979 +
1.1980 + for (nRect = 0; nRect < KNumTestRects; nRect++)
1.1981 + {
1.1982 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.1983 + {
1.1984 + if ((nBackColor>=KMaxNon16BackColours) && (iDispMode!= EColor16MAP))
1.1985 + continue;
1.1986 +
1.1987 + TRgb bakCol = TestBackground[nBackColor];
1.1988 + Clear(bakCol);
1.1989 + TRect rect = TestRect[nRect];
1.1990 +
1.1991 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.1992 + {
1.1993 + iDrawDevice->WriteRgbAlphaLine(rect.iTl.iX,yy,rect.Width(),writeBuffer,maskBuffer,CGraphicsContext::EDrawModePEN);
1.1994 + iIteration++;
1.1995 + }
1.1996 + TRgb checkColor3=bakCol;
1.1997 + if (iDispMode == EColor16MAP)
1.1998 + checkColor3.SetInternal (0xffffff);
1.1999 +
1.2000 + CheckRgb(rect,checkColor3,bakCol,CGraphicsContext::EDrawModePEN,0);
1.2001 + CheckBackground(rect,bakCol);
1.2002 +
1.2003 + Clear(bakCol);
1.2004 +
1.2005 + for (TInt yy2 = rect.iTl.iY; yy2 < rect.iBr.iY; yy2++)
1.2006 + {
1.2007 + iDrawDevice->WriteRgbAlphaMulti(rect.iTl.iX,yy2,rect.Width(),KRgbWhite,maskBuffer);
1.2008 + iIteration++;
1.2009 + }
1.2010 +
1.2011 + CheckRgb(rect,checkColor3,bakCol,CGraphicsContext::EDrawModePEN,0);
1.2012 + CheckBackground(rect,bakCol);
1.2013 + }
1.2014 + }
1.2015 + Report();
1.2016 +
1.2017 + //Extra test for DEF082251
1.2018 + if (iDispMode==EColor16MU)
1.2019 + {
1.2020 + Mem::Fill(maskBuffer,iSize.iWidth,0x7f);
1.2021 +
1.2022 + for (nRect = 0; nRect < KNumTestRects; nRect++)
1.2023 + {
1.2024 + for (TInt nBackColor = 0; nBackColor < KNumTestBackgrounds; nBackColor++)
1.2025 + {
1.2026 + TRgb bakCol = TestBackground[nBackColor];
1.2027 + Clear(bakCol);
1.2028 + TRect rect=TestRect[nRect];
1.2029 +
1.2030 + const TInt red = 50;
1.2031 + const TInt green = 60;
1.2032 + const TInt blue = 70;
1.2033 + const TInt alpha = 80;
1.2034 +
1.2035 + for (TInt yy2 = rect.iTl.iY; yy2 < rect.iBr.iY; yy2++)
1.2036 + {
1.2037 + iDrawDevice->WriteRgbAlphaMulti(rect.iTl.iX,yy2,rect.Width(),
1.2038 + TRgb(red,green,blue,alpha),maskBuffer);
1.2039 + iIteration++;
1.2040 + }
1.2041 +
1.2042 + //work out the color - based on OptimizedBlend32 in the
1.2043 + //screendriver bmdraw32.cpp
1.2044 + TInt combinedAlpha = (alpha * 0x7f)>>8;
1.2045 +
1.2046 + const TUint32 alphaValue = (combinedAlpha << 8) + combinedAlpha;
1.2047 + TUint32 secondary= bakCol.Value();
1.2048 +
1.2049 + const TInt r2 = secondary & 0x000000ff;
1.2050 + const TInt g2 = (secondary & 0x0000ff00) >> 8;
1.2051 + const TInt b2 = (secondary & 0x00ff0000) >> 16;
1.2052 +
1.2053 + const TInt r3 = ((alphaValue * (red - r2)) >> 16) + r2;
1.2054 + const TInt g3 = ((alphaValue * (green - g2)) >> 16) + g2;
1.2055 + const TInt b3 = ((alphaValue * (blue - b2)) >> 16) + b2;
1.2056 +
1.2057 + TInt result= (b3 & 0xFF) | ((g3<<8) & 0xFF00) | ((r3<<16) & 0xFF0000) | 0xFF000000;
1.2058 + TRgb resultColor = TRgb(result,0);
1.2059 +
1.2060 + CheckRgb(rect,resultColor,bakCol,CGraphicsContext::EDrawModePEN,0);
1.2061 + CheckBackground(rect,bakCol);
1.2062 + }
1.2063 + }
1.2064 + Report();
1.2065 + }
1.2066 + delete [] writeBuffer;
1.2067 + delete [] maskBuffer;
1.2068 + delete [] writeBuffer2;
1.2069 + }
1.2070 +
1.2071 +void CTLowLevel::TestShadow()
1.2072 + {
1.2073 + for (TInt shadowMode = 0; shadowMode < KNumShadowModes; shadowMode++)
1.2074 + {
1.2075 + for (TInt nRect = 0; nRect < KNumTestRects; nRect++)
1.2076 + {
1.2077 + for (TInt nColor = 0; nColor < KNumTestColors; nColor++)
1.2078 + {
1.2079 + if ((nColor>=KMaxNon16Colours) && (iDispMode!= EColor16MAP))
1.2080 + continue;
1.2081 +
1.2082 + TRgb col = TestColor[nColor];
1.2083 + Clear(col);
1.2084 +
1.2085 + TRect rect = TestRect[nRect];
1.2086 +
1.2087 + iDrawDevice->SetShadowMode(CFbsDrawDevice::TShadowMode(shadowMode));
1.2088 + iDrawDevice->ShadowArea(rect);
1.2089 +
1.2090 + CheckShadowRgb(rect,col,shadowMode);
1.2091 +
1.2092 + TRgb checkColor=col;
1.2093 + if (iDispMode == EColor16MAP)
1.2094 + {
1.2095 + checkColor.SetInternal (0); //only want contribution from one colour
1.2096 + }
1.2097 +
1.2098 + TRect outside(0,0,iSize.iWidth,rect.iTl.iY);
1.2099 + if (!outside.IsEmpty())
1.2100 + CheckRgb(outside,checkColor,col,CGraphicsContext::EDrawModePEN,0);
1.2101 + outside.SetRect(0,rect.iBr.iY,iSize.iWidth,iSize.iHeight);
1.2102 + if (!outside.IsEmpty())
1.2103 + CheckRgb(outside,checkColor,col,CGraphicsContext::EDrawModePEN,0);
1.2104 + outside.SetRect(0,rect.iTl.iY,rect.iTl.iX,rect.iBr.iY);
1.2105 + if (!outside.IsEmpty())
1.2106 + CheckRgb(outside,checkColor,col,CGraphicsContext::EDrawModePEN,0);
1.2107 + outside.SetRect(rect.iBr.iX,rect.iTl.iY,iSize.iWidth,rect.iBr.iY);
1.2108 + if (!outside.IsEmpty())
1.2109 + CheckRgb(outside,checkColor,col,CGraphicsContext::EDrawModePEN,0);
1.2110 + iIteration++;
1.2111 + }
1.2112 + }
1.2113 + Report();
1.2114 + }
1.2115 + }
1.2116 +
1.2117 +/**
1.2118 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0002
1.2119 +
1.2120 + @SYMPREQ PREQ1543
1.2121 +
1.2122 + @SYMTestCaseDesc This test code tests WriteRgbOutlineAndShadow() which blends the four colours.
1.2123 + Colours used for blending are outline, shadow, foreground and background.
1.2124 +
1.2125 + @SYMTestPriority High
1.2126 +
1.2127 + @SYMTestStatus Implemented
1.2128 +
1.2129 + @SYMTestActions It compares the colour written by WriteRgbOutlineAndShadow() with colour
1.2130 + calculated using lookup table provided by Monotype.
1.2131 + API Calls:
1.2132 + CDrawBitmap::GetInterface()
1.2133 + MOutlineAndShadowBlend::WriteRgbOutlineAndShadow()
1.2134 + CDrawBitmap::ReadLine()
1.2135 +
1.2136 + @SYMTestExpectedResults Test should pass and colour written by WriteRgbOutlineAndShadow should
1.2137 + match with the colour calculated through lookup table.
1.2138 +*/
1.2139 +void CTLowLevel::TestWriteRgbOutlineAndShadow()
1.2140 + {
1.2141 + MOutlineAndShadowBlend* outlineAndShadow = NULL;
1.2142 + TInt byteSize = ByteSize();
1.2143 + TUint8* writeBuffer = new TUint8[iSize.iWidth * sizeof(TRgb)];
1.2144 + TUint8* readBuffer = new TUint8[iSize.iWidth * sizeof(TRgb)];
1.2145 + TColorConvertor& colorConvertor = ColorConvertor(iDispMode);
1.2146 + Check(writeBuffer != NULL);
1.2147 + Check(readBuffer != NULL);
1.2148 + TInt err = iDrawDevice->GetInterface(KOutlineAndShadowInterfaceID, reinterpret_cast <TAny*&> (outlineAndShadow));
1.2149 + Check(err == KErrNone);
1.2150 +
1.2151 + TRect rect = TestRect[0];
1.2152 + for (TInt nBlendingColors = 0; nBlendingColors < KNumBlendingColors; nBlendingColors++)
1.2153 + {
1.2154 + // Select different combinations of colours for testing from the array
1.2155 + TRgb outlinePenColor = TestOSFBColorsForBlending[nBlendingColors][0];
1.2156 + TRgb shadowColor = TestOSFBColorsForBlending[nBlendingColors][1];
1.2157 + TRgb fillColor = TestOSFBColorsForBlending[nBlendingColors][2];
1.2158 + TRgb backgroundColor = colorConvertor.Color(colorConvertor.Index(TestOSFBColorsForBlending[nBlendingColors][3]));
1.2159 + Clear(backgroundColor);
1.2160 + for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
1.2161 + {
1.2162 + // Run the test for values from 0 to 255 so that it will cover all the entries
1.2163 + // of lookup table provided by Monotype
1.2164 + for (TInt index = 0; index < 256; index++)
1.2165 + {
1.2166 + // In case alpha is supported and if alpha value is less than 255 then the colour drawn will be different
1.2167 + // than the colour specified as it blends with the existing background pixel colour.
1.2168 + TRgb backgroundColorDrawn= iDrawDevice->ReadPixel(rect.iTl.iX, yy);
1.2169 +
1.2170 + // Fill zeroes in the readBuffer so that we can make sure that there is no garbage value.
1.2171 + Mem::FillZ(readBuffer, iSize.iWidth * 3);
1.2172 +
1.2173 + // We are writing index in writeBuffer to simulate the buffer provided by rasterizer
1.2174 + // This index should be a value between 0-255, It would be corresponding the entries of lookup table
1.2175 + Mem::Fill(writeBuffer, iSize.iWidth * 3, index);
1.2176 +
1.2177 + // Below function blends outline, shadow, foreground and background colours, and writes aLength pixels with new colour
1.2178 + // starting from aX, aY.
1.2179 + err = outlineAndShadow->WriteRgbOutlineAndShadow(rect.iTl.iX, yy , rect.Width(), outlinePenColor.Internal(),
1.2180 + shadowColor.Internal(),fillColor.Internal(),writeBuffer);
1.2181 + Check(err == KErrNone);
1.2182 +
1.2183 + // Read the whole line which has been written by WriteRgbOutlineAndShadow()
1.2184 + iDrawDevice->ReadLine(rect.iTl.iX, yy, rect.Width(), (TUint32*)readBuffer, iDispMode);
1.2185 +
1.2186 + // Check colour of each pixel, it should be same as the colour which is calulated manually in CheckBlendedOutlineAndShadow()
1.2187 + TBool result = CheckBlendedOutlineAndShadow(outlinePenColor, shadowColor, fillColor, backgroundColorDrawn, index, rect.Width(), readBuffer);
1.2188 + Check(result);
1.2189 + if (!result)
1.2190 + {
1.2191 + Report();
1.2192 + delete [] writeBuffer;
1.2193 + delete [] readBuffer;
1.2194 + return;
1.2195 + }
1.2196 +
1.2197 + iIteration++;
1.2198 + }
1.2199 + }
1.2200 + Report();
1.2201 + }
1.2202 + delete [] writeBuffer;
1.2203 + delete [] readBuffer;
1.2204 + }
1.2205 +
1.2206 +inline TInt CTLowLevel::ByteSize()
1.2207 + {
1.2208 + return ::ByteSize(iDispMode,iSize.iWidth);
1.2209 + }
1.2210 +
1.2211 +TInt CTLowLevel::LongWidth(TInt aWidth,TDisplayMode aDispMode)
1.2212 + {
1.2213 + switch (aDispMode)
1.2214 + {
1.2215 + case EGray2:
1.2216 + return (aWidth + 31) & ~31;
1.2217 + case EGray4:
1.2218 + return (aWidth + 15) & ~15;
1.2219 + case EGray16:
1.2220 + case EColor16:
1.2221 + return (aWidth + 7) & ~7;
1.2222 + case EGray256:
1.2223 + case EColor256:
1.2224 + return (aWidth + 3) & ~3;
1.2225 + case EColor4K:
1.2226 + case EColor64K:
1.2227 + return (aWidth + 1) & ~1;
1.2228 + case EColor16M:
1.2229 + return (((aWidth * 3) + 11) / 12) * 4;
1.2230 + case EColor16MU:
1.2231 + case EColor16MA:
1.2232 + case EColor16MAP:
1.2233 + return aWidth;
1.2234 + default:
1.2235 + break;
1.2236 + };
1.2237 + return 0;
1.2238 + }
1.2239 +
1.2240 +void CTLowLevel::Clear(TRgb aColor)
1.2241 + {
1.2242 + iDrawDevice->SetShadowMode(CFbsDrawDevice::ENoShadow);
1.2243 + iDrawDevice->WriteRgbMulti(0,0,iSize.iWidth,iSize.iHeight,aColor,CGraphicsContext::EDrawModeWriteAlpha);
1.2244 + }
1.2245 +
1.2246 +/*
1.2247 +Fill aBuffer with aByteSize random bytes in such a way that the result is a
1.2248 +valid scan line buffer for a driver of which the display mode is aDispMode.
1.2249 +If aDispMode is EColor16MU, the alpha bytes will be 0xFF if aNoAlpha16MU is ETrue,
1.2250 +or random bytes if aNoAlpha16MU is EFalse.
1.2251 +*/
1.2252 +void CTLowLevel::FillBuffer(TUint8* aBuffer, TInt aByteSize, TDisplayMode aDispMode, TBool aNoAlpha16MU)
1.2253 + {
1.2254 + TUint8* bufferLimit = aBuffer + aByteSize;
1.2255 + TUint8* buffer=aBuffer;
1.2256 +
1.2257 + TInt64 seed = TInt64(TInt(aBuffer) * aByteSize * aDispMode * User::TickCount());
1.2258 +
1.2259 + if (aDispMode != EColor16MU || !aNoAlpha16MU)
1.2260 + {
1.2261 + while (aBuffer < bufferLimit)
1.2262 + {
1.2263 + *aBuffer++ = (TUint8)Math::Rand(seed);
1.2264 + }
1.2265 + }
1.2266 + else
1.2267 + {
1.2268 + while (aBuffer < bufferLimit)
1.2269 + {
1.2270 + if (TInt(aBuffer) & 3 == 3)
1.2271 + *aBuffer++ = 0xFF;
1.2272 + else
1.2273 + *aBuffer++ = (TUint8)Math::Rand(seed);
1.2274 + }
1.2275 + }
1.2276 + if (aDispMode == EColor16MU && !aNoAlpha16MU || aDispMode == EColor16MAP)
1.2277 + {
1.2278 + //need to do the premultiply alpha to ensure that all the colours are valid
1.2279 + //in the colour space
1.2280 + for (;buffer < (bufferLimit-3);buffer+=4)
1.2281 + {
1.2282 + TUint alpha=*(buffer+3);
1.2283 + *(buffer)=((*(buffer))* alpha)/255; //do a pre multiply alpha operation
1.2284 + *(buffer+1)=((*(buffer+1))* alpha)/255;
1.2285 + *(buffer+2)=((*(buffer+2))* alpha)/255;
1.2286 + }
1.2287 + }
1.2288 +
1.2289 + }
1.2290 +
1.2291 +void CTLowLevel::CheckBuffer(TUint8* aWriteBuffer,TDisplayMode aWriteDispMode,TUint8* aReadBuffer,TDisplayMode aReadDispMode,TInt aPixelLength)
1.2292 + {
1.2293 + switch (aWriteDispMode)
1.2294 + {
1.2295 + case EGray2:
1.2296 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray2);
1.2297 + break;
1.2298 + case EGray4:
1.2299 + if (aReadDispMode == EGray2)
1.2300 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray2);
1.2301 + else
1.2302 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray4);
1.2303 + break;
1.2304 + case EGray16:
1.2305 + if (aReadDispMode == EGray2)
1.2306 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray2);
1.2307 + else if (aReadDispMode == EGray4)
1.2308 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray4);
1.2309 + else if (aReadDispMode == EColor16)
1.2310 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor16);
1.2311 + else
1.2312 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray16);
1.2313 + break;
1.2314 + case EGray256:
1.2315 + switch (aReadDispMode)
1.2316 + {
1.2317 + case EGray2:
1.2318 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray2);
1.2319 + break;
1.2320 + case EGray4:
1.2321 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray4);
1.2322 + break;
1.2323 + case EGray16:
1.2324 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray16);
1.2325 + break;
1.2326 + case EGray256:
1.2327 + case EColor16M:
1.2328 + case ERgb:
1.2329 + case EColor16MU:
1.2330 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray256);
1.2331 + break;
1.2332 + case EColor16:
1.2333 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor16);
1.2334 + break;
1.2335 + case EColor256:
1.2336 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor256);
1.2337 + break;
1.2338 + case EColor4K:
1.2339 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor4K);
1.2340 + break;
1.2341 + case EColor64K:
1.2342 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor64K);
1.2343 + break;
1.2344 + default:
1.2345 + break;
1.2346 + }
1.2347 + break;
1.2348 + case EColor16:
1.2349 + switch (aReadDispMode)
1.2350 + {
1.2351 + case EGray2:
1.2352 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray2);
1.2353 + break;
1.2354 + case EGray4:
1.2355 + case EGray16:
1.2356 + case EGray256:
1.2357 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray4);
1.2358 + break;
1.2359 + case EColor16:
1.2360 + case EColor256:
1.2361 + case EColor4K:
1.2362 + case EColor64K:
1.2363 + case EColor16M:
1.2364 + case ERgb:
1.2365 + case EColor16MU:
1.2366 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor16);
1.2367 + break;
1.2368 + default:
1.2369 + break;
1.2370 + }
1.2371 + break;
1.2372 + case EColor256:
1.2373 + switch (aReadDispMode)
1.2374 + {
1.2375 + case EGray2:
1.2376 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray2);
1.2377 + break;
1.2378 + case EGray4:
1.2379 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray4);
1.2380 + break;
1.2381 + case EGray16:
1.2382 + case EGray256:
1.2383 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray16);
1.2384 + break;
1.2385 + case EColor16:
1.2386 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor16);
1.2387 + break;
1.2388 + case EColor256:
1.2389 + case EColor4K:
1.2390 + case EColor64K:
1.2391 + case EColor16M:
1.2392 + case ERgb:
1.2393 + case EColor16MU:
1.2394 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor256);
1.2395 + break;
1.2396 + default:
1.2397 + break;
1.2398 + }
1.2399 + break;
1.2400 + case EColor4K:
1.2401 + switch (aReadDispMode)
1.2402 + {
1.2403 + case EGray2:
1.2404 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray2);
1.2405 + break;
1.2406 + case EGray4:
1.2407 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray4);
1.2408 + break;
1.2409 + case EGray16:
1.2410 + case EGray256:
1.2411 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray16);
1.2412 + break;
1.2413 + case EColor16:
1.2414 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor16);
1.2415 + break;
1.2416 + case EColor256:
1.2417 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor256);
1.2418 + break;
1.2419 + case EColor4K:
1.2420 + case EColor64K:
1.2421 + case EColor16M:
1.2422 + case ERgb:
1.2423 + case EColor16MU:
1.2424 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor4K);
1.2425 + break;
1.2426 + default:
1.2427 + break;
1.2428 + }
1.2429 + break;
1.2430 + case EColor64K:
1.2431 + switch (aReadDispMode)
1.2432 + {
1.2433 + case EGray2:
1.2434 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray2);
1.2435 + break;
1.2436 + case EGray4:
1.2437 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray4);
1.2438 + break;
1.2439 + case EGray16:
1.2440 + case EGray256:
1.2441 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EGray16);
1.2442 + break;
1.2443 + case EColor16:
1.2444 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor16);
1.2445 + break;
1.2446 + case EColor256:
1.2447 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor256);
1.2448 + break;
1.2449 + case EColor4K:
1.2450 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor4K);
1.2451 + break;
1.2452 + case EColor64K:
1.2453 + case EColor16M:
1.2454 + case ERgb:
1.2455 + case EColor16MU:
1.2456 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,EColor64K);
1.2457 + break;
1.2458 + default:
1.2459 + break;
1.2460 + }
1.2461 + break;
1.2462 + case EColor16M:
1.2463 + case EColor16MU:
1.2464 + case EColor16MA:
1.2465 + case EColor16MAP:
1.2466 + CheckPixel(aWriteBuffer,aWriteDispMode,aReadBuffer,aReadDispMode,aPixelLength,aReadDispMode);
1.2467 + break;
1.2468 + default:
1.2469 + break;
1.2470 + };
1.2471 + }
1.2472 +
1.2473 +void CTLowLevel::CheckPixel(TUint8* aWriteBuffer,TDisplayMode aWriteDispMode,TUint8* aReadBuffer,TDisplayMode aReadDispMode,TInt aPixelLength,TDisplayMode aCompareDispMode)
1.2474 + {
1.2475 + TColorConvertor& colorConvertor = ColorConvertor(aCompareDispMode);
1.2476 +
1.2477 + for (TInt count = 0; count < aPixelLength; count++)
1.2478 + {
1.2479 + TRgb writeValue = ExtractRgbValue(count,aWriteBuffer,aWriteDispMode);
1.2480 + TRgb readValue = ExtractRgbValue(count,aReadBuffer,aReadDispMode);
1.2481 + CheckMatch(colorConvertor.Index(writeValue),colorConvertor.Index(readValue));
1.2482 + }
1.2483 + }
1.2484 +
1.2485 +void CTLowLevel::CheckRgb(const TPoint& aPoint,TRgb aColor,TRgb aBackgroundColor,CGraphicsContext::TDrawMode aDrawMode,TInt aShadowMode)
1.2486 + {
1.2487 + TRect rect(aPoint,TSize(1,1));
1.2488 + iDrawDevice->CFbsDrawDevice::SetDitherOrigin(aPoint);
1.2489 + CheckRgb(rect,aColor,aBackgroundColor,aDrawMode,aShadowMode);
1.2490 + }
1.2491 +
1.2492 +void CTLowLevel::CheckRgb(const TRect& aRect,TRgb aColor,TRgb aBackgroundColor,CGraphicsContext::TDrawMode aDrawMode,TInt aShadowMode)
1.2493 + {
1.2494 + Shadow(aColor,aShadowMode);
1.2495 +
1.2496 + if (aDrawMode == CGraphicsContext::EDrawModeNOTPEN)
1.2497 + aColor = ~aColor;
1.2498 +
1.2499 + TRgb foreColor[4];
1.2500 + Normalize(aColor,foreColor);
1.2501 +
1.2502 + TRgb backColor[4];
1.2503 + Normalize(aBackgroundColor,backColor);
1.2504 +
1.2505 + TRgb fore11 = foreColor[0];
1.2506 + TRgb fore21 = foreColor[1];
1.2507 + TRgb back11 = backColor[0];
1.2508 + TRgb back21 = backColor[1];
1.2509 + TRgb fore12 = foreColor[2];
1.2510 + TRgb fore22 = foreColor[3];
1.2511 + TRgb back12 = backColor[2];
1.2512 + TRgb back22 = backColor[3];
1.2513 +
1.2514 + TInt startY = aRect.iTl.iY;
1.2515 + TInt endY = aRect.iBr.iY - 1;
1.2516 +
1.2517 + if (startY & 1)
1.2518 + {
1.2519 + CheckScanline(aRect.iTl.iX,startY,aRect.Width(),fore12,fore22,back12,back22,aDrawMode);
1.2520 + startY++;
1.2521 + }
1.2522 +
1.2523 + for (TInt yy = startY; yy < endY; yy += 2)
1.2524 + {
1.2525 + CheckScanline(aRect.iTl.iX,yy,aRect.Width(),fore11,fore21,back11,back21,aDrawMode);
1.2526 + CheckScanline(aRect.iTl.iX,yy + 1,aRect.Width(),fore12,fore22,back12,back22,aDrawMode);
1.2527 + }
1.2528 +
1.2529 + if (aRect.iBr.iY & 1)
1.2530 + {
1.2531 + CheckScanline(aRect.iTl.iX,endY,aRect.Width(),fore11,fore21,back11,back21,aDrawMode);
1.2532 + }
1.2533 + }
1.2534 +
1.2535 +void CTLowLevel::CheckShadowRgb(const TRect& aRect,TRgb aColor,TInt aShadowMode)
1.2536 + {
1.2537 + TRgb foreColor[4];
1.2538 + Normalize(aColor,foreColor);
1.2539 +
1.2540 + TRgb fore11 = foreColor[0];
1.2541 + TRgb fore21 = foreColor[1];
1.2542 + TRgb fore12 = foreColor[2];
1.2543 + TRgb fore22 = foreColor[3];
1.2544 +
1.2545 + Shadow(fore11,aShadowMode & 2);
1.2546 + Shadow(fore21,aShadowMode & 2);
1.2547 + Shadow(fore12,aShadowMode & 2);
1.2548 + Shadow(fore22,aShadowMode & 2);
1.2549 +
1.2550 + Normalize(fore11);
1.2551 + Normalize(fore21);
1.2552 + Normalize(fore12);
1.2553 + Normalize(fore22);
1.2554 +
1.2555 + Shadow(fore11,aShadowMode & 1);
1.2556 + Shadow(fore21,aShadowMode & 1);
1.2557 + Shadow(fore12,aShadowMode & 1);
1.2558 + Shadow(fore22,aShadowMode & 1);
1.2559 +
1.2560 + Normalize(fore11);
1.2561 + Normalize(fore21);
1.2562 + Normalize(fore12);
1.2563 + Normalize(fore22);
1.2564 +
1.2565 + TInt startY = aRect.iTl.iY;
1.2566 + TInt endY = aRect.iBr.iY - 1;
1.2567 +
1.2568 + iDrawDevice->CFbsDrawDevice::ShadowArea(aRect);
1.2569 +
1.2570 + if (iDispMode== EColor16MAP)
1.2571 + {
1.2572 + //No dithering, no blending, just checking for a solid colour
1.2573 + fore12.SetAlpha(0);//do not want any blending to take place
1.2574 + fore22.SetAlpha(0);//do not want any blending to take place
1.2575 + for (TInt yy = startY; yy < endY; yy ++)
1.2576 + {
1.2577 + CheckScanline(aRect.iTl.iX,yy,aRect.Width(),fore11,fore11,fore22,fore22,CGraphicsContext::EDrawModePEN);
1.2578 + }
1.2579 + return;
1.2580 + }
1.2581 +
1.2582 + if (startY & 1)
1.2583 + {
1.2584 + CheckScanline(aRect.iTl.iX,startY,aRect.Width(),fore12,fore22,fore12,fore22,CGraphicsContext::EDrawModePEN);
1.2585 + startY++;
1.2586 + }
1.2587 +
1.2588 + for (TInt yy = startY; yy < endY; yy += 2)
1.2589 + {
1.2590 + CheckScanline(aRect.iTl.iX,yy,aRect.Width(),fore11,fore21,fore11,fore21,CGraphicsContext::EDrawModePEN);
1.2591 + CheckScanline(aRect.iTl.iX,yy + 1,aRect.Width(),fore12,fore22,fore12,fore22,CGraphicsContext::EDrawModePEN);
1.2592 + }
1.2593 +
1.2594 + if (aRect.iBr.iY & 1)
1.2595 + {
1.2596 + CheckScanline(aRect.iTl.iX,endY,aRect.Width(),fore11,fore21,fore11,fore21,CGraphicsContext::EDrawModePEN);
1.2597 + }
1.2598 + }
1.2599 +
1.2600 +void CTLowLevel::CheckScanline(TInt aX,TInt aY,TInt aLength,TRgb aFore1,TRgb aFore2,TRgb aBack1,TRgb aBack2,CGraphicsContext::TDrawMode aDrawMode)
1.2601 + {
1.2602 + iDrawDevice->ReadLine(aX,aY,aLength,iDrawDevice->ScanLineBuffer(),iDispMode);
1.2603 +
1.2604 + TUint32 binaryPixel1 = BinaryValue(aFore1,aBack1,aDrawMode);
1.2605 + TUint32 binaryPixel2 = BinaryValue(aFore2,aBack2,aDrawMode);
1.2606 + if (aX & 1)
1.2607 + {
1.2608 + TUint32 spare = binaryPixel1;
1.2609 + binaryPixel1 = binaryPixel2;
1.2610 + binaryPixel2 = spare;
1.2611 + }
1.2612 +
1.2613 + TInt extra = aLength & 1;
1.2614 + aLength &= ~1;
1.2615 + TInt x = 0;
1.2616 +
1.2617 + if (iPostBlendShadow)
1.2618 + {
1.2619 + PostBlendShadow(binaryPixel1);
1.2620 + PostBlendShadow(binaryPixel2);
1.2621 + }
1.2622 + if (i16MAUserDispMode)
1.2623 + {
1.2624 + binaryPixel1 = PMA2NonPMAPixel(binaryPixel1,PtrTo16BitNormalisationTable());
1.2625 + binaryPixel2 = PMA2NonPMAPixel(binaryPixel1,PtrTo16BitNormalisationTable());
1.2626 + }
1.2627 + while (x < aLength)
1.2628 + {
1.2629 + TUint32 binaryValue = ExtractBinaryValue(x,iDrawDevice->ScanLineBuffer(),iDispMode);
1.2630 + CheckMatch(binaryPixel1,binaryValue);
1.2631 + x++;
1.2632 +
1.2633 + binaryValue = ExtractBinaryValue(x,iDrawDevice->ScanLineBuffer(),iDispMode);
1.2634 + CheckMatch(binaryPixel2,binaryValue);
1.2635 + x++;
1.2636 + }
1.2637 + if (extra)
1.2638 + {
1.2639 + TUint32 binaryValue = ExtractBinaryValue(x,iDrawDevice->ScanLineBuffer(),iDispMode);
1.2640 + CheckMatch(binaryPixel1,binaryValue);
1.2641 + }
1.2642 + }
1.2643 +
1.2644 +void CTLowLevel::CheckLine(TUint8* aWriteBuffer,TUint8* aReadBuffer,TUint8* aBackBuffer,TInt aPixelLength,CGraphicsContext::TDrawMode aDrawMode,TDisplayMode aDispMode)
1.2645 + {
1.2646 + TInt wholeBytes = 0;
1.2647 + TInt extraBits = 0;
1.2648 +
1.2649 + switch (aDispMode)
1.2650 + {
1.2651 + case EGray2:
1.2652 + wholeBytes = aPixelLength / 8;
1.2653 + extraBits = aPixelLength & 7;
1.2654 + break;
1.2655 + case EGray4:
1.2656 + wholeBytes = aPixelLength / 4;
1.2657 + extraBits = (aPixelLength & 3) * 2;
1.2658 + break;
1.2659 + case EGray16:
1.2660 + case EColor16:
1.2661 + wholeBytes = aPixelLength / 2;
1.2662 + extraBits = (aPixelLength & 1) * 4;
1.2663 + break;
1.2664 + case EGray256:
1.2665 + case EColor256:
1.2666 + wholeBytes = aPixelLength;
1.2667 + break;
1.2668 + case EColor4K:
1.2669 + case EColor64K:
1.2670 + wholeBytes = aPixelLength * 2;
1.2671 + break;
1.2672 + case EColor16M:
1.2673 + wholeBytes = aPixelLength * 3;
1.2674 + break;
1.2675 + case EColor16MU:
1.2676 + case EColor16MA:
1.2677 + case EColor16MAP:
1.2678 + wholeBytes = aPixelLength * 4;
1.2679 + break;
1.2680 + default:
1.2681 + break;
1.2682 + };
1.2683 +
1.2684 + TUint8* readLimit = aReadBuffer + wholeBytes;
1.2685 + TUint8 mask = TUint8(0xff >> (8 - extraBits));
1.2686 + TInt byteCounter = 0;
1.2687 +
1.2688 + switch (aDrawMode)
1.2689 + {
1.2690 + case CGraphicsContext::EDrawModeAND:
1.2691 + if (iDispMode==EColor16MAP)
1.2692 + break; //logical opeations not supported for premultiplied alpha
1.2693 + for (; aReadBuffer < readLimit; aReadBuffer++, aWriteBuffer++, aBackBuffer++)
1.2694 + {
1.2695 + if(!((aDispMode == EColor16MU || aDispMode == EColor16MA || aDispMode == EColor16MAP)
1.2696 + && ++byteCounter % 4 == 0))
1.2697 + Check(*aReadBuffer == (*aWriteBuffer & *aBackBuffer));
1.2698 + }
1.2699 + if (extraBits > 0)
1.2700 + Check((*aReadBuffer & mask) == (*aWriteBuffer & *aBackBuffer & mask));
1.2701 + break;
1.2702 + case CGraphicsContext::EDrawModePEN:
1.2703 + if(aDispMode == EColor16MU || aDispMode == EColor16MA || aDispMode == EColor16MAP)
1.2704 + {
1.2705 + for (; aReadBuffer<readLimit; aReadBuffer+=4, aWriteBuffer+=4)
1.2706 + {
1.2707 + TBool fail=EFalse;
1.2708 + Blend(aWriteBuffer,aBackBuffer,aDispMode);
1.2709 + if (!iFuzzyMatch)
1.2710 + {
1.2711 + fail|=Check(AbsDiff(*aReadBuffer,*aWriteBuffer)<2);
1.2712 + fail|=Check(AbsDiff(*(aReadBuffer+1),*(aWriteBuffer+1))<2);
1.2713 + fail|=Check(AbsDiff(*(aReadBuffer+2),*(aWriteBuffer+2))<2);
1.2714 + fail|=Check(AbsDiff(*(aReadBuffer+3),*(aWriteBuffer+3))<2);
1.2715 + }
1.2716 + else
1.2717 + {
1.2718 + fail|=Check(AbsDiff(*aReadBuffer,*aWriteBuffer)<KInaccuracyLimit);
1.2719 + fail|=Check(AbsDiff(*(aReadBuffer+1),*(aWriteBuffer+1))<KInaccuracyLimit);
1.2720 + fail|=Check(AbsDiff(*(aReadBuffer+2),*(aWriteBuffer+2))<KInaccuracyLimit);
1.2721 + fail|=Check(AbsDiff(*(aReadBuffer+3),*(aWriteBuffer+3))<KInaccuracyLimit);
1.2722 + }
1.2723 + if (fail)
1.2724 + {
1.2725 + _LIT(KLog,"The values 0x%x and 0x%x don't match, fuzzyMatch=%d (limit=%d), memory 0x%x 0x%x");
1.2726 + INFO_PRINTF7(KLog,*reinterpret_cast<TUint*>(aReadBuffer),*reinterpret_cast<TUint*>(aWriteBuffer),iFuzzyMatch,KInaccuracyLimit,aReadBuffer,aWriteBuffer);
1.2727 + }
1.2728 + }
1.2729 + }
1.2730 + else
1.2731 + {
1.2732 + for (; aReadBuffer < readLimit; aReadBuffer++, aWriteBuffer++)
1.2733 + {
1.2734 + if (Check(*aReadBuffer == *aWriteBuffer))
1.2735 + {
1.2736 + _LIT(KLog,"The values 0x%x and 0x%x don't match, memory 0x%x 0x%x");
1.2737 + INFO_PRINTF5(KLog,*aReadBuffer,*aWriteBuffer,aReadBuffer,aWriteBuffer);
1.2738 + }
1.2739 + }
1.2740 + if (extraBits > 0)
1.2741 + Check((*aReadBuffer & mask) == (*aWriteBuffer & mask));
1.2742 + }
1.2743 + break;
1.2744 + case CGraphicsContext::EDrawModeNOTPEN:
1.2745 + if (iDispMode==EColor16MAP)
1.2746 + break; //logical opeations not supported for premultiplied alpha
1.2747 + if(aDispMode == EColor16MU || aDispMode == EColor16MA )
1.2748 + {
1.2749 + for (; aReadBuffer < readLimit; aReadBuffer +=4, aWriteBuffer+=4)
1.2750 + {
1.2751 + *aWriteBuffer ^= 0xff;
1.2752 + *(aWriteBuffer+1) ^= 0xff;
1.2753 + *(aWriteBuffer+2) ^= 0xff;
1.2754 +
1.2755 + Blend(aWriteBuffer,aBackBuffer,aDispMode);
1.2756 +
1.2757 + if (!iFuzzyMatch)
1.2758 + {
1.2759 + Check(AbsDiff(*aReadBuffer, *aWriteBuffer) < 2);
1.2760 + Check(AbsDiff(*(aReadBuffer+1), *(aWriteBuffer+1)) < 2);
1.2761 + Check(AbsDiff(*(aReadBuffer+2), *(aWriteBuffer+2)) < 2);
1.2762 + Check(AbsDiff(*(aReadBuffer+3), *(aWriteBuffer+3)) < 2);
1.2763 + }
1.2764 + else
1.2765 + {
1.2766 + Check(AbsDiff(*aReadBuffer, *aWriteBuffer) < KInaccuracyLimit);
1.2767 + Check(AbsDiff(*(aReadBuffer+1), *(aWriteBuffer+1)) < KInaccuracyLimit);
1.2768 + Check(AbsDiff(*(aReadBuffer+2), *(aWriteBuffer+2)) < KInaccuracyLimit);
1.2769 + Check(AbsDiff(*(aReadBuffer+3), *(aWriteBuffer+3)) < KInaccuracyLimit);
1.2770 + }
1.2771 + }
1.2772 + }
1.2773 + else
1.2774 + {
1.2775 +
1.2776 + for (; aReadBuffer < readLimit; aReadBuffer++, aWriteBuffer++)
1.2777 + {
1.2778 + if(!((aDispMode == EColor16MU || aDispMode == EColor16MA || aDispMode == EColor16MAP) && ++byteCounter % 4 == 0))
1.2779 + Check(*aReadBuffer == (*aWriteBuffer ^ 0xff));
1.2780 + }
1.2781 + if (extraBits > 0)
1.2782 + Check((*aReadBuffer & mask) == ((*aWriteBuffer ^ 0xff) & mask));
1.2783 + }
1.2784 + break;
1.2785 + case CGraphicsContext::EDrawModeXOR:
1.2786 + if (iDispMode==EColor16MAP)
1.2787 + break;//logical opeations not supported for premultiplied alpha
1.2788 + for (; aReadBuffer < readLimit; aReadBuffer++, aWriteBuffer++, aBackBuffer++)
1.2789 + {
1.2790 + if(!((aDispMode == EColor16MU || aDispMode == EColor16MA || aDispMode == EColor16MAP) && ++byteCounter % 4 == 0))
1.2791 + Check(*aReadBuffer == (*aWriteBuffer ^ *aBackBuffer));
1.2792 + }
1.2793 + if (extraBits > 0)
1.2794 + Check((*aReadBuffer & mask) == ((*aWriteBuffer ^ *aBackBuffer) & mask));
1.2795 + break;
1.2796 + case CGraphicsContext::EDrawModeOR:
1.2797 + if (iDispMode==EColor16MAP)
1.2798 + break;//logical opeations not supported for premultiplied alpha
1.2799 + for (; aReadBuffer < readLimit; aReadBuffer++, aWriteBuffer++, aBackBuffer++)
1.2800 + {
1.2801 + if(!((aDispMode == EColor16MU || aDispMode == EColor16MA || aDispMode == EColor16MAP) && ++byteCounter % 4 == 0))
1.2802 + Check(*aReadBuffer == (*aWriteBuffer | *aBackBuffer));
1.2803 + }
1.2804 + if (extraBits > 0)
1.2805 + Check((*aReadBuffer & mask) == ((*aWriteBuffer | *aBackBuffer) & mask));
1.2806 + break;
1.2807 + case CGraphicsContext::EDrawModeNOTSCREEN:
1.2808 + if (iDispMode==EColor16MAP)
1.2809 + break;//logical opeations not supported for premultiplied alpha
1.2810 + if (aDispMode != EColor4K)
1.2811 + {
1.2812 + for (; aReadBuffer < readLimit; aReadBuffer++, aBackBuffer++)
1.2813 + {
1.2814 + if(!((aDispMode == EColor16MU || aDispMode == EColor16MA || aDispMode == EColor16MAP) && ++byteCounter % 4 == 0))
1.2815 + {
1.2816 + if (iFuzzyMatch==EFalse)
1.2817 + Check(*aReadBuffer == (*aBackBuffer ^ 0xff));
1.2818 + else
1.2819 + {
1.2820 + TUint8 vals[3];
1.2821 + vals[0]=*aReadBuffer;
1.2822 + //put in some tolerance values, try with +/- 1, to begin with
1.2823 + if (vals[0]<255)
1.2824 + vals[1]=vals[0]+1;
1.2825 + else
1.2826 + vals[1]=vals[0];
1.2827 + if (vals[0]>0)
1.2828 + vals[2]=vals[0]-1;
1.2829 + else
1.2830 + vals[2]=vals[0];
1.2831 + Check((vals[0] == (*aBackBuffer ^ 0xff))||
1.2832 + (vals[1] == (*aBackBuffer ^ 0xff))||
1.2833 + (vals[2] == (*aBackBuffer ^ 0xff)));
1.2834 + }
1.2835 + }
1.2836 + }
1.2837 + if (extraBits > 0)
1.2838 + Check((*aReadBuffer & mask) == ((*aBackBuffer ^ 0xff) & mask));
1.2839 + }
1.2840 + else
1.2841 + {
1.2842 + while (aReadBuffer < readLimit)
1.2843 + {
1.2844 + if (TInt(aReadBuffer) & 1)
1.2845 + Check(*aReadBuffer++ == (*aBackBuffer++ ^ 0x0f));
1.2846 + else
1.2847 + Check(*aReadBuffer++ == (*aBackBuffer++ ^ 0xff));
1.2848 + }
1.2849 + }
1.2850 + break;
1.2851 + default:
1.2852 + break;
1.2853 + };
1.2854 + }
1.2855 +
1.2856 +void CTLowLevel::CheckBinary(const TRect& aRect,TUint32* aBuffer,TRgb aForeColor,TRgb aBackColor,CGraphicsContext::TDrawMode aDrawMode,TInt aShadowMode,TBool aWrapDataWords,TBool aUp)
1.2857 + {
1.2858 + Shadow(aForeColor,aShadowMode);
1.2859 +
1.2860 + if (aDrawMode == CGraphicsContext::EDrawModeNOTPEN)
1.2861 + aForeColor = ~aForeColor;
1.2862 +
1.2863 + TRgb foreColor[4];
1.2864 + Normalize(aForeColor,foreColor);
1.2865 +
1.2866 + TRgb backColor[4];
1.2867 + Normalize(aBackColor,backColor);
1.2868 +
1.2869 + foreColor[0] = RgbValue(foreColor[0],backColor[0],aDrawMode);
1.2870 + foreColor[1] = RgbValue(foreColor[1],backColor[1],aDrawMode);
1.2871 + foreColor[2] = RgbValue(foreColor[2],backColor[2],aDrawMode);
1.2872 + foreColor[3] = RgbValue(foreColor[3],backColor[3],aDrawMode);
1.2873 +
1.2874 +
1.2875 + if (iDispMode==EColor16MAP)
1.2876 + {
1.2877 + //pre-multiply and unpremultiply
1.2878 + TInt count;
1.2879 + for (count=0;count<4;count++)
1.2880 + {
1.2881 + TUint32 tempInt;
1.2882 + tempInt = backColor[count].Color16MAP(); //Now premultiplied
1.2883 + backColor[count] = TRgb::Color16MAP(tempInt);
1.2884 + }
1.2885 + }
1.2886 +
1.2887 + TUint32 data = *aBuffer++;
1.2888 + TUint32 mask = 1;
1.2889 +
1.2890 + TInt yy = (aUp) ? aRect.iBr.iY - 1 : aRect.iTl.iY;
1.2891 + TInt ylimit = (aUp) ? aRect.iTl.iY - 1 : aRect.iBr.iY;
1.2892 + TInt yinc = (aUp) ? -1 : 1;
1.2893 +
1.2894 + TRgb pixelBuffer[KCheckBinaryPixelBufferSize];
1.2895 + __ASSERT_ALWAYS(aRect.Width() <= KCheckBinaryPixelBufferSize,User::Panic(_L("CheckBinary buffer"),KErrOverflow));
1.2896 +
1.2897 + for (; yy != ylimit; yy += yinc)
1.2898 + {
1.2899 + TInt yoffset = 2 * (yy & 1);
1.2900 +
1.2901 + iDrawDevice->ReadLine(aRect.iTl.iX,yy,aRect.Width(),pixelBuffer,ERgb);
1.2902 + TRgb* color = pixelBuffer;
1.2903 +
1.2904 + for (TInt xx = aRect.iTl.iX; xx < aRect.iBr.iX; xx++)
1.2905 + {
1.2906 + if (!mask)
1.2907 + {
1.2908 + mask = 1;
1.2909 + data = *aBuffer++;
1.2910 + }
1.2911 +
1.2912 + if (data & mask)
1.2913 + CheckMatch((*color).Internal(), foreColor[(xx & 1) + yoffset].Internal());
1.2914 + else
1.2915 + CheckMatch((*color).Internal(), backColor[(xx & 1) + yoffset].Internal());
1.2916 +
1.2917 + color++;
1.2918 + mask <<= 1;
1.2919 + }
1.2920 +
1.2921 + if (aWrapDataWords)
1.2922 + mask = 0;
1.2923 + }
1.2924 + }
1.2925 +
1.2926 +void CTLowLevel::CheckBackground(const TRect& aRect,TRgb aBackgroundColor)
1.2927 + {
1.2928 + iBlendTestColors= EFalse;
1.2929 + if (aRect.iTl.iX > 0)
1.2930 + CheckRgb(TRect(aRect.iTl.iX - 1,aRect.iTl.iY,aRect.iTl.iX,aRect.iBr.iY),aBackgroundColor,aBackgroundColor,CGraphicsContext::EDrawModePEN,0);
1.2931 + if (aRect.iTl.iY > 0)
1.2932 + CheckRgb(TRect(aRect.iTl.iX,aRect.iTl.iY - 1,aRect.iBr.iX,aRect.iTl.iY),aBackgroundColor,aBackgroundColor,CGraphicsContext::EDrawModePEN,0);
1.2933 + if (aRect.iBr.iX < iSize.iWidth - 1)
1.2934 + CheckRgb(TRect(aRect.iBr.iX,aRect.iTl.iY,aRect.iBr.iX + 1,aRect.iBr.iY),aBackgroundColor,aBackgroundColor,CGraphicsContext::EDrawModePEN,0);
1.2935 + if (aRect.iBr.iY < iSize.iHeight - 1)
1.2936 + CheckRgb(TRect(aRect.iTl.iX,aRect.iBr.iY,aRect.iBr.iX,aRect.iBr.iY + 1),aBackgroundColor,aBackgroundColor,CGraphicsContext::EDrawModePEN,0);
1.2937 + iBlendTestColors= ETrue;
1.2938 + }
1.2939 +/**
1.2940 +This function is copied as it is from BMDRAW32A.CPP which is used to test WriteRgbOutlineAndShadow for EColor16MA.
1.2941 +It is used in CTLowLevel::CheckBlendedOutlineAndShadow.
1.2942 +@param aBeneath The background pixel colour value
1.2943 +@param aSrcColor The source pixel colour value
1.2944 +@param aAlpha The alpha value
1.2945 +*/
1.2946 +FORCEINLINE TUint32 OptimizedBlend32A(TUint32 aBeneath,TUint32 aSrcColor,TUint8 aAlpha)
1.2947 + {
1.2948 + if(aAlpha)
1.2949 + {
1.2950 + if(aAlpha == 0xff) // opaque, so unchanged
1.2951 + {
1.2952 + //Still need to convert source to destination from non-multiplied to pre-multiplied
1.2953 + //But this code resolves to a copy. The ARM optimiser prefers shifts over big constants.
1.2954 + return (aSrcColor|(aAlpha<<24));
1.2955 + }
1.2956 + else
1.2957 + {
1.2958 + //0, 1, 2, 3
1.2959 + //b, g, rect, alpha
1.2960 +
1.2961 + const TUint32 srcMult = aAlpha;
1.2962 + TUint32 destMult = ((255 - aAlpha) * ((aBeneath >> 24)));
1.2963 + //This gives a slightly more accurate result than ((aBeneath >> 24)+1)
1.2964 + destMult=destMult+(destMult>>8);
1.2965 + destMult+= 0x0080;
1.2966 + destMult >>= 8;
1.2967 +
1.2968 + TUint32 rb =(((aSrcColor&0x00ff00ff)*srcMult)) + (((aBeneath&0x00ff00ff)*destMult));
1.2969 + rb = rb+((rb>>8)&0x00ff00ff);
1.2970 + rb+=0x00800080;
1.2971 + rb>>=8;
1.2972 + TUint32 ag = (((aSrcColor&0x0000ff00)*srcMult)) + (((aBeneath&0x0000ff00)*destMult));
1.2973 + ag>>=8; //Note that if alpha is processed here, this shift must be performed before the multiplies
1.2974 + ag = ag+((ag>>8)&0x00ff00ff);
1.2975 + ag+=0x00800080;
1.2976 + TUint32 aa = srcMult+destMult;
1.2977 + return (rb&0x00ff00ff) | (ag&0x0000ff00) | (aa << 24);
1.2978 +
1.2979 + }
1.2980 + }
1.2981 + else // completely transparent
1.2982 + {
1.2983 + return aBeneath;
1.2984 + }
1.2985 +
1.2986 + }
1.2987 +
1.2988 +/**
1.2989 +Helper function for TestWriteRgbOutlineAndShadow(). Creates the final colour, blending the outline, shadow,
1.2990 +fill and background colour using lookup table provided by Monotype and compares with the
1.2991 +pixel colour drawn using WriteRgbOutlineAndShadow.
1.2992 +
1.2993 +@param aOutlinePenColor Colour used for drawing outline of font
1.2994 +@param aShadowColor Colour used for drawing shadow of font
1.2995 +@param aFillColor Colour used for filling of font
1.2996 +@param aBackgroundColor Background colour of the pixel
1.2997 +@param aLookupIndex Index of the lookup table to be used for generating final colour
1.2998 +@param aLength Number of pixels to compare the pixel colour with the generated colour
1.2999 +@param aReadBuffer Buffer containing the colours drawn using WriteRgbOutlineAndShadow.This will be used for comparing
1.3000 +@return EFalse if pixel colour doesnt match with the calculated colour, otherwise ETrue on success.
1.3001 +*/
1.3002 +TBool CTLowLevel::CheckBlendedOutlineAndShadow(TRgb aOutlinePenColor, TRgb aShadowColor, TRgb aFillColor,
1.3003 + TRgb aBackgroundColor, TInt aLookupIndex, TInt aLength, TUint8* aReadBuffer)
1.3004 + {
1.3005 + TRgb finalColor;
1.3006 + TInt alpha = aOutlinePenColor.Internal() >> 24;
1.3007 +
1.3008 + if (255 == FourColorBlendLookup[aLookupIndex][3])
1.3009 + {
1.3010 + //background colour
1.3011 + finalColor.SetInternal(aBackgroundColor.Internal());
1.3012 +
1.3013 + /*Reset the alpha with background colour alpha as in product code in case of 255 == FourColorBlendLookup[aLookupIndex][3]
1.3014 + it doesnt draw and leaves the background colour as it is. So the alpha to be checked should be of background colour alpha*/
1.3015 + alpha = aBackgroundColor.Alpha();
1.3016 + }
1.3017 + else if (255 == FourColorBlendLookup[aLookupIndex][2])
1.3018 + {
1.3019 + //fill colour
1.3020 + finalColor.SetInternal(aFillColor.Internal());
1.3021 + }
1.3022 + else if (255 == FourColorBlendLookup[aLookupIndex][1])
1.3023 + {
1.3024 + //Shadow colour
1.3025 + finalColor.SetInternal(aShadowColor.Internal());
1.3026 + }
1.3027 + else if (255 == FourColorBlendLookup[aLookupIndex][0])
1.3028 + {
1.3029 + //Outline colour
1.3030 + finalColor.SetInternal(aOutlinePenColor.Internal());
1.3031 + }
1.3032 + else
1.3033 + {
1.3034 + TInt blendedRedColor = (aOutlinePenColor.Red() * FourColorBlendLookup[aLookupIndex][0] +
1.3035 + aShadowColor.Red() * FourColorBlendLookup[aLookupIndex][1] +
1.3036 + aFillColor.Red() * FourColorBlendLookup[aLookupIndex][2] +
1.3037 + aBackgroundColor.Red() * FourColorBlendLookup[aLookupIndex][3]) >> 8;
1.3038 +
1.3039 + TInt blendedGreenColor = (aOutlinePenColor.Green() * FourColorBlendLookup[aLookupIndex][0] +
1.3040 + aShadowColor.Green() * FourColorBlendLookup[aLookupIndex][1] +
1.3041 + aFillColor.Green() * FourColorBlendLookup[aLookupIndex][2] +
1.3042 + aBackgroundColor.Green() * FourColorBlendLookup[aLookupIndex][3]) >> 8;
1.3043 +
1.3044 + TInt blendedBlueColor = (aOutlinePenColor.Blue() * FourColorBlendLookup[aLookupIndex][0] +
1.3045 + aShadowColor.Blue() * FourColorBlendLookup[aLookupIndex][1] +
1.3046 + aFillColor.Blue() * FourColorBlendLookup[aLookupIndex][2] +
1.3047 + aBackgroundColor.Blue() * FourColorBlendLookup[aLookupIndex][3]) >> 8;
1.3048 +
1.3049 + finalColor = TRgb(blendedRedColor, blendedGreenColor, blendedBlueColor);
1.3050 + }
1.3051 +
1.3052 + //Set the alpha in the final colour
1.3053 + finalColor.SetAlpha(alpha);
1.3054 +
1.3055 + //Alpha blending is not supported for display modes below EColor64K.
1.3056 + switch(iDispMode)
1.3057 + {
1.3058 + case EColor64K:
1.3059 + case EColor16M:
1.3060 + case EColor16MU:
1.3061 + if (alpha != 0xff)
1.3062 + {
1.3063 + finalColor = AlphaBlend(finalColor.Red(), finalColor.Green(), finalColor.Blue(), aBackgroundColor.Red(), aBackgroundColor.Green(), aBackgroundColor.Blue(), alpha);
1.3064 + }
1.3065 + break;
1.3066 + case EColor16MA:
1.3067 + //Just use the background color to draw in case 255 == FourColorBlendLookup[aLookupIndex][3]
1.3068 + if (255 != FourColorBlendLookup[aLookupIndex][3])
1.3069 + {
1.3070 + finalColor.SetInternal(OptimizedBlend32A(aBackgroundColor.Internal(), finalColor.Internal(), alpha));
1.3071 + }
1.3072 + break;
1.3073 + case EColor16MAP:
1.3074 + //Just use the background color to draw in case 255 == FourColorBlendLookup[aLookupIndex][3]
1.3075 + if (255 != FourColorBlendLookup[aLookupIndex][3])
1.3076 + {
1.3077 + TUint32 color16MAP = finalColor.Internal();
1.3078 + Convert2PMA(color16MAP);
1.3079 + finalColor.SetInternal(PMAPixelBlend(aBackgroundColor.Internal(), color16MAP));
1.3080 + }
1.3081 + break;
1.3082 + };
1.3083 +
1.3084 + Normalize(finalColor);
1.3085 + TColorConvertor& colorConvertor = ColorConvertor(iDispMode);
1.3086 + // Check each pixel of the line, it should match with the calculated blended color.
1.3087 + for (TInt count = 0; count < aLength; count++)
1.3088 + {
1.3089 + TRgb readValue = ExtractRgbValue(count, aReadBuffer, iDispMode);
1.3090 + if (colorConvertor.Index(finalColor) != colorConvertor.Index(readValue))
1.3091 + {
1.3092 + return EFalse;
1.3093 + }
1.3094 + }
1.3095 + return ETrue;
1.3096 + }
1.3097 +
1.3098 +TRgb CTLowLevel::RgbValue(TRgb aFore,TRgb aBack,CGraphicsContext::TDrawMode aDrawMode)
1.3099 + {
1.3100 + TUint32 value = BinaryValue(aFore,aBack,aDrawMode);
1.3101 +
1.3102 + switch (iDispMode)
1.3103 + {
1.3104 + case EGray2:
1.3105 + return TRgb::Gray2(value);
1.3106 + case EGray4:
1.3107 + return TRgb::Gray4(value);
1.3108 + case EGray16:
1.3109 + return TRgb::Gray16(value);
1.3110 + case EGray256:
1.3111 + return TRgb::Gray256(value);
1.3112 + case EColor16:
1.3113 + return TRgb::Color16(value);
1.3114 + case EColor256:
1.3115 + return TRgb::Color256(value);
1.3116 + case EColor4K:
1.3117 + return TRgb::Color4K(value);
1.3118 + case EColor64K:
1.3119 + return TRgb::Color64K(value);
1.3120 + case EColor16M:
1.3121 + return TRgb::Color16M(value);
1.3122 + case EColor16MU:
1.3123 + return TRgb::Color16MU(value);
1.3124 + case EColor16MA:
1.3125 + return TRgb::Color16MA(value);
1.3126 + case EColor16MAP:
1.3127 + return TRgb::Color16MAP(value);
1.3128 + default:
1.3129 + break;
1.3130 + };
1.3131 + return KRgbBlack;
1.3132 + }
1.3133 +
1.3134 +TUint32 CTLowLevel::BinaryValue(TRgb aFore,TRgb aBack,CGraphicsContext::TDrawMode aDrawMode)
1.3135 + {
1.3136 + TUint32 f = 0;
1.3137 + TUint32 b = 0;
1.3138 + TUint32 notVal = 0;
1.3139 +
1.3140 + switch (iDispMode)
1.3141 + {
1.3142 + case EGray2:
1.3143 + f = aFore.Gray2();
1.3144 + b = aBack.Gray2();
1.3145 + notVal = 1;
1.3146 + break;
1.3147 + case EGray4:
1.3148 + f = aFore.Gray4();
1.3149 + b = aBack.Gray4();
1.3150 + notVal = 3;
1.3151 + break;
1.3152 + case EGray16:
1.3153 + f = aFore.Gray16();
1.3154 + b = aBack.Gray16();
1.3155 + notVal = 0xf;
1.3156 + break;
1.3157 + case EGray256:
1.3158 + f = aFore.Gray256();
1.3159 + b = aBack.Gray256();
1.3160 + notVal = 0xff;
1.3161 + break;
1.3162 + case EColor16:
1.3163 + f = aFore.Color16();
1.3164 + b = aBack.Color16();
1.3165 + notVal = 0xf;
1.3166 + break;
1.3167 + case EColor256:
1.3168 + f = aFore.Color256();
1.3169 + b = aBack.Color256();
1.3170 + notVal = 0xff;
1.3171 + break;
1.3172 + case EColor4K:
1.3173 + f = aFore.Color4K();
1.3174 + b = aBack.Color4K();
1.3175 + notVal = 0xfff;
1.3176 + break;
1.3177 + case EColor64K:
1.3178 + f = aFore.Color64K();
1.3179 + b = aBack.Color64K();
1.3180 + notVal = 0xffff;
1.3181 + break;
1.3182 + case EColor16M:
1.3183 + f = aFore.Color16M();
1.3184 + b = aBack.Color16M();
1.3185 + notVal = 0xffffff;
1.3186 + break;
1.3187 + case EColor16MU:
1.3188 + f = aFore.Color16MU();
1.3189 + b = aBack.Color16MU();
1.3190 + notVal = 0x00ffffff;
1.3191 + break;
1.3192 + case EColor16MA:
1.3193 + f = aFore.Color16MA();
1.3194 + b = aBack.Color16MA();
1.3195 + notVal = 0xffffffff;
1.3196 + break;
1.3197 + case EColor16MAP:
1.3198 + f = aFore.Color16MAP();
1.3199 + b = aBack.Color16MAP();
1.3200 +
1.3201 + //do not want to blend backgound colours for testing
1.3202 + if (iBlendTestColors && (aDrawMode&CGraphicsContext::EDrawModePEN))
1.3203 + {
1.3204 + Blend((TUint8*)(&f),(TUint8*)(&b),iDispMode);
1.3205 + }
1.3206 + notVal = 0xffffffff;
1.3207 + break;
1.3208 + default:
1.3209 + break;
1.3210 + };
1.3211 +
1.3212 + switch (aDrawMode)
1.3213 + {
1.3214 + case CGraphicsContext::EDrawModeAND: return f & b;
1.3215 + case CGraphicsContext::EDrawModePEN: return f;
1.3216 + case CGraphicsContext::EDrawModeWriteAlpha: return f;
1.3217 + case CGraphicsContext::EDrawModeXOR: return f ^ b;
1.3218 + case CGraphicsContext::EDrawModeOR: return f | b;
1.3219 + case CGraphicsContext::EDrawModeNOTSCREEN: return b ^ notVal;
1.3220 + case CGraphicsContext::EDrawModeNOTPEN: return f;
1.3221 + default:
1.3222 + break;
1.3223 + };
1.3224 + return 0;
1.3225 + }
1.3226 +
1.3227 +TRgb CTLowLevel::ExtractRgbValue(TInt aX,TUint8* aBuffer,TDisplayMode aDispMode)
1.3228 + {
1.3229 + TUint32 value = ExtractBinaryValue(aX,(TUint32*)aBuffer,aDispMode);
1.3230 +
1.3231 + switch (aDispMode)
1.3232 + {
1.3233 + case EGray2:
1.3234 + return TRgb::Gray2(value);
1.3235 + case EGray4:
1.3236 + return TRgb::Gray4(value);
1.3237 + case EGray16:
1.3238 + return TRgb::Gray16(value);
1.3239 + case EGray256:
1.3240 + return TRgb::Gray256(value);
1.3241 + case EColor16:
1.3242 + return TRgb::Color16(value);
1.3243 + case EColor256:
1.3244 + return TRgb::Color256(value);
1.3245 + case EColor4K:
1.3246 + return TRgb::Color4K(value);
1.3247 + case EColor64K:
1.3248 + return TRgb::Color64K(value);
1.3249 + case EColor16M:
1.3250 + return TRgb::Color16M(value);
1.3251 + case ERgb:
1.3252 + return TRgb(value, value>>24);
1.3253 + case EColor16MU:
1.3254 + return TRgb::Color16MU(value);
1.3255 + case EColor16MA:
1.3256 + return TRgb::Color16MA(value);
1.3257 + case EColor16MAP:
1.3258 + return TRgb::Color16MAP(value);
1.3259 + default:
1.3260 + break;
1.3261 + };
1.3262 + return KRgbBlack;
1.3263 + }
1.3264 +
1.3265 +TUint32 CTLowLevel::ExtractBinaryValue(TInt aX,TUint32* aBuffer,TDisplayMode aDispMode)
1.3266 + {
1.3267 + switch (aDispMode)
1.3268 + {
1.3269 + case EGray2:
1.3270 + return ((*(aBuffer + (aX >> 5))) >> (aX & 0x1f)) & 1;
1.3271 + case EGray4:
1.3272 + return ((*(aBuffer + (aX >> 4))) >> ((aX & 0xf) * 2)) & 3;
1.3273 + case EGray16:
1.3274 + case EColor16:
1.3275 + return ((*(aBuffer + (aX >> 3))) >> ((aX & 7) * 4)) & 0xf;
1.3276 + case EGray256:
1.3277 + case EColor256:
1.3278 + return ((*(aBuffer + (aX >> 2))) >> ((aX & 3) * 8)) & 0xff;
1.3279 + case EColor4K:
1.3280 + return ((*(aBuffer + (aX >> 1))) >> ((aX & 1) * 16)) & 0xfff;
1.3281 + case EColor64K:
1.3282 + return ((*(aBuffer + (aX >> 1))) >> ((aX & 1) * 16)) & 0xffff;
1.3283 + case EColor16M:
1.3284 + {
1.3285 + TUint8* buffer = ((TUint8*)aBuffer) + (aX * 3);
1.3286 + return *buffer | (*(buffer + 1) << 8) | (*(buffer + 2) << 16);
1.3287 + }
1.3288 + case ERgb:
1.3289 + return *(aBuffer + aX);
1.3290 + case EColor16MU:
1.3291 + return *(aBuffer + aX) & 0x00FFFFFF;
1.3292 + case EColor16MA:
1.3293 + case EColor16MAP:
1.3294 + return *(aBuffer + aX);
1.3295 + default:
1.3296 + break;
1.3297 + };
1.3298 + return 0;
1.3299 + }
1.3300 +
1.3301 +void CTLowLevel::Normalize(TRgb& aColor)
1.3302 + {
1.3303 + return(Normalize(aColor,iDispMode));
1.3304 + }
1.3305 +
1.3306 +void CTLowLevel::Normalize(TRgb& aColor, TDisplayMode aDispMode)
1.3307 + {
1.3308 + switch (aDispMode)
1.3309 + {
1.3310 + case EGray2:
1.3311 + aColor = TRgb::Gray2(aColor.Gray2());
1.3312 + break;
1.3313 + case EGray4:
1.3314 + aColor = TRgb::Gray4(aColor.Gray4());
1.3315 + break;
1.3316 + case EGray16:
1.3317 + aColor = TRgb::Gray16(aColor.Gray16());
1.3318 + break;
1.3319 + case EGray256:
1.3320 + aColor = TRgb::Gray256(aColor.Gray256());
1.3321 + break;
1.3322 + case EColor16:
1.3323 + aColor = TRgb::Color16(aColor.Color16());
1.3324 + break;
1.3325 + case EColor256:
1.3326 + aColor = TRgb::Color256(aColor.Color256());
1.3327 + break;
1.3328 + case EColor4K:
1.3329 + aColor = TRgb::Color4K(aColor.Color4K());
1.3330 + break;
1.3331 + case EColor64K:
1.3332 + aColor = TRgb::Color64K(aColor.Color64K());
1.3333 + break;
1.3334 + case EColor16M:
1.3335 + aColor = TRgb::Color16M(aColor.Color16M());
1.3336 + break;
1.3337 + case EColor16MU:
1.3338 + aColor = TRgb::Color16MU(aColor.Color16MU());
1.3339 + break;
1.3340 + case EColor16MA:
1.3341 + aColor = TRgb::Color16MA(aColor.Color16MA());
1.3342 + break;
1.3343 + case EColor16MAP:
1.3344 + //do nothing, because TRGb is already unpremultiplied
1.3345 + break;
1.3346 + default:
1.3347 + break;
1.3348 + };
1.3349 + }
1.3350 +
1.3351 +void CTLowLevel::Normalize(TRgb& aColor,TRgb aDitherColors[4])
1.3352 + {
1.3353 + switch (iDispMode)
1.3354 + {
1.3355 + case EGray2:
1.3356 + FillArray(TRgb::Gray2(aColor.Gray2()),aDitherColors);
1.3357 + break;
1.3358 + case EGray4:
1.3359 + if (iUserDispMode == EGray2)
1.3360 + FillArray(TRgb::Gray2(aColor.Gray2()),aDitherColors);
1.3361 + else
1.3362 + {
1.3363 + TInt gray16 = aColor.Gray16();
1.3364 + aDitherColors[0] = TRgb::Gray4(ditherlutab[gray16][0]);
1.3365 + aDitherColors[1] = TRgb::Gray4(ditherlutab[gray16][1]);
1.3366 + aDitherColors[2] = TRgb::Gray4(ditherlutab[gray16][2]);
1.3367 + aDitherColors[3] = TRgb::Gray4(ditherlutab[gray16][3]);
1.3368 + }
1.3369 + break;
1.3370 + case EGray16:
1.3371 + if (iUserDispMode == EGray2)
1.3372 + FillArray(TRgb::Gray2(aColor.Gray2()),aDitherColors);
1.3373 + else if (iUserDispMode == EGray4)
1.3374 + {
1.3375 + TInt gray16 = aColor.Gray16();
1.3376 + aDitherColors[0] = TRgb::Gray4(ditherlutab[gray16][0]);
1.3377 + aDitherColors[1] = TRgb::Gray4(ditherlutab[gray16][1]);
1.3378 + aDitherColors[2] = TRgb::Gray4(ditherlutab[gray16][2]);
1.3379 + aDitherColors[3] = TRgb::Gray4(ditherlutab[gray16][3]);
1.3380 + }
1.3381 + else
1.3382 + FillArray(TRgb::Gray16(aColor.Gray16()),aDitherColors);
1.3383 + break;
1.3384 + case EGray256:
1.3385 + FillArray(TRgb::Gray256(aColor.Gray256()),aDitherColors);
1.3386 + break;
1.3387 + case EColor16:
1.3388 + FillArray(TRgb::Color16(aColor.Color16()),aDitherColors);
1.3389 + break;
1.3390 + case EColor256:
1.3391 + FillArray(TRgb::Color256(aColor.Color256()),aDitherColors);
1.3392 + break;
1.3393 + case EColor4K:
1.3394 + FillArray(TRgb::Color4K(aColor.Color4K()),aDitherColors);
1.3395 + break;
1.3396 + case EColor64K:
1.3397 + FillArray(TRgb::Color64K(aColor.Color64K()),aDitherColors);
1.3398 + break;
1.3399 + case EColor16M:
1.3400 + case EColor16MU:
1.3401 + case EColor16MA:
1.3402 + case EColor16MAP:
1.3403 + FillArray(aColor,aDitherColors);
1.3404 + break;
1.3405 + default:
1.3406 + break;
1.3407 + };
1.3408 + }
1.3409 +
1.3410 +void CTLowLevel::FillArray(TRgb aColor,TRgb aArray[4])
1.3411 + {
1.3412 + aArray[0] = aColor;
1.3413 + aArray[1] = aColor;
1.3414 + aArray[2] = aColor;
1.3415 + aArray[3] = aColor;
1.3416 + }
1.3417 +
1.3418 +
1.3419 +void CTLowLevel::PostBlendShadow(TUint32 &aPmaColor)
1.3420 + {
1.3421 + //this function should only be called for PMA colours
1.3422 + const TInt alpha = aPmaColor >> 24;
1.3423 + TUint32 value = aPmaColor & 0x00ffffff;
1.3424 +
1.3425 + if (iPostBlendShadow & CFbsDrawDevice::EFade)
1.3426 + {
1.3427 +#if defined(SYMBIAN_USE_FAST_FADING)
1.3428 + TUint32 fast_fade_offset = ((SYMBIAN_USE_FAST_FADING & 0xff) * alpha) >>8;
1.3429 + fast_fade_offset = fast_fade_offset | (fast_fade_offset << 8) | (fast_fade_offset <<16);
1.3430 + value = ((value >> 1) & ~0x00808080) + (fast_fade_offset);
1.3431 + value = value | (((TUint32)alpha)<<24);
1.3432 +#else
1.3433 + /*
1.3434 + here blackmap = 200,
1.3435 + whitemap = 100
1.3436 + iFadeMapFactor = aWhiteMap - aBlackMap + 1;
1.3437 + iFadeMapOffset = aBlackMap;
1.3438 + */
1.3439 +
1.3440 + const TInt fadeMapOffset = ((alpha * 0x7f) >> 8) & 0xff;
1.3441 + const TInt wordFadeMapOffset = ((fadeMapOffset) << 16) | (fadeMapOffset);
1.3442 + const TInt rb = ((((value & 0x00ff00ff) * 0x7f) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
1.3443 + const TInt g = ((((value & 0x0000ff00) * 0x7f) >> 16) + fadeMapOffset) << 8;
1.3444 + value = rb | g | (((TUint32)alpha)<<24);
1.3445 +#endif
1.3446 + }
1.3447 +
1.3448 + if (iPostBlendShadow & CFbsDrawDevice::EShadow)
1.3449 + {
1.3450 + TInt alpha = (aPmaColor>>24);
1.3451 + TInt red = (value>>16)&0xff;
1.3452 + TInt green = (value>>8)&0xff;
1.3453 + TInt blue = value &0xff;
1.3454 +
1.3455 + TInt shadow= (alpha*0x40)>>8;
1.3456 + red = Max(0,red-shadow);
1.3457 + green = Max (0,green-shadow);
1.3458 + blue = Max (0,blue-shadow);
1.3459 + value = (((TUint32)alpha)<<24)|(((TUint32)red)<<16)|(((TUint32)green)<<8)|((TUint32)blue);
1.3460 + }
1.3461 + aPmaColor = value;
1.3462 + }
1.3463 +
1.3464 +void CTLowLevel::Shadow(TRgb& aColor,TInt aShadowMode)
1.3465 + {
1.3466 + if (aShadowMode & 2)
1.3467 + {
1.3468 + switch (iDrawDevice->DisplayMode())
1.3469 + {
1.3470 + case EGray2:
1.3471 + aColor = TRgb::Gray256(FadeGray(aColor.Gray2() * 255));
1.3472 + break;
1.3473 + case EGray4:
1.3474 + case EGray16:
1.3475 + aColor = TRgb::Gray256(FadeGray(aColor.Gray16() * 17));
1.3476 + break;
1.3477 + case EGray256:
1.3478 + aColor = TRgb::Gray256(FadeGray(aColor.Gray256()));
1.3479 + break;
1.3480 + case EColor16:
1.3481 + aColor = FadeRgb(TRgb::Color16(aColor.Color16()));
1.3482 + break;
1.3483 + case EColor256:
1.3484 + aColor = FadeRgb(TRgb::Color256(aColor.Color256()));
1.3485 + break;
1.3486 + case EColor4K:
1.3487 + aColor = FadeRgb(TRgb::Color4K(aColor.Color4K()));
1.3488 + break;
1.3489 + case EColor64K:
1.3490 + aColor = FadeRgb(TRgb::Color64K(aColor.Color64K()),KFastFading && iUseFastFade);
1.3491 + break;
1.3492 + case EColor16M:
1.3493 + aColor = FadeRgb(TRgb::Color16M(aColor.Color16M()));
1.3494 + break;
1.3495 + case EColor16MU:
1.3496 + aColor = FadeRgb(TRgb::Color16MU(aColor.Color16MU()),KFastFading && iUseFastFade);
1.3497 + break;
1.3498 + case EColor16MA:
1.3499 + aColor = FadeRgb(TRgb::Color16MA(aColor.Color16MA()),KFastFading && iUseFastFade);
1.3500 + break;
1.3501 + case EColor16MAP:
1.3502 + aColor = FadeRgb(TRgb::Color16MAP(aColor.Color16MAP()),KFastFading && iUseFastFade);
1.3503 + break;
1.3504 + default:
1.3505 + break;
1.3506 + };
1.3507 + }
1.3508 +
1.3509 + if (aShadowMode & 1)
1.3510 + {
1.3511 + switch (iDrawDevice->DisplayMode())
1.3512 + {
1.3513 + case EGray2:
1.3514 + aColor = KRgbBlack;
1.3515 + break;
1.3516 + case EGray4:
1.3517 + case EGray16:
1.3518 + aColor = TRgb::Gray16(Max(0,aColor.Gray16()-5));
1.3519 + break;
1.3520 + case EGray256:
1.3521 + aColor = TRgb::Gray256(Max(0,aColor.Gray256()-85));
1.3522 + break;
1.3523 + case EColor16:
1.3524 + {
1.3525 + TInt color = aColor.Color16();
1.3526 + if (color == 15) color--;
1.3527 + else if (color == 14) color = 1;
1.3528 + else if (color > 7) color += 3;
1.3529 + else if (color > 4) color -= 3;
1.3530 + else color = 0;
1.3531 + aColor = TRgb::Color16(color);
1.3532 + }
1.3533 + break;
1.3534 + case EColor256:
1.3535 + {
1.3536 + aColor = TRgb::Color256(aColor.Color256());
1.3537 + TInt red = aColor.Red();
1.3538 + TInt green = aColor.Green();
1.3539 + TInt blue = aColor.Blue();
1.3540 + red = Max(0,red-0x33);
1.3541 + green = Max(0,green-0x33);
1.3542 + blue = Max(0,blue-0x33);
1.3543 + aColor = TRgb(red,green,blue);
1.3544 + }
1.3545 + break;
1.3546 + case EColor4K:
1.3547 + {
1.3548 + TInt color = aColor.Color4K();
1.3549 + TInt red = (color & 0xf00) >> 8;
1.3550 + TInt green = (color & 0x0f0) >> 4;
1.3551 + TInt blue = color & 0x00f;
1.3552 +
1.3553 + red = Max(0,red-5);
1.3554 + green = Max(0,green-5);
1.3555 + blue = Max(0,blue-5);
1.3556 +
1.3557 + aColor = TRgb::Color4K((red << 8) | (green << 4) | blue);
1.3558 + }
1.3559 + break;
1.3560 + case EColor64K:
1.3561 + {
1.3562 + TInt color = aColor.Color64K();
1.3563 + TInt red = (color & 0xf800) >> 11;
1.3564 + TInt green = (color & 0x07e0) >> 5;
1.3565 + TInt blue = color & 0x001f;
1.3566 +
1.3567 + red = Max(0,red-8);
1.3568 + green = Max(0,green-16);
1.3569 + blue = Max(0,blue-8);
1.3570 +
1.3571 + aColor = TRgb::Color64K((red << 11) | (green << 5) | blue);
1.3572 + }
1.3573 + break;
1.3574 + case EColor16M:
1.3575 + case EColor16MU:
1.3576 + case EColor16MA:
1.3577 + case EColor16MAP:
1.3578 + {
1.3579 + TInt red = aColor.Red();
1.3580 + TInt green = aColor.Green();
1.3581 + TInt blue = aColor.Blue();
1.3582 + red = Max(0,red-0x40);
1.3583 + green = Max(0,green-0x40);
1.3584 + blue = Max(0,blue-0x40);
1.3585 + aColor = TRgb(red,green,blue,aColor.Alpha());
1.3586 + }
1.3587 + break;
1.3588 + default:
1.3589 + break;
1.3590 + };
1.3591 + }
1.3592 + }
1.3593 +
1.3594 +void CTLowLevel::Blend(TUint8* aBuffer,TUint8* aBufferDest, TDisplayMode aDispMode)
1.3595 + {
1.3596 + TUint32* buffer = reinterpret_cast<TUint32*> (aBuffer);
1.3597 + TUint32* bufferDest = reinterpret_cast<TUint32*> (aBufferDest);
1.3598 + TInt mask = (*buffer & 0xff000000) >> 24;
1.3599 + TRgb rgbDest;
1.3600 +
1.3601 + switch(aDispMode)
1.3602 + {
1.3603 + case EColor16MU:
1.3604 + {
1.3605 + // src + ((255 - mask) * dest) / 255
1.3606 + if(mask!=255)
1.3607 + {
1.3608 + rgbDest=TRgb::Color16MU(*bufferDest);
1.3609 + if(mask)
1.3610 + {
1.3611 + TRgb rgbSrc=TRgb::Color16MU(*buffer);
1.3612 + rgbDest.SetRed(rgbSrc.Red() + ((255 - mask) * rgbDest.Red()) / 255);
1.3613 + rgbDest.SetGreen(rgbSrc.Green() + ((255 - mask) * rgbDest.Green()) / 255);
1.3614 + rgbDest.SetBlue(rgbSrc.Blue() + ((255 - mask) * rgbDest.Blue()) / 255);
1.3615 + }
1.3616 + *buffer=rgbDest.Internal();
1.3617 + }
1.3618 + }
1.3619 + break;
1.3620 + case EColor16MA:
1.3621 + {
1.3622 + // (mask * src + (255 - mask) * dest) / 255
1.3623 + if(mask!=255)
1.3624 + {
1.3625 + rgbDest=TRgb::Color16MA(*bufferDest);
1.3626 + if(mask)
1.3627 + {
1.3628 + TRgb rgbSrc=TRgb::Color16MA(*buffer);
1.3629 + rgbDest.SetRed((mask * rgbSrc.Red() + (255 - mask) * rgbDest.Red()) / 255);
1.3630 + rgbDest.SetGreen((mask * rgbSrc.Green() + (255 - mask) * rgbDest.Green()) / 255);
1.3631 + rgbDest.SetBlue((mask * rgbSrc.Blue() + (255 - mask) * rgbDest.Blue()) / 255);
1.3632 + }
1.3633 + *buffer=rgbDest.Internal();
1.3634 + }
1.3635 + }
1.3636 + break;
1.3637 + case EColor16MAP:
1.3638 + {
1.3639 + /*
1.3640 + * Blend function uses the Porter Duff composition equation
1.3641 + * This blends two pixels with alphas:
1.3642 + * Ar = As + Ad * (1 - As) (Blended Alpha)
1.3643 + * Cr = Cs + Cd(1 - As) (Blended Colour)
1.3644 + * Cr = Cs + Cd(255-As)/255 : for alpha 0-255
1.3645 + * where Ar = alpha result
1.3646 + * where Cr = colour result
1.3647 + * where Cs = source colour
1.3648 + * where Cd = destination colour
1.3649 + * The function assumes that the mask buffer is the alpha value of the source pixel.
1.3650 + */
1.3651 + if(mask!=255)
1.3652 + {
1.3653 + rgbDest=TRgb::Color16MA(*bufferDest);
1.3654 + if(mask)
1.3655 + {
1.3656 + TInt destAlpha = (*bufferDest & 0xff000000) >> 24;
1.3657 + TInt sourceAlpha = (*buffer & 0xff000000) >> 24;
1.3658 + TRgb rgbSrc;
1.3659 + rgbSrc.SetInternal(*buffer);
1.3660 + rgbDest.SetInternal(*bufferDest);
1.3661 + TInt resultAlpha = sourceAlpha +((255-sourceAlpha)*destAlpha)/255;
1.3662 + rgbDest.SetRed(rgbSrc.Red() + ((255 - sourceAlpha) * rgbDest.Red()) / 255);
1.3663 + rgbDest.SetGreen(rgbSrc.Green() + ((255 - sourceAlpha) * rgbDest.Green()) / 255);
1.3664 + rgbDest.SetBlue(rgbSrc.Blue() + ((255 - sourceAlpha) * rgbDest.Blue())/ 255);
1.3665 + rgbDest.SetAlpha(resultAlpha);
1.3666 + }
1.3667 + *buffer=rgbDest.Internal();
1.3668 + }
1.3669 + }
1.3670 + break;
1.3671 + default: break;
1.3672 + }
1.3673 + }
1.3674 +
1.3675 +void CTLowLevel::Shadow(TUint8* aBuffer,TInt aByteLength,TInt aShadowMode)
1.3676 + {
1.3677 + TUint8* buffer = aBuffer;
1.3678 + const TUint8* bufferLimit = aBuffer + aByteLength;
1.3679 +
1.3680 + if (aShadowMode & 2)
1.3681 + {
1.3682 + switch (iDrawDevice->DisplayMode())
1.3683 + {
1.3684 + case EGray2:
1.3685 + while (buffer < bufferLimit)
1.3686 + *buffer++ = 0xff;
1.3687 + break;
1.3688 + case EGray4:
1.3689 + while (buffer < bufferLimit)
1.3690 + {
1.3691 + TInt first = FadeGray((buffer[0] & 0x03) * 85) >> 6;
1.3692 + TInt second = FadeGray(((buffer[0] >> 2) & 0x03) * 85) >> 6;
1.3693 + TInt third = FadeGray(((buffer[0] >> 4) & 0x03) * 85) >> 6;
1.3694 + TInt fourth = FadeGray(((buffer[0] >> 6) & 0x03) * 85) >> 6;
1.3695 + *buffer++ = TUint8(first | (second << 2) | (third << 4) | (fourth << 6));
1.3696 + }
1.3697 + break;
1.3698 + case EGray16:
1.3699 + while (buffer < bufferLimit)
1.3700 + {
1.3701 + TInt low = FadeGray((buffer[0] & 0x0f) * 17) >> 4;
1.3702 + TInt high = FadeGray((buffer[0] >> 4) * 17) >> 4;
1.3703 + *buffer++ = TUint8((high << 4) | low);
1.3704 + }
1.3705 + break;
1.3706 + case EGray256:
1.3707 + while (buffer < bufferLimit)
1.3708 + *buffer++ = FadeGray(*buffer);
1.3709 + break;
1.3710 + case EColor16:
1.3711 + while (buffer < bufferLimit)
1.3712 + {
1.3713 + TInt low = FadeRgb(TRgb::Color16(buffer[0] & 0x0f)).Color16();
1.3714 + TInt high = FadeRgb(TRgb::Color16(buffer[0] >> 4)).Color16();
1.3715 + *buffer++ = TUint8((high << 4) | low);
1.3716 + }
1.3717 + break;
1.3718 + case EColor256:
1.3719 + while (buffer < bufferLimit)
1.3720 + *buffer++ = TUint8(FadeRgb(TRgb::Color256(buffer[0])).Color256());
1.3721 + break;
1.3722 + case EColor4K:
1.3723 + while (buffer < bufferLimit)
1.3724 + {
1.3725 + TInt color4K = FadeRgb(TRgb::Color4K(buffer[0] | (buffer[1] << 8))).Color4K();
1.3726 + buffer[0] = TUint8(color4K);
1.3727 + buffer[1] = TUint8(color4K >> 8);
1.3728 + buffer += 2;
1.3729 + }
1.3730 + break;
1.3731 + case EColor64K:
1.3732 + while (buffer < bufferLimit)
1.3733 + {
1.3734 + TInt color64K = FadeRgb(TRgb::Color64K(buffer[0] | (buffer[1] << 8)),ETrue).Color64K();
1.3735 + buffer[0] = TUint8(color64K);
1.3736 + buffer[1] = TUint8(color64K >> 8);
1.3737 + buffer += 2;
1.3738 + }
1.3739 + break;
1.3740 + case EColor16M:
1.3741 + {
1.3742 + while (buffer < bufferLimit)
1.3743 + *buffer++ = FadeGray(buffer[0]);
1.3744 + }
1.3745 + break;
1.3746 + case EColor16MU:
1.3747 + {
1.3748 + TUint32* buffer32 = reinterpret_cast <TUint32*> (buffer);
1.3749 + TUint32* bufferLimit32 = buffer32 + aByteLength / 4;
1.3750 + while (buffer32 < bufferLimit32)
1.3751 + {
1.3752 + // scanline buffer for 16MU driver is pre-multiplied
1.3753 + TRgb color = FadeRgb(TRgb::Color16MAP(*buffer32),ETrue);
1.3754 + // avoid rounding errors with EDrawModeAND etc.
1.3755 + *buffer32++ = color.Alpha() == 255 ? color.Internal() : color.Color16MAP();
1.3756 + }
1.3757 + }
1.3758 + break;
1.3759 + case EColor16MA:
1.3760 + {
1.3761 + TUint32* buffer32 = reinterpret_cast <TUint32*> (buffer);
1.3762 + TUint32* bufferLimit32 = buffer32 + aByteLength / 4;
1.3763 + while (buffer32 < bufferLimit32)
1.3764 + {
1.3765 + TRgb color = FadeRgb(TRgb::Color16MA(*buffer32),ETrue);
1.3766 + *buffer32++ = color.Color16MA();
1.3767 + }
1.3768 + }
1.3769 + break;
1.3770 + case EColor16MAP:
1.3771 + {
1.3772 + TUint32* buffer32 = reinterpret_cast <TUint32*> (buffer);
1.3773 + TUint32* bufferLimit32 = buffer32 + aByteLength / 4;
1.3774 + while (buffer32 < bufferLimit32)
1.3775 + {
1.3776 + TRgb color = FadeRgb(TRgb::Color16MAP(*buffer32),ETrue);
1.3777 + *buffer32++ = color.Color16MAP();
1.3778 + }
1.3779 + }
1.3780 + break;
1.3781 + default:
1.3782 + break;
1.3783 + }
1.3784 + }
1.3785 +
1.3786 + buffer = aBuffer;
1.3787 +
1.3788 + if (aShadowMode & 1)
1.3789 + {
1.3790 + switch (iDrawDevice->DisplayMode())
1.3791 + {
1.3792 + case EGray2:
1.3793 + while (buffer < bufferLimit)
1.3794 + {
1.3795 + *buffer++ = 0;
1.3796 + }
1.3797 + break;
1.3798 + case EGray4:
1.3799 + while (buffer < bufferLimit)
1.3800 + {
1.3801 + TInt first = buffer[0] & 0x03;
1.3802 + TInt second = buffer[0] & 0x0c;
1.3803 + TInt third = buffer[0] & 0x30;
1.3804 + TInt fourth = buffer[0] & 0xc0;
1.3805 + first = Max(0,first-1);
1.3806 + second = Max(0,second-4);
1.3807 + third = Max(0,third-16);
1.3808 + fourth = Max(0,fourth-64);
1.3809 + *buffer++ = TUint8(fourth | third | second | first);
1.3810 + }
1.3811 + break;
1.3812 + case EGray16:
1.3813 + while (buffer < bufferLimit)
1.3814 + {
1.3815 + TInt low = buffer[0] & 0x0f;
1.3816 + TInt high = buffer[0] >> 4;
1.3817 + low = Max(0,low-5);
1.3818 + high = Max(0,high-5);
1.3819 + *buffer++ = TUint8((high << 4) | low);
1.3820 + }
1.3821 + break;
1.3822 + case EGray256:
1.3823 + while (buffer < bufferLimit)
1.3824 + {
1.3825 + buffer[0] = TUint8(Max(0,buffer[0]-85));
1.3826 + buffer++;
1.3827 + }
1.3828 + break;
1.3829 + case EColor16:
1.3830 + while (buffer < bufferLimit)
1.3831 + {
1.3832 + TInt low = buffer[0] & 0x0f;
1.3833 + TInt high = buffer[0] >> 4;
1.3834 + if (low == 15) low = 14;
1.3835 + else if (low == 14) low = 1;
1.3836 + else if (low >= 11) low = 0;
1.3837 + else if (low >= 8) low += 3;
1.3838 + else if (low >= 5) low -= 3;
1.3839 + else low = 0;
1.3840 + if (high == 15) high = 14;
1.3841 + else if (high == 14) high = 1;
1.3842 + else if (high >= 11) high = 0;
1.3843 + else if (high >= 8) high += 3;
1.3844 + else if (high >= 5) high -= 3;
1.3845 + else high = 0;
1.3846 + *buffer++ = TUint8((high << 4) | low);
1.3847 + }
1.3848 + break;
1.3849 + case EColor256:
1.3850 + while (buffer < bufferLimit)
1.3851 + {
1.3852 + TRgb color(TRgb::Color256(buffer[0]));
1.3853 + TInt red = color.Red();
1.3854 + TInt green = color.Green();
1.3855 + TInt blue = color.Blue();
1.3856 + red = Max(0,red-0x33);
1.3857 + green = Max(0,green-0x33);
1.3858 + blue = Max(0,blue-0x33);
1.3859 + *buffer++ = TUint8(TRgb(red,green,blue).Color256());
1.3860 + }
1.3861 + break;
1.3862 + case EColor4K:
1.3863 + while (buffer < bufferLimit)
1.3864 + {
1.3865 + TInt data = (buffer[1] << 8) | buffer[0];
1.3866 + TInt red = (data & 0xf00) >> 8;
1.3867 + TInt green = (data & 0x0f0) >> 4;
1.3868 + TInt blue = data & 0x00f;
1.3869 + red = Max(0,red-5);
1.3870 + green = Max(0,green-5);
1.3871 + blue = Max(0,blue-5);
1.3872 + data = (red << 8) | (green << 4) | blue;
1.3873 + buffer[0] = TUint8(data);
1.3874 + buffer[1] = TUint8(data >> 8);
1.3875 + buffer += 2;
1.3876 + }
1.3877 + break;
1.3878 + case EColor64K:
1.3879 + while (buffer < bufferLimit)
1.3880 + {
1.3881 + TInt data = (buffer[1] << 8) | buffer[0];
1.3882 + TInt red = (data & 0xf800) >> 11;
1.3883 + TInt green = (data & 0x07e0) >> 5;
1.3884 + TInt blue = data & 0x001f;
1.3885 + red = Max(0,red-8);
1.3886 + green = Max(0,green-16);
1.3887 + blue = Max(0,blue-8);
1.3888 + data = (red << 11) | (green << 5) | blue;
1.3889 + buffer[0] = TUint8(data);
1.3890 + buffer[1] = TUint8(data >> 8);
1.3891 + buffer += 2;
1.3892 + }
1.3893 + break;
1.3894 + case EColor16M:
1.3895 + while (buffer < bufferLimit)
1.3896 + {
1.3897 + buffer[0] = TUint8(Max(0,buffer[0]-0x40));
1.3898 + buffer++;
1.3899 + }
1.3900 + break;
1.3901 + case EColor16MU:
1.3902 + {
1.3903 + TUint32* buffer32 = reinterpret_cast <TUint32*> (buffer);
1.3904 + TUint32* bufferLimit32 = buffer32 + aByteLength / 4;
1.3905 + while (buffer32 < bufferLimit32)
1.3906 + {
1.3907 + // scanline buffer for 16MU driver is pre-multiplied
1.3908 + TRgb color = TRgb::Color16MAP(*buffer32);
1.3909 + color = TRgb(Max(0,color.Red()-0x40),Max(0,color.Green()-0x40),Max(0,color.Blue()-0x40), color.Alpha());
1.3910 + // avoid rounding errors with EDrawModeAND etc.
1.3911 + *buffer32++ = color.Alpha() == 255 ? color.Internal() : color.Color16MAP();
1.3912 + }
1.3913 + }
1.3914 + break;
1.3915 + case EColor16MA:
1.3916 + {
1.3917 + TUint32* buffer32 = reinterpret_cast <TUint32*> (buffer);
1.3918 + TUint32* bufferLimit32 = buffer32 + aByteLength / 4;
1.3919 + while (buffer32 < bufferLimit32)
1.3920 + {
1.3921 + TRgb color = TRgb::Color16MA(*buffer32);
1.3922 + color = TRgb(Max(0,color.Red()-0x40),Max(0,color.Green()-0x40),Max(0,color.Blue()-0x40), color.Alpha());
1.3923 + *buffer32++ = color.Color16MA();
1.3924 + }
1.3925 + }
1.3926 + break;
1.3927 + case EColor16MAP:
1.3928 + {
1.3929 + TUint32* buffer32 = reinterpret_cast <TUint32*> (buffer);
1.3930 + TUint32* bufferLimit32 = buffer32 + aByteLength / 4;
1.3931 + while (buffer32 < bufferLimit32)
1.3932 + {
1.3933 + TRgb color = TRgb::Color16MAP(*buffer32);
1.3934 + color = TRgb(Max(0,color.Red()-0x40),Max(0,color.Green()-0x40),Max(0,color.Blue()-0x40), color.Alpha());
1.3935 + *buffer32++ = color.Color16MAP();
1.3936 + }
1.3937 + }
1.3938 + break;
1.3939 + default:
1.3940 + break;
1.3941 + }
1.3942 + }
1.3943 + }
1.3944 +
1.3945 +TUint8 CTLowLevel::FadeGray(TInt aGray256)
1.3946 + {
1.3947 + return TUint8((aGray256 >> 1) + 128);
1.3948 + }
1.3949 +
1.3950 +/**
1.3951 +A test code function for Fading colour values.
1.3952 +@param aColor Colour value for which faded colour is needed.
1.3953 +@param aFastFade Used to check whether Fast Fading method is required or not.
1.3954 + aFastFade flag should be true only when there is a corresponding Fast Fading
1.3955 + implementation in product code and the fading method uses the Fast Fading method.
1.3956 +@return TRgb Faded colour value.
1.3957 +*/
1.3958 +TRgb CTLowLevel::FadeRgb(TRgb aColor, TBool aFastFade/*=EFalse*/)
1.3959 + {
1.3960 + if(aFastFade)
1.3961 + {
1.3962 +#if defined(SYMBIAN_USE_FAST_FADING)
1.3963 + TUint32 value = ((aColor.Internal() >> 1) & ~0x00808080) + SYMBIAN_USE_FAST_FADING;
1.3964 + TInt alpha = aColor.Alpha();
1.3965 + return TRgb(value, alpha);
1.3966 +#endif
1.3967 + }
1.3968 + TInt red = (aColor.Red() >> 1) + 128;
1.3969 + TInt green = (aColor.Green() >> 1) + 128;
1.3970 + TInt blue = (aColor.Blue() >> 1) + 128;
1.3971 + TInt alpha = aColor.Alpha();
1.3972 + return TRgb(red,green,blue,alpha);
1.3973 + }
1.3974 +
1.3975 +TColorConvertor& CTLowLevel::ColorConvertor(TDisplayMode aDisplayMode)
1.3976 + {
1.3977 + return *iColorConvertor[aDisplayMode];
1.3978 + }
1.3979 +
1.3980 +void CTLowLevel::Report()
1.3981 + {
1.3982 + INFO_PRINTF4(_L("Test %d: %d/%d"),iTestNo,iReportIteration,iTotalReportIterations);
1.3983 + if (iReportIteration < iTotalReportIterations)
1.3984 + iReportIteration++;
1.3985 + }
1.3986 +
1.3987 +inline TBool CTLowLevel::Check(TBool aValue)
1.3988 + {
1.3989 + if (iLastFailTestNo!=iIteration)
1.3990 + {
1.3991 + if (!aValue)
1.3992 + {
1.3993 + _LIT(KLog,"Test %d, iteration %d failed iDispMode %d iUserDispMode %d iOrientation %d");
1.3994 + INFO_PRINTF6(KLog,iTestNo,iIteration,iDispMode,iUserDispMode,iOrientation);
1.3995 + iLastFailTestNo=iIteration;
1.3996 + }
1.3997 + TEST(aValue);
1.3998 + }
1.3999 + return !aValue;
1.4000 + }
1.4001 +
1.4002 +//-----------
1.4003 +CTLowLevel1::CTLowLevel1(CTestStep* aStep):
1.4004 + CTLowLevel(aStep)
1.4005 + {
1.4006 + iOrientation = CFbsDrawDevice::EOrientationRotated180;
1.4007 + iOrientationEnd = CFbsDrawDevice::EOrientationRotated270;
1.4008 + }
1.4009 +
1.4010 +void CTLowLevel1::RunTestCaseL(TInt /*aCurTestCase*/)
1.4011 + {
1.4012 + if(iOrientation <= iOrientationEnd)
1.4013 + {
1.4014 + INFO_PRINTF2(_L("Screen device : %S"), &DisplayModeNames1[iCurScreenDeviceModeIndex]);
1.4015 + TDisplayMode display = TestDisplayMode1[iCurScreenDeviceModeIndex++];
1.4016 +/**
1.4017 + @SYMTestCaseID GRAPHICS-SCREENDRIVER-0018
1.4018 +*/
1.4019 + ((CTLowLevelStep*)iStep)->SetTestStepID(_L("GRAPHICS-SCREENDRIVER-0018"));
1.4020 + TestScreenDrawL(display);
1.4021 + if(iCurScreenDeviceModeIndex >= KNumberDisplayModes1)
1.4022 + {
1.4023 + iCurScreenDeviceModeIndex = 0;
1.4024 + iOrientation ++;
1.4025 + }
1.4026 + ((CTLowLevelStep*)iStep)->RecordTestResultL();
1.4027 + }
1.4028 + else
1.4029 + {
1.4030 + ((CTLowLevelStep*)iStep)->CloseTMSGraphicsStep();
1.4031 + TestComplete();
1.4032 + }
1.4033 + }
1.4034 +
1.4035 +//--------------
1.4036 +__CONSTRUCT_STEP__(LowLevel)
1.4037 +
1.4038 +__CONSTRUCT_STEP__(LowLevel1)