aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/xfermodeimagefilter.cpp
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-09 18:31:42 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-09 18:31:42 +0000
commite93e1dbf0eced1e1b9aeed7c0c170961e2d61e32 (patch)
treeb0d4b72c85db74c4dcb18f5c72bf91e729854d62 /gm/xfermodeimagefilter.cpp
parent907fbd53c5e5dd4cbde7b72f9242b51febd7ef95 (diff)
Implement srcRect and dstRect functionality in SkBitmapSource. This is required for the "preserveAspectRatio" options of SVG's feImage. Covered by new GM "bitmapsource".
This also includes some changes to the xfermodeimagefilter and tileimagefilter GMs to properly handle the CTM. This worked before only because SkBitmapSource was ignoring the CTM. Now that it respects it, we need to give the correct transform. This also means the GMs now work while zoomed. It also implements CTM support for SkTileImageFilter. NOTE: this will require rebaselining a number of imagefilter GMs on Nexus4, since they render in perspective (using the CTM). The changes to the results should all be improvements. R=reed@google.com, robertphillips@google.com Review URL: https://codereview.chromium.org/106933002 git-svn-id: http://skia.googlecode.com/svn/trunk@12571 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/xfermodeimagefilter.cpp')
-rw-r--r--gm/xfermodeimagefilter.cpp78
1 files changed, 35 insertions, 43 deletions
diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp
index 01bfe0ad61..936af46ec6 100644
--- a/gm/xfermodeimagefilter.cpp
+++ b/gm/xfermodeimagefilter.cpp
@@ -19,12 +19,12 @@ namespace skiagm {
class XfermodeImageFilterGM : public GM {
public:
- XfermodeImageFilterGM() : fInitialized(false) {
+ XfermodeImageFilterGM(){
this->setBGColor(0xFF000000);
}
protected:
- virtual SkString onShortName() {
+ virtual SkString onShortName() SK_OVERRIDE {
return SkString("xfermodeimagefilter");
}
@@ -65,25 +65,35 @@ protected:
}
}
- virtual SkISize onISize() {
+ virtual SkISize onISize() SK_OVERRIDE {
return make_isize(WIDTH, HEIGHT);
}
- void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint,
- SkScalar x, SkScalar y) {
+ static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint,
+ 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();
}
- virtual void onDraw(SkCanvas* canvas) {
- if (!fInitialized) {
- make_bitmap();
- make_checkerboard();
- fInitialized = true;
- }
+ static 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();
+ }
+
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
+ make_bitmap();
+ make_checkerboard();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
canvas->clear(0x00000000);
SkPaint paint;
@@ -130,7 +140,7 @@ protected:
SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
SkXfermodeImageFilter, (mode, background)));
paint.setImageFilter(filter);
- 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);
- 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);
- 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);
- 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;
@@ -227,14 +221,12 @@ protected:
}
}
private:
- typedef GM INHERITED;
SkBitmap fBitmap, fCheckerboard;
- bool fInitialized;
+ typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
-static GM* MyFactory(void*) { return new XfermodeImageFilterGM; }
-static GMRegistry reg(MyFactory);
+DEF_GM( return new XfermodeImageFilterGM; );
}