Title: [279938] trunk/Source/WebCore
Revision
279938
Author
[email protected]
Date
2021-07-15 01:08:24 -0700 (Thu, 15 Jul 2021)

Log Message

[GStreamer][GL] A420 compositing support
https://bugs.webkit.org/show_bug.cgi?id=227953

Reviewed by Xabier Rodriguez-Calvar.

A420 is YUV+alpha in a separate component. vp9dec outputs this format for assets encoded
with alpha support. Our GL sink now supports this format and lets the TextureMapper handle the
final conversion to RGBA.

* platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp:
* platform/graphics/gstreamer/GStreamerVideoFrameHolder.cpp:
(WebCore::GstVideoFrameHolder::platformLayerBuffer):
* platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp:
(WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::drawTexturePlanarYUV):
* platform/graphics/texmap/TextureMapperGL.h:
* platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
(WebCore::TextureMapperPlatformLayerBuffer::paintToTextureMapper):
* platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h:
* platform/graphics/texmap/TextureMapperShaderProgram.cpp:
(WebCore::TextureMapperShaderProgram::create):
* platform/graphics/texmap/TextureMapperShaderProgram.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (279937 => 279938)


--- trunk/Source/WebCore/ChangeLog	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/ChangeLog	2021-07-15 08:08:24 UTC (rev 279938)
@@ -1,3 +1,29 @@
+2021-07-15  Philippe Normand  <[email protected]> and Miguel Gomez  <[email protected]>
+
+        [GStreamer][GL] A420 compositing support
+        https://bugs.webkit.org/show_bug.cgi?id=227953
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        A420 is YUV+alpha in a separate component. vp9dec outputs this format for assets encoded
+        with alpha support. Our GL sink now supports this format and lets the TextureMapper handle the
+        final conversion to RGBA.
+
+        * platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp:
+        * platform/graphics/gstreamer/GStreamerVideoFrameHolder.cpp:
+        (WebCore::GstVideoFrameHolder::platformLayerBuffer):
+        * platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp:
+        (WebCore::VideoTextureCopierGStreamer::copyVideoTextureToPlatformTexture):
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGL::drawTexturePlanarYUV):
+        * platform/graphics/texmap/TextureMapperGL.h:
+        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
+        (WebCore::TextureMapperPlatformLayerBuffer::paintToTextureMapper):
+        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h:
+        * platform/graphics/texmap/TextureMapperShaderProgram.cpp:
+        (WebCore::TextureMapperShaderProgram::create):
+        * platform/graphics/texmap/TextureMapperShaderProgram.h:
+
 2021-07-14  Alex Christensen  <[email protected]>
 
         Link against Catalyst ANGLE-shared.dylib when linking Catalyst WebCore.framework

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp (279937 => 279938)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp	2021-07-15 08:08:24 UTC (rev 279938)
@@ -51,7 +51,7 @@
 GST_DEBUG_CATEGORY_STATIC(webkit_gl_video_sink_debug);
 #define GST_CAT_DEFAULT webkit_gl_video_sink_debug
 
