Shader support
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-graphics-program.h
1 #ifndef DALI_GRAPHICS_GLES_PROGRAM_H
2 #define DALI_GRAPHICS_GLES_PROGRAM_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 // EXTERNAL INCLUDES
21 #include <dali/graphics-api/graphics-program-create-info.h>
22 #include <dali/graphics-api/graphics-program.h>
23
24 // INTERNAL INCLUDES
25 #include "gles-graphics-resource.h"
26
27 namespace Dali::Graphics
28 {
29 class Reflection;
30 namespace GLES
31 {
32 /**
33  * @brief Program implementation
34  *
35  * Program implementation is owned only by the PipelineCache
36  *
37  * Like pipeline, it's created and managed by the PipelineCache
38  */
39 class ProgramImpl
40 {
41 public:
42   /**
43    * @brief Constructor
44    *
45    * @param[in] createInfo  Valid create info structure
46    * @param[in] controller Valid reference to the controller object
47    */
48   ProgramImpl(const Graphics::ProgramCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
49
50   /**
51    * @brief Destructor
52    */
53   ~ProgramImpl();
54
55   /**
56    * @brief Destroys GL resources associated with the Program
57    *
58    * @return True on success
59    */
60   bool Destroy();
61
62   /**
63    * @brief Creates GL resource for this Program
64    *
65    * @return True on success
66    */
67   bool Create();
68
69   /**
70    * @brief Returns GL program id
71    *
72    * @return GL program id
73    */
74   [[nodiscard]] uint32_t GetGlProgram() const;
75
76   /**
77    * @brief Increases ref count
78    *
79    * @return new refcount
80    */
81   uint32_t Retain();
82
83   /**
84    * @brief Decreases ref count
85    *
86    * @return New refcount
87    */
88   uint32_t Release();
89
90   /**
91    * @brief Returns reflection
92    *
93    * @return Valid reflection associated with the Program
94    */
95   [[nodiscard]] const Graphics::Reflection& GetReflection() const;
96
97   /**
98    * @brief Returns controller
99    *
100    * @return Valid Controller object
101    */
102   [[nodiscard]] EglGraphicsController& GetController() const;
103
104   /**
105    * @brief Returns create info structure
106    *
107    * @return Reference to valid create info structure
108    */
109   [[nodiscard]] const ProgramCreateInfo& GetCreateInfo() const;
110
111   /**
112    * @brief Returns parameter value specified by parameterId
113    *
114    * This function can be used as a backdoor into the implementation
115    * used to retrieve internal data.
116    *
117    * @param[in] parameterId Integer parameter id
118    * @param[out] out Pointer to write to
119    *
120    * @return True on success
121    */
122   bool GetParameter(uint32_t parameterId, void* out);
123
124 private:
125   friend class Program;
126
127   struct Impl;
128   std::unique_ptr<Impl> mImpl;
129 };
130
131 ///////////////////////////////////////////////////////////////
132
133 /**
134  * @brief Wrapper for the pipeline implementation
135  *
136  * This object is returned back to the client-side
137  */
138 class Program : public Graphics::Program
139 {
140 public:
141   /**
142    * @brief Constructor
143    *
144    * @param[in] impl Pointer to valid implementation
145    */
146   explicit Program(ProgramImpl* impl)
147   : mProgram(impl)
148   {
149     mProgram->Retain();
150   }
151
152   /**
153    * @brief Destructor
154    */
155   ~Program() override;
156
157   /**
158    * @brief Returns reference to the Reflection object
159
160    * @return Reflection
161    */
162   [[nodiscard]] const Graphics::Reflection& GetReflection() const;
163
164   /**
165    * @brief Retrieves internal program implementation
166    *
167    * @return Valid pointer to the ProgramImpl object
168    */
169   [[nodiscard]] ProgramImpl* GetImplementation() const
170   {
171     return mProgram;
172   }
173
174   /**
175    * @brief Returns controller
176    *
177    * @return controller
178    */
179   [[nodiscard]] EglGraphicsController& GetController() const;
180
181   /**
182    * @brief Returns create info structure
183    *
184    * @return create info structure
185    */
186   [[nodiscard]] const ProgramCreateInfo& GetCreateInfo() const;
187
188   bool operator==(const GLES::Program& program) const
189   {
190     return (program.mProgram == mProgram);
191   }
192
193   bool operator==(const GLES::ProgramImpl* programImpl) const
194   {
195     return (programImpl == mProgram);
196   }
197
198   bool operator!=(const GLES::Program& program) const
199   {
200     return (program.mProgram != mProgram);
201   }
202
203   /**
204    * @brief Run by UniquePtr to discard resource
205    */
206   void DiscardResource();
207
208   /**
209    * @brief Destroying GL resources
210    *
211    * This function is kept for compatibility with Resource<> class
212    * so can the object can be use with templated functions.
213    */
214   void DestroyResource()
215   {
216     // nothing to do here
217   }
218
219 private:
220   ProgramImpl* mProgram{nullptr};
221 };
222 } // namespace GLES
223 } // namespace Dali::Graphics
224
225 #endif //DALI_GRAPHICS_PROGRAM_H