DALi Version 2.2.53
[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
27 // INTERNAL INCLUDES
28 #include "gles-graphics-resource.h"
29
30 namespace Dali::Graphics
31 {
32 class EglGraphicsController;
33 namespace GLES
34 {
35 class Pipeline;
36 class PipelineImpl;
37 class Program;
38 class ProgramImpl;
39 /**
40  * @brief PipelineCache manages pipeline and program
41  * objects so there are no duplicates created.
42  */
43 class PipelineCache
44 {
45 public:
46   /**
47    * @brief Constructor
48    */
49   explicit PipelineCache(EglGraphicsController& controller);
50
51   /**
52    * @brief Destructor
53    */
54   ~PipelineCache();
55
56   /**
57    * @brief Retrieves pipeline matching the spec
58    *
59    * Function returns either existing pipeline if one is found
60    * in the cache or creates new one.
61    *
62    * @param[in] pipelineCreateInfo Valid PipelineCreateInfo structure
63    * @param[in] oldPipeline previous pipeline object
64    * @return Pipeline object
65    */
66   Graphics::UniquePtr<Graphics::Pipeline> GetPipeline(const PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline);
67
68   /**
69    * @brief Retrieves program matching the spec
70    *
71    * Function returns either existing program if one is found
72    * in the cache or creates new one.
73    *
74    * @param[in] programCreateInfo Valid ProgramCreateInfo structure
75    * @param[in] oldProgram previous program object
76    * @return Program object
77    */
78   Graphics::UniquePtr<Graphics::Program> GetProgram(const ProgramCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram);
79
80   /**
81    * @brief Flushes pipeline and program cache
82    *
83    * Removes cached items when they are no longer needed. This function
84    * should be called at the very end of Controller render loop iteration.
85    */
86   void FlushCache();
87
88   /**
89    * @brief Notify that we need to flush pipeline cache next FlushCache API.
90    */
91   void MarkPipelineCacheFlushRequired();
92
93   /**
94    * @brief Notify that we need to flush program cache next FlushCache API.
95    */
96   void MarkProgramCacheFlushRequired();
97
98 private:
99   /**
100    * @brief Finds pipeline implementation based on the spec
101    * @param[in] info Valid create info structure
102    * @return Returns pointer to pipeline or nullptr
103    */
104   PipelineImpl* FindPipelineImpl(const PipelineCreateInfo& info);
105
106   /**
107  * @brief Finds program implementation based on the spec
108  * @param[in] info Valid create info structure
109  * @return Returns pointer to program or nullptr
110  */
111   ProgramImpl* FindProgramImpl(const ProgramCreateInfo& info);
112
113 private:
114   struct Impl;
115   std::unique_ptr<Impl> mImpl;
116 };
117 } // namespace GLES
118 } // namespace Dali::Graphics
119 #endif