2014-12-17 19:22:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-05-01 21:28:53 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkClipOp.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2020-08-03 15:02:20 +00:00
|
|
|
#include "include/core/SkPathBuilder.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2014-12-17 19:22:37 +00:00
|
|
|
|
2018-06-18 19:11:00 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2014-12-17 19:22:37 +00:00
|
|
|
namespace skiagm {
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkColor gPathColor = SK_ColorYELLOW;
|
2014-12-17 19:22:37 +00:00
|
|
|
|
|
|
|
class ComplexClip3GM : public GM {
|
|
|
|
public:
|
|
|
|
ComplexClip3GM(bool doSimpleClipFirst)
|
|
|
|
: fDoSimpleClipFirst(doSimpleClipFirst) {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2014-12-17 19:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2020-07-21 21:03:56 +00:00
|
|
|
SkString onShortName() override {
|
2014-12-17 19:22:37 +00:00
|
|
|
SkString str;
|
|
|
|
str.printf("complexclip3_%s", fDoSimpleClipFirst ? "simple" : "complex");
|
|
|
|
return str;
|
2016-03-29 16:03:52 +00:00
|
|
|
}
|
2014-12-17 19:22:37 +00:00
|
|
|
|
2020-07-21 21:03:56 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(400, 950); }
|
2014-12-17 19:22:37 +00:00
|
|
|
|
2020-07-21 21:03:56 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2020-08-03 15:02:20 +00:00
|
|
|
SkPath clipSimple = SkPath::Circle(70, 50, 20);
|
2014-12-17 19:22:37 +00:00
|
|
|
|
|
|
|
SkRect r1 = { 10, 20, 70, 80 };
|
2020-08-03 15:02:20 +00:00
|
|
|
SkPath clipComplex = SkPathBuilder().moveTo(40, 50)
|
|
|
|
.arcTo(r1, 30, 300, false)
|
|
|
|
.close()
|
|
|
|
.detach();
|
2014-12-17 19:22:37 +00:00
|
|
|
|
|
|
|
SkPath* firstClip = &clipSimple;
|
|
|
|
SkPath* secondClip = &clipComplex;
|
|
|
|
if (!fDoSimpleClipFirst) {
|
2020-08-03 15:02:20 +00:00
|
|
|
std::swap(firstClip, secondClip);
|
2014-12-17 19:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2019-01-05 21:35:13 +00:00
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 20);
|
2014-12-17 19:22:37 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr struct {
|
2016-12-09 14:00:50 +00:00
|
|
|
SkClipOp fOp;
|
|
|
|
const char* fName;
|
2014-12-17 19:22:37 +00:00
|
|
|
} gOps[] = {
|
2021-08-03 17:08:50 +00:00
|
|
|
{SkClipOp::kIntersect, "I"},
|
|
|
|
{SkClipOp::kDifference, "D" },
|
2014-12-17 19:22:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
canvas->scale(3 * SK_Scalar1 / 4, 3 * SK_Scalar1 / 4);
|
|
|
|
|
|
|
|
SkPaint pathPaint;
|
|
|
|
pathPaint.setAntiAlias(true);
|
|
|
|
pathPaint.setColor(gPathColor);
|
|
|
|
|
|
|
|
for (int invA = 0; invA < 2; ++invA) {
|
|
|
|
for (int aaBits = 0; aaBits < 4; ++aaBits) {
|
|
|
|
canvas->save();
|
|
|
|
for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); ++op) {
|
|
|
|
for (int invB = 0; invB < 2; ++invB) {
|
|
|
|
bool doAAA = SkToBool(aaBits & 1);
|
|
|
|
bool doAAB = SkToBool(aaBits & 2);
|
|
|
|
bool doInvA = SkToBool(invA);
|
|
|
|
bool doInvB = SkToBool(invB);
|
|
|
|
canvas->save();
|
|
|
|
// set clip
|
2019-11-26 17:17:17 +00:00
|
|
|
firstClip->setFillType(doInvA ? SkPathFillType::kInverseEvenOdd :
|
|
|
|
SkPathFillType::kEvenOdd);
|
|
|
|
secondClip->setFillType(doInvB ? SkPathFillType::kInverseEvenOdd :
|
|
|
|
SkPathFillType::kEvenOdd);
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipPath(*firstClip, doAAA);
|
2014-12-17 19:22:37 +00:00
|
|
|
canvas->clipPath(*secondClip, gOps[op].fOp, doAAB);
|
|
|
|
|
|
|
|
// draw rect clipped
|
|
|
|
SkRect r = { 0, 0, 100, 100 };
|
|
|
|
canvas->drawRect(r, pathPaint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
|
|
|
|
SkScalar txtX = SkIntToScalar(10);
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
SkString str;
|
|
|
|
str.printf("%s%s %s %s%s", doAAA ? "A" : "B",
|
|
|
|
doInvA ? "I" : "N",
|
|
|
|
gOps[op].fName,
|
|
|
|
doAAB ? "A" : "B",
|
|
|
|
doInvB ? "I" : "N");
|
|
|
|
|
2019-01-05 21:35:13 +00:00
|
|
|
canvas->drawString(str.c_str(), txtX, SkIntToScalar(130), font, paint);
|
2014-12-17 19:22:37 +00:00
|
|
|
if (doInvB) {
|
|
|
|
canvas->translate(SkIntToScalar(150),0);
|
|
|
|
} else {
|
|
|
|
canvas->translate(SkIntToScalar(120),0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fDoSimpleClipFirst;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2014-12-17 19:22:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Simple clip first
|
|
|
|
DEF_GM( return new ComplexClip3GM(true); )
|
|
|
|
// Complex clip first
|
|
|
|
DEF_GM( return new ComplexClip3GM(false); )
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|