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