#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<SkSurface> 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<SkImage> image(make_image(width, height, colors));
SkPaint paint;
SkRect r;
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);
}
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);