1 /*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPath.h"
11 #include "include/core/SkPathUtils.h"
12
get_path()13 static SkPath get_path() {
14 SkPath path;
15 path.setFillType(SkPathFillType::kWinding);
16 path.moveTo(SkBits2Float(0x45034ec4), SkBits2Float(0x42e7fb80)); // 2100.92f, 115.991f
17 path.quadTo(SkBits2Float(0x4500f46c),
18 SkBits2Float(0x43333300),
19 SkBits2Float(0x4500f46c),
20 SkBits2Float(0x431f0ec0)); // 2063.28f, 179.199f, 2063.28f, 159.058f
21 path.quadTo(SkBits2Float(0x4500f46c),
22 SkBits2Float(0x430ad7c0),
23 SkBits2Float(0x45019462),
24 SkBits2Float(0x42fed580)); // 2063.28f, 138.843f, 2073.27f, 127.417f
25 path.quadTo(SkBits2Float(0x45023458),
26 SkBits2Float(0x42e7fb80),
27 SkBits2Float(0x45034ec4),
28 SkBits2Float(0x42e7fb80)); // 2083.27f, 115.991f, 2100.92f, 115.991f
29 path.close();
30 return path;
31 }
32
33 // Reproduces the underlying problem from skbug.com/12866.
34 // The path (part of a glyph) was being drawn stroked, and with a perspective matrix.
35 // The perspective matrix forces a very large resScale when stroking the path.
36 // The resulting filled path is incorrect. Note that stroking with a smaller resScale works fine.
37 DEF_SIMPLE_GM(bug12866, canvas, 128, 64) {
38 SkPaint strokePaint;
39 strokePaint.setAntiAlias(true);
40 strokePaint.setStyle(SkPaint::kStroke_Style);
41 strokePaint.setStrokeWidth(3);
42
43 SkPaint fillPaint;
44 fillPaint.setAntiAlias(true);
45
46 SkPath strokePath = get_path();
47 SkPath fillPath;
48 skpathutils::FillPathWithPaint(strokePath, strokePaint, &fillPath, nullptr, 1200.0f);
49
50 SkRect strokeBounds = strokePath.getBounds();
51 SkRect fillBounds = fillPath.getBounds();
52
53 // Draw the stroked path. This (internally) uses a resScale of 1.0, and looks good.
54 canvas->save();
55 canvas->translate(10 - strokeBounds.fLeft, 10 - strokeBounds.fTop);
56 canvas->drawPath(strokePath, strokePaint);
57 canvas->restore();
58
59 // With a perspective CTM, it's possible for resScale to become large. Draw the filled
60 // path produced by the stroker in that situation, which ends up being incorrect.
61 canvas->save();
62 canvas->translate(74 - fillBounds.fLeft, 10 - fillBounds.fTop);
63 canvas->drawPath(fillPath, fillPaint);
64 canvas->restore();
65 }
66