Skip to content

Commit

Permalink
Bug 1098701. Part 2: Allow disabling thread assertions. r=kats
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason Chang committed Jan 23, 2015
1 parent 130c675 commit fece617
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 24 additions & 3 deletions widget/VsyncDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "VsyncDispatcher.h"
#include "VsyncSource.h"
#include "gfxPlatform.h"
#include "mozilla/layers/Compositor.h"
#include "mozilla/layers/CompositorParent.h"

#ifdef MOZ_ENABLE_PROFILER_SPS
Expand All @@ -15,6 +16,14 @@
#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")
Expand Down Expand Up @@ -47,6 +56,16 @@ CompositorVsyncDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
}
}

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

Compositor::AssertOnCompositorThread();
}

void
CompositorVsyncDispatcher::ObserveVsync(bool aEnable)
{
Expand All @@ -66,9 +85,11 @@ CompositorVsyncDispatcher::ObserveVsync(bool aEnable)
void
CompositorVsyncDispatcher::SetCompositorVsyncObserver(VsyncObserver* aVsyncObserver)
{
MOZ_ASSERT(layers::CompositorParent::IsInCompositorThread());
MutexAutoLock lock(mCompositorObserverLock);
mCompositorVsyncObserver = aVsyncObserver;
AssertOnCompositorThread();
{ // scope lock
MutexAutoLock lock(mCompositorObserverLock);
mCompositorVsyncObserver = aVsyncObserver;
}

bool observeVsync = aVsyncObserver != nullptr;
nsCOMPtr<nsIRunnable> vsyncControl = NS_NewRunnableMethodWithArg<bool>(this,
Expand Down
6 changes: 6 additions & 0 deletions widget/VsyncDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ class CompositorVsyncDispatcher MOZ_FINAL
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);

Expand Down

0 comments on commit fece617

Please sign in to comment.