<!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>[206862] 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/206862">206862</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-10-06 03:53:28 -0700 (Thu, 06 Oct 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[GTK] Copying video textures to webgl should not depend on cairo-gl
https://bugs.webkit.org/show_bug.cgi?id=162904
Patch by Miguel Gomez <magomez@igalia.com> on 2016-10-06
Reviewed by Žan Doberšek.
Perform the texture copy without using cairo-gl.
Covered by existent tests.
* platform/GStreamer.cmake:
Add the new VideoTextureCopierGStreamer class to the build.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
(WebCore::MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture):
Use VideoTextureCopierGStreamer to perform the copy.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:
Add a VideoTextureCopierGStreamer as a class attribute.
* platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp: Added.
(WebCore::VideoTextureCopierGStreamer::VideoTextureCopierGStreamer):
(WebCore::VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer):
(WebCore::VideoTextureCopierGStreamer::updateTextureSpaceMatrix):
Recalculates the matrix used as the texture coordinates transformation.
(WebCore::VideoTextureCopierGStreamer::updateTransformationMatrix):
Recalculates the matrices used as the vertices coordinates transformation.
(WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
Performs the texture copy by using a shader that applies the rotation needed to follow
the video orientation.
* platform/graphics/gstreamer/VideoTextureCopierGStreamer.h: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformGStreamercmake">trunk/Source/WebCore/platform/GStreamer.cmake</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>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerVideoTextureCopierGStreamercpp">trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerVideoTextureCopierGStreamerh">trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (206861 => 206862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-06 10:44:31 UTC (rev 206861)
+++ trunk/Source/WebCore/ChangeLog        2016-10-06 10:53:28 UTC (rev 206862)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-10-06 Miguel Gomez <magomez@igalia.com>
+
+ [GTK] Copying video textures to webgl should not depend on cairo-gl
+ https://bugs.webkit.org/show_bug.cgi?id=162904
+
+ Reviewed by Žan Doberšek.
+
+ Perform the texture copy without using cairo-gl.
+
+ Covered by existent tests.
+
+ * platform/GStreamer.cmake:
+ Add the new VideoTextureCopierGStreamer class to the build.
+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
+ (WebCore::MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture):
+ Use VideoTextureCopierGStreamer to perform the copy.
+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:
+ Add a VideoTextureCopierGStreamer as a class attribute.
+ * platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp: Added.
+ (WebCore::VideoTextureCopierGStreamer::VideoTextureCopierGStreamer):
+ (WebCore::VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer):
+ (WebCore::VideoTextureCopierGStreamer::updateTextureSpaceMatrix):
+ Recalculates the matrix used as the texture coordinates transformation.
+ (WebCore::VideoTextureCopierGStreamer::updateTransformationMatrix):
+ Recalculates the matrices used as the vertices coordinates transformation.
+ (WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
+ Performs the texture copy by using a shader that applies the rotation needed to follow
+ the video orientation.
+ * platform/graphics/gstreamer/VideoTextureCopierGStreamer.h: Added.
+
</ins><span class="cx"> 2016-10-06 Gwang Yoon Hwang <yoon@igalia.com>
</span><span class="cx">
</span><span class="cx"> [GTK] Build fix for X11 and GStreamerGL after r183731
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformGStreamercmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/GStreamer.cmake (206861 => 206862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/GStreamer.cmake        2016-10-06 10:44:31 UTC (rev 206861)
+++ trunk/Source/WebCore/platform/GStreamer.cmake        2016-10-06 10:53:28 UTC (rev 206862)
</span><span class="lines">@@ -88,6 +88,9 @@
</span><span class="cx"> list(APPEND WebCore_LIBRARIES
</span><span class="cx"> ${GSTREAMER_GL_LIBRARIES}
</span><span class="cx"> )
</span><ins>+ list(APPEND WebCore_SOURCES
+ platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp
+ )
</ins><span class="cx"> endif ()
</span><span class="cx"> endif ()
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp (206861 => 206862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp        2016-10-06 10:44:31 UTC (rev 206861)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp        2016-10-06 10:53:28 UTC (rev 206862)
</span><span class="lines">@@ -74,6 +74,7 @@
</span><span class="cx"> #if PLATFORM(X11) && GST_GL_HAVE_PLATFORM_EGL
</span><span class="cx"> #undef None
</span><span class="cx"> #endif // PLATFORM(X11) && GST_GL_HAVE_PLATFORM_EGL
</span><ins>+#include "VideoTextureCopierGStreamer.h"
</ins><span class="cx"> #endif // USE(GSTREAMER_GL)
</span><span class="cx">
</span><span class="cx"> #if USE(TEXTURE_MAPPER_GL)
</span><span class="lines">@@ -781,9 +782,8 @@
</span><span class="cx">
</span><span class="cx"> bool MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture(GraphicsContext3D* context, Platform3DObject outputTexture, GC3Denum outputTarget, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool premultiplyAlpha, bool flipY)
</span><span class="cx"> {
</span><del>-#if !USE(CAIRO)
- return false;
-#endif
</del><ins>+#if USE(GSTREAMER_GL)
+ UNUSED_PARAM(context);
</ins><span class="cx">
</span><span class="cx"> if (m_usingFallbackVideoSink)
</span><span class="cx"> return false;
</span><span class="lines">@@ -791,31 +791,33 @@
</span><span class="cx"> if (premultiplyAlpha)
</span><span class="cx"> return false;
</span><span class="cx">
</span><ins>+ WTF::GMutexLocker<GMutex> lock(m_sampleMutex);
+
</ins><span class="cx"> GstVideoInfo videoInfo;
</span><del>- IntSize size, rotatedSize;
- WTF::GMutexLocker<GMutex> lock(m_sampleMutex);
- GLContext* glContext = prepareContextForCairoPaint(videoInfo, size, rotatedSize);
- if (!glContext)
</del><ins>+ if (!getSampleVideoInfo(m_sample.get(), videoInfo))
</ins><span class="cx"> return false;
</span><span class="cx">
</span><del>- // Allocate uninitialized memory for the output texture.
- context->bindTexture(outputTarget, outputTexture);
- context->texImage2DDirect(outputTarget, level, internalFormat, rotatedSize.width(), rotatedSize.height(), 0, format, type, nullptr);
</del><ins>+ GstBuffer* buffer = gst_sample_get_buffer(m_sample.get());
+ GstVideoFrame videoFrame;
+ if (!gst_video_frame_map(&videoFrame, &videoInfo, buffer, static_cast<GstMapFlags>(GST_MAP_READ | GST_MAP_GL)))
+ return false;
</ins><span class="cx">
</span><del>- // cairo_gl_surface_create_for_texture sets these parameters to GL_NEAREST, so we need to backup them.
- GC3Dint minFilter, magFilter;
- context->getTexParameteriv(outputTarget, GL_TEXTURE_MIN_FILTER, &minFilter);
- context->getTexParameteriv(outputTarget, GL_TEXTURE_MAG_FILTER, &magFilter);
</del><ins>+ IntSize size(GST_VIDEO_INFO_WIDTH(&videoInfo), GST_VIDEO_INFO_HEIGHT(&videoInfo));
+ if (m_videoSourceOrientation.usesWidthAsHeight())
+ size = size.transposedSize();
+ unsigned textureID = *reinterpret_cast<unsigned*>(videoFrame.data[0]);
</ins><span class="cx">
</span><del>- 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, flipY))
- return false;
</del><ins>+ if (!m_videoTextureCopier)
+ m_videoTextureCopier = std::make_unique<VideoTextureCopierGStreamer>();
</ins><span class="cx">
</span><del>- context->bindTexture(outputTarget, outputTexture);
- context->texParameteri(outputTarget, GraphicsContext3D::TEXTURE_MIN_FILTER, minFilter);
- context->texParameteri(outputTarget, GraphicsContext3D::TEXTURE_MAG_FILTER, magFilter);
</del><ins>+ bool copied = m_videoTextureCopier->copyVideoTextureToPlatformTexture(textureID, size, outputTexture, outputTarget, level, internalFormat, format, type, flipY, m_videoSourceOrientation);
</ins><span class="cx">
</span><del>- return true;
</del><ins>+ gst_video_frame_unmap(&videoFrame);
+
+ return copied;
+#else
+ return false;
+#endif
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> NativeImagePtr MediaPlayerPrivateGStreamerBase::nativeImageForCurrentTime()
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h (206861 => 206862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h        2016-10-06 10:44:31 UTC (rev 206861)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h        2016-10-06 10:53:28 UTC (rev 206862)
</span><span class="lines">@@ -52,6 +52,7 @@
</span><span class="cx"> class GraphicsContext3D;
</span><span class="cx"> class IntSize;
</span><span class="cx"> class IntRect;
</span><ins>+class VideoTextureCopierGStreamer;
</ins><span class="cx">
</span><span class="cx"> class MediaPlayerPrivateGStreamerBase : public MediaPlayerPrivateInterface
</span><span class="cx"> #if USE(COORDINATED_GRAPHICS_THREADED) || (USE(TEXTURE_MAPPER_GL) && !USE(COORDINATED_GRAPHICS))
</span><span class="lines">@@ -205,6 +206,10 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> ImageOrientation m_videoSourceOrientation;
</span><ins>+
+#if USE(GSTREAMER_GL)
+ std::unique_ptr<VideoTextureCopierGStreamer> m_videoTextureCopier;
+#endif
</ins><span class="cx"> };
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerVideoTextureCopierGStreamercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp (0 => 206862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp         (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp        2016-10-06 10:53:28 UTC (rev 206862)
</span><span class="lines">@@ -0,0 +1,190 @@
</span><ins>+/*
+ Copyright (C) 2016 Igalia S.L.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+
+#include "config.h"
+#include "VideoTextureCopierGStreamer.h"
+
+#if USE(GSTREAMER_GL)
+
+#include "GLContext.h"
+#include "ImageOrientation.h"
+#include "TextureMapperShaderProgram.h"
+
+namespace WebCore {
+
+VideoTextureCopierGStreamer::VideoTextureCopierGStreamer()
+{
+ GLContext* previousContext = GLContext::current();
+ ASSERT(previousContext);
+ PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->makeContextCurrent();
+
+ m_context3D = GraphicsContext3D::createForCurrentGLContext();
+
+ m_shaderProgram = TextureMapperShaderProgram::create(*m_context3D, TextureMapperShaderProgram::Texture);
+
+ m_framebuffer = m_context3D->createFramebuffer();
+
+ static const GLfloat vertices[] = { 0, 0, 1, 0, 1, 1, 0, 1 };
+ m_vbo = m_context3D->createBuffer();
+ m_context3D->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_vbo);
+ m_context3D->bufferData(GraphicsContext3D::ARRAY_BUFFER, sizeof(GC3Dfloat) * 8, vertices, GraphicsContext3D::STATIC_DRAW);
+
+ updateTextureSpaceMatrix();
+
+ previousContext->makeContextCurrent();
+}
+
+VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer()
+{
+ GLContext* previousContext = GLContext::current();
+ ASSERT(previousContext);
+ PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->makeContextCurrent();
+
+ m_context3D->deleteFramebuffer(m_framebuffer);
+ m_context3D->deleteBuffer(m_vbo);
+ m_shaderProgram = nullptr;
+ m_context3D = nullptr;
+
+ previousContext->makeContextCurrent();
+}
+
+void VideoTextureCopierGStreamer::updateTextureSpaceMatrix()
+{
+ m_textureSpaceMatrix.makeIdentity();
+
+ switch (m_orientation) {
+ case OriginRightTop:
+ m_textureSpaceMatrix.rotate(-90);
+ m_textureSpaceMatrix.translate(-1, 0);
+ break;
+ case OriginBottomRight:
+ m_textureSpaceMatrix.rotate(180);
+ m_textureSpaceMatrix.translate(-1, -1);
+ break;
+ case OriginLeftBottom:
+ m_textureSpaceMatrix.rotate(-270);
+ m_textureSpaceMatrix.translate(0, -1);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ if (!m_flipY) {
+ m_textureSpaceMatrix.flipY();
+ m_textureSpaceMatrix.translate(0, -1);
+ }
+}
+
+void VideoTextureCopierGStreamer::updateTransformationMatrix()
+{
+ FloatRect targetRect = FloatRect(FloatPoint(), m_size);
+ TransformationMatrix identityMatrix;
+ m_modelViewMatrix = TransformationMatrix(identityMatrix).multiply(TransformationMatrix::rectToRect(FloatRect(0, 0, 1, 1), targetRect));
+
+ // Taken from TextureMapperGL.
+ const float nearValue = 9999999;
+ const float farValue = -99999;
+
+ m_projectionMatrix = TransformationMatrix(2.0 / float(m_size.width()), 0, 0, 0,
+ 0, (-2.0) / float(m_size.height()), 0, 0,
+ 0, 0, -2.f / (farValue - nearValue), 0,
+ -1, 1, -(farValue + nearValue) / (farValue - nearValue), 1);
+}
+
+bool VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture(Platform3DObject inputTexture, IntSize& frameSize, Platform3DObject outputTexture, GC3Denum outputTarget, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool flipY, ImageOrientation& sourceOrientation)
+{
+ if (!m_shaderProgram || !m_framebuffer || !m_vbo || frameSize.isEmpty())
+ return false;
+
+ if (m_size != frameSize) {
+ m_size = frameSize;
+ updateTransformationMatrix();
+ }
+
+ if (m_flipY != flipY || m_orientation != sourceOrientation) {
+ m_flipY = flipY;
+ m_orientation = sourceOrientation;
+ updateTextureSpaceMatrix();
+ }
+
+ // Save previous context and activate the sharing one.
+ GLContext* previousContext = GLContext::current();
+ ASSERT(previousContext);
+ PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->makeContextCurrent();
+
+ // Save previous bound framebuffer, texture and viewport.
+ GC3Dint boundFramebuffer = 0;
+ GC3Dint boundTexture = 0;
+ GC3Dint previousViewport[4] = { 0, 0, 0, 0};
+ m_context3D->getIntegerv(GraphicsContext3D::FRAMEBUFFER_BINDING, &boundFramebuffer);
+ m_context3D->getIntegerv(GraphicsContext3D::TEXTURE_BINDING_2D, &boundTexture);
+ m_context3D->getIntegerv(GraphicsContext3D::VIEWPORT, previousViewport);
+
+ // Set proper parameters to the output texture and allocate uninitialized memory for it.
+ m_context3D->bindTexture(outputTarget, outputTexture);
+ m_context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
+ m_context3D->texParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
+ m_context3D->texParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
+ m_context3D->texImage2DDirect(outputTarget, level, internalFormat, m_size.width(), m_size.height(), 0, format, type, nullptr);
+
+ // Bind framebuffer to paint and attach the destination texture to it.
+ m_context3D->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebuffer);
+ m_context3D->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GL_TEXTURE_2D, outputTexture, 0);
+
+ // Set proper wrap parameter to the source texture.
+ m_context3D->bindTexture(GL_TEXTURE_2D, inputTexture);
+ m_context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
+ m_context3D->texParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
+ m_context3D->texParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
+
+ // Set the viewport.
+ m_context3D->viewport(0, 0, m_size.width(), m_size.height());
+
+ // Set program parameters.
+ m_context3D->useProgram(m_shaderProgram->programID());
+ m_context3D->uniform1i(m_shaderProgram->samplerLocation(), 0);
+ m_shaderProgram->setMatrix(m_shaderProgram->modelViewMatrixLocation(), m_modelViewMatrix);
+ m_shaderProgram->setMatrix(m_shaderProgram->projectionMatrixLocation(), m_projectionMatrix);
+ m_shaderProgram->setMatrix(m_shaderProgram->textureSpaceMatrixLocation(), m_textureSpaceMatrix);
+
+ // Perform the copy.
+ m_context3D->enableVertexAttribArray(m_shaderProgram->vertexLocation());
+ m_context3D->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_vbo);
+ m_context3D->vertexAttribPointer(m_shaderProgram->vertexLocation(), 2, GraphicsContext3D::FLOAT, false, 0, 0);
+ m_context3D->drawArrays(GraphicsContext3D::TRIANGLE_FAN, 0, 4);
+ m_context3D->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, 0);
+ m_context3D->disableVertexAttribArray(m_shaderProgram->vertexLocation());
+ m_context3D->useProgram(0);
+
+ // Restore previous bindings and viewport.
+ m_context3D->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, boundFramebuffer);
+ m_context3D->bindTexture(outputTarget, boundTexture);
+ m_context3D->viewport(previousViewport[0], previousViewport[1], previousViewport[2], previousViewport[3]);
+
+ bool ok = (m_context3D->getError() == GraphicsContext3D::NO_ERROR);
+
+ // Restore previous context.
+ previousContext->makeContextCurrent();
+ return ok;
+}
+
+} // namespace WebCore
+
+#endif // USE(GSTREAMER_GL)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerVideoTextureCopierGStreamerh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.h (0 => 206862)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.h         (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.h        2016-10-06 10:53:28 UTC (rev 206862)
</span><span class="lines">@@ -0,0 +1,59 @@
</span><ins>+/*
+ Copyright (C) 2016 Igalia S.L.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+ */
+
+#ifndef VideoTextureCopierGStreamer_h
+#define VideoTextureCopierGStreamer_h
+
+#if USE(GSTREAMER_GL)
+
+#include "GraphicsContext3D.h"
+#include "TransformationMatrix.h"
+
+namespace WebCore {
+
+class TextureMapperShaderProgram;
+class ImageOrientation;
+
+class VideoTextureCopierGStreamer {
+public:
+ VideoTextureCopierGStreamer();
+ ~VideoTextureCopierGStreamer();
+
+ bool copyVideoTextureToPlatformTexture(Platform3DObject inputTexture, IntSize& frameSize, Platform3DObject outputTexture, GC3Denum outputTarget, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool flipY, ImageOrientation& sourceOrientation);
+ void updateTextureSpaceMatrix();
+ void updateTransformationMatrix();
+
+private:
+ RefPtr<GraphicsContext3D> m_context3D;
+ RefPtr<TextureMapperShaderProgram> m_shaderProgram;
+ Platform3DObject m_framebuffer { 0 };
+ Platform3DObject m_vbo { 0 };
+ bool m_flipY { false };
+ ImageOrientation m_orientation;
+ IntSize m_size;
+ TransformationMatrix m_modelViewMatrix;
+ TransformationMatrix m_projectionMatrix;
+ TransformationMatrix m_textureSpaceMatrix;
+};
+
+} // namespace WebCore
+
+#endif // USE(GSTREAMER_GL)
+
+#endif // VideoTextureCopierGStreamer_h
</ins></span></pre>
</div>
</div>
</body>
</html>