Home | History | Annotate | Download | only in gui
      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 
     17 #ifndef ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
     18 #define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
     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 
     28 #include <ui/Fence.h>
     29 #include <ui/GraphicBuffer.h>
     30 #include <ui/Rect.h>
     31 #include <ui/Region.h>
     32 
     33 #include <gui/FrameTimestamps.h>
     34 
     35 #include <hidl/HybridInterface.h>
     36 #include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h>
     37 
     38 namespace android {
     39 // ----------------------------------------------------------------------------
     40 
     41 class IProducerListener;
     42 class NativeHandle;
     43 class Surface;
     44 typedef ::android::hardware::graphics::bufferqueue::V1_0::IGraphicBufferProducer
     45         HGraphicBufferProducer;
     46 
     47 /*
     48  * This class defines the Binder IPC interface for the producer side of
     49  * a queue of graphics buffers.  It's used to send graphics data from one
     50  * component to another.  For example, a class that decodes video for
     51  * playback might use this to provide frames.  This is typically done
     52  * indirectly, through Surface.
     53  *
     54  * The underlying mechanism is a BufferQueue, which implements
     55  * BnGraphicBufferProducer.  In normal operation, the producer calls
     56  * dequeueBuffer() to get an empty buffer, fills it with data, then
     57  * calls queueBuffer() to make it available to the consumer.
     58  *
     59  * This class was previously called ISurfaceTexture.
     60  */
     61 class IGraphicBufferProducer : public IInterface
     62 {
     63 public:
     64     DECLARE_HYBRID_META_INTERFACE(GraphicBufferProducer, HGraphicBufferProducer)
     65 
     66     enum {
     67         // A flag returned by dequeueBuffer when the client needs to call
     68         // requestBuffer immediately thereafter.
     69         BUFFER_NEEDS_REALLOCATION = 0x1,
     70         // A flag returned by dequeueBuffer when all mirrored slots should be
     71         // released by the client. This flag should always be processed first.
     72         RELEASE_ALL_BUFFERS       = 0x2,
     73     };
     74 
     75     // requestBuffer requests a new buffer for the given index. The server (i.e.
     76     // the IGraphicBufferProducer implementation) assigns the newly created
     77     // buffer to the given slot index, and the client is expected to mirror the
     78     // slot->buffer mapping so that it's not necessary to transfer a
     79     // GraphicBuffer for every dequeue operation.
     80     //
     81     // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
     82     //
     83     // Return of a value other than NO_ERROR means an error has occurred:
     84     // * NO_INIT - the buffer queue has been abandoned or the producer is not
     85     //             connected.
     86     // * BAD_VALUE - one of the two conditions occurred:
     87     //              * slot was out of range (see above)
     88     //              * buffer specified by the slot is not dequeued
     89     virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
     90 
     91     // setMaxDequeuedBufferCount sets the maximum number of buffers that can be
     92     // dequeued by the producer at one time. If this method succeeds, any new
     93     // buffer slots will be both unallocated and owned by the BufferQueue object
     94     // (i.e. they are not owned by the producer or consumer). Calling this may
     95     // also cause some buffer slots to be emptied. If the caller is caching the
     96     // contents of the buffer slots, it should empty that cache after calling
     97     // this method.
     98     //
     99     // This function should not be called with a value of maxDequeuedBuffers
    100     // that is less than the number of currently dequeued buffer slots. Doing so
    101     // will result in a BAD_VALUE error.
    102     //
    103     // The buffer count should be at least 1 (inclusive), but at most
    104     // (NUM_BUFFER_SLOTS - the minimum undequeued buffer count) (exclusive). The
    105     // minimum undequeued buffer count can be obtained by calling
    106     // query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS).
    107     //
    108     // Return of a value other than NO_ERROR means an error has occurred:
    109     // * NO_INIT - the buffer queue has been abandoned.
    110     // * BAD_VALUE - one of the below conditions occurred:
    111     //     * bufferCount was out of range (see above).
    112     //     * client would have more than the requested number of dequeued
    113     //       buffers after this call.
    114     //     * this call would cause the maxBufferCount value to be exceeded.
    115     //     * failure to adjust the number of available slots.
    116     virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) = 0;
    117 
    118     // Set the async flag if the producer intends to asynchronously queue
    119     // buffers without blocking. Typically this is used for triple-buffering
    120     // and/or when the swap interval is set to zero.
    121     //
    122     // Enabling async mode will internally allocate an additional buffer to
    123     // allow for the asynchronous behavior. If it is not enabled queue/dequeue
    124     // calls may block.
    125     //
    126     // Return of a value other than NO_ERROR means an error has occurred:
    127     // * NO_INIT - the buffer queue has been abandoned.
    128     // * BAD_VALUE - one of the following has occurred:
    129     //             * this call would cause the maxBufferCount value to be
    130     //               exceeded
    131     //             * failure to adjust the number of available slots.
    132     virtual status_t setAsyncMode(bool async) = 0;
    133 
    134     // dequeueBuffer requests a new buffer slot for the client to use. Ownership
    135     // of the slot is transfered to the client, meaning that the server will not
    136     // use the contents of the buffer associated with that slot.
    137     //
    138     // The slot index returned may or may not contain a buffer (client-side).
    139     // If the slot is empty the client should call requestBuffer to assign a new
    140     // buffer to that slot.
    141     //
    142     // Once the client is done filling this buffer, it is expected to transfer
    143     // buffer ownership back to the server with either cancelBuffer on
    144     // the dequeued slot or to fill in the contents of its associated buffer
    145     // contents and call queueBuffer.
    146     //
    147     // If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is
    148     // expected to call requestBuffer immediately.
    149     //
    150     // If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is
    151     // expected to release all of the mirrored slot->buffer mappings.
    152     //
    153     // The fence parameter will be updated to hold the fence associated with
    154     // the buffer. The contents of the buffer must not be overwritten until the
    155     // fence signals. If the fence is Fence::NO_FENCE, the buffer may be written
    156     // immediately.
    157     //
    158     // The width and height parameters must be no greater than the minimum of
    159     // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
    160     // An error due to invalid dimensions might not be reported until
    161     // updateTexImage() is called.  If width and height are both zero, the
    162     // default values specified by setDefaultBufferSize() are used instead.
    163     //
    164     // If the format is 0, the default format will be used.
    165     //
    166     // The usage argument specifies gralloc buffer usage flags.  The values
    167     // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER.  These
    168     // will be merged with the usage flags specified by
    169     // IGraphicBufferConsumer::setConsumerUsageBits.
    170     //
    171     // This call will block until a buffer is available to be dequeued. If
    172     // both the producer and consumer are controlled by the app, then this call
    173     // can never block and will return WOULD_BLOCK if no buffer is available.
    174     //
    175     // A non-negative value with flags set (see above) will be returned upon
    176     // success.
    177     //
    178     // Return of a negative means an error has occurred:
    179     // * NO_INIT - the buffer queue has been abandoned or the producer is not
    180     //             connected.
    181     // * BAD_VALUE - both in async mode and buffer count was less than the
    182     //               max numbers of buffers that can be allocated at once.
    183     // * INVALID_OPERATION - cannot attach the buffer because it would cause
    184     //                       too many buffers to be dequeued, either because
    185     //                       the producer already has a single buffer dequeued
    186     //                       and did not set a buffer count, or because a
    187     //                       buffer count was set and this call would cause
    188     //                       it to be exceeded.
    189     // * WOULD_BLOCK - no buffer is currently available, and blocking is disabled
    190     //                 since both the producer/consumer are controlled by app
    191     // * NO_MEMORY - out of memory, cannot allocate the graphics buffer.
    192     // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while
    193     //               waiting for a buffer to become available.
    194     //
    195     // All other negative values are an unknown error returned downstream
    196     // from the graphics allocator (typically errno).
    197     virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w,
    198             uint32_t h, PixelFormat format, uint32_t usage,
    199             FrameEventHistoryDelta* outTimestamps) = 0;
    200 
    201     // detachBuffer attempts to remove all ownership of the buffer in the given
    202     // slot from the buffer queue. If this call succeeds, the slot will be
    203     // freed, and there will be no way to obtain the buffer from this interface.
    204     // The freed slot will remain unallocated until either it is selected to
    205     // hold a freshly allocated buffer in dequeueBuffer or a buffer is attached
    206     // to the slot. The buffer must have already been dequeued, and the caller
    207     // must already possesses the sp<GraphicBuffer> (i.e., must have called
    208     // requestBuffer).
    209     //
    210     // Return of a value other than NO_ERROR means an error has occurred:
    211     // * NO_INIT - the buffer queue has been abandoned or the producer is not
    212     //             connected.
    213     // * BAD_VALUE - the given slot number is invalid, either because it is
    214     //               out of the range [0, NUM_BUFFER_SLOTS), or because the slot
    215     //               it refers to is not currently dequeued and requested.
    216     virtual status_t detachBuffer(int slot) = 0;
    217 
    218     // detachNextBuffer is equivalent to calling dequeueBuffer, requestBuffer,
    219     // and detachBuffer in sequence, except for two things:
    220     //
    221     // 1) It is unnecessary to know the dimensions, format, or usage of the
    222     //    next buffer.
    223     // 2) It will not block, since if it cannot find an appropriate buffer to
    224     //    return, it will return an error instead.
    225     //
    226     // Only slots that are free but still contain a GraphicBuffer will be
    227     // considered, and the oldest of those will be returned. outBuffer is
    228     // equivalent to outBuffer from the requestBuffer call, and outFence is
    229     // equivalent to fence from the dequeueBuffer call.
    230     //
    231     // Return of a value other than NO_ERROR means an error has occurred:
    232     // * NO_INIT - the buffer queue has been abandoned or the producer is not
    233     //             connected.
    234     // * BAD_VALUE - either outBuffer or outFence were NULL.
    235     // * NO_MEMORY - no slots were found that were both free and contained a
    236     //               GraphicBuffer.
    237     virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
    238             sp<Fence>* outFence) = 0;
    239 
    240     // attachBuffer attempts to transfer ownership of a buffer to the buffer
    241     // queue. If this call succeeds, it will be as if this buffer was dequeued
    242     // from the returned slot number. As such, this call will fail if attaching
    243     // this buffer would cause too many buffers to be simultaneously dequeued.
    244     //
    245     // If attachBuffer returns the RELEASE_ALL_BUFFERS flag, the caller is
    246     // expected to release all of the mirrored slot->buffer mappings.
    247     //
    248     // A non-negative value with flags set (see above) will be returned upon
    249     // success.
    250     //
    251     // Return of a negative value means an error has occurred:
    252     // * NO_INIT - the buffer queue has been abandoned or the producer is not
    253     //             connected.
    254     // * BAD_VALUE - outSlot or buffer were NULL, invalid combination of
    255     //               async mode and buffer count override, or the generation
    256     //               number of the buffer did not match the buffer queue.
    257     // * INVALID_OPERATION - cannot attach the buffer because it would cause
    258     //                       too many buffers to be dequeued, either because
    259     //                       the producer already has a single buffer dequeued
    260     //                       and did not set a buffer count, or because a
    261     //                       buffer count was set and this call would cause
    262     //                       it to be exceeded.
    263     // * WOULD_BLOCK - no buffer slot is currently available, and blocking is
    264     //                 disabled since both the producer/consumer are
    265     //                 controlled by the app.
    266     // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while
    267     //               waiting for a slot to become available.
    268     virtual status_t attachBuffer(int* outSlot,
    269             const sp<GraphicBuffer>& buffer) = 0;
    270 
    271     // queueBuffer indicates that the client has finished filling in the
    272     // contents of the buffer associated with slot and transfers ownership of
    273     // that slot back to the server.
    274     //
    275     // It is not valid to call queueBuffer on a slot that is not owned
    276     // by the client or one for which a buffer associated via requestBuffer
    277     // (an attempt to do so will fail with a return value of BAD_VALUE).
    278     //
    279     // In addition, the input must be described by the client (as documented
    280     // below). Any other properties (zero point, etc)
    281     // are client-dependent, and should be documented by the client.
    282     //
    283     // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
    284     //
    285     // Upon success, the output will be filled with meaningful values
    286     // (refer to the documentation below).
    287     //
    288     // Return of a value other than NO_ERROR means an error has occurred:
    289     // * NO_INIT - the buffer queue has been abandoned or the producer is not
    290     //             connected.
    291     // * BAD_VALUE - one of the below conditions occurred:
    292     //              * fence was NULL
    293     //              * scaling mode was unknown
    294     //              * both in async mode and buffer count was less than the
    295     //                max numbers of buffers that can be allocated at once
    296     //              * slot index was out of range (see above).
    297     //              * the slot was not in the dequeued state
    298     //              * the slot was enqueued without requesting a buffer
    299     //              * crop rect is out of bounds of the buffer dimensions
    300 
    301     struct QueueBufferInput : public Flattenable<QueueBufferInput> {
    302         friend class Flattenable<QueueBufferInput>;
    303         explicit inline QueueBufferInput(const Parcel& parcel);
    304 
    305         // timestamp - a monotonically increasing value in nanoseconds
    306         // isAutoTimestamp - if the timestamp was synthesized at queue time
    307         // dataSpace - description of the contents, interpretation depends on format
    308         // crop - a crop rectangle that's used as a hint to the consumer
    309         // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h>
    310         // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h>
    311         // fence - a fence that the consumer must wait on before reading the buffer,
    312         //         set this to Fence::NO_FENCE if the buffer is ready immediately
    313         // sticky - the sticky transform set in Surface (only used by the LEGACY
    314         //          camera mode).
    315         // getFrameTimestamps - whether or not the latest frame timestamps
    316         //                      should be retrieved from the consumer.
    317         inline QueueBufferInput(int64_t _timestamp, bool _isAutoTimestamp,
    318                 android_dataspace _dataSpace, const Rect& _crop,
    319                 int _scalingMode, uint32_t _transform, const sp<Fence>& _fence,
    320                 uint32_t _sticky = 0, bool _getFrameTimestamps = false)
    321                 : timestamp(_timestamp), isAutoTimestamp(_isAutoTimestamp),
    322                   dataSpace(_dataSpace), crop(_crop), scalingMode(_scalingMode),
    323                   transform(_transform), stickyTransform(_sticky), fence(_fence),
    324                   surfaceDamage(), getFrameTimestamps(_getFrameTimestamps) { }
    325 
    326         inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp,
    327                 android_dataspace* outDataSpace,
    328                 Rect* outCrop, int* outScalingMode,
    329                 uint32_t* outTransform, sp<Fence>* outFence,
    330                 uint32_t* outStickyTransform = nullptr,
    331                 bool* outGetFrameTimestamps = nullptr) const {
    332             *outTimestamp = timestamp;
    333             *outIsAutoTimestamp = bool(isAutoTimestamp);
    334             *outDataSpace = dataSpace;
    335             *outCrop = crop;
    336             *outScalingMode = scalingMode;
    337             *outTransform = transform;
    338             *outFence = fence;
    339             if (outStickyTransform != NULL) {
    340                 *outStickyTransform = stickyTransform;
    341             }
    342             if (outGetFrameTimestamps) {
    343                 *outGetFrameTimestamps = getFrameTimestamps;
    344             }
    345         }
    346 
    347         // Flattenable protocol
    348         static constexpr size_t minFlattenedSize();
    349         size_t getFlattenedSize() const;
    350         size_t getFdCount() const;
    351         status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
    352         status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
    353 
    354         const Region& getSurfaceDamage() const { return surfaceDamage; }
    355         void setSurfaceDamage(const Region& damage) { surfaceDamage = damage; }
    356 
    357     private:
    358         int64_t timestamp{0};
    359         int isAutoTimestamp{0};
    360         android_dataspace dataSpace{HAL_DATASPACE_UNKNOWN};
    361         Rect crop;
    362         int scalingMode{0};
    363         uint32_t transform{0};
    364         uint32_t stickyTransform{0};
    365         sp<Fence> fence;
    366         Region surfaceDamage;
    367         bool getFrameTimestamps{false};
    368     };
    369 
    370     struct QueueBufferOutput : public Flattenable<QueueBufferOutput> {
    371         QueueBufferOutput() = default;
    372 
    373         // Moveable.
    374         QueueBufferOutput(QueueBufferOutput&& src) = default;
    375         QueueBufferOutput& operator=(QueueBufferOutput&& src) = default;
    376         // Not copyable.
    377         QueueBufferOutput(const QueueBufferOutput& src) = delete;
    378         QueueBufferOutput& operator=(const QueueBufferOutput& src) = delete;
    379 
    380         // Flattenable protocol
    381         static constexpr size_t minFlattenedSize();
    382         size_t getFlattenedSize() const;
    383         size_t getFdCount() const;
    384         status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
    385         status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
    386 
    387         uint32_t width{0};
    388         uint32_t height{0};
    389         uint32_t transformHint{0};
    390         uint32_t numPendingBuffers{0};
    391         uint64_t nextFrameNumber{0};
    392         FrameEventHistoryDelta frameTimestamps;
    393         bool bufferReplaced{false};
    394     };
    395 
    396     virtual status_t queueBuffer(int slot, const QueueBufferInput& input,
    397             QueueBufferOutput* output) = 0;
    398 
    399     // cancelBuffer indicates that the client does not wish to fill in the
    400     // buffer associated with slot and transfers ownership of the slot back to
    401     // the server.
    402     //
    403     // The buffer is not queued for use by the consumer.
    404     //
    405     // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
    406     //
    407     // The buffer will not be overwritten until the fence signals.  The fence
    408     // will usually be the one obtained from dequeueBuffer.
    409     //
    410     // Return of a value other than NO_ERROR means an error has occurred:
    411     // * NO_INIT - the buffer queue has been abandoned or the producer is not
    412     //             connected.
    413     // * BAD_VALUE - one of the below conditions occurred:
    414     //              * fence was NULL
    415     //              * slot index was out of range (see above).
    416     //              * the slot was not in the dequeued state
    417     virtual status_t cancelBuffer(int slot, const sp<Fence>& fence) = 0;
    418 
    419     // query retrieves some information for this surface
    420     // 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h>
    421     //
    422     // Return of a value other than NO_ERROR means an error has occurred:
    423     // * NO_INIT - the buffer queue has been abandoned.
    424     // * BAD_VALUE - what was out of range
    425     virtual int query(int what, int* value) = 0;
    426 
    427     // connect attempts to connect a client API to the IGraphicBufferProducer.
    428     // This must be called before any other IGraphicBufferProducer methods are
    429     // called except for getAllocator. A consumer must be already connected.
    430     //
    431     // This method will fail if the connect was previously called on the
    432     // IGraphicBufferProducer and no corresponding disconnect call was made.
    433     //
    434     // The listener is an optional binder callback object that can be used if
    435     // the producer wants to be notified when the consumer releases a buffer
    436     // back to the BufferQueue. It is also used to detect the death of the
    437     // producer. If only the latter functionality is desired, there is a
    438     // DummyProducerListener class in IProducerListener.h that can be used.
    439     //
    440     // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
    441     //
    442     // The producerControlledByApp should be set to true if the producer is hosted
    443     // by an untrusted process (typically app_process-forked processes). If both
    444     // the producer and the consumer are app-controlled then all buffer queues
    445     // will operate in async mode regardless of the async flag.
    446     //
    447     // Upon success, the output will be filled with meaningful data
    448     // (refer to QueueBufferOutput documentation above).
    449     //
    450     // Return of a value other than NO_ERROR means an error has occurred:
    451     // * NO_INIT - one of the following occurred:
    452     //             * the buffer queue was abandoned
    453     //             * no consumer has yet connected
    454     // * BAD_VALUE - one of the following has occurred:
    455     //             * the producer is already connected
    456     //             * api was out of range (see above).
    457     //             * output was NULL.
    458     //             * Failure to adjust the number of available slots. This can
    459     //               happen because of trying to allocate/deallocate the async
    460     //               buffer in response to the value of producerControlledByApp.
    461     // * DEAD_OBJECT - the token is hosted by an already-dead process
    462     //
    463     // Additional negative errors may be returned by the internals, they
    464     // should be treated as opaque fatal unrecoverable errors.
    465     virtual status_t connect(const sp<IProducerListener>& listener,
    466             int api, bool producerControlledByApp, QueueBufferOutput* output) = 0;
    467 
    468     enum class DisconnectMode {
    469         // Disconnect only the specified API.
    470         Api,
    471         // Disconnect any API originally connected from the process calling disconnect.
    472         AllLocal
    473     };
    474 
    475     // disconnect attempts to disconnect a client API from the
    476     // IGraphicBufferProducer.  Calling this method will cause any subsequent
    477     // calls to other IGraphicBufferProducer methods to fail except for
    478     // getAllocator and connect.  Successfully calling connect after this will
    479     // allow the other methods to succeed again.
    480     //
    481     // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
    482     //
    483     // Alternatively if mode is AllLocal, then the API value is ignored, and any API
    484     // connected from the same PID calling disconnect will be disconnected.
    485     //
    486     // Disconnecting from an abandoned IGraphicBufferProducer is legal and
    487     // is considered a no-op.
    488     //
    489     // Return of a value other than NO_ERROR means an error has occurred:
    490     // * NO_INIT - the producer is not connected
    491     // * BAD_VALUE - one of the following has occurred:
    492     //             * the api specified does not match the one that was connected
    493     //             * api was out of range (see above).
    494     // * DEAD_OBJECT - the token is hosted by an already-dead process
    495     virtual status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api) = 0;
    496 
    497     // Attaches a sideband buffer stream to the IGraphicBufferProducer.
    498     //
    499     // A sideband stream is a device-specific mechanism for passing buffers
    500     // from the producer to the consumer without using dequeueBuffer/
    501     // queueBuffer. If a sideband stream is present, the consumer can choose
    502     // whether to acquire buffers from the sideband stream or from the queued
    503     // buffers.
    504     //
    505     // Passing NULL or a different stream handle will detach the previous
    506     // handle if any.
    507     virtual status_t setSidebandStream(const sp<NativeHandle>& stream) = 0;
    508 
    509     // Allocates buffers based on the given dimensions/format.
    510     //
    511     // This function will allocate up to the maximum number of buffers
    512     // permitted by the current BufferQueue configuration. It will use the
    513     // given format, dimensions, and usage bits, which are interpreted in the
    514     // same way as for dequeueBuffer, and the async flag must be set the same
    515     // way as for dequeueBuffer to ensure that the correct number of buffers are
    516     // allocated. This is most useful to avoid an allocation delay during
    517     // dequeueBuffer. If there are already the maximum number of buffers
    518     // allocated, this function has no effect.
    519     virtual void allocateBuffers(uint32_t width, uint32_t height,
    520             PixelFormat format, uint32_t usage) = 0;
    521 
    522     // Sets whether dequeueBuffer is allowed to allocate new buffers.
    523     //
    524     // Normally dequeueBuffer does not discriminate between free slots which
    525     // already have an allocated buffer and those which do not, and will
    526     // allocate a new buffer if the slot doesn't have a buffer or if the slot's
    527     // buffer doesn't match the requested size, format, or usage. This method
    528     // allows the producer to restrict the eligible slots to those which already
    529     // have an allocated buffer of the correct size, format, and usage. If no
    530     // eligible slot is available, dequeueBuffer will block or return an error
    531     // as usual.
    532     virtual status_t allowAllocation(bool allow) = 0;
    533 
    534     // Sets the current generation number of the BufferQueue.
    535     //
    536     // This generation number will be inserted into any buffers allocated by the
    537     // BufferQueue, and any attempts to attach a buffer with a different
    538     // generation number will fail. Buffers already in the queue are not
    539     // affected and will retain their current generation number. The generation
    540     // number defaults to 0.
    541     virtual status_t setGenerationNumber(uint32_t generationNumber) = 0;
    542 
    543     // Returns the name of the connected consumer.
    544     virtual String8 getConsumerName() const = 0;
    545 
    546     // Used to enable/disable shared buffer mode.
    547     //
    548     // When shared buffer mode is enabled the first buffer that is queued or
    549     // dequeued will be cached and returned to all subsequent calls to
    550     // dequeueBuffer and acquireBuffer. This allows the producer and consumer to
    551     // simultaneously access the same buffer.
    552     virtual status_t setSharedBufferMode(bool sharedBufferMode) = 0;
    553 
    554     // Used to enable/disable auto-refresh.
    555     //
    556     // Auto refresh has no effect outside of shared buffer mode. In shared
    557     // buffer mode, when enabled, it indicates to the consumer that it should
    558     // attempt to acquire buffers even if it is not aware of any being
    559     // available.
    560     virtual status_t setAutoRefresh(bool autoRefresh) = 0;
    561 
    562     // Sets how long dequeueBuffer will wait for a buffer to become available
    563     // before returning an error (TIMED_OUT).
    564     //
    565     // This timeout also affects the attachBuffer call, which will block if
    566     // there is not a free slot available into which the attached buffer can be
    567     // placed.
    568     //
    569     // By default, the BufferQueue will wait forever, which is indicated by a
    570     // timeout of -1. If set (to a value other than -1), this will disable
    571     // non-blocking mode and its corresponding spare buffer (which is used to
    572     // ensure a buffer is always available).
    573     //
    574     // Return of a value other than NO_ERROR means an error has occurred:
    575     // * BAD_VALUE - Failure to adjust the number of available slots. This can
    576     //               happen because of trying to allocate/deallocate the async
    577     //               buffer.
    578     virtual status_t setDequeueTimeout(nsecs_t timeout) = 0;
    579 
    580     // Returns the last queued buffer along with a fence which must signal
    581     // before the contents of the buffer are read. If there are no buffers in
    582     // the queue, outBuffer will be populated with nullptr and outFence will be
    583     // populated with Fence::NO_FENCE
    584     //
    585     // outTransformMatrix is not modified if outBuffer is null.
    586     //
    587     // Returns NO_ERROR or the status of the Binder transaction
    588     virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
    589             sp<Fence>* outFence, float outTransformMatrix[16]) = 0;
    590 
    591     // Gets the frame events that haven't already been retrieved.
    592     virtual void getFrameTimestamps(FrameEventHistoryDelta* /*outDelta*/) {}
    593 
    594     // Returns a unique id for this BufferQueue
    595     virtual status_t getUniqueId(uint64_t* outId) const = 0;
    596 };
    597 
    598 // ----------------------------------------------------------------------------
    599 
    600 class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer>
    601 {
    602 public:
    603     virtual status_t    onTransact( uint32_t code,
    604                                     const Parcel& data,
    605                                     Parcel* reply,
    606                                     uint32_t flags = 0);
    607 };
    608 
    609 // ----------------------------------------------------------------------------
    610 }; // namespace android
    611 
    612 #endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
    613