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"
|
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) {
|
2014-01-25 16:46:20 +00:00
|
|
|
bm->allocN32Pixels(width, height);
|
2013-10-24 17:52:07 +00:00
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2};
|
|
|
|
SkScalar radius = 40;
|
2015-08-27 14:41:13 +00:00
|
|
|
SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, nullptr, 2,
|
2013-10-24 17:52:07 +00:00
|
|
|
SkShader::kMirror_TileMode);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setShader(shader)->unref();
|
|
|
|
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
|
|
|
canvas.drawPaint(paint);
|
2012-08-07 14:05:14 +00:00
|
|
|
bm->setImmutable();
|
|
|
|
}
|
|
|
|
|
2013-10-24 17:52:07 +00:00
|
|
|
static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
|
2012-08-07 14:05:14 +00:00
|
|
|
SkBitmap bm;
|
2013-10-24 17:52:07 +00:00
|
|
|
make_bm(&bm, 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-08-27 14:41:13 +00:00
|
|
|
canvas->drawBitmap(bm, 0, 0, nullptr);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->restore();
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
r.offset(SkIntToScalar(150), 0);
|
|
|
|
// exercises extract bitmap, but not shader
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->drawBitmapRect(bm, ir, r, nullptr);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
r.offset(SkIntToScalar(150), 0);
|
|
|
|
// exercises bitmapshader
|
2015-08-06 17:02:53 +00:00
|
|
|
canvas->drawBitmapRect(bm, r, nullptr);
|
2012-08-07 14:05:14 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
class VeryLargeBitmapGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
VeryLargeBitmapGM() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2012-08-07 14:05:14 +00:00
|
|
|
return SkString("verylargebitmap");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
show_bm(canvas, small, small, colors);
|
|
|
|
canvas->translate(0, SkIntToScalar(150));
|
|
|
|
|
|
|
|
colors[0] = SK_ColorBLUE;
|
|
|
|
colors[1] = SK_ColorMAGENTA;
|
|
|
|
show_bm(canvas, big, small, colors);
|
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;
|
|
|
|
show_bm(canvas, medium, medium, colors);
|
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)
|
2013-10-24 17:52:07 +00:00
|
|
|
show_bm(canvas, veryBig, small, colors);
|
2012-08-07 14:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; }
|
|
|
|
static skiagm::GMRegistry reg(MyFactory);
|