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