skia2/gm/imageblurclampmode.cpp
wutao 0dc1f4f4cd Add GM image test for blur with clamp mode.
Adding a GM (Golden Master) image test in Skia to reproduce the bleed
black issue in Chrome. This would allow regressions to be caught in
Skia's status page before being rolled into Chrome.

Bug: 622128
Change-Id: Ifd2824fff59483c8e4be48392ba467414d41ca13
TEST=imageblurclampmode.cpp
Reviewed-on: https://skia-review.googlesource.com/20778
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2017-06-27 11:37:26 +00:00

101 lines
2.9 KiB
C++

/*
* Copyright 2017 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 "sk_tool_utils.h"
#include "SkSurface.h"
#include "SkBlurImageFilter.h"
static sk_sp<SkSurface> make_surface(SkCanvas* canvas, const SkImageInfo& info) {
auto surface = canvas->makeSurface(info);
if (!surface) {
surface = SkSurface::MakeRaster(info);
}
return surface;
}
static sk_sp<SkImage> make_image(SkCanvas* canvas) {
SkImageInfo info = SkImageInfo::MakeN32Premul(250, 200);
auto surface = make_surface(canvas, info);
SkCanvas* c = surface->getCanvas();
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorBLUE);
c->drawRect(SkRect::MakeIWH(info.width(), info.height()), paint);
paint.setColor(SK_ColorGREEN);
c->drawCircle(125, 100, 100, paint);
paint.setColor(SK_ColorRED);
c->drawRect(SkRect::MakeIWH(80, 80), paint);
return surface->makeImageSnapshot();
}
static void draw_image(SkCanvas* canvas, const sk_sp<SkImage> image, sk_sp<SkImageFilter> filter) {
SkAutoCanvasRestore acr(canvas, true);
SkPaint paint;
paint.setImageFilter(std::move(filter));
canvas->translate(SkIntToScalar(30), 0);
canvas->clipRect(SkRect::MakeIWH(image->width(),image->height()));
canvas->drawImage(image, 0, 0, &paint);
}
namespace skiagm {
// This GM draws one rectangle, one green inscribed circle, and one red square
// with different blur settings.
class ImageBlurClampModeGM : public GM {
public:
ImageBlurClampModeGM() {
this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
}
protected:
SkString onShortName() override {
return SkString("imageblurclampmode");
}
SkISize onISize() override {
return SkISize::Make(850, 920);
}
void onDraw(SkCanvas* canvas) override {
sk_sp<SkImage> image(make_image(canvas));
canvas->translate(0, 30);
// Test different kernel size, including the one to launch 2d Gaussian
// blur.
for (auto sigma: { 0.6f, 3.0f, 8.0f, 20.0f }) {
canvas->save();
sk_sp<SkImageFilter> filter(SkBlurImageFilter::Make(sigma, 0.0f, nullptr));
draw_image(canvas, image, std::move(filter));
canvas->translate(image->width() + 20, 0);
filter = SkBlurImageFilter::Make(0.0f, sigma, nullptr);
draw_image(canvas, image, std::move(filter));
canvas->translate(image->width() + 20, 0);
filter = SkBlurImageFilter::Make(sigma, sigma, nullptr);
draw_image(canvas, image, std::move(filter));
canvas->translate(image->width() + 20, 0);
canvas->restore();
canvas->translate(0, image->height() + 20);
}
}
private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM(return new ImageBlurClampModeGM;)
}