move SkClipStack::asPath into PDFUtils
bug: skia:9734
Change-Id: I115c990c1532ab6852fe23956591878a04b3edc6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261282
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Hal Canary <halcanary@google.com>
diff --git a/src/utils/SkClipStackUtils.cpp b/src/utils/SkClipStackUtils.cpp
new file mode 100644
index 0000000..00b9336
--- /dev/null
+++ b/src/utils/SkClipStackUtils.cpp
@@ -0,0 +1,29 @@
+/*
+* Copyright 2019 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#include "include/pathops/SkPathOps.h"
+#include "src/core/SkClipStack.h"
+
+void SkClipStack_AsPath(const SkClipStack& cs, SkPath* path) {
+ path->reset();
+ path->setFillType(SkPathFillType::kInverseEvenOdd);
+
+ SkClipStack::Iter iter(cs, SkClipStack::Iter::kBottom_IterStart);
+ while (const SkClipStack::Element* element = iter.next()) {
+ SkPath operand;
+ if (element->getDeviceSpaceType() != SkClipStack::Element::DeviceSpaceType::kEmpty) {
+ element->asDeviceSpacePath(&operand);
+ }
+
+ SkClipOp elementOp = element->getOp();
+ if (elementOp == kReplace_SkClipOp) {
+ *path = operand;
+ } else {
+ Op(*path, operand, (SkPathOp)elementOp, path);
+ }
+ }
+}