1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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"
16 class RefreshTimerVsyncDispatcher
;
17 class CompositorVsyncDispatcher
;
21 // Controls how and when to enable/disable vsync. Lives as long as the
22 // gfxPlatform does on the parent process
25 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource
)
27 typedef mozilla::RefreshTimerVsyncDispatcher RefreshTimerVsyncDispatcher
;
28 typedef mozilla::CompositorVsyncDispatcher CompositorVsyncDispatcher
;
31 // Controls vsync unique to each display and unique on each platform
37 // Notified when this display's vsync occurs, on the vsync thread
38 // The aVsyncTimestamp should normalize to the Vsync time that just occured
39 // However, different platforms give different vsync notification times.
40 // OSX - The vsync timestamp of the upcoming frame, in the future
41 // Windows: It's messy, see gfxWindowsPlatform.
43 // All platforms should normalize to the vsync that just occured.
44 // Large parts of Gecko assume TimeStamps should not be in the future such as animations
45 virtual void NotifyVsync(TimeStamp aVsyncTimestamp
);
47 RefPtr
<RefreshTimerVsyncDispatcher
> GetRefreshTimerVsyncDispatcher();
49 void AddCompositorVsyncDispatcher(CompositorVsyncDispatcher
* aCompositorVsyncDispatcher
);
50 void RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher
* aCompositorVsyncDispatcher
);
51 void NotifyRefreshTimerVsyncStatus(bool aEnable
);
52 virtual TimeDuration
GetVsyncRate();
54 // These should all only be called on the main thread
55 virtual void EnableVsync() = 0;
56 virtual void DisableVsync() = 0;
57 virtual bool IsVsyncEnabled() = 0;
58 virtual void Shutdown() = 0;
61 void UpdateVsyncStatus();
63 Mutex mDispatcherLock
;
64 bool mRefreshTimerNeedsVsync
;
65 nsTArray
<RefPtr
<CompositorVsyncDispatcher
>> mCompositorVsyncDispatchers
;
66 RefPtr
<RefreshTimerVsyncDispatcher
> mRefreshTimerVsyncDispatcher
;
69 void AddCompositorVsyncDispatcher(CompositorVsyncDispatcher
* aCompositorVsyncDispatcher
);
70 void RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher
* aCompositorVsyncDispatcher
);
72 RefPtr
<RefreshTimerVsyncDispatcher
> GetRefreshTimerVsyncDispatcher();
73 virtual Display
& GetGlobalDisplay() = 0; // Works across all displays
77 virtual ~VsyncSource() {}
81 } // namespace mozilla
83 #endif /* GFX_VSYNCSOURCE_H */