Debian Codegraph @

gm/batchedconvexpaths.cpp

raw
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
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkPath.h"
13 #include "include/core/SkPathBuilder.h"
14
15 #if defined(SK_GANESH)
16 #include "include/gpu/ganesh/GrContextOptions.h"
17 #endif
18
19 namespace skiagm {
20
21 class BatchedConvexPathsGM : public GM {
22 private:
23 SkString getName() const override { return SkString("batchedconvexpaths"); }
24 SkISize getISize() override { return SkISize::Make(512, 512); }
25
26 #if defined(SK_GANESH)
27 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
28 // Ensure our paths don't go through the atlas path renderer.
29 ctxOptions->fGpuPathRenderers &= ~GpuPathRenderers::kAtlas;
30 }
31 #endif
32
33 DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
34 canvas->clear(SK_ColorBLACK);
35 for (uint32_t i = 0; i < 10; ++i) {
36 SkAutoCanvasRestore acr(canvas, true);
37
38 int numPoints = (i + 3) * 3;
39 SkPathBuilder builder;
40 builder.moveTo(1, 0);
41 for (float j = 1; j < numPoints; j += 3) {
42 constexpr float k2PI = SK_ScalarPI * 2;
43 builder.cubicTo(cosf(j/numPoints * k2PI), sinf(j/numPoints * k2PI),
44 cosf((j+1)/numPoints * k2PI), sinf((j+1)/numPoints * k2PI),
45 j+2 == numPoints ? 1 : cosf((j+2)/numPoints * k2PI),
46 j+2 == numPoints ? 0 : sinf((j+2)/numPoints * k2PI));
47 }
48 float scale = 256 - i*24;
49 canvas->translate(scale + (256 - scale) * .33f, scale + (256 - scale) * .33f);
50 canvas->scale(scale, scale);
51
52 SkPaint paint;
53 paint.setColor(((i + 123458383u) * 285018463u) | 0xff808080);
54 paint.setAlphaf(0.3f);
55 paint.setAntiAlias(true);
56
57 canvas->drawPath(builder.detach(), paint);
58 }
59 return DrawResult::kOk;
60 }
61 };
62
63 DEF_GM( return new BatchedConvexPathsGM; )
64
65 } // namespace skiagm