Debian Codegraph @

gm/preservefillrule.cpp

raw
1 /*
2 * Copyright 2019 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/SkPath.h"
11 #include "src/core/SkCanvasPriv.h"
12 #include "tools/ToolUtils.h"
13
14 #if defined(SK_GANESH)
15 #include "include/gpu/ganesh/GrContextOptions.h"
16 #include "include/gpu/ganesh/GrDirectContext.h"
17 #endif
18
19 namespace skiagm {
20
21 /**
22 * This test originally ensured that the ccpr path cache preserved fill rules properly. CCPR is gone
23 * now, but we decided to keep the test.
24 */
25 class PreserveFillRuleGM : public GM {
26 public:
27 PreserveFillRuleGM(bool big) : fBig(big) , fStarSize((big) ? 200 : 20) {}
28
29 private:
30 SkString getName() const override {
31 SkString name("preservefillrule");
32 name += (fBig) ? "_big" : "_little";
33 return name;
34 }
35 SkISize getISize() override { return SkISize::Make(fStarSize * 2, fStarSize * 2); }
36
37 #if defined(SK_GANESH)
38 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
39 ctxOptions->fAllowPathMaskCaching = true;
40 }
41 #endif
42
43 void onDraw(SkCanvas* canvas) override {
44 auto starRect = SkRect::MakeWH(fStarSize, fStarSize);
45 SkPath star7_winding = ToolUtils::make_star(starRect, 7);
46 star7_winding.setFillType(SkPathFillType::kWinding);
47
48 SkPath star7_evenOdd = star7_winding.makeTransform(SkMatrix::Translate(0, fStarSize))
49 .makeFillType(SkPathFillType::kEvenOdd);
50
51 SkPath star5_winding = ToolUtils::make_star(starRect, 5)
52 .makeTransform(SkMatrix::Translate(fStarSize, 0))
53 .makeFillType(SkPathFillType::kWinding);
54
55 SkPath star5_evenOdd = star5_winding.makeTransform(SkMatrix::Translate(0, fStarSize))
56 .makeFillType(SkPathFillType::kEvenOdd);
57
58 SkPaint paint;
59 paint.setColor(SK_ColorGREEN);
60 paint.setAntiAlias(true);
61
62 canvas->clear(SK_ColorWHITE);
63 canvas->drawPath(star7_winding, paint);
64 canvas->drawPath(star7_evenOdd, paint);
65 canvas->drawPath(star5_winding, paint);
66 canvas->drawPath(star5_evenOdd, paint);
67
68 #if defined(SK_GANESH)
69 if (auto dContext = GrAsDirectContext(canvas->recordingContext())) {
70 dContext->flush();
71 }
72 #endif
73 }
74
75 private:
76 const bool fBig;
77 const int fStarSize;
78 };
79
80 DEF_GM( return new PreserveFillRuleGM(true); )
81 DEF_GM( return new PreserveFillRuleGM(false); )
82
83 } // namespace skiagm