Revert "[Tizen] Fix gcc-13 compile error"
[platform/core/uifw/dali-core.git] / dali / integration-api / shader-precompiler.h
1 #ifndef DALI_INTEGRATION_SHADER_PRECOMPILER_H
2 #define DALI_INTEGRATION_SHADER_PRECOMPILER_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 // INTERNAL HEADER
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/devel-api/threading/conditional-wait.h>
25 #include <dali/devel-api/threading/mutex.h>
26
27 // EXTERNAL HEDAER
28 #include <string_view>
29 #include <memory>
30 #include <mutex>
31
32 namespace Dali
33 {
34 namespace Internal DALI_INTERNAL
35 {
36 class ShaderPrecompiler;
37 }
38
39 struct RawShaderData
40 {
41   int shaderCount;
42   std::vector<std::string_view> vertexPrefix;
43   std::vector<std::string_view> fragmentPrefix;
44   std::string_view vertexShader;
45   std::string_view fragmentShader;
46 };
47
48 namespace Integration
49 {
50 /**
51  * ShaderPrecompiler  is used to precompile shaders.
52  * The precompiled shaders are stored in a file.
53  * @SINCE_2_2.45
54  */
55 class DALI_CORE_API ShaderPrecompiler : public BaseHandle
56 {
57 public:
58   /**
59    * @brief Gets the singleton of ShaderPrecompiler object.
60    *
61    * @SINCE_2_2.45
62    * @return A handle to the ShaderPrecompiler
63    */
64   static ShaderPrecompiler& Get();
65
66   /**
67    * @brief Get the precompile shader list.
68    *
69    *  @SINCE_2_2.45
70    *  @param[in] shaders shader data for precompile
71    */
72   void GetPrecompileShaderList(std::vector<RawShaderData>& shaders);
73
74   /**
75    * @brief Save the precompile shader list.
76    *
77    * @SINCE_2_2.45
78    * @param[in] shaders shader data for precompile
79    */
80   void SavePrecomipleShaderList(std::vector<RawShaderData>& shaders);
81
82   /**
83    * @brief Check precompile list is ready or not
84    *
85    * @SINCE_2_2.45
86    * @return true if precompile list is ready
87    */
88   bool IsReady() const;
89
90   /**
91    * @brief Enable the feature of precompile
92    *
93    * @SINCE_2_2.45
94    */
95   void Enable();
96
97   /**
98    * @brief Check the feature of precompile is enabled or not
99    *
100    * @SINCE_2_2.45
101    * @return true if the feature of precompile is enabled
102   */
103   bool IsEnable();
104
105   /**
106    * @brief Waiting for a list of shaders to be precompiled
107    *
108    */
109   void WaitPrecompileList();
110
111   /**
112    * @brief Stop waiting for a list of shaders to be precompiled
113    *
114    */
115   void StopPrecompile();
116
117   /**
118    * Construct a new ShaderPrecompiler.
119    */
120   ShaderPrecompiler();
121
122   // Undefined
123   ShaderPrecompiler(const ShaderPrecompiler&) = delete;
124
125   // Undefined
126   ShaderPrecompiler& operator=(const ShaderPrecompiler& rhs) = delete;
127
128 private:
129   static std::unique_ptr<ShaderPrecompiler> mInstance;
130   static std::once_flag mOnceFlag;
131   std::vector<RawShaderData> mRawShaderList;
132   ConditionalWait mConditionalWait;
133   Dali::Mutex mMutex;
134   bool mPrecompiled;
135   bool mEnabled;
136   bool mNeedsSleep{true};
137 };
138
139 } // namespace Integration
140
141 } // namespace Dali
142
143 #endif // DALI_INTEGRATION_SHADER_PRECOMPILER_H