2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/update/common/texture-cache-dispatcher.h>
22 #include <dali/internal/render/queue/render-queue.h>
23 #include <dali/internal/render/gl-resources/texture-cache.h>
31 // value types used by messages
32 template <> struct ParameterType< Pixel::Format > : public BasicType< Pixel::Format > {};
33 template <> struct ParameterType< RenderBuffer::Format > : public BasicType< RenderBuffer::Format > {};
38 TextureCacheDispatcher::TextureCacheDispatcher( RenderQueue& renderQueue, TextureCache& textureCache )
39 : mRenderQueue( renderQueue ),
40 mTextureCache( textureCache ),
41 mSceneGraphBuffers(NULL)
45 TextureCacheDispatcher::~TextureCacheDispatcher()
49 void TextureCacheDispatcher::SetBufferIndices( const SceneGraphBuffers* bufferIndices )
51 mSceneGraphBuffers = bufferIndices;
54 /********************************************************************************
55 ********************** Implements TextureCacheDispatcher *********************
56 ********************************************************************************/
58 void TextureCacheDispatcher::DispatchCreateTexture( ResourceId id,
61 Pixel::Format pixelFormat,
64 // NULL, means being shutdown, so ignore msgs
65 if( mSceneGraphBuffers != NULL )
67 typedef MessageValue5< TextureCache, ResourceId, unsigned int, unsigned int, Pixel::Format, bool > DerivedType;
69 // Reserve some memory inside the render queue
70 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
72 // Construct message in the render queue memory; note that delete should not be called on the return value
73 new (slot) DerivedType( &mTextureCache, &TextureCache::CreateTexture, id, width, height, pixelFormat, clearPixels );
77 void TextureCacheDispatcher::DispatchCreateTextureForBitmap( ResourceId id, Integration::Bitmap* bitmap )
79 // NULL, means being shutdown, so ignore msgs
80 if( mSceneGraphBuffers != NULL )
82 typedef MessageValue2< TextureCache, ResourceId, Integration::BitmapPtr > DerivedType;
84 // Reserve some memory inside the render queue
85 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
87 // Construct message in the render queue memory; note that delete should not be called on the return value
88 new (slot) DerivedType( &mTextureCache, &TextureCache::AddBitmap, id, bitmap );
92 void TextureCacheDispatcher::DispatchCreateTextureForNativeImage( ResourceId id, NativeImageInterfacePtr nativeImage )
94 // NULL, means being shutdown, so ignore msgs
95 if( mSceneGraphBuffers != NULL )
97 typedef MessageValue2< TextureCache, ResourceId, NativeImageInterfacePtr > DerivedType;
99 // Reserve some memory inside the render queue
100 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
102 // Construct message in the render queue memory; note that delete should not be called on the return value
103 new (slot) DerivedType( &mTextureCache, &TextureCache::AddNativeImage, id, nativeImage );
107 void TextureCacheDispatcher::DispatchCreateGlTexture( ResourceId id )
109 // NULL, means being shutdown, so ignore msgs
110 if( mSceneGraphBuffers != NULL )
112 typedef MessageValue1< TextureCache, ResourceId > DerivedType;
114 // Reserve some memory inside the render queue
115 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
117 // Construct message in the render queue memory; note that delete should not be called on the return value
118 new (slot) DerivedType( &mTextureCache, &TextureCache::CreateGlTexture, id );
122 void TextureCacheDispatcher::DispatchCreateTextureForFrameBuffer( ResourceId id, unsigned int width, unsigned int height, Pixel::Format pixelFormat, RenderBuffer::Format bufferFormat )
124 // NULL, means being shutdown, so ignore msgs
125 if( mSceneGraphBuffers != NULL )
127 typedef MessageValue5< TextureCache, ResourceId, unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format > DerivedType;
129 // Reserve some memory inside the render queue
130 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
132 // Construct message in the render queue memory; note that delete should not be called on the return value
133 new (slot) DerivedType( &mTextureCache, &TextureCache::AddFrameBuffer, id, width, height, pixelFormat, bufferFormat );
137 void TextureCacheDispatcher::DispatchCreateTextureForFrameBuffer( ResourceId id, NativeImageInterfacePtr nativeImage )
139 // NULL, means being shutdown, so ignore msgs
140 if( mSceneGraphBuffers != NULL )
142 typedef MessageValue2< TextureCache, ResourceId, NativeImageInterfacePtr > DerivedType;
144 // Reserve some memory inside the render queue
145 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
147 // Construct message in the render queue memory; note that delete should not be called on the return value
148 new (slot) DerivedType( &mTextureCache, &TextureCache::AddFrameBuffer, id, nativeImage );
152 void TextureCacheDispatcher::DispatchUpdateTexture( ResourceId id, Integration::Bitmap* bitmap )
154 // NULL, means being shutdown, so ignore msgs
155 if( mSceneGraphBuffers != NULL )
157 typedef MessageValue2< TextureCache, ResourceId, Integration::BitmapPtr > DerivedType;
159 // Reserve some memory inside the render queue
160 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
162 // Construct message in the render queue memory; note that delete should not be called on the return value
163 new (slot) DerivedType( &mTextureCache, &TextureCache::UpdateTexture, id, bitmap );
167 void TextureCacheDispatcher::DispatchUpdateTexture( ResourceId id, Integration::BitmapPtr bitmap , std::size_t xOffset, std::size_t yOffset)
169 // NULL, means being shutdown, so ignore msgs
170 if( mSceneGraphBuffers != NULL )
172 typedef MessageValue4< TextureCache, ResourceId, Integration::BitmapPtr, std::size_t, std::size_t > DerivedType;
174 // Reserve some memory inside the render queue
175 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
177 // Construct message in the render queue memory; note that delete should not be called on the return value
178 new (slot) DerivedType( &mTextureCache, &TextureCache::UpdateTexture, id, bitmap, xOffset, yOffset );
182 void TextureCacheDispatcher::DispatchUpdateTexture( ResourceId destId, ResourceId srcId, std::size_t xOffset, std::size_t yOffset )
184 // NULL, means being shutdown, so ignore msgs
185 if( mSceneGraphBuffers != NULL )
187 typedef MessageValue4< TextureCache, ResourceId, ResourceId, std::size_t, std::size_t > DerivedType;
189 // Reserve some memory inside the render queue
190 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
192 // Construct message in the render queue memory; note that delete should not be called on the return value
193 new (slot) DerivedType( &mTextureCache, &TextureCache::UpdateTexture, destId, srcId, xOffset, yOffset );
197 void TextureCacheDispatcher::DispatchUpdateTexture( ResourceId id, PixelDataPtr pixelData , std::size_t xOffset, std::size_t yOffset)
199 // NULL, means being shutdown, so ignore msgs
200 if( mSceneGraphBuffers != NULL )
202 typedef MessageValue4< TextureCache, ResourceId, PixelDataPtr, std::size_t, std::size_t > DerivedType;
204 // Reserve some memory inside the render queue
205 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
207 // Construct message in the render queue memory; note that delete should not be called on the return value
208 new (slot) DerivedType( &mTextureCache, &TextureCache::UpdateTexture, id, pixelData, xOffset, yOffset );
212 void TextureCacheDispatcher::DispatchUpdateTextureArea( ResourceId id, const Dali::RectArea& area )
214 // NULL, means being shutdown, so ignore msgs
215 if( mSceneGraphBuffers != NULL )
217 typedef MessageValue2< TextureCache, ResourceId, Dali::RectArea > DerivedType;
219 // Reserve some memory inside the render queue
220 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
222 // Construct message in the render queue memory; note that delete should not be called on the return value
223 new (slot) DerivedType( &mTextureCache, &TextureCache::UpdateTextureArea, id, area );
227 void TextureCacheDispatcher::DispatchDiscardTexture( ResourceId id )
229 // NULL, means being shutdown, so ignore msgs
230 if( mSceneGraphBuffers != NULL )
232 typedef MessageValue1< TextureCache, ResourceId > DerivedType;
234 // Reserve some memory inside the render queue
235 unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
237 // Construct message in the render queue memory; note that delete should not be called on the return value
238 new (slot) DerivedType( &mTextureCache, &TextureCache::DiscardTexture, id );