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