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 #pragma once 16 17 #include <stddef.h> 18 #include <stdint.h> 19 20 #include <cutils/native_handle.h> 21 22 typedef struct AHardwareBuffer AHardwareBuffer; 23 24 namespace gfxstream { 25 26 constexpr uint32_t kGlRGB = 0x1907; 27 constexpr uint32_t kGlRGBA = 0x1908; 28 constexpr uint32_t kGlRGB565 = 0x8D62; 29 30 // Abstraction for gralloc handle conversion 31 class Gralloc { 32 public: ~Gralloc()33 virtual ~Gralloc() {} 34 35 virtual uint32_t createColorBuffer(void* rcEnc, int width, int height, 36 uint32_t glformat) = 0; 37 38 virtual void acquire(AHardwareBuffer* ahb) = 0; 39 virtual void release(AHardwareBuffer* ahb) = 0; 40 41 virtual int allocate(uint32_t width, 42 uint32_t height, 43 uint32_t format, 44 uint64_t usage, 45 AHardwareBuffer** outputAhb) = 0; 46 47 virtual uint32_t getHostHandle(const native_handle_t* handle) = 0; 48 virtual uint32_t getHostHandle(const AHardwareBuffer* handle) = 0; 49 50 virtual int getFormat(const native_handle_t* handle) = 0; 51 virtual int getFormat(const AHardwareBuffer* handle) = 0; 52 getFormatDrmFourcc(const AHardwareBuffer *)53 virtual uint32_t getFormatDrmFourcc(const AHardwareBuffer* /*handle*/) { 54 // Equal to DRM_FORMAT_INVALID -- see <drm_fourcc.h> 55 return 0; 56 } getFormatDrmFourcc(const native_handle_t *)57 virtual uint32_t getFormatDrmFourcc(const native_handle_t* /*handle*/) { 58 // Equal to DRM_FORMAT_INVALID -- see <drm_fourcc.h> 59 return 0; 60 } 61 62 virtual size_t getAllocatedSize(const native_handle_t* handle) = 0; 63 virtual size_t getAllocatedSize(const AHardwareBuffer* handle) = 0; 64 treatBlobAsImage()65 virtual bool treatBlobAsImage() { return false; }; 66 }; 67 68 } // namespace gfxstream 69