Skip to content
Permalink
Browse files
[TexMap] Remove GraphicsContext3D usage from TextureMapperShaderProgram
https://bugs.webkit.org/show_bug.cgi?id=175425

Reviewed by Žan Doberšek.

Remove usage of the GraphicsContext3D class in TextureMapperShaderProgram.
Direct OpenGL API calls, types and constants are used instead.

By removing GraphicsContext3D, we don't use ANGLE anymore to perform the
shader adaptation to the used OpenGL/GLES2 version, so we need to do that
inside TextureMapperShaderProgram. The main changes required for this are
adding the #version directive and use in/out to define input/output parameters
when using OpenGL >= 3.2, and defining the default precision only when using
GLES2.

Besides that, now that VideoTextureCopierGStreamer doesn't have its own
GraphicsContext3D, we need to add a VAO to it when using OpenGL >= 3.2.

Based on a previous patch by Žan Doberšek <zdobersek@igalia.com>.

No behavior change.

* platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp:
(WebCore::VideoTextureCopierGStreamer::VideoTextureCopierGStreamer):
(WebCore::VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer):
(WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
* platform/graphics/gstreamer/VideoTextureCopierGStreamer.h:
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGLData::getShaderProgram):
(WebCore::prepareFilterProgram):
(WebCore::TextureMapperGL::drawTexture):
(WebCore::TextureMapperGL::drawFiltered):
* platform/graphics/texmap/TextureMapperShaderProgram.cpp:
(WebCore::TextureMapperShaderProgram::create):
(WebCore::getShaderLog):
(WebCore::getProgramLog):
(WebCore::TextureMapperShaderProgram::TextureMapperShaderProgram):
(WebCore::TextureMapperShaderProgram::~TextureMapperShaderProgram):
(WebCore::TextureMapperShaderProgram::setMatrix):
(WebCore::TextureMapperShaderProgram::getLocation):
* platform/graphics/texmap/TextureMapperShaderProgram.h:
(WebCore::TextureMapperShaderProgram::programID const):


Canonical link: https://commits.webkit.org/194829@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223833 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
magomez committed Oct 23, 2017
1 parent 722425c commit 13a1302bd717598edec69d8406f5f926dadea636
@@ -1,3 +1,48 @@
2017-10-23 Miguel Gomez <magomez@igalia.com>

[TexMap] Remove GraphicsContext3D usage from TextureMapperShaderProgram
https://bugs.webkit.org/show_bug.cgi?id=175425

Reviewed by Žan Doberšek.

Remove usage of the GraphicsContext3D class in TextureMapperShaderProgram.
Direct OpenGL API calls, types and constants are used instead.

By removing GraphicsContext3D, we don't use ANGLE anymore to perform the
shader adaptation to the used OpenGL/GLES2 version, so we need to do that
inside TextureMapperShaderProgram. The main changes required for this are
adding the #version directive and use in/out to define input/output parameters
when using OpenGL >= 3.2, and defining the default precision only when using
GLES2.

Besides that, now that VideoTextureCopierGStreamer doesn't have its own
GraphicsContext3D, we need to add a VAO to it when using OpenGL >= 3.2.

Based on a previous patch by Žan Doberšek <zdobersek@igalia.com>.

No behavior change.

* platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp:
(WebCore::VideoTextureCopierGStreamer::VideoTextureCopierGStreamer):
(WebCore::VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer):
(WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
* platform/graphics/gstreamer/VideoTextureCopierGStreamer.h:
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGLData::getShaderProgram):
(WebCore::prepareFilterProgram):
(WebCore::TextureMapperGL::drawTexture):
(WebCore::TextureMapperGL::drawFiltered):
* platform/graphics/texmap/TextureMapperShaderProgram.cpp:
(WebCore::TextureMapperShaderProgram::create):
(WebCore::getShaderLog):
(WebCore::getProgramLog):
(WebCore::TextureMapperShaderProgram::TextureMapperShaderProgram):
(WebCore::TextureMapperShaderProgram::~TextureMapperShaderProgram):
(WebCore::TextureMapperShaderProgram::setMatrix):
(WebCore::TextureMapperShaderProgram::getLocation):
* platform/graphics/texmap/TextureMapperShaderProgram.h:
(WebCore::TextureMapperShaderProgram::programID const):

2017-10-22 Sam Weinig <sam@webkit.org>

[Settings] Replace current Settings generation with template file based approach
@@ -27,9 +27,6 @@
#include "ImageOrientation.h"
#include "TextureMapperShaderProgram.h"

// FIXME: Remove after TextureMapperShaderProgram drops GraphicsContext3D usage.
#include "GraphicsContext3D.h"

