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

Unified Diff: gm/xfermodeimagefilter.cpp

Issue 106933002: Implement srcRect and dstRect functionality in SkBitmapSource. This is required for the "preserveAs… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix nits Created 7 years 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 | « gm/tileimagefilter.cpp ('k') | gyp/gmslides.gypi » ('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 01bfe0ad611d879d7097cd3abd492162e192c776..936af46ec6604a7fcc76459f146f747649f8bde2 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; );
}
« no previous file with comments | « gm/tileimagefilter.cpp ('k') | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698