Lock uniform buffer only 1 times per each render + minor fixup of uniforms
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / uniform-buffer-view-pool.h
1 #ifndef DALI_INTERNAL_UNIFORM_BUFFER_VIEW_POOL_H
2 #define DALI_INTERNAL_UNIFORM_BUFFER_VIEW_POOL_H
3
4 /*
5  * Copyright (c) 2022 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 // INTERNAL INCLUDES
22 #include <dali/graphics-api/graphics-types.h>
23
24 // EXTERNAL INCLUDES
25 #include <stdint.h>
26 #include <stdlib.h>
27
28 namespace Dali::Internal::Render
29 {
30 class UniformBufferManager;
31 class UniformBufferView;
32 class UniformBuffer;
33
34 /**
35  * Class UniformBufferPoolView
36  *
37  * The class is responsible for managing the UniformBuffer memory.
38  * It is stack-based pool allocator. It doesn't own the UniformBuffer but
39  * it's mere view into the memory.
40  *
41  * The view may however request UniformBuffer to resize if there is a need
42  * to allocate memory beyond its current size.
43  *
44  * The UniformBuffer may be trimmed on Rollback().
45  *
46  * Rollback() operation moves allocation pointer to the very beginning
47  * of the UniformBuffer. The data stored in the UniformBuffer after
48  * Rollback() is considered invalid and shouldn't be used by the client side.
49  */
50 class UniformBufferViewPool
51 {
52   friend class UniformBufferManager;
53
54 private:
55   UniformBufferViewPool(UniformBufferManager& manager, uint32_t alignment);
56
57 public:
58   ~UniformBufferViewPool();
59
60   /**
61    * @brief Rolls back allocation to the beginning of pool
62    */
63   void Rollback();
64
65   /**
66    * @brief Creates view for next free chunk of UBO memory of specified size.
67    */
68   Graphics::UniquePtr<UniformBufferView> CreateUniformBufferView(size_t size);
69
70   /**
71    * @copydoc Dali::Internal::Render::UniformBufferManager::ReadyToLockUniformBuffer
72    */
73   void ReadyToLockUniformBuffer();
74
75   /**
76    * @copydoc Dali::Internal::Render::UniformBufferManager::UnlockUniformBuffer
77    */
78   void UnlockUniformBuffer();
79
80 private:
81   UniformBufferManager&              mUboManager;
82   Graphics::UniquePtr<UniformBuffer> mUniformBufferStorage;
83
84   uint32_t mAlignment; // 1 for tightly packed emulated UBO
85   uint32_t mCurrentOffset;
86 };
87
88 } // namespace Dali::Internal::Render
89 #endif //DALI_INTERNAL_UNIFORM_BUFFER_VIEW_POOL_H