Add video support of wayland platform (x86/vaapi) 32/9032/1
authorZhao Halley <halley.zhao@intel.com>
Mon, 12 Aug 2013 00:34:33 +0000 (08:34 +0800)
committerZhao Halley <halley.zhao@intel.com>
Mon, 2 Sep 2013 02:38:38 +0000 (10:38 +0800)
- Add video platform: SharedVideoPlatformSurfaceTizenWayland
- disable WTF_USE_TIZEN_GSTREAMER_VIDEO_SET_SINK when vaapisink is possible (x86)
- deal with the difference of surface id (m_bufferHandle) and
  native surface (wl_surface) for wayland platform surface
- Accept 'frame-rendered' signal to update video layer
- only luma component is rendered

Change-Id: I1a1cc519c9778f9deaeb471fb50297abb88bfd50

Source/WebCore/PlatformTizen.cmake
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
Source/WebCore/platform/graphics/gstreamer/tizen/SharedVideoPlatformSurfaceTizen.cpp
Source/WebCore/platform/graphics/gstreamer/tizen/SharedVideoPlatformSurfaceTizen.h
Source/WebCore/platform/graphics/gstreamer/tizen/VideoLayerTizen.cpp
Source/WebCore/platform/graphics/surfaces/tizen/SharedVideoPlatformSurfaceTizenWayland.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/surfaces/tizen/SharedVideoPlatformSurfaceTizenWayland.h [new file with mode: 0644]
Source/cmake/OptionsTizen.cmake

index e2b10d2..cf4b9ca 100755 (executable)
@@ -236,6 +236,7 @@ IF (WTF_USE_ACCELERATED_COMPOSITING AND ENABLE_WEBKIT2)
             platform/graphics/surfaces/wayland/WaylandDisplay.cpp
             platform/graphics/surfaces/wayland/WaylandSurface.cpp
             platform/graphics/surfaces/wayland/GraphicsSurfaceWayland.cpp
+            platform/graphics/surfaces/tizen/SharedVideoPlatformSurfaceTizenWayland.cpp
         )
     ENDIF()
 ENDIF()
index f9a9d69..1530578 100755 (executable)
@@ -236,7 +236,7 @@ static GstBusSyncReply mediaPlayerPrivateSyncHandler(GstBus* bus, GstMessage* me
     if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_ELEMENT)
         return GST_BUS_PASS;
 #ifdef GST_API_VERSION_1
-    if (gst_is_video_overlay_prepare_window_handle_message(message))
+    if (!gst_is_video_overlay_prepare_window_handle_message(message))
 #else
     if (!gst_structure_has_name (message->structure, "prepare-xid"))
 #endif
@@ -1110,6 +1110,15 @@ gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
         LOG_MEDIA_MESSAGE("Duration changed");
         durationChanged();
         break;
