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.
|
|
|
|
*/
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
|
|
|
|
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) {
|
2015-06-15 13:51:08 +00:00
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
2014-12-17 19:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() {
|
|
|
|
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
|
|
|
|
|
|
|
SkISize onISize() { return SkISize::Make(1000, 950); }
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkPath clipSimple;
|
|
|
|
clipSimple.addCircle(SkIntToScalar(70), SkIntToScalar(50), SkIntToScalar(20));
|
|
|
|
|
|
|
|
SkRect r1 = { 10, 20, 70, 80 };
|
|
|
|
SkPath clipComplex;
|
|
|
|
clipComplex.moveTo(SkIntToScalar(40), SkIntToScalar(50));
|
|
|
|
clipComplex.arcTo(r1, SkIntToScalar(30), SkIntToScalar(300), false);
|
|
|
|
clipComplex.close();
|
|
|
|
|
|
|
|
SkPath* firstClip = &clipSimple;
|
|
|
|
SkPath* secondClip = &clipComplex;
|
|
|
|
|
|
|
|
if (!fDoSimpleClipFirst) {
|
|
|
|
SkTSwap<SkPath*>(firstClip, secondClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2015-07-24 19:09:25 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
2014-12-17 19:22:37 +00:00
|
|
|
paint.setTextSize(SkIntToScalar(20));
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr struct {
|
2016-09-20 15:42:38 +00:00
|
|
|
SkCanvas::ClipOp fOp;
|
|
|
|
const char* fName;
|
2014-12-17 19:22:37 +00:00
|
|
|
} gOps[] = {
|
2016-09-20 15:42:38 +00:00
|
|
|
{SkCanvas::kIntersect_Op, "I"},
|
|
|
|
{SkCanvas::kDifference_Op, "D" },
|
|
|
|
{SkCanvas::kUnion_Op, "U"},
|
|
|
|
{SkCanvas::kXOR_Op, "X" },
|
|
|
|
{SkCanvas::kReverseDifference_Op, "R"}
|
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
|
|
|
|
firstClip->setFillType(doInvA ? SkPath::kInverseEvenOdd_FillType :
|
|
|
|
SkPath::kEvenOdd_FillType);
|
|
|
|
secondClip->setFillType(doInvB ? SkPath::kInverseEvenOdd_FillType :
|
|
|
|
SkPath::kEvenOdd_FillType);
|
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");
|
|
|
|
|
|
|
|
canvas->drawText(str.c_str(), strlen(str.c_str()), txtX, SkIntToScalar(130),
|
|
|
|
paint);
|
|
|
|
if (doInvB) {
|
|
|
|
canvas->translate(SkIntToScalar(150),0);
|
|
|
|
} else {
|
|
|
|
canvas->translate(SkIntToScalar(120),0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fDoSimpleClipFirst;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Simple clip first
|
|
|
|
DEF_GM( return new ComplexClip3GM(true); )
|
|
|
|
// Complex clip first
|
|
|
|
DEF_GM( return new ComplexClip3GM(false); )
|
|
|
|
}
|