Bumping manifests a=b2g-bump
[gecko.git] / widget / VsyncDispatcher.h
blobed6066d8b7a4738b2cef3f46b2d26a04ed4deaf2
1 /* -*- Mode: C++; tab-width: 2; 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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_widget_VsyncDispatcher_h
7 #define mozilla_widget_VsyncDispatcher_h
9 #include "mozilla/Mutex.h"
10 #include "mozilla/TimeStamp.h"
11 #include "nsISupportsImpl.h"
12 #include "nsTArray.h"
13 #include "nsRefPtr.h"
15 namespace mozilla {
17 class VsyncObserver
19 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncObserver)
21 public:
22 // The method called when a vsync occurs. Return true if some work was done.
23 // In general, this vsync notification will occur on the hardware vsync
24 // thread from VsyncSource. But it might also be called on PVsync ipc thread
25 // if this notification is cross process. Thus all observer should check the
26 // thread model before handling the real task.
27 virtual bool NotifyVsync(TimeStamp aVsyncTimestamp) = 0;
29 protected:
30 VsyncObserver() {}
31 virtual ~VsyncObserver() {}
32 }; // VsyncObserver
34 // Used to dispatch vsync events in the parent process to compositors
35 class CompositorVsyncDispatcher MOZ_FINAL
37 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorVsyncDispatcher)
39 public:
40 CompositorVsyncDispatcher();
42 // Called on the vsync thread when a hardware vsync occurs
43 // The aVsyncTimestamp can mean different things depending on the platform:
44 // b2g - The vsync timestamp of the previous frame that was just displayed
45 // OSX - The vsync timestamp of the upcoming frame
46 // TODO: Windows / Linux. DOCUMENT THIS WHEN IMPLEMENTING ON THOSE PLATFORMS
47 // Android: TODO
48 void NotifyVsync(TimeStamp aVsyncTimestamp);
50 // Compositor vsync observers must be added/removed on the compositor thread
51 void SetCompositorVsyncObserver(VsyncObserver* aVsyncObserver);
52 void Shutdown();
54 private:
55 virtual ~CompositorVsyncDispatcher();
56 void ObserveVsync(bool aEnable);
58 Mutex mCompositorObserverLock;
59 nsRefPtr<VsyncObserver> mCompositorVsyncObserver;
60 bool mDidShutdown;
63 // Dispatch vsync event to ipc actor parent and chrome RefreshTimer.
64 class RefreshTimerVsyncDispatcher MOZ_FINAL
66 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RefreshTimerVsyncDispatcher)
68 public:
69 RefreshTimerVsyncDispatcher();
71 // Please check CompositorVsyncDispatcher::NotifyVsync().
72 void NotifyVsync(TimeStamp aVsyncTimestamp);
74 // Set chrome process's RefreshTimer to this dispatcher.
75 // This function can be called from any thread.
76 void SetParentRefreshTimer(VsyncObserver* aVsyncObserver);
78 // Add or remove the content process' RefreshTimer to this dispatcher. This
79 // will be a no-op for AddChildRefreshTimer() if the observer is already
80 // registered.
81 // These functions can be called from any thread.
82 void AddChildRefreshTimer(VsyncObserver* aVsyncObserver);
83 void RemoveChildRefreshTimer(VsyncObserver* aVsyncObserver);
85 private:
86 virtual ~RefreshTimerVsyncDispatcher();
87 void UpdateVsyncStatus();
88 bool NeedsVsync();
90 Mutex mRefreshTimersLock;
91 nsRefPtr<VsyncObserver> mParentRefreshTimer;
92 nsTArray<nsRefPtr<VsyncObserver>> mChildRefreshTimers;
95 } // namespace mozilla
97 #endif // mozilla_widget_VsyncDispatcher_h