bf17c063f3e495f0d4abbcd23d95b885f21cb8d1
[platform/core/uifw/dali-core.git] / dali / internal / update / common / texture-cache-dispatcher.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/common/texture-cache-dispatcher.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/render/queue/render-queue.h>
23 #include <dali/internal/render/gl-resources/texture-cache.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
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 > {};
34
35 namespace SceneGraph
36 {
37
38 TextureCacheDispatcher::TextureCacheDispatcher( RenderQueue& renderQueue, TextureCache& textureCache )
39 : mRenderQueue( renderQueue ),
40   mTextureCache( textureCache ),
41   mSceneGraphBuffers(NULL)
42 {
43 }
44
45 TextureCacheDispatcher::~TextureCacheDispatcher()
46 {
47 }
48
49 void TextureCacheDispatcher::SetBufferIndices( const SceneGraphBuffers* bufferIndices )
50 {
51   mSceneGraphBuffers = bufferIndices;
52 }
53
54 /********************************************************************************
55  **********************  Implements TextureCacheDispatcher  *********************
56  ********************************************************************************/
57
58 void TextureCacheDispatcher::DispatchCreateTexture( ResourceId        id,
59                                                     unsigned int      width,
60                                                     unsigned int      height,
61                                                     Pixel::Format     pixelFormat,
62                                                     bool              clearPixels )
63 {
64   // NULL, means being shutdown, so ignore msgs
65   if( mSceneGraphBuffers != NULL )
66   {
67     typedef MessageValue5< TextureCache, ResourceId, unsigned int, unsigned int, Pixel::Format, bool > DerivedType;
68
69     // Reserve some memory inside the render queue
70     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
71
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 );
74   }
75 }
76
77 void TextureCacheDispatcher::DispatchCreateTextureForBitmap( ResourceId id, Integration::Bitmap* bitmap )
78 {
79   // NULL, means being shutdown, so ignore msgs
80   if( mSceneGraphBuffers != NULL )
81   {
82     typedef MessageValue2< TextureCache, ResourceId, Integration::BitmapPtr > DerivedType;
83
84     // Reserve some memory inside the render queue
85     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
86
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 );
89   }
90 }
91
92 void TextureCacheDispatcher::DispatchCreateTextureForNativeImage( ResourceId id, NativeImageInterfacePtr nativeImage )
93 {
94   // NULL, means being shutdown, so ignore msgs
95   if( mSceneGraphBuffers != NULL )
96   {
97     typedef MessageValue2< TextureCache, ResourceId, NativeImageInterfacePtr > DerivedType;
98
99     // Reserve some memory inside the render queue
100     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
101
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 );
104   }
105 }
106
107 void TextureCacheDispatcher::DispatchCreateGlTexture( ResourceId id )
108 {
109   // NULL, means being shutdown, so ignore msgs
110   if( mSceneGraphBuffers != NULL )
111   {
112     typedef MessageValue1< TextureCache, ResourceId > DerivedType;
113
114     // Reserve some memory inside the render queue
115     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
116
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 );
119   }
120 }
121
122 void TextureCacheDispatcher::DispatchCreateTextureForFrameBuffer( ResourceId id, unsigned int width, unsigned int height, Pixel::Format pixelFormat, RenderBuffer::Format bufferFormat )
123 {
124   // NULL, means being shutdown, so ignore msgs
125   if( mSceneGraphBuffers != NULL )
126   {
127     typedef MessageValue5< TextureCache, ResourceId, unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format > DerivedType;
128
129     // Reserve some memory inside the render queue
130     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
131
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 );
134   }
135 }
136
137 void TextureCacheDispatcher::DispatchCreateTextureForFrameBuffer( ResourceId id, NativeImageInterfacePtr nativeImage )
138 {
139   // NULL, means being shutdown, so ignore msgs
140   if( mSceneGraphBuffers != NULL )
141   {
142     typedef MessageValue2< TextureCache, ResourceId, NativeImageInterfacePtr > DerivedType;
143
144     // Reserve some memory inside the render queue
145     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
146
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 );
149   }
150 }
151
152 void TextureCacheDispatcher::DispatchUpdateTexture( ResourceId id, Integration::Bitmap* bitmap )
153 {
154   // NULL, means being shutdown, so ignore msgs
155   if( mSceneGraphBuffers != NULL )
156   {
157     typedef MessageValue2< TextureCache, ResourceId, Integration::BitmapPtr > DerivedType;
158
159     // Reserve some memory inside the render queue
160     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
161
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 );
164   }
165 }
166
167 void TextureCacheDispatcher::DispatchUpdateTexture( ResourceId id, Integration::BitmapPtr bitmap , std::size_t xOffset, std::size_t yOffset)
168 {
169   // NULL, means being shutdown, so ignore msgs
170   if( mSceneGraphBuffers != NULL )
171   {
172     typedef MessageValue4< TextureCache, ResourceId, Integration::BitmapPtr, std::size_t, std::size_t > DerivedType;
173
174     // Reserve some memory inside the render queue
175     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
176
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 );
179   }
180 }
181
182 void TextureCacheDispatcher::DispatchUpdateTexture( ResourceId destId, ResourceId srcId, std::size_t xOffset, std::size_t yOffset )
183 {
184   // NULL, means being shutdown, so ignore msgs
185   if( mSceneGraphBuffers != NULL )
186   {
187     typedef MessageValue4< TextureCache, ResourceId, ResourceId, std::size_t, std::size_t > DerivedType;
188
189     // Reserve some memory inside the render queue
190     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
191
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 );
194   }
195 }
196
197 void TextureCacheDispatcher::DispatchUpdateTexture( ResourceId id, PixelDataPtr pixelData , std::size_t xOffset, std::size_t yOffset)
198 {
199   // NULL, means being shutdown, so ignore msgs
200   if( mSceneGraphBuffers != NULL )
201   {
202     typedef MessageValue4< TextureCache, ResourceId, PixelDataPtr, std::size_t, std::size_t > DerivedType;
203
204     // Reserve some memory inside the render queue
205     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
206
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 );
209   }
210 }
211
212 void TextureCacheDispatcher::DispatchUpdateTextureArea( ResourceId id, const Dali::RectArea& area )
213 {
214   // NULL, means being shutdown, so ignore msgs
215   if( mSceneGraphBuffers != NULL )
216   {
217     typedef MessageValue2< TextureCache, ResourceId, Dali::RectArea > DerivedType;
218
219     // Reserve some memory inside the render queue
220     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
221
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 );
224   }
225 }
226
227 void TextureCacheDispatcher::DispatchDiscardTexture( ResourceId id )
228 {
229   // NULL, means being shutdown, so ignore msgs
230   if( mSceneGraphBuffers != NULL )
231   {
232     typedef MessageValue1< TextureCache, ResourceId > DerivedType;
233
234     // Reserve some memory inside the render queue
235     unsigned int* slot = mRenderQueue.ReserveMessageSlot( mSceneGraphBuffers->GetUpdateBufferIndex(), sizeof( DerivedType ) );
236
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 );
239   }
240 }
241
242 } // SceneGraph
243
244 } // Internal
245
246 } // Dali