Conversion to Apache 2.0 license
[platform/core/uifw/dali-core.git] / dali / internal / update / resources / resource-manager.h
1 #ifndef __DALI_INTERNAL_RESOURCE_MANAGER_H__
2 #define __DALI_INTERNAL_RESOURCE_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23 #include <boost/functional/hash.hpp>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/images/image.h>
27 #include <dali/public-api/images/native-image.h>
28 #include <dali/public-api/images/bitmap-image.h>
29 #include <dali/public-api/common/ref-counted-dali-vector.h>
30
31 #include <dali/integration-api/bitmap.h>
32 #include <dali/integration-api/platform-abstraction.h>
33 #include <dali/integration-api/resource-cache.h>
34 #include <dali/integration-api/shader-data.h>
35
36 #include <dali/internal/common/event-to-update.h>
37 #include <dali/internal/common/message.h>
38 #include <dali/internal/common/bitmap-upload.h>
39 #include <dali/internal/event/text/font-impl.h>
40 #include <dali/internal/event/modeling/model-data-impl.h>
41 #include <dali/internal/event/resources/resource-client-declarations.h>
42 #include <dali/internal/event/effects/shader-factory.h>
43 #include <dali/internal/update/modeling/internal-mesh-data.h>
44 #include <dali/internal/update/modeling/scene-graph-mesh-declarations.h>
45 #include <dali/internal/update/resources/resource-manager-declarations.h>
46 #include <dali/internal/update/resources/bitmap-metadata.h>
47
48 namespace Dali
49 {
50
51 typedef boost::hash<const std::string> StringHash;
52
53 class NativeImage;
54
55 namespace Integration
56 {
57 struct ResourceType;
58 }
59
60 namespace Internal
61 {
62
63 // value types used by messages
64 template <> struct ParameterType< Integration::LoadResourcePriority >
65 : public BasicType< Integration::LoadResourcePriority > {};
66 template <> struct ParameterType< Pixel::Format >
67 : public BasicType< Pixel::Format > {};
68 template <> struct ParameterType< Integration::ResourceTypeId >
69 : public BasicType< Integration::ResourceTypeId > {};
70
71 namespace SceneGraph
72 {
73 class DiscardQueue;
74 class RenderQueue;
75 class TextureCacheDispatcher;
76 class PostProcessResourceDispatcher;
77 }
78
79 class NotificationManager;
80
81 /** Raw bytes of a resource laid out exactly as it wouldbe in a file, but in memory. */
82 typedef Dali::RefCountedVector<uint8_t> RequestBuffer;
83 /** Counting smart pointer for managing a buffer of raw bytes. */
84 typedef IntrusivePtr<RequestBuffer> RequestBufferPtr;
85
86 /**
87  * ResourceManager keeps track of resource loading requests, and caches resources that are loaded.
88  * It uses ResourceTicket objects, to keep track of the lifetime of each request.
89  * If the same resource is required by two client objects, they will share the same ResourceTicket
90  * i.e. only one load will occur using the native filesystem.
91  *
92  * Multi-threading notes:
93  * Resources are received from the PlatformAbstraction API during the Core::Render() method, which
94  * may be called from a dedicated rendering thread.
95  * Loading requests must be made from the application's main thread e.g. when Dali::Image is created.
96  */
97 class ResourceManager : public Integration::ResourceCache
98 {
99 public:
100
101   /**
102    * Create a resource manager.
103    * There should exactly one of these objects per Dali Core.
104    * @param[in] platformAbstraction Used to request resources from the native filesystem.
105    * @param[in] notificationManager Used to send NotifyTickets message.
106    * @param[in] postProcessResourcesQueue Used for performing post processing on resources
107    * @param[in] discardQueue Used to cleanup nodes & resources when no longer in use.
108    * @param[in] renderQueue Used to queue resource updates until the next Render.
109    */
110   ResourceManager( Integration::PlatformAbstraction& platformAbstraction,
111                    NotificationManager& notificationManager,
112                    SceneGraph::TextureCacheDispatcher& textureCacheDispatcher,
113                    ResourcePostProcessList& postProcessResourcesQueue,
114                    SceneGraph::PostProcessResourceDispatcher& postProcessResourceDispatcher,
115                    SceneGraph::DiscardQueue& discardQueue,
116                    SceneGraph::RenderQueue& renderQueue );
117
118   /**
119    * Virtual destructor.
120    */
121   virtual ~ResourceManager();
122
123 public: // Used by ResourceClient
124
125   /********************************************************************************
126    ************************ ResourceClient direct interface  **********************
127    ********************************************************************************/
128
129   /**
130    * Resource client passes itself for secondary intialisation.
131    * (The resource client requires the ResourceManager to be instantiated first).
132    * @param[in] resourceClient The ResourceClient.
133    */
134   void SetClient( ResourceClient& resourceClient );
135
136   /********************************************************************************
137    ************************ UpdateManager direct interface  ***********************
138    ********************************************************************************/
139
140   /**
141    * Called to update the resource cache before rendering.
142    * New resources will be added to the cache using PlatformAbstraction::FillResourceCache().
143    * Unwanted resources will be added to the DiscardQueue.
144    * @param[in] updateBufferIndex The current update buffer index.
145    * @return true, if a resource load was completed or failed
146    */
147   bool UpdateCache( BufferIndex updateBufferIndex );
148
149   /**
150    * Iterate through the post process queue, performing requested updates.
151    * @param[in] updateBufferIndex The current update buffer index.
152    */
153   void PostProcessResources( BufferIndex updateBufferIndex );
154
155   /********************************************************************************
156    *************************** CoreImpl direct interface  *************************
157    ********************************************************************************/
158
159   /**
160    * Returns whether the Resource Manager is still processing any resource requests.
161    * @return true if still processing, false otherwise.
162    */
163   bool ResourcesToProcess();
164
165   /********************************************************************************
166    ********************************* Message handlers *****************************
167    ********************************************************************************/
168
169   /**
170    * Request a resource from the native filesystem.
171    * @param[in] id The Id of the requested resource
172    * @param[in] typePath The type & path of requested resource.
173    * @param[in] priority The priority of the request. This is ignored if the resource is already being loaded.
174    */
175   void HandleLoadResourceRequest( ResourceId id,
176                                   const ResourceTypePath& typePath,
177                                   Integration::LoadResourcePriority priority );
178
179   /**
180    * Decode a resource from a memory buffer with the semantics of loading.
181    * Notifications of partial completion, success, and failure will happen via
182    * the same loading notification path used for loading from files: Update()
183    * will retrieve loading events in its main loop and notify listeners to its
184    * own loading events, and forward them, still as loading events, to the event
185    * thread via its update queue.
186    * Resource manager and lower levels make no attempt to detect resource
187    * aliases as is done for multiple requests to load the same resource
188    * file, so the caller is responsible for ensuring that it only requests
189    * the decoding of an in-memory resource once and for doing the sharing of the
190    * resulting object itself. Ultimately this responsibility resides with the
191    * application.
192    * @note ! Only Bitmap resources are supported for decoding from memory !
193    * @param[in] id The Id of the requested resource.
194    * @param[in] typePath The type of the requested resource and a path that is ignored.
195    * @param[in] buffer The raw encoded bytes of the resource as they would appear in a file.
196    * @param[in] priority The priority of the request. This is ignored if the resource is already being loaded.
197    */
198   void HandleDecodeResourceRequest( ResourceId id,
199                                     const ResourceTypePath& typePath,
200                                     RequestBufferPtr buffer,
201                                     Integration::LoadResourcePriority priority );
202
203   /**
204    * Injects a bitmap resource (does not require loading).
205    * @pre bitmap has to be initialized
206    * @param[in] id The resource id
207    * @param[in] bitmap an initialized bitmap
208    */
209   void HandleAddBitmapImageRequest(ResourceId id, Integration::Bitmap* bitmap);
210
211   /**
212    * Add an existing resource to the resource manager.
213    * @param[in] id The resource id
214    * @param [in] resourceData the NativeImage object
215    * @return A ref-counted request object. Keep a copy until the resource is no longer required.
216    */
217   void HandleAddNativeImageRequest( ResourceId id, NativeImagePtr resourceData );
218
219   /**
220    * Add an existing resource to the resource manager.
221    * @param[in] id The resource id
222    * @param[in] width       width in pixels
223    * @param[in] height      height in pixels
224    * @param[in] pixelFormat Pixel format
225    */
226   void HandleAddFrameBufferImageRequest( ResourceId id, unsigned int width, unsigned int height, Pixel::Format pixelFormat );
227
228   /**
229    * Add an existing resource to the resource manager.
230    * @param[in] id            The resource id
231    * @param[in] nativeImage   The NativeImage
232    */
233   void HandleAddFrameBufferImageRequest( ResourceId id, NativeImagePtr nativeImage );
234
235   /**
236    * Allocate a new empty texture.
237    * @param[in] id The resource id
238    * @param[in] width       width in pixels
239    * @param[in] height      height in pixels
240    * @param[in] pixelFormat Pixel format
241    */
242   void HandleAllocateTextureRequest( ResourceId id, unsigned int width, unsigned int height, Pixel::Format pixelFormat );
243
244   /**
245    * Upload an array of bitmaps to a texture.
246    * @param[in] id The resource id
247    * @param[in] uploadArray  bitmap upload array.
248    */
249   void HandleUpdateTextureRequest( ResourceId id,  const BitmapUploadArray& uploadArray );
250
251   /**
252    * Requests allocation of a mesh resource
253    * @param[in] id The resource id
254    * @param[in] meshData The mesh data
255    */
256   void HandleAllocateMeshRequest (ResourceId id, MeshData* meshData);
257
258   /**
259    * Requests allocation of a font resource
260    */
261   void HandleAllocateFontRequest(ResourceId id, const std::string& familyNameAndStyle);
262
263   /**
264    * Load a shader program from a file
265    * @param[in] id The resource id
266    * @param[in] typePath The type & path of the resource
267    */
268   void HandleLoadShaderRequest(ResourceId id, const ResourceTypePath& typePath );
269
270   /**
271    * Update bitmap area request
272    * @param[in] textureId The resource ID of a bitmap-texture to remove.
273    * @param[in] area The updated area. Zero width/height indicates the whole bitmap has been updated
274    */
275   void HandleUpdateBitmapAreaRequest( ResourceId textureId, const Dali::RectArea& area );
276
277   /**
278    * Upload mesh buffer changes.
279    * @param[in] updateBufferIndex The current update buffer index.
280    * @param[in] id The ID of a Mesh resource.
281    * @param[in] meshData Newly allocated mesh data; ownership is taken.
282    */
283   void HandleUpdateMeshRequest( BufferIndex updateBufferIndex, ResourceId id, MeshData* meshData );
284
285   /**
286    * Request reloading a resource from the native filesystem.
287    * @param[in] id The resource id
288    * @param[in] typePath The type & path of the resource
289    * @param[in] priority The priority of the request. This is ignored if the resource is already being refreshed.
290    */
291   void HandleReloadResourceRequest( ResourceId id, const ResourceTypePath& typePath, Integration::LoadResourcePriority priority );
292
293   /**
294    * Save a resource to the given url
295    * @param[in] id       The resource id
296    * @param[in] typePath The type & path of the resource
297    */
298   void HandleSaveResourceRequest( ResourceId id, const ResourceTypePath& typePath );
299
300   /**
301    * Resource ticket has been discarded, throw away the actual resource
302    */
303   void HandleDiscardResourceRequest( ResourceId id, Integration::ResourceTypeId typeId );
304
305   /**
306    * Update font texture atlas status
307    * @param[in] id         The resource id
308    * @param[in] atlasId    texture ID of the atlas
309    * @param[in] loadStatus The status update.
310    */
311   void HandleAtlasUpdateRequest( ResourceId id, ResourceId atlasId, Integration::LoadStatus loadStatus );
312
313   /********************************************************************************
314    ******************** Event thread object direct interface  *********************
315    ********************************************************************************/
316
317   /**
318    * Called by model implementations which require access to the model
319    * data.
320    * @note Only called from event thread objects - ModelData is not used
321    * by update objects.
322    * @param[in] id - the id of a ModelData resource.
323    * @return the model data or NULL if it has not been loaded.
324    */
325   Internal::ModelDataPtr GetModelData(ResourceId id);
326
327   /********************************************************************************
328    ******************** Update thread object direct interface  ********************
329    ********************************************************************************/
330
331   /**
332    * Check if a resource has completed loading.
333    * @param[in] id The ID of a bitmap/texture resource.
334    * @return true if the bitmap or texture has finished loading
335    */
336   bool IsResourceLoaded(ResourceId id);
337
338   /**
339    * Check if a resource has failed to load, e.g. file not found, etc.
340    * @param[in] id The ID of a bitmap/texture resource.
341    * @return true if the bitmap or texture has failed to load
342    */
343   bool IsResourceLoadFailed(ResourceId id);
344
345   /**
346    * Get bitmap metadata. This stores meta data about the resource, but
347    * doesn't keep track of the resource
348    */
349   BitmapMetadata GetBitmapMetadata(ResourceId id);
350
351   /**
352    * Get the mesh data.
353    * @note Used by update thread objects (SceneGraph::Mesh) only
354    * @param[in] id - the id of a MeshData resource.
355    * @return the mesh data or NULL if this resource isn't valid
356    */
357   Internal::SceneGraph::Mesh* GetMesh(ResourceId id);
358
359   /**
360    * Returns the shader resource corresponding to the Id
361    * @param[in] id - the id of a shader binary resource.
362    * @return the shader binary resource data or NULL if it has not been loaded.
363    */
364   Integration::ShaderDataPtr GetShaderData(ResourceId id);
365
366   /**
367    * Check if current set of glyph requests on given atlas have finished loading
368    * @param[in] id Request Id of the text atlas texture
369    * @return true if the current set of glyph requests have all completed, false
370    * if there are outstanding glyph requests that haven't finished.
371    */
372   bool IsAtlasLoaded(ResourceId id);
373
374   /**
375    * Check the load status of a given atlas.
376    * @param[in] id Request Id of the text atlas texture
377    * @return LoadStatus
378    */
379   Integration::LoadStatus GetAtlasLoadStatus( ResourceId atlasId );
380
381   /********************************************************************************
382    ************************* ResourceCache Implementation  ************************
383    ********************************************************************************/
384 public:
385
386   /**
387    * @copydoc Integration::ResourceCache::LoadResponse
388    */
389   virtual void LoadResponse(ResourceId id, Integration::ResourceTypeId type, Integration::ResourcePointer resource, Integration::LoadStatus loadStatus);
390
391   /**
392    * @copydoc Integration::ResourceCache::SaveComplete
393    */
394   virtual void SaveComplete(ResourceId id, Integration::ResourceTypeId type);
395
396   /**
397    * @copydoc Integration::ResourceCache::LoadFailed
398    */
399   virtual void LoadFailed(ResourceId id, Integration::ResourceFailure failure);
400
401   /**
402    * @copydoc Integration::ResourceCache::SaveFailed
403    */
404   virtual void SaveFailed(ResourceId id, Integration::ResourceFailure failure);
405
406   /********************************************************************************
407    ********************************* Private Methods  *****************************
408    ********************************************************************************/
409 private:
410   /**
411    * @param[in] id Resource id to clear
412    * @param[in] typePath Glyphs to be loaded, and cleared beforehand
413    */
414   void ClearRequestedGlyphArea( ResourceId id, const ResourceTypePath& typePath );
415
416   /**
417    * Sends loaded glyphs to texture atlas for uploading
418    * @param[in] glyphSet Loaded glyphs
419    */
420   void UploadGlyphsToTexture( const Integration::GlyphSet& glyphSet );
421
422   /**
423    * Sends notification messages for load sucess & failure,
424    * pushes from newComplete / newFailed into oldComplete / oldFailed respectively
425    */
426   void NotifyTickets();
427
428   /**
429    * Triggers message to Event thread to update the ticket's image attributes
430    * @pre An Image resource with the given id should exist in the cache.
431    * @param id ID of the image resource
432    * @param attributes Resource image attributes
433    */
434   void UpdateImageTicket( ResourceId id, ImageAttributes& attributes );
435
436   /**
437    * Send message to ResourceClient in event thread
438    * @param[in] message The message to send
439    */
440   void SendToClient( MessageBase* message );
441
442   /**
443    * Discard all dead resources.
444    * @param[in] updateBufferIndex The current update buffer index.
445    */
446   void DiscardDeadResources( BufferIndex updateBufferIndex );
447
448 private:
449   struct ResourceManagerImpl;
450   ResourceManagerImpl* mImpl;
451 };
452
453 // Messages sent to resource manager from other threads:
454 // These functions are run on other threads and insert messages to be
455 // picked-up by the update thread in its main loop and executed on that in
456 // submission order.
457
458 inline void RequestLoadResourceMessage( EventToUpdate& eventToUpdate,
459                                         ResourceManager& manager,
460                                         ResourceId id,
461                                         const ResourceTypePath& typePath,
462                                         Integration::LoadResourcePriority priority )
463 {
464   typedef MessageValue3< ResourceManager, ResourceId, ResourceTypePath, Integration::LoadResourcePriority > LocalType;
465
466   // Reserve some memory inside the message queue
467   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ), false );
468
469   // Construct message in the message queue memory; note that delete should not be called on the return value
470   new (slot) LocalType( &manager, &ResourceManager::HandleLoadResourceRequest, id, typePath, priority );
471 }
472
473 inline void RequestDecodeResourceMessage( EventToUpdate& eventToUpdate,
474                                           ResourceManager& manager,
475                                           const ResourceId id,
476                                           /// We use typePath instead of the raw type for ownership and to enable copying of a concrete type.
477                                           const ResourceTypePath& typePath,
478                                           RequestBufferPtr buffer,
479                                           Integration::LoadResourcePriority priority )
480 {
481   typedef MessageValue4< ResourceManager, ResourceId, ResourceTypePath, RequestBufferPtr, Integration::LoadResourcePriority > LocalType;
482
483   // Reserve some memory inside the message queue
484   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ), false );
485
486   // Construct message in the message queue memory; note that delete should not be called on the return value
487   new (slot) LocalType( &manager, &ResourceManager::HandleDecodeResourceRequest, id, typePath, buffer, priority );
488 }
489
490 inline void RequestAddBitmapImageMessage( EventToUpdate& eventToUpdate,
491                                           ResourceManager& manager,
492                                           ResourceId id,
493                                           Integration::Bitmap* resourceData )
494 {
495   typedef MessageValue2< ResourceManager, ResourceId, Integration::Bitmap* > LocalType;
496
497   // Reserve some memory inside the message queue
498   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
499
500   // Construct message in the message queue memory; note that delete should not be called on the return value
501   new (slot) LocalType( &manager, &ResourceManager::HandleAddBitmapImageRequest, id, resourceData );
502 }
503
504 inline void RequestAddNativeImageMessage( EventToUpdate& eventToUpdate,
505                                           ResourceManager& manager,
506                                           ResourceId id,
507                                           NativeImagePtr resourceData )
508 {
509   typedef MessageValue2< ResourceManager, ResourceId, NativeImagePtr > LocalType;
510
511   // Reserve some memory inside the message queue
512   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
513
514   // Construct message in the message queue memory; note that delete should not be called on the return value
515   new (slot) LocalType( &manager, &ResourceManager::HandleAddNativeImageRequest, id, resourceData );
516 }
517
518 inline void RequestAddFrameBufferImageMessage( EventToUpdate& eventToUpdate,
519                                                ResourceManager& manager,
520                                                ResourceId id,
521                                                unsigned int width,
522                                                unsigned int height,
523                                                Pixel::Format pixelFormat )
524 {
525   typedef MessageValue4< ResourceManager, ResourceId, unsigned int, unsigned int, Pixel::Format > LocalType;
526
527   // Reserve some memory inside the message queue
528   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
529
530   // Construct message in the message queue memory; note that delete should not be called on the return value
531   new (slot) LocalType( &manager, &ResourceManager::HandleAddFrameBufferImageRequest, id, width, height, pixelFormat );
532 }
533
534 inline void RequestAddFrameBufferImageMessage( EventToUpdate& eventToUpdate,
535                                                ResourceManager& manager,
536                                                ResourceId id,
537                                                NativeImagePtr resourceData )
538 {
539   typedef MessageValue2< ResourceManager, ResourceId, NativeImagePtr > LocalType;
540
541   // Reserve some memory inside the message queue
542   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
543
544   // Construct message in the message queue memory; note that delete should not be called on the return value
545   new (slot) LocalType( &manager, &ResourceManager::HandleAddFrameBufferImageRequest, id, resourceData );
546 }
547
548 inline void RequestAllocateTextureMessage(EventToUpdate& eventToUpdate,
549                                                ResourceManager& manager,
550                                                ResourceId id,
551                                                unsigned int width,
552                                                unsigned int height,
553                                                Pixel::Format pixelFormat)
554 {
555   typedef MessageValue4< ResourceManager, ResourceId, unsigned int, unsigned int, Pixel::Format > LocalType;
556
557   // Reserve some memory inside the message queue
558   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
559
560   // Construct message in the message queue memory; note that delete should not be called on the return value
561   new (slot) LocalType( &manager, &ResourceManager::HandleAllocateTextureRequest, id, width, height, pixelFormat );
562 }
563
564 inline void RequestUpdateTextureMessage(EventToUpdate& eventToUpdate,
565                                                ResourceManager& manager,
566                                                ResourceId id,
567                                                BitmapUploadArray uploadArray )
568 {
569   typedef MessageValue2< ResourceManager, ResourceId, BitmapUploadArray > LocalType;
570
571   // Reserve some memory inside the message queue
572   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
573
574   // Construct message in the message queue memory; note that delete should not be called on the return value
575   new (slot) LocalType( &manager, &ResourceManager::HandleUpdateTextureRequest, id, uploadArray );
576 }
577
578 inline void RequestAllocateMeshMessage( EventToUpdate& eventToUpdate,
579                                         ResourceManager& manager,
580                                         ResourceId id,
581                                         OwnerPointer<MeshData>& meshData )
582 {
583   typedef MessageValue2< ResourceManager, ResourceId, OwnerPointer<MeshData> > LocalType;
584
585   // Reserve some memory inside the message queue
586   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
587
588   // Construct message in the message queue memory; note that delete should not be called on the return value
589   new (slot) LocalType( &manager, &ResourceManager::HandleAllocateMeshRequest, id, meshData.Release() );
590 }
591
592 inline void RequestAllocateFontMessage( EventToUpdate& eventToUpdate,
593                                         ResourceManager& manager,
594                                         ResourceId id,
595                                         const std::string& familyNameAndStyle)
596 {
597   typedef MessageValue2< ResourceManager, ResourceId, std::string > LocalType;
598
599   // Reserve some memory inside the message queue
600   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
601
602   // Construct message in the message queue memory; note that delete should not be called on the return value
603   new (slot) LocalType( &manager, &ResourceManager::HandleAllocateFontRequest, id, familyNameAndStyle );
604 }
605
606 inline void RequestLoadShaderMessage( EventToUpdate& eventToUpdate,
607                                       ResourceManager& manager,
608                                       ResourceId id,
609                                       const ResourceTypePath& typePath )
610 {
611   typedef MessageValue2< ResourceManager, ResourceId, ResourceTypePath > LocalType;
612
613   // Reserve some memory inside the message queue
614   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
615
616   // Construct message in the message queue memory; note that delete should not be called on the return value
617   new (slot) LocalType( &manager, &ResourceManager::HandleLoadShaderRequest, id, typePath );
618 }
619
620 inline void RequestUpdateBitmapAreaMessage( EventToUpdate& eventToUpdate,
621                                             ResourceManager& manager,
622                                             ResourceId id,
623                                             const Dali::RectArea& area )
624 {
625   typedef MessageValue2< ResourceManager, ResourceId, Dali::RectArea > LocalType;
626
627   // Reserve some memory inside the message queue
628   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ), false );
629
630   // Construct message in the message queue memory; note that delete should not be called on the return value
631   new (slot) LocalType( &manager, &ResourceManager::HandleUpdateBitmapAreaRequest, id, area );
632 }
633
634 inline void RequestUpdateMeshMessage( EventToUpdate& eventToUpdate,
635                                       ResourceManager& manager,
636                                       ResourceId id,
637                                       const Dali::MeshData& meshData )
638 {
639   typedef MessageDoubleBuffered2< ResourceManager, ResourceId, OwnerPointer< MeshData > > LocalType;
640
641   // Reserve some memory inside the message queue
642   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
643
644   MeshData* internalMeshData = new MeshData( meshData, true, false );
645
646   // Construct message in the message queue memory; note that delete should not be called on the return value
647   new (slot) LocalType( &manager, &ResourceManager::HandleUpdateMeshRequest, id, internalMeshData );
648 }
649
650 inline void RequestReloadResourceMessage( EventToUpdate& eventToUpdate,
651                                           ResourceManager& manager,
652                                           ResourceId id,
653                                           const ResourceTypePath& typePath,
654                                           Integration::LoadResourcePriority priority )
655 {
656   typedef MessageValue3< ResourceManager, ResourceId, ResourceTypePath, Integration::LoadResourcePriority > LocalType;
657
658   // Reserve some memory inside the message queue
659   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ), false );
660
661   // Construct message in the message queue memory; note that delete should not be called on the return value
662   new (slot) LocalType( &manager, &ResourceManager::HandleReloadResourceRequest, id, typePath, priority );
663 }
664
665 inline void RequestSaveResourceMessage( EventToUpdate& eventToUpdate,
666                                         ResourceManager& manager,
667                                         ResourceId id,
668                                         const ResourceTypePath& typePath )
669 {
670   typedef MessageValue2< ResourceManager, ResourceId, ResourceTypePath > LocalType;
671
672   // Reserve some memory inside the message queue
673   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
674
675   // Construct message in the message queue memory; note that delete should not be called on the return value
676   new (slot) LocalType( &manager, &ResourceManager::HandleSaveResourceRequest, id, typePath );
677 }
678
679 inline void RequestDiscardResourceMessage( EventToUpdate& eventToUpdate,
680                                            ResourceManager& manager,
681                                            ResourceId id,
682                                            Integration::ResourceTypeId typeId )
683 {
684   typedef MessageValue2< ResourceManager, ResourceId, Integration::ResourceTypeId > LocalType;
685
686   // Reserve some memory inside the message queue
687   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
688
689   // Construct message in the message queue memory; note that delete should not be called on the return value
690   new (slot) LocalType( &manager, &ResourceManager::HandleDiscardResourceRequest, id, typeId );
691 }
692
693 inline void RequestAtlasUpdateMessage( EventToUpdate& eventToUpdate,
694                                        ResourceManager& manager,
695                                        ResourceId id,
696                                        ResourceId atlasId,
697                                        Integration::LoadStatus loadStatus )
698 {
699   typedef MessageValue3< ResourceManager, ResourceId, ResourceId, Integration::LoadStatus > LocalType;
700
701   // Reserve some memory inside the message queue
702   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
703
704   // Construct message in the message queue memory; note that delete should not be called on the return value
705   new (slot) LocalType( &manager, &ResourceManager::HandleAtlasUpdateRequest, id, atlasId, loadStatus );
706 }
707
708 } // namespace Internal
709
710 } // namespace Dali
711
712 #endif // __DALI_INTERNAL_RESOURCE_MANAGER_H__