2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "sk_tool_utils.h"
14 constexpr SkColor gPathColor = SK_ColorYELLOW;
16 class ComplexClip3GM : public GM {
18 ComplexClip3GM(bool doSimpleClipFirst)
19 : fDoSimpleClipFirst(doSimpleClipFirst) {
20 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
25 SkString onShortName() {
27 str.printf("complexclip3_%s", fDoSimpleClipFirst ? "simple" : "complex");
31 SkISize onISize() { return SkISize::Make(1000, 950); }
33 virtual void onDraw(SkCanvas* canvas) {
35 clipSimple.addCircle(SkIntToScalar(70), SkIntToScalar(50), SkIntToScalar(20));
37 SkRect r1 = { 10, 20, 70, 80 };
39 clipComplex.moveTo(SkIntToScalar(40), SkIntToScalar(50));
40 clipComplex.arcTo(r1, SkIntToScalar(30), SkIntToScalar(300), false);
43 SkPath* firstClip = &clipSimple;
44 SkPath* secondClip = &clipComplex;
46 if (!fDoSimpleClipFirst) {
47 SkTSwap<SkPath*>(firstClip, secondClip);
51 paint.setAntiAlias(true);
52 sk_tool_utils::set_portable_typeface(&paint);
53 paint.setTextSize(SkIntToScalar(20));
59 {kIntersect_SkClipOp, "I"},
60 {kDifference_SkClipOp, "D" },
61 {kUnion_SkClipOp, "U"},
62 {kXOR_SkClipOp, "X" },
63 {kReverseDifference_SkClipOp, "R"}
66 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
67 canvas->scale(3 * SK_Scalar1 / 4, 3 * SK_Scalar1 / 4);
70 pathPaint.setAntiAlias(true);
71 pathPaint.setColor(gPathColor);
73 for (int invA = 0; invA < 2; ++invA) {
74 for (int aaBits = 0; aaBits < 4; ++aaBits) {
76 for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); ++op) {
77 for (int invB = 0; invB < 2; ++invB) {
78 bool doAAA = SkToBool(aaBits & 1);
79 bool doAAB = SkToBool(aaBits & 2);
80 bool doInvA = SkToBool(invA);
81 bool doInvB = SkToBool(invB);
84 firstClip->setFillType(doInvA ? SkPath::kInverseEvenOdd_FillType :
85 SkPath::kEvenOdd_FillType);
86 secondClip->setFillType(doInvB ? SkPath::kInverseEvenOdd_FillType :
87 SkPath::kEvenOdd_FillType);
88 canvas->clipPath(*firstClip, doAAA);
89 canvas->clipPath(*secondClip, gOps[op].fOp, doAAB);
92 SkRect r = { 0, 0, 100, 100 };
93 canvas->drawRect(r, pathPaint);
97 SkScalar txtX = SkIntToScalar(10);
98 paint.setColor(SK_ColorBLACK);
100 str.printf("%s%s %s %s%s", doAAA ? "A" : "B",
106 canvas->drawString(str.c_str(), txtX, SkIntToScalar(130), paint);
108 canvas->translate(SkIntToScalar(150),0);
110 canvas->translate(SkIntToScalar(120),0);
115 canvas->translate(0, SkIntToScalar(150));
121 bool fDoSimpleClipFirst;
123 typedef GM INHERITED;
126 //////////////////////////////////////////////////////////////////////////////
129 DEF_GM( return new ComplexClip3GM(true); )
130 // Complex clip first
131 DEF_GM( return new ComplexClip3GM(false); )