Bug 1592031 - Use NativeLayerSnapshotter to capture profiler screenshots with WebRender on macOS. r=mattwoodrow

Differential Revision: https://phabricator.services.mozilla.com/D86880
This commit is contained in:
Markus Stange 2020-08-21 22:33:41 +00:00
Родитель 1191e4de06
Коммит 66928a1e5b
4 изменённых файлов: 48 добавлений и 2 удалений

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

@ -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.

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

@ -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) {

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

@ -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<uint8_t>& 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<layers::NativeLayerRoot> mNativeLayerRoot;
UniquePtr<layers::NativeLayerRootSnapshotter> mNativeLayerRootSnapshotter;
layers::ScreenshotGrabber mProfilerScreenshotGrabber;
RefPtr<layers::NativeLayer> mNativeLayerForEntireWindow;
RefPtr<layers::SurfacePoolHandle> mSurfacePoolHandle;

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

@ -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.