https://bugs.webkit.org/show_bug.cgi?id=172749
Reviewed by Žan Doberšek.
Currently TextureMapperGL is only able to paint properly textures that are in RGBA format. There are
situations where we will want it to be able to handle other formats (for example BGRA for gstreamer-gl).
To make this possible without having to perform the color conversion in the CPU, we add a new color
conversion matrix to TextureMapperShaderProgram. This matrix will perform the color space conversion
in the GPU, just after sampling the source texture.
Also, add a new flag to TextureMapperGL to indicate that a color conversion is required to handle a
texture. This flag will be set to the TextureMapperPlatformLayerBuffers as required, and TextureMapperGL
will set the appropriate color space matrix to the shader. Initially only the flag for BGRA->RGBA conversion
is defined, but support for new transformations can be added as needed.
VideoTextureCopierGStreamer also uses the TextureMapperShaderProgram to perform texture sampling, but for
the moment it just sets an identity matrix because when using gstreamer-gl, the format of the video frames
is RGBA. This will be changed soon to use BGRA.
No new tests.
* platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp:
(WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::colorSpaceMatrixForFlags):
(WebCore::TextureMapperGL::drawTexturedQuadWithProgram):
* platform/graphics/texmap/TextureMapperGL.h:
* platform/graphics/texmap/TextureMapperShaderProgram.cpp:
* platform/graphics/texmap/TextureMapperShaderProgram.h:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217706
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2017-06-02 Miguel Gomez <magomez@igalia.com>
+
+ [GTK+][WPE] Allow TextureMapperShaderProgram to perform colorspace conversions with the source texture pixels
+ https://bugs.webkit.org/show_bug.cgi?id=172749
+
+ Reviewed by Žan Doberšek.
+
+ Currently TextureMapperGL is only able to paint properly textures that are in RGBA format. There are
+ situations where we will want it to be able to handle other formats (for example BGRA for gstreamer-gl).
+ To make this possible without having to perform the color conversion in the CPU, we add a new color
+ conversion matrix to TextureMapperShaderProgram. This matrix will perform the color space conversion
+ in the GPU, just after sampling the source texture.
+
+ Also, add a new flag to TextureMapperGL to indicate that a color conversion is required to handle a
+ texture. This flag will be set to the TextureMapperPlatformLayerBuffers as required, and TextureMapperGL
+ will set the appropriate color space matrix to the shader. Initially only the flag for BGRA->RGBA conversion
+ is defined, but support for new transformations can be added as needed.
+
+ VideoTextureCopierGStreamer also uses the TextureMapperShaderProgram to perform texture sampling, but for
+ the moment it just sets an identity matrix because when using gstreamer-gl, the format of the video frames
+ is RGBA. This will be changed soon to use BGRA.
+
+ No new tests.
+
+ * platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp:
+ (WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
+ * platform/graphics/texmap/TextureMapperGL.cpp:
+ (WebCore::colorSpaceMatrixForFlags):
+ (WebCore::TextureMapperGL::drawTexturedQuadWithProgram):
+ * platform/graphics/texmap/TextureMapperGL.h:
+ * platform/graphics/texmap/TextureMapperShaderProgram.cpp:
+ * platform/graphics/texmap/TextureMapperShaderProgram.h:
+
2017-06-02 Javier Fernandez <jfernandez@igalia.com>
[css-grid] Margin wrong applied when stretching an orthogonal item in fixed size track
m_shaderProgram->setMatrix(m_shaderProgram->modelViewMatrixLocation(), m_modelViewMatrix);
m_shaderProgram->setMatrix(m_shaderProgram->projectionMatrixLocation(), m_projectionMatrix);
m_shaderProgram->setMatrix(m_shaderProgram->textureSpaceMatrixLocation(), m_textureSpaceMatrix);
+ m_shaderProgram->setMatrix(m_shaderProgram->textureColorSpaceMatrixLocation(), TransformationMatrix());
// Perform the copy.
m_context3D->enableVertexAttribArray(m_shaderProgram->vertexLocation());
}
}
+static TransformationMatrix colorSpaceMatrixForFlags(TextureMapperGL::Flags flags)
+{
+ // The matrix is initially the identity one, which means no color conversion.
+ TransformationMatrix matrix;
+ if (flags & TextureMapperGL::ShouldConvertTextureBGRAToRGBA)
+ matrix.setMatrix(0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+
+ return matrix;
+}
+
void TextureMapperGL::drawTexture(const BitmapTexture& texture, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, unsigned exposedEdges)
{
if (!texture.isValid())
patternTransform.translate(0, -1);
program.setMatrix(program.textureSpaceMatrixLocation(), patternTransform);
+ program.setMatrix(program.textureColorSpaceMatrixLocation(), colorSpaceMatrixForFlags(flags));
m_context3D->uniform1f(program.opacityLocation(), opacity);
if (opacity < 1)
ShouldAntialias = 0x08,
ShouldRotateTexture90 = 0x10,
ShouldRotateTexture180 = 0x20,
- ShouldRotateTexture270 = 0x40
+ ShouldRotateTexture270 = 0x40,
+ ShouldConvertTextureBGRAToRGBA = 0x80
};
typedef int Flags;
STRINGIFY(
precision TextureSpaceMatrixPrecision float;
uniform mat4 u_textureSpaceMatrix;
+ uniform mat4 u_textureColorSpaceMatrix;
precision mediump float;
uniform SamplerType s_sampler;
uniform sampler2D s_contentTexture;
void applyManualRepeat(inout vec2 pos) { pos = fract(pos); }
- void applyTexture(inout vec4 color, vec2 texCoord) { color = SamplerFunction(s_sampler, texCoord); }
+ void applyTexture(inout vec4 color, vec2 texCoord) { color = u_textureColorSpaceMatrix * SamplerFunction(s_sampler, texCoord); }
void applyOpacity(inout vec4 color) { color *= u_opacity; }
void applyAntialiasing(inout vec4 color) { color *= antialias(); }
TEXMAP_DECLARE_UNIFORM(modelViewMatrix)
TEXMAP_DECLARE_UNIFORM(projectionMatrix)
TEXMAP_DECLARE_UNIFORM(textureSpaceMatrix)
+ TEXMAP_DECLARE_UNIFORM(textureColorSpaceMatrix)
TEXMAP_DECLARE_UNIFORM(opacity)
TEXMAP_DECLARE_UNIFORM(color)
TEXMAP_DECLARE_UNIFORM(expandedQuadEdgesInScreenSpace)