<!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>[202901] trunk/Source/WebCore</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/202901">202901</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-07 06:04:00 -0700 (Thu, 07 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Painting a video into a canvas doesn't work when accelerated compositing is enabled
https://bugs.webkit.org/show_bug.cgi?id=159405

Patch by Miguel Gomez &lt;magomez@igalia.com&gt; on 2016-07-07
Reviewed by Xabier Rodriguez-Calvar.

Implement video frame painting to the canvas when accelerated compositing is enabled.

Already covered by existent tests.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::handleMessage):
Replace custom enumeration for the video rotation with the ImageOrientation class.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
(WebCore::MediaPlayerPrivateGStreamerBase::naturalSize):
Replace the orientation value comparison with ImageOrientation::usesWidthAsHeight().
(WebCore::MediaPlayerPrivateGStreamerBase::paint):
Perform the frame painting taking into account the video orientation tag.
(WebCore::MediaPlayerPrivateGStreamerBase::nativeImageForCurrentTime):
Rotate the native image before returning it.
(WebCore::MediaPlayerPrivateGStreamerBase::setVideoSourceOrientation):
Replace custom enumeration for the video rotation with the ImageOrientation class.
(WebCore::MediaPlayerPrivateGStreamerBase::MediaPlayerPrivateGStreamerBase): Deleted.
Remove orientation initialization.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:
Remove custom enumeration for the video orientation.</pre>