-#define GST_GL_CAPS_FORMAT "{ RGBx, RGBA, I420, Y444, YV12, Y41B, Y42B, NV12, NV21, VUYA }"
+#define GST_GL_CAPS_FORMAT "{ A420, RGBx, RGBA, I420, Y444, YV12, Y41B, Y42B, NV12, NV21, VUYA }"
 static GstStaticPadTemplate sinkTemplate = GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY);
 
 #define webkit_gl_video_sink_parent_class parent_class

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.cpp (279937 => 279938)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.cpp	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.cpp	2021-07-15 08:08:24 UTC (rev 279938)
@@ -182,7 +182,7 @@
         return makeUnique<Buffer>(Buffer::TextureVariant { Buffer::RGBTexture { m_textureID } }, m_size, m_flags, GL_RGBA);
 
     if (GST_VIDEO_INFO_IS_YUV(&m_videoFrame.info)) {
-        if (GST_VIDEO_INFO_N_COMPONENTS(&m_videoFrame.info) < 3 || GST_VIDEO_INFO_N_PLANES(&m_videoFrame.info) > 3)
+        if (GST_VIDEO_INFO_N_COMPONENTS(&m_videoFrame.info) < 3 || GST_VIDEO_INFO_N_PLANES(&m_videoFrame.info) > 4)
             return nullptr;
 
         if (m_videoDecoderPlatform && *m_videoDecoderPlatform == GstVideoDecoderPlatform::ImxVPU) {
@@ -193,12 +193,12 @@
         }
 
         unsigned numberOfPlanes = GST_VIDEO_INFO_N_PLANES(&m_videoFrame.info);
-        std::array<GLuint, 3> planes;
-        std::array<unsigned, 3> yuvPlane;
-        std::array<unsigned, 3> yuvPlaneOffset;
+        std::array<GLuint, 4> planes;
+        std::array<unsigned, 4> yuvPlane;
+        std::array<unsigned, 4> yuvPlaneOffset;
         for (unsigned i = 0; i < numberOfPlanes; ++i)
             planes[i] = *static_cast<GLuint*>(m_videoFrame.data[i]);
-        for (unsigned i = 0; i < 3; ++i) {
+        for (unsigned i = 0; i < numberOfPlanes; ++i) {
             yuvPlane[i] = GST_VIDEO_INFO_COMP_PLANE(&m_videoFrame.info, i);
             yuvPlaneOffset[i] = GST_VIDEO_INFO_COMP_POFFSET(&m_videoFrame.info, i);
         }
@@ -219,7 +219,7 @@
             };
         }
 
-        return makeUnique<Buffer>( Buffer::TextureVariant { Buffer::YUVTexture { numberOfPlanes, planes, yuvPlane, yuvPlaneOffset, yuvToRgb } }, m_size, m_flags, GL_RGBA);
+        return makeUnique<Buffer>(Buffer::TextureVariant { Buffer::YUVTexture { numberOfPlanes, planes, yuvPlane, yuvPlaneOffset, yuvToRgb } }, m_size, m_flags, GL_RGBA);
     }
 
     return nullptr;

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


--- trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp	2021-07-15 08:08:24 UTC (rev 279938)
@@ -177,6 +177,10 @@
                 ASSERT(!texture.yuvPlaneOffset[0] && !texture.yuvPlaneOffset[1] && !texture.yuvPlaneOffset[2]);
                 options = TextureMapperShaderProgram::TextureYUV;
                 break;
+            case 4:
+                ASSERT(!texture.yuvPlaneOffset[0] && !texture.yuvPlaneOffset[1] && !texture.yuvPlaneOffset[2]);
+                options = TextureMapperShaderProgram::TextureYUVA;
+                break;
             }
         },
         [&](const Buffer::ExternalOESTexture&) {
@@ -246,6 +250,12 @@
                 glUniform1i(m_shaderProgram->samplerULocation(), texture.yuvPlane[1]);
                 glUniform1i(m_shaderProgram->samplerVLocation(), texture.yuvPlane[2]);
                 break;
+            case 4:
+                glUniform1i(m_shaderProgram->samplerYLocation(), texture.yuvPlane[0]);
+                glUniform1i(m_shaderProgram->samplerULocation(), texture.yuvPlane[1]);
+                glUniform1i(m_shaderProgram->samplerVLocation(), texture.yuvPlane[2]);
+                glUniform1i(m_shaderProgram->samplerALocation(), texture.yuvPlane[3]);
+                break;
             }
             glUniformMatrix3fv(m_shaderProgram->yuvToRgbLocation(), 1, GL_FALSE, static_cast<const GLfloat *>(&texture.yuvToRgbMatrix[0]));
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp (279937 => 279938)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2021-07-15 08:08:24 UTC (rev 279938)
@@ -540,7 +540,7 @@
         patternTransform.translate(0, -1);
 }
 
-void TextureMapperGL::drawTexturePlanarYUV(const std::array<GLuint, 3>& textures, const std::array<GLfloat, 9>& yuvToRgbMatrix, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges)
+void TextureMapperGL::drawTexturePlanarYUV(const std::array<GLuint, 3>& textures, const std::array<GLfloat, 9>& yuvToRgbMatrix, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, std::optional<GLuint> alphaPlane, unsigned exposedEdges)
 {
     bool useRect = flags & ShouldUseARBTextureRect;
     bool useAntialiasing = m_enableEdgeDistanceAntialiasing
@@ -547,7 +547,7 @@
         && exposedEdges == AllEdges
         && !modelViewMatrix.mapQuad(targetRect).isRectilinear();
 
-    TextureMapperShaderProgram::Options options = TextureMapperShaderProgram::TextureYUV;
+    TextureMapperShaderProgram::Options options = alphaPlane ? TextureMapperShaderProgram::TextureYUVA : TextureMapperShaderProgram::TextureYUV;
     if (useRect)
         options |= TextureMapperShaderProgram::Rect;
     if (opacity < 1)
@@ -578,6 +578,9 @@
         flags |= ShouldBlend;
     }
 
