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_SURFACE_H 18 #define ANDROID_GUI_SURFACE_H 19 20 #include <gui/BufferQueueDefs.h> 21 #include <gui/FrameTimelineInfo.h> 22 #include <gui/HdrMetadata.h> 23 #include <gui/IGraphicBufferProducer.h> 24 #include <gui/IProducerListener.h> 25 #include <system/window.h> 26 #include <ui/ANativeObjectBase.h> 27 #include <ui/GraphicTypes.h> 28 #include <ui/Region.h> 29 #include <utils/Condition.h> 30 #include <utils/Mutex.h> 31 #include <utils/RefBase.h> 32 33 #include <shared_mutex> 34 #include <unordered_set> 35 36 namespace android { 37 38 class ISurfaceComposer; 39 40 /* This is the same as ProducerListener except that onBuffersDiscarded is 41 * called with a vector of graphic buffers instead of buffer slots. 42 */ 43 class SurfaceListener : public virtual RefBase 44 { 45 public: 46 SurfaceListener() = default; 47 virtual ~SurfaceListener() = default; 48 49 virtual void onBufferReleased() = 0; 50 virtual bool needsReleaseNotify() = 0; 51 52 virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& buffers) = 0; 53 }; 54 55 /* 56 * An implementation of ANativeWindow that feeds graphics buffers into a 57 * BufferQueue. 58 * 59 * This is typically used by programs that want to render frames through 60 * some means (maybe OpenGL, a software renderer, or a hardware decoder) 61 * and have the frames they create forwarded to SurfaceFlinger for 62 * compositing. For example, a video decoder could render a frame and call 63 * eglSwapBuffers(), which invokes ANativeWindow callbacks defined by 64 * Surface. Surface then forwards the buffers through Binder IPC 65 * to the BufferQueue's producer interface, providing the new frame to a 66 * consumer such as GLConsumer. 67 */ 68 class Surface 69 : public ANativeObjectBase<ANativeWindow, Surface, RefBase> 70 { 71 public: 72 /* 73 * creates a Surface from the given IGraphicBufferProducer (which concrete 74 * implementation is a BufferQueue). 75 * 76 * Surface is mainly state-less while it's disconnected, it can be 77 * viewed as a glorified IGraphicBufferProducer holder. It's therefore 78 * safe to create other Surfaces from the same IGraphicBufferProducer. 79 * 80 * However, once a Surface is connected, it'll prevent other Surfaces 81 * referring to the same IGraphicBufferProducer to become connected and 82 * therefore prevent them to be used as actual producers of buffers. 83 * 84 * the controlledByApp flag indicates that this Surface (producer) is 85 * controlled by the application. This flag is used at connect time. 86 * 87 * Pass in the SurfaceControlHandle to store a weak reference to the layer 88 * that the Surface was created from. This handle can be used to create a 89 * child surface without using the IGBP to identify the layer. This is used 90 * for surfaces created by the BlastBufferQueue whose IGBP is created on the 91 * client and cannot be verified in SF. 92 */ 93 explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false, 94 const sp<IBinder>& surfaceControlHandle = nullptr); 95 96 /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this 97 * Surface was created with. Usually it's an error to use the 98 * IGraphicBufferProducer while the Surface is connected. 99 */ 100 sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; 101 getSurfaceControlHandle()102 sp<IBinder> getSurfaceControlHandle() const { return mSurfaceControlHandle; } 103 104 /* convenience function to check that the given surface is non NULL as 105 * well as its IGraphicBufferProducer */ isValid(const sp<Surface> & surface)106 static bool isValid(const sp<Surface>& surface) { 107 return surface != nullptr && surface->getIGraphicBufferProducer() != nullptr; 108 } 109 110 /* Attaches a sideband buffer stream to the Surface's IGraphicBufferProducer. 111 * 112 * A sideband stream is a device-specific mechanism for passing buffers 113 * from the producer to the consumer without using dequeueBuffer/ 114 * queueBuffer. If a sideband stream is present, the consumer can choose 115 * whether to acquire buffers from the sideband stream or from the queued 116 * buffers. 117 * 118 * Passing NULL or a different stream handle will detach the previous 119 * handle if any. 120 */ 121 void setSidebandStream(const sp<NativeHandle>& stream); 122 123 /* Allocates buffers based on the current dimensions/format. 124 * 125 * This function will allocate up to the maximum number of buffers 126 * permitted by the current BufferQueue configuration. It will use the 127 * default format and dimensions. This is most useful to avoid an allocation 128 * delay during dequeueBuffer. If there are already the maximum number of 129 * buffers allocated, this function has no effect. 130 */ 131 virtual void allocateBuffers(); 132 133 /* Sets the generation number on the IGraphicBufferProducer and updates the 134 * generation number on any buffers attached to the Surface after this call. 135 * See IGBP::setGenerationNumber for more information. */ 136 status_t setGenerationNumber(uint32_t generationNumber); 137 138 // See IGraphicBufferProducer::getConsumerName 139 String8 getConsumerName() const; 140 141 // See IGraphicBufferProducer::getNextFrameNumber 142 uint64_t getNextFrameNumber() const; 143 144 /* Set the scaling mode to be used with a Surface. 145 * See NATIVE_WINDOW_SET_SCALING_MODE and its parameters 146 * in <system/window.h>. */ 147 int setScalingMode(int mode); 148 149 // See IGraphicBufferProducer::setDequeueTimeout 150 status_t setDequeueTimeout(nsecs_t timeout); 151 152 /* 153 * Wait for frame number to increase past lastFrame for at most 154 * timeoutNs. Useful for one thread to wait for another unknown 155 * thread to queue a buffer. 156 */ 157 bool waitForNextFrame(uint64_t lastFrame, nsecs_t timeout); 158 159 // See IGraphicBufferProducer::getLastQueuedBuffer 160 // See GLConsumer::getTransformMatrix for outTransformMatrix format 161 status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, 162 sp<Fence>* outFence, float outTransformMatrix[16]); 163 164 status_t getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration); 165 166 /* Enables or disables frame timestamp tracking. It is disabled by default 167 * to avoid overhead during queue and dequeue for applications that don't 168 * need the feature. If disabled, calls to getFrameTimestamps will fail. 169 */ 170 void enableFrameTimestamps(bool enable); 171 172 status_t getCompositorTiming( 173 nsecs_t* compositeDeadline, nsecs_t* compositeInterval, 174 nsecs_t* compositeToPresentLatency); 175 176 // See IGraphicBufferProducer::getFrameTimestamps 177 status_t getFrameTimestamps(uint64_t frameNumber, 178 nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime, 179 nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime, 180 nsecs_t* outLastRefreshStartTime, nsecs_t* outGlCompositionDoneTime, 181 nsecs_t* outDisplayPresentTime, nsecs_t* outDequeueReadyTime, 182 nsecs_t* outReleaseTime); 183 184 status_t getWideColorSupport(bool* supported); 185 status_t getHdrSupport(bool* supported); 186 187 status_t getUniqueId(uint64_t* outId) const; 188 status_t getConsumerUsage(uint64_t* outUsage) const; 189 190 virtual status_t setFrameRate(float frameRate, int8_t compatibility, 191 int8_t changeFrameRateStrategy); 192 virtual status_t setFrameTimelineInfo(const FrameTimelineInfo& info); 193 194 protected: 195 virtual ~Surface(); 196 197 // Virtual for testing. 198 virtual sp<ISurfaceComposer> composerService() const; 199 virtual nsecs_t now() const; 200 201 private: 202 // can't be copied 203 Surface& operator = (const Surface& rhs); 204 Surface(const Surface& rhs); 205 206 // ANativeWindow hooks 207 static int hook_cancelBuffer(ANativeWindow* window, 208 ANativeWindowBuffer* buffer, int fenceFd); 209 static int hook_dequeueBuffer(ANativeWindow* window, 210 ANativeWindowBuffer** buffer, int* fenceFd); 211 static int hook_perform(ANativeWindow* window, int operation, ...); 212 static int hook_query(const ANativeWindow* window, int what, int* value); 213 static int hook_queueBuffer(ANativeWindow* window, 214 ANativeWindowBuffer* buffer, int fenceFd); 215 static int hook_setSwapInterval(ANativeWindow* window, int interval); 216 217 static int cancelBufferInternal(ANativeWindow* window, ANativeWindowBuffer* buffer, 218 int fenceFd); 219 static int dequeueBufferInternal(ANativeWindow* window, ANativeWindowBuffer** buffer, 220 int* fenceFd); 221 static int performInternal(ANativeWindow* window, int operation, va_list args); 222 static int queueBufferInternal(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd); 223 static int queryInternal(const ANativeWindow* window, int what, int* value); 224 225 static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window, 226 ANativeWindowBuffer* buffer); 227 static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, 228 ANativeWindowBuffer** buffer); 229 static int hook_lockBuffer_DEPRECATED(ANativeWindow* window, 230 ANativeWindowBuffer* buffer); 231 static int hook_queueBuffer_DEPRECATED(ANativeWindow* window, 232 ANativeWindowBuffer* buffer); 233 234 int dispatchConnect(va_list args); 235 int dispatchDisconnect(va_list args); 236 int dispatchSetBufferCount(va_list args); 237 int dispatchSetBuffersGeometry(va_list args); 238 int dispatchSetBuffersDimensions(va_list args); 239 int dispatchSetBuffersUserDimensions(va_list args); 240 int dispatchSetBuffersFormat(va_list args); 241 int dispatchSetScalingMode(va_list args); 242 int dispatchSetBuffersTransform(va_list args); 243 int dispatchSetBuffersStickyTransform(va_list args); 244 int dispatchSetBuffersTimestamp(va_list args); 245 int dispatchSetCrop(va_list args); 246 int dispatchSetUsage(va_list args); 247 int dispatchSetUsage64(va_list args); 248 int dispatchLock(va_list args); 249 int dispatchUnlockAndPost(va_list args); 250 int dispatchSetSidebandStream(va_list args); 251 int dispatchSetBuffersDataSpace(va_list args); 252 int dispatchSetBuffersSmpte2086Metadata(va_list args); 253 int dispatchSetBuffersCta8613Metadata(va_list args); 254 int dispatchSetBuffersHdr10PlusMetadata(va_list args); 255 int dispatchSetSurfaceDamage(va_list args); 256 int dispatchSetSharedBufferMode(va_list args); 257 int dispatchSetAutoRefresh(va_list args); 258 int dispatchGetDisplayRefreshCycleDuration(va_list args); 259 int dispatchGetNextFrameId(va_list args); 260 int dispatchEnableFrameTimestamps(va_list args); 261 int dispatchGetCompositorTiming(va_list args); 262 int dispatchGetFrameTimestamps(va_list args); 263 int dispatchGetWideColorSupport(va_list args); 264 int dispatchGetHdrSupport(va_list args); 265 int dispatchGetConsumerUsage64(va_list args); 266 int dispatchSetAutoPrerotation(va_list args); 267 int dispatchGetLastDequeueStartTime(va_list args); 268 int dispatchSetDequeueTimeout(va_list args); 269 int dispatchGetLastDequeueDuration(va_list args); 270 int dispatchGetLastQueueDuration(va_list args); 271 int dispatchSetFrameRate(va_list args); 272 int dispatchAddCancelInterceptor(va_list args); 273 int dispatchAddDequeueInterceptor(va_list args); 274 int dispatchAddPerformInterceptor(va_list args); 275 int dispatchAddQueueInterceptor(va_list args); 276 int dispatchAddQueryInterceptor(va_list args); 277 int dispatchGetLastQueuedBuffer(va_list args); 278 int dispatchGetLastQueuedBuffer2(va_list args); 279 int dispatchSetFrameTimelineInfo(va_list args); 280 281 protected: 282 virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd); 283 virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd); 284 virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd); 285 virtual int perform(int operation, va_list args); 286 virtual int setSwapInterval(int interval); 287 288 virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer); 289 290 virtual int connect(int api); 291 virtual int setBufferCount(int bufferCount); 292 virtual int setBuffersUserDimensions(uint32_t width, uint32_t height); 293 virtual int setBuffersFormat(PixelFormat format); 294 virtual int setBuffersTransform(uint32_t transform); 295 virtual int setBuffersStickyTransform(uint32_t transform); 296 virtual int setBuffersTimestamp(int64_t timestamp); 297 virtual int setBuffersDataSpace(ui::Dataspace dataSpace); 298 virtual int setBuffersSmpte2086Metadata(const android_smpte2086_metadata* metadata); 299 virtual int setBuffersCta8613Metadata(const android_cta861_3_metadata* metadata); 300 virtual int setBuffersHdr10PlusMetadata(const size_t size, const uint8_t* metadata); 301 virtual int setCrop(Rect const* rect); 302 virtual int setUsage(uint64_t reqUsage); 303 virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects); 304 305 public: 306 virtual int disconnect(int api, 307 IGraphicBufferProducer::DisconnectMode mode = 308 IGraphicBufferProducer::DisconnectMode::Api); 309 310 virtual int setMaxDequeuedBufferCount(int maxDequeuedBuffers); 311 virtual int setAsyncMode(bool async); 312 virtual int setSharedBufferMode(bool sharedBufferMode); 313 virtual int setAutoRefresh(bool autoRefresh); 314 virtual int setAutoPrerotation(bool autoPrerotation); 315 virtual int setBuffersDimensions(uint32_t width, uint32_t height); 316 virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds); 317 virtual int unlockAndPost(); 318 virtual int query(int what, int* value) const; 319 320 virtual int connect(int api, const sp<IProducerListener>& listener); 321 322 // When reportBufferRemoval is true, clients must call getAndFlushRemovedBuffers to fetch 323 // GraphicBuffers removed from this surface after a dequeueBuffer, detachNextBuffer or 324 // attachBuffer call. This allows clients with their own buffer caches to free up buffers no 325 // longer in use by this surface. 326 virtual int connect( 327 int api, const sp<IProducerListener>& listener, 328 bool reportBufferRemoval); 329 virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer, 330 sp<Fence>* outFence); 331 virtual int attachBuffer(ANativeWindowBuffer*); 332 333 virtual int connect( 334 int api, bool reportBufferRemoval, 335 const sp<SurfaceListener>& sListener); 336 337 // When client connects to Surface with reportBufferRemoval set to true, any buffers removed 338 // from this Surface will be collected and returned here. Once this method returns, these 339 // buffers will no longer be referenced by this Surface unless they are attached to this 340 // Surface later. The list of removed buffers will only be stored until the next dequeueBuffer, 341 // detachNextBuffer, or attachBuffer call. 342 status_t getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out); 343 344 ui::Dataspace getBuffersDataSpace(); 345 346 static status_t attachAndQueueBufferWithDataspace(Surface* surface, sp<GraphicBuffer> buffer, 347 ui::Dataspace dataspace); 348 349 // Batch version of dequeueBuffer, cancelBuffer and queueBuffer 350 // Note that these batched operations are not supported when shared buffer mode is being used. 351 struct BatchBuffer { 352 ANativeWindowBuffer* buffer = nullptr; 353 int fenceFd = -1; 354 }; 355 virtual int dequeueBuffers(std::vector<BatchBuffer>* buffers); 356 virtual int cancelBuffers(const std::vector<BatchBuffer>& buffers); 357 358 struct BatchQueuedBuffer { 359 ANativeWindowBuffer* buffer = nullptr; 360 int fenceFd = -1; 361 nsecs_t timestamp = NATIVE_WINDOW_TIMESTAMP_AUTO; 362 }; 363 virtual int queueBuffers( 364 const std::vector<BatchQueuedBuffer>& buffers); 365 366 protected: 367 enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS }; 368 enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; 369 370 class ProducerListenerProxy : public BnProducerListener { 371 public: ProducerListenerProxy(wp<Surface> parent,sp<SurfaceListener> listener)372 ProducerListenerProxy(wp<Surface> parent, sp<SurfaceListener> listener) 373 : mParent(parent), mSurfaceListener(listener) {} ~ProducerListenerProxy()374 virtual ~ProducerListenerProxy() {} 375 onBufferReleased()376 virtual void onBufferReleased() { 377 mSurfaceListener->onBufferReleased(); 378 } 379 needsReleaseNotify()380 virtual bool needsReleaseNotify() { 381 return mSurfaceListener->needsReleaseNotify(); 382 } 383 384 virtual void onBuffersDiscarded(const std::vector<int32_t>& slots); 385 private: 386 wp<Surface> mParent; 387 sp<SurfaceListener> mSurfaceListener; 388 }; 389 390 void querySupportedTimestampsLocked() const; 391 392 void freeAllBuffers(); 393 int getSlotFromBufferLocked(android_native_buffer_t* buffer) const; 394 395 void getDequeueBufferInputLocked(IGraphicBufferProducer::DequeueBufferInput* dequeueInput); 396 397 void getQueueBufferInputLocked(android_native_buffer_t* buffer, int fenceFd, nsecs_t timestamp, 398 IGraphicBufferProducer::QueueBufferInput* out); 399 400 void onBufferQueuedLocked(int slot, sp<Fence> fence, 401 const IGraphicBufferProducer::QueueBufferOutput& output); 402 403 struct BufferSlot { 404 sp<GraphicBuffer> buffer; 405 Region dirtyRegion; 406 }; 407 408 // mSurfaceTexture is the interface to the surface texture server. All 409 // operations on the surface texture client ultimately translate into 410 // interactions with the server using this interface. 411 // TODO: rename to mBufferProducer 412 sp<IGraphicBufferProducer> mGraphicBufferProducer; 413 414 // mSlots stores the buffers that have been allocated for each buffer slot. 415 // It is initialized to null pointers, and gets filled in with the result of 416 // IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a 417 // slot that has not yet been used. The buffer allocated to a slot will also 418 // be replaced if the requested buffer usage or geometry differs from that 419 // of the buffer allocated to a slot. 420 BufferSlot mSlots[NUM_BUFFER_SLOTS]; 421 422 // mReqWidth is the buffer width that will be requested at the next dequeue 423 // operation. It is initialized to 1. 424 uint32_t mReqWidth; 425 426 // mReqHeight is the buffer height that will be requested at the next 427 // dequeue operation. It is initialized to 1. 428 uint32_t mReqHeight; 429 430 // mReqFormat is the buffer pixel format that will be requested at the next 431 // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888. 432 PixelFormat mReqFormat; 433 434 // mReqUsage is the set of buffer usage flags that will be requested 435 // at the next deuque operation. It is initialized to 0. 436 uint64_t mReqUsage; 437 438 // mTimestamp is the timestamp that will be used for the next buffer queue 439 // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that 440 // a timestamp is auto-generated when queueBuffer is called. 441 int64_t mTimestamp; 442 443 // mDataSpace is the buffer dataSpace that will be used for the next buffer 444 // queue operation. It defaults to Dataspace::UNKNOWN, which 445 // means that the buffer contains some type of color data. 446 ui::Dataspace mDataSpace; 447 448 // mHdrMetadata is the HDR metadata that will be used for the next buffer 449 // queue operation. There is no HDR metadata by default. 450 HdrMetadata mHdrMetadata; 451 452 // mCrop is the crop rectangle that will be used for the next buffer 453 // that gets queued. It is set by calling setCrop. 454 Rect mCrop; 455 456 // mScalingMode is the scaling mode that will be used for the next 457 // buffers that get queued. It is set by calling setScalingMode. 458 int mScalingMode; 459 460 // mTransform is the transform identifier that will be used for the next 461 // buffer that gets queued. It is set by calling setTransform. 462 uint32_t mTransform; 463 464 // mStickyTransform is a transform that is applied on top of mTransform 465 // in each buffer that is queued. This is typically used to force the 466 // compositor to apply a transform, and will prevent the transform hint 467 // from being set by the compositor. 468 uint32_t mStickyTransform; 469 470 // mDefaultWidth is default width of the buffers, regardless of the 471 // native_window_set_buffers_dimensions call. 472 uint32_t mDefaultWidth; 473 474 // mDefaultHeight is default height of the buffers, regardless of the 475 // native_window_set_buffers_dimensions call. 476 uint32_t mDefaultHeight; 477 478 // mUserWidth, if non-zero, is an application-specified override 479 // of mDefaultWidth. This is lower priority than the width set by 480 // native_window_set_buffers_dimensions. 481 uint32_t mUserWidth; 482 483 // mUserHeight, if non-zero, is an application-specified override 484 // of mDefaultHeight. This is lower priority than the height set 485 // by native_window_set_buffers_dimensions. 486 uint32_t mUserHeight; 487 488 // mTransformHint is the transform probably applied to buffers of this 489 // window. this is only a hint, actual transform may differ. 490 uint32_t mTransformHint; getTransformHint()491 virtual uint32_t getTransformHint() const { return mTransformHint; } 492 bool transformToDisplayInverse() const; 493 494 // mProducerControlledByApp whether this buffer producer is controlled 495 // by the application 496 bool mProducerControlledByApp; 497 498 // mSwapIntervalZero set if we should drop buffers at queue() time to 499 // achieve an asynchronous swap interval 500 bool mSwapIntervalZero; 501 502 // mConsumerRunningBehind whether the consumer is running more than 503 // one buffer behind the producer. 504 mutable bool mConsumerRunningBehind; 505 506 // mMutex is the mutex used to prevent concurrent access to the member 507 // variables of Surface objects. It must be locked whenever the 508 // member variables are accessed. 509 mutable Mutex mMutex; 510 511 // mInterceptorMutex is the mutex guarding interceptors. 512 mutable std::shared_mutex mInterceptorMutex; 513 514 ANativeWindow_cancelBufferInterceptor mCancelInterceptor = nullptr; 515 void* mCancelInterceptorData = nullptr; 516 ANativeWindow_dequeueBufferInterceptor mDequeueInterceptor = nullptr; 517 void* mDequeueInterceptorData = nullptr; 518 ANativeWindow_performInterceptor mPerformInterceptor = nullptr; 519 void* mPerformInterceptorData = nullptr; 520 ANativeWindow_queueBufferInterceptor mQueueInterceptor = nullptr; 521 void* mQueueInterceptorData = nullptr; 522 ANativeWindow_queryInterceptor mQueryInterceptor = nullptr; 523 void* mQueryInterceptorData = nullptr; 524 525 // must be used from the lock/unlock thread 526 sp<GraphicBuffer> mLockedBuffer; 527 sp<GraphicBuffer> mPostedBuffer; 528 bool mConnectedToCpu; 529 530 // When a CPU producer is attached, this reflects the region that the 531 // producer wished to update as well as whether the Surface was able to copy 532 // the previous buffer back to allow a partial update. 533 // 534 // When a non-CPU producer is attached, this reflects the surface damage 535 // (the change since the previous frame) passed in by the producer. 536 Region mDirtyRegion; 537 538 // mBufferAge tracks the age of the contents of the most recently dequeued 539 // buffer as the number of frames that have elapsed since it was last queued 540 uint64_t mBufferAge; 541 542 // Stores the current generation number. See setGenerationNumber and 543 // IGraphicBufferProducer::setGenerationNumber for more information. 544 uint32_t mGenerationNumber; 545 546 // Caches the values that have been passed to the producer. 547 bool mSharedBufferMode; 548 bool mAutoRefresh; 549 bool mAutoPrerotation; 550 551 // If in shared buffer mode and auto refresh is enabled, store the shared 552 // buffer slot and return it for all calls to queue/dequeue without going 553 // over Binder. 554 int mSharedBufferSlot; 555 556 // This is true if the shared buffer has already been queued/canceled. It's 557 // used to prevent a mismatch between the number of queue/dequeue calls. 558 bool mSharedBufferHasBeenQueued; 559 560 // These are used to satisfy the NATIVE_WINDOW_LAST_*_DURATION queries 561 nsecs_t mLastDequeueDuration = 0; 562 nsecs_t mLastQueueDuration = 0; 563 564 // Stores the time right before we call IGBP::dequeueBuffer 565 nsecs_t mLastDequeueStartTime = 0; 566 567 Condition mQueueBufferCondition; 568 569 uint64_t mNextFrameNumber = 1; 570 uint64_t mLastFrameNumber = 0; 571 572 // Mutable because ANativeWindow::query needs this class const. 573 mutable bool mQueriedSupportedTimestamps; 574 mutable bool mFrameTimestampsSupportsPresent; 575 576 // A cached copy of the FrameEventHistory maintained by the consumer. 577 bool mEnableFrameTimestamps = false; 578 std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory; 579 580 // Reference to the SurfaceFlinger layer that was used to create this 581 // surface. This is only populated when the Surface is created from 582 // a BlastBufferQueue. 583 sp<IBinder> mSurfaceControlHandle; 584 585 bool mReportRemovedBuffers = false; 586 std::vector<sp<GraphicBuffer>> mRemovedBuffers; 587 int mMaxBufferCount; 588 589 sp<IProducerListener> mListenerProxy; 590 591 // Get and flush the buffers of given slots, if the buffer in the slot 592 // is currently dequeued then it won't be flushed and won't be returned 593 // in outBuffers. 594 status_t getAndFlushBuffersFromSlots(const std::vector<int32_t>& slots, 595 std::vector<sp<GraphicBuffer>>* outBuffers); 596 597 // Buffers that are successfully dequeued/attached and handed to clients 598 std::unordered_set<int> mDequeuedSlots; 599 }; 600 601 } // namespace android 602 603 #endif // ANDROID_GUI_SURFACE_H 604