Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_GUI_BUFFERQUEUE_H |
| 18 | #define ANDROID_GUI_BUFFERQUEUE_H |
| 19 | |
| 20 | #include <EGL/egl.h> |
Daniel Lam | f71c4ae | 2012-03-23 18:12:04 -0700 | [diff] [blame] | 21 | #include <EGL/eglext.h> |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 22 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 23 | #include <gui/IConsumerListener.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 24 | #include <gui/IGraphicBufferAlloc.h> |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 25 | #include <gui/IGraphicBufferProducer.h> |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 26 | #include <gui/IGraphicBufferConsumer.h> |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 27 | |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 28 | #include <ui/Fence.h> |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 29 | #include <ui/GraphicBuffer.h> |
| 30 | |
| 31 | #include <utils/String8.h> |
| 32 | #include <utils/Vector.h> |
| 33 | #include <utils/threads.h> |
| 34 | |
| 35 | namespace android { |
| 36 | // ---------------------------------------------------------------------------- |
| 37 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 38 | class BufferQueue : public BnGraphicBufferProducer, public BnGraphicBufferConsumer { |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 39 | public: |
| 40 | enum { MIN_UNDEQUEUED_BUFFERS = 2 }; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 41 | enum { NUM_BUFFER_SLOTS = 32 }; |
| 42 | enum { NO_CONNECTED_API = 0 }; |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 43 | enum { INVALID_BUFFER_SLOT = -1 }; |
Andy McFadden | 1585c4d | 2013-06-28 13:52:40 -0700 | [diff] [blame] | 44 | enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE, PRESENT_LATER }; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 45 | |
Jamie Gennis | c68f2ec | 2012-08-30 18:36:22 -0700 | [diff] [blame] | 46 | // When in async mode we reserve two slots in order to guarantee that the |
| 47 | // producer and consumer can run asynchronously. |
| 48 | enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; |
| 49 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 50 | // for backward source compatibility |
| 51 | typedef ::android::ConsumerListener ConsumerListener; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 52 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 53 | // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak |
| 54 | // reference to the actual consumer object. It forwards all calls to that |
| 55 | // consumer object so long as it exists. |
| 56 | // |
| 57 | // This class exists to avoid having a circular reference between the |
| 58 | // BufferQueue object and the consumer object. The reason this can't be a weak |
| 59 | // reference in the BufferQueue class is because we're planning to expose the |
| 60 | // consumer side of a BufferQueue as a binder interface, which doesn't support |
| 61 | // weak references. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 62 | class ProxyConsumerListener : public BnConsumerListener { |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 63 | public: |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 64 | ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 65 | virtual ~ProxyConsumerListener(); |
| 66 | virtual void onFrameAvailable(); |
| 67 | virtual void onBuffersReleased(); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 68 | private: |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 69 | // mConsumerListener is a weak reference to the IConsumerListener. This is |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 70 | // the raison d'etre of ProxyConsumerListener. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 71 | wp<ConsumerListener> mConsumerListener; |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 75 | // BufferQueue manages a pool of gralloc memory slots to be used by |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 76 | // producers and consumers. allocator is used to allocate all the |
| 77 | // needed gralloc buffers. |
| 78 | BufferQueue(const sp<IGraphicBufferAlloc>& allocator = NULL); |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 79 | virtual ~BufferQueue(); |
| 80 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 81 | // dump our state in a String |
| 82 | virtual void dump(String8& result) const; |
| 83 | virtual void dump(String8& result, const char* prefix) const; |
| 84 | |
| 85 | /* |
| 86 | * IGraphicBufferProducer interface |
| 87 | */ |
| 88 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 89 | // Query native window attributes. The "what" values are enumerated in |
| 90 | // window.h (e.g. NATIVE_WINDOW_FORMAT). |
Daniel Lam | b856052 | 2012-01-30 15:51:27 -0800 | [diff] [blame] | 91 | virtual int query(int what, int* value); |
| 92 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 93 | // setBufferCount updates the number of available buffer slots. If this |
| 94 | // method succeeds, buffer slots will be both unallocated and owned by |
| 95 | // the BufferQueue object (i.e. they are not owned by the producer or |
| 96 | // consumer). |
| 97 | // |
| 98 | // This will fail if the producer has dequeued any buffers, or if |
| 99 | // bufferCount is invalid. bufferCount must generally be a value |
| 100 | // between the minimum undequeued buffer count and NUM_BUFFER_SLOTS |
| 101 | // (inclusive). It may also be set to zero (the default) to indicate |
| 102 | // that the producer does not wish to set a value. The minimum value |
| 103 | // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, |
| 104 | // ...). |
| 105 | // |
| 106 | // This may only be called by the producer. The consumer will be told |
| 107 | // to discard buffers through the onBuffersReleased callback. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 108 | virtual status_t setBufferCount(int bufferCount); |
| 109 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 110 | // requestBuffer returns the GraphicBuffer for slot N. |
| 111 | // |
| 112 | // In normal operation, this is called the first time slot N is returned |
| 113 | // by dequeueBuffer. It must be called again if dequeueBuffer returns |
| 114 | // flags indicating that previously-returned buffers are no longer valid. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 115 | virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf); |
| 116 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 117 | // dequeueBuffer gets the next buffer slot index for the producer to use. |
| 118 | // If a buffer slot is available then that slot index is written to the |
| 119 | // location pointed to by the buf argument and a status of OK is returned. |
| 120 | // If no slot is available then a status of -EBUSY is returned and buf is |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 121 | // unmodified. |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 122 | // |
| 123 | // The fence parameter will be updated to hold the fence associated with |
| 124 | // the buffer. The contents of the buffer must not be overwritten until the |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 125 | // fence signals. If the fence is Fence::NO_FENCE, the buffer may be |
| 126 | // written immediately. |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 127 | // |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 128 | // The width and height parameters must be no greater than the minimum of |
| 129 | // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). |
| 130 | // An error due to invalid dimensions might not be reported until |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 131 | // updateTexImage() is called. If width and height are both zero, the |
| 132 | // default values specified by setDefaultBufferSize() are used instead. |
| 133 | // |
| 134 | // The pixel formats are enumerated in graphics.h, e.g. |
| 135 | // HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format |
| 136 | // will be used. |
| 137 | // |
| 138 | // The usage argument specifies gralloc buffer usage flags. The values |
| 139 | // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These |
| 140 | // will be merged with the usage flags specified by setConsumerUsageBits. |
| 141 | // |
| 142 | // The return value may be a negative error value or a non-negative |
| 143 | // collection of flags. If the flags are set, the return values are |
| 144 | // valid, but additional actions must be performed. |
| 145 | // |
| 146 | // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the |
| 147 | // producer must discard cached GraphicBuffer references for the slot |
| 148 | // returned in buf. |
| 149 | // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer |
| 150 | // must discard cached GraphicBuffer references for all slots. |
| 151 | // |
| 152 | // In both cases, the producer will need to call requestBuffer to get a |
| 153 | // GraphicBuffer handle for the returned slot. |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 154 | virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async, |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 155 | uint32_t width, uint32_t height, uint32_t format, uint32_t usage); |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 156 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 157 | // queueBuffer returns a filled buffer to the BufferQueue. |
| 158 | // |
| 159 | // Additional data is provided in the QueueBufferInput struct. Notably, |
| 160 | // a timestamp must be provided for the buffer. The timestamp is in |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 161 | // nanoseconds, and must be monotonically increasing. Its other semantics |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 162 | // (zero point, etc) are producer-specific and should be documented by the |
| 163 | // producer. |
| 164 | // |
| 165 | // The caller may provide a fence that signals when all rendering |
| 166 | // operations have completed. Alternatively, NO_FENCE may be used, |
| 167 | // indicating that the buffer is ready immediately. |
| 168 | // |
| 169 | // Some values are returned in the output struct: the current settings |
| 170 | // for default width and height, the current transform hint, and the |
| 171 | // number of queued buffers. |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 172 | virtual status_t queueBuffer(int buf, |
| 173 | const QueueBufferInput& input, QueueBufferOutput* output); |
| 174 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 175 | // cancelBuffer returns a dequeued buffer to the BufferQueue, but doesn't |
| 176 | // queue it for use by the consumer. |
| 177 | // |
| 178 | // The buffer will not be overwritten until the fence signals. The fence |
| 179 | // will usually be the one obtained from dequeueBuffer. |
Jesse Hall | 4c00cc1 | 2013-03-15 21:34:30 -0700 | [diff] [blame] | 180 | virtual void cancelBuffer(int buf, const sp<Fence>& fence); |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 181 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 182 | // connect attempts to connect a producer API to the BufferQueue. This |
| 183 | // must be called before any other IGraphicBufferProducer methods are |
| 184 | // called except for getAllocator. A consumer must already be connected. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 185 | // |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 186 | // This method will fail if connect was previously called on the |
| 187 | // BufferQueue and no corresponding disconnect call was made (i.e. if |
| 188 | // it's still connected to a producer). |
| 189 | // |
| 190 | // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU). |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 191 | virtual status_t connect(int api, bool producerControlledByApp, QueueBufferOutput* output); |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 192 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 193 | // disconnect attempts to disconnect a producer API from the BufferQueue. |
| 194 | // Calling this method will cause any subsequent calls to other |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 195 | // IGraphicBufferProducer methods to fail except for getAllocator and connect. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 196 | // Successfully calling connect after this will allow the other methods to |
| 197 | // succeed again. |
| 198 | // |
| 199 | // This method will fail if the the BufferQueue is not currently |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 200 | // connected to the specified producer API. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 201 | virtual status_t disconnect(int api); |
| 202 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 203 | /* |
| 204 | * IGraphicBufferConsumer interface |
| 205 | */ |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 206 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 207 | // acquireBuffer attempts to acquire ownership of the next pending buffer in |
| 208 | // the BufferQueue. If no buffer is pending then it returns -EINVAL. If a |
| 209 | // buffer is successfully acquired, the information about the buffer is |
| 210 | // returned in BufferItem. If the buffer returned had previously been |
| 211 | // acquired then the BufferItem::mGraphicBuffer field of buffer is set to |
| 212 | // NULL and it is assumed that the consumer still holds a reference to the |
| 213 | // buffer. |
Andy McFadden | 1585c4d | 2013-06-28 13:52:40 -0700 | [diff] [blame] | 214 | // |
| 215 | // If presentWhen is nonzero, it indicates the time when the buffer will |
| 216 | // be displayed on screen. If the buffer's timestamp is farther in the |
| 217 | // future, the buffer won't be acquired, and PRESENT_LATER will be |
| 218 | // returned. The presentation time is in nanoseconds, and the time base |
| 219 | // is CLOCK_MONOTONIC. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 220 | virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 221 | |
| 222 | // releaseBuffer releases a buffer slot from the consumer back to the |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 223 | // BufferQueue. This may be done while the buffer's contents are still |
| 224 | // being accessed. The fence will signal when the buffer is no longer |
Lajos Molnar | c5d7b7d | 2013-05-03 14:50:50 -0700 | [diff] [blame] | 225 | // in use. frameNumber is used to indentify the exact buffer returned. |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 226 | // |
Eino-Ville Talvala | e41b318 | 2012-04-16 17:54:33 -0700 | [diff] [blame] | 227 | // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free |
| 228 | // any references to the just-released buffer that it might have, as if it |
| 229 | // had received a onBuffersReleased() call with a mask set for the released |
| 230 | // buffer. |
| 231 | // |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 232 | // Note that the dependencies on EGL will be removed once we switch to using |
| 233 | // the Android HW Sync HAL. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 234 | virtual status_t releaseBuffer(int buf, uint64_t frameNumber, |
Lajos Molnar | c5d7b7d | 2013-05-03 14:50:50 -0700 | [diff] [blame] | 235 | EGLDisplay display, EGLSyncKHR fence, |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 236 | const sp<Fence>& releaseFence); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 237 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 238 | // consumerConnect connects a consumer to the BufferQueue. Only one |
| 239 | // consumer may be connected, and when that consumer disconnects the |
| 240 | // BufferQueue is placed into the "abandoned" state, causing most |
| 241 | // interactions with the BufferQueue by the producer to fail. |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 242 | // controlledByApp indicates whether the consumer is controlled by |
| 243 | // the application. |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 244 | // |
| 245 | // consumer may not be NULL. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 246 | virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 247 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 248 | // consumerDisconnect disconnects a consumer from the BufferQueue. All |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 249 | // buffers will be freed and the BufferQueue is placed in the "abandoned" |
| 250 | // state, causing most interactions with the BufferQueue by the producer to |
| 251 | // fail. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 252 | virtual status_t consumerDisconnect(); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 253 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 254 | // getReleasedBuffers sets the value pointed to by slotMask to a bit mask |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 255 | // indicating which buffer slots have been released by the BufferQueue |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 256 | // but have not yet been released by the consumer. |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 257 | // |
| 258 | // This should be called from the onBuffersReleased() callback. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 259 | virtual status_t getReleasedBuffers(uint32_t* slotMask); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 260 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 261 | // setDefaultBufferSize is used to set the size of buffers returned by |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 262 | // dequeueBuffer when a width and height of zero is requested. Default |
| 263 | // is 1x1. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 264 | virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 265 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 266 | // setDefaultMaxBufferCount sets the default value for the maximum buffer |
| 267 | // count (the initial default is 2). If the producer has requested a |
| 268 | // buffer count using setBufferCount, the default buffer count will only |
| 269 | // take effect if the producer sets the count back to zero. |
| 270 | // |
| 271 | // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 272 | virtual status_t setDefaultMaxBufferCount(int bufferCount); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 273 | |
Mathias Agopian | ad678e1 | 2013-07-23 17:28:53 -0700 | [diff] [blame] | 274 | // disableAsyncBuffer disables the extra buffer used in async mode |
| 275 | // (when both producer and consumer have set their "isControlledByApp" |
| 276 | // flag) and has dequeueBuffer() return WOULD_BLOCK instead. |
| 277 | // |
| 278 | // This can only be called before consumerConnect(). |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 279 | virtual status_t disableAsyncBuffer(); |
Mathias Agopian | ad678e1 | 2013-07-23 17:28:53 -0700 | [diff] [blame] | 280 | |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 281 | // setMaxAcquiredBufferCount sets the maximum number of buffers that can |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 282 | // be acquired by the consumer at one time (default 1). This call will |
| 283 | // fail if a producer is connected to the BufferQueue. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 284 | virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 285 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 286 | // setConsumerName sets the name used in logging |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 287 | virtual void setConsumerName(const String8& name); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 288 | |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 289 | // setDefaultBufferFormat allows the BufferQueue to create |
| 290 | // GraphicBuffers of a defaultFormat if no format is specified |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 291 | // in dequeueBuffer. Formats are enumerated in graphics.h; the |
| 292 | // initial default is HAL_PIXEL_FORMAT_RGBA_8888. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 293 | virtual status_t setDefaultBufferFormat(uint32_t defaultFormat); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 294 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 295 | // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. |
| 296 | // These are merged with the bits passed to dequeueBuffer. The values are |
| 297 | // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 298 | virtual status_t setConsumerUsageBits(uint32_t usage); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 299 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 300 | // setTransformHint bakes in rotation to buffers so overlays can be used. |
| 301 | // The values are enumerated in window.h, e.g. |
| 302 | // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 303 | virtual status_t setTransformHint(uint32_t hint); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 304 | |
Mathias Agopian | ad678e1 | 2013-07-23 17:28:53 -0700 | [diff] [blame] | 305 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 306 | private: |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 307 | // freeBufferLocked frees the GraphicBuffer and sync resources for the |
| 308 | // given slot. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 309 | void freeBufferLocked(int index); |
| 310 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 311 | // freeAllBuffersLocked frees the GraphicBuffer and sync resources for |
| 312 | // all slots. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 313 | void freeAllBuffersLocked(); |
| 314 | |
Jamie Gennis | 31a353d | 2012-08-24 17:25:13 -0700 | [diff] [blame] | 315 | // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots |
| 316 | // that will be used if the producer does not override the buffer slot |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 317 | // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. |
| 318 | // The initial default is 2. |
Jamie Gennis | 31a353d | 2012-08-24 17:25:13 -0700 | [diff] [blame] | 319 | status_t setDefaultMaxBufferCountLocked(int count); |
| 320 | |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 321 | // getMinUndequeuedBufferCount returns the minimum number of buffers |
| 322 | // that must remain in a state other than DEQUEUED. |
| 323 | // The async parameter tells whether we're in asynchronous mode. |
| 324 | int getMinUndequeuedBufferCount(bool async) const; |
| 325 | |
Jamie Gennis | 31a353d | 2012-08-24 17:25:13 -0700 | [diff] [blame] | 326 | // getMinBufferCountLocked returns the minimum number of buffers allowed |
| 327 | // given the current BufferQueue state. |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 328 | // The async parameter tells whether we're in asynchronous mode. |
| 329 | int getMinMaxBufferCountLocked(bool async) const; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 330 | |
Jamie Gennis | e191e6c | 2012-08-24 20:26:34 -0700 | [diff] [blame] | 331 | // getMaxBufferCountLocked returns the maximum number of buffers that can |
| 332 | // be allocated at once. This value depends upon the following member |
| 333 | // variables: |
| 334 | // |
Mathias Agopian | a3fbda3 | 2013-07-18 15:55:03 -0700 | [diff] [blame] | 335 | // mDequeueBufferCannotBlock |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 336 | // mMaxAcquiredBufferCount |
Jamie Gennis | e191e6c | 2012-08-24 20:26:34 -0700 | [diff] [blame] | 337 | // mDefaultMaxBufferCount |
| 338 | // mOverrideMaxBufferCount |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 339 | // async parameter |
Jamie Gennis | e191e6c | 2012-08-24 20:26:34 -0700 | [diff] [blame] | 340 | // |
| 341 | // Any time one of these member variables is changed while a producer is |
| 342 | // connected, mDequeueCondition must be broadcast. |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 343 | int getMaxBufferCountLocked(bool async) const; |
Jamie Gennis | e191e6c | 2012-08-24 20:26:34 -0700 | [diff] [blame] | 344 | |
Lajos Molnar | c5d7b7d | 2013-05-03 14:50:50 -0700 | [diff] [blame] | 345 | // stillTracking returns true iff the buffer item is still being tracked |
| 346 | // in one of the slots. |
| 347 | bool stillTracking(const BufferItem *item) const; |
| 348 | |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 349 | struct BufferSlot { |
| 350 | |
| 351 | BufferSlot() |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 352 | : mEglDisplay(EGL_NO_DISPLAY), |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 353 | mBufferState(BufferSlot::FREE), |
| 354 | mRequestBufferCalled(false), |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 355 | mFrameNumber(0), |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 356 | mEglFence(EGL_NO_SYNC_KHR), |
Daniel Lam | 9abe1eb | 2012-03-26 20:37:15 -0700 | [diff] [blame] | 357 | mAcquireCalled(false), |
| 358 | mNeedsCleanupOnRelease(false) { |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | // mGraphicBuffer points to the buffer allocated for this slot or is NULL |
| 362 | // if no buffer has been allocated. |
| 363 | sp<GraphicBuffer> mGraphicBuffer; |
| 364 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 365 | // mEglDisplay is the EGLDisplay used to create EGLSyncKHR objects. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 366 | EGLDisplay mEglDisplay; |
| 367 | |
| 368 | // BufferState represents the different states in which a buffer slot |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 369 | // can be. All slots are initially FREE. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 370 | enum BufferState { |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 371 | // FREE indicates that the buffer is available to be dequeued |
| 372 | // by the producer. The buffer may be in use by the consumer for |
| 373 | // a finite time, so the buffer must not be modified until the |
| 374 | // associated fence is signaled. |
| 375 | // |
| 376 | // The slot is "owned" by BufferQueue. It transitions to DEQUEUED |
| 377 | // when dequeueBuffer is called. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 378 | FREE = 0, |
| 379 | |
| 380 | // DEQUEUED indicates that the buffer has been dequeued by the |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 381 | // producer, but has not yet been queued or canceled. The |
| 382 | // producer may modify the buffer's contents as soon as the |
| 383 | // associated ready fence is signaled. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 384 | // |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 385 | // The slot is "owned" by the producer. It can transition to |
| 386 | // QUEUED (via queueBuffer) or back to FREE (via cancelBuffer). |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 387 | DEQUEUED = 1, |
| 388 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 389 | // QUEUED indicates that the buffer has been filled by the |
| 390 | // producer and queued for use by the consumer. The buffer |
| 391 | // contents may continue to be modified for a finite time, so |
| 392 | // the contents must not be accessed until the associated fence |
| 393 | // is signaled. |
| 394 | // |
| 395 | // The slot is "owned" by BufferQueue. It can transition to |
| 396 | // ACQUIRED (via acquireBuffer) or to FREE (if another buffer is |
| 397 | // queued in asynchronous mode). |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 398 | QUEUED = 2, |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 399 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 400 | // ACQUIRED indicates that the buffer has been acquired by the |
| 401 | // consumer. As with QUEUED, the contents must not be accessed |
| 402 | // by the consumer until the fence is signaled. |
| 403 | // |
| 404 | // The slot is "owned" by the consumer. It transitions to FREE |
| 405 | // when releaseBuffer is called. |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 406 | ACQUIRED = 3 |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | // mBufferState is the current state of this buffer slot. |
| 410 | BufferState mBufferState; |
| 411 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 412 | // mRequestBufferCalled is used for validating that the producer did |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 413 | // call requestBuffer() when told to do so. Technically this is not |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 414 | // needed but useful for debugging and catching producer bugs. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 415 | bool mRequestBufferCalled; |
| 416 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 417 | // mFrameNumber is the number of the queued frame for this slot. This |
| 418 | // is used to dequeue buffers in LRU order (useful because buffers |
| 419 | // may be released before their release fence is signaled). |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 420 | uint64_t mFrameNumber; |
| 421 | |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 422 | // mEglFence is the EGL sync object that must signal before the buffer |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 423 | // associated with this buffer slot may be dequeued. It is initialized |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 424 | // to EGL_NO_SYNC_KHR when the buffer is created and may be set to a |
| 425 | // new sync object in releaseBuffer. (This is deprecated in favor of |
| 426 | // mFence, below.) |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 427 | EGLSyncKHR mEglFence; |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 428 | |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 429 | // mFence is a fence which will signal when work initiated by the |
| 430 | // previous owner of the buffer is finished. When the buffer is FREE, |
| 431 | // the fence indicates when the consumer has finished reading |
| 432 | // from the buffer, or when the producer has finished writing if it |
| 433 | // called cancelBuffer after queueing some writes. When the buffer is |
| 434 | // QUEUED, it indicates when the producer has finished filling the |
| 435 | // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been |
| 436 | // passed to the consumer or producer along with ownership of the |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 437 | // buffer, and mFence is set to NO_FENCE. |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 438 | sp<Fence> mFence; |
Jesse Hall | ef19414 | 2012-06-14 14:45:17 -0700 | [diff] [blame] | 439 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 440 | // Indicates whether this buffer has been seen by a consumer yet |
| 441 | bool mAcquireCalled; |
Daniel Lam | 9abe1eb | 2012-03-26 20:37:15 -0700 | [diff] [blame] | 442 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 443 | // Indicates whether this buffer needs to be cleaned up by the |
| 444 | // consumer. This is set when a buffer in ACQUIRED state is freed. |
| 445 | // It causes releaseBuffer to return STALE_BUFFER_SLOT. |
Daniel Lam | 9abe1eb | 2012-03-26 20:37:15 -0700 | [diff] [blame] | 446 | bool mNeedsCleanupOnRelease; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 447 | }; |
| 448 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 449 | // mSlots is the array of buffer slots that must be mirrored on the |
| 450 | // producer side. This allows buffer ownership to be transferred between |
| 451 | // the producer and consumer without sending a GraphicBuffer over binder. |
| 452 | // The entire array is initialized to NULL at construction time, and |
| 453 | // buffers are allocated for a slot when requestBuffer is called with |
| 454 | // that slot's index. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 455 | BufferSlot mSlots[NUM_BUFFER_SLOTS]; |
| 456 | |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 457 | // mDefaultWidth holds the default width of allocated buffers. It is used |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 458 | // in dequeueBuffer() if a width and height of zero is specified. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 459 | uint32_t mDefaultWidth; |
| 460 | |
| 461 | // mDefaultHeight holds the default height of allocated buffers. It is used |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 462 | // in dequeueBuffer() if a width and height of zero is specified. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 463 | uint32_t mDefaultHeight; |
| 464 | |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 465 | // mMaxAcquiredBufferCount is the number of buffers that the consumer may |
| 466 | // acquire at one time. It defaults to 1 and can be changed by the |
| 467 | // consumer via the setMaxAcquiredBufferCount method, but this may only be |
| 468 | // done when no producer is connected to the BufferQueue. |
| 469 | // |
| 470 | // This value is used to derive the value returned for the |
| 471 | // MIN_UNDEQUEUED_BUFFERS query by the producer. |
| 472 | int mMaxAcquiredBufferCount; |
Daniel Lam | abe61bf | 2012-03-26 20:37:15 -0700 | [diff] [blame] | 473 | |
Jamie Gennis | 31a353d | 2012-08-24 17:25:13 -0700 | [diff] [blame] | 474 | // mDefaultMaxBufferCount is the default limit on the number of buffers |
| 475 | // that will be allocated at one time. This default limit is set by the |
| 476 | // consumer. The limit (as opposed to the default limit) may be |
| 477 | // overridden by the producer. |
| 478 | int mDefaultMaxBufferCount; |
Daniel Lam | abe61bf | 2012-03-26 20:37:15 -0700 | [diff] [blame] | 479 | |
Jamie Gennis | 31a353d | 2012-08-24 17:25:13 -0700 | [diff] [blame] | 480 | // mOverrideMaxBufferCount is the limit on the number of buffers that will |
| 481 | // be allocated at one time. This value is set by the image producer by |
| 482 | // calling setBufferCount. The default is zero, which means the producer |
| 483 | // doesn't care about the number of buffers in the pool. In that case |
| 484 | // mDefaultMaxBufferCount is used as the limit. |
| 485 | int mOverrideMaxBufferCount; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 486 | |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 487 | // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to |
| 488 | // allocate new GraphicBuffer objects. |
| 489 | sp<IGraphicBufferAlloc> mGraphicBufferAlloc; |
| 490 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 491 | // mConsumerListener is used to notify the connected consumer of |
| 492 | // asynchronous events that it may wish to react to. It is initially set |
| 493 | // to NULL and is written by consumerConnect and consumerDisconnect. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame^] | 494 | sp<IConsumerListener> mConsumerListener; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 495 | |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 496 | // mConsumerControlledByApp whether the connected consumer is controlled by the |
| 497 | // application. |
| 498 | bool mConsumerControlledByApp; |
| 499 | |
| 500 | // mDequeueBufferCannotBlock whether dequeueBuffer() isn't allowed to block. |
Mathias Agopian | ad678e1 | 2013-07-23 17:28:53 -0700 | [diff] [blame] | 501 | // this flag is set during connect() when both consumer and producer are controlled |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 502 | // by the application. |
| 503 | bool mDequeueBufferCannotBlock; |
| 504 | |
Mathias Agopian | ad678e1 | 2013-07-23 17:28:53 -0700 | [diff] [blame] | 505 | // mUseAsyncBuffer whether an extra buffer is used in async mode to prevent |
| 506 | // dequeueBuffer() from ever blocking. |
| 507 | bool mUseAsyncBuffer; |
| 508 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 509 | // mConnectedApi indicates the producer API that is currently connected |
| 510 | // to this BufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets |
| 511 | // updated by the connect and disconnect methods. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 512 | int mConnectedApi; |
| 513 | |
| 514 | // mDequeueCondition condition used for dequeueBuffer in synchronous mode |
| 515 | mutable Condition mDequeueCondition; |
| 516 | |
| 517 | // mQueue is a FIFO of queued buffers used in synchronous mode |
Lajos Molnar | c5d7b7d | 2013-05-03 14:50:50 -0700 | [diff] [blame] | 518 | typedef Vector<BufferItem> Fifo; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 519 | Fifo mQueue; |
| 520 | |
| 521 | // mAbandoned indicates that the BufferQueue will no longer be used to |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 522 | // consume image buffers pushed to it using the IGraphicBufferProducer |
| 523 | // interface. It is initialized to false, and set to true in the |
| 524 | // consumerDisconnect method. A BufferQueue that has been abandoned will |
| 525 | // return the NO_INIT error from all IGraphicBufferProducer methods |
| 526 | // capable of returning an error. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 527 | bool mAbandoned; |
| 528 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 529 | // mConsumerName is a string used to identify the BufferQueue in log |
| 530 | // messages. It is set by the setConsumerName method. |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 531 | String8 mConsumerName; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 532 | |
| 533 | // mMutex is the mutex used to prevent concurrent access to the member |
| 534 | // variables of BufferQueue objects. It must be locked whenever the |
| 535 | // member variables are accessed. |
| 536 | mutable Mutex mMutex; |
| 537 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 538 | // mFrameCounter is the free running counter, incremented on every |
Lajos Molnar | c5d7b7d | 2013-05-03 14:50:50 -0700 | [diff] [blame] | 539 | // successful queueBuffer call, and buffer allocation. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 540 | uint64_t mFrameCounter; |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 541 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 542 | // mBufferHasBeenQueued is true once a buffer has been queued. It is |
| 543 | // reset when something causes all buffers to be freed (e.g. changing the |
| 544 | // buffer count). |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 545 | bool mBufferHasBeenQueued; |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 546 | |
| 547 | // mDefaultBufferFormat can be set so it will override |
| 548 | // the buffer format when it isn't specified in dequeueBuffer |
| 549 | uint32_t mDefaultBufferFormat; |
| 550 | |
| 551 | // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers |
| 552 | uint32_t mConsumerUsageBits; |
| 553 | |
| 554 | // mTransformHint is used to optimize for screen rotations |
| 555 | uint32_t mTransformHint; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 556 | }; |
| 557 | |
| 558 | // ---------------------------------------------------------------------------- |
| 559 | }; // namespace android |
| 560 | |
| 561 | #endif // ANDROID_GUI_BUFFERQUEUE_H |