Bug 1567650 [wpt PR 17950] - [ElementTiming] Replace responseEnd with loadTime, a...
[gecko.git] / gfx / thebes / VsyncSource.h
blobae06e1abaf7cafd4a4599bf4b8125bf87998f6cb
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_VSYNCSOURCE_H
7 #define GFX_VSYNCSOURCE_H
9 #include "nsTArray.h"
10 #include "mozilla/RefPtr.h"
11 #include "mozilla/Mutex.h"
12 #include "mozilla/TimeStamp.h"
13 #include "nsISupportsImpl.h"
14 #include "mozilla/layers/LayersTypes.h"
16 namespace mozilla {
17 class RefreshTimerVsyncDispatcher;
18 class CompositorVsyncDispatcher;
20 class VsyncIdType {};
21 typedef layers::BaseTransactionId<VsyncIdType> VsyncId;
23 namespace layout {
24 class PVsyncChild;
27 namespace gfx {
28 class PVsyncBridgeParent;
30 // Controls how and when to enable/disable vsync. Lives as long as the
31 // gfxPlatform does on the parent process
32 class VsyncSource {
33 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource)
35 typedef mozilla::RefreshTimerVsyncDispatcher RefreshTimerVsyncDispatcher;
36 typedef mozilla::CompositorVsyncDispatcher CompositorVsyncDispatcher;
38 public:
39 // Controls vsync unique to each display and unique on each platform
40 class Display {
41 public:
42 Display();
43 virtual ~Display();
45 // Notified when this display's vsync occurs, on the vsync thread
46 // The aVsyncTimestamp should normalize to the Vsync time that just occured
47 // However, different platforms give different vsync notification times.
48 // OSX - The vsync timestamp of the upcoming frame, in the future
49 // Windows: It's messy, see gfxWindowsPlatform.
50 // Android: TODO
51 // All platforms should normalize to the vsync that just occured.
52 // Large parts of Gecko assume TimeStamps should not be in the future such
53 // as animations
54 virtual void NotifyVsync(TimeStamp aVsyncTimestamp);
56 RefPtr<RefreshTimerVsyncDispatcher> GetRefreshTimerVsyncDispatcher();
58 void AddCompositorVsyncDispatcher(
59 CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
60 void RemoveCompositorVsyncDispatcher(
61 CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
62 void MoveListenersToNewSource(VsyncSource::Display& aNewDisplay);
63 void NotifyRefreshTimerVsyncStatus(bool aEnable);
64 virtual TimeDuration GetVsyncRate();
66 // These should all only be called on the main thread
67 virtual void EnableVsync() = 0;
68 virtual void DisableVsync() = 0;
69 virtual bool IsVsyncEnabled() = 0;
70 virtual void Shutdown() = 0;
72 private:
73 void UpdateVsyncStatus();
75 Mutex mDispatcherLock;
76 bool mRefreshTimerNeedsVsync;
77 nsTArray<RefPtr<CompositorVsyncDispatcher>> mCompositorVsyncDispatchers;
78 RefPtr<RefreshTimerVsyncDispatcher> mRefreshTimerVsyncDispatcher;
79 VsyncId mVsyncId;
82 void AddCompositorVsyncDispatcher(
83 CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
84 void RemoveCompositorVsyncDispatcher(
85 CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
87 void MoveListenersToNewSource(VsyncSource* aNewSource);
89 RefPtr<RefreshTimerVsyncDispatcher> GetRefreshTimerVsyncDispatcher();
90 virtual Display& GetGlobalDisplay() = 0; // Works across all displays
91 void Shutdown();
93 protected:
94 virtual ~VsyncSource() = default;
97 } // namespace gfx
99 namespace recordreplay {
100 namespace child {
101 void NotifyVsyncObserver();
103 } // namespace recordreplay
105 struct VsyncEvent {
106 VsyncId mId;
107 TimeStamp mTime;
109 private:
110 VsyncEvent(const VsyncId& aId, const TimeStamp& aTime)
111 : mId(aId), mTime(aTime) {}
112 VsyncEvent() {}
113 friend class gfx::VsyncSource::Display;
114 friend class gfx::PVsyncBridgeParent;
115 friend class layout::PVsyncChild;
116 friend void recordreplay::child::NotifyVsyncObserver();
119 } // namespace mozilla
121 #endif /* GFX_VSYNCSOURCE_H */