diff --git a/gfx/gl/GLContextEGL.h b/gfx/gl/GLContextEGL.h index 5a88f4a2a256..39b003629401 100644 --- a/gfx/gl/GLContextEGL.h +++ b/gfx/gl/GLContextEGL.h @@ -30,6 +30,15 @@ inline std::shared_ptr DefaultEglDisplay( return lib->DefaultDisplay(out_failureId); } +inline std::shared_ptr CreateSoftwareEglDisplay( + nsACString* const out_failureId) { + const auto lib = GLLibraryEGL::Get(out_failureId); + if (!lib) { + return nullptr; + } + return lib->CreateDisplay(false, true, out_failureId); +} + // - class GLContextEGL final : public GLContext { diff --git a/gfx/gl/GLContextProviderEGL.cpp b/gfx/gl/GLContextProviderEGL.cpp index 02211238af87..c2de8d42e452 100644 --- a/gfx/gl/GLContextProviderEGL.cpp +++ b/gfx/gl/GLContextProviderEGL.cpp @@ -1242,7 +1242,11 @@ void GLContextEGL::DestroySurface(EglDisplay& aEgl, const EGLSurface aSurface) { /*static*/ already_AddRefed GLContextProviderEGL::CreateHeadless( const GLContextCreateDesc& desc, nsACString* const out_failureId) { - const auto display = DefaultEglDisplay(out_failureId); + bool useSoftwareDisplay = + static_cast(desc.flags & CreateContextFlags::FORBID_HARDWARE); + const auto display = useSoftwareDisplay + ? CreateSoftwareEglDisplay(out_failureId) + : DefaultEglDisplay(out_failureId); if (!display) { return nullptr; } diff --git a/gfx/gl/GLLibraryEGL.cpp b/gfx/gl/GLLibraryEGL.cpp index c724f96ba5be..e381dea28cd4 100644 --- a/gfx/gl/GLLibraryEGL.cpp +++ b/gfx/gl/GLLibraryEGL.cpp @@ -938,14 +938,14 @@ std::shared_ptr GLLibraryEGL::CreateDisplayLocked( ret = GetAndInitSoftwareDisplay(*this, aProofOfLock); } // Initialize the display the normal way - if (!ret && !gdk_display_get_default()) { + if (!ret && !gdk_display_get_default() && !forceSoftware) { ret = GetAndInitDeviceDisplay(*this, aProofOfLock); if (!ret) { ret = GetAndInitSurfacelessDisplay(*this, aProofOfLock); } } # ifdef MOZ_WAYLAND - else if (!ret && widget::GdkIsWaylandDisplay()) { + else if (!ret && widget::GdkIsWaylandDisplay() && !forceSoftware) { // Wayland does not support EGL_DEFAULT_DISPLAY nativeDisplay = widget::WaylandDisplayGetWLDisplay(); if (!nativeDisplay) { @@ -955,7 +955,7 @@ std::shared_ptr GLLibraryEGL::CreateDisplayLocked( } # endif #endif - if (!ret) { + if (!ret && !forceSoftware) { ret = GetAndInitDisplay(*this, nativeDisplay, aProofOfLock); } }