Added recycling of Graphics resources.
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-graphics-resource.h
1 #ifndef DALI_GRAPHICS_GLES_RESOURCE_H
2 #define DALI_GRAPHICS_GLES_RESOURCE_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 namespace Dali::Graphics
22 {
23 class EglGraphicsController;
24
25 namespace GLES
26 {
27 /**
28  * @brief Base class for the Graphics resource.
29  */
30 template<class BASE, class CreateInfo>
31 class Resource : public BASE
32 {
33 public:
34   /**
35    * @brief Constructor
36    * @param[in] createInfo CreateInfo structure for the resource
37    * @param[in] controller Reference to the controller
38    */
39   Resource(const CreateInfo& createInfo, Graphics::EglGraphicsController& controller)
40   : mCreateInfo(createInfo),
41     mController(controller)
42   {
43   }
44
45   /**
46    * @brief Tries to recycle Graphics resource
47    *
48    * If False returned, the object must be initialized with use of constructor
49    *
50    * By default, all graphics resources are non-recyclable
51    *
52    * @param[in] createInfo CreateInfo structure of new object
53    * @param[in] controller Reference to the controller
54    * @return True on success, False otherwise
55    */
56   virtual bool TryRecycle(const CreateInfo& createInfo, Graphics::EglGraphicsController& controller)
57   {
58     return false;
59   }
60
61   /**
62    * @brief Destructor
63    */
64   ~Resource() override = default;
65
66   /**
67    * @brief Retrieves create info structure
68    * @return Reference to the create info structure
69    */
70   [[nodiscard]] const CreateInfo& GetCreateInfo() const
71   {
72     return mCreateInfo;
73   }
74
75   /**
76    * @brief Retrieves controller
77    * @return Reference to the controller object
78    */
79   [[nodiscard]] Graphics::EglGraphicsController& GetController() const
80   {
81     return mController;
82   }
83
84   /**
85    * @brief Destroys resource
86    *
87    * This function must be implemented by the derived class.
88    * It should perform final destruction of used GL resources.
89    */
90   virtual void DestroyResource() = 0;
91
92   /**
93    * @brief Initializes resource
94    *
95    * This function must be implemented by the derived class.
96    * It should initialize all necessary GL resources.
97    *
98    * @return True on success
99    */
100   virtual bool InitializeResource() = 0;
101
102   /**
103    * @brief Discards resource by adding it to the discard queue
104    */
105   virtual void DiscardResource() = 0;
106
107   /**
108    * @brief returns pointer to base
109    * @return
110    */
111   BASE* GetBase()
112   {
113     return this;
114   }
115
116 protected:
117   CreateInfo                       mCreateInfo; ///< CreateInfo structure
118   Graphics::EglGraphicsController& mController; ///< Reference to the Controller object
119 };
120 } // namespace GLES
121 } // namespace Dali::Graphics
122 #endif