Drop AA on quads that are extremely thin before AA insetting/outsetting.

Bug: chromium:1174186
Change-Id: I91a88d2d57150dee37f08bc4270d399abfd0d60d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368497
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
Brian Salomon 2021-02-09 20:44:09 -05:00 committed by Skia Commit-Bot
parent e89b50ae05
commit ec04e062f3
3 changed files with 52 additions and 0 deletions

42
gm/crbug_1174186.cpp Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright 2021 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/SkMatrix.h"
#include "include/core/SkRect.h"
// Outsetting of very thin, nearly line, quads for AA would go haywire and draw far outside of the
// quad. Artifacts seemed to occur more when coord values are large, hence the large GM size. At the
// time of GM creation this was fixed by dropping AA, which makes these quads practically never draw
// as it's very unlikely a pixel center would fall inside the geometry.
DEF_SIMPLE_GM(crbug_1174186, canvas, 1200, 1200) {
auto m = SkMatrix::MakeAll(
SkBits2Float(0x24480629), SkBits2Float(0xbf3555c2), SkBits2Float(0x4377d67b),
SkBits2Float(0x23a61d51), SkBits2Float(0x3f34b400), SkBits2Float(0x4453f572),
SkBits2Float(0x00000000), SkBits2Float(0x00000000), SkBits2Float(0x3f800000));
SkPoint pts[] = {{SkBits2Float(0x3f7ffff2), SkBits2Float(0x43483d60)},
{SkBits2Float(0x00000000), SkBits2Float(0x43483d60)},
{SkBits2Float(0x00000000), SkBits2Float(0x4311a628)},
{SkBits2Float(0x3f800000), SkBits2Float(0x43130f8c)}};
SkColor color = SK_ColorGREEN;
canvas->translate(-500, 0);
for (int i = 0; i < 10; ++i) {
for (int flags = 0; flags < static_cast<int>(SkCanvas::kAll_QuadAAFlags); ++flags) {
SkCanvas::QuadAAFlags aaFlags = static_cast<SkCanvas::QuadAAFlags>(flags);
canvas->save();
canvas->concat(m);
canvas->experimental_DrawEdgeAAQuad(SkRect::MakeWH(1000, 1000), pts, aaFlags, color,
SkBlendMode::kSrcOver);
canvas->restore();
canvas->translate(5.1f, 0);
SkColor rgb = color & 0x00FFFFFF;
color = 0xFF000000 | (rgb << 4) | (rgb >> 20);
}
}
}

View File

@ -115,6 +115,7 @@ gm_sources = [
"$_gm/crbug_1156804.cpp",
"$_gm/crbug_1162942.cpp",
"$_gm/crbug_1167277.cpp",
"$_gm/crbug_1174186.cpp",
"$_gm/crbug_224618.cpp",
"$_gm/crbug_691386.cpp",
"$_gm/crbug_788500.cpp",

View File

@ -719,6 +719,15 @@ V4f TessellationHelper::EdgeEquations::estimateCoverage(const V4f& x2d, const V4
int TessellationHelper::EdgeEquations::computeDegenerateQuad(const V4f& signedEdgeDistances,
V4f* x2d, V4f* y2d,
M4f* aaMask) const {
// If the original points form a line in the 2D projection then give up on antialiasing.
for (int i = 0; i < 4; ++i) {
V4f d = (*x2d)*fA[i] + (*y2d)*fB[i] + fC[i];
if (all(abs(d) < kDistTolerance)) {
*aaMask = M4f(0);
return 4;
}
}
*aaMask = signedEdgeDistances != 0.f;
// Move the edge by the signed edge adjustment.