Skip to content

Commit

Permalink
Bug 1696845 - Use dlsym for gdk_*_display_get_type. r=stransky
Browse files Browse the repository at this point in the history
Using `dlsym` for `gdk_wayland_display_get_type` is a cleaner solution
to bug 1696319, allowing running with a GTK that lacks the Wayland
backend.

Also adds a symmetric implementation for `gdk_x11_display_get_type`,
which should help running without X11.

Differential Revision: https://phabricator.services.mozilla.com/D107406
  • Loading branch information
heftig committed Mar 9, 2021
1 parent a82889d commit 1261a74
Show file tree
Hide file tree
Showing 30 changed files with 124 additions and 125 deletions.
10 changes: 3 additions & 7 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifdef MOZ_WIDGET_GTK
# include <gdk/gdkx.h>
# include <gtk/gtk.h>
#endif

#include "BrowserChild.h"
#include "ContentChild.h"
#include "GeckoProfiler.h"
Expand Down Expand Up @@ -286,7 +281,9 @@
#include "private/pprio.h"

#ifdef MOZ_WIDGET_GTK
# include "mozilla/WidgetUtilsGtk.h"
# include "nsAppRunner.h"
# include <gtk/gtk.h>
#endif

#ifdef MOZ_CODE_COVERAGE
Expand Down Expand Up @@ -727,8 +724,7 @@ bool ContentChild::Init(MessageLoop* aIOLoop, base::ProcessId aParentPid,

#ifdef MOZ_X11
# ifdef MOZ_WIDGET_GTK
if (GDK_IS_X11_DISPLAY(gdk_display_get_default()) &&
!gfxPlatform::IsHeadless()) {
if (GdkIsX11Display() && !gfxPlatform::IsHeadless()) {
// Send the parent our X socket to act as a proxy reference for our X
// resources.
int xSocketFd = ConnectionNumber(DefaultXDisplay());
Expand Down
10 changes: 3 additions & 7 deletions dom/plugins/base/nsPluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@
# include "winbase.h"
#endif
#if (MOZ_WIDGET_GTK)
# include <gdk/gdk.h>
# include <gdk/gdkx.h>
# include "mozilla/WidgetUtilsGtk.h"
#endif

using namespace mozilla;
Expand Down Expand Up @@ -289,11 +288,8 @@ nsPluginHost::nsPluginHost()
Preferences::GetBool("plugin.override_internal_types", false);

bool waylandBackend = false;
#if defined(MOZ_WIDGET_GTK) && defined(MOZ_X11)
GdkDisplay* display = gdk_display_get_default();
if (display) {
waylandBackend = !GDK_IS_X11_DISPLAY(display);
}
#if defined(MOZ_WIDGET_GTK)
waylandBackend = mozilla::widget::GdkIsWaylandDisplay();
#endif
mPluginsDisabled =
Preferences::GetBool("plugin.disable", false) || waylandBackend;
Expand Down
3 changes: 2 additions & 1 deletion dom/plugins/ipc/PluginModuleChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mozilla/ipc/MessageChannel.h"

#ifdef MOZ_WIDGET_GTK
# include "mozilla/WidgetUtilsGtk.h"
# include <gtk/gtk.h>
# include <gdk/gdkx.h>
#endif
Expand Down Expand Up @@ -1551,7 +1552,7 @@ NPError PluginModuleChild::DoNP_Initialize(const PluginSettings& aSettings) {

#ifdef MOZ_X11
# ifdef MOZ_WIDGET_GTK
if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
if (!GdkIsX11Display()) {
// We don't support NPAPI plugins on Wayland.
return NPERR_GENERIC_ERROR;
}
Expand Down
54 changes: 24 additions & 30 deletions gfx/gl/GLContextProviderEGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,14 @@

#if defined(MOZ_WIDGET_GTK)
# include "mozilla/widget/GtkCompositorWidget.h"
# include "mozilla/WidgetUtilsGtk.h"
# if defined(MOZ_WAYLAND)
# include <dlfcn.h>
# include <gdk/gdkwayland.h>
# include <wayland-egl.h>
# define MOZ_GTK_WAYLAND 1
# endif
#endif

inline bool IsWaylandDisplay() {
#ifdef MOZ_GTK_WAYLAND
return gdk_display_get_default() &&
GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default());
#else
return false;
#endif
}

inline bool IsX11Display() {
#ifdef MOZ_WIDGET_GTK
return gdk_display_get_default() &&
GDK_IS_X11_DISPLAY(gdk_display_get_default());
#else
return false;
#endif
}

struct wl_egl_window;

using namespace mozilla::gfx;
Expand All @@ -128,15 +110,17 @@ class WaylandGLSurface {
static nsDataHashtable<nsPtrHashKey<void>, WaylandGLSurface*> sWaylandGLSurface;

void DeleteWaylandGLSurface(EGLSurface surface) {
# ifdef MOZ_GTK_WAYLAND
// We're running on Wayland which means our EGLSurface may
// have attached Wayland backend data which must be released.
if (IsWaylandDisplay()) {
if (GdkIsWaylandDisplay()) {
auto entry = sWaylandGLSurface.Lookup(surface);
if (entry) {
delete entry.Data();
entry.Remove();
}
}
# endif
}
#endif

Expand Down Expand Up @@ -269,10 +253,10 @@ already_AddRefed<GLContext> GLContextEGLFactory::CreateImpl(
}

int visualID = 0;
if (IsX11Display()) {
#ifdef MOZ_X11
GdkDisplay* gdkDisplay = gdk_display_get_default();
auto display = gdkDisplay ? GDK_DISPLAY_XDISPLAY(gdkDisplay) : nullptr;
GdkDisplay* gdkDisplay = gdk_display_get_default();
if (GdkIsX11Display(gdkDisplay)) {
auto* display = GDK_DISPLAY_XDISPLAY(gdkDisplay);
if (display) {
XWindowAttributes windowAttrs;
if (!XGetWindowAttributes(display, (Window)aWindow, &windowAttrs)) {
Expand All @@ -281,8 +265,8 @@ already_AddRefed<GLContext> GLContextEGLFactory::CreateImpl(
}
visualID = XVisualIDFromVisual(windowAttrs.visual);
}
#endif
}
#endif

bool doubleBuffered = true;

Expand Down Expand Up @@ -346,10 +330,12 @@ already_AddRefed<GLContext> GLContextEGLFactory::CreateImpl(
gl->MakeCurrent();
gl->SetIsDoubleBuffered(doubleBuffered);

if (surface && IsWaylandDisplay()) {
#ifdef MOZ_GTK_WAYLAND
if (surface && GdkIsWaylandDisplay()) {
// Make eglSwapBuffers() non-blocking on wayland
egl->fSwapInterval(0);
}
#endif
if (aWebRender && egl->mLib->IsANGLE()) {
MOZ_ASSERT(doubleBuffered);
egl->fSwapInterval(0);
Expand Down Expand Up @@ -529,10 +515,12 @@ bool GLContextEGL::RenewSurface(CompositorWidget* aWidget) {
}
const bool ok = MakeCurrent(true);
MOZ_ASSERT(ok);
if (mSurface && IsWaylandDisplay()) {
#ifdef MOZ_GTK_WAYLAND
if (mSurface && GdkIsWaylandDisplay()) {
// Make eglSwapBuffers() non-blocking on wayland
mEgl->fSwapInterval(0);
}
#endif
return ok;
}

Expand Down Expand Up @@ -1055,11 +1043,14 @@ EGLSurface GLContextEGL::CreateCompatibleSurface(void* aWindow) const {

static void FillContextAttribs(bool es3, bool useGles, nsTArray<EGLint>* out) {
out->AppendElement(LOCAL_EGL_SURFACE_TYPE);
if (IsWaylandDisplay()) {
#ifdef MOZ_GTK_WAYLAND
if (GdkIsWaylandDisplay()) {
// Wayland on desktop does not support PBuffer or FBO.
// We create a dummy wl_egl_window instead.
out->AppendElement(LOCAL_EGL_WINDOW_BIT);
} else {
} else
#endif
{
out->AppendElement(LOCAL_EGL_PBUFFER_BIT);
}

Expand Down Expand Up @@ -1175,9 +1166,12 @@ RefPtr<GLContextEGL> GLContextEGL::CreateEGLPBufferOffscreenContextImpl(

mozilla::gfx::IntSize pbSize(size);
EGLSurface surface = nullptr;
if (IsWaylandDisplay()) {
#ifdef MOZ_GTK_WAYLAND
if (GdkIsWaylandDisplay()) {
surface = GLContextEGL::CreateWaylandBufferSurface(*egl, config, pbSize);
} else {
} else
#endif
{
surface = GLContextEGL::CreatePBufferSurfaceTryingPowerOfTwo(
*egl, config, LOCAL_EGL_NONE, pbSize);
}
Expand Down
11 changes: 5 additions & 6 deletions gfx/gl/GLContextProviderWayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifdef MOZ_WIDGET_GTK
# include <gdk/gdk.h>
# include <gdk/gdkx.h>
# include "mozilla/WidgetUtilsGtk.h"
#endif

#include "GLContextProvider.h"
Expand All @@ -21,7 +20,7 @@ static class GLContextProviderEGL sGLContextProviderEGL;
already_AddRefed<GLContext> GLContextProviderWayland::CreateForCompositorWidget(
CompositorWidget* aCompositorWidget, bool aWebRender,
bool aForceAccelerated) {
if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
if (GdkIsX11Display()) {
return sGLContextProviderX11.CreateForCompositorWidget(
aCompositorWidget, aWebRender, aForceAccelerated);
} else {
Expand All @@ -33,7 +32,7 @@ already_AddRefed<GLContext> GLContextProviderWayland::CreateForCompositorWidget(
/*static*/
already_AddRefed<GLContext> GLContextProviderWayland::CreateHeadless(
const GLContextCreateDesc& desc, nsACString* const out_failureId) {
if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
if (GdkIsX11Display()) {
return sGLContextProviderX11.CreateHeadless(desc, out_failureId);
} else {
return sGLContextProviderEGL.CreateHeadless(desc, out_failureId);
Expand All @@ -42,7 +41,7 @@ already_AddRefed<GLContext> GLContextProviderWayland::CreateHeadless(

/*static*/
GLContext* GLContextProviderWayland::GetGlobalContext() {
if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
if (GdkIsX11Display()) {
return sGLContextProviderX11.GetGlobalContext();
} else {
return sGLContextProviderEGL.GetGlobalContext();
Expand All @@ -51,7 +50,7 @@ GLContext* GLContextProviderWayland::GetGlobalContext() {

/*static*/
void GLContextProviderWayland::Shutdown() {
if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
if (GdkIsX11Display()) {
sGLContextProviderX11.Shutdown();
} else {
sGLContextProviderEGL.Shutdown();
Expand Down
9 changes: 4 additions & 5 deletions gfx/gl/GLLibraryEGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
#include "GLReadTexImageHelper.h"
#include "ScopedGLHelpers.h"
#ifdef MOZ_WIDGET_GTK
# include <gdk/gdk.h>
# include "mozilla/WidgetUtilsGtk.h"
# ifdef MOZ_WAYLAND
# include <gdk/gdkwayland.h>
# include <dlfcn.h>
# include "mozilla/widget/nsWaylandDisplay.h"
# endif // MOZ_WIDGET_GTK
#endif // MOZ_WAYLAND
# include <gdk/gdk.h>
#endif // MOZ_WAYLAND

namespace mozilla {
namespace gl {
Expand Down Expand Up @@ -784,7 +783,7 @@ std::shared_ptr<EglDisplay> GLLibraryEGL::CreateDisplay(
#ifdef MOZ_WAYLAND
// Some drivers doesn't support EGL_DEFAULT_DISPLAY
GdkDisplay* gdkDisplay = gdk_display_get_default();
if (gdkDisplay && !GDK_IS_X11_DISPLAY(gdkDisplay)) {
if (widget::GdkIsWaylandDisplay(gdkDisplay)) {
nativeDisplay = widget::WaylandDisplayGetWLDisplay(gdkDisplay);
if (!nativeDisplay) {
NS_WARNING("Failed to get wl_display.");
Expand Down
3 changes: 2 additions & 1 deletion gfx/src/X11Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#if defined(MOZ_WIDGET_GTK)
# include <gdk/gdk.h>
# include <gdk/gdkx.h>
# include "mozilla/WidgetUtilsGtk.h"
# include "X11UndefineNone.h"
#else
# error Unknown toolkit
Expand All @@ -28,7 +29,7 @@ namespace mozilla {
inline Display* DefaultXDisplay() {
#if defined(MOZ_WIDGET_GTK)
GdkDisplay* gdkDisplay = gdk_display_get_default();
if (GDK_IS_X11_DISPLAY(gdkDisplay)) {
if (mozilla::widget::GdkIsX11Display(gdkDisplay)) {
return GDK_DISPLAY_XDISPLAY(gdkDisplay);
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion gfx/thebes/gfxFcPlatformFontList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#ifdef MOZ_WIDGET_GTK
# include <gdk/gdk.h>
# include "gfxPlatformGtk.h"
# include "mozilla/WidgetUtilsGtk.h"
#endif

#ifdef MOZ_X11
Expand Down Expand Up @@ -716,7 +717,7 @@ static void PreparePattern(FcPattern* aPattern, bool aIsPrinterFont) {
int lcdfilter;
if (FcPatternGet(aPattern, FC_LCD_FILTER, 0, &value) == FcResultNoMatch) {
GdkDisplay* dpy = gdk_display_get_default();
if (GDK_IS_X11_DISPLAY(dpy) &&
if (mozilla::widget::GdkIsX11Display(dpy) &&
GetXftInt(GDK_DISPLAY_XDISPLAY(dpy), "lcdfilter", &lcdfilter)) {
FcPatternAddInteger(aPattern, FC_LCD_FILTER, lcdfilter);
}
Expand Down
4 changes: 1 addition & 3 deletions gfx/thebes/gfxPlatformGtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ gfxPlatformGtk::gfxPlatformGtk() {
}

mMaxGenericSubstitutions = UNINITIALIZED_VALUE;
mIsX11Display = gfxPlatform::IsHeadless()
? false
: GDK_IS_X11_DISPLAY(gdk_display_get_default());
mIsX11Display = gfxPlatform::IsHeadless() ? false : GdkIsX11Display();
if (XRE_IsParentProcess()) {
#ifdef MOZ_X11
if (mIsX11Display && mozilla::Preferences::GetBool("gfx.xrender.enabled")) {
Expand Down
6 changes: 2 additions & 4 deletions gfx/webrender_bindings/RenderCompositorEGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
#include "mozilla/widget/CompositorWidget.h"

#ifdef MOZ_WAYLAND
# include "mozilla/WidgetUtilsGtk.h"
# include "mozilla/widget/GtkCompositorWidget.h"
# include <gdk/gdk.h>
# include <gdk/gdkx.h>
#endif

#ifdef MOZ_WIDGET_ANDROID
Expand All @@ -37,8 +36,7 @@ namespace mozilla::wr {
UniquePtr<RenderCompositor> RenderCompositorEGL::Create(
RefPtr<widget::CompositorWidget> aWidget, nsACString& aError) {
#ifdef MOZ_WAYLAND
if (!gdk_display_get_default() ||
GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
if (!mozilla::widget::GdkIsWaylandDisplay()) {
return nullptr;
}
#endif
Expand Down
5 changes: 2 additions & 3 deletions gfx/webrender_bindings/RenderThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#endif

#ifdef MOZ_WIDGET_GTK
# include <gdk/gdkx.h>
# include "mozilla/WidgetUtilsGtk.h"
#endif

#ifdef MOZ_WAYLAND
Expand Down Expand Up @@ -1125,8 +1125,7 @@ static already_AddRefed<gl::GLContext> CreateGLContext(nsACString& aError) {
#elif defined(MOZ_WIDGET_ANDROID)
gl = CreateGLContextEGL();
#elif defined(MOZ_WAYLAND)
if (gdk_display_get_default() &&
!GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
if (mozilla::widget::GdkIsWaylandDisplay()) {
gl = CreateGLContextEGL();
}
#elif XP_MACOSX
Expand Down
Loading

0 comments on commit 1261a74

Please sign in to comment.