1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tdynamicres/src/wsdynamicresbase.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,440 @@
1.4 +// Copyright (c) 2008-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 <w32std.h>
1.20 +#include "wsdynamicresbase.h"
1.21 +#include "teflogextensions.h"
1.22 +#include "globalsettings.h"
1.23 +#include <bitdraw.h>
1.24 +#include <bitdrawinterfaceid.h>
1.25 +#include <bitdrawsurface.h>
1.26 +#include <graphics/surfaceconfiguration.h>
1.27 +#include "regionextend.h"
1.28 +
1.29 +
1.30 +#if defined(__X86GCC__)
1.31 +extern "C" TInt atexit(void (*function)(void))
1.32 + {
1.33 + return KErrNone;
1.34 + }
1.35 +#endif
1.36 +
1.37 +CWsDynamicResBase::CWsDynamicResBase():
1.38 + iUtility(this)
1.39 + {
1.40 + }
1.41 +
1.42 +CWsDynamicResBase::~CWsDynamicResBase()
1.43 + {
1.44 + }
1.45 +
1.46 +/**
1.47 +Common set up code for all tests.
1.48 +
1.49 +Creates the session and window group for further windows, plus a simple white
1.50 +background to obscure any unwanted stuff behind the test. Sets up the surface
1.51 +update session and surface manager, to work with surfaces. Creates a screen
1.52 +device for use in the tests.
1.53 +*/
1.54 +void CWsDynamicResBase::SetupL()
1.55 + {
1.56 + SetupL(EFalse);
1.57 + }
1.58 +void CWsDynamicResBase::SetupL(TBool aUseOtherScreenForInfo)
1.59 + {
1.60 + CWsDynamicResWinBase::SetupL(aUseOtherScreenForInfo);
1.61 +
1.62 +
1.63 +//clean-up if previous test abended
1.64 + if (PostTestCleanupInstance().iSharedUtility)
1.65 + {
1.66 +//Temp removed - may be causing ONB fails!
1.67 +// if (PostTestCleanupInstance().iSharedUtility->DestroyAll())
1.68 +// {
1.69 +// INFO_PRINTF1(_L("Destroyed some surfaces from previous test."));
1.70 +//
1.71 +// }
1.72 + }
1.73 + if (!PostTestCleanupInstance().iCleanedUpOnExit)
1.74 + PostTestCleanupInstance().iCleanedUpOnExit=EFalse;
1.75 +
1.76 + if (!GCEIsSupported())
1.77 + {
1.78 + INFO_PRINTF1(_L("Some Setup skipped: GCE support is not loaded"));
1.79 + return;
1.80 + }
1.81 +
1.82 + TRAPD(err_FailedToCreateSurfaceUtility, iUtility = CSurfaceUtility::NewL( PostTestCleanupInstance().iSharedUtility));
1.83 + ASSERT_EQUALS(err_FailedToCreateSurfaceUtility,KErrNone);
1.84 +
1.85 +
1.86 + }
1.87 +
1.88 +/**
1.89 +Common tear down code for all tests.
1.90 +
1.91 +Windows, group and session created are closed. Screen device is destroyed.
1.92 +Surfaces, manager and update session are closed.
1.93 +*/
1.94 +void CWsDynamicResBase::TearDownL()
1.95 + {
1.96 + CWsDynamicResWinBase::TearDownL();
1.97 + delete iUtility();
1.98 + PostTestCleanupInstance().iCleanedUpOnExit=ETrue;
1.99 + //Pause(1000);
1.100 + }
1.101 +/**
1.102 + * Note that this is not the ideal mechanism.
1.103 + * A derived class may thinks its TearDown is safe to do from delete, but in the class it is derived from it may not be safe
1.104 + **/
1.105 +void CWsDynamicResBase::TearDownFromDeleteL()
1.106 + {
1.107 + CWsDynamicResBase::TearDownL();
1.108 + }
1.109 +
1.110 +//Allocating an instance of surface utility here means all test code instances will share the same instance of the utility class.
1.111 +// Owns the singleton
1.112 +/*static*/ const CWsDynamicResBase::TPostTestCleanup& CWsDynamicResBase::PostTestCleanupInstance()
1.113 + {
1.114 + static
1.115 + class RPostTestCleanup:public TPostTestCleanup
1.116 + {
1.117 + public:
1.118 + RPostTestCleanup()
1.119 + {
1.120 + iSharedUtility=NULL;
1.121 + iCleanedUpOnExit=ETrue;
1.122 + }
1.123 + ~RPostTestCleanup()
1.124 + {
1.125 + // I want to cleanly release the surface utility, but at this point the threads have already been pulled down!
1.126 + // if (iSharedUtility)
1.127 + // delete iSharedUtility;
1.128 + iSharedUtility=NULL; //avoid phoenix behaviour
1.129 + }
1.130 + } staticInstance;
1.131 + return staticInstance;
1.132 + }
1.133 +
1.134 +void CWsDynamicResBase::TPostTestCleanup::CreateSharedUtilityL()const
1.135 + {
1.136 + if (iSharedUtility==NULL)
1.137 + iSharedUtility=CSurfaceUtility::NewL();
1.138 + }
1.139 +
1.140 +/**
1.141 +Pause for the given number of milliseconds.
1.142 +
1.143 +@param aMilliseconds Time to wait in milliseconds.
1.144 +*/
1.145 +void CWsDynamicResBase::Pause(TInt aMilliseconds)
1.146 + {
1.147 + User::After(TTimeIntervalMicroSeconds32(aMilliseconds * 1000));
1.148 + }
1.149 +
1.150 +void CWsDynamicResBase::LargerTestWindow(TInt aPercentOfBack)
1.151 + {
1.152 + TRect newPos=iTestPos;
1.153 + TSize backSize=iTestPos.Size();
1.154 + newPos.Grow((aPercentOfBack-100)*backSize.iWidth/200,(aPercentOfBack-100)*backSize.iHeight/200);
1.155 + iCenteredFrontWinRect=newPos;
1.156 + if (iTestFront.WsHandle())
1.157 + {
1.158 + iTestFront.SetExtent(newPos.iTl,newPos.Size());
1.159 + }
1.160 +
1.161 + }
1.162 +
1.163 +
1.164 +void CWsDynamicResBase::MakeExtraChildWindowL(const RWindowBase& aFromParent,TRect aChildRect,TRgb aChildColor)
1.165 + {
1.166 + ASSERT(aFromParent.WsHandle());
1.167 + if (!iTestSecondChild.WsHandle())
1.168 + {
1.169 + iTestSecondChild=RWindow(iSession);
1.170 + ASSERT_EQUALS_X(iTestSecondChild.Construct(aFromParent, ++iWindowHandle), KErrNone);
1.171 + iTestSecondChild.SetRequiredDisplayMode(iDisplayMode);
1.172 + }
1.173 + iTestSecondChild.SetBackgroundColor(aChildColor);
1.174 + iTestSecondChild.SetExtent(aChildRect.iTl,aChildRect.Size());
1.175 + iTestSecondChild.Activate();
1.176 + iTestSecondChild.BeginRedraw();
1.177 + iGc->Activate(iCompare);
1.178 + iGc->SetBrushColor(iBlue);
1.179 + iGc->Clear();
1.180 + iGc->Deactivate();
1.181 + iTestSecondChild.EndRedraw();
1.182 + iTestSecondChild.SetVisible(ETrue);
1.183 + }
1.184 +
1.185 +CWsDynamicResBase::LoopingGcPtr CWsDynamicResBase::LoopBeginActivateWithWipe(const TRegion& aRegion,RWindow& aWin,TRgb aColor)
1.186 + {
1.187 + InvalidateRegion(aRegion,aWin);
1.188 + return LoopingGcPtr(aRegion,aWin,aColor,GcForWindow(aWin));
1.189 + }
1.190 +
1.191 +//This gets called each itteration of the while loop, and is used to step the rectangle count!
1.192 +void CWsDynamicResBase::LoopingGcPtr::operator ++()
1.193 + {
1.194 + iPass++;
1.195 + if (iPass<iRegion.Count())
1.196 + { //Invalidate all the rectangles in the region
1.197 + iWin.BeginRedraw(iRegion[iPass]);
1.198 + CWsDynamicResWinBase::ActivateWithWipe(iGc,iWin,iColor);
1.199 +// return true;
1.200 + }
1.201 + else
1.202 + {
1.203 + iGc=NULL;
1.204 +// return false;
1.205 + }
1.206 + }
1.207 +
1.208 +CWindowGc* CWsDynamicResBase::BeginActivateWithWipe(TBool aInvalidate,RWindow& aWin,TRgb aColor)
1.209 + {
1.210 + return CWsDynamicResWinBase::BeginActivateWithWipe(aInvalidate,aWin,aColor);
1.211 + }
1.212 +
1.213 +CWindowGc* CWsDynamicResBase::BeginActivateWithWipe(TBool aInvalidate,TRect aRect,RWindow& aWin,TRgb aColor)
1.214 + {
1.215 + return CWsDynamicResWinBase::BeginActivateWithWipe(aInvalidate,aRect,aWin,aColor);
1.216 + }
1.217 +
1.218 +CWindowGc* CWsDynamicResBase::BeginActivateWithWipe(const TRegion& aRegion,RWindow& aWin,TRgb aColor)
1.219 + {
1.220 + return CWsDynamicResWinBase::BeginActivateWithWipe(aRegion,aWin,aColor);
1.221 + }
1.222 +
1.223 +/**
1.224 + * Generates a valid surfaceID for the current display mode.
1.225 + * This is then used in negative testing.
1.226 + *
1.227 + *
1.228 + **/
1.229 +void CWsDynamicResBase::UISurfaceL(TSurfaceId& aSurfaceId) const
1.230 + {
1.231 + CFbsDrawDevice* screenDevice=NULL;
1.232 + TDisplayMode displayMode=iScreenDevice->DisplayMode();
1.233 + screenDevice = CFbsDrawDevice::NewScreenDeviceL(TGlobalSettings::Instance().iScreen, displayMode);
1.234 + CleanupStack::PushL(screenDevice);
1.235 + TAny* p=NULL;
1.236 + User::LeaveIfError(screenDevice->GetInterface(KSurfaceInterfaceID, p));
1.237 + MSurfaceId* uiSurface = static_cast<MSurfaceId*>(p);
1.238 + uiSurface->GetSurface(aSurfaceId);
1.239 + CleanupStack::PopAndDestroy(screenDevice);
1.240 + }
1.241 +
1.242 +/**
1.243 +Common set up code for creating a surface based window.
1.244 +
1.245 +Given window and surface objects and a color: creates the window and surface,
1.246 +sets the window to a default size (the same as the surface), sets the background
1.247 +to the bitwise inverse of the given color, sets the surface as the background,
1.248 +fills the surface with the color and completes a redraw to prevent an event.
1.249 +
1.250 +@param aWindow The window object, connected to a session.
1.251 +@param aSurface The surface object, to be initialized.
1.252 +@param aColor The color to fill the surface with.
1.253 +*/
1.254 +void CWsDynamicResBase::CommonSurfaceWindowSetupL(RWindow& aWindow, TSurfaceId& aSurface, const TRgb& aColor)
1.255 + {
1.256 + TInt err = KErrNone;
1.257 +
1.258 + TRAP(err, aSurface = iUtility->CreateSurfaceL(TSize(KSurfaceWidth, KSurfaceHeight),
1.259 + KSurfaceFormat, KSurfaceWidth * KBytesPerPixel));
1.260 + PRINT_ON_ERROR2_L(err, _L("Failed to create surface: %d"), err);
1.261 + ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone);
1.262 +
1.263 + aWindow.SetRequiredDisplayMode(iDisplayMode);
1.264 + aWindow.SetExtent(TPoint(0, 0), TSize(KSurfaceWidth, KSurfaceHeight));
1.265 + aWindow.SetBackgroundColor(TRgb(aColor.Value() ^ 0xFFFFFF));
1.266 +
1.267 + ASSERT_EQUALS_X(aWindow.SetBackgroundSurface(aSurface), KErrNone);
1.268 +
1.269 + TRAP(err, iUtility->FillSurfaceL(aSurface, aColor));
1.270 + PRINT_ON_ERROR2_L(err, _L("Failed to fill surface: %d"), err);
1.271 + DrawUIContent(aWindow);
1.272 + }
1.273 +
1.274 +/**
1.275 +Common set up code for resizing tests.
1.276 +
1.277 +Similar to the common surface window code, but filling the surface with a grid
1.278 +instead of a solid color. The grid lines are always black. Also, the background
1.279 +color is always blue.
1.280 +*/
1.281 +void CWsDynamicResBase::ResizeTestCommonSetupL(RWindow& aWindow, const TRgb& aColor)
1.282 + {
1.283 + // Session and group created in SetUpL()
1.284 +
1.285 + TSurfaceId surface;
1.286 + TInt err = KErrNone;
1.287 +
1.288 + TRAP(err, surface = iUtility->CreateSurfaceL(TSize(KSurfaceWidth, KSurfaceHeight),
1.289 + KSurfaceFormat, KSurfaceWidth * KBytesPerPixel));
1.290 + PRINT_ON_ERROR2_L(err, _L("Failed to create surface: %d"), err);
1.291 +
1.292 + ASSERT_EQUALS_X(aWindow.Construct(iGroup, ++iWindowHandle), KErrNone);
1.293 +
1.294 + aWindow.SetRequiredDisplayMode(iDisplayMode);
1.295 + aWindow.SetExtent(TPoint(0, 0), TSize(KSurfaceWidth, KSurfaceHeight));
1.296 + aWindow.SetBackgroundColor(iBlue);
1.297 + ASSERT_EQUALS_X(aWindow.SetBackgroundSurface(surface), KErrNone);
1.298 +
1.299 + TRAP(err, iUtility->GridFillSurfaceL(surface, aColor, TRgb(0)));
1.300 + PRINT_ON_ERROR2_L(err, _L("Failed to grid fill surface: %d"), err);
1.301 + DrawUIContent(aWindow);
1.302 + }
1.303 +
1.304 +CFbsBitmap* CWsDynamicResBase::RotateBitmapLC(const CFbsBitmap* aSrcBitmap)
1.305 + {
1.306 + CFbsBitmap* rv=new CFbsBitmap;
1.307 + CleanupStack::PushL(rv);
1.308 + TSize srcSize=aSrcBitmap->SizeInPixels();
1.309 + rv->Create(TSize(srcSize.iHeight,srcSize.iWidth),EColor16MA);
1.310 + TRgb* linestore=new TRgb[srcSize.iHeight];
1.311 + TPtr8 buff((unsigned char*)linestore,srcSize.iHeight*sizeof(TRgb),srcSize.iHeight*sizeof(TRgb));
1.312 + for (TInt col=0;col<aSrcBitmap->SizeInPixels().iWidth;col++)
1.313 + {
1.314 + for (TInt row=0,brow=srcSize.iHeight-1;row<srcSize.iHeight;row++,brow--)
1.315 + {
1.316 + aSrcBitmap->GetPixel(linestore[row],TPoint(col,brow));
1.317 + }
1.318 + rv->SetScanLine(buff,col);
1.319 + }
1.320 + delete[] linestore;
1.321 + return rv;
1.322 + }
1.323 +
1.324 +
1.325 +//
1.326 +//
1.327 +//
1.328 +// Pattern checking. Is a given pattern still present?
1.329 +// To make life interesting, the pattern is stored backwards!
1.330 +// The pattern is fibonnacci sequence masked to byte:
1.331 +// 1 2 3 5 8 13 21 34 55 89 144 233 121
1.332 +// 98 219 61 24 85 109 194 47 241 32 17 49 66
1.333 +// 115 181 40 221 5 226 231 201 176 121 41 162
1.334 +//
1.335 +//
1.336 +void Pattern::Fill(void* aTrg,TInt aOffset,TInt aLength)
1.337 + {
1.338 + unsigned char* ptr=(unsigned char*)aTrg;
1.339 + TInt a=0;
1.340 + TInt b=1;
1.341 + while (--aLength)
1.342 + {
1.343 + TInt c=a+b;
1.344 + *(ptr+aOffset+aLength)=c&0xff;
1.345 + a=b;
1.346 + b=c;
1.347 + }
1.348 + }
1.349 +TBool Pattern::Check(void* aTrg,TInt aOffset,TInt aLength)
1.350 + {
1.351 + unsigned char* ptr=(unsigned char*)aTrg;
1.352 + TInt a=0;
1.353 + TInt b=1;
1.354 + while (--aLength)
1.355 + {
1.356 + TInt c=a+b;
1.357 + if (*(ptr+aOffset+aLength)!=c&0xff)
1.358 + return EFalse;
1.359 + a=b;
1.360 + b=c;
1.361 + }
1.362 + return ETrue;
1.363 + }
1.364 +TBool Pattern::CheckVal(void* aTrg,TInt aOffset,TInt aLength,char val)
1.365 + {
1.366 + unsigned char* ptr=(unsigned char*)aTrg;
1.367 + while (--aLength)
1.368 + {
1.369 + if (*(ptr+aOffset+aLength)!=val&0xff)
1.370 + return EFalse;
1.371 + }
1.372 + return ETrue;
1.373 + }
1.374 +
1.375 +//I have removed these only because they use TRegionExtend
1.376 +//
1.377 +//TInt CWsDynamicResBase::RegionDiffForUiLayer(TInt aUiLayer)
1.378 +// {
1.379 +// EWsDebugGetUILayerConfig, //return: TSurfaceConfig //Index UI layer via EWsDebugArgLayerMask
1.380 +// EWsDebugGetUILayerBase, //return: TRect[]
1.381 +//
1.382 +// RRegion layerRegion;
1.383 +// TInt layerRegionLen=iSession.DebugInfo(EWsDebugGetUILayerBase,iSession.ObjInd(0,aUiLayer),layerRegion);
1.384 +// if (layerRegionLen==KErrCancel)
1.385 +// return TRegionExtend::EExact;
1.386 +// ASSERT_TRUE(layerRegionLen>=0);
1.387 +// TBuf8<sizeof(TSurfaceConfiguration)> configBuf(sizeof(TSurfaceConfiguration));
1.388 +// const TSurfaceConfiguration* config;
1.389 +// TInt configLen=iSession.DebugInfo(EWsDebugGetUILayerConfig,iSession.ObjInd(0,aUiLayer),configBuf,config);
1.390 +// ASSERT_TRUE(configLen>=0);
1.391 +// TRect layerExtent;
1.392 +// config->GetExtent(layerExtent);
1.393 +// TInt retVal=TRegionExtend::Cast(layerRegion).TestDifference(layerExtent.Size());
1.394 +// layerRegion.Close();
1.395 +// return retVal;
1.396 +// }
1.397 +//CWsDynamicResBase::FastPathMode CWsDynamicResBase::DeduceUiFastPathMode()
1.398 +// {
1.399 +// TInt blendedRegionState=RegionDiffForUiLayer(0);
1.400 +// TInt opaqueRegionState=RegionDiffForUiLayer(1);
1.401 +// if (blendedRegionState&TRegionExtend::ENoIntersect)
1.402 +// {
1.403 +// if (opaqueRegionState&TRegionExtend::ENoIntersect)
1.404 +// {
1.405 +// return EFpExternalOpaque; //fullscreen fast-path external surface
1.406 +// }
1.407 +// else
1.408 +// if (opaqueRegionState&TRegionExtend::EAdd)
1.409 +// {
1.410 +// return (FastPathMode)(EFpUiOpaque|EFpUiRegions); //windowed max-opt no blending
1.411 +// }
1.412 +// else
1.413 +// {
1.414 +// return EFpUiOpaque; //full-screen fastpath
1.415 +// }
1.416 +// }
1.417 +// else
1.418 +// {
1.419 +// if (opaqueRegionState&TRegionExtend::ENoIntersect)
1.420 +// {
1.421 +// if (blendedRegionState&TRegionExtend::EAdd)
1.422 +// {
1.423 +// return (FastPathMode)(EFpUiBlended|EFpUiRegions); //windowed max-opt no opaque
1.424 +// }
1.425 +// else
1.426 +// {
1.427 +// return (EFpUiBlended); //full-screen blended
1.428 +// }
1.429 +// }
1.430 +// else
1.431 +// {
1.432 +// if ((blendedRegionState|opaqueRegionState)&TRegionExtend::EAdd)
1.433 +// {
1.434 +// return (FastPathMode)(EFpUiComplex|EFpUiRegions); //moxed blending, opaque and external max optimisation
1.435 +// }
1.436 +// else
1.437 +// {
1.438 +// return EFpUiComplex; //Error! blend and opaque both enabled and full-screen!
1.439 +// }
1.440 +// }
1.441 +//
1.442 +// }
1.443 +// }