From 5598b63cd2443a608a74a222d0206bb2455383b7 Mon Sep 17 00:00:00 2001 From: fmalita Date: Tue, 15 Sep 2015 11:26:13 -0700 Subject: Convert unit tests, GMs from SkBitmapSource to SkImagesource This removes SkBitmapSource clients within Skia. http://crrev.com/1334173004 does the same for Blink, so we should be able to remove SkBitmapSource in a follow-up. R=reed@google.com,robertphillips@google.com,mtklein@google.com Review URL: https://codereview.chromium.org/1343123002 --- gm/xfermodeimagefilter.cpp | 73 +++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 34 deletions(-) (limited to 'gm/xfermodeimagefilter.cpp') diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp index e09c0abe94..bb86ceffa8 100644 --- a/gm/xfermodeimagefilter.cpp +++ b/gm/xfermodeimagefilter.cpp @@ -8,9 +8,10 @@ #include "gm.h" #include "sk_tool_utils.h" #include "SkArithmeticMode.h" +#include "SkImage.h" +#include "SkImageSource.h" #include "SkOffsetImageFilter.h" #include "SkXfermodeImageFilter.h" -#include "SkBitmapSource.h" #define WIDTH 600 #define HEIGHT 600 @@ -33,33 +34,14 @@ protected: return SkISize::Make(WIDTH, HEIGHT); } - static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, - int x, int y) { - canvas->save(); - canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); - canvas->clipRect(SkRect::MakeWH( - SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); - canvas->drawBitmap(bitmap, 0, 0, &paint); - canvas->restore(); - } - - 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(); - } - void onOnceBeforeDraw() override { fBitmap = 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 { @@ -103,12 +85,12 @@ protected: }; int x = 0, y = 0; - SkAutoTUnref background(SkBitmapSource::Create(fCheckerboard)); + SkAutoTUnref background(SkImageSource::Create(fCheckerboard)); for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { SkAutoTUnref mode(SkXfermode::Create(gModes[i].fMode)); SkAutoTUnref filter(SkXfermodeImageFilter::Create(mode, background)); paint.setImageFilter(filter); - drawClippedBitmap(canvas, fBitmap, paint, x, y); + DrawClippedBitmap(canvas, fBitmap, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; @@ -119,7 +101,7 @@ protected: SkAutoTUnref mode(SkArithmeticMode::Create(0, SK_Scalar1, SK_Scalar1, 0)); SkAutoTUnref filter(SkXfermodeImageFilter::Create(mode, background)); paint.setImageFilter(filter); - drawClippedBitmap(canvas, fBitmap, paint, x, y); + DrawClippedBitmap(canvas, fBitmap, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; @@ -128,7 +110,7 @@ protected: // Test nullptr mode filter.reset(SkXfermodeImageFilter::Create(nullptr, background)); paint.setImageFilter(filter); - drawClippedBitmap(canvas, fBitmap, paint, x, y); + DrawClippedBitmap(canvas, fBitmap, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; @@ -137,7 +119,8 @@ protected: SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), SkIntToScalar(fBitmap.height() + 4)); // Test offsets on SrcMode (uses fixed-function blend) - SkAutoTUnref foreground(SkBitmapSource::Create(fBitmap)); + SkAutoTUnref bitmapImage(SkImage::NewFromBitmap(fBitmap)); + SkAutoTUnref foreground(SkImageSource::Create(bitmapImage)); SkAutoTUnref offsetForeground(SkOffsetImageFilter::Create( SkIntToScalar(4), SkIntToScalar(-4), foreground)); SkAutoTUnref offsetBackground(SkOffsetImageFilter::Create( @@ -145,7 +128,7 @@ protected: mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offsetForeground)); paint.setImageFilter(filter); - drawClippedPaint(canvas, clipRect, paint, x, y); + DrawClippedPaint(canvas, clipRect, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; @@ -155,7 +138,7 @@ protected: mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offsetForeground)); paint.setImageFilter(filter); - drawClippedPaint(canvas, clipRect, paint, x, y); + DrawClippedPaint(canvas, clipRect, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; @@ -179,7 +162,7 @@ protected: filter.reset(SkXfermodeImageFilter::Create( mode, offsetBackground, offsetForeground, &rect)); paint.setImageFilter(filter); - drawClippedPaint(canvas, clipRect, paint, x, y); + DrawClippedPaint(canvas, clipRect, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; @@ -187,8 +170,30 @@ protected: } } } + private: - SkBitmap fBitmap, fCheckerboard; + static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, + int x, int y) { + canvas->save(); + canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); + canvas->clipRect(SkRect::MakeWH( + SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); + canvas->drawBitmap(bitmap, 0, 0, &paint); + canvas->restore(); + } + + 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(); + } + + SkBitmap fBitmap; + SkAutoTUnref fCheckerboard; + typedef GM INHERITED; }; -- cgit v1.2.3