blob: d2d2b6da36313609770469bc1994e9d633226e9f [file] [log] [blame]
Michael Ludwig0a1e9ef2019-08-30 10:03:15 -04001/*
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/SkPath.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 SkPath path;
47
48 // 4: ctx.scale(203.20, 203.20);
49 canvas->scale(s, s);
50 // 5: ctx.translate(-14.55, -711.51);
51 canvas->translate(tx, ty);
52
53 // 6: ctx.fillStyle = "red";
54 SkPaint fill;
55 fill.setColor(SK_ColorRED);
56 fill.setStyle(SkPaint::kFill_Style);
57 fill.setAntiAlias(true);
58
59 // 7: ctx.strokeStyle = "blue";
60 SkPaint stroke;
61 stroke.setColor(SK_ColorBLUE);
62 stroke.setStrokeWidth(1.f);
63 stroke.setStyle(SkPaint::kStroke_Style);
64 stroke.setAntiAlias(true);
65
66 // 9: ctx.arc(19.221, 720-6.76,0.0295275590551181,0,2*Math.PI);
67 // This matches how Canvas prepares an arc(x, y, radius, 0, 2pi) call
68 SkRect boundingBox = SkRect::MakeLTRB(cx - radius, cy - radius, cx + radius, cy + radius);
69 path.arcTo(boundingBox, 0, 180.f, false);
70 path.arcTo(boundingBox, 180.f, 180.f, false);
71
72 // 12: ctx.closePath();
73 // path.close();
74
75 // 10: ctx.stroke(); (NOT NEEDED TO REPRODUCE FAILING RED CIRCLE)
76 canvas->drawPath(path, stroke);
77 // 11: ctx.fill()
78 canvas->drawPath(path, fill);
79}