From 9117630ce95675e107aa97d753dd9867f01d9676 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 7 Jul 2015 15:38:38 +1200 Subject: [PATCH] Bug 1143575. Store composition time in Compositor. r=nical We'll need this later so ImageHost can select the correct image to use. Adding a TimeStamp parameter to BeginFrame is a bit annoying since BeginFrame is overridden by every subclass. It's a bit more convenient to just call a separate non-virtual method just before we call BeginFrame. --- gfx/layers/Compositor.h | 13 ++++++++++- .../composite/LayerManagerComposite.cpp | 22 +++++-------------- gfx/layers/composite/LayerManagerComposite.h | 16 +++++++++++--- gfx/layers/ipc/CompositorParent.cpp | 3 ++- gfx/layers/ipc/LayerTransactionParent.cpp | 2 +- gfx/tests/gtest/TestCompositor.cpp | 2 +- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/gfx/layers/Compositor.h b/gfx/layers/Compositor.h index 8771076d9dd..04a43aa6753 100644 --- a/gfx/layers/Compositor.h +++ b/gfx/layers/Compositor.h @@ -478,11 +478,17 @@ public: ScreenRotation GetScreenRotation() const { return mScreenRotation; } - void SetScreenRotation(ScreenRotation aRotation) { mScreenRotation = aRotation; } + TimeStamp GetCompositionTime() const { + return mCompositionTime; + } + void SetCompositionTime(TimeStamp aTimeStamp) { + mCompositionTime = aTimeStamp; + } + protected: void DrawDiagnosticsInternal(DiagnosticFlags aFlags, const gfx::Rect& aVisibleRect, @@ -497,6 +503,11 @@ protected: */ static void SetBackend(LayersBackend backend); + /** + * Render time for the current composition. + */ + TimeStamp mCompositionTime; + uint32_t mCompositorID; DiagnosticTypes mDiagnosticTypes; PCompositorParent* mParent; diff --git a/gfx/layers/composite/LayerManagerComposite.cpp b/gfx/layers/composite/LayerManagerComposite.cpp index 61b2aa8e842..0c817553a37 100644 --- a/gfx/layers/composite/LayerManagerComposite.cpp +++ b/gfx/layers/composite/LayerManagerComposite.cpp @@ -248,27 +248,11 @@ LayerManagerComposite::ApplyOcclusionCulling(Layer* aLayer, nsIntRegion& aOpaque } } -bool -LayerManagerComposite::EndEmptyTransaction(EndTransactionFlags aFlags) -{ - NS_ASSERTION(mInTransaction, "Didn't call BeginTransaction?"); - if (!mRoot) { - mInTransaction = false; - mIsCompositorReady = false; - return false; - } - - EndTransaction(nullptr, nullptr); - return true; -} - void -LayerManagerComposite::EndTransaction(DrawPaintedLayerCallback aCallback, - void* aCallbackData, +LayerManagerComposite::EndTransaction(const TimeStamp& aTimeStamp, EndTransactionFlags aFlags) { NS_ASSERTION(mInTransaction, "Didn't call BeginTransaction?"); - NS_ASSERTION(!aCallback && !aCallbackData, "Not expecting callbacks here"); NS_ASSERTION(!(aFlags & END_NO_COMPOSITE), "Shouldn't get END_NO_COMPOSITE here"); mInTransaction = false; @@ -300,6 +284,10 @@ LayerManagerComposite::EndTransaction(DrawPaintedLayerCallback aCallback, } if (mRoot && !(aFlags & END_NO_IMMEDIATE_REDRAW)) { + MOZ_ASSERT(!aTimeStamp.IsNull()); + // Set composition timestamp here because we need it in + // ComputeEffectiveTransforms (so the correct video frame size is picked) + mCompositor->SetCompositionTime(aTimeStamp); // The results of our drawing always go directly into a pixel buffer, // so we don't need to pass any global transform here. mRoot->ComputeEffectiveTransforms(gfx::Matrix4x4()); diff --git a/gfx/layers/composite/LayerManagerComposite.h b/gfx/layers/composite/LayerManagerComposite.h index 29f1ea943f9..6451b7acb9d 100644 --- a/gfx/layers/composite/LayerManagerComposite.h +++ b/gfx/layers/composite/LayerManagerComposite.h @@ -109,12 +109,22 @@ public: { MOZ_CRASH("Use BeginTransactionWithDrawTarget"); } - void BeginTransactionWithDrawTarget(gfx::DrawTarget* aTarget, const gfx::IntRect& aRect); + void BeginTransactionWithDrawTarget(gfx::DrawTarget* aTarget, + const gfx::IntRect& aRect); - virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT) override; + virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT) override + { + MOZ_CRASH("Use EndTransaction(aTimeStamp)"); + return false; + } virtual void EndTransaction(DrawPaintedLayerCallback aCallback, void* aCallbackData, - EndTransactionFlags aFlags = END_DEFAULT) override; + EndTransactionFlags aFlags = END_DEFAULT) override + { + MOZ_CRASH("Use EndTransaction(aTimeStamp)"); + } + void EndTransaction(const TimeStamp& aTimeStamp, + EndTransactionFlags aFlags = END_DEFAULT); virtual void SetRoot(Layer* aLayer) override { mRoot = aLayer; } diff --git a/gfx/layers/ipc/CompositorParent.cpp b/gfx/layers/ipc/CompositorParent.cpp index 79e04f1f2b0..e8581330800 100644 --- a/gfx/layers/ipc/CompositorParent.cpp +++ b/gfx/layers/ipc/CompositorParent.cpp @@ -1170,7 +1170,7 @@ CompositorParent::CompositeToTarget(DrawTarget* aTarget, const gfx::IntRect* aRe } #endif mLayerManager->SetDebugOverlayWantsNextFrame(false); - mLayerManager->EndEmptyTransaction(); + mLayerManager->EndTransaction(time); if (!aTarget) { DidComposite(); @@ -1199,6 +1199,7 @@ CompositorParent::CompositeToTarget(DrawTarget* aTarget, const gfx::IntRect* aRe // Special full-tilt composite mode for performance testing ScheduleComposition(); } + mCompositor->SetCompositionTime(TimeStamp()); mozilla::Telemetry::AccumulateTimeDelta(mozilla::Telemetry::COMPOSITE_TIME, start); profiler_tracing("Paint", "Composite", TRACING_INTERVAL_END); diff --git a/gfx/layers/ipc/LayerTransactionParent.cpp b/gfx/layers/ipc/LayerTransactionParent.cpp index 6a910fa6b0a..a29870a3dad 100644 --- a/gfx/layers/ipc/LayerTransactionParent.cpp +++ b/gfx/layers/ipc/LayerTransactionParent.cpp @@ -596,7 +596,7 @@ LayerTransactionParent::RecvUpdate(InfallibleTArray&& cset, { AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this)); - layer_manager()->EndTransaction(nullptr, nullptr, LayerManager::END_NO_IMMEDIATE_REDRAW); + layer_manager()->EndTransaction(TimeStamp(), LayerManager::END_NO_IMMEDIATE_REDRAW); } if (reply) { diff --git a/gfx/tests/gtest/TestCompositor.cpp b/gfx/tests/gtest/TestCompositor.cpp index b8c452af646..f8965a6a866 100644 --- a/gfx/tests/gtest/TestCompositor.cpp +++ b/gfx/tests/gtest/TestCompositor.cpp @@ -181,7 +181,7 @@ static bool CompositeAndCompare(nsRefPtr layerManager, Dr RefPtr drawTarget = CreateDT(); layerManager->BeginTransactionWithDrawTarget(drawTarget, IntRect(0, 0, gCompWidth, gCompHeight)); - layerManager->EndEmptyTransaction(); + layerManager->EndTransaction(TimeStamp::Now()); RefPtr ss = drawTarget->Snapshot(); RefPtr dss = ss->GetDataSurface();