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