Flutter Engine
The Flutter Engine
batchedconvexpaths.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC.
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
12#include "include/core/SkPath.h"
14
15namespace skiagm {
16
17class BatchedConvexPathsGM : public GM {
18private:
19 SkString getName() const override { return SkString("batchedconvexpaths"); }
20 SkISize getISize() override { return SkISize::Make(512, 512); }
21
22 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
23 // Ensure our paths don't go through the atlas path renderer.
24 ctxOptions->fGpuPathRenderers &= ~GpuPathRenderers::kAtlas;
25 }
26
27 DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
28 canvas->clear(SK_ColorBLACK);
29 for (uint32_t i = 0; i < 10; ++i) {
30 SkAutoCanvasRestore acr(canvas, true);
31
32 int numPoints = (i + 3) * 3;
34 path.moveTo(1, 0);
35 for (float j = 1; j < numPoints; j += 3) {
36 constexpr float k2PI = SK_ScalarPI * 2;
37 path.cubicTo(cosf(j/numPoints * k2PI), sinf(j/numPoints * k2PI),
38 cosf((j+1)/numPoints * k2PI), sinf((j+1)/numPoints * k2PI),
39 j+2 == numPoints ? 1 : cosf((j+2)/numPoints * k2PI),
40 j+2 == numPoints ? 0 : sinf((j+2)/numPoints * k2PI));
41 }
42 float scale = 256 - i*24;
43 canvas->translate(scale + (256 - scale) * .33f, scale + (256 - scale) * .33f);
44 canvas->scale(scale, scale);
45
47 paint.setColor(((i + 123458383u) * 285018463u) | 0xff808080);
48 paint.setAlphaf(0.3f);
49 paint.setAntiAlias(true);
50
51 canvas->drawPath(path, paint);
52 }
53 return DrawResult::kOk;
54 }
55};
56
57DEF_GM( return new BatchedConvexPathsGM; )
58
59} // namespace skiagm
GpuPathRenderers
Definition: GrTypesPriv.h:506
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define SK_ScalarPI
Definition: SkScalar.h:21
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 scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
Definition: SkPath.h:59
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
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
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
static SkPath scale(const SkPath &path, SkScalar scale)
Definition: patheffects.cpp:68
DrawResult
Definition: gm.h:104
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20