[GStreamer] share GL context in pipeline, part 2
authorvjaquez@igalia.com <vjaquez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Mar 2015 10:31:00 +0000 (10:31 +0000)
committervjaquez@igalia.com <vjaquez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Mar 2015 10:31:00 +0000 (10:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143049

Reviewed by Carlos Garcia Campos.

.:

* Source/cmake/OptionsGTK.cmake: USE_GSTREAMER_GL is set only if
OpenGL/ES2 is found and GLX/EGL is found too.

Source/WebCore:

This patch, instead of cluttering the GstGL attributes creation in
::handleSyncMessage(), creates a new method ::ensureGstGLContext(),
where those attributes are defined. This method is guarded by
USE(GSTREAMER_GL)

::handlSyncMessage() shall return nothing, according to GStreamer
documentation, not a boolean.

The GstGL attributes are now GRefPtr<> to avoid memory leaks.

The GstGLAPI and GstGLPlatform are now set given by the pre-processor
directives, and the code in ::ensureGstGLContext() is simpler.

No new tests because this is platform specific and it depends in the
run-time availability and configurations of GstGL elements.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
Don't initialise the GstGL attributes since are GRefPtr<>
(WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): Changed the
signature to use void instead of gboolean.
(WebCore::MediaPlayerPrivateGStreamer::ensureGstGLContext): New method.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182056 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
Source/cmake/OptionsGTK.cmake

index 629fce7..9aae406 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2015-03-27  Víctor Manuel Jáquez Leal  <vjaquez@igalia.com>
+
+        [GStreamer] share GL context in pipeline, part 2
+        https://bugs.webkit.org/show_bug.cgi?id=143049
+
+        Reviewed by Carlos Garcia Campos.
+
+        * Source/cmake/OptionsGTK.cmake: USE_GSTREAMER_GL is set only if
+        OpenGL/ES2 is found and GLX/EGL is found too.
+
 2015-03-26  Alex Christensen  <achristensen@webkit.org>
 
         Progress towards CMake on Mac.
index 6890b5e..95235f7 100644 (file)
@@ -1,3 +1,34 @@
+2015-03-27  Víctor Manuel Jáquez Leal  <vjaquez@igalia.com>
+
+        [GStreamer] share GL context in pipeline, part 2
+        https://bugs.webkit.org/show_bug.cgi?id=143049
+
+        Reviewed by Carlos Garcia Campos.
+
+        This patch, instead of cluttering the GstGL attributes creation in
+        ::handleSyncMessage(), creates a new method ::ensureGstGLContext(),
+        where those attributes are defined. This method is guarded by
+        USE(GSTREAMER_GL)
+
+        ::handlSyncMessage() shall return nothing, according to GStreamer
+        documentation, not a boolean.
+
+        The GstGL attributes are now GRefPtr<> to avoid memory leaks.
+
+        The GstGLAPI and GstGLPlatform are now set given by the pre-processor
+        directives, and the code in ::ensureGstGLContext() is simpler.
+
+        No new tests because this is platform specific and it depends in the
+        run-time availability and configurations of GstGL elements.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
+        Don't initialise the GstGL attributes since are GRefPtr<>
+        (WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): Changed the
+        signature to use void instead of gboolean.
+        (WebCore::MediaPlayerPrivateGStreamer::ensureGstGLContext): New method.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
+
 2015-03-26  Jeremy Jones  <jeremyj@apple.com>
 
         Optimized Fullscreen fails to cleanup because of no longer necessary release of m_playerController in exitFullscreen()
index 25ffd08..7b3fe0b 100644 (file)
@@ -106,9 +106,9 @@ static gboolean mediaPlayerPrivateMessageCallback(GstBus*, GstMessage* message,
     return player->handleMessage(message);
 }
 
-static gboolean mediaPlayerPrivateSyncMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamer* player)
+static void mediaPlayerPrivateSyncMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamer* player)
 {
-    return player->handleSyncMessage(message);
+    player->handleSyncMessage(message);
 }
 
 static void mediaPlayerPrivateSourceChangedCallback(GObject*, GParamSpec*, MediaPlayerPrivateGStreamer* player)
