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 <GLES2/gl2.h> 16 17 #include <memory> 18 #include <vector> 19 20 #include "ExternalObjectManager.h" 21 #include "FrameworkFormats.h" 22 #include "aemu/base/files/Stream.h" 23 24 namespace gfxstream { 25 namespace vk { 26 27 class ColorBufferVk { 28 public: 29 static std::unique_ptr<ColorBufferVk> create(uint32_t handle, uint32_t width, uint32_t height, 30 GLenum format, FrameworkFormat frameworkFormat, 31 bool vulkanOnly, uint32_t memoryProperty, 32 android::base::Stream* stream = nullptr); 33 34 ~ColorBufferVk(); 35 36 bool readToBytes(std::vector<uint8_t>* outBytes); 37 bool readToBytes(uint32_t x, uint32_t y, uint32_t w, uint32_t h, void* outBytes, 38 uint64_t outBytesSize); 39 40 bool updateFromBytes(const std::vector<uint8_t>& bytes); 41 bool updateFromBytes(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const void* bytes); 42 43 bool importExtMemoryHandle(void* nativeResource, uint32_t type, bool preserveContent); 44 45 void onSave(android::base::Stream* stream); 46 47 int waitSync(); 48 std::optional<BlobDescriptorInfo> exportBlob(); 49 50 private: 51 ColorBufferVk(uint32_t handle); 52 53 const uint32_t mHandle; 54 }; 55 56 } // namespace vk 57 } // namespace gfxstream 58