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