blob: 5d83fcdf1c2ff332ede0d47cdaf3cdf9ee810486 [file] [log] [blame]
Robert Phillips8ced6882016-12-16 11:47:46 -05001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkBitmap.h"
10#include "include/core/SkCanvas.h"
11#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkColorPriv.h"
13#include "include/core/SkImage.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#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 Phillips8ced6882016-12-16 11:47:46 -050023
John Stilesec9b4aa2020-08-07 13:05:14 -040024static sk_sp<SkImage> make_image(int firstBlackRow, int lastBlackRow) {
Robert Phillips8ced6882016-12-16 11:47:46 -050025 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 Reedac9f0c92020-12-23 10:11:33 -050040 return bm.asImage();
Robert Phillips8ced6882016-12-16 11:47:46 -050041}
42
43// GM to reproduce crbug.com/673261.
44class FilterBugGM : public skiagm::GM {
45public:
46 FilterBugGM() { this->setBGColor(SK_ColorRED); }
47
48protected:
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 Reedf3ac2af2021-02-05 12:55:38 -050061 static const SkSamplingOptions kSampling(SkCubicResampler::Mitchell());
Robert Phillips8ced6882016-12-16 11:47:46 -050062 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 Phillips8ced6882016-12-16 11:47:46 -050068 SkMatrix localMat;
69 localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 0.0f);
Mike Reedb612b6c2020-12-08 21:58:35 -050070 p1.setShader(fTop->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
71 kSampling, &localMat));
Robert Phillips8ced6882016-12-16 11:47:46 -050072
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 Phillips8ced6882016-12-16 11:47:46 -050082
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 Phillips8ced6882016-12-16 11:47:46 -050091 SkMatrix localMat;
92 localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 86.0f);
Mike Reedb612b6c2020-12-08 21:58:35 -050093 p3.setShader(fBot->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
94 kSampling, &localMat));
Robert Phillips8ced6882016-12-16 11:47:46 -050095
96 canvas->drawRect(r3, p3);
97 }
98 }
99
100private:
101 sk_sp<SkImage> fTop;
102 sk_sp<SkImage> fBot;
103
John Stiles7571f9e2020-09-02 22:42:33 -0400104 using INHERITED = skiagm::GM;
Robert Phillips8ced6882016-12-16 11:47:46 -0500105};
106
107//////////////////////////////////////////////////////////////////////////////
108
109DEF_GM(return new FilterBugGM;)