Index: gm/offsetimagefilter.cpp |
diff --git a/gm/offsetimagefilter.cpp b/gm/offsetimagefilter.cpp |
index fcf2b9843fedc34955be342fd23b89b9f7427b66..eec18cffb9a72d630f5a2cc2e06b1932ee88293a 100644 |
--- a/gm/offsetimagefilter.cpp |
+++ b/gm/offsetimagefilter.cpp |
@@ -6,8 +6,10 @@ |
*/ |
#include "sk_tool_utils.h" |
-#include "SkBitmapSource.h" |
+#include "SkImage.h" |
+#include "SkImageSource.h" |
#include "SkOffsetImageFilter.h" |
+#include "SkSurface.h" |
#include "gm.h" |
#define WIDTH 600 |
@@ -29,36 +31,15 @@ protected: |
return SkISize::Make(WIDTH, HEIGHT); |
} |
- void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, |
- SkScalar scale, const SkIRect& cropRect) { |
- SkRect clipRect = SkRect::MakeIWH(bitmap.width(), bitmap.height()); |
- |
- canvas->save(); |
- canvas->clipRect(clipRect); |
- canvas->scale(scale, scale); |
- canvas->drawBitmap(bitmap, 0, 0, &paint); |
- canvas->restore(); |
- |
- // Draw a boundary rect around the intersection of the clip rect and crop rect. |
- SkRect cropRectFloat; |
- SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(cropRect)); |
- if (clipRect.intersect(cropRectFloat)) { |
- SkPaint strokePaint; |
- strokePaint.setStyle(SkPaint::kStroke_Style); |
- strokePaint.setStrokeWidth(2); |
- strokePaint.setColor(SK_ColorRED); |
- canvas->drawRect(clipRect, strokePaint); |
- } |
- } |
- |
void onOnceBeforeDraw() override { |
- fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "e"); |
+ fBitmap.reset(SkImage::NewFromBitmap( |
+ sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "e"))); |
- fCheckerboard = sk_tool_utils::create_checkerboard_bitmap( |
- 80, 80, |
- sk_tool_utils::color_to_565(0xFFA0A0A0), |
- sk_tool_utils::color_to_565(0xFF404040), |
- 8); |
+ fCheckerboard.reset(SkImage::NewFromBitmap( |
+ sk_tool_utils::create_checkerboard_bitmap(80, 80, |
+ sk_tool_utils::color_to_565(0xFFA0A0A0), |
+ sk_tool_utils::color_to_565(0xFF404040), |
+ 8))); |
} |
void onDraw(SkCanvas* canvas) override { |
@@ -66,30 +47,52 @@ protected: |
SkPaint paint; |
for (int i = 0; i < 4; i++) { |
- const SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; |
+ const SkImage* image = (i & 0x01) ? fCheckerboard : fBitmap; |
SkIRect cropRect = SkIRect::MakeXYWH(i * 12, |
i * 8, |
- bitmap->width() - i * 8, |
- bitmap->height() - i * 12); |
+ image->width() - i * 8, |
+ image->height() - i * 12); |
SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
- SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap)); |
+ SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image)); |
SkScalar dx = SkIntToScalar(i*5); |
SkScalar dy = SkIntToScalar(i*10); |
SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, dy, tileInput, |
&rect)); |
paint.setImageFilter(filter); |
- drawClippedBitmap(canvas, *bitmap, paint, 1, cropRect); |
- canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0); |
+ DrawClippedImage(canvas, image, paint, 1, cropRect); |
+ canvas->translate(SkIntToScalar(image->width() + MARGIN), 0); |
} |
SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); |
SkImageFilter::CropRect rect(SkRect::Make(cropRect)); |
SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect)); |
paint.setImageFilter(filter); |
- drawClippedBitmap(canvas, fBitmap, paint, 2, cropRect); |
+ DrawClippedImage(canvas, fBitmap, paint, 2, cropRect); |
} |
private: |
- SkBitmap fBitmap, fCheckerboard; |
+ static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const SkPaint& paint, |
+ SkScalar scale, const SkIRect& cropRect) { |
+ SkRect clipRect = SkRect::MakeIWH(image->width(), image->height()); |
+ |
+ canvas->save(); |
+ canvas->clipRect(clipRect); |
+ canvas->scale(scale, scale); |
+ canvas->drawImage(image, 0, 0, &paint); |
+ canvas->restore(); |
+ |
+ // Draw a boundary rect around the intersection of the clip rect and crop rect. |
+ SkRect cropRectFloat; |
+ SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(cropRect)); |
+ if (clipRect.intersect(cropRectFloat)) { |
+ SkPaint strokePaint; |
+ strokePaint.setStyle(SkPaint::kStroke_Style); |
+ strokePaint.setStrokeWidth(2); |
+ strokePaint.setColor(SK_ColorRED); |
+ canvas->drawRect(clipRect, strokePaint); |
+ } |
+ } |
+ |
+ SkAutoTUnref<SkImage> fBitmap, fCheckerboard; |
typedef skiagm::GM INHERITED; |
}; |