os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoappcfbsbitmapanim.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoappcfbsbitmapanim.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,171 @@
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_pseudoappcfbsbitmapanim.h"
1.26 +#include "t_testsurfacerasterizer.h"
1.27 +
1.28 +EXPORT_C CCFbsBitmapAnimation* CCFbsBitmapAnimation::NewL(TDisplayMode aMode, const TSize& aAnimSize, const TSize& aSurfaceSize,
1.29 + TPtrC& aBitmapFile, TInt aHorizontalRate, TInt aVerticalRate,
1.30 + TPixelFormat aPixelFormat)
1.31 + {
1.32 + RDebug::Print(_L("Creating CCFbsBitmapAnimation class\n"));
1.33 + CCFbsBitmapAnimation* self = new (ELeave) CCFbsBitmapAnimation();
1.34 + CleanupStack::PushL(self);
1.35 + self->ConstructL(aMode, aAnimSize, aSurfaceSize, aBitmapFile, aHorizontalRate, aVerticalRate, aPixelFormat);
1.36 + CleanupStack::Pop(); // self;
1.37 + return self;
1.38 + }
1.39 +
1.40 +void CCFbsBitmapAnimation::ConstructL(TDisplayMode aMode, const TSize& aAnimSize, const TSize& aSurfaceSize,
1.41 + TPtrC& aBitmapFile, TInt aHorizontalRate, TInt aVerticalRate,
1.42 + TPixelFormat aPixelFormat)
1.43 + {
1.44 + RDebug::Print(_L("Creating full-screen bitmap\n"));
1.45 +
1.46 + iBitmapAnimFile.Set(aBitmapFile);
1.47 + iHorizontalRate = aHorizontalRate;
1.48 + iVerticalRate = aVerticalRate;
1.49 + iAnimSize = aAnimSize;
1.50 + iSurfaceSize = aSurfaceSize;
1.51 + iPixelFormat = aPixelFormat;
1.52 + iRotationSupported = ETrue;
1.53 +
1.54 + iFullSurfaceBitmap = new(ELeave) CFbsBitmap;
1.55 +
1.56 + if(iPixelFormat == EFormatYuv)
1.57 + {
1.58 + TSize sz(iSurfaceSize.iWidth/2, iSurfaceSize.iHeight);
1.59 + iFullSurfaceBitmap->Create(sz, static_cast<TDisplayMode>(aMode));
1.60 + }
1.61 + else
1.62 + {
1.63 + iFullSurfaceBitmap->Create(iSurfaceSize, static_cast<TDisplayMode>(aMode));
1.64 + }
1.65 + iFullSurfaceBitmapDevice = CFbsBitmapDevice::NewL(iFullSurfaceBitmap);
1.66 + iFullSurfaceBitmapGc = CFbsBitGc::NewL();
1.67 + iFullSurfaceBitmapGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
1.68 + }
1.69 +
1.70 +CCFbsBitmapAnimation::CCFbsBitmapAnimation() : CTestAnimation()
1.71 + {
1.72 + };
1.73 +
1.74 +EXPORT_C CCFbsBitmapAnimation::~CCFbsBitmapAnimation()
1.75 + {
1.76 + delete iFullSurfaceBitmapGc;
1.77 + delete iFullSurfaceBitmapDevice;
1.78 + delete iFullSurfaceBitmap;
1.79 + }
1.80 +
1.81 +EXPORT_C void CCFbsBitmapAnimation::Rotate(TSize /*aScreenSize*/)
1.82 + {
1.83 + }
1.84 +
1.85 +EXPORT_C void CCFbsBitmapAnimation::DrawL(CTestSurfaceRasterizer* aSurfaceRasterizer, SurfaceDetails& aSurfDetails)
1.86 + {
1.87 + iFullSurfaceBitmapGc->Activate(iFullSurfaceBitmapDevice);
1.88 + iFullSurfaceBitmapGc->Clear();
1.89 +
1.90 + RedrawSurfaceL();
1.91 +
1.92 + //Send the fullscreen bitmap to the test rasterizer
1.93 + iFullSurfaceBitmap->LockHeap();
1.94 +
1.95 + TUint32* bitmapBufferPtr = iFullSurfaceBitmap->DataAddress();
1.96 + aSurfaceRasterizer->DrawRect(bitmapBufferPtr, aSurfDetails);
1.97 +
1.98 + iFullSurfaceBitmap->UnlockHeap();
1.99 + }
1.100 +
1.101 +EXPORT_C void CCFbsBitmapAnimation::SetFrameNumber(TInt aFrameNumber)
1.102 + {
1.103 + iFrameCounter = aFrameNumber;
1.104 + }
1.105 +
1.106 +void CCFbsBitmapAnimation::RedrawSurfaceL()
1.107 + {
1.108 + CFbsBitmap bitmap;
1.109 + User::LeaveIfError(bitmap.Load(iBitmapAnimFile, iFrameCounter));
1.110 +
1.111 + const TSize nativeSize(bitmap.SizeInPixels());
1.112 +
1.113 + const TSize fullScreenSize(iFullSurfaceBitmap->SizeInPixels());
1.114 +
1.115 + if(iPixelFormat == EFormatYuv)
1.116 + {
1.117 + TInt noOfPixels=fullScreenSize.iWidth * fullScreenSize.iHeight;
1.118 + TInt counter=noOfPixels;
1.119 + TUint32* address = iFullSurfaceBitmap->DataAddress();
1.120 + for(TInt i=0; i<counter; i++)
1.121 + {
1.122 + /* The only supported Yuv format is KPixelFormatYUV422Interleaved */
1.123 + /* Paint the surface white */
1.124 + address[i] = 0xFF7FFF7F;
1.125 + }
1.126 + }
1.127 +
1.128 + /* Potentially four screen copies will be required in the wrapping case *
1.129 + * (1) no wrapping (2) wrap in x co-ord (3) wrap in y co-ord *
1.130 + * (4) wrap in both x and y co-ords *
1.131 + * There is no problem with specifying negative co-ordinates for the *
1.132 + * top LH corner as the offscreen section will not be displayed */
1.133 +
1.134 + //Perform blits to the fullscreen bitmap
1.135 + //iAnimSize is the size of the square bitmap as it appears on the surface and iDisplayedSize is the size of the
1.136 + //rectangulara area limiting the animation
1.137 +
1.138 + TSize sz = iAnimSize;
1.139 + if(iPixelFormat == EFormatYuv)
1.140 + {
1.141 + sz = TSize(iAnimSize.iWidth/2, iAnimSize.iHeight);
1.142 + }
1.143 +
1.144 + iFullSurfaceBitmapGc->DrawBitmap(TRect(TPoint(iXPos, iYPos), sz), &bitmap, TRect(TPoint(0,0), nativeSize));
1.145 +
1.146 + //Wrap in x co-ord
1.147 + if( (iXPos + iAnimSize.iWidth) > iSurfaceSize.iWidth)
1.148 + {
1.149 + iFullSurfaceBitmapGc->DrawBitmap(TRect(TPoint(iXPos - iSurfaceSize.iWidth, iYPos), sz),
1.150 + &bitmap, TRect(TPoint(0,0), nativeSize));
1.151 + }
1.152 +
1.153 + //Wrap in y co-ord
1.154 + if( (iYPos + iAnimSize.iHeight) > iSurfaceSize.iHeight)
1.155 + {
1.156 + iFullSurfaceBitmapGc->DrawBitmap(TRect(TPoint(iXPos, iYPos - iSurfaceSize.iHeight), sz),
1.157 + &bitmap, TRect(TPoint(0,0), nativeSize));
1.158 + }
1.159 +
1.160 + //Wrap in both x and y co-ords
1.161 + if( ((iXPos + iAnimSize.iWidth) > iSurfaceSize.iWidth) && ((iYPos + iAnimSize.iHeight) > iSurfaceSize.iHeight) )
1.162 + {
1.163 + iFullSurfaceBitmapGc->DrawBitmap(TRect(TPoint(iXPos - iSurfaceSize.iWidth, iYPos - iSurfaceSize.iHeight), sz),
1.164 + &bitmap, TRect(TPoint(0,0), nativeSize));
1.165 + }
1.166 +
1.167 + //Increment x and y positions and wrap if necessary
1.168 + iXPos += iSurfaceSize.iWidth/iHorizontalRate;
1.169 + iYPos += iSurfaceSize.iHeight/iVerticalRate;
1.170 + iXPos = iXPos % iSurfaceSize.iWidth;
1.171 + iYPos = iYPos % iSurfaceSize.iHeight;
1.172 +
1.173 + iFrameCounter++;
1.174 + }