11a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis/*
21a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * Copyright (C) 2010 The Android Open Source Project
31a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis *
41a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * Licensed under the Apache License, Version 2.0 (the "License");
51a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * you may not use this file except in compliance with the License.
61a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * You may obtain a copy of the License at
71a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis *
81a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis *      http://www.apache.org/licenses/LICENSE-2.0
91a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis *
101a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * Unless required by applicable law or agreed to in writing, software
111a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * distributed under the License is distributed on an "AS IS" BASIS,
121a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * See the License for the specific language governing permissions and
141a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis * limitations under the License.
151a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis */
161a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
171a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis#ifndef ANDROID_GUI_CONSUMERBASE_H
181a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis#define ANDROID_GUI_CONSUMERBASE_H
191a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
20a9347647eca3101c014be902b713772de3977d87Mathias Agopian#include <gui/BufferQueueDefs.h>
21a9347647eca3101c014be902b713772de3977d87Mathias Agopian#include <gui/IConsumerListener.h>
22a9347647eca3101c014be902b713772de3977d87Mathias Agopian#include <gui/IGraphicBufferConsumer.h>
23a9347647eca3101c014be902b713772de3977d87Mathias Agopian#include <gui/OccupancyTracker.h>
241a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
25a9347647eca3101c014be902b713772de3977d87Mathias Agopian#include <ui/PixelFormat.h>
261a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
271a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis#include <utils/String8.h>
281a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis#include <utils/Vector.h>
291a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis#include <utils/threads.h>
30a9347647eca3101c014be902b713772de3977d87Mathias Agopian
311a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
321a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennisnamespace android {
331a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis// ----------------------------------------------------------------------------
341a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
351a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennisclass String8;
36a9347647eca3101c014be902b713772de3977d87Mathias Agopianclass GraphicBuffer;
371a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
381a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis// ConsumerBase is a base class for BufferQueue consumer end-points. It
391a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis// handles common tasks like management of the connection to the BufferQueue
401a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis// and the buffer pool.
411a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennisclass ConsumerBase : public virtual RefBase,
42a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian        protected ConsumerListener {
431a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennispublic:
441a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    struct FrameAvailableListener : public virtual RefBase {
45dc13c5b85b099050c73297a19f1ef89308f7620bDan Stoza        // See IConsumerListener::onFrame{Available,Replaced}
468dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza        virtual void onFrameAvailable(const BufferItem& item) = 0;
47dc13c5b85b099050c73297a19f1ef89308f7620bDan Stoza        virtual void onFrameReplaced(const BufferItem& /* item */) {}
481a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    };
491a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
501a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    virtual ~ConsumerBase();
511a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
521a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // abandon frees all the buffers and puts the ConsumerBase into the
531a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // 'abandoned' state.  Once put in this state the ConsumerBase can never
541a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // leave it.  When in the 'abandoned' state, all methods of the
552adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // IGraphicBufferProducer interface will fail with the NO_INIT error.
561a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    //
571a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // Note that while calling this method causes all the buffers to be freed
581a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // from the perspective of the the ConsumerBase, if there are additional
591a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // references on the buffers (e.g. if a buffer is referenced by a client
601a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // or by OpenGL ES as a texture) then those buffer will remain allocated.
611a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    void abandon();
621a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
63e478305181bb8dc8706361bc702256fe73f958deJohn Reck    // Returns true if the ConsumerBase is in the 'abandoned' state
64e478305181bb8dc8706361bc702256fe73f958deJohn Reck    bool isAbandoned();
65e478305181bb8dc8706361bc702256fe73f958deJohn Reck
661a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // set the name of the ConsumerBase that will be used to identify it in
671a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // log messages.
681a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    void setName(const String8& name);
691a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
703d1d280fa3cbc30700f728a4b13e5308315433d3Colin Cross    // dumpState writes the current state to a string. Child classes should add
717adb0f8a9fdb961692ffd2f0c65cacb155143f64Jesse Hall    // their state to the dump by overriding the dumpLocked method, which is
727adb0f8a9fdb961692ffd2f0c65cacb155143f64Jesse Hall    // called by these methods after locking the mutex.
733d1d280fa3cbc30700f728a4b13e5308315433d3Colin Cross    void dumpState(String8& result) const;
743d1d280fa3cbc30700f728a4b13e5308315433d3Colin Cross    void dumpState(String8& result, const char* prefix) const;
751a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
761a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // setFrameAvailableListener sets the listener object that will be notified
771a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // when a new frame becomes available.
78a4a3149a36bc69a06e4824aeae909ab910661070Igor Murashkin    void setFrameAvailableListener(const wp<FrameAvailableListener>& listener);
791a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
80634f5ee6a713b3cf4086a2af8e9b56e76cba245fDan Stoza    // See IGraphicBufferConsumer::detachBuffer
81634f5ee6a713b3cf4086a2af8e9b56e76cba245fDan Stoza    status_t detachBuffer(int slot);
82634f5ee6a713b3cf4086a2af8e9b56e76cba245fDan Stoza
83847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine    // See IGraphicBufferConsumer::setDefaultBufferSize
84847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine    status_t setDefaultBufferSize(uint32_t width, uint32_t height);
85847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine
86847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine    // See IGraphicBufferConsumer::setDefaultBufferFormat
87847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine    status_t setDefaultBufferFormat(PixelFormat defaultFormat);
88847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine
89847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine    // See IGraphicBufferConsumer::setDefaultBufferDataSpace
90847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine    status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace);
91847f11e215e86b107ab50c1359fc7bc3cd7a3a11Michael Lentine
92e77c7669bee30b7c0099172cf0c38cef92412040Dan Stoza    // See IGraphicBufferConsumer::getOccupancyHistory
93e77c7669bee30b7c0099172cf0c38cef92412040Dan Stoza    status_t getOccupancyHistory(bool forceFlush,
94e77c7669bee30b7c0099172cf0c38cef92412040Dan Stoza            std::vector<OccupancyTracker::Segment>* outHistory);
95e77c7669bee30b7c0099172cf0c38cef92412040Dan Stoza
96bc2df65a3f3f4b8abaaaa2a4e576a3a42c2d30f3Eino-Ville Talvala    // See IGraphicBufferConsumer::discardFreeBuffers
97bc2df65a3f3f4b8abaaaa2a4e576a3a42c2d30f3Eino-Ville Talvala    status_t discardFreeBuffers();
98bc2df65a3f3f4b8abaaaa2a4e576a3a42c2d30f3Eino-Ville Talvala
991a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennisprivate:
1001a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    ConsumerBase(const ConsumerBase&);
1011a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    void operator=(const ConsumerBase&);
1021a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
1031a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennisprotected:
1049fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // ConsumerBase constructs a new ConsumerBase object to consume image
105db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian    // buffers from the given IGraphicBufferConsumer.
106595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    // The controlledByApp flag indicates that this consumer is under the application's
107595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian    // control.
10865d4787875544af168de512d3172777595ab59f7Chih-Hung Hsieh    explicit ConsumerBase(const sp<IGraphicBufferConsumer>& consumer, bool controlledByApp = false);
1091a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
110ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // onLastStrongRef gets called by RefBase just before the dtor of the most
111ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // derived class.  It is used to clean up the buffers so that ConsumerBase
112ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // can coordinate the clean-up by calling into virtual methods implemented
113ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // by the derived classes.  This would not be possible from the
114ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // ConsuemrBase dtor because by the time that gets called the derived
115ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // classes have already been destructed.
116ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    //
117ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // This methods should not need to be overridden by derived classes, but
118ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // if they are overridden the ConsumerBase implementation must be called
119ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    // from the derived class.
120ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis    virtual void onLastStrongRef(const void* id);
121ad669b04f4633957eea55b8ad2d8253adcefe39bJamie Gennis
122e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    // Implementation of the IConsumerListener interface.  These
123e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    // calls are used to notify the ConsumerBase of asynchronous events in the
124e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    // BufferQueue.  The onFrameAvailable, onFrameReplaced, and
125e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    // onBuffersReleased methods should not need to be overridden by derived
126e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    // classes, but if they are overridden the ConsumerBase implementation must
127e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    // be called from the derived class. The ConsumerBase version of
128e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    // onSidebandStreamChanged does nothing and can be overriden by derived
129e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    // classes if they want the notification.
130e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    virtual void onFrameAvailable(const BufferItem& item) override;
131e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    virtual void onFrameReplaced(const BufferItem& item) override;
132e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    virtual void onBuffersReleased() override;
133e07e3e5ef56b768d73e78fb273f2cfe6ebffc945Pablo Ceballos    virtual void onSidebandStreamChanged() override;
1341a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
1351a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // freeBufferLocked frees up the given buffer slot.  If the slot has been
1361a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // initialized this will release the reference to the GraphicBuffer in that
1379fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // slot.  Otherwise it has no effect.
1389fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    //
1399fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // Derived classes should override this method to clean up any state they
1409fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // keep per slot.  If it is overridden, the derived class's implementation
1419fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // must call ConsumerBase::freeBufferLocked.
1421a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    //
1431a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // This method must be called with mMutex locked.
1441a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    virtual void freeBufferLocked(int slotIndex);
1451a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
1461a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // abandonLocked puts the BufferQueue into the abandoned state, causing
1471a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // all future operations on it to fail. This method rather than the public
1481a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // abandon method should be overridden by child classes to add abandon-
1491a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // time behavior.
1501a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    //
1519fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // Derived classes should override this method to clean up any object
1529fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // state they keep (as opposed to per-slot state).  If it is overridden,
1539fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // the derived class's implementation must call ConsumerBase::abandonLocked.
1549fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    //
1551a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // This method must be called with mMutex locked.
1561a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    virtual void abandonLocked();
1571a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
1589fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // dumpLocked dumps the current state of the ConsumerBase object to the
1599fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // result string.  Each line is prefixed with the string pointed to by the
1609fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // prefix argument.  The buffer argument points to a buffer that may be
1619fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // used for intermediate formatting data, and the size of that buffer is
1629fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // indicated by the size argument.
1639fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    //
1649fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // Derived classes should override this method to dump their internal
1659fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // state.  If this method is overridden the derived class's implementation
1669fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // should call ConsumerBase::dumpLocked.
1679fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    //
1689fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // This method must be called with mMutex locked.
16974d211ae26a0257c6075a823812e40b55aa1e653Mathias Agopian    virtual void dumpLocked(String8& result, const char* prefix) const;
1701a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
1711a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // acquireBufferLocked fetches the next buffer from the BufferQueue and
1721a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // updates the buffer slot for the buffer returned.
1739fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    //
1749fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // Derived classes should override this method to perform any
1759fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // initialization that must take place the first time a buffer is assigned
1769fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // to a slot.  If it is overridden the derived class's implementation must
1779fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // call ConsumerBase::acquireBufferLocked.
178a4650a50a0b35e9e4342d6600b6eb24fd94bb8e5Dan Stoza    virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen,
179a4650a50a0b35e9e4342d6600b6eb24fd94bb8e5Dan Stoza            uint64_t maxFrameNumber = 0);
1801a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
1811a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // releaseBufferLocked relinquishes control over a buffer, returning that
1821a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // control to the BufferQueue.
1839fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    //
1849fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // Derived classes should override this method to perform any cleanup that
1859fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // must take place when a buffer is released back to the BufferQueue.  If
1869fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // it is overridden the derived class's implementation must call
1873546a3f08ad84099db4006d651c656d58d2ed566Brian Anderson    // ConsumerBase::releaseBufferLocked.
188c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar    virtual status_t releaseBufferLocked(int slot,
189c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar            const sp<GraphicBuffer> graphicBuffer,
190c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar            EGLDisplay display, EGLSyncKHR eglFence);
191c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar
192c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar    // returns true iff the slot still has the graphicBuffer in it.
193c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar    bool stillTracking(int slot, const sp<GraphicBuffer> graphicBuffer);
194b27254154642575dfb4bbfa79fbedde7d7ee23ddJamie Gennis
1959504eb915c9628e130f45019bdefda0168089886Jesse Hall    // addReleaseFence* adds the sync points associated with a fence to the set
196b27254154642575dfb4bbfa79fbedde7d7ee23ddJamie Gennis    // of sync points that must be reached before the buffer in the given slot
197b27254154642575dfb4bbfa79fbedde7d7ee23ddJamie Gennis    // may be used after the slot has been released.  This should be called by
198b27254154642575dfb4bbfa79fbedde7d7ee23ddJamie Gennis    // derived classes each time some asynchronous work is kicked off that
199b27254154642575dfb4bbfa79fbedde7d7ee23ddJamie Gennis    // references the buffer.
200c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar    status_t addReleaseFence(int slot,
201c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar            const sp<GraphicBuffer> graphicBuffer, const sp<Fence>& fence);
202c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar    status_t addReleaseFenceLocked(int slot,
203c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar            const sp<GraphicBuffer> graphicBuffer, const sp<Fence>& fence);
2041a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2051a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // Slot contains the information and object references that
2061a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // ConsumerBase maintains about a BufferQueue buffer slot.
2071a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    struct Slot {
2081a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis        // mGraphicBuffer is the Gralloc buffer store in the slot or NULL if
2091a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis        // no Gralloc buffer is in the slot.
2101a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis        sp<GraphicBuffer> mGraphicBuffer;
2111a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2121a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis        // mFence is a fence which will signal when the buffer associated with
2131a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis        // this buffer slot is no longer being used by the consumer and can be
2141a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis        // overwritten. The buffer can be dequeued before the fence signals;
2151a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis        // the producer is responsible for delaying writes until it signals.
2161a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis        sp<Fence> mFence;
217c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar
218c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar        // the frame number of the last acquired frame for this slot
219c5d7b7d323bba8772a9005f7d300ad983a04733aLajos Molnar        uint64_t mFrameNumber;
2201a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    };
2211a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2221a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // mSlots stores the buffers that have been allocated by the BufferQueue
2231a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // for each buffer slot.  It is initialized to null pointers, and gets
2241a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // filled in with the result of BufferQueue::acquire when the
2251a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // client dequeues a buffer from a
2261a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // slot that has not yet been used. The buffer allocated to a slot will also
2271a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // be replaced if the requested buffer usage or geometry differs from that
2281a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // of the buffer allocated to a slot.
229a9347647eca3101c014be902b713772de3977d87Mathias Agopian    Slot mSlots[BufferQueueDefs::NUM_BUFFER_SLOTS];
2301a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2311a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // mAbandoned indicates that the BufferQueue will no longer be used to
2322adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden    // consume images buffers pushed to it using the IGraphicBufferProducer
2331a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // interface. It is initialized to false, and set to true in the abandon
2341a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // method.  A BufferQueue that has been abandoned will return the NO_INIT
2351a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // error from all IConsumerBase methods capable of returning an error.
2361a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    bool mAbandoned;
2371a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2381a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // mName is a string used to identify the ConsumerBase in log messages.
2391a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // It can be set by the setName method.
2401a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    String8 mName;
2411a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2421a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // mFrameAvailableListener is the listener object that will be called when a
2431a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // new frame becomes available. If it is not NULL it will be called from
24465bee228207da4064b09abc4c2b88cd7b797890bDan Stoza    // queueBuffer. The listener object is protected by mFrameAvailableMutex
24565bee228207da4064b09abc4c2b88cd7b797890bDan Stoza    // (not mMutex).
24665bee228207da4064b09abc4c2b88cd7b797890bDan Stoza    Mutex mFrameAvailableMutex;
247a4a3149a36bc69a06e4824aeae909ab910661070Igor Murashkin    wp<FrameAvailableListener> mFrameAvailableListener;
2481a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2491a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // The ConsumerBase has-a BufferQueue and is responsible for creating this object
2501a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // if none is supplied
251db89edc94bd2a78226b407f9f7261e202e7fa325Mathias Agopian    sp<IGraphicBufferConsumer> mConsumer;
2521a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2533546a3f08ad84099db4006d651c656d58d2ed566Brian Anderson    // The final release fence of the most recent buffer released by
2543546a3f08ad84099db4006d651c656d58d2ed566Brian Anderson    // releaseBufferLocked.
2553546a3f08ad84099db4006d651c656d58d2ed566Brian Anderson    sp<Fence> mPrevFinalReleaseFence;
2563546a3f08ad84099db4006d651c656d58d2ed566Brian Anderson
2571a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // mMutex is the mutex used to prevent concurrent access to the member
2581a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    // variables of ConsumerBase objects. It must be locked whenever the
2599fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // member variables are accessed or when any of the *Locked methods are
2609fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // called.
2619fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    //
2629fea3421ffddf6480f57f55a25936a886043d909Jamie Gennis    // This mutex is intended to be locked by derived classes.
2631a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis    mutable Mutex mMutex;
2641a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis};
2651a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2661a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis// ----------------------------------------------------------------------------
2671a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis}; // namespace android
2681a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis
2691a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennis#endif // ANDROID_GUI_CONSUMERBASE_H
270