2014-10-27 17:32:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2016-03-13 21:13:58 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFilterQuality.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#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"
|
2014-10-27 17:32:06 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
*
|
|
|
|
* This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
|
|
|
|
* when fractional image scaling was ignored by the high quality bitmap scaler.
|
|
|
|
*
|
|
|
|
***/
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class TiledScaledBitmapGM : public GM {
|
|
|
|
public:
|
|
|
|
|
|
|
|
TiledScaledBitmapGM() {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-10-27 17:32:06 +00:00
|
|
|
return SkString("tiledscaledbitmap");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-10-27 17:32:06 +00:00
|
|
|
return SkISize::Make(1016, 616);
|
|
|
|
}
|
|
|
|
|
2014-12-20 14:53:43 +00:00
|
|
|
static SkBitmap make_bm(int width, int height) {
|
2014-10-27 17:32:06 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(width, height);
|
|
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
canvas.drawCircle(width/2.f, height/2.f, width/4.f, paint);
|
2014-12-20 14:53:43 +00:00
|
|
|
return bm;
|
2014-10-27 17:32:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2014-10-27 17:32:06 +00:00
|
|
|
fBitmap = make_bm(360, 288);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-10-27 17:32:06 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(kHigh_SkFilterQuality);
|
2014-10-27 17:32:06 +00:00
|
|
|
|
|
|
|
SkMatrix mat;
|
|
|
|
mat.setScale(121.f/360.f, 93.f/288.f);
|
|
|
|
mat.postTranslate(-72, -72);
|
|
|
|
|
2019-04-08 17:20:23 +00:00
|
|
|
paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &mat));
|
2017-02-22 18:21:42 +00:00
|
|
|
canvas->drawRect({ 8, 8, 1008, 608 }, paint);
|
2014-10-27 17:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkBitmap fBitmap;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new TiledScaledBitmapGM;)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|