Bug 1444940 [wpt PR 9917] - Writable streams: test changes to abort() under error...
[gecko.git] / gfx / thebes / VsyncSource.h
blob17bcbf11699f1fd7346bad04c6969f9ccb09feb9
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
9 #include "nsTArray.h"
10 #include "mozilla/RefPtr.h"
11 #include "mozilla/Mutex.h"
12 #include "mozilla/TimeStamp.h"
13 #include "nsISupportsImpl.h"
15 namespace mozilla {
16 class RefreshTimerVsyncDispatcher;
17 class CompositorVsyncDispatcher;
19 namespace gfx {
21 // Controls how and when to enable/disable vsync. Lives as long as the
22 // gfxPlatform does on the parent process
23 class VsyncSource
25 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource)
27 typedef mozilla::RefreshTimerVsyncDispatcher RefreshTimerVsyncDispatcher;
28 typedef mozilla::CompositorVsyncDispatcher CompositorVsyncDispatcher;
30 public:
31 // Controls vsync unique to each display and unique on each platform
32 class Display {
33 public:
34 Display();
35 virtual ~Display();
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.
42 // Android: TODO
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;
60 private:
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
74 void Shutdown();
76 protected:
77 virtual ~VsyncSource() {}
80 } // namespace gfx
81 } // namespace mozilla
83 #endif /* GFX_VSYNCSOURCE_H */