1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoappwindow.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,497 @@
1.4 +// Copyright (c) 2007-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 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include "t_pseudoappwindow.h"
1.26 +#include "t_winutils.h"
1.27 +
1.28 +EXPORT_C CTestWindow::CTestWindow(TInt aScreenNo, TDisplayMode aMode)
1.29 + {
1.30 + RDebug::Print(_L("Creating CTestWindow class\n"));
1.31 + TRAPD(err, ConstructL(aScreenNo, aMode));
1.32 + if(err)
1.33 + {
1.34 + RDebug::Print(_L("CTestWindow::ConstructL() leaves with error %d\n"), err);
1.35 + User::Exit(0);
1.36 + }
1.37 + }
1.38 +
1.39 +CTestWindow::~CTestWindow()
1.40 + {
1.41 + if(iScreen)
1.42 + {
1.43 + delete iScreen;
1.44 + }
1.45 +
1.46 + if(iWindowGc)
1.47 + {
1.48 + delete iWindowGc;
1.49 + }
1.50 +
1.51 + iSession.Close();
1.52 + }
1.53 +
1.54 +EXPORT_C void CTestWindow::ConstructL(TInt aScreenNo, TDisplayMode aMode)
1.55 + {
1.56 + RDebug::Print(_L("Constructing CTestWindow class\n"));
1.57 + User::LeaveIfError(iSession.Connect());
1.58 +
1.59 + RDebug::Print(_L("Create CWsScreenDevice\n"));
1.60 + iScreen = new(ELeave) CWsScreenDevice(iSession);
1.61 + User::LeaveIfError(iScreen->Construct(aScreenNo));
1.62 +
1.63 + RDebug::Print(_L("Create RWindowGroup\n"));
1.64 + iGroup = RWindowGroup(iSession);
1.65 +
1.66 + User::LeaveIfError(iGroup.Construct(8970 + aScreenNo, ETrue));
1.67 +
1.68 + RDebug::Print(_L("Create Window\n"));
1.69 + iWindow = RWindow(iSession);
1.70 + User::LeaveIfError(iWindow.Construct((RWindowTreeNode)iGroup,(TUint32)this));
1.71 +
1.72 + RDebug::Print(_L("Create CWindowGc\n"));
1.73 + iWindowGc = new (ELeave) CWindowGc(iScreen);
1.74 + User::LeaveIfError(iWindowGc->Construct());
1.75 +
1.76 + TInt ret = iWindow.SetRequiredDisplayMode(aMode);
1.77 + RDebug::Print(_L("Window display mode set to %d\n"), ret);
1.78 +
1.79 + iMode = aMode;
1.80 + iWindow.Activate();
1.81 + }
1.82 +
1.83 +EXPORT_C void CTestWindow::Rotate(TSize /*aScreenSize*/)
1.84 + {
1.85 + }
1.86 +
1.87 +EXPORT_C void CTestWindow::DrawL()
1.88 + {
1.89 + }
1.90 +
1.91 +void CTestWindow::SetPosition()
1.92 + {
1.93 + iWindow.SetPosition((*iLoadsaParameters)[iFrameCounter].iWindowPos);
1.94 + iSession.Flush();
1.95 + }
1.96 +
1.97 +void CTestWindow::SetSize()
1.98 + {
1.99 + iWindow.SetSize((*iLoadsaParameters)[iFrameCounter].iWindowSize);
1.100 + iSession.Flush();
1.101 + }
1.102 +
1.103 +void CTestWindow::SetExtent()
1.104 + {
1.105 + iWindow.SetExtent((*iLoadsaParameters)[iFrameCounter].iWindowPos, (*iLoadsaParameters)[iFrameCounter].iWindowSize);
1.106 + iSession.Flush();
1.107 + }
1.108 +
1.109 +EXPORT_C CTestEmptyWindow* CTestEmptyWindow::NewL(TInt aScreenNo, TDisplayMode aMode, const TSize& aScreenSize)
1.110 + {
1.111 + CTestEmptyWindow* self = new (ELeave) CTestEmptyWindow(aScreenNo, aMode);
1.112 + CleanupStack::PushL(self);
1.113 + self->ConstructL(aScreenSize);
1.114 + CleanupStack::Pop(); // self;
1.115 + return self;
1.116 + }
1.117 +
1.118 +void CTestEmptyWindow::ConstructL(const TSize& aScreenSize)
1.119 + {
1.120 + RDebug::Print(_L("Construct CTestEmptyWindow class\n"));
1.121 + iWindowDrawn = EFalse;
1.122 + iWindow.SetExtent(TPoint(0,0), aScreenSize);
1.123 + }
1.124 +
1.125 +EXPORT_C CTestEmptyWindow::CTestEmptyWindow(TInt aScreenNo, TDisplayMode aMode) :
1.126 + CTestWindow(aScreenNo, aMode)
1.127 + {
1.128 + }
1.129 +
1.130 +CTestEmptyWindow::~CTestEmptyWindow()
1.131 + {
1.132 + }
1.133 +
1.134 +EXPORT_C void CTestEmptyWindow::Rotate(TSize /*aScreenSize*/)
1.135 + {
1.136 + }
1.137 +
1.138 +EXPORT_C void CTestEmptyWindow::DrawL()
1.139 + {
1.140 + iWindowDrawn = ETrue;
1.141 + iWindowGc->Activate(iWindow);
1.142 + iWindow.Invalidate();
1.143 + iWindow.BeginRedraw();
1.144 + iWindow.EndRedraw();
1.145 + iWindowGc->Deactivate();
1.146 +
1.147 + iSession.Flush();
1.148 + }
1.149 +
1.150 +EXPORT_C CTestEcomWindow* CTestEcomWindow::NewL(TInt aScreenNo, TDisplayMode aMode, const TPtrC& aMultiBitmapEcomFile,
1.151 + TInt aMultiBitmapEcomFileSize, TGceTestResults* aGceTestResults,
1.152 + CArrayFixFlat<TDrawParameters>* aLoadsaParameters)
1.153 + {
1.154 + CTestEcomWindow* self = new (ELeave) CTestEcomWindow(aScreenNo, aMode);
1.155 + CleanupStack::PushL(self);
1.156 + self->ConstructL(aMultiBitmapEcomFile, aMultiBitmapEcomFileSize, aGceTestResults, aLoadsaParameters);
1.157 + CleanupStack::Pop(); // self;
1.158 + return self;
1.159 + }
1.160 +
1.161 +void CTestEcomWindow::ConstructL(const TPtrC& aMultiBitmapEcomFile, TInt aMultiBitmapEcomFileSize, TGceTestResults* aGceTestResults,
1.162 + CArrayFixFlat<TDrawParameters>* aLoadsaParameters)
1.163 + {
1.164 + RDebug::Print(_L("Construct CTestEcomWindow class\n"));
1.165 +
1.166 + iMultiBitmapEcomFile.Set(aMultiBitmapEcomFile);
1.167 + iMultiBitmapEcomFileSize = aMultiBitmapEcomFileSize;
1.168 + iLoadsaParameters = aLoadsaParameters;
1.169 +
1.170 + //Pass notification value back to ui
1.171 + iGceTestResults = aGceTestResults;
1.172 + }
1.173 +
1.174 +EXPORT_C CTestEcomWindow::CTestEcomWindow(TInt aScreenNo, TDisplayMode aMode) :
1.175 + CTestWindow(aScreenNo, aMode)
1.176 + {
1.177 + }
1.178 +
1.179 +CTestEcomWindow::~CTestEcomWindow()
1.180 + {
1.181 + }
1.182 +
1.183 +EXPORT_C void CTestEcomWindow::Rotate(TSize /*aScreenSize*/)
1.184 + {
1.185 + }
1.186 +
1.187 +EXPORT_C void CTestEcomWindow::DrawL()
1.188 + {
1.189 + if(iBitmapCounter == iMultiBitmapEcomFileSize)
1.190 + {
1.191 + iBitmapCounter = 0;
1.192 + }
1.193 +
1.194 + TParamChange redraw = Redraw();
1.195 + if(redraw != ENoParamChange)
1.196 + {
1.197 + if(redraw == EPositionChange)
1.198 + {
1.199 + SetPosition();
1.200 + }
1.201 +
1.202 + if(redraw == ESizeChange)
1.203 + {
1.204 + SetSize();
1.205 + }
1.206 +
1.207 + if(redraw == EExtentChange)
1.208 + {
1.209 + SetExtent();
1.210 + }
1.211 + }
1.212 +
1.213 + CFbsBitmap bitmap;
1.214 + iWindowGc->Activate(iWindow);
1.215 + iWindow.Invalidate();
1.216 + iWindow.BeginRedraw();
1.217 +
1.218 + bitmap.Load(iMultiBitmapEcomFile, iBitmapCounter);
1.219 +
1.220 + iWindowGc->DrawBitmap(TRect(TPoint(0,0), (*iLoadsaParameters)[0].iWindowSize), &bitmap);
1.221 +
1.222 + iWindow.EndRedraw();
1.223 + iWindowGc->Deactivate();
1.224 + iSession.Flush();
1.225 +
1.226 + iFrameCounter++;
1.227 + iBitmapCounter++;
1.228 + }
1.229 +
1.230 +TParamChange CTestEcomWindow::Redraw()
1.231 + {
1.232 + if(iFrameCounter == 0)
1.233 + {
1.234 + iWindow.SetExtent((*iLoadsaParameters)[0].iWindowPos, (*iLoadsaParameters)[0].iWindowSize);
1.235 + iWindow.SetVisible(ETrue);
1.236 +
1.237 + return EFirstFrame;
1.238 + }
1.239 + else
1.240 + {
1.241 + TDrawParameters current = (*iLoadsaParameters)[iFrameCounter];
1.242 + TDrawParameters last = (*iLoadsaParameters)[iFrameCounter - 1];
1.243 +
1.244 + if(current.iWindowSize != last.iWindowSize)
1.245 + {
1.246 + if(current.iWindowPos != last.iWindowPos)
1.247 + {
1.248 + return EExtentChange;
1.249 + }
1.250 + return ESizeChange;
1.251 + }
1.252 + else if(current.iWindowPos != last.iWindowPos)
1.253 + {
1.254 + return EPositionChange;
1.255 + }
1.256 + }
1.257 + return ENoParamChange;
1.258 + }
1.259 +
1.260 +EXPORT_C CTestUiWindow* CTestUiWindow::NewL(TInt aScreenNo, TDisplayMode aMode, const TPtrC& aMultiBitmapUiFile, TInt aMultiBitmapUiFileSize,
1.261 + CArrayFixFlat<TRect>* aRectArray, TInt aFrameDuration, TInt aMultiBitmapUiFileTransparency,
1.262 + TGceTestResults* aGceTestResults,
1.263 + CArrayFixFlat<TDrawParameters>* aLoadsaParameters)
1.264 + {
1.265 + CTestUiWindow* self = new (ELeave) CTestUiWindow(aScreenNo ,aMode);
1.266 + CleanupStack::PushL(self);
1.267 + self->ConstructL(aMultiBitmapUiFile, aMultiBitmapUiFileSize, aRectArray, aFrameDuration,
1.268 + aMultiBitmapUiFileTransparency, aGceTestResults,
1.269 + aLoadsaParameters);
1.270 +
1.271 + CleanupStack::Pop(); // self;
1.272 + return self;
1.273 + }
1.274 +
1.275 +void CTestUiWindow::ConstructL(const TPtrC& aMultiBitmapUiFile, TInt aMultiBitmapUiFileSize, CArrayFixFlat<TRect>* aRectArray,
1.276 + TInt aFrameDuration, TInt aMultiBitmapUiFileTransparency, TGceTestResults* aGceTestResults,
1.277 + CArrayFixFlat<TDrawParameters>* aLoadsaParameters)
1.278 + {
1.279 + RDebug::Print(_L("Construct CTestUiWindow class\n"));
1.280 +
1.281 + iSimUiDrawn = EFalse;
1.282 + iMultiBitmapUiFile.Set(aMultiBitmapUiFile);
1.283 + iMultiBitmapUiFileSize = aMultiBitmapUiFileSize;
1.284 + iMultiBitmapUiFileTransparency = aMultiBitmapUiFileTransparency;
1.285 + iRectArray = aRectArray;
1.286 + iFrameDuration = aFrameDuration;
1.287 + iLoadsaParameters = aLoadsaParameters;
1.288 +
1.289 + //Pass notification value back to ui
1.290 + iGceTestResults = aGceTestResults;
1.291 + }
1.292 +
1.293 +EXPORT_C CTestUiWindow::CTestUiWindow(TInt aScreenNo, TDisplayMode aMode) :
1.294 + CTestWindow(aScreenNo, aMode)
1.295 + {
1.296 + }
1.297 +
1.298 +CTestUiWindow::~CTestUiWindow()
1.299 + {
1.300 + }
1.301 +
1.302 +void CTestUiWindow::SetBitmapTransparency(CFbsBitmap* aBitmap, TUint8 aAlphaValue, TInt aAlphaByteLocation)
1.303 + {
1.304 + aBitmap->LockHeap();
1.305 + TUint32* bitmapBufferPtr = aBitmap->DataAddress();
1.306 + if(bitmapBufferPtr == 0)
1.307 + {
1.308 + RDebug::Print(_L("Error getting bitmap address, aborting\n"));
1.309 + //Unlock heap before exitting
1.310 + aBitmap->UnlockHeap();
1.311 + User::Exit(0);
1.312 + }
1.313 +
1.314 + TSize aBitmapSize = aBitmap->SizeInPixels();
1.315 + TUint32 noOfPixels = aBitmapSize.iHeight * aBitmapSize.iWidth;
1.316 +
1.317 + while(noOfPixels)
1.318 + {
1.319 + *bitmapBufferPtr = ( (*bitmapBufferPtr & ~(0xFF << (aAlphaByteLocation * 8))) | (aAlphaValue << (aAlphaByteLocation * 8)) );
1.320 + bitmapBufferPtr++;
1.321 + noOfPixels--;
1.322 + }
1.323 + aBitmap->UnlockHeap();
1.324 + }
1.325 +
1.326 +EXPORT_C void CTestUiWindow::Rotate(const TSize& aScreenSize)
1.327 + {
1.328 + //Adjust the sizes of the UI bitmap components to reflect the aspect ratio change
1.329 + for(TInt j=0; j<iMultiBitmapUiFileSize; j++)
1.330 + {
1.331 + (*iRectArray)[j].iTl.iX = ((*iRectArray)[j].iTl.iX*aScreenSize.iWidth)/aScreenSize.iHeight;
1.332 + (*iRectArray)[j].iTl.iY = ((*iRectArray)[j].iTl.iY*aScreenSize.iHeight)/aScreenSize.iWidth;
1.333 + (*iRectArray)[j].iBr.iX = ((*iRectArray)[j].iBr.iX*aScreenSize.iWidth)/aScreenSize.iHeight;
1.334 + (*iRectArray)[j].iBr.iY = ((*iRectArray)[j].iBr.iY*aScreenSize.iHeight)/aScreenSize.iWidth;
1.335 + }
1.336 +
1.337 + iWindow.SetSize(aScreenSize);
1.338 + }
1.339 +
1.340 +EXPORT_C void CTestUiWindow::DrawL()
1.341 + {
1.342 + TParamChange redraw = Redraw();
1.343 +
1.344 + if(redraw == EPositionChange)
1.345 + {
1.346 + SetPosition();
1.347 + }
1.348 +
1.349 + if(redraw == ESizeChange)
1.350 + {
1.351 + SetSize();
1.352 + }
1.353 +
1.354 + if(redraw == EExtentChange)
1.355 + {
1.356 + SetExtent();
1.357 + }
1.358 +
1.359 + CFbsBitmap bitmap;
1.360 + iWindowGc->Activate(iWindow);
1.361 + iWindow.Invalidate();
1.362 + iWindow.BeginRedraw();
1.363 +
1.364 + CTestBitmap* bitmapSource = NULL;
1.365 + bitmapSource = CTestBitmap::NewL(TSize(0,0), iMode);
1.366 +
1.367 + for(TInt j=0; j<iMultiBitmapUiFileSize; j++)
1.368 + {
1.369 + User::LeaveIfError(bitmapSource->Bitmap().Load(iMultiBitmapUiFile, j));
1.370 +
1.371 + TInt lastSize = (*iLoadsaParameters)[iFrameCounter].iBitmapScale;
1.372 + TRect destRect;
1.373 + TPoint drawPos;
1.374 +
1.375 +
1.376 + destRect.SetRect(TPoint( ((*iRectArray)[j].iTl.iX*lastSize)/100, ((*iRectArray)[j].iTl.iY*lastSize)/100),
1.377 + TPoint( ((*iRectArray)[j].iBr.iX*lastSize)/100, ((*iRectArray)[j].iBr.iY*lastSize)/100 ));
1.378 +
1.379 + drawPos = TPoint(((*iRectArray)[j].iTl.iX*lastSize)/100, ((*iRectArray)[j].iTl.iY*lastSize)/100);
1.380 +
1.381 + if(iMultiBitmapUiFileTransparency)
1.382 + {
1.383 + CTestBitmap* bitmapSourceAlpha = CTestBitmap::NewL(TSize(0,0), EGray256);
1.384 + User::LeaveIfError(bitmapSourceAlpha->Bitmap().Load(iMultiBitmapUiFile, j+iMultiBitmapUiFileSize));
1.385 +
1.386 + //Adjust the transparency controlled by the alpha bitmap
1.387 + SetBitmapAlpha(&(bitmapSourceAlpha->Bitmap()));
1.388 +
1.389 + CTestBitmap* bitmapDest = CTestBitmap::NewL(destRect.Size(), iMode);
1.390 + bitmapDest->Bitmap().SetSizeInTwips(bitmapSource->Bitmap().SizeInTwips());
1.391 + bitmapDest->Gc().DrawBitmap(TRect(TPoint(0,0), destRect.Size()), &(bitmapSource->Bitmap()));
1.392 +
1.393 + CTestBitmap* bitmapDestAlpha = CTestBitmap::NewL(destRect.Size(), EGray256);
1.394 + bitmapDestAlpha->Bitmap().SetSizeInTwips(bitmapSourceAlpha->Bitmap().SizeInTwips());
1.395 + bitmapDestAlpha->Gc().DrawBitmap(TRect(TPoint(0,0), destRect.Size()), &(bitmapSourceAlpha->Bitmap()));
1.396 +
1.397 + iWindowGc->AlphaBlendBitmaps(drawPos, &(bitmapDest->Bitmap()), TRect(TPoint(0,0), destRect.Size()),
1.398 + &(bitmapDestAlpha->Bitmap()), TPoint(0,0));
1.399 +
1.400 + delete bitmapSourceAlpha;
1.401 + delete bitmapDest;
1.402 + delete bitmapDestAlpha;
1.403 + }
1.404 + else
1.405 + {
1.406 + iWindowGc->DrawBitmap(destRect, &(bitmapSource->Bitmap()));
1.407 + }
1.408 + }
1.409 +
1.410 + delete bitmapSource;
1.411 +
1.412 + iWindow.EndRedraw();
1.413 + iWindowGc->Deactivate();
1.414 + iSession.Flush();
1.415 +
1.416 + iFrameCounter++;
1.417 + }
1.418 +
1.419 +void CTestUiWindow::SetBitmapAlpha(CFbsBitmap* aBitmap)
1.420 + {
1.421 + aBitmap->LockHeap();
1.422 + TUint32* bitmapBufferPtr = aBitmap->DataAddress();
1.423 +
1.424 + TSize aBitmapSize = aBitmap->SizeInPixels();
1.425 + TUint32 noOfPixels = (aBitmapSize.iHeight * aBitmapSize.iWidth)/4;
1.426 + TUint8 alpha = (*iLoadsaParameters)[iFrameCounter].iBitmapAlpha;
1.427 +
1.428 + TUint32 alpha32 = (alpha << 24) | (alpha << 16) | (alpha << 8) | alpha;
1.429 + while(noOfPixels)
1.430 + {
1.431 + //Only modify grey pixels leaving the white ones untouched
1.432 + if(*bitmapBufferPtr != 0x0)
1.433 + {
1.434 + *bitmapBufferPtr = alpha32;
1.435 + }
1.436 +
1.437 + bitmapBufferPtr++;
1.438 + noOfPixels--;
1.439 + }
1.440 + aBitmap->UnlockHeap();
1.441 + }
1.442 +
1.443 +TParamChange CTestUiWindow::Redraw()
1.444 + {
1.445 + if(iFrameCounter == 0)
1.446 + {
1.447 + iWindow.SetExtent((*iLoadsaParameters)[0].iWindowPos, (*iLoadsaParameters)[0].iWindowSize);
1.448 + iWindow.SetVisible(ETrue);
1.449 +
1.450 + return EFirstFrame;
1.451 + }
1.452 + else
1.453 + {
1.454 + TDrawParameters current = (*iLoadsaParameters)[iFrameCounter];
1.455 + TDrawParameters last = (*iLoadsaParameters)[iFrameCounter - 1];
1.456 +
1.457 + if(current.iWindowSize != last.iWindowSize)
1.458 + {
1.459 + if(current.iWindowPos != last.iWindowPos)
1.460 + {
1.461 + return EExtentChange;
1.462 + }
1.463 + return ESizeChange;
1.464 + }
1.465 + else if(current.iWindowPos != last.iWindowPos)
1.466 + {
1.467 + return EPositionChange;
1.468 + }
1.469 + else if(current.iBitmapScale != last.iBitmapScale)
1.470 + {
1.471 + return EBitmapScale;
1.472 + }
1.473 + else if(current.iBitmapAlpha != last.iBitmapAlpha)
1.474 + {
1.475 + return EOpacityChange;
1.476 + }
1.477 + }
1.478 + return ENoParamChange;
1.479 + }
1.480 +
1.481 +TDrawParameters::TDrawParameters() : iRedraw(EFalse), iBitmapScale(0), iBitmapAlpha(0), iWindowSize(0,0), iWindowPos(0,0)
1.482 + {
1.483 + }
1.484 +
1.485 +TDrawParameters::~TDrawParameters()
1.486 + {
1.487 + }
1.488 +
1.489 +TBool TDrawParameters::operator==(const TDrawParameters& x) const
1.490 + {
1.491 + if( (x.iBitmapScale != iBitmapScale) ||
1.492 + (x.iBitmapAlpha != iBitmapAlpha) ||
1.493 + (x.iWindowSize != iWindowSize) ||
1.494 + (x.iWindowPos != iWindowPos) )
1.495 + {
1.496 + return ETrue;
1.497 + }
1.498 +
1.499 + return EFalse;
1.500 + }