1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_GUI_BUFFERQUEUEPRODUCER_H 18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_GUI_BUFFERQUEUEPRODUCER_H 19*38e8c45fSAndroid Build Coastguard Worker 20*38e8c45fSAndroid Build Coastguard Worker #include <gui/AdditionalOptions.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <gui/BufferQueueDefs.h> 22*38e8c45fSAndroid Build Coastguard Worker 23*38e8c45fSAndroid Build Coastguard Worker #include <gui/IGraphicBufferProducer.h> 24*38e8c45fSAndroid Build Coastguard Worker 25*38e8c45fSAndroid Build Coastguard Worker namespace android { 26*38e8c45fSAndroid Build Coastguard Worker 27*38e8c45fSAndroid Build Coastguard Worker class IBinder; 28*38e8c45fSAndroid Build Coastguard Worker struct BufferSlot; 29*38e8c45fSAndroid Build Coastguard Worker 30*38e8c45fSAndroid Build Coastguard Worker #ifndef NO_BINDER 31*38e8c45fSAndroid Build Coastguard Worker class BufferQueueProducer : public BnGraphicBufferProducer, 32*38e8c45fSAndroid Build Coastguard Worker private IBinder::DeathRecipient { 33*38e8c45fSAndroid Build Coastguard Worker #else 34*38e8c45fSAndroid Build Coastguard Worker class BufferQueueProducer : public BnGraphicBufferProducer { 35*38e8c45fSAndroid Build Coastguard Worker #endif 36*38e8c45fSAndroid Build Coastguard Worker public: 37*38e8c45fSAndroid Build Coastguard Worker friend class BufferQueue; // Needed to access binderDied 38*38e8c45fSAndroid Build Coastguard Worker 39*38e8c45fSAndroid Build Coastguard Worker explicit BufferQueueProducer(const sp<BufferQueueCore>& core, 40*38e8c45fSAndroid Build Coastguard Worker bool consumerIsSurfaceFlinger = false); 41*38e8c45fSAndroid Build Coastguard Worker ~BufferQueueProducer() override; 42*38e8c45fSAndroid Build Coastguard Worker 43*38e8c45fSAndroid Build Coastguard Worker // requestBuffer returns the GraphicBuffer for slot N. 44*38e8c45fSAndroid Build Coastguard Worker // 45*38e8c45fSAndroid Build Coastguard Worker // In normal operation, this is called the first time slot N is returned 46*38e8c45fSAndroid Build Coastguard Worker // by dequeueBuffer. It must be called again if dequeueBuffer returns 47*38e8c45fSAndroid Build Coastguard Worker // flags indicating that previously-returned buffers are no longer valid. 48*38e8c45fSAndroid Build Coastguard Worker virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf); 49*38e8c45fSAndroid Build Coastguard Worker 50*38e8c45fSAndroid Build Coastguard Worker // see IGraphicsBufferProducer::setMaxDequeuedBufferCount 51*38e8c45fSAndroid Build Coastguard Worker virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers); 52*38e8c45fSAndroid Build Coastguard Worker 53*38e8c45fSAndroid Build Coastguard Worker // see IGraphicsBufferProducer::setAsyncMode 54*38e8c45fSAndroid Build Coastguard Worker virtual status_t setAsyncMode(bool async); 55*38e8c45fSAndroid Build Coastguard Worker 56*38e8c45fSAndroid Build Coastguard Worker // dequeueBuffer gets the next buffer slot index for the producer to use. 57*38e8c45fSAndroid Build Coastguard Worker // If a buffer slot is available then that slot index is written to the 58*38e8c45fSAndroid Build Coastguard Worker // location pointed to by the buf argument and a status of OK is returned. 59*38e8c45fSAndroid Build Coastguard Worker // If no slot is available then a status of -EBUSY is returned and buf is 60*38e8c45fSAndroid Build Coastguard Worker // unmodified. 61*38e8c45fSAndroid Build Coastguard Worker // 62*38e8c45fSAndroid Build Coastguard Worker // The outFence parameter will be updated to hold the fence associated with 63*38e8c45fSAndroid Build Coastguard Worker // the buffer. The contents of the buffer must not be overwritten until the 64*38e8c45fSAndroid Build Coastguard Worker // fence signals. If the fence is Fence::NO_FENCE, the buffer may be 65*38e8c45fSAndroid Build Coastguard Worker // written immediately. 66*38e8c45fSAndroid Build Coastguard Worker // 67*38e8c45fSAndroid Build Coastguard Worker // The width and height parameters must be no greater than the minimum of 68*38e8c45fSAndroid Build Coastguard Worker // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). 69*38e8c45fSAndroid Build Coastguard Worker // An error due to invalid dimensions might not be reported until 70*38e8c45fSAndroid Build Coastguard Worker // updateTexImage() is called. If width and height are both zero, the 71*38e8c45fSAndroid Build Coastguard Worker // default values specified by setDefaultBufferSize() are used instead. 72*38e8c45fSAndroid Build Coastguard Worker // 73*38e8c45fSAndroid Build Coastguard Worker // If the format is 0, the default format will be used. 74*38e8c45fSAndroid Build Coastguard Worker // 75*38e8c45fSAndroid Build Coastguard Worker // The usage argument specifies gralloc buffer usage flags. The values 76*38e8c45fSAndroid Build Coastguard Worker // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These 77*38e8c45fSAndroid Build Coastguard Worker // will be merged with the usage flags specified by setConsumerUsageBits. 78*38e8c45fSAndroid Build Coastguard Worker // 79*38e8c45fSAndroid Build Coastguard Worker // The return value may be a negative error value or a non-negative 80*38e8c45fSAndroid Build Coastguard Worker // collection of flags. If the flags are set, the return values are 81*38e8c45fSAndroid Build Coastguard Worker // valid, but additional actions must be performed. 82*38e8c45fSAndroid Build Coastguard Worker // 83*38e8c45fSAndroid Build Coastguard Worker // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the 84*38e8c45fSAndroid Build Coastguard Worker // producer must discard cached GraphicBuffer references for the slot 85*38e8c45fSAndroid Build Coastguard Worker // returned in buf. 86*38e8c45fSAndroid Build Coastguard Worker // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer 87*38e8c45fSAndroid Build Coastguard Worker // must discard cached GraphicBuffer references for all slots. 88*38e8c45fSAndroid Build Coastguard Worker // 89*38e8c45fSAndroid Build Coastguard Worker // In both cases, the producer will need to call requestBuffer to get a 90*38e8c45fSAndroid Build Coastguard Worker // GraphicBuffer handle for the returned slot. 91*38e8c45fSAndroid Build Coastguard Worker virtual status_t dequeueBuffer(int* outSlot, sp<Fence>* outFence, uint32_t width, 92*38e8c45fSAndroid Build Coastguard Worker uint32_t height, PixelFormat format, uint64_t usage, 93*38e8c45fSAndroid Build Coastguard Worker uint64_t* outBufferAge, 94*38e8c45fSAndroid Build Coastguard Worker FrameEventHistoryDelta* outTimestamps) override; 95*38e8c45fSAndroid Build Coastguard Worker 96*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::detachBuffer 97*38e8c45fSAndroid Build Coastguard Worker virtual status_t detachBuffer(int slot); 98*38e8c45fSAndroid Build Coastguard Worker 99*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::detachNextBuffer 100*38e8c45fSAndroid Build Coastguard Worker virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, 101*38e8c45fSAndroid Build Coastguard Worker sp<Fence>* outFence); 102*38e8c45fSAndroid Build Coastguard Worker 103*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::attachBuffer 104*38e8c45fSAndroid Build Coastguard Worker virtual status_t attachBuffer(int* outSlot, const sp<GraphicBuffer>& buffer); 105*38e8c45fSAndroid Build Coastguard Worker 106*38e8c45fSAndroid Build Coastguard Worker // queueBuffer returns a filled buffer to the BufferQueue. 107*38e8c45fSAndroid Build Coastguard Worker // 108*38e8c45fSAndroid Build Coastguard Worker // Additional data is provided in the QueueBufferInput struct. Notably, 109*38e8c45fSAndroid Build Coastguard Worker // a timestamp must be provided for the buffer. The timestamp is in 110*38e8c45fSAndroid Build Coastguard Worker // nanoseconds, and must be monotonically increasing. Its other semantics 111*38e8c45fSAndroid Build Coastguard Worker // (zero point, etc) are producer-specific and should be documented by the 112*38e8c45fSAndroid Build Coastguard Worker // producer. 113*38e8c45fSAndroid Build Coastguard Worker // 114*38e8c45fSAndroid Build Coastguard Worker // The caller may provide a fence that signals when all rendering 115*38e8c45fSAndroid Build Coastguard Worker // operations have completed. Alternatively, NO_FENCE may be used, 116*38e8c45fSAndroid Build Coastguard Worker // indicating that the buffer is ready immediately. 117*38e8c45fSAndroid Build Coastguard Worker // 118*38e8c45fSAndroid Build Coastguard Worker // Some values are returned in the output struct: the current settings 119*38e8c45fSAndroid Build Coastguard Worker // for default width and height, the current transform hint, and the 120*38e8c45fSAndroid Build Coastguard Worker // number of queued buffers. 121*38e8c45fSAndroid Build Coastguard Worker virtual status_t queueBuffer(int slot, 122*38e8c45fSAndroid Build Coastguard Worker const QueueBufferInput& input, QueueBufferOutput* output); 123*38e8c45fSAndroid Build Coastguard Worker 124*38e8c45fSAndroid Build Coastguard Worker // cancelBuffer returns a dequeued buffer to the BufferQueue, but doesn't 125*38e8c45fSAndroid Build Coastguard Worker // queue it for use by the consumer. 126*38e8c45fSAndroid Build Coastguard Worker // 127*38e8c45fSAndroid Build Coastguard Worker // The buffer will not be overwritten until the fence signals. The fence 128*38e8c45fSAndroid Build Coastguard Worker // will usually be the one obtained from dequeueBuffer. 129*38e8c45fSAndroid Build Coastguard Worker virtual status_t cancelBuffer(int slot, const sp<Fence>& fence); 130*38e8c45fSAndroid Build Coastguard Worker 131*38e8c45fSAndroid Build Coastguard Worker // Query native window attributes. The "what" values are enumerated in 132*38e8c45fSAndroid Build Coastguard Worker // window.h (e.g. NATIVE_WINDOW_FORMAT). 133*38e8c45fSAndroid Build Coastguard Worker virtual int query(int what, int* outValue); 134*38e8c45fSAndroid Build Coastguard Worker 135*38e8c45fSAndroid Build Coastguard Worker // connect attempts to connect a producer API to the BufferQueue. This 136*38e8c45fSAndroid Build Coastguard Worker // must be called before any other IGraphicBufferProducer methods are 137*38e8c45fSAndroid Build Coastguard Worker // called except for getAllocator. A consumer must already be connected. 138*38e8c45fSAndroid Build Coastguard Worker // 139*38e8c45fSAndroid Build Coastguard Worker // This method will fail if connect was previously called on the 140*38e8c45fSAndroid Build Coastguard Worker // BufferQueue and no corresponding disconnect call was made (i.e. if 141*38e8c45fSAndroid Build Coastguard Worker // it's still connected to a producer). 142*38e8c45fSAndroid Build Coastguard Worker // 143*38e8c45fSAndroid Build Coastguard Worker // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU). 144*38e8c45fSAndroid Build Coastguard Worker virtual status_t connect(const sp<IProducerListener>& listener, 145*38e8c45fSAndroid Build Coastguard Worker int api, bool producerControlledByApp, QueueBufferOutput* output); 146*38e8c45fSAndroid Build Coastguard Worker 147*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::disconnect 148*38e8c45fSAndroid Build Coastguard Worker virtual status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api); 149*38e8c45fSAndroid Build Coastguard Worker 150*38e8c45fSAndroid Build Coastguard Worker // Attaches a sideband buffer stream to the IGraphicBufferProducer. 151*38e8c45fSAndroid Build Coastguard Worker // 152*38e8c45fSAndroid Build Coastguard Worker // A sideband stream is a device-specific mechanism for passing buffers 153*38e8c45fSAndroid Build Coastguard Worker // from the producer to the consumer without using dequeueBuffer/ 154*38e8c45fSAndroid Build Coastguard Worker // queueBuffer. If a sideband stream is present, the consumer can choose 155*38e8c45fSAndroid Build Coastguard Worker // whether to acquire buffers from the sideband stream or from the queued 156*38e8c45fSAndroid Build Coastguard Worker // buffers. 157*38e8c45fSAndroid Build Coastguard Worker // 158*38e8c45fSAndroid Build Coastguard Worker // Passing NULL or a different stream handle will detach the previous 159*38e8c45fSAndroid Build Coastguard Worker // handle if any. 160*38e8c45fSAndroid Build Coastguard Worker virtual status_t setSidebandStream(const sp<NativeHandle>& stream); 161*38e8c45fSAndroid Build Coastguard Worker 162*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::allocateBuffers 163*38e8c45fSAndroid Build Coastguard Worker virtual void allocateBuffers(uint32_t width, uint32_t height, 164*38e8c45fSAndroid Build Coastguard Worker PixelFormat format, uint64_t usage) override; 165*38e8c45fSAndroid Build Coastguard Worker 166*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::allowAllocation 167*38e8c45fSAndroid Build Coastguard Worker virtual status_t allowAllocation(bool allow); 168*38e8c45fSAndroid Build Coastguard Worker 169*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::setGenerationNumber 170*38e8c45fSAndroid Build Coastguard Worker virtual status_t setGenerationNumber(uint32_t generationNumber); 171*38e8c45fSAndroid Build Coastguard Worker 172*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::getConsumerName 173*38e8c45fSAndroid Build Coastguard Worker virtual String8 getConsumerName() const override; 174*38e8c45fSAndroid Build Coastguard Worker 175*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::setSharedBufferMode 176*38e8c45fSAndroid Build Coastguard Worker virtual status_t setSharedBufferMode(bool sharedBufferMode) override; 177*38e8c45fSAndroid Build Coastguard Worker 178*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::setAutoRefresh 179*38e8c45fSAndroid Build Coastguard Worker virtual status_t setAutoRefresh(bool autoRefresh) override; 180*38e8c45fSAndroid Build Coastguard Worker 181*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::setDequeueTimeout 182*38e8c45fSAndroid Build Coastguard Worker virtual status_t setDequeueTimeout(nsecs_t timeout) override; 183*38e8c45fSAndroid Build Coastguard Worker 184*38e8c45fSAndroid Build Coastguard Worker // see IGraphicBufferProducer::setLegacyBufferDrop 185*38e8c45fSAndroid Build Coastguard Worker virtual status_t setLegacyBufferDrop(bool drop); 186*38e8c45fSAndroid Build Coastguard Worker 187*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::getLastQueuedBuffer 188*38e8c45fSAndroid Build Coastguard Worker virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, 189*38e8c45fSAndroid Build Coastguard Worker sp<Fence>* outFence, float outTransformMatrix[16]) override; 190*38e8c45fSAndroid Build Coastguard Worker 191*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::getLastQueuedBuffer 192*38e8c45fSAndroid Build Coastguard Worker virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence, 193*38e8c45fSAndroid Build Coastguard Worker Rect* outRect, uint32_t* outTransform) override; 194*38e8c45fSAndroid Build Coastguard Worker 195*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::getFrameTimestamps 196*38e8c45fSAndroid Build Coastguard Worker virtual void getFrameTimestamps(FrameEventHistoryDelta* outDelta) override; 197*38e8c45fSAndroid Build Coastguard Worker 198*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::getUniqueId 199*38e8c45fSAndroid Build Coastguard Worker virtual status_t getUniqueId(uint64_t* outId) const override; 200*38e8c45fSAndroid Build Coastguard Worker 201*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::getConsumerUsage 202*38e8c45fSAndroid Build Coastguard Worker virtual status_t getConsumerUsage(uint64_t* outUsage) const override; 203*38e8c45fSAndroid Build Coastguard Worker 204*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::setAutoPrerotation 205*38e8c45fSAndroid Build Coastguard Worker virtual status_t setAutoPrerotation(bool autoPrerotation); 206*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) 207*38e8c45fSAndroid Build Coastguard Worker // See IGraphicBufferProducer::setFrameRate 208*38e8c45fSAndroid Build Coastguard Worker status_t setFrameRate(float frameRate, int8_t compatibility, 209*38e8c45fSAndroid Build Coastguard Worker int8_t changeFrameRateStrategy) override; 210*38e8c45fSAndroid Build Coastguard Worker #endif 211*38e8c45fSAndroid Build Coastguard Worker 212*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) 213*38e8c45fSAndroid Build Coastguard Worker status_t setAdditionalOptions(const std::vector<gui::AdditionalOptions>& options) override; 214*38e8c45fSAndroid Build Coastguard Worker #endif 215*38e8c45fSAndroid Build Coastguard Worker 216*38e8c45fSAndroid Build Coastguard Worker protected: 217*38e8c45fSAndroid Build Coastguard Worker // see IGraphicsBufferProducer::setMaxDequeuedBufferCount, but with the ability to retrieve the 218*38e8c45fSAndroid Build Coastguard Worker // total maximum buffer count for the buffer queue (dequeued AND acquired) 219*38e8c45fSAndroid Build Coastguard Worker status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers, int* maxBufferCount); 220*38e8c45fSAndroid Build Coastguard Worker 221*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL) 222*38e8c45fSAndroid Build Coastguard Worker // Wait until a buffer has been released. The method may spuriously return OK when no buffer has 223*38e8c45fSAndroid Build Coastguard Worker // been released. The BufferQueue mutex is passed in the locked state. It must be unlocked 224*38e8c45fSAndroid Build Coastguard Worker // before waiting for a release and locked before returning. 225*38e8c45fSAndroid Build Coastguard Worker virtual status_t waitForBufferRelease(std::unique_lock<std::mutex>& lock, 226*38e8c45fSAndroid Build Coastguard Worker nsecs_t timeout) const; 227*38e8c45fSAndroid Build Coastguard Worker #endif 228*38e8c45fSAndroid Build Coastguard Worker 229*38e8c45fSAndroid Build Coastguard Worker private: 230*38e8c45fSAndroid Build Coastguard Worker // This is required by the IBinder::DeathRecipient interface 231*38e8c45fSAndroid Build Coastguard Worker virtual void binderDied(const wp<IBinder>& who); 232*38e8c45fSAndroid Build Coastguard Worker 233*38e8c45fSAndroid Build Coastguard Worker // Returns the slot of the next free buffer if one is available or 234*38e8c45fSAndroid Build Coastguard Worker // BufferQueueCore::INVALID_BUFFER_SLOT otherwise 235*38e8c45fSAndroid Build Coastguard Worker int getFreeBufferLocked() const; 236*38e8c45fSAndroid Build Coastguard Worker 237*38e8c45fSAndroid Build Coastguard Worker // Returns the next free slot if one is available or 238*38e8c45fSAndroid Build Coastguard Worker // BufferQueueCore::INVALID_BUFFER_SLOT otherwise 239*38e8c45fSAndroid Build Coastguard Worker int getFreeSlotLocked() const; 240*38e8c45fSAndroid Build Coastguard Worker 241*38e8c45fSAndroid Build Coastguard Worker void addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, 242*38e8c45fSAndroid Build Coastguard Worker FrameEventHistoryDelta* outDelta); 243*38e8c45fSAndroid Build Coastguard Worker 244*38e8c45fSAndroid Build Coastguard Worker // waitForFreeSlotThenRelock finds the oldest slot in the FREE state. It may 245*38e8c45fSAndroid Build Coastguard Worker // block if there are no available slots and we are not in non-blocking 246*38e8c45fSAndroid Build Coastguard Worker // mode (producer and consumer controlled by the application). If it blocks, 247*38e8c45fSAndroid Build Coastguard Worker // it will release mCore->mMutex while blocked so that other operations on 248*38e8c45fSAndroid Build Coastguard Worker // the BufferQueue may succeed. 249*38e8c45fSAndroid Build Coastguard Worker enum class FreeSlotCaller { 250*38e8c45fSAndroid Build Coastguard Worker Dequeue, 251*38e8c45fSAndroid Build Coastguard Worker Attach, 252*38e8c45fSAndroid Build Coastguard Worker }; 253*38e8c45fSAndroid Build Coastguard Worker status_t waitForFreeSlotThenRelock(FreeSlotCaller caller, std::unique_lock<std::mutex>& lock, 254*38e8c45fSAndroid Build Coastguard Worker int* found) const; 255*38e8c45fSAndroid Build Coastguard Worker 256*38e8c45fSAndroid Build Coastguard Worker sp<BufferQueueCore> mCore; 257*38e8c45fSAndroid Build Coastguard Worker 258*38e8c45fSAndroid Build Coastguard Worker // This references mCore->mSlots. Lock mCore->mMutex while accessing. 259*38e8c45fSAndroid Build Coastguard Worker BufferQueueDefs::SlotsType& mSlots; 260*38e8c45fSAndroid Build Coastguard Worker 261*38e8c45fSAndroid Build Coastguard Worker // This is a cached copy of the name stored in the BufferQueueCore. 262*38e8c45fSAndroid Build Coastguard Worker // It's updated during connect and dequeueBuffer (which should catch 263*38e8c45fSAndroid Build Coastguard Worker // most updates). 264*38e8c45fSAndroid Build Coastguard Worker String8 mConsumerName; 265*38e8c45fSAndroid Build Coastguard Worker 266*38e8c45fSAndroid Build Coastguard Worker uint32_t mStickyTransform; 267*38e8c45fSAndroid Build Coastguard Worker 268*38e8c45fSAndroid Build Coastguard Worker // This controls whether the GraphicBuffer pointer in the BufferItem is 269*38e8c45fSAndroid Build Coastguard Worker // cleared after being queued 270*38e8c45fSAndroid Build Coastguard Worker bool mConsumerIsSurfaceFlinger; 271*38e8c45fSAndroid Build Coastguard Worker 272*38e8c45fSAndroid Build Coastguard Worker // This saves the fence from the last queueBuffer, such that the 273*38e8c45fSAndroid Build Coastguard Worker // next queueBuffer call can throttle buffer production. The prior 274*38e8c45fSAndroid Build Coastguard Worker // queueBuffer's fence is not nessessarily available elsewhere, 275*38e8c45fSAndroid Build Coastguard Worker // since the previous buffer might have already been acquired. 276*38e8c45fSAndroid Build Coastguard Worker sp<Fence> mLastQueueBufferFence; 277*38e8c45fSAndroid Build Coastguard Worker 278*38e8c45fSAndroid Build Coastguard Worker Rect mLastQueuedCrop; 279*38e8c45fSAndroid Build Coastguard Worker uint32_t mLastQueuedTransform; 280*38e8c45fSAndroid Build Coastguard Worker 281*38e8c45fSAndroid Build Coastguard Worker // Take-a-ticket system for ensuring that onFrame* callbacks are called in 282*38e8c45fSAndroid Build Coastguard Worker // the order that frames are queued. While the BufferQueue lock 283*38e8c45fSAndroid Build Coastguard Worker // (mCore->mMutex) is held, a ticket is retained by the producer. After 284*38e8c45fSAndroid Build Coastguard Worker // dropping the BufferQueue lock, the producer must wait on the condition 285*38e8c45fSAndroid Build Coastguard Worker // variable until the current callback ticket matches its retained ticket. 286*38e8c45fSAndroid Build Coastguard Worker std::mutex mCallbackMutex; 287*38e8c45fSAndroid Build Coastguard Worker int mNextCallbackTicket; // Protected by mCore->mMutex 288*38e8c45fSAndroid Build Coastguard Worker int mCurrentCallbackTicket; // Protected by mCallbackMutex 289*38e8c45fSAndroid Build Coastguard Worker std::condition_variable mCallbackCondition; 290*38e8c45fSAndroid Build Coastguard Worker 291*38e8c45fSAndroid Build Coastguard Worker // Sets how long dequeueBuffer or attachBuffer will block if a buffer or 292*38e8c45fSAndroid Build Coastguard Worker // slot is not yet available. 293*38e8c45fSAndroid Build Coastguard Worker nsecs_t mDequeueTimeout; 294*38e8c45fSAndroid Build Coastguard Worker 295*38e8c45fSAndroid Build Coastguard Worker // If set to true, dequeueBuffer() is currently waiting for buffer allocation to complete. 296*38e8c45fSAndroid Build Coastguard Worker bool mDequeueWaitingForAllocation; 297*38e8c45fSAndroid Build Coastguard Worker 298*38e8c45fSAndroid Build Coastguard Worker // Condition variable to signal allocateBuffers() that dequeueBuffer() is no longer waiting for 299*38e8c45fSAndroid Build Coastguard Worker // allocation to complete. 300*38e8c45fSAndroid Build Coastguard Worker std::condition_variable mDequeueWaitingForAllocationCondition; 301*38e8c45fSAndroid Build Coastguard Worker 302*38e8c45fSAndroid Build Coastguard Worker }; // class BufferQueueProducer 303*38e8c45fSAndroid Build Coastguard Worker 304*38e8c45fSAndroid Build Coastguard Worker } // namespace android 305*38e8c45fSAndroid Build Coastguard Worker 306*38e8c45fSAndroid Build Coastguard Worker #endif 307