1 /* 2 * Copyright 2019 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 "src/utils/SkClipStackUtils.h" 9 10 #include "include/core/SkPath.h" 11 #include "include/core/SkPathTypes.h" 12 #include "include/pathops/SkPathOps.h" 13 #include "src/core/SkClipStack.h" 14 15 enum class SkClipOp; 16 SkClipStack_AsPath(const SkClipStack & cs,SkPath * path)17void SkClipStack_AsPath(const SkClipStack& cs, SkPath* path) { 18 path->reset(); 19 path->setFillType(SkPathFillType::kInverseEvenOdd); 20 21 SkClipStack::Iter iter(cs, SkClipStack::Iter::kBottom_IterStart); 22 while (const SkClipStack::Element* element = iter.next()) { 23 if (element->getDeviceSpaceType() == SkClipStack::Element::DeviceSpaceType::kShader) { 24 // TODO: Handle DeviceSpaceType::kShader somehow; it can't be turned into an SkPath 25 // but perhaps the pdf backend can apply shaders in another way. 26 continue; 27 } 28 SkPath operand; 29 if (element->getDeviceSpaceType() != SkClipStack::Element::DeviceSpaceType::kEmpty) { 30 element->asDeviceSpacePath(&operand); 31 } 32 33 SkClipOp elementOp = element->getOp(); 34 if (element->isReplaceOp()) { 35 *path = operand; 36 // TODO: Once expanding clip ops are removed, we can switch the iterator to be top 37 // to bottom, which allows us to break here on encountering a replace op. 38 } else { 39 Op(*path, operand, (SkPathOp)elementOp, path); 40 } 41 } 42 } 43