Changeset 183731 in webkit


Ignore:
Timestamp:
May 3, 2015 8:20:34 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK][EFL] Unify platform display handling
https://bugs.webkit.org/show_bug.cgi?id=144517

Reviewed by Martin Robinson.

Source/WebCore:

There are several places were we are handling the X display
connection:

  • GLContext::sharedX11Display() creates a new connection.
  • X11Helper::nativeDisplay() creates a new connection.
  • BackingStoreBackendCairoX11 uses the GTK+ shared connection.
  • NetscapePlugin::x11HostDisplay() uses the GTK+/ecore shared connection
  • The rest of the GTK+ code uses the shared GTK+ connection

And then we also have WaylandDisplay and the code to check if the
current display is wayland or X11.
We could unify all these to share the same connection to reduce
the amount of ifdefs and ensure a single connection. That will
also allow us to use "smart pointers" for the X resources that
need a Display* to be freed.

  • PlatformEfl.cmake: Add new files to compilation.
  • PlatformGTK.cmake: Move some files to WebCore_SOURCES sinc ethey

don't use GTK+ anymore, and add new files to compilation.

  • platform/graphics/GLContext.cpp:

(WebCore::GLContext::cleanupActiveContextsAtExit): Remove the
custom X11 connection.
(WebCore::GLContext::createContextForWindow): Check if the shared
display is Wayland to create a EGL context in such case.

  • platform/graphics/PlatformDisplay.cpp: Added.

(WebCore::PlatformDisplay::createPlatformDisplay): Creates the
shared display, using the GTK+/ecore shared connection.
(WebCore::PlatformDisplay::sharedDisplay): Return the shared display.

  • platform/graphics/PlatformDisplay.h: Added.
  • platform/graphics/egl/GLContextEGL.cpp:

(WebCore::sharedEGLDisplay): Use PlatformDisplay::sharedDisplay()
to get the native display.
(WebCore::GLContextEGL::createPixmapContext): Ditto.

  • platform/graphics/glx/GLContextGLX.cpp:

(WebCore::GLContextGLX::createWindowContext): Ditto.
(WebCore::GLContextGLX::createPbufferContext): Ditto.
(WebCore::GLContextGLX::createPixmapContext): Ditto.
(WebCore::GLContextGLX::createContext): Ditto.
(WebCore::GLContextGLX::~GLContextGLX): Ditto.
(WebCore::GLContextGLX::defaultFrameBufferSize): Ditto.
(WebCore::GLContextGLX::makeContextCurrent): Ditto.
(WebCore::GLContextGLX::swapBuffers): Ditto.
(WebCore::GLContextGLX::cairoDevice): Ditto.

  • platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:

(WebCore::MediaPlayerPrivateGStreamerBase::ensureGstGLContext): Ditto.

  • platform/graphics/surfaces/glx/X11Helper.cpp:

(WebCore::X11Helper::nativeDisplay): Ditto.

  • platform/graphics/wayland/PlatformDisplayWayland.cpp: Renamed from Source/WebCore/platform/graphics/wayland/WaylandDisplay.cpp.

(WebCore::PlatformDisplayWayland::globalCallback):
(WebCore::PlatformDisplayWayland::globalRemoveCallback):
(WebCore::PlatformDisplayWayland::create): Renamed instance() as
create() since the single instance is now handled by PlatformDisplay.
(WebCore::PlatformDisplayWayland::PlatformDisplayWayland):
(WebCore::PlatformDisplayWayland::createSurface):
(WebCore::PlatformDisplayWayland::createSharingGLContext):

  • platform/graphics/wayland/PlatformDisplayWayland.h: Renamed from Source/WebCore/platform/graphics/wayland/WaylandDisplay.h.
  • platform/graphics/x11/PlatformDisplayX11.cpp: Added.

(WebCore::PlatformDisplayX11::PlatformDisplayX11):
(WebCore::PlatformDisplayX11::~PlatformDisplayX11):

  • platform/graphics/x11/PlatformDisplayX11.h: Added.
  • platform/gtk/GtkUtilities.cpp:

(WebCore::getDisplaySystemType): Deleted.

  • platform/gtk/GtkUtilities.h:

Source/WebKit2:

  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseRealize): Use PlatformDisplay::sharedDisplay()
to checkt the display type.
(webkitWebViewBaseCreateWebPage): Ditto.

  • UIProcess/cairo/BackingStoreCairo.cpp:

(WebKit::BackingStore::createBackend): Pass the native X11 shared
display to BackingStoreBackendCairoX11.

  • WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp:

