1 /* 2 * Copyright (C) 2007 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_LAYER_H 18 #define ANDROID_LAYER_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 #include <EGL/egl.h> 24 #include <EGL/eglext.h> 25 26 #include <utils/RefBase.h> 27 #include <utils/String8.h> 28 #include <utils/Timers.h> 29 30 #include <ui/FrameStats.h> 31 #include <ui/GraphicBuffer.h> 32 #include <ui/PixelFormat.h> 33 #include <ui/Region.h> 34 35 #include <gui/ISurfaceComposerClient.h> 36 37 #include <private/gui/LayerState.h> 38 39 #include <list> 40 41 #include "FrameTracker.h" 42 #include "Client.h" 43 #include "LayerVector.h" 44 #include "MonitoredProducer.h" 45 #include "SurfaceFlinger.h" 46 #include "SurfaceFlingerConsumer.h" 47 #include "Transform.h" 48 49 #include "DisplayHardware/HWComposer.h" 50 #include "DisplayHardware/HWComposerBufferCache.h" 51 #include "RenderEngine/Mesh.h" 52 #include "RenderEngine/Texture.h" 53 54 namespace android { 55 56 // --------------------------------------------------------------------------- 57 58 class Client; 59 class Colorizer; 60 class DisplayDevice; 61 class GraphicBuffer; 62 class SurfaceFlinger; 63 64 // --------------------------------------------------------------------------- 65 66 /* 67 * A new BufferQueue and a new SurfaceFlingerConsumer are created when the 68 * Layer is first referenced. 69 * 70 * This also implements onFrameAvailable(), which notifies SurfaceFlinger 71 * that new data has arrived. 72 */ 73 class Layer : public SurfaceFlingerConsumer::ContentsChangedListener { 74 static int32_t sSequence; 75 76 public: 77 mutable bool contentDirty; 78 // regions below are in window-manager space 79 Region visibleRegion; 80 Region coveredRegion; 81 Region visibleNonTransparentRegion; 82 Region surfaceDamageRegion; 83 84 // Layer serial number. This gives layers an explicit ordering, so we 85 // have a stable sort order when their layer stack and Z-order are 86 // the same. 87 int32_t sequence; 88 89 enum { // flags for doTransaction() 90 eDontUpdateGeometryState = 0x00000001, 91 eVisibleRegion = 0x00000002, 92 }; 93 94 struct Geometry { 95 uint32_t w; 96 uint32_t h; 97 Transform transform; 98 99 inline bool operator ==(const Geometry& rhs) const { 100 return (w == rhs.w && h == rhs.h) && 101 (transform.tx() == rhs.transform.tx()) && 102 (transform.ty() == rhs.transform.ty()); 103 } 104 inline bool operator !=(const Geometry& rhs) const { 105 return !operator ==(rhs); 106 } 107 }; 108 109 struct State { 110 Geometry active; 111 Geometry requested; 112 int32_t z; 113 114 // The identifier of the layer stack this layer belongs to. A layer can 115 // only be associated to a single layer stack. A layer stack is a 116 // z-ordered group of layers which can be associated to one or more 117 // displays. Using the same layer stack on different displays is a way 118 // to achieve mirroring. 119 uint32_t layerStack; 120 121 #ifdef USE_HWC2 122 float alpha; 123 #else 124 uint8_t alpha; 125 #endif 126 uint8_t flags; 127 uint8_t mask; 128 uint8_t reserved[2]; 129 int32_t sequence; // changes when visible regions can change 130 bool modified; 131 132 // Crop is expressed in layer space coordinate. 133 Rect crop; 134 Rect requestedCrop; 135 136 // finalCrop is expressed in display space coordinate. 137 Rect finalCrop; 138 Rect requestedFinalCrop; 139 140 // If set, defers this state update until the identified Layer 141 // receives a frame with the given frameNumber 142 wp<Layer> barrierLayer; 143 uint64_t frameNumber; 144 145 // the transparentRegion hint is a bit special, it's latched only 146 // when we receive a buffer -- this is because it's "content" 147 // dependent. 148 Region activeTransparentRegion; 149 Region requestedTransparentRegion; 150 android_dataspace dataSpace; 151 152 uint32_t appId; 153 uint32_t type; 154 155 // If non-null, a Surface this Surface's Z-order is interpreted relative to. 156 wp<Layer> zOrderRelativeOf; 157 158 // A list of surfaces whose Z-order is interpreted relative to ours. 159 SortedVector<wp<Layer>> zOrderRelatives; 160 }; 161 162 // ----------------------------------------------------------------------- 163 164 Layer(SurfaceFlinger* flinger, const sp<Client>& client, 165 const String8& name, uint32_t w, uint32_t h, uint32_t flags); 166 167 virtual ~Layer(); 168 169 void setPrimaryDisplayOnly() { mPrimaryDisplayOnly = true; } 170 171 // the this layer's size and format 172 status_t setBuffers(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); 173 174 // ------------------------------------------------------------------------ 175 // Geometry setting functions. 176 // 177 // The following group of functions are used to specify the layers 178 // bounds, and the mapping of the texture on to those bounds. According 179 // to various settings changes to them may apply immediately, or be delayed until 180 // a pending resize is completed by the producer submitting a buffer. For example 181 // if we were to change the buffer size, and update the matrix ahead of the 182 // new buffer arriving, then we would be stretching the buffer to a different 183 // aspect before and after the buffer arriving, which probably isn't what we wanted. 184 // 185 // The first set of geometry functions are controlled by the scaling mode, described 186 // in window.h. The scaling mode may be set by the client, as it submits buffers. 187 // This value may be overriden through SurfaceControl, with setOverrideScalingMode. 188 // 189 // Put simply, if our scaling mode is SCALING_MODE_FREEZE, then 190 // matrix updates will not be applied while a resize is pending 191 // and the size and transform will remain in their previous state 192 // until a new buffer is submitted. If the scaling mode is another value 193 // then the old-buffer will immediately be scaled to the pending size 194 // and the new matrix will be immediately applied following this scaling 195 // transformation. 196 197 // Set the default buffer size for the assosciated Producer, in pixels. This is 198 // also the rendered size of the layer prior to any transformations. Parent 199 // or local matrix transformations will not affect the size of the buffer, 200 // but may affect it's on-screen size or clipping. 201 bool setSize(uint32_t w, uint32_t h); 202 // Set a 2x2 transformation matrix on the layer. This transform 203 // will be applied after parent transforms, but before any final 204 // producer specified transform. 205 bool setMatrix(const layer_state_t::matrix22_t& matrix); 206 207 // This second set of geometry attributes are controlled by 208 // setGeometryAppliesWithResize, and their default mode is to be 209 // immediate. If setGeometryAppliesWithResize is specified 210 // while a resize is pending, then update of these attributes will 211 // be delayed until the resize completes. 212 213 // setPosition operates in parent buffer space (pre parent-transform) or display 214 // space for top-level layers. 215 bool setPosition(float x, float y, bool immediate); 216 // Buffer space 217 bool setCrop(const Rect& crop, bool immediate); 218 // Parent buffer space/display space 219 bool setFinalCrop(const Rect& crop, bool immediate); 220 221 // TODO(b/38182121): Could we eliminate the various latching modes by 222 // using the layer hierarchy? 223 // ----------------------------------------------------------------------- 224 bool setLayer(int32_t z); 225 bool setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ); 226 227 #ifdef USE_HWC2 228 bool setAlpha(float alpha); 229 #else 230 bool setAlpha(uint8_t alpha); 231 #endif 232 bool setTransparentRegionHint(const Region& transparent); 233 bool setFlags(uint8_t flags, uint8_t mask); 234 bool setLayerStack(uint32_t layerStack); 235 bool setDataSpace(android_dataspace dataSpace); 236 android_dataspace getDataSpace() const; 237 uint32_t getLayerStack() const; 238 void deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber); 239 void deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber); 240 bool setOverrideScalingMode(int32_t overrideScalingMode); 241 void setInfo(uint32_t type, uint32_t appId); 242 bool reparentChildren(const sp<IBinder>& layer); 243 bool detachChildren(); 244 245 // If we have received a new buffer this frame, we will pass its surface 246 // damage down to hardware composer. Otherwise, we must send a region with 247 // one empty rect. 248 void useSurfaceDamage(); 249 void useEmptyDamage(); 250 251 uint32_t getTransactionFlags(uint32_t flags); 252 uint32_t setTransactionFlags(uint32_t flags); 253 254 bool belongsToDisplay(uint32_t layerStack, bool isPrimaryDisplay) const { 255 return getLayerStack() == layerStack && (!mPrimaryDisplayOnly || isPrimaryDisplay); 256 } 257 258 void computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh, 259 bool useIdentityTransform) const; 260 Rect computeBounds(const Region& activeTransparentRegion) const; 261 Rect computeBounds() const; 262 263 int32_t getSequence() const { return sequence; } 264 265 // ----------------------------------------------------------------------- 266 // Virtuals 267 268 virtual const char* getTypeId() const { return "Layer"; } 269 270 /* 271 * isOpaque - true if this surface is opaque 272 * 273 * This takes into account the buffer format (i.e. whether or not the 274 * pixel format includes an alpha channel) and the "opaque" flag set 275 * on the layer. It does not examine the current plane alpha value. 276 */ 277 virtual bool isOpaque(const Layer::State& s) const; 278 279 /* 280 * isSecure - true if this surface is secure, that is if it prevents 281 * screenshots or VNC servers. 282 */ 283 virtual bool isSecure() const; 284 285 /* 286 * isProtected - true if the layer may contain protected content in the 287 * GRALLOC_USAGE_PROTECTED sense. 288 */ 289 virtual bool isProtected() const; 290 291 /* 292 * isVisible - true if this layer is visible, false otherwise 293 */ 294 virtual bool isVisible() const; 295 296 /* 297 * isHiddenByPolicy - true if this layer has been forced invisible. 298 * just because this is false, doesn't mean isVisible() is true. 299 * For example if this layer has no active buffer, it may not be hidden by 300 * policy, but it still can not be visible. 301 */ 302 virtual bool isHiddenByPolicy() const; 303 304 /* 305 * isFixedSize - true if content has a fixed size 306 */ 307 virtual bool isFixedSize() const; 308 309 protected: 310 /* 311 * onDraw - draws the surface. 312 */ 313 virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip, 314 bool useIdentityTransform) const; 315 316 public: 317 // ----------------------------------------------------------------------- 318 319 #ifdef USE_HWC2 320 void setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z); 321 void forceClientComposition(int32_t hwcId); 322 void setPerFrameData(const sp<const DisplayDevice>& displayDevice); 323 324 // callIntoHwc exists so we can update our local state and call 325 // acceptDisplayChanges without unnecessarily updating the device's state 326 void setCompositionType(int32_t hwcId, HWC2::Composition type, 327 bool callIntoHwc = true); 328 HWC2::Composition getCompositionType(int32_t hwcId) const; 329 330 void setClearClientTarget(int32_t hwcId, bool clear); 331 bool getClearClientTarget(int32_t hwcId) const; 332 333 void updateCursorPosition(const sp<const DisplayDevice>& hw); 334 #else 335 void setGeometry(const sp<const DisplayDevice>& hw, 336 HWComposer::HWCLayerInterface& layer); 337 void setPerFrameData(const sp<const DisplayDevice>& hw, 338 HWComposer::HWCLayerInterface& layer); 339 void setAcquireFence(const sp<const DisplayDevice>& hw, 340 HWComposer::HWCLayerInterface& layer); 341 342 Rect getPosition(const sp<const DisplayDevice>& hw); 343 #endif 344 345 /* 346 * called after page-flip 347 */ 348 #ifdef USE_HWC2 349 void onLayerDisplayed(const sp<Fence>& releaseFence); 350 #else 351 void onLayerDisplayed(const sp<const DisplayDevice>& hw, 352 HWComposer::HWCLayerInterface* layer); 353 #endif 354 355 bool shouldPresentNow(const DispSync& dispSync) const; 356 357 /* 358 * called before composition. 359 * returns true if the layer has pending updates. 360 */ 361 bool onPreComposition(nsecs_t refreshStartTime); 362 363 /* 364 * called after composition. 365 * returns true if the layer latched a new buffer this frame. 366 */ 367 bool onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence, 368 const std::shared_ptr<FenceTime>& presentFence, 369 const CompositorTiming& compositorTiming); 370 371 #ifdef USE_HWC2 372 // If a buffer was replaced this frame, release the former buffer 373 void releasePendingBuffer(nsecs_t dequeueReadyTime); 374 #endif 375 376 /* 377 * draw - performs some global clipping optimizations 378 * and calls onDraw(). 379 */ 380 void draw(const sp<const DisplayDevice>& hw, const Region& clip) const; 381 void draw(const sp<const DisplayDevice>& hw, bool useIdentityTransform) const; 382 void draw(const sp<const DisplayDevice>& hw) const; 383 384 /* 385 * doTransaction - process the transaction. This is a good place to figure 386 * out which attributes of the surface have changed. 387 */ 388 uint32_t doTransaction(uint32_t transactionFlags); 389 390 /* 391 * setVisibleRegion - called to set the new visible region. This gives 392 * a chance to update the new visible region or record the fact it changed. 393 */ 394 void setVisibleRegion(const Region& visibleRegion); 395 396 /* 397 * setCoveredRegion - called when the covered region changes. The covered 398 * region corresponds to any area of the surface that is covered 399 * (transparently or not) by another surface. 400 */ 401 void setCoveredRegion(const Region& coveredRegion); 402 403 /* 404 * setVisibleNonTransparentRegion - called when the visible and 405 * non-transparent region changes. 406 */ 407 void setVisibleNonTransparentRegion(const Region& 408 visibleNonTransparentRegion); 409 410 /* 411 * latchBuffer - called each time the screen is redrawn and returns whether 412 * the visible regions need to be recomputed (this is a fairly heavy 413 * operation, so this should be set only if needed). Typically this is used 414 * to figure out if the content or size of a surface has changed. 415 */ 416 Region latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime); 417 bool isBufferLatched() const { return mRefreshPending; } 418 419 bool isPotentialCursor() const { return mPotentialCursor;} 420 421 /* 422 * called with the state lock from a binder thread when the layer is 423 * removed from the current list to the pending removal list 424 */ 425 void onRemovedFromCurrentState(); 426 427 /* 428 * called with the state lock from the main thread when the layer is 429 * removed from the pending removal list 430 */ 431 void onRemoved(); 432 433 434 // Updates the transform hint in our SurfaceFlingerConsumer to match 435 // the current orientation of the display device. 436 void updateTransformHint(const sp<const DisplayDevice>& hw) const; 437 438 /* 439 * returns the rectangle that crops the content of the layer and scales it 440 * to the layer's size. 441 */ 442 Rect getContentCrop() const; 443 444 /* 445 * Returns if a frame is queued. 446 */ 447 bool hasQueuedFrame() const { return mQueuedFrames > 0 || 448 mSidebandStreamChanged || mAutoRefresh; } 449 450 #ifdef USE_HWC2 451 // ----------------------------------------------------------------------- 452 453 bool createHwcLayer(HWComposer* hwc, int32_t hwcId); 454 void destroyHwcLayer(int32_t hwcId); 455 void destroyAllHwcLayers(); 456 457 bool hasHwcLayer(int32_t hwcId) { 458 return mHwcLayers.count(hwcId) > 0; 459 } 460 461 HWC2::Layer* getHwcLayer(int32_t hwcId) { 462 if (mHwcLayers.count(hwcId) == 0) { 463 return nullptr; 464 } 465 return mHwcLayers[hwcId].layer; 466 } 467 468 #endif 469 // ----------------------------------------------------------------------- 470 471 void clearWithOpenGL(const sp<const DisplayDevice>& hw) const; 472 void setFiltering(bool filtering); 473 bool getFiltering() const; 474 475 // only for debugging 476 inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; } 477 478 inline const State& getDrawingState() const { return mDrawingState; } 479 inline const State& getCurrentState() const { return mCurrentState; } 480 inline State& getCurrentState() { return mCurrentState; } 481 482 483 /* always call base class first */ 484 void dump(String8& result, Colorizer& colorizer) const; 485 #ifdef USE_HWC2 486 static void miniDumpHeader(String8& result); 487 void miniDump(String8& result, int32_t hwcId) const; 488 #endif 489 void dumpFrameStats(String8& result) const; 490 void dumpFrameEvents(String8& result); 491 void clearFrameStats(); 492 void logFrameStats(); 493 void getFrameStats(FrameStats* outStats) const; 494 495 std::vector<OccupancyTracker::Segment> getOccupancyHistory(bool forceFlush); 496 497 void onDisconnect(); 498 void addAndGetFrameTimestamps(const NewFrameEventsEntry* newEntry, 499 FrameEventHistoryDelta* outDelta); 500 501 bool getTransformToDisplayInverse() const; 502 503 Transform getTransform() const; 504 505 // Returns the Alpha of the Surface, accounting for the Alpha 506 // of parent Surfaces in the hierarchy (alpha's will be multiplied 507 // down the hierarchy). 508 #ifdef USE_HWC2 509 float getAlpha() const; 510 #else 511 uint8_t getAlpha() const; 512 #endif 513 514 void traverseInReverseZOrder(LayerVector::StateSet stateSet, 515 const LayerVector::Visitor& visitor); 516 void traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor); 517 518 size_t getChildrenCount() const; 519 void addChild(const sp<Layer>& layer); 520 // Returns index if removed, or negative value otherwise 521 // for symmetry with Vector::remove 522 ssize_t removeChild(const sp<Layer>& layer); 523 sp<Layer> getParent() const { return mCurrentParent.promote(); } 524 bool hasParent() const { return getParent() != nullptr; } 525 526 Rect computeScreenBounds(bool reduceTransparentRegion = true) const; 527 bool setChildLayer(const sp<Layer>& childLayer, int32_t z); 528 529 // Copy the current list of children to the drawing state. Called by 530 // SurfaceFlinger to complete a transaction. 531 void commitChildList(); 532 533 int32_t getZ() const; 534 protected: 535 // constant 536 sp<SurfaceFlinger> mFlinger; 537 /* 538 * Trivial class, used to ensure that mFlinger->onLayerDestroyed(mLayer) 539 * is called. 540 */ 541 class LayerCleaner { 542 sp<SurfaceFlinger> mFlinger; 543 wp<Layer> mLayer; 544 protected: 545 ~LayerCleaner() { 546 // destroy client resources 547 mFlinger->onLayerDestroyed(mLayer); 548 } 549 public: 550 LayerCleaner(const sp<SurfaceFlinger>& flinger, 551 const sp<Layer>& layer) 552 : mFlinger(flinger), mLayer(layer) { 553 } 554 }; 555 556 557 virtual void onFirstRef(); 558 559 560 561 private: 562 friend class SurfaceInterceptor; 563 // Interface implementation for SurfaceFlingerConsumer::ContentsChangedListener 564 virtual void onFrameAvailable(const BufferItem& item) override; 565 virtual void onFrameReplaced(const BufferItem& item) override; 566 virtual void onSidebandStreamChanged() override; 567 568 void commitTransaction(const State& stateToCommit); 569 570 // needsLinearFiltering - true if this surface's state requires filtering 571 bool needsFiltering(const sp<const DisplayDevice>& hw) const; 572 573 uint32_t getEffectiveUsage(uint32_t usage) const; 574 575 FloatRect computeCrop(const sp<const DisplayDevice>& hw) const; 576 // Compute the initial crop as specified by parent layers and the SurfaceControl 577 // for this layer. Does not include buffer crop from the IGraphicBufferProducer 578 // client, as that should not affect child clipping. Returns in screen space. 579 Rect computeInitialCrop(const sp<const DisplayDevice>& hw) const; 580 bool isCropped() const; 581 static bool getOpacityForFormat(uint32_t format); 582 583 // drawing 584 void clearWithOpenGL(const sp<const DisplayDevice>& hw, 585 float r, float g, float b, float alpha) const; 586 void drawWithOpenGL(const sp<const DisplayDevice>& hw, 587 bool useIdentityTransform) const; 588 589 // Temporary - Used only for LEGACY camera mode. 590 uint32_t getProducerStickyTransform() const; 591 592 // Loads the corresponding system property once per process 593 static bool latchUnsignaledBuffers(); 594 595 void setParent(const sp<Layer>& layer); 596 597 LayerVector makeTraversalList(LayerVector::StateSet stateSet); 598 void addZOrderRelative(const wp<Layer>& relative); 599 void removeZOrderRelative(const wp<Layer>& relative); 600 601 // ----------------------------------------------------------------------- 602 603 class SyncPoint 604 { 605 public: 606 explicit SyncPoint(uint64_t frameNumber) : mFrameNumber(frameNumber), 607 mFrameIsAvailable(false), mTransactionIsApplied(false) {} 608 609 uint64_t getFrameNumber() const { 610 return mFrameNumber; 611 } 612 613 bool frameIsAvailable() const { 614 return mFrameIsAvailable; 615 } 616 617 void setFrameAvailable() { 618 mFrameIsAvailable = true; 619 } 620 621 bool transactionIsApplied() const { 622 return mTransactionIsApplied; 623 } 624 625 void setTransactionApplied() { 626 mTransactionIsApplied = true; 627 } 628 629 private: 630 const uint64_t mFrameNumber; 631 std::atomic<bool> mFrameIsAvailable; 632 std::atomic<bool> mTransactionIsApplied; 633 }; 634 635 // SyncPoints which will be signaled when the correct frame is at the head 636 // of the queue and dropped after the frame has been latched. Protected by 637 // mLocalSyncPointMutex. 638 Mutex mLocalSyncPointMutex; 639 std::list<std::shared_ptr<SyncPoint>> mLocalSyncPoints; 640 641 // SyncPoints which will be signaled and then dropped when the transaction 642 // is applied 643 std::list<std::shared_ptr<SyncPoint>> mRemoteSyncPoints; 644 645 uint64_t getHeadFrameNumber() const; 646 bool headFenceHasSignaled() const; 647 648 // Returns false if the relevant frame has already been latched 649 bool addSyncPoint(const std::shared_ptr<SyncPoint>& point); 650 651 void pushPendingState(); 652 void popPendingState(State* stateToCommit); 653 bool applyPendingStates(State* stateToCommit); 654 655 void clearSyncPoints(); 656 657 // Returns mCurrentScaling mode (originating from the 658 // Client) or mOverrideScalingMode mode (originating from 659 // the Surface Controller) if set. 660 uint32_t getEffectiveScalingMode() const; 661 public: 662 /* 663 * The layer handle is just a BBinder object passed to the client 664 * (remote process) -- we don't keep any reference on our side such that 665 * the dtor is called when the remote side let go of its reference. 666 * 667 * LayerCleaner ensures that mFlinger->onLayerDestroyed() is called for 668 * this layer when the handle is destroyed. 669 */ 670 class Handle : public BBinder, public LayerCleaner { 671 public: 672 Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer) 673 : LayerCleaner(flinger, layer), owner(layer) {} 674 675 wp<Layer> owner; 676 }; 677 678 sp<IBinder> getHandle(); 679 sp<IGraphicBufferProducer> getProducer() const; 680 const String8& getName() const; 681 void notifyAvailableFrames(); 682 private: 683 684 // ----------------------------------------------------------------------- 685 686 // Check all of the local sync points to ensure that all transactions 687 // which need to have been applied prior to the frame which is about to 688 // be latched have signaled 689 bool allTransactionsSignaled(); 690 691 // constants 692 sp<SurfaceFlingerConsumer> mSurfaceFlingerConsumer; 693 sp<IGraphicBufferProducer> mProducer; 694 uint32_t mTextureName; // from GLES 695 bool mPremultipliedAlpha; 696 String8 mName; 697 String8 mTransactionName; // A cached version of "TX - " + mName for systraces 698 PixelFormat mFormat; 699 700 bool mPrimaryDisplayOnly = false; 701 702 // these are protected by an external lock 703 State mCurrentState; 704 State mDrawingState; 705 volatile int32_t mTransactionFlags; 706 707 // Accessed from main thread and binder threads 708 Mutex mPendingStateMutex; 709 Vector<State> mPendingStates; 710 711 // thread-safe 712 volatile int32_t mQueuedFrames; 713 volatile int32_t mSidebandStreamChanged; // used like an atomic boolean 714 715 // Timestamp history for UIAutomation. Thread safe. 716 FrameTracker mFrameTracker; 717 718 // Timestamp history for the consumer to query. 719 // Accessed by both consumer and producer on main and binder threads. 720 Mutex mFrameEventHistoryMutex; 721 ConsumerFrameEventHistory mFrameEventHistory; 722 FenceTimeline mAcquireTimeline; 723 FenceTimeline mReleaseTimeline; 724 725 // main thread 726 int mActiveBufferSlot; 727 sp<GraphicBuffer> mActiveBuffer; 728 sp<NativeHandle> mSidebandStream; 729 Rect mCurrentCrop; 730 uint32_t mCurrentTransform; 731 uint32_t mCurrentScalingMode; 732 // We encode unset as -1. 733 int32_t mOverrideScalingMode; 734 bool mCurrentOpacity; 735 bool mBufferLatched = false; // TODO: Use mActiveBuffer? 736 std::atomic<uint64_t> mCurrentFrameNumber; 737 uint64_t mPreviousFrameNumber; // Only accessed on the main thread. 738 bool mRefreshPending; 739 bool mFrameLatencyNeeded; 740 // Whether filtering is forced on or not 741 bool mFiltering; 742 // Whether filtering is needed b/c of the drawingstate 743 bool mNeedsFiltering; 744 // The mesh used to draw the layer in GLES composition mode 745 mutable Mesh mMesh; 746 // The texture used to draw the layer in GLES composition mode 747 mutable Texture mTexture; 748 749 #ifdef USE_HWC2 750 // HWC items, accessed from the main thread 751 struct HWCInfo { 752 HWCInfo() 753 : hwc(nullptr), 754 layer(nullptr), 755 forceClientComposition(false), 756 compositionType(HWC2::Composition::Invalid), 757 clearClientTarget(false) {} 758 759 HWComposer* hwc; 760 HWC2::Layer* layer; 761 bool forceClientComposition; 762 HWC2::Composition compositionType; 763 bool clearClientTarget; 764 Rect displayFrame; 765 FloatRect sourceCrop; 766 HWComposerBufferCache bufferCache; 767 }; 768 769 // A layer can be attached to multiple displays when operating in mirror mode 770 // (a.k.a: when several displays are attached with equal layerStack). In this 771 // case we need to keep track. In non-mirror mode, a layer will have only one 772 // HWCInfo. This map key is a display layerStack. 773 std::unordered_map<int32_t, HWCInfo> mHwcLayers; 774 #else 775 bool mIsGlesComposition; 776 #endif 777 778 // page-flip thread (currently main thread) 779 bool mProtectedByApp; // application requires protected path to external sink 780 781 // protected by mLock 782 mutable Mutex mLock; 783 // Set to true once we've returned this surface's handle 784 mutable bool mHasSurface; 785 const wp<Client> mClientRef; 786 787 // This layer can be a cursor on some displays. 788 bool mPotentialCursor; 789 790 // Local copy of the queued contents of the incoming BufferQueue 791 mutable Mutex mQueueItemLock; 792 Condition mQueueItemCondition; 793 Vector<BufferItem> mQueueItems; 794 std::atomic<uint64_t> mLastFrameNumberReceived; 795 bool mUpdateTexImageFailed; // This is only accessed on the main thread. 796 797 bool mAutoRefresh; 798 bool mFreezeGeometryUpdates; 799 800 // Child list about to be committed/used for editing. 801 LayerVector mCurrentChildren; 802 // Child list used for rendering. 803 LayerVector mDrawingChildren; 804 805 wp<Layer> mCurrentParent; 806 wp<Layer> mDrawingParent; 807 }; 808 809 // --------------------------------------------------------------------------- 810 811 }; // namespace android 812 813 #endif // ANDROID_LAYER_H 814