<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[182056] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/182056">182056</a></dd>
<dt>Author</dt> <dd>vjaquez@igalia.com</dd>
<dt>Date</dt> <dd>2015-03-27 03:31:00 -0700 (Fri, 27 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[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.

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&lt;&gt; 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&lt;&gt;
(WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): Changed the
signature to use void instead of gboolean.
(WebCore::MediaPlayerPrivateGStreamer::ensureGstGLContext): New method.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkChangeLog">trunk/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamercpp">trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerh">trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h</a></li>
<li><a href="#trunkSourcecmakeOptionsGTKcmake">trunk/Source/cmake/OptionsGTK.cmake</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/ChangeLog (182055 => 182056)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/ChangeLog        2015-03-27 07:26:35 UTC (rev 182055)
+++ trunk/ChangeLog        2015-03-27 10:31:00 UTC (rev 182056)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2015-03-27  Víctor Manuel Jáquez Leal  &lt;vjaquez@igalia.com&gt;
+
+        [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.
+
</ins><span class="cx"> 2015-03-26  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Progress towards CMake on Mac.
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (182055 => 182056)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-03-27 07:26:35 UTC (rev 182055)
+++ trunk/Source/WebCore/ChangeLog        2015-03-27 10:31:00 UTC (rev 182056)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2015-03-27  Víctor Manuel Jáquez Leal  &lt;vjaquez@igalia.com&gt;
+
+        [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&lt;&gt; 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&lt;&gt;
+        (WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): Changed the
+        signature to use void instead of gboolean.
+        (WebCore::MediaPlayerPrivateGStreamer::ensureGstGLContext): New method.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
+
</ins><span class="cx"> 2015-03-26  Jeremy Jones  &lt;jeremyj@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Optimized Fullscreen fails to cleanup because of no longer necessary release of m_playerController in exitFullscreen()
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (182055 => 182056)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp        2015-03-27 07:26:35 UTC (rev 182055)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp        2015-03-27 10:31:00 UTC (rev 182056)
</span><span class="lines">@@ -106,9 +106,9 @@
</span><span class="cx">     return player-&gt;handleMessage(message);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static gboolean mediaPlayerPrivateSyncMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamer* player)
</del><ins>+static void mediaPlayerPrivateSyncMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamer* player)
</ins><span class="cx"> {
</span><del>-    return player-&gt;handleSyncMessage(message);
</del><ins>+    player-&gt;handleSyncMessage(message);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void mediaPlayerPrivateSourceChangedCallback(GObject*, GParamSpec*, MediaPlayerPrivateGStreamer* player)
</span><span class="lines">@@ -244,10 +244,6 @@
</span><span class="cx"> #endif
</span><span class="cx">     , m_requestedState(GST_STATE_VOID_PENDING)
</span><span class="cx">     , m_missingPlugins(false)
</span><del>-#if USE(GSTREAMER_GL)
-    , m_glContext(nullptr)
-    , m_glDisplay(nullptr)
-#endif
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -935,7 +931,7 @@
</span><span class="cx">     return timeRanges;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-gboolean MediaPlayerPrivateGStreamer::handleSyncMessage(GstMessage* message)
</del><ins>+void MediaPlayerPrivateGStreamer::handleSyncMessage(GstMessage* message)
</ins><span class="cx"> {
</span><span class="cx">     switch (GST_MESSAGE_TYPE(message)) {
</span><span class="cx"> #if USE(GSTREAMER_GL)
</span><span class="lines">@@ -943,42 +939,22 @@
</span><span class="cx">         const gchar* contextType;
</span><span class="cx">         gst_message_parse_context_type(message, &amp;contextType);
</span><span class="cx"> 
</span><del>-        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()-&gt;eglDisplay();
-            GstGLDisplayEGL* gstGLDisplay = gst_gl_display_egl_new_with_egl_display(display);
-#else
-            return FALSE;
-#endif
</del><ins>+        if (!ensureGstGLContext())
+            return;
</ins><span class="cx"> 
</span><del>-            m_glDisplay = reinterpret_cast&lt;GstGLDisplay*&gt;(gstGLDisplay);
-            GLContext* webkitContext = GLContext::sharingContext();
-#if USE(GLX)
-            GLXContext* glxSharingContext = reinterpret_cast&lt;GLXContext*&gt;(webkitContext-&gt;platformContext());
-            if (glxSharingContext &amp;&amp; !m_glContext)
-                m_glContext = gst_gl_context_new_wrapped(GST_GL_DISPLAY(gstGLDisplay), reinterpret_cast&lt;guintptr&gt;(glxSharingContext), GST_GL_PLATFORM_GLX, GST_GL_API_OPENGL);
-#elif USE(EGL)
-            EGLContext* eglSharingContext = reinterpret_cast&lt;EGLContext*&gt;(webkitContext-&gt;platformContext());
-            if (eglSharingContext &amp;&amp; !m_glContext)
-                m_glContext = gst_gl_context_new_wrapped(GST_GL_DISPLAY(gstGLDisplay), reinterpret_cast&lt;guintptr&gt;(eglSharingContext), GST_GL_PLATFORM_EGL, GST_GL_API_GLES2);
-#endif
-        }
-
</del><span class="cx">         if (!g_strcmp0(contextType, GST_GL_DISPLAY_CONTEXT_TYPE)) {
</span><span class="cx">             GstContext* displayContext = gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
</span><del>-            gst_context_set_gl_display(displayContext, m_glDisplay);
</del><ins>+            gst_context_set_gl_display(displayContext, m_glDisplay.get());
</ins><span class="cx">             gst_element_set_context(GST_ELEMENT(message-&gt;src), displayContext);
</span><del>-            return TRUE;
</del><ins>+            return;
</ins><span class="cx">         }
</span><ins>+
</ins><span class="cx">         if (!g_strcmp0(contextType, &quot;gst.gl.app_context&quot;)) {
</span><span class="cx">             GstContext* appContext = gst_context_new(&quot;gst.gl.app_context&quot;, TRUE);
</span><span class="cx">             GstStructure* structure = gst_context_writable_structure(appContext);
</span><del>-            gst_structure_set(structure, &quot;context&quot;, GST_GL_TYPE_CONTEXT, m_glContext, nullptr);
</del><ins>+            gst_structure_set(structure, &quot;context&quot;, GST_GL_TYPE_CONTEXT, m_glContext.get(), nullptr);
</ins><span class="cx">             gst_element_set_context(GST_ELEMENT(message-&gt;src), appContext);
</span><del>-            return TRUE;
</del><ins>+            return;
</ins><span class="cx">         }
</span><span class="cx">         break;
</span><span class="cx">     }
</span><span class="lines">@@ -986,9 +962,43 @@
</span><span class="cx">     default:
</span><span class="cx">         break;
</span><span class="cx">     }
</span><del>-    return FALSE;
</del><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#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()-&gt;eglDisplay();
+        m_glDisplay = GST_GL_DISPLAY(gst_gl_display_egl_new_with_egl_display(display));
+#endif
+    }
+
+    PlatformGraphicsContext3D contextHandle = GLContext::sharingContext()-&gt;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&lt;guintptr&gt;(contextHandle), glPlatform, glAPI);
+
+    return true;
+}
+#endif // USE(GSTREAMER_GL)
+
</ins><span class="cx"> gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
</span><span class="cx"> {
</span><span class="cx">     GUniqueOutPtr&lt;GError&gt; err;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h (182055 => 182056)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h        2015-03-27 07:26:35 UTC (rev 182055)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h        2015-03-27 10:31:00 UTC (rev 182056)
</span><span class="lines">@@ -68,7 +68,7 @@
</span><span class="cx">     ~MediaPlayerPrivateGStreamer();
</span><span class="cx"> 
</span><span class="cx">     static void registerMediaEngine(MediaEngineRegistrar);
</span><del>-    gboolean handleSyncMessage(GstMessage*);
</del><ins>+    void handleSyncMessage(GstMessage*);
</ins><span class="cx">     gboolean handleMessage(GstMessage*);
</span><span class="cx">     void handlePluginInstallerResult(GstInstallPluginsReturn);
</span><span class="cx"> 
</span><span class="lines">@@ -159,6 +159,10 @@
</span><span class="cx"> 
</span><span class="cx">     void createGSTPlayBin();
</span><span class="cx"> 
</span><ins>+#if USE(GSTREAMER_GL)
+    bool ensureGstGLContext();
+#endif
+
</ins><span class="cx">     bool loadNextLocation();
</span><span class="cx">     void mediaLocationChanged(GstMessage*);
</span><span class="cx"> 
</span><span class="lines">@@ -255,8 +259,8 @@
</span><span class="cx">     bool isMediaSource() const { return false; }
</span><span class="cx"> #endif
</span><span class="cx"> #if USE(GSTREAMER_GL)
</span><del>-    GstGLContext* m_glContext;
-    GstGLDisplay* m_glDisplay;
</del><ins>+    GRefPtr&lt;GstGLContext&gt; m_glContext;
+    GRefPtr&lt;GstGLDisplay&gt; m_glDisplay;
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourcecmakeOptionsGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/cmake/OptionsGTK.cmake (182055 => 182056)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/cmake/OptionsGTK.cmake        2015-03-27 07:26:35 UTC (rev 182055)
+++ trunk/Source/cmake/OptionsGTK.cmake        2015-03-27 10:31:00 UTC (rev 182056)
</span><span class="lines">@@ -282,11 +282,6 @@
</span><span class="cx">         add_definitions(-DWTF_USE_GSTREAMER_MPEGTS)
</span><span class="cx">         set(USE_GSTREAMER_MPEGTS TRUE)
</span><span class="cx">     endif ()
</span><del>-
-    if (PC_GSTREAMER_GL_FOUND)
-        add_definitions(-DWTF_USE_GSTREAMER_GL)
-        set(USE_GSTREAMER_GL TRUE)
-    endif ()
</del><span class="cx"> endif ()
</span><span class="cx"> 
</span><span class="cx"> if (ENABLE_WAYLAND_TARGET)
</span><span class="lines">@@ -393,6 +388,11 @@
</span><span class="cx">         add_definitions(-DWTF_USE_COORDINATED_GRAPHICS=1)
</span><span class="cx">         add_definitions(-DWTF_USE_COORDINATED_GRAPHICS_THREADED=1)
</span><span class="cx">     endif ()
</span><ins>+
+    if (PC_GSTREAMER_GL_FOUND)
+        add_definitions(-DWTF_USE_GSTREAMER_GL)
+        set(USE_GSTREAMER_GL TRUE)
+    endif ()
</ins><span class="cx"> endif ()
</span><span class="cx"> 
</span><span class="cx"> if (ENABLE_GAMEPAD_DEPRECATED)
</span></span></pre>
</div>
</div>

</body>
</html>