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