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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkShader.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
2012-03-07 21:47:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode 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() {
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == fBM) {
|
2012-03-07 21:47:41 +00:00
|
|
|
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:
|
2019-04-03 14:27:45 +00:00
|
|
|
GiantBitmapGM(SkTileMode mode, bool doFilter, bool doRotate) : fBM(nullptr) {
|
2012-03-08 22:13:39 +00:00
|
|
|
fMode = mode;
|
|
|
|
fDoFilter = doFilter;
|
|
|
|
fDoRotate = doRotate;
|
|
|
|
}
|
2012-03-07 21:47:41 +00:00
|
|
|
|
2017-03-22 16:05:03 +00:00
|
|
|
~GiantBitmapGM() override { delete fBM; }
|
2012-03-07 21:47:41 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2012-03-07 21:47:41 +00:00
|
|
|
SkString str("giantbitmap_");
|
|
|
|
switch (fMode) {
|
2019-04-03 14:27:45 +00:00
|
|
|
case SkTileMode::kClamp:
|
2012-03-07 21:47:41 +00:00
|
|
|
str.append("clamp");
|
|
|
|
break;
|
2019-04-03 14:27:45 +00:00
|
|
|
case SkTileMode::kRepeat:
|
2012-03-07 21:47:41 +00:00
|
|
|
str.append("repeat");
|
|
|
|
break;
|
2019-04-03 14:27:45 +00:00
|
|
|
case SkTileMode::kMirror:
|
2012-03-07 21:47:41 +00:00
|
|
|
str.append("mirror");
|
|
|
|
break;
|
2019-04-03 14:27:45 +00:00
|
|
|
case SkTileMode::kDecal:
|
|
|
|
str.append("decal");
|
|
|
|
break;
|
2012-03-07 21:47:41 +00:00
|
|
|
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-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(640, 480); }
|
2012-03-07 21:47:41 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) 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.setSkew(SK_Scalar1, 0, 0, 0);
|
|
|
|
} 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
|
|
|
}
|
2021-07-17 02:19:26 +00:00
|
|
|
paint.setShader(getBitmap().makeShader(
|
|
|
|
fMode, fMode,
|
|
|
|
SkSamplingOptions(fDoFilter ? SkFilterMode::kLinear
|
|
|
|
: SkFilterMode::kNearest),
|
|
|
|
m));
|
2012-03-07 21:47:41 +00:00
|
|
|
|
2021-07-18 14:54:25 +00:00
|
|
|
canvas->translate(50, 50);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-07 21:47:41 +00:00
|
|
|
canvas->drawPaint(paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2012-03-07 21:47:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kClamp, false, false); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kRepeat, false, false); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kMirror, false, false); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kClamp, true, false); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kRepeat, true, false); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kMirror, true, false); )
|
|
|
|
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kClamp, false, true); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kRepeat, false, true); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kMirror, false, true); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kClamp, true, true); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kRepeat, true, true); )
|
|
|
|
DEF_GM( return new GiantBitmapGM(SkTileMode::kMirror, true, true); )
|