1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "gm.h" 9 #include "SkCanvas.h" 10 #include "SkPath.h" 11 12 namespace skiagm { 13 14 class CircularClipsGM : public GM { 15 public: 16 CircularClipsGM() {} 17 18 protected: 19 virtual SkString onShortName() { 20 return SkString("circular-clips"); 21 } 22 23 virtual SkISize onISize() { 24 return SkISize::Make(800, 600); 25 } 26 27 virtual void onDraw(SkCanvas* canvas) { 28 SkRegion::Op ops[] = { 29 SkRegion::kDifference_Op, 30 SkRegion::kIntersect_Op, 31 SkRegion::kUnion_Op, 32 SkRegion::kXOR_Op, 33 SkRegion::kReverseDifference_Op, 34 SkRegion::kReplace_Op, 35 }; 36 37 SkScalar x1 = 80, x2 = 120; 38 SkScalar y = 50; 39 SkScalar r = 40; 40 41 SkPath circle1, circle2; 42 circle1.addCircle(x1, y, r, SkPath::kCW_Direction); 43 circle2.addCircle(x2, y, r, SkPath::kCW_Direction); 44 SkRect rect = SkRect::MakeLTRB(x1 - r, y - r, x2 + r, y + r); 45 46 SkPaint fillPaint; 47 48 for (size_t i = 0; i < 4; i++) { 49 circle1.toggleInverseFillType(); 50 if (i % 2 == 0) { 51 circle2.toggleInverseFillType(); 52 } 53 54 canvas->save(); 55 for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) { 56 canvas->save(); 57 58 canvas->clipPath(circle1, SkRegion::kReplace_Op); 59 canvas->clipPath(circle2, ops[op]); 60 61 canvas->drawRect(rect, fillPaint); 62 63 canvas->restore(); 64 canvas->translate(0, 2 * y); 65 } 66 canvas->restore(); 67 canvas->translate(x1 + x2, 0); 68 } 69 } 70 71 private: 72 typedef GM INHERITED; 73 }; 74 75 ////////////////////////////////////////////////////////////////////////////// 76 77 DEF_GM( return new CircularClipsGM; ) 78 } 79