2014-10-21 15:40:54 -07: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-23 18:50:31 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-01-07 18:17:36 -08:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2014-10-21 15:40:54 -07:00
|
|
|
#include "nsISupportsImpl.h"
|
2014-10-23 18:50:31 -07:00
|
|
|
#include "nsTArray.h"
|
2015-10-17 22:24:48 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-10-23 18:50:31 -07:00
|
|
|
|
2014-10-21 15:40:54 -07:00
|
|
|
namespace mozilla {
|
2014-10-23 18:50:31 -07:00
|
|
|
|
2014-10-21 15:40:54 -07:00
|
|
|
class VsyncObserver
|
|
|
|
{
|
2014-12-18 08:30:06 -08:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncObserver)
|
2014-10-23 18:50:31 -07:00
|
|
|
|
2014-10-21 15:40:54 -07:00
|
|
|
public:
|
|
|
|
// The method called when a vsync occurs. Return true if some work was done.
|
2015-01-07 18:17:36 -08: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 15:40:54 -07:00
|
|
|
virtual bool NotifyVsync(TimeStamp aVsyncTimestamp) = 0;
|
|
|
|
|
|
|
|
protected:
|
2014-10-23 18:50:31 -07:00
|
|
|
VsyncObserver() {}
|
|
|
|
virtual ~VsyncObserver() {}
|
2014-11-18 13:28:42 -08:00
|
|
|
}; // VsyncObserver
|
2014-10-21 15:40:54 -07:00
|
|
|
|
2015-01-07 18:17:36 -08:00
|
|
|
// Used to dispatch vsync events in the parent process to compositors
|
2015-03-21 09:28:04 -07:00
|
|
|
class CompositorVsyncDispatcher final
|
2014-10-21 15:40:54 -07:00
|
|
|
{
|
2014-12-19 12:52:42 -08:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorVsyncDispatcher)
|
2015-01-07 18:17:36 -08:00
|
|
|
|
2014-10-21 15:40:54 -07:00
|
|
|
public:
|
2014-12-19 12:52:42 -08:00
|
|
|
CompositorVsyncDispatcher();
|
2014-12-18 08:30:06 -08:00
|
|
|
|
2014-10-23 18:50:31 -07:00
|
|
|
// Called on the vsync thread when a hardware vsync occurs
|
2014-10-29 13:37:06 -07:00
|
|
|
void NotifyVsync(TimeStamp aVsyncTimestamp);
|
2014-10-21 15:40:54 -07:00
|
|
|
|
|
|
|
// Compositor vsync observers must be added/removed on the compositor thread
|
2014-12-18 08:30:06 -08:00
|
|
|
void SetCompositorVsyncObserver(VsyncObserver* aVsyncObserver);
|
|
|
|
void Shutdown();
|
2014-10-21 15:40:54 -07:00
|
|
|
|
2015-01-23 11:19:53 -08: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 15:40:54 -07:00
|
|
|
private:
|
2015-01-23 11:19:53 -08:00
|
|
|
void AssertOnCompositorThread();
|
2014-12-19 12:52:42 -08:00
|
|
|
virtual ~CompositorVsyncDispatcher();
|
2015-01-20 08:31:24 -08:00
|
|
|
void ObserveVsync(bool aEnable);
|
2015-01-07 18:17:36 -08:00
|
|
|
|
2014-10-23 18:50:31 -07:00
|
|
|
Mutex mCompositorObserverLock;
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<VsyncObserver> mCompositorVsyncObserver;
|
2015-01-20 08:31:24 -08:00
|
|
|
bool mDidShutdown;
|
2014-12-19 12:52:42 -08:00
|
|
|
};
|
2014-10-21 15:40:54 -07:00
|
|
|
|
2015-01-07 18:17:36 -08:00
|
|
|
// Dispatch vsync event to ipc actor parent and chrome RefreshTimer.
|
2015-03-21 09:28:04 -07:00
|
|
|
class RefreshTimerVsyncDispatcher final
|
2015-01-07 18:17:36 -08: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 08:31:26 -08:00
|
|
|
void UpdateVsyncStatus();
|
|
|
|
bool NeedsVsync();
|
2015-01-07 18:17:36 -08:00
|
|
|
|
|
|
|
Mutex mRefreshTimersLock;
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<VsyncObserver> mParentRefreshTimer;
|
|
|
|
nsTArray<RefPtr<VsyncObserver>> mChildRefreshTimers;
|
2015-01-07 18:17:36 -08:00
|
|
|
};
|
|
|
|
|
2014-10-21 15:40:54 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-01-07 18:17:36 -08:00
|
|
|
#endif // mozilla_widget_VsyncDispatcher_h
|