| 1 |
/* |
| 2 |
* Copyright 2021 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 |
|
| 13 |
constexpr int kSize = 1000; |
| 14 |
|
| 15 |
// Makes sure PathInnerTriangulateOp uses correct stencil settings when there is a clip in the |
| 16 |
// stencil buffer. |
| 17 |
static void draw_clipped_flower(SkCanvas* canvas, SkPathFillType fillType) { |
| 18 |
canvas->clear(SK_ColorCYAN); |
| 19 |
SkPathBuilder clip; |
| 20 |
clip.setFillType(SkPathFillType::kWinding); |
| 21 |
constexpr static int kGridCount = 50; |
| 22 |
constexpr static float kCellSize = (float)kSize / kGridCount; |
| 23 |
for (int y = 0; y < kGridCount; ++y) { |
| 24 |
clip.addRect({0, y * kCellSize, kSize, (y + 1) * kCellSize}, SkPathDirection(y & 1)); |
| 25 |
} |
| 26 |
for (int x = 0; x < kGridCount; ++x) { |
| 27 |
clip.addRect({x * kCellSize, 0, (x + 1) * kCellSize, kSize}, SkPathDirection(x & 1)); |
| 28 |
} |
| 29 |
canvas->clipPath(clip.detach()); |
| 30 |
SkPathBuilder flower(fillType); |
| 31 |
flower.moveTo(1, 0); |
| 32 |
constexpr static int kNumPetals = 9; |
| 33 |
for (int i = 1; i <= kNumPetals; ++i) { |
| 34 |
float c = 2*SK_ScalarPI*(i - .5f) / kNumPetals; |
| 35 |
float theta = 2*SK_ScalarPI*i / kNumPetals; |
| 36 |
flower.quadTo(cosf(c)*2, sinf(c)*2, cosf(theta), sinf(theta)); |
| 37 |
} |
| 38 |
flower.close(); |
| 39 |
flower.addArc(SkRect::MakeLTRB(-.75f, -.75f, .75f, .75f), 0, 360); |
| 40 |
canvas->translate(kSize/2.f, kSize/2.f); |
| 41 |
canvas->scale(kSize/3.f, kSize/3.f); |
| 42 |
SkPaint p; |
| 43 |
p.setAntiAlias(true); |
| 44 |
p.setColor(SK_ColorMAGENTA); |
| 45 |
canvas->drawPath(flower.detach(), p); |
| 46 |
} |
| 47 |
|
| 48 |
DEF_SIMPLE_GM(largeclippedpath_winding, canvas, kSize, kSize) { |
| 49 |
draw_clipped_flower(canvas, SkPathFillType::kWinding); |
| 50 |
} |
| 51 |
|
| 52 |
DEF_SIMPLE_GM(largeclippedpath_evenodd, canvas, kSize, kSize) { |
| 53 |
draw_clipped_flower(canvas, SkPathFillType::kEvenOdd); |
| 54 |
} |