1 // Copyright 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expresso or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "ColorBufferVk.h"
16 
17 #include "VkCommonOperations.h"
18 
19 namespace gfxstream {
20 namespace vk {
21 
22 /*static*/
create(uint32_t handle,uint32_t width,uint32_t height,GLenum format,FrameworkFormat frameworkFormat,bool vulkanOnly,uint32_t memoryProperty)23 std::unique_ptr<ColorBufferVk> ColorBufferVk::create(uint32_t handle, uint32_t width,
24                                                      uint32_t height, GLenum format,
25                                                      FrameworkFormat frameworkFormat,
26                                                      bool vulkanOnly, uint32_t memoryProperty) {
27     if (!setupVkColorBuffer(width, height, format, frameworkFormat, handle, vulkanOnly,
28                             memoryProperty)) {
29         GL_LOG("Failed to create ColorBufferVk:%d", handle);
30         return nullptr;
31     }
32 
33     return std::unique_ptr<ColorBufferVk>(new ColorBufferVk(handle));
34 }
35 
ColorBufferVk(uint32_t handle)36 ColorBufferVk::ColorBufferVk(uint32_t handle) : mHandle(handle) {}
37 
~ColorBufferVk()38 ColorBufferVk::~ColorBufferVk() {
39     if (!teardownVkColorBuffer(mHandle)) {
40         ERR("Failed to destroy ColorBufferVk:%d", mHandle);
41     }
42 }
43 
readToBytes(std::vector<uint8_t> * outBytes)44 bool ColorBufferVk::readToBytes(std::vector<uint8_t>* outBytes) {
45     return readColorBufferToBytes(mHandle, outBytes);
46 }
47 
readToBytes(uint32_t x,uint32_t y,uint32_t w,uint32_t h,void * outBytes)48 bool ColorBufferVk::readToBytes(uint32_t x, uint32_t y, uint32_t w, uint32_t h, void* outBytes) {
49     return readColorBufferToBytes(mHandle, x, y, w, h, outBytes);
50 }
51 
updateFromBytes(const std::vector<uint8_t> & bytes)52 bool ColorBufferVk::updateFromBytes(const std::vector<uint8_t>& bytes) {
53     return updateColorBufferFromBytes(mHandle, bytes);
54 }
55 
updateFromBytes(uint32_t x,uint32_t y,uint32_t w,uint32_t h,const void * bytes)56 bool ColorBufferVk::updateFromBytes(uint32_t x, uint32_t y, uint32_t w, uint32_t h,
57                                     const void* bytes) {
58     return updateColorBufferFromBytes(mHandle, x, y, w, h, bytes);
59 }
60 
61 }  // namespace vk
62 }  // namespace gfxstream
63