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