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