Revert "[Tizen] Fix FrameBuffer sync issue, etc."
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / texture-set-impl.cpp
1 /*
2  * Copyright (c) 2019 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/event/rendering/texture-set-impl.h> // Dali::Internal::TextureSet
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/internal/update/manager/update-manager.h>
24 #include <dali/internal/update/rendering/scene-graph-texture-set.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30
31 TextureSetPtr TextureSet::New()
32 {
33   TextureSetPtr textureSet( new TextureSet() );
34   textureSet->Initialize();
35   return textureSet;
36 }
37
38 void TextureSet::SetTexture( uint32_t index, TexturePtr texture )
39 {
40   uint32_t textureCount = static_cast<uint32_t>( mTextures.size() );
41   if( index >= textureCount )
42   {
43     mTextures.resize(index + 1);
44
45     bool samplerExist = true;
46     if( mSamplers.size() < index + 1 )
47     {
48       mSamplers.resize( index + 1 );
49       samplerExist = false;
50     }
51
52     for( uint32_t i(textureCount); i<=index; ++i )
53     {
54       mTextures[i] = NULL;
55
56       if( !samplerExist )
57       {
58         mSamplers[i] = NULL;
59       }
60     }
61   }
62
63   mTextures[index]= texture;
64
65   Render::Texture* renderTexture(0);
66   if( texture )
67   {
68     renderTexture = texture->GetRenderObject();
69   }
70
71   SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
72 }
73
74 Texture* TextureSet::GetTexture( uint32_t index ) const
75 {
76   Texture* result(0);
77   if( index < mTextures.size() )
78   {
79     result = mTextures[index].Get();
80   }
81   else
82   {
83     DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture\n");
84   }
85
86   return result;
87 }
88
89 void TextureSet::SetImage( uint32_t index, ImagePtr image )
90 {
91   Texture* texture( NULL );
92   if( image )
93   {
94     uint32_t textureCount = static_cast<uint32_t>( mImages.size() );
95     if( index >= textureCount )
96     {
97       mImages.resize(index + 1);
98     }
99     mImages[index] = image;
100
101     texture = image->GetTexture();
102   }
103
104   SetTexture( index, texture );
105 }
106
107 Image* TextureSet::GetImage( uint32_t index ) const
108 {
109   Image* result( NULL );
110   if( index < mImages.size() )
111   {
112     result = mImages[index].Get();
113   }
114   else
115   {
116     DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage\n");
117   }
118
119   return result;
120 }
121
122 void TextureSet::SetSampler( uint32_t index, SamplerPtr sampler )
123 {
124   uint32_t samplerCount = static_cast<uint32_t>( mSamplers.size() );
125   if( samplerCount < index + 1  )
126   {
127     mSamplers.resize( index + 1 );
128     for( uint32_t i = samplerCount; i<=index; ++i )
129     {
130       mSamplers[i] = NULL;
131     }
132   }
133
134   mSamplers[index] = sampler;
135
136   Render::Sampler* renderSampler(0);
137   if( sampler )
138   {
139     renderSampler = sampler->GetSamplerRenderObject();
140   }
141
142   SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
143 }
144
145 Sampler* TextureSet::GetSampler( uint32_t index ) const
146 {
147   Sampler* result(0);
148   if( index < mSamplers.size() )
149   {
150     result = mSamplers[index].Get();
151   }
152   else
153   {
154     DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler\n");
155   }
156
157   return result;
158 }
159
160 uint32_t TextureSet::GetTextureCount() const
161 {
162   return static_cast<uint32_t>( mTextures.size() );
163 }
164
165 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
166 {
167   return mSceneObject;
168 }
169
170 TextureSet::TextureSet()
171 :mEventThreadServices( EventThreadServices::Get() ),
172  mSceneObject( NULL )
173 {
174 }
175
176 void TextureSet::Initialize()
177 {
178   SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
179
180   mSceneObject = SceneGraph::TextureSet::New();
181   OwnerPointer< SceneGraph::TextureSet > transferOwnership( mSceneObject );
182   AddTextureSetMessage( updateManager, transferOwnership );
183 }
184
185 TextureSet::~TextureSet()
186 {
187   if( EventThreadServices::IsCoreRunning() )
188   {
189     SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
190     RemoveTextureSetMessage( updateManager, *mSceneObject );
191   }
192 }
193
194 } // namespace Internal
195 } // namespace Dali