1 /* 2 * Copyright 2015 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.h" 9 10 #include "SkShader.h" 11 12 // Inspired by svg/as-border-image/svg-as-border-image.html. Draws a four-color checker board bitmap 13 // such that it is stretched and repeat tiled with different filter qualities. It is testing whether 14 // the bmp filter respects the repeat mode at the tile seams. 15 class BmpFilterQualityRepeat : public skiagm::GM { 16 public: BmpFilterQualityRepeat()17 BmpFilterQualityRepeat() { this->setBGColor(0xFFCCBBAA); } 18 19 protected: 20 onOnceBeforeDraw()21 void onOnceBeforeDraw() override { 22 fBmp.allocN32Pixels(40, 40, true); 23 SkCanvas canvas(fBmp); 24 SkBitmap colorBmp; 25 colorBmp.allocN32Pixels(20, 20, true); 26 colorBmp.eraseColor(0xFFFF0000); 27 canvas.drawBitmap(colorBmp, 0, 0); 28 colorBmp.eraseColor(0xFF008200); 29 canvas.drawBitmap(colorBmp, 20, 0); 30 colorBmp.eraseColor(0xFFFF9000); 31 canvas.drawBitmap(colorBmp, 0, 20); 32 colorBmp.eraseColor(0xFF2000FF); 33 canvas.drawBitmap(colorBmp, 20, 20); 34 } 35 onShortName()36 SkString onShortName() override { return SkString("bmp_filter_quality_repeat"); } 37 onISize()38 SkISize onISize() override { return SkISize::Make(1000, 235); } 39 onDraw(SkCanvas * canvas)40 void onDraw(SkCanvas* canvas) override { 41 42 static const struct { 43 SkFilterQuality fQuality; 44 const char* fName; 45 } kQualities[] = { 46 {kNone_SkFilterQuality, "none"}, 47 {kLow_SkFilterQuality, "low"}, 48 {kMedium_SkFilterQuality, "medium"}, 49 {kHigh_SkFilterQuality, "high"}, 50 }; 51 52 for (size_t q = 0; q < SK_ARRAY_COUNT(kQualities); ++q) { 53 SkPaint paint; 54 paint.setFilterQuality(kQualities[q].fQuality); 55 SkPaint bmpPaint(paint); 56 SkMatrix lm = SkMatrix::I(); 57 lm.setScaleX(2.5); 58 lm.setTranslateX(423); 59 lm.setTranslateY(330); 60 61 static const SkShader::TileMode kTM = SkShader::kRepeat_TileMode; 62 bmpPaint.setShader(SkShader::CreateBitmapShader(fBmp, kTM, kTM, &lm))->unref(); 63 SkRect rect = SkRect::MakeLTRB(20, 60, 220, 210); 64 canvas->drawRect(rect, bmpPaint); 65 paint.setAntiAlias(true); 66 canvas->drawText(kQualities[q].fName, strlen(kQualities[q].fName), 20, 40, paint); 67 canvas->translate(250, 0); 68 } 69 } 70 71 private: 72 SkBitmap fBmp; 73 74 typedef skiagm::GM INHERITED; 75 }; 76 77 ////////////////////////////////////////////////////////////////////////////// 78 79 DEF_GM( return SkNEW(BmpFilterQualityRepeat); ) 80