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 "include/gpu/GrContextOptions.h" 12 #include "include/gpu/GrRecordingContext.h" 13 #include "src/core/SkCanvasPriv.h" 14 #include "src/gpu/ganesh/GrDirectContextPriv.h" 15 #include "src/gpu/ganesh/GrDrawingManager.h" 16 #include "src/gpu/ganesh/GrRecordingContextPriv.h" 17 #include "src/gpu/ganesh/SurfaceDrawContext.h" 18 #include "tools/ToolUtils.h" 19 20 namespace 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 */ 36 class PreserveFillRuleGM : public GM { 37 public: PreserveFillRuleGM(bool big)38 PreserveFillRuleGM(bool big) : fBig(big) , fStarSize((big) ? 200 : 20) {} 39 40 private: onShortName()41 SkString onShortName() override { 42 SkString name("preservefillrule"); 43 name += (fBig) ? "_big" : "_little"; 44 return name; 45 } onISize()46 SkISize onISize() override { return SkISize::Make(fStarSize * 2, fStarSize * 2); } 47 modifyGrContextOptions(GrContextOptions * ctxOptions)48 void modifyGrContextOptions(GrContextOptions* ctxOptions) override { 49 ctxOptions->fAllowPathMaskCaching = true; 50 } 51 onDraw(SkCanvas * canvas)52 void onDraw(SkCanvas* canvas) override { 53 auto starRect = SkRect::MakeWH(fStarSize, fStarSize); 54 SkPath star7_winding = ToolUtils::make_star(starRect, 7); 55 star7_winding.setFillType(SkPathFillType::kWinding); 56 57 SkPath star7_evenOdd = star7_winding; 58 star7_evenOdd.transform(SkMatrix::Translate(0, fStarSize)); 59 star7_evenOdd.setFillType(SkPathFillType::kEvenOdd); 60 61 SkPath star5_winding = ToolUtils::make_star(starRect, 5); 62 star5_winding.transform(SkMatrix::Translate(fStarSize, 0)); 63 star5_winding.setFillType(SkPathFillType::kWinding); 64 65 SkPath star5_evenOdd = star5_winding; 66 star5_evenOdd.transform(SkMatrix::Translate(0, fStarSize)); 67 star5_evenOdd.setFillType(SkPathFillType::kEvenOdd); 68 69 SkPaint paint; 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 85 private: 86 const bool fBig; 87 const int fStarSize; 88 }; 89 90 DEF_GM( return new PreserveFillRuleGM(true); ) 91 DEF_GM( return new PreserveFillRuleGM(false); ) 92 93 } // namespace skiagm 94