|
1 /* |
|
2 * Copyright (c) 2006 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: Loads textures. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef C_ALFTEXTUREMANAGER_H |
|
21 #define C_ALFTEXTUREMANAGER_H |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <e32cmn.h> |
|
25 #include <alf/alftexture.h> |
|
26 |
|
27 |
|
28 /* Forward declarations */ |
|
29 class CAlfEnv; |
|
30 class CAlfTextureProcessor; |
|
31 class CAlfTextureManager; |
|
32 class MAlfBitmapProvider; |
|
33 struct TLoadQueueEntry; |
|
34 struct TTextureEntry; |
|
35 |
|
36 /** |
|
37 * Special texture id, can be used to let CAlfTextureManager to assign |
|
38 * ids for textures when those are created or loaded. |
|
39 * |
|
40 * @see CAlfTextureManager |
|
41 */ |
|
42 const TInt KAlfAutoGeneratedTextureId = 0; |
|
43 |
|
44 /** |
|
45 * Texture release level. |
|
46 * |
|
47 * @see Release(), RestoreL() |
|
48 * @see CAlfTexture::SetPriority() |
|
49 */ |
|
50 enum TAlfTexturePriority |
|
51 { |
|
52 /** Texture is released only on destruction */ |
|
53 EAlfTexturePriorityHighest = 0, |
|
54 |
|
55 /** Texture is released on the background only if memory is running out */ |
|
56 EAlfTexturePriorityHigh = 1000, |
|
57 |
|
58 /** Texture is released when application goes into background */ |
|
59 EAlfTexturePriorityNormal= 2000, // = default |
|
60 |
|
61 /** Texture is released on the foreground if memory is running out */ |
|
62 EAlfTexturePriorityLow= 3000 |
|
63 }; |
|
64 |
|
65 /** |
|
66 * Provides callback methods for getting notifications when texture manager |
|
67 * finishes asynchronous texture loads. An observer of a CAlfTextureManager. |
|
68 * |
|
69 * The class willing to receive these events must implement the methods |
|
70 * of this interface, and then register itself to the obsevers list of |
|
71 * the texture manager. |
|
72 * |
|
73 * @see CAlfTextureManager |
|
74 */ |
|
75 class MAlfTextureLoadingCompletedObserver |
|
76 { |
|
77 public: |
|
78 /** |
|
79 * Called to notify the observer that loading of a texture has |
|
80 * been completed. |
|
81 * @param aTexture Reference to the texture that has been loaded. |
|
82 * @param aTextureId Id of the texture in the texture manager. Can be used |
|
83 * to identify the loaded texture, provided that an id was assigned to the |
|
84 * texture. |
|
85 * @param aErrorCode KErrNone if the load was successful, otherwise one of |
|
86 * the system-wide error codes indicating reason why the texture loading |
|
87 * failed. |
|
88 * @note One should not commence loading of a new texture in this callback method. |
|
89 */ |
|
90 virtual void TextureLoadingCompleted(CAlfTexture& aTexture, |
|
91 TInt aTextureId, |
|
92 TInt aErrorCode) = 0; |
|
93 |
|
94 }; |
|
95 |
|
96 /** |
|
97 * Provides callback methods for getting notifications of texture manager state |
|
98 * changes. An observer of a CAlfTextureManager. |
|
99 * |
|
100 * @see CAlfTextureManager |
|
101 */ |
|
102 class MAlfTextureManagerStateChangedObserver |
|
103 { |
|
104 public: |
|
105 /** |
|
106 * Called to notify the observer that the state of the texture manager |
|
107 * has changed. This is called when the state changes between Idle and |
|
108 * Loading. |
|
109 * |
|
110 * @param aManager Texture manager. |
|
111 */ |
|
112 virtual void TextureManagerStateChanged(const CAlfTextureManager& aManager) = 0; |
|
113 |
|
114 }; |
|
115 |
|
116 |
|
117 |
|
118 /** |
|
119 * Provides callback methods for getting notifications when texture manager |
|
120 * notices a texture which preferrred size is changed. |
|
121 * |
|
122 * The class willing to receive these events must implement the methods |
|
123 * of this interface, and then register itself to the obsevers list of |
|
124 * the texture manager. |
|
125 * |
|
126 */ |
|
127 class MAlfTextureAutoSizeObserver |
|
128 { |
|
129 public: |
|
130 /** |
|
131 * Called to notify the observer that the preferred size of some texture |
|
132 * has been changed. |
|
133 * |
|
134 * @param aChangedTexture Texture which preferred size has changed. |
|
135 * @param aPreferredSize preferred size for texture. |
|
136 * @return ETrue if observer accepts new size, EFalse if it does not accept or |
|
137 * doesn't care. |
|
138 */ |
|
139 virtual TBool PreferredSizeChanged(const CAlfTexture& aChangedTexture, TSize aPreferredSize) = 0; |
|
140 }; |
|
141 |
|
142 |
|
143 /** |
|
144 * CAlfTextureManager is responsible for managing the texture objects used by |
|
145 * the application. It provides asynchronous loading of image data into |
|
146 * CAlfTexture instances. The texture manager also manages font textures, |
|
147 * which can be used for compositing text in text meshes. |
|
148 * |
|
149 * The texture manager makes sure that only one copy of each image is loaded |
|
150 * at a time, so even if the application requests the same image several times |
|
151 * it is only loaded once. Textures are identified either by an integer ID or |
|
152 * by their file name. |
|
153 * |
|
154 * CAlfTextureManager is owned by CAlfEnv, and should be accessed via a |
|
155 * CAlfEnv instance. You should never construct your own texturemanagers. |
|
156 * |
|
157 * Usage: |
|
158 * @code |
|
159 * |
|
160 * //Get TextureManager |
|
161 * CAlfTextureManager* textureMgr = &iEnv->TextureManager(); |
|
162 * |
|
163 * //Set texturemanager image path |
|
164 * textureMgr->setImagePath(_L( "C:\\data\\Images\\Pictures\\" ) ); |
|
165 * |
|
166 * //Load texture |
|
167 * CAlfTexture* texture = textureMgr->LoadTextureL( _L("1.bmp"), EAlfTextureFlagDefault, 10 ); |
|
168 * |
|
169 * //Unload texture. Here, texture instance itself is not destroyed, only its |
|
170 * //contents are emptied. |
|
171 * textureMgr->UnloadTexture(10); |
|
172 * |
|
173 * //Update texturecontent without changing the texture istance |
|
174 * textureMgr->updateTextureFromFile( 10, _L( "2.jpg" ) ); |
|
175 * |
|
176 * //Create texture |
|
177 * //BitmapProviderTest - implements MalfBitMapProvider interface |
|
178 * //Default implementation of this interface, provided by toolkit is |
|
179 * //CAlfImageLoaderUtil |
|
180 * BitmapProviderTest* callback = new (ELeave) BitmapProviderTest(); |
|
181 * textureMgr->CreateTextureL( 42, *callback, EAlfTextureFlagDefault ); |
|
182 * |
|
183 * @endcode |
|
184 * @lib alfclient.lib |
|
185 * @since S60 v3.2 |
|
186 */ |
|
187 NONSHARABLE_CLASS( CAlfTextureManager ): public CActive |
|
188 { |
|
189 public: |
|
190 |
|
191 /** |
|
192 * States of a CAlfTextureManager object. |
|
193 */ |
|
194 enum TState |
|
195 { |
|
196 /** Indicates that the manager is in idle state. A new bitmap loading |
|
197 operation can be started. */ |
|
198 EIdle, |
|
199 |
|
200 /** Indicates that the manager is loading a bitmap. */ |
|
201 ELoading |
|
202 }; |
|
203 |
|
204 /* Constructors and destructor. */ |
|
205 |
|
206 /** |
|
207 * Static factory method. Creates a texture appropriate for the current |
|
208 * renderer. |
|
209 */ |
|
210 static CAlfTextureManager* NewL(CAlfEnv& aEnv, TUid aUid); |
|
211 |
|
212 /** |
|
213 * Static factory method. Creates a texture appropriate for the current |
|
214 * renderer. |
|
215 */ |
|
216 static CAlfTextureManager* NewLC(CAlfEnv& aEnv, TUid aUid); |
|
217 |
|
218 /** |
|
219 * Destructor. |
|
220 */ |
|
221 virtual ~CAlfTextureManager(); |
|
222 |
|
223 |
|
224 /* Methods. */ |
|
225 |
|
226 /** @beginAPI */ |
|
227 |
|
228 /** |
|
229 * Determines the environment the manager belongs to. |
|
230 */ |
|
231 IMPORT_C CAlfEnv& Env(); |
|
232 |
|
233 /** |
|
234 * Retuns a texture having given id. Will return a default blank |
|
235 * texture if the id was not found. |
|
236 */ |
|
237 IMPORT_C const CAlfTexture* Texture(TInt aId) const; |
|
238 |
|
239 /** |
|
240 * Returns a texture associated with the given id. |
|
241 * Will leave if no associated texture exists. |
|
242 * |
|
243 * @param aId Id of the retrieved texture. |
|
244 * @return Pointer to the texture. If the method leaves the return value is undefined. |
|
245 * @leave KErrNotFound If a texture with the given id does not exist. |
|
246 */ |
|
247 IMPORT_C CAlfTexture* TextureL(TInt aId); |
|
248 |
|
249 /** |
|
250 * Sets the path where bitmaps are loaded from. If drive is not included, tries to resolver that |
|
251 * using CCoeEnv |
|
252 * |
|
253 * @param aPath Path for bitmap files. |
|
254 * @see LoadTexture() Call to load textures from this location. |
|
255 */ |
|
256 IMPORT_C void SetImagePathL(const TDesC& aPath); |
|
257 |
|
258 /** |
|
259 * Returns the current image path. |
|
260 * @see LoadTexture() Call to load textures from this location. |
|
261 */ |
|
262 IMPORT_C const TDesC& ImagePath() const; |
|
263 |
|
264 /** |
|
265 * Returns the blank texture. This can be used as a dummy texture if |
|
266 * no real texture is available. |
|
267 */ |
|
268 IMPORT_C const CAlfTexture& BlankTexture() const; |
|
269 |
|
270 /** |
|
271 * Returns the blank texture. This can be used as a dummy texture if |
|
272 * no real texture is available. Will generate the blank texture |
|
273 * if the texture is not yet available. |
|
274 */ |
|
275 IMPORT_C CAlfTexture& BlankTexture(); |
|
276 |
|
277 /** |
|
278 * Loads an image and makes it a texture. The bitmap files are searched in |
|
279 * the path specified with SetImagePathL. The format of the loaded image |
|
280 * must be supported by the system (Series 60) codecs. |
|
281 * |
|
282 * LoadTextureL is an asynchronous method, which returns an empty texture |
|
283 * which is loaded and filled in the background. Register an |
|
284 * MAlfTextureLoadingCompletedObserver instance to the iLoadedObservers |
|
285 * array, whose TextureLoadingCompleted() method will be called when |
|
286 * textures finish loading. The same observer is also called if an error |
|
287 * occurs during the loading process. The other method is to check if an |
|
288 * image has been loaded with TextureManagers IsLoaded(). |
|
289 * |
|
290 * If a texture with the given id or filename is already loaded the previously |
|
291 * loaded texture is returned. If texture with the given id has been unloaded |
|
292 * with UnloadTexture() method then the id is reused by loading a new texture |
|
293 * on the id. |
|
294 * |
|
295 * @param aImageFileName Name of the image bitmap file to load. Relative |
|
296 * to the image load path. If empty filename is |
|
297 * used, will check if a filename for the id has |
|
298 * been defined and load a texture using that resource |
|
299 * location, if possible. |
|
300 * @param aFlags Specify flags for the texture loading and |
|
301 * uploading - how to convert the bitmap to |
|
302 * texture. |
|
303 * @param aId Id for the texture. Must be unique. |
|
304 * KAlfAutoGeneratedTextureId can be used to let |
|
305 * texture manager automatically decide id. |
|
306 * |
|
307 * @note If both image name and id are left undefined |
|
308 * ("" and zero), will return a blank texture. |
|
309 * |
|
310 * @return Reference to the texture. |
|
311 * |
|
312 * @see SetImagePathL() To set the image search path. Set to "" to use |
|
313 * absolute image filenames. |
|
314 * @see iLoadObservers |
|
315 * @see MAlfTextureLoadingCompletedObserver::TextureLoadingCompleted() |
|
316 * @see IsLoaded() |
|
317 */ |
|
318 IMPORT_C CAlfTexture& LoadTextureL(const TDesC& aImageFileName, |
|
319 TAlfTextureFlags aFlags, |
|
320 TInt aId); |
|
321 |
|
322 /** |
|
323 * Loads an image based on pre-registered id and file name. |
|
324 * |
|
325 * @see DefineFileName() |
|
326 * |
|
327 * LoadTextureL is an asynchronous method, which returns an empty texture |
|
328 * which is loaded and filled in the background. Register an |
|
329 * MAlfTextureLoadingCompletedObserver instance to the iLoadedObservers |
|
330 * array, whose TextureLoadingCompleted() method will be called when |
|
331 * textures finish loading. The same observer is also called if an error |
|
332 * occurs during the loading process. The other method is to check if an |
|
333 * image has been loaded with TextureManagers IsLoaded(). |
|
334 * |
|
335 * If a texture with the given id or filename is already loaded the previously |
|
336 * loaded texture is returned. If texture with the given id has been unloaded |
|
337 * with UnloadTexture() method then the id is reused by loading a new texture |
|
338 * on the id. |
|
339 * |
|
340 * @param aId The id of the texture/filename to load. The id must |
|
341 * have a filename assigned by a call to DefineFileName(). |
|
342 * |
|
343 * @param aTextureMaxSize Can be used to define a maximum dimensions for |
|
344 * the final texture. The image data loaded will be |
|
345 * scaled (down) and fitted to these dimensions. Use |
|
346 * zero or below-zero values if size does not matter. |
|
347 * If the texture size is larger than the texture size |
|
348 * supported by the GL, the texture will be split to |
|
349 * multiple segments. |
|
350 * @param aFlags Specify upload behavior - how to convert the bitmap |
|
351 * to texture and other load/upload behavior. |
|
352 * |
|
353 * @return Reference to the texture. |
|
354 * |
|
355 * @see SetImagePathL() To set the image search path. Set to "" to use |
|
356 * absolute image filenames. |
|
357 * @see iLoadObservers |
|
358 * @see MAlfTextureLoadingCompletedObserver::TextureLoadingCompleted() |
|
359 * @see IsLoaded() |
|
360 */ |
|
361 IMPORT_C CAlfTexture& LoadTextureL(const TInt aId, |
|
362 TSize aTextureMaxSize = TSize(0,0), |
|
363 TAlfTextureFlags aFlags = EAlfTextureFlagDefault); |
|
364 |
|
365 /** |
|
366 * Loads an image and makes it a texture. The bitmap files are searched in |
|
367 * the path specified with SetImagePathL. The format of the loaded image |
|
368 * must be supported by the system (Series 60) codecs. |
|
369 * |
|
370 * LoadTextureL is an asynchronous method, which returns an empty texture |
|
371 * which is loaded and filled in the background. Register an |
|
372 * MAlfTextureLoadingCompletedObserver instance to the iLoadedObservers |
|
373 * array, whose TextureLoadingCompleted() method will be called when |
|
374 * textures finish loading. The same observer is also called if an error |
|
375 * occurs during the loading process. The other method is to check if an |
|
376 * image has been loaded with TextureManagers IsLoaded(). |
|
377 * |
|
378 * If a texture with the given id or filename is already loaded the previously |
|
379 * loaded texture is returned. If texture with the given id has been unloaded |
|
380 * with UnloadTexture() method then the id is reused by loading a new texture |
|
381 * on the id. |
|
382 * |
|
383 * @param aImageName Name of the image bitmap file to load. If |
|
384 * empty filename is used, will check if a |
|
385 * filename for the aId has been defined |
|
386 * (using DefineFileNameL()) and load a texture |
|
387 * using that resource location, if possible. |
|
388 * @param aTextureMaxSize Can be used to define a maximum dimensions |
|
389 * for the final texture. The image data |
|
390 * loaded will be scaled (down) and fitted to |
|
391 * these dimensions. Use zero or below-zero |
|
392 * values if size does not matter. If the |
|
393 * texture size is larger than the texture |
|
394 * size supported by the GL, the texture will |
|
395 * be split to multiple segments. |
|
396 * @param aFlags Specify load/upload behavior - how to convert |
|
397 * the bitmap to texture. |
|
398 * @param aId Id for the texture. Must be unique. |
|
399 * KAlfAutoGeneratedTextureId can be used to let |
|
400 * texture manager automatically decide id. |
|
401 * |
|
402 * @note If both image name and id are left undefined |
|
403 * ("" and zero), will return a blank texture. |
|
404 * |
|
405 * @return Reference to the texture. |
|
406 * |
|
407 * @see SetImagePathL() To set the image search path. Set to "" to use |
|
408 * absolute image filenames. |
|
409 * @see iLoadObservers |
|
410 * @see MAlfTextureLoadingCompletedObserver::TextureLoadingCompleted() |
|
411 * @see IsLoaded() |
|
412 */ |
|
413 IMPORT_C CAlfTexture& LoadTextureL(const TDesC& aImageName, |
|
414 TSize aTextureMaxSize, |
|
415 TAlfTextureFlags aFlags, |
|
416 TInt aId); |
|
417 |
|
418 /** |
|
419 * Creates a texture by calling the ProvideBitmapL method of the passed MAlfBitmapProvider. |
|
420 * |
|
421 * If a texture with the given id is already created or loaded the previously |
|
422 * existing texture is returned. If texture with the given id has been unloaded |
|
423 * with UnloadTexture() method then the id is reused by loading a new texture |
|
424 * on the id. |
|
425 * |
|
426 * @param aBitmapProvider A bitmap provider that will load the bitmaps for us. The |
|
427 * ProvideBitmapL method of this will be called, which should |
|
428 * load or generate the needed bitmaps. |
|
429 * @param aFlags Specify load/upload behavior - how to convert |
|
430 * the bitmap to texture. |
|
431 * @param aId Id for the texture. Must be unique, use |
|
432 * KAlfAutoGeneratedTextureId to let texture manager |
|
433 * automatically decide id. |
|
434 * |
|
435 * @return Reference to the created texture. |
|
436 * @leave KErrArgument The bitmap and the mask bitmap are incompatible (different size). |
|
437 */ |
|
438 IMPORT_C CAlfTexture& CreateTextureL(TInt aId, |
|
439 MAlfBitmapProvider* aBitmapProvider, |
|
440 TAlfTextureFlags aFlags); |
|
441 |
|
442 |
|
443 |
|
444 /** |
|
445 * Unloads a texture from memory. |
|
446 * |
|
447 * This method releases the texture id and image name for reusing. |
|
448 * @see LoadTexture(). |
|
449 * |
|
450 * @note May unload several textures from memory, if they have the |
|
451 * sane image name assigned! |
|
452 */ |
|
453 IMPORT_C void UnloadTexture(const TDesC& aImageName); |
|
454 |
|
455 /** |
|
456 * Unloads a texture from memory. |
|
457 * |
|
458 * This method releases the texture id and image name for reusing. |
|
459 * |
|
460 */ |
|
461 IMPORT_C void UnloadTexture(TInt aId); |
|
462 |
|
463 /** |
|
464 * Updates texture content without changing the texture address. |
|
465 * |
|
466 * this is an asynchronous method which is loaded and filled in |
|
467 * the background. Register an MAlfTextureLoadingCompletedObserver instance |
|
468 * to the iLoadedObservers array, whose TextureLoadingCompleted() method |
|
469 * will be called when textures finish loading. The same observer is also |
|
470 * called if an error occurs during the loading process. The other method |
|
471 * is to check if an image has been loaded with TextureManagers IsLoaded(). |
|
472 * |
|
473 * @param aId Id for the texture. Must be unique. |
|
474 * |
|
475 * @param aFileName Name of the image bitmap file to load. Relative |
|
476 * to the image load path. If filename is empty or |
|
477 * not given, will check if a filename for the id has |
|
478 * been defined and load a texture using that resource |
|
479 * location, if possible. |
|
480 * @leave If this method leaves the texture is not valid any more. |
|
481 * |
|
482 * @see SetImagePathL() To set the image search path. Set to "" to use |
|
483 * absolute image filenames. |
|
484 * @see iLoadObservers |
|
485 * @see MAlfTextureLoadingCompletedObserver::TextureLoadingCompleted() |
|
486 * @see IsLoaded() |
|
487 */ |
|
488 IMPORT_C void UpdateTextureFromFileL(TInt aId, const TDesC* aFileName = NULL); |
|
489 |
|
490 /** |
|
491 * Updates texture content without changing the texture address. |
|
492 * |
|
493 * @param aId Id for the texture. |
|
494 * @param aBitmapProvider A bitmap provider that will load the bitmaps for us. The |
|
495 * ProvideBitmapL method of this will be called, which should |
|
496 * load or generate the needed bitmaps. If this is not given |
|
497 * the current provider is called instead. |
|
498 * @leave If this method leaves the texture is not valid any more. |
|
499 */ |
|
500 IMPORT_C void UpdateTextureFromBitmapL(TInt aId, MAlfBitmapProvider* aBitmapProvider = NULL); |
|
501 |
|
502 /** |
|
503 * Define (register) a texture resource (filename/path) for |
|
504 * a texture id. Enables calling the LoadTextureL only with an id. |
|
505 * This resource will then be loaded when LoadTextureL |
|
506 * is called with the id. |
|
507 */ |
|
508 IMPORT_C void DefineFileNameL(TInt aId, const TDesC& aImageName); |
|
509 |
|
510 /** |
|
511 * Prepends the image path to the beginning of the file name, |
|
512 * if necessary. |
|
513 */ |
|
514 IMPORT_C void PrependImagePath(TDes& aFileName); |
|
515 |
|
516 /** |
|
517 * Adds texture loading observer |
|
518 * |
|
519 * @param aObserver observer to be added to array |
|
520 * @leave any system wide error code |
|
521 */ |
|
522 IMPORT_C void AddLoadObserverL(MAlfTextureLoadingCompletedObserver* aObserver); |
|
523 |
|
524 /** |
|
525 * Removes texture loading observer, this must be done at latest when observer is being deleted |
|
526 * |
|
527 * @param aObserver observer to be removed from array |
|
528 */ |
|
529 IMPORT_C void RemoveLoadObserver(MAlfTextureLoadingCompletedObserver* aObserver); |
|
530 |
|
531 /** |
|
532 * Adds texture manager state observer |
|
533 * |
|
534 * @param aObserver observer to be added to array |
|
535 * @leave any system wide error code |
|
536 */ |
|
537 IMPORT_C void AddStateObserverL(MAlfTextureManagerStateChangedObserver* aObserver); |
|
538 |
|
539 /** |
|
540 * Removes texture manager state observer, this must be done at latest when observer is being deleted |
|
541 * |
|
542 * @param aObserver observer to be removed from array |
|
543 */ |
|
544 IMPORT_C void RemoveStateObserver(MAlfTextureManagerStateChangedObserver* aObserver); |
|
545 |
|
546 /** |
|
547 * Returns a reference to the texture processor. |
|
548 * @return Texture processor |
|
549 */ |
|
550 IMPORT_C CAlfTextureProcessor& Processor(); |
|
551 |
|
552 /** |
|
553 * Sets the range where texture manager is allowed to assign new texture ids automatically. |
|
554 * |
|
555 * @param aLow Smallest texture id that can be auto assigned. |
|
556 * @param aHigh Largest texture id that can be auto assigned. |
|
557 * |
|
558 */ |
|
559 IMPORT_C void SetAutomaticTextureIdRange(TInt aLow, TInt aHigh); |
|
560 |
|
561 /** |
|
562 * Checks if a texture exists, has content and is not found |
|
563 * from the texture load queue. |
|
564 * |
|
565 * Mainly meant for file-based textures to check if the |
|
566 * texture is ready to be used. |
|
567 * |
|
568 * Note that textures may have some temporary placeholder |
|
569 * content already before they have been fully loaded! |
|
570 * |
|
571 * For CreateTextureL -based textures it is recommended to use |
|
572 * CAlfTexture::HasContent() directly. |
|
573 * |
|
574 * @see LoadTextureL() |
|
575 * @see CreateTextureL() |
|
576 * @see CAlfTexture::HasContent() |
|
577 * |
|
578 * @param aImageName Name of the image bitmap file to check. |
|
579 * ImagePath (if set) will be prepended to |
|
580 * this name. |
|
581 * @return ETrue if texture exists, has content and |
|
582 * is not found from the texture load queue. |
|
583 */ |
|
584 IMPORT_C TBool IsLoaded(const TDesC& aImageName) const; |
|
585 |
|
586 /** |
|
587 * Returns the texture ID of the previously loaded file. |
|
588 * |
|
589 * @param aImageName Name of the image bitmap file to check. |
|
590 * ImagePath (if set) will be prepended to |
|
591 * this name. |
|
592 * @return Texture ID of the already created texture |
|
593 * KErrNotFound if the texture has not been created. |
|
594 */ |
|
595 IMPORT_C TInt TextureId(const TDesC& aImageName) const; |
|
596 |
|
597 /** |
|
598 * Checks if a texture exists, has content and is not found |
|
599 * from the texture load queue. |
|
600 * |
|
601 * Mainly meant for file-based textures to check if the |
|
602 * texture is ready to be used. |
|
603 * |
|
604 * Note that textures may have some temporary placeholder |
|
605 * content already before they have been fully loaded! |
|
606 * |
|
607 * For CreateTextureL -based textures it is recommended to use |
|
608 * CAlfTexture::HasContent() directly. |
|
609 * |
|
610 * @see LoadTextureL() |
|
611 * @see CreateTextureL() |
|
612 * @see CAlfTexture::HasContent() |
|
613 * |
|
614 * @param aId Id of the texture. |
|
615 * @return ETrue if texture exists, has content and is not found |
|
616 * from the texture load queue. |
|
617 */ |
|
618 IMPORT_C TBool IsLoaded(TInt aId) const; |
|
619 |
|
620 /** |
|
621 * Checks if a texture exists, has content and is not found |
|
622 * from the texture load queue. |
|
623 * |
|
624 * Mainly meant for file-based textures to check when the |
|
625 * texture is ready to be used. |
|
626 * |
|
627 * Note that textures may have some temporary placeholder |
|
628 * content already before they have been fully loaded! |
|
629 * |
|
630 * For CreateTextureL -based textures it is recommended to use |
|
631 * CAlfTexture::HasContent() directly. |
|
632 * |
|
633 * @see LoadTextureL() |
|
634 * @see CreateTextureL() |
|
635 * @see CAlfTexture::HasContent() |
|
636 * |
|
637 * @param aTexture Texture object. |
|
638 * @return True if texture exists, has content and is not found |
|
639 * from the texture load queue. |
|
640 */ |
|
641 IMPORT_C TBool IsLoaded(const CAlfTexture * aTexture) const; |
|
642 |
|
643 /** |
|
644 * @deprecated <b>Always returns an invalid reference!</b> |
|
645 * |
|
646 * Loads a sequence of images and makes it an animated texture. |
|
647 * |
|
648 * @param aSkinName Logical name of animated element |
|
649 * @param aTextureMaxSize Can be used to define a maximum dimensions |
|
650 * for the final texture. The image data |
|
651 * loaded will be scaled (down) and fitted to |
|
652 * these dimensions. Use zero or below-zero |
|
653 * values if size does not matter. |
|
654 * @param aFlags Specify load/upload behavior |
|
655 * @param aId Id for the texture. Must be unique. |
|
656 * KAlfAutoGeneratedTextureId can be used to let |
|
657 * texture manager automatically decide id. |
|
658 * |
|
659 * @return Reference to the texture. |
|
660 */ |
|
661 IMPORT_C CAlfTexture& LoadAnimatedTextureL(const TDesC& aSkinName, |
|
662 TSize aTextureMaxSize, |
|
663 TAlfTextureFlags aFlags, |
|
664 TInt aId); |
|
665 |
|
666 /** @endAPI */ |
|
667 |
|
668 TUid ManagerUid(); |
|
669 |
|
670 /** |
|
671 * Appends a texture to the texture manager's list of managed textures. |
|
672 * Ownership of the texture is transferred to the manager; when the manager |
|
673 * is destroyed, the texture will be destroyed, too. |
|
674 * |
|
675 * Checks already existing duplicate textures |
|
676 * having matching id and leaves with appropriate errorcode if needed. |
|
677 * |
|
678 * @param aTexture Texture to transfer to the manager. |
|
679 * @param aId Id for the texture. Must be unique. |
|
680 * @leave KErrAlreadyExists if a texture with the given id already exists. |
|
681 * |
|
682 */ |
|
683 void AppendTextureL(CAlfTexture* aTexture); |
|
684 |
|
685 /** |
|
686 * Removes a texture from management. The texture's ownership is |
|
687 * transferred to the caller. |
|
688 * |
|
689 * @param aTexture Texture to remove from management. |
|
690 */ |
|
691 void RemoveTexture(CAlfTexture& aTexture); |
|
692 |
|
693 /** |
|
694 * Gets the state of the texture manager. |
|
695 * |
|
696 * @return State of the texture manager. |
|
697 */ |
|
698 TState State() const; |
|
699 |
|
700 /** |
|
701 * Releases texture manager resources. Releases all textures. |
|
702 * Called when AlfEnv is restored. |
|
703 * |
|
704 * While the release operation is in progress, it is not possible to delete |
|
705 * CAlfTexture instances or create new ones. After the release has been |
|
706 * completed, textures can again be deleted and created. |
|
707 * |
|
708 * @param aReleasePriorityLevel Priority level. All textures, which |
|
709 * priority has equal or higher value are released. |
|
710 * |
|
711 * @return Were all textures released? If ETrue all texture were released. |
|
712 * If EFalse, some texture were not released. |
|
713 * |
|
714 * @panic ETextureManagerTextureConstructedDuringRelease |
|
715 * A new CAlfTexture was constructed and added to the texture |
|
716 * manager during the release operation. |
|
717 * @panic ETextureManagerTextureDestroyedDuringRelease |
|
718 * An existing CAlfTexture was destroyed and removed from the texture |
|
719 * manager during the release operation. |
|
720 * |
|
721 * @see RestoreL() |
|
722 */ |
|
723 TBool Release( TInt aReleasePriorityLevel = EAlfTexturePriorityNormal ); |
|
724 |
|
725 /** |
|
726 * Restores texture manager resources. Restores the content of all textures |
|
727 * released in Release(). Called when AlfEnv is restored. |
|
728 * |
|
729 * While the restore operation is in progress, it is not possible to delete |
|
730 * CAlfTexture instances or create new ones. After the restore has been |
|
731 * completed, textures can again be deleted and created. |
|
732 * |
|
733 * @param aRestorePriorityLevel Priority level. All textures, which |
|
734 * priority has equal or lower value are restored. |
|
735 * |
|
736 * @return Were all textures restored? If ETrue all texture were restored. |
|
737 * If EFalse, some texture were not restored. |
|
738 * |
|
739 * @panic ETextureManagerTextureConstructedDuringRestore |
|
740 * A new CAlfTexture was constructed and added to the texture |
|
741 * manager during the restore operation. |
|
742 * @panic ETextureManagerTextureDestroyedDuringRestore |
|
743 * An existing CAlfTexture was destroyed and removed from the texture |
|
744 * manager during the restore operation. |
|
745 * |
|
746 * @see Release() |
|
747 */ |
|
748 TBool RestoreL( TInt aRestorePriorityLevel = EAlfTexturePriorityLow ); |
|
749 |
|
750 /** |
|
751 * Releases and restores skin dependent textures. Usually called after |
|
752 * system skin has been changed. |
|
753 */ |
|
754 void NotifySkinChangedL(); |
|
755 |
|
756 /** |
|
757 * Increases the texture reference count based on texture id. |
|
758 * |
|
759 * @param aId the texture id |
|
760 */ |
|
761 void IncRefcount(TInt aId); |
|
762 |
|
763 /** |
|
764 * Decreases the texture reference count based on texture id. |
|
765 * |
|
766 * @param aId the texture id |
|
767 */ |
|
768 void DecRefcount(TInt aId); |
|
769 |
|
770 /** |
|
771 * Reports texture information, i.e. what's the size of texture in |
|
772 * display. |
|
773 * @param aTextureId texture identifier. |
|
774 * @param aSize texture size. |
|
775 */ |
|
776 void ReportTextureInfoL( TInt aTextureId, const TSize& aTextureSize ); |
|
777 |
|
778 /** |
|
779 * Adds texture manager texture auto size observer. |
|
780 * |
|
781 * @param aObserver observer to be added to array |
|
782 * @leave any system wide error code |
|
783 */ |
|
784 IMPORT_C void AddAutoSizeObserverL(MAlfTextureAutoSizeObserver* aObserver); |
|
785 |
|
786 /** |
|
787 * Removes texture manager texture auto size observer. |
|
788 * |
|
789 * @param aObserver observer to be removed from array |
|
790 */ |
|
791 IMPORT_C void RemoveAutoSizeObserver(MAlfTextureAutoSizeObserver* aObserver); |
|
792 |
|
793 protected: |
|
794 |
|
795 /* Constructors. */ |
|
796 |
|
797 /** |
|
798 * Constructor. |
|
799 */ |
|
800 CAlfTextureManager(); |
|
801 |
|
802 /** |
|
803 * Second-phase constructor. |
|
804 */ |
|
805 void ConstructL(CAlfEnv& aEnv, TUid aUid); |
|
806 |
|
807 private: |
|
808 |
|
809 /** |
|
810 * Check the existence of a texture. |
|
811 * |
|
812 * @param aFileName File name of the texture. |
|
813 * |
|
814 * @return Index of the texture, in the iTextures array, or KErrNotFound if not found. |
|
815 */ |
|
816 TInt CheckTexture(const TDesC& aFileName) const; |
|
817 |
|
818 /** |
|
819 * Check if texture exists with given id. |
|
820 * |
|
821 * @return Index of the texture, in the iTextures array, or KErrNotFound if not found. |
|
822 */ |
|
823 TInt CheckTexture(TInt aId) const; |
|
824 |
|
825 /** |
|
826 * Called when image loading (decoding) operation is complete. |
|
827 */ |
|
828 void RunL(); |
|
829 |
|
830 /** |
|
831 * Handles a leave occurring in the request completion event handler RunL(). |
|
832 */ |
|
833 TInt RunError(TInt aError); |
|
834 |
|
835 /** |
|
836 * Cancel active object operation. |
|
837 */ |
|
838 void DoCancel(); |
|
839 |
|
840 /** |
|
841 * Starts loading next images from the load queue. If scheduling a |
|
842 * queue entry fails for some reason, the entry is discarded and the |
|
843 * next queue entry is processed. |
|
844 */ |
|
845 void StartLoading(); |
|
846 |
|
847 /** |
|
848 * Cleans up the topmost load queue entry and removes it from the |
|
849 * load queue. Deletes the decoder, but not the loaded texture entry. |
|
850 */ |
|
851 TLoadQueueEntry PopLoadedQueueEntry(); |
|
852 |
|
853 /** |
|
854 * Sets up image decoding and starts to load the first entry in the load |
|
855 * queue. |
|
856 * @leave Standard error code if decoder initialization/resource read |
|
857 * fails. |
|
858 */ |
|
859 void DoLoadNextL(); |
|
860 |
|
861 /** |
|
862 * Called when an image has finished loading. Handles |
|
863 * uploading of the loaded bitmap to the texture. |
|
864 * |
|
865 * @param aEntry Entry whose contents have been loaded. |
|
866 */ |
|
867 void ImageLoadingCompleteL(TLoadQueueEntry& aEntry); |
|
868 |
|
869 /** |
|
870 * Helper method that notifies observers of texture manager state change. |
|
871 * |
|
872 */ |
|
873 void NotifyStateChange() const; |
|
874 |
|
875 /** |
|
876 * Helper method that notifies observers of texture load completion. |
|
877 */ |
|
878 void NotifyTextureLoaded(CAlfTexture& aTexture, |
|
879 TInt aTextureId, |
|
880 TInt aErrorCode) const; |
|
881 |
|
882 |
|
883 /** Returns true if the given texture is still in the load queue. */ |
|
884 TBool IsInLoadQueue(const CAlfTexture* texture) const; |
|
885 |
|
886 /** Cancels loading of a texture */ |
|
887 void CancelLoadingOfTexture(CAlfTexture& aTexture); |
|
888 |
|
889 /** Generates unique id for texture */ |
|
890 TInt GenerateTextureId(); |
|
891 |
|
892 /** Releases one texture */ |
|
893 void ReleaseEntry(const TTextureEntry& aEntry); |
|
894 |
|
895 /** Restores one texture */ |
|
896 void RestoreEntryL(const TTextureEntry& aEntry); |
|
897 |
|
898 /** Returns ETrue if this texturemanager is a shared texture manager */ |
|
899 TBool IsShared(); |
|
900 |
|
901 /** Updates texture by re-uploading content */ |
|
902 void UpdateTextureL(TInt aId, TSize aSize); |
|
903 |
|
904 /** Reloads texture from a file */ |
|
905 void ReloadTextureL(const TDesC& aImageName, |
|
906 TSize aTextureMaxSize, |
|
907 TAlfTextureFlags aFlags, |
|
908 TInt aId); |
|
909 |
|
910 /** Recreates texture from a bitmap provider */ |
|
911 void RecreateTextureL(TInt aId, |
|
912 MAlfBitmapProvider* aBitmapProvider, |
|
913 TAlfTextureFlags aFlags); |
|
914 |
|
915 /** Starts the texture garbagecollecting, triggered |
|
916 * automatically when zero refcount textures are |
|
917 * detected |
|
918 */ |
|
919 void StartGarbageCollect(); |
|
920 |
|
921 /* Garbace collector callback function */ |
|
922 static TInt GarbageCollect(TAny* aPtr); |
|
923 |
|
924 /* Modifies flags */ |
|
925 void RemoveFlags(TAlfTextureFlags& aFlags, TInt aFlagsToBeRemoved); |
|
926 |
|
927 /* Modifies flags */ |
|
928 void SetFlags(TAlfTextureFlags& aFlags, TInt aFlagsToBeSet); |
|
929 |
|
930 private: |
|
931 |
|
932 /* Private data. Owned */ |
|
933 struct TPrivateData; |
|
934 TPrivateData* iData; |
|
935 |
|
936 }; |
|
937 |
|
938 #endif |