(WebKit::NetscapePlugin::x11HostDisplay): Return the native X11
shared display.

Location:
trunk/Source
Files:
5 added
14 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r183729 r183731  
     12015-05-03  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][EFL] Unify platform display handling
     4        https://bugs.webkit.org/show_bug.cgi?id=144517
     5
     6        Reviewed by Martin Robinson.
     7
     8        There are several places were we are handling the X display
     9        connection:
     10
     11        - GLContext::sharedX11Display() creates a new connection.
     12        - X11Helper::nativeDisplay() creates a new connection.
     13        - BackingStoreBackendCairoX11 uses the GTK+ shared connection.
     14        - NetscapePlugin::x11HostDisplay() uses the GTK+/ecore shared connection
     15        - The rest of the GTK+ code uses the shared GTK+ connection
     16
     17        And then we also have WaylandDisplay and the code to check if the
     18        current display is wayland or X11.
     19        We could unify all these to share the same connection to reduce
     20        the amount of ifdefs and ensure a single connection. That will
     21        also allow us to use "smart pointers" for the X resources that
     22        need a Display* to be freed.
     23
     24        * PlatformEfl.cmake: Add new files to compilation.
     25        * PlatformGTK.cmake: Move some files to WebCore_SOURCES sinc ethey
     26        don't use GTK+ anymore, and add new files to compilation.
     27        * platform/graphics/GLContext.cpp:
     28        (WebCore::GLContext::cleanupActiveContextsAtExit): Remove the
     29        custom X11 connection.
     30        (WebCore::GLContext::createContextForWindow): Check if the shared
     31        display is Wayland to create a EGL context in such case.
     32        * platform/graphics/PlatformDisplay.cpp: Added.
     33        (WebCore::PlatformDisplay::createPlatformDisplay): Creates the
     34        shared display, using the GTK+/ecore shared connection.
     35        (WebCore::PlatformDisplay::sharedDisplay): Return the shared display.
     36        * platform/graphics/PlatformDisplay.h: Added.
     37        * platform/graphics/egl/GLContextEGL.cpp:
     38        (WebCore::sharedEGLDisplay): Use PlatformDisplay::sharedDisplay()
     39        to get the native display.
     40        (WebCore::GLContextEGL::createPixmapContext): Ditto.
     41        * platform/graphics/glx/GLContextGLX.cpp:
     42        (WebCore::GLContextGLX::createWindowContext): Ditto.
     43        (WebCore::GLContextGLX::createPbufferContext): Ditto.
     44        (WebCore::GLContextGLX::createPixmapContext): Ditto.
     45        (WebCore::GLContextGLX::createContext): Ditto.
     46        (WebCore::GLContextGLX::~GLContextGLX): Ditto.
     47        (WebCore::GLContextGLX::defaultFrameBufferSize): Ditto.
     48        (WebCore::GLContextGLX::makeContextCurrent): Ditto.
     49        (WebCore::GLContextGLX::swapBuffers): Ditto.
     50        (WebCore::GLContextGLX::cairoDevice): Ditto.
     51        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
     52        (WebCore::MediaPlayerPrivateGStreamerBase::ensureGstGLContext): Ditto.
     53        * platform/graphics/surfaces/glx/X11Helper.cpp:
     54        (WebCore::X11Helper::nativeDisplay): Ditto.
     55        * platform/graphics/wayland/PlatformDisplayWayland.cpp: Renamed from Source/WebCore/platform/graphics/wayland/WaylandDisplay.cpp.
     56        (WebCore::PlatformDisplayWayland::globalCallback):
     57        (WebCore::PlatformDisplayWayland::globalRemoveCallback):
     58        (WebCore::PlatformDisplayWayland::create): Renamed instance() as
     59        create() since the single instance is now handled by PlatformDisplay.
     60        (WebCore::PlatformDisplayWayland::PlatformDisplayWayland):
     61        (WebCore::PlatformDisplayWayland::createSurface):
     62        (WebCore::PlatformDisplayWayland::createSharingGLContext):
     63        * platform/graphics/wayland/PlatformDisplayWayland.h: Renamed from Source/WebCore/platform/graphics/wayland/WaylandDisplay.h.
     64        * platform/graphics/x11/PlatformDisplayX11.cpp: Added.
     65        (WebCore::PlatformDisplayX11::PlatformDisplayX11):
     66        (WebCore::PlatformDisplayX11::~PlatformDisplayX11):
     67        * platform/graphics/x11/PlatformDisplayX11.h: Added.
     68        * platform/gtk/GtkUtilities.cpp:
     69        (WebCore::getDisplaySystemType): Deleted.
     70        * platform/gtk/GtkUtilities.h:
     71
    1722015-05-03  Carlos Garcia Campos  <cgarcia@igalia.com>
    273
  • trunk/Source/WebCore/PlatformEfl.cmake

    r183697 r183731  
    1818    "${WEBCORE_DIR}/platform/graphics/texmap"
    1919    "${WEBCORE_DIR}/platform/graphics/texmap/coordinated"
     20    "${WEBCORE_DIR}/platform/graphics/x11"
    2021    "${WEBCORE_DIR}/platform/linux"
    2122    "${WEBCORE_DIR}/platform/mediastream/openwebrtc"
     
    108109
    109110    platform/graphics/ImageSource.cpp
     111    platform/graphics/PlatformDisplay.cpp
    110112    platform/graphics/WOFFFileFormat.cpp
    111113
     
    195197    platform/graphics/texmap/coordinated/TiledBackingStore.cpp
    196198    platform/graphics/texmap/coordinated/UpdateAtlas.cpp
     199
     200    platform/graphics/x11/PlatformDisplayX11.cpp
    197201
    198202    platform/image-decoders/ImageDecoder.cpp
  • trunk/Source/WebCore/PlatformGTK.cmake

    r183697 r183731  
    1818    "${WEBCORE_DIR}/platform/graphics/opentype"
    1919    "${WEBCORE_DIR}/platform/graphics/wayland"
     20    "${WEBCORE_DIR}/platform/graphics/x11"
    2021    "${WEBCORE_DIR}/platform/linux"
    2122    "${WEBCORE_DIR}/platform/mediastream/openwebrtc"
     
    6465    platform/geoclue/GeolocationProviderGeoclue2.cpp
    6566
     67    platform/graphics/GLContext.cpp
    6668    platform/graphics/GraphicsContext3DPrivate.cpp
    6769    platform/graphics/ImageSource.cpp
     
    8890    platform/graphics/cairo/TransformationMatrixCairo.cpp
    8991
     92    platform/graphics/egl/GLContextEGL.cpp
     93
    9094    platform/graphics/freetype/FontCacheFreeType.cpp
    9195    platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp
    9296    platform/graphics/freetype/GlyphPageTreeNodeFreeType.cpp
    9397    platform/graphics/freetype/SimpleFontDataFreeType.cpp
     98
     99    platform/graphics/glx/GLContextGLX.cpp
    94100
    95101    platform/graphics/gstreamer/AudioTrackPrivateGStreamer.cpp
     
    120126    platform/graphics/opentype/OpenTypeVerticalData.cpp
    121127
     128    platform/graphics/x11/PlatformDisplayX11.cpp
     129
    122130    platform/gtk/ErrorsGtk.cpp
    123131    platform/gtk/EventLoopGtk.cpp
     
    192200    page/gtk/EventHandlerGtk.cpp
    193201
    194     platform/graphics/GLContext.cpp
    195 
    196     platform/graphics/egl/GLContextEGL.cpp
     202    platform/graphics/PlatformDisplay.cpp
    197203
    198204    platform/graphics/freetype/FontPlatformDataFreeType.cpp
    199 
    200     platform/graphics/glx/GLContextGLX.cpp
    201205
    202206    platform/graphics/gtk/ColorGtk.cpp
     
    473477if (ENABLE_WAYLAND_TARGET)
    474478    list(APPEND WebCorePlatformGTK_SOURCES
    475         platform/graphics/wayland/WaylandDisplay.cpp
     479        platform/graphics/wayland/PlatformDisplayWayland.cpp
    476480        platform/graphics/wayland/WaylandEventSource.cpp
    477481        platform/graphics/wayland/WaylandSurface.cpp
  • trunk/Source/WebCore/platform/graphics/GLContext.cpp

    r183639 r183731  
    2323#include "GLContext.h"
    2424
     25#include "PlatformDisplay.h"
     26#include <wtf/ThreadSpecific.h>
     27
    2528#if USE(EGL)
    2629#include "GLContextEGL.h"
     
    2932#if USE(GLX)
    3033#include "GLContextGLX.h"
    31 #endif
    32 
    33 #include <wtf/ThreadSpecific.h>
    34 
    35 #if PLATFORM(X11)
    36 #include <X11/Xlib.h>
    37 #endif
    38 
    39 #if PLATFORM(GTK)
    40 #include <gdk/gdk.h>
    41 #if PLATFORM(WAYLAND) && !defined(GTK_API_VERSION_2) && defined(GDK_WINDOWING_WAYLAND)
    42 #include <gdk/gdkwayland.h>
    43 #endif
    4434#endif
    4535
     
    7565
    7666#if PLATFORM(X11)
    77 // We do not want to call glXMakeContextCurrent using different Display pointers,
    78 // because it might lead to crashes in some drivers (fglrx). We use a shared display
    79 // pointer here.
    80 static Display* gSharedX11Display = 0;
    81 Display* GLContext::sharedX11Display()
    82 {
    83     if (!gSharedX11Display)
    84         gSharedX11Display = XOpenDisplay(0);
    85     return gSharedX11Display;
    86 }
    87 
    88 void GLContext::cleanupSharedX11Display()
    89 {
    90     if (!gSharedX11Display)
    91         return;
    92     XCloseDisplay(gSharedX11Display);
    93     gSharedX11Display = 0;
    94 }
    95 
    9667// Because of driver bugs, exiting the program when there are active pbuffers
    9768// can crash the X server (this has been observed with the official Nvidia drivers).
     
    138109    for (size_t i = 0; i < contextList.size(); ++i)
    139110        delete contextList[i];
    140 
    141     cleanupSharedX11Display();
    142111}
    143112#endif // PLATFORM(X11)
     
    146115std::unique_ptr<GLContext> GLContext::createContextForWindow(GLNativeWindowType windowHandle, GLContext* sharingContext)
    147116{
    148 #if PLATFORM(GTK) && PLATFORM(WAYLAND) && !defined(GTK_API_VERSION_2) && defined(GDK_WINDOWING_WAYLAND) && USE(EGL)
    149     GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get());
    150 
    151     if (GDK_IS_WAYLAND_DISPLAY(display)) {
     117#if PLATFORM(WAYLAND) && USE(EGL)
     118    if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland) {
    152119        if (auto eglContext = GLContextEGL::createContext(windowHandle, sharingContext))
    153120            return WTF::move(eglContext);
  • trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp

    r183432 r183731  
    3535#endif
    3636
    37 #if PLATFORM(GTK)
    38 #include "GtkUtilities.h"
    39 #if PLATFORM(WAYLAND) && !defined(GTK_API_VERSION_2)
    40 #include "WaylandDisplay.h"
    41 #endif
     37#if PLATFORM(X11)
     38#include "PlatformDisplayX11.h"
     39#endif
     40
     41#if PLATFORM(WAYLAND)
     42#include "PlatformDisplayWayland.h"
    4243#endif
    4344
     
    6566    if (!initialized) {
    6667        initialized = true;
    67 #if PLATFORM(GTK) && PLATFORM(WAYLAND) && !defined(GTK_API_VERSION_2)
    68         if (getDisplaySystemType() == DisplaySystemType::Wayland && WaylandDisplay::instance())
    69             gSharedEGLDisplay = eglGetDisplay(WaylandDisplay::instance()->nativeDisplay());
     68
     69        const auto& sharedDisplay = PlatformDisplay::sharedDisplay();
     70#if PLATFORM(WAYLAND)
     71        if (is<PlatformDisplayWayland>(sharedDisplay))
     72            gSharedEGLDisplay = eglGetDisplay(downcast<PlatformDisplayWayland>(sharedDisplay).native());
    7073        else // Note that this branch continutes outside this #if-guarded segment.
    7174#endif
    7275#if PLATFORM(X11)
    73             gSharedEGLDisplay = eglGetDisplay(GLContext::sharedX11Display());
     76            gSharedEGLDisplay = eglGetDisplay(downcast<PlatformDisplayX11>(sharedDisplay).native());
    7477#else
    7578            gSharedEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     
    187190        return nullptr;
    188191
    189     Pixmap pixmap = XCreatePixmap(sharedX11Display(), DefaultRootWindow(sharedX11Display()), 1, 1, depth);
     192    Display* x11Display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
     193    Pixmap pixmap = XCreatePixmap(x11Display, DefaultRootWindow(x11Display), 1, 1, depth);
    190194    if (!pixmap)
    191195        return nullptr;
  • trunk/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp

    r183432 r183731  
    2323#include "GraphicsContext3D.h"
    2424#include "OpenGLShims.h"
     25#include "PlatformDisplayX11.h"
    2526#include <GL/glx.h>
    2627#include <cairo.h>
     
    3435std::unique_ptr<GLContextGLX> GLContextGLX::createWindowContext(XID window, GLContext* sharingContext)
    3536{
    36     Display* display = sharedX11Display();
     37    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    3738    XWindowAttributes attributes;
    3839    if (!XGetWindowAttributes(display, window, &attributes))
     
    7374
    7475    int returnedElements;
    75     Display* display = sharedX11Display();
     76    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    7677    GLXFBConfig* configs = glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements);
    7778    if (!returnedElements) {
     
    113114    };
    114115
    115     Display* display = sharedX11Display();
     116    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    116117    XVisualInfo* visualInfo = glXChooseVisual(display, DefaultScreen(display), visualAttributes);
    117118    if (!visualInfo)
     
    143144std::unique_ptr<GLContextGLX> GLContextGLX::createContext(XID window, GLContext* sharingContext)
    144145{
    145     if (!sharedX11Display())
    146         return nullptr;
    147 
    148146    static bool initialized = false;
    149147    static bool success = true;
     
    192190        cairo_device_destroy(m_cairoDevice);
    193191
     192    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    194193    if (m_context) {
    195194        // This may be necessary to prevent crashes with NVidia's closed source drivers. Originally
    196195        // from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/
    197196        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    198         glXMakeCurrent(sharedX11Display(), None, None);
    199         glXDestroyContext(sharedX11Display(), m_context);
     197        glXMakeCurrent(display, None, None);
     198        glXDestroyContext(display, m_context);
    200199    }
    201200
    202201    if (m_pbuffer) {
    203         glXDestroyPbuffer(sharedX11Display(), m_pbuffer);
     202        glXDestroyPbuffer(display, m_pbuffer);
    204203        m_pbuffer = 0;
    205204    }
    206205    if (m_glxPixmap) {
    207         glXDestroyGLXPixmap(sharedX11Display(), m_glxPixmap);
     206        glXDestroyGLXPixmap(display, m_glxPixmap);
    208207        m_glxPixmap = 0;
    209208    }
    210209    if (m_pixmap) {
    211         XFreePixmap(sharedX11Display(), m_pixmap);
     210        XFreePixmap(display, m_pixmap);
    212211        m_pixmap = 0;
    213212    }
     
    227226    Window rootWindow;
    228227    unsigned int width, height, borderWidth, depth;
    229     if (!XGetGeometry(sharedX11Display(), m_window, &rootWindow, &x, &y, &width, &height, &borderWidth, &depth))
     228    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
     229    if (!XGetGeometry(display, m_window, &rootWindow, &x, &y, &width, &height, &borderWidth, &depth))
    230230        return IntSize();
    231231
     
    241241        return true;
    242242
     243    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    243244    if (m_window)
    244         return glXMakeCurrent(sharedX11Display(), m_window, m_context);
     245        return glXMakeCurrent(display, m_window, m_context);
    245246
    246247    if (m_pbuffer)
    247         return glXMakeCurrent(sharedX11Display(), m_pbuffer, m_context);
    248 
    249     return ::glXMakeCurrent(sharedX11Display(), m_glxPixmap, m_context);
     248        return glXMakeCurrent(display, m_pbuffer, m_context);
     249
     250    return ::glXMakeCurrent(display, m_glxPixmap, m_context);
    250251}
    251252
     
    253254{
    254255    if (m_window)
    255         glXSwapBuffers(sharedX11Display(), m_window);
     256        glXSwapBuffers(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_window);
    256257}
    257258
     
    267268
    268269#if ENABLE(ACCELERATED_2D_CANVAS)
    269     m_cairoDevice = cairo_glx_device_create(sharedX11Display(), m_context);
     270    m_cairoDevice = cairo_glx_device_create(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_context);
    270271#endif
    271272
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp

    r182229 r183731  
    7272#endif
    7373
     74#if PLATFORM(X11)
     75#include "PlatformDisplayX11.h"
     76#elif PLATFORM(WAYLAND)
     77#include "PlatformDisplayWayland.h"
     78#endif
     79
    7480// gstglapi.h may include eglplatform.h and it includes X.h, which
    7581// defines None, breaking MediaPlayer::None enum
     
    229235
    230236    if (!m_glDisplay) {
     237        const auto& sharedDisplay = PlatformDisplay::sharedDisplay();
    231238#if PLATFORM(X11)
    232         Display* display = GLContext::sharedX11Display();
    233         m_glDisplay = GST_GL_DISPLAY(gst_gl_display_x11_new_with_display(display));
     239        m_glDisplay = GST_GL_DISPLAY(gst_gl_display_x11_new_with_display(downcast<PlatformDisplayX11>(sharedDisplay).native()));
    234240#elif PLATFORM(WAYLAND)
    235         EGLDisplay display = WaylandDisplay::instance()->eglDisplay();
    236         m_glDisplay = GST_GL_DISPLAY(gst_gl_display_egl_new_with_egl_display(display));
     241        m_glDisplay = GST_GL_DISPLAY(gst_gl_display_egl_new_with_egl_display(downcast<PlatformDisplayWayland>(sharedDisplay).native()));
    237242#endif
    238243    }
  • trunk/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.cpp

    r183265 r183731  
    2727#include "X11Helper.h"
    2828
     29#include "PlatformDisplayX11.h"
     30
    2931namespace WebCore {
    3032
     
    5456}
    5557
    56 struct DisplayConnection {
    57     DisplayConnection()
    58     {
    59         m_display = XOpenDisplay(0);
    60 
    61         if (!m_display)
    62             LOG_ERROR("Failed to make connection with X");
    63     }
    64 
    65     ~DisplayConnection()
    66     {
    67         XCloseDisplay(m_display);
    68     }
    69 
    70     Display* display() { return m_display; }
    71 private:
    72     Display* m_display;
    73 };
    74 
    7558struct OffScreenRootWindow {
    7659
     
    332315Display* X11Helper::nativeDisplay()
    333316{
    334     // Display connection will only be broken at program shutdown.
    335     static DisplayConnection displayConnection;
    336     return displayConnection.display();
     317    return downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    337318}
    338319
  • trunk/Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.cpp

    r183730 r183731  
    2525
    2626#include "config.h"
    27 #include "WaylandDisplay.h"
     27#include "PlatformDisplayWayland.h"
    2828
    2929#if PLATFORM(WAYLAND)
     
    3636namespace WebCore {
    3737
    38 const struct wl_registry_listener WaylandDisplay::m_registryListener = {
    39     WaylandDisplay::globalCallback,
    40     WaylandDisplay::globalRemoveCallback
     38const struct wl_registry_listener PlatformDisplayWayland::m_registryListener = {
     39    PlatformDisplayWayland::globalCallback,
     40    PlatformDisplayWayland::globalRemoveCallback
    4141};
    4242
    43 void WaylandDisplay::globalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t)
     43void PlatformDisplayWayland::globalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t)
    4444{
    45     auto display = static_cast<WaylandDisplay*>(data);
     45    auto display = static_cast<PlatformDisplayWayland*>(data);
    4646    if (!std::strcmp(interface, "wl_compositor"))
    4747        display->m_compositor = static_cast<struct wl_compositor*>(wl_registry_bind(registry, name, &wl_compositor_interface, 1));
     
    5050}
    5151
    52 void WaylandDisplay::globalRemoveCallback(void*, struct wl_registry*, uint32_t)
     52void PlatformDisplayWayland::globalRemoveCallback(void*, struct wl_registry*, uint32_t)
    5353{
    5454    // FIXME: if this can happen without the UI Process getting shut down
     
    5656}
    5757
    58 WaylandDisplay* WaylandDisplay::instance()
     58std::unique_ptr<PlatformDisplayWayland> PlatformDisplayWayland::create()
    5959{
    60     static WaylandDisplay* display = nullptr;
    61     static bool initialized = false;
    62     if (initialized)
    63         return display;
    64 
    65     initialized = true;
    6660    struct wl_display* wlDisplay = wl_display_connect("webkitgtk-wayland-compositor-socket");
    6761    if (!wlDisplay)
    6862        return nullptr;
    6963
    70     display = new WaylandDisplay(wlDisplay);
    71     if (!display->isInitialized()) {
    72         delete display;
     64    auto display = std::make_unique<PlatformDisplayWayland>(wlDisplay);
     65    if (!display->isInitialized())
    7366        return nullptr;
    74     }
    7567
    76     return display;
     68    return WTF::move(display);
    7769}
    7870
    79 WaylandDisplay::WaylandDisplay(struct wl_display* wlDisplay)
     71PlatformDisplayWayland::PlatformDisplayWayland(struct wl_display* wlDisplay)
    8072    : m_display(wlDisplay)
    8173    , m_registry(wl_display_get_registry(m_display))
     
    9789    m_eglDisplay = eglGetDisplay(m_display);
    9890    if (m_eglDisplay == EGL_NO_DISPLAY) {
    99         g_warning("WaylandDisplay initialization: failed to acquire EGL display.");
     91        g_warning("PlatformDisplayWayland initialization: failed to acquire EGL display.");
    10092        return;
    10193    }
    10294
    10395    if (eglInitialize(m_eglDisplay, 0, 0) == EGL_FALSE) {
    104         g_warning("WaylandDisplay initialization: failed to initialize the EGL display.");
     96        g_warning("PlatformDisplayWayland initialization: failed to initialize the EGL display.");
    10597        return;
    10698    }
    10799
    108100    if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
    109         g_warning("WaylandDisplay initialization: failed to set EGL_OPENGL_ES_API as the rendering API.");
     101        g_warning("PlatformDisplayWayland initialization: failed to set EGL_OPENGL_ES_API as the rendering API.");
    110102        return;
    111103    }
     
    113105    EGLint numberOfConfigs;
    114106    if (!eglChooseConfig(m_eglDisplay, configAttributes, &m_eglConfig, 1, &numberOfConfigs) || numberOfConfigs != 1) {
    115         g_warning("WaylandDisplay initialization: failed to find the desired EGL configuration.");
     107        g_warning("PlatformDisplayWayland initialization: failed to find the desired EGL configuration.");
    116108        return;
    117109    }
     
    120112}
    121113
    122 std::unique_ptr<WaylandSurface> WaylandDisplay::createSurface(const IntSize& size, int widgetId)
     114std::unique_ptr<WaylandSurface> PlatformDisplayWayland::createSurface(const IntSize& size, int widgetId)
    123115{
    124116    struct wl_surface* wlSurface = wl_compositor_create_surface(m_compositor);
     
    132124}
    133125
    134 std::unique_ptr<GLContextEGL> WaylandDisplay::createSharingGLContext()
     126std::unique_ptr<GLContextEGL> PlatformDisplayWayland::createSharingGLContext()
    135127{
    136128    struct wl_surface* wlSurface = wl_compositor_create_surface(m_compositor);
  • trunk/Source/WebCore/platform/graphics/wayland/PlatformDisplayWayland.h

    r183730 r183731  
    2424 */
    2525
    26 #ifndef  WaylandDisplay_h
    27 #define  WaylandDisplay_h
     26#ifndef  PlatformDisplayWayland_h
     27#define  PlatformDisplayWayland_h
    2828
    2929#if PLATFORM(WAYLAND)
    3030
     31#include "PlatformDisplay.h"
    3132#include "WebKitGtkWaylandClientProtocol.h"
    3233#include <memory>
    3334#include <wayland-client.h>
    34 
    3535#include <wayland-egl.h>
    3636#include <EGL/egl.h>
     
    4242class WaylandSurface;
    4343
    44 class WaylandDisplay {
     44class PlatformDisplayWayland final: public PlatformDisplay {
    4545public:
    46     static WaylandDisplay* instance();
     46    static std::unique_ptr<PlatformDisplayWayland> create();
     47    virtual ~PlatformDisplayWayland();
    4748
    48     struct wl_display* nativeDisplay() const { return m_display; }
     49    struct wl_display* native() const { return m_display; }
    4950    EGLDisplay eglDisplay() const { return m_eglDisplay; }
    5051
     
    5859    static void globalRemoveCallback(void* data, struct wl_registry*, uint32_t name);
    5960
    60     WaylandDisplay(struct wl_display*);
     61    PlatformDisplayWayland(struct wl_display*);
    6162    bool isInitialized() { return m_compositor && m_webkitgtk && m_eglDisplay != EGL_NO_DISPLAY && m_eglConfigChosen; }
     63
     64    Type type() const override { return PlatformDisplay::Type::Wayland; }
    6265
    6366    struct wl_display* m_display;
     
    7578#endif // PLATFORM(WAYLAND)
    7679
    77 #endif // WaylandDisplay_h
     80#endif // PlatformDisplayWayland_h
  • trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp

    r183584 r183731  
    2424#include <wtf/gobject/GUniquePtr.h>
    2525#include <wtf/gobject/GlibUtilities.h>
    26 
    27 #if PLATFORM(X11)
    28 #include <gdk/gdkx.h>
    29 #endif
    30 #if PLATFORM(WAYLAND) && !defined(GTK_API_VERSION_2)
    31 #include <gdk/gdkwayland.h>
    32 #endif
    3326
    3427namespace WebCore {
     
    6255}
    6356
    64 DisplaySystemType getDisplaySystemType()
    65 {
    66 #if defined(GTK_API_VERSION_2)
    67     return DisplaySystemType::X11;
    68 #else
    69     static DisplaySystemType type = [] {
    70         GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get());
    71 #if PLATFORM(X11)
    72         if (GDK_IS_X11_DISPLAY(display))
    73             return DisplaySystemType::X11;
    74 #endif
    75 #if PLATFORM(WAYLAND)
    76         if (GDK_IS_WAYLAND_DISPLAY(display))
    77             return DisplaySystemType::Wayland;
    78 #endif
    79         ASSERT_NOT_REACHED();
    80         return DisplaySystemType::X11;
    81     }();
    82     return type;
    83 #endif
    84 }
    85 
    8657#if defined(DEVELOPMENT_BUILD)
    8758static CString topLevelPath()
  • trunk/Source/WebCore/platform/gtk/GtkUtilities.h

    r183584 r183731  
    2929bool widgetIsOnscreenToplevelWindow(GtkWidget*);
    3030
    31 enum class DisplaySystemType {
    32     X11,
    33     Wayland
    34 };
    35 
    36 DisplaySystemType getDisplaySystemType();
    37 
    3831#if defined(DEVELOPMENT_BUILD)
    3932CString webkitBuildDirectory();
  • trunk/Source/WebKit2/ChangeLog

    r183730 r183731  
     12015-05-03  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][EFL] Unify platform display handling
     4        https://bugs.webkit.org/show_bug.cgi?id=144517
     5
     6        Reviewed by Martin Robinson.
     7
     8        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     9        (webkitWebViewBaseRealize): Use PlatformDisplay::sharedDisplay()
     10        to checkt the display type.
     11        (webkitWebViewBaseCreateWebPage): Ditto.
     12        * UIProcess/cairo/BackingStoreCairo.cpp:
     13        (WebKit::BackingStore::createBackend): Pass the native X11 shared
     14        display to BackingStoreBackendCairoX11.
     15        * WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp:
     16        (WebKit::NetscapePlugin::x11HostDisplay): Return the native X11
     17        shared display.
     18
    1192015-05-03  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r182176 r183731  
    5555#include <WebCore/NotImplemented.h>
    5656#include <WebCore/PasteboardHelper.h>
     57#include <WebCore/PlatformDisplay.h>
    5758#include <WebCore/RefPtrCairo.h>
    5859#include <WebCore/Region.h>
     
    321322
    322323#if USE(REDIRECTED_XCOMPOSITE_WINDOW)
    323     GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get());
    324     if (GDK_IS_X11_DISPLAY(display)) {
     324    if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11) {
    325325        priv->redirectedWindow = RedirectedXCompositeWindow::create(
    326326            gtk_widget_get_parent_window(widget),
     
    11341134    // FIXME: Accelerated compositing under Wayland is not yet supported.
    11351135    // https://bugs.webkit.org/show_bug.cgi?id=115803
    1136     GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get());
    1137     if (GDK_IS_WAYLAND_DISPLAY(display))
     1136    if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland)
    11381137        preferences->setAcceleratedCompositingEnabled(false);
    11391138#endif
  • trunk/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp

    r181789 r183731  
    3939#if PLATFORM(GTK) && PLATFORM(X11) && defined(GDK_WINDOWING_X11)
    4040#include <WebCore/BackingStoreBackendCairoX11.h>
     41#include <WebCore/PlatformDisplayX11.h>
    4142#include <gdk/gdkx.h>
    4243#endif
     
    4950{
    5051#if PLATFORM(GTK) && PLATFORM(X11)
    51     GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get());
    52     if (GDK_IS_X11_DISPLAY(display)) {
     52    const auto& sharedDisplay = PlatformDisplay::sharedDisplay();
     53    if (is<PlatformDisplayX11>(sharedDisplay)) {
    5354        GdkVisual* visual = gtk_widget_get_visual(m_webPageProxy.viewWidget());
    5455        GdkScreen* screen = gdk_visual_get_screen(visual);
    55         return std::make_unique<BackingStoreBackendCairoX11>(GDK_SCREEN_XDISPLAY(screen), GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
     56        ASSERT(downcast<PlatformDisplayX11>(sharedDisplay).native() == GDK_SCREEN_XDISPLAY(screen));
     57        return std::make_unique<BackingStoreBackendCairoX11>(downcast<PlatformDisplayX11>(sharedDisplay).native(), GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
    5658            GDK_VISUAL_XVISUAL(visual), gdk_visual_get_depth(visual), m_size, m_deviceScaleFactor);
    5759    }
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp

    r182963 r183731  
    3434#include <WebCore/GraphicsContext.h>
    3535#include <WebCore/NotImplemented.h>
     36#include <WebCore/PlatformDisplayX11.h>
    3637
    3738#if PLATFORM(GTK)
     
    104105Display* NetscapePlugin::x11HostDisplay()
    105106{
    106 #if PLATFORM(GTK)
    107     return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
    108 #elif PLATFORM(EFL) && defined(HAVE_ECORE_X)
    109     return static_cast<Display*>(ecore_x_display_get());
    110 #else
    111     return 0;
    112 #endif
     107    return downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    113108}
    114109
Note: See TracChangeset for help on using the changeset viewer.