Index: gm/xfermodeimagefilter.cpp |
diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp |
index 01bfe0ad611d879d7097cd3abd492162e192c776..259136af4fc6b8089ff01d70062f3ef519b8879e 100644 |
--- a/gm/xfermodeimagefilter.cpp |
+++ b/gm/xfermodeimagefilter.cpp |
@@ -70,11 +70,21 @@ protected: |
} |
void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, |
- SkScalar x, SkScalar y) { |
+ int x, int y) { |
canvas->save(); |
- canvas->clipRect(SkRect::MakeXYWH(x, y, |
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
+ canvas->clipRect(SkRect::MakeWH( |
SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); |
- canvas->drawBitmap(bitmap, x, y, &paint); |
+ canvas->drawBitmap(bitmap, 0, 0, &paint); |
+ canvas->restore(); |
+ } |
+ |
+ void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkPaint& paint, |
+ int x, int y) { |
+ canvas->save(); |
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
+ canvas->clipRect(rect); |
+ canvas->drawPaint(paint); |
canvas->restore(); |
} |
@@ -130,7 +140,7 @@ protected: |
SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( |
SkXfermodeImageFilter, (mode, background))); |
paint.setImageFilter(filter); |
robertphillips
2013/12/09 16:23:01
this->
Stephen White
2013/12/09 17:04:25
Made static instead.
|
- drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); |
+ drawClippedBitmap(canvas, fBitmap, paint, x, y); |
x += fBitmap.width() + MARGIN; |
if (x + fBitmap.width() > WIDTH) { |
x = 0; |
@@ -141,7 +151,7 @@ protected: |
SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK_Scalar1, 0)); |
SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkXfermodeImageFilter, (mode, background))); |
paint.setImageFilter(filter); |
robertphillips
2013/12/09 16:23:01
this->
|
- drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); |
+ drawClippedBitmap(canvas, fBitmap, paint, x, y); |
x += fBitmap.width() + MARGIN; |
if (x + fBitmap.width() > WIDTH) { |
x = 0; |
@@ -150,12 +160,14 @@ protected: |
// Test NULL mode |
filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (NULL, background))); |
paint.setImageFilter(filter); |
robertphillips
2013/12/09 16:23:01
this->
|
- drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); |
+ drawClippedBitmap(canvas, fBitmap, paint, x, y); |
x += fBitmap.width() + MARGIN; |
if (x + fBitmap.width() > WIDTH) { |
x = 0; |
y += fBitmap.height() + MARGIN; |
} |
+ SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), |
+ SkIntToScalar(fBitmap.height() + 4)); |
// Test offsets on SrcMode (uses fixed-function blend) |
SkAutoTUnref<SkImageFilter> foreground(SkNEW_ARGS(SkBitmapSource, (fBitmap))); |
SkAutoTUnref<SkImageFilter> offsetForeground(SkNEW_ARGS(SkOffsetImageFilter, |
@@ -166,13 +178,7 @@ protected: |
filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, |
(mode, offsetBackground, offsetForeground))); |
paint.setImageFilter(filter); |
robertphillips
2013/12/09 16:23:01
this-> on all drawClippedPaint calls
Stephen White
2013/12/09 17:04:25
See above.
|
- canvas->save(); |
- canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), |
- SkIntToScalar(y), |
- SkIntToScalar(fBitmap.width() + 4), |
- SkIntToScalar(fBitmap.height() + 4))); |
- canvas->drawPaint(paint); |
- canvas->restore(); |
+ drawClippedPaint(canvas, clipRect, paint, x, y); |
x += fBitmap.width() + MARGIN; |
if (x + fBitmap.width() > WIDTH) { |
x = 0; |
@@ -182,13 +188,7 @@ protected: |
mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); |
filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground))); |
paint.setImageFilter(filter); |
- canvas->save(); |
- canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), |
- SkIntToScalar(y), |
- SkIntToScalar(fBitmap.width() + 4), |
- SkIntToScalar(fBitmap.height() + 4))); |
- canvas->drawPaint(paint); |
- canvas->restore(); |
+ drawClippedPaint(canvas, clipRect, paint, x, y); |
x += fBitmap.width() + MARGIN; |
if (x + fBitmap.width() > WIDTH) { |
x = 0; |
@@ -203,8 +203,8 @@ protected: |
{ 10, 10, 10, 10}, |
{-10, -10, -6, -6}}; |
for (size_t i = 0; i < nbSamples; ++i) { |
- SkIRect cropRect = SkIRect::MakeXYWH(x + offsets[i][0], |
- y + offsets[i][1], |
+ SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], |
+ offsets[i][1], |
fBitmap.width() + offsets[i][2], |
fBitmap.height() + offsets[i][3]); |
SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
@@ -212,13 +212,7 @@ protected: |
filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, |
(mode, offsetBackground, offsetForeground, &rect))); |
paint.setImageFilter(filter); |
- canvas->save(); |
- canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), |
- SkIntToScalar(y), |
- SkIntToScalar(fBitmap.width() + 4), |
- SkIntToScalar(fBitmap.height() + 4))); |
- canvas->drawPaint(paint); |
- canvas->restore(); |
+ drawClippedPaint(canvas, clipRect, paint, x, y); |
x += fBitmap.width() + MARGIN; |
if (x + fBitmap.width() > WIDTH) { |
x = 0; |