First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #ifndef __SURFACE_UTILITY__
23 #define __SURFACE_UTILITY__
26 #include <graphics/surface.h>
27 #include <graphics/surfacemanager.h>
28 #include <graphics/surfaceupdateclient.h>
30 #define ENABLE_TEST_LOGGING
31 #define ALPHA_FIX_24BIT 0x7f //This forces a non-zero value into the X byte of 16MU color values
33 #if defined(ENABLE_TEST_LOGGING)
34 #define LOG(X) RDebug::Printf X
42 class CSurfaceUtility : public CBase
45 static CSurfaceUtility* NewL(CSurfaceUtility* aClone=NULL);
46 virtual ~CSurfaceUtility();
47 TSize SurfaceSize(const TSurfaceId& aSurface);
48 void CreateSurfaceFromFileL(const TDesC& aFileName, TSurfaceId& aSurface);
49 TSurfaceId CreateSurfaceL(const TSize& aSize, TUidPixelFormat aPixelFormat, TInt aStride, TInt aBuffers = 1);
50 void FillSurfaceL(TSurfaceId& aSurface, const TRgb& aColor);
51 void FillChunkL(TSurfaceId& aSurface, RChunk& aChunk, const TRgb& aColor, TInt aBufferNumber);
52 void FillRectangleL(TSurfaceId& aSurface, TPoint& aStartPos, TSize& aSize, const TRgb& aColor);
53 void FillRectangleNoUpdateL(TSurfaceId& aSurface, TPoint& aStartPos, TSize& aSize, const TRgb& aColor);
54 void GridFillSurfaceL(TSurfaceId& aSurface, const TRgb& aColor, const TRgb& aLines);
55 void PatternFillSurfaceL(TSurfaceId& aSurface);
56 void FanFillSurfaceL(TSurfaceId& aSurface, const TRgb& aColor, const TRgb& aLinesTL,const TRgb& aLinesBR);
57 void LineFillSurfaceL(TSurfaceId& aSurface, const TRgb& aBackColor, const TRgb& aLineColor, TInt aPosition);
58 CFbsBitmap* EquivalentBitmapL(TSurfaceId& aSurface, CFbsBitmap* aCopyTo=NULL);
59 void DestroySurface(TSurfaceId& aSurface);
61 void SubmitUpdate(TInt aScreenNumber, const TSurfaceId& aSurface, const TRegion* aRegion, TInt aBufferNumber = 0);
62 void MapAndSubmitUpdateL(RChunk& aChunk, TInt aScreenNumber, const TSurfaceId& aSurface, const TRegion* aRegion);
63 void MapSurfaceL(const TSurfaceId& aSurface, RChunk& aChunk);
64 void CopyBitmapFromFileToSurfaceL(const TDesC& aFileName, const TSurfaceId& aSurface);
65 void ScaleBitmapFromFileToSurfaceL(const TDesC& aFileName, const TSurfaceId& aSurface);
66 void CopyBitmapSurfaceL(const CFbsBitmap* aBitmap, TSurfaceId& aSurface);
67 void CopyBitmapToSurfaceL(TSurfaceId& aSurface, const CFbsBitmap& aBitmap);
68 TInt PixelDataOffet(const TSurfaceId& aSurface);
69 TInt BytesPerPixelL(TUidPixelFormat aPixelFormat);
71 CSurfaceUtility(CSurfaceUtility* aClone);
75 RSurfaceManager iManager;
76 RSurfaceUpdateSession iSurfaceUpdateSession;
77 //This local object wraps the array operations in a heap switch
78 //The reason for providing this wrapper is to allow threads to share the surface manager surface ID list.
79 //In particular, the next test can attempt to release the previous test's surfaces if it paniced.
80 //Note that the presumption is that the owning thread will be paused,
81 //so there will be no thread interlock issues with it's heap manager.
82 class RHeapSurfaceArray
85 typedef RArray<TSurfaceId> Array;
86 RHeapSurfaceArray(RHeapSurfaceArray* aUseExternalArray=NULL);
88 //Emulation of RArray entrypoints. Add more stub methods if required...
89 TSurfaceId& operator[](TUint aIndex);
93 void AppendL(const TSurfaceId &anEntry);
94 TInt Find(const TSurfaceId &anEntry) const;
95 void Remove(TInt anIndex);
98 static void PopHeap(void* mainheap);
99 static void SwitchHeapLC(RHeap* aNewHeap);
103 RHeap &iExternalHeapRef;
108 CActiveListener provides the asynchronous operation
111 class CActiveListener : public CActive
114 static CActiveListener* NewLC();
118 TBool IsRequestCancelled();
124 virtual void DoCancel();
127 #endif // __SURFACE_UTILITY__