+    if (flags & ShouldPremultiply)
+        options |= TextureMapperShaderProgram::Premultiply;
+
     Ref<TextureMapperShaderProgram> program = data().getShaderProgram(options);
 
     if (filter)
@@ -592,6 +595,9 @@
         { textures[2], program->samplerVLocation() }
     };
 
+    if (alphaPlane)
+        texturesAndSamplers.append({*alphaPlane, program->samplerALocation() });
+
     glUseProgram(program->programID());
     glUniformMatrix3fv(program->yuvToRgbLocation(), 1, GL_FALSE, static_cast<const GLfloat *>(&yuvToRgbMatrix[0]));
     drawTexturedQuadWithProgram(program.get(), texturesAndSamplers, flags, textureSize, targetRect, modelViewMatrix, opacity);

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h (279937 => 279938)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h	2021-07-15 08:08:24 UTC (rev 279938)
@@ -68,7 +68,7 @@
     void drawNumber(int number, const Color&, const FloatPoint&, const TransformationMatrix&) override;
     void drawTexture(const BitmapTexture&, const FloatRect&, const TransformationMatrix&, float opacity, unsigned exposedEdges) override;
     virtual void drawTexture(GLuint texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges = AllEdges);
-    void drawTexturePlanarYUV(const std::array<GLuint, 3>& textures, const std::array<GLfloat, 9>& yuvToRgbMatrix, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges = AllEdges);
+    void drawTexturePlanarYUV(const std::array<GLuint, 3>& textures, const std::array<GLfloat, 9>& yuvToRgbMatrix, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, std::optional<GLuint> alphaPlane, unsigned exposedEdges = AllEdges);
     void drawTextureSemiPlanarYUV(const std::array<GLuint, 2>& textures, bool uvReversed, const std::array<GLfloat, 9>& yuvToRgbMatrix, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges = AllEdges);
     void drawTexturePackedYUV(GLuint texture, const std::array<GLfloat, 9>& yuvToRgbMatrix, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges = AllEdges);
     void drawSolidColor(const FloatRect&, const TransformationMatrix&, const Color&, bool) override;

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp (279937 => 279938)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp	2021-07-15 08:08:24 UTC (rev 279938)
@@ -143,8 +143,13 @@
             case 3:
                 ASSERT(!texture.yuvPlaneOffset[0] && !texture.yuvPlaneOffset[1] && !texture.yuvPlaneOffset[2]);
                 texmapGL.drawTexturePlanarYUV(std::array<GLuint, 3> { texture.planes[texture.yuvPlane[0]], texture.planes[texture.yuvPlane[1]], texture.planes[texture.yuvPlane[2]] },
-                    texture.yuvToRgbMatrix, m_extraFlags, m_size, targetRect, modelViewMatrix, opacity);
+                    texture.yuvToRgbMatrix, m_extraFlags, m_size, targetRect, modelViewMatrix, opacity, std::nullopt);
                 break;
