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