Remove annoying log message
[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) 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 // 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   [[nodiscard]] uint32_t GetGLBuffer() const
60   {
61     return mBufferId;
62   }
63
64   [[nodiscard]] void* GetCPUAllocatedAddress() const
65   {
66     return mBufferPtr;
67   }
68
69   [[nodiscard]] bool IsTransient() const
70   {
71     return mTransient;
72   }
73
74   [[nodiscard]] bool IsCPUAllocated() const
75   {
76     return mCpuAllocated;
77   }
78
79 private:
80
81   void InitializeCPUBuffer();
82
83   void InitializeGPUBuffer();
84
85   uint32_t mBufferId{};
86   void*    mBufferPtr{nullptr}; // CPU allocated memory
87   bool     mCpuAllocated{false};
88   bool     mTransient{false};
89 };
90 } // namespace GLES
91 } // namespace Dali::Graphics
92
93 template<>
94 struct std::default_delete<Dali::Graphics::Buffer>
95 {
96   void operator()(Dali::Graphics::Buffer* object)
97   {
98     // Add to the queue
99     auto resource = static_cast<Dali::Graphics::GLES::Buffer*>(object);
100     resource->DiscardResource();
101   }
102 };
103
104 #endif