diff options
author | robertphillips <robertphillips@google.com> | 2015-06-16 09:44:56 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-16 09:44:56 -0700 |
commit | c3176aa5e578cc64a2534a9ddac2fec5ab6d8d77 (patch) | |
tree | 1dd1e9157c2147de3ef4817c2070312b190e5626 /gm/bigtileimagefilter.cpp | |
parent | 446ee67fda73b11281b8e28a68edec811347c0c5 (diff) |
Fix dst bound reported by SkTileImageFilter
In the example from the bug we had the filter DAG:
color filter (table)
0: xfermode filter (arith)
0: tile filter [0,80,34,114] -> [0,80,800,480]
0: color filter (table)
0: bitmap src 34x34 -> [0,80,34,114]
1: color filter (table)
0: picture filter [0, 80, 800, 480]
computeFastBounds was coming out of the DAG with a bound of [0,80,34,114] which didn't represent the pixels that would be drawn.
This CL updates SkTileImageFilter to correctly set the bound for the pixels it will hit.
BUG=493783
Committed: https://skia.googlesource.com/skia/+/05be93bbdf09576f7903130e3b106b0a8c7c4b4e
Committed: https://skia.googlesource.com/skia/+/0be685755f942baea26c66a87226b569fc17e960
Review URL: https://codereview.chromium.org/1152553006
Diffstat (limited to 'gm/bigtileimagefilter.cpp')
-rw-r--r-- | gm/bigtileimagefilter.cpp | 69 |
1 files changed, 50 insertions, 19 deletions
diff --git a/gm/bigtileimagefilter.cpp b/gm/bigtileimagefilter.cpp index 97de0d2042..f465fe4d38 100644 --- a/gm/bigtileimagefilter.cpp +++ b/gm/bigtileimagefilter.cpp @@ -9,6 +9,19 @@ #include "SkTileImageFilter.h" #include "gm.h" +static void create_circle_texture(SkBitmap* bm, SkColor color) { + SkCanvas canvas(*bm); + canvas.clear(0xFF000000); + + SkPaint paint; + paint.setColor(color); + paint.setStrokeWidth(3); + paint.setStyle(SkPaint::kStroke_Style); + + canvas.drawCircle(SkScalarHalf(bm->width()), SkScalarHalf(bm->height()), + SkScalarHalf(bm->width()), paint); +} + namespace skiagm { class BigTileImageFilterGM : public GM { @@ -28,35 +41,52 @@ protected: } void onOnceBeforeDraw() override { - fBitmap.allocN32Pixels(kBitmapSize, kBitmapSize); - - SkCanvas canvas(fBitmap); - canvas.clear(0xFF000000); - - SkPaint paint; - paint.setColor(SK_ColorRED); - paint.setStrokeWidth(3); - paint.setStyle(SkPaint::kStroke_Style); + fRedBitmap.allocN32Pixels(kBitmapSize, kBitmapSize); + create_circle_texture(&fRedBitmap, SK_ColorRED); - canvas.drawCircle(SkScalarHalf(kBitmapSize), SkScalarHalf(kBitmapSize), - SkScalarHalf(kBitmapSize), paint); + fGreenBitmap.allocN32Pixels(kBitmapSize, kBitmapSize); + create_circle_texture(&fGreenBitmap, SK_ColorGREEN); } void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorBLACK); - SkPaint p; + { + SkPaint p; - SkAutoTUnref<SkBitmapSource> bms(SkBitmapSource::Create(fBitmap)); - SkAutoTUnref<SkTileImageFilter> tif(SkTileImageFilter::Create( + SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)); + SkAutoTUnref<SkBitmapSource> bms(SkBitmapSource::Create(fRedBitmap)); + SkAutoTUnref<SkTileImageFilter> tif(SkTileImageFilter::Create( SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)), SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)), bms)); - p.setImageFilter(tif); + p.setImageFilter(tif); - SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)); - canvas->saveLayer(&bound, &p); - canvas->restore(); + canvas->saveLayer(&bound, &p); + canvas->restore(); + } + + { + SkPaint p2; + + SkRect bound2 = SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)); + + SkAutoTUnref<SkTileImageFilter> tif2(SkTileImageFilter::Create( + SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)), + SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)), + NULL)); + p2.setImageFilter(tif2); + + canvas->translate(320, 320); + canvas->saveLayer(&bound2, &p2); + canvas->setMatrix(SkMatrix::I()); + + SkRect bound3 = SkRect::MakeXYWH(320, 320, + SkIntToScalar(kBitmapSize), + SkIntToScalar(kBitmapSize)); + canvas->drawBitmapRectToRect(fGreenBitmap, &bound2, bound3); + canvas->restore(); + } } private: @@ -64,7 +94,8 @@ private: static const int kHeight = 512; static const int kBitmapSize = 64; - SkBitmap fBitmap; + SkBitmap fRedBitmap; + SkBitmap fGreenBitmap; typedef GM INHERITED; }; |