namespace WebCore {

VideoTextureCopierGStreamer::VideoTextureCopierGStreamer(ColorConversion colorConversion)
@@ -38,15 +35,17 @@ VideoTextureCopierGStreamer::VideoTextureCopierGStreamer(ColorConversion colorCo
ASSERT(previousContext);
PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->makeContextCurrent();

{
// FIXME: Remove after TextureMapperShaderProgram drops GraphicsContext3D usage.
auto context3D = GraphicsContext3D::createForCurrentGLContext();
m_shaderProgram = TextureMapperShaderProgram::create(*context3D, TextureMapperShaderProgram::Texture);
}
m_shaderProgram = TextureMapperShaderProgram::create(TextureMapperShaderProgram::Texture);

glGenFramebuffers(1, &m_framebuffer);
glGenTextures(1, &m_resultTexture);

#if !USE(OPENGL_ES_2)
// For OpenGL > 3.2 we need to have a VAO.
if (GLContext::current()->version() >= 320)
glGenVertexArrays(1, &m_vao);
#endif

static const GLfloat vertices[] = { 0, 0, 1, 0, 1, 1, 0, 1 };
glGenBuffers(1, &m_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
@@ -66,6 +65,10 @@ VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer()
glDeleteFramebuffers(1, &m_framebuffer);
glDeleteBuffers(1, &m_vbo);
glDeleteTextures(1, &m_resultTexture);
#if !USE(OPENGL_ES_2)
if (m_vao)
glDeleteVertexArrays(1, &m_vao);
#endif
m_shaderProgram = nullptr;

if (previousContext)
@@ -193,6 +196,10 @@ bool VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture(GLuint input
m_shaderProgram->setMatrix(m_shaderProgram->textureColorSpaceMatrixLocation(), m_colorConversionMatrix);

// Perform the copy.
#if !USE(OPENGL_ES_2)
if (GLContext::current()->version() >= 320 && m_vao)
glBindVertexArray(m_vao);
#endif
glEnableVertexAttribArray(m_shaderProgram->vertexLocation());
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
glVertexAttribPointer(m_shaderProgram->vertexLocation(), 2, GL_FLOAT, false, 0, 0);
@@ -52,6 +52,9 @@ class VideoTextureCopierGStreamer {
RefPtr<TextureMapperShaderProgram> m_shaderProgram;
GLuint m_framebuffer { 0 };
GLuint m_vbo { 0 };
#if !USE(OPENGL_ES_2)
GLuint m_vao { 0 };
#endif
bool m_flipY { false };
ImageOrientation m_orientation;
IntSize m_size;
@@ -158,7 +158,7 @@ Platform3DObject TextureMapperGLData::getStaticVBO(GC3Denum target, GC3Dsizeiptr
Ref<TextureMapperShaderProgram> TextureMapperGLData::getShaderProgram(TextureMapperShaderProgram::Options options)
{
auto addResult = m_sharedGLData->m_programs.ensure(options,
[this, options] { return TextureMapperShaderProgram::create(Ref<GraphicsContext3D>(m_context), options); });
[this, options] { return TextureMapperShaderProgram::create(options); });
return *addResult.iterator->value;
}

@@ -352,9 +352,8 @@ static float* gaussianKernel()
return kernel;
}

static void prepareFilterProgram(TextureMapperShaderProgram& program, const FilterOperation& operation, unsigned pass, const IntSize& size, GC3Duint contentTexture)
static void prepareFilterProgram(GraphicsContext3D* context, TextureMapperShaderProgram& program, const FilterOperation& operation, unsigned pass, const IntSize& size, GC3Duint contentTexture)
{
Ref<GraphicsContext3D> context = program.context();
context->useProgram(program.programID());

switch (operation.type()) {
@@ -474,7 +473,7 @@ void TextureMapperGL::drawTexture(Platform3DObject texture, Flags flags, const I
Ref<TextureMapperShaderProgram> program = data().getShaderProgram(options);

if (filter)
prepareFilterProgram(program.get(), *filter.get(), data().filterInfo->pass, textureSize, filterContentTextureID);
prepareFilterProgram(m_context3D.get(), program.get(), *filter.get(), data().filterInfo->pass, textureSize, filterContentTextureID);

drawTexturedQuadWithProgram(program.get(), texture, flags, textureSize, targetRect, modelViewMatrix, opacity);
}
@@ -626,7 +625,7 @@ void TextureMapperGL::drawFiltered(const BitmapTexture& sampler, const BitmapTex
TextureMapperShaderProgram::Options options = optionsForFilterType(filter.type(), pass);
Ref<TextureMapperShaderProgram> program = data().getShaderProgram(options);

prepareFilterProgram(program.get(), filter, pass, sampler.contentSize(), contentTexture ? static_cast<const BitmapTextureGL*>(contentTexture)->id() : 0);
prepareFilterProgram(m_context3D.get(), program.get(), filter, pass, sampler.contentSize(), contentTexture ? static_cast<const BitmapTextureGL*>(contentTexture)->id() : 0);
FloatRect targetRect(IntPoint::zero(), sampler.contentSize());
drawTexturedQuadWithProgram(program.get(), static_cast<const BitmapTextureGL&>(sampler).id(), 0, IntSize(1, 1), targetRect, TransformationMatrix(), 1);
}

0 comments on commit 13a1302

Please sign in to comment.