BufferQueueProducer.h revision 8e3e92b906db431c4fa822f21242977d4ee99942
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 1763559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos // See IGraphicBufferProducer::setSharedBufferMode 1773559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos virtual status_t setSharedBufferMode(bool sharedBufferMode) override; 178127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza 179ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos // See IGraphicBufferProducer::setAutoRefresh 180ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos virtual status_t setAutoRefresh(bool autoRefresh) override; 181ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos 182127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza // See IGraphicBufferProducer::setDequeueTimeout 183127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza virtual status_t setDequeueTimeout(nsecs_t timeout) override; 184ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos 18550101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza // See IGraphicBufferProducer::getLastQueuedBuffer 18650101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, 1871a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck sp<Fence>* outFence, float outTransformMatrix[16]) override; 18850101d02a8eae555887282a5f761fdec57bdaf30Dan Stoza 1898e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos // See IGraphicBufferProducer::getUniqueId 1908e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos virtual status_t getUniqueId(uint64_t* outId) const override; 1918e3e92b906db431c4fa822f21242977d4ee99942Pablo Ceballos 192289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaprivate: 193289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // This is required by the IBinder::DeathRecipient interface 194289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza virtual void binderDied(const wp<IBinder>& who); 195289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 1965ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza // Returns the slot of the next free buffer if one is available or 1975ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza // BufferQueueCore::INVALID_BUFFER_SLOT otherwise 1985ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza int getFreeBufferLocked() const; 1995ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza 20023b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos // Returns the next free slot if one is available or 20123b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos // BufferQueueCore::INVALID_BUFFER_SLOT otherwise 20223b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos int getFreeSlotLocked() const; 2035ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza 2049f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza // waitForFreeSlotThenRelock finds the oldest slot in the FREE state. It may 2059f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza // block if there are no available slots and we are not in non-blocking 2069f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza // mode (producer and consumer controlled by the application). If it blocks, 2079f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza // it will release mCore->mMutex while blocked so that other operations on 2089f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza // the BufferQueue may succeed. 2095ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza enum class FreeSlotCaller { 2105ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza Dequeue, 2115ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza Attach, 2125ecfb68ffd63d352df0392dca6e95ef67a66c679Dan Stoza }; 21323b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos status_t waitForFreeSlotThenRelock(FreeSlotCaller caller, int* found) const; 2149f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza 215289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza sp<BufferQueueCore> mCore; 2163e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2173e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // This references mCore->mSlots. Lock mCore->mMutex while accessing. 2183e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza BufferQueueDefs::SlotsType& mSlots; 219289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 220289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // This is a cached copy of the name stored in the BufferQueueCore. 221289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // It's updated during connect and dequeueBuffer (which should catch 222289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // most updates). 223289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza String8 mConsumerName; 224289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 2251681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk uint32_t mStickyTransform; 2261681d95989271f3a9ac0dbb93d10e4a29f2b4444Ruben Brunk 22799a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner // This saves the fence from the last queueBuffer, such that the 22899a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner // next queueBuffer call can throttle buffer production. The prior 22999a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner // queueBuffer's fence is not nessessarily available elsewhere, 23099a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner // since the previous buffer might have already been acquired. 23199a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner sp<Fence> mLastQueueBufferFence; 23299a0afbaee9eddabc2b544e3a5c432901c1d498cEric Penner 2331a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck Rect mLastQueuedCrop; 2341a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck uint32_t mLastQueuedTransform; 2351a61da5e28fa16ad556a58193c8bbeb32a5f636dJohn Reck 2368dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // Take-a-ticket system for ensuring that onFrame* callbacks are called in 2378dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // the order that frames are queued. While the BufferQueue lock 2388dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // (mCore->mMutex) is held, a ticket is retained by the producer. After 2398dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // dropping the BufferQueue lock, the producer must wait on the condition 2408dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // variable until the current callback ticket matches its retained ticket. 2418dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza Mutex mCallbackMutex; 2428dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza int mNextCallbackTicket; // Protected by mCore->mMutex 2438dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza int mCurrentCallbackTicket; // Protected by mCallbackMutex 2448dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza Condition mCallbackCondition; 2458dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza 246127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza // Sets how long dequeueBuffer or attachBuffer will block if a buffer or 247127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza // slot is not yet available. 248127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza nsecs_t mDequeueTimeout; 249127fc63e8a15366b4395f1363e8e18eb058d1709Dan Stoza 250289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza}; // class BufferQueueProducer 251289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 252289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza} // namespace android 253289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 254289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#endif 255