2012-03-07 21:47:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Want to ensure that our bitmap sampler (in bitmap shader) keeps plenty of
|
|
|
|
* precision when scaling very large images (where the dx might get very small.
|
|
|
|
*/
|
|
|
|
|
2012-03-14 20:15:47 +00:00
|
|
|
#define W 257
|
|
|
|
#define H 161
|
2012-03-07 21:47:41 +00:00
|
|
|
|
|
|
|
class GiantBitmapGM : public skiagm::GM {
|
|
|
|
SkBitmap* fBM;
|
|
|
|
SkShader::TileMode fMode;
|
2012-03-08 22:13:39 +00:00
|
|
|
bool fDoFilter;
|
|
|
|
bool fDoRotate;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-07 21:47:41 +00:00
|
|
|
const SkBitmap& getBitmap() {
|
|
|
|
if (NULL == fBM) {
|
|
|
|
fBM = new SkBitmap;
|
2014-01-25 16:46:20 +00:00
|
|
|
fBM->allocN32Pixels(W, H);
|
2012-03-07 21:47:41 +00:00
|
|
|
fBM->eraseColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
const SkColor colors[] = {
|
|
|
|
SK_ColorBLUE, SK_ColorRED, SK_ColorBLACK, SK_ColorGREEN
|
|
|
|
};
|
|
|
|
|
|
|
|
SkCanvas canvas(*fBM);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2012-03-14 20:15:47 +00:00
|
|
|
paint.setStrokeWidth(SkIntToScalar(20));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-14 20:15:47 +00:00
|
|
|
#if 0
|
|
|
|
for (int y = -H*2; y < H; y += 50) {
|
2012-03-07 21:47:41 +00:00
|
|
|
SkScalar yy = SkIntToScalar(y);
|
2012-03-14 20:15:47 +00:00
|
|
|
paint.setColor(colors[y/50 & 0x3]);
|
2012-03-07 21:47:41 +00:00
|
|
|
canvas.drawLine(0, yy, SkIntToScalar(W), yy + SkIntToScalar(W),
|
|
|
|
paint);
|
|
|
|
}
|
2012-03-14 20:15:47 +00:00
|
|
|
#else
|
|
|
|
for (int x = -W; x < W; x += 60) {
|
|
|
|
paint.setColor(colors[x/60 & 0x3]);
|
|
|
|
|
|
|
|
SkScalar xx = SkIntToScalar(x);
|
|
|
|
canvas.drawLine(xx, 0, xx, SkIntToScalar(H),
|
|
|
|
paint);
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-07 21:47:41 +00:00
|
|
|
}
|
|
|
|
return *fBM;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2012-03-08 22:13:39 +00:00
|
|
|
GiantBitmapGM(SkShader::TileMode mode, bool doFilter, bool doRotate) : fBM(NULL) {
|
|
|
|
fMode = mode;
|
|
|
|
fDoFilter = doFilter;
|
|
|
|
fDoRotate = doRotate;
|
|
|
|
}
|
2012-03-07 21:47:41 +00:00
|
|
|
|
|
|
|
virtual ~GiantBitmapGM() {
|
|
|
|
SkDELETE(fBM);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkString onShortName() SK_OVERRIDE {
|
2012-03-07 21:47:41 +00:00
|
|
|
SkString str("giantbitmap_");
|
|
|
|
switch (fMode) {
|
|
|
|
case SkShader::kClamp_TileMode:
|
|
|
|
str.append("clamp");
|
|
|
|
break;
|
|
|
|
case SkShader::kRepeat_TileMode:
|
|
|
|
str.append("repeat");
|
|
|
|
break;
|
|
|
|
case SkShader::kMirror_TileMode:
|
|
|
|
str.append("mirror");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-03-08 22:13:39 +00:00
|
|
|
str.append(fDoFilter ? "_bilerp" : "_point");
|
|
|
|
str.append(fDoRotate ? "_rotate" : "_scale");
|
2012-03-07 21:47:41 +00:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkISize onISize() SK_OVERRIDE { return SkISize::Make(640, 480); }
|
2012-03-07 21:47:41 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2012-03-07 21:47:41 +00:00
|
|
|
SkPaint paint;
|
2012-03-08 22:13:39 +00:00
|
|
|
|
2012-03-07 21:47:41 +00:00
|
|
|
SkMatrix m;
|
2012-03-08 22:13:39 +00:00
|
|
|
if (fDoRotate) {
|
|
|
|
// m.setRotate(SkIntToScalar(30), 0, 0);
|
|
|
|
m.setSkew(SK_Scalar1, 0, 0, 0);
|
2012-03-14 20:15:47 +00:00
|
|
|
// m.postScale(2*SK_Scalar1/3, 2*SK_Scalar1/3);
|
2012-03-08 22:13:39 +00:00
|
|
|
} else {
|
2012-03-14 20:15:47 +00:00
|
|
|
SkScalar scale = 11*SK_Scalar1/12;
|
|
|
|
m.setScale(scale, scale);
|
2012-03-08 22:13:39 +00:00
|
|
|
}
|
2014-04-28 14:55:39 +00:00
|
|
|
SkShader* s = SkShader::CreateBitmapShader(getBitmap(), fMode, fMode, &m);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-07 21:47:41 +00:00
|
|
|
paint.setShader(s)->unref();
|
2013-10-31 17:28:30 +00:00
|
|
|
paint.setFilterLevel(fDoFilter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
|
2012-03-07 21:47:41 +00:00
|
|
|
|
2012-03-08 22:13:39 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), SkIntToScalar(50));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-01-07 16:47:43 +00:00
|
|
|
// SkRect r = SkRect::MakeXYWH(-50, -50, 32, 16);
|
2012-03-14 20:15:47 +00:00
|
|
|
// canvas->drawRect(r, paint); return;
|
2012-03-07 21:47:41 +00:00
|
|
|
canvas->drawPaint(paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-03-08 22:13:39 +00:00
|
|
|
static skiagm::GM* G000(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, false, false); }
|
|
|
|
static skiagm::GM* G100(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, false, false); }
|
|
|
|
static skiagm::GM* G200(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, false, false); }
|
|
|
|
static skiagm::GM* G010(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, true, false); }
|
|
|
|
static skiagm::GM* G110(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, true, false); }
|
|
|
|
static skiagm::GM* G210(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, true, false); }
|
|
|
|
|
|
|
|
static skiagm::GM* G001(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, false, true); }
|
|
|
|
static skiagm::GM* G101(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, false, true); }
|
|
|
|
static skiagm::GM* G201(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, false, true); }
|
|
|
|
static skiagm::GM* G011(void*) { return new GiantBitmapGM(SkShader::kClamp_TileMode, true, true); }
|
|
|
|
static skiagm::GM* G111(void*) { return new GiantBitmapGM(SkShader::kRepeat_TileMode, true, true); }
|
|
|
|
static skiagm::GM* G211(void*) { return new GiantBitmapGM(SkShader::kMirror_TileMode, true, true); }
|
|
|
|
|
|
|
|
static skiagm::GMRegistry reg000(G000);
|
|
|
|
static skiagm::GMRegistry reg100(G100);
|
|
|
|
static skiagm::GMRegistry reg200(G200);
|
|
|
|
static skiagm::GMRegistry reg010(G010);
|
|
|
|
static skiagm::GMRegistry reg110(G110);
|
|
|
|
static skiagm::GMRegistry reg210(G210);
|
|
|
|
|
|
|
|
static skiagm::GMRegistry reg001(G001);
|
|
|
|
static skiagm::GMRegistry reg101(G101);
|
|
|
|
static skiagm::GMRegistry reg201(G201);
|
|
|
|
static skiagm::GMRegistry reg011(G011);
|
|
|
|
static skiagm::GMRegistry reg111(G111);
|
|
|
|
static skiagm::GMRegistry reg211(G211);
|