Skip to content

Commit e2c201c

Browse files
committed
[WPE] Holepunch doesn't work when the video element has rounded corners https://bugs.webkit.org/show_bug.cgi?id=271653 Reviewed by Carlos Garcia Campos. Modify the rounded rectangle clipping in the TextureMapper so it can work when blending is disabled. To do this, the fragments that are out of rounded rectangle are discarded by the fragment shader, instead of painting them transparent. When blending is enabled, we can do some antialiasing of the pixels on the rounded corners by reducing their opacity depending on how much they are inside the rect. When blending is disabled we can't do antialiasing of the rounded corners, so the visual result is a bit worse. The good thing is that blending is only disabled when we're rendering a holepunch buffer, so it's not a big problem. * Source/WebCore/platform/graphics/texmap/TextureMapper.cpp: (WebCore::TextureMapper::drawSolidColor): * Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp: Canonical link: https://commits.webkit.org/276876@main
1 parent e32bce9 commit e2c201c

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,16 @@ void TextureMapperGL::drawSolidColor(const FloatRect& rect, const Transformation
712712
flags |= ShouldAntialias | (isBlendingAllowed ? ShouldBlend : 0);
713713
}
714714

715-
if (clipStack().isRoundedRectClipEnabled() && isBlendingAllowed) {
715+
if (clipStack().isRoundedRectClipEnabled()) {
716716
options.add(TextureMapperShaderProgram::RoundedRectClip);
717-
flags |= ShouldBlend;
717+
if (isBlendingAllowed)
718+
flags |= ShouldBlend;
718719
}
719720

720721
Ref<TextureMapperShaderProgram> program = data().getShaderProgram(options);
721722
glUseProgram(program->programID());
722723

723-
if (options.contains(TextureMapperShaderProgram::RoundedRectClip))
724+
if (clipStack().isRoundedRectClipEnabled())
724725
prepareRoundedRectClip(program.get(), clipStack().roundedRectComponents(), clipStack().roundedRectInverseTransformComponents(), clipStack().roundedRectCount());
725726

726727
auto [r, g, b, a] = premultiplied(color.toColorTypeLossy<SRGBA<float>>()).resolved();

Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,23 @@ static const char* fragmentTemplateCommon =
474474
vec2 topRightRadii = u_roundedRect[(rectIndex * 3) + 1].zw;
475475
vec2 bottomLeftRadii = u_roundedRect[(rectIndex * 3) + 2].xy;
476476
vec2 bottomRightRadii = u_roundedRect[(rectIndex * 3) + 2].zw;
477-
color *= roundedRectCoverage(fragCoord.xy, bounds, topLeftRadii, topRightRadii, bottomLeftRadii, bottomRightRadii);
477+
float coverage = roundedRectCoverage(fragCoord.xy, bounds, topLeftRadii, topRightRadii, bottomLeftRadii, bottomRightRadii);
478+
479+
// Pixels outside the rect have coverage 0.0.
480+
// Pixels inside the rect have coverage 1.0.
481+
// Pixels on the border of the rounded parts have coverage between 0.0 and 1.0.
482+
483+
// Discard the fragments that are outside the rect.
484+
if (coverage == 0.0)
485+
discard;
486+
487+
// By multiplying the color by the coverage, pixels on the border of the rounded corners get
488+
// a bit more transparent.
489+
// If blending is enabled, this does some antialiasing on the border pixels.
490+
// If blending is disabled it means that we're rendering a holepunch buffer, so the color
491+
// is always (0,0,0,0). In this case, multiplying by the coverage doesn't cause any effect
492+
// and no antialiasing is done.
493+
color *= coverage;
478494
}
479495
}
480496

0 commit comments

Comments
 (0)