Source/WebCore/ChangeLog

 12016-11-24 Carlos Garcia Campos <cgarcia@igalia.com>
 2
 3 [GTK] Crash in WebCore::PlatformDisplayX11::supportsXComposite when running under Wayland
 4 https://bugs.webkit.org/show_bug.cgi?id=164917
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 WebKitGTK+ appplications are expected to call gtk_init(), because WebKitGTK+, like GTK+ itself, requires a
 9 display to work. We currently fallback to create a X11 display when X11 is enabled in cases where GTK+ doesn't
 10 have a default display (gtk_init() wasn't called or failed). That's why we end up creating an X11 display under
 11 Wayland when both Wayland and X11 option are enabled. The code assumes X11 display creation will always work if
 12 X11 is enabled, but that's not true now that we support also Wayland at runtime. So, we should try to get a
 13 native display before creating the PlatformDisplay. Rendering will not work in any case when gtk_init() is not
 14 called, but in most of the cases those applications are not actually going to render anything, so this way at
 15 least we will not crash.
 16
 17 * platform/graphics/PlatformDisplay.cpp:
 18 (WebCore::PlatformDisplay::createPlatformDisplay): Use create() method for X11 and Wayland if we couldn't get a
 19 native display from GTK+. If everything fails create a display with no native.
 20 (WebCore::PlatformDisplay::PlatformDisplay): Add NativeDisplayOwned parameter.
 21 * platform/graphics/PlatformDisplay.h:
 22 * platform/graphics/wayland/PlatformDisplayWayland.cpp:
 23 (WebCore::PlatformDisplayWayland::create): Try to create a native Wayland display or return nullptr.
 24 (WebCore::PlatformDisplayWayland::PlatformDisplayWayland): Initialize NativeDisplayOwned parameter.
 25 (WebCore::PlatformDisplayWayland::~PlatformDisplayWayland): Destroy the display if owned.
 26 (WebCore::PlatformDisplayWayland::initialize): Return early if native display is nullptr.
 27 * platform/graphics/wayland/PlatformDisplayWayland.h:
 28 * platform/graphics/x11/PlatformDisplayX11.cpp:
 29 (WebCore::PlatformDisplayX11::create): Try to create a native X11 display or return nullptr.
 30 (WebCore::PlatformDisplayX11::PlatformDisplayX11): Use NativeDisplayOwned now.
 31 (WebCore::PlatformDisplayX11::~PlatformDisplayX11): Ditto.
 32 * platform/graphics/x11/PlatformDisplayX11.h:
 33
1342016-11-24 Antti Koivisto <antti@apple.com>
235
336 Remove unused bool return from Element::willRecalcStyle

Source/WebCore/platform/graphics/PlatformDisplay.cpp

@@std::unique_ptr<PlatformDisplay> PlatformDisplay::createPlatformDisplay()
8888 return std::make_unique<PlatformDisplayWin>();
8989#endif
9090
 91#if PLATFORM(WAYLAND)
 92 if (auto platformDisplay = PlatformDisplayWayland::create())
 93 return platformDisplay;
 94#endif
 95
 96#if PLATFORM(X11)
 97 if (auto platformDisplay = PlatformDisplayX11::create())
 98 return platformDisplay;
 99#endif
 100
 101 // If at this point we still don't have a display, just create a fake display with no native.
 102#if PLATFORM(WAYLAND)
 103 return std::make_unique<PlatformDisplayWayland>(nullptr);
 104#endif
91105#if PLATFORM(X11)
92  return std::make_unique<PlatformDisplayX11>();
 106 return std::make_unique<PlatformDisplayX11>(nullptr);
93107#endif
94108
95109 ASSERT_NOT_REACHED();

@@void PlatformDisplay::setSharedDisplayForCompositing(PlatformDisplay& display)
118132 s_sharedDisplayForCompositing = &display;
119133}
120134
121 PlatformDisplay::PlatformDisplay()
 135PlatformDisplay::PlatformDisplay(NativeDisplayOwned displayOwned)
122136#if USE(EGL)
123137 : m_eglDisplay(EGL_NO_DISPLAY)
 138 , m_nativeDisplayOwned(displayOwned)
124139#endif
125140{
126141}

Source/WebCore/platform/graphics/PlatformDisplay.h

@@public:
7070#endif
7171
7272protected:
73  PlatformDisplay();
 73 enum class NativeDisplayOwned { No, Yes };
 74 PlatformDisplay(NativeDisplayOwned = NativeDisplayOwned::No);
