2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkFont.h"
12 #include "include/core/SkMatrix.h"
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkRect.h"
15 #include "include/core/SkScalar.h"
16 #include "include/core/SkShader.h"
17 #include "include/core/SkSize.h"
18 #include "include/core/SkString.h"
19 #include "include/core/SkTileMode.h"
20 #include "include/core/SkTypeface.h"
21 #include "include/core/SkTypes.h"
22 #include "tools/ToolUtils.h"
24 // Inspired by svg/as-border-image/svg-as-border-image.html. Draws a four-color checker board bitmap
25 // such that it is stretched and repeat tiled with different filter qualities. It is testing whether
26 // the bmp filter respects the repeat mode at the tile seams.
27 class BmpFilterQualityRepeat : public skiagm::GM {
29 BmpFilterQualityRepeat() { this->setBGColor(ToolUtils::color_to_565(0xFFCCBBAA)); }
33 void onOnceBeforeDraw() override {
34 fBmp.allocN32Pixels(40, 40, true);
35 SkCanvas canvas(fBmp);
37 colorBmp.allocN32Pixels(20, 20, true);
38 colorBmp.eraseColor(0xFFFF0000);
39 canvas.drawImage(colorBmp.asImage(), 0, 0);
40 colorBmp.eraseColor(ToolUtils::color_to_565(0xFF008200));
41 canvas.drawImage(colorBmp.asImage(), 20, 0);
42 colorBmp.eraseColor(ToolUtils::color_to_565(0xFFFF9000));
43 canvas.drawImage(colorBmp.asImage(), 0, 20);
44 colorBmp.eraseColor(ToolUtils::color_to_565(0xFF2000FF));
45 canvas.drawImage(colorBmp.asImage(), 20, 20);
48 SkString onShortName() override { return SkString("bmp_filter_quality_repeat"); }
50 SkISize onISize() override { return SkISize::Make(1000, 400); }
52 void onDraw(SkCanvas* canvas) override {
53 this->drawAll(canvas, 2.5f);
54 canvas->translate(0, 250);
55 canvas->scale(0.5, 0.5);
56 this->drawAll(canvas, 1);
60 void drawAll(SkCanvas* canvas, SkScalar scaleX) const {
61 SkRect rect = SkRect::MakeLTRB(20, 60, 220, 210);
62 SkMatrix lm = SkMatrix::I();
64 lm.setTranslateX(423);
65 lm.setTranslateY(330);
68 textPaint.setAntiAlias(true);
70 SkPaint bmpPaint(textPaint);
72 SkFont font(ToolUtils::create_portable_typeface());
74 SkAutoCanvasRestore acr(canvas, true);
78 SkSamplingOptions sampling;
80 { "none", SkSamplingOptions(SkFilterMode::kNearest) },
81 { "low", SkSamplingOptions(SkFilterMode::kLinear) },
82 { "medium", SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear) },
83 { "high", SkSamplingOptions(SkCubicResampler::Mitchell()) },
86 for (const auto& rec : recs) {
87 constexpr SkTileMode kTM = SkTileMode::kRepeat;
88 bmpPaint.setShader(fBmp.makeShader(kTM, kTM, rec.sampling, lm));
89 canvas->drawRect(rect, bmpPaint);
90 canvas->drawString(rec.name, 20, 40, font, textPaint);
91 canvas->translate(250, 0);
98 using INHERITED = skiagm::GM;
101 //////////////////////////////////////////////////////////////////////////////
103 DEF_GM(return new BmpFilterQualityRepeat;)