need to apply CTM to clip rect in arithmetic imagefilter
BUG=skia:5800
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2708
NOTRY=True
upload steps are failing, but the tests themselves passed
Change-Id: I0210d0095b4ffdd376f18fad895655d39714bf38
Reviewed-on: https://skia-review.googlesource.com/2708
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp
index f832503..952ce97 100644
--- a/src/effects/SkXfermodeImageFilter.cpp
+++ b/src/effects/SkXfermodeImageFilter.cpp
@@ -401,9 +401,9 @@
}
}
-static bool intersect(SkPixmap* dst, SkPixmap* src, SkIPoint srcOffset) {
+static bool intersect(SkPixmap* dst, SkPixmap* src, int srcDx, int srcDy) {
SkIRect dstR = SkIRect::MakeWH(dst->width(), dst->height());
- SkIRect srcR = SkIRect::MakeXYWH(srcOffset.x(), srcOffset.y(), src->width(), src->height());
+ SkIRect srcR = SkIRect::MakeXYWH(srcDx, srcDy, src->width(), src->height());
SkIRect sect;
if (!sect.intersect(dstR, srcR)) {
return false;
@@ -412,7 +412,7 @@
dst->addr(sect.fLeft, sect.fTop),
dst->rowBytes());
*src = SkPixmap(src->info().makeWH(sect.width(), sect.height()),
- src->addr(SkTMax(0, -srcOffset.x()), SkTMax(0, -srcOffset.y())),
+ src->addr(SkTMax(0, -srcDx), SkTMax(0, -srcDy)),
src->rowBytes());
return true;
}
@@ -424,6 +424,11 @@
return;
}
+ const SkMatrix& ctm = canvas->getTotalMatrix();
+ SkASSERT(ctm.getType() <= SkMatrix::kTranslate_Mask);
+ const int dx = SkScalarRoundToInt(ctm.getTranslateX());
+ const int dy = SkScalarRoundToInt(ctm.getTranslateY());
+
if (img) {
SkBitmap srcBM;
SkPixmap src;
@@ -436,14 +441,8 @@
}
auto proc = fEnforcePMColor ? arith_span<true> : arith_span<false>;
- const SkMatrix& ctm = canvas->getTotalMatrix();
- SkASSERT(ctm.getType() <= SkMatrix::kTranslate_Mask);
- SkIPoint offset {
- fgBounds.fLeft + SkScalarRoundToInt(ctm.getTranslateX()),
- fgBounds.fTop + SkScalarRoundToInt(ctm.getTranslateY()),
- };
SkPixmap tmpDst = dst;
- if (intersect(&tmpDst, &src, offset)) {
+ if (intersect(&tmpDst, &src, fgBounds.fLeft + dx, fgBounds.fTop + dy)) {
for (int y = 0; y < tmpDst.height(); ++y) {
proc(fK, tmpDst.writable_addr32(0, y), src.addr32(0, y), tmpDst.width());
}
@@ -452,7 +451,7 @@
// Now apply the mode with transparent-color to the outside of the fg image
SkRegion outside(SkIRect::MakeWH(dst.width(), dst.height()));
- outside.op(fgBounds, SkRegion::kDifference_Op);
+ outside.op(fgBounds.makeOffset(dx, dy), SkRegion::kDifference_Op);
auto proc = fEnforcePMColor ? arith_transparent<true> : arith_transparent<false>;
for (SkRegion::Iterator iter(outside); !iter.done(); iter.next()) {
const SkIRect r = iter.rect();