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