2012-08-07 14:05:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
2013-10-24 17:52:07 +00:00
|
|
|
#include "SkGradientShader.h"
|
2012-08-07 14:05:14 +00:00
|
|
|
#include "SkPath.h"
|
2015-09-09 18:29:09 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2015-09-09 17:45:36 +00:00
|
|
|
#include "SkSurface.h"
|
2012-08-07 14:05:14 +00:00
|
|
|
|
2015-09-09 18:29:09 +00:00
|
|
|
static void draw(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
|
2015-09-09 17:45:36 +00:00
|
|
|
const SkPoint center = { SkIntToScalar(width)/2, SkIntToScalar(height)/2 };
|
|
|
|
const SkScalar radius = 40;
|
2013-10-24 17:52:07 +00:00
|
|
|
SkPaint paint;
|
2016-03-13 21:13:58 +00:00
|
|
|
paint.setShader(SkGradientShader::MakeRadial(center, radius, colors, nullptr, 2,
|
|
|
|
SkShader::kMirror_TileMode));
|
2013-10-24 17:52:07 +00:00
|
|
|
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
2015-09-09 18:29:09 +00:00
|
|
|
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);
|
2015-09-09 17:45:36 +00:00
|
|
|
return surface->newImageSnapshot();
|
2012-08-07 14:05:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 18:29:09 +00:00
|
|
|
static SkImage* make_picture_image(int width, int height, SkColor colors[2]) {
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
draw(recorder.beginRecording(SkRect::MakeIWH(width, height)), width, height, colors);
|
2015-09-09 20:42:14 +00:00
|
|
|
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
|
|
|
|
return SkImage::NewFromPicture(picture, SkISize::Make(width, height),
|
2015-09-09 18:29:09 +00:00
|
|
|
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));
|
2012-08-07 14:05:14 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
SkRect r;
|
|
|
|
SkIRect ir;
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
ir.set(0, 0, 128, 128);
|
|
|
|
r.set(ir);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(r);
|
2015-09-09 17:45:36 +00:00
|
|
|
canvas->drawImage(image, 0, 0, nullptr);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->restore();
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
r.offset(SkIntToScalar(150), 0);
|
2015-09-09 17:45:36 +00:00
|
|
|
canvas->drawImageRect(image, ir, r, nullptr);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
r.offset(SkIntToScalar(150), 0);
|
2015-09-09 17:45:36 +00:00
|
|
|
canvas->drawImageRect(image, r, nullptr);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
class VeryLargeBitmapGM : public skiagm::GM {
|
2015-09-09 18:29:09 +00:00
|
|
|
ImageMakerProc fProc;
|
|
|
|
SkString fName;
|
|
|
|
|
2012-08-07 14:05:14 +00:00
|
|
|
public:
|
2015-09-09 18:29:09 +00:00
|
|
|
VeryLargeBitmapGM(ImageMakerProc proc, const char suffix[]) : fProc(proc) {
|
|
|
|
fName.printf("verylarge%s", suffix);
|
|
|
|
}
|
2012-08-07 14:05:14 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2015-09-09 18:29:09 +00:00
|
|
|
return fName;
|
2012-08-07 14:05:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2013-10-24 17:52:07 +00:00
|
|
|
return SkISize::Make(500, 600);
|
2012-08-07 14:05:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-10-24 20:55:14 +00:00
|
|
|
int veryBig = 65*1024; // 64K < size
|
|
|
|
int big = 33*1024; // 32K < size < 64K
|
2013-10-24 17:52:07 +00:00
|
|
|
// smaller than many max texture sizes, but large enough to gpu-tile for memory reasons.
|
2013-10-24 20:55:14 +00:00
|
|
|
int medium = 5*1024;
|
2013-07-15 15:48:48 +00:00
|
|
|
int small = 150;
|
2012-08-07 14:05:14 +00:00
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
SkColor colors[2];
|
|
|
|
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
|
2013-10-24 17:52:07 +00:00
|
|
|
colors[0] = SK_ColorRED;
|
|
|
|
colors[1] = SK_ColorGREEN;
|
2015-09-09 18:29:09 +00:00
|
|
|
show_image(canvas, small, small, colors, fProc);
|
2013-10-24 17:52:07 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
|
|
|
|
|
|
|
colors[0] = SK_ColorBLUE;
|
|
|
|
colors[1] = SK_ColorMAGENTA;
|
2015-09-09 18:29:09 +00:00
|
|
|
show_image(canvas, big, small, colors, fProc);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
colors[0] = SK_ColorMAGENTA;
|
|
|
|
colors[1] = SK_ColorYELLOW;
|
2015-09-09 18:29:09 +00:00
|
|
|
show_image(canvas, medium, medium, colors, fProc);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
colors[0] = SK_ColorGREEN;
|
|
|
|
colors[1] = SK_ColorYELLOW;
|
2012-08-07 14:05:14 +00:00
|
|
|
// 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)
|
2015-09-09 18:29:09 +00:00
|
|
|
show_image(canvas, veryBig, small, colors, fProc);
|
2012-08-07 14:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
2015-09-09 18:29:09 +00:00
|
|
|
DEF_GM( return new VeryLargeBitmapGM(make_raster_image, "bitmap"); )
|
|
|
|
DEF_GM( return new VeryLargeBitmapGM(make_picture_image, "_picture_image"); )
|
2012-08-07 14:05:14 +00:00
|
|
|
|