1 /* 2 * Copyright (C) 2010 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_IGRAPHICBUFFERPRODUCER_H 18 #define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 #include <utils/Errors.h> 24 #include <utils/RefBase.h> 25 26 #include <binder/IInterface.h> 27 28 #include <ui/Fence.h> 29 #include <ui/GraphicBuffer.h> 30 #include <ui/Rect.h> 31 #include <ui/Region.h> 32 33 #include <gui/FrameTimestamps.h> 34 35 namespace android { 36 // ---------------------------------------------------------------------------- 37 38 class IProducerListener; 39 class NativeHandle; 40 class Surface; 41 42 /* 43 * This class defines the Binder IPC interface for the producer side of 44 * a queue of graphics buffers. It's used to send graphics data from one 45 * component to another. For example, a class that decodes video for 46 * playback might use this to provide frames. This is typically done 47 * indirectly, through Surface. 48 * 49 * The underlying mechanism is a BufferQueue, which implements 50 * BnGraphicBufferProducer. In normal operation, the producer calls 51 * dequeueBuffer() to get an empty buffer, fills it with data, then 52 * calls queueBuffer() to make it available to the consumer. 53 * 54 * This class was previously called ISurfaceTexture. 55 */ 56 class IGraphicBufferProducer : public IInterface 57 { 58 public: 59 DECLARE_META_INTERFACE(GraphicBufferProducer); 60 61 enum { 62 // A flag returned by dequeueBuffer when the client needs to call 63 // requestBuffer immediately thereafter. 64 BUFFER_NEEDS_REALLOCATION = 0x1, 65 // A flag returned by dequeueBuffer when all mirrored slots should be 66 // released by the client. This flag should always be processed first. 67 RELEASE_ALL_BUFFERS = 0x2, 68 }; 69 70 // requestBuffer requests a new buffer for the given index. The server (i.e. 71 // the IGraphicBufferProducer implementation) assigns the newly created 72 // buffer to the given slot index, and the client is expected to mirror the 73 // slot->buffer mapping so that it's not necessary to transfer a 74 // GraphicBuffer for every dequeue operation. 75 // 76 // The slot must be in the range of [0, NUM_BUFFER_SLOTS). 77 // 78 // Return of a value other than NO_ERROR means an error has occurred: 79 // * NO_INIT - the buffer queue has been abandoned or the producer is not 80 // connected. 81 // * BAD_VALUE - one of the two conditions occurred: 82 // * slot was out of range (see above) 83 // * buffer specified by the slot is not dequeued 84 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0; 85 86 // setMaxDequeuedBufferCount sets the maximum number of buffers that can be 87 // dequeued by the producer at one time. If this method succeeds, any new 88 // buffer slots will be both unallocated and owned by the BufferQueue object 89 // (i.e. they are not owned by the producer or consumer). Calling this may 90 // also cause some buffer slots to be emptied. If the caller is caching the 91 // contents of the buffer slots, it should empty that cache after calling 92 // this method. 93 // 94 // This function should not be called with a value of maxDequeuedBuffers 95 // that is less than the number of currently dequeued buffer slots. Doing so 96 // will result in a BAD_VALUE error. 97 // 98 // The buffer count should be at least 1 (inclusive), but at most 99 // (NUM_BUFFER_SLOTS - the minimum undequeued buffer count) (exclusive). The 100 // minimum undequeued buffer count can be obtained by calling 101 // query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS). 102 // 103 // Return of a value other than NO_ERROR means an error has occurred: 104 // * NO_INIT - the buffer queue has been abandoned. 105 // * BAD_VALUE - one of the below conditions occurred: 106 // * bufferCount was out of range (see above). 107 // * client would have more than the requested number of dequeued 108 // buffers after this call. 109 // * this call would cause the maxBufferCount value to be exceeded. 110 // * failure to adjust the number of available slots. 111 virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) = 0; 112 113 // Set the async flag if the producer intends to asynchronously queue 114 // buffers without blocking. Typically this is used for triple-buffering 115 // and/or when the swap interval is set to zero. 116 // 117 // Enabling async mode will internally allocate an additional buffer to 118 // allow for the asynchronous behavior. If it is not enabled queue/dequeue 119 // calls may block. 120 // 121 // Return of a value other than NO_ERROR means an error has occurred: 122 // * NO_INIT - the buffer queue has been abandoned. 123 // * BAD_VALUE - one of the following has occurred: 124 // * this call would cause the maxBufferCount value to be 125 // exceeded 126 // * failure to adjust the number of available slots. 127 virtual status_t setAsyncMode(bool async) = 0; 128 129 // dequeueBuffer requests a new buffer slot for the client to use. Ownership 130 // of the slot is transfered to the client, meaning that the server will not 131 // use the contents of the buffer associated with that slot. 132 // 133 // The slot index returned may or may not contain a buffer (client-side). 134 // If the slot is empty the client should call requestBuffer to assign a new 135 // buffer to that slot. 136 // 137 // Once the client is done filling this buffer, it is expected to transfer 138 // buffer ownership back to the server with either cancelBuffer on 139 // the dequeued slot or to fill in the contents of its associated buffer 140 // contents and call queueBuffer. 141 // 142 // If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is 143 // expected to call requestBuffer immediately. 144 // 145 // If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is 146 // expected to release all of the mirrored slot->buffer mappings. 147 // 148 // The fence parameter will be updated to hold the fence associated with 149 // the buffer. The contents of the buffer must not be overwritten until the 150 // fence signals. If the fence is Fence::NO_FENCE, the buffer may be written 151 // immediately. 152 // 153 // The width and height parameters must be no greater than the minimum of 154 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). 155 // An error due to invalid dimensions might not be reported until 156 // updateTexImage() is called. If width and height are both zero, the 157 // default values specified by setDefaultBufferSize() are used instead. 158 // 159 // If the format is 0, the default format will be used. 160 // 161 // The usage argument specifies gralloc buffer usage flags. The values 162 // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER. These 163 // will be merged with the usage flags specified by 164 // IGraphicBufferConsumer::setConsumerUsageBits. 165 // 166 // This call will block until a buffer is available to be dequeued. If 167 // both the producer and consumer are controlled by the app, then this call 168 // can never block and will return WOULD_BLOCK if no buffer is available. 169 // 170 // A non-negative value with flags set (see above) will be returned upon 171 // success. 172 // 173 // Return of a negative means an error has occurred: 174 // * NO_INIT - the buffer queue has been abandoned or the producer is not 175 // connected. 176 // * BAD_VALUE - both in async mode and buffer count was less than the 177 // max numbers of buffers that can be allocated at once. 178 // * INVALID_OPERATION - cannot attach the buffer because it would cause 179 // too many buffers to be dequeued, either because 180 // the producer already has a single buffer dequeued 181 // and did not set a buffer count, or because a 182 // buffer count was set and this call would cause 183 // it to be exceeded. 184 // * WOULD_BLOCK - no buffer is currently available, and blocking is disabled 185 // since both the producer/consumer are controlled by app 186 // * NO_MEMORY - out of memory, cannot allocate the graphics buffer. 187 // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while 188 // waiting for a buffer to become available. 189 // 190 // All other negative values are an unknown error returned downstream 191 // from the graphics allocator (typically errno). 192 virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, 193 uint32_t h, PixelFormat format, uint32_t usage) = 0; 194 195 // detachBuffer attempts to remove all ownership of the buffer in the given 196 // slot from the buffer queue. If this call succeeds, the slot will be 197 // freed, and there will be no way to obtain the buffer from this interface. 198 // The freed slot will remain unallocated until either it is selected to 199 // hold a freshly allocated buffer in dequeueBuffer or a buffer is attached 200 // to the slot. The buffer must have already been dequeued, and the caller 201 // must already possesses the sp<GraphicBuffer> (i.e., must have called 202 // requestBuffer). 203 // 204 // Return of a value other than NO_ERROR means an error has occurred: 205 // * NO_INIT - the buffer queue has been abandoned or the producer is not 206 // connected. 207 // * BAD_VALUE - the given slot number is invalid, either because it is 208 // out of the range [0, NUM_BUFFER_SLOTS), or because the slot 209 // it refers to is not currently dequeued and requested. 210 virtual status_t detachBuffer(int slot) = 0; 211 212 // detachNextBuffer is equivalent to calling dequeueBuffer, requestBuffer, 213 // and detachBuffer in sequence, except for two things: 214 // 215 // 1) It is unnecessary to know the dimensions, format, or usage of the 216 // next buffer. 217 // 2) It will not block, since if it cannot find an appropriate buffer to 218 // return, it will return an error instead. 219 // 220 // Only slots that are free but still contain a GraphicBuffer will be 221 // considered, and the oldest of those will be returned. outBuffer is 222 // equivalent to outBuffer from the requestBuffer call, and outFence is 223 // equivalent to fence from the dequeueBuffer call. 224 // 225 // Return of a value other than NO_ERROR means an error has occurred: 226 // * NO_INIT - the buffer queue has been abandoned or the producer is not 227 // connected. 228 // * BAD_VALUE - either outBuffer or outFence were NULL. 229 // * NO_MEMORY - no slots were found that were both free and contained a 230 // GraphicBuffer. 231 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, 232 sp<Fence>* outFence) = 0; 233 234 // attachBuffer attempts to transfer ownership of a buffer to the buffer 235 // queue. If this call succeeds, it will be as if this buffer was dequeued 236 // from the returned slot number. As such, this call will fail if attaching 237 // this buffer would cause too many buffers to be simultaneously dequeued. 238 // 239 // If attachBuffer returns the RELEASE_ALL_BUFFERS flag, the caller is 240 // expected to release all of the mirrored slot->buffer mappings. 241 // 242 // A non-negative value with flags set (see above) will be returned upon 243 // success. 244 // 245 // Return of a negative value means an error has occurred: 246 // * NO_INIT - the buffer queue has been abandoned or the producer is not 247 // connected. 248 // * BAD_VALUE - outSlot or buffer were NULL, invalid combination of 249 // async mode and buffer count override, or the generation 250 // number of the buffer did not match the buffer queue. 251 // * INVALID_OPERATION - cannot attach the buffer because it would cause 252 // too many buffers to be dequeued, either because 253 // the producer already has a single buffer dequeued 254 // and did not set a buffer count, or because a 255 // buffer count was set and this call would cause 256 // it to be exceeded. 257 // * WOULD_BLOCK - no buffer slot is currently available, and blocking is 258 // disabled since both the producer/consumer are 259 // controlled by the app. 260 // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while 261 // waiting for a slot to become available. 262 virtual status_t attachBuffer(int* outSlot, 263 const sp<GraphicBuffer>& buffer) = 0; 264 265 // queueBuffer indicates that the client has finished filling in the 266 // contents of the buffer associated with slot and transfers ownership of 267 // that slot back to the server. 268 // 269 // It is not valid to call queueBuffer on a slot that is not owned 270 // by the client or one for which a buffer associated via requestBuffer 271 // (an attempt to do so will fail with a return value of BAD_VALUE). 272 // 273 // In addition, the input must be described by the client (as documented 274 // below). Any other properties (zero point, etc) 275 // are client-dependent, and should be documented by the client. 276 // 277 // The slot must be in the range of [0, NUM_BUFFER_SLOTS). 278 // 279 // Upon success, the output will be filled with meaningful values 280 // (refer to the documentation below). 281 // 282 // Return of a value other than NO_ERROR means an error has occurred: 283 // * NO_INIT - the buffer queue has been abandoned or the producer is not 284 // connected. 285 // * BAD_VALUE - one of the below conditions occurred: 286 // * fence was NULL 287 // * scaling mode was unknown 288 // * both in async mode and buffer count was less than the 289 // max numbers of buffers that can be allocated at once 290 // * slot index was out of range (see above). 291 // * the slot was not in the dequeued state 292 // * the slot was enqueued without requesting a buffer 293 // * crop rect is out of bounds of the buffer dimensions 294 295 struct QueueBufferInput : public Flattenable<QueueBufferInput> { 296 friend class Flattenable<QueueBufferInput>; 297 inline QueueBufferInput(const Parcel& parcel); 298 // timestamp - a monotonically increasing value in nanoseconds 299 // isAutoTimestamp - if the timestamp was synthesized at queue time 300 // dataSpace - description of the contents, interpretation depends on format 301 // crop - a crop rectangle that's used as a hint to the consumer 302 // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h> 303 // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h> 304 // fence - a fence that the consumer must wait on before reading the buffer, 305 // set this to Fence::NO_FENCE if the buffer is ready immediately 306 // sticky - the sticky transform set in Surface (only used by the LEGACY 307 // camera mode). 308 inline QueueBufferInput(int64_t timestamp, bool isAutoTimestamp, 309 android_dataspace dataSpace, const Rect& crop, int scalingMode, 310 uint32_t transform, const sp<Fence>& fence, uint32_t sticky = 0) 311 : timestamp(timestamp), isAutoTimestamp(isAutoTimestamp), 312 dataSpace(dataSpace), crop(crop), scalingMode(scalingMode), 313 transform(transform), stickyTransform(sticky), fence(fence), 314 surfaceDamage() { } 315 inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp, 316 android_dataspace* outDataSpace, 317 Rect* outCrop, int* outScalingMode, 318 uint32_t* outTransform, sp<Fence>* outFence, 319 uint32_t* outStickyTransform = NULL) const { 320 *outTimestamp = timestamp; 321 *outIsAutoTimestamp = bool(isAutoTimestamp); 322 *outDataSpace = dataSpace; 323 *outCrop = crop; 324 *outScalingMode = scalingMode; 325 *outTransform = transform; 326 *outFence = fence; 327 if (outStickyTransform != NULL) { 328 *outStickyTransform = stickyTransform; 329 } 330 } 331 332 // Flattenable protocol 333 size_t getFlattenedSize() const; 334 size_t getFdCount() const; 335 status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; 336 status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); 337 338 const Region& getSurfaceDamage() const { return surfaceDamage; } 339 void setSurfaceDamage(const Region& damage) { surfaceDamage = damage; } 340 341 private: 342 int64_t timestamp; 343 int isAutoTimestamp; 344 android_dataspace dataSpace; 345 Rect crop; 346 int scalingMode; 347 uint32_t transform; 348 uint32_t stickyTransform; 349 sp<Fence> fence; 350 Region surfaceDamage; 351 }; 352 353 // QueueBufferOutput must be a POD structure 354 struct __attribute__ ((__packed__)) QueueBufferOutput { 355 inline QueueBufferOutput() { } 356 // outWidth - filled with default width applied to the buffer 357 // outHeight - filled with default height applied to the buffer 358 // outTransformHint - filled with default transform applied to the buffer 359 // outNumPendingBuffers - num buffers queued that haven't yet been acquired 360 // (counting the currently queued buffer) 361 inline void deflate(uint32_t* outWidth, 362 uint32_t* outHeight, 363 uint32_t* outTransformHint, 364 uint32_t* outNumPendingBuffers, 365 uint64_t* outNextFrameNumber) const { 366 *outWidth = width; 367 *outHeight = height; 368 *outTransformHint = transformHint; 369 *outNumPendingBuffers = numPendingBuffers; 370 *outNextFrameNumber = nextFrameNumber; 371 } 372 inline void inflate(uint32_t inWidth, uint32_t inHeight, 373 uint32_t inTransformHint, uint32_t inNumPendingBuffers, 374 uint64_t inNextFrameNumber) { 375 width = inWidth; 376 height = inHeight; 377 transformHint = inTransformHint; 378 numPendingBuffers = inNumPendingBuffers; 379 nextFrameNumber = inNextFrameNumber; 380 } 381 private: 382 uint32_t width; 383 uint32_t height; 384 uint32_t transformHint; 385 uint32_t numPendingBuffers; 386 uint64_t nextFrameNumber{0}; 387 }; 388 389 virtual status_t queueBuffer(int slot, const QueueBufferInput& input, 390 QueueBufferOutput* output) = 0; 391 392 // cancelBuffer indicates that the client does not wish to fill in the 393 // buffer associated with slot and transfers ownership of the slot back to 394 // the server. 395 // 396 // The buffer is not queued for use by the consumer. 397 // 398 // The slot must be in the range of [0, NUM_BUFFER_SLOTS). 399 // 400 // The buffer will not be overwritten until the fence signals. The fence 401 // will usually be the one obtained from dequeueBuffer. 402 // 403 // Return of a value other than NO_ERROR means an error has occurred: 404 // * NO_INIT - the buffer queue has been abandoned or the producer is not 405 // connected. 406 // * BAD_VALUE - one of the below conditions occurred: 407 // * fence was NULL 408 // * slot index was out of range (see above). 409 // * the slot was not in the dequeued state 410 virtual status_t cancelBuffer(int slot, const sp<Fence>& fence) = 0; 411 412 // query retrieves some information for this surface 413 // 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h> 414 // 415 // Return of a value other than NO_ERROR means an error has occurred: 416 // * NO_INIT - the buffer queue has been abandoned. 417 // * BAD_VALUE - what was out of range 418 virtual int query(int what, int* value) = 0; 419 420 // connect attempts to connect a client API to the IGraphicBufferProducer. 421 // This must be called before any other IGraphicBufferProducer methods are 422 // called except for getAllocator. A consumer must be already connected. 423 // 424 // This method will fail if the connect was previously called on the 425 // IGraphicBufferProducer and no corresponding disconnect call was made. 426 // 427 // The listener is an optional binder callback object that can be used if 428 // the producer wants to be notified when the consumer releases a buffer 429 // back to the BufferQueue. It is also used to detect the death of the 430 // producer. If only the latter functionality is desired, there is a 431 // DummyProducerListener class in IProducerListener.h that can be used. 432 // 433 // The api should be one of the NATIVE_WINDOW_API_* values in <window.h> 434 // 435 // The producerControlledByApp should be set to true if the producer is hosted 436 // by an untrusted process (typically app_process-forked processes). If both 437 // the producer and the consumer are app-controlled then all buffer queues 438 // will operate in async mode regardless of the async flag. 439 // 440 // Upon success, the output will be filled with meaningful data 441 // (refer to QueueBufferOutput documentation above). 442 // 443 // Return of a value other than NO_ERROR means an error has occurred: 444 // * NO_INIT - one of the following occurred: 445 // * the buffer queue was abandoned 446 // * no consumer has yet connected 447 // * BAD_VALUE - one of the following has occurred: 448 // * the producer is already connected 449 // * api was out of range (see above). 450 // * output was NULL. 451 // * Failure to adjust the number of available slots. This can 452 // happen because of trying to allocate/deallocate the async 453 // buffer in response to the value of producerControlledByApp. 454 // * DEAD_OBJECT - the token is hosted by an already-dead process 455 // 456 // Additional negative errors may be returned by the internals, they 457 // should be treated as opaque fatal unrecoverable errors. 458 virtual status_t connect(const sp<IProducerListener>& listener, 459 int api, bool producerControlledByApp, QueueBufferOutput* output) = 0; 460 461 enum class DisconnectMode { 462 // Disconnect only the specified API. 463 Api, 464 // Disconnect any API originally connected from the process calling disconnect. 465 AllLocal 466 }; 467 468 // disconnect attempts to disconnect a client API from the 469 // IGraphicBufferProducer. Calling this method will cause any subsequent 470 // calls to other IGraphicBufferProducer methods to fail except for 471 // getAllocator and connect. Successfully calling connect after this will 472 // allow the other methods to succeed again. 473 // 474 // The api should be one of the NATIVE_WINDOW_API_* values in <window.h> 475 // 476 // Alternatively if mode is AllLocal, then the API value is ignored, and any API 477 // connected from the same PID calling disconnect will be disconnected. 478 // 479 // Disconnecting from an abandoned IGraphicBufferProducer is legal and 480 // is considered a no-op. 481 // 482 // Return of a value other than NO_ERROR means an error has occurred: 483 // * BAD_VALUE - one of the following has occurred: 484 // * the api specified does not match the one that was connected 485 // * api was out of range (see above). 486 // * DEAD_OBJECT - the token is hosted by an already-dead process 487 virtual status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api) = 0; 488 489 // Attaches a sideband buffer stream to the IGraphicBufferProducer. 490 // 491 // A sideband stream is a device-specific mechanism for passing buffers 492 // from the producer to the consumer without using dequeueBuffer/ 493 // queueBuffer. If a sideband stream is present, the consumer can choose 494 // whether to acquire buffers from the sideband stream or from the queued 495 // buffers. 496 // 497 // Passing NULL or a different stream handle will detach the previous 498 // handle if any. 499 virtual status_t setSidebandStream(const sp<NativeHandle>& stream) = 0; 500 501 // Allocates buffers based on the given dimensions/format. 502 // 503 // This function will allocate up to the maximum number of buffers 504 // permitted by the current BufferQueue configuration. It will use the 505 // given format, dimensions, and usage bits, which are interpreted in the 506 // same way as for dequeueBuffer, and the async flag must be set the same 507 // way as for dequeueBuffer to ensure that the correct number of buffers are 508 // allocated. This is most useful to avoid an allocation delay during 509 // dequeueBuffer. If there are already the maximum number of buffers 510 // allocated, this function has no effect. 511 virtual void allocateBuffers(uint32_t width, uint32_t height, 512 PixelFormat format, uint32_t usage) = 0; 513 514 // Sets whether dequeueBuffer is allowed to allocate new buffers. 515 // 516 // Normally dequeueBuffer does not discriminate between free slots which 517 // already have an allocated buffer and those which do not, and will 518 // allocate a new buffer if the slot doesn't have a buffer or if the slot's 519 // buffer doesn't match the requested size, format, or usage. This method 520 // allows the producer to restrict the eligible slots to those which already 521 // have an allocated buffer of the correct size, format, and usage. If no 522 // eligible slot is available, dequeueBuffer will block or return an error 523 // as usual. 524 virtual status_t allowAllocation(bool allow) = 0; 525 526 // Sets the current generation number of the BufferQueue. 527 // 528 // This generation number will be inserted into any buffers allocated by the 529 // BufferQueue, and any attempts to attach a buffer with a different 530 // generation number will fail. Buffers already in the queue are not 531 // affected and will retain their current generation number. The generation 532 // number defaults to 0. 533 virtual status_t setGenerationNumber(uint32_t generationNumber) = 0; 534 535 // Returns the name of the connected consumer. 536 virtual String8 getConsumerName() const = 0; 537 538 // Used to enable/disable shared buffer mode. 539 // 540 // When shared buffer mode is enabled the first buffer that is queued or 541 // dequeued will be cached and returned to all subsequent calls to 542 // dequeueBuffer and acquireBuffer. This allows the producer and consumer to 543 // simultaneously access the same buffer. 544 virtual status_t setSharedBufferMode(bool sharedBufferMode) = 0; 545 546 // Used to enable/disable auto-refresh. 547 // 548 // Auto refresh has no effect outside of shared buffer mode. In shared 549 // buffer mode, when enabled, it indicates to the consumer that it should 550 // attempt to acquire buffers even if it is not aware of any being 551 // available. 552 virtual status_t setAutoRefresh(bool autoRefresh) = 0; 553 554 // Sets how long dequeueBuffer will wait for a buffer to become available 555 // before returning an error (TIMED_OUT). 556 // 557 // This timeout also affects the attachBuffer call, which will block if 558 // there is not a free slot available into which the attached buffer can be 559 // placed. 560 // 561 // By default, the BufferQueue will wait forever, which is indicated by a 562 // timeout of -1. If set (to a value other than -1), this will disable 563 // non-blocking mode and its corresponding spare buffer (which is used to 564 // ensure a buffer is always available). 565 // 566 // Return of a value other than NO_ERROR means an error has occurred: 567 // * BAD_VALUE - Failure to adjust the number of available slots. This can 568 // happen because of trying to allocate/deallocate the async 569 // buffer. 570 virtual status_t setDequeueTimeout(nsecs_t timeout) = 0; 571 572 // Returns the last queued buffer along with a fence which must signal 573 // before the contents of the buffer are read. If there are no buffers in 574 // the queue, outBuffer will be populated with nullptr and outFence will be 575 // populated with Fence::NO_FENCE 576 // 577 // outTransformMatrix is not modified if outBuffer is null. 578 // 579 // Returns NO_ERROR or the status of the Binder transaction 580 virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, 581 sp<Fence>* outFence, float outTransformMatrix[16]) = 0; 582 583 // Attempts to retrieve timestamp information for the given frame number. 584 // If information for the given frame number is not found, returns false. 585 // Returns true otherwise. 586 // 587 // If a fence has not yet signaled the timestamp returned will be 0; 588 virtual bool getFrameTimestamps(uint64_t /*frameNumber*/, 589 FrameTimestamps* /*outTimestamps*/) const { return false; } 590 591 // Returns a unique id for this BufferQueue 592 virtual status_t getUniqueId(uint64_t* outId) const = 0; 593 }; 594 595 // ---------------------------------------------------------------------------- 596 597 class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer> 598 { 599 public: 600 virtual status_t onTransact( uint32_t code, 601 const Parcel& data, 602 Parcel* reply, 603 uint32_t flags = 0); 604 }; 605 606 // ---------------------------------------------------------------------------- 607 }; // namespace android 608 609 #endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H 610