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