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