Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkBitmap.h" |
| 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkColorPriv.h" |
| 13 | #include "include/core/SkImage.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | #include "include/core/SkImageInfo.h" |
| 15 | #include "include/core/SkMatrix.h" |
| 16 | #include "include/core/SkPaint.h" |
| 17 | #include "include/core/SkRect.h" |
| 18 | #include "include/core/SkRefCnt.h" |
| 19 | #include "include/core/SkShader.h" |
| 20 | #include "include/core/SkSize.h" |
| 21 | #include "include/core/SkString.h" |
| 22 | #include "include/core/SkTileMode.h" |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 23 | |
John Stiles | ec9b4aa | 2020-08-07 13:05:14 -0400 | [diff] [blame] | 24 | static sk_sp<SkImage> make_image(int firstBlackRow, int lastBlackRow) { |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 25 | static const int kWidth = 25; |
| 26 | static const int kHeight = 27; |
| 27 | |
| 28 | SkBitmap bm; |
| 29 | bm.allocN32Pixels(kWidth, kHeight); |
| 30 | bm.eraseColor(SK_ColorWHITE); |
| 31 | for (int y = firstBlackRow; y < lastBlackRow; ++y) { |
| 32 | for (int x = 0; x < kWidth; ++x) { |
| 33 | *bm.getAddr32(x, y) = SkPackARGB32(0xFF, 0x0, 0x0, 0x0); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | bm.setAlphaType(SkAlphaType::kOpaque_SkAlphaType); |
| 38 | bm.setImmutable(); |
| 39 | |
Mike Reed | ac9f0c9 | 2020-12-23 10:11:33 -0500 | [diff] [blame] | 40 | return bm.asImage(); |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | // GM to reproduce crbug.com/673261. |
| 44 | class FilterBugGM : public skiagm::GM { |
| 45 | public: |
| 46 | FilterBugGM() { this->setBGColor(SK_ColorRED); } |
| 47 | |
| 48 | protected: |
| 49 | SkString onShortName() override { return SkString("filterbug"); } |
| 50 | |
| 51 | SkISize onISize() override { return SkISize::Make(150, 150); } |
| 52 | |
| 53 | void onOnceBeforeDraw() override { |
| 54 | // The top texture has 5 black rows on top and then 22 white rows on the bottom |
| 55 | fTop = make_image(0, 5); |
| 56 | // The bottom texture has 5 black rows on the bottom and then 22 white rows on the top |
| 57 | fBot = make_image(22, 27); |
| 58 | } |
| 59 | |
| 60 | void onDraw(SkCanvas* canvas) override { |
Mike Reed | f3ac2af | 2021-02-05 12:55:38 -0500 | [diff] [blame] | 61 | static const SkSamplingOptions kSampling(SkCubicResampler::Mitchell()); |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 62 | static const bool kDoAA = true; |
| 63 | |
| 64 | { |
| 65 | SkRect r1 = SkRect::MakeXYWH(50.0f, 0.0f, 50.0f, 50.0f); |
| 66 | SkPaint p1; |
| 67 | p1.setAntiAlias(kDoAA); |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 68 | SkMatrix localMat; |
| 69 | localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 0.0f); |
Mike Reed | b612b6c | 2020-12-08 21:58:35 -0500 | [diff] [blame] | 70 | p1.setShader(fTop->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, |
| 71 | kSampling, &localMat)); |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 72 | |
| 73 | canvas->drawRect(r1, p1); |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | SkRect r2 = SkRect::MakeXYWH(50.0f, 50.0f, 50.0f, 36.0f); |
| 78 | |
| 79 | SkPaint p2; |
| 80 | p2.setColor(SK_ColorWHITE); |
| 81 | p2.setAntiAlias(kDoAA); |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 82 | |
| 83 | canvas->drawRect(r2, p2); |
| 84 | } |
| 85 | |
| 86 | { |
| 87 | SkRect r3 = SkRect::MakeXYWH(50.0f, 86.0f, 50.0f, 50.0f); |
| 88 | |
| 89 | SkPaint p3; |
| 90 | p3.setAntiAlias(kDoAA); |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 91 | SkMatrix localMat; |
| 92 | localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 86.0f); |
Mike Reed | b612b6c | 2020-12-08 21:58:35 -0500 | [diff] [blame] | 93 | p3.setShader(fBot->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, |
| 94 | kSampling, &localMat)); |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 95 | |
| 96 | canvas->drawRect(r3, p3); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | private: |
| 101 | sk_sp<SkImage> fTop; |
| 102 | sk_sp<SkImage> fBot; |
| 103 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 104 | using INHERITED = skiagm::GM; |
Robert Phillips | 8ced688 | 2016-12-16 11:47:46 -0500 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | ////////////////////////////////////////////////////////////////////////////// |
| 108 | |
| 109 | DEF_GM(return new FilterBugGM;) |