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
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"
17 class RefreshTimerVsyncDispatcher
;
18 class CompositorVsyncDispatcher
;
21 typedef layers::BaseTransactionId
<VsyncIdType
> VsyncId
;
28 class PVsyncBridgeParent
;
30 // Controls how and when to enable/disable vsync. Lives as long as the
31 // gfxPlatform does on the parent process
33 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource
)
35 typedef mozilla::RefreshTimerVsyncDispatcher RefreshTimerVsyncDispatcher
;
36 typedef mozilla::CompositorVsyncDispatcher CompositorVsyncDispatcher
;
39 // Controls vsync unique to each display and unique on each platform
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.
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
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;
73 void UpdateVsyncStatus();
75 Mutex mDispatcherLock
;
76 bool mRefreshTimerNeedsVsync
;
77 nsTArray
<RefPtr
<CompositorVsyncDispatcher
>> mCompositorVsyncDispatchers
;
78 RefPtr
<RefreshTimerVsyncDispatcher
> mRefreshTimerVsyncDispatcher
;
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
94 virtual ~VsyncSource() = default;
99 namespace recordreplay
{
101 void NotifyVsyncObserver();
103 } // namespace recordreplay
110 VsyncEvent(const VsyncId
& aId
, const TimeStamp
& aTime
)
111 : mId(aId
), mTime(aTime
) {}
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 */