Moved OwnerContainer from internal to devel-api.
[platform/core/uifw/dali-core.git] / dali / internal / render / common / texture-cache-dispatcher.h
1 #ifndef __DALI_INTERNAL_TEXTURE_CACHE_DISPATCHER_H__
2 #define __DALI_INTERNAL_TEXTURE_CACHE_DISPATCHER_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 <stdint.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/images/native-image-interface.h>
26 #include <dali/public-api/images/buffer-image.h>
27 #include <dali/public-api/images/pixel.h>
28 #include <dali/public-api/images/frame-buffer-image.h>
29 #include <dali/internal/common/message.h>
30 #include <dali/internal/update/common/scene-graph-buffers.h>
31 #include <dali/integration-api/resource-declarations.h>
32 #include <dali/integration-api/bitmap.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39 typedef Integration::ResourceId ResourceId;
40
41 namespace SceneGraph
42 {
43
44 class RenderQueue;
45
46 class TextureCacheDispatcher
47 {
48 public:
49
50   /**
51    * Constructor
52    * @param[in] renderQueue The queue to which to send messages
53    */
54   TextureCacheDispatcher( RenderQueue& renderQueue );
55
56   /**
57    * Virtual destructor; TextureCacheDispatcher is a base class.
58    */
59   virtual ~TextureCacheDispatcher();
60
61   /**
62    * mRenderQueue needs the update buffer index when any of the dispatch methods are
63    * called. Should really store a functor to get this index, but existing functors
64    * use references. Could heap allocate the functor, but that seems overly wasteful.
65    * Instead, store a pointer to the SceneGraphBuffers object, and call the relevant
66    * function when required. (increases coupling, requires object lifetime management :/ )
67    *
68    * @param[in] bufferIndices Pointer to SceneGraphBuffers object that can query
69    * the current RenderQueue buffer index.
70    */
71   void SetBufferIndices( const SceneGraphBuffers* bufferIndices );
72
73   /**
74    * Dispatch a message to create an empty texture and add it to the texture cache.
75    * May be called from Update thread
76    * @param[in] id Resource Id of the texture
77    * @param[in] width Width of the texture
78    * @param[in] height Height of the texture
79    * @param[in] pixelFormat Pixel format of the texture
80    * @param[in] clearPixels True if the data should be cleared to 0 on creation
81    */
82   virtual void DispatchCreateTexture( ResourceId        id,
83                                       unsigned int      width,
84                                       unsigned int      height,
85                                       Pixel::Format     pixelFormat,
86                                       bool              clearPixels ) = 0;
87
88   /**
89    * Dispatch a message to add a texture for bitmap.
90    * May be called from Update thread
91    * @param[in] id Resource Id of the bitmap
92    * @param[in] bitmap The bitmap
93    */
94   virtual void DispatchCreateTextureForBitmap( ResourceId id, Integration::Bitmap* bitmap ) = 0;
95
96   /**
97    * Dispatch a message to add a native image to the texture cache
98    * May be called from Update thread
99    * @param[in] id Resource Id of the native image
100    * @param[in] nativeImage The native image
101    */
102   virtual void DispatchCreateTextureForNativeImage( ResourceId id, NativeImageInterfacePtr nativeImage ) = 0;
103
104   /**
105    * Dispatch a message to create a framebuffer texture and add it to the texture cache
106    * May be called from Update thread
107    * @param[in] id Resource Id of the framebuffer
108    * @param[in] width Width of the framebuffer
109    * @param[in] height Height of the framebuffer
110    * @param[in] pixelFormat Pixel format of the framebuffer
111    */
112   virtual void DispatchCreateTextureForFrameBuffer( ResourceId id, unsigned int width, unsigned int height, Pixel::Format pixelFormat, RenderBuffer::Format bufferFormat ) = 0;
113
114   /**
115    * Dispatch a message to create a framebuffer texture and add it to the texture cache
116    * May be called from Update thread
117    * @param[in] id Resource Id of the framebuffer
118    * @param[in] nativeImage The NativeImage
119    */
120   virtual void DispatchCreateTextureForFrameBuffer( ResourceId id, NativeImageInterfacePtr nativeImage ) = 0;
121
122   /**
123    * @brief Create GL texture for native image resource.
124    * @param[in] id The resource id.
125    */
126   virtual void DispatchCreateGlTexture( ResourceId id ) = 0;
127
128   /**
129    * Dispatch a message to update the texture.
130    * May be called from Update thread
131    * @param[in] id Resource Id of the texture
132    * @param[in] bitmap The updated bitmap
133    */
134   virtual void DispatchUpdateTexture( ResourceId id, Integration::Bitmap* bitmap ) = 0;
135
136   /**
137    * Dispatch a message to update the part of a texture with the bitmap data.
138    * May be called from Update thread
139    * @param[in] destId The ID of the texture to update
140    * @param[in] bitmap The pointer pointing to the source bitmap data.
141    * @param [in] xOffset Specifies an offset in the x direction within the texture
142    * @param [in] yOffset Specifies an offset in the y direction within the texture
143    */
144   virtual void DispatchUpdateTexture( ResourceId id, Integration::BitmapPtr bitmap, std::size_t xOffset, std::size_t yOffset ) = 0;
145
146   /**
147    * Dispatch a message to update the part of a texture with a newly loaded bitmap
148    * May be called from Update thread
149    * @param[in] destId The ID of the texture to update
150    * @param[in] srcId The resource ID of the source bitmap
151    * @param [in] xOffset Specifies an offset in the x direction within the texture
152    * @param [in] yOffset Specifies an offset in the y direction within the texture
153    */
154   virtual void DispatchUpdateTexture( ResourceId destId, ResourceId srcId, std::size_t xOffset, std::size_t yOffset ) = 0;
155
156   /**
157    * Dispatch a message to update the texture area
158    * May be called from the Update thread
159    * @param[in] id Resource Id of the texture
160    * @param[in] area The area of the bitmap that has changed
161    */
162   virtual void DispatchUpdateTextureArea( ResourceId id, const RectArea& area ) = 0;
163
164   /**
165    * Dispatch a message to discard a texture
166    * May be called from Update thread
167    * @param[in] id Resource Id of the texture
168    */
169   virtual void DispatchDiscardTexture( ResourceId id ) = 0;
170
171 protected:
172
173   RenderQueue&             mRenderQueue;
174   const SceneGraphBuffers* mSceneGraphBuffers;
175 };
176
177 } // SceneGraph
178
179 } // Internal
180
181 } // Dali
182
183 #endif // __DALI_INTERNAL_TEXTURE_CACHE_DISPATCHER_H__