Merge branch 'devel/master' into tizen
[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) 2023 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
23 #include <dali/internal/common/buffer-index.h>
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/event/common/event-thread-services.h>
26 #include <dali/internal/render/renderers/render-texture-key.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace Render
33 {
34 struct Sampler;
35 class Texture;
36 } // namespace Render
37 namespace SceneGraph
38 {
39 class Renderer;
40 class RenderMessageDispatcher;
41
42 class TextureSet
43 {
44 public:
45   /**
46    * Construct a new TextureSet.
47    */
48   static TextureSet* New();
49
50   /**
51    * Destructor. Not virtual as not a base class and not inheriting anything
52    */
53   ~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(uint32_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(uint32_t index, const Render::TextureKey& 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    * Accessor for textures (used by RenderDataProvider impl)
83    */
84   const Vector<Render::TextureKey>& GetTextures()
85   {
86     return mTextures;
87   }
88
89   /**
90    * Accessor for samplers (used by RenderDataProvider impl)
91    */
92   const Vector<Render::Sampler*>& GetSamplers()
93   {
94     return mSamplers;
95   }
96
97   /**
98    * Set the renderMessageDispatcher to send message.
99    * @param[in] renderMessageDispatcher The renderMessageDispatcher to send messages.
100    */
101   void SetRenderMessageDispatcher(RenderMessageDispatcher* renderMessageDispatcher);
102
103   /**
104    * Get the capacity of the memory pools
105    * @return the capacity of the memory pools
106    */
107   static uint32_t GetMemoryPoolCapacity();
108
109 private:
110   /**
111    * Protected constructor; See also TextureSet::New()
112    */
113   TextureSet();
114
115 private:
116   Vector<Render::Sampler*>   mSamplers;                         ///< List of samplers used by each texture. Not owned
117   Vector<Render::TextureKey> mTextures;                         ///< List of Textures. Not owned
118   RenderMessageDispatcher*   mRenderMessageDispatcher{nullptr}; ///< for sending messages to render thread. Not owned
119   bool                       mHasAlpha;                         ///< if any of the textures has an alpha channel
120 };
121
122 inline void SetTextureMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, const Render::TextureKey& textureKey)
123 {
124   using LocalType = MessageValue2<TextureSet, uint32_t, Render::TextureKey>;
125
126   // Reserve some memory inside the message queue
127   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
128
129   // Construct message in the message queue memory; note that delete should not be called on the return value
130   new(slot) LocalType(&textureSet, &TextureSet::SetTexture, index, textureKey);
131 }
132
133 inline void SetSamplerMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Sampler* sampler)
134 {
135   using LocalType = MessageValue2<TextureSet, uint32_t, Render::Sampler*>;
136
137   // Reserve some memory inside the message queue
138   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
139
140   // Construct message in the message queue memory; note that delete should not be called on the return value
141   new(slot) LocalType(&textureSet, &TextureSet::SetSampler, index, sampler);
142 }
143
144 } // namespace SceneGraph
145
146 } // namespace Internal
147
148 } // namespace Dali
149
150 #endif //  DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H