aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/pathopsskpclip.cpp
diff options
context:
space:
mode:
authorGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-25 13:34:40 +0000
committerGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-25 13:34:40 +0000
commit45a75fb4d0ca5daa0ac5e634238970306e3b5838 (patch)
tree20ec83c238e15edc4e76f57b54030cb671abf864 /gm/pathopsskpclip.cpp
parent32c1b66a2c4f26935ba59f3afe3e81600fade78d (diff)
path ops : make it real
Add an option to SkCanvas to turn on path ops when combining clips. Allow Op() to use one of the input paths as an output path. Fix a bug in Op() when the minuend is empty and the subtrahend is not (for difference). Change the build to allow core to depend on pathops. Review URL: https://codereview.chromium.org/14474002 git-svn-id: http://skia.googlecode.com/svn/trunk@8855 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/pathopsskpclip.cpp')
-rw-r--r--gm/pathopsskpclip.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/gm/pathopsskpclip.cpp b/gm/pathopsskpclip.cpp
new file mode 100644
index 0000000000..b85b294fef
--- /dev/null
+++ b/gm/pathopsskpclip.cpp
@@ -0,0 +1,73 @@
+/*
+ * 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 "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkClipStack.h"
+#include "SkDevice.h"
+#include "SkPath.h"
+#include "SkPathOps.h"
+#include "SkPicture.h"
+#include "SkRect.h"
+
+namespace skiagm {
+
+class PathOpsSkpClipGM : public GM {
+public:
+ PathOpsSkpClipGM() {
+ }
+
+protected:
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("pathopsskpclip");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return make_isize(1200, 900);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkPicture* pict = SkNEW(SkPicture);
+ SkCanvas* rec = pict->beginRecording(1200, 900);
+ SkPath p;
+ SkRect r = {
+ SkIntToScalar(100),
+ SkIntToScalar(200),
+ SkIntToScalar(400),
+ SkIntToScalar(700)
+ };
+ p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50));
+ rec->clipPath(p, SkRegion::kIntersect_Op, true);
+ rec->translate(SkIntToScalar(250), SkIntToScalar(250));
+ rec->clipPath(p, SkRegion::kIntersect_Op, true);
+ rec->drawColor(0xffff0000);
+ pict->endRecording();
+
+ canvas->setAllowSimplifyClip(true);
+ canvas->save();
+ canvas->drawPicture(*pict);
+ canvas->restore();
+
+ canvas->setAllowSimplifyClip(false);
+ canvas->save();
+ canvas->translate(SkIntToScalar(1200 / 2), 0);
+ canvas->drawPicture(*pict);
+ canvas->restore();
+ SkSafeUnref(pict);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new PathOpsSkpClipGM; }
+static GMRegistry reg(MyFactory);
+
+}