Avoid infinite inverse inner-radii in eliiptical rrect op

Bug: chromium:1139750, skia:8389
Cq-Include-Trybots: luci.chromium.try:linux-blink-rel,win10-blink-rel
Change-Id: I69c55f505947fdec5d9d391d2b2d2d3ff6dec9b8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/330216
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2020-10-28 10:49:56 -04:00 committed by Skia Commit-Bot
parent c22288fbdb
commit e3afdd5b75
3 changed files with 35 additions and 0 deletions

29
gm/crbug_1139750.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRRect.h"
DEF_SIMPLE_GM_BG(crbug_1139750, canvas, 50, 50, SK_ColorWHITE) {
// Draw a round-rect with a (slightly) non-square scale. This forces the GPU backend to use
// the elliptical round-rect op. We set the stroke width to exactly double the radii, which
// makes the inner radii exactly zero. The shader uses the inverse inner radii to compute the
// coverage ramp, so this would end up producing infinity, and the geometry would disappear.
SkPaint p;
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
p.setStrokeWidth(2);
SkRect r = SkRect::MakeXYWH(1, 1, 19, 19);
SkRRect rr = SkRRect::MakeRectXY(r, 1, 1);
canvas->translate(10, 10);
canvas->scale(1.47619f, 1.52381f);
canvas->drawRRect(rr, p);
}

View File

@ -109,6 +109,7 @@ gm_sources = [
"$_gm/crbug_1073670.cpp",
"$_gm/crbug_1086705.cpp",
"$_gm/crbug_1113794.cpp",
"$_gm/crbug_1139750.cpp",
"$_gm/crbug_224618.cpp",
"$_gm/crbug_691386.cpp",
"$_gm/crbug_788500.cpp",

View File

@ -2987,6 +2987,11 @@ private:
SkScalarInvert(rrect.fInnerYRadius)
};
// If the stroke width is exactly double the radius, the inner radii will be zero.
// Pin to a large value, to avoid infinities in the shader. crbug.com/1139750
reciprocalRadii[2] = std::min(reciprocalRadii[2], 1e6f);
reciprocalRadii[3] = std::min(reciprocalRadii[3], 1e6f);
// Extend the radii out half a pixel to antialias.
SkScalar xOuterRadius = rrect.fXRadius + SK_ScalarHalf;
SkScalar yOuterRadius = rrect.fYRadius + SK_ScalarHalf;