+            case 4:
+                ASSERT(!texture.yuvPlaneOffset[0] && !texture.yuvPlaneOffset[1] && !texture.yuvPlaneOffset[2]);
+                texmapGL.drawTexturePlanarYUV(std::array<GLuint, 3> { texture.planes[texture.yuvPlane[0]], texture.planes[texture.yuvPlane[1]], texture.planes[texture.yuvPlane[2]] },
+                    texture.yuvToRgbMatrix, m_extraFlags, m_size, targetRect, modelViewMatrix, opacity, texture.planes[texture.yuvPlane[3]]);
+                break;
             }
         },
         [&](const ExternalOESTexture& texture) {

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h (279937 => 279938)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h	2021-07-15 08:08:24 UTC (rev 279938)
@@ -48,9 +48,9 @@
     };
     struct YUVTexture {
         unsigned numberOfPlanes;
-        std::array<GLuint, 3> planes;
-        std::array<unsigned, 3> yuvPlane;
-        std::array<unsigned, 3> yuvPlaneOffset;
+        std::array<GLuint, 4> planes;
+        std::array<unsigned, 4> yuvPlane;
+        std::array<unsigned, 4> yuvPlaneOffset;
         std::array<GLfloat, 9> yuvToRgbMatrix;
     };
     struct ExternalOESTexture {

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp (279937 => 279938)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp	2021-07-15 08:08:24 UTC (rev 279938)
@@ -233,6 +233,7 @@
         uniform SamplerType s_samplerY;
         uniform SamplerType s_samplerU;
         uniform SamplerType s_samplerV;
+        uniform SamplerType s_samplerA;
         uniform sampler2D s_contentTexture;
         uniform SamplerExternalOESType s_externalOESTexture;
         uniform float u_opacity;
@@ -280,6 +281,15 @@
             vec4 data = "" u, v), 1.0);
             color = u_textureColorSpaceMatrix * data;
         }
+        void applyTextureYUVA(inout vec4 color, vec2 texCoord)
+        {
+            float y = SamplerFunction(s_samplerY, texCoord).r;
+            float u = SamplerFunction(s_samplerU, texCoord).r;
+            float v = SamplerFunction(s_samplerV, texCoord).r;
+            float a = SamplerFunction(s_samplerA, texCoord).r;
+            vec4 data = "" u, v), a);
+            color = u_textureColorSpaceMatrix * data;
+        }
         void applyTextureNV12(inout vec4 color, vec2 texCoord)
         {
             float y = SamplerFunction(s_samplerY, texCoord).r;
@@ -485,11 +495,12 @@
             vec2 texCoord = transformTexCoord();
             applyManualRepeatIfNeeded(texCoord);
             applyTextureRGBIfNeeded(color, texCoord);
-            applyPremultiplyIfNeeded(color);
             applyTextureYUVIfNeeded(color, texCoord);
+            applyTextureYUVAIfNeeded(color, texCoord);
             applyTextureNV12IfNeeded(color, texCoord);
             applyTextureNV21IfNeeded(color, texCoord);
             applyTexturePackedYUVIfNeeded(color, texCoord);
+            applyPremultiplyIfNeeded(color);
             applySolidColorIfNeeded(color);
             applyAntialiasingIfNeeded(color);
             applyOpacityIfNeeded(color);
@@ -519,6 +530,7 @@
     StringBuilder optionsApplierBuilder;
     SET_APPLIER_FROM_OPTIONS(TextureRGB);
     SET_APPLIER_FROM_OPTIONS(TextureYUV);
+    SET_APPLIER_FROM_OPTIONS(TextureYUVA);
     SET_APPLIER_FROM_OPTIONS(TextureNV12);
     SET_APPLIER_FROM_OPTIONS(TextureNV21);
     SET_APPLIER_FROM_OPTIONS(TexturePackedYUV);

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h (279937 => 279938)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h	2021-07-15 03:11:53 UTC (rev 279937)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h	2021-07-15 08:08:24 UTC (rev 279938)
@@ -50,16 +50,17 @@
     macro(shadowOffset) \
     macro(roundedRectNumber) \
     macro(roundedRect) \
-    macro(roundedRectInverseTransformMatrix) \
+    macro(roundedRectInverseTransformMatrix)
 
-#define TEXMAP_SAMPLER_VARIABLES(macro) \
-    macro(sampler) \
-    macro(samplerY) \
-    macro(samplerU) \
-    macro(samplerV) \
-    macro(mask) \
-    macro(contentTexture) \
-    macro(externalOESTexture) \
+#define TEXMAP_SAMPLER_VARIABLES(macro)           \
+    macro(sampler)                                \
+    macro(samplerY)                               \
+    macro(samplerU)                               \
+    macro(samplerV)                               \
+    macro(samplerA)                               \
+    macro(mask)                                   \
+    macro(contentTexture)                         \
+    macro(externalOESTexture)
 
 #define TEXMAP_VARIABLES(macro) \
     TEXMAP_ATTRIBUTE_VARIABLES(macro) \
@@ -104,6 +105,7 @@
         TextureExternalOES = 1L << 22,
         RoundedRectClip  = 1L << 23,
         Premultiply      = 1L << 24,
+        TextureYUVA      = 1L << 25,
     };
 
     enum class VariableID {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to