Skip to content

Commit

Permalink
Remove CompositorVsyncDispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vvuk committed Jul 21, 2015
1 parent 712c409 commit f84ba2e
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 254 deletions.
27 changes: 0 additions & 27 deletions gfx/tests/gtest/TestVsync.cpp
Expand Up @@ -127,33 +127,6 @@ TEST_F(VsyncTester, EnableVsync)
ASSERT_FALSE(globalDisplay.IsVsyncEnabled());
}

// Test that if we have vsync enabled, the display should get vsync notifications
TEST_F(VsyncTester, CompositorGetVsyncNotifications)
{
if (!gfxPrefs::HardwareVsyncEnabled() || !gfxPrefs::VsyncAlignedCompositor()) {
return;
}

CompositorVsyncDispatcher::SetThreadAssertionsEnabled(false);

VsyncSource::Display& globalDisplay = mVsyncSource->GetGlobalDisplay();
globalDisplay.DisableVsync();
ASSERT_FALSE(globalDisplay.IsVsyncEnabled());

nsRefPtr<CompositorVsyncDispatcher> vsyncDispatcher = new CompositorVsyncDispatcher();
nsRefPtr<TestVsyncObserver> testVsyncObserver = new TestVsyncObserver();

vsyncDispatcher->SetCompositorVsyncObserver(testVsyncObserver);
FlushMainThreadLoop();
ASSERT_TRUE(globalDisplay.IsVsyncEnabled());

testVsyncObserver->WaitForVsyncNotification();
ASSERT_TRUE(testVsyncObserver->DidGetVsyncNotification());

vsyncDispatcher = nullptr;
testVsyncObserver = nullptr;
}

// Test that if we have vsync enabled, the parent refresh driver should get notifications
TEST_F(VsyncTester, ParentRefreshDriverGetVsyncNotifications)
{
Expand Down
55 changes: 1 addition & 54 deletions gfx/thebes/VsyncSource.cpp
Expand Up @@ -12,30 +12,10 @@
namespace mozilla {
namespace gfx {

void
VsyncSource::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
{
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
// Just use the global display until we have enough information to get the
// corresponding display for compositor.
GetGlobalDisplay().AddCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
}

void
VsyncSource::RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
{
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
// See also AddCompositorVsyncDispatcher().
GetGlobalDisplay().RemoveCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
}

nsRefPtr<RefreshTimerVsyncDispatcher>
VsyncSource::GetRefreshTimerVsyncDispatcher()
{
MOZ_ASSERT(XRE_IsParentProcess());
// See also AddCompositorVsyncDispatcher().
return GetGlobalDisplay().GetRefreshTimerVsyncDispatcher();
}

Expand All @@ -52,7 +32,6 @@ VsyncSource::Display::~Display()
MOZ_ASSERT(NS_IsMainThread());
MutexAutoLock lock(mDispatcherLock);
mRefreshTimerVsyncDispatcher = nullptr;
mCompositorVsyncDispatchers.Clear();
}

void
Expand All @@ -61,41 +40,9 @@ VsyncSource::Display::NotifyVsync(TimeStamp aVsyncTimestamp)
// Called on the vsync thread
MutexAutoLock lock(mDispatcherLock);

for (size_t i = 0; i < mCompositorVsyncDispatchers.Length(); i++) {
mCompositorVsyncDispatchers[i]->NotifyVsync(aVsyncTimestamp);
}

mRefreshTimerVsyncDispatcher->NotifyVsync(aVsyncTimestamp);
}

void
VsyncSource::Display::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aCompositorVsyncDispatcher);
{ // scope lock
MutexAutoLock lock(mDispatcherLock);
if (!mCompositorVsyncDispatchers.Contains(aCompositorVsyncDispatcher)) {
mCompositorVsyncDispatchers.AppendElement(aCompositorVsyncDispatcher);
}
}
UpdateVsyncStatus();
}

void
VsyncSource::Display::RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aCompositorVsyncDispatcher);
{ // Scope lock
MutexAutoLock lock(mDispatcherLock);
if (mCompositorVsyncDispatchers.Contains(aCompositorVsyncDispatcher)) {
mCompositorVsyncDispatchers.RemoveElement(aCompositorVsyncDispatcher);
}
}
UpdateVsyncStatus();
}

