• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/gpu/GrContextOptions.h"
14 
15 namespace skiagm {
16 
17 class BatchedConvexPathsGM : public GM {
18 private:
onShortName()19     SkString onShortName() override { return SkString("batchedconvexpaths"); }
onISize()20     SkISize onISize() override { return SkISize::Make(512, 512); }
21 
modifyGrContextOptions(GrContextOptions * ctxOptions)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 
onDraw(SkCanvas * canvas,SkString * errorMsg)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 
57 DEF_GM( return new BatchedConvexPathsGM; )
58 
59 }  // namespace skiagm
60