1 #ifndef __DALI_INTERNAL_TEXTURE_CACHE_DISPATCHER_H__
2 #define __DALI_INTERNAL_TEXTURE_CACHE_DISPATCHER_H__
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
40 typedef Integration::ResourceId ResourceId;
48 class TextureCacheDispatcher
54 * @param[in] renderQueue The queue on which to send messages
55 * @param[in] textureCache The Texture Cache object to which to send messages
57 TextureCacheDispatcher( RenderQueue& renderQueue, TextureCache& textureCache );
62 ~TextureCacheDispatcher();
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 :/ )
71 * @param[in] bufferIndices Pointer to SceneGraphBuffers object that can query
72 * the current RenderQueue buffer index.
74 void SetBufferIndices( const SceneGraphBuffers* bufferIndices );
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
85 void DispatchCreateTexture( ResourceId id,
88 Pixel::Format pixelFormat,
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
97 void DispatchCreateTextureForBitmap( ResourceId id, Integration::Bitmap* bitmap );
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
105 void DispatchCreateTextureForNativeImage( ResourceId id, NativeImageInterfacePtr nativeImage );
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
115 void DispatchCreateTextureForFrameBuffer( ResourceId id, unsigned int width, unsigned int height, Pixel::Format pixelFormat, RenderBuffer::Format bufferFormat );
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
123 void DispatchCreateTextureForFrameBuffer( ResourceId id, NativeImageInterfacePtr nativeImage );
126 * @brief Create GL texture for native image resource.
127 * @param[in] id The resource id.
129 void DispatchCreateGlTexture( ResourceId id );
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
137 void DispatchUpdateTexture( ResourceId id, Integration::Bitmap* bitmap );
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
147 void DispatchUpdateTexture( ResourceId id, Integration::BitmapPtr bitmap, std::size_t xOffset, std::size_t yOffset );
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
157 void DispatchUpdateTexture( ResourceId destId, ResourceId srcId, std::size_t xOffset, std::size_t yOffset );
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
167 void DispatchUpdateTexture( ResourceId id, PixelDataPtr pixelData, std::size_t xOffset, std::size_t yOffset );
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
175 void DispatchUpdateTextureArea( ResourceId id, const RectArea& area );
178 * Dispatch a message to discard a texture
179 * May be called from Update thread
180 * @param[in] id Resource Id of the texture
182 void DispatchDiscardTexture( ResourceId id );
186 RenderQueue& mRenderQueue;
187 TextureCache& mTextureCache;
188 const SceneGraphBuffers* mSceneGraphBuffers;
197 #endif // __DALI_INTERNAL_TEXTURE_CACHE_DISPATCHER_H__