Flutter Engine
The Flutter Engine
widebuttcaps.cpp
Go to the documentation of this file.
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"
10#include "include/core/SkPath.h"
14#include "src/base/SkRandom.h"
20
21static constexpr float kStrokeWidth = 100;
22static constexpr int kTestWidth = 120 * 4;
23static constexpr int kTestHeight = 120 * 3 + 140;
24
25static 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);
31
32 SkAutoCanvasRestore arc(canvas, true);
34 strokePaint.setColor(rand->nextU() | 0xff808080);
35 canvas->drawPath(path, strokePaint);
36
37 canvas->translate(120, 0);
39 strokePaint.setColor(rand->nextU() | 0xff808080);
40 canvas->drawPath(path, strokePaint);
41
42 canvas->translate(120, 0);
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
52static 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
81DEF_SIMPLE_GM(widebuttcaps, canvas, kTestWidth, kTestHeight) {
82 canvas->clear(SK_ColorBLACK);
83 draw_test(canvas);
84}
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
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
void setStrokeJoin(Join join)
Definition: SkPaint.cpp:189
@ kRound_Join
adds circle
Definition: SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
uint32_t nextU()
Definition: SkRandom.h:42
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:195
DEF_SIMPLE_GM(widebuttcaps, canvas, kTestWidth, kTestHeight)
static void draw_strokes(SkCanvas *canvas, SkRandom *rand, const SkPath &path, const SkPath &cubic)
static constexpr float kStrokeWidth
static constexpr int kTestHeight
static constexpr int kTestWidth
static void draw_test(SkCanvas *canvas)