Removing rendering backend
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-texture-set.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
3
4 /*
5  * Copyright (c) 2018 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 // INTERNAL INCLUDES
21 #include <dali/public-api/rendering/texture-set.h>
22 #include <dali/internal/common/buffer-index.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/event/common/event-thread-services.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace SceneGraph
31 {
32
33 class Renderer;
34 class Sampler;
35 class Texture;
36
37 class TextureSet
38 {
39 public:
40
41   /**
42    * Construct a new TextureSet.
43    */
44   static TextureSet* New();
45
46   /**
47    * Destructor
48    */
49   virtual ~TextureSet();
50
51   /**
52    * Overriden delete operator
53    * Deletes the texture set from its global memory pool
54    */
55   void operator delete( void* ptr );
56
57   /**
58    * Set the sampler to be used by the texture at position "index"
59    * @param[in] index The index of the texture
60    * @param[in] sampler The sampler to be used by the texture
61    */
62   void SetSampler( size_t index, SceneGraph::Sampler* sampler );
63
64   /**
65    * Set the texture at position "index"
66    * @param[in] index The index of the texture
67    * @param[in] texture The texture
68    */
69   void SetTexture( size_t index, SceneGraph::Texture* texture );
70
71   /**
72    * Return whether any texture in the texture set has an alpha channel
73    * @return true if at least one texture in the texture set has an alpha channel, false otherwise
74    */
75   bool HasAlpha() const;
76
77   /**
78    * Adds a renderer to the Renderers list of the texture set.
79    * Renderers using the TextureSet get a notification when the texture set changes
80    *
81    * @param[in] renderer The renderer using the TextureSet
82    */
83   void AddObserver( Renderer* renderer );
84
85   /**
86    * Removes a renderer from the TextureSet renderers list
87    *
88    * @param[in] renderer The renderer no longer using the TextureSet
89    */
90   void RemoveObserver( Renderer* renderer );
91
92   /**
93    * Get the sampler of a texture in the TextureSet
94    * @param[in] index The index of the texture in the textures array
95    * @return the sampler used by the texture
96    */
97   SceneGraph::Sampler* GetTextureSampler( size_t index )
98   {
99     return mSamplers[index];
100   }
101
102   /**
103    * Get the number of Textures in the texture set
104    * @return The number of Textures
105    */
106   size_t GetTextureCount()
107   {
108     return mTextures.Size();
109   }
110
111   /**
112    * Get the pointer to  a Texture in the TextureSet
113    * @param[in] index The index of the texture in the textures array
114    * @return the pointer to the Texture in that position
115    */
116   SceneGraph::Texture* GetTexture( size_t index )
117   {
118     return mTextures[index];
119   }
120
121 private:
122
123   /**
124    * Protected constructor; See also TextureSet::New()
125    */
126   TextureSet();
127
128   /**
129    * Helper method to notify the renderers observing the TextureSet
130    * that the TextureSet has changed
131    */
132   void NotifyChangeToRenderers();
133
134 private: // Data
135
136   Vector< SceneGraph::Sampler* >  mSamplers;  ///< List of samplers used by each texture. Not owned
137   Vector< SceneGraph::Texture* >  mTextures;  ///< List of Textures. Not owned
138   Vector<Renderer*>               mRenderers; ///< List of renderers using the TextureSet
139   bool                            mHasAlpha;  ///< if any of the textures has an alpha channel
140 };
141
142 inline void SetTextureMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, SceneGraph::Texture* texture )
143 {
144   typedef MessageValue2< TextureSet, size_t, SceneGraph::Texture* > LocalType;
145
146   // Reserve some memory inside the message queue
147   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
148
149   // Construct message in the message queue memory; note that delete should not be called on the return value
150   new (slot) LocalType( &textureSet, &TextureSet::SetTexture, index, texture );
151 }
152
153 inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, SceneGraph::Sampler* sampler )
154 {
155   typedef MessageValue2< TextureSet, size_t, SceneGraph::Sampler* > LocalType;
156
157   // Reserve some memory inside the message queue
158   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
159
160   // Construct message in the message queue memory; note that delete should not be called on the return value
161   new (slot) LocalType( &textureSet, &TextureSet::SetSampler, index, sampler );
162 }
163
164 } // namespace SceneGraph
165
166 } // namespace Internal
167
168 } // namespace Dali
169
170 #endif //  DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H