1ea5f802423ced3c7826df467e872dd2a50e23d5
[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.h>
26 #include <dali/public-api/images/bitmap-image.h>
27 #include <dali/public-api/images/pixel.h>
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/update/common/scene-graph-buffers.h>
30 #include <dali/internal/common/bitmap-upload.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, NativeImagePtr 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 ) = 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, NativeImagePtr nativeImage ) = 0;
121
122   /**
123    * Dispatch a message to update the texture.
124    * May be called from Update thread
125    * @param[in] id Resource Id of the texture
126    * @param[in] bitmap The updated bitmap
127    */
128   virtual void DispatchUpdateTexture( ResourceId id, Integration::Bitmap* bitmap ) = 0;
129
130   /**
131    * Update the part of a texture with a newly loaded bitmap
132    * May be called from Update thread
133    * @param[in] destId The ID of the texture to update
134    * @param[in] srcId The resource ID of the source bitmap
135    * @param [in] xOffset Specifies an offset in the x direction within the texture
136    * @param [in] yOffset Specifies an offset in the y direction within the texture
137    */
138   virtual void DispatchUpdateTexture( ResourceId destId, ResourceId srcId,std::size_t xOffset, std::size_t yOffset ) = 0;
139
140   /**
141    * Dispatch a message to update the texture area
142    * May be called from the Update thread
143    * @param[in] id Resource Id of the texture
144    * @param[in] area The area of the bitmap that has changed
145    */
146   virtual void DispatchUpdateTextureArea( ResourceId id, const RectArea& area ) = 0;
147
148  /**
149    * Dispatch a message to insert an array of bitmaps into the texture.
150    * Used for uploading multiple images into an atlas.
151    * @param[in] id Resource id of the texture
152    * @param[in] uploadArray array of BitmapUpload structures
153    */
154   virtual void DispatchUploadBitmapArrayToTexture( ResourceId id, const BitmapUploadArray& uploadArray ) = 0;
155
156   /**
157    * Dispatch a message to clear multiple areas of a texture to a specific color
158    * @param[in] id Resource id of the texture to clear
159    * @param[in] area Rectangles to clear
160    * @param[in] blockSize Size of block to clear
161    * @param[in] color Clear color (as a pixel value)
162    */
163   virtual void DispatchClearAreas( ResourceId id, const BitmapClearArray& area, std::size_t blockSize, uint32_t color ) = 0;
164
165   /**
166    * Dispatch a message to discard a texture
167    * May be called from Update thread
168    * @param[in] id Resource Id of the texture
169    */
170   virtual void DispatchDiscardTexture( ResourceId id ) = 0;
171
172 protected:
173
174   RenderQueue&             mRenderQueue;
175   const SceneGraphBuffers* mSceneGraphBuffers;
176 };
177
178 } // SceneGraph
179
180 } // Internal
181
182 } // Dali
183
184 #endif // __DALI_INTERNAL_TEXTURE_CACHE_DISPATCHER_H__