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