Index: gm/displacement.cpp |
diff --git a/gm/displacement.cpp b/gm/displacement.cpp |
index 350b8e30f3a100fc8c0dd28fc039d6568f234afe..5a20f8187be4a7a57beb761483e36599e0d4a776 100644 |
--- a/gm/displacement.cpp |
+++ b/gm/displacement.cpp |
@@ -22,6 +22,15 @@ protected: |
return SkString("displacement"); |
} |
+ void make_bitmaps() { |
+ make_bitmap(); |
+ make_checkerboard(&fCheckerboard, 80, 80); |
+ make_checkerboard(&fSmall, 64, 64); |
+ make_checkerboard(&fLarge, 96, 96); |
+ make_checkerboard(&fLargeW, 96, 64); |
+ make_checkerboard(&fLargeH, 64, 96); |
+ } |
+ |
void make_bitmap() { |
fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); |
fBitmap.allocPixels(); |
@@ -36,18 +45,18 @@ protected: |
canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint); |
} |
- void make_checkerboard() { |
- fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); |
- fCheckerboard.allocPixels(); |
- SkBitmapDevice device(fCheckerboard); |
+ void make_checkerboard(SkBitmap* bitmap, int w, int h) { |
+ bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
+ bitmap->allocPixels(); |
+ SkBitmapDevice device(*bitmap); |
SkCanvas canvas(&device); |
canvas.clear(0x00000000); |
SkPaint darkPaint; |
darkPaint.setColor(0xFF804020); |
SkPaint lightPaint; |
lightPaint.setColor(0xFF244484); |
- for (int y = 0; y < 80; y += 16) { |
- for (int x = 0; x < 80; x += 16) { |
+ for (int y = 0; y < h; y += 16) { |
+ for (int x = 0; x < w; x += 16) { |
canvas.save(); |
canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
@@ -60,7 +69,7 @@ protected: |
} |
virtual SkISize onISize() { |
- return make_isize(500, 400); |
+ return make_isize(500, 500); |
} |
void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { |
@@ -73,8 +82,7 @@ protected: |
virtual void onDraw(SkCanvas* canvas) { |
if (!fInitialized) { |
- make_bitmap(); |
- make_checkerboard(); |
+ make_bitmaps(); |
fInitialized = true; |
} |
canvas->clear(0x00000000); |
@@ -174,11 +182,36 @@ protected: |
SkDisplacementMapEffect::kA_ChannelSelectorType, |
40.0f, displ, NULL, &cropRect)))->unref(); |
drawClippedBitmap(canvas, 400, 300, paint); |
+ |
+ displ.reset(SkNEW_ARGS(SkBitmapSource, (fSmall))); |
+ paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, |
+ (SkDisplacementMapEffect::kR_ChannelSelectorType, |
+ SkDisplacementMapEffect::kG_ChannelSelectorType, |
+ 40.0f, displ)))->unref(); |
+ drawClippedBitmap(canvas, 0, 400, paint); |
+ displ.reset(SkNEW_ARGS(SkBitmapSource, (fLarge))); |
+ paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, |
+ (SkDisplacementMapEffect::kB_ChannelSelectorType, |
+ SkDisplacementMapEffect::kA_ChannelSelectorType, |
+ 40.0f, displ)))->unref(); |
+ drawClippedBitmap(canvas, 100, 400, paint); |
+ displ.reset(SkNEW_ARGS(SkBitmapSource, (fLargeW))); |
+ paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, |
+ (SkDisplacementMapEffect::kR_ChannelSelectorType, |
+ SkDisplacementMapEffect::kB_ChannelSelectorType, |
+ 40.0f, displ)))->unref(); |
+ drawClippedBitmap(canvas, 200, 400, paint); |
+ displ.reset(SkNEW_ARGS(SkBitmapSource, (fLargeH))); |
+ paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, |
+ (SkDisplacementMapEffect::kG_ChannelSelectorType, |
+ SkDisplacementMapEffect::kA_ChannelSelectorType, |
+ 40.0f, displ)))->unref(); |
+ drawClippedBitmap(canvas, 300, 400, paint); |
} |
private: |
typedef GM INHERITED; |
- SkBitmap fBitmap, fCheckerboard; |
+ SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; |
bool fInitialized; |
}; |