blob: 89430e0bf889bd6c2f324cd81a4f5be5c9d55fbc [file] [log] [blame]
humper535e3b22014-10-27 10:32:06 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed1a9b9642016-03-13 14:13:58 -07007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
humper535e3b22014-10-27 10:32:06 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkBitmap.h"
11#include "include/core/SkPaint.h"
12#include "include/core/SkShader.h"
13#include "include/core/SkStream.h"
14#include "tools/Resources.h"
humper535e3b22014-10-27 10:32:06 -070015
humper535e3b22014-10-27 10:32:06 -070016 /***
17 *
18 * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
19 * when fractional image scaling was ignored by the high quality bitmap scaler.
20 *
21 ***/
22
23namespace skiagm {
24
25class TiledScaledBitmapGM : public GM {
26public:
27
28 TiledScaledBitmapGM() {
29 }
30
31protected:
mtklein36352bf2015-03-25 18:17:31 -070032 SkString onShortName() override {
humper535e3b22014-10-27 10:32:06 -070033 return SkString("tiledscaledbitmap");
34 }
35
mtklein36352bf2015-03-25 18:17:31 -070036 SkISize onISize() override {
humper535e3b22014-10-27 10:32:06 -070037 return SkISize::Make(1016, 616);
38 }
39
tfarina752e7eb2014-12-20 06:53:43 -080040 static SkBitmap make_bm(int width, int height) {
humper535e3b22014-10-27 10:32:06 -070041 SkBitmap bm;
42 bm.allocN32Pixels(width, height);
43 bm.eraseColor(SK_ColorTRANSPARENT);
44 SkCanvas canvas(bm);
45 SkPaint paint;
46 paint.setAntiAlias(true);
47 canvas.drawCircle(width/2.f, height/2.f, width/4.f, paint);
tfarina752e7eb2014-12-20 06:53:43 -080048 return bm;
humper535e3b22014-10-27 10:32:06 -070049 }
50
mtklein36352bf2015-03-25 18:17:31 -070051 void onOnceBeforeDraw() override {
humper535e3b22014-10-27 10:32:06 -070052 fBitmap = make_bm(360, 288);
53 }
54
mtklein36352bf2015-03-25 18:17:31 -070055 void onDraw(SkCanvas* canvas) override {
humper535e3b22014-10-27 10:32:06 -070056 SkPaint paint;
57
58 paint.setAntiAlias(true);
reed93a12152015-03-16 10:08:34 -070059 paint.setFilterQuality(kHigh_SkFilterQuality);
humper535e3b22014-10-27 10:32:06 -070060
61 SkMatrix mat;
62 mat.setScale(121.f/360.f, 93.f/288.f);
63 mat.postTranslate(-72, -72);
64
Mike Reed50acf8f2019-04-08 13:20:23 -040065 paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &mat));
Mike Reed3661bc92017-02-22 13:21:42 -050066 canvas->drawRect({ 8, 8, 1008, 608 }, paint);
humper535e3b22014-10-27 10:32:06 -070067 }
68
69private:
70 SkBitmap fBitmap;
71
72 typedef GM INHERITED;
73};
74
75//////////////////////////////////////////////////////////////////////////////
76
halcanary385fe4d2015-08-26 13:07:48 -070077DEF_GM(return new TiledScaledBitmapGM;)
humper535e3b22014-10-27 10:32:06 -070078}