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-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2018-12-08 02:27:28 +03:00
|
|
|
#include "VsyncSource.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.
|
2018-12-08 02:27:28 +03:00
|
|
|
virtual bool NotifyVsync(const VsyncEvent& aVsync) = 0;
|
2014-10-22 02:40:54 +04:00
|
|
|
|
|
|
|
protected:
|
2020-03-16 13:56:57 +03:00
|
|
|
VsyncObserver() = default;
|
|
|
|
virtual ~VsyncObserver() = default;
|
2014-11-19 00:28:42 +03:00
|
|
|
}; // VsyncObserver
|
2014-10-22 02:40:54 +04:00
|
|
|
|
2016-07-19 21:56:07 +03:00
|
|
|
// Used to dispatch vsync events in the parent process to compositors.
|
|
|
|
//
|
|
|
|
// When the compositor is in-process, CompositorWidgets own a
|
|
|
|
// CompositorVsyncDispatcher, and directly attach the compositor's observer
|
|
|
|
// to it.
|
|
|
|
//
|
|
|
|
// When the compositor is out-of-process, the CompositorWidgetDelegate owns
|
|
|
|
// the vsync dispatcher instead. The widget receives vsync observer/unobserve
|
|
|
|
// commands via IPDL, and uses this to attach a CompositorWidgetVsyncObserver.
|
|
|
|
// This observer forwards vsync notifications (on the vsync thread) to a
|
|
|
|
// dedicated vsync I/O thread, which then forwards the notification to the
|
|
|
|
// compositor thread in the compositor process.
|
2015-03-21 19:28:04 +03:00
|
|
|
class CompositorVsyncDispatcher final {
|
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();
|
2019-11-27 03:21:33 +03:00
|
|
|
explicit CompositorVsyncDispatcher(RefPtr<gfx::VsyncSource> aVsyncSource);
|
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
|
2018-12-08 02:27:28 +03:00
|
|
|
void NotifyVsync(const VsyncEvent& aVsync);
|
2014-10-22 02:40:54 +04:00
|
|
|
|
2020-03-17 02:24:39 +03:00
|
|
|
void MoveToSource(const RefPtr<gfx::VsyncSource>& aVsyncSource);
|
|
|
|
|
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
|
|
|
|
|
|
|
private:
|
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
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
RefPtr<gfx::VsyncSource> mVsyncSource;
|
2014-10-24 05:50:31 +04:00
|
|
|
Mutex mCompositorObserverLock;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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:
|
2019-11-27 03:21:33 +03:00
|
|
|
explicit RefreshTimerVsyncDispatcher(gfx::VsyncSource::Display* aDisplay);
|
2015-01-08 05:17:36 +03:00
|
|
|
|
|
|
|
// Please check CompositorVsyncDispatcher::NotifyVsync().
|
2018-12-08 02:27:28 +03:00
|
|
|
void NotifyVsync(const VsyncEvent& aVsync);
|
2015-01-08 05:17:36 +03:00
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
void MoveToDisplay(gfx::VsyncSource::Display* aDisplay);
|
|
|
|
|
2015-01-08 05:17:36 +03:00
|
|
|
// 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
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
// We need to hold a weak ref to the display we belong to in order to notify
|
|
|
|
// it of our vsync requirement. The display holds a RefPtr to us, so we can't
|
|
|
|
// hold a RefPtr back without causing a cyclic dependency.
|
|
|
|
gfx::VsyncSource::Display* mDisplay;
|
2015-01-08 05:17:36 +03:00
|
|
|
Mutex mRefreshTimersLock;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VsyncObserver> mParentRefreshTimer;
|
|
|
|
nsTArray<RefPtr<VsyncObserver>> mChildRefreshTimers;
|
2015-01-08 05:17:36 +03:00
|
|
|
};
|
|
|
|
|
2014-10-22 02:40:54 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-01-08 05:17:36 +03:00
|
|
|
#endif // mozilla_widget_VsyncDispatcher_h
|