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