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