blob: 5511b8b3d9432e208571d86799d0a2853b8d48c3 [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
humper535e3b22014-10-27 10:32:06 -07008#include "gm.h"
9
10#include "Resources.h"
11#include "SkBitmap.h"
humper535e3b22014-10-27 10:32:06 -070012#include "SkPaint.h"
13#include "SkShader.h"
14#include "SkStream.h"
15
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
reed1a9b9642016-03-13 14:13:58 -070065 paint.setShader(SkShader::MakeBitmapShader(fBitmap, SkShader::kRepeat_TileMode,
66 SkShader::kRepeat_TileMode, &mat));
humper535e3b22014-10-27 10:32:06 -070067 canvas->drawRectCoords(8,8,1008, 608, paint);
68 }
69
70private:
71 SkBitmap fBitmap;
72
73 typedef GM INHERITED;
74};
75
76//////////////////////////////////////////////////////////////////////////////
77
halcanary385fe4d2015-08-26 13:07:48 -070078DEF_GM(return new TiledScaledBitmapGM;)
humper535e3b22014-10-27 10:32:06 -070079}