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