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