|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Declares CHuiTexture texture base class and THuiTextureFormat |
|
15 * texture data buffer formats. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __HUITEXTURE_H__ |
|
22 #define __HUITEXTURE_H__ |
|
23 |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <e32std.h> |
|
27 #include <gdi.h> |
|
28 |
|
29 #include <uiacceltk/HuiTextureIf.h> |
|
30 #include <uiacceltk/HuiTextureHandle.h> |
|
31 #include <uiacceltk/HuiSegmentedTexture.h> |
|
32 #include <uiacceltk/HuiShadowedTexture.h> |
|
33 #include <uiacceltk/HuiObserverArray.h> |
|
34 #include <uiacceltk/HuiSessionObject.h> |
|
35 #include <uiacceltk/HuiRealSize.h> |
|
36 #include <uiacceltk/huitextureautosizeparams.h> |
|
37 |
|
38 // Uids for the extension functions used by TextureExtension() |
|
39 const TUid KHuiTextureExtUid_UploadDirectL = {0x200100C3}; |
|
40 |
|
41 /* Forward declaration. */ |
|
42 class CHuiTexture; |
|
43 |
|
44 |
|
45 /** |
|
46 * Texture content observing interface. |
|
47 */ |
|
48 class MHuiTextureContentObserver |
|
49 { |
|
50 public: |
|
51 |
|
52 virtual ~MHuiTextureContentObserver() |
|
53 { |
|
54 } |
|
55 |
|
56 /** |
|
57 * Called when new content has been uploaded to the specified texture. |
|
58 * |
|
59 * The implementor should call the relevant methods in CHuiTexture to |
|
60 * get more information about the new content (CFbsBitmaps or raw data; |
|
61 * these are available while the notification is taking place). |
|
62 * |
|
63 * @param aTexture Texture that has received new content. |
|
64 */ |
|
65 virtual void TextureContentUploaded(CHuiTexture& aTexture) = 0; |
|
66 |
|
67 /** |
|
68 * Called when the texture's content has been released. |
|
69 * |
|
70 * @param aTexture Texture that has been released. |
|
71 */ |
|
72 virtual void TextureContentReleased(CHuiTexture& aTexture) = 0; |
|
73 |
|
74 /** |
|
75 * Called when the content of the texture needs to be restored to the |
|
76 * same state it was when the texture was released. |
|
77 * |
|
78 * @param aTexture Texture that has been restored. |
|
79 */ |
|
80 virtual void RestoreTextureContentL(CHuiTexture& aTexture) = 0; |
|
81 |
|
82 }; |
|
83 |
|
84 |
|
85 |
|
86 /** |
|
87 * CHuiTexture is the base class for all texture objects. It implements |
|
88 * the MHuiSegmentedTexture interface for multipart support. Multi-segment |
|
89 * textures can be operated in the same way as one would operate |
|
90 * single-segment textures. |
|
91 * |
|
92 * The application will only need to call a method with "Segment" in its name |
|
93 * if it explicitly wants to manipulate a specific segment in a texture. |
|
94 * (E.g., when it wants to upload a new sub-texture into the segment.) |
|
95 * |
|
96 * The base class enables CHuiTexture to handle large textures as smaller |
|
97 * texture segments. Each segment has a position, dimensions, and a name that |
|
98 * identifies the texture image of the segment. The purpose is that it is |
|
99 * possible to compose large images out of smaller segments. The segments can |
|
100 * overlap. |
|
101 * |
|
102 * One use case is where the OpenGL texture size is limited (e.g., 256x256). |
|
103 * CHuiTexture can split the uploaded source image to multiple |
|
104 * segments and create a different OpenGL texture for each. All of the segments |
|
105 * are hidden inside CHuiTexture, though, so it could be treated as |
|
106 * a single entity. |
|
107 * |
|
108 * A CHuiTexture always represents one or more fully loaded (OpenGL ES) texture |
|
109 * objects. When drawing something, THuiImages are used for determining the |
|
110 * area of the texture to draw. However, different segments may utilize |
|
111 * textures in different resolutions. |
|
112 * |
|
113 * @see THuiImage |
|
114 * @see CHuiGc |
|
115 * |
|
116 */ |
|
117 class CHuiTexture : public CBase, public MHuiTexture, |
|
118 public MHuiSegmentedTexture, public MHuiShadowedTexture, |
|
119 public MHuiSessionObject |
|
120 { |
|
121 public: |
|
122 |
|
123 /* Constructors and destructor. */ |
|
124 |
|
125 /** @beginAPI */ |
|
126 |
|
127 /** |
|
128 * Exported static factory method. Creates a texture appropriate for the current |
|
129 * renderer. |
|
130 */ |
|
131 IMPORT_C static CHuiTexture* NewL(const THuiTextureHandle* aExistingTexture = 0); |
|
132 |
|
133 /** |
|
134 * Exported static factory method. Creates a texture appropriate for the current |
|
135 * renderer. |
|
136 */ |
|
137 IMPORT_C static CHuiTexture* NewLC(const THuiTextureHandle* aExistingTexture = 0); |
|
138 |
|
139 /** |
|
140 * Destructor. |
|
141 */ |
|
142 IMPORT_C ~CHuiTexture(); |
|
143 |
|
144 |
|
145 public: // new methods |
|
146 /** |
|
147 * Returns the file name of the texture's source image (if any). |
|
148 */ |
|
149 IMPORT_C const TDesC& ImageFileName() const; |
|
150 |
|
151 /** |
|
152 * Determines whether the texture has content. Only textures that |
|
153 * have content can be drawn. |
|
154 * |
|
155 * Note that a texture that has not finished loading will return EFalse |
|
156 * here, because its content will only become available after it has |
|
157 * been fully loaded. |
|
158 * |
|
159 * @return ETrue, if this texture has content. |
|
160 */ |
|
161 IMPORT_C virtual TBool HasContent() const; |
|
162 |
|
163 |
|
164 |
|
165 /* CHuiTexture pure virtual methods (interface methods). */ |
|
166 |
|
167 /** |
|
168 * Determines if the texture has an alpha channel. |
|
169 * |
|
170 * @return <code>ETrue</code>, if the texture has an alpha channel. |
|
171 * Otherwise, <code>EFalse</code>. |
|
172 */ |
|
173 virtual TBool HasAlpha() const = 0; |
|
174 |
|
175 /** |
|
176 * Determines the maximum possible actual (OpenGL/in-memory) size for |
|
177 * textures. Typically returns power-of-two dimensions. This limit is |
|
178 * usually set by the underlying graphics driver/hardware. |
|
179 */ |
|
180 virtual TSize MaxTextureSize() const = 0; |
|
181 |
|
182 /** |
|
183 * Uploads texture data from an FBS bitmap onto this texture. |
|
184 * |
|
185 * Bitmap to texture upload consists of the following tasks: |
|
186 * <ul> |
|
187 * <li> Setups the texture (logical) size.</li> |
|
188 * <li> Calculates if segmentation is needed, and setups the segments |
|
189 * (as necessary / optional).</li> |
|
190 * <li> Convert / downscale and crop the bitmap data to create bitmap(s) |
|
191 * suitable for uploading.</li> |
|
192 * <li> Transfers bitmap data to the graphics device driver. |
|
193 * </ul> |
|
194 * |
|
195 * If the texture uses EHuiTextureFlagAllowDirectBitmapUsage flag, the method |
|
196 * CHuiTextureManager::UpdateTextureFromBitmapL() should be used instead. This |
|
197 * method leaves with KErrNotSupported in that case. |
|
198 * |
|
199 * @param aBitmap Bitmap to copy image contents and format from |
|
200 * (RGB data). The support for input CFbsBitmap formats |
|
201 * varies between different renderers. |
|
202 * See \ref cfbsbitmapsupport Table describing renderer |
|
203 * bitmap support. |
|
204 * |
|
205 * @param aMaskBitmap Optional Bitmap for alpha (transparency) channel. |
|
206 * If the image does not require an alpha channel or the |
|
207 * aBitmap already has alpha information (RGBA image) |
|
208 * this value may be left as NULL. The bitmap will be |
|
209 * combined with aBitmap to single RGBA image. If used, |
|
210 * this alpha mask bitmap will replace any alpha |
|
211 * information in aBitmap. |
|
212 * |
|
213 * @param aFlags Specify texture upload behavior - how to convert the |
|
214 * bitmap to texture. You can OR these flags together. |
|
215 * |
|
216 * If the UploadL runs out of memory while uploading/converting |
|
217 * the method may try to upload with smaller bitmap sizes and |
|
218 * force use of more memory-efficient single-segment texture. |
|
219 * |
|
220 * @see SetSize() Use if you want to change the logical size (for example to |
|
221 * fix the aspect ratio of the bitmap) of the texture after uploading. |
|
222 */ |
|
223 virtual void UploadL(const CFbsBitmap& aBitmap, |
|
224 const CFbsBitmap * aMaskBitmap = NULL, |
|
225 THuiTextureUploadFlags aFlags = EHuiTextureUploadFlagDefault) = 0; |
|
226 |
|
227 /** |
|
228 * Uploads bitmap data onto this texture. |
|
229 * |
|
230 * Bitmap to texture upload consists of the following tasks: |
|
231 * <ul> |
|
232 * <li> Setups the texture (logical) size.</li> |
|
233 * <li> Transfers bitmap data to the graphics device driver. |
|
234 * </ul> |
|
235 * |
|
236 * Note: This method does NOT support texture segmentation. See the |
|
237 * CFbsBitmap upload methods (UploadL()) to create segmented textures. |
|
238 * |
|
239 * @param aFormat Format of aBuffer, the image data buffer. |
|
240 * @param aSize Size (width and height in pixels) of the texture in the |
|
241 * data buffer (aBuffer). |
|
242 * @param aBuffer Source Image data buffer. |
|
243 * @param aFlags Specify upload behavior - how to convert the bitmap to texure. |
|
244 * |
|
245 * @param aBufferSize Length of the compressed image data. Set as 0 for |
|
246 * non-compressed formats. |
|
247 */ |
|
248 virtual void UploadL(THuiTextureFormat aFormat, |
|
249 const TSize& aSize, |
|
250 const TUint8* aBuffer, |
|
251 THuiTextureUploadFlags aFlags = EHuiTextureUploadFlagDefault, |
|
252 TUint aBufferSize = 0) = 0; |
|
253 |
|
254 /** |
|
255 * Updates a partial area of this texture. Does not change the |
|
256 * dimensions of the texture (logical size or segmentation). |
|
257 * |
|
258 * @note You must first call Upload() at least once so the texture object |
|
259 * has dimensions. |
|
260 * |
|
261 * No local copy of the buffer data |
|
262 * is made. |
|
263 * |
|
264 * @note Does not work with multisegmented textures! |
|
265 * |
|
266 * @param aFormat Format of the data buffer. |
|
267 * @param aOrigin Position to place the partial texture data. |
|
268 * @param aSize Size of the texture in the data buffer. |
|
269 * @param aBuffer Texture data buffer. |
|
270 */ |
|
271 virtual void PartialUploadL(THuiTextureFormat aFormat, |
|
272 const TPoint& aOrigin, |
|
273 const TSize& aSize, |
|
274 const TUint8* aBuffer) = 0; |
|
275 |
|
276 /** |
|
277 * Clears the texture object and initializes it with solid color pixels. Will |
|
278 * setup the logical size and reserve space for the texture if size and |
|
279 * segmentation has not yet been prepared. |
|
280 * |
|
281 * @param aSize Size of the texture. Does not matter if the size |
|
282 * and segmentation of this texture has already been set up. |
|
283 * @param aColor Initial color of the texture. |
|
284 * @return System error code if task failed and KErrNone if successful. |
|
285 */ |
|
286 IMPORT_C TInt ClearL(const TSize& aSize, const TRgb& aColor); |
|
287 |
|
288 /** |
|
289 * Clears the texture object and initializes it with solid color pixels. |
|
290 * The texture will be initialized with alpha data. Will |
|
291 * setup the logical size and reserve space for the texture, if needed. |
|
292 * |
|
293 * @param aSize Size of the texture. Does not matter if the size |
|
294 * and segmentation of this texture has already been set up. Use |
|
295 * Reset() before calling Clear() to change the texture resolution and |
|
296 * dimensions. |
|
297 * @param aColor Initial color of the texture. |
|
298 * @param aAlpha Initial alpha level of the texture. |
|
299 * @return System error code if task failed and KErrNone if successful. |
|
300 */ |
|
301 IMPORT_C TInt ClearWithAlphaL(const TSize& aSize, const TRgb& aColor, TUint8 aAlpha); |
|
302 |
|
303 |
|
304 |
|
305 /** |
|
306 * @internal |
|
307 * |
|
308 * Creates shadow with given parameters. If the shadow already exists with the |
|
309 * given paramters, this function does not do a thing. |
|
310 * |
|
311 * @param aBlurDimension 2*radius used by the blur filter |
|
312 * @param aStyle Defines the used shadow texture size |
|
313 */ |
|
314 void CreateShadowTextureL( TInt aBlurDimension, THuiShadowStyle aStyle ); |
|
315 |
|
316 /** |
|
317 * @internal |
|
318 * |
|
319 * Fetches shadow with given parameters. |
|
320 * |
|
321 * @param aHandle Will be filled with the shadow information if found. |
|
322 * i.e. the function returns ETrue, |
|
323 * @param aBlurDimension 2*radius used by the blur filter |
|
324 * |
|
325 * @return ETrue if a shadow texture is found with the given dimension. |
|
326 */ |
|
327 TBool GetShadowTexture( THuiTextureHandle& aHandle, TInt aBlurDimension ) const; |
|
328 |
|
329 |
|
330 public: // from baseclasses |
|
331 |
|
332 /* Implementation of MHuiTexture. */ |
|
333 |
|
334 IMPORT_C MHuiSegmentedTexture* SegmentedTexture(); |
|
335 |
|
336 IMPORT_C const MHuiSegmentedTexture* SegmentedTexture() const; |
|
337 |
|
338 IMPORT_C MHuiShadowedTexture* ShadowedTexture(); |
|
339 |
|
340 IMPORT_C const MHuiShadowedTexture* ShadowedTexture() const; |
|
341 |
|
342 /* Implementation of MHuiShadowedTexture. */ |
|
343 |
|
344 // @deprecated |
|
345 IMPORT_C virtual void EnableShadow(TBool aEnable = ETrue); |
|
346 |
|
347 // @deprecated |
|
348 IMPORT_C virtual TBool IsShadowEnabled() const; |
|
349 |
|
350 /** |
|
351 * Sets the shadow generation style of the texture. |
|
352 * |
|
353 * @param aShadowStyle Shadowing style. |
|
354 */ |
|
355 IMPORT_C virtual void SetShadowStyle(THuiShadowStyle aShadowStyle); |
|
356 |
|
357 /** |
|
358 * Determines the current shadow style. |
|
359 */ |
|
360 IMPORT_C THuiShadowStyle ShadowStyle() const; |
|
361 |
|
362 IMPORT_C TBool GetShadowTexture(THuiTextureHandle& aHandle) const; |
|
363 |
|
364 |
|
365 /** |
|
366 * Set the logical dimensions of the texture. This is the original size |
|
367 * of the image loaded as a texture. Also will update (resize) the |
|
368 * logical sizes and offsets of texture segments, if such segments have |
|
369 * been previously configured. |
|
370 * |
|
371 * @see Size() Use to check the logical size of the texture. |
|
372 */ |
|
373 IMPORT_C virtual void SetSize(const TSize& aSize); |
|
374 |
|
375 |
|
376 /* Implementation of MHuiSegmentedTexture. */ |
|
377 |
|
378 /** |
|
379 * Return logical dimensions of texture. |
|
380 * @return The logical dimensions of the texture. |
|
381 * @see SetSize() |
|
382 */ |
|
383 |
|
384 IMPORT_C TSize Size() const; |
|
385 |
|
386 /** |
|
387 * Number of segments in the texture. |
|
388 * @return The number of segments in the texture. |
|
389 */ |
|
390 IMPORT_C TInt SegmentCount() const; |
|
391 |
|
392 /** |
|
393 * ID of the given segment. |
|
394 * @param aSegment The ordinal of the segment that we want the name of. |
|
395 * @return The ID of the segment at the passed ordinal. |
|
396 */ |
|
397 IMPORT_C TUint SegmentName(TInt aSegment) const; |
|
398 |
|
399 /** |
|
400 * Return logical dimensions of a segment. |
|
401 * @param aSegment The ordinal of the segment that we want the dimensions of. |
|
402 * @return The logical dimensions of the segment. |
|
403 */ |
|
404 IMPORT_C TSize SegmentSize(TInt aSegment) const; |
|
405 |
|
406 /** |
|
407 * Return texture dimensions of a segment. |
|
408 * @param aSegment The ordinal of the segment that we want the texture dimensions of. |
|
409 * @return The dimensions of the segment's texture. |
|
410 */ |
|
411 IMPORT_C TSize SegmentTextureSize(TInt aSegment) const; |
|
412 |
|
413 /** |
|
414 * Return offset of a segment. |
|
415 * @param aSegment The ordinal of the segment that we want the offset of. |
|
416 * @return The the segment's offset. |
|
417 */ |
|
418 IMPORT_C TPoint SegmentOffset(TInt aSegment) const; |
|
419 |
|
420 /** |
|
421 * Has texture changed. |
|
422 * Check if the texture has changed since the last update. |
|
423 * @return ETrue if the texture has changed. |
|
424 */ |
|
425 IMPORT_C virtual TBool TextureChanged() const; |
|
426 |
|
427 /** |
|
428 * Set texture as not changed. |
|
429 * Clear the changed flag of this texture once changes have been handled. |
|
430 * @see TextureChanged() |
|
431 */ |
|
432 IMPORT_C virtual void TextureClearChanged() const; |
|
433 |
|
434 /** |
|
435 * Set texture as (not) changed. |
|
436 * Clear the changed flag of this texture once changes have been handled. |
|
437 * @see TextureChanged() |
|
438 */ |
|
439 IMPORT_C void SetTextureChanged(TBool aChanged); |
|
440 |
|
441 /* Segmented texture data methods. */ |
|
442 |
|
443 /** |
|
444 * Sets the number of segments. Will delete/create new segments as |
|
445 * needed. |
|
446 * |
|
447 * @param aSegmentCount Number of segments. |
|
448 */ |
|
449 IMPORT_C virtual void SetSegmentCountL(TInt aSegmentCount); |
|
450 |
|
451 /** |
|
452 * Sets the name of a segment. |
|
453 */ |
|
454 IMPORT_C virtual void SetSegmentName(TInt aSegment, TUint aName); |
|
455 |
|
456 /** |
|
457 * Sets the size of a segment. |
|
458 */ |
|
459 IMPORT_C virtual void SetSegmentSize(TInt aSegment, const TSize& aSegmentSize); |
|
460 |
|
461 /** |
|
462 * Sets the texture size of the segment. |
|
463 * |
|
464 * @param aSegment Valid segment index for this texture. |
|
465 */ |
|
466 IMPORT_C virtual void SetSegmentTextureSize(TInt aSegment, const TSize& aSegmentTextureSize); |
|
467 |
|
468 /** |
|
469 * Sets the logical offset of a texture segment. |
|
470 * |
|
471 * @param aSegment Valid segment index for this texture. |
|
472 * @param aOffset Offset of the texture segment. Must be inside the logical |
|
473 * dimensions of the whole texture. |
|
474 */ |
|
475 IMPORT_C virtual void SetSegmentOffset(TInt aSegment, const TPoint& aOffset); |
|
476 |
|
477 /** |
|
478 * Defines whether the texture is of skin content or not. If this texture is |
|
479 * a part of skin content this texture will be released and restored whenever |
|
480 * CHuiEnv::NotifySkinChangedL is called. This allows skin specific texture |
|
481 * observers to update the content of this texture depending on the skin and |
|
482 * it's parameters. Textures that are not part of skin content will be inaffected |
|
483 * by the call to the CHuiEnv::NotifySkinChangedL. |
|
484 * |
|
485 * @see CHuiEnv::NotifySkinChangedL() |
|
486 * @see IsSkinContent() |
|
487 * |
|
488 * @param aSkinContent ETrue to set this texture as part of skin content. EFalse |
|
489 * to mark that this texture is not part of skin content. |
|
490 */ |
|
491 IMPORT_C virtual void SetSkinContent(TBool aSkinContent); |
|
492 |
|
493 /** |
|
494 * Informs whether this texture is part of skin content or not. By default textures |
|
495 * are not part of skin content. |
|
496 * |
|
497 * @see SetSkinContent() |
|
498 * |
|
499 * @return ETrue if this texture is part of skin content, EFalse otherwise. |
|
500 */ |
|
501 IMPORT_C virtual TBool IsSkinContent() const; |
|
502 |
|
503 /* CHuiTexture segmentation pure virtual methods (interface methods). */ |
|
504 |
|
505 /** |
|
506 * Calculates and sets up segmentation for given size. If |
|
507 * the given size exceeds the available maximum texture |
|
508 * size, the area is split up to segments having dimensions no |
|
509 * more than the maximum texture size. |
|
510 * |
|
511 * @param aLogicalSize Logical size of the full image. |
|
512 * @param aTextureSize Texture resolution required, in pixels. |
|
513 * @param aUploadFlags Specify segmentation behavior - how the uploaded |
|
514 * data is laid out to a texture. |
|
515 */ |
|
516 virtual void SetupSegmentsL(const TSize& aLogicalSize, |
|
517 const TSize& aTextureSize, |
|
518 THuiTextureUploadFlags aFlags = EHuiTextureUploadFlagDefault) = 0; |
|
519 |
|
520 /** |
|
521 * Uploads bitmap data onto a texture segment. Does not |
|
522 * change the dimensions of the texture (logical size or segmentation). |
|
523 * |
|
524 * This method allows direct access to texture segments. @see UploadL() |
|
525 * if you do not care about texture segmentation. |
|
526 * |
|
527 * @note The image segment has to have valid dimensions. |
|
528 * |
|
529 * @param aSegment Valid segment index for this texture. |
|
530 * @param aFormat Format of the image data buffer. |
|
531 * @param aSize Size (width and height in pixels) of the texture in the |
|
532 * data buffer (aBuffer). |
|
533 * @param aBuffer Image data buffer. |
|
534 * @param aBufferSize Length of the compressed image data. Set as 0 for |
|
535 * non-compressed formats. |
|
536 */ |
|
537 virtual void SegmentUploadL(TInt aSegment, |
|
538 THuiTextureFormat aFormat, |
|
539 const TSize& aSize, |
|
540 const TUint8* aBuffer, |
|
541 TUint aBufferSize = 0) = 0; |
|
542 |
|
543 /** |
|
544 * Uploads FBS bitmap data onto a texture segment. Does not |
|
545 * change the dimensions of the texture (logical size or segmentation). |
|
546 * |
|
547 * This method allows direct access to texture segments. @see UploadL() |
|
548 * if you do not care about texture segmentation. |
|
549 * |
|
550 * @note The image segment has to have valid dimensions. |
|
551 * |
|
552 * @param aSegment Valid segment index for this texture. |
|
553 * @param aBitmap Bitmap to copy image contents and format from |
|
554 * (RGB data). |
|
555 * @param aMaskBitmap Optional Bitmap for alpha (transparency) channel. |
|
556 * If the image does not require an alpha channel or the |
|
557 * aBitmap already has alpha information (RGBA image) |
|
558 * this value may be left as NULL. The bitmap will be |
|
559 * combined with aBitmap to single RGBA image. If used, |
|
560 * this alpha mask bitmap will replace any alpha |
|
561 * information in aBitmap. |
|
562 * @param aFlags Specify how the uploaded data is laid out to a |
|
563 * texture. |
|
564 */ |
|
565 virtual void SegmentUploadL(TInt aSegment, |
|
566 const CFbsBitmap& aBitmap, |
|
567 const CFbsBitmap * aMaskBitmap = NULL, |
|
568 THuiTextureUploadFlags aFlags = EHuiTextureUploadFlagDefault) = 0; |
|
569 |
|
570 /** |
|
571 * Updates a partial area to a texture segment. Does not change the |
|
572 * dimensions of the texture (logical size or segmentation). |
|
573 * |
|
574 * This method allows direct access to texture segments. |
|
575 * @see PartialUploadL() if you do not care about texture segmentation. |
|
576 |
|
577 * @note You must first call Upload() at least once so the texture object |
|
578 * has dimensions and at least one segment to be updated. |
|
579 * |
|
580 * No local copy of the buffer data is made. |
|
581 * |
|
582 * @param aSegment Valid segment index for this texture. |
|
583 * @param aFormat Format of the data buffer. |
|
584 * @param aOrigin Position to place the partial texture data. |
|
585 * @param aSize Size of the texture in the data buffer. |
|
586 * @param aBuffer Texture data buffer. |
|
587 */ |
|
588 virtual void SegmentPartialUpload( |
|
589 TInt aSegment, |
|
590 THuiTextureFormat aFormat, |
|
591 const TPoint& aOrigin, |
|
592 const TSize& aSize, |
|
593 const TUint8* aBuffer) = 0; |
|
594 |
|
595 /** |
|
596 * Clear a texture segment to a solid color. |
|
597 */ |
|
598 virtual void SegmentClearL(TInt aSegment, |
|
599 TBool aWithAlpha, |
|
600 const TRgb& aColor, |
|
601 TUint8 aAlpha) = 0; |
|
602 |
|
603 |
|
604 // Implementation of MHuiSessionObject |
|
605 |
|
606 /** |
|
607 * Gets the object type. |
|
608 */ |
|
609 IMPORT_C TType Type() const; |
|
610 |
|
611 /** |
|
612 * Gets the session id for object. |
|
613 */ |
|
614 IMPORT_C TInt SessionId() const; |
|
615 |
|
616 /** |
|
617 * Sets the session id for object. |
|
618 */ |
|
619 IMPORT_C void SetSessionId(TInt aSessionId); |
|
620 |
|
621 /** @endAPI */ |
|
622 |
|
623 |
|
624 /** |
|
625 * Delete the texture. |
|
626 */ |
|
627 IMPORT_C virtual void Reset(); |
|
628 |
|
629 /** |
|
630 * Deletes the shadow textures. |
|
631 */ |
|
632 IMPORT_C void ResetShadows(); |
|
633 |
|
634 /** |
|
635 * Releases the texture. The caller is responsible of checking the |
|
636 * release priority of the texture. |
|
637 */ |
|
638 IMPORT_C virtual void Release(); |
|
639 |
|
640 /** |
|
641 * Restores the texture. |
|
642 */ |
|
643 IMPORT_C virtual void RestoreL(); |
|
644 |
|
645 /** |
|
646 * Sets the texture priority. The prioriry is used when the textures are |
|
647 * released/restored. |
|
648 * |
|
649 * @param aPriority 0 = never release |
|
650 * other values to be decided |
|
651 * By default != 0 |
|
652 */ |
|
653 IMPORT_C void SetPriority( TInt aPriority ); |
|
654 |
|
655 /** |
|
656 * Returns the priority of the texture |
|
657 * |
|
658 * @return The priority |
|
659 * |
|
660 * @see SetPriority() |
|
661 */ |
|
662 IMPORT_C TInt Priority() const; |
|
663 |
|
664 /** |
|
665 * Sets the placeholder texture. Set to zero to disable the placeholder. |
|
666 * |
|
667 * @param aPlaceholder Placeholder texture. |
|
668 */ |
|
669 void SetPlaceholder(THuiTextureHandle* aPlaceholder); |
|
670 |
|
671 /** |
|
672 * Generates a blob texture. The texture can be then used for drawing |
|
673 * shadow edges, for example. |
|
674 * |
|
675 * @param aSize Dimensions of the blob texture. |
|
676 */ |
|
677 void GenerateBlobL(const TSize& aSize); |
|
678 |
|
679 /** |
|
680 * Sets the file name of the texture's source image. |
|
681 * |
|
682 * @param aFileName Image file name. |
|
683 */ |
|
684 void SetImageFileNameL(const TDesC& aFileName); |
|
685 |
|
686 /** |
|
687 * Uploads the texture data to the texture. Allows using EHuiTextureFlagAllowDirectBitmapUsage flag, |
|
688 * but the caller have to take care of deleting the bitmaps. |
|
689 * |
|
690 * The bitmaps must be suitable for direct usage. Otherwise this can cause panic in rendering. |
|
691 * |
|
692 * @param aBitmap Bitmap to copy image contents from. |
|
693 * @param aMaskBitmap Optional Bitmap for alpha (transparency) channel. |
|
694 * @param aFlags Specify texture upload behavior. |
|
695 */ |
|
696 void UploadDirectL(const CFbsBitmap& aBitmap, const CFbsBitmap* aMaskBitmap, THuiTextureUploadFlags aFlags); |
|
697 |
|
698 /** |
|
699 * Notifies one size what would be the most optimal size for this texture. |
|
700 * This method can be called e.g. from some CHuiGc image drawing operation which knows |
|
701 * the excact size that the image appears in the display. |
|
702 * |
|
703 * @param aSize Auto size candidate. |
|
704 */ |
|
705 void NotifyPreferredSize(const THuiRealSize& aSize); |
|
706 |
|
707 /** |
|
708 * Clears auto size candidates that has been reported (during last frame). This |
|
709 * is called by the texture manager after each frame. |
|
710 */ |
|
711 void ResetAutoSizeCalculation(); |
|
712 |
|
713 /** |
|
714 * Flag to indicate that auto size calculations for this texture is enabled. |
|
715 * @return ETrue if auto size calculation is enabled. |
|
716 */ |
|
717 TBool IsAutoSizeCalculationEnabled() const; |
|
718 |
|
719 /** |
|
720 * Enables auto size calculations for this texture. |
|
721 * |
|
722 * Caller of this method may observe auto size changes through texture managers |
|
723 * MHuiTextureAutoSizeObserver interface. |
|
724 * |
|
725 * @param aEnable ETrue if auto size calculation is to be enabled. |
|
726 */ |
|
727 IMPORT_C void EnableAutoSizeCalculation(TBool aEnable=ETrue); |
|
728 |
|
729 /** |
|
730 * Checks if calculated auto size has been changed since last frame. |
|
731 * @return ETrue if calculated auto size is different than the size before last reset. |
|
732 */ |
|
733 TBool CalculatedAutoSizeChanged() const; |
|
734 |
|
735 /** |
|
736 * Calculates one size which is most optimal based on all the reported sizes. |
|
737 * @return Automatically determined size for this texture. |
|
738 */ |
|
739 THuiRealSize CalculateAutoSize(); |
|
740 |
|
741 /** |
|
742 * Sets parameters to be used when calculating auto size. |
|
743 * @param aParams New parameters. |
|
744 */ |
|
745 IMPORT_C void SetAutoSizeParams(const THuiTextureAutoSizeParams& aParams); |
|
746 |
|
747 /** |
|
748 * Gets parameters to be used when calculating auto size. |
|
749 * @return Currently used parameters. |
|
750 */ |
|
751 IMPORT_C THuiTextureAutoSizeParams AutoSizeParams() const; |
|
752 |
|
753 |
|
754 /** |
|
755 * Defines whether the texture is in NVG format or not. If the texture is in |
|
756 * NVG format, it will not eat up any texture memory. Also the autosizing |
|
757 * is being disabled by default, since the sizing is practically free with |
|
758 * NVG and OpenVG backend. |
|
759 * |
|
760 * @see EnableAutoSizeCalculation() |
|
761 * @see IsNVGContent() |
|
762 * |
|
763 * @param aNvgContent ETrue to set this texture as extended with NVG content. EFalse |
|
764 * to mark that this is not an extended texture. |
|
765 */ |
|
766 IMPORT_C void SetNvgContent(TBool aNvgContent); |
|
767 |
|
768 /** |
|
769 * Informs whether this texture is in NVG format or not. |
|
770 * |
|
771 * @see SetNvgContent() |
|
772 * |
|
773 * @return ETrue if this texture is extended and in NVG format, EFalse otherwise. |
|
774 */ |
|
775 IMPORT_C TBool IsNvgContent() const; |
|
776 |
|
777 |
|
778 protected: |
|
779 |
|
780 |
|
781 struct TExtParams_UploadDirectL |
|
782 { |
|
783 const CFbsBitmap& iBitmap; |
|
784 const CFbsBitmap* iMaskBitmap; |
|
785 THuiTextureUploadFlags iFlags; |
|
786 TInt iLeaveCode; |
|
787 }; |
|
788 |
|
789 |
|
790 protected: |
|
791 |
|
792 /* Constructors. */ |
|
793 |
|
794 /** |
|
795 * Constructor. Creates a new texture object with no texture maps. |
|
796 */ |
|
797 IMPORT_C CHuiTexture(); |
|
798 |
|
799 /** |
|
800 * Second-phase constructor. |
|
801 */ |
|
802 IMPORT_C void BaseConstructL(); |
|
803 |
|
804 |
|
805 /* Methods. */ |
|
806 |
|
807 /** |
|
808 * Set segment data. Note that the texture name is |
|
809 * allocated when calling InitSegmentL(). |
|
810 */ |
|
811 IMPORT_C virtual void SetSegment(TInt aSegment, |
|
812 const TSize & iSize, |
|
813 const TPoint & iOffset, |
|
814 const TSize & iTextureSize); |
|
815 |
|
816 |
|
817 /** |
|
818 * Deallocate resources associated with segment. Will free |
|
819 * all resources associated with a texture segment. |
|
820 * @see SetSegmentCount() |
|
821 */ |
|
822 virtual void ResetSegment(TInt aSegment) = 0; |
|
823 |
|
824 /** |
|
825 * Initialize segment for holding texture data. |
|
826 * Allocate texture name etc. |
|
827 */ |
|
828 virtual void InitSegmentL(TInt aSegment) = 0; |
|
829 |
|
830 // from MHuiTexture |
|
831 |
|
832 IMPORT_C void TextureExtension(const TUid& aExtensionUid, TAny** aExtensionParameters); |
|
833 |
|
834 |
|
835 private: |
|
836 |
|
837 /** Flags for texture state. */ |
|
838 enum THuiTextureFlags |
|
839 { |
|
840 /** Default flags. All special properties disabled. */ |
|
841 EHuiTextureFlagDefault = 0, |
|
842 |
|
843 /** |
|
844 * Shadow is enabled in the texture. |
|
845 */ |
|
846 EHuiTextureFlagShadowEnabled = 1, |
|
847 |
|
848 /** |
|
849 * Texture is included in the skin content. |
|
850 */ |
|
851 EHuiTextureFlagSkinContent = 2, |
|
852 |
|
853 EHuiTextureFlagAddedToTManager = 4, |
|
854 |
|
855 /** |
|
856 * Texture is extended and has NVG content |
|
857 */ |
|
858 EHuiTextureFlagNvgContent = 8 |
|
859 |
|
860 // note: next flag value is 16 (we use bit positions because |
|
861 // we want to be able to bitwise OR these together) |
|
862 }; |
|
863 |
|
864 /** |
|
865 * A subdivided segment of this texture. This may have its OpenGL texture |
|
866 * manipulated independently of its parent CHuiTexture. |
|
867 */ |
|
868 struct TSegment |
|
869 { |
|
870 /** Name of texture. */ |
|
871 TUint iName; |
|
872 /** Dimensions of texture. */ |
|
873 TSize iSize; |
|
874 /** Offset of segment within parent. */ |
|
875 TPoint iOffset; |
|
876 /** Size of the texture. */ |
|
877 TSize iTextureSize; |
|
878 }; |
|
879 |
|
880 /** |
|
881 * Resets and removes all texture segments |
|
882 */ |
|
883 void RemoveAllSegments(); |
|
884 |
|
885 public: |
|
886 |
|
887 /** |
|
888 * Array of content observers. |
|
889 */ |
|
890 RHuiObserverArray<MHuiTextureContentObserver> iContentObservers; |
|
891 TInt iFrameNumber; |
|
892 TInt iFrameCount; |
|
893 TInt iFrameInterval; |
|
894 |
|
895 |
|
896 private: |
|
897 |
|
898 /** Name of the image file where the texture was loaded from. */ |
|
899 HBufC* iImageFileName; |
|
900 |
|
901 /** Temporary texture to use until the real texture has been loaded.*/ |
|
902 THuiTextureHandle* iPlaceholder; |
|
903 |
|
904 /** Index of the active segment. */ |
|
905 mutable TInt iActiveSegment; |
|
906 |
|
907 /** Names of the segments. */ |
|
908 RArray<TSegment> iSegments; |
|
909 |
|
910 /** The logical size of this texture. */ |
|
911 TSize iSize; |
|
912 |
|
913 /** The internal texture state. Composed of THuiTextureFlags. */ |
|
914 TUint iInternalState; |
|
915 |
|
916 /** Shadow generation style. */ |
|
917 THuiShadowStyle iShadowStyle; |
|
918 |
|
919 /** Session id */ |
|
920 TInt iSessionId; |
|
921 |
|
922 /** Priority */ |
|
923 TInt iPriority; |
|
924 |
|
925 /** Flag to indicate that auto size calculations for this texture is enabled */ |
|
926 TBool iAutoSizeCalculationEnabled; |
|
927 |
|
928 /** Sizes reported for this texture during last frame */ |
|
929 RArray<THuiRealSize> iPreferredSizes; |
|
930 |
|
931 /** Most optimal size calculated based on all reported sizes */ |
|
932 THuiRealSize iCalculatedAutoSize; |
|
933 |
|
934 /** Previous most optimal size calculated based on all reported sizes */ |
|
935 THuiRealSize iCalculatedPreviousAutoSize; |
|
936 |
|
937 THuiTextureAutoSizeParams iAutoSizeParams; |
|
938 |
|
939 |
|
940 NONSHARABLE_STRUCT( TShadowData ) |
|
941 { |
|
942 CHuiTexture* iShadowTexture; |
|
943 TInt iBlurDimension; |
|
944 }; |
|
945 |
|
946 RArray<TShadowData> iShadows; |
|
947 |
|
948 mutable TBool iTextureChanged; |
|
949 }; |
|
950 |
|
951 #endif // __HUITEXTURE_H__ |