sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent sl@0: */ sl@0: sl@0: #include "t_pseudoappwindow.h" sl@0: #include "t_winutils.h" sl@0: sl@0: EXPORT_C CTestWindow::CTestWindow(TInt aScreenNo, TDisplayMode aMode) sl@0: { sl@0: RDebug::Print(_L("Creating CTestWindow class\n")); sl@0: TRAPD(err, ConstructL(aScreenNo, aMode)); sl@0: if(err) sl@0: { sl@0: RDebug::Print(_L("CTestWindow::ConstructL() leaves with error %d\n"), err); sl@0: User::Exit(0); sl@0: } sl@0: } sl@0: sl@0: CTestWindow::~CTestWindow() sl@0: { sl@0: if(iScreen) sl@0: { sl@0: delete iScreen; sl@0: } sl@0: sl@0: if(iWindowGc) sl@0: { sl@0: delete iWindowGc; sl@0: } sl@0: sl@0: iSession.Close(); sl@0: } sl@0: sl@0: EXPORT_C void CTestWindow::ConstructL(TInt aScreenNo, TDisplayMode aMode) sl@0: { sl@0: RDebug::Print(_L("Constructing CTestWindow class\n")); sl@0: User::LeaveIfError(iSession.Connect()); sl@0: sl@0: RDebug::Print(_L("Create CWsScreenDevice\n")); sl@0: iScreen = new(ELeave) CWsScreenDevice(iSession); sl@0: User::LeaveIfError(iScreen->Construct(aScreenNo)); sl@0: sl@0: RDebug::Print(_L("Create RWindowGroup\n")); sl@0: iGroup = RWindowGroup(iSession); sl@0: sl@0: User::LeaveIfError(iGroup.Construct(8970 + aScreenNo, ETrue)); sl@0: sl@0: RDebug::Print(_L("Create Window\n")); sl@0: iWindow = RWindow(iSession); sl@0: User::LeaveIfError(iWindow.Construct((RWindowTreeNode)iGroup,(TUint32)this)); sl@0: sl@0: RDebug::Print(_L("Create CWindowGc\n")); sl@0: iWindowGc = new (ELeave) CWindowGc(iScreen); sl@0: User::LeaveIfError(iWindowGc->Construct()); sl@0: sl@0: TInt ret = iWindow.SetRequiredDisplayMode(aMode); sl@0: RDebug::Print(_L("Window display mode set to %d\n"), ret); sl@0: sl@0: iMode = aMode; sl@0: iWindow.Activate(); sl@0: } sl@0: sl@0: EXPORT_C void CTestWindow::Rotate(TSize /*aScreenSize*/) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CTestWindow::DrawL() sl@0: { sl@0: } sl@0: sl@0: void CTestWindow::SetPosition() sl@0: { sl@0: iWindow.SetPosition((*iLoadsaParameters)[iFrameCounter].iWindowPos); sl@0: iSession.Flush(); sl@0: } sl@0: sl@0: void CTestWindow::SetSize() sl@0: { sl@0: iWindow.SetSize((*iLoadsaParameters)[iFrameCounter].iWindowSize); sl@0: iSession.Flush(); sl@0: } sl@0: sl@0: void CTestWindow::SetExtent() sl@0: { sl@0: iWindow.SetExtent((*iLoadsaParameters)[iFrameCounter].iWindowPos, (*iLoadsaParameters)[iFrameCounter].iWindowSize); sl@0: iSession.Flush(); sl@0: } sl@0: sl@0: EXPORT_C CTestEmptyWindow* CTestEmptyWindow::NewL(TInt aScreenNo, TDisplayMode aMode, const TSize& aScreenSize) sl@0: { sl@0: CTestEmptyWindow* self = new (ELeave) CTestEmptyWindow(aScreenNo, aMode); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aScreenSize); sl@0: CleanupStack::Pop(); // self; sl@0: return self; sl@0: } sl@0: sl@0: void CTestEmptyWindow::ConstructL(const TSize& aScreenSize) sl@0: { sl@0: RDebug::Print(_L("Construct CTestEmptyWindow class\n")); sl@0: iWindowDrawn = EFalse; sl@0: iWindow.SetExtent(TPoint(0,0), aScreenSize); sl@0: } sl@0: sl@0: EXPORT_C CTestEmptyWindow::CTestEmptyWindow(TInt aScreenNo, TDisplayMode aMode) : sl@0: CTestWindow(aScreenNo, aMode) sl@0: { sl@0: } sl@0: sl@0: CTestEmptyWindow::~CTestEmptyWindow() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CTestEmptyWindow::Rotate(TSize /*aScreenSize*/) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CTestEmptyWindow::DrawL() sl@0: { sl@0: iWindowDrawn = ETrue; sl@0: iWindowGc->Activate(iWindow); sl@0: iWindow.Invalidate(); sl@0: iWindow.BeginRedraw(); sl@0: iWindow.EndRedraw(); sl@0: iWindowGc->Deactivate(); sl@0: sl@0: iSession.Flush(); sl@0: } sl@0: sl@0: EXPORT_C CTestEcomWindow* CTestEcomWindow::NewL(TInt aScreenNo, TDisplayMode aMode, const TPtrC& aMultiBitmapEcomFile, sl@0: TInt aMultiBitmapEcomFileSize, TGceTestResults* aGceTestResults, sl@0: CArrayFixFlat* aLoadsaParameters) sl@0: { sl@0: CTestEcomWindow* self = new (ELeave) CTestEcomWindow(aScreenNo, aMode); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aMultiBitmapEcomFile, aMultiBitmapEcomFileSize, aGceTestResults, aLoadsaParameters); sl@0: CleanupStack::Pop(); // self; sl@0: return self; sl@0: } sl@0: sl@0: void CTestEcomWindow::ConstructL(const TPtrC& aMultiBitmapEcomFile, TInt aMultiBitmapEcomFileSize, TGceTestResults* aGceTestResults, sl@0: CArrayFixFlat* aLoadsaParameters) sl@0: { sl@0: RDebug::Print(_L("Construct CTestEcomWindow class\n")); sl@0: sl@0: iMultiBitmapEcomFile.Set(aMultiBitmapEcomFile); sl@0: iMultiBitmapEcomFileSize = aMultiBitmapEcomFileSize; sl@0: iLoadsaParameters = aLoadsaParameters; sl@0: sl@0: //Pass notification value back to ui sl@0: iGceTestResults = aGceTestResults; sl@0: } sl@0: sl@0: EXPORT_C CTestEcomWindow::CTestEcomWindow(TInt aScreenNo, TDisplayMode aMode) : sl@0: CTestWindow(aScreenNo, aMode) sl@0: { sl@0: } sl@0: sl@0: CTestEcomWindow::~CTestEcomWindow() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CTestEcomWindow::Rotate(TSize /*aScreenSize*/) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CTestEcomWindow::DrawL() sl@0: { sl@0: if(iBitmapCounter == iMultiBitmapEcomFileSize) sl@0: { sl@0: iBitmapCounter = 0; sl@0: } sl@0: sl@0: TParamChange redraw = Redraw(); sl@0: if(redraw != ENoParamChange) sl@0: { sl@0: if(redraw == EPositionChange) sl@0: { sl@0: SetPosition(); sl@0: } sl@0: sl@0: if(redraw == ESizeChange) sl@0: { sl@0: SetSize(); sl@0: } sl@0: sl@0: if(redraw == EExtentChange) sl@0: { sl@0: SetExtent(); sl@0: } sl@0: } sl@0: sl@0: CFbsBitmap bitmap; sl@0: iWindowGc->Activate(iWindow); sl@0: iWindow.Invalidate(); sl@0: iWindow.BeginRedraw(); sl@0: sl@0: bitmap.Load(iMultiBitmapEcomFile, iBitmapCounter); sl@0: sl@0: iWindowGc->DrawBitmap(TRect(TPoint(0,0), (*iLoadsaParameters)[0].iWindowSize), &bitmap); sl@0: sl@0: iWindow.EndRedraw(); sl@0: iWindowGc->Deactivate(); sl@0: iSession.Flush(); sl@0: sl@0: iFrameCounter++; sl@0: iBitmapCounter++; sl@0: } sl@0: sl@0: TParamChange CTestEcomWindow::Redraw() sl@0: { sl@0: if(iFrameCounter == 0) sl@0: { sl@0: iWindow.SetExtent((*iLoadsaParameters)[0].iWindowPos, (*iLoadsaParameters)[0].iWindowSize); sl@0: iWindow.SetVisible(ETrue); sl@0: sl@0: return EFirstFrame; sl@0: } sl@0: else sl@0: { sl@0: TDrawParameters current = (*iLoadsaParameters)[iFrameCounter]; sl@0: TDrawParameters last = (*iLoadsaParameters)[iFrameCounter - 1]; sl@0: sl@0: if(current.iWindowSize != last.iWindowSize) sl@0: { sl@0: if(current.iWindowPos != last.iWindowPos) sl@0: { sl@0: return EExtentChange; sl@0: } sl@0: return ESizeChange; sl@0: } sl@0: else if(current.iWindowPos != last.iWindowPos) sl@0: { sl@0: return EPositionChange; sl@0: } sl@0: } sl@0: return ENoParamChange; sl@0: } sl@0: sl@0: EXPORT_C CTestUiWindow* CTestUiWindow::NewL(TInt aScreenNo, TDisplayMode aMode, const TPtrC& aMultiBitmapUiFile, TInt aMultiBitmapUiFileSize, sl@0: CArrayFixFlat* aRectArray, TInt aFrameDuration, TInt aMultiBitmapUiFileTransparency, sl@0: TGceTestResults* aGceTestResults, sl@0: CArrayFixFlat* aLoadsaParameters) sl@0: { sl@0: CTestUiWindow* self = new (ELeave) CTestUiWindow(aScreenNo ,aMode); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aMultiBitmapUiFile, aMultiBitmapUiFileSize, aRectArray, aFrameDuration, sl@0: aMultiBitmapUiFileTransparency, aGceTestResults, sl@0: aLoadsaParameters); sl@0: sl@0: CleanupStack::Pop(); // self; sl@0: return self; sl@0: } sl@0: sl@0: void CTestUiWindow::ConstructL(const TPtrC& aMultiBitmapUiFile, TInt aMultiBitmapUiFileSize, CArrayFixFlat* aRectArray, sl@0: TInt aFrameDuration, TInt aMultiBitmapUiFileTransparency, TGceTestResults* aGceTestResults, sl@0: CArrayFixFlat* aLoadsaParameters) sl@0: { sl@0: RDebug::Print(_L("Construct CTestUiWindow class\n")); sl@0: sl@0: iSimUiDrawn = EFalse; sl@0: iMultiBitmapUiFile.Set(aMultiBitmapUiFile); sl@0: iMultiBitmapUiFileSize = aMultiBitmapUiFileSize; sl@0: iMultiBitmapUiFileTransparency = aMultiBitmapUiFileTransparency; sl@0: iRectArray = aRectArray; sl@0: iFrameDuration = aFrameDuration; sl@0: iLoadsaParameters = aLoadsaParameters; sl@0: sl@0: //Pass notification value back to ui sl@0: iGceTestResults = aGceTestResults; sl@0: } sl@0: sl@0: EXPORT_C CTestUiWindow::CTestUiWindow(TInt aScreenNo, TDisplayMode aMode) : sl@0: CTestWindow(aScreenNo, aMode) sl@0: { sl@0: } sl@0: sl@0: CTestUiWindow::~CTestUiWindow() sl@0: { sl@0: } sl@0: sl@0: void CTestUiWindow::SetBitmapTransparency(CFbsBitmap* aBitmap, TUint8 aAlphaValue, TInt aAlphaByteLocation) sl@0: { sl@0: aBitmap->LockHeap(); sl@0: TUint32* bitmapBufferPtr = aBitmap->DataAddress(); sl@0: if(bitmapBufferPtr == 0) sl@0: { sl@0: RDebug::Print(_L("Error getting bitmap address, aborting\n")); sl@0: //Unlock heap before exitting sl@0: aBitmap->UnlockHeap(); sl@0: User::Exit(0); sl@0: } sl@0: sl@0: TSize aBitmapSize = aBitmap->SizeInPixels(); sl@0: TUint32 noOfPixels = aBitmapSize.iHeight * aBitmapSize.iWidth; sl@0: sl@0: while(noOfPixels) sl@0: { sl@0: *bitmapBufferPtr = ( (*bitmapBufferPtr & ~(0xFF << (aAlphaByteLocation * 8))) | (aAlphaValue << (aAlphaByteLocation * 8)) ); sl@0: bitmapBufferPtr++; sl@0: noOfPixels--; sl@0: } sl@0: aBitmap->UnlockHeap(); sl@0: } sl@0: sl@0: EXPORT_C void CTestUiWindow::Rotate(const TSize& aScreenSize) sl@0: { sl@0: //Adjust the sizes of the UI bitmap components to reflect the aspect ratio change sl@0: for(TInt j=0; jActivate(iWindow); sl@0: iWindow.Invalidate(); sl@0: iWindow.BeginRedraw(); sl@0: sl@0: CTestBitmap* bitmapSource = NULL; sl@0: bitmapSource = CTestBitmap::NewL(TSize(0,0), iMode); sl@0: sl@0: for(TInt j=0; jBitmap().Load(iMultiBitmapUiFile, j)); sl@0: sl@0: TInt lastSize = (*iLoadsaParameters)[iFrameCounter].iBitmapScale; sl@0: TRect destRect; sl@0: TPoint drawPos; sl@0: sl@0: sl@0: destRect.SetRect(TPoint( ((*iRectArray)[j].iTl.iX*lastSize)/100, ((*iRectArray)[j].iTl.iY*lastSize)/100), sl@0: TPoint( ((*iRectArray)[j].iBr.iX*lastSize)/100, ((*iRectArray)[j].iBr.iY*lastSize)/100 )); sl@0: sl@0: drawPos = TPoint(((*iRectArray)[j].iTl.iX*lastSize)/100, ((*iRectArray)[j].iTl.iY*lastSize)/100); sl@0: sl@0: if(iMultiBitmapUiFileTransparency) sl@0: { sl@0: CTestBitmap* bitmapSourceAlpha = CTestBitmap::NewL(TSize(0,0), EGray256); sl@0: User::LeaveIfError(bitmapSourceAlpha->Bitmap().Load(iMultiBitmapUiFile, j+iMultiBitmapUiFileSize)); sl@0: sl@0: //Adjust the transparency controlled by the alpha bitmap sl@0: SetBitmapAlpha(&(bitmapSourceAlpha->Bitmap())); sl@0: sl@0: CTestBitmap* bitmapDest = CTestBitmap::NewL(destRect.Size(), iMode); sl@0: bitmapDest->Bitmap().SetSizeInTwips(bitmapSource->Bitmap().SizeInTwips()); sl@0: bitmapDest->Gc().DrawBitmap(TRect(TPoint(0,0), destRect.Size()), &(bitmapSource->Bitmap())); sl@0: sl@0: CTestBitmap* bitmapDestAlpha = CTestBitmap::NewL(destRect.Size(), EGray256); sl@0: bitmapDestAlpha->Bitmap().SetSizeInTwips(bitmapSourceAlpha->Bitmap().SizeInTwips()); sl@0: bitmapDestAlpha->Gc().DrawBitmap(TRect(TPoint(0,0), destRect.Size()), &(bitmapSourceAlpha->Bitmap())); sl@0: sl@0: iWindowGc->AlphaBlendBitmaps(drawPos, &(bitmapDest->Bitmap()), TRect(TPoint(0,0), destRect.Size()), sl@0: &(bitmapDestAlpha->Bitmap()), TPoint(0,0)); sl@0: sl@0: delete bitmapSourceAlpha; sl@0: delete bitmapDest; sl@0: delete bitmapDestAlpha; sl@0: } sl@0: else sl@0: { sl@0: iWindowGc->DrawBitmap(destRect, &(bitmapSource->Bitmap())); sl@0: } sl@0: } sl@0: sl@0: delete bitmapSource; sl@0: sl@0: iWindow.EndRedraw(); sl@0: iWindowGc->Deactivate(); sl@0: iSession.Flush(); sl@0: sl@0: iFrameCounter++; sl@0: } sl@0: sl@0: void CTestUiWindow::SetBitmapAlpha(CFbsBitmap* aBitmap) sl@0: { sl@0: aBitmap->LockHeap(); sl@0: TUint32* bitmapBufferPtr = aBitmap->DataAddress(); sl@0: sl@0: TSize aBitmapSize = aBitmap->SizeInPixels(); sl@0: TUint32 noOfPixels = (aBitmapSize.iHeight * aBitmapSize.iWidth)/4; sl@0: TUint8 alpha = (*iLoadsaParameters)[iFrameCounter].iBitmapAlpha; sl@0: sl@0: TUint32 alpha32 = (alpha << 24) | (alpha << 16) | (alpha << 8) | alpha; sl@0: while(noOfPixels) sl@0: { sl@0: //Only modify grey pixels leaving the white ones untouched sl@0: if(*bitmapBufferPtr != 0x0) sl@0: { sl@0: *bitmapBufferPtr = alpha32; sl@0: } sl@0: sl@0: bitmapBufferPtr++; sl@0: noOfPixels--; sl@0: } sl@0: aBitmap->UnlockHeap(); sl@0: } sl@0: sl@0: TParamChange CTestUiWindow::Redraw() sl@0: { sl@0: if(iFrameCounter == 0) sl@0: { sl@0: iWindow.SetExtent((*iLoadsaParameters)[0].iWindowPos, (*iLoadsaParameters)[0].iWindowSize); sl@0: iWindow.SetVisible(ETrue); sl@0: sl@0: return EFirstFrame; sl@0: } sl@0: else sl@0: { sl@0: TDrawParameters current = (*iLoadsaParameters)[iFrameCounter]; sl@0: TDrawParameters last = (*iLoadsaParameters)[iFrameCounter - 1]; sl@0: sl@0: if(current.iWindowSize != last.iWindowSize) sl@0: { sl@0: if(current.iWindowPos != last.iWindowPos) sl@0: { sl@0: return EExtentChange; sl@0: } sl@0: return ESizeChange; sl@0: } sl@0: else if(current.iWindowPos != last.iWindowPos) sl@0: { sl@0: return EPositionChange; sl@0: } sl@0: else if(current.iBitmapScale != last.iBitmapScale) sl@0: { sl@0: return EBitmapScale; sl@0: } sl@0: else if(current.iBitmapAlpha != last.iBitmapAlpha) sl@0: { sl@0: return EOpacityChange; sl@0: } sl@0: } sl@0: return ENoParamChange; sl@0: } sl@0: sl@0: TDrawParameters::TDrawParameters() : iRedraw(EFalse), iBitmapScale(0), iBitmapAlpha(0), iWindowSize(0,0), iWindowPos(0,0) sl@0: { sl@0: } sl@0: sl@0: TDrawParameters::~TDrawParameters() sl@0: { sl@0: } sl@0: sl@0: TBool TDrawParameters::operator==(const TDrawParameters& x) const sl@0: { sl@0: if( (x.iBitmapScale != iBitmapScale) || sl@0: (x.iBitmapAlpha != iBitmapAlpha) || sl@0: (x.iWindowSize != iWindowSize) || sl@0: (x.iWindowPos != iWindowPos) ) sl@0: { sl@0: return ETrue; sl@0: } sl@0: sl@0: return EFalse; sl@0: }