@@ -244,10 +244,6 @@ MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
 #endif
     , m_requestedState(GST_STATE_VOID_PENDING)
     , m_missingPlugins(false)
-#if USE(GSTREAMER_GL)
-    , m_glContext(nullptr)
-    , m_glDisplay(nullptr)
-#endif
 {
 }
 
@@ -935,7 +931,7 @@ std::unique_ptr<PlatformTimeRanges> MediaPlayerPrivateGStreamer::buffered() cons
     return timeRanges;
 }
 
-gboolean MediaPlayerPrivateGStreamer::handleSyncMessage(GstMessage* message)
+void MediaPlayerPrivateGStreamer::handleSyncMessage(GstMessage* message)
 {
     switch (GST_MESSAGE_TYPE(message)) {
 #if USE(GSTREAMER_GL)
@@ -943,42 +939,22 @@ gboolean MediaPlayerPrivateGStreamer::handleSyncMessage(GstMessage* message)
         const gchar* contextType;
         gst_message_parse_context_type(message, &contextType);
 
-        if (!m_glDisplay) {
-#if PLATFORM(X11)
-            Display* display = GLContext::sharedX11Display();
-            GstGLDisplayX11* gstGLDisplay = gst_gl_display_x11_new_with_display(display);
-#elif PLATFORM(WAYLAND)
-            EGLDisplay display = WaylandDisplay::instance()->eglDisplay();
-            GstGLDisplayEGL* gstGLDisplay = gst_gl_display_egl_new_with_egl_display(display);
-#else
-            return FALSE;
-#endif
-
-            m_glDisplay = reinterpret_cast<GstGLDisplay*>(gstGLDisplay);
-            GLContext* webkitContext = GLContext::sharingContext();
-#if USE(GLX)
-            GLXContext* glxSharingContext = reinterpret_cast<GLXContext*>(webkitContext->platformContext());
-            if (glxSharingContext && !m_glContext)
-                m_glContext = gst_gl_context_new_wrapped(GST_GL_DISPLAY(gstGLDisplay), reinterpret_cast<guintptr>(glxSharingContext), GST_GL_PLATFORM_GLX, GST_GL_API_OPENGL);
-#elif USE(EGL)
-            EGLContext* eglSharingContext = reinterpret_cast<EGLContext*>(webkitContext->platformContext());
-            if (eglSharingContext && !m_glContext)
-                m_glContext = gst_gl_context_new_wrapped(GST_GL_DISPLAY(gstGLDisplay), reinterpret_cast<guintptr>(eglSharingContext), GST_GL_PLATFORM_EGL, GST_GL_API_GLES2);
-#endif
-        }
+        if (!ensureGstGLContext())
+            return;
 
         if (!g_strcmp0(contextType, GST_GL_DISPLAY_CONTEXT_TYPE)) {
             GstContext* displayContext = gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
-            gst_context_set_gl_display(displayContext, m_glDisplay);
+            gst_context_set_gl_display(displayContext, m_glDisplay.get());
             gst_element_set_context(GST_ELEMENT(message->src), displayContext);
-            return TRUE;
+            return;
         }
+
         if (!g_strcmp0(contextType, "gst.gl.app_context")) {
             GstContext* appContext = gst_context_new("gst.gl.app_context", TRUE);
             GstStructure* structure = gst_context_writable_structure(appContext);
-            gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_glContext, nullptr);
+            gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_glContext.get(), nullptr);
             gst_element_set_context(GST_ELEMENT(message->src), appContext);
-            return TRUE;
+            return;
         }
         break;
     }
@@ -986,9 +962,43 @@ gboolean MediaPlayerPrivateGStreamer::handleSyncMessage(GstMessage* message)
     default:
         break;
     }
