BufferQueueProducer.h revision 127fc63e8a15366b4395f1363e8e18eb058d1709
1289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza/*
2289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Copyright 2014 The Android Open Source Project
3289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
4289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Licensed under the Apache License, Version 2.0 (the "License");
5289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * you may not use this file except in compliance with the License.
6289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * You may obtain a copy of the License at
7289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
8289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *      http://www.apache.org/licenses/LICENSE-2.0
9289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
10289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Unless required by applicable law or agreed to in writing, software
11289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * distributed under the License is distributed on an "AS IS" BASIS,
12289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * See the License for the specific language governing permissions and
14289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * limitations under the License.
15289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza */
16289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
17289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#ifndef ANDROID_GUI_BUFFERQUEUEPRODUCER_H
18289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define ANDROID_GUI_BUFFERQUEUEPRODUCER_H
19289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
203e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza#include <gui/BufferQueueDefs.h>
21289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <gui/IGraphicBufferProducer.h>
22289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
23289ade165e60b5f71734d30e535f16eb1f4313adDan Stozanamespace android {
24289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
25289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass BufferSlot;
26289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
27289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass BufferQueueProducer : public BnGraphicBufferProducer,
28289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza                            private IBinder::DeathRecipient {
29289ade165e60b5f71734d30e535f16eb1f4313adDan Stozapublic:
303e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    friend class BufferQueue; // Needed to access binderDied
313e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
32289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    BufferQueueProducer(const sp<BufferQueueCore>& core);
33289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    virtual ~BufferQueueProducer();
34289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
35289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // requestBuffer returns the GraphicBuffer for slot N.
36289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
37289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // In normal operation, this is called the first time slot N is returned
38289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // by dequeueBuffer.  It must be called again if dequeueBuffer returns
39289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // flags indicating that previously-returned buffers are no longer valid.
40289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
41289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
42fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // see IGraphicsBufferProducer::setMaxDequeuedBufferCount
43fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers);
44fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos
45fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    // see IGraphicsBufferProducer::setAsyncMode
46fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos    virtual status_t setAsyncMode(bool async);
47fa455354557f6283ff3a7d76979e52fd251c155fPablo Ceballos
48289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // dequeueBuffer gets the next buffer slot index for the producer to use.
49289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // If a buffer slot is available then that slot index is written to the
50289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // location pointed to by the buf argument and a status of OK is returned.
51289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // If no slot is available then a status of -EBUSY is returned and buf is
52289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // unmodified.
53289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
54289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // The outFence parameter will be updated to hold the fence associated with
55289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // the buffer. The contents of the buffer must not be overwritten until the
56289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // fence signals. If the fence is Fence::NO_FENCE, the buffer may be
57289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // written immediately.
58289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
59289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // The width and height parameters must be no greater than the minimum of
60289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
61289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // An error due to invalid dimensions might not be reported until
62289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // updateTexImage() is called.  If width and height are both zero, the
63289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // default values specified by setDefaultBufferSize() are used instead.
64289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
653be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    // If the format is 0, the default format will be used.
66289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
67289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // The usage argument specifies gralloc buffer usage flags.  The values
68289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER.  These
69289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // will be merged with the usage flags specified by setConsumerUsageBits.
70289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
71289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // The return value may be a negative error value or a non-negative
72289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // collection of flags.  If the flags are set, the return values are
73289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // valid, but additional actions must be performed.
74289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
75289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the
76289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // producer must discard cached GraphicBuffer references for the slot
77289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // returned in buf.
78289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer
79289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // must discard cached GraphicBuffer references for all slots.
80289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
81289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // In both cases, the producer will need to call requestBuffer to get a
82289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // GraphicBuffer handle for the returned slot.
833be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza    virtual status_t dequeueBuffer(int *outSlot, sp<Fence>* outFence,
84567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos            uint32_t width, uint32_t height, PixelFormat format,
853be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza            uint32_t usage);
86289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
879f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // See IGraphicBufferProducer::detachBuffer
889f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    virtual status_t detachBuffer(int slot);
899f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza
90d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    // See IGraphicBufferProducer::detachNextBuffer
91d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza    virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
92d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza            sp<Fence>* outFence);
93d9822a3843017444364899afc3c23fb5be6b9cb9Dan Stoza
949f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // See IGraphicBufferProducer::attachBuffer
959f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    virtual status_t attachBuffer(int* outSlot, const sp<GraphicBuffer>& buffer);
969f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza
97289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // queueBuffer returns a filled buffer to the BufferQueue.
98289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
99289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // Additional data is provided in the QueueBufferInput struct.  Notably,
100289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // a timestamp must be provided for the buffer. The timestamp is in
101289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // nanoseconds, and must be monotonically increasing. Its other semantics
102289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // (zero point, etc) are producer-specific and should be documented by the
103289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // producer.
104289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
105289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // The caller may provide a fence that signals when all rendering
106289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // operations have completed.  Alternatively, NO_FENCE may be used,
107289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // indicating that the buffer is ready immediately.
108289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
109289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // Some values are returned in the output struct: the current settings
110289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // for default width and height, the current transform hint, and the
111289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // number of queued buffers.
112289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    virtual status_t queueBuffer(int slot,
113289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza            const QueueBufferInput& input, QueueBufferOutput* output);
114289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
115289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // cancelBuffer returns a dequeued buffer to the BufferQueue, but doesn't
116289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // queue it for use by the consumer.
117289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
118289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // The buffer will not be overwritten until the fence signals.  The fence
119289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // will usually be the one obtained from dequeueBuffer.
120583b1b32191992d6ada58b3c61c71932a71c0c4bPablo Ceballos    virtual status_t cancelBuffer(int slot, const sp<Fence>& fence);
121289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
122289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // Query native window attributes.  The "what" values are enumerated in
123289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // window.h (e.g. NATIVE_WINDOW_FORMAT).
124289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    virtual int query(int what, int* outValue);
125289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
126289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // connect attempts to connect a producer API to the BufferQueue.  This
127289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // must be called before any other IGraphicBufferProducer methods are
128289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // called except for getAllocator.  A consumer must already be connected.
129289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
130289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // This method will fail if connect was previously called on the
131289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // BufferQueue and no corresponding disconnect call was made (i.e. if
132289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // it's still connected to a producer).
133289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
134289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU).
135f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza    virtual status_t connect(const sp<IProducerListener>& listener,
136289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza            int api, bool producerControlledByApp, QueueBufferOutput* output);
137289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
138289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // disconnect attempts to disconnect a producer API from the BufferQueue.
139289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // Calling this method will cause any subsequent calls to other
140289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // IGraphicBufferProducer methods to fail except for getAllocator and connect.
141289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // Successfully calling connect after this will allow the other methods to
142289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // succeed again.
143289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    //
144289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // This method will fail if the the BufferQueue is not currently
145289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // connected to the specified producer API.
146289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    virtual status_t disconnect(int api);
147289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
148399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // Attaches a sideband buffer stream to the IGraphicBufferProducer.
149399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    //
150399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // A sideband stream is a device-specific mechanism for passing buffers
151399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // from the producer to the consumer without using dequeueBuffer/
152399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // queueBuffer. If a sideband stream is present, the consumer can choose
153399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // whether to acquire buffers from the sideband stream or from the queued
154399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // buffers.
155399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    //
156399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // Passing NULL or a different stream handle will detach the previous
157399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // handle if any.
158399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    virtual status_t setSidebandStream(const sp<NativeHandle>& stream);
159399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall
16029a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza    // See IGraphicBufferProducer::allocateBuffers
161567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos    virtual void allocateBuffers(uint32_t width, uint32_t height,
1623be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza            PixelFormat format, uint32_t usage);
16329a3e90879fd96404c971e7187cd0e05927bbce0Dan Stoza
1649de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    // See IGraphicBufferProducer::allowAllocation
1659de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza    virtual status_t allowAllocation(bool allow);
1669de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza
167812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    // See IGraphicBufferProducer::setGenerationNumber
168812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza    virtual status_t setGenerationNumber(uint32_t generationNumber);
169812ed0644f8f8f71ca403f4e5793f0dbc1fcf9b2Dan Stoza
170c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza    // See IGraphicBufferProducer::getConsumerName
171c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza    virtual String8 getConsumerName() const override;
172c6f30bdee1f634eb90d68cb76efe935b6535a1e8Dan Stoza
1737dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza    // See IGraphicBufferProducer::getNextFrameNumber
1747dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza    virtual uint64_t getNextFrameNumber() const override;
1757dde599bf1a0dbef7390d91c2689d506371cdbd7Dan Stoza
176ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // See IGraphicBufferProducer::setSingleBufferMode
177127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    virtual status_t setSingleBufferMode(bool singleBufferMode) override;
178127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza
179127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // See IGraphicBufferProducer::setDequeueTimeout
180127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    virtual status_t setDequeueTimeout(nsecs_t timeout) override;
181ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
182289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaprivate:
183289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // This is required by the IBinder::DeathRecipient interface
184289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    virtual void binderDied(const wp<IBinder>& who);
185289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
1869f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // waitForFreeSlotThenRelock finds the oldest slot in the FREE state. It may
1879f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // block if there are no available slots and we are not in non-blocking
1889f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // mode (producer and consumer controlled by the application). If it blocks,
1899f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // it will release mCore->mMutex while blocked so that other operations on
1909f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza    // the BufferQueue may succeed.
191567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos    status_t waitForFreeSlotThenRelock(const char* caller, int* found,
192567dbbb6dd42be5013fcde0dadb3316d85f2fa0dPablo Ceballos            status_t* returnFlags) const;
1939f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza
194289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    sp<BufferQueueCore> mCore;
1953e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1963e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // This references mCore->mSlots. Lock mCore->mMutex while accessing.
1973e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    BufferQueueDefs::SlotsType& mSlots;
198289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
199289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // This is a cached copy of the name stored in the BufferQueueCore.
200289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // It's updated during connect and dequeueBuffer (which should catch
201289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // most updates).
202289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    String8 mConsumerName;
203289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
2041681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk    uint32_t mStickyTransform;
2051681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk
20699a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner    // This saves the fence from the last queueBuffer, such that the
20799a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner    // next queueBuffer call can throttle buffer production. The prior
20899a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner    // queueBuffer's fence is not nessessarily available elsewhere,
20999a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner    // since the previous buffer might have already been acquired.
21099a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner    sp<Fence> mLastQueueBufferFence;
21199a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner
2128dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    // Take-a-ticket system for ensuring that onFrame* callbacks are called in
2138dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    // the order that frames are queued. While the BufferQueue lock
2148dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    // (mCore->mMutex) is held, a ticket is retained by the producer. After
2158dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    // dropping the BufferQueue lock, the producer must wait on the condition
2168dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    // variable until the current callback ticket matches its retained ticket.
2178dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    Mutex mCallbackMutex;
2188dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    int mNextCallbackTicket; // Protected by mCore->mMutex
2198dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    int mCurrentCallbackTicket; // Protected by mCallbackMutex
2208dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    Condition mCallbackCondition;
2218dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza
222127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // Sets how long dequeueBuffer or attachBuffer will block if a buffer or
223127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    // slot is not yet available.
224127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza    nsecs_t mDequeueTimeout;
225127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza
226289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza}; // class BufferQueueProducer
227289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
228289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza} // namespace android
229289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
230289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#endif
231