Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
preservefillrule.cpp
Go to the documentation of this file.
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"
18#include "tools/ToolUtils.h"
19
20namespace skiagm {
21
22#define ERR_MSG_ASSERT(COND) \
23 do { \
24 if (!(COND)) { \
25 errorMsg->printf("preservefillrule.cpp(%i): assert(%s)", \
26 __LINE__, #COND); \
27 return DrawResult::kFail; \
28 } \
29 } while (false)
30
31
32/**
33 * This test originally ensured that the ccpr path cache preserved fill rules properly. CCPR is gone
34 * now, but we decided to keep the test.
35 */
36class PreserveFillRuleGM : public GM {
37public:
38 PreserveFillRuleGM(bool big) : fBig(big) , fStarSize((big) ? 200 : 20) {}
39
40private:
41 SkString getName() const override {
42 SkString name("preservefillrule");
43 name += (fBig) ? "_big" : "_little";
44 return name;
45 }
46 SkISize getISize() override { return SkISize::Make(fStarSize * 2, fStarSize * 2); }
47
48 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
49 ctxOptions->fAllowPathMaskCaching = true;
50 }
51
52 void onDraw(SkCanvas* canvas) override {
53 auto starRect = SkRect::MakeWH(fStarSize, fStarSize);
54 SkPath star7_winding = ToolUtils::make_star(starRect, 7);
56
57 SkPath star7_evenOdd = star7_winding;
58 star7_evenOdd.transform(SkMatrix::Translate(0, fStarSize));
60
61 SkPath star5_winding = ToolUtils::make_star(starRect, 5);
62 star5_winding.transform(SkMatrix::Translate(fStarSize, 0));
64
65 SkPath star5_evenOdd = star5_winding;
66 star5_evenOdd.transform(SkMatrix::Translate(0, fStarSize));
68
70 paint.setColor(SK_ColorGREEN);
71 paint.setAntiAlias(true);
72
73 canvas->clear(SK_ColorWHITE);
74 canvas->drawPath(star7_winding, paint);
75 canvas->drawPath(star7_evenOdd, paint);
76 canvas->drawPath(star5_winding, paint);
77 canvas->drawPath(star5_evenOdd, paint);
78
79 auto dContext = GrAsDirectContext(canvas->recordingContext());
80 if (dContext) {
81 dContext->flush();
82 }
83 }
84
85private:
86 const bool fBig;
87 const int fStarSize;
88};
89
90DEF_GM( return new PreserveFillRuleGM(true); )
91DEF_GM( return new PreserveFillRuleGM(false); )
92
93} // namespace skiagm
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
virtual GrRecordingContext * recordingContext() const
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
void setFillType(SkPathFillType ft)
Definition SkPath.h:235
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition SkPath.cpp:1647
SkString getName() const override
void modifyGrContextOptions(GrContextOptions *ctxOptions) override
void onDraw(SkCanvas *canvas) override
const Paint & paint
const char * name
Definition fuchsia.cc:50
#define DEF_GM(CODE)
Definition gm.h:40
SkPath make_star(const SkRect &bounds, int numPts, int step)
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609