blob: 9638081d2a9b9a762691ecaacc339a69ba38fafe [file] [log] [blame]
Chris Dalton08a97112021-11-11 11:32:12 -07001/*
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
10#include "include/core/SkCanvas.h"
11#include "include/core/SkPaint.h"
12#include "include/core/SkPath.h"
13#include "include/gpu/GrContextOptions.h"
14
15namespace skiagm {
16
17class BatchedConvexPathsGM : public GM {
18private:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000019 SkString getName() const override { return SkString("batchedconvexpaths"); }
Leandro Lovisolo8f023882023-08-15 21:13:52 +000020 SkISize getISize() override { return SkISize::Make(512, 512); }
Chris Dalton08a97112021-11-11 11:32:12 -070021
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
46 SkPaint paint;
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