7475
7576 static void setSharedDisplayForCompositing(PlatformDisplay&);
7677

@@protected:
8485 std::unique_ptr<GLContext> m_sharingGLContext;
8586#endif
8687
 88 NativeDisplayOwned m_nativeDisplayOwned { NativeDisplayOwned::No };
 89
8790private:
8891 static std::unique_ptr<PlatformDisplay> createPlatformDisplay();
8992

Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.cpp

@@const struct wl_registry_listener PlatformDisplayWayland::s_registryListener = {
5050 }
5151};
5252
53 PlatformDisplayWayland::PlatformDisplayWayland(struct wl_display* display)
 53std::unique_ptr<PlatformDisplay> PlatformDisplayWayland::create()
 54{
 55 struct wl_display* display = wl_display_connect(getenv("DISPLAY"));
 56 if (!display)
 57 return nullptr;
 58
 59 return std::make_unique<PlatformDisplayWayland>(display, NativeDisplayOwned::Yes);
 60}
 61
 62PlatformDisplayWayland::PlatformDisplayWayland(struct wl_display* display, NativeDisplayOwned displayOwned)
 63 : PlatformDisplay(displayOwned)
5464{
5565 initialize(display);
5666}
5767
5868PlatformDisplayWayland::~PlatformDisplayWayland()
5969{
 70 if (m_nativeDisplayOwned == NativeDisplayOwned::Yes)
 71 wl_display_destroy(m_display);
6072}
6173
6274void PlatformDisplayWayland::initialize(wl_display* display)
6375{
6476 m_display = display;
 77 if (!m_display)
 78 return;
 79
6580 m_registry.reset(wl_display_get_registry(m_display));
6681 wl_registry_add_listener(m_registry.get(), &s_registryListener, this);
6782 wl_display_roundtrip(m_display);

Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.h

@@namespace WebCore {
3636
3737class PlatformDisplayWayland : public PlatformDisplay {
3838public:
39  PlatformDisplayWayland(struct wl_display*);
 39 static std::unique_ptr<PlatformDisplay> create();
 40 PlatformDisplayWayland(struct wl_display*, NativeDisplayOwned = NativeDisplayOwned::No);
4041 virtual ~PlatformDisplayWayland();
4142
4243 struct wl_display* native() const { return m_display; }

Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp

4242
4343namespace WebCore {
4444
45 PlatformDisplayX11::PlatformDisplayX11()
46  : m_display(XOpenDisplay(nullptr))
 45std::unique_ptr<PlatformDisplay> PlatformDisplayX11::create()
4746{
48  m_ownedDisplay = m_display != nullptr;
 47 Display* display = XOpenDisplay(getenv("DISPLAY"));
 48 if (!display)
 49 return nullptr;
 50
 51 return std::make_unique<PlatformDisplayX11>(display, NativeDisplayOwned::Yes);
4952}
5053
51 PlatformDisplayX11::PlatformDisplayX11(Display* display)
52  : m_display(display)
53  , m_ownedDisplay(false)
 54PlatformDisplayX11::PlatformDisplayX11(Display* display, NativeDisplayOwned displayOwned)
 55 : PlatformDisplay(displayOwned)
 56 , m_display(display)
5457{
5558}
5659

@@PlatformDisplayX11::~PlatformDisplayX11()
6063 // Clear the sharing context before releasing the display.
6164 m_sharingGLContext = nullptr;
6265#endif
63  if (m_ownedDisplay)
 66 if (m_nativeDisplayOwned == NativeDisplayOwned::Yes)
6467 XCloseDisplay(m_display);
6568}
6669

Source/WebCore/platform/graphics/x11/PlatformDisplayX11.h

@@namespace WebCore {
3737
3838class PlatformDisplayX11 final : public PlatformDisplay {
3939public:
40  PlatformDisplayX11();
41  PlatformDisplayX11(Display*);
 40 static std::unique_ptr<PlatformDisplay> create();
 41 PlatformDisplayX11(Display*, NativeDisplayOwned = NativeDisplayOwned::No);
4242 virtual ~PlatformDisplayX11();
4343
4444 Display* native() const { return m_display; }

@@private:
5252 void initializeEGLDisplay() override;
5353#endif
5454
55  Display* m_display;
56  bool m_ownedDisplay;
 55 Display* m_display { nullptr };
5756 mutable Optional<bool> m_supportsXComposite;
5857 mutable Optional<bool> m_supportsXDamage;
5958 mutable Optional<int> m_damageEventBase;