2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
18 class ComplexClip2GM : public GM {
26 ComplexClip2GM(Clip clip, bool antiAlias)
28 , fAntiAlias(antiAlias) {
38 fTotalWidth = kCols * fWidth + SK_Scalar1 * (kCols + 1) * kPadX;
39 fTotalHeight = kRows * fHeight + SK_Scalar1 * (kRows + 1) * kPadY;
43 void onOnceBeforeDraw() override {
44 this->setBGColor(SkColorSetRGB(0xDD,0xA0,0xDD));
46 // offset the rects a bit so we get antialiasing even in the rect case
61 fRects[0].set(xB, yB, xE, yE);
62 fRRects[0].setRectXY(fRects[0], 7, 7);
63 fPaths[0].addRoundRect(fRects[0], 5, 5);
64 fRectColors[0] = SK_ColorRED;
66 fRects[1].set(xA, yA, xD, yD);
67 fRRects[1].setRectXY(fRects[1], 7, 7);
68 fPaths[1].addRoundRect(fRects[1], 5, 5);
69 fRectColors[1] = SK_ColorGREEN;
71 fRects[2].set(xC, yA, xF, yD);
72 fRRects[2].setRectXY(fRects[2], 7, 7);
73 fPaths[2].addRoundRect(fRects[2], 5, 5);
74 fRectColors[2] = SK_ColorBLUE;
76 fRects[3].set(xA, yC, xD, yF);
77 fRRects[3].setRectXY(fRects[3], 7, 7);
78 fPaths[3].addRoundRect(fRects[3], 5, 5);
79 fRectColors[3] = SK_ColorYELLOW;
81 fRects[4].set(xC, yC, xF, yF);
82 fRRects[4].setRectXY(fRects[4], 7, 7);
83 fPaths[4].addRoundRect(fRects[4], 5, 5);
84 fRectColors[4] = SK_ColorCYAN;
86 const SkClipOp ops[] = {
91 kReverseDifference_SkClipOp,
96 for (int i = 0; i < kRows; ++i) {
97 for (int j = 0; j < kCols; ++j) {
98 for (int k = 0; k < 5; ++k) {
99 fOps[j*kRows+i][k] = ops[r.nextU() % SK_ARRAY_COUNT(ops)];
105 static constexpr int kRows = 5;
106 static constexpr int kCols = 5;
107 static constexpr int kPadX = 20;
108 static constexpr int kPadY = 20;
110 static const char* ClipStr(Clip clip) {
119 SkDEBUGFAIL("Unknown clip type.");
123 SkString onShortName() override {
124 if (kRect_Clip == fClip && !fAntiAlias) {
125 return SkString("complexclip2");
129 str.printf("complexclip2_%s_%s",
131 fAntiAlias ? "aa" : "bw");
135 SkISize onISize() override {
136 return SkISize::Make(SkScalarRoundToInt(fTotalWidth),
137 SkScalarRoundToInt(fTotalHeight));
140 void onDraw(SkCanvas* canvas) override {
142 rectPaint.setStyle(SkPaint::kStroke_Style);
143 rectPaint.setStrokeWidth(-1);
146 fillPaint.setColor(SkColorSetRGB(0xA0,0xDD,0xA0));
148 for (int i = 0; i < kRows; ++i) {
149 for (int j = 0; j < kCols; ++j) {
152 canvas->translate(kPadX * SK_Scalar1 + (fWidth + kPadX * SK_Scalar1)*j,
153 kPadY * SK_Scalar1 + (fHeight + kPadY * SK_Scalar1)*i);
155 // draw the original shapes first so we can see the
156 // antialiasing on the clipped draw
157 for (int k = 0; k < 5; ++k) {
158 rectPaint.setColor(fRectColors[k]);
161 canvas->drawRect(fRects[k], rectPaint);
164 canvas->drawRRect(fRRects[k], rectPaint);
167 canvas->drawPath(fPaths[k], rectPaint);
172 for (int k = 0; k < 5; ++k) {
175 canvas->clipRect(fRects[k],
180 canvas->clipRRect(fRRects[k],
185 canvas->clipPath(fPaths[k],
191 canvas->drawRect(SkRect::MakeWH(fWidth, fHeight), fillPaint);
202 SkColor fRectColors[5];
203 SkClipOp fOps[kRows * kCols][5];
206 SkScalar fTotalWidth;
207 SkScalar fTotalHeight;
209 typedef GM INHERITED;
212 //////////////////////////////////////////////////////////////////////////////
215 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, false); )
216 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, false); )
217 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, false); )
220 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, true); )
221 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, true); )
222 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, true); )