2 * Copyright 2016 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 "SkImageShader.h"
11 static const sk_sp<SkImage> make_image(int firstBlackRow, int lastBlackRow) {
12 static const int kWidth = 25;
13 static const int kHeight = 27;
16 bm.allocN32Pixels(kWidth, kHeight);
17 bm.eraseColor(SK_ColorWHITE);
18 for (int y = firstBlackRow; y < lastBlackRow; ++y) {
19 for (int x = 0; x < kWidth; ++x) {
20 *bm.getAddr32(x, y) = SkPackARGB32(0xFF, 0x0, 0x0, 0x0);
24 bm.setAlphaType(SkAlphaType::kOpaque_SkAlphaType);
27 return SkImage::MakeFromBitmap(bm);
30 // GM to reproduce crbug.com/673261.
31 class FilterBugGM : public skiagm::GM {
33 FilterBugGM() { this->setBGColor(SK_ColorRED); }
36 SkString onShortName() override { return SkString("filterbug"); }
38 SkISize onISize() override { return SkISize::Make(150, 150); }
40 void onOnceBeforeDraw() override {
41 // The top texture has 5 black rows on top and then 22 white rows on the bottom
42 fTop = make_image(0, 5);
43 // The bottom texture has 5 black rows on the bottom and then 22 white rows on the top
44 fBot = make_image(22, 27);
47 void onDraw(SkCanvas* canvas) override {
48 static const SkFilterQuality kFilterQuality = SkFilterQuality::kHigh_SkFilterQuality;
49 static const bool kDoAA = true;
52 SkRect r1 = SkRect::MakeXYWH(50.0f, 0.0f, 50.0f, 50.0f);
54 p1.setAntiAlias(kDoAA);
55 p1.setFilterQuality(kFilterQuality);
57 localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 0.0f);
58 p1.setShader(SkImageShader::Make(fTop,
59 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
62 canvas->drawRect(r1, p1);
66 SkRect r2 = SkRect::MakeXYWH(50.0f, 50.0f, 50.0f, 36.0f);
69 p2.setColor(SK_ColorWHITE);
70 p2.setAntiAlias(kDoAA);
71 p2.setFilterQuality(kFilterQuality);
73 canvas->drawRect(r2, p2);
77 SkRect r3 = SkRect::MakeXYWH(50.0f, 86.0f, 50.0f, 50.0f);
80 p3.setAntiAlias(kDoAA);
81 p3.setFilterQuality(kFilterQuality);
83 localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 86.0f);
84 p3.setShader(SkImageShader::Make(fBot,
85 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
88 canvas->drawRect(r3, p3);
96 typedef skiagm::GM INHERITED;
99 //////////////////////////////////////////////////////////////////////////////
101 DEF_GM(return new FilterBugGM;)