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 */ 7 8 #include "gm/gm.h" 9 #include "include/core/SkBitmap.h" 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkColor.h" 12 #include "include/core/SkMatrix.h" 13 #include "include/core/SkPaint.h" 14 #include "include/core/SkShader.h" 15 #include "include/core/SkSize.h" 16 #include "include/core/SkString.h" 17 #include "include/core/SkTileMode.h" 18 19 /*** 20 * 21 * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly 22 * when fractional image scaling was ignored by the high quality bitmap scaler. 23 * 24 ***/ 25 26 namespace skiagm { 27 28 class TiledScaledBitmapGM : public GM { 29 public: 30 TiledScaledBitmapGM()31 TiledScaledBitmapGM() { 32 } 33 34 protected: onShortName()35 SkString onShortName() override { 36 return SkString("tiledscaledbitmap"); 37 } 38 onISize()39 SkISize onISize() override { 40 return SkISize::Make(1016, 616); 41 } 42 make_bm(int width,int height)43 static SkBitmap make_bm(int width, int height) { 44 SkBitmap bm; 45 bm.allocN32Pixels(width, height); 46 bm.eraseColor(SK_ColorTRANSPARENT); 47 SkCanvas canvas(bm); 48 SkPaint paint; 49 paint.setAntiAlias(true); 50 canvas.drawCircle(width/2.f, height/2.f, width/4.f, paint); 51 return bm; 52 } 53 onOnceBeforeDraw()54 void onOnceBeforeDraw() override { 55 fBitmap = make_bm(360, 288); 56 } 57 onDraw(SkCanvas * canvas)58 void onDraw(SkCanvas* canvas) override { 59 SkPaint paint; 60 61 paint.setAntiAlias(true); 62 63 SkMatrix mat; 64 mat.setScale(121.f/360.f, 93.f/288.f); 65 mat.postTranslate(-72, -72); 66 67 paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, 68 SkSamplingOptions(SkCubicResampler::Mitchell()), mat)); 69 canvas->drawRect({ 8, 8, 1008, 608 }, paint); 70 } 71 72 private: 73 SkBitmap fBitmap; 74 75 using INHERITED = GM; 76 }; 77 78 ////////////////////////////////////////////////////////////////////////////// 79 80 DEF_GM(return new TiledScaledBitmapGM;) 81 } // namespace skiagm 82