Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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;
33 SkPath path;
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
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
#define SK_ScalarPI
Definition SkScalar.h:21
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
void scale(SkScalar sx, SkScalar sy)
SkString getName() const override
void modifyGrContextOptions(GrContextOptions *ctxOptions) override
DrawResult onDraw(SkCanvas *canvas, SkString *errorMsg) override
const Paint & paint
#define DEF_GM(CODE)
Definition gm.h:40
DrawResult
Definition gm.h:104
const Scalar scale
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20