Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Unified Diff: gm/imagealphathreshold.cpp

Issue 1609573002: Fix SkAlphaThresholdFilter bounds handling. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix nits Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/effects/SkAlphaThresholdFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/imagealphathreshold.cpp
diff --git a/gm/imagealphathreshold.cpp b/gm/imagealphathreshold.cpp
index 13a0ffa90b404fcf2a1c8c098940107ff5b1b2e5..ea7185be1dbb8747d8cadcd9109f8ef3a602ed38 100644
--- a/gm/imagealphathreshold.cpp
+++ b/gm/imagealphathreshold.cpp
@@ -8,10 +8,39 @@
#include "gm.h"
#include "SkAlphaThresholdFilter.h"
#include "SkRandom.h"
+#include "SkSurface.h"
#define WIDTH 500
#define HEIGHT 500
+namespace {
+
+void draw_rects(SkCanvas* canvas) {
+ SkPaint rectPaint;
+ rectPaint.setColor(0xFF0000FF);
+ canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2), rectPaint);
+ rectPaint.setColor(0xBFFF0000);
+ canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2), rectPaint);
+ rectPaint.setColor(0x3F00FF00);
+ canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rectPaint);
+ rectPaint.setColor(0x00000000);
+ canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rectPaint);
+}
+
+SkPaint create_filter_paint() {
+ SkIRect rects[2];
+ rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300);
+ rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT);
+ SkRegion region;
+ region.setRects(rects, 2);
+
+ SkPaint paint;
+ paint.setImageFilter(SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref();
+ return paint;
+}
+
+};
+
namespace skiagm {
class ImageAlphaThresholdGM : public GM {
@@ -31,12 +60,6 @@ protected:
}
void onDraw(SkCanvas* canvas) override {
- SkIRect rects[2];
- rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300);
- rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT);
- SkRegion region;
- region.setRects(rects, 2);
-
SkMatrix matrix;
matrix.reset();
matrix.setTranslate(WIDTH * .1f, HEIGHT * .1f);
@@ -44,25 +67,9 @@ protected:
canvas->concat(matrix);
- SkPaint paint;
- paint.setImageFilter(
- SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref();
+ SkPaint paint = create_filter_paint();
canvas->saveLayer(nullptr, &paint);
- paint.setAntiAlias(true);
-
- SkPaint rect_paint;
- rect_paint.setColor(0xFF0000FF);
- canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2),
- rect_paint);
- rect_paint.setColor(0xBFFF0000);
- canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2),
- rect_paint);
- rect_paint.setColor(0x3F00FF00);
- canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
- rect_paint);
- rect_paint.setColor(0x00000000);
- canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
- rect_paint);
+ draw_rects(canvas);
canvas->restore();
}
@@ -71,9 +78,43 @@ private:
typedef GM INHERITED;
};
+class ImageAlphaThresholdSurfaceGM : public GM {
+public:
+ ImageAlphaThresholdSurfaceGM() {
+ this->setBGColor(0xFFFFFFFF);
+ }
+
+protected:
+ SkString onShortName() override {
+ return SkString("imagealphathreshold_surface");
+ }
+
+ SkISize onISize() override {
+ return SkISize::Make(WIDTH, HEIGHT);
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ SkImageInfo info = SkImageInfo::MakeN32(WIDTH, HEIGHT, kOpaque_SkAlphaType);
+ SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
+ if (nullptr == surface) {
+ surface.reset(SkSurface::NewRaster(info));
+ }
+ surface->getCanvas()->clear(SK_ColorWHITE);
+ draw_rects(surface->getCanvas());
+
+ SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
+ SkPaint paint = create_filter_paint();
+ canvas->clipRect(SkRect::MakeLTRB(100, 100, WIDTH - 100, HEIGHT - 100));
+ canvas->drawImage(image, 0, 0, &paint);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
//////////////////////////////////////////////////////////////////////////////
-static GM* MyFactory(void*) { return new ImageAlphaThresholdGM; }
-static GMRegistry reg(MyFactory);
+DEF_GM(return new ImageAlphaThresholdGM();)
+DEF_GM(return new ImageAlphaThresholdSurfaceGM();)
}
« no previous file with comments | « no previous file | src/effects/SkAlphaThresholdFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698