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