2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/render/renderers/gpu-buffer.h>
22 #include <dali/graphics-api/graphics-types.h>
23 #include <dali/public-api/common/dali-common.h>
34 GpuBuffer::GpuBuffer(Graphics::Controller& graphicsController, Graphics::BufferUsageFlags usage)
39 void GpuBuffer::UpdateDataBuffer(Graphics::Controller& graphicsController, uint32_t size, const void* data)
41 DALI_ASSERT_DEBUG(size > 0);
44 if(!mGraphicsObject || size > mCapacity)
46 Graphics::BufferCreateInfo createInfo{};
47 createInfo.SetUsage(mUsage).SetSize(size);
48 mGraphicsObject = graphicsController.CreateBuffer(createInfo, std::move(mGraphicsObject));
52 Graphics::MapBufferInfo info{};
53 info.buffer = mGraphicsObject.get();
54 info.usage = 0 | Graphics::MemoryUsageFlagBits::WRITE;
58 auto memory = graphicsController.MapBufferRange(info);
59 void* ptr = memory->LockRegion(0, size);
60 memcpy(ptr, data, size);
62 graphicsController.UnmapMemory(std::move(memory));
65 void GpuBuffer::Destroy()
69 mGraphicsObject.reset();
72 } // namespace Internal