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 } setDataspace(buffer_handle_t,ui::Dataspace)164 virtual status_t setDataspace(buffer_handle_t /*bufferHandle*/, 165 ui::Dataspace /*dataspace*/) const { 166 return INVALID_OPERATION; 167 } getBlendMode(buffer_handle_t,ui::BlendMode *)168 virtual status_t getBlendMode(buffer_handle_t /*bufferHandle*/, 169 ui::BlendMode* /*outBlendMode*/) const { 170 return INVALID_OPERATION; 171 } getSmpte2086(buffer_handle_t,std::optional<ui::Smpte2086> *)172 virtual status_t getSmpte2086(buffer_handle_t /*bufferHandle*/, 173 std::optional<ui::Smpte2086>* /*outSmpte2086*/) const { 174 return INVALID_OPERATION; 175 } setSmpte2086(buffer_handle_t,std::optional<ui::Smpte2086>)176 virtual status_t setSmpte2086(buffer_handle_t /*bufferHandle*/, 177 std::optional<ui::Smpte2086> /*smpte2086*/) const { 178 return INVALID_OPERATION; 179 } getCta861_3(buffer_handle_t,std::optional<ui::Cta861_3> *)180 virtual status_t getCta861_3(buffer_handle_t /*bufferHandle*/, 181 std::optional<ui::Cta861_3>* /*outCta861_3*/) const { 182 return INVALID_OPERATION; 183 } setCta861_3(buffer_handle_t,std::optional<ui::Cta861_3>)184 virtual status_t setCta861_3(buffer_handle_t /*bufferHandle*/, 185 std::optional<ui::Cta861_3> /*cta861_3*/) const { 186 return INVALID_OPERATION; 187 } getSmpte2094_40(buffer_handle_t,std::optional<std::vector<uint8_t>> *)188 virtual status_t getSmpte2094_40( 189 buffer_handle_t /*bufferHandle*/, 190 std::optional<std::vector<uint8_t>>* /*outSmpte2094_40*/) const { 191 return INVALID_OPERATION; 192 } setSmpte2094_40(buffer_handle_t,std::optional<std::vector<uint8_t>>)193 virtual status_t setSmpte2094_40(buffer_handle_t /*bufferHandle*/, 194 std::optional<std::vector<uint8_t>> /*smpte2094_40*/) const { 195 return INVALID_OPERATION; 196 } getSmpte2094_10(buffer_handle_t,std::optional<std::vector<uint8_t>> *)197 virtual status_t getSmpte2094_10( 198 buffer_handle_t /*bufferHandle*/, 199 std::optional<std::vector<uint8_t>>* /*outSmpte2094_10*/) const { 200 return INVALID_OPERATION; 201 } setSmpte2094_10(buffer_handle_t,std::optional<std::vector<uint8_t>>)202 virtual status_t setSmpte2094_10(buffer_handle_t /*bufferHandle*/, 203 std::optional<std::vector<uint8_t>> /*smpte2094_10*/) const { 204 return INVALID_OPERATION; 205 } getDefaultPixelFormatFourCC(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,uint32_t *)206 virtual status_t getDefaultPixelFormatFourCC(uint32_t /*width*/, uint32_t /*height*/, 207 PixelFormat /*format*/, uint32_t /*layerCount*/, 208 uint64_t /*usage*/, 209 uint32_t* /*outPixelFormatFourCC*/) const { 210 return INVALID_OPERATION; 211 } getDefaultPixelFormatModifier(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,uint64_t *)212 virtual status_t getDefaultPixelFormatModifier(uint32_t /*width*/, uint32_t /*height*/, 213 PixelFormat /*format*/, uint32_t /*layerCount*/, 214 uint64_t /*usage*/, 215 uint64_t* /*outPixelFormatModifier*/) const { 216 return INVALID_OPERATION; 217 } getDefaultAllocationSize(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,uint64_t *)218 virtual status_t getDefaultAllocationSize(uint32_t /*width*/, uint32_t /*height*/, 219 PixelFormat /*format*/, uint32_t /*layerCount*/, 220 uint64_t /*usage*/, 221 uint64_t* /*outAllocationSize*/) const { 222 return INVALID_OPERATION; 223 } getDefaultProtectedContent(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,uint64_t *)224 virtual status_t getDefaultProtectedContent(uint32_t /*width*/, uint32_t /*height*/, 225 PixelFormat /*format*/, uint32_t /*layerCount*/, 226 uint64_t /*usage*/, 227 uint64_t* /*outProtectedContent*/) const { 228 return INVALID_OPERATION; 229 } getDefaultCompression(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,aidl::android::hardware::graphics::common::ExtendableType *)230 virtual status_t getDefaultCompression( 231 uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, 232 uint32_t /*layerCount*/, uint64_t /*usage*/, 233 aidl::android::hardware::graphics::common::ExtendableType* /*outCompression*/) const { 234 return INVALID_OPERATION; 235 } getDefaultCompression(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,ui::Compression *)236 virtual status_t getDefaultCompression(uint32_t /*width*/, uint32_t /*height*/, 237 PixelFormat /*format*/, uint32_t /*layerCount*/, 238 uint64_t /*usage*/, 239 ui::Compression* /*outCompression*/) const { 240 return INVALID_OPERATION; 241 } getDefaultInterlaced(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,aidl::android::hardware::graphics::common::ExtendableType *)242 virtual status_t getDefaultInterlaced( 243 uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, 244 uint32_t /*layerCount*/, uint64_t /*usage*/, 245 aidl::android::hardware::graphics::common::ExtendableType* /*outInterlaced*/) const { 246 return INVALID_OPERATION; 247 } getDefaultInterlaced(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,ui::Interlaced *)248 virtual status_t getDefaultInterlaced(uint32_t /*width*/, uint32_t /*height*/, 249 PixelFormat /*format*/, uint32_t /*layerCount*/, 250 uint64_t /*usage*/, 251 ui::Interlaced* /*outInterlaced*/) const { 252 return INVALID_OPERATION; 253 } getDefaultChromaSiting(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,aidl::android::hardware::graphics::common::ExtendableType *)254 virtual status_t getDefaultChromaSiting( 255 uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, 256 uint32_t /*layerCount*/, uint64_t /*usage*/, 257 aidl::android::hardware::graphics::common::ExtendableType* /*outChromaSiting*/) const { 258 return INVALID_OPERATION; 259 } getDefaultChromaSiting(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,ui::ChromaSiting *)260 virtual status_t getDefaultChromaSiting(uint32_t /*width*/, uint32_t /*height*/, 261 PixelFormat /*format*/, uint32_t /*layerCount*/, 262 uint64_t /*usage*/, 263 ui::ChromaSiting* /*outChromaSiting*/) const { 264 return INVALID_OPERATION; 265 } getDefaultPlaneLayouts(uint32_t,uint32_t,PixelFormat,uint32_t,uint64_t,std::vector<ui::PlaneLayout> *)266 virtual status_t getDefaultPlaneLayouts( 267 uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, 268 uint32_t /*layerCount*/, uint64_t /*usage*/, 269 std::vector<ui::PlaneLayout>* /*outPlaneLayouts*/) const { 270 return INVALID_OPERATION; 271 } 272 273 virtual std::vector<android::hardware::graphics::mapper::V4_0::IMapper::MetadataTypeDescription> listSupportedMetadataTypes()274 listSupportedMetadataTypes() const { 275 return {}; 276 } 277 }; 278 279 // A wrapper to IAllocator 280 class GrallocAllocator { 281 public: 282 virtual ~GrallocAllocator(); 283 284 virtual bool isLoaded() const = 0; 285 286 virtual std::string dumpDebugInfo(bool less = true) const = 0; 287 288 /* 289 * The returned buffers are already imported and must not be imported 290 * again. outBufferHandles must point to a space that can contain at 291 * least "bufferCount" buffer_handle_t. 292 */ 293 virtual status_t allocate(std::string requestorName, uint32_t width, uint32_t height, 294 PixelFormat format, uint32_t layerCount, uint64_t usage, 295 uint32_t bufferCount, uint32_t* outStride, 296 buffer_handle_t* outBufferHandles, 297 bool importBuffers = true) const = 0; 298 }; 299 300 } // namespace android 301 302 #endif // ANDROID_UI_GRALLOC_H 303