humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 7 | |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 8 | #include "gm.h" |
| 9 | |
| 10 | #include "Resources.h" |
| 11 | #include "SkBitmap.h" |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 12 | #include "SkPaint.h" |
| 13 | #include "SkShader.h" |
| 14 | #include "SkStream.h" |
| 15 | |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 16 | /*** |
| 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 | |
| 23 | namespace skiagm { |
| 24 | |
| 25 | class TiledScaledBitmapGM : public GM { |
| 26 | public: |
| 27 | |
| 28 | TiledScaledBitmapGM() { |
| 29 | } |
| 30 | |
| 31 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | SkString onShortName() override { |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 33 | return SkString("tiledscaledbitmap"); |
| 34 | } |
| 35 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 36 | SkISize onISize() override { |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 37 | return SkISize::Make(1016, 616); |
| 38 | } |
| 39 | |
tfarina | 752e7eb | 2014-12-20 06:53:43 -0800 | [diff] [blame] | 40 | static SkBitmap make_bm(int width, int height) { |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 41 | 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); |
tfarina | 752e7eb | 2014-12-20 06:53:43 -0800 | [diff] [blame] | 48 | return bm; |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 49 | } |
| 50 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 51 | void onOnceBeforeDraw() override { |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 52 | fBitmap = make_bm(360, 288); |
| 53 | } |
| 54 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 55 | void onDraw(SkCanvas* canvas) override { |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 56 | SkPaint paint; |
| 57 | |
| 58 | paint.setAntiAlias(true); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 59 | paint.setFilterQuality(kHigh_SkFilterQuality); |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 60 | |
| 61 | SkMatrix mat; |
| 62 | mat.setScale(121.f/360.f, 93.f/288.f); |
| 63 | mat.postTranslate(-72, -72); |
| 64 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 65 | paint.setShader(SkShader::MakeBitmapShader(fBitmap, SkShader::kRepeat_TileMode, |
| 66 | SkShader::kRepeat_TileMode, &mat)); |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 67 | canvas->drawRectCoords(8,8,1008, 608, paint); |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | SkBitmap fBitmap; |
| 72 | |
| 73 | typedef GM INHERITED; |
| 74 | }; |
| 75 | |
| 76 | ////////////////////////////////////////////////////////////////////////////// |
| 77 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 78 | DEF_GM(return new TiledScaledBitmapGM;) |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 79 | } |