Bug 1578099 - Use NativeLayer::NextSurfaceAsFramebuffer for WebRender. r=mattwoodrow

Depends on D44325

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2019-09-01 22:36:00 +00:00
Родитель c6660314f0
Коммит 85f866aad1
1 изменённых файлов: 8 добавлений и 52 удалений

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

@ -11,11 +11,6 @@
#include "mozilla/StaticPrefs_gfx.h"
#include "mozilla/widget/CompositorWidget.h"
#ifdef XP_MACOSX
# include "GLContextCGL.h"
# include "mozilla/layers/NativeLayerCA.h"
#endif
namespace mozilla {
namespace wr {
@ -60,22 +55,6 @@ RenderCompositorOGL::~RenderCompositorOGL() {
}
}
#ifdef XP_MACOSX
class SurfaceRegistryWrapperAroundGLContextCGL
: public layers::IOSurfaceRegistry {
public:
explicit SurfaceRegistryWrapperAroundGLContextCGL(gl::GLContextCGL* aContext)
: mContext(aContext) {}
void RegisterSurface(CFTypeRefPtr<IOSurfaceRef> aSurface) override {
mContext->RegisterIOSurface(aSurface.get());
}
void UnregisterSurface(CFTypeRefPtr<IOSurfaceRef> aSurface) override {
mContext->UnregisterIOSurface(aSurface.get());
}
RefPtr<gl::GLContextCGL> mContext;
};
#endif
bool RenderCompositorOGL::BeginFrame(layers::NativeLayer* aNativeLayer) {
if (!mGL->MakeCurrent()) {
gfxCriticalNote << "Failed to make render context current, can't draw.";
@ -83,35 +62,18 @@ bool RenderCompositorOGL::BeginFrame(layers::NativeLayer* aNativeLayer) {
}
if (aNativeLayer) {
#ifdef XP_MACOSX
layers::NativeLayerCA* nativeLayer = aNativeLayer->AsNativeLayerCA();
MOZ_RELEASE_ASSERT(nativeLayer, "Unexpected native layer type");
nativeLayer->SetSurfaceIsFlipped(true);
auto glContextCGL = gl::GLContextCGL::Cast(mGL);
MOZ_RELEASE_ASSERT(glContextCGL, "Unexpected GLContext type");
RefPtr<layers::IOSurfaceRegistry> currentRegistry =
nativeLayer->GetSurfaceRegistry();
if (!currentRegistry) {
nativeLayer->SetSurfaceRegistry(
MakeAndAddRef<SurfaceRegistryWrapperAroundGLContextCGL>(
glContextCGL));
} else {
MOZ_RELEASE_ASSERT(static_cast<SurfaceRegistryWrapperAroundGLContextCGL*>(
currentRegistry.get())
->mContext == glContextCGL);
}
CFTypeRefPtr<IOSurfaceRef> surf = nativeLayer->NextSurface();
if (!surf) {
aNativeLayer->SetSurfaceIsFlipped(true);
aNativeLayer->SetGLContext(mGL);
Maybe<GLuint> fbo = aNativeLayer->NextSurfaceAsFramebuffer(true);
if (!fbo) {
return false;
}
glContextCGL->UseRegisteredIOSurfaceForDefaultFramebuffer(surf.get());
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, *fbo);
mCurrentNativeLayer = aNativeLayer;
#else
MOZ_CRASH("Unexpected native layer on this platform");
#endif
} else {
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGL->GetDefaultFramebuffer());
}
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGL->GetDefaultFramebuffer());
return true;
}
@ -120,14 +82,8 @@ void RenderCompositorOGL::EndFrame() {
mGL->SwapBuffers();
if (mCurrentNativeLayer) {
#ifdef XP_MACOSX
layers::NativeLayerCA* nativeLayer = mCurrentNativeLayer->AsNativeLayerCA();
MOZ_RELEASE_ASSERT(nativeLayer, "Unexpected native layer type");
nativeLayer->NotifySurfaceReady();
mCurrentNativeLayer->NotifySurfaceReady();
mCurrentNativeLayer = nullptr;
#else
MOZ_CRASH("Unexpected native layer on this platform");
#endif
}
}