2014-10-21 22:40:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_widget_VsyncDispatcher_h
|
|
|
|
#define mozilla_widget_VsyncDispatcher_h
|
|
|
|
|
2014-10-24 01:50:31 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-01-08 02:17:36 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2014-10-21 22:40:54 +00:00
|
|
|
#include "nsISupportsImpl.h"
|
2014-10-24 01:50:31 +00:00
|
|
|
#include "nsTArray.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-10-24 01:50:31 +00:00
|
|
|
|
2014-10-21 22:40:54 +00:00
|
|
|
namespace mozilla {
|
2014-10-24 01:50:31 +00:00
|
|
|
|
2014-10-21 22:40:54 +00:00
|
|
|
class VsyncObserver
|
|
|
|
{
|
2014-12-18 16:30:06 +00:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncObserver)
|
2014-10-24 01:50:31 +00:00
|
|
|
|
2014-10-21 22:40:54 +00:00
|
|
|
public:
|
|
|
|
// The method called when a vsync occurs. Return true if some work was done.
|
2015-01-08 02:17:36 +00:00
|
|
|
// In general, this vsync notification will occur on the hardware vsync
|
|
|
|
// thread from VsyncSource. But it might also be called on PVsync ipc thread
|
|
|
|
// if this notification is cross process. Thus all observer should check the
|
|
|
|
// thread model before handling the real task.
|
2014-10-21 22:40:54 +00:00
|
|
|
virtual bool NotifyVsync(TimeStamp aVsyncTimestamp) = 0;
|
|
|
|
|
|
|
|
protected:
|
2014-10-24 01:50:31 +00:00
|
|
|
VsyncObserver() {}
|
|
|
|
virtual ~VsyncObserver() {}
|
2014-11-18 21:28:42 +00:00
|
|
|
}; // VsyncObserver
|
2014-10-21 22:40:54 +00:00
|
|
|
|
2015-01-08 02:17:36 +00:00
|
|
|
// Used to dispatch vsync events in the parent process to compositors
|
2015-03-21 16:28:04 +00:00
|
|
|
class CompositorVsyncDispatcher final
|
2014-10-21 22:40:54 +00:00
|
|
|
{
|
2014-12-19 20:52:42 +00:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorVsyncDispatcher)
|
2015-01-08 02:17:36 +00:00
|
|
|
|
2014-10-21 22:40:54 +00:00
|
|
|
public:
|
2014-12-19 20:52:42 +00:00
|
|
|
CompositorVsyncDispatcher();
|
2014-12-18 16:30:06 +00:00
|
|
|
|
2014-10-24 01:50:31 +00:00
|
|
|
// Called on the vsync thread when a hardware vsync occurs
|
2014-10-29 20:37:06 +00:00
|
|
|
void NotifyVsync(TimeStamp aVsyncTimestamp);
|
2014-10-21 22:40:54 +00:00
|
|
|
|
|
|
|
// Compositor vsync observers must be added/removed on the compositor thread
|
2014-12-18 16:30:06 +00:00
|
|
|
void SetCompositorVsyncObserver(VsyncObserver* aVsyncObserver);
|
|
|
|
void Shutdown();
|
2014-10-21 22:40:54 +00:00
|
|
|
|
2015-01-23 19:19:53 +00:00
|
|
|
// This can be used to enable or disable thread assertions.
|
|
|
|
// This is useful for gtests because usually things run
|
|
|
|
// in only one thread in that environment
|
|
|
|
static void SetThreadAssertionsEnabled(bool aEnable);
|
|
|
|
|
2014-10-21 22:40:54 +00:00
|
|
|
private:
|
2015-01-23 19:19:53 +00:00
|
|
|
void AssertOnCompositorThread();
|
2014-12-19 20:52:42 +00:00
|
|
|
virtual ~CompositorVsyncDispatcher();
|
2015-01-20 16:31:24 +00:00
|
|
|
void ObserveVsync(bool aEnable);
|
2015-01-08 02:17:36 +00:00
|
|
|
|
2014-10-24 01:50:31 +00:00
|
|
|
Mutex mCompositorObserverLock;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<VsyncObserver> mCompositorVsyncObserver;
|
2015-01-20 16:31:24 +00:00
|
|
|
bool mDidShutdown;
|
2014-12-19 20:52:42 +00:00
|
|
|
};
|
2014-10-21 22:40:54 +00:00
|
|
|
|
2015-01-08 02:17:36 +00:00
|
|
|
// Dispatch vsync event to ipc actor parent and chrome RefreshTimer.
|
2015-03-21 16:28:04 +00:00
|
|
|
class RefreshTimerVsyncDispatcher final
|
2015-01-08 02:17:36 +00:00
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RefreshTimerVsyncDispatcher)
|
|
|
|
|
|
|
|
public:
|
|
|
|
RefreshTimerVsyncDispatcher();
|
|
|
|
|
|
|
|
// Please check CompositorVsyncDispatcher::NotifyVsync().
|
|
|
|
void NotifyVsync(TimeStamp aVsyncTimestamp);
|
|
|
|
|
|
|
|
// Set chrome process's RefreshTimer to this dispatcher.
|
|
|
|
// This function can be called from any thread.
|
|
|
|
void SetParentRefreshTimer(VsyncObserver* aVsyncObserver);
|
|
|
|
|
|
|
|
// Add or remove the content process' RefreshTimer to this dispatcher. This
|
|
|
|
// will be a no-op for AddChildRefreshTimer() if the observer is already
|
|
|
|
// registered.
|
|
|
|
// These functions can be called from any thread.
|
|
|
|
void AddChildRefreshTimer(VsyncObserver* aVsyncObserver);
|
|
|
|
void RemoveChildRefreshTimer(VsyncObserver* aVsyncObserver);
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~RefreshTimerVsyncDispatcher();
|
2015-01-20 16:31:26 +00:00
|
|
|
void UpdateVsyncStatus();
|
|
|
|
bool NeedsVsync();
|
2015-01-08 02:17:36 +00:00
|
|
|
|
|
|
|
Mutex mRefreshTimersLock;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<VsyncObserver> mParentRefreshTimer;
|
|
|
|
nsTArray<RefPtr<VsyncObserver>> mChildRefreshTimers;
|
2015-01-08 02:17:36 +00:00
|
|
|
};
|
|
|
|
|
2014-10-21 22:40:54 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-01-08 02:17:36 +00:00
|
|
|
#endif // mozilla_widget_VsyncDispatcher_h
|