Merge "Fixed an issue the triple tap did not work." into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / uniform-buffer-manager.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/render/renderers/uniform-buffer-manager.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/render/renderers/uniform-buffer.h>
23 #include <dali/internal/render/renderers/uniform-buffer-view.h>
24 #include <dali/internal/render/renderers/uniform-buffer-view-pool.h>
25
26 #include <dali/graphics-api/graphics-buffer-create-info.h>
27 #include <dali/graphics-api/graphics-buffer.h>
28
29 #include <cstring>
30 #include <memory>
31
32 namespace Dali::Internal::Render
33 {
34
35 UniformBufferManager::UniformBufferManager(Dali::Graphics::Controller* controller)
36 : mController(controller)
37 {
38 }
39
40 UniformBufferManager::~UniformBufferManager() = default;
41
42 Graphics::UniquePtr<UniformBuffer> UniformBufferManager::AllocateUniformBuffer(uint32_t size, uint32_t alignment)
43 {
44   return Graphics::UniquePtr<UniformBuffer>(
45     new UniformBuffer(mController, size, alignment, true, Dali::Graphics::BufferUsageFlags{0u} | Dali::Graphics::BufferUsage::TRANSFER_DST | Dali::Graphics::BufferUsage::UNIFORM_BUFFER));
46 }
47
48 Graphics::UniquePtr<UniformBufferView> UniformBufferManager::CreateUniformBufferView( UniformBuffer* uniformBuffer, uint32_t offset, uint32_t size )
49 {
50   // Allocate offset of given UBO (allocation strategy may reuse memory)
51   return Graphics::UniquePtr<UniformBufferView>( new UniformBufferView(*uniformBuffer, offset, size) );
52 }
53
54 Graphics::UniquePtr<UniformBufferViewPool> UniformBufferManager::CreateUniformBufferViewPool()
55 {
56   return Graphics::UniquePtr<UniformBufferViewPool>(
57     new UniformBufferViewPool( *this, 1 )
58     );
59 }
60
61 [[nodiscard]] UniformBufferViewPool* UniformBufferManager::GetUniformBufferViewPool( uint32_t bufferIndex )
62 {
63   if(!mUniformBufferPoolStorage[bufferIndex])
64   {
65     // create new uniform buffer view pool with default (initial) capacity
66     mUniformBufferPoolStorage[bufferIndex] = CreateUniformBufferViewPool();
67   }
68   return mUniformBufferPoolStorage[bufferIndex].get();
69 }
70
71 } // namespace Dali::Internal::Render