Bug 1435282 - Add a helper FlushPendingComposite function. r?sotaro
This extracts a code pattern that appears a couple of times in the code.
It occurs in CompositorBridgeParent as well but there's some extra stuff
involved there with the mOverrideComposeReadiness flag that I don't
understand so I'm leaving that as-is for now.
MozReview-Commit-ID: 2xqgaQZT4e1
--- a/gfx/layers/ipc/CompositorVsyncScheduler.cpp
+++ b/gfx/layers/ipc/CompositorVsyncScheduler.cpp
@@ -281,16 +281,28 @@ CompositorVsyncScheduler::ForceComposeTo
bool
CompositorVsyncScheduler::NeedsComposite()
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
return mNeedsComposite;
}
+bool
+CompositorVsyncScheduler::FlushPendingComposite()
+{
+ MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
+ if (mNeedsComposite) {
+ CancelCurrentCompositeTask();
+ ForceComposeToTarget(nullptr, nullptr);
+ return true;
+ }
+ return false;
+}
+
void
CompositorVsyncScheduler::ObserveVsync()
{
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
mWidget->ObserveVsync(mVsyncObserver);
mIsObservingVsync = true;
}
--- a/gfx/layers/ipc/CompositorVsyncScheduler.h
+++ b/gfx/layers/ipc/CompositorVsyncScheduler.h
@@ -76,16 +76,23 @@ public:
/**
* Force a composite to happen right away, without waiting for the next vsync.
* This must be called on the compositor thread.
*/
void ForceComposeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect);
/**
+ * If a composite is pending, force it to trigger right away. This must be
+ * called on the compositor thread. Returns true if there was a composite
+ * flushed.
+ */
+ bool FlushPendingComposite();
+
+ /**
* Return the vsync timestamp of the last or ongoing composite. Must be called
* on the compositor thread.
*/
const TimeStamp& GetLastComposeTime() const;
private:
virtual ~CompositorVsyncScheduler();
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -800,21 +800,17 @@ WebRenderBridgeParent::RecvGetSnapshot(P
MOZ_ASSERT(bufferTexture->GetFormat() == SurfaceFormat::B8G8R8A8);
uint32_t buffer_size = size.width * size.height * 4;
// Assert the stride of the buffer is what webrender expects
MOZ_ASSERT((uint32_t)(size.width * 4) == stride);
mForceRendering = true;
- if (mCompositorScheduler->NeedsComposite()) {
- mCompositorScheduler->CancelCurrentCompositeTask();
- mCompositorScheduler->ForceComposeToTarget(nullptr, nullptr);
- }
-
+ mCompositorScheduler->FlushPendingComposite();
mApi->Readback(size, buffer, buffer_size);
mForceRendering = false;
return IPC_OK();
}
mozilla::ipc::IPCResult
@@ -1343,25 +1339,21 @@ WebRenderBridgeParent::ScheduleGenerateF
void
WebRenderBridgeParent::FlushRendering(bool aIsSync)
{
if (mDestroyed) {
return;
}
- if (!mCompositorScheduler->NeedsComposite()) {
- return;
- }
-
mForceRendering = true;
- mCompositorScheduler->CancelCurrentCompositeTask();
- mCompositorScheduler->ForceComposeToTarget(nullptr, nullptr);
- if (aIsSync) {
- mApi->WaitFlushed();
+ if (mCompositorScheduler->FlushPendingComposite()) {
+ if (aIsSync) {
+ mApi->WaitFlushed();
+ }
}
mForceRendering = false;
}
void
WebRenderBridgeParent::Pause()
{
MOZ_ASSERT(mWidget);