aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkDevice.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-03-07 09:37:29 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-07 15:43:03 +0000
commita1361364e64138adda3dc5f71d50d7503838bb6d (patch)
tree13dd723a62883d7bf3e8d280a0a454fae02081a2 /src/core/SkDevice.cpp
parent467921e5e6479fe9cebba125657d8e33d89004ae (diff)
Revert[6] "Remove SkDraw from device-draw methods, and enable device-centric clipping.""""""
Previous failure was failure to detect that the clip wasn't wide-open when optimizing for retain-vs-discard in copy-on-write. gm:copy_on_write_retain detected this. Now fixed by adding new method to SkBaseDevice.h This reverts commit 27d07f0acb85eea4062075dfbe9148ce12d92c66. BUG=skia:6214 Change-Id: I532d16ec075a4525c2a550b1157bcec695dd8efd Reviewed-on: https://skia-review.googlesource.com/9341 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core/SkDevice.cpp')
-rw-r--r--src/core/SkDevice.cpp96
1 files changed, 52 insertions, 44 deletions
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index cd3bf502c7..7c5c2bfdeb 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -48,6 +48,17 @@ void SkBaseDevice::setGlobalCTM(const SkMatrix& ctm) {
}
}
+bool SkBaseDevice::clipIsWideOpen() const {
+ if (kRect_ClipType == this->onGetClipType()) {
+ SkRegion rgn;
+ this->onAsRgnClip(&rgn);
+ SkASSERT(rgn.isRect());
+ return rgn.getBounds() == SkIRect::MakeWH(this->width(), this->height());
+ } else {
+ return false;
+ }
+}
+
SkPixelGeometry SkBaseDevice::CreateInfo::AdjustGeometry(const SkImageInfo& info,
TileUsage tileUsage,
SkPixelGeometry geo,
@@ -71,35 +82,36 @@ static inline bool is_int(float x) {
return x == (float) sk_float_round2int(x);
}
-void SkBaseDevice::drawRegion(const SkDraw& draw, const SkRegion& region, const SkPaint& paint) {
- bool isNonTranslate = draw.fMatrix->getType() & ~(SkMatrix::kTranslate_Mask);
+void SkBaseDevice::drawRegion(const SkRegion& region, const SkPaint& paint) {
+ const SkMatrix& ctm = this->ctm();
+ bool isNonTranslate = ctm.getType() & ~(SkMatrix::kTranslate_Mask);
bool complexPaint = paint.getStyle() != SkPaint::kFill_Style || paint.getMaskFilter() ||
paint.getPathEffect();
- bool antiAlias = paint.isAntiAlias() && (!is_int(draw.fMatrix->getTranslateX()) ||
- !is_int(draw.fMatrix->getTranslateY()));
+ bool antiAlias = paint.isAntiAlias() && (!is_int(ctm.getTranslateX()) ||
+ !is_int(ctm.getTranslateY()));
if (isNonTranslate || complexPaint || antiAlias) {
SkPath path;
region.getBoundaryPath(&path);
- return this->drawPath(draw, path, paint, nullptr, false);
+ return this->drawPath(path, paint, nullptr, false);
}
SkRegion::Iterator it(region);
while (!it.done()) {
- this->drawRect(draw, SkRect::Make(it.rect()), paint);
+ this->drawRect(SkRect::Make(it.rect()), paint);
it.next();
}
}
-void SkBaseDevice::drawArc(const SkDraw& draw, const SkRect& oval, SkScalar startAngle,
+void SkBaseDevice::drawArc(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(draw, path, paint);
+ this->drawPath(path, paint);
}
-void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
+void SkBaseDevice::drawDRRect(const SkRRect& outer,
const SkRRect& inner, const SkPaint& paint) {
SkPath path;
path.addRRect(outer);
@@ -109,25 +121,25 @@ void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
const SkMatrix* preMatrix = nullptr;
const bool pathIsMutable = true;
- this->drawPath(draw, path, paint, preMatrix, pathIsMutable);
+ this->drawPath(path, paint, preMatrix, pathIsMutable);
}
-void SkBaseDevice::drawPatch(const SkDraw& draw, const SkPoint cubics[12], const SkColor colors[4],
+void SkBaseDevice::drawPatch(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, draw.fMatrix);
+ SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &this->ctm());
// 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(draw, SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints,
+ this->drawVertices(SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints,
data.fTexCoords, data.fColors, bmode, data.fIndices, data.fIndexCount,
paint);
}
}
-void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y,
+void SkBaseDevice::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint &paint, SkDrawFilter* drawFilter) {
SkPaint runPaint = paint;
@@ -150,14 +162,14 @@ void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSc
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
- this->drawText(draw, it.glyphs(), textLen, x + offset.x(), y + offset.y(), runPaint);
+ this->drawText(it.glyphs(), textLen, x + offset.x(), y + offset.y(), runPaint);
break;
case SkTextBlob::kHorizontal_Positioning:
- this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 1,
+ this->drawPosText(it.glyphs(), textLen, it.pos(), 1,
SkPoint::Make(x, y + offset.y()), runPaint);
break;
case SkTextBlob::kFull_Positioning:
- this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 2,
+ this->drawPosText(it.glyphs(), textLen, it.pos(), 2,
SkPoint::Make(x, y), runPaint);
break;
default:
@@ -171,66 +183,66 @@ void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSc
}
}
-void SkBaseDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x, SkScalar y,
+void SkBaseDevice::drawImage(const SkImage* image, SkScalar x, SkScalar y,
const SkPaint& paint) {
SkBitmap bm;
if (as_IB(image)->getROPixels(&bm, this->imageInfo().colorSpace())) {
- this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint);
+ this->drawBitmap(bm, SkMatrix::MakeTrans(x, y), paint);
}
}
-void SkBaseDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const SkRect* src,
+void SkBaseDevice::drawImageRect(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(draw, bm, src, dst, paint, constraint);
+ this->drawBitmapRect(bm, src, dst, paint, constraint);
}
}
-void SkBaseDevice::drawImageNine(const SkDraw& draw, const SkImage* image, const SkIRect& center,
+void SkBaseDevice::drawImageNine(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(draw, image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
+ this->drawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
}
}
-void SkBaseDevice::drawBitmapNine(const SkDraw& draw, const SkBitmap& bitmap, const SkIRect& center,
+void SkBaseDevice::drawBitmapNine(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(draw, bitmap, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
+ this->drawBitmapRect(bitmap, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
}
}
-void SkBaseDevice::drawImageLattice(const SkDraw& draw, const SkImage* image,
+void SkBaseDevice::drawImageLattice(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(draw, image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
+ this->drawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
}
}
-void SkBaseDevice::drawBitmapLattice(const SkDraw& draw, const SkBitmap& bitmap,
+void SkBaseDevice::drawBitmapLattice(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(draw, bitmap, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
+ this->drawBitmapRect(bitmap, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
}
}
-void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[],
+void SkBaseDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[],
const SkRect tex[], const SkColor colors[], int count,
SkBlendMode mode, const SkPaint& paint) {
SkPath path;
@@ -260,23 +272,23 @@ void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkR
path.rewind();
path.addPoly(quad, 4, true);
path.setConvexity(SkPath::kConvex_Convexity);
- this->drawPath(draw, path, pnt, nullptr, true);
+ this->drawPath(path, pnt, nullptr, true);
}
}
-void SkBaseDevice::drawVerticesObject(const SkDraw& draw, sk_sp<SkVertices> vertices,
+void SkBaseDevice::drawVerticesObject(sk_sp<SkVertices> 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(draw, vertices->mode(), vertices->vertexCount(), vertices->positions(), texs,
+ this->drawVertices(vertices->mode(), vertices->vertexCount(), vertices->positions(), texs,
colors, mode, vertices->indices(), vertices->indexCount(), paint);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-void SkBaseDevice::drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) {}
+void SkBaseDevice::drawSpecial(SkSpecialImage*, int x, int y, const SkPaint&) {}
sk_sp<SkSpecialImage> SkBaseDevice::makeSpecial(const SkBitmap&) { return nullptr; }
sk_sp<SkSpecialImage> SkBaseDevice::makeSpecial(const SkImage*) { return nullptr; }
sk_sp<SkSpecialImage> SkBaseDevice::snapSpecial() { return nullptr; }
@@ -392,13 +404,13 @@ static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas,
}
}
-void SkBaseDevice::drawTextOnPath(const SkDraw& draw, const void* text, size_t byteLength,
+void SkBaseDevice::drawTextOnPath(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 || draw.fRC->isEmpty()) {
+ if (text == nullptr || byteLength == 0) {
return;
}
@@ -433,7 +445,7 @@ void SkBaseDevice::drawTextOnPath(const SkDraw& draw, const void* text, size_t b
m.postConcat(*matrix);
}
morphpath(&tmp, *iterPath, meas, m);
- this->drawPath(draw, tmp, iter.getPaint(), nullptr, true);
+ this->drawPath(tmp, iter.getPaint(), nullptr, true);
}
}
}
@@ -448,7 +460,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 SkDraw& draw, const void* text, size_t len,
+void SkBaseDevice::drawTextRSXform(const void* text, size_t len,
const SkRSXform xform[], const SkPaint& paint) {
CountTextProc proc = nullptr;
switch (paint.getTextEncoding()) {
@@ -466,19 +478,15 @@ void SkBaseDevice::drawTextRSXform(const SkDraw& draw, const void* text, size_t
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(*draw.fMatrix, localM);
- localD.fMatrix = &currM;
-#ifdef SK_USE_DEVICE_CLIPPING
+ currM.setConcat(this->ctm(), localM);
SkAutoDeviceCTMRestore adc(this, currM);
-#endif
int subLen = proc((const char*)text);
- this->drawText(localD, text, subLen, 0, 0, paint);
+ this->drawText(text, subLen, 0, 0, paint);
text = (const char*)text + subLen;
}
}