+    case GST_MESSAGE_ELEMENT:
+#ifdef GST_API_VERSION_1
+        if (gst_structure_has_name (structure, "frame-rendered")) {
+#else
+        if (gst_structure_has_name (message->structure, "frame-rendered")) {
+#endif
+            m_videoLayer->notifySyncRequired();
+        }
+        break;
     default:
         LOG_MEDIA_MESSAGE("Unhandled GStreamer message type: %s",
                     GST_MESSAGE_TYPE_NAME(message));
@@ -2363,6 +2372,7 @@ IntSize MediaPlayerPrivateGStreamer::scaleHDVideoToDisplaySize(int videoWidth, i
 #endif
 void MediaPlayerPrivateGStreamer::xWindowIdPrepared(GstMessage* message)
 {
+#if !PLATFORM(WAYLAND)
 #if USE(ACCELERATED_VIDEO_VAAPI)
     int displayWidth, displayHeight;
 #endif
@@ -2391,6 +2401,9 @@ void MediaPlayerPrivateGStreamer::xWindowIdPrepared(GstMessage* message)
     m_videoSize = IntSize(videoWidth, videoHeight);
 #endif
     m_videoLayer->setOverlay(m_videoSize);
+#else
+    m_videoLayer->setOverlay(IntSize(1,1));
+#endif
 }
 
 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
index dad93d1..a6ce375 100644 (file)
@@ -36,6 +36,8 @@
 
 #if PLATFORM(X11)
 #include "SharedVideoPlatformSurfaceTizenX.h"
+#elif PLATFORM(WAYLAND)
+#include "SharedVideoPlatformSurfaceTizenWayland.h"
 #endif
 
 namespace WebCore {
@@ -44,6 +46,8 @@ PassOwnPtr<SharedVideoPlatformSurfaceTizen> SharedVideoPlatformSurfaceTizen::cre
 {
 #if PLATFORM(X11)
     return adoptPtr(new SharedVideoPlatformSurfaceTizenX(size));
+#elif PLATFORM(WAYLAND)
+    return adoptPtr(new SharedVideoPlatformSurfaceTizenWayland(size));
 #else
     return nullptr;
 #endif
index f828c26..9bd4469 100644 (file)
@@ -55,6 +55,7 @@ public:
     void copySurface(SharedVideoPlatformSurfaceTizen*, CopySurfaceType);
     void platformSurfaceUpdated();
     int graphicsSurfaceFlags() const;
+    virtual void *nativeVideoSurface() {return (void*)m_bufferHandle;};
 
 protected:
     SharedVideoPlatformSurfaceTizen(const IntSize&);
index d462bea..cff81fb 100644 (file)
 #endif
 #include <gst/video/gstvideosink.h>
 #include <gst/video/video.h>
+#if PLATFORM(X11)
+// no header file is required for X, becase media pipeline creates X connecttion of its own.
+#elif PLATFORM(WAYLAND)
+#include "WaylandDisplay.h"
+#endif
 #else
+#if PLATFORM(X11)
 #include <cairo-xlib.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#elif PLATFORM(WAYLAND)
+// note-1:
+// there is no implementation of wayland platform for !TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE,
+// because it is not possible to composite wl_surface by cairo.
+#endif
 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
 
 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) || USE(TIZEN_GSTREAMER_VIDEO_SET_SINK)
+#if PLATFORM(X11)
 static Display* g_nativeDisplay = 0;
+#elif PLATFORM(WAYLAND)
+// see above note-1
+#endif
 #endif
 
 namespace WebCore {
@@ -61,12 +76,17 @@ VideoLayerTizen::VideoLayerTizen(HTMLMediaElement* media)
 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && !USE(TIZEN_GSTREAMER_VIDEO_SET_SINK)
     : m_videoSink(0)
 #else
+#if PLATFORM(X11)
     : m_platformSurfaceID(0)
     , m_nativeWindow(0)
+#elif PLATFORM(WAYLAND)
+// see above note-1
+#endif
 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
     , m_media(media)
 {
-#if !ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) || USE(TIZEN_GSTREAMER_VIDEO_SET_SINK)
+#if (!ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) || USE(TIZEN_GSTREAMER_VIDEO_SET_SINK))
+#if PLATFORM(X11)
     if (!g_nativeDisplay)
         g_nativeDisplay = XOpenDisplay(0);
 
@@ -77,6 +97,9 @@ VideoLayerTizen::VideoLayerTizen(HTMLMediaElement* media)
                                0, 0, 1, 1, 0,
                                BlackPixel(g_nativeDisplay, 0), WhitePixel(g_nativeDisplay, 0));
     XFlush(g_nativeDisplay);
+#elif PLATFORM(WAYLAND)
+// see above note-1
+#endif
 #endif
 }
 
@@ -93,6 +116,7 @@ VideoLayerTizen::~VideoLayerTizen()
 
     m_videoSink = 0;
 #else
+#if PLATFORM(X11)
     if (m_platformSurfaceID) {
         XFreePixmap(g_nativeDisplay, m_platformSurfaceID);
         m_platformSurfaceID = 0;
@@ -101,6 +125,9 @@ VideoLayerTizen::~VideoLayerTizen()
         XDestroyWindow(g_nativeDisplay, m_nativeWindow);
         m_nativeWindow = 0;
     }
+#elif PLATFORM(WAYLAND)
+// see above note-1
+#endif
 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
 }
 
@@ -147,7 +174,11 @@ GstElement* VideoLayerTizen::createVideoSink()
 #else
     setVaapiEnv();
     GstElement* videoSink = gst_element_factory_make("vaapisink", "vaapisink");
+#if PLATFORM(X11)
     g_object_set(videoSink, "is-pixmap", 1, NULL);
+#elif PLATFORM(WAYLAND)
+    g_object_set(videoSink, "wl-display", WaylandDisplay::instance()->nativeDisplay(), NULL);
+#endif
 #endif
 
     m_videoSink = videoSink;
@@ -188,14 +219,12 @@ void VideoLayerTizen::setOverlay(IntSize size)
         m_platformSurface->copySurface(m_platformSurfaceToBeRemoved.get(), SharedVideoPlatformSurfaceTizen::FitToWidth);
 
 #ifdef GST_API_VERSION_1
-    gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(m_videoSink), m_platformSurface->handle());
+    gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(m_videoSink), (guintptr)m_platformSurface->nativeVideoSurface());
 #else
-    gst_x_overlay_set_window_handle(GST_X_OVERLAY(m_videoSink), m_platformSurface->handle());
+    gst_x_overlay_set_window_handle(GST_X_OVERLAY(m_videoSink), (guintptr)m_platformSurface->nativeVideoSurface());
 #endif
 #if !USE(ACCELERATED_VIDEO_VAAPI)
     g_object_set(m_videoSink, "rotate", 0, NULL);
-#else
-    g_object_set(m_videoSink, "is-pixmap", 1, NULL);
 #endif
 }
 
@@ -204,11 +233,10 @@ void VideoLayerTizen::paintCurrentFrameInContext(GraphicsContext* context, const
     if (m_platformSurface)
         m_platformSurface->paintCurrentFrameInContext(context, rect);
 }
