aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/circularclips.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-08 02:52:05 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-08 02:52:05 +0000
commitd2623a1a0bcd23801c86a7d3f352b5e1f1c2e195 (patch)
treefd886d61ad79bfb5ffa1d25ee017696d5a60aa8d /gm/circularclips.cpp
parentb265741cc17f897b349caacdb890119e4111a415 (diff)
Use Path Ops to generate PDF clips
R=vandebo@chromium.org, edisonn@google.com, caryclark@google.com Author: richardlin@chromium.org Review URL: https://chromiumcodereview.appspot.com/21161003 git-svn-id: http://skia.googlecode.com/svn/trunk@10633 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/circularclips.cpp')
-rw-r--r--gm/circularclips.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/gm/circularclips.cpp b/gm/circularclips.cpp
new file mode 100644
index 0000000000..fdf2dfb4f3
--- /dev/null
+++ b/gm/circularclips.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2013 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 {
+
+class CircularClipsGM : public GM {
+public:
+ CircularClipsGM() {}
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("circular-clips");
+ }
+
+ virtual SkISize onISize() {
+ return SkISize::Make(800, 600);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ SkRegion::Op ops[] = {
+ SkRegion::kDifference_Op,
+ SkRegion::kIntersect_Op,
+ SkRegion::kUnion_Op,
+ SkRegion::kXOR_Op,
+ SkRegion::kReverseDifference_Op,
+ SkRegion::kReplace_Op,
+ };
+
+ SkScalar x1 = 80, x2 = 120;
+ SkScalar y = 50;
+ SkScalar r = 40;
+
+ SkPath circle1, circle2;
+ circle1.addCircle(x1, y, r, SkPath::kCW_Direction);
+ circle2.addCircle(x2, y, r, SkPath::kCW_Direction);
+ SkRect rect = SkRect::MakeLTRB(x1 - r, y - r, x2 + r, y + r);
+
+ SkPaint fillPaint;
+
+ for (size_t i = 0; i < 4; i++) {
+ circle1.toggleInverseFillType();
+ if (i % 2 == 0) {
+ circle2.toggleInverseFillType();
+ }
+
+ canvas->save();
+ for (size_t op = 0; op < SK_ARRAY_COUNT(ops); op++) {
+ canvas->save();
+
+ canvas->clipPath(circle1, SkRegion::kReplace_Op);
+ canvas->clipPath(circle2, ops[op]);
+
+ canvas->drawRect(rect, fillPaint);
+
+ canvas->restore();
+ canvas->translate(0, 2 * y);
+ }
+ canvas->restore();
+ canvas->translate(x1 + x2, 0);
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return new CircularClipsGM; )
+}