Bug 1435022 - Inline the SetNeedsComposite function. r=sotaro

SetNeedsComposite is only ever called from one place on the compositor
thread, but it has a bunch of generic boilerplate to handle being called
from any thread. If we inline it we don't need the extra boilerplate and
it's much simpler to follow the code.

MozReview-Commit-ID: E1AcMh80KsH

--HG--
extra : rebase_source : 717fe101a3b23e30f8443110de5b6bf1a84cddda
This commit is contained in:
Kartikaya Gupta 2018-02-01 16:28:53 -05:00
Родитель 88a5174812
Коммит 00c2abf4c9
2 изменённых файлов: 10 добавлений и 56 удалений

Просмотреть файл

@ -82,8 +82,6 @@ CompositorVsyncScheduler::CompositorVsyncScheduler(CompositorVsyncSchedulerOwner
, mWidget(aWidget) , mWidget(aWidget)
, mCurrentCompositeTaskMonitor("CurrentCompositeTaskMonitor") , mCurrentCompositeTaskMonitor("CurrentCompositeTaskMonitor")
, mCurrentCompositeTask(nullptr) , mCurrentCompositeTask(nullptr)
, mSetNeedsCompositeMonitor("SetNeedsCompositeMonitor")
, mSetNeedsCompositeTask(nullptr)
, mCurrentVRListenerTaskMonitor("CurrentVRTaskMonitor") , mCurrentVRListenerTaskMonitor("CurrentVRTaskMonitor")
, mCurrentVRListenerTask(nullptr) , mCurrentVRListenerTask(nullptr)
{ {
@ -116,7 +114,7 @@ CompositorVsyncScheduler::Destroy()
mVsyncObserver->Destroy(); mVsyncObserver->Destroy();
mVsyncObserver = nullptr; mVsyncObserver = nullptr;
CancelCurrentSetNeedsCompositeTask(); mNeedsComposite = 0;
CancelCurrentCompositeTask(); CancelCurrentCompositeTask();
} }
@ -173,54 +171,15 @@ CompositorVsyncScheduler::ScheduleComposition()
PostCompositeTask(TimeStamp::Now()); PostCompositeTask(TimeStamp::Now());
#endif #endif
} else { } else {
SetNeedsComposite(); mNeedsComposite++;
} if (!mIsObservingVsync && mNeedsComposite) {
} ObserveVsync();
// Starting to observe vsync is an async operation that goes
void // through the main thread of the UI process. It's possible that
CompositorVsyncScheduler::CancelCurrentSetNeedsCompositeTask() // we're blocking there waiting on a composite, so schedule an initial
{ // one now to get things started.
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); PostCompositeTask(TimeStamp::Now());
MonitorAutoLock lock(mSetNeedsCompositeMonitor); }
if (mSetNeedsCompositeTask) {
mSetNeedsCompositeTask->Cancel();
mSetNeedsCompositeTask = nullptr;
}
mNeedsComposite = 0;
}
/**
* TODO Potential performance heuristics:
* If a composite takes 17 ms, do we composite ASAP or wait until next vsync?
* If a layer transaction comes after vsync, do we composite ASAP or wait until
* next vsync?
* How many skipped vsync events until we stop listening to vsync events?
*/
void
CompositorVsyncScheduler::SetNeedsComposite()
{
if (!CompositorThreadHolder::IsInCompositorThread()) {
MonitorAutoLock lock(mSetNeedsCompositeMonitor);
RefPtr<CancelableRunnable> task = NewCancelableRunnableMethod(
"layers::CompositorVsyncScheduler::SetNeedsComposite",
this,
&CompositorVsyncScheduler::SetNeedsComposite);
mSetNeedsCompositeTask = task;
ScheduleTask(task.forget());
return;
} else {
MonitorAutoLock lock(mSetNeedsCompositeMonitor);
mSetNeedsCompositeTask = nullptr;
}
mNeedsComposite++;
if (!mIsObservingVsync && mNeedsComposite) {
ObserveVsync();
// Starting to observe vsync is an async operation that goes
// through the main thread of the UI process. It's possible that
// we're blocking there waiting on a composite, so schedule an initial
// one now to get things started.
PostCompositeTask(TimeStamp::Now());
} }
} }

Просмотреть файл

@ -49,7 +49,6 @@ public:
widget::CompositorWidget* aWidget); widget::CompositorWidget* aWidget);
bool NotifyVsync(TimeStamp aVsyncTimestamp); bool NotifyVsync(TimeStamp aVsyncTimestamp);
void SetNeedsComposite();
/** /**
* Do cleanup. This must be called on the compositor thread. * Do cleanup. This must be called on the compositor thread.
@ -93,7 +92,6 @@ private:
void UnobserveVsync(); void UnobserveVsync();
void DispatchTouchEvents(TimeStamp aVsyncTimestamp); void DispatchTouchEvents(TimeStamp aVsyncTimestamp);
void DispatchVREvents(TimeStamp aVsyncTimestamp); void DispatchVREvents(TimeStamp aVsyncTimestamp);
void CancelCurrentSetNeedsCompositeTask();
class Observer final : public VsyncObserver class Observer final : public VsyncObserver
{ {
@ -126,9 +124,6 @@ private:
mozilla::Monitor mCurrentCompositeTaskMonitor; mozilla::Monitor mCurrentCompositeTaskMonitor;
RefPtr<CancelableRunnable> mCurrentCompositeTask; RefPtr<CancelableRunnable> mCurrentCompositeTask;
mozilla::Monitor mSetNeedsCompositeMonitor;
RefPtr<CancelableRunnable> mSetNeedsCompositeTask;
mozilla::Monitor mCurrentVRListenerTaskMonitor; mozilla::Monitor mCurrentVRListenerTaskMonitor;
RefPtr<Runnable> mCurrentVRListenerTask; RefPtr<Runnable> mCurrentVRListenerTask;
}; };