Bug 1591523 - Move existing NativeLayer management into RenderCompositorOGL. r=sotaro

Differential Revision: https://phabricator.services.mozilla.com/D50724

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2019-10-29 20:50:33 +00:00
Родитель 67f934d684
Коммит f2c9430255
9 изменённых файлов: 39 добавлений и 43 удалений

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

@ -19,7 +19,6 @@ class GLContext;
}
namespace layers {
class NativeLayer;
class SyncObjectHost;
} // namespace layers
@ -37,7 +36,7 @@ class RenderCompositor {
RenderCompositor(RefPtr<widget::CompositorWidget>&& aWidget);
virtual ~RenderCompositor();
virtual bool BeginFrame(layers::NativeLayer* aNativeLayer) = 0;
virtual bool BeginFrame() = 0;
virtual void EndFrame() = 0;
// Returns false when waiting gpu tasks is failed.
// It might happen when rendering context is lost.

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

@ -349,8 +349,7 @@ RefPtr<IDXGISwapChain1> RenderCompositorANGLE::CreateSwapChainForDComp(
return nullptr;
}
bool RenderCompositorANGLE::BeginFrame(layers::NativeLayer* aNativeLayer) {
MOZ_RELEASE_ASSERT(!aNativeLayer, "Unexpected native layer on this platform");
bool RenderCompositorANGLE::BeginFrame() {
mWidget->AsWindows()->UpdateCompositorWndSizeIfNecessary();
if (mDCLayerTree) {

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

@ -39,7 +39,7 @@ class RenderCompositorANGLE : public RenderCompositor {
virtual ~RenderCompositorANGLE();
bool Initialize();
bool BeginFrame(layers::NativeLayer* aNativeLayer) override;
bool BeginFrame() override;
void EndFrame() override;
bool WaitForGPU() override;
void Pause() override;

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

@ -63,8 +63,7 @@ RenderCompositorEGL::~RenderCompositorEGL() {
DestroyEGLSurface();
}
bool RenderCompositorEGL::BeginFrame(layers::NativeLayer* aNativeLayer) {
MOZ_RELEASE_ASSERT(!aNativeLayer, "Unexpected native layer on this platform");
bool RenderCompositorEGL::BeginFrame() {
#ifdef MOZ_WAYLAND
bool newSurface =
mWidget->AsX11() && mWidget->AsX11()->WaylandRequestsUpdatingEGLSurface();

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

@ -22,7 +22,7 @@ class RenderCompositorEGL : public RenderCompositor {
explicit RenderCompositorEGL(RefPtr<widget::CompositorWidget> aWidget);
virtual ~RenderCompositorEGL();
bool BeginFrame(layers::NativeLayer* aNativeLayer) override;
bool BeginFrame() override;
void EndFrame() override;
void Pause() override;
bool Resume() override;

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

@ -32,12 +32,28 @@ RenderCompositorOGL::RenderCompositorOGL(
RefPtr<gl::GLContext>&& aGL, RefPtr<widget::CompositorWidget>&& aWidget)
: RenderCompositor(std::move(aWidget)),
mGL(aGL),
mNativeLayerRoot(GetWidget()->GetNativeLayerRoot()),
mPreviousFrameDoneSync(nullptr),
mThisFrameDoneSync(nullptr) {
MOZ_ASSERT(mGL);
if (mNativeLayerRoot) {
mNativeLayerForEntireWindow = mNativeLayerRoot->CreateLayer();
mNativeLayerForEntireWindow->SetSurfaceIsFlipped(true);
mNativeLayerForEntireWindow->SetGLContext(mGL);
mNativeLayerRoot->AppendLayer(mNativeLayerForEntireWindow);
}
}
RenderCompositorOGL::~RenderCompositorOGL() {
if (mNativeLayerRoot) {
if (mNativeLayerForEntireWindow) {
mNativeLayerRoot->RemoveLayer(mNativeLayerForEntireWindow);
mNativeLayerForEntireWindow = nullptr;
}
mNativeLayerRoot = nullptr;
}
if (!mGL->MakeCurrent()) {
gfxCriticalNote
<< "Failed to make render context current during destroying.";
@ -55,21 +71,21 @@ RenderCompositorOGL::~RenderCompositorOGL() {
}
}
bool RenderCompositorOGL::BeginFrame(layers::NativeLayer* aNativeLayer) {
bool RenderCompositorOGL::BeginFrame() {
if (!mGL->MakeCurrent()) {
gfxCriticalNote << "Failed to make render context current, can't draw.";
return false;
}
if (aNativeLayer) {
aNativeLayer->SetSurfaceIsFlipped(true);
aNativeLayer->SetGLContext(mGL);
Maybe<GLuint> fbo = aNativeLayer->NextSurfaceAsFramebuffer(true);
if (mNativeLayerForEntireWindow) {
gfx::IntRect bounds({}, GetBufferSize().ToUnknownSize());
mNativeLayerForEntireWindow->SetRect(bounds);
Maybe<GLuint> fbo =
mNativeLayerForEntireWindow->NextSurfaceAsFramebuffer(true);
if (!fbo) {
return false;
}
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, *fbo);
mCurrentNativeLayer = aNativeLayer;
} else {
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGL->GetDefaultFramebuffer());
}
@ -81,9 +97,8 @@ void RenderCompositorOGL::EndFrame() {
InsertFrameDoneSync();
mGL->SwapBuffers();
if (mCurrentNativeLayer) {
mCurrentNativeLayer->NotifySurfaceReady();
mCurrentNativeLayer = nullptr;
if (mNativeLayerForEntireWindow) {
mNativeLayerForEntireWindow->NotifySurfaceReady();
}
}

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

@ -11,6 +11,11 @@
namespace mozilla {
namespace layers {
class NativeLayerRoot;
class NativeLayer;
} // namespace layers
namespace wr {
class RenderCompositorOGL : public RenderCompositor {
@ -22,7 +27,7 @@ class RenderCompositorOGL : public RenderCompositor {
RefPtr<widget::CompositorWidget>&& aWidget);
virtual ~RenderCompositorOGL();
bool BeginFrame(layers::NativeLayer* aNativeLayer) override;
bool BeginFrame() override;
void EndFrame() override;
bool WaitForGPU() override;
void Pause() override;
@ -39,10 +44,9 @@ class RenderCompositorOGL : public RenderCompositor {
RefPtr<gl::GLContext> mGL;
// The native layer that we're currently rendering to, if any.
// Non-null only between BeginFrame and EndFrame if BeginFrame has been called
// with a non-null aNativeLayer.
RefPtr<layers::NativeLayer> mCurrentNativeLayer;
// Can be null.
RefPtr<layers::NativeLayerRoot> mNativeLayerRoot;
RefPtr<layers::NativeLayer> mNativeLayerForEntireWindow;
// Used to apply back-pressure in WaitForGPU().
GLsync mPreviousFrameDoneSync;

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

@ -58,12 +58,6 @@ RendererOGL::RendererOGL(RefPtr<RenderThread>&& aThread,
MOZ_ASSERT(mRenderer);
MOZ_ASSERT(mBridge);
MOZ_COUNT_CTOR(RendererOGL);
mNativeLayerRoot = mCompositor->GetWidget()->GetNativeLayerRoot();
if (mNativeLayerRoot) {
mNativeLayerForEntireWindow = mNativeLayerRoot->CreateLayer();
mNativeLayerRoot->AppendLayer(mNativeLayerForEntireWindow);
}
}
RendererOGL::~RendererOGL() {
@ -74,11 +68,6 @@ RendererOGL::~RendererOGL() {
// Leak resources!
return;
}
if (mNativeLayerRoot) {
mNativeLayerRoot->RemoveLayer(mNativeLayerForEntireWindow);
mNativeLayerForEntireWindow = nullptr;
mNativeLayerRoot = nullptr;
}
wr_renderer_delete(mRenderer);
}
@ -120,12 +109,7 @@ bool RendererOGL::UpdateAndRender(const Maybe<gfx::IntSize>& aReadbackSize,
}
// XXX set clear color if MOZ_WIDGET_ANDROID is defined.
if (mNativeLayerForEntireWindow) {
gfx::IntRect bounds({}, mCompositor->GetBufferSize().ToUnknownSize());
mNativeLayerForEntireWindow->SetRect(bounds);
}
if (!mCompositor->BeginFrame(mNativeLayerForEntireWindow)) {
if (!mCompositor->BeginFrame()) {
if (mCompositor->IsContextLost()) {
RenderThread::Get()->HandleDeviceReset("BeginFrame", /* aNotify */ true);
}

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

@ -26,8 +26,6 @@ class GLContext;
namespace layers {
class CompositorBridgeParent;
class NativeLayerRoot;
class NativeLayer;
class SyncObjectHost;
} // namespace layers
@ -108,8 +106,6 @@ class RendererOGL {
protected:
RefPtr<RenderThread> mThread;
UniquePtr<RenderCompositor> mCompositor;
RefPtr<layers::NativeLayerRoot> mNativeLayerRoot;
RefPtr<layers::NativeLayer> mNativeLayerForEntireWindow;
wr::Renderer* mRenderer;
layers::CompositorBridgeParent* mBridge;
wr::WindowId mWindowId;