From ea5e676a7b75600edcde3912886486004ccd7626 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Thu, 2 Mar 2017 20:22:35 +0000 Subject: Revert "Remove SkDraw from device-draw methods, and enable device-centric clipping." This reverts commit c77e33f73d3e86cfabf925d6f2e1166f81022575. Reason for revert: breaks isClipRect - this CL inspected the conservative clip for this, which is (by definition) a rect - probably need to query the device for this info Original change's description: > Remove SkDraw from device-draw methods, and enable device-centric clipping. > > BUG=skia:6214 > > Change-Id: I593900724310d09133ae4791ef68d38c43762fc2 > Reviewed-on: https://skia-review.googlesource.com/8806 > Reviewed-by: Brian Salomon > Commit-Queue: Mike Reed > TBR=bsalomon@google.com,halcanary@google.com,msarett@google.com,robertphillips@google.com,fmalita@chromium.org,reed@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia:6214 Change-Id: I9090cbbb9f45b2dd204d9fdc187de2ff714b93f6 Reviewed-on: https://skia-review.googlesource.com/9172 Reviewed-by: Mike Reed Commit-Queue: Mike Reed --- src/core/SkDevice.cpp | 85 ++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 41 deletions(-) (limited to 'src/core/SkDevice.cpp') diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index fad73e9961..cd3bf502c7 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -71,36 +71,35 @@ static inline bool is_int(float x) { return x == (float) sk_float_round2int(x); } -void SkBaseDevice::drawRegion(const SkRegion& region, const SkPaint& paint) { - const SkMatrix& ctm = this->ctm(); - bool isNonTranslate = ctm.getType() & ~(SkMatrix::kTranslate_Mask); +void SkBaseDevice::drawRegion(const SkDraw& draw, const SkRegion& region, const SkPaint& paint) { + bool isNonTranslate = draw.fMatrix->getType() & ~(SkMatrix::kTranslate_Mask); bool complexPaint = paint.getStyle() != SkPaint::kFill_Style || paint.getMaskFilter() || paint.getPathEffect(); - bool antiAlias = paint.isAntiAlias() && (!is_int(ctm.getTranslateX()) || - !is_int(ctm.getTranslateY())); + bool antiAlias = paint.isAntiAlias() && (!is_int(draw.fMatrix->getTranslateX()) || + !is_int(draw.fMatrix->getTranslateY())); if (isNonTranslate || complexPaint || antiAlias) { SkPath path; region.getBoundaryPath(&path); - return this->drawPath(path, paint, nullptr, false); + return this->drawPath(draw, path, paint, nullptr, false); } SkRegion::Iterator it(region); while (!it.done()) { - this->drawRect(SkRect::Make(it.rect()), paint); + this->drawRect(draw, SkRect::Make(it.rect()), paint); it.next(); } } -void SkBaseDevice::drawArc(const SkRect& oval, SkScalar startAngle, +void SkBaseDevice::drawArc(const SkDraw& draw, const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint& paint) { SkPath path; bool isFillNoPathEffect = SkPaint::kFill_Style == paint.getStyle() && !paint.getPathEffect(); SkPathPriv::CreateDrawArcPath(&path, oval, startAngle, sweepAngle, useCenter, isFillNoPathEffect); - this->drawPath(path, paint); + this->drawPath(draw, path, paint); } -void SkBaseDevice::drawDRRect(const SkRRect& outer, +void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { SkPath path; path.addRRect(outer); @@ -110,25 +109,25 @@ void SkBaseDevice::drawDRRect(const SkRRect& outer, const SkMatrix* preMatrix = nullptr; const bool pathIsMutable = true; - this->drawPath(path, paint, preMatrix, pathIsMutable); + this->drawPath(draw, path, paint, preMatrix, pathIsMutable); } -void SkBaseDevice::drawPatch(const SkPoint cubics[12], const SkColor colors[4], +void SkBaseDevice::drawPatch(const SkDraw& draw, const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode bmode, const SkPaint& paint) { SkPatchUtils::VertexData data; - SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &this->ctm()); + SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, draw.fMatrix); // It automatically adjusts lodX and lodY in case it exceeds the number of indices. // If it fails to generate the vertices, then we do not draw. if (SkPatchUtils::getVertexData(&data, cubics, colors, texCoords, lod.width(), lod.height())) { - this->drawVertices(SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints, + this->drawVertices(draw, SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints, data.fTexCoords, data.fColors, bmode, data.fIndices, data.fIndexCount, paint); } } -void SkBaseDevice::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, +void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint &paint, SkDrawFilter* drawFilter) { SkPaint runPaint = paint; @@ -151,14 +150,14 @@ void SkBaseDevice::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, switch (it.positioning()) { case SkTextBlob::kDefault_Positioning: - this->drawText(it.glyphs(), textLen, x + offset.x(), y + offset.y(), runPaint); + this->drawText(draw, it.glyphs(), textLen, x + offset.x(), y + offset.y(), runPaint); break; case SkTextBlob::kHorizontal_Positioning: - this->drawPosText(it.glyphs(), textLen, it.pos(), 1, + this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()), runPaint); break; case SkTextBlob::kFull_Positioning: - this->drawPosText(it.glyphs(), textLen, it.pos(), 2, + this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 2, SkPoint::Make(x, y), runPaint); break; default: @@ -172,66 +171,66 @@ void SkBaseDevice::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, } } -void SkBaseDevice::drawImage(const SkImage* image, SkScalar x, SkScalar y, +void SkBaseDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x, SkScalar y, const SkPaint& paint) { SkBitmap bm; if (as_IB(image)->getROPixels(&bm, this->imageInfo().colorSpace())) { - this->drawBitmap(bm, SkMatrix::MakeTrans(x, y), paint); + this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); } } -void SkBaseDevice::drawImageRect(const SkImage* image, const SkRect* src, +void SkBaseDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src, const SkRect& dst, const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { SkBitmap bm; if (as_IB(image)->getROPixels(&bm, this->imageInfo().colorSpace())) { - this->drawBitmapRect(bm, src, dst, paint, constraint); + this->drawBitmapRect(draw, bm, src, dst, paint, constraint); } } -void SkBaseDevice::drawImageNine(const SkImage* image, const SkIRect& center, +void SkBaseDevice::drawImageNine(const SkDraw& draw, const SkImage* image, const SkIRect& center, const SkRect& dst, const SkPaint& paint) { SkLatticeIter iter(image->width(), image->height(), center, dst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { - this->drawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); + this->drawImageRect(draw, image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); } } -void SkBaseDevice::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, +void SkBaseDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, const SkPaint& paint) { SkLatticeIter iter(bitmap.width(), bitmap.height(), center, dst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { - this->drawBitmapRect(bitmap, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); + this->drawBitmapRect(draw, bitmap, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); } } -void SkBaseDevice::drawImageLattice(const SkImage* image, +void SkBaseDevice::drawImageLattice(const SkDraw& draw, const SkImage* image, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint& paint) { SkLatticeIter iter(lattice, dst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { - this->drawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); + this->drawImageRect(draw, image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); } } -void SkBaseDevice::drawBitmapLattice(const SkBitmap& bitmap, +void SkBaseDevice::drawBitmapLattice(const SkDraw& draw, const SkBitmap& bitmap, const SkCanvas::Lattice& lattice, const SkRect& dst, const SkPaint& paint) { SkLatticeIter iter(lattice, dst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { - this->drawBitmapRect(bitmap, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); + this->drawBitmapRect(draw, bitmap, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint); } } -void SkBaseDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[], +void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkBlendMode mode, const SkPaint& paint) { SkPath path; @@ -261,23 +260,23 @@ void SkBaseDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[], path.rewind(); path.addPoly(quad, 4, true); path.setConvexity(SkPath::kConvex_Convexity); - this->drawPath(path, pnt, nullptr, true); + this->drawPath(draw, path, pnt, nullptr, true); } } -void SkBaseDevice::drawVerticesObject(sk_sp vertices, +void SkBaseDevice::drawVerticesObject(const SkDraw& draw, sk_sp vertices, SkBlendMode mode, const SkPaint& paint, uint32_t flags) { const SkPoint* texs = (flags & SkCanvas::kIgnoreTexCoords_VerticesFlag) ? nullptr : vertices->texCoords(); const SkColor* colors = (flags & SkCanvas::kIgnoreColors_VerticesFlag) ? nullptr : vertices->colors(); - this->drawVertices(vertices->mode(), vertices->vertexCount(), vertices->positions(), texs, + this->drawVertices(draw, vertices->mode(), vertices->vertexCount(), vertices->positions(), texs, colors, mode, vertices->indices(), vertices->indexCount(), paint); } /////////////////////////////////////////////////////////////////////////////////////////////////// -void SkBaseDevice::drawSpecial(SkSpecialImage*, int x, int y, const SkPaint&) {} +void SkBaseDevice::drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) {} sk_sp SkBaseDevice::makeSpecial(const SkBitmap&) { return nullptr; } sk_sp SkBaseDevice::makeSpecial(const SkImage*) { return nullptr; } sk_sp SkBaseDevice::snapSpecial() { return nullptr; } @@ -393,13 +392,13 @@ static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas, } } -void SkBaseDevice::drawTextOnPath(const void* text, size_t byteLength, +void SkBaseDevice::drawTextOnPath(const SkDraw& draw, const void* text, size_t byteLength, const SkPath& follow, const SkMatrix* matrix, const SkPaint& paint) { SkASSERT(byteLength == 0 || text != nullptr); // nothing to draw - if (text == nullptr || byteLength == 0) { + if (text == nullptr || byteLength == 0 || draw.fRC->isEmpty()) { return; } @@ -434,7 +433,7 @@ void SkBaseDevice::drawTextOnPath(const void* text, size_t byteLength, m.postConcat(*matrix); } morphpath(&tmp, *iterPath, meas, m); - this->drawPath(tmp, iter.getPaint(), nullptr, true); + this->drawPath(draw, tmp, iter.getPaint(), nullptr, true); } } } @@ -449,7 +448,7 @@ static int count_utf16(const char* text) { static int return_4(const char* text) { return 4; } static int return_2(const char* text) { return 2; } -void SkBaseDevice::drawTextRSXform(const void* text, size_t len, +void SkBaseDevice::drawTextRSXform(const SkDraw& draw, const void* text, size_t len, const SkRSXform xform[], const SkPaint& paint) { CountTextProc proc = nullptr; switch (paint.getTextEncoding()) { @@ -467,15 +466,19 @@ void SkBaseDevice::drawTextRSXform(const void* text, size_t len, break; } + SkDraw localD(draw); SkMatrix localM, currM; const void* stopText = (const char*)text + len; while ((const char*)text < (const char*)stopText) { localM.setRSXform(*xform++); - currM.setConcat(this->ctm(), localM); + currM.setConcat(*draw.fMatrix, localM); + localD.fMatrix = &currM; +#ifdef SK_USE_DEVICE_CLIPPING SkAutoDeviceCTMRestore adc(this, currM); +#endif int subLen = proc((const char*)text); - this->drawText(text, subLen, 0, 0, paint); + this->drawText(localD, text, subLen, 0, 0, paint); text = (const char*)text + subLen; } } -- cgit v1.2.3