diff --git a/gfx/webrender_bindings/RenderCompositor.h b/gfx/webrender_bindings/RenderCompositor.h index 71118a548b7d..f40ff9859e5d 100644 --- a/gfx/webrender_bindings/RenderCompositor.h +++ b/gfx/webrender_bindings/RenderCompositor.h @@ -136,6 +136,10 @@ class RenderCompositor { bool* aNeedsYFlip) { return false; } + virtual bool MaybeGrabScreenshot(const gfx::IntSize& aWindowSize) { + return false; + } + virtual bool MaybeProcessScreenshotQueue() { return false; } protected: // We default this to 2, so that mLatestRenderFrameId.Prev() is always valid. diff --git a/gfx/webrender_bindings/RenderCompositorNative.cpp b/gfx/webrender_bindings/RenderCompositorNative.cpp index f650372bfb43..4d2db8252fb3 100644 --- a/gfx/webrender_bindings/RenderCompositorNative.cpp +++ b/gfx/webrender_bindings/RenderCompositorNative.cpp @@ -35,6 +35,7 @@ RenderCompositorNative::RenderCompositorNative( } RenderCompositorNative::~RenderCompositorNative() { + mProfilerScreenshotGrabber.Destroy(); mNativeLayerRoot->SetLayers({}); mNativeLayerForEntireWindow = nullptr; mNativeLayerRootSnapshotter = nullptr; @@ -121,6 +122,39 @@ bool RenderCompositorNative::MaybeReadback( return success; } +bool RenderCompositorNative::MaybeGrabScreenshot( + const gfx::IntSize& aWindowSize) { + if (!ShouldUseNativeCompositor()) { + return false; + } + + if (!mNativeLayerRootSnapshotter) { + mNativeLayerRootSnapshotter = mNativeLayerRoot->CreateSnapshotter(); + } + mNativeLayerRootSnapshotter->MaybeGrabProfilerScreenshot( + &mProfilerScreenshotGrabber, aWindowSize); + + // MaybeGrabScreenshot might have changed the current context. Make sure our + // context is current again. + MakeCurrent(); + + return true; +} + +bool RenderCompositorNative::MaybeProcessScreenshotQueue() { + if (!ShouldUseNativeCompositor()) { + return false; + } + + mProfilerScreenshotGrabber.MaybeProcessQueue(); + + // MaybeProcessQueue might have changed the current context. Make sure our + // context is current again. + MakeCurrent(); + + return true; +} + uint32_t RenderCompositorNative::GetMaxUpdateRects() { if (ShouldUseNativeCompositor() && StaticPrefs::gfx_webrender_compositor_max_update_rects_AtStartup() > 0) { diff --git a/gfx/webrender_bindings/RenderCompositorNative.h b/gfx/webrender_bindings/RenderCompositorNative.h index d9c3a39a6934..51f6c71c4cb7 100644 --- a/gfx/webrender_bindings/RenderCompositorNative.h +++ b/gfx/webrender_bindings/RenderCompositorNative.h @@ -8,6 +8,7 @@ #define MOZILLA_GFX_RENDERCOMPOSITOR_NATIVE_H #include "GLTypes.h" +#include "mozilla/layers/ScreenshotGrabber.h" #include "mozilla/webrender/RenderCompositor.h" #include "mozilla/TimeStamp.h" @@ -45,6 +46,8 @@ class RenderCompositorNative : public RenderCompositor { const wr::ImageFormat& aReadbackFormat, const Range& aReadbackBuffer, bool* aNeedsYFlip) override; + bool MaybeGrabScreenshot(const gfx::IntSize& aWindowSize) override; + bool MaybeProcessScreenshotQueue() override; // Interface for wr::Compositor void CompositorBeginFrame() override; @@ -84,6 +87,7 @@ class RenderCompositorNative : public RenderCompositor { // Can be null. RefPtr mNativeLayerRoot; UniquePtr mNativeLayerRootSnapshotter; + layers::ScreenshotGrabber mProfilerScreenshotGrabber; RefPtr mNativeLayerForEntireWindow; RefPtr mSurfacePoolHandle; diff --git a/gfx/webrender_bindings/RendererOGL.cpp b/gfx/webrender_bindings/RendererOGL.cpp index 3a0493e13d5c..548ed3fe6c81 100644 --- a/gfx/webrender_bindings/RendererOGL.cpp +++ b/gfx/webrender_bindings/RendererOGL.cpp @@ -180,7 +180,9 @@ RenderedFrameId RendererOGL::UpdateAndRender( } } - mScreenshotGrabber.MaybeGrabScreenshot(this, size.ToUnknownSize()); + if (!mCompositor->MaybeGrabScreenshot(size.ToUnknownSize())) { + mScreenshotGrabber.MaybeGrabScreenshot(this, size.ToUnknownSize()); + } RenderedFrameId frameId = mCompositor->EndFrame(dirtyRects); @@ -196,7 +198,9 @@ RenderedFrameId RendererOGL::UpdateAndRender( mFrameStartTime = TimeStamp(); #endif - mScreenshotGrabber.MaybeProcessQueue(this); + if (!mCompositor->MaybeProcessScreenshotQueue()) { + mScreenshotGrabber.MaybeProcessQueue(this); + } // TODO: Flush pending actions such as texture deletions/unlocks and // textureHosts recycling.