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