void
VsyncSource::Display::NotifyRefreshTimerVsyncStatus(bool aEnable)
{
Expand All @@ -116,7 +63,7 @@ VsyncSource::Display::UpdateVsyncStatus()
bool enableVsync = false;
{ // scope lock
MutexAutoLock lock(mDispatcherLock);
enableVsync = !mCompositorVsyncDispatchers.IsEmpty() || mRefreshTimerNeedsVsync;
enableVsync = mRefreshTimerNeedsVsync;
}

if (enableVsync) {
Expand Down
8 changes: 0 additions & 8 deletions gfx/thebes/VsyncSource.h
Expand Up @@ -14,7 +14,6 @@

namespace mozilla {
class RefreshTimerVsyncDispatcher;
class CompositorVsyncDispatcher;

namespace gfx {

Expand All @@ -25,7 +24,6 @@ class VsyncSource
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource)

typedef mozilla::RefreshTimerVsyncDispatcher RefreshTimerVsyncDispatcher;
typedef mozilla::CompositorVsyncDispatcher CompositorVsyncDispatcher;

public:
// Controls vsync unique to each display and unique on each platform
Expand All @@ -47,8 +45,6 @@ class VsyncSource

nsRefPtr<RefreshTimerVsyncDispatcher> GetRefreshTimerVsyncDispatcher();

void AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
void RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
void NotifyRefreshTimerVsyncStatus(bool aEnable);

// These should all only be called on the main thread
Expand All @@ -61,13 +57,9 @@ class VsyncSource

Mutex mDispatcherLock;
bool mRefreshTimerNeedsVsync;
nsTArray<nsRefPtr<CompositorVsyncDispatcher>> mCompositorVsyncDispatchers;
nsRefPtr<RefreshTimerVsyncDispatcher> mRefreshTimerVsyncDispatcher;
};

void AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
void RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);

nsRefPtr<RefreshTimerVsyncDispatcher> GetRefreshTimerVsyncDispatcher();
virtual Display& GetGlobalDisplay() = 0; // Works across all displays

Expand Down
3 changes: 0 additions & 3 deletions widget/PuppetWidget.cpp
Expand Up @@ -129,9 +129,6 @@ PuppetWidget::Create(nsIWidget *aParent,
obs->AddObserver(mMemoryPressureObserver, "memory-pressure", false);
}

// XXX this isn't the right place for this, but it'll work
UpdateVsyncObserver();

return NS_OK;
}

Expand Down
94 changes: 0 additions & 94 deletions widget/VsyncDispatcher.cpp
Expand Up @@ -16,100 +16,6 @@
#endif

namespace mozilla {
static bool sThreadAssertionsEnabled = true;

void CompositorVsyncDispatcher::SetThreadAssertionsEnabled(bool aEnable)
{
// Should only be used in test environments
MOZ_ASSERT(NS_IsMainThread());
sThreadAssertionsEnabled = aEnable;
}

CompositorVsyncDispatcher::CompositorVsyncDispatcher()
: mCompositorObserverLock("CompositorObserverLock")
, mDidShutdown(false)
{
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
}

CompositorVsyncDispatcher::~CompositorVsyncDispatcher()
{
MOZ_ASSERT(XRE_IsParentProcess());
// We auto remove this vsync dispatcher from the vsync source in the nsBaseWidget
}

void
CompositorVsyncDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
{
// In vsync thread
#ifdef MOZ_ENABLE_PROFILER_SPS
layers::CompositorParent::PostInsertVsyncProfilerMarker(aVsyncTimestamp);
#endif

MutexAutoLock lock(mCompositorObserverLock);
if (mCompositorVsyncObserver) {
mCompositorVsyncObserver->NotifyVsync(aVsyncTimestamp);
}
}

void
CompositorVsyncDispatcher::AssertOnCompositorThread()
{
if (!sThreadAssertionsEnabled) {
return;
}

Compositor::AssertOnCompositorThread();
}

void
CompositorVsyncDispatcher::ObserveVsync(bool aEnable)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
if (mDidShutdown) {
return;
}

if (aEnable) {
gfxPlatform::GetPlatform()->GetHardwareVsync()->AddCompositorVsyncDispatcher(this);
} else {
gfxPlatform::GetPlatform()->GetHardwareVsync()->RemoveCompositorVsyncDispatcher(this);
}
}

void
CompositorVsyncDispatcher::SetCompositorVsyncObserver(VsyncObserver* aVsyncObserver)
{
AssertOnCompositorThread();
{ // scope lock
MutexAutoLock lock(mCompositorObserverLock);
mCompositorVsyncObserver = aVsyncObserver;
}

bool observeVsync = aVsyncObserver != nullptr;
nsCOMPtr<nsIRunnable> vsyncControl = NS_NewRunnableMethodWithArg<bool>(this,
&CompositorVsyncDispatcher::ObserveVsync,
observeVsync);
NS_DispatchToMainThread(vsyncControl);
}

void
CompositorVsyncDispatcher::Shutdown()
{
// Need to explicitly remove CompositorVsyncDispatcher when the nsBaseWidget shuts down.
// Otherwise, we would get dead vsync notifications between when the nsBaseWidget
// shuts down and the CompositorParent shuts down.
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
ObserveVsync(false);
mDidShutdown = true;
{ // scope lock
MutexAutoLock lock(mCompositorObserverLock);
mCompositorVsyncObserver = nullptr;
}
}