<h3>Modified Paths</h3>
<ul>
<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="#trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBasecpp">trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBaseh">trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (202900 => 202901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-07-07 11:57:22 UTC (rev 202900)
+++ trunk/Source/WebCore/ChangeLog        2016-07-07 13:04:00 UTC (rev 202901)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2016-07-07  Miguel Gomez  &lt;magomez@igalia.com&gt;
+
+        [GTK] Painting a video into a canvas doesn't work when accelerated compositing is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=159405
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Implement video frame painting to the canvas when accelerated compositing is enabled.
+
+        Already covered by existent tests.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::handleMessage):
+        Replace custom enumeration for the video rotation with the ImageOrientation class.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
+        (WebCore::MediaPlayerPrivateGStreamerBase::naturalSize):
+        Replace the orientation value comparison with ImageOrientation::usesWidthAsHeight().
+        (WebCore::MediaPlayerPrivateGStreamerBase::paint):
+        Perform the frame painting taking into account the video orientation tag.
+        (WebCore::MediaPlayerPrivateGStreamerBase::nativeImageForCurrentTime):
+        Rotate the native image before returning it.
+        (WebCore::MediaPlayerPrivateGStreamerBase::setVideoSourceOrientation):
+        Replace custom enumeration for the video rotation with the ImageOrientation class.
+        (WebCore::MediaPlayerPrivateGStreamerBase::MediaPlayerPrivateGStreamerBase): Deleted.
+        Remove orientation initialization.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:
+        Remove custom enumeration for the video orientation.
+
</ins><span class="cx"> 2016-07-07  Philippe Normand  &lt;pnormand@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GStreamer][GL] switch to appsink
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (202900 => 202901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp        2016-07-07 11:57:22 UTC (rev 202900)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp        2016-07-07 13:04:00 UTC (rev 202901)
</span><span class="lines">@@ -1032,11 +1032,11 @@
</span><span class="cx">         gst_message_parse_tag(message, &amp;tags);
</span><span class="cx">         if (gst_tag_list_get_string(tags, GST_TAG_IMAGE_ORIENTATION, &amp;tag.outPtr())) {
</span><span class="cx">             if (!g_strcmp0(tag.get(), &quot;rotate-90&quot;))
</span><del>-                setVideoSourceRotation(VideoSourceRotation90);
</del><ins>+                setVideoSourceOrientation(ImageOrientation(OriginRightTop));
</ins><span class="cx">             else if (!g_strcmp0(tag.get(), &quot;rotate-180&quot;))
</span><del>-                setVideoSourceRotation(VideoSourceRotation180);
</del><ins>+                setVideoSourceOrientation(ImageOrientation(OriginBottomRight));
</ins><span class="cx">             else if (!g_strcmp0(tag.get(), &quot;rotate-270&quot;))
</span><del>-                setVideoSourceRotation(VideoSourceRotation270);
</del><ins>+                setVideoSourceOrientation(ImageOrientation(OriginLeftBottom));
</ins><span class="cx">         }
</span><span class="cx">         gst_tag_list_unref(tags);
</span><span class="cx">         break;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp (202900 => 202901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp        2016-07-07 11:57:22 UTC (rev 202900)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp        2016-07-07 13:04:00 UTC (rev 202901)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #include &quot;WebKitWebSourceGStreamer.h&quot;
</span><span class="cx"> #include &lt;wtf/glib/GMutexLocker.h&gt;
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><ins>+#include &lt;wtf/MathExtras.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #include &lt;gst/audio/streamvolume.h&gt;
</span><span class="cx"> #include &lt;gst/video/gstvideometa.h&gt;
</span><span class="lines">@@ -153,7 +154,6 @@
</span><span class="cx">     , m_drawTimer(RunLoop::main(), this, &amp;MediaPlayerPrivateGStreamerBase::repaint)
</span><span class="cx"> #endif
</span><span class="cx">     , m_usingFallbackVideoSink(false)
</span><del>-    , m_videoSourceRotation(NoVideoSourceRotation)
</del><span class="cx"> #if USE(TEXTURE_MAPPER_GL)
</span><span class="cx">     , m_textureMapperRotationFlag(0)
</span><span class="cx"> #endif
</span><span class="lines">@@ -300,7 +300,7 @@
</span><span class="cx"> #if USE(TEXTURE_MAPPER_GL)
</span><span class="cx">     // When using accelerated compositing, if the video is tagged as rotated 90 or 270 degrees, swap width and height.
</span><span class="cx">     if (m_player-&gt;client().mediaPlayerRenderingCanBeAccelerated(m_player)) {
</span><del>-        if (m_videoSourceRotation == VideoSourceRotation90 || m_videoSourceRotation == VideoSourceRotation270)
</del><ins>+        if (m_videoSourceOrientation.usesWidthAsHeight())
</ins><span class="cx">             originalSize = originalSize.transposedSize();
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="lines">@@ -608,13 +608,6 @@
</span><span class="cx"> 
</span><span class="cx"> void MediaPlayerPrivateGStreamerBase::paint(GraphicsContext&amp; context, const FloatRect&amp; rect)
</span><span class="cx"> {
</span><del>-#if USE(COORDINATED_GRAPHICS_THREADED)
-    return;
-#elif USE(TEXTURE_MAPPER_GL) &amp;&amp; !USE(COORDINATED_GRAPHICS)
-    if (client())
-        return;
-#endif
-
</del><span class="cx">     if (context.paintingDisabled())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -625,12 +618,16 @@
</span><span class="cx">     if (!GST_IS_SAMPLE(m_sample.get()))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    ImagePaintingOptions paintingOptions(CompositeCopy);
+    if (m_player-&gt;client().mediaPlayerRenderingCanBeAccelerated(m_player))
+        paintingOptions.m_orientationDescription.setImageOrientationEnum(m_videoSourceOrientation);
+
</ins><span class="cx">     RefPtr&lt;ImageGStreamer&gt; gstImage = ImageGStreamer::createImage(m_sample.get());
</span><span class="cx">     if (!gstImage)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (Image* image = reinterpret_cast&lt;Image*&gt;(gstImage-&gt;image().get()))
</span><del>-        context.drawImage(*image, rect, gstImage-&gt;rect(), CompositeCopy);
</del><ins>+        context.drawImage(*image, rect, gstImage-&gt;rect(), paintingOptions);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if USE(TEXTURE_MAPPER_GL) &amp;&amp; !USE(COORDINATED_GRAPHICS)
</span><span class="lines">@@ -712,32 +709,63 @@
</span><span class="cx"> 
</span><span class="cx">     unsigned textureID = *reinterpret_cast&lt;unsigned*&gt;(videoFrame.data[0]);
</span><span class="cx">     IntSize size = IntSize(GST_VIDEO_INFO_WIDTH(&amp;videoInfo), GST_VIDEO_INFO_HEIGHT(&amp;videoInfo));
</span><del>-    cairo_surface_t* surface = cairo_gl_surface_create_for_texture(device, CAIRO_CONTENT_COLOR_ALPHA, textureID, size.width(), size.height());
</del><ins>+    RefPtr&lt;cairo_surface_t&gt; surface = adoptRef(cairo_gl_surface_create_for_texture(device, CAIRO_CONTENT_COLOR_ALPHA, textureID, size.width(), size.height()));
+
+    IntSize rotatedSize = m_videoSourceOrientation.usesWidthAsHeight() ? size.transposedSize() : size;
+    RefPtr&lt;cairo_surface_t&gt; rotatedSurface = adoptRef(cairo_gl_surface_create(device, CAIRO_CONTENT_COLOR_ALPHA, rotatedSize.width(), rotatedSize.height()));
+    RefPtr&lt;cairo_t&gt; cr = adoptRef(cairo_create(rotatedSurface.get()));
+
+    switch (m_videoSourceOrientation) {
+    case DefaultImageOrientation:
+        break;
+    case OriginRightTop:
+        cairo_translate(cr.get(), rotatedSize.width() * 0.5, rotatedSize.height() * 0.5);
+        cairo_rotate(cr.get(), piOverTwoDouble);
+        cairo_translate(cr.get(), -rotatedSize.height() * 0.5, -rotatedSize.width() * 0.5);
+        break;
+    case OriginBottomRight:
+        cairo_translate(cr.get(), rotatedSize.width() * 0.5, rotatedSize.height() * 0.5);
+        cairo_rotate(cr.get(), piDouble);
+        cairo_translate(cr.get(), -rotatedSize.width() * 0.5, -rotatedSize.height() * 0.5);
+        break;
+    case OriginLeftBottom:
+        cairo_translate(cr.get(), rotatedSize.width() * 0.5, rotatedSize.height() * 0.5);
+        cairo_rotate(cr.get(), 3 * piOverTwoDouble);
+        cairo_translate(cr.get(), -rotatedSize.height() * 0.5, -rotatedSize.width() * 0.5);
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+    cairo_set_source_surface(cr.get(), surface.get(), 0, 0);
+    cairo_set_operator(cr.get(), CAIRO_OPERATOR_SOURCE);
+    cairo_paint(cr.get());
+
</ins><span class="cx">     gst_video_frame_unmap(&amp;videoFrame);
</span><span class="cx"> 
</span><del>-    return adoptRef(surface);
</del><ins>+    return rotatedSurface;
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-void MediaPlayerPrivateGStreamerBase::setVideoSourceRotation(VideoSourceRotation rotation)
</del><ins>+void MediaPlayerPrivateGStreamerBase::setVideoSourceOrientation(const ImageOrientation&amp; orientation)
</ins><span class="cx"> {
</span><del>-    if (m_videoSourceRotation == rotation)
</del><ins>+    if (m_videoSourceOrientation == orientation)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_videoSourceRotation = rotation;
</del><ins>+    m_videoSourceOrientation = orientation;
</ins><span class="cx"> 
</span><span class="cx"> #if USE(TEXTURE_MAPPER_GL)
</span><del>-    switch (m_videoSourceRotation) {
-    case NoVideoSourceRotation:
</del><ins>+    switch (m_videoSourceOrientation) {
+    case DefaultImageOrientation:
</ins><span class="cx">         m_textureMapperRotationFlag = 0;
</span><span class="cx">         break;
</span><del>-    case VideoSourceRotation90:
</del><ins>+    case OriginRightTop:
</ins><span class="cx">         m_textureMapperRotationFlag = TextureMapperGL::ShouldRotateTexture90;
</span><span class="cx">         break;
</span><del>-    case VideoSourceRotation180:
</del><ins>+    case OriginBottomRight:
</ins><span class="cx">         m_textureMapperRotationFlag = TextureMapperGL::ShouldRotateTexture180;
</span><span class="cx">         break;
</span><del>-    case VideoSourceRotation270:
</del><ins>+    case OriginLeftBottom:
</ins><span class="cx">         m_textureMapperRotationFlag = TextureMapperGL::ShouldRotateTexture270;
</span><span class="cx">         break;
</span><span class="cx">     default:
</span><span class="lines">@@ -771,6 +799,10 @@
</span><span class="cx"> #if USE(GSTREAMER_GL)
</span><span class="cx"> GstElement* MediaPlayerPrivateGStreamerBase::createVideoSinkGL()
</span><span class="cx"> {
</span><ins>+    // FIXME: Currently it's not possible to get the video frames and caps using this approach until
+    // the pipeline gets into playing state. Due to this, trying to grab a frame and painting it by some
+    // other mean (canvas or webgl) before playing state can result in a crash.
+    // This is being handled in https://bugs.webkit.org/show_bug.cgi?id=159460.
</ins><span class="cx">     if (!webkitGstCheckVersion(1, 8, 0))
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h (202900 => 202901)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h        2016-07-07 11:57:22 UTC (rev 202900)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h        2016-07-07 13:04:00 UTC (rev 202901)
</span><span class="lines">@@ -62,13 +62,6 @@
</span><span class="cx"> {
</span><span class="cx"> 
</span><span class="cx"> public:
</span><del>-    enum VideoSourceRotation {
-        NoVideoSourceRotation,
-        VideoSourceRotation90,
-        VideoSourceRotation180,
-        VideoSourceRotation270
-    };
-
</del><span class="cx">     virtual ~MediaPlayerPrivateGStreamerBase();
</span><span class="cx"> 
</span><span class="cx">     FloatSize naturalSize() const override;
</span><span class="lines">@@ -129,7 +122,7 @@
</span><span class="cx">     NativeImagePtr nativeImageForCurrentTime() override;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    void setVideoSourceRotation(VideoSourceRotation);
</del><ins>+    void setVideoSourceOrientation(const ImageOrientation&amp;);
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     MediaPlayerPrivateGStreamerBase(MediaPlayer*);
</span><span class="lines">@@ -208,7 +201,7 @@
</span><span class="cx">     Lock m_drawMutex;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    VideoSourceRotation m_videoSourceRotation;
</del><ins>+    ImageOrientation m_videoSourceOrientation;
</ins><span class="cx"> #if USE(TEXTURE_MAPPER_GL)
</span><span class="cx">     TextureMapperGL::Flags m_textureMapperRotationFlag;
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>