1 /* 2 * Copyright 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_UI_GRALLOC_H 18 #define ANDROID_UI_GRALLOC_H 19 20 #include <gralloctypes/Gralloc4.h> 21 #include <hidl/HidlSupport.h> 22 #include <ui/GraphicTypes.h> 23 #include <ui/PixelFormat.h> 24 #include <ui/Rect.h> 25 #include <utils/StrongPointer.h> 26 27 #include <string> 28 29 namespace android { 30 31 // A wrapper to IMapper 32 class GrallocMapper { 33 public: 34 virtual ~GrallocMapper(); 35 36 virtual bool isLoaded() const = 0; 37 dumpBuffer(buffer_handle_t,bool)38 virtual std::string dumpBuffer(buffer_handle_t /*bufferHandle*/, bool /*less*/) const { 39 return ""; 40 } 41 42 virtual status_t createDescriptor(void* bufferDescriptorInfo, 43 void* outBufferDescriptor) const = 0; 44 45 // Import a buffer that is from another HAL, another process, or is 46 // cloned. 47 // 48 // The returned handle must be freed with freeBuffer. 49 virtual status_t importBuffer(const hardware::hidl_handle& rawHandle, 50 buffer_handle_t* outBufferHandle) const = 0; 51 52 virtual void freeBuffer(buffer_handle_t bufferHandle) const = 0; 53 54 virtual status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, 55 uint32_t height, android::PixelFormat format, 56 uint32_t layerCount, uint64_t usage, 57 uint32_t stride) const = 0; 58 59 virtual void getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds, 60 uint32_t* outNumInts) const = 0; 61 62 // The ownership of acquireFence is always transferred to the callee, even 63 // on errors. 64 virtual status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, 65 int acquireFence, void** outData, int32_t* outBytesPerPixel, 66 int32_t* outBytesPerStride) const = 0; 67 68 // The ownership of acquireFence is always transferred to the callee, even 69 // on errors. 70 virtual status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, 71 int acquireFence, android_ycbcr* ycbcr) const = 0; 72 73 // unlock returns a fence sync object (or -1) and the fence sync object is 74 // owned by the caller 75 virtual int unlock(buffer_handle_t bufferHandle) const = 0; 76 77 // isSupported queries whether or not a buffer with the given width, height, 78 // format, layer count, and usage can be allocated on the device. If 79 // *outSupported is set to true, a buffer with the given specifications may be successfully 80 // allocated if resources are available. If false, a buffer with the given specifications will 81 // never successfully allocate on this device. Note that this function is not guaranteed to be 82 // supported on all devices, in which case a status_t of INVALID_OPERATION will be returned. isSupported(uint32_t,uint32_t,android::PixelFormat,uint32_t,uint64_t,bool *)83 virtual status_t isSupported(uint32_t /*width*/, uint32_t /*height*/, 84 android::PixelFormat /*format*/, uint32_t /*layerCount*/, 85 uint64_t /*usage*/, bool* /*outSupported*/) const { 86 return INVALID_OPERATION; 87 } 88 getBufferId(buffer_handle_t,uint64_t *)89 virtual status_t getBufferId(buffer_handle_t /*bufferHandle*/, 90 uint64_t* /*outBufferId*/) const { 91 return INVALID_OPERATION; 92 } getName(buffer_handle_t,std::string *)93 virtual status_t getName(buffer_handle_t /*bufferHandle*/, std::string* /*outName*/) const { 94 return INVALID_OPERATION; 95 } getWidth(buffer_handle_t,uint64_t *)96 virtual status_t getWidth(buffer_handle_t /*bufferHandle*/, uint64_t* /*outWidth*/) const { 97 return INVALID_OPERATION; 98 } getHeight(buffer_handle_t,uint64_t *)99 virtual status_t getHeight(buffer_handle_t /*bufferHandle*/, uint64_t* /*outHeight*/) const { 100 return INVALID_OPERATION; 101 } getLayerCount(buffer_handle_t,uint64_t *)102 virtual status_t getLayerCount(buffer_handle_t /*bufferHandle*/, 103 uint64_t* /*outLayerCount*/) const { 104 return INVALID_OPERATION; 105 } getPixelFormatRequested(buffer_handle_t,ui::PixelFormat *)106 virtual status_t getPixelFormatRequested(buffer_handle_t /*bufferHandle*/, 107 ui::PixelFormat* /*outPixelFormatRequested*/) const { 108 return INVALID_OPERATION; 109 } getPixelFormatFourCC(buffer_handle_t,uint32_t *)110 virtual status_t getPixelFormatFourCC(buffer_handle_t /*bufferHandle*/, 111 uint32_t* /*outPixelFormatFourCC*/) const { 112 return INVALID_OPERATION; 113 } getPixelFormatModifier(buffer_handle_t,uint64_t *)114 virtual status_t getPixelFormatModifier(buffer_handle_t /*bufferHandle*/, 115 uint64_t* /*outPixelFormatModifier*/) const { 116 return INVALID_OPERATION; 117 } getUsage(buffer_handle_t,uint64_t *)118 virtual status_t getUsage(buffer_handle_t /*bufferHandle*/, uint64_t* /*outUsage*/) const { 119 return INVALID_OPERATION; 120 } getAllocationSize(buffer_handle_t,uint64_t *)121 virtual status_t getAllocationSize(buffer_handle_t /*bufferHandle*/, 122 uint64_t* /*outAllocationSize*/) const { 123 return INVALID_OPERATION; 124 } getProtectedContent(buffer_handle_t,uint64_t *)125 virtual status_t getProtectedContent(buffer_handle_t /*bufferHandle*/, 126 uint64_t* /*outProtectedContent*/) const { 127 return INVALID_OPERATION; 128 } getCompression(buffer_handle_t,aidl::android::hardware::graphics::common::ExtendableType *)129 virtual status_t getCompression( 130 buffer_handle_t /*bufferHandle*/, 131 aidl::android::hardware::graphics::common::ExtendableType* /*outCompression*/) const { 132 return INVALID_OPERATION; 133 } getCompression(buffer_handle_t,ui::Compression *)134 virtual status_t getCompression(buffer_handle_t /*bufferHandle*/, 135 ui::Compression* /*outCompression*/) const { 136 return INVALID_OPERATION; 137 } getInterlaced(buffer_handle_t,aidl::android::hardware::graphics::common::ExtendableType *)138 virtual status_t getInterlaced( 139 buffer_handle_t /*bufferHandle*/, 140 aidl::android::hardware::graphics::common::ExtendableType* /*outInterlaced*/) const { 141 return INVALID_OPERATION; 142 } getInterlaced(buffer_handle_t,ui::Interlaced *)143 virtual status_t getInterlaced(buffer_handle_t /*bufferHandle*/, 144 ui::Interlaced* /*outInterlaced*/) const { 145 return INVALID_OPERATION; 146 } getChromaSiting(buffer_handle_t,aidl::android::hardware::graphics::common::ExtendableType *)147 virtual status_t getChromaSiting( 148 buffer_handle_t /*bufferHandle*/, 149 aidl::android::hardware::graphics::common::ExtendableType* /*outChromaSiting*/) const { 150 return INVALID_OPERATION; 151 } getChromaSiting(buffer_handle_t,ui::ChromaSiting *)152 virtual status_t getChromaSiting(buffer_handle_t /*bufferHandle*/, 153 ui::ChromaSiting* /*outChromaSiting*/) const { 154 return INVALID_OPERATION; 155 } getPlaneLayouts(buffer_handle_t,std::vector<ui::PlaneLayout> *)156 virtual status_t getPlaneLayouts(buffer_handle_t /*bufferHandle*/, 157 std::vector<ui::PlaneLayout>* /*outPlaneLayouts*/) const { 158 return INVALID_OPERATION; 159 } getDataspace(buffer_handle_t,ui::Dataspace *)160 virtual status_t getDataspace(buffer_handle_t /*bufferHandle*/, 161 ui::Dataspace* /*outDataspace*/) const { 162 return INVALID_OPERATION; 163 } getBlendMode(buffer_handle_t,ui::BlendMode *)164 virtual status_t getBlendMode(buffer_handle_t /*bufferHandle*/, 165 ui::BlendMode* /*outBlendMode*/) const { 166 return INVALID_OPERATION; 167 } getSmpte2086(buffer_handle_t,std::optional<ui::Smpte2086> *)168 virtual status_t getSmpte2086(buffer_handle_t /*bufferHandle*/, 169 std::optional<ui::Smpte2086>* /*outSmpte2086*/) const { 170 return INVALID_OPERATION; 171 } getCta861_3(buffer_handle_t,std::optional<ui::Cta861_3> *)172 virtual status_t getCta861_3(buffer_handle_t /*bufferHandle*/, 173 std::optional<ui::Cta861_3>* /*outCta861_3*/) const { 174 return INVALID_OPERATION; 175 } getSmpte2094_40(buffer_handle_t,std::optional<std::vector<uint8_t>> *)176 virtual status_t getSmpte2094_40( 177 buffer_handle_t /*bufferHandle*/, 178 std::optional<std::vector<uint8_t>>* /*outSmpte2094_40*/) const { 179 return INVALID_OPERATION; 180 } 181 getDefaultPixelFormatFourCC(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,uint32_t *)182 virtual status_t getDefaultPixelFormatFourCC(uint32_t /*width*/, uint32_t /*height*/, 183 PixelFormat /*format*/, uint32_t /*layerCount*/, 184 uint64_t /*usage*/, 185 uint32_t* /*outPixelFormatFourCC*/) const { 186 return INVALID_OPERATION; 187 } getDefaultPixelFormatModifier(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,uint64_t *)188 virtual status_t getDefaultPixelFormatModifier(uint32_t /*width*/, uint32_t /*height*/, 189 PixelFormat /*format*/, uint32_t /*layerCount*/, 190 uint64_t /*usage*/, 191 uint64_t* /*outPixelFormatModifier*/) const { 192 return INVALID_OPERATION; 193 } getDefaultAllocationSize(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,uint64_t *)194 virtual status_t getDefaultAllocationSize(uint32_t /*width*/, uint32_t /*height*/, 195 PixelFormat /*format*/, uint32_t /*layerCount*/, 196 uint64_t /*usage*/, 197 uint64_t* /*outAllocationSize*/) const { 198 return INVALID_OPERATION; 199 } getDefaultProtectedContent(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,uint64_t *)200 virtual status_t getDefaultProtectedContent(uint32_t /*width*/, uint32_t /*height*/, 201 PixelFormat /*format*/, uint32_t /*layerCount*/, 202 uint64_t /*usage*/, 203 uint64_t* /*outProtectedContent*/) const { 204 return INVALID_OPERATION; 205 } getDefaultCompression(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,aidl::android::hardware::graphics::common::ExtendableType *)206 virtual status_t getDefaultCompression( 207 uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, 208 uint32_t /*layerCount*/, uint64_t /*usage*/, 209 aidl::android::hardware::graphics::common::ExtendableType* /*outCompression*/) const { 210 return INVALID_OPERATION; 211 } getDefaultCompression(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,ui::Compression *)212 virtual status_t getDefaultCompression(uint32_t /*width*/, uint32_t /*height*/, 213 PixelFormat /*format*/, uint32_t /*layerCount*/, 214 uint64_t /*usage*/, 215 ui::Compression* /*outCompression*/) const { 216 return INVALID_OPERATION; 217 } getDefaultInterlaced(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,aidl::android::hardware::graphics::common::ExtendableType *)218 virtual status_t getDefaultInterlaced( 219 uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, 220 uint32_t /*layerCount*/, uint64_t /*usage*/, 221 aidl::android::hardware::graphics::common::ExtendableType* /*outInterlaced*/) const { 222 return INVALID_OPERATION; 223 } getDefaultInterlaced(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,ui::Interlaced *)224 virtual status_t getDefaultInterlaced(uint32_t /*width*/, uint32_t /*height*/, 225 PixelFormat /*format*/, uint32_t /*layerCount*/, 226 uint64_t /*usage*/, 227 ui::Interlaced* /*outInterlaced*/) const { 228 return INVALID_OPERATION; 229 } getDefaultChromaSiting(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,aidl::android::hardware::graphics::common::ExtendableType *)230 virtual status_t getDefaultChromaSiting( 231 uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, 232 uint32_t /*layerCount*/, uint64_t /*usage*/, 233 aidl::android::hardware::graphics::common::ExtendableType* /*outChromaSiting*/) const { 234 return INVALID_OPERATION; 235 } getDefaultChromaSiting(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,ui::ChromaSiting *)236 virtual status_t getDefaultChromaSiting(uint32_t /*width*/, uint32_t /*height*/, 237 PixelFormat /*format*/, uint32_t /*layerCount*/, 238 uint64_t /*usage*/, 239 ui::ChromaSiting* /*outChromaSiting*/) const { 240 return INVALID_OPERATION; 241 } getDefaultPlaneLayouts(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,std::vector<ui::PlaneLayout> *)242 virtual status_t getDefaultPlaneLayouts( 243 uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, 244 uint32_t /*layerCount*/, uint64_t /*usage*/, 245 std::vector<ui::PlaneLayout>* /*outPlaneLayouts*/) const { 246 return INVALID_OPERATION; 247 } 248 249 virtual std::vector<android::hardware::graphics::mapper::V4_0::IMapper::MetadataTypeDescription> listSupportedMetadataTypes()250 listSupportedMetadataTypes() const { 251 return {}; 252 } 253 }; 254 255 // A wrapper to IAllocator 256 class GrallocAllocator { 257 public: 258 virtual ~GrallocAllocator(); 259 260 virtual bool isLoaded() const = 0; 261 262 virtual std::string dumpDebugInfo(bool less = true) const = 0; 263 264 /* 265 * The returned buffers are already imported and must not be imported 266 * again. outBufferHandles must point to a space that can contain at 267 * least "bufferCount" buffer_handle_t. 268 */ 269 virtual status_t allocate(std::string requestorName, uint32_t width, uint32_t height, 270 PixelFormat format, uint32_t layerCount, uint64_t usage, 271 uint32_t bufferCount, uint32_t* outStride, 272 buffer_handle_t* outBufferHandles, 273 bool importBuffers = true) const = 0; 274 }; 275 276 } // namespace android 277 278 #endif // ANDROID_UI_GRALLOC_H 279