Changeset 209064 in webkit


Ignore:
Timestamp:
Nov 28, 2016 11:34:44 PM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Crash in WebCore::PlatformDisplayX11::supportsXComposite when running under Wayland
https://bugs.webkit.org/show_bug.cgi?id=164917

Reviewed by Michael Catanzaro.

WebKitGTK+ appplications are expected to call gtk_init(), because WebKitGTK+, like GTK+ itself, requires a
display to work. We currently fallback to create a X11 display when X11 is enabled in cases where GTK+ doesn't
have a default display (gtk_init() wasn't called or failed). That's why we end up creating an X11 display under
Wayland when both Wayland and X11 option are enabled. The code assumes X11 display creation will always work if
X11 is enabled, but that's not true now that we support also Wayland at runtime. So, we should try to get a
native display before creating the PlatformDisplay. Rendering will not work in any case when gtk_init() is not
called, but in most of the cases those applications are not actually going to render anything, so this way at
least we will not crash.

  • platform/graphics/PlatformDisplay.cpp:

(WebCore::PlatformDisplay::createPlatformDisplay): Use create() method for X11 and Wayland if we couldn't get a
native display from GTK+. If everything fails create a display with no native.
(WebCore::PlatformDisplay::PlatformDisplay): Add NativeDisplayOwned parameter.

  • platform/graphics/PlatformDisplay.h:
  • platform/graphics/wayland/PlatformDisplayWayland.cpp:

(WebCore::PlatformDisplayWayland::create): Try to create a native Wayland display or return nullptr.
(WebCore::PlatformDisplayWayland::PlatformDisplayWayland): Initialize NativeDisplayOwned parameter.
(WebCore::PlatformDisplayWayland::~PlatformDisplayWayland): Destroy the display if owned.
(WebCore::PlatformDisplayWayland::initialize): Return early if native display is nullptr.

  • platform/graphics/wayland/PlatformDisplayWayland.h:
  • platform/graphics/x11/PlatformDisplayX11.cpp:

(WebCore::PlatformDisplayX11::create): Try to create a native X11 display or return nullptr.
(WebCore::PlatformDisplayX11::PlatformDisplayX11): Use NativeDisplayOwned now.
(WebCore::PlatformDisplayX11::~PlatformDisplayX11): Ditto.

  • platform/graphics/x11/PlatformDisplayX11.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r209062 r209064  
     12016-11-28  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 Michael Catanzaro.
     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-28  Matt Baker  <mattbaker@apple.com>
    235
  • trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp

    r207658 r209064  
    8989#endif
    9090
    91 #if PLATFORM(X11)
    92     return std::make_unique<PlatformDisplayX11>();
     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
     105#if PLATFORM(X11)
     106    return std::make_unique<PlatformDisplayX11>(nullptr);
    93107#endif
    94108
     
    119133}
    120134
    121 PlatformDisplay::PlatformDisplay()
    122 #if USE(EGL)
    123     : m_eglDisplay(EGL_NO_DISPLAY)
     135PlatformDisplay::PlatformDisplay(NativeDisplayOwned displayOwned)
     136    : m_nativeDisplayOwned(displayOwned)
     137#if USE(EGL)
     138    , m_eglDisplay(EGL_NO_DISPLAY)
    124139#endif
    125140{
  • trunk/Source/WebCore/platform/graphics/PlatformDisplay.h

    r207658 r209064  
    7171
    7272protected:
    73     PlatformDisplay();
     73    enum class NativeDisplayOwned { No, Yes };
     74    explicit PlatformDisplay(NativeDisplayOwned = NativeDisplayOwned::No);
    7475
    7576    static void setSharedDisplayForCompositing(PlatformDisplay&);
     77
     78    NativeDisplayOwned m_nativeDisplayOwned { NativeDisplayOwned::No };
    7679
    7780#if USE(EGL)
  • trunk/Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.cpp

    r207658 r209064  
    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);
     
    5868PlatformDisplayWayland::~PlatformDisplayWayland()
    5969{
     70    if (m_nativeDisplayOwned == NativeDisplayOwned::Yes)
     71        wl_display_destroy(m_display);
    6072}
    6173
     
    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);
  • trunk/Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.h

    r205116 r209064  
    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
  • trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp

    r208985 r209064  
    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}
     
    6164    m_sharingGLContext = nullptr;
    6265#endif
    63     if (m_ownedDisplay)
     66    if (m_nativeDisplayOwned == NativeDisplayOwned::Yes)
    6467        XCloseDisplay(m_display);
    6568}
  • trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.h

    r208985 r209064  
    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
     
    5353#endif
    5454
    55     Display* m_display;
    56     bool m_ownedDisplay;
     55    Display* m_display { nullptr };
    5756    mutable std::optional<bool> m_supportsXComposite;
    5857    mutable std::optional<bool> m_supportsXDamage;
Note: See TracChangeset for help on using the changeset viewer.