Initial Wayland support. 95/3995/1
authorKondapally Kalyan <kalyan.kondapally@intel.com>
Thu, 13 Jun 2013 22:55:19 +0000 (01:55 +0300)
committerKondapally Kalyan <kalyan.kondapally@intel.com>
Thu, 13 Jun 2013 22:55:19 +0000 (01:55 +0300)
The patch adds support to open a wayland display connection
and initialize EGL.

Source/WebCore/PlatformTizen.cmake
Source/WebCore/platform/graphics/efl/tizen/SharedPlatformSurfaceTizen.cpp
Source/WebCore/platform/graphics/surfaces/egl/EGLHelper.cpp
Source/WebCore/platform/graphics/surfaces/egl/EGLSurface.h
Source/WebCore/platform/graphics/surfaces/wayland/WaylandHelper.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/wayland/WaylandHelper.h [new file with mode: 0644]
Source/cmake/OptionsTizen.cmake

index c8bb2f2..9863fd4 100755 (executable)
@@ -35,6 +35,10 @@ IF (WTF_PLATFORM_X11)
     LIST(APPEND WebCore_INCLUDE_DIRECTORIES
         "${WEBCORE_DIR}/platform/graphics/surfaces/x"
     )
+ELSEIF (WTF_PLATFORM_WAYLAND)
+    LIST(APPEND WebCore_INCLUDE_DIRECTORIES
+        "${WEBCORE_DIR}/platform/graphics/surfaces/wayland"
+    )
 ENDIF ()
 
 LIST(APPEND WebCore_LIBRARIES
@@ -208,6 +212,10 @@ IF (WTF_USE_ACCELERATED_COMPOSITING AND ENABLE_WEBKIT2)
             platform/graphics/surfaces/egl/EGLXSurface.cpp
             platform/graphics/surfaces/tizen/SharedVideoPlatformSurfaceTizenX.cpp
         )
+    ELSEIF (WTF_PLATFORM_WAYLAND)
+        LIST(APPEND WebCore_SOURCES
+            platform/graphics/surfaces/wayland/WaylandHelper.cpp
+        )
     ENDIF()
 ENDIF()
 
