Merge "(gles-sync-pool.cpp) Fixed some SVACE errors" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-graphics-buffer.h
1 #ifndef DALI_GRAPHICS_GLES_BUFFER_H
2 #define DALI_GRAPHICS_GLES_BUFFER_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-buffer-create-info.h>
23 #include <dali/graphics-api/graphics-buffer.h>
24
25 // INTERNAL INCLUDES
26 #include "gles-graphics-resource.h"
27
28 namespace Dali::Graphics
29 {
30 class EglGraphicsController;
31
32 namespace GLES
33 {
34 using BufferResource = Resource<Graphics::Buffer, Graphics::BufferCreateInfo>;
35
36 /**
37  * Buffer class represents a GPU buffer object. It may represent
38  * vertex buffer, index buffer, pixel buffer, uniform buffer and
39  * any other.
40  */
41 class Buffer : public BufferResource
42 {
43 public:
44   Buffer(const Graphics::BufferCreateInfo& createInfo, Graphics::EglGraphicsController& controller);
45
46   ~Buffer() override = default;
47
48   /**
49    * @brief Called when resource is being destroyed
50    */
51   void DestroyResource() override;
52
53   bool InitializeResource() override;
54
55   void DiscardResource() override;
56
57   void Bind(Graphics::BufferUsage bindingTarget) const;
58
59   bool TryRecycle(const Graphics::BufferCreateInfo& createInfo, Graphics::EglGraphicsController& controller) override;
60
61   [[nodiscard]] uint32_t GetGLBuffer() const
62   {
63     return mBufferId;
64   }
65
66   [[nodiscard]] void* GetCPUAllocatedAddress() const
67   {
68     return mBufferPtr;
69   }
70
71   [[nodiscard]] bool IsTransient() const
72   {
73     return mTransient;
74   }
75
76   [[nodiscard]] bool IsCPUAllocated() const
77   {
78     return mCpuAllocated;
79   }
80
81 private:
82   void InitializeCPUBuffer();
83
84   void InitializeGPUBuffer();
85
86   uint32_t mBufferId{};
87   void*    mBufferPtr{nullptr}; // CPU allocated memory
88   bool     mCpuAllocated{false};
89   bool     mTransient{false};
90
91   bool mSetForGLRecycling{false}; ///< If flag set true the buffer will recycle
92 };
93 } // namespace GLES
94 } // namespace Dali::Graphics
95
96 #endif