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 | |
Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame^] | 20 | #include <gui/BufferQueueProducer.h> |
| 21 | #include <gui/BufferQueueConsumer.h> |
| 22 | #include <gui/IConsumerListener.h> |
| 23 | |
| 24 | // These are only required to keep other parts of the framework with incomplete |
| 25 | // dependencies building successfully |
| 26 | #include <gui/IGraphicBufferAlloc.h> |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 27 | |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 28 | #include <binder/IBinder.h> |
| 29 | |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 30 | namespace android { |
| 31 | // ---------------------------------------------------------------------------- |
| 32 | |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 33 | class BufferQueue : public BnGraphicBufferProducer, |
| 34 | public BnGraphicBufferConsumer, |
| 35 | private IBinder::DeathRecipient { |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 36 | public: |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 37 | // BufferQueue will keep track of at most this value of buffers. |
| 38 | // Attempts at runtime to increase the number of buffers past this will fail. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 39 | enum { NUM_BUFFER_SLOTS = 32 }; |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 40 | // Used as a placeholder slot# when the value isn't pointing to an existing buffer. |
| 41 | enum { INVALID_BUFFER_SLOT = IGraphicBufferConsumer::BufferItem::INVALID_BUFFER_SLOT }; |
| 42 | // Alias to <IGraphicBufferConsumer.h> -- please scope from there in future code! |
| 43 | enum { |
| 44 | NO_BUFFER_AVAILABLE = IGraphicBufferConsumer::NO_BUFFER_AVAILABLE, |
| 45 | PRESENT_LATER = IGraphicBufferConsumer::PRESENT_LATER, |
| 46 | }; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 47 | |
Jamie Gennis | c68f2ec | 2012-08-30 18:36:22 -0700 | [diff] [blame] | 48 | // When in async mode we reserve two slots in order to guarantee that the |
| 49 | // producer and consumer can run asynchronously. |
| 50 | enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; |
| 51 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 52 | // for backward source compatibility |
| 53 | typedef ::android::ConsumerListener ConsumerListener; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 54 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 55 | // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak |
| 56 | // reference to the actual consumer object. It forwards all calls to that |
| 57 | // consumer object so long as it exists. |
| 58 | // |
| 59 | // This class exists to avoid having a circular reference between the |
| 60 | // BufferQueue object and the consumer object. The reason this can't be a weak |
| 61 | // reference in the BufferQueue class is because we're planning to expose the |
| 62 | // consumer side of a BufferQueue as a binder interface, which doesn't support |
| 63 | // weak references. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 64 | class ProxyConsumerListener : public BnConsumerListener { |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 65 | public: |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 66 | ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 67 | virtual ~ProxyConsumerListener(); |
| 68 | virtual void onFrameAvailable(); |
| 69 | virtual void onBuffersReleased(); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 70 | private: |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 71 | // mConsumerListener is a weak reference to the IConsumerListener. This is |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 72 | // the raison d'etre of ProxyConsumerListener. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 73 | wp<ConsumerListener> mConsumerListener; |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 76 | // BufferQueue manages a pool of gralloc memory slots to be used by |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 77 | // producers and consumers. allocator is used to allocate all the |
| 78 | // needed gralloc buffers. |
| 79 | BufferQueue(const sp<IGraphicBufferAlloc>& allocator = NULL); |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 80 | virtual ~BufferQueue(); |
| 81 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 82 | /* |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 83 | * IBinder::DeathRecipient interface |
| 84 | */ |
| 85 | |
| 86 | virtual void binderDied(const wp<IBinder>& who); |
| 87 | |
| 88 | /* |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 89 | * IGraphicBufferProducer interface |
| 90 | */ |
| 91 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 92 | // Query native window attributes. The "what" values are enumerated in |
| 93 | // window.h (e.g. NATIVE_WINDOW_FORMAT). |
Daniel Lam | b856052 | 2012-01-30 15:51:27 -0800 | [diff] [blame] | 94 | virtual int query(int what, int* value); |
| 95 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 96 | // setBufferCount updates the number of available buffer slots. If this |
| 97 | // method succeeds, buffer slots will be both unallocated and owned by |
| 98 | // the BufferQueue object (i.e. they are not owned by the producer or |
| 99 | // consumer). |
| 100 | // |
| 101 | // This will fail if the producer has dequeued any buffers, or if |
| 102 | // bufferCount is invalid. bufferCount must generally be a value |
Igor Murashkin | 7ea777f | 2013-11-18 16:58:36 -0800 | [diff] [blame] | 103 | // between the minimum undequeued buffer count (exclusive) and NUM_BUFFER_SLOTS |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 104 | // (inclusive). It may also be set to zero (the default) to indicate |
| 105 | // that the producer does not wish to set a value. The minimum value |
| 106 | // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, |
| 107 | // ...). |
| 108 | // |
| 109 | // This may only be called by the producer. The consumer will be told |
| 110 | // to discard buffers through the onBuffersReleased callback. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 111 | virtual status_t setBufferCount(int bufferCount); |
| 112 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 113 | // requestBuffer returns the GraphicBuffer for slot N. |
| 114 | // |
| 115 | // In normal operation, this is called the first time slot N is returned |
| 116 | // by dequeueBuffer. It must be called again if dequeueBuffer returns |
| 117 | // flags indicating that previously-returned buffers are no longer valid. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 118 | virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf); |
| 119 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 120 | // dequeueBuffer gets the next buffer slot index for the producer to use. |
| 121 | // If a buffer slot is available then that slot index is written to the |
| 122 | // location pointed to by the buf argument and a status of OK is returned. |
| 123 | // 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] | 124 | // unmodified. |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 125 | // |
| 126 | // The fence parameter will be updated to hold the fence associated with |
| 127 | // 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] | 128 | // fence signals. If the fence is Fence::NO_FENCE, the buffer may be |
| 129 | // written immediately. |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 130 | // |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 131 | // The width and height parameters must be no greater than the minimum of |
| 132 | // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). |
| 133 | // An error due to invalid dimensions might not be reported until |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 134 | // updateTexImage() is called. If width and height are both zero, the |
| 135 | // default values specified by setDefaultBufferSize() are used instead. |
| 136 | // |
| 137 | // The pixel formats are enumerated in graphics.h, e.g. |
| 138 | // HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format |
| 139 | // will be used. |
| 140 | // |
| 141 | // The usage argument specifies gralloc buffer usage flags. The values |
| 142 | // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These |
| 143 | // will be merged with the usage flags specified by setConsumerUsageBits. |
| 144 | // |
| 145 | // The return value may be a negative error value or a non-negative |
| 146 | // collection of flags. If the flags are set, the return values are |
| 147 | // valid, but additional actions must be performed. |
| 148 | // |
| 149 | // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the |
| 150 | // producer must discard cached GraphicBuffer references for the slot |
| 151 | // returned in buf. |
| 152 | // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer |
| 153 | // must discard cached GraphicBuffer references for all slots. |
| 154 | // |
| 155 | // In both cases, the producer will need to call requestBuffer to get a |
| 156 | // GraphicBuffer handle for the returned slot. |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 157 | virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async, |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 158 | uint32_t width, uint32_t height, uint32_t format, uint32_t usage); |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 159 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 160 | // queueBuffer returns a filled buffer to the BufferQueue. |
| 161 | // |
| 162 | // Additional data is provided in the QueueBufferInput struct. Notably, |
| 163 | // a timestamp must be provided for the buffer. The timestamp is in |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 164 | // nanoseconds, and must be monotonically increasing. Its other semantics |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 165 | // (zero point, etc) are producer-specific and should be documented by the |
| 166 | // producer. |
| 167 | // |
| 168 | // The caller may provide a fence that signals when all rendering |
| 169 | // operations have completed. Alternatively, NO_FENCE may be used, |
| 170 | // indicating that the buffer is ready immediately. |
| 171 | // |
| 172 | // Some values are returned in the output struct: the current settings |
| 173 | // for default width and height, the current transform hint, and the |
| 174 | // number of queued buffers. |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 175 | virtual status_t queueBuffer(int buf, |
| 176 | const QueueBufferInput& input, QueueBufferOutput* output); |
| 177 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 178 | // cancelBuffer returns a dequeued buffer to the BufferQueue, but doesn't |
| 179 | // queue it for use by the consumer. |
| 180 | // |
| 181 | // The buffer will not be overwritten until the fence signals. The fence |
| 182 | // will usually be the one obtained from dequeueBuffer. |
Jesse Hall | 4c00cc1 | 2013-03-15 21:34:30 -0700 | [diff] [blame] | 183 | virtual void cancelBuffer(int buf, const sp<Fence>& fence); |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 184 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 185 | // connect attempts to connect a producer API to the BufferQueue. This |
| 186 | // must be called before any other IGraphicBufferProducer methods are |
| 187 | // called except for getAllocator. A consumer must already be connected. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 188 | // |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 189 | // This method will fail if connect was previously called on the |
| 190 | // BufferQueue and no corresponding disconnect call was made (i.e. if |
| 191 | // it's still connected to a producer). |
| 192 | // |
| 193 | // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU). |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 194 | virtual status_t connect(const sp<IBinder>& token, |
| 195 | int api, bool producerControlledByApp, QueueBufferOutput* output); |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 196 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 197 | // disconnect attempts to disconnect a producer API from the BufferQueue. |
| 198 | // Calling this method will cause any subsequent calls to other |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 199 | // IGraphicBufferProducer methods to fail except for getAllocator and connect. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 200 | // Successfully calling connect after this will allow the other methods to |
| 201 | // succeed again. |
| 202 | // |
| 203 | // This method will fail if the the BufferQueue is not currently |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 204 | // connected to the specified producer API. |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 205 | virtual status_t disconnect(int api); |
| 206 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 207 | /* |
| 208 | * IGraphicBufferConsumer interface |
| 209 | */ |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 210 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 211 | // acquireBuffer attempts to acquire ownership of the next pending buffer in |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 212 | // the BufferQueue. If no buffer is pending then it returns NO_BUFFER_AVAILABLE. If a |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 213 | // buffer is successfully acquired, the information about the buffer is |
| 214 | // returned in BufferItem. If the buffer returned had previously been |
| 215 | // acquired then the BufferItem::mGraphicBuffer field of buffer is set to |
| 216 | // NULL and it is assumed that the consumer still holds a reference to the |
| 217 | // buffer. |
Andy McFadden | 1585c4d | 2013-06-28 13:52:40 -0700 | [diff] [blame] | 218 | // |
| 219 | // If presentWhen is nonzero, it indicates the time when the buffer will |
| 220 | // be displayed on screen. If the buffer's timestamp is farther in the |
| 221 | // future, the buffer won't be acquired, and PRESENT_LATER will be |
| 222 | // returned. The presentation time is in nanoseconds, and the time base |
| 223 | // is CLOCK_MONOTONIC. |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 224 | virtual status_t acquireBuffer(BufferItem* buffer, nsecs_t presentWhen); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 225 | |
| 226 | // releaseBuffer releases a buffer slot from the consumer back to the |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 227 | // BufferQueue. This may be done while the buffer's contents are still |
| 228 | // being accessed. The fence will signal when the buffer is no longer |
Lajos Molnar | c5d7b7d | 2013-05-03 14:50:50 -0700 | [diff] [blame] | 229 | // in use. frameNumber is used to indentify the exact buffer returned. |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 230 | // |
Eino-Ville Talvala | e41b318 | 2012-04-16 17:54:33 -0700 | [diff] [blame] | 231 | // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free |
| 232 | // any references to the just-released buffer that it might have, as if it |
| 233 | // had received a onBuffersReleased() call with a mask set for the released |
| 234 | // buffer. |
| 235 | // |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 236 | // Note that the dependencies on EGL will be removed once we switch to using |
| 237 | // the Android HW Sync HAL. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 238 | virtual status_t releaseBuffer(int buf, uint64_t frameNumber, |
Lajos Molnar | c5d7b7d | 2013-05-03 14:50:50 -0700 | [diff] [blame] | 239 | EGLDisplay display, EGLSyncKHR fence, |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 240 | const sp<Fence>& releaseFence); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 241 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 242 | // consumerConnect connects a consumer to the BufferQueue. Only one |
| 243 | // consumer may be connected, and when that consumer disconnects the |
| 244 | // BufferQueue is placed into the "abandoned" state, causing most |
| 245 | // interactions with the BufferQueue by the producer to fail. |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 246 | // controlledByApp indicates whether the consumer is controlled by |
| 247 | // the application. |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 248 | // |
| 249 | // consumer may not be NULL. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 250 | virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 251 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 252 | // consumerDisconnect disconnects a consumer from the BufferQueue. All |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 253 | // buffers will be freed and the BufferQueue is placed in the "abandoned" |
| 254 | // state, causing most interactions with the BufferQueue by the producer to |
| 255 | // fail. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 256 | virtual status_t consumerDisconnect(); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 257 | |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 258 | // getReleasedBuffers sets the value pointed to by slotMask to a bit mask |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 259 | // indicating which buffer slots have been released by the BufferQueue |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 260 | // but have not yet been released by the consumer. |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 261 | // |
| 262 | // This should be called from the onBuffersReleased() callback. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 263 | virtual status_t getReleasedBuffers(uint32_t* slotMask); |
Jamie Gennis | fa5b40e | 2012-03-15 14:01:24 -0700 | [diff] [blame] | 264 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 265 | // setDefaultBufferSize is used to set the size of buffers returned by |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 266 | // dequeueBuffer when a width and height of zero is requested. Default |
| 267 | // is 1x1. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 268 | virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 269 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 270 | // setDefaultMaxBufferCount sets the default value for the maximum buffer |
| 271 | // count (the initial default is 2). If the producer has requested a |
| 272 | // buffer count using setBufferCount, the default buffer count will only |
| 273 | // take effect if the producer sets the count back to zero. |
| 274 | // |
| 275 | // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 276 | virtual status_t setDefaultMaxBufferCount(int bufferCount); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 277 | |
Mathias Agopian | ad678e1 | 2013-07-23 17:28:53 -0700 | [diff] [blame] | 278 | // disableAsyncBuffer disables the extra buffer used in async mode |
| 279 | // (when both producer and consumer have set their "isControlledByApp" |
| 280 | // flag) and has dequeueBuffer() return WOULD_BLOCK instead. |
| 281 | // |
| 282 | // This can only be called before consumerConnect(). |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 283 | virtual status_t disableAsyncBuffer(); |
Mathias Agopian | ad678e1 | 2013-07-23 17:28:53 -0700 | [diff] [blame] | 284 | |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 285 | // setMaxAcquiredBufferCount sets the maximum number of buffers that can |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 286 | // be acquired by the consumer at one time (default 1). This call will |
| 287 | // fail if a producer is connected to the BufferQueue. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 288 | virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); |
Jamie Gennis | 72f096f | 2012-08-27 18:48:37 -0700 | [diff] [blame] | 289 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 290 | // setConsumerName sets the name used in logging |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 291 | virtual void setConsumerName(const String8& name); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 292 | |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 293 | // setDefaultBufferFormat allows the BufferQueue to create |
| 294 | // GraphicBuffers of a defaultFormat if no format is specified |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 295 | // in dequeueBuffer. Formats are enumerated in graphics.h; the |
| 296 | // initial default is HAL_PIXEL_FORMAT_RGBA_8888. |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 297 | virtual status_t setDefaultBufferFormat(uint32_t defaultFormat); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 298 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 299 | // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. |
| 300 | // These are merged with the bits passed to dequeueBuffer. The values are |
| 301 | // 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] | 302 | virtual status_t setConsumerUsageBits(uint32_t usage); |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 303 | |
Andy McFadden | 753e341 | 2013-04-04 17:09:03 -0700 | [diff] [blame] | 304 | // setTransformHint bakes in rotation to buffers so overlays can be used. |
| 305 | // The values are enumerated in window.h, e.g. |
| 306 | // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 307 | virtual status_t setTransformHint(uint32_t hint); |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 308 | |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 309 | // dump our state in a String |
| 310 | virtual void dump(String8& result, const char* prefix) const; |
| 311 | |
Daniel Lam | eae59d2 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 312 | private: |
Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame^] | 313 | sp<BufferQueueProducer> mProducer; |
| 314 | sp<BufferQueueConsumer> mConsumer; |
Daniel Lam | 6b091c5 | 2012-01-22 15:26:27 -0800 | [diff] [blame] | 315 | }; |
| 316 | |
| 317 | // ---------------------------------------------------------------------------- |
| 318 | }; // namespace android |
| 319 | |
| 320 | #endif // ANDROID_GUI_BUFFERQUEUE_H |