• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkPathBuilder.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 */
31 DEF_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;
54     fill.setColor(SK_ColorRED);
55     fill.setStyle(SkPaint::kFill_Style);
56     fill.setAntiAlias(true);
57 
58     // 7: ctx.strokeStyle = "blue";
59     SkPaint stroke;
60     stroke.setColor(SK_ColorBLUE);
61     stroke.setStrokeWidth(1.f);
62     stroke.setStyle(SkPaint::kStroke_Style);
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 }
81