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