aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFDevice.cpp
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2018-03-09 12:16:42 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-09 21:06:30 +0000
commit4e83ff1aa746e4bfd0c6470713084cc6783c367f (patch)
tree049c63f537a259413848b8682383766beff27c5a /src/pdf/SkPDFDevice.cpp
parentbbfda2583f5bff3b9b0c76e0bdb132ff0cce7f8d (diff)
SkPDF: simplify PathOp code, emit empty clips.
BUG=skia:772685 Change-Id: Ia658551cadcfeb2777f4a6727b48ec9d9fc22dd8 Reviewed-on: https://skia-review.googlesource.com/113462 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src/pdf/SkPDFDevice.cpp')
-rw-r--r--src/pdf/SkPDFDevice.cpp66
1 files changed, 12 insertions, 54 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 91f170d194..01bd0a661e 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -209,8 +209,7 @@ public:
fEntries[0].fClipStack = existingClipStack;
}
- void updateClip(const SkClipStack& clipStack,
- const SkPoint& translation, const SkRect& bounds);
+ void updateClip(const SkClipStack& clipStack, const SkIRect& bounds);
void updateMatrix(const SkMatrix& matrix);
void updateDrawingState(const SkPDFDevice::GraphicStateEntry& state);
@@ -283,56 +282,11 @@ bool apply_clip(SkClipOp op, const SkPath& u, const SkPath& v, SkPath* r) {
}
}
-/* Uses Path Ops to calculate a vector SkPath clip from a clip stack.
- * Returns true if successful, or false if not successful.
- * If successful, the resulting clip is stored in outClipPath.
- * If not successful, outClipPath is undefined, and a fallback method
- * should be used.
- */
-static bool get_clip_stack_path(const SkMatrix& transform,
- const SkClipStack& clipStack,
- const SkRect& bounds,
- SkPath* outClipPath) {
- outClipPath->reset();
- outClipPath->setFillType(SkPath::kInverseWinding_FillType);
-
- const SkClipStack::Element* clipEntry;
- SkClipStack::Iter iter;
- iter.reset(clipStack, SkClipStack::Iter::kBottom_IterStart);
- for (clipEntry = iter.next(); clipEntry; clipEntry = iter.next()) {
- SkPath entryPath;
- if (SkClipStack::Element::DeviceSpaceType::kEmpty == clipEntry->getDeviceSpaceType()) {
- outClipPath->reset();
- outClipPath->setFillType(SkPath::kInverseWinding_FillType);
- continue;
- } else {
- clipEntry->asDeviceSpacePath(&entryPath);
- }
- entryPath.transform(transform);
- if (!apply_clip(clipEntry->getOp(), *outClipPath, entryPath, outClipPath)) {
- return false;
- }
- }
-
- if (outClipPath->isInverseFillType()) {
- // The bounds are slightly outset to ensure this is correct in the
- // face of floating-point accuracy and possible SkRegion bitmap
- // approximations.
- SkRect clipBounds = bounds;
- clipBounds.outset(SK_Scalar1, SK_Scalar1);
- if (!calculate_inverse_path(clipBounds, *outClipPath, outClipPath)) {
- return false;
- }
- }
- return true;
-}
-
// TODO(vandebo): Take advantage of SkClipStack::getSaveCount(), the PDF
// graphic state stack, and the fact that we can know all the clips used
// on the page to optimize this.
void GraphicStackState::updateClip(const SkClipStack& clipStack,
- const SkPoint& translation,
- const SkRect& bounds) {
+ const SkIRect& bounds) {
if (clipStack == currentEntry()->fClipStack) {
return;
}
@@ -347,11 +301,16 @@ void GraphicStackState::updateClip(const SkClipStack& clipStack,
currentEntry()->fClipStack = clipStack;
- SkMatrix transform;
- transform.setTranslate(translation.fX, translation.fY);
-
SkPath clipPath;
- if (get_clip_stack_path(transform, clipStack, bounds, &clipPath)) {
+ (void)clipStack.asPath(&clipPath);
+
+ // The bounds are slightly outset to ensure this is correct in the
+ // face of floating-point accuracy and possible SkRegion bitmap
+ // approximations.
+ SkPath clipBoundsPath;
+ clipBoundsPath.addRect(SkRect::Make(bounds.makeOutset(1, 1)));
+
+ if (Op(clipPath, clipBoundsPath, kIntersect_SkPathOp, &clipPath)) {
SkPDFUtils::EmitPath(clipPath, SkPaint::kFill_Style, fContentStream);
SkPath::FillType clipFill = clipPath.getFillType();
NOT_IMPLEMENTED(clipFill == SkPath::kInverseEvenOdd_FillType, false);
@@ -1776,8 +1735,7 @@ std::unique_ptr<SkStreamAsset> SkPDFDevice::content() const {
GraphicStackState gsState(fExistingClipStack, &buffer);
for (const auto& entry : fContentEntries) {
- gsState.updateClip(entry.fState.fClipStack,
- {0, 0}, SkRect::Make(this->bounds()));
+ gsState.updateClip(entry.fState.fClipStack, this->bounds());
gsState.updateMatrix(entry.fState.fMatrix);
gsState.updateDrawingState(entry.fState);