Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(918)

Unified Diff: gm/xfermodeimagefilter.cpp

Issue 15995026: Image filters: implement offsets in GPU path. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Wrap lines at 100 chars. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/core/SkImageFilter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/xfermodeimagefilter.cpp
diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp
index a6d395e658a3044c8d8cf3e2ed5037a165705892..e602c7079d66453600dfbe362734bc83630e7762 100644
--- a/gm/xfermodeimagefilter.cpp
+++ b/gm/xfermodeimagefilter.cpp
@@ -7,6 +7,7 @@
#include "gm.h"
#include "SkArithmeticMode.h"
+#include "SkOffsetImageFilter.h"
#include "SkXfermodeImageFilter.h"
#include "SkBitmapSource.h"
@@ -68,7 +69,8 @@ protected:
return make_isize(WIDTH, HEIGHT);
}
- void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, SkScalar x, SkScalar y) {
+ void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint,
+ SkScalar x, SkScalar y) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(x, y,
SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
@@ -125,7 +127,8 @@ protected:
SkAutoTUnref<SkImageFilter> background(SkNEW_ARGS(SkBitmapSource, (fCheckerboard)));
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode));
- SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(SkXfermodeImageFilter, (mode, background)));
+ SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
+ SkXfermodeImageFilter, (mode, background)));
paint.setImageFilter(filter);
drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y));
x += fBitmap.width() + MARGIN;
@@ -148,6 +151,40 @@ protected:
filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (NULL, background)));
paint.setImageFilter(filter);
drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(x), SkIntToScalar(y));
+ x += fBitmap.width() + MARGIN;
+ if (x + fBitmap.width() > WIDTH) {
+ x = 0;
+ y += fBitmap.height() + MARGIN;
+ }
+ // Test offsets on SrcMode (uses fixed-function blend)
+ SkAutoTUnref<SkImageFilter> foreground(SkNEW_ARGS(SkBitmapSource, (fBitmap)));
+ SkAutoTUnref<SkImageFilter> offsetForeground(SkNEW_ARGS(SkOffsetImageFilter,
+ (SkIntToScalar(4), SkIntToScalar(-4), foreground)));
+ SkAutoTUnref<SkImageFilter> offsetBackground(SkNEW_ARGS(SkOffsetImageFilter,
+ (SkIntToScalar(4), SkIntToScalar(4), background)));
+ mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
+ filter.reset(SkNEW_ARGS(SkXfermodeImageFilter,
+ (mode, offsetBackground, offsetForeground)));
+ paint.setImageFilter(filter);
+ canvas->save();
+ canvas->clipRect(SkRect::MakeXYWH(x, y,
+ SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() + 4)));
+ canvas->drawPaint(paint);
+ canvas->restore();
+ x += fBitmap.width() + MARGIN;
+ if (x + fBitmap.width() > WIDTH) {
+ x = 0;
+ y += fBitmap.height() + MARGIN;
+ }
+ // Test offsets on Darken (uses shader blend)
+ mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode));
+ filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground)));
+ paint.setImageFilter(filter);
+ canvas->save();
+ canvas->clipRect(SkRect::MakeXYWH(x, y,
+ SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() + 4)));
+ canvas->drawPaint(paint);
+ canvas->restore();
}
private:
typedef GM INHERITED;
« no previous file with comments | « no previous file | include/core/SkImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698