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

Unified Diff: gm/verylargebitmap.cpp

Issue 1329283002: add picture-image variant (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rename new gm 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 eaf7316687e2e544f1801bd3a6151dc9e78dc4ab..112092c9fd0b2456deeb99b737dd2fc699c1c66e 100644
--- a/gm/verylargebitmap.cpp
+++ b/gm/verylargebitmap.cpp
@@ -9,11 +9,10 @@
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkPath.h"
+#include "SkPictureRecorder.h"
#include "SkSurface.h"
-static SkImage* make_image(int width, int height, SkColor colors[2]) {
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, height));
-
+static void draw(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
const SkPoint center = { SkIntToScalar(width)/2, SkIntToScalar(height)/2 };
const SkScalar radius = 40;
SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, nullptr, 2,
@@ -21,12 +20,27 @@ static SkImage* make_image(int width, int height, SkColor colors[2]) {
SkPaint paint;
paint.setShader(shader)->unref();
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- surface->getCanvas()->drawPaint(paint);
+ canvas->drawPaint(paint);
+}
+
+static SkImage* make_raster_image(int width, int height, SkColor colors[2]) {
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, height));
+ draw(surface->getCanvas(), width, height, colors);
return surface->newImageSnapshot();
}
-static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
- SkAutoTUnref<SkImage> image(make_image(width, height, colors));
+static SkImage* make_picture_image(int width, int height, SkColor colors[2]) {
+ SkPictureRecorder recorder;
+ draw(recorder.beginRecording(SkRect::MakeIWH(width, height)), width, height, colors);
+ return SkImage::NewFromPicture(recorder.endRecording(), SkISize::Make(width, height),
+ nullptr, nullptr);
+}
+
+typedef SkImage* (*ImageMakerProc)(int width, int height, SkColor colors[2]);
+
+static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2],
+ ImageMakerProc proc) {
+ SkAutoTUnref<SkImage> image(proc(width, height, colors));
SkPaint paint;
SkRect r;
@@ -53,12 +67,17 @@ static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2
}
class VeryLargeBitmapGM : public skiagm::GM {
+ ImageMakerProc fProc;
+ SkString fName;
+
public:
- VeryLargeBitmapGM() {}
+ VeryLargeBitmapGM(ImageMakerProc proc, const char suffix[]) : fProc(proc) {
+ fName.printf("verylarge%s", suffix);
+ }
protected:
SkString onShortName() override {
- return SkString("verylargebitmap");
+ return fName;
}
SkISize onISize() override {
@@ -77,28 +96,29 @@ protected:
canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
colors[0] = SK_ColorRED;
colors[1] = SK_ColorGREEN;
- show_image(canvas, small, small, colors);
+ show_image(canvas, small, small, colors, fProc);
canvas->translate(0, SkIntToScalar(150));
colors[0] = SK_ColorBLUE;
colors[1] = SK_ColorMAGENTA;
- show_image(canvas, big, small, colors);
+ show_image(canvas, big, small, colors, fProc);
canvas->translate(0, SkIntToScalar(150));
colors[0] = SK_ColorMAGENTA;
colors[1] = SK_ColorYELLOW;
- show_image(canvas, medium, medium, colors);
+ show_image(canvas, medium, medium, colors, fProc);
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_image(canvas, veryBig, small, colors);
+ show_image(canvas, veryBig, small, colors, fProc);
}
private:
typedef skiagm::GM INHERITED;
};
-DEF_GM( return new VeryLargeBitmapGM; )
+DEF_GM( return new VeryLargeBitmapGM(make_raster_image, "bitmap"); )
+DEF_GM( return new VeryLargeBitmapGM(make_picture_image, "_picture_image"); )
« 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