Changed RenderDataProvider to remove copy
[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) 2021 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/internal/common/buffer-index.h>
22 #include <dali/internal/common/message.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/public-api/rendering/texture-set.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace Render
31 {
32 struct Sampler;
33 class Texture;
34 } // namespace Render
35 namespace SceneGraph
36 {
37 class Renderer;
38
39 class TextureSet
40 {
41 public:
42   /**
43    * Construct a new TextureSet.
44    */
45   static TextureSet* New();
46
47   /**
48    * Destructor. Not virtual as not a base class and not inheriting anything
49    */
50   ~TextureSet();
51
52   /**
53    * Overriden delete operator
54    * Deletes the texture set from its global memory pool
55    */
56   void operator delete(void* ptr);
57
58   /**
59    * Set the sampler to be used by the texture at position "index"
60    * @param[in] index The index of the texture
61    * @param[in] sampler The sampler to be used by the texture
62    */
63   void SetSampler(uint32_t index, Render::Sampler* sampler);
64
65   /**
66    * Set the texture at position "index"
67    * @param[in] index The index of the texture
68    * @param[in] texture The texture
69    */
70   void SetTexture(uint32_t index, Render::Texture* texture);
71
72   /**
73    * Return whether any texture in the texture set has an alpha channel
74    * @return true if at least one texture in the texture set has an alpha channel, false otherwise
75    */
76   bool HasAlpha() const;
77
78   /**
79    * Accessor for textures (used by RenderDataProvider impl)
80    */
81   const Vector<Render::Texture*>& GetTextures()
82   {
83     return mTextures;
84   }
85
86   /**
87    * Accessor for samplers (used by RenderDataProvider impl)
88    */
89   const Vector<Render::Sampler*>& GetSamplers()
90   {
91     return mSamplers;
92   }
93
94 private:
95   /**
96    * Protected constructor; See also TextureSet::New()
97    */
98   TextureSet();
99
100 private:                              // Data
101   Vector<Render::Sampler*> mSamplers; ///< List of samplers used by each texture. Not owned
102   Vector<Render::Texture*> mTextures; ///< List of Textures. Not owned
103   bool                     mHasAlpha; ///< if any of the textures has an alpha channel
104 };
105
106 inline void SetTextureMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Texture* texture)
107 {
108   using LocalType = MessageValue2<TextureSet, uint32_t, Render::Texture*>;
109
110   // Reserve some memory inside the message queue
111   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
112
113   // Construct message in the message queue memory; note that delete should not be called on the return value
114   new(slot) LocalType(&textureSet, &TextureSet::SetTexture, index, texture);
115 }
116
117 inline void SetSamplerMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Sampler* sampler)
118 {
119   using LocalType = MessageValue2<TextureSet, uint32_t, Render::Sampler*>;
120
121   // Reserve some memory inside the message queue
122   uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
123
124   // Construct message in the message queue memory; note that delete should not be called on the return value
125   new(slot) LocalType(&textureSet, &TextureSet::SetSampler, index, sampler);
126 }
127
128 } // namespace SceneGraph
129
130 } // namespace Internal
131
132 } // namespace Dali
133
134 #endif //  DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H