diff options
-rw-r--r-- | bench/CoverageBench.cpp | 1 | ||||
-rw-r--r-- | include/core/SkCanvas.h | 3 | ||||
-rw-r--r-- | include/core/SkDraw.h | 5 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 7 | ||||
-rw-r--r-- | src/core/SkDevice.cpp | 2 | ||||
-rw-r--r-- | src/core/SkDraw.cpp | 2 | ||||
-rw-r--r-- | src/core/SkRasterClip.cpp | 24 | ||||
-rw-r--r-- | src/core/SkRasterClip.h | 17 | ||||
-rw-r--r-- | src/core/SkScalerContext.cpp | 1 | ||||
-rw-r--r-- | src/effects/SkLayerRasterizer.cpp | 1 | ||||
-rw-r--r-- | src/gpu/GrSWMaskHelper.cpp | 1 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 19 | ||||
-rw-r--r-- | src/gpu/batches/GrAADistanceFieldPathRenderer.cpp | 1 | ||||
-rw-r--r-- | src/pdf/SkPDFCanvas.cpp | 17 | ||||
-rw-r--r-- | src/pdf/SkPDFCanvas.h | 7 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 33 | ||||
-rw-r--r-- | src/utils/SkCanvasStateUtils.cpp | 3 | ||||
-rw-r--r-- | src/xps/SkXPSDevice.cpp | 19 | ||||
-rw-r--r-- | tests/AAClipTest.cpp | 28 | ||||
-rw-r--r-- | tests/CanvasTest.cpp | 3 |
20 files changed, 118 insertions, 76 deletions
diff --git a/bench/CoverageBench.cpp b/bench/CoverageBench.cpp index ebde4208a0..e1b53f879d 100644 --- a/bench/CoverageBench.cpp +++ b/bench/CoverageBench.cpp @@ -40,7 +40,6 @@ public: fDraw.fDst = fPixmap; fDraw.fMatrix = &fIdentity; - fDraw.fClip = &fRC.bwRgn(); fDraw.fRC = &fRC; } diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 611603715b..4853d35cef 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -32,6 +32,7 @@ class SkMetaData; class SkPath; class SkPicture; class SkPixmap; +class SkRasterClip; class SkRRect; struct SkRSXform; class SkSurface; @@ -1259,7 +1260,7 @@ protected: SkBaseDevice* device() const; const SkMatrix& matrix() const; - const SkRegion& clip() const; + const SkRasterClip& clip() const; const SkPaint& paint() const; int x() const; int y() const; diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h index e3cb1aca9c..96a4fc7ad7 100644 --- a/include/core/SkDraw.h +++ b/include/core/SkDraw.h @@ -145,11 +145,10 @@ private: public: SkPixmap fDst; const SkMatrix* fMatrix; // required - const SkRegion* fClip; // DEPRECATED const SkRasterClip* fRC; // required - const SkClipStack* fClipStack; // optional - SkBaseDevice* fDevice; // optional + const SkClipStack* fClipStack; // optional, may be null + SkBaseDevice* fDevice; // optional, may be null #ifdef SK_DEBUG void validate() const; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 905849254c..6c4cd27250 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -349,7 +349,6 @@ public: if (rec && rec->fDevice) { fMatrix = rec->fMatrix; - fClip = &((SkRasterClip*)&rec->fClip)->forceGetBW(); fRC = &rec->fClip; fDevice = rec->fDevice; if (!fDevice->accessPixels(&fDst)) { @@ -367,10 +366,10 @@ public: } SkBaseDevice* getDevice() const { return fDevice; } + const SkRasterClip& getClip() const { return *fRC; } int getX() const { return fDevice->getOrigin().x(); } int getY() const { return fDevice->getOrigin().y(); } const SkMatrix& getMatrix() const { return *fMatrix; } - const SkRegion& getClip() const { return *fClip; } const SkPaint* getPaint() const { return fPaint; } private: @@ -2503,7 +2502,7 @@ void SkCanvas::DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, // nothing to draw if (text == nullptr || byteLength == 0 || - draw.fClip->isEmpty() || + draw.fRC->isEmpty() || (paint.getAlpha() == 0 && paint.getXfermode() == nullptr)) { return; } @@ -2994,7 +2993,7 @@ const SkPaint& SkCanvas::LayerIter::paint() const { return *paint; } -const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } +const SkRasterClip& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } int SkCanvas::LayerIter::x() const { return fImpl->getX(); } int SkCanvas::LayerIter::y() const { return fImpl->getY(); } diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 24118f4662..70f4e07431 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -412,7 +412,7 @@ void SkBaseDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitm SkIPoint offset = SkIPoint::Make(0, 0); SkMatrix matrix = *draw.fMatrix; matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); - const SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-x, -y); + const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y); SkAutoTUnref<SkImageFilter::Cache> cache(this->getImageFilterCache()); SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 232973488e..0cdd3a19dc 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -1965,7 +1965,6 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, void SkDraw::validate() const { SkASSERT(fMatrix != nullptr); - SkASSERT(fClip != nullptr); SkASSERT(fRC != nullptr); const SkIRect& cr = fRC->getBounds(); @@ -2041,7 +2040,6 @@ static void draw_into_mask(const SkMask& mask, const SkPath& devPath, SkPaint::S -SkIntToScalar(mask.fBounds.fTop)); draw.fRC = &clip; - draw.fClip = &clip.bwRgn(); draw.fMatrix = &matrix; paint.setAntiAlias(true); paint.setStyle(style); diff --git a/src/core/SkRasterClip.cpp b/src/core/SkRasterClip.cpp index 89467677f3..88bfbafc36 100644 --- a/src/core/SkRasterClip.cpp +++ b/src/core/SkRasterClip.cpp @@ -24,6 +24,14 @@ SkRasterClip::SkRasterClip(const SkRasterClip& src) { SkDEBUGCODE(this->validate();) } +SkRasterClip::SkRasterClip(const SkRegion& rgn) : fBW(rgn) { + fForceConservativeRects = false; + fIsBW = true; + fIsEmpty = this->computeIsEmpty(); // bounds might be empty, so compute + fIsRect = !fIsEmpty; + SkDEBUGCODE(this->validate();) +} + SkRasterClip::SkRasterClip(const SkIRect& bounds, bool forceConservativeRects) : fBW(bounds) { fForceConservativeRects = forceConservativeRects; fIsBW = true; @@ -44,6 +52,22 @@ SkRasterClip::~SkRasterClip() { SkDEBUGCODE(this->validate();) } +bool SkRasterClip::operator==(const SkRasterClip& other) const { + // This impl doesn't care if fForceConservativeRects is the same in both, only the current state + + if (fIsBW != other.fIsBW) { + return false; + } + bool isEqual = fIsBW ? fBW == other.fBW : fAA == other.fAA; +#ifdef SK_DEBUG + if (isEqual) { + SkASSERT(fIsEmpty == other.fIsEmpty); + SkASSERT(fIsRect == other.fIsRect); + } +#endif + return isEqual; +} + bool SkRasterClip::isComplex() const { return fIsBW ? fBW.isComplex() : !fAA.isEmpty(); } diff --git a/src/core/SkRasterClip.h b/src/core/SkRasterClip.h index 5d99f1dfab..14d34fdaf0 100644 --- a/src/core/SkRasterClip.h +++ b/src/core/SkRasterClip.h @@ -13,13 +13,30 @@ class SkRRect; +/** + * Wraps a SkRegion and SkAAClip, so we have a single object that can represent either our + * BW or antialiased clips. + * + * This class is optimized for the raster backend of canvas, but can be expense to keep up2date, + * so it supports a runtime option (force-conservative-rects) to turn it into a super-fast + * rect-only tracker. The gpu backend uses this since it does not need the result (it uses + * SkClipStack instead). + */ class SkRasterClip { public: SkRasterClip(bool forceConservativeRects = false); SkRasterClip(const SkIRect&, bool forceConservativeRects = false); + SkRasterClip(const SkRegion&); SkRasterClip(const SkRasterClip&); ~SkRasterClip(); + // Only compares the current state. Does not compare isForceConservativeRects(), so that field + // could be different but this could still return true. + bool operator==(const SkRasterClip&) const; + bool operator!=(const SkRasterClip& other) const { + return !(*this == other); + } + bool isForceConservativeRects() const { return fForceConservativeRects; } bool isBW() const { return fIsBW; } diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index ad753dfd21..85e8994f4f 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -402,7 +402,6 @@ static void generateMask(const SkMask& mask, const SkPath& path, SkDraw draw; draw.fDst = dst; draw.fRC = &clip; - draw.fClip = &clip.bwRgn(); draw.fMatrix = &matrix; draw.drawPath(path, paint); diff --git a/src/effects/SkLayerRasterizer.cpp b/src/effects/SkLayerRasterizer.cpp index 91502b7e84..39e3e231ef 100644 --- a/src/effects/SkLayerRasterizer.cpp +++ b/src/effects/SkLayerRasterizer.cpp @@ -129,7 +129,6 @@ bool SkLayerRasterizer::onRasterize(const SkPath& path, const SkMatrix& matrix, draw.fMatrix = &drawMatrix; draw.fRC = &rectClip; - draw.fClip = &rectClip.bwRgn(); // we set the matrixproc in the loop, as the matrix changes each time (potentially) SkDeque::F2BIter iter(*fLayers); diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp index 0e1fd3e61c..b69edab82c 100644 --- a/src/gpu/GrSWMaskHelper.cpp +++ b/src/gpu/GrSWMaskHelper.cpp @@ -215,7 +215,6 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds, fDraw.fDst = fPixels; fRasterClip.setRect(bounds); fDraw.fRC = &fRasterClip; - fDraw.fClip = &fRasterClip.bwRgn(); fDraw.fMatrix = &fMatrix; return true; } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index f6137de56e..535d55ee79 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -32,6 +32,7 @@ #include "SkPathEffect.h" #include "SkPicture.h" #include "SkPictureData.h" +#include "SkRasterClip.h" #include "SkRRect.h" #include "SkRecord.h" #include "SkStroke.h" @@ -515,7 +516,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, fClip, path, paint, *draw.fMatrix, nullptr, - draw.fClip->getBounds(), true); + draw.fRC->getBounds(), true); return; } @@ -553,12 +554,12 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, if (devRRect.allCornersCircular()) { SkRect maskRect; if (paint.getMaskFilter()->canFilterMaskGPU(devRRect, - draw.fClip->getBounds(), + draw.fRC->getBounds(), *draw.fMatrix, &maskRect)) { SkIRect finalIRect; maskRect.roundOut(&finalIRect); - if (draw.fClip->quickReject(finalIRect)) { + if (draw.fRC->quickReject(finalIRect)) { // clipped out return; } @@ -587,7 +588,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, fClip, path, paint, *draw.fMatrix, nullptr, - draw.fClip->getBounds(), true); + draw.fRC->getBounds(), true); return; } @@ -633,7 +634,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, fClip, path, paint, *draw.fMatrix, nullptr, - draw.fClip->getBounds(), true); + draw.fRC->getBounds(), true); } @@ -703,7 +704,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, fClip, origSrcPath, paint, *draw.fMatrix, prePathMatrix, - draw.fClip->getBounds(), pathIsMutable); + draw.fRC->getBounds(), pathIsMutable); } static const int kBmpSmallTileSize = 1 << 10; @@ -1676,7 +1677,7 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text, SkDEBUGCODE(this->validate();) fDrawContext->drawText(fClip, grPaint, paint, *draw.fMatrix, - (const char *)text, byteLength, x, y, draw.fClip->getBounds()); + (const char *)text, byteLength, x, y, draw.fRC->getBounds()); } void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteLength, @@ -1696,7 +1697,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL fDrawContext->drawPosText(fClip, grPaint, paint, *draw.fMatrix, (const char *)text, byteLength, pos, scalarsPerPos, offset, - draw.fClip->getBounds()); + draw.fRC->getBounds()); } void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y, @@ -1708,7 +1709,7 @@ void SkGpuDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca SkDEBUGCODE(this->validate();) fDrawContext->drawTextBlob(fClip, paint, *draw.fMatrix, - blob, x, y, drawFilter, draw.fClip->getBounds()); + blob, x, y, drawFilter, draw.fRC->getBounds()); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp index 655a77127e..f891b8d1f5 100644 --- a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp +++ b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp @@ -379,7 +379,6 @@ private: SkRasterClip rasterClip; rasterClip.setRect(devPathBounds); draw.fRC = &rasterClip; - draw.fClip = &rasterClip.bwRgn(); draw.fMatrix = &drawMatrix; draw.fDst = dst; 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); diff --git a/src/utils/SkCanvasStateUtils.cpp b/src/utils/SkCanvasStateUtils.cpp index 2c34d360d6..462636ead9 100644 --- a/src/utils/SkCanvasStateUtils.cpp +++ b/src/utils/SkCanvasStateUtils.cpp @@ -11,6 +11,7 @@ #include "SkCanvasStack.h" #include "SkDevice.h" #include "SkErrorInternals.h" +#include "SkRasterClip.h" #include "SkWriter32.h" /* @@ -250,7 +251,7 @@ SkCanvasState* SkCanvasStateUtils::CaptureCanvasState(SkCanvas* canvas) { layerState->raster.rowBytes = pmap.rowBytes(); layerState->raster.pixels = pmap.writable_addr(); - setup_MC_state(&layerState->mcState, layer.matrix(), layer.clip()); + setup_MC_state(&layerState->mcState, layer.matrix(), layer.clip().bwRgn()); layerCount++; } diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index febd0278ff..90fc68091c 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -35,6 +35,7 @@ #include "SkPathEffect.h" #include "SkPathOps.h" #include "SkPoint.h" +#include "SkRasterClip.h" #include "SkRasterizer.h" #include "SkSFNTHeader.h" #include "SkShader.h" @@ -1210,7 +1211,7 @@ void SkXPSDevice::internalDrawRect(const SkDraw& d, bool transformRect, const SkPaint& paint) { //Exit early if there is nothing to draw. - if (d.fClip->isEmpty() || + if (d.fRC->isEmpty() || (paint.getAlpha() == 0 && paint.getXfermode() == nullptr)) { return; } @@ -1526,7 +1527,7 @@ void SkXPSDevice::drawPath(const SkDraw& d, SkTCopyOnFirstWrite<SkPaint> paint(origPaint); // nothing to draw - if (d.fClip->isEmpty() || + if (d.fRC->isEmpty() || (paint->getAlpha() == 0 && paint->getXfermode() == nullptr)) { return; } @@ -1609,7 +1610,7 @@ void SkXPSDevice::drawPath(const SkDraw& d, this->convertToPpm(filter, &matrix, &ppuScale, - d.fClip->getBounds(), + d.fRC->getBounds(), &clipIRect); SkMask* mask = nullptr; @@ -1647,7 +1648,7 @@ void SkXPSDevice::drawPath(const SkDraw& d, this->convertToPpm(filter, &matrix, &ppuScale, - d.fClip->getBounds(), + d.fRC->getBounds(), &clipIRect); //[Fillable-path -> Pixel-path] @@ -1765,7 +1766,13 @@ void SkXPSDevice::drawPath(const SkDraw& d, HRESULT SkXPSDevice::clip(IXpsOMVisual* xpsVisual, const SkDraw& d) { SkPath clipPath; - SkAssertResult(d.fClip->getBoundaryPath(&clipPath)); + if (d.fRC->isBW()) { + SkAssertResult(d.fRC->bwRgn().getBoundaryPath(&clipPath)); + } else { + // Don't have a way to turn a AAClip into a path, so we just use the bounds. + // TODO: consider using fClipStack instead? + clipPath.addRect(SkRect::Make(d.fRC->getBounds())); + } return this->clipToPath(xpsVisual, clipPath, XPS_FILL_RULE_EVENODD); } @@ -1797,7 +1804,7 @@ HRESULT SkXPSDevice::clipToPath(IXpsOMVisual* xpsVisual, void SkXPSDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap, const SkMatrix& matrix, const SkPaint& paint) { - if (d.fClip->isEmpty()) { + if (d.fRC->isEmpty()) { return; } diff --git a/tests/AAClipTest.cpp b/tests/AAClipTest.cpp index 42c320cde1..438dab4da8 100644 --- a/tests/AAClipTest.cpp +++ b/tests/AAClipTest.cpp @@ -10,6 +10,7 @@ #include "SkMask.h" #include "SkPath.h" #include "SkRandom.h" +#include "SkRasterClip.h" #include "SkRRect.h" #include "Test.h" @@ -342,33 +343,6 @@ static void test_really_a_rect(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, clip.isRect()); } -#include "SkRasterClip.h" - -static void copyToMask(const SkRasterClip& rc, SkMask* mask) { - if (rc.isAA()) { - rc.aaRgn().copyToMask(mask); - } else { - copyToMask(rc.bwRgn(), mask); - } -} - -static bool operator==(const SkRasterClip& a, const SkRasterClip& b) { - if (a.isEmpty()) { - return b.isEmpty(); - } - if (b.isEmpty()) { - return false; - } - - SkMask ma, mb; - copyToMask(a, &ma); - copyToMask(b, &mb); - SkAutoMaskFreeImage aCleanUp(ma.fImage); - SkAutoMaskFreeImage bCleanUp(mb.fImage); - - return ma == mb; -} - static void did_dx_affect(skiatest::Reporter* reporter, const SkScalar dx[], size_t count, bool changed) { const SkIRect baseBounds = SkIRect::MakeXYWH(0, 0, 10, 10); diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index f22b7d0e25..1f217e21ca 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -55,6 +55,7 @@ #include "SkPicture.h" #include "SkPictureRecord.h" #include "SkPictureRecorder.h" +#include "SkRasterClip.h" #include "SkRect.h" #include "SkRegion.h" #include "SkShader.h" @@ -507,7 +508,7 @@ public: return false; } if (layerIter1.clip() != layerIter2.clip()) { - return false; + return false; } if (layerIter1.paint() != layerIter2.paint()) { return false; |