SurfaceFlinger.h revision 78491c9f694cb0767996503c629776a8eda950d7
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_SURFACE_FLINGER_H
18#define ANDROID_SURFACE_FLINGER_H
19
20#include <memory>
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <EGL/egl.h>
25
26/*
27 * NOTE: Make sure this file doesn't include  anything from <gl/ > or <gl2/ >
28 */
29
30#include <cutils/compiler.h>
31
32#include <utils/Atomic.h>
33#include <utils/Errors.h>
34#include <utils/KeyedVector.h>
35#include <utils/RefBase.h>
36#include <utils/SortedVector.h>
37#include <utils/threads.h>
38
39#include <ui/FenceTime.h>
40#include <ui/PixelFormat.h>
41#include <math/mat4.h>
42
43#include <gui/FrameTimestamps.h>
44#include <gui/ISurfaceComposer.h>
45#include <gui/ISurfaceComposerClient.h>
46#include <gui/OccupancyTracker.h>
47
48#include <hardware/hwcomposer_defs.h>
49
50#include <system/graphics.h>
51
52#include <private/gui/LayerState.h>
53
54#include "Barrier.h"
55#include "DisplayDevice.h"
56#include "DispSync.h"
57#include "FrameTracker.h"
58#include "LayerVector.h"
59#include "MessageQueue.h"
60#include "SurfaceInterceptor.h"
61#include "StartBootAnimThread.h"
62
63#include "DisplayHardware/HWComposer.h"
64#include "Effects/Daltonizer.h"
65
66#include <map>
67#include <mutex>
68#include <queue>
69#include <string>
70#include <utility>
71
72namespace android {
73
74// ---------------------------------------------------------------------------
75
76class Client;
77class DisplayEventConnection;
78class EventThread;
79class Layer;
80class LayerDim;
81class Surface;
82class RenderEngine;
83class EventControlThread;
84class VSyncSource;
85class InjectVSyncSource;
86class VrStateCallbacks;
87
88namespace dvr {
89class VrFlinger;
90} // namespace dvr
91
92// ---------------------------------------------------------------------------
93
94enum {
95    eTransactionNeeded        = 0x01,
96    eTraversalNeeded          = 0x02,
97    eDisplayTransactionNeeded = 0x04,
98    eTransactionMask          = 0x07
99};
100
101class SurfaceFlinger : public BnSurfaceComposer,
102                       private IBinder::DeathRecipient,
103                       private HWComposer::EventHandler
104{
105public:
106
107
108    // This is the phase offset in nanoseconds of the software vsync event
109    // relative to the vsync event reported by HWComposer.  The software vsync
110    // event is when SurfaceFlinger and Choreographer-based applications run each
111    // frame.
112    //
113    // This phase offset allows adjustment of the minimum latency from application
114    // wake-up time (by Choreographer) to the time at which the resulting window
115    // image is displayed.  This value may be either positive (after the HW vsync)
116    // or negative (before the HW vsync). Setting it to 0 will result in a lower
117    // latency bound of two vsync periods because the app and SurfaceFlinger
118    // will run just after the HW vsync.  Setting it to a positive number will
119    // result in the minimum latency being:
120    //
121    //     (2 * VSYNC_PERIOD - (vsyncPhaseOffsetNs % VSYNC_PERIOD))
122    //
123    // Note that reducing this latency makes it more likely for the applications
124    // to not have their window content image ready in time.  When this happens
125    // the latency will end up being an additional vsync period, and animations
126    // will hiccup.  Therefore, this latency should be tuned somewhat
127    // conservatively (or at least with awareness of the trade-off being made).
128    static int64_t vsyncPhaseOffsetNs;
129    static int64_t sfVsyncPhaseOffsetNs;
130
131    // Instruct the Render Engine to use EGL_IMG_context_priority is available.
132    static bool useContextPriority;
133
134    static char const* getServiceName() ANDROID_API {
135        return "SurfaceFlinger";
136    }
137
138    SurfaceFlinger() ANDROID_API;
139
140    // must be called before clients can connect
141    void init() ANDROID_API;
142
143    // starts SurfaceFlinger main loop in the current thread
144    void run() ANDROID_API;
145
146    enum {
147        EVENT_VSYNC = HWC_EVENT_VSYNC
148    };
149
150    // post an asynchronous message to the main thread
151    status_t postMessageAsync(const sp<MessageBase>& msg, nsecs_t reltime = 0, uint32_t flags = 0);
152
153    // post a synchronous message to the main thread
154    status_t postMessageSync(const sp<MessageBase>& msg, nsecs_t reltime = 0, uint32_t flags = 0);
155
156    // force full composition on all displays
157    void repaintEverything();
158
159    // returns the default Display
160    sp<const DisplayDevice> getDefaultDisplayDevice() const {
161        return getDisplayDevice(mBuiltinDisplays[DisplayDevice::DISPLAY_PRIMARY]);
162    }
163
164    // utility function to delete a texture on the main thread
165    void deleteTextureAsync(uint32_t texture);
166
167    // enable/disable h/w composer event
168    // TODO: this should be made accessible only to EventThread
169#ifdef USE_HWC2
170    void setVsyncEnabled(int disp, int enabled);
171#else
172    void eventControl(int disp, int event, int enabled);
173#endif
174
175    // called on the main thread by MessageQueue when an internal message
176    // is received
177    // TODO: this should be made accessible only to MessageQueue
178    void onMessageReceived(int32_t what);
179
180    // for debugging only
181    // TODO: this should be made accessible only to HWComposer
182    const Vector< sp<Layer> >& getLayerSortedByZForHwcDisplay(int id);
183
184    RenderEngine& getRenderEngine() const {
185        return *mRenderEngine;
186    }
187
188    bool authenticateSurfaceTextureLocked(
189        const sp<IGraphicBufferProducer>& bufferProducer) const;
190
191private:
192    friend class Client;
193    friend class DisplayEventConnection;
194    friend class EventThread;
195    friend class Layer;
196    friend class MonitoredProducer;
197    friend class VrStateCallbacks;
198
199    // This value is specified in number of frames.  Log frame stats at most
200    // every half hour.
201    enum { LOG_FRAME_STATS_PERIOD =  30*60*60 };
202
203    static const size_t MAX_LAYERS = 4096;
204
205    // We're reference counted, never destroy SurfaceFlinger directly
206    virtual ~SurfaceFlinger();
207
208    /* ------------------------------------------------------------------------
209     * Internal data structures
210     */
211
212    class State {
213    public:
214        LayerVector layersSortedByZ;
215        DefaultKeyedVector< wp<IBinder>, DisplayDeviceState> displays;
216
217        void traverseInZOrder(const std::function<void(Layer*)>& consume) const;
218        void traverseInReverseZOrder(const std::function<void(Layer*)>& consume) const;
219    };
220
221    /* ------------------------------------------------------------------------
222     * IBinder interface
223     */
224    virtual status_t onTransact(uint32_t code, const Parcel& data,
225        Parcel* reply, uint32_t flags);
226    virtual status_t dump(int fd, const Vector<String16>& args);
227
228    /* ------------------------------------------------------------------------
229     * ISurfaceComposer interface
230     */
231    virtual sp<ISurfaceComposerClient> createConnection();
232    virtual sp<ISurfaceComposerClient> createScopedConnection(const sp<IGraphicBufferProducer>& gbp);
233    virtual sp<IBinder> createDisplay(const String8& displayName, bool secure);
234    virtual void destroyDisplay(const sp<IBinder>& display);
235    virtual sp<IBinder> getBuiltInDisplay(int32_t id);
236    virtual void setTransactionState(const Vector<ComposerState>& state,
237            const Vector<DisplayState>& displays, uint32_t flags);
238    virtual void bootFinished();
239    virtual bool authenticateSurfaceTexture(
240        const sp<IGraphicBufferProducer>& bufferProducer) const;
241    virtual status_t getSupportedFrameTimestamps(
242            std::vector<FrameEvent>* outSupported) const;
243    virtual sp<IDisplayEventConnection> createDisplayEventConnection();
244    virtual status_t captureScreen(const sp<IBinder>& display,
245            const sp<IGraphicBufferProducer>& producer,
246            Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
247            int32_t minLayerZ, int32_t maxLayerZ,
248            bool useIdentityTransform, ISurfaceComposer::Rotation rotation);
249    virtual status_t getDisplayStats(const sp<IBinder>& display,
250            DisplayStatInfo* stats);
251    virtual status_t getDisplayConfigs(const sp<IBinder>& display,
252            Vector<DisplayInfo>* configs);
253    virtual int getActiveConfig(const sp<IBinder>& display);
254    virtual status_t getDisplayColorModes(const sp<IBinder>& display,
255            Vector<android_color_mode_t>* configs);
256    virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display);
257    virtual status_t setActiveColorMode(const sp<IBinder>& display, android_color_mode_t colorMode);
258    virtual void setPowerMode(const sp<IBinder>& display, int mode);
259    virtual status_t setActiveConfig(const sp<IBinder>& display, int id);
260    virtual status_t clearAnimationFrameStats();
261    virtual status_t getAnimationFrameStats(FrameStats* outStats) const;
262    virtual status_t getHdrCapabilities(const sp<IBinder>& display,
263            HdrCapabilities* outCapabilities) const;
264    virtual status_t enableVSyncInjections(bool enable);
265    virtual status_t injectVSync(nsecs_t when);
266
267
268    /* ------------------------------------------------------------------------
269     * DeathRecipient interface
270     */
271    virtual void binderDied(const wp<IBinder>& who);
272
273    /* ------------------------------------------------------------------------
274     * RefBase interface
275     */
276    virtual void onFirstRef();
277
278    /* ------------------------------------------------------------------------
279     * HWComposer::EventHandler interface
280     */
281    virtual void onVSyncReceived(HWComposer* composer, int type, nsecs_t timestamp);
282    virtual void onHotplugReceived(int disp, bool connected);
283    virtual void onInvalidateReceived(HWComposer* composer);
284
285    /* ------------------------------------------------------------------------
286     * Message handling
287     */
288    void waitForEvent();
289    void signalTransaction();
290    void signalLayerUpdate();
291    void signalRefresh();
292
293    // called on the main thread in response to initializeDisplays()
294    void onInitializeDisplays();
295    // called on the main thread in response to setActiveConfig()
296    void setActiveConfigInternal(const sp<DisplayDevice>& hw, int mode);
297    // called on the main thread in response to setPowerMode()
298    void setPowerModeInternal(const sp<DisplayDevice>& hw, int mode);
299
300    // Called on the main thread in response to setActiveColorMode()
301    void setActiveColorModeInternal(const sp<DisplayDevice>& hw, android_color_mode_t colorMode);
302
303    // Returns whether the transaction actually modified any state
304    bool handleMessageTransaction();
305
306    // Returns whether a new buffer has been latched (see handlePageFlip())
307    bool handleMessageInvalidate();
308
309    void handleMessageRefresh();
310
311    void handleTransaction(uint32_t transactionFlags);
312    void handleTransactionLocked(uint32_t transactionFlags);
313
314    void updateCursorAsync();
315
316    /* handlePageFlip - latch a new buffer if available and compute the dirty
317     * region. Returns whether a new buffer has been latched, i.e., whether it
318     * is necessary to perform a refresh during this vsync.
319     */
320    bool handlePageFlip();
321
322    /* ------------------------------------------------------------------------
323     * Transactions
324     */
325    uint32_t getTransactionFlags(uint32_t flags);
326    uint32_t peekTransactionFlags();
327    uint32_t setTransactionFlags(uint32_t flags);
328    void commitTransaction();
329    uint32_t setClientStateLocked(const sp<Client>& client, const layer_state_t& s);
330    uint32_t setDisplayStateLocked(const DisplayState& s);
331
332    /* ------------------------------------------------------------------------
333     * Layer management
334     */
335    status_t createLayer(const String8& name, const sp<Client>& client,
336            uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
337            uint32_t windowType, uint32_t ownerUid, sp<IBinder>* handle,
338            sp<IGraphicBufferProducer>* gbp, sp<Layer>* parent);
339
340    status_t createNormalLayer(const sp<Client>& client, const String8& name,
341            uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format,
342            sp<IBinder>* outHandle, sp<IGraphicBufferProducer>* outGbp,
343            sp<Layer>* outLayer);
344
345    status_t createDimLayer(const sp<Client>& client, const String8& name,
346            uint32_t w, uint32_t h, uint32_t flags, sp<IBinder>* outHandle,
347            sp<IGraphicBufferProducer>* outGbp, sp<Layer>* outLayer);
348
349    // called in response to the window-manager calling
350    // ISurfaceComposerClient::destroySurface()
351    status_t onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle);
352
353    // called when all clients have released all their references to
354    // this layer meaning it is entirely safe to destroy all
355    // resources associated to this layer.
356    status_t onLayerDestroyed(const wp<Layer>& layer);
357
358    // remove a layer from SurfaceFlinger immediately
359    status_t removeLayer(const sp<Layer>& layer);
360
361    // add a layer to SurfaceFlinger
362    status_t addClientLayer(const sp<Client>& client,
363            const sp<IBinder>& handle,
364            const sp<IGraphicBufferProducer>& gbc,
365            const sp<Layer>& lbc,
366            const sp<Layer>& parent);
367
368    /* ------------------------------------------------------------------------
369     * Boot animation, on/off animations and screen capture
370     */
371
372    void startBootAnim();
373
374    void renderScreenImplLocked(
375            const sp<const DisplayDevice>& hw,
376            Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
377            int32_t minLayerZ, int32_t maxLayerZ,
378            bool yswap, bool useIdentityTransform, Transform::orientation_flags rotation);
379
380    status_t captureScreenImplLocked(
381            const sp<const DisplayDevice>& hw,
382            const sp<IGraphicBufferProducer>& producer,
383            Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
384            int32_t minLayerZ, int32_t maxLayerZ,
385            bool useIdentityTransform, Transform::orientation_flags rotation,
386            bool isLocalScreenshot);
387
388    sp<StartBootAnimThread> mStartBootAnimThread = nullptr;
389
390    /* ------------------------------------------------------------------------
391     * EGL
392     */
393    size_t getMaxTextureSize() const;
394    size_t getMaxViewportDims() const;
395
396    /* ------------------------------------------------------------------------
397     * Display and layer stack management
398     */
399    // called when starting, or restarting after system_server death
400    void initializeDisplays();
401
402    // Create an IBinder for a builtin display and add it to current state
403    void createBuiltinDisplayLocked(DisplayDevice::DisplayType type);
404
405    // NOTE: can only be called from the main thread or with mStateLock held
406    sp<const DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) const {
407        return mDisplays.valueFor(dpy);
408    }
409
410    // NOTE: can only be called from the main thread or with mStateLock held
411    sp<DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) {
412        return mDisplays.valueFor(dpy);
413    }
414
415    int32_t getDisplayType(const sp<IBinder>& display) {
416        if (!display.get()) return NAME_NOT_FOUND;
417        for (int i = 0; i < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES; ++i) {
418            if (display == mBuiltinDisplays[i]) {
419                return i;
420            }
421        }
422        return NAME_NOT_FOUND;
423    }
424
425    // mark a region of a layer stack dirty. this updates the dirty
426    // region of all screens presenting this layer stack.
427    void invalidateLayerStack(uint32_t layerStack, const Region& dirty);
428
429#ifndef USE_HWC2
430    int32_t allocateHwcDisplayId(DisplayDevice::DisplayType type);
431#endif
432
433    /* ------------------------------------------------------------------------
434     * H/W composer
435     */
436
437    HWComposer& getHwComposer() const { return *mHwc; }
438
439    /* ------------------------------------------------------------------------
440     * Compositing
441     */
442    void invalidateHwcGeometry();
443    void computeVisibleRegions(uint32_t layerStack,
444            Region& dirtyRegion, Region& opaqueRegion);
445
446    void preComposition(nsecs_t refreshStartTime);
447    void postComposition(nsecs_t refreshStartTime);
448    void updateCompositorTiming(
449            nsecs_t vsyncPhase, nsecs_t vsyncInterval, nsecs_t compositeTime,
450            std::shared_ptr<FenceTime>& presentFenceTime);
451    void rebuildLayerStacks();
452    void setUpHWComposer();
453    void doComposition();
454    void doDebugFlashRegions();
455    void doDisplayComposition(const sp<const DisplayDevice>& displayDevice, const Region& dirtyRegion);
456
457    // compose surfaces for display hw. this fails if using GL and the surface
458    // has been destroyed and is no longer valid.
459    bool doComposeSurfaces(const sp<const DisplayDevice>& displayDevice, const Region& dirty);
460
461    void postFramebuffer();
462    void drawWormhole(const sp<const DisplayDevice>& displayDevice, const Region& region) const;
463
464    /* ------------------------------------------------------------------------
465     * Display management
466     */
467
468    /* ------------------------------------------------------------------------
469     * VSync
470     */
471    void enableHardwareVsync();
472    void resyncToHardwareVsync(bool makeAvailable);
473    void disableHardwareVsync(bool makeUnavailable);
474
475public:
476    void resyncWithRateLimit();
477    void getCompositorTiming(CompositorTiming* compositorTiming);
478private:
479
480    /* ------------------------------------------------------------------------
481     * Debugging & dumpsys
482     */
483    void listLayersLocked(const Vector<String16>& args, size_t& index, String8& result) const;
484    void dumpStatsLocked(const Vector<String16>& args, size_t& index, String8& result) const;
485    void clearStatsLocked(const Vector<String16>& args, size_t& index, String8& result);
486    void dumpAllLocked(const Vector<String16>& args, size_t& index, String8& result) const;
487    bool startDdmConnection();
488    void appendSfConfigString(String8& result) const;
489    void checkScreenshot(size_t w, size_t s, size_t h, void const* vaddr,
490            const sp<const DisplayDevice>& hw,
491            int32_t minLayerZ, int32_t maxLayerZ);
492
493    void logFrameStats();
494
495    void dumpStaticScreenStats(String8& result) const;
496    // Not const because each Layer needs to query Fences and cache timestamps.
497    void dumpFrameEventsLocked(String8& result);
498
499    void recordBufferingStats(const char* layerName,
500            std::vector<OccupancyTracker::Segment>&& history);
501    void dumpBufferingStats(String8& result) const;
502
503    bool isLayerTripleBufferingDisabled() const {
504        return this->mLayerTripleBufferingDisabled;
505    }
506
507#ifdef USE_HWC2
508    /* ------------------------------------------------------------------------
509     * VrFlinger
510     */
511    void clearHwcLayers(const LayerVector& layers);
512    void resetHwc();
513
514    // Check to see if we should change to or from vr mode, and if so, perform
515    // the handoff.
516    void updateVrMode();
517#endif
518
519    /* ------------------------------------------------------------------------
520     * Attributes
521     */
522
523    // access must be protected by mStateLock
524    mutable Mutex mStateLock;
525    State mCurrentState;
526    volatile int32_t mTransactionFlags;
527    Condition mTransactionCV;
528    bool mTransactionPending;
529    bool mAnimTransactionPending;
530    SortedVector< sp<Layer> > mLayersPendingRemoval;
531    SortedVector< wp<IBinder> > mGraphicBufferProducerList;
532
533    // protected by mStateLock (but we could use another lock)
534    bool mLayersRemoved;
535    bool mLayersAdded;
536
537    // access must be protected by mInvalidateLock
538    volatile int32_t mRepaintEverything;
539
540    // current, real and vr hardware composers.
541    HWComposer* mHwc;
542#ifdef USE_HWC2
543    HWComposer* mRealHwc;
544    HWComposer* mVrHwc;
545#endif
546    // constant members (no synchronization needed for access)
547    RenderEngine* mRenderEngine;
548    nsecs_t mBootTime;
549    bool mGpuToCpuSupported;
550    sp<EventThread> mEventThread;
551    sp<EventThread> mSFEventThread;
552    sp<EventThread> mInjectorEventThread;
553    sp<InjectVSyncSource> mVSyncInjector;
554    sp<EventControlThread> mEventControlThread;
555    EGLContext mEGLContext;
556    EGLDisplay mEGLDisplay;
557    sp<IBinder> mBuiltinDisplays[DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES];
558
559#ifdef USE_HWC2
560    std::unique_ptr<dvr::VrFlinger> mVrFlinger;
561#endif
562
563    // Can only accessed from the main thread, these members
564    // don't need synchronization
565    State mDrawingState;
566    bool mVisibleRegionsDirty;
567#ifndef USE_HWC2
568    bool mHwWorkListDirty;
569#else
570    bool mGeometryInvalid;
571#endif
572    bool mAnimCompositionPending;
573#ifdef USE_HWC2
574    std::vector<sp<Layer>> mLayersWithQueuedFrames;
575    sp<Fence> mPreviousPresentFence = Fence::NO_FENCE;
576    bool mHadClientComposition = false;
577#endif
578    FenceTimeline mGlCompositionDoneTimeline;
579    FenceTimeline mDisplayTimeline;
580
581    // this may only be written from the main thread with mStateLock held
582    // it may be read from other threads with mStateLock held
583    DefaultKeyedVector< wp<IBinder>, sp<DisplayDevice> > mDisplays;
584
585    // don't use a lock for these, we don't care
586    int mVrModeSupported;
587    int mDebugRegion;
588    int mDebugDDMS;
589    int mDebugDisableHWC;
590    int mDebugDisableTransformHint;
591    volatile nsecs_t mDebugInSwapBuffers;
592    nsecs_t mLastSwapBufferTime;
593    volatile nsecs_t mDebugInTransaction;
594    nsecs_t mLastTransactionTime;
595    bool mBootFinished;
596    bool mForceFullDamage;
597#ifdef USE_HWC2
598    bool mPropagateBackpressure = true;
599#endif
600    SurfaceInterceptor mInterceptor;
601    bool mUseHwcVirtualDisplays = false;
602
603    // Restrict layers to use two buffers in their bufferqueues.
604    bool mLayerTripleBufferingDisabled = false;
605
606    // these are thread safe
607    mutable MessageQueue mEventQueue;
608    FrameTracker mAnimFrameTracker;
609    DispSync mPrimaryDispSync;
610
611    // protected by mDestroyedLayerLock;
612    mutable Mutex mDestroyedLayerLock;
613    Vector<Layer const *> mDestroyedLayers;
614
615    // protected by mHWVsyncLock
616    Mutex mHWVsyncLock;
617    bool mPrimaryHWVsyncEnabled;
618    bool mHWVsyncAvailable;
619
620    // protected by mCompositorTimingLock;
621    mutable std::mutex mCompositeTimingLock;
622    CompositorTiming mCompositorTiming;
623
624    // Only accessed from the main thread.
625    struct CompositePresentTime {
626        nsecs_t composite { -1 };
627        std::shared_ptr<FenceTime> display { FenceTime::NO_FENCE };
628    };
629    std::queue<CompositePresentTime> mCompositePresentTimes;
630
631    /* ------------------------------------------------------------------------
632     * Feature prototyping
633     */
634
635    bool mInjectVSyncs;
636
637    Daltonizer mDaltonizer;
638#ifndef USE_HWC2
639    bool mDaltonize;
640#endif
641
642    mat4 mPreviousColorMatrix;
643    mat4 mColorMatrix;
644    bool mHasColorMatrix;
645
646    // Static screen stats
647    bool mHasPoweredOff;
648    static const size_t NUM_BUCKETS = 8; // < 1-7, 7+
649    nsecs_t mFrameBuckets[NUM_BUCKETS];
650    nsecs_t mTotalTime;
651    std::atomic<nsecs_t> mLastSwapTime;
652
653    size_t mNumLayers;
654
655    // Double- vs. triple-buffering stats
656    struct BufferingStats {
657        BufferingStats()
658          : numSegments(0),
659            totalTime(0),
660            twoBufferTime(0),
661            doubleBufferedTime(0),
662            tripleBufferedTime(0) {}
663
664        size_t numSegments;
665        nsecs_t totalTime;
666
667        // "Two buffer" means that a third buffer was never used, whereas
668        // "double-buffered" means that on average the segment only used two
669        // buffers (though it may have used a third for some part of the
670        // segment)
671        nsecs_t twoBufferTime;
672        nsecs_t doubleBufferedTime;
673        nsecs_t tripleBufferedTime;
674    };
675    mutable Mutex mBufferingStatsMutex;
676    std::unordered_map<std::string, BufferingStats> mBufferingStats;
677
678    // Verify that transaction is being called by an approved process:
679    // either AID_GRAPHICS or AID_SYSTEM.
680    status_t CheckTransactCodeCredentials(uint32_t code);
681
682#ifdef USE_HWC2
683    sp<VrStateCallbacks> mVrStateCallbacks;
684
685    std::atomic<bool> mEnterVrMode;
686#endif
687    };
688}; // namespace android
689
690#endif // ANDROID_SURFACE_FLINGER_H
691