Ensure to check GLES::ShaderImpl when we found GLES:ProgramImpl
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-graphics-pipeline-cache.h
1 #ifndef DALI_GRAPHICS_GLES_PIPELINE_CACHE_H
2 #define DALI_GRAPHICS_GLES_PIPELINE_CACHE_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-pipeline-create-info.h>
23 #include <dali/graphics-api/graphics-pipeline.h>
24 #include <dali/graphics-api/graphics-program-create-info.h>
25 #include <dali/graphics-api/graphics-program.h>
26 #include <dali/graphics-api/graphics-shader-create-info.h>
27 #include <dali/graphics-api/graphics-shader.h>
28
29 // INTERNAL INCLUDES
30 #include "gles-graphics-resource.h"
31
32 namespace Dali::Graphics
33 {
34 class EglGraphicsController;
35 namespace GLES
36 {
37 class Pipeline;
38 class PipelineImpl;
39 class Program;
40 class ProgramImpl;
41 class Shader;
42 class ShaderImpl;
43
44 /**
45  * @brief PipelineCache manages pipeline and program
46  * objects so there are no duplicates created.
47  */
48 class PipelineCache
49 {
50 public:
51   /**
52    * @brief Constructor
53    */
54   explicit PipelineCache(EglGraphicsController& controller);
55
56   /**
57    * @brief Destructor
58    */
59   ~PipelineCache();
60
61   /**
62    * @brief Retrieves pipeline matching the spec
63    *
64    * Function returns either existing pipeline if one is found
65    * in the cache or creates new one.
66    *
67    * @param[in] pipelineCreateInfo Valid PipelineCreateInfo structure
68    * @param[in] oldPipeline previous pipeline object
69    * @return Pipeline object
70    */
71   Graphics::UniquePtr<Graphics::Pipeline> GetPipeline(const PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline);
72
73   /**
74    * @brief Retrieves program matching the spec
75    *
76    * Function returns either existing program if one is found
77    * in the cache or creates new one.
78    *
79    * @param[in] programCreateInfo Valid ProgramCreateInfo structure
80    * @param[in] oldProgram previous program object
81    * @return Program object
82    */
83   Graphics::UniquePtr<Graphics::Program> GetProgram(const ProgramCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram);
84
85   /**
86    * @brief Retrieves shader matching the spec
87    *
88    * Function returns either existing shader if one is found
89    * in the cache or creates new one.
90    *
91    * @param[in] shaderCreateInfo Valid ShaderCreateInfo structure
92    * @param[in] oldShader previous shader object
93    * @return Shader object
94    */
95   Graphics::UniquePtr<Graphics::Shader> GetShader(const ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader);
96
97   /**
98    * @brief Flushes pipeline and program cache
99    *
100    * Removes cached items when they are no longer needed. This function
101    * should be called at the very end of Controller render loop iteration.
102    */
103   void FlushCache();
104
105   /**
106    * @brief Set true if we can flush cached pipeline / program / shader.
107    * If we make it false, we can keep shader / program instance during app running.
108    * But it might have sightly panalty for memory.
109    * Default is True.
110    *
111    * @param enabled True if we can flush the caches. False when we don't want to flush caches.
112    */
113   void EnableCacheFlush(bool enabled);
114
115   /**
116    * @brief Notify that we need to flush pipeline cache next FlushCache API.
117    */
118   void MarkPipelineCacheFlushRequired();
119
120   /**
121    * @brief Notify that we need to flush program cache next FlushCache API.
122    */
123   void MarkProgramCacheFlushRequired();
124
125   /**
126    * @brief Notify that we need to flush shader cache next FlushCache API.
127    */
128   void MarkShaderCacheFlushRequired();
129
130 private:
131   /**
132    * @brief Finds pipeline implementation based on the spec
133    * @param[in] info Valid create info structure
134    * @return Returns pointer to pipeline or nullptr
135    */
136   PipelineImpl* FindPipelineImpl(const PipelineCreateInfo& info);
137
138   /**
139    * @brief Finds program implementation based on the spec
140    * @param[in] info Valid create info structure
141    * @return Returns pointer to program or nullptr
142    */
143   ProgramImpl* FindProgramImpl(const ProgramCreateInfo& info);
144
145   /**
146    * @brief Finds shader implementation based on create info
147    *
148    * @param[in] shadercreateinfo Valid create info structure
149    * @return Returns pointer to shader or nullptr
150    */
151   ShaderImpl* FindShaderImpl(const ShaderCreateInfo& shaderCreateInfo);
152
153 private:
154   struct Impl;
155   std::unique_ptr<Impl> mImpl;
156 };
157 } // namespace GLES
158 } // namespace Dali::Graphics
159 #endif