Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
largeclippedpath.cpp
Go to the documentation of this file.
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"
10#include "include/core/SkPath.h"
11
12constexpr int kSize = 1000;
13
14// Makes sure PathInnerTriangulateOp uses correct stencil settings when there is a clip in the
15// stencil buffer.
16static void draw_clipped_flower(SkCanvas* canvas, SkPathFillType fillType) {
17 canvas->clear(SK_ColorCYAN);
20 constexpr static int kGridCount = 50;
21 constexpr static float kCellSize = (float)kSize / kGridCount;
22 for (int y = 0; y < kGridCount; ++y) {
23 clip.addRect(0, y * kCellSize, kSize, (y + 1) * kCellSize, SkPathDirection(y & 1));
24 }
25 for (int x = 0; x < kGridCount; ++x) {
26 clip.addRect(x * kCellSize, 0, (x + 1) * kCellSize, kSize, SkPathDirection(x & 1));
27 }
28 canvas->clipPath(clip);
30 flower.setFillType(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, p);
46}
47
48DEF_SIMPLE_GM(largeclippedpath_winding, canvas, kSize, kSize) {
50}
51
52DEF_SIMPLE_GM(largeclippedpath_evenodd, canvas, kSize, kSize) {
54}
constexpr SkColor SK_ColorMAGENTA
Definition SkColor.h:147
constexpr SkColor SK_ColorCYAN
Definition SkColor.h:143
SkPathDirection
Definition SkPathTypes.h:34
SkPathFillType
Definition SkPathTypes.h:11
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
#define SK_ScalarPI
Definition SkScalar.h:21
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
Definition SkCanvas.h:1199
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
void drawPath(const SkPath &path, const SkPaint &paint)
void scale(SkScalar sx, SkScalar sy)
void setFillType(SkPathFillType ft)
Definition SkPath.h:235
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Definition SkPath.cpp:854
static void flower(SkCanvas *canvas, const SkPath &path, SkScalar intervals[2], SkPaint::Join join)
const int kCellSize
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
constexpr int kSize
static void draw_clipped_flower(SkCanvas *canvas, SkPathFillType fillType)
double y
double x
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646