Cleanup in Aisle #1
[platform/core/uifw/dali-core.git] / dali / internal / render / shaders / render-shader.h
1 #ifndef DALI_INTERNAL_RENDER_SHADER_H
2 #define DALI_INTERNAL_RENDER_SHADER_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
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/shader-data.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class Program;
32 class ProgramCache;
33
34 namespace SceneGraph
35 {
36 class SceneController;
37
38 /**
39  * A holder class for Program; also enables sharing of uniform properties
40  */
41 class Shader : public PropertyOwner, public UniformMap::Observer
42 {
43 public:
44   /**
45    * Constructor
46    * @param hints Shader hints
47    */
48   explicit Shader(Dali::Shader::Hint::Value& hints);
49
50   /**
51    * Virtual destructor
52    */
53   ~Shader() override;
54
55   /**
56    * Query whether a shader hint is set.
57    *
58    * @warning This method is called from Update Algorithms.
59    *
60    * @pre The shader has been initialized.
61    * @param[in] hint The hint to check.
62    * @return True if the given hint is set.
63    */
64   [[nodiscard]] bool HintEnabled(Dali::Shader::Hint::Value hint) const
65   {
66     return mHints & hint;
67   }
68
69   /**
70    * @brief Set the shader data for this shader.
71    * @param[in] shaderData The program's vertex/fragment source and optionally pre-compiled shader binary.
72    */
73   void SetShaderData(ShaderDataPtr shaderData);
74
75   /**
76    * Get the shader data for this shader.
77    * @return The shader data.
78    */
79   [[nodiscard]] ShaderDataPtr GetShaderData() const;
80
81 public:
82   /**
83    * @copydoc ConnectionChangePropagator::AddObserver
84    */
85   void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
86
87   /**
88    * @copydoc ConnectionChangePropagator::RemoveObserver
89    */
90   void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
91
92 public: // UniformMap::Observer
93   /**
94    * @copydoc UniformMap::Observer::UniformMappingsChanged
95    */
96   void UniformMappingsChanged(const UniformMap& mappings) override;
97
98 private: // Data
99   Dali::Shader::Hint::Value mHints;
100
101   ShaderDataPtr mShaderData;
102
103   ConnectionChangePropagator mConnectionObservers;
104 };
105
106 inline void SetShaderDataMessage(EventThreadServices& eventThreadServices, const Shader& shader, ShaderDataPtr shaderData)
107 {
108   using LocalType = MessageValue1<Shader, ShaderDataPtr>;
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(&shader, &Shader::SetShaderData, shaderData);
115 }
116
117 } // namespace SceneGraph
118
119 } // namespace Internal
120
121 } // namespace Dali
122
123 #endif // DALI_INTERNAL_RENDER_SHADER_H