Title: [220402] trunk/Source/WebCore
Revision
220402
Author
zandober...@gmail.com
Date
2017-08-08 06:29:30 -0700 (Tue, 08 Aug 2017)

Log Message

[GStreamer] Don't use GraphicsContext3D in VideoTextureCoperGStreamer
https://bugs.webkit.org/show_bug.cgi?id=174774

Reviewed by Carlos Garcia Campos.

VideoTextureCoperGStreamer class creates a new GraphicsContext3D internally
that's used to render to whichever OpenGL context is current. Such usage
doesn't add anything to the user since there's no underlying offscreen-based
OpenGL context created, and instead all GraphicsContext3D calls are directly
translated to usual OpenGL API calls. We should avoid using GraphicsContext3D
in such cases and instead use direct OpenGL API calls.

This patch achieves that for the VideoTextureCoperGStreamer class. A
GraphicsContext3D object is still created because it's needed to construct an
instance of the TextureMapperShaderProgram class, but this will be removed as
soon as TextureMapperShaderProgram drops the GraphicsContext3D dependence.

No new tests -- no change in behavior.

* platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp:
(WebCore::VideoTextureCopierGStreamer::VideoTextureCopierGStreamer):
(WebCore::VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer):
(WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
* platform/graphics/gstreamer/VideoTextureCopierGStreamer.h:
(WebCore::VideoTextureCopierGStreamer::resultTexture):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (220401 => 220402)


--- trunk/Source/WebCore/ChangeLog	2017-08-08 13:11:00 UTC (rev 220401)
+++ trunk/Source/WebCore/ChangeLog	2017-08-08 13:29:30 UTC (rev 220402)
@@ -1,5 +1,33 @@
 2017-08-08  Zan Dobersek  <zdober...@igalia.com>
 
+        [GStreamer] Don't use GraphicsContext3D in VideoTextureCoperGStreamer
+        https://bugs.webkit.org/show_bug.cgi?id=174774
+
+        Reviewed by Carlos Garcia Campos.
+
+        VideoTextureCoperGStreamer class creates a new GraphicsContext3D internally
+        that's used to render to whichever OpenGL context is current. Such usage
+        doesn't add anything to the user since there's no underlying offscreen-based
+        OpenGL context created, and instead all GraphicsContext3D calls are directly
+        translated to usual OpenGL API calls. We should avoid using GraphicsContext3D
+        in such cases and instead use direct OpenGL API calls.
+
+        This patch achieves that for the VideoTextureCoperGStreamer class. A
+        GraphicsContext3D object is still created because it's needed to construct an
+        instance of the TextureMapperShaderProgram class, but this will be removed as
+        soon as TextureMapperShaderProgram drops the GraphicsContext3D dependence.
+
+        No new tests -- no change in behavior.
+
+        * platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp:
+        (WebCore::VideoTextureCopierGStreamer::VideoTextureCopierGStreamer):
+        (WebCore::VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer):
+        (WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
+        * platform/graphics/gstreamer/VideoTextureCopierGStreamer.h:
+        (WebCore::VideoTextureCopierGStreamer::resultTexture):
+
+2017-08-08  Zan Dobersek  <zdober...@igalia.com>
+
         [TexMap] Drop GC3D* type usage from TextureMapperPlatformLayer{Buffer,Proxy}
         https://bugs.webkit.org/show_bug.cgi?id=175314
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp (220401 => 220402)


--- trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp	2017-08-08 13:11:00 UTC (rev 220401)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp	2017-08-08 13:29:30 UTC (rev 220402)
@@ -27,6 +27,9 @@
 #include "ImageOrientation.h"
 #include "TextureMapperShaderProgram.h"
 
+// FIXME: Remove after TextureMapperShaderProgram drops GraphicsContext3D usage.
+#include "GraphicsContext3D.h"
+
 namespace WebCore {
 
 VideoTextureCopierGStreamer::VideoTextureCopierGStreamer(ColorConversion colorConversion)
@@ -35,18 +38,19 @@
     ASSERT(previousContext);
     PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->makeContextCurrent();
 
-    m_context3D = GraphicsContext3D::createForCurrentGLContext();
+    {
+        // FIXME: Remove after TextureMapperShaderProgram drops GraphicsContext3D usage.
+        auto context3D = GraphicsContext3D::createForCurrentGLContext();
+        m_shaderProgram = TextureMapperShaderProgram::create(*context3D, TextureMapperShaderProgram::Texture);
+    }
 
-    m_shaderProgram = TextureMapperShaderProgram::create(*m_context3D, TextureMapperShaderProgram::Texture);
+    glGenFramebuffers(1, &m_framebuffer);
+    glGenTextures(1, &m_resultTexture);
 
-    m_framebuffer = m_context3D->createFramebuffer();
-
-    m_resultTexture = m_context3D->createTexture();
-
     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);
+    glGenBuffers(1, &m_vbo);
+    glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
+    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 8, vertices, GL_STATIC_DRAW);
 
     updateColorConversionMatrix(colorConversion);
     updateTextureSpaceMatrix();
@@ -59,11 +63,10 @@
     GLContext* previousContext = GLContext::current();
     PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->makeContextCurrent();
 
-    m_context3D->deleteFramebuffer(m_framebuffer);
-    m_context3D->deleteBuffer(m_vbo);
-    m_context3D->deleteTexture(m_resultTexture);
+    glDeleteFramebuffers(1, &m_framebuffer);
+    glDeleteBuffers(1, &m_vbo);
+    glDeleteTextures(1, &m_resultTexture);
     m_shaderProgram = nullptr;
-    m_context3D = nullptr;
 
     if (previousContext)
         previousContext->makeContextCurrent();
@@ -128,7 +131,7 @@
         -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)
