Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
crbug_996140.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
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"
13
14/*
15 * Canvas example. Expected large blue stroked circle, white middle, small red circle.
16 * GPU-accelerated canvas produces large blue stroked circle, white middle, NO red circle.
17 *
18 * 1: var c = document.getElementById("myCanvas");
19 * 2: var ctx = c.getContext("2d");
20 * 3: ctx.beginPath();
21 * 4: ctx.scale(203.20, 203.20);
22 * 5: ctx.translate(-14.55, -711.51);
23 * 6: ctx.fillStyle = "red";
24 * 7: ctx.strokeStyle = "blue";
25 * 8: //ctx.lineWidth = 1/203.20;
26 * 9: ctx.arc(19.221, 720-6.76,0.0295275590551181,0,2*Math.PI);
27 * 10: ctx.stroke();
28 * 11: ctx.fill();
29 * 12: ctx.closePath();
30*/
31DEF_SIMPLE_GM_BG(crbug_996140, canvas, 300, 300, SK_ColorWHITE) {
32 // Specific parameters taken from the canvas minimum working example
33 SkScalar cx = 19.221f;
34 SkScalar cy = 720-6.76f;
35 SkScalar radius = 0.0295275590551181f;
36
37 SkScalar s = 203.20f;
38 SkScalar tx = -14.55f;
39 SkScalar ty = -711.51f;
40
41 // 0: The test canvas was 1920x574 and the circle was located in the bottom left, but that's
42 // not necessary to reproduce the problem, so translate to make a smaller GM.
43 canvas->translate(-800, -200);
44
45 // 3: ctx.beginPath();
46
47 // 4: ctx.scale(203.20, 203.20);
48 canvas->scale(s, s);
49 // 5: ctx.translate(-14.55, -711.51);
50 canvas->translate(tx, ty);
51
52 // 6: ctx.fillStyle = "red";
53 SkPaint fill;
56 fill.setAntiAlias(true);
57
58 // 7: ctx.strokeStyle = "blue";
59 SkPaint stroke;
60 stroke.setColor(SK_ColorBLUE);
61 stroke.setStrokeWidth(1.f);
63 stroke.setAntiAlias(true);
64
65 // 9: ctx.arc(19.221, 720-6.76,0.0295275590551181,0,2*Math.PI);
66 // This matches how Canvas prepares an arc(x, y, radius, 0, 2pi) call
67 SkRect boundingBox = SkRect::MakeLTRB(cx - radius, cy - radius, cx + radius, cy + radius);
68
69 auto path = SkPathBuilder().arcTo(boundingBox, 0, 180.f, false)
70 .arcTo(boundingBox, 180.f, 180.f, false)
71 .detach();
72
73 // 12: ctx.closePath();
74 // path.close();
75
76 // 10: ctx.stroke(); (NOT NEEDED TO REPRODUCE FAILING RED CIRCLE)
77 canvas->drawPath(path, stroke);
78 // 11: ctx.fill()
79 canvas->drawPath(path, fill);
80}
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
void setStrokeWidth(SkScalar width)
Definition SkPaint.cpp:159
SkPathBuilder & arcTo(const SkRect &oval, SkScalar startAngleDeg, SkScalar sweepAngleDeg, bool forceMoveTo)
float SkScalar
Definition extension.cpp:12
struct MyStruct s
#define DEF_SIMPLE_GM_BG(NAME, CANVAS, W, H, BGCOLOR)
Definition gm.h:52
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646