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 #include "GraphicBufferAllocator.h" 27 28 #include <string> 29 30 namespace android { 31 32 // A wrapper to IMapper 33 class GrallocMapper { 34 public: 35 virtual ~GrallocMapper(); 36 37 virtual bool isLoaded() const = 0; 38 dumpBuffer(buffer_handle_t,bool)39 virtual std::string dumpBuffer(buffer_handle_t /*bufferHandle*/, bool /*less*/) const { 40 return ""; 41 } 42 43 // Import a buffer that is from another HAL, another process, or is 44 // cloned. 45 // 46 // The returned handle must be freed with freeBuffer. 47 virtual status_t importBuffer(const native_handle_t* rawHandle, 48 buffer_handle_t* outBufferHandle) const = 0; 49 50 virtual void freeBuffer(buffer_handle_t bufferHandle) const = 0; 51 52 virtual status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, 53 uint32_t height, android::PixelFormat format, 54 uint32_t layerCount, uint64_t usage, 55 uint32_t stride) const = 0; 56 57 virtual void getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds, 58 uint32_t* outNumInts) const = 0; 59 60 // The ownership of acquireFence is always transferred to the callee, even 61 // on errors. 62 virtual status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, 63 int acquireFence, void** outData, int32_t* outBytesPerPixel, 64 int32_t* outBytesPerStride) const = 0; 65 66 // The ownership of acquireFence is always transferred to the callee, even 67 // on errors. 68 virtual status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, 69 int acquireFence, android_ycbcr* ycbcr) const = 0; 70 71 // unlock returns a fence sync object (or -1) and the fence sync object is 72 // owned by the caller 73 virtual int unlock(buffer_handle_t bufferHandle) const = 0; 74 75 // isSupported queries whether or not a buffer with the given width, height, 76 // format, layer count, and usage can be allocated on the device. If 77 // *outSupported is set to true, a buffer with the given specifications may be successfully 78 // allocated if resources are available. If false, a buffer with the given specifications will 79 // never successfully allocate on this device. Note that this function is not guaranteed to be 80 // 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 *)81 virtual status_t isSupported(uint32_t /*width*/, uint32_t /*height*/, 82 android::PixelFormat /*format*/, uint32_t /*layerCount*/, 83 uint64_t /*usage*/, bool* /*outSupported*/) const { 84 return INVALID_OPERATION; 85 } 86 getBufferId(buffer_handle_t,uint64_t *)87 virtual status_t getBufferId(buffer_handle_t /*bufferHandle*/, 88 uint64_t* /*outBufferId*/) const { 89 return INVALID_OPERATION; 90 } getName(buffer_handle_t,std::string *)91 virtual status_t getName(buffer_handle_t /*bufferHandle*/, std::string* /*outName*/) const { 92 return INVALID_OPERATION; 93 } getWidth(buffer_handle_t,uint64_t *)94 virtual status_t getWidth(buffer_handle_t /*bufferHandle*/, uint64_t* /*outWidth*/) const { 95 return INVALID_OPERATION; 96 } getHeight(buffer_handle_t,uint64_t *)97 virtual status_t getHeight(buffer_handle_t /*bufferHandle*/, uint64_t* /*outHeight*/) const { 98 return INVALID_OPERATION; 99 } getLayerCount(buffer_handle_t,uint64_t *)100 virtual status_t getLayerCount(buffer_handle_t /*bufferHandle*/, 101 uint64_t* /*outLayerCount*/) const { 102 return INVALID_OPERATION; 103 } getPixelFormatRequested(buffer_handle_t,ui::PixelFormat *)104 virtual status_t getPixelFormatRequested(buffer_handle_t /*bufferHandle*/, 105 ui::PixelFormat* /*outPixelFormatRequested*/) const { 106 return INVALID_OPERATION; 107 } getPixelFormatFourCC(buffer_handle_t,uint32_t *)108 virtual status_t getPixelFormatFourCC(buffer_handle_t /*bufferHandle*/, 109 uint32_t* /*outPixelFormatFourCC*/) const { 110 return INVALID_OPERATION; 111 } getPixelFormatModifier(buffer_handle_t,uint64_t *)112 virtual status_t getPixelFormatModifier(buffer_handle_t /*bufferHandle*/, 113 uint64_t* /*outPixelFormatModifier*/) const { 114 return INVALID_OPERATION; 115 } getUsage(buffer_handle_t,uint64_t *)116 virtual status_t getUsage(buffer_handle_t /*bufferHandle*/, uint64_t* /*outUsage*/) const { 117 return INVALID_OPERATION; 118 } getAllocationSize(buffer_handle_t,uint64_t *)119 virtual status_t getAllocationSize(buffer_handle_t /*bufferHandle*/, 120 uint64_t* /*outAllocationSize*/) const { 121 return INVALID_OPERATION; 122 } getProtectedContent(buffer_handle_t,uint64_t *)123 virtual status_t getProtectedContent(buffer_handle_t /*bufferHandle*/, 124 uint64_t* /*outProtectedContent*/) const { 125 return INVALID_OPERATION; 126 } getCompression(buffer_handle_t,aidl::android::hardware::graphics::common::ExtendableType *)127 virtual status_t getCompression( 128 buffer_handle_t /*bufferHandle*/, 129 aidl::android::hardware::graphics::common::ExtendableType* /*outCompression*/) const { 130 return INVALID_OPERATION; 131 } getCompression(buffer_handle_t,ui::Compression *)132 virtual status_t getCompression(buffer_handle_t /*bufferHandle*/, 133 ui::Compression* /*outCompression*/) const { 134 return INVALID_OPERATION; 135 } getInterlaced(buffer_handle_t,aidl::android::hardware::graphics::common::ExtendableType *)136 virtual status_t getInterlaced( 137 buffer_handle_t /*bufferHandle*/, 138 aidl::android::hardware::graphics::common::ExtendableType* /*outInterlaced*/) const { 139 return INVALID_OPERATION; 140 } getInterlaced(buffer_handle_t,ui::Interlaced *)141 virtual status_t getInterlaced(buffer_handle_t /*bufferHandle*/, 142 ui::Interlaced* /*outInterlaced*/) const { 143 return INVALID_OPERATION; 144 } getChromaSiting(buffer_handle_t,aidl::android::hardware::graphics::common::ExtendableType *)145 virtual status_t getChromaSiting( 146 buffer_handle_t /*bufferHandle*/, 147 aidl::android::hardware::graphics::common::ExtendableType* /*outChromaSiting*/) const { 148 return INVALID_OPERATION; 149 } getChromaSiting(buffer_handle_t,ui::ChromaSiting *)150 virtual status_t getChromaSiting(buffer_handle_t /*bufferHandle*/, 151 ui::ChromaSiting* /*outChromaSiting*/) const { 152 return INVALID_OPERATION; 153 } getPlaneLayouts(buffer_handle_t,std::vector<ui::PlaneLayout> *)154 virtual status_t getPlaneLayouts(buffer_handle_t /*bufferHandle*/, 155 std::vector<ui::PlaneLayout>* /*outPlaneLayouts*/) const { 156 return INVALID_OPERATION; 157 } getDataspace(buffer_handle_t,ui::Dataspace *)158 virtual status_t getDataspace(buffer_handle_t /*bufferHandle*/, 159 ui::Dataspace* /*outDataspace*/) const { 160 return INVALID_OPERATION; 161 } setDataspace(buffer_handle_t,ui::Dataspace)162 virtual status_t setDataspace(buffer_handle_t /*bufferHandle*/, 163 ui::Dataspace /*dataspace*/) const { 164 return INVALID_OPERATION; 165 } getBlendMode(buffer_handle_t,ui::BlendMode *)166 virtual status_t getBlendMode(buffer_handle_t /*bufferHandle*/, 167 ui::BlendMode* /*outBlendMode*/) const { 168 return INVALID_OPERATION; 169 } getSmpte2086(buffer_handle_t,std::optional<ui::Smpte2086> *)170 virtual status_t getSmpte2086(buffer_handle_t /*bufferHandle*/, 171 std::optional<ui::Smpte2086>* /*outSmpte2086*/) const { 172 return INVALID_OPERATION; 173 } setSmpte2086(buffer_handle_t,std::optional<ui::Smpte2086>)174 virtual status_t setSmpte2086(buffer_handle_t /*bufferHandle*/, 175 std::optional<ui::Smpte2086> /*smpte2086*/) const { 176 return INVALID_OPERATION; 177 } getCta861_3(buffer_handle_t,std::optional<ui::Cta861_3> *)178 virtual status_t getCta861_3(buffer_handle_t /*bufferHandle*/, 179 std::optional<ui::Cta861_3>* /*outCta861_3*/) const { 180 return INVALID_OPERATION; 181 } setCta861_3(buffer_handle_t,std::optional<ui::Cta861_3>)182 virtual status_t setCta861_3(buffer_handle_t /*bufferHandle*/, 183 std::optional<ui::Cta861_3> /*cta861_3*/) const { 184 return INVALID_OPERATION; 185 } getSmpte2094_40(buffer_handle_t,std::optional<std::vector<uint8_t>> *)186 virtual status_t getSmpte2094_40( 187 buffer_handle_t /*bufferHandle*/, 188 std::optional<std::vector<uint8_t>>* /*outSmpte2094_40*/) const { 189 return INVALID_OPERATION; 190 } setSmpte2094_40(buffer_handle_t,std::optional<std::vector<uint8_t>>)191 virtual status_t setSmpte2094_40(buffer_handle_t /*bufferHandle*/, 192 std::optional<std::vector<uint8_t>> /*smpte2094_40*/) const { 193 return INVALID_OPERATION; 194 } getSmpte2094_10(buffer_handle_t,std::optional<std::vector<uint8_t>> *)195 virtual status_t getSmpte2094_10( 196 buffer_handle_t /*bufferHandle*/, 197 std::optional<std::vector<uint8_t>>* /*outSmpte2094_10*/) const { 198 return INVALID_OPERATION; 199 } setSmpte2094_10(buffer_handle_t,std::optional<std::vector<uint8_t>>)200 virtual status_t setSmpte2094_10(buffer_handle_t /*bufferHandle*/, 201 std::optional<std::vector<uint8_t>> /*smpte2094_10*/) const { 202 return INVALID_OPERATION; 203 } 204 }; 205 206 // A wrapper to IAllocator 207 class GrallocAllocator { 208 public: 209 virtual ~GrallocAllocator(); 210 211 virtual bool isLoaded() const = 0; 212 213 virtual std::string dumpDebugInfo(bool less = true) const = 0; 214 215 /* 216 * The returned buffers are already imported and must not be imported 217 * again. outBufferHandles must point to a space that can contain at 218 * least "bufferCount" buffer_handle_t. 219 */ 220 virtual status_t allocate(std::string requestorName, uint32_t width, uint32_t height, 221 PixelFormat format, uint32_t layerCount, uint64_t usage, 222 uint32_t* outStride, buffer_handle_t* outBufferHandles, 223 bool importBuffers = true) const = 0; 224 allocate(const GraphicBufferAllocator::AllocationRequest &)225 virtual GraphicBufferAllocator::AllocationResult allocate( 226 const GraphicBufferAllocator::AllocationRequest&) const { 227 return GraphicBufferAllocator::AllocationResult(UNKNOWN_TRANSACTION); 228 } 229 supportsAdditionalOptions()230 virtual bool supportsAdditionalOptions() const { return false; } 231 }; 232 233 } // namespace android 234 235 #endif // ANDROID_UI_GRALLOC_H 236