RefreshTimerVsyncDispatcher::RefreshTimerVsyncDispatcher()
: mRefreshTimersLock("RefreshTimers lock")
Expand Down
32 changes: 1 addition & 31 deletions widget/VsyncDispatcher.h
Expand Up @@ -31,36 +31,6 @@ class VsyncObserver
virtual ~VsyncObserver() {}
}; // VsyncObserver

// Used to dispatch vsync events in the parent process to compositors
class CompositorVsyncDispatcher final
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorVsyncDispatcher)

public:
CompositorVsyncDispatcher();

// Called on the vsync thread when a hardware vsync occurs
void NotifyVsync(TimeStamp aVsyncTimestamp);

// Compositor vsync observers must be added/removed on the compositor thread
void SetCompositorVsyncObserver(VsyncObserver* aVsyncObserver);
void Shutdown();

// 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);

private:
void AssertOnCompositorThread();
virtual ~CompositorVsyncDispatcher();
void ObserveVsync(bool aEnable);

Mutex mCompositorObserverLock;
nsRefPtr<VsyncObserver> mCompositorVsyncObserver;
bool mDidShutdown;
};

// Dispatch vsync event to ipc actor parent and chrome RefreshTimer.
class RefreshTimerVsyncDispatcher final
{
Expand All @@ -69,7 +39,7 @@ class RefreshTimerVsyncDispatcher final
public:
RefreshTimerVsyncDispatcher();

// Please check CompositorVsyncDispatcher::NotifyVsync().
// Called on the vsync thread when a hardware vsync occurs
void NotifyVsync(TimeStamp aVsyncTimestamp);

// Set chrome process's RefreshTimer to this dispatcher.
Expand Down
28 changes: 0 additions & 28 deletions widget/nsBaseWidget.cpp
Expand Up @@ -153,7 +153,6 @@ nsBaseWidget::nsBaseWidget()
: mWidgetListener(nullptr)
, mAttachedWidgetListener(nullptr)
, mLayerManager(nullptr)
, mCompositorVsyncDispatcher(nullptr)
, mVsyncObserversLock("Widget vsync observer lock")
, mCursor(eCursor_standard)
, mUpdateCursor(true)
Expand Down Expand Up @@ -253,12 +252,6 @@ void nsBaseWidget::DestroyCompositor()
nsRefPtr<CompositorParent> compositorParent = mCompositorParent;
mCompositorChild->Destroy();
}

// Can have base widgets that are things like tooltips
// which don't have CompositorVsyncDispatchers
if (mCompositorVsyncDispatcher) {
mCompositorVsyncDispatcher->Shutdown();
}
}

void nsBaseWidget::DestroyLayerManager()
Expand Down Expand Up @@ -1111,27 +1104,6 @@ nsBaseWidget::GetDocument() const
return nullptr;
}

void nsBaseWidget::CreateCompositorVsyncDispatcher()
{
if (gfxPrefs::HardwareVsyncEnabled()) {
// Parent directly listens to the vsync source whereas
// child process communicate via IPC
// Should be called AFTER gfxPlatform is initialized
if (XRE_IsParentProcess()) {
mCompositorVsyncDispatcher = new CompositorVsyncDispatcher();
}
}

// XXX this isn't the right place for this, but it'll work
UpdateVsyncObserver();
}

CompositorVsyncDispatcher*
nsBaseWidget::GetCompositorVsyncDispatcher()
{
return mCompositorVsyncDispatcher;
}

namespace {

// The PBackground protocol connection callback. It will be called when
Expand Down
4 changes: 0 additions & 4 deletions widget/nsBaseWidget.h
Expand Up @@ -47,7 +47,6 @@ namespace layout {
class VsyncChild;
} // namespace layout (XXX to move from layout to gfx)

class CompositorVsyncDispatcher;
class VsyncObserver;
} // namespace mozilla

Expand Down Expand Up @@ -272,8 +271,6 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference
/*
* Vsync
*/
CompositorVsyncDispatcher* GetCompositorVsyncDispatcher() override;
void CreateCompositorVsyncDispatcher();
bool AddVsyncObserver(mozilla::VsyncObserver *aObserver) override;
bool RemoveVsyncObserver(mozilla::VsyncObserver *aObserver) override;

Expand All @@ -286,7 +283,6 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference
void UpdateVsyncObserver();
void ForwardVsyncNotification(mozilla::TimeStamp aVsyncTimestamp);

nsRefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
nsRefPtr<mozilla::layout::VsyncChild> mVsyncChild;
nsRefPtr<VsyncForwardingObserver> mIncomingVsyncObserver;
nsTArray<nsRefPtr<mozilla::VsyncObserver>> mVsyncObservers;
Expand Down

0 comments on commit f84ba2e

Please sign in to comment.