-
 #else
-
 void VideoLayerTizen::paintVideoLayer(IntSize videoSize)
 {
+#if PLATFORM(X11)
     if (videoSize.isEmpty())
         return;
 
@@ -233,6 +261,9 @@ void VideoLayerTizen::paintVideoLayer(IntSize videoSize)
     XFlush(g_nativeDisplay);
 
     syncLayer(this);
+#elif PLATFORM(WAYLAND)
+    notImplemented();
+#endif
 }
 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
 
diff --git a/Source/WebCore/platform/graphics/surfaces/tizen/SharedVideoPlatformSurfaceTizenWayland.cpp b/Source/WebCore/platform/graphics/surfaces/tizen/SharedVideoPlatformSurfaceTizenWayland.cpp
new file mode 100644 (file)
index 0000000..788c663
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * 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"
+
+#if PLATFORM(WAYLAND) && USE(EGL)
+#include "SharedVideoPlatformSurfaceTizenWayland.h"
+#include "GraphicsSurface.h"
+#include "WaylandDisplay.h"
+#include "NotImplemented.h"
+
+namespace WebCore {
+
+SharedVideoPlatformSurfaceTizenWayland::SharedVideoPlatformSurfaceTizenWayland(const IntSize& size)
+    : SharedVideoPlatformSurfaceTizen(size)
+{
+    m_surface = WaylandDisplay::instance()->createSurface();
+
+    if (!m_surface) {
+        LOG_ERROR("Failed to create surface.");
+        destroy();
+        return;
+    }
+
+    m_bufferHandle = m_surface->handle();
+}
+
+SharedVideoPlatformSurfaceTizenWayland::~SharedVideoPlatformSurfaceTizenWayland()
+{
+    destroy();
+}
+
+void *SharedVideoPlatformSurfaceTizenWayland::nativeVideoSurface()
+{
+    return m_surface->wlSurface();
+}
+
+void SharedVideoPlatformSurfaceTizenWayland::destroy()
+{
+    if (m_surface)
+        m_surface->deleteFrameCallBack();
+
+    m_surface = nullptr;
+    m_bufferHandle = 0;
+}
+
+void SharedVideoPlatformSurfaceTizenWayland::platformPaintCurrentFrameInContext(GraphicsContext* context, const IntRect& rect)
+{
+    notImplemented();
+}
+
+void SharedVideoPlatformSurfaceTizenWayland::platformCopySurface(SharedVideoPlatformSurfaceTizen* other, float xPosition, float xScale, float yPosition, float yScale)
+{
+    notImplemented();
+}
+
+void SharedVideoPlatformSurfaceTizenWayland::clearPlatformSurface()
+{
+    notImplemented();
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/surfaces/tizen/SharedVideoPlatformSurfaceTizenWayland.h b/Source/WebCore/platform/graphics/surfaces/tizen/SharedVideoPlatformSurfaceTizenWayland.h
new file mode 100644 (file)
index 0000000..15a5c0a
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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 SharedVideoPlatformSurfaceTizenWayland_h
+#define SharedVideoPlatformSurfaceTizenWayland_h
+
+#if PLATFORM(WAYLAND)
+
+#include "SharedVideoPlatformSurfaceTizen.h"
+#include "WaylandSurface.h"
+
+namespace WebCore {
+
+class SharedVideoPlatformSurfaceTizenWayland : public SharedVideoPlatformSurfaceTizen {
+public:
+    SharedVideoPlatformSurfaceTizenWayland(const IntSize&);
+    virtual ~SharedVideoPlatformSurfaceTizenWayland();
+    virtual void* nativeVideoSurface();
+
+protected:
+    virtual void platformCopySurface(SharedVideoPlatformSurfaceTizen* other, float xPosition, float xScale, float yPosition, float yScale) OVERRIDE;
+    virtual void platformPaintCurrentFrameInContext(GraphicsContext* context, const IntRect& rect) OVERRIDE;
+    virtual void destroy();
+private:
+    void clearPlatformSurface();
+    void registerDamageHandler();
+    void unregisterDamageHandler();
+
+    OwnPtr<WaylandSurface> m_surface;
+};
+
+}
+
+#endif
+
+#endif
+
index dd523fd..50f12bb 100644 (file)
@@ -309,7 +309,7 @@ IF (WTF_USE_TILED_BACKING_STORE)
     ADD_DEFINITIONS(-DWTF_USE_TEXTURE_MAPPER=1)
 ENDIF ()
 
-IF (ENABLE_TIZEN_GSTREAMER_VIDEO_SET_SINK)
+IF (ENABLE_TIZEN_GSTREAMER_VIDEO_SET_SINK AND NOT ("${EFL_TARGET}" STREQUAL "i386"))
     SET(WTF_USE_TIZEN_GSTREAMER_VIDEO_SET_SINK 1)
     ADD_DEFINITIONS(-DWTF_USE_TIZEN_GSTREAMER_VIDEO_SET_SINK=1)
 ENDIF ()