[GStreamer] Support flipY for GPU-to-GPU copy of video textures to WebGL
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Sep 2016 10:20:48 +0000 (10:20 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Sep 2016 10:20:48 +0000 (10:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162491

Patch by Olivier Blin <olivier.blin@softathome.com> on 2016-09-26
Reviewed by Philippe Normand.

GPU-GPU copy of video textures to WebGL has been added for
GStreamer in bug 159928. It did not handle textures with inverted
Y, and thus copy to such textures was not accelerated.

This occurs with THREE.js which defaults to flipY for textures.
It can be tested on http://flimshaw.github.io/Valiant360/

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
(WebCore::MediaPlayerPrivateGStreamerBase::paintToCairoSurface):
(WebCore::MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture):
(WebCore::MediaPlayerPrivateGStreamerBase::nativeImageForCurrentTime):
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h

index e22079c..da2a69e 100644 (file)
@@ -1,3 +1,23 @@
+2016-09-26  Olivier Blin  <olivier.blin@softathome.com>
+
+        [GStreamer] Support flipY for GPU-to-GPU copy of video textures to WebGL
+        https://bugs.webkit.org/show_bug.cgi?id=162491
+
+        Reviewed by Philippe Normand.
+
+        GPU-GPU copy of video textures to WebGL has been added for
+        GStreamer in bug 159928. It did not handle textures with inverted
+        Y, and thus copy to such textures was not accelerated.
+
+        This occurs with THREE.js which defaults to flipY for textures.
+        It can be tested on http://flimshaw.github.io/Valiant360/
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
+        (WebCore::MediaPlayerPrivateGStreamerBase::paintToCairoSurface):
+        (WebCore::MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture):
+        (WebCore::MediaPlayerPrivateGStreamerBase::nativeImageForCurrentTime):
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:
+
 2016-09-25  Antti Koivisto  <antti@apple.com>
 
         AuthorStyleSheets shouldn't trigger synchronous style resolutions
index 91e7f8a..ee12e4f 100644 (file)
@@ -716,7 +716,7 @@ GLContext* MediaPlayerPrivateGStreamerBase::prepareContextForCairoPaint(GstVideo
 }
 
 // This should be called with the sample mutex locked.
-bool MediaPlayerPrivateGStreamerBase::paintToCairoSurface(cairo_surface_t* outputSurface, cairo_device_t* device, GstVideoInfo& videoInfo, const IntSize& size, const IntSize& rotatedSize)
+bool MediaPlayerPrivateGStreamerBase::paintToCairoSurface(cairo_surface_t* outputSurface, cairo_device_t* device, GstVideoInfo& videoInfo, const IntSize& size, const IntSize& rotatedSize, bool flipY)
 {
     GstBuffer* buffer = gst_sample_get_buffer(m_sample.get());
     GstVideoFrame videoFrame;
@@ -749,6 +749,12 @@ bool MediaPlayerPrivateGStreamerBase::paintToCairoSurface(cairo_surface_t* outpu
         ASSERT_NOT_REACHED();
         break;
     }
+
+    if (flipY) {
+        cairo_scale(cr.get(), 1.0f, -1.0f);
+        cairo_translate(cr.get(), 0.0f, -size.height());
+    }
+
     cairo_set_source_surface(cr.get(), surface.get(), 0, 0);
     cairo_set_operator(cr.get(), CAIRO_OPERATOR_SOURCE);
     cairo_paint(cr.get());
@@ -767,7 +773,7 @@ bool MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture(Graphics
     if (m_usingFallbackVideoSink)
         return false;
 
-    if (flipY || premultiplyAlpha)
+    if (premultiplyAlpha)
         return false;
 
     GstVideoInfo videoInfo;
@@ -787,7 +793,7 @@ bool MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture(Graphics
     context->getTexParameteriv(outputTarget, GL_TEXTURE_MAG_FILTER, &magFilter);
 
     RefPtr<cairo_surface_t> outputSurface = adoptRef(cairo_gl_surface_create_for_texture(glContext->cairoDevice(), CAIRO_CONTENT_COLOR_ALPHA, outputTexture, rotatedSize.width(), rotatedSize.height()));
-    if (!paintToCairoSurface(outputSurface.get(), glContext->cairoDevice(), videoInfo, size, rotatedSize))
+    if (!paintToCairoSurface(outputSurface.get(), glContext->cairoDevice(), videoInfo, size, rotatedSize, flipY))
         return false;
 
     context->bindTexture(outputTarget, outputTexture);
@@ -811,7 +817,7 @@ NativeImagePtr MediaPlayerPrivateGStreamerBase::nativeImageForCurrentTime()
         return nullptr;
 
     RefPtr<cairo_surface_t> rotatedSurface = adoptRef(cairo_gl_surface_create(context->cairoDevice(), CAIRO_CONTENT_COLOR_ALPHA, rotatedSize.width(), rotatedSize.height()));
-    if (!paintToCairoSurface(rotatedSurface.get(), context->cairoDevice(), videoInfo, size, rotatedSize))
+    if (!paintToCairoSurface(rotatedSurface.get(), context->cairoDevice(), videoInfo, size, rotatedSize, false))
         return nullptr;
 
     return rotatedSurface;
index e4ac9c8..36bd8a5 100644 (file)
@@ -133,7 +133,7 @@ protected:
     GstElement* createGLAppSink();
     GstElement* createVideoSinkGL();
     GLContext* prepareContextForCairoPaint(GstVideoInfo&, IntSize&, IntSize&);
-    bool paintToCairoSurface(cairo_surface_t*, cairo_device_t*, GstVideoInfo&, const IntSize&, const IntSize&);
+    bool paintToCairoSurface(cairo_surface_t*, cairo_device_t*, GstVideoInfo&, const IntSize&, const IntSize&, bool);
 #endif
 
     void setStreamVolumeElement(GstStreamVolume*);