Changeset 223833 in webkit
- Timestamp:
- Oct 23, 2017 3:11:12 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r223828 r223833 1 2017-10-23 Miguel Gomez <magomez@igalia.com> 2 3 [TexMap] Remove GraphicsContext3D usage from TextureMapperShaderProgram 4 https://bugs.webkit.org/show_bug.cgi?id=175425 5 6 Reviewed by Žan Doberšek. 7 8 Remove usage of the GraphicsContext3D class in TextureMapperShaderProgram. 9 Direct OpenGL API calls, types and constants are used instead. 10 11 By removing GraphicsContext3D, we don't use ANGLE anymore to perform the 12 shader adaptation to the used OpenGL/GLES2 version, so we need to do that 13 inside TextureMapperShaderProgram. The main changes required for this are 14 adding the #version directive and use in/out to define input/output parameters 15 when using OpenGL >= 3.2, and defining the default precision only when using 16 GLES2. 17 18 Besides that, now that VideoTextureCopierGStreamer doesn't have its own 19 GraphicsContext3D, we need to add a VAO to it when using OpenGL >= 3.2. 20 21 Based on a previous patch by Žan Doberšek <zdobersek@igalia.com>. 22 23 No behavior change. 24 25 * platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp: 26 (WebCore::VideoTextureCopierGStreamer::VideoTextureCopierGStreamer): 27 (WebCore::VideoTextureCopierGStreamer::~VideoTextureCopierGStreamer): 28 (WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture): 29 * platform/graphics/gstreamer/VideoTextureCopierGStreamer.h: 30 * platform/graphics/texmap/TextureMapperGL.cpp: 31 (WebCore::TextureMapperGLData::getShaderProgram): 32 (WebCore::prepareFilterProgram): 33 (WebCore::TextureMapperGL::drawTexture): 34 (WebCore::TextureMapperGL::drawFiltered): 35 * platform/graphics/texmap/TextureMapperShaderProgram.cpp: 36 (WebCore::TextureMapperShaderProgram::create): 37 (WebCore::getShaderLog): 38 (WebCore::getProgramLog): 39 (WebCore::TextureMapperShaderProgram::TextureMapperShaderProgram): 40 (WebCore::TextureMapperShaderProgram::~TextureMapperShaderProgram): 41 (WebCore::TextureMapperShaderProgram::setMatrix): 42 (WebCore::TextureMapperShaderProgram::getLocation): 43 * platform/graphics/texmap/TextureMapperShaderProgram.h: 44 (WebCore::TextureMapperShaderProgram::programID const): 45 1 46 2017-10-22 Sam Weinig <sam@webkit.org> 2 47 -
trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp
r220402 r223833 28 28 #include "TextureMapperShaderProgram.h" 29 29 30 // FIXME: Remove after TextureMapperShaderProgram drops GraphicsContext3D usage.31 #include "GraphicsContext3D.h"32 33 30 namespace WebCore { 34 31 … … 39 36 PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->makeContextCurrent(); 40 37 41 { 42 // FIXME: Remove after TextureMapperShaderProgram drops GraphicsContext3D usage. 43 auto context3D = GraphicsContext3D::createForCurrentGLContext(); 44 m_shaderProgram = TextureMapperShaderProgram::create(*context3D, TextureMapperShaderProgram::Texture); 45 } 38 m_shaderProgram = TextureMapperShaderProgram::create(TextureMapperShaderProgram::Texture); 46 39 47 40 glGenFramebuffers(1, &m_framebuffer); 48 41 glGenTextures(1, &m_resultTexture); 42 43 #if !USE(OPENGL_ES_2) 44 // For OpenGL > 3.2 we need to have a VAO. 45 if (GLContext::current()->version() >= 320) 46 glGenVertexArrays(1, &m_vao); 47 #endif 49 48 50 49 static const GLfloat vertices[] = { 0, 0, 1, 0, 1, 1, 0, 1 }; … … 67 66 glDeleteBuffers(1, &m_vbo); 68 67 glDeleteTextures(1, &m_resultTexture); 68 #if !USE(OPENGL_ES_2) 69 if (m_vao) 70 glDeleteVertexArrays(1, &m_vao); 71 #endif 69 72 m_shaderProgram = nullptr; 70 73 … … 194 197 195 198 // Perform the copy. 199 #if !USE(OPENGL_ES_2) 200 if (GLContext::current()->version() >= 320 && m_vao) 201 glBindVertexArray(m_vao); 202 #endif 196 203 glEnableVertexAttribArray(m_shaderProgram->vertexLocation()); 197 204 glBindBuffer(GL_ARRAY_BUFFER, m_vbo); -
trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.h
r220402 r223833 53 53 GLuint m_framebuffer { 0 }; 54 54 GLuint m_vbo { 0 }; 55 #if !USE(OPENGL_ES_2) 56 GLuint m_vao { 0 }; 57 #endif 55 58 bool m_flipY { false }; 56 59 ImageOrientation m_orientation; -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
r220699 r223833 159 159 { 160 160 auto addResult = m_sharedGLData->m_programs.ensure(options, 161 [this, options] { return TextureMapperShaderProgram::create( Ref<GraphicsContext3D>(m_context),options); });161 [this, options] { return TextureMapperShaderProgram::create(options); }); 162 162 return *addResult.iterator->value; 163 163 } … … 353 353 } 354 354 355 static void prepareFilterProgram(TextureMapperShaderProgram& program, const FilterOperation& operation, unsigned pass, const IntSize& size, GC3Duint contentTexture) 356 { 357 Ref<GraphicsContext3D> context = program.context(); 355 static void prepareFilterProgram(GraphicsContext3D* context, TextureMapperShaderProgram& program, const FilterOperation& operation, unsigned pass, const IntSize& size, GC3Duint contentTexture) 356 { 358 357 context->useProgram(program.programID()); 359 358 … … 475 474 476 475 if (filter) 477 prepareFilterProgram( program.get(), *filter.get(), data().filterInfo->pass, textureSize, filterContentTextureID);476 prepareFilterProgram(m_context3D.get(), program.get(), *filter.get(), data().filterInfo->pass, textureSize, filterContentTextureID); 478 477 479 478 drawTexturedQuadWithProgram(program.get(), texture, flags, textureSize, targetRect, modelViewMatrix, opacity); … … 627 626 Ref<TextureMapperShaderProgram> program = data().getShaderProgram(options); 628 627 629 prepareFilterProgram( program.get(), filter, pass, sampler.contentSize(), contentTexture ? static_cast<const BitmapTextureGL*>(contentTexture)->id() : 0);628 prepareFilterProgram(m_context3D.get(), program.get(), filter, pass, sampler.contentSize(), contentTexture ? static_cast<const BitmapTextureGL*>(contentTexture)->id() : 0); 630 629 FloatRect targetRect(IntPoint::zero(), sampler.contentSize()); 631 630 drawTexturedQuadWithProgram(program.get(), static_cast<const BitmapTextureGL&>(sampler).id(), 0, IntSize(1, 1), targetRect, TransformationMatrix(), 1); -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp
r217706 r223833 25 25 #if USE(TEXTURE_MAPPER_GL) 26 26 27 #include "GLContext.h" 27 28 #include "Logging.h" 28 29 #include "TextureMapperGL.h" … … 51 52 GLSL_DIRECTIVE(endif) 52 53 53 static const char* vertexTemplate = 54 55 // Input/output variables definition for both GLES and OpenGL < 3.2. 56 // The default precision directive is only needed for GLES. 57 static const char* vertexTemplateLT320Vars = 58 #if USE(OPENGL_ES_2) 54 59 TEXTURE_SPACE_MATRIX_PRECISION_DIRECTIVE 55 STRINGIFY( 60 #endif 61 STRINGIFY( 62 #if USE(OPENGL_ES_2) 56 63 precision TextureSpaceMatrixPrecision float; 64 #endif 57 65 attribute vec4 a_vertex; 66 varying vec2 v_texCoord; 67 varying vec2 v_transformedTexCoord; 68 varying float v_antialias; 69 ); 70 71 // Input/output variables definition for OpenGL >= 3.2. 72 static const char* vertexTemplateGE320Vars = 73 STRINGIFY( 74 in vec4 a_vertex; 75 out vec2 v_texCoord; 76 out vec2 v_transformedTexCoord; 77 out float v_antialias; 78 ); 79 80 static const char* vertexTemplateCommon = 81 STRINGIFY( 58 82 uniform mat4 u_modelViewMatrix; 59 83 uniform mat4 u_projectionMatrix; 60 84 uniform mat4 u_textureSpaceMatrix; 61 62 varying vec2 v_texCoord;63 varying vec2 v_transformedTexCoord;64 varying float v_antialias;65 85 66 86 void noop(inout vec2 dummyParameter) { } … … 137 157 138 158 139 static const char* fragmentTemplate = 159 // Common header for all versions. We define the matrices variables here to keep the precision 160 // directives scope: the first one applies to the matrices variables and the next one to the 161 // rest of them. The precision is only used in GLES. 162 static const char* fragmentTemplateHeaderCommon = 140 163 RECT_TEXTURE_DIRECTIVE 141 164 ANTIALIASING_TEX_COORD_DIRECTIVE 142 165 BLUR_CONSTANTS 166 #if USE(OPENGL_ES_2) 143 167 TEXTURE_SPACE_MATRIX_PRECISION_DIRECTIVE 144 STRINGIFY( 168 #endif 169 STRINGIFY( 170 #if USE(OPENGL_ES_2) 145 171 precision TextureSpaceMatrixPrecision float; 172 #endif 146 173 uniform mat4 u_textureSpaceMatrix; 147 174 uniform mat4 u_textureColorSpaceMatrix; 175 #if USE(OPENGL_ES_2) 148 176 precision mediump float; 177 #endif 178 ); 179 180 // Input/output variables definition for both GLES and OpenGL < 3.2. 181 static const char* fragmentTemplateLT320Vars = 182 STRINGIFY( 183 varying float v_antialias; 184 varying vec2 v_texCoord; 185 varying vec2 v_transformedTexCoord; 186 ); 187 188 // Input/output variables definition for OpenGL >= 3.2. 189 static const char* fragmentTemplateGE320Vars = 190 STRINGIFY( 191 in float v_antialias; 192 in vec2 v_texCoord; 193 in vec2 v_transformedTexCoord; 194 ); 195 196 static const char* fragmentTemplateCommon = 197 STRINGIFY( 149 198 uniform SamplerType s_sampler; 150 199 uniform sampler2D s_contentTexture; 151 200 uniform float u_opacity; 152 varying float v_antialias;153 varying vec2 v_texCoord;154 varying vec2 v_transformedTexCoord;155 201 uniform float u_filterAmount; 156 202 uniform vec2 u_blurRadius; … … 306 352 ); 307 353 308 Ref<TextureMapperShaderProgram> TextureMapperShaderProgram::create( Ref<GraphicsContext3D>&& context,TextureMapperShaderProgram::Options options)354 Ref<TextureMapperShaderProgram> TextureMapperShaderProgram::create(TextureMapperShaderProgram::Options options) 309 355 { 310 356 #define SET_APPLIER_FROM_OPTIONS(Applier) \ … … 331 377 SET_APPLIER_FROM_OPTIONS(ManualRepeat); 332 378 379 unsigned glVersion = GLContext::current()->version(); 333 380 StringBuilder vertexShaderBuilder; 381 382 // OpenGL >= 3.2 requires a #version directive at the beginning of the code. 383 #if !USE(OPENGL_ES_2) 384 if (glVersion >= 320) 385 vertexShaderBuilder.append(GLSL_DIRECTIVE(version 150)); 386 #endif 387 388 // Append the options. 334 389 vertexShaderBuilder.append(optionsApplierBuilder.toString()); 335 vertexShaderBuilder.append(vertexTemplate); 390 391 // Append the appropriate input/output variable definitions. 392 #if USE(OPENGL_ES_2) 393 vertexShaderBuilder.append(vertexTemplateLT320Vars); 394 #else 395 if (glVersion >= 320) 396 vertexShaderBuilder.append(vertexTemplateGE320Vars); 397 else 398 vertexShaderBuilder.append(vertexTemplateLT320Vars); 399 #endif 400 401 // Append the common code. 402 vertexShaderBuilder.append(vertexTemplateCommon); 336 403 337 404 StringBuilder fragmentShaderBuilder; 405 406 // OpenGL >= 3.2 requires a #version directive at the beginning of the code. 407 #if !USE(OPENGL_ES_2) 408 if (glVersion >= 320) 409 fragmentShaderBuilder.append(GLSL_DIRECTIVE(version 150)); 410 #endif 411 412 // Append the options. 338 413 fragmentShaderBuilder.append(optionsApplierBuilder.toString()); 339 fragmentShaderBuilder.append(fragmentTemplate); 340 341 return adoptRef(*new TextureMapperShaderProgram(WTFMove(context), vertexShaderBuilder.toString(), fragmentShaderBuilder.toString())); 342 } 343 344 TextureMapperShaderProgram::TextureMapperShaderProgram(Ref<GraphicsContext3D>&& context, const String& vertex, const String& fragment) 345 : m_context(WTFMove(context)) 346 { 347 m_vertexShader = m_context->createShader(GraphicsContext3D::VERTEX_SHADER); 348 m_context->shaderSource(m_vertexShader, vertex); 349 350 m_fragmentShader = m_context->createShader(GraphicsContext3D::FRAGMENT_SHADER); 351 m_context->shaderSource(m_fragmentShader, fragment); 352 353 m_id = m_context->createProgram(); 354 m_context->compileShader(m_vertexShader); 355 m_context->compileShader(m_fragmentShader); 356 m_context->attachShader(m_id, m_vertexShader); 357 m_context->attachShader(m_id, m_fragmentShader); 358 m_context->linkProgram(m_id); 359 360 if (!compositingLogEnabled()) 414 415 // Append the common header. 416 fragmentShaderBuilder.append(fragmentTemplateHeaderCommon); 417 418 // Append the appropriate input/output variable definitions. 419 #if USE(OPENGL_ES_2) 420 fragmentShaderBuilder.append(fragmentTemplateLT320Vars); 421 #else 422 if (glVersion >= 320) 423 fragmentShaderBuilder.append(fragmentTemplateGE320Vars); 424 else 425 fragmentShaderBuilder.append(fragmentTemplateLT320Vars); 426 #endif 427 428 // Append the common code. 429 fragmentShaderBuilder.append(fragmentTemplateCommon); 430 431 return adoptRef(*new TextureMapperShaderProgram(vertexShaderBuilder.toString(), fragmentShaderBuilder.toString())); 432 } 433 434 #if !LOG_DISABLED 435 static CString getShaderLog(GLuint shader) 436 { 437 GLint logLength = 0; 438 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); 439 if (!logLength) 440 return { }; 441 442 auto info = std::make_unique<GLchar[]>(logLength); 443 GLsizei infoLength = 0; 444 glGetShaderInfoLog(shader, logLength, &infoLength, info.get()); 445 446 size_t stringLength = std::max(infoLength, 0); 447 return { info.get(), stringLength }; 448 } 449 450 static CString getProgramLog(GLuint program) 451 { 452 GLint logLength = 0; 453 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); 454 if (!logLength) 455 return { }; 456 457 auto info = std::make_unique<GLchar[]>(logLength); 458 GLsizei infoLength = 0; 459 glGetProgramInfoLog(program, logLength, &infoLength, info.get()); 460 461 size_t stringLength = std::max(infoLength, 0); 462 return { info.get(), stringLength }; 463 } 464 #endif 465 466 TextureMapperShaderProgram::TextureMapperShaderProgram(const String& vertex, const String& fragment) 467 { 468 m_vertexShader = glCreateShader(GL_VERTEX_SHADER); 469 { 470 CString vertexCString = vertex.utf8(); 471 const char* data = vertexCString.data(); 472 int length = vertexCString.length(); 473 glShaderSource(m_vertexShader, 1, &data, &length); 474 } 475 glCompileShader(m_vertexShader); 476 477 m_fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); 478 { 479 CString fragmentCString = fragment.utf8(); 480 const char* data = fragmentCString.data(); 481 int length = fragmentCString.length(); 482 glShaderSource(m_fragmentShader, 1, &data, &length); 483 } 484 glCompileShader(m_fragmentShader); 485 486 m_id = glCreateProgram(); 487 glAttachShader(m_id, m_vertexShader); 488 glAttachShader(m_id, m_fragmentShader); 489 glLinkProgram(m_id); 490 491 if (!compositingLogEnabled() || glGetError() == GL_NO_ERROR) 361 492 return; 362 493 363 if (m_context->getError() == GraphicsContext3D::NO_ERROR) 364 return; 365 366 String log = m_context->getShaderInfoLog(m_vertexShader); 367 LOG(Compositing, "Vertex shader log: %s\n", log.utf8().data()); 368 log = m_context->getShaderInfoLog(m_fragmentShader); 369 LOG(Compositing, "Fragment shader log: %s\n", log.utf8().data()); 370 log = m_context->getProgramInfoLog(m_id); 371 LOG(Compositing, "Program log: %s\n", log.utf8().data()); 494 LOG(Compositing, "Vertex shader log: %s\n", getShaderLog(m_vertexShader).data()); 495 LOG(Compositing, "Fragment shader log: %s\n", getShaderLog(m_fragmentShader).data()); 496 LOG(Compositing, "Program log: %s\n", getProgramLog(m_id).data()); 372 497 } 373 498 … … 377 502 return; 378 503 379 m_context->detachShader(m_id, m_vertexShader);380 m_context->deleteShader(m_vertexShader);381 m_context->detachShader(m_id, m_fragmentShader);382 m_context->deleteShader(m_fragmentShader);383 m_context->deleteProgram(m_id);384 } 385 386 void TextureMapperShaderProgram::setMatrix(G C3Duint location, const TransformationMatrix& matrix)504 glDetachShader(m_id, m_vertexShader); 505 glDeleteShader(m_vertexShader); 506 glDetachShader(m_id, m_fragmentShader); 507 glDeleteShader(m_fragmentShader); 508 glDeleteProgram(m_id); 509 } 510 511 void TextureMapperShaderProgram::setMatrix(GLuint location, const TransformationMatrix& matrix) 387 512 { 388 513 TransformationMatrix::FloatMatrix4 floatMatrix; 389 514 matrix.toColumnMajorFloatArray(floatMatrix); 390 m_context->uniformMatrix4fv(location, 1, false, floatMatrix);391 } 392 393 G C3Duint TextureMapperShaderProgram::getLocation(const AtomicString& name, VariableType type)515 glUniformMatrix4fv(location, 1, false, floatMatrix); 516 } 517 518 GLuint TextureMapperShaderProgram::getLocation(const AtomicString& name, VariableType type) 394 519 { 395 520 auto addResult = m_variables.ensure(name, 396 521 [this, &name, type] { 522 CString nameCString = name.string().utf8(); 397 523 switch (type) { 398 524 case UniformVariable: 399 return m_context->getUniformLocation(m_id, name);525 return glGetUniformLocation(m_id, nameCString.data()); 400 526 case AttribVariable: 401 return m_context->getAttribLocation(m_id, name);527 return glGetAttribLocation(m_id, nameCString.data()); 402 528 } 403 529 ASSERT_NOT_REACHED(); -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h
r217706 r223833 24 24 #if USE(TEXTURE_MAPPER_GL) 25 25 26 #include " GraphicsContext3D.h"26 #include "TextureMapperGLHeaders.h" 27 27 #include "TransformationMatrix.h" 28 28 #include <wtf/HashMap.h> … … 34 34 35 35 #define TEXMAP_DECLARE_VARIABLE(Accessor, Name, Type) \ 36 G C3Duint Accessor##Location() { \36 GLuint Accessor##Location() { \ 37 37 static NeverDestroyed<const AtomicString> name(Name, AtomicString::ConstructFromLiteral); \ 38 38 return getLocation(name.get(), Type); \ … … 67 67 typedef unsigned Options; 68 68 69 static Ref<TextureMapperShaderProgram> create( Ref<GraphicsContext3D>&&,Options);69 static Ref<TextureMapperShaderProgram> create(Options); 70 70 virtual ~TextureMapperShaderProgram(); 71 71 72 Platform3DObject programID() const { return m_id; } 73 GraphicsContext3D& context() { return m_context; } 72 GLuint programID() const { return m_id; } 74 73 75 74 TEXMAP_DECLARE_ATTRIBUTE(vertex) … … 91 90 TEXMAP_DECLARE_SAMPLER(contentTexture) 92 91 93 void setMatrix(G C3Duint, const TransformationMatrix&);92 void setMatrix(GLuint, const TransformationMatrix&); 94 93 95 94 private: 96 TextureMapperShaderProgram( Ref<GraphicsContext3D>&&,const String& vertexShaderSource, const String& fragmentShaderSource);95 TextureMapperShaderProgram(const String& vertexShaderSource, const String& fragmentShaderSource); 97 96 98 Platform3DObject m_vertexShader;99 Platform3DObject m_fragmentShader;97 GLuint m_vertexShader; 98 GLuint m_fragmentShader; 100 99 101 100 enum VariableType { UniformVariable, AttribVariable }; 102 G C3Duint getLocation(const AtomicString&, VariableType);101 GLuint getLocation(const AtomicString&, VariableType); 103 102 104 Ref<GraphicsContext3D> m_context; 105 Platform3DObject m_id; 106 HashMap<AtomicString, GC3Duint> m_variables; 103 GLuint m_id; 104 HashMap<AtomicString, GLuint> m_variables; 107 105 }; 108 106
Note: See TracChangeset
for help on using the changeset viewer.