Merge "Added shader support to pipeline cache" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-graphics-shader.h
1 #ifndef DALI_GRAPHICS_GLES_SHADER_H
2 #define DALI_GRAPHICS_GLES_SHADER_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
21 // EXTERNAL INCLUDES
22 #include <dali/graphics-api/graphics-shader-create-info.h>
23 #include <dali/graphics-api/graphics-shader.h>
24
25 // INTERNAL INCLUDES
26 #include "gles-graphics-resource.h"
27
28 namespace Dali::Graphics::GLES
29 {
30 class ShaderImpl
31 {
32 public:
33   /**
34    * @brief Constructor
35    * @param[in] createInfo Valid createInfo structure
36    * @param[in] controller Reference to the controller
37    */
38   ShaderImpl(const Graphics::ShaderCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
39   ~ShaderImpl();
40
41   uint32_t Retain();
42
43   uint32_t Release();
44
45   [[nodiscard]] uint32_t GetRefCount() const;
46
47   /**
48    * Whilst unreferenced, increase the flush count and return it
49    *
50    * @return The new flush count
51    */
52   [[nodiscard]] uint32_t IncreaseFlushCount();
53
54   /**
55    * Get the flush count whilst unreferenced
56    *
57    * @return the flush count
58    */
59   [[nodiscard]] uint32_t GetFlushCount() const;
60
61   /**
62    * @brief Compiles shader
63    *
64    * @return True on success
65    */
66   [[nodiscard]] bool Compile() const;
67
68   /**
69    * @brief Destroys GL shader
70    */
71   void Destroy();
72
73   uint32_t GetGLShader() const;
74
75   [[nodiscard]] const ShaderCreateInfo& GetCreateInfo() const;
76
77   [[nodiscard]] EglGraphicsController& GetController() const;
78
79 private:
80   friend class Shader;
81   struct Impl;
82   std::unique_ptr<Impl> mImpl{nullptr};
83 };
84
85 class Shader : public Graphics::Shader
86 {
87 public:
88   /**
89    * @brief Constructor
90    *
91    * @param[in] impl Pointer to valid implementation
92    */
93   explicit Shader(ShaderImpl* impl)
94   : mShader(impl)
95   {
96     mShader->Retain();
97   }
98
99   /**
100    * @brief Destructor
101    */
102   ~Shader() override;
103
104   [[nodiscard]] ShaderImpl* GetImplementation() const
105   {
106     return mShader;
107   }
108
109   [[nodiscard]] const ShaderCreateInfo& GetCreateInfo() const;
110
111   bool operator==(const GLES::Shader& shader) const
112   {
113     return (shader.mShader == mShader);
114   }
115
116   bool operator==(const GLES::ShaderImpl* shaderImpl) const
117   {
118     return (shaderImpl == mShader);
119   }
120
121   bool operator!=(const GLES::Shader& shader) const
122   {
123     return (shader.mShader != mShader);
124   }
125
126   /**
127    * @brief Called when UniquePtr<> on client-side dies.
128    */
129   void DiscardResource();
130
131   /**
132    * @brief Destroying GL resources
133    *
134    * This function is kept for compatibility with Resource<> class
135    * so can the object can be use with templated functions.
136    */
137   void DestroyResource()
138   {
139     // nothing to do here
140   }
141
142 private:
143   ShaderImpl* mShader{nullptr};
144 };
145
146 } // namespace Dali::Graphics::GLES
147
148 #endif