From 8ced688a3a3489ac696e5ee2d10557b389fd4ebf Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Fri, 16 Dec 2016 11:47:46 -0500 Subject: [PATCH] Add GM for filtering bug For SkFilterQuality we get: High - repros for GPU Medium - repros for both! Low - repros for both! None - doesn't repro For AA quality (with filter quality fixed at High) we get: AA - repros for GPU BW - repros for GPU BUG=673261 Change-Id: Ibf0644352bfa9d9c0e2d166e396ce9e9799b6d9d Reviewed-on: https://skia-review.googlesource.com/6187 Commit-Queue: Robert Phillips Reviewed-by: Florin Malita --- gm/filterbug.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++++++ gn/gm.gni | 1 + 2 files changed, 102 insertions(+) create mode 100644 gm/filterbug.cpp diff --git a/gm/filterbug.cpp b/gm/filterbug.cpp new file mode 100644 index 0000000000..181ba7c4e2 --- /dev/null +++ b/gm/filterbug.cpp @@ -0,0 +1,101 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkImageShader.h" + +static const sk_sp make_image(int firstBlackRow, int lastBlackRow) { + static const int kWidth = 25; + static const int kHeight = 27; + + SkBitmap bm; + bm.allocN32Pixels(kWidth, kHeight); + bm.eraseColor(SK_ColorWHITE); + for (int y = firstBlackRow; y < lastBlackRow; ++y) { + for (int x = 0; x < kWidth; ++x) { + *bm.getAddr32(x, y) = SkPackARGB32(0xFF, 0x0, 0x0, 0x0); + } + } + + bm.setAlphaType(SkAlphaType::kOpaque_SkAlphaType); + bm.setImmutable(); + + return SkImage::MakeFromBitmap(bm); +} + +// GM to reproduce crbug.com/673261. +class FilterBugGM : public skiagm::GM { +public: + FilterBugGM() { this->setBGColor(SK_ColorRED); } + +protected: + SkString onShortName() override { return SkString("filterbug"); } + + SkISize onISize() override { return SkISize::Make(150, 150); } + + void onOnceBeforeDraw() override { + // The top texture has 5 black rows on top and then 22 white rows on the bottom + fTop = make_image(0, 5); + // The bottom texture has 5 black rows on the bottom and then 22 white rows on the top + fBot = make_image(22, 27); + } + + void onDraw(SkCanvas* canvas) override { + static const SkFilterQuality kFilterQuality = SkFilterQuality::kHigh_SkFilterQuality; + static const bool kDoAA = true; + + { + SkRect r1 = SkRect::MakeXYWH(50.0f, 0.0f, 50.0f, 50.0f); + SkPaint p1; + p1.setAntiAlias(kDoAA); + p1.setFilterQuality(kFilterQuality); + SkMatrix localMat; + localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 0.0f); + p1.setShader(SkImageShader::Make(fTop, + SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, + &localMat)); + + canvas->drawRect(r1, p1); + } + + { + SkRect r2 = SkRect::MakeXYWH(50.0f, 50.0f, 50.0f, 36.0f); + + SkPaint p2; + p2.setColor(SK_ColorWHITE); + p2.setAntiAlias(kDoAA); + p2.setFilterQuality(kFilterQuality); + + canvas->drawRect(r2, p2); + } + + { + SkRect r3 = SkRect::MakeXYWH(50.0f, 86.0f, 50.0f, 50.0f); + + SkPaint p3; + p3.setAntiAlias(kDoAA); + p3.setFilterQuality(kFilterQuality); + SkMatrix localMat; + localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 86.0f); + p3.setShader(SkImageShader::Make(fBot, + SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, + &localMat)); + + canvas->drawRect(r3, p3); + } + } + +private: + sk_sp fTop; + sk_sp fBot; + + typedef skiagm::GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +DEF_GM(return new FilterBugGM;) diff --git a/gn/gm.gni b/gn/gm.gni index e73c1a5b8a..a8e0eb46f2 100644 --- a/gn/gm.gni +++ b/gn/gm.gni @@ -118,6 +118,7 @@ gm_sources = [ "$_gm/filltypes.cpp", "$_gm/filltypespersp.cpp", "$_gm/filterbitmap.cpp", + "$_gm/filterbug.cpp", "$_gm/filterfastbounds.cpp", "$_gm/filterindiabox.cpp", "$_gm/fontcache.cpp",