Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H |
| 18 | #define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/Errors.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | |
| 26 | #include <binder/IInterface.h> |
| 27 | |
Chong Zhang | 20288fd | 2019-03-21 15:15:27 -0700 | [diff] [blame] | 28 | #include <ui/BufferQueueDefs.h> |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 29 | #include <ui/Fence.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 30 | #include <ui/GraphicBuffer.h> |
| 31 | #include <ui/Rect.h> |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 32 | #include <ui/Region.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 33 | |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 34 | #include <gui/FrameTimestamps.h> |
Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 35 | #include <gui/HdrMetadata.h> |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 36 | |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 37 | #include <hidl/HybridInterface.h> |
| 38 | #include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h> |
Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 39 | #include <android/hardware/graphics/bufferqueue/2.0/IGraphicBufferProducer.h> |
Pawin Vongmasa | 6e1193a | 2017-03-07 13:08:40 -0800 | [diff] [blame] | 40 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 41 | namespace android { |
| 42 | // ---------------------------------------------------------------------------- |
| 43 | |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 44 | class IProducerListener; |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 45 | class NativeHandle; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 46 | class Surface; |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 47 | |
Chong Zhang | 6249309 | 2020-01-15 16:04:47 -0800 | [diff] [blame] | 48 | using HGraphicBufferProducerV1_0 = |
| 49 | ::android::hardware::graphics::bufferqueue::V1_0:: |
| 50 | IGraphicBufferProducer; |
| 51 | using HGraphicBufferProducerV2_0 = |
| 52 | ::android::hardware::graphics::bufferqueue::V2_0:: |
| 53 | IGraphicBufferProducer; |
| 54 | |
Andy McFadden | 0273adb | 2012-12-12 17:10:08 -0800 | [diff] [blame] | 55 | /* |
Andy McFadden | 466a192 | 2013-01-08 11:25:51 -0800 | [diff] [blame] | 56 | * This class defines the Binder IPC interface for the producer side of |
| 57 | * a queue of graphics buffers. It's used to send graphics data from one |
| 58 | * component to another. For example, a class that decodes video for |
| 59 | * playback might use this to provide frames. This is typically done |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 60 | * indirectly, through Surface. |
Andy McFadden | 0273adb | 2012-12-12 17:10:08 -0800 | [diff] [blame] | 61 | * |
Andy McFadden | 466a192 | 2013-01-08 11:25:51 -0800 | [diff] [blame] | 62 | * The underlying mechanism is a BufferQueue, which implements |
| 63 | * BnGraphicBufferProducer. In normal operation, the producer calls |
| 64 | * dequeueBuffer() to get an empty buffer, fills it with data, then |
| 65 | * calls queueBuffer() to make it available to the consumer. |
Andy McFadden | 0273adb | 2012-12-12 17:10:08 -0800 | [diff] [blame] | 66 | * |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 67 | * This class was previously called ISurfaceTexture. |
Andy McFadden | 0273adb | 2012-12-12 17:10:08 -0800 | [diff] [blame] | 68 | */ |
Chong Zhang | 6249309 | 2020-01-15 16:04:47 -0800 | [diff] [blame] | 69 | #ifndef NO_BINDER |
| 70 | class IGraphicBufferProducer : public IInterface { |
Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 71 | DECLARE_HYBRID_META_INTERFACE(GraphicBufferProducer, |
| 72 | HGraphicBufferProducerV1_0, |
| 73 | HGraphicBufferProducerV2_0) |
Chong Zhang | 6249309 | 2020-01-15 16:04:47 -0800 | [diff] [blame] | 74 | #else |
| 75 | class IGraphicBufferProducer : public RefBase { |
| 76 | #endif |
| 77 | public: |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 78 | enum { |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 79 | // A flag returned by dequeueBuffer when the client needs to call |
| 80 | // requestBuffer immediately thereafter. |
Chong Zhang | 20288fd | 2019-03-21 15:15:27 -0700 | [diff] [blame] | 81 | BUFFER_NEEDS_REALLOCATION = BufferQueueDefs::BUFFER_NEEDS_REALLOCATION, |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 82 | // A flag returned by dequeueBuffer when all mirrored slots should be |
| 83 | // released by the client. This flag should always be processed first. |
Chong Zhang | 20288fd | 2019-03-21 15:15:27 -0700 | [diff] [blame] | 84 | RELEASE_ALL_BUFFERS = BufferQueueDefs::RELEASE_ALL_BUFFERS, |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 85 | }; |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 86 | |
Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 87 | enum { |
| 88 | // A parcelable magic indicates using Binder BufferQueue as transport |
| 89 | // backend. |
| 90 | USE_BUFFER_QUEUE = 0x62717565, // 'bque' |
| 91 | // A parcelable magic indicates using BufferHub as transport backend. |
| 92 | USE_BUFFER_HUB = 0x62687562, // 'bhub' |
| 93 | }; |
| 94 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 95 | // requestBuffer requests a new buffer for the given index. The server (i.e. |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 96 | // the IGraphicBufferProducer implementation) assigns the newly created |
| 97 | // buffer to the given slot index, and the client is expected to mirror the |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 98 | // slot->buffer mapping so that it's not necessary to transfer a |
| 99 | // GraphicBuffer for every dequeue operation. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 100 | // |
| 101 | // The slot must be in the range of [0, NUM_BUFFER_SLOTS). |
| 102 | // |
| 103 | // Return of a value other than NO_ERROR means an error has occurred: |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 104 | // * NO_INIT - the buffer queue has been abandoned or the producer is not |
| 105 | // connected. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 106 | // * BAD_VALUE - one of the two conditions occurred: |
| 107 | // * slot was out of range (see above) |
| 108 | // * buffer specified by the slot is not dequeued |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 109 | virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 110 | |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 111 | // setMaxDequeuedBufferCount sets the maximum number of buffers that can be |
Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 112 | // dequeued by the producer at one time. If this method succeeds, any new |
| 113 | // buffer slots will be both unallocated and owned by the BufferQueue object |
| 114 | // (i.e. they are not owned by the producer or consumer). Calling this may |
| 115 | // also cause some buffer slots to be emptied. If the caller is caching the |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 116 | // contents of the buffer slots, it should empty that cache after calling |
| 117 | // this method. |
| 118 | // |
Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 119 | // This function should not be called with a value of maxDequeuedBuffers |
| 120 | // that is less than the number of currently dequeued buffer slots. Doing so |
| 121 | // will result in a BAD_VALUE error. |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 122 | // |
| 123 | // The buffer count should be at least 1 (inclusive), but at most |
| 124 | // (NUM_BUFFER_SLOTS - the minimum undequeued buffer count) (exclusive). The |
| 125 | // minimum undequeued buffer count can be obtained by calling |
| 126 | // query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS). |
| 127 | // |
| 128 | // Return of a value other than NO_ERROR means an error has occurred: |
| 129 | // * NO_INIT - the buffer queue has been abandoned. |
| 130 | // * BAD_VALUE - one of the below conditions occurred: |
Pablo Ceballos | 72daab6 | 2015-12-07 16:38:43 -0800 | [diff] [blame] | 131 | // * bufferCount was out of range (see above). |
| 132 | // * client would have more than the requested number of dequeued |
| 133 | // buffers after this call. |
| 134 | // * this call would cause the maxBufferCount value to be exceeded. |
Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 135 | // * failure to adjust the number of available slots. |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 136 | virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) = 0; |
| 137 | |
| 138 | // Set the async flag if the producer intends to asynchronously queue |
| 139 | // buffers without blocking. Typically this is used for triple-buffering |
| 140 | // and/or when the swap interval is set to zero. |
| 141 | // |
| 142 | // Enabling async mode will internally allocate an additional buffer to |
| 143 | // allow for the asynchronous behavior. If it is not enabled queue/dequeue |
| 144 | // calls may block. |
| 145 | // |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 146 | // Return of a value other than NO_ERROR means an error has occurred: |
| 147 | // * NO_INIT - the buffer queue has been abandoned. |
Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 148 | // * BAD_VALUE - one of the following has occurred: |
| 149 | // * this call would cause the maxBufferCount value to be |
Pablo Ceballos | b687a28 | 2015-10-06 11:14:51 -0700 | [diff] [blame] | 150 | // exceeded |
Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 151 | // * failure to adjust the number of available slots. |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 152 | virtual status_t setAsyncMode(bool async) = 0; |
| 153 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 154 | // dequeueBuffer requests a new buffer slot for the client to use. Ownership |
| 155 | // of the slot is transfered to the client, meaning that the server will not |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 156 | // use the contents of the buffer associated with that slot. |
| 157 | // |
| 158 | // The slot index returned may or may not contain a buffer (client-side). |
| 159 | // If the slot is empty the client should call requestBuffer to assign a new |
| 160 | // buffer to that slot. |
| 161 | // |
| 162 | // Once the client is done filling this buffer, it is expected to transfer |
| 163 | // buffer ownership back to the server with either cancelBuffer on |
| 164 | // the dequeued slot or to fill in the contents of its associated buffer |
| 165 | // contents and call queueBuffer. |
| 166 | // |
| 167 | // If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 168 | // expected to call requestBuffer immediately. |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 169 | // |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 170 | // If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is |
| 171 | // expected to release all of the mirrored slot->buffer mappings. |
| 172 | // |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 173 | // The fence parameter will be updated to hold the fence associated with |
| 174 | // the buffer. The contents of the buffer must not be overwritten until the |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 175 | // fence signals. If the fence is Fence::NO_FENCE, the buffer may be written |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 176 | // immediately. |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 177 | // |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 178 | // The width and height parameters must be no greater than the minimum of |
| 179 | // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). |
| 180 | // An error due to invalid dimensions might not be reported until |
| 181 | // updateTexImage() is called. If width and height are both zero, the |
| 182 | // default values specified by setDefaultBufferSize() are used instead. |
| 183 | // |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 184 | // If the format is 0, the default format will be used. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 185 | // |
| 186 | // The usage argument specifies gralloc buffer usage flags. The values |
| 187 | // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER. These |
| 188 | // will be merged with the usage flags specified by |
| 189 | // IGraphicBufferConsumer::setConsumerUsageBits. |
| 190 | // |
| 191 | // This call will block until a buffer is available to be dequeued. If |
| 192 | // both the producer and consumer are controlled by the app, then this call |
| 193 | // can never block and will return WOULD_BLOCK if no buffer is available. |
| 194 | // |
| 195 | // A non-negative value with flags set (see above) will be returned upon |
| 196 | // success. |
| 197 | // |
| 198 | // Return of a negative means an error has occurred: |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 199 | // * NO_INIT - the buffer queue has been abandoned or the producer is not |
| 200 | // connected. |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 201 | // * BAD_VALUE - both in async mode and buffer count was less than the |
| 202 | // max numbers of buffers that can be allocated at once. |
| 203 | // * INVALID_OPERATION - cannot attach the buffer because it would cause |
| 204 | // too many buffers to be dequeued, either because |
| 205 | // the producer already has a single buffer dequeued |
| 206 | // and did not set a buffer count, or because a |
| 207 | // buffer count was set and this call would cause |
| 208 | // it to be exceeded. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 209 | // * WOULD_BLOCK - no buffer is currently available, and blocking is disabled |
| 210 | // since both the producer/consumer are controlled by app |
| 211 | // * NO_MEMORY - out of memory, cannot allocate the graphics buffer. |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 212 | // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while |
| 213 | // waiting for a buffer to become available. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 214 | // |
| 215 | // All other negative values are an unknown error returned downstream |
| 216 | // from the graphics allocator (typically errno). |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 217 | virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h, |
| 218 | PixelFormat format, uint64_t usage, uint64_t* outBufferAge, |
| 219 | FrameEventHistoryDelta* outTimestamps) = 0; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 220 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 221 | // detachBuffer attempts to remove all ownership of the buffer in the given |
| 222 | // slot from the buffer queue. If this call succeeds, the slot will be |
| 223 | // freed, and there will be no way to obtain the buffer from this interface. |
| 224 | // The freed slot will remain unallocated until either it is selected to |
| 225 | // hold a freshly allocated buffer in dequeueBuffer or a buffer is attached |
| 226 | // to the slot. The buffer must have already been dequeued, and the caller |
| 227 | // must already possesses the sp<GraphicBuffer> (i.e., must have called |
| 228 | // requestBuffer). |
| 229 | // |
| 230 | // Return of a value other than NO_ERROR means an error has occurred: |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 231 | // * NO_INIT - the buffer queue has been abandoned or the producer is not |
| 232 | // connected. |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 233 | // * BAD_VALUE - the given slot number is invalid, either because it is |
| 234 | // out of the range [0, NUM_BUFFER_SLOTS), or because the slot |
| 235 | // it refers to is not currently dequeued and requested. |
| 236 | virtual status_t detachBuffer(int slot) = 0; |
| 237 | |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 238 | // detachNextBuffer is equivalent to calling dequeueBuffer, requestBuffer, |
| 239 | // and detachBuffer in sequence, except for two things: |
| 240 | // |
| 241 | // 1) It is unnecessary to know the dimensions, format, or usage of the |
| 242 | // next buffer. |
| 243 | // 2) It will not block, since if it cannot find an appropriate buffer to |
| 244 | // return, it will return an error instead. |
| 245 | // |
| 246 | // Only slots that are free but still contain a GraphicBuffer will be |
| 247 | // considered, and the oldest of those will be returned. outBuffer is |
| 248 | // equivalent to outBuffer from the requestBuffer call, and outFence is |
| 249 | // equivalent to fence from the dequeueBuffer call. |
| 250 | // |
| 251 | // Return of a value other than NO_ERROR means an error has occurred: |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 252 | // * NO_INIT - the buffer queue has been abandoned or the producer is not |
| 253 | // connected. |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 254 | // * BAD_VALUE - either outBuffer or outFence were NULL. |
| 255 | // * NO_MEMORY - no slots were found that were both free and contained a |
| 256 | // GraphicBuffer. |
| 257 | virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, |
| 258 | sp<Fence>* outFence) = 0; |
| 259 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 260 | // attachBuffer attempts to transfer ownership of a buffer to the buffer |
| 261 | // queue. If this call succeeds, it will be as if this buffer was dequeued |
| 262 | // from the returned slot number. As such, this call will fail if attaching |
| 263 | // this buffer would cause too many buffers to be simultaneously dequeued. |
| 264 | // |
| 265 | // If attachBuffer returns the RELEASE_ALL_BUFFERS flag, the caller is |
| 266 | // expected to release all of the mirrored slot->buffer mappings. |
| 267 | // |
| 268 | // A non-negative value with flags set (see above) will be returned upon |
| 269 | // success. |
| 270 | // |
| 271 | // Return of a negative value means an error has occurred: |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 272 | // * NO_INIT - the buffer queue has been abandoned or the producer is not |
| 273 | // connected. |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 274 | // * BAD_VALUE - outSlot or buffer were NULL, invalid combination of |
| 275 | // async mode and buffer count override, or the generation |
| 276 | // number of the buffer did not match the buffer queue. |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 277 | // * INVALID_OPERATION - cannot attach the buffer because it would cause |
| 278 | // too many buffers to be dequeued, either because |
| 279 | // the producer already has a single buffer dequeued |
| 280 | // and did not set a buffer count, or because a |
| 281 | // buffer count was set and this call would cause |
| 282 | // it to be exceeded. |
| 283 | // * WOULD_BLOCK - no buffer slot is currently available, and blocking is |
| 284 | // disabled since both the producer/consumer are |
| 285 | // controlled by the app. |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 286 | // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while |
| 287 | // waiting for a slot to become available. |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 288 | virtual status_t attachBuffer(int* outSlot, |
| 289 | const sp<GraphicBuffer>& buffer) = 0; |
| 290 | |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 291 | struct QueueBufferInput : public Flattenable<QueueBufferInput> { |
| 292 | friend class Flattenable<QueueBufferInput>; |
Chih-Hung Hsieh | 65d4787 | 2016-09-01 11:39:25 -0700 | [diff] [blame] | 293 | explicit inline QueueBufferInput(const Parcel& parcel); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 294 | |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 295 | // timestamp - a monotonically increasing value in nanoseconds |
| 296 | // isAutoTimestamp - if the timestamp was synthesized at queue time |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 297 | // dataSpace - description of the contents, interpretation depends on format |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 298 | // crop - a crop rectangle that's used as a hint to the consumer |
| 299 | // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h> |
| 300 | // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h> |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 301 | // fence - a fence that the consumer must wait on before reading the buffer, |
| 302 | // set this to Fence::NO_FENCE if the buffer is ready immediately |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 303 | // sticky - the sticky transform set in Surface (only used by the LEGACY |
| 304 | // camera mode). |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 305 | // getFrameTimestamps - whether or not the latest frame timestamps |
| 306 | // should be retrieved from the consumer. |
Colin Cross | 382ecd3 | 2016-09-26 13:33:59 -0700 | [diff] [blame] | 307 | inline QueueBufferInput(int64_t _timestamp, bool _isAutoTimestamp, |
| 308 | android_dataspace _dataSpace, const Rect& _crop, |
| 309 | int _scalingMode, uint32_t _transform, const sp<Fence>& _fence, |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 310 | uint32_t _sticky = 0, bool _getFrameTimestamps = false) |
Colin Cross | 382ecd3 | 2016-09-26 13:33:59 -0700 | [diff] [blame] | 311 | : timestamp(_timestamp), isAutoTimestamp(_isAutoTimestamp), |
| 312 | dataSpace(_dataSpace), crop(_crop), scalingMode(_scalingMode), |
| 313 | transform(_transform), stickyTransform(_sticky), fence(_fence), |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 314 | surfaceDamage(), getFrameTimestamps(_getFrameTimestamps) { } |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 315 | |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 316 | inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp, |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 317 | android_dataspace* outDataSpace, |
| 318 | Rect* outCrop, int* outScalingMode, |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 319 | uint32_t* outTransform, sp<Fence>* outFence, |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 320 | uint32_t* outStickyTransform = nullptr, |
| 321 | bool* outGetFrameTimestamps = nullptr) const { |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 322 | *outTimestamp = timestamp; |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 323 | *outIsAutoTimestamp = bool(isAutoTimestamp); |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 324 | *outDataSpace = dataSpace; |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 325 | *outCrop = crop; |
| 326 | *outScalingMode = scalingMode; |
| 327 | *outTransform = transform; |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 328 | *outFence = fence; |
Yi Kong | a03e044 | 2018-07-17 11:16:57 -0700 | [diff] [blame] | 329 | if (outStickyTransform != nullptr) { |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 330 | *outStickyTransform = stickyTransform; |
| 331 | } |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 332 | if (outGetFrameTimestamps) { |
| 333 | *outGetFrameTimestamps = getFrameTimestamps; |
| 334 | } |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 335 | } |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 336 | |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 337 | // Flattenable protocol |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 338 | static constexpr size_t minFlattenedSize(); |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 339 | size_t getFlattenedSize() const; |
| 340 | size_t getFdCount() const; |
| 341 | status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; |
| 342 | status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 343 | |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 344 | const Region& getSurfaceDamage() const { return surfaceDamage; } |
| 345 | void setSurfaceDamage(const Region& damage) { surfaceDamage = damage; } |
| 346 | |
Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 347 | const HdrMetadata& getHdrMetadata() const { return hdrMetadata; } |
| 348 | void setHdrMetadata(const HdrMetadata& metadata) { hdrMetadata = metadata; } |
| 349 | |
Pablo Ceballos | bd3577e | 2016-06-20 17:40:34 -0700 | [diff] [blame] | 350 | int64_t timestamp{0}; |
| 351 | int isAutoTimestamp{0}; |
| 352 | android_dataspace dataSpace{HAL_DATASPACE_UNKNOWN}; |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 353 | Rect crop; |
Pablo Ceballos | bd3577e | 2016-06-20 17:40:34 -0700 | [diff] [blame] | 354 | int scalingMode{0}; |
| 355 | uint32_t transform{0}; |
| 356 | uint32_t stickyTransform{0}; |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 357 | sp<Fence> fence; |
Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 358 | Region surfaceDamage; |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 359 | bool getFrameTimestamps{false}; |
Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 360 | HdrMetadata hdrMetadata; |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 361 | }; |
| 362 | |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 363 | struct QueueBufferOutput : public Flattenable<QueueBufferOutput> { |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 364 | QueueBufferOutput() = default; |
| 365 | |
| 366 | // Moveable. |
| 367 | QueueBufferOutput(QueueBufferOutput&& src) = default; |
| 368 | QueueBufferOutput& operator=(QueueBufferOutput&& src) = default; |
| 369 | // Not copyable. |
| 370 | QueueBufferOutput(const QueueBufferOutput& src) = delete; |
| 371 | QueueBufferOutput& operator=(const QueueBufferOutput& src) = delete; |
| 372 | |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 373 | // Flattenable protocol |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 374 | static constexpr size_t minFlattenedSize(); |
Brian Anderson | baaad32 | 2016-07-22 15:55:13 -0700 | [diff] [blame] | 375 | size_t getFlattenedSize() const; |
| 376 | size_t getFdCount() const; |
| 377 | status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; |
| 378 | status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); |
| 379 | |
Pablo Ceballos | bd3577e | 2016-06-20 17:40:34 -0700 | [diff] [blame] | 380 | uint32_t width{0}; |
| 381 | uint32_t height{0}; |
| 382 | uint32_t transformHint{0}; |
| 383 | uint32_t numPendingBuffers{0}; |
Pablo Ceballos | bc8c192 | 2016-07-01 14:15:41 -0700 | [diff] [blame] | 384 | uint64_t nextFrameNumber{0}; |
Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 385 | FrameEventHistoryDelta frameTimestamps; |
Shuzhen Wang | 22f842b | 2017-01-18 23:02:36 -0800 | [diff] [blame] | 386 | bool bufferReplaced{false}; |
silence_dogood | e9d092a | 2019-06-19 16:14:53 -0700 | [diff] [blame] | 387 | int maxBufferCount{0}; |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 388 | }; |
| 389 | |
Marin Shalamanov | a54a736 | 2019-11-04 16:18:42 +0100 | [diff] [blame] | 390 | // queueBuffer indicates that the client has finished filling in the |
| 391 | // contents of the buffer associated with slot and transfers ownership of |
| 392 | // that slot back to the server. |
| 393 | // |
| 394 | // It is not valid to call queueBuffer on a slot that is not owned |
| 395 | // by the client or one for which a buffer associated via requestBuffer |
| 396 | // (an attempt to do so will fail with a return value of BAD_VALUE). |
| 397 | // |
| 398 | // In addition, the input must be described by the client (as documented |
| 399 | // below). Any other properties (zero point, etc) |
| 400 | // are client-dependent, and should be documented by the client. |
| 401 | // |
| 402 | // The slot must be in the range of [0, NUM_BUFFER_SLOTS). |
| 403 | // |
| 404 | // Upon success, the output will be filled with meaningful values |
| 405 | // (refer to the documentation below). |
| 406 | // |
| 407 | // Return of a value other than NO_ERROR means an error has occurred: |
| 408 | // * NO_INIT - the buffer queue has been abandoned or the producer is not |
| 409 | // connected. |
| 410 | // * BAD_VALUE - one of the below conditions occurred: |
| 411 | // * fence was NULL |
| 412 | // * scaling mode was unknown |
| 413 | // * both in async mode and buffer count was less than the |
| 414 | // max numbers of buffers that can be allocated at once |
| 415 | // * slot index was out of range (see above). |
| 416 | // * the slot was not in the dequeued state |
| 417 | // * the slot was enqueued without requesting a buffer |
| 418 | // * crop rect is out of bounds of the buffer dimensions |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 419 | virtual status_t queueBuffer(int slot, const QueueBufferInput& input, |
| 420 | QueueBufferOutput* output) = 0; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 421 | |
| 422 | // cancelBuffer indicates that the client does not wish to fill in the |
| 423 | // buffer associated with slot and transfers ownership of the slot back to |
| 424 | // the server. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 425 | // |
| 426 | // The buffer is not queued for use by the consumer. |
| 427 | // |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 428 | // The slot must be in the range of [0, NUM_BUFFER_SLOTS). |
| 429 | // |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 430 | // The buffer will not be overwritten until the fence signals. The fence |
| 431 | // will usually be the one obtained from dequeueBuffer. |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 432 | // |
| 433 | // Return of a value other than NO_ERROR means an error has occurred: |
| 434 | // * NO_INIT - the buffer queue has been abandoned or the producer is not |
| 435 | // connected. |
| 436 | // * BAD_VALUE - one of the below conditions occurred: |
| 437 | // * fence was NULL |
| 438 | // * slot index was out of range (see above). |
| 439 | // * the slot was not in the dequeued state |
| 440 | virtual status_t cancelBuffer(int slot, const sp<Fence>& fence) = 0; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 441 | |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 442 | // query retrieves some information for this surface |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 443 | // 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h> |
| 444 | // |
| 445 | // Return of a value other than NO_ERROR means an error has occurred: |
| 446 | // * NO_INIT - the buffer queue has been abandoned. |
| 447 | // * BAD_VALUE - what was out of range |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 448 | virtual int query(int what, int* value) = 0; |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 449 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 450 | // connect attempts to connect a client API to the IGraphicBufferProducer. |
| 451 | // This must be called before any other IGraphicBufferProducer methods are |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 452 | // called except for getAllocator. A consumer must be already connected. |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 453 | // |
| 454 | // This method will fail if the connect was previously called on the |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 455 | // IGraphicBufferProducer and no corresponding disconnect call was made. |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 456 | // |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 457 | // The listener is an optional binder callback object that can be used if |
| 458 | // the producer wants to be notified when the consumer releases a buffer |
| 459 | // back to the BufferQueue. It is also used to detect the death of the |
| 460 | // producer. If only the latter functionality is desired, there is a |
Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 461 | // StubProducerListener class in IProducerListener.h that can be used. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 462 | // |
| 463 | // The api should be one of the NATIVE_WINDOW_API_* values in <window.h> |
| 464 | // |
| 465 | // The producerControlledByApp should be set to true if the producer is hosted |
| 466 | // by an untrusted process (typically app_process-forked processes). If both |
| 467 | // the producer and the consumer are app-controlled then all buffer queues |
| 468 | // will operate in async mode regardless of the async flag. |
| 469 | // |
| 470 | // Upon success, the output will be filled with meaningful data |
| 471 | // (refer to QueueBufferOutput documentation above). |
| 472 | // |
| 473 | // Return of a value other than NO_ERROR means an error has occurred: |
| 474 | // * NO_INIT - one of the following occurred: |
| 475 | // * the buffer queue was abandoned |
| 476 | // * no consumer has yet connected |
| 477 | // * BAD_VALUE - one of the following has occurred: |
| 478 | // * the producer is already connected |
| 479 | // * api was out of range (see above). |
Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 480 | // * output was NULL. |
Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 481 | // * Failure to adjust the number of available slots. This can |
| 482 | // happen because of trying to allocate/deallocate the async |
| 483 | // buffer in response to the value of producerControlledByApp. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 484 | // * DEAD_OBJECT - the token is hosted by an already-dead process |
| 485 | // |
| 486 | // Additional negative errors may be returned by the internals, they |
| 487 | // should be treated as opaque fatal unrecoverable errors. |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 488 | virtual status_t connect(const sp<IProducerListener>& listener, |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 489 | int api, bool producerControlledByApp, QueueBufferOutput* output) = 0; |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 490 | |
Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 491 | enum class DisconnectMode { |
| 492 | // Disconnect only the specified API. |
| 493 | Api, |
| 494 | // Disconnect any API originally connected from the process calling disconnect. |
| 495 | AllLocal |
| 496 | }; |
| 497 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 498 | // disconnect attempts to disconnect a client API from the |
| 499 | // IGraphicBufferProducer. Calling this method will cause any subsequent |
| 500 | // calls to other IGraphicBufferProducer methods to fail except for |
| 501 | // getAllocator and connect. Successfully calling connect after this will |
| 502 | // allow the other methods to succeed again. |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 503 | // |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 504 | // The api should be one of the NATIVE_WINDOW_API_* values in <window.h> |
| 505 | // |
Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 506 | // Alternatively if mode is AllLocal, then the API value is ignored, and any API |
| 507 | // connected from the same PID calling disconnect will be disconnected. |
| 508 | // |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 509 | // Disconnecting from an abandoned IGraphicBufferProducer is legal and |
| 510 | // is considered a no-op. |
| 511 | // |
| 512 | // Return of a value other than NO_ERROR means an error has occurred: |
Wonsik Kim | 3e198b2 | 2017-04-07 15:43:16 -0700 | [diff] [blame] | 513 | // * NO_INIT - the producer is not connected |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 514 | // * BAD_VALUE - one of the following has occurred: |
| 515 | // * the api specified does not match the one that was connected |
| 516 | // * api was out of range (see above). |
| 517 | // * DEAD_OBJECT - the token is hosted by an already-dead process |
Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 518 | virtual status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api) = 0; |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 519 | |
| 520 | // Attaches a sideband buffer stream to the IGraphicBufferProducer. |
| 521 | // |
| 522 | // A sideband stream is a device-specific mechanism for passing buffers |
| 523 | // from the producer to the consumer without using dequeueBuffer/ |
| 524 | // queueBuffer. If a sideband stream is present, the consumer can choose |
| 525 | // whether to acquire buffers from the sideband stream or from the queued |
| 526 | // buffers. |
| 527 | // |
| 528 | // Passing NULL or a different stream handle will detach the previous |
| 529 | // handle if any. |
| 530 | virtual status_t setSidebandStream(const sp<NativeHandle>& stream) = 0; |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 531 | |
| 532 | // Allocates buffers based on the given dimensions/format. |
| 533 | // |
| 534 | // This function will allocate up to the maximum number of buffers |
| 535 | // permitted by the current BufferQueue configuration. It will use the |
| 536 | // given format, dimensions, and usage bits, which are interpreted in the |
| 537 | // same way as for dequeueBuffer, and the async flag must be set the same |
| 538 | // way as for dequeueBuffer to ensure that the correct number of buffers are |
| 539 | // allocated. This is most useful to avoid an allocation delay during |
| 540 | // dequeueBuffer. If there are already the maximum number of buffers |
| 541 | // allocated, this function has no effect. |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 542 | virtual void allocateBuffers(uint32_t width, uint32_t height, |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 543 | PixelFormat format, uint64_t usage) = 0; |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 544 | |
| 545 | // Sets whether dequeueBuffer is allowed to allocate new buffers. |
| 546 | // |
| 547 | // Normally dequeueBuffer does not discriminate between free slots which |
| 548 | // already have an allocated buffer and those which do not, and will |
| 549 | // allocate a new buffer if the slot doesn't have a buffer or if the slot's |
| 550 | // buffer doesn't match the requested size, format, or usage. This method |
| 551 | // allows the producer to restrict the eligible slots to those which already |
| 552 | // have an allocated buffer of the correct size, format, and usage. If no |
| 553 | // eligible slot is available, dequeueBuffer will block or return an error |
| 554 | // as usual. |
| 555 | virtual status_t allowAllocation(bool allow) = 0; |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 556 | |
| 557 | // Sets the current generation number of the BufferQueue. |
| 558 | // |
| 559 | // This generation number will be inserted into any buffers allocated by the |
| 560 | // BufferQueue, and any attempts to attach a buffer with a different |
| 561 | // generation number will fail. Buffers already in the queue are not |
| 562 | // affected and will retain their current generation number. The generation |
| 563 | // number defaults to 0. |
| 564 | virtual status_t setGenerationNumber(uint32_t generationNumber) = 0; |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 565 | |
| 566 | // Returns the name of the connected consumer. |
| 567 | virtual String8 getConsumerName() const = 0; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 568 | |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 569 | // Used to enable/disable shared buffer mode. |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 570 | // |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 571 | // When shared buffer mode is enabled the first buffer that is queued or |
Pablo Ceballos | 295a9fc | 2016-03-14 16:02:19 -0700 | [diff] [blame] | 572 | // dequeued will be cached and returned to all subsequent calls to |
| 573 | // dequeueBuffer and acquireBuffer. This allows the producer and consumer to |
| 574 | // simultaneously access the same buffer. |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 575 | virtual status_t setSharedBufferMode(bool sharedBufferMode) = 0; |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 576 | |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 577 | // Used to enable/disable auto-refresh. |
| 578 | // |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 579 | // Auto refresh has no effect outside of shared buffer mode. In shared |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 580 | // buffer mode, when enabled, it indicates to the consumer that it should |
| 581 | // attempt to acquire buffers even if it is not aware of any being |
| 582 | // available. |
| 583 | virtual status_t setAutoRefresh(bool autoRefresh) = 0; |
| 584 | |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 585 | // Sets how long dequeueBuffer will wait for a buffer to become available |
| 586 | // before returning an error (TIMED_OUT). |
| 587 | // |
| 588 | // This timeout also affects the attachBuffer call, which will block if |
| 589 | // there is not a free slot available into which the attached buffer can be |
| 590 | // placed. |
| 591 | // |
| 592 | // By default, the BufferQueue will wait forever, which is indicated by a |
| 593 | // timeout of -1. If set (to a value other than -1), this will disable |
| 594 | // non-blocking mode and its corresponding spare buffer (which is used to |
| 595 | // ensure a buffer is always available). |
Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 596 | // |
Sungtak Lee | 3249fb6 | 2019-03-02 16:40:47 -0800 | [diff] [blame] | 597 | // Note well: queueBuffer will stop buffer dropping behavior if timeout is |
| 598 | // strictly positive. If timeout is zero or negative, previous buffer |
| 599 | // dropping behavior will not be changed. |
| 600 | // |
Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 601 | // Return of a value other than NO_ERROR means an error has occurred: |
| 602 | // * BAD_VALUE - Failure to adjust the number of available slots. This can |
| 603 | // happen because of trying to allocate/deallocate the async |
| 604 | // buffer. |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 605 | virtual status_t setDequeueTimeout(nsecs_t timeout) = 0; |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 606 | |
Sungtak Lee | 3249fb6 | 2019-03-02 16:40:47 -0800 | [diff] [blame] | 607 | // Used to enable/disable buffer drop behavior of queueBuffer. |
| 608 | // If it's not used, legacy drop behavior will be retained. |
| 609 | virtual status_t setLegacyBufferDrop(bool drop); |
| 610 | |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 611 | // Returns the last queued buffer along with a fence which must signal |
| 612 | // before the contents of the buffer are read. If there are no buffers in |
| 613 | // the queue, outBuffer will be populated with nullptr and outFence will be |
| 614 | // populated with Fence::NO_FENCE |
| 615 | // |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 616 | // outTransformMatrix is not modified if outBuffer is null. |
| 617 | // |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 618 | // Returns NO_ERROR or the status of the Binder transaction |
| 619 | virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 620 | sp<Fence>* outFence, float outTransformMatrix[16]) = 0; |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 621 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 622 | // Gets the frame events that haven't already been retrieved. |
| 623 | virtual void getFrameTimestamps(FrameEventHistoryDelta* /*outDelta*/) {} |
Pablo Ceballos | 0ade247 | 2016-06-30 16:48:02 -0700 | [diff] [blame] | 624 | |
Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 625 | // Returns a unique id for this BufferQueue |
| 626 | virtual status_t getUniqueId(uint64_t* outId) const = 0; |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 627 | |
| 628 | // Returns the consumer usage flags for this BufferQueue. This returns the |
| 629 | // full 64-bit usage flags, rather than the truncated 32-bit usage flags |
| 630 | // returned by querying the now deprecated |
| 631 | // NATIVE_WINDOW_CONSUMER_USAGE_BITS attribute. |
| 632 | virtual status_t getConsumerUsage(uint64_t* outUsage) const = 0; |
Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 633 | |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 634 | // Enable/disable the auto prerotation at buffer allocation when the buffer |
| 635 | // size is driven by the consumer. |
| 636 | // |
| 637 | // When buffer size is driven by the consumer and the transform hint |
| 638 | // specifies a 90 or 270 degree rotation, if auto prerotation is enabled, |
| 639 | // the width and height used for dequeueBuffer will be additionally swapped. |
| 640 | virtual status_t setAutoPrerotation(bool autoPrerotation); |
| 641 | |
Chong Zhang | 6249309 | 2020-01-15 16:04:47 -0800 | [diff] [blame] | 642 | #ifndef NO_BINDER |
Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 643 | // Static method exports any IGraphicBufferProducer object to a parcel. It |
| 644 | // handles null producer as well. |
| 645 | static status_t exportToParcel(const sp<IGraphicBufferProducer>& producer, |
| 646 | Parcel* parcel); |
| 647 | |
| 648 | // Factory method that creates a new IBGP instance from the parcel. |
| 649 | static sp<IGraphicBufferProducer> createFromParcel(const Parcel* parcel); |
| 650 | |
| 651 | protected: |
| 652 | // Exports the current producer as a binder parcelable object. Note that the |
| 653 | // producer must be disconnected to be exportable. After successful export, |
| 654 | // the producer queue can no longer be connected again. Returns NO_ERROR |
| 655 | // when the export is successful and writes an implementation defined |
| 656 | // parcelable object into the parcel. For traditional Android BufferQueue, |
| 657 | // it writes a strong binder object; for BufferHub, it writes a |
| 658 | // ProducerQueueParcelable object. |
| 659 | virtual status_t exportToParcel(Parcel* parcel); |
Chong Zhang | 6249309 | 2020-01-15 16:04:47 -0800 | [diff] [blame] | 660 | #endif |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 661 | }; |
| 662 | |
| 663 | // ---------------------------------------------------------------------------- |
Chong Zhang | 6249309 | 2020-01-15 16:04:47 -0800 | [diff] [blame] | 664 | #ifndef NO_BINDER |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 665 | class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 666 | { |
| 667 | public: |
| 668 | virtual status_t onTransact( uint32_t code, |
| 669 | const Parcel& data, |
| 670 | Parcel* reply, |
| 671 | uint32_t flags = 0); |
| 672 | }; |
Chong Zhang | 6249309 | 2020-01-15 16:04:47 -0800 | [diff] [blame] | 673 | #else |
| 674 | class BnGraphicBufferProducer : public IGraphicBufferProducer { |
| 675 | }; |
| 676 | #endif |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 677 | |
| 678 | // ---------------------------------------------------------------------------- |
| 679 | }; // namespace android |
| 680 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 681 | #endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H |