• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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/SkPath.h"
11 #include "include/core/SkPoint.h"
12 #include "include/gpu/GrContextOptions.h"
13 #include "include/gpu/GrDirectContext.h"
14 #include "src/base/SkRandom.h"
15 #include "src/gpu/ganesh/GrCaps.h"
16 #include "src/gpu/ganesh/GrDirectContextPriv.h"
17 #include "src/gpu/ganesh/GrDrawingManager.h"
18 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
19 #include "src/gpu/ganesh/ops/TessellationPathRenderer.h"
20 
21 static constexpr float kStrokeWidth = 100;
22 static constexpr int kTestWidth = 120 * 4;
23 static constexpr int kTestHeight = 120 * 3 + 140;
24 
draw_strokes(SkCanvas * canvas,SkRandom * rand,const SkPath & path,const SkPath & cubic)25 static void draw_strokes(SkCanvas* canvas, SkRandom* rand, const SkPath& path,
26                          const SkPath& cubic) {
27     SkPaint strokePaint;
28     strokePaint.setAntiAlias(true);
29     strokePaint.setStrokeWidth(kStrokeWidth);
30     strokePaint.setStyle(SkPaint::kStroke_Style);
31 
32     SkAutoCanvasRestore arc(canvas, true);
33     strokePaint.setStrokeJoin(SkPaint::kBevel_Join);
34     strokePaint.setColor(rand->nextU() | 0xff808080);
35     canvas->drawPath(path, strokePaint);
36 
37     canvas->translate(120, 0);
38     strokePaint.setStrokeJoin(SkPaint::kRound_Join);
39     strokePaint.setColor(rand->nextU() | 0xff808080);
40     canvas->drawPath(path, strokePaint);
41 
42     canvas->translate(120, 0);
43     strokePaint.setStrokeJoin(SkPaint::kMiter_Join);
44     strokePaint.setColor(rand->nextU() | 0xff808080);
45     canvas->drawPath(path, strokePaint);
46 
47     canvas->translate(120, 0);
48     strokePaint.setColor(rand->nextU() | 0xff808080);
49     canvas->drawPath(cubic, strokePaint);
50 }
51 
draw_test(SkCanvas * canvas)52 static void draw_test(SkCanvas* canvas) {
53     SkRandom rand;
54 
55     canvas->clear(SK_ColorBLACK);
56 
57     SkAutoCanvasRestore arc(canvas, true);
58     canvas->translate(60, 60);
59 
60     draw_strokes(canvas, &rand,
61             SkPath().lineTo(10,0).lineTo(10,10),
62             SkPath().cubicTo(10,0, 10,0, 10,10));
63     canvas->translate(0, 120);
64 
65     draw_strokes(canvas, &rand,
66             SkPath().lineTo(0,-10).lineTo(0,10),
67             SkPath().cubicTo(0,-10, 0,-10, 0,10));
68     canvas->translate(0, 120);
69 
70     draw_strokes(canvas, &rand,
71             SkPath().lineTo(0,-10).lineTo(10,-10).lineTo(10,10).lineTo(0,10),
72             SkPath().cubicTo(0,-10, 10,10, 0,10));
73     canvas->translate(0, 140);
74 
75     draw_strokes(canvas, &rand,
76             SkPath().lineTo(0,-10).lineTo(10,-10).lineTo(10,0).lineTo(0,0),
77             SkPath().cubicTo(0,-10, 10,0, 0,0));
78     canvas->translate(0, 120);
79 }
80 
DEF_SIMPLE_GM(widebuttcaps,canvas,kTestWidth,kTestHeight)81 DEF_SIMPLE_GM(widebuttcaps, canvas, kTestWidth, kTestHeight) {
82     canvas->clear(SK_ColorBLACK);
83     draw_test(canvas);
84 }
85