[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / uniform-buffer-view.h
1 #ifndef DALI_INTERNAL_UNIFORM_BUFFER_VIEW_H
2 #define DALI_INTERNAL_UNIFORM_BUFFER_VIEW_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 <stdint.h>
23 #include <stdlib.h>
24 #include <memory>
25
26 namespace Dali
27 {
28 namespace Graphics
29 {
30 class Buffer;
31 }
32 namespace Internal::Render
33 {
34 class UniformBufferV2;
35
36 /**
37  * Class UniformBufferView
38  *
39  * The class is responsible for providing view into the UniformBuffer object
40  * giving access to part or all of its memory. UniformBufferView doesn't own
41  * memory.
42  *
43  * The memory accessed through the UniformBufferView should be addressed at
44  * the offset of 0 and up to specified size. The memory beyond the view may be
45  * invalid.
46  *
47  */
48 class UniformBufferView
49 {
50 public:
51   UniformBufferView(UniformBufferV2& ubo, uint32_t offset, size_t size);
52
53   ~UniformBufferView();
54
55   /**
56    * @brief Writes data into the current uniform buffer view.
57    * @note We prefer to call UniformBuffer::ReadyToLockUniformBuffer before call Write API.
58    * And also, prefer to call UniformBuffer::UnlockUniformBuffer if current frame's all Write API action done.
59    *
60    * @param[in] data pointer to the source data
61    * @param[in] size size of source data
62    * @param[in] offset destination offset
63    */
64   void Write(const void* data, uint32_t size, uint32_t offset);
65
66   /**
67    * @brief Returns the size of the view
68    *
69    * @return size of view
70    */
71   [[nodiscard]] uint32_t GetSize() const
72   {
73     return mSize;
74   }
75
76   /**
77    * @brief Returns the offset within the UBO
78    * @return Offset
79    */
80   [[nodiscard]] uint32_t GetOffset() const
81   {
82     return mOffset;
83   }
84
85   /**
86    * @brief Returns Graphics buffer associated with this View
87    *
88    * @return Pointer to a valid Graphics::Buffer object
89    */
90   [[nodiscard]] Graphics::Buffer* GetBuffer() const;
91
92 private:
93   UniformBufferV2* mUniformBuffer{nullptr}; ///< UniformBuffer that the view views
94   uint32_t         mOffset{0u};             ///< Offset within the buffer
95   size_t           mSize{0u};               ///< Size of view
96 };
97 } // Namespace Internal::Render
98 } // Namespace Dali
99 #endif //DALI_INTERNAL_UNIFORM_BUFFER_VIEW_H