diff options
author | robertphillips <robertphillips@google.com> | 2016-04-14 07:54:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-14 07:54:04 -0700 |
commit | b2a4dc6a350abe3b18ecac719e499600f739a6e2 (patch) | |
tree | a5a0c8972a01a729c1103ffeba17a21b681647a3 /gm/imagemagnifier.cpp | |
parent | e34635dee169b8710141d6d0841db1e2bde9626b (diff) |
Switch SkMagnifierImageFilter over to new onFilterImage interface
Additionally, this CL:
adds crop handling to the CPU path (the GPU path handled it but with a bug)
adds a cropRect (to better justify the applyCropRect)
adds a GM to exercise the cropRect
Note: I believe the handling of cropRects and clipping is deeply flawed but, at least, the two paths are consistently flawed now.
TBR=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1882943002
Review URL: https://codereview.chromium.org/1882943002
Diffstat (limited to 'gm/imagemagnifier.cpp')
-rw-r--r-- | gm/imagemagnifier.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gm/imagemagnifier.cpp b/gm/imagemagnifier.cpp index 5697aa2480..a012a9e396 100644 --- a/gm/imagemagnifier.cpp +++ b/gm/imagemagnifier.cpp @@ -6,8 +6,10 @@ */ #include "gm.h" +#include "SkImageSource.h" #include "SkMagnifierImageFilter.h" #include "SkRandom.h" +#include "SkSurface.h" #define WIDTH 500 #define HEIGHT 500 @@ -36,3 +38,51 @@ DEF_SIMPLE_GM_BG(imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK) { } canvas->restore(); } + +//////////////////////////////////////////////////////////////////////////////// +#define WIDTH_HEIGHT 256 + +static sk_sp<SkImage> make_img() { + const SkImageInfo info = SkImageInfo::MakeN32Premul(WIDTH_HEIGHT, WIDTH_HEIGHT); + + sk_sp<SkSurface> surf(SkSurface::MakeRaster(info)); + + SkCanvas* canvas = surf->getCanvas(); + + canvas->clear(0x0); + + SkPaint paint; + paint.setColor(SK_ColorBLUE); + + for (float pos = 0; pos < WIDTH_HEIGHT; pos += 16) { + canvas->drawLine(0, pos, SkIntToScalar(WIDTH_HEIGHT), pos, paint); + canvas->drawLine(pos, 0, pos, SkIntToScalar(WIDTH_HEIGHT), paint); + } + + return surf->makeImageSnapshot(); +} + +DEF_SIMPLE_GM_BG(imagemagnifier_cropped, canvas, WIDTH_HEIGHT, WIDTH_HEIGHT, SK_ColorBLACK) { + + sk_sp<SkImage> image(make_img()); + + sk_sp<SkImageFilter> imageSource(SkImageSource::Make(std::move(image))); + + SkRect srcRect = SkRect::MakeWH(SkIntToScalar(WIDTH_HEIGHT-32), + SkIntToScalar(WIDTH_HEIGHT-32)); + srcRect.inset(64.0f, 64.0f); + + static const SkScalar kInset = 64.0f; + + // Crop out a 16 pixel ring around the result + const SkRect rect = SkRect::MakeXYWH(16, 16, WIDTH_HEIGHT-32, WIDTH_HEIGHT-32); + SkImageFilter::CropRect cropRect(rect); + + SkPaint filterPaint; + filterPaint.setImageFilter(SkMagnifierImageFilter::Make(srcRect, kInset, + std::move(imageSource), + &cropRect)); + + canvas->saveLayer(nullptr, &filterPaint); + canvas->restore(); +} |