From 4228c1fa2cec5840abaa50ad6644c89021da10fc Mon Sep 17 00:00:00 2001 From: reed Date: Wed, 9 Sep 2015 10:45:36 -0700 Subject: [PATCH] switch over to using images BUG=skia: TBR= Review URL: https://codereview.chromium.org/1313543004 --- gm/verylargebitmap.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/gm/verylargebitmap.cpp b/gm/verylargebitmap.cpp index 9b5496bc0f..eaf7316687 100644 --- a/gm/verylargebitmap.cpp +++ b/gm/verylargebitmap.cpp @@ -9,24 +9,24 @@ #include "SkCanvas.h" #include "SkGradientShader.h" #include "SkPath.h" +#include "SkSurface.h" -static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) { - bm->allocN32Pixels(width, height); - SkCanvas canvas(*bm); - SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2}; - SkScalar radius = 40; +static SkImage* make_image(int width, int height, SkColor colors[2]) { + SkAutoTUnref surface(SkSurface::NewRasterN32Premul(width, height)); + + const SkPoint center = { SkIntToScalar(width)/2, SkIntToScalar(height)/2 }; + const SkScalar radius = 40; SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, nullptr, 2, SkShader::kMirror_TileMode); SkPaint paint; paint.setShader(shader)->unref(); paint.setXfermodeMode(SkXfermode::kSrc_Mode); - canvas.drawPaint(paint); - bm->setImmutable(); + surface->getCanvas()->drawPaint(paint); + return surface->newImageSnapshot(); } -static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) { - SkBitmap bm; - make_bm(&bm, width, height, colors); +static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2]) { + SkAutoTUnref image(make_image(width, height, colors)); SkPaint paint; SkRect r; @@ -39,18 +39,16 @@ static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) canvas->save(); canvas->clipRect(r); - canvas->drawBitmap(bm, 0, 0, nullptr); + canvas->drawImage(image, 0, 0, nullptr); canvas->restore(); canvas->drawRect(r, paint); r.offset(SkIntToScalar(150), 0); - // exercises extract bitmap, but not shader - canvas->drawBitmapRect(bm, ir, r, nullptr); + canvas->drawImageRect(image, ir, r, nullptr); canvas->drawRect(r, paint); r.offset(SkIntToScalar(150), 0); - // exercises bitmapshader - canvas->drawBitmapRect(bm, r, nullptr); + canvas->drawImageRect(image, r, nullptr); canvas->drawRect(r, paint); } @@ -79,31 +77,28 @@ protected: canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); colors[0] = SK_ColorRED; colors[1] = SK_ColorGREEN; - show_bm(canvas, small, small, colors); + show_image(canvas, small, small, colors); canvas->translate(0, SkIntToScalar(150)); colors[0] = SK_ColorBLUE; colors[1] = SK_ColorMAGENTA; - show_bm(canvas, big, small, colors); + show_image(canvas, big, small, colors); canvas->translate(0, SkIntToScalar(150)); colors[0] = SK_ColorMAGENTA; colors[1] = SK_ColorYELLOW; - show_bm(canvas, medium, medium, colors); + show_image(canvas, medium, medium, colors); canvas->translate(0, SkIntToScalar(150)); colors[0] = SK_ColorGREEN; colors[1] = SK_ColorYELLOW; // as of this writing, the raster code will fail to draw the scaled version // since it has a 64K limit on x,y coordinates... (but gpu should succeed) - show_bm(canvas, veryBig, small, colors); + show_image(canvas, veryBig, small, colors); } private: typedef skiagm::GM INHERITED; }; +DEF_GM( return new VeryLargeBitmapGM; ) -////////////////////////////////////////////////////////////////////////////// - -static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; } -static skiagm::GMRegistry reg(MyFactory);