|
1 /** |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 * @file |
|
20 */ |
|
21 |
|
22 #ifndef __SURFACE_UTILITY__ |
|
23 #define __SURFACE_UTILITY__ |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <graphics/surface.h> |
|
27 #include <graphics/surfacemanager.h> |
|
28 #include <graphics/surfaceupdateclient.h> |
|
29 |
|
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 |
|
32 |
|
33 #if defined(ENABLE_TEST_LOGGING) |
|
34 #define LOG(X) RDebug::Printf X |
|
35 #else |
|
36 #define LOG(X) |
|
37 #endif |
|
38 |
|
39 class TRgb; |
|
40 class CFbsBitmap; |
|
41 |
|
42 class CSurfaceUtility : public CBase |
|
43 { |
|
44 public: |
|
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); |
|
60 TBool DestroyAll(); |
|
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); |
|
70 private: |
|
71 CSurfaceUtility(CSurfaceUtility* aClone); |
|
72 void ConstructL(); |
|
73 |
|
74 private: |
|
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 |
|
83 { |
|
84 public: |
|
85 typedef RArray<TSurfaceId> Array; |
|
86 RHeapSurfaceArray(RHeapSurfaceArray* aUseExternalArray=NULL); |
|
87 |
|
88 //Emulation of RArray entrypoints. Add more stub methods if required... |
|
89 TSurfaceId& operator[](TUint aIndex); |
|
90 void Close(); |
|
91 TInt Count() const; |
|
92 inline void Reset(); |
|
93 void AppendL(const TSurfaceId &anEntry); |
|
94 TInt Find(const TSurfaceId &anEntry) const; |
|
95 void Remove(TInt anIndex); |
|
96 |
|
97 private: |
|
98 static void PopHeap(void* mainheap); |
|
99 static void SwitchHeapLC(RHeap* aNewHeap); |
|
100 |
|
101 Array iLocalArray; |
|
102 Array* iUseArray; |
|
103 RHeap &iExternalHeapRef; |
|
104 } iSurfaces; |
|
105 }; |
|
106 |
|
107 /** |
|
108 CActiveListener provides the asynchronous operation |
|
109 of an active object |
|
110 */ |
|
111 class CActiveListener : public CActive |
|
112 { |
|
113 public: |
|
114 static CActiveListener* NewLC(); |
|
115 ~CActiveListener(); |
|
116 |
|
117 void Initialize(); |
|
118 TBool IsRequestCancelled(); |
|
119 |
|
120 private: |
|
121 CActiveListener(); |
|
122 |
|
123 virtual void RunL(); |
|
124 virtual void DoCancel(); |
|
125 }; |
|
126 |
|
127 #endif // __SURFACE_UTILITY__ |
|
128 |