Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Unified Diff: gm/verylargebitmap.cpp

Issue 1313543004: switch over to using images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/verylargebitmap.cpp
diff --git a/gm/verylargebitmap.cpp b/gm/verylargebitmap.cpp
index 9b5496bc0f74206b978f3be6a87321477fe5f5bf..eaf7316687e2e544f1801bd3a6151dc9e78dc4ab 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<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;
@@ -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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698