-    return FALSE;
 }
 
+#if USE(GSTREAMER_GL)
+bool MediaPlayerPrivateGStreamer::ensureGstGLContext()
+{
+    if (m_glContext)
+        return true;
+
+    if (!m_glDisplay) {
+#if PLATFORM(X11)
+        Display* display = GLContext::sharedX11Display();
+        m_glDisplay = GST_GL_DISPLAY(gst_gl_display_x11_new_with_display(display));
+#elif PLATFORM(WAYLAND)
+        EGLDisplay display = WaylandDisplay::instance()->eglDisplay();
+        m_glDisplay = GST_GL_DISPLAY(gst_gl_display_egl_new_with_egl_display(display));
+#endif
+    }
+
+    PlatformGraphicsContext3D contextHandle = GLContext::sharingContext()->platformContext();
+    if (!contextHandle)
+        return false;
+#if USE(EGL)
+    GstGLPlatform glPlatform = GST_GL_PLATFORM_EGL;
+#else
+    GstGLPlatform glPlatform = GST_GL_PLATFORM_GLX;
+#endif
+#if USE(GLES2)
+    GstGLAPI glAPI = GST_GL_API_GLES2;
+#else
+    GstGLAPI glAPI = GST_GL_API_OPENGL;
+#endif
+    m_glContext = gst_gl_context_new_wrapped(m_glDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI);
+
+    return true;
+}
+#endif // USE(GSTREAMER_GL)
+
 gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
 {
     GUniqueOutPtr<GError> err;
index 8819d50..39226d2 100644 (file)
@@ -68,7 +68,7 @@ public:
     ~MediaPlayerPrivateGStreamer();
 
     static void registerMediaEngine(MediaEngineRegistrar);
-    gboolean handleSyncMessage(GstMessage*);
+    void handleSyncMessage(GstMessage*);
     gboolean handleMessage(GstMessage*);
     void handlePluginInstallerResult(GstInstallPluginsReturn);
 
@@ -159,6 +159,10 @@ private:
 
     void createGSTPlayBin();
 
+#if USE(GSTREAMER_GL)
+    bool ensureGstGLContext();
+#endif
+
     bool loadNextLocation();
     void mediaLocationChanged(GstMessage*);
 
@@ -255,8 +259,8 @@ private:
     bool isMediaSource() const { return false; }
 #endif
 #if USE(GSTREAMER_GL)
-    GstGLContext* m_glContext;
-    GstGLDisplay* m_glDisplay;
+    GRefPtr<GstGLContext> m_glContext;
+    GRefPtr<GstGLDisplay> m_glDisplay;
 #endif
 };
 }
index 190c380..db20910 100644 (file)
@@ -282,11 +282,6 @@ if (ENABLE_VIDEO OR ENABLE_WEB_AUDIO)
         add_definitions(-DWTF_USE_GSTREAMER_MPEGTS)
         set(USE_GSTREAMER_MPEGTS TRUE)
     endif ()
-
-    if (PC_GSTREAMER_GL_FOUND)
-        add_definitions(-DWTF_USE_GSTREAMER_GL)
-        set(USE_GSTREAMER_GL TRUE)
-    endif ()
 endif ()
 
 if (ENABLE_WAYLAND_TARGET)
@@ -393,6 +388,11 @@ if ((OPENGL_FOUND OR OPENGLES2_FOUND) AND (GLX_FOUND OR EGL_FOUND))
         add_definitions(-DWTF_USE_COORDINATED_GRAPHICS=1)
         add_definitions(-DWTF_USE_COORDINATED_GRAPHICS_THREADED=1)
     endif ()
+
+    if (PC_GSTREAMER_GL_FOUND)
+        add_definitions(-DWTF_USE_GSTREAMER_GL)
+        set(USE_GSTREAMER_GL TRUE)
+    endif ()
 endif ()
 
 if (ENABLE_GAMEPAD_DEPRECATED)