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.
16 class ComplexClip2GM : public GM {
24 ComplexClip2GM(Clip clip, bool antiAlias)
26 , fAntiAlias(antiAlias) {
36 fTotalWidth = kCols * fWidth + SK_Scalar1 * (kCols + 1) * kPadX;
37 fTotalHeight = kRows * fHeight + SK_Scalar1 * (kRows + 1) * kPadY;
41 void onOnceBeforeDraw() SK_OVERRIDE {
42 this->setBGColor(SkColorSetRGB(0xDD,0xA0,0xDD));
44 // offset the rects a bit so we get antialiasing even in the rect case
59 fRects[0].set(xB, yB, xE, yE);
60 fRRects[0].setRectXY(fRects[0], 7, 7);
61 fPaths[0].addRoundRect(fRects[0], 5, 5);
62 fRectColors[0] = SK_ColorRED;
64 fRects[1].set(xA, yA, xD, yD);
65 fRRects[1].setRectXY(fRects[1], 7, 7);
66 fPaths[1].addRoundRect(fRects[1], 5, 5);
67 fRectColors[1] = SK_ColorGREEN;
69 fRects[2].set(xC, yA, xF, yD);
70 fRRects[2].setRectXY(fRects[2], 7, 7);
71 fPaths[2].addRoundRect(fRects[2], 5, 5);
72 fRectColors[2] = SK_ColorBLUE;
74 fRects[3].set(xA, yC, xD, yF);
75 fRRects[3].setRectXY(fRects[3], 7, 7);
76 fPaths[3].addRoundRect(fRects[3], 5, 5);
77 fRectColors[3] = SK_ColorYELLOW;
79 fRects[4].set(xC, yC, xF, yF);
80 fRRects[4].setRectXY(fRects[4], 7, 7);
81 fPaths[4].addRoundRect(fRects[4], 5, 5);
82 fRectColors[4] = SK_ColorCYAN;
84 SkRegion::Op ops[] = {
85 SkRegion::kDifference_Op,
86 SkRegion::kIntersect_Op,
89 SkRegion::kReverseDifference_Op,
90 SkRegion::kReplace_Op,
94 for (int i = 0; i < kRows; ++i) {
95 for (int j = 0; j < kCols; ++j) {
96 for (int k = 0; k < 5; ++k) {
97 fOps[j*kRows+i][k] = ops[r.nextU() % SK_ARRAY_COUNT(ops)];
103 static const int kRows = 5;
104 static const int kCols = 5;
105 static const int kPadX = 20;
106 static const int kPadY = 20;
108 static const char* ClipStr(Clip clip) {
117 SkDEBUGFAIL("Unknown clip type.");
121 virtual SkString onShortName() {
122 if (kRect_Clip == fClip && !fAntiAlias) {
123 return SkString("complexclip2");
127 str.printf("complexclip2_%s_%s",
129 fAntiAlias ? "aa" : "bw");
133 virtual SkISize onISize() {
134 return SkISize::Make(SkScalarRoundToInt(fTotalWidth),
135 SkScalarRoundToInt(fTotalHeight));
138 virtual void onDraw(SkCanvas* canvas) {
140 rectPaint.setStyle(SkPaint::kStroke_Style);
141 rectPaint.setStrokeWidth(-1);
144 fillPaint.setColor(SkColorSetRGB(0xA0,0xDD,0xA0));
146 for (int i = 0; i < kRows; ++i) {
147 for (int j = 0; j < kCols; ++j) {
150 canvas->translate(kPadX * SK_Scalar1 + (fWidth + kPadX * SK_Scalar1)*j,
151 kPadY * SK_Scalar1 + (fHeight + kPadY * SK_Scalar1)*i);
153 // draw the original shapes first so we can see the
154 // antialiasing on the clipped draw
155 for (int k = 0; k < 5; ++k) {
156 rectPaint.setColor(fRectColors[k]);
159 canvas->drawRect(fRects[k], rectPaint);
162 canvas->drawRRect(fRRects[k], rectPaint);
165 canvas->drawPath(fPaths[k], rectPaint);
170 for (int k = 0; k < 5; ++k) {
173 canvas->clipRect(fRects[k],
178 canvas->clipRRect(fRRects[k],
183 canvas->clipPath(fPaths[k],
189 canvas->drawRect(SkRect::MakeWH(fWidth, fHeight), fillPaint);
200 SkColor fRectColors[5];
201 SkRegion::Op fOps[kRows * kCols][5];
204 SkScalar fTotalWidth;
205 SkScalar fTotalHeight;
207 typedef GM INHERITED;
210 //////////////////////////////////////////////////////////////////////////////
213 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, false); )
214 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, false); )
215 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, false); )
218 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRect_Clip, true); )
219 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kRRect_Clip, true); )
220 DEF_GM( return new ComplexClip2GM(ComplexClip2GM::kPath_Clip, true); )