widget/gonk/nativewindow/GonkBufferQueueKK.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial