18ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis/*
28ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Copyright (C) 2010 The Android Open Source Project
38ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *
48ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Licensed under the Apache License, Version 2.0 (the "License");
58ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * you may not use this file except in compliance with the License.
68ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * You may obtain a copy of the License at
78ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *
88ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *      http://www.apache.org/licenses/LICENSE-2.0
98ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *
108ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Unless required by applicable law or agreed to in writing, software
118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * distributed under the License is distributed on an "AS IS" BASIS,
128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * See the License for the specific language governing permissions and
148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * limitations under the License.
158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis */
168ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
172adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden#ifndef ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
182adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden#define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
198ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
208ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <stdint.h>
218ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <sys/types.h>
228ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/Errors.h>
248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/RefBase.h>
258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <binder/IInterface.h>
278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
28f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall#include <ui/Fence.h>
298ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <ui/GraphicBuffer.h>
308ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <ui/Rect.h>
315065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza#include <ui/Region.h>
328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
33ce796e78a57018f186b062199c75d94545318acaPablo Ceballos#include <gui/FrameTimestamps.h>
349bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter#include <gui/HdrMetadata.h>
35ce796e78a57018f186b062199c75d94545318acaPablo Ceballos
366e1193af40c870c50013affec37c8429986b3c7bPawin Vongmasa#include <hidl/HybridInterface.h>
376e1193af40c870c50013affec37c8429986b3c7bPawin Vongmasa#include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h>
386e1193af40c870c50013affec37c8429986b3c7bPawin Vongmasa
398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisnamespace android {
408ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ----------------------------------------------------------------------------
418ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
42f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stozaclass IProducerListener;
43399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hallclass NativeHandle;
44e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianclass Surface;
456e1193af40c870c50013affec37c8429986b3c7bPawin Vongmasatypedef ::android::hardware::graphics::bufferqueue::V1_0::IGraphicBufferProducer
466e1193af40c870c50013affec37c8429986b3c7bPawin Vongmasa        HGraphicBufferProducer;
47eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian
480273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden/*
49466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * This class defines the Binder IPC interface for the producer side of
50466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * a queue of graphics buffers.  It's used to send graphics data from one
51466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * component to another.  For example, a class that decodes video for
52466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * playback might use this to provide frames.  This is typically done
53e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * indirectly, through Surface.
540273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden *
55466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * The underlying mechanism is a BufferQueue, which implements
56466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * BnGraphicBufferProducer.  In normal operation, the producer calls
57466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * dequeueBuffer() to get an empty buffer, fills it with data, then
58466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * calls queueBuffer() to make it available to the consumer.
590273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden *
602adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden * This class was previously called ISurfaceTexture.
610273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden */
622adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenclass IGraphicBufferProducer : public IInterface
638ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{
648ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennispublic:
656e1193af40c870c50013affec37c8429986b3c7bPawin Vongmasa    DECLARE_HYBRID_META_INTERFACE(GraphicBufferProducer, HGraphicBufferProducer)
668ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
678072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    enum {
687d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // A flag returned by dequeueBuffer when the client needs to call
697d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // requestBuffer immediately thereafter.
708072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian        BUFFER_NEEDS_REALLOCATION = 0x1,
717d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // A flag returned by dequeueBuffer when all mirrored slots should be
727d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // released by the client. This flag should always be processed first.
738072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian        RELEASE_ALL_BUFFERS       = 0x2,
748072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    };
75a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian
76c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    enum {
77c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai        // A parcelable magic indicates using Binder BufferQueue as transport
78c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai        // backend.
79c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai        USE_BUFFER_QUEUE = 0x62717565, // 'bque'
80c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai        // A parcelable magic indicates using BufferHub as transport backend.
81c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai        USE_BUFFER_HUB = 0x62687562, // 'bhub'
82c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    };
83c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai
848ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // requestBuffer requests a new buffer for the given index. The server (i.e.
852adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // the IGraphicBufferProducer implementation) assigns the newly created
862adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // buffer to the given slot index, and the client is expected to mirror the
878ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // slot->buffer mapping so that it's not necessary to transfer a
888ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // GraphicBuffer for every dequeue operation.
897d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
907d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
917d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
927d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
93583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned or the producer is not
94583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //             connected.
957d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the two conditions occurred:
967d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * slot was out of range (see above)
977d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * buffer specified by the slot is not dequeued
987b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
998ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
100fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // setMaxDequeuedBufferCount sets the maximum number of buffers that can be
10172daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    // dequeued by the producer at one time. If this method succeeds, any new
10272daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    // buffer slots will be both unallocated and owned by the BufferQueue object
10372daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    // (i.e. they are not owned by the producer or consumer). Calling this may
10472daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    // also cause some buffer slots to be emptied. If the caller is caching the
105fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // contents of the buffer slots, it should empty that cache after calling
106fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // this method.
107fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    //
10872daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    // This function should not be called with a value of maxDequeuedBuffers
10972daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    // that is less than the number of currently dequeued buffer slots. Doing so
11072daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    // will result in a BAD_VALUE error.
111fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    //
112fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // The buffer count should be at least 1 (inclusive), but at most
113fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // (NUM_BUFFER_SLOTS - the minimum undequeued buffer count) (exclusive). The
114fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // minimum undequeued buffer count can be obtained by calling
115fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS).
116fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    //
117fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // Return of a value other than NO_ERROR means an error has occurred:
118fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned.
119fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // * BAD_VALUE - one of the below conditions occurred:
12072daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    //     * bufferCount was out of range (see above).
12172daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    //     * client would have more than the requested number of dequeued
12272daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    //       buffers after this call.
12372daab652e3481566c01ce45c6afdb9fcec6f140Pablo Ceballos    //     * this call would cause the maxBufferCount value to be exceeded.
12423b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //     * failure to adjust the number of available slots.
125fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) = 0;
126fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos
127fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // Set the async flag if the producer intends to asynchronously queue
128fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // buffers without blocking. Typically this is used for triple-buffering
129fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // and/or when the swap interval is set to zero.
130fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    //
131fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // Enabling async mode will internally allocate an additional buffer to
132fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // allow for the asynchronous behavior. If it is not enabled queue/dequeue
133fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // calls may block.
134fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    //
135fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // Return of a value other than NO_ERROR means an error has occurred:
136fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned.
13723b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    // * BAD_VALUE - one of the following has occurred:
13823b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //             * this call would cause the maxBufferCount value to be
139b687a2814ca9db576eb1ea33dea90ac35cd61bc1Pablo Ceballos    //               exceeded
14023b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //             * failure to adjust the number of available slots.
141fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    virtual status_t setAsyncMode(bool async) = 0;
142fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos
1438ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // dequeueBuffer requests a new buffer slot for the client to use. Ownership
1448ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // of the slot is transfered to the client, meaning that the server will not
1457d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // use the contents of the buffer associated with that slot.
1467d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1477d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The slot index returned may or may not contain a buffer (client-side).
1487d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // If the slot is empty the client should call requestBuffer to assign a new
1497d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // buffer to that slot.
1507d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1517d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Once the client is done filling this buffer, it is expected to transfer
1527d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // buffer ownership back to the server with either cancelBuffer on
1537d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // the dequeued slot or to fill in the contents of its associated buffer
1547d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // contents and call queueBuffer.
1557d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1567d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is
157a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // expected to call requestBuffer immediately.
158f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall    //
1597d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is
1607d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // expected to release all of the mirrored slot->buffer mappings.
1617d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
162f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall    // The fence parameter will be updated to hold the fence associated with
163f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall    // the buffer. The contents of the buffer must not be overwritten until the
1647d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // fence signals. If the fence is Fence::NO_FENCE, the buffer may be written
165f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall    // immediately.
1667cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    //
1677d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The width and height parameters must be no greater than the minimum of
1687d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
1697d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // An error due to invalid dimensions might not be reported until
1707d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // updateTexImage() is called.  If width and height are both zero, the
1717d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // default values specified by setDefaultBufferSize() are used instead.
1727d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1733be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // If the format is 0, the default format will be used.
1747d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1757d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The usage argument specifies gralloc buffer usage flags.  The values
1767d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER.  These
1777d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // will be merged with the usage flags specified by
1787d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // IGraphicBufferConsumer::setConsumerUsageBits.
1797d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1807d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // This call will block until a buffer is available to be dequeued. If
1817d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // both the producer and consumer are controlled by the app, then this call
1827d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // can never block and will return WOULD_BLOCK if no buffer is available.
1837d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1847d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // A non-negative value with flags set (see above) will be returned upon
1857d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // success.
1867d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1877d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a negative means an error has occurred:
188583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned or the producer is not
189583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //             connected.
1909f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // * BAD_VALUE - both in async mode and buffer count was less than the
1919f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //               max numbers of buffers that can be allocated at once.
1929f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // * INVALID_OPERATION - cannot attach the buffer because it would cause
1939f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       too many buffers to be dequeued, either because
1949f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       the producer already has a single buffer dequeued
1959f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       and did not set a buffer count, or because a
1969f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       buffer count was set and this call would cause
1979f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       it to be exceeded.
1987d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * WOULD_BLOCK - no buffer is currently available, and blocking is disabled
1997d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //                 since both the producer/consumer are controlled by app
2007d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_MEMORY - out of memory, cannot allocate the graphics buffer.
201127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while
202127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    //               waiting for a buffer to become available.
2037d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
2047d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // All other negative values are an unknown error returned downstream
2057d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // from the graphics allocator (typically errno).
206a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott    virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h,
207a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott                                   PixelFormat format, uint64_t usage, uint64_t* outBufferAge,
208a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8Ian Elliott                                   FrameEventHistoryDelta* outTimestamps) = 0;
2098ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2109f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // detachBuffer attempts to remove all ownership of the buffer in the given
2119f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // slot from the buffer queue. If this call succeeds, the slot will be
2129f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // freed, and there will be no way to obtain the buffer from this interface.
2139f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // The freed slot will remain unallocated until either it is selected to
2149f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // hold a freshly allocated buffer in dequeueBuffer or a buffer is attached
2159f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // to the slot. The buffer must have already been dequeued, and the caller
2169f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // must already possesses the sp<GraphicBuffer> (i.e., must have called
2179f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // requestBuffer).
2189f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //
2199f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // Return of a value other than NO_ERROR means an error has occurred:
220583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned or the producer is not
221583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //             connected.
2229f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // * BAD_VALUE - the given slot number is invalid, either because it is
2239f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //               out of the range [0, NUM_BUFFER_SLOTS), or because the slot
2249f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //               it refers to is not currently dequeued and requested.
2259f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    virtual status_t detachBuffer(int slot) = 0;
2269f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza
227d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // detachNextBuffer is equivalent to calling dequeueBuffer, requestBuffer,
228d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // and detachBuffer in sequence, except for two things:
229d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    //
230d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // 1) It is unnecessary to know the dimensions, format, or usage of the
231d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    //    next buffer.
232d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // 2) It will not block, since if it cannot find an appropriate buffer to
233d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    //    return, it will return an error instead.
234d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    //
235d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // Only slots that are free but still contain a GraphicBuffer will be
236d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // considered, and the oldest of those will be returned. outBuffer is
237d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // equivalent to outBuffer from the requestBuffer call, and outFence is
238d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // equivalent to fence from the dequeueBuffer call.
239d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    //
240d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // Return of a value other than NO_ERROR means an error has occurred:
241583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned or the producer is not
242583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //             connected.
243d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // * BAD_VALUE - either outBuffer or outFence were NULL.
244d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // * NO_MEMORY - no slots were found that were both free and contained a
245d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    //               GraphicBuffer.
246d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
247d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza            sp<Fence>* outFence) = 0;
248d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza
2499f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // attachBuffer attempts to transfer ownership of a buffer to the buffer
2509f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // queue. If this call succeeds, it will be as if this buffer was dequeued
2519f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // from the returned slot number. As such, this call will fail if attaching
2529f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // this buffer would cause too many buffers to be simultaneously dequeued.
2539f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //
2549f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // If attachBuffer returns the RELEASE_ALL_BUFFERS flag, the caller is
2559f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // expected to release all of the mirrored slot->buffer mappings.
2569f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //
2579f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // A non-negative value with flags set (see above) will be returned upon
2589f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // success.
2599f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //
2609f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // Return of a negative value means an error has occurred:
261583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned or the producer is not
262583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //             connected.
263812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // * BAD_VALUE - outSlot or buffer were NULL, invalid combination of
264812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    //               async mode and buffer count override, or the generation
265812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    //               number of the buffer did not match the buffer queue.
2669f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // * INVALID_OPERATION - cannot attach the buffer because it would cause
2679f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       too many buffers to be dequeued, either because
2689f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       the producer already has a single buffer dequeued
2699f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       and did not set a buffer count, or because a
2709f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       buffer count was set and this call would cause
2719f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                       it to be exceeded.
2729f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // * WOULD_BLOCK - no buffer slot is currently available, and blocking is
2739f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                 disabled since both the producer/consumer are
2749f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    //                 controlled by the app.
275127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while
276127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    //               waiting for a slot to become available.
2779f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    virtual status_t attachBuffer(int* outSlot,
2789f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza            const sp<GraphicBuffer>& buffer) = 0;
2799f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza
2808ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // queueBuffer indicates that the client has finished filling in the
2818ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // contents of the buffer associated with slot and transfers ownership of
2827d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // that slot back to the server.
2837d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
2847d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // It is not valid to call queueBuffer on a slot that is not owned
2857d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // by the client or one for which a buffer associated via requestBuffer
2867d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // (an attempt to do so will fail with a return value of BAD_VALUE).
2877d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
2887d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // In addition, the input must be described by the client (as documented
2897d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // below). Any other properties (zero point, etc)
2901d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // are client-dependent, and should be documented by the client.
29197c602c5af5f3ffd69009bf496d86347b71a2b4cMathias Agopian    //
2927d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
2937d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
2947d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Upon success, the output will be filled with meaningful values
2957d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // (refer to the documentation below).
2967cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    //
2977d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
298583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned or the producer is not
299583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //             connected.
3007d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the below conditions occurred:
3017d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * fence was NULL
3027d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * scaling mode was unknown
3037d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * both in async mode and buffer count was less than the
3047d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //                max numbers of buffers that can be allocated at once
3057d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * slot index was out of range (see above).
3067d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * the slot was not in the dequeued state
3077d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * the slot was enqueued without requesting a buffer
3087d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * crop rect is out of bounds of the buffer dimensions
309f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian
310e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian    struct QueueBufferInput : public Flattenable<QueueBufferInput> {
311e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        friend class Flattenable<QueueBufferInput>;
31265d4787875544af168de512d3172777595ab59f7Chih-Hung Hsieh        explicit inline QueueBufferInput(const Parcel& parcel);
313baaad32cd582bcc09db89135715717234ea398eaBrian Anderson
3147d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // timestamp - a monotonically increasing value in nanoseconds
3157d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // isAutoTimestamp - if the timestamp was synthesized at queue time
31682c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala        // dataSpace - description of the contents, interpretation depends on format
3177d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // crop - a crop rectangle that's used as a hint to the consumer
3187d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h>
3197d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h>
3207d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // fence - a fence that the consumer must wait on before reading the buffer,
3217d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        //         set this to Fence::NO_FENCE if the buffer is ready immediately
3221681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk        // sticky - the sticky transform set in Surface (only used by the LEGACY
3231681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk        //          camera mode).
3247c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson        // getFrameTimestamps - whether or not the latest frame timestamps
3257c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson        //                      should be retrieved from the consumer.
326382ecd3d6345aeeda158a8d94cc0aee1bd3a45dcColin Cross        inline QueueBufferInput(int64_t _timestamp, bool _isAutoTimestamp,
327382ecd3d6345aeeda158a8d94cc0aee1bd3a45dcColin Cross                android_dataspace _dataSpace, const Rect& _crop,
328382ecd3d6345aeeda158a8d94cc0aee1bd3a45dcColin Cross                int _scalingMode, uint32_t _transform, const sp<Fence>& _fence,
3297c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson                uint32_t _sticky = 0, bool _getFrameTimestamps = false)
330382ecd3d6345aeeda158a8d94cc0aee1bd3a45dcColin Cross                : timestamp(_timestamp), isAutoTimestamp(_isAutoTimestamp),
331382ecd3d6345aeeda158a8d94cc0aee1bd3a45dcColin Cross                  dataSpace(_dataSpace), crop(_crop), scalingMode(_scalingMode),
332382ecd3d6345aeeda158a8d94cc0aee1bd3a45dcColin Cross                  transform(_transform), stickyTransform(_sticky), fence(_fence),
3337c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson                  surfaceDamage(), getFrameTimestamps(_getFrameTimestamps) { }
334baaad32cd582bcc09db89135715717234ea398eaBrian Anderson
3353c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden        inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp,
33682c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala                android_dataspace* outDataSpace,
33782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala                Rect* outCrop, int* outScalingMode,
338567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos                uint32_t* outTransform, sp<Fence>* outFence,
3397c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson                uint32_t* outStickyTransform = nullptr,
3407c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson                bool* outGetFrameTimestamps = nullptr) const {
341f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outTimestamp = timestamp;
3423c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden            *outIsAutoTimestamp = bool(isAutoTimestamp);
34382c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala            *outDataSpace = dataSpace;
344f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outCrop = crop;
345f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outScalingMode = scalingMode;
346f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outTransform = transform;
347c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall            *outFence = fence;
3481681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk            if (outStickyTransform != NULL) {
3491681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk                *outStickyTransform = stickyTransform;
3501681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk            }
3517c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson            if (outGetFrameTimestamps) {
3527c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson                *outGetFrameTimestamps = getFrameTimestamps;
3537c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson            }
354f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        }
355c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall
356e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        // Flattenable protocol
3577c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson        static constexpr size_t minFlattenedSize();
358e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        size_t getFlattenedSize() const;
359e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        size_t getFdCount() const;
360e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
361e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
362c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall
3635065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza        const Region& getSurfaceDamage() const { return surfaceDamage; }
3645065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza        void setSurfaceDamage(const Region& damage) { surfaceDamage = damage; }
3655065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza
3669bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter        const HdrMetadata& getHdrMetadata() const { return hdrMetadata; }
3679bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter        void setHdrMetadata(const HdrMetadata& metadata) { hdrMetadata = metadata; }
3689bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter
369f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    private:
370bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        int64_t timestamp{0};
371bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        int isAutoTimestamp{0};
372bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        android_dataspace dataSpace{HAL_DATASPACE_UNKNOWN};
373f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        Rect crop;
374bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        int scalingMode{0};
375bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        uint32_t transform{0};
376bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        uint32_t stickyTransform{0};
377c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall        sp<Fence> fence;
3785065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza        Region surfaceDamage;
3797c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson        bool getFrameTimestamps{false};
3809bad0d7e726e6b264c528a3dd13d0c58fd92c0e1Courtney Goeltzenleuchter        HdrMetadata hdrMetadata;
381f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    };
382f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian
383baaad32cd582bcc09db89135715717234ea398eaBrian Anderson    struct QueueBufferOutput : public Flattenable<QueueBufferOutput> {
3843d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson        QueueBufferOutput() = default;
3853d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson
3863d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson        // Moveable.
3873d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson        QueueBufferOutput(QueueBufferOutput&& src) = default;
3883d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson        QueueBufferOutput& operator=(QueueBufferOutput&& src) = default;
3893d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson        // Not copyable.
3903d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson        QueueBufferOutput(const QueueBufferOutput& src) = delete;
3913d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson        QueueBufferOutput& operator=(const QueueBufferOutput& src) = delete;
3923d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson
393baaad32cd582bcc09db89135715717234ea398eaBrian Anderson        // Flattenable protocol
3947c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson        static constexpr size_t minFlattenedSize();
395baaad32cd582bcc09db89135715717234ea398eaBrian Anderson        size_t getFlattenedSize() const;
396baaad32cd582bcc09db89135715717234ea398eaBrian Anderson        size_t getFdCount() const;
397baaad32cd582bcc09db89135715717234ea398eaBrian Anderson        status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
398baaad32cd582bcc09db89135715717234ea398eaBrian Anderson        status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
399baaad32cd582bcc09db89135715717234ea398eaBrian Anderson
400bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        uint32_t width{0};
401bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        uint32_t height{0};
402bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        uint32_t transformHint{0};
403bd3577ef5bae7d65e54bddc04f90b619330edb89Pablo Ceballos        uint32_t numPendingBuffers{0};
404bc8c1928e1dbdaf6a2820f6e426c96ed61284043Pablo Ceballos        uint64_t nextFrameNumber{0};
4057c3ba8aa288755fad78ddbabcee0ad5a0610ac1cBrian Anderson        FrameEventHistoryDelta frameTimestamps;
40622f842ba04c32cef2faf855dc304eb0ab131b9ecShuzhen Wang        bool bufferReplaced{false};
407f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    };
408f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian
409567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos    virtual status_t queueBuffer(int slot, const QueueBufferInput& input,
410567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos            QueueBufferOutput* output) = 0;
4118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
4128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // cancelBuffer indicates that the client does not wish to fill in the
4138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // buffer associated with slot and transfers ownership of the slot back to
4148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // the server.
4157d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
4167d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The buffer is not queued for use by the consumer.
4177d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
418583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
419583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //
4207d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The buffer will not be overwritten until the fence signals.  The fence
4217d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // will usually be the one obtained from dequeueBuffer.
422583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //
423583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // Return of a value other than NO_ERROR means an error has occurred:
424583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // * NO_INIT - the buffer queue has been abandoned or the producer is not
425583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //             connected.
426583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    // * BAD_VALUE - one of the below conditions occurred:
427583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //              * fence was NULL
428583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //              * slot index was out of range (see above).
429583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    //              * the slot was not in the dequeued state
430583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    virtual status_t cancelBuffer(int slot, const sp<Fence>& fence) = 0;
4318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
432eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian    // query retrieves some information for this surface
4337d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h>
4347d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
4357d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
4367d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_INIT - the buffer queue has been abandoned.
4377d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - what was out of range
438eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian    virtual int query(int what, int* value) = 0;
4398072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian
4402adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // connect attempts to connect a client API to the IGraphicBufferProducer.
4412adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // This must be called before any other IGraphicBufferProducer methods are
4427d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // called except for getAllocator. A consumer must be already connected.
443fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    //
444fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // This method will fail if the connect was previously called on the
4452adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // IGraphicBufferProducer and no corresponding disconnect call was made.
4465bfc24515bb5c8ea7975f72d538df37753733a2fMathias Agopian    //
447f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza    // The listener is an optional binder callback object that can be used if
448f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza    // the producer wants to be notified when the consumer releases a buffer
449f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza    // back to the BufferQueue. It is also used to detect the death of the
450f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza    // producer. If only the latter functionality is desired, there is a
451f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza    // DummyProducerListener class in IProducerListener.h that can be used.
4527d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
4537d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
4547d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
4557d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The producerControlledByApp should be set to true if the producer is hosted
4567d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // by an untrusted process (typically app_process-forked processes). If both
4577d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // the producer and the consumer are app-controlled then all buffer queues
4587d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // will operate in async mode regardless of the async flag.
4597d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
4607d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Upon success, the output will be filled with meaningful data
4617d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // (refer to QueueBufferOutput documentation above).
4627d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
4637d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
4647d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_INIT - one of the following occurred:
4657d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * the buffer queue was abandoned
4667d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * no consumer has yet connected
4677d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the following has occurred:
4687d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * the producer is already connected
4697d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * api was out of range (see above).
4707ea777f097784492f880623067becac1b276f884Igor Murashkin    //             * output was NULL.
47123b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //             * Failure to adjust the number of available slots. This can
47223b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //               happen because of trying to allocate/deallocate the async
47323b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //               buffer in response to the value of producerControlledByApp.
4747d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * DEAD_OBJECT - the token is hosted by an already-dead process
4757d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
4767d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Additional negative errors may be returned by the internals, they
4777d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // should be treated as opaque fatal unrecoverable errors.
478f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza    virtual status_t connect(const sp<IProducerListener>& listener,
479365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian            int api, bool producerControlledByApp, QueueBufferOutput* output) = 0;
480fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis
48197b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    enum class DisconnectMode {
48297b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr        // Disconnect only the specified API.
48397b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr        Api,
48497b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr        // Disconnect any API originally connected from the process calling disconnect.
48597b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr        AllLocal
48697b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    };
48797b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr
4882adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // disconnect attempts to disconnect a client API from the
4892adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // IGraphicBufferProducer.  Calling this method will cause any subsequent
4902adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // calls to other IGraphicBufferProducer methods to fail except for
4912adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // getAllocator and connect.  Successfully calling connect after this will
4922adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // allow the other methods to succeed again.
493fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    //
4947d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
4957d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
49697b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    // Alternatively if mode is AllLocal, then the API value is ignored, and any API
49797b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    // connected from the same PID calling disconnect will be disconnected.
49897b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    //
4997d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Disconnecting from an abandoned IGraphicBufferProducer is legal and
5007d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // is considered a no-op.
5017d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
5027d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
5033e198b2b331c09e8d078b5cd4cb770bcf049c0d1Wonsik Kim    // * NO_INIT - the producer is not connected
5047d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the following has occurred:
5057d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * the api specified does not match the one that was connected
5067d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * api was out of range (see above).
5077d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * DEAD_OBJECT - the token is hosted by an already-dead process
50897b9c86338e2d364d47ea7522c2d81a8014f0e07Robert Carr    virtual status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api) = 0;
509399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall
510399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // Attaches a sideband buffer stream to the IGraphicBufferProducer.
511399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    //
512399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // A sideband stream is a device-specific mechanism for passing buffers
513399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // from the producer to the consumer without using dequeueBuffer/
514399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // queueBuffer. If a sideband stream is present, the consumer can choose
515399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // whether to acquire buffers from the sideband stream or from the queued
516399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // buffers.
517399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    //
518399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // Passing NULL or a different stream handle will detach the previous
519399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // handle if any.
520399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    virtual status_t setSidebandStream(const sp<NativeHandle>& stream) = 0;
52129a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza
52229a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // Allocates buffers based on the given dimensions/format.
52329a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    //
52429a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // This function will allocate up to the maximum number of buffers
52529a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // permitted by the current BufferQueue configuration. It will use the
52629a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // given format, dimensions, and usage bits, which are interpreted in the
52729a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // same way as for dequeueBuffer, and the async flag must be set the same
52829a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // way as for dequeueBuffer to ensure that the correct number of buffers are
52929a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // allocated. This is most useful to avoid an allocation delay during
53029a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // dequeueBuffer. If there are already the maximum number of buffers
53129a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // allocated, this function has no effect.
532567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos    virtual void allocateBuffers(uint32_t width, uint32_t height,
533cb496acbe593326e8d5d563847067d02b2df40ecMathias Agopian            PixelFormat format, uint64_t usage) = 0;
5349de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza
5359de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // Sets whether dequeueBuffer is allowed to allocate new buffers.
5369de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    //
5379de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // Normally dequeueBuffer does not discriminate between free slots which
5389de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // already have an allocated buffer and those which do not, and will
5399de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // allocate a new buffer if the slot doesn't have a buffer or if the slot's
5409de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // buffer doesn't match the requested size, format, or usage. This method
5419de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // allows the producer to restrict the eligible slots to those which already
5429de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // have an allocated buffer of the correct size, format, and usage. If no
5439de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // eligible slot is available, dequeueBuffer will block or return an error
5449de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // as usual.
5459de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    virtual status_t allowAllocation(bool allow) = 0;
546812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza
547812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // Sets the current generation number of the BufferQueue.
548812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    //
549812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // This generation number will be inserted into any buffers allocated by the
550812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // BufferQueue, and any attempts to attach a buffer with a different
551812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // generation number will fail. Buffers already in the queue are not
552812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // affected and will retain their current generation number. The generation
553812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // number defaults to 0.
554812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    virtual status_t setGenerationNumber(uint32_t generationNumber) = 0;
555c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza
556c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza    // Returns the name of the connected consumer.
557c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza    virtual String8 getConsumerName() const = 0;
5587dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza
5593559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    // Used to enable/disable shared buffer mode.
560ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    //
5613559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    // When shared buffer mode is enabled the first buffer that is queued or
562295a9fc8aa87daa2cded5c1a279b8cd24e9a9a9fPablo Ceballos    // dequeued will be cached and returned to all subsequent calls to
563295a9fc8aa87daa2cded5c1a279b8cd24e9a9a9fPablo Ceballos    // dequeueBuffer and acquireBuffer. This allows the producer and consumer to
564295a9fc8aa87daa2cded5c1a279b8cd24e9a9a9fPablo Ceballos    // simultaneously access the same buffer.
5653559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    virtual status_t setSharedBufferMode(bool sharedBufferMode) = 0;
566127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza
567ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // Used to enable/disable auto-refresh.
568ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    //
5693559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    // Auto refresh has no effect outside of shared buffer mode. In shared
570ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // buffer mode, when enabled, it indicates to the consumer that it should
571ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // attempt to acquire buffers even if it is not aware of any being
572ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    // available.
573ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos    virtual status_t setAutoRefresh(bool autoRefresh) = 0;
574ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos
575127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // Sets how long dequeueBuffer will wait for a buffer to become available
576127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // before returning an error (TIMED_OUT).
577127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    //
578127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // This timeout also affects the attachBuffer call, which will block if
579127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // there is not a free slot available into which the attached buffer can be
580127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // placed.
581127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    //
582127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // By default, the BufferQueue will wait forever, which is indicated by a
583127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // timeout of -1. If set (to a value other than -1), this will disable
584127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // non-blocking mode and its corresponding spare buffer (which is used to
585127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // ensure a buffer is always available).
58623b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //
58723b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    // Return of a value other than NO_ERROR means an error has occurred:
58823b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    // * BAD_VALUE - Failure to adjust the number of available slots. This can
58923b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //               happen because of trying to allocate/deallocate the async
59023b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    //               buffer.
591127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    virtual status_t setDequeueTimeout(nsecs_t timeout) = 0;
59250101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza
59350101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    // Returns the last queued buffer along with a fence which must signal
59450101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    // before the contents of the buffer are read. If there are no buffers in
59550101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    // the queue, outBuffer will be populated with nullptr and outFence will be
59650101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    // populated with Fence::NO_FENCE
59750101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    //
5981a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck    // outTransformMatrix is not modified if outBuffer is null.
5991a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck    //
60050101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    // Returns NO_ERROR or the status of the Binder transaction
60150101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza    virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
6021a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck            sp<Fence>* outFence, float outTransformMatrix[16]) = 0;
603ce796e78a57018f186b062199c75d94545318acaPablo Ceballos
6043890c3995c4a52439844faeb80b5503d42b977d8Brian Anderson    // Gets the frame events that haven't already been retrieved.
6053890c3995c4a52439844faeb80b5503d42b977d8Brian Anderson    virtual void getFrameTimestamps(FrameEventHistoryDelta* /*outDelta*/) {}
6060ade247d4b02b81f323480b4ba043927f6b36a73Pablo Ceballos
6078e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos    // Returns a unique id for this BufferQueue
6088e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos    virtual status_t getUniqueId(uint64_t* outId) const = 0;
609e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu
610e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    // Returns the consumer usage flags for this BufferQueue. This returns the
611e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    // full 64-bit usage flags, rather than the truncated 32-bit usage flags
612e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    // returned by querying the now deprecated
613e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    // NATIVE_WINDOW_CONSUMER_USAGE_BITS attribute.
614e2786ea5aec3a12d948feb85ffbb535fc89c0fe6Chia-I Wu    virtual status_t getConsumerUsage(uint64_t* outUsage) const = 0;
615c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai
616c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // Static method exports any IGraphicBufferProducer object to a parcel. It
617c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // handles null producer as well.
618c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    static status_t exportToParcel(const sp<IGraphicBufferProducer>& producer,
619c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai                                   Parcel* parcel);
620c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai
621c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // Factory method that creates a new IBGP instance from the parcel.
622c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    static sp<IGraphicBufferProducer> createFromParcel(const Parcel* parcel);
623c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai
624c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Caiprotected:
625c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // Exports the current producer as a binder parcelable object. Note that the
626c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // producer must be disconnected to be exportable. After successful export,
627c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // the producer queue can no longer be connected again. Returns NO_ERROR
628c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // when the export is successful and writes an implementation defined
629c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // parcelable object into the parcel. For traditional Android BufferQueue,
630c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // it writes a strong binder object; for BufferHub, it writes a
631c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    // ProducerQueueParcelable object.
632c90a77f1e5b42d8fcf336d2b9bd2259280814df2Jiwen 'Steve' Cai    virtual status_t exportToParcel(Parcel* parcel);
6338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis};
6348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
6358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ----------------------------------------------------------------------------
6368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
6372adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenclass BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer>
6388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{
6398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennispublic:
6408ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    virtual status_t    onTransact( uint32_t code,
6418ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis                                    const Parcel& data,
6428ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis                                    Parcel* reply,
6438ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis                                    uint32_t flags = 0);
6448ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis};
6458ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
6468ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ----------------------------------------------------------------------------
6478ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; // namespace android
6488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
6492adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden#endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
650