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