|
1 /* |
|
2 * Copyright (c) 2006-2008 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: Defines CHuiVg10Texture, an OpenVG-based texture class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __HUIVG10TEXTURE_H__ |
|
21 #define __HUIVG10TEXTURE_H__ |
|
22 |
|
23 |
|
24 #include <bldvariant.hrh> |
|
25 #include <e32base.h> |
|
26 #include <e32std.h> |
|
27 #include <gdi.h> |
|
28 #include <VG/openvg.h> |
|
29 |
|
30 #include "uiacceltk/HuiTexture.h" |
|
31 #include "uiacceltk/HuiTextureHandle.h" |
|
32 #include "HuiVg10RenderPlugin.h" |
|
33 |
|
34 #ifdef __NVG |
|
35 #include <AknIconHeader.h> |
|
36 class CNvgEngine; |
|
37 class MNVGIcon; |
|
38 #endif |
|
39 |
|
40 /** |
|
41 * CHuiVg10Texture wraps an OpenVG texture object. It provides methods |
|
42 * for uploading image data. When an instance of CHuiVg10Texture is |
|
43 * destroyed, the OpenVG texture object is deleted as well. |
|
44 * |
|
45 * @todo Proper segment support. Support more than two segments. |
|
46 * @todo Placeholder should be a THuiTextureHandle. |
|
47 */ |
|
48 NONSHARABLE_CLASS(CHuiVg10Texture) : public CHuiTexture |
|
49 { |
|
50 public: |
|
51 |
|
52 /* Constructors and destructor. */ |
|
53 |
|
54 /** |
|
55 * Constructs a new texture object. The texture has no segments initially. |
|
56 * |
|
57 * @param aRenderPlugin The render plugin that created this texture. |
|
58 * @return Texture object. |
|
59 */ |
|
60 static CHuiVg10Texture* NewL(CHuiVg10RenderPlugin& aRenderPlugin, const THuiTextureHandle* aExistingTexture = 0); |
|
61 |
|
62 /** |
|
63 * Constructs a new texture object and leaves it on the cleanup stack. |
|
64 * The texture has no segments initially. |
|
65 * |
|
66 * @param aRenderPlugin The render plugin that created this texture. |
|
67 * @return Texture object. |
|
68 */ |
|
69 static CHuiVg10Texture* NewLC(CHuiVg10RenderPlugin& aRenderPlugin, const THuiTextureHandle* aExistingTexture = 0); |
|
70 |
|
71 |
|
72 /** @beginAPI */ |
|
73 |
|
74 /** |
|
75 * Destructor. |
|
76 */ |
|
77 virtual ~CHuiVg10Texture(); |
|
78 |
|
79 |
|
80 /* Methods. */ |
|
81 |
|
82 TBool HasContent() const; // override |
|
83 |
|
84 /** |
|
85 * Determines if the texture has an alpha channel. |
|
86 * |
|
87 * @return <code>ETrue</code>, if the texture has an alpha channel. |
|
88 * Otherwise, <code>EFalse</code>. |
|
89 */ |
|
90 TBool HasAlpha() const; |
|
91 |
|
92 /** |
|
93 * Determines the maximum possible actual (OpenVG) size for |
|
94 * textures. This limit is usually set by the underlying |
|
95 * graphics driver/hardware. |
|
96 * @todo should be moved out? |
|
97 */ |
|
98 TSize MaxTextureSize() const; |
|
99 |
|
100 void UploadL(const CFbsBitmap& aBitmap, |
|
101 const CFbsBitmap * aMaskBitmap = NULL, |
|
102 THuiTextureUploadFlags aFlags = EHuiTextureUploadFlagDefault); |
|
103 |
|
104 void UploadL(THuiTextureFormat aFormat, |
|
105 const TSize& aSize, |
|
106 const TUint8* aBuffer, |
|
107 THuiTextureUploadFlags aFlags = EHuiTextureUploadFlagDefault, |
|
108 TUint aBufferSize = 0); |
|
109 |
|
110 void PartialUploadL(THuiTextureFormat aFormat, |
|
111 const TPoint& aOrigin, |
|
112 const TSize& aSize, |
|
113 const TUint8* aBuffer); |
|
114 |
|
115 void SegmentUploadL(TInt aSegment, |
|
116 const CFbsBitmap& aBitmap, |
|
117 const CFbsBitmap * aMaskBitmap = NULL, |
|
118 THuiTextureUploadFlags aFlags = EHuiTextureUploadFlagDefault); |
|
119 |
|
120 void SegmentUploadL(TInt aSegment, |
|
121 THuiTextureFormat aFormat, |
|
122 const TSize& aSize, |
|
123 const TUint8* aBuffer, |
|
124 TUint aBufferSize = 0); |
|
125 |
|
126 void SegmentPartialUpload(TInt aSegment, |
|
127 THuiTextureFormat aFormat, |
|
128 const TPoint& aOrigin, |
|
129 const TSize& aSize, |
|
130 const TUint8* aBuffer); |
|
131 |
|
132 void SegmentClearL(TInt aSegment, |
|
133 TBool aWithAlpha, |
|
134 const TRgb& aColor, |
|
135 TUint8 aAlpha); |
|
136 |
|
137 void SetupSegmentsL(const TSize& aLogicalSize, |
|
138 const TSize& aTextureSize, |
|
139 THuiTextureUploadFlags aFlags = EHuiTextureUploadFlagDefault); |
|
140 |
|
141 /** @endAPI */ |
|
142 |
|
143 /** |
|
144 * Delete the texture. |
|
145 */ |
|
146 void Reset(); |
|
147 |
|
148 void EnableShadow(TBool aEnable = ETrue); |
|
149 |
|
150 TBool IsShadowEnabled() const; |
|
151 |
|
152 TBool GetShadowTexture(THuiTextureHandle& aHandle) const; |
|
153 |
|
154 #ifdef __NVG |
|
155 /** |
|
156 * Creates a normal texture with the VGImage from extended texture |
|
157 * |
|
158 * @param aNvgEngine Used to draw the extended bitmap data on the VGImage, if ObjectCached icon wasn't found |
|
159 * @param aDestSize Destination size for the VGImage |
|
160 * @return Handle to the rasterized image or <code>VG_INVALID_HANDLE</code> if something went wrong. |
|
161 */ |
|
162 VGImage CreateRenderedImage(CNvgEngine* aNvgEngine, HBufC8* aNVGData, const TSize& aDestSize); |
|
163 |
|
164 /** |
|
165 * Identifies whether this texture contains extended texture data |
|
166 */ |
|
167 TBool IsExtended() const; |
|
168 |
|
169 /** |
|
170 * Gets the extended texture data. Prefer the GetIconCommandsData() instead. |
|
171 * |
|
172 * @return The OpenVG command buffer for the texture |
|
173 */ |
|
174 HBufC8* GetExtendedTextureData() const; |
|
175 |
|
176 /** |
|
177 * Gets the VG ObjectCached NVG icon, which can be drawn directly by calling the DrawL() method |
|
178 * |
|
179 * @return The OpenVG Object Cached NVG icon |
|
180 */ |
|
181 MNVGIcon* GetIconCommandsData() const; |
|
182 #endif |
|
183 |
|
184 protected: |
|
185 |
|
186 /* Constructors. */ |
|
187 |
|
188 /** |
|
189 * Constructor. Creates a new texture object with no texture maps. |
|
190 */ |
|
191 CHuiVg10Texture(CHuiVg10RenderPlugin& aRenderPlugin); |
|
192 |
|
193 /** |
|
194 * Second-phase constructor. |
|
195 * @param aRenderPlugin The render plugin that created this texture. |
|
196 */ |
|
197 void ConstructL(const THuiTextureHandle* aExistingTexture); |
|
198 |
|
199 |
|
200 /* Methods. */ |
|
201 |
|
202 /** |
|
203 * Deallocate resources associated with segment. Will free |
|
204 * all resources associated with a texture segment. |
|
205 * @see SetSegmentCount() |
|
206 */ |
|
207 virtual void ResetSegment(TInt aSegment); |
|
208 |
|
209 /** |
|
210 * Initialize segment for holding texture data. Allocate texture name etc. |
|
211 */ |
|
212 virtual void InitSegmentL(TInt aSegment); |
|
213 |
|
214 // from MHuiTexture |
|
215 |
|
216 void TextureExtension(const TUid& aExtensionUid, TAny** aExtensionParameters); |
|
217 |
|
218 private: |
|
219 /** |
|
220 * Define the contents of an image using raw data. |
|
221 * |
|
222 * @param aCreateImage If ETrue, a new image is created, otherwise an existing image is updated. |
|
223 * |
|
224 * @see SegmentPartialUpload |
|
225 */ |
|
226 void SegmentPartialUploadInternal(TInt aSegment, THuiTextureFormat aFormat, const TPoint& aOrigin, |
|
227 const TSize& aSize, const TUint8* aBuffer, TBool aCreateImage); |
|
228 |
|
229 |
|
230 /** |
|
231 * Generate a shadow for this texture if shadowing is enabled. |
|
232 */ |
|
233 void GenerateShadowL(); |
|
234 |
|
235 /** |
|
236 * Make sure the shadow texture is of the proper dimensions. |
|
237 */ |
|
238 void UpdateShadowSizeL(const TSize& aSize); |
|
239 |
|
240 /** The render plugin that created this texture. */ |
|
241 CHuiVg10RenderPlugin& iRenderPlugin; |
|
242 |
|
243 /** Flags indicating the state of the image object */ |
|
244 TInt iInternalFlags; |
|
245 |
|
246 /** Shadow texture */ |
|
247 THuiTextureHandle iShadow; |
|
248 |
|
249 /** Should a shadow texture be generated */ |
|
250 TBool iShadowEnabled; |
|
251 |
|
252 #ifdef __NVG |
|
253 /** |
|
254 * Reads the NVG data from the extended CFbsBitmap |
|
255 * |
|
256 * @param aBitmap The extended bitmap, which carries the NVG data to be read |
|
257 * @return The read NVG data in a 8-bit descriptor |
|
258 */ |
|
259 HBufC8* ReadNVGDataL(const CFbsBitmap& aBitmap); |
|
260 |
|
261 /** |
|
262 * Compares two NVG data buffers. Ignores the iconheader part. |
|
263 */ |
|
264 TInt CompareNvgData(HBufC8* aNVGData1, HBufC8* aNVGData2); |
|
265 |
|
266 /** |
|
267 * Uploads the NVG data into the texture. |
|
268 * |
|
269 * @param aBitmap The bitmap that is to be uploaded. Includes the extended NVG data. |
|
270 * @param aFlags Texture upload flags, either EHuiTextureUploadFlagUsePureNvg => upload as object cached NVG. Otherwise will be rasterized into VGImage. |
|
271 */ |
|
272 void SegmentUploadNvgL(const CFbsBitmap& aBitmap, const CFbsBitmap* aMaskBitmap, THuiTextureUploadFlags aFlags); |
|
273 |
|
274 /** |
|
275 * Create the Object cached icon out of the NVG data. Does the parsing of the icon header as well. |
|
276 */ |
|
277 void CreateObjCachedNVGIconL(); |
|
278 |
|
279 /** |
|
280 * Parses the NVG icon header out of the NVG data. |
|
281 * |
|
282 * @param aNVGData The NVG formatted data, from which to parse the icon header |
|
283 * @return The iconheader information |
|
284 */ |
|
285 TAknIconHeader GetNvgIconHeader(HBufC8* aNVGData); |
|
286 |
|
287 /** |
|
288 * This method has to be called before calling nvgEngine->DrawNvg(). |
|
289 * |
|
290 * @param aNVGData Nvg data buffer |
|
291 * @return Descriptor to the NVG data without the additional header information. |
|
292 */ |
|
293 TPtr8 GetNvgDataWithoutHeader(HBufC8* aNVGData); |
|
294 |
|
295 /** |
|
296 * Sets the NVG icon aspect ratio and rotation (from the NVG icon header). |
|
297 * |
|
298 * @param aNvgEngine NvgEngine instance used for setting the aspect ratio. |
|
299 * @param aNVGData Nvg data buffer |
|
300 * @param aIgnoreAspectRatio Use this, if you want to set the rotation, but ignore the aspect ratio. |
|
301 */ |
|
302 void SetNvgParamsFromIconHeader(CNvgEngine& aNvgEngine, HBufC8* aNVGData); |
|
303 |
|
304 /** |
|
305 * Calculates new iconsize that will have at least the required 12% margin. |
|
306 * |
|
307 * @param aVgImage Image that has been rasterized from the NvgData, used for determining if there's enough margin or not |
|
308 * @param aSize Size for drawing the image. Used as a base for margin calculations. |
|
309 * @param aDisplay EGLDisplay, needed for making the VGImage based ClientPBuffer current again. |
|
310 * @param aSurface EGLSurface, -||- |
|
311 * @param aContext EGLContext, -||- |
|
312 * @return New size with the correct margin. |
|
313 */ |
|
314 TSize ApplyMargin(VGImage aVgImage, TSize aSize, EGLDisplay aDisplay, EGLSurface aSurface, EGLContext aContext); |
|
315 |
|
316 /** |
|
317 * Sets the color for the icon, if such is defined in the icon header. |
|
318 * |
|
319 * @param aSrcImage Image that has been rasterized from the NvgData, used as a source for the color transformation. |
|
320 * Will be replaced by the new image got from transformation. |
|
321 * @param aSize Size for creating destination image. |
|
322 * @param aColor Color from the iconheader, used to fill the icon with it. |
|
323 */ |
|
324 void SetIconColor(VGImage& aSrcImage, TSize aSize, TUint32 aColor); |
|
325 |
|
326 /** |
|
327 * Replaces the alpha channel information within aImage, with the alpha mask |
|
328 * information from the aMaskImage. Both images have to be in VG_sARGB_8888 format. |
|
329 * |
|
330 * @param aImage VGImage, which's alpha channel is to be replaced. |
|
331 * @param aMaskImage a mask VGImage. |
|
332 * @param aSize Size of the images. |
|
333 */ |
|
334 void ReplaceVGImageAlphaChannelL(VGImage aImage, VGImage aMaskImage, TSize aSize); |
|
335 |
|
336 /* |
|
337 * Assertains that all texture uploads are done into the same EGL context as the first upload. |
|
338 * Changes context if necessary. |
|
339 */ |
|
340 void PushEGLContext(); |
|
341 |
|
342 /* |
|
343 * Rolls back to the previous EGL context, if necessary. |
|
344 */ |
|
345 void PopEGLContext(); |
|
346 |
|
347 // Rolling back to state for PopEGLContext |
|
348 TEGLState iPreviousEGLState; |
|
349 |
|
350 /** Identifies whether this texture has extended bitmap NVG data **/ |
|
351 TBool iIsExtended; |
|
352 |
|
353 /** Carries the extended NVG data, if any **/ |
|
354 HBufC8* iNVGData; |
|
355 |
|
356 /** |
|
357 * Stores the ObjectCached VG commands, which are ready to be drawn without |
|
358 * the need to parse the NVG data and create the VG objects again |
|
359 */ |
|
360 MNVGIcon* iIconCommands; |
|
361 #endif |
|
362 |
|
363 }; |
|
364 |
|
365 #endif // __HUIVG10TEXTURE_H__ |