diff options
author | reed <reed@google.com> | 2016-04-27 07:49:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-27 07:49:17 -0700 |
commit | 1e7f5e708e5daeb0c18ae49001c9e3cd5e3b13cb (patch) | |
tree | c012c4ab0679914ca494e3ccceac6ce2242faed2 /src/pdf | |
parent | 4b6566644f704cf9e30c71fa547c9b5915752792 (diff) |
remove 'deprecated' region from SkDraw
Most call-sites that used it just took its bounds, so it was trivial to convert them
to get the bounds of the RasterClip. Two clients wanted the actual region:
1. layeriter for android
2. pdf
Android already only has BW clips, so should be safe.
PDF now overrides its clip methods to ensure that all clips are BW.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1925693002
Review URL: https://codereview.chromium.org/1925693002
Diffstat (limited to 'src/pdf')
-rw-r--r-- | src/pdf/SkPDFCanvas.cpp | 17 | ||||
-rw-r--r-- | src/pdf/SkPDFCanvas.h | 7 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 33 |
3 files changed, 41 insertions, 16 deletions
diff --git a/src/pdf/SkPDFCanvas.cpp b/src/pdf/SkPDFCanvas.cpp index de3dc93528..f3ba66b57a 100644 --- a/src/pdf/SkPDFCanvas.cpp +++ b/src/pdf/SkPDFCanvas.cpp @@ -14,6 +14,23 @@ SkPDFCanvas::SkPDFCanvas(const sk_sp<SkPDFDevice>& dev) SkPDFCanvas::~SkPDFCanvas() {} +/* + * PDF's impl sometimes wants to access the raster clip as a SkRegion. To keep this valid, + * we intercept all clip calls to ensure that the clip stays BW (i.e. never antialiased), since + * an antialiased clip won't build a SkRegion (it builds SkAAClip). + */ +void SkPDFCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { + this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle); +} + +void SkPDFCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { + this->INHERITED::onClipRRect(rrect, op, kHard_ClipEdgeStyle); +} + +void SkPDFCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { + this->INHERITED::onClipPath(path, op, kHard_ClipEdgeStyle); +} + void SkPDFCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, diff --git a/src/pdf/SkPDFCanvas.h b/src/pdf/SkPDFCanvas.h index 3a673e22b3..1c3ec715b7 100644 --- a/src/pdf/SkPDFCanvas.h +++ b/src/pdf/SkPDFCanvas.h @@ -17,6 +17,10 @@ public: ~SkPDFCanvas(); protected: + void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override; + void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override; + void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override; + void onDrawBitmapNine(const SkBitmap&, const SkIRect&, const SkRect&, const SkPaint*) override; @@ -34,6 +38,9 @@ protected: const SkRect&, const SkPaint*, SkCanvas::SrcRectConstraint) override; + +private: + typedef SkCanvas INHERITED; }; #endif // SkPDFCanvas_DEFINED diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index fb4d2510b7..5b4ae93504 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -567,7 +567,7 @@ public: fContentEntry(nullptr), fXfermode(SkXfermode::kSrcOver_Mode), fDstFormXObject(nullptr) { - init(draw.fClipStack, *draw.fClip, *draw.fMatrix, paint, hasText); + init(draw.fClipStack, draw.fRC->bwRgn(), *draw.fMatrix, paint, hasText); } ScopedContentEntry(SkPDFDevice* device, const SkClipStack* clipStack, const SkRegion& clipRegion, const SkMatrix& matrix, @@ -752,7 +752,7 @@ void SkPDFDevice::drawPoints(const SkDraw& d, // We only use this when there's a path effect because of the overhead // of multiple calls to setUpContentEntry it causes. if (passedPaint.getPathEffect()) { - if (d.fClip->isEmpty()) { + if (d.fRC->isEmpty()) { return; } SkDraw pointDraw(d); @@ -876,7 +876,7 @@ void SkPDFDevice::drawRect(const SkDraw& d, r.sort(); if (paint.getPathEffect()) { - if (d.fClip->isEmpty()) { + if (d.fRC->isEmpty()) { return; } SkPath path; @@ -938,7 +938,7 @@ void SkPDFDevice::drawPath(const SkDraw& d, } if (paint.getPathEffect()) { - if (d.fClip->isEmpty()) { + if (d.fRC->isEmpty()) { return; } if (!pathIsMutable) { @@ -963,7 +963,7 @@ void SkPDFDevice::drawPath(const SkDraw& d, return; } - ScopedContentEntry content(this, d.fClipStack, *d.fClip, matrix, paint); + ScopedContentEntry content(this, d.fClipStack, d.fRC->bwRgn(), matrix, paint); if (!content.entry()) { return; } @@ -996,7 +996,7 @@ void SkPDFDevice::drawBitmap(const SkDraw& d, replace_srcmode_on_opaque_paint(&paint); } - if (d.fClip->isEmpty()) { + if (d.fRC->isEmpty()) { return; } @@ -1004,7 +1004,7 @@ void SkPDFDevice::drawBitmap(const SkDraw& d, transform.postConcat(*d.fMatrix); SkImageBitmap imageBitmap(bitmap); this->internalDrawImage( - transform, d.fClipStack, *d.fClip, imageBitmap, paint); + transform, d.fClipStack, d.fRC->bwRgn(), imageBitmap, paint); } void SkPDFDevice::drawSprite(const SkDraw& d, @@ -1017,7 +1017,7 @@ void SkPDFDevice::drawSprite(const SkDraw& d, replace_srcmode_on_opaque_paint(&paint); } - if (d.fClip->isEmpty()) { + if (d.fRC->isEmpty()) { return; } @@ -1025,7 +1025,7 @@ void SkPDFDevice::drawSprite(const SkDraw& d, matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); SkImageBitmap imageBitmap(bitmap); this->internalDrawImage( - matrix, d.fClipStack, *d.fClip, imageBitmap, paint); + matrix, d.fClipStack, d.fRC->bwRgn(), imageBitmap, paint); } void SkPDFDevice::drawImage(const SkDraw& draw, @@ -1040,14 +1040,14 @@ void SkPDFDevice::drawImage(const SkDraw& draw, if (image->isOpaque()) { replace_srcmode_on_opaque_paint(&paint); } - if (draw.fClip->isEmpty()) { + if (draw.fRC->isEmpty()) { return; } SkMatrix transform = SkMatrix::MakeTrans(x, y); transform.postConcat(*draw.fMatrix); SkImageBitmap imageBitmap(const_cast<SkImage*>(image)); this->internalDrawImage( - transform, draw.fClipStack, *draw.fClip, imageBitmap, paint); + transform, draw.fClipStack, draw.fRC->bwRgn(), imageBitmap, paint); } void SkPDFDevice::drawImageRect(const SkDraw& draw, @@ -1277,7 +1277,7 @@ void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, const SkPoint texs[], const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint& paint) { - if (d.fClip->isEmpty()) { + if (d.fRC->isEmpty()) { return; } // TODO: implement drawVertices @@ -1309,7 +1309,7 @@ void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, SkMatrix matrix; matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); - ScopedContentEntry content(this, d.fClipStack, *d.fClip, matrix, paint); + ScopedContentEntry content(this, d.fClipStack, d.fRC->bwRgn(), matrix, paint); if (!content.entry()) { return; } @@ -1434,7 +1434,7 @@ bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath, return false; } - if (d.fClip->isEmpty()) { + if (d.fRC->isEmpty()) { return false; } @@ -1470,7 +1470,7 @@ bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath, if (!totalMatrix.invert(&transformInverse)) { return false; } - bounds.set(d.fClip->getBounds()); + bounds.set(d.fRC->getBounds()); transformInverse.mapRect(&bounds); // Extend the bounds by the line width (plus some padding) @@ -1758,9 +1758,10 @@ void SkPDFDevice::finishContentEntry(SkXfermode::Mode xfermode, SkPDFFormXObject* dstMask = srcFormXObject.get(); if (shape != nullptr) { // Draw shape into a form-xobject. + SkRasterClip rc(clipRegion); SkDraw d; d.fMatrix = &identity; - d.fClip = &clipRegion; + d.fRC = &rc; d.fClipStack = &clipStack; SkPaint filledPaint; filledPaint.setColor(SK_ColorBLACK); |