blob: 151a32f92130ce29120c535cf14900304f8dba66 [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"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkFilterQuality.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/core/SkImage.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040015#include "include/core/SkImageInfo.h"
16#include "include/core/SkMatrix.h"
17#include "include/core/SkPaint.h"
18#include "include/core/SkRect.h"
19#include "include/core/SkRefCnt.h"
20#include "include/core/SkShader.h"
21#include "include/core/SkSize.h"
22#include "include/core/SkString.h"
23#include "include/core/SkTileMode.h"
Robert Phillips8ced6882016-12-16 11:47:46 -050024
25static const sk_sp<SkImage> make_image(int firstBlackRow, int lastBlackRow) {
26 static const int kWidth = 25;
27 static const int kHeight = 27;
28
29 SkBitmap bm;
30 bm.allocN32Pixels(kWidth, kHeight);
31 bm.eraseColor(SK_ColorWHITE);
32 for (int y = firstBlackRow; y < lastBlackRow; ++y) {
33 for (int x = 0; x < kWidth; ++x) {
34 *bm.getAddr32(x, y) = SkPackARGB32(0xFF, 0x0, 0x0, 0x0);
35 }
36 }
37
38 bm.setAlphaType(SkAlphaType::kOpaque_SkAlphaType);
39 bm.setImmutable();
40
41 return SkImage::MakeFromBitmap(bm);
42}
43
44// GM to reproduce crbug.com/673261.
45class FilterBugGM : public skiagm::GM {
46public:
47 FilterBugGM() { this->setBGColor(SK_ColorRED); }
48
49protected:
50 SkString onShortName() override { return SkString("filterbug"); }
51
52 SkISize onISize() override { return SkISize::Make(150, 150); }
53
54 void onOnceBeforeDraw() override {
55 // The top texture has 5 black rows on top and then 22 white rows on the bottom
56 fTop = make_image(0, 5);
57 // The bottom texture has 5 black rows on the bottom and then 22 white rows on the top
58 fBot = make_image(22, 27);
59 }
60
61 void onDraw(SkCanvas* canvas) override {
62 static const SkFilterQuality kFilterQuality = SkFilterQuality::kHigh_SkFilterQuality;
63 static const bool kDoAA = true;
64
65 {
66 SkRect r1 = SkRect::MakeXYWH(50.0f, 0.0f, 50.0f, 50.0f);
67 SkPaint p1;
68 p1.setAntiAlias(kDoAA);
69 p1.setFilterQuality(kFilterQuality);
70 SkMatrix localMat;
71 localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 0.0f);
Mike Reede25b4472019-04-02 17:49:12 -040072 p1.setShader(fTop->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &localMat));
Robert Phillips8ced6882016-12-16 11:47:46 -050073
74 canvas->drawRect(r1, p1);
75 }
76
77 {
78 SkRect r2 = SkRect::MakeXYWH(50.0f, 50.0f, 50.0f, 36.0f);
79
80 SkPaint p2;
81 p2.setColor(SK_ColorWHITE);
82 p2.setAntiAlias(kDoAA);
83 p2.setFilterQuality(kFilterQuality);
84
85 canvas->drawRect(r2, p2);
86 }
87
88 {
89 SkRect r3 = SkRect::MakeXYWH(50.0f, 86.0f, 50.0f, 50.0f);
90
91 SkPaint p3;
92 p3.setAntiAlias(kDoAA);
93 p3.setFilterQuality(kFilterQuality);
94 SkMatrix localMat;
95 localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 86.0f);
Mike Reede25b4472019-04-02 17:49:12 -040096 p3.setShader(fBot->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &localMat));
Robert Phillips8ced6882016-12-16 11:47:46 -050097
98 canvas->drawRect(r3, p3);
99 }
100 }
101
102private:
103 sk_sp<SkImage> fTop;
104 sk_sp<SkImage> fBot;
105
106 typedef skiagm::GM INHERITED;
107};
108
109//////////////////////////////////////////////////////////////////////////////
110
111DEF_GM(return new FilterBugGM;)