blob: 2b559d17cb453215b05e76286d1ce891202cbf59 [file] [log] [blame]
Chris Dalton5b5403e2019-06-05 11:54:39 -06001/*
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"
Chris Dalton5b5403e2019-06-05 11:54:39 -060011#include "include/gpu/GrContextOptions.h"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040012#include "include/gpu/GrRecordingContext.h"
Robert Phillips7a0d3c32021-07-21 15:39:51 -040013#include "src/core/SkCanvasPriv.h"
Adlai Hollera0693042020-10-14 11:23:11 -040014#include "src/gpu/GrDirectContextPriv.h"
Chris Dalton5b5403e2019-06-05 11:54:39 -060015#include "src/gpu/GrDrawingManager.h"
Robert Phillips95c250c2020-06-29 15:36:12 -040016#include "src/gpu/GrRecordingContextPriv.h"
Robert Phillips4dca8312021-07-28 15:13:20 -040017#include "src/gpu/v1/SurfaceDrawContext_v1.h"
Chris Dalton5b5403e2019-06-05 11:54:39 -060018#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/**
Chris Dalton03730e62021-03-11 19:41:40 -070033 * This test originally ensured that the ccpr path cache preserved fill rules properly. CCRP is gone
34 * now, but we decided to keep the test.
Chris Dalton5b5403e2019-06-05 11:54:39 -060035 */
36class PreserveFillRuleGM : public GpuGM {
37public:
Chris Dalton03730e62021-03-11 19:41:40 -070038 PreserveFillRuleGM(bool big) : fBig(big) , fStarSize((big) ? 200 : 20) {}
Chris Dalton5b5403e2019-06-05 11:54:39 -060039
40private:
41 SkString onShortName() override {
42 SkString name("preservefillrule");
Chris Dalton03730e62021-03-11 19:41:40 -070043 name += (fBig) ? "_big" : "_little";
Chris Dalton5b5403e2019-06-05 11:54:39 -060044 return name;
45 }
46 SkISize onISize() override { return SkISize::Make(fStarSize * 2, fStarSize * 2); }
47
48 void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
Chris Dalton5b5403e2019-06-05 11:54:39 -060049 ctxOptions->fAllowPathMaskCaching = true;
50 }
51
Robert Phillips7a0d3c32021-07-21 15:39:51 -040052 DrawResult onDraw(GrRecordingContext* rContext, SkCanvas* canvas, SkString* errorMsg) override {
Robert Phillips27f283f2020-10-14 11:46:51 -040053 auto dContext = GrAsDirectContext(rContext);
John Stilesab7ff172021-07-30 10:59:25 -040054 auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas);
55 if (!dContext || !sfc) {
Robert Phillips267826c2020-11-10 11:10:09 -050056 *errorMsg = "Requires a direct context.";
57 return skiagm::DrawResult::kSkip;
58 }
Robert Phillips27f283f2020-10-14 11:46:51 -040059
Chris Dalton5b5403e2019-06-05 11:54:39 -060060 auto starRect = SkRect::MakeWH(fStarSize, fStarSize);
61 SkPath star7_winding = ToolUtils::make_star(starRect, 7);
Mike Reed7d34dc72019-11-26 12:17:17 -050062 star7_winding.setFillType(SkPathFillType::kWinding);
Chris Dalton5b5403e2019-06-05 11:54:39 -060063
64 SkPath star7_evenOdd = star7_winding;
Mike Reed1f607332020-05-21 12:11:27 -040065 star7_evenOdd.transform(SkMatrix::Translate(0, fStarSize));
Mike Reed7d34dc72019-11-26 12:17:17 -050066 star7_evenOdd.setFillType(SkPathFillType::kEvenOdd);
Chris Dalton5b5403e2019-06-05 11:54:39 -060067
68 SkPath star5_winding = ToolUtils::make_star(starRect, 5);
Mike Reed1f607332020-05-21 12:11:27 -040069 star5_winding.transform(SkMatrix::Translate(fStarSize, 0));
Mike Reed7d34dc72019-11-26 12:17:17 -050070 star5_winding.setFillType(SkPathFillType::kWinding);
Chris Dalton5b5403e2019-06-05 11:54:39 -060071
72 SkPath star5_evenOdd = star5_winding;
Mike Reed1f607332020-05-21 12:11:27 -040073 star5_evenOdd.transform(SkMatrix::Translate(0, fStarSize));
Mike Reed7d34dc72019-11-26 12:17:17 -050074 star5_evenOdd.setFillType(SkPathFillType::kEvenOdd);
Chris Dalton5b5403e2019-06-05 11:54:39 -060075
76 SkPaint paint;
77 paint.setColor(SK_ColorGREEN);
78 paint.setAntiAlias(true);
79
Chris Dalton03730e62021-03-11 19:41:40 -070080 canvas->clear(SK_ColorWHITE);
81 canvas->drawPath(star7_winding, paint);
82 canvas->drawPath(star7_evenOdd, paint);
83 canvas->drawPath(star5_winding, paint);
84 canvas->drawPath(star5_evenOdd, paint);
Robert Phillips7a0d3c32021-07-21 15:39:51 -040085 dContext->priv().flushSurface(sfc->asSurfaceProxy());
Chris Dalton5b5403e2019-06-05 11:54:39 -060086
87 return DrawResult::kOk;
88 }
89
90private:
Chris Dalton03730e62021-03-11 19:41:40 -070091 const bool fBig;
Chris Dalton5b5403e2019-06-05 11:54:39 -060092 const int fStarSize;
93};
94
95DEF_GM( return new PreserveFillRuleGM(true); )
96DEF_GM( return new PreserveFillRuleGM(false); )
97
John Stilesa6841be2020-08-06 14:11:56 -040098} // namespace skiagm