IGraphicBufferProducer.h revision 7ea777f097784492f880623067becac1b276f884
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>
318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisnamespace android {
338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ----------------------------------------------------------------------------
348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
35e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopianclass Surface;
36eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian
370273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden/*
38466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * This class defines the Binder IPC interface for the producer side of
39466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * a queue of graphics buffers.  It's used to send graphics data from one
40466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * component to another.  For example, a class that decodes video for
41466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * playback might use this to provide frames.  This is typically done
42e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian * indirectly, through Surface.
430273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden *
44466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * The underlying mechanism is a BufferQueue, which implements
45466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * BnGraphicBufferProducer.  In normal operation, the producer calls
46466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * dequeueBuffer() to get an empty buffer, fills it with data, then
47466a192d2088f9238d34597d1aa28da41367c1caAndy McFadden * calls queueBuffer() to make it available to the consumer.
480273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden *
492adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden * This class was previously called ISurfaceTexture.
500273adbf0bc202eda2ca579ae0773464ea9c701fAndy McFadden */
512adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenclass IGraphicBufferProducer : public IInterface
528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{
538ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennispublic:
542adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    DECLARE_META_INTERFACE(GraphicBufferProducer);
558ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
568072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    enum {
577d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // A flag returned by dequeueBuffer when the client needs to call
587d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // requestBuffer immediately thereafter.
598072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian        BUFFER_NEEDS_REALLOCATION = 0x1,
607d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // A flag returned by dequeueBuffer when all mirrored slots should be
617d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // released by the client. This flag should always be processed first.
628072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian        RELEASE_ALL_BUFFERS       = 0x2,
638072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian    };
64a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian
658ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // requestBuffer requests a new buffer for the given index. The server (i.e.
662adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // the IGraphicBufferProducer implementation) assigns the newly created
672adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // buffer to the given slot index, and the client is expected to mirror the
688ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // slot->buffer mapping so that it's not necessary to transfer a
698ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // GraphicBuffer for every dequeue operation.
707d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
717d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
727d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
737d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
747d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_INIT - the buffer queue has been abandoned.
757d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the two conditions occurred:
767d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * slot was out of range (see above)
777d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * buffer specified by the slot is not dequeued
787b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis    virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
798ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
808ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // setBufferCount sets the number of buffer slots available. Calling this
818ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // will also cause all buffer slots to be emptied. The caller should empty
828ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // its mirrored copy of the buffer slots when calling this method.
837d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
847d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // This function should not be called when there are any dequeued buffer
857d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // slots, doing so will result in a BAD_VALUE error returned.
867d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
877ea777f097784492f880623067becac1b276f884Igor Murashkin    // The buffer count should be at most NUM_BUFFER_SLOTS (inclusive), but at least
887ea777f097784492f880623067becac1b276f884Igor Murashkin    // the minimum undequeued buffer count (exclusive). The minimum value
897ea777f097784492f880623067becac1b276f884Igor Murashkin    // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS).
907ea777f097784492f880623067becac1b276f884Igor Murashkin    // In particular the range is (minUndequeudBuffers, NUM_BUFFER_SLOTS].
917ea777f097784492f880623067becac1b276f884Igor Murashkin    //
927ea777f097784492f880623067becac1b276f884Igor Murashkin    // The buffer count may also be set to 0 (the default), to indicate that
937ea777f097784492f880623067becac1b276f884Igor Murashkin    // the producer does not wish to set a value.
947d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
957d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
967d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_INIT - the buffer queue has been abandoned.
977d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the below conditions occurred:
987d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * bufferCount was out of range (see above)
997d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * client has one or more buffers dequeued
1008ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    virtual status_t setBufferCount(int bufferCount) = 0;
1018ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
1028ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // dequeueBuffer requests a new buffer slot for the client to use. Ownership
1038ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // of the slot is transfered to the client, meaning that the server will not
1047d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // use the contents of the buffer associated with that slot.
1057d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1067d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The slot index returned may or may not contain a buffer (client-side).
1077d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // If the slot is empty the client should call requestBuffer to assign a new
1087d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // buffer to that slot.
1097d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1107d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Once the client is done filling this buffer, it is expected to transfer
1117d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // buffer ownership back to the server with either cancelBuffer on
1127d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // the dequeued slot or to fill in the contents of its associated buffer
1137d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // contents and call queueBuffer.
1147d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1157d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is
116a5c75c01620179ce00812354778a29a80d76e71fMathias Agopian    // expected to call requestBuffer immediately.
117f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall    //
1187d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is
1197d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // expected to release all of the mirrored slot->buffer mappings.
1207d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
121f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall    // The fence parameter will be updated to hold the fence associated with
122f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall    // the buffer. The contents of the buffer must not be overwritten until the
1237d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // fence signals. If the fence is Fence::NO_FENCE, the buffer may be written
124f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall    // immediately.
1257cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    //
1267d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The async parameter sets whether we're in asynchronous mode for this
1277d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // dequeueBuffer() call.
1287d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1297d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The width and height parameters must be no greater than the minimum of
1307d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
1317d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // An error due to invalid dimensions might not be reported until
1327d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // updateTexImage() is called.  If width and height are both zero, the
1337d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // default values specified by setDefaultBufferSize() are used instead.
1347d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1357d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The pixel formats are enumerated in <graphics.h>, e.g.
1367d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // HAL_PIXEL_FORMAT_RGBA_8888.  If the format is 0, the default format
1377d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // will be used.
1387d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1397d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The usage argument specifies gralloc buffer usage flags.  The values
1407d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER.  These
1417d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // will be merged with the usage flags specified by
1427d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // IGraphicBufferConsumer::setConsumerUsageBits.
1437d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1447d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // This call will block until a buffer is available to be dequeued. If
1457d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // both the producer and consumer are controlled by the app, then this call
1467d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // can never block and will return WOULD_BLOCK if no buffer is available.
1477d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1487d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // A non-negative value with flags set (see above) will be returned upon
1497d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // success.
1507d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1517d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a negative means an error has occurred:
1527d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_INIT - the buffer queue has been abandoned.
1537d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the below conditions occurred:
1547d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * both in async mode and buffer count was less than the
1557d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //                max numbers of buffers that can be allocated at once
1567d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * attempting dequeue more than one buffer at a time
1577d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //                without setting the buffer count with setBufferCount()
1587d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * -EBUSY - attempting to dequeue too many buffers at a time
1597d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * WOULD_BLOCK - no buffer is currently available, and blocking is disabled
1607d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //                 since both the producer/consumer are controlled by app
1617d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_MEMORY - out of memory, cannot allocate the graphics buffer.
1627d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1637d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // All other negative values are an unknown error returned downstream
1647d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // from the graphics allocator (typically errno).
1657d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, bool async,
166f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall            uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0;
1678ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
1688ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // queueBuffer indicates that the client has finished filling in the
1698ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // contents of the buffer associated with slot and transfers ownership of
1707d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // that slot back to the server.
1717d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1727d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // It is not valid to call queueBuffer on a slot that is not owned
1737d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // by the client or one for which a buffer associated via requestBuffer
1747d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // (an attempt to do so will fail with a return value of BAD_VALUE).
1757d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1767d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // In addition, the input must be described by the client (as documented
1777d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // below). Any other properties (zero point, etc)
1781d01a12e7150be569557b64da9b8663c62c13594Eino-Ville Talvala    // are client-dependent, and should be documented by the client.
17997c602c5af5f3ffd69009bf496d86347b71a2b4cMathias Agopian    //
1807d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The slot must be in the range of [0, NUM_BUFFER_SLOTS).
1817d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
1827d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Upon success, the output will be filled with meaningful values
1837d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // (refer to the documentation below).
1847cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian    //
1857d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
1867d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_INIT - the buffer queue has been abandoned.
1877d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the below conditions occurred:
1887d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * fence was NULL
1897d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * scaling mode was unknown
1907d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * both in async mode and buffer count was less than the
1917d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //                max numbers of buffers that can be allocated at once
1927d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * slot index was out of range (see above).
1937d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * the slot was not in the dequeued state
1947d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * the slot was enqueued without requesting a buffer
1957d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //              * crop rect is out of bounds of the buffer dimensions
196f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian
197e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian    struct QueueBufferInput : public Flattenable<QueueBufferInput> {
198e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        friend class Flattenable<QueueBufferInput>;
199c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall        inline QueueBufferInput(const Parcel& parcel);
2007d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // timestamp - a monotonically increasing value in nanoseconds
2017d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // isAutoTimestamp - if the timestamp was synthesized at queue time
2027d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // crop - a crop rectangle that's used as a hint to the consumer
2037d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h>
2047d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h>
2057d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // async - if the buffer is queued in asynchronous mode
2067d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // fence - a fence that the consumer must wait on before reading the buffer,
2077d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        //         set this to Fence::NO_FENCE if the buffer is ready immediately
2083c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden        inline QueueBufferInput(int64_t timestamp, bool isAutoTimestamp,
2097cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian                const Rect& crop, int scalingMode, uint32_t transform, bool async,
2107cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian                const sp<Fence>& fence)
2113c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden        : timestamp(timestamp), isAutoTimestamp(isAutoTimestamp), crop(crop),
2123c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden          scalingMode(scalingMode), transform(transform), async(async),
2133c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden          fence(fence) { }
2143c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden        inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp,
2153c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden                Rect* outCrop, int* outScalingMode, uint32_t* outTransform,
2163c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden                bool* outAsync, sp<Fence>* outFence) const {
217f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outTimestamp = timestamp;
2183c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden            *outIsAutoTimestamp = bool(isAutoTimestamp);
219f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outCrop = crop;
220f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outScalingMode = scalingMode;
221f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outTransform = transform;
2227cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian            *outAsync = bool(async);
223c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall            *outFence = fence;
224f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        }
225c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall
226e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        // Flattenable protocol
227e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        size_t getFlattenedSize() const;
228e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        size_t getFdCount() const;
229e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
230e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian        status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
231c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall
232f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    private:
233f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        int64_t timestamp;
2343c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden        int isAutoTimestamp;
235f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        Rect crop;
236f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        int scalingMode;
237f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        uint32_t transform;
2387cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian        int async;
239c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall        sp<Fence> fence;
240f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    };
241f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian
242f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    // QueueBufferOutput must be a POD structure
2437d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    struct __attribute__ ((__packed__)) QueueBufferOutput {
244f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        inline QueueBufferOutput() { }
2457d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // outWidth - filled with default width applied to the buffer
2467d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // outHeight - filled with default height applied to the buffer
2477d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // outTransformHint - filled with default transform applied to the buffer
2487d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        // outNumPendingBuffers - num buffers queued that haven't yet been acquired
2497d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin        //                        (counting the currently queued buffer)
250f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        inline void deflate(uint32_t* outWidth,
2512488b20aec097accb20a853d9876bb0a5dc04636Mathias Agopian                uint32_t* outHeight,
2522488b20aec097accb20a853d9876bb0a5dc04636Mathias Agopian                uint32_t* outTransformHint,
2532488b20aec097accb20a853d9876bb0a5dc04636Mathias Agopian                uint32_t* outNumPendingBuffers) const {
254f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outWidth = width;
255f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outHeight = height;
256f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            *outTransformHint = transformHint;
2572488b20aec097accb20a853d9876bb0a5dc04636Mathias Agopian            *outNumPendingBuffers = numPendingBuffers;
258f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        }
259f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        inline void inflate(uint32_t inWidth, uint32_t inHeight,
2602488b20aec097accb20a853d9876bb0a5dc04636Mathias Agopian                uint32_t inTransformHint, uint32_t inNumPendingBuffers) {
261f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            width = inWidth;
262f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            height = inHeight;
263f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            transformHint = inTransformHint;
2642488b20aec097accb20a853d9876bb0a5dc04636Mathias Agopian            numPendingBuffers = inNumPendingBuffers;
265f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        }
266f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    private:
267f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        uint32_t width;
268f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        uint32_t height;
269f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian        uint32_t transformHint;
2702488b20aec097accb20a853d9876bb0a5dc04636Mathias Agopian        uint32_t numPendingBuffers;
271f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    };
272f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian
273f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian    virtual status_t queueBuffer(int slot,
274f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian            const QueueBufferInput& input, QueueBufferOutput* output) = 0;
2758ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
2768ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // cancelBuffer indicates that the client does not wish to fill in the
2778ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // buffer associated with slot and transfers ownership of the slot back to
2788ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    // the server.
2797d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
2807d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The buffer is not queued for use by the consumer.
2817d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
2827d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The buffer will not be overwritten until the fence signals.  The fence
2837d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // will usually be the one obtained from dequeueBuffer.
2844c00cc11141da7d159eb2323b186ed344115c0f1Jesse Hall    virtual void cancelBuffer(int slot, const sp<Fence>& fence) = 0;
2858ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
286eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian    // query retrieves some information for this surface
2877d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h>
2887d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
2897d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
2907d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_INIT - the buffer queue has been abandoned.
2917d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - what was out of range
292eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian    virtual int query(int what, int* value) = 0;
2938072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian
2942adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // connect attempts to connect a client API to the IGraphicBufferProducer.
2952adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // This must be called before any other IGraphicBufferProducer methods are
2967d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // called except for getAllocator. A consumer must be already connected.
297fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    //
298fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // This method will fail if the connect was previously called on the
2992adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // IGraphicBufferProducer and no corresponding disconnect call was made.
3005bfc24515bb5c8ea7975f72d538df37753733a2fMathias Agopian    //
3017d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The token needs to be any opaque binder object that lives in the
302365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian    // producer process -- it is solely used for obtaining a death notification
303365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian    // when the producer is killed.
3047d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
3057d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
3067d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
3077d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The producerControlledByApp should be set to true if the producer is hosted
3087d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // by an untrusted process (typically app_process-forked processes). If both
3097d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // the producer and the consumer are app-controlled then all buffer queues
3107d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // will operate in async mode regardless of the async flag.
3117d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
3127d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Upon success, the output will be filled with meaningful data
3137d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // (refer to QueueBufferOutput documentation above).
3147d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
3157d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
3167d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * NO_INIT - one of the following occurred:
3177d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * the buffer queue was abandoned
3187d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * no consumer has yet connected
3197d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the following has occurred:
3207d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * the producer is already connected
3217d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * api was out of range (see above).
3227ea777f097784492f880623067becac1b276f884Igor Murashkin    //             * output was NULL.
3237d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * DEAD_OBJECT - the token is hosted by an already-dead process
3247d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
3257d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Additional negative errors may be returned by the internals, they
3267d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // should be treated as opaque fatal unrecoverable errors.
327365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian    virtual status_t connect(const sp<IBinder>& token,
328365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian            int api, bool producerControlledByApp, QueueBufferOutput* output) = 0;
329fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis
3302adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // disconnect attempts to disconnect a client API from the
3312adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // IGraphicBufferProducer.  Calling this method will cause any subsequent
3322adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // calls to other IGraphicBufferProducer methods to fail except for
3332adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // getAllocator and connect.  Successfully calling connect after this will
3342adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // allow the other methods to succeed again.
335fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    //
3362adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // This method will fail if the the IGraphicBufferProducer is not currently
337fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    // connected to the specified client API.
3387d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
3397d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // The api should be one of the NATIVE_WINDOW_API_* values in <window.h>
3407d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
3417d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Disconnecting from an abandoned IGraphicBufferProducer is legal and
3427d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // is considered a no-op.
3437d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //
3447d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // Return of a value other than NO_ERROR means an error has occurred:
3457d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * BAD_VALUE - one of the following has occurred:
3467d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * the api specified does not match the one that was connected
3477d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    //             * api was out of range (see above).
3487d2d160cdc3cba9f4454f38433c94b68376cb843Igor Murashkin    // * DEAD_OBJECT - the token is hosted by an already-dead process
349fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis    virtual status_t disconnect(int api) = 0;
3508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis};
3518ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
3528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ----------------------------------------------------------------------------
3538ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
3542adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenclass BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer>
3558ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{
3568ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennispublic:
3578ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis    virtual status_t    onTransact( uint32_t code,
3588ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis                                    const Parcel& data,
3598ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis                                    Parcel* reply,
3608ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis                                    uint32_t flags = 0);
3618ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis};
3628ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
3638ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ----------------------------------------------------------------------------
3648ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; // namespace android
3658ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis
3662adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden#endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
367