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