ed0e297a7a7e6bab34f825ef07e13bd7c6cae050
[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) 2021 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 Destructor
47    */
48   ~Resource() override = default;
49
50   /**
51    * @brief Retrieves create info structure
52    * @return Reference to the create info structure
53    */
54   [[nodiscard]] const CreateInfo& GetCreateInfo() const
55   {
56     return mCreateInfo;
57   }
58
59   /**
60    * @brief Retrieves controller
61    * @return Reference to the controller object
62    */
63   [[nodiscard]] Graphics::EglGraphicsController& GetController() const
64   {
65     return mController;
66   }
67
68   /**
69    * @brief Destroys resource
70    *
71    * This function must be implemented by the derived class.
72    * It should perform final destruction of used GL resources.
73    */
74   virtual void DestroyResource() = 0;
75
76   /**
77    * @brief Initializes resource
78    *
79    * This function must be implemented by the derived class.
80    * It should initialize all necessary GL resources.
81    *
82    * @return True on success
83    */
84   virtual bool InitializeResource() = 0;
85
86   /**
87    * @brief Discards resource by adding it to the discard queue
88    */
89   virtual void DiscardResource() = 0;
90
91   /**
92    * @brief returns pointer to base
93    * @return
94    */
95   BASE* GetBase()
96   {
97     return this;
98   }
99
100 protected:
101   CreateInfo                       mCreateInfo; ///< CreateInfo structure
102   Graphics::EglGraphicsController& mController; ///< Reference to the Controller object
103 };
104 } // namespace GLES
105 } // namespace Dali::Graphics
106 #endif