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