+bool VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture(GLuint inputTexture, IntSize& frameSize, GLuint outputTexture, GLenum outputTarget, GLint level, GLenum internalFormat, GLenum format, GLenum type, bool flipY, ImageOrientation& sourceOrientation)
 {
     if (!m_shaderProgram || !m_framebuffer || !m_vbo || frameSize.isEmpty())
         return false;
@@ -150,12 +153,12 @@
     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);
+    GLint boundFramebuffer = 0;
+    GLint boundTexture = 0;
+    GLint previousViewport[4] = { 0, 0, 0, 0};
+    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &boundFramebuffer);
+    glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTexture);
+    glGetIntegerv(GL_VIEWPORT, previousViewport);
 
     // Use our own output texture if we are not given one.
     if (!outputTexture)
@@ -162,28 +165,28 @@
         outputTexture = m_resultTexture;
 
     // 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);
+    glBindTexture(outputTarget, outputTexture);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    glTexImage2D(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);
+    glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
+    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_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);
+    glBindTexture(GL_TEXTURE_2D, inputTexture);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
     // Set the viewport.
-    m_context3D->viewport(0, 0, m_size.width(), m_size.height());
+    glViewport(0, 0, m_size.width(), m_size.height());
 
     // Set program parameters.
-    m_context3D->useProgram(m_shaderProgram->programID());
-    m_context3D->uniform1i(m_shaderProgram->samplerLocation(), 0);
+    glUseProgram(m_shaderProgram->programID());
+    glUniform1i(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);
@@ -190,20 +193,20 @@
     m_shaderProgram->setMatrix(m_shaderProgram->textureColorSpaceMatrixLocation(), m_colorConversionMatrix);
 
     // 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);
+    glEnableVertexAttribArray(m_shaderProgram->vertexLocation());
+    glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
+    glVertexAttribPointer(m_shaderProgram->vertexLocation(), 2, GL_FLOAT, false, 0, 0);
+    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+    glBindBuffer(GL_ARRAY_BUFFER, 0);
+    glDisableVertexAttribArray(m_shaderProgram->vertexLocation());
+    glUseProgram(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]);
+    glBindFramebuffer(GL_FRAMEBUFFER, boundFramebuffer);
+    glBindTexture(outputTarget, boundTexture);
+    glViewport(previousViewport[0], previousViewport[1], previousViewport[2], previousViewport[3]);
 
-    bool ok = (m_context3D->getError() == GraphicsContext3D::NO_ERROR);
+    bool ok = (glGetError() == GL_NO_ERROR);
 
     // Restore previous context.
     previousContext->makeContextCurrent();

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.h (220401 => 220402)


--- trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.h	2017-08-08 13:11:00 UTC (rev 220401)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.h	2017-08-08 13:29:30 UTC (rev 220402)
@@ -22,8 +22,10 @@
 
 #if USE(GSTREAMER_GL)
 
-#include "GraphicsContext3D.h"
+#include "ImageOrientation.h"
+#include "TextureMapperGLHeaders.h"
 #include "TransformationMatrix.h"
+#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
@@ -40,17 +42,16 @@
     VideoTextureCopierGStreamer(ColorConversion);
     ~VideoTextureCopierGStreamer();
 
-    bool copyVideoTextureToPlatformTexture(Platform3DObject inputTexture, IntSize& frameSize, Platform3DObject outputTexture, GC3Denum outputTarget, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool flipY, ImageOrientation& sourceOrientation);
+    bool copyVideoTextureToPlatformTexture(GLuint inputTexture, IntSize& frameSize, GLuint outputTexture, GLenum outputTarget, GLint level, GLenum internalFormat, GLenum format, GLenum type, bool flipY, ImageOrientation& sourceOrientation);
     void updateColorConversionMatrix(ColorConversion);
     void updateTextureSpaceMatrix();
     void updateTransformationMatrix();
-    Platform3DObject resultTexture() { return m_resultTexture; }
+    GLuint resultTexture() { return m_resultTexture; }
 
 private:
-    RefPtr<GraphicsContext3D> m_context3D;
     RefPtr<TextureMapperShaderProgram> m_shaderProgram;
-    Platform3DObject m_framebuffer { 0 };
-    Platform3DObject m_vbo { 0 };
+    GLuint m_framebuffer { 0 };
+    GLuint m_vbo { 0 };
     bool m_flipY { false };
     ImageOrientation m_orientation;
     IntSize m_size;
@@ -58,7 +59,7 @@
     TransformationMatrix m_projectionMatrix;
     TransformationMatrix m_textureSpaceMatrix;
     TransformationMatrix m_colorConversionMatrix;
-    Platform3DObject m_resultTexture { 0 };
+    GLuint m_resultTexture { 0 };
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to