index 7b3d15e..a9f6f05 100755 (executable)
@@ -117,7 +117,6 @@ PassOwnPtr<SharedPlatformSurfaceTizen> SharedPlatformSurfaceTizen::create(const
 
 bool SharedPlatformSurfaceTizen::supportsLockSurfaceExtension()
 {
-#if PLATFORM(X11)
     static bool extSupportQueried = false;
     static bool supportLockSurfaceExt = false;
 
@@ -132,9 +131,6 @@ bool SharedPlatformSurfaceTizen::supportsLockSurfaceExtension()
 
     supportLockSurfaceExt = GLPlatformContext::supportsEGLExtension(display, "EGL_KHR_lock_surface");
     return supportLockSurfaceExt;
-#else
-    return false;
-#endif
 }
 
 SharedPlatformSurfaceTizen::SharedPlatformSurfaceTizen(const IntSize& size, bool lockable, bool hasAlpha, bool hasDepth, bool hasStencil)
index 3df7ed6..d6c9eee 100644 (file)
@@ -32,6 +32,8 @@
 
 #if PLATFORM(X11)
 #include "X11Helper.h"
+#elif PLATFORM(WAYLAND)
+#include "WaylandHelper.h"
 #endif
 
 namespace WebCore {
@@ -39,8 +41,9 @@ namespace WebCore {
 #if PLATFORM(X11)
 typedef X11Helper NativeWrapper;
 typedef Display NativeSharedDisplay;
-#else
-typedef void NativeSharedDisplay;
+#elif PLATFORM(WAYLAND)
+typedef WaylandHelper NativeWrapper;
+typedef struct wl_display NativeSharedDisplay;
 #endif
 
 static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = 0;
@@ -64,7 +67,8 @@ struct EGLDisplayConnection {
         }
 
         EGLBoolean success;
-        success = eglInitialize(m_eglDisplay, 0, 0);
+        EGLint major, minor;
+        success = eglInitialize(m_eglDisplay, &major, &minor);
 
         if (success != EGL_TRUE) {
             LOG_ERROR("EGLInitialization failed.");
@@ -104,11 +108,7 @@ private:
 PlatformDisplay EGLHelper::eglDisplay()
 {
     // Display connection will only be broken at program shutdown.
-#if PLATFORM(X11)
     static EGLDisplayConnection displayConnection(NativeWrapper::nativeDisplay());
-#else
-    static EGLDisplayConnection displayConnection;
-#endif
     return displayConnection.display();
 }
 
index a2d2833..b54cbea 100644 (file)
 #include "GLPlatformSurface.h"
 #include <wtf/PassOwnPtr.h>
 
+#if PLATFORM(WAYLAND)
+#include <wayland-client.h>
+#include <wayland-egl.h>
+#endif
+
 #define EGL_EGLEXT_PROTOTYPES 1
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
diff --git a/Source/WebCore/platform/graphics/surfaces/wayland/WaylandHelper.cpp b/Source/WebCore/platform/graphics/surfaces/wayland/WaylandHelper.cpp
new file mode 100644 (file)
index 0000000..d5898f8
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WaylandHelper.h"
+
+#include <string.h>
+
+namespace WebCore {
+struct wl_compositor* WaylandHelper::m_compositor = 0;
+
+static const struct wl_registry_listener registrylistener = {
+    WaylandHelper::handleGlobal,
+    WaylandHelper::handleGlobalRemove
+};
+
+struct DisplayConnection {
+    DisplayConnection()
+        : m_display(0)
+        , m_registry(0)
+    {
+        m_display = wl_display_connect(0);
+        if (!m_display) {
+            LOG_ERROR("Failed to make connection with Wayland.");
+            return;
+        }
+
+        m_registry = wl_display_get_registry(m_display);
+        wl_registry_add_listener(m_registry, &registrylistener, 0);
+
+        if (wl_display_roundtrip(m_display) < 0) {
+            LOG_ERROR("Failed to process Wayland connection.");
+            close();
+        }
+    }
+
+    ~DisplayConnection()
+    {
+        close();
+    }
+
+    struct wl_display* display() const { return m_display; }
+
+private:
+    void close()
+    {
+        if (m_registry) {
+            wl_registry_destroy(m_registry);
+            m_registry = 0;
+        }
+
+        if (m_display) {
+            wl_display_flush(m_display);
+            wl_display_disconnect(m_display);
+            m_display = 0;
+        }
+    }
+
+    struct wl_display* m_display;
+    struct wl_registry* m_registry;
+};
+
+struct wl_display* WaylandHelper::nativeDisplay()
+{
+    // Display connection will only be broken at program shutdown.
+    static DisplayConnection displayConnection;
+    return displayConnection.display();
+}
+
+void WaylandHelper::handleGlobal(void*, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t)
+{
+    if (!strcmp(interface, "wl_compositor"))
+        m_compositor = static_cast<struct wl_compositor*>(wl_registry_bind(registry, name, &wl_compositor_interface, 1));
+}
+
+void WaylandHelper::handleGlobalRemove(void*, struct wl_registry*, uint32_t)
+{
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/surfaces/wayland/WaylandHelper.h b/Source/WebCore/platform/graphics/surfaces/wayland/WaylandHelper.h
new file mode 100644 (file)
index 0000000..4a920bf
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WaylandHelper_h
+#define WaylandHelper_h
+
+#include <wayland-client.h>
+#include <wayland-egl.h>
+
+namespace WebCore {
+
+class WaylandHelper {
+public:
+    static struct wl_display* nativeDisplay();
+    static struct wl_compositor* compositor() { return m_compositor; }
+
+    // Used for registration purpose only.
+    static void handleGlobal(void*, struct wl_registry*, uint32_t, const char*, uint32_t);
+    static void handleGlobalRemove(void*, struct wl_registry*, uint32_t);
+private:
+    static struct wl_compositor* m_compositor;
+};
+
+}
+#endif
index 7dc1a9b..d7d50cd 100644 (file)
@@ -378,6 +378,9 @@ IF (ENABLE_ECORE_X)
     ADD_DEFINITIONS(-DHAVE_ECORE_X)
     ADD_DEFINITIONS(-DWTF_PLATFORM_X11=1)
     SET(WTF_PLATFORM_X11 1)
+ELSE ()
+    ADD_DEFINITIONS(-DWTF_PLATFORM_WAYLAND=1)
+    SET(WTF_PLATFORM_WAYLAND 1)
 ENDIF ()
 
 FIND_PACKAGE(Eina 1.2 REQUIRED)