2019-06-05 17:54:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google LLC.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm/gm.h"
|
|
|
|
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/gpu/GrContextOptions.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2021-07-21 19:39:51 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-06-05 17:54:39 +00:00
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
2020-06-29 19:36:12 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2021-07-28 19:13:20 +00:00
|
|
|
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
2019-06-05 17:54:39 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
#define ERR_MSG_ASSERT(COND) \
|
|
|
|
do { \
|
|
|
|
if (!(COND)) { \
|
|
|
|
errorMsg->printf("preservefillrule.cpp(%i): assert(%s)", \
|
|
|
|
__LINE__, #COND); \
|
|
|
|
return DrawResult::kFail; \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-12 02:41:40 +00:00
|
|
|
* This test originally ensured that the ccpr path cache preserved fill rules properly. CCRP is gone
|
|
|
|
* now, but we decided to keep the test.
|
2019-06-05 17:54:39 +00:00
|
|
|
*/
|
|
|
|
class PreserveFillRuleGM : public GpuGM {
|
|
|
|
public:
|
2021-03-12 02:41:40 +00:00
|
|
|
PreserveFillRuleGM(bool big) : fBig(big) , fStarSize((big) ? 200 : 20) {}
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkString onShortName() override {
|
|
|
|
SkString name("preservefillrule");
|
2021-03-12 02:41:40 +00:00
|
|
|
name += (fBig) ? "_big" : "_little";
|
2019-06-05 17:54:39 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
SkISize onISize() override { return SkISize::Make(fStarSize * 2, fStarSize * 2); }
|
|
|
|
|
|
|
|
void modifyGrContextOptions(GrContextOptions* ctxOptions) override {
|
|
|
|
ctxOptions->fAllowPathMaskCaching = true;
|
|
|
|
}
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DrawResult onDraw(GrRecordingContext* rContext, SkCanvas* canvas, SkString* errorMsg) override {
|
2020-10-14 15:46:51 +00:00
|
|
|
auto dContext = GrAsDirectContext(rContext);
|
2020-11-10 16:10:09 +00:00
|
|
|
if (!dContext) {
|
|
|
|
*errorMsg = "Requires a direct context.";
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
2020-10-14 15:46:51 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas);
|
|
|
|
|
2019-06-05 17:54:39 +00:00
|
|
|
auto starRect = SkRect::MakeWH(fStarSize, fStarSize);
|
|
|
|
SkPath star7_winding = ToolUtils::make_star(starRect, 7);
|
2019-11-26 17:17:17 +00:00
|
|
|
star7_winding.setFillType(SkPathFillType::kWinding);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
SkPath star7_evenOdd = star7_winding;
|
2020-05-21 16:11:27 +00:00
|
|
|
star7_evenOdd.transform(SkMatrix::Translate(0, fStarSize));
|
2019-11-26 17:17:17 +00:00
|
|
|
star7_evenOdd.setFillType(SkPathFillType::kEvenOdd);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
SkPath star5_winding = ToolUtils::make_star(starRect, 5);
|
2020-05-21 16:11:27 +00:00
|
|
|
star5_winding.transform(SkMatrix::Translate(fStarSize, 0));
|
2019-11-26 17:17:17 +00:00
|
|
|
star5_winding.setFillType(SkPathFillType::kWinding);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
SkPath star5_evenOdd = star5_winding;
|
2020-05-21 16:11:27 +00:00
|
|
|
star5_evenOdd.transform(SkMatrix::Translate(0, fStarSize));
|
2019-11-26 17:17:17 +00:00
|
|
|
star5_evenOdd.setFillType(SkPathFillType::kEvenOdd);
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2021-03-12 02:41:40 +00:00
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
canvas->drawPath(star7_winding, paint);
|
|
|
|
canvas->drawPath(star7_evenOdd, paint);
|
|
|
|
canvas->drawPath(star5_winding, paint);
|
|
|
|
canvas->drawPath(star5_evenOdd, paint);
|
2021-07-21 19:39:51 +00:00
|
|
|
dContext->priv().flushSurface(sfc->asSurfaceProxy());
|
2019-06-05 17:54:39 +00:00
|
|
|
|
|
|
|
return DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-03-12 02:41:40 +00:00
|
|
|
const bool fBig;
|
2019-06-05 17:54:39 +00:00
|
|
|
const int fStarSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM( return new PreserveFillRuleGM(true); )
|
|
|
|
DEF_GM( return new PreserveFillRuleGM(false); )
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|