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
This commit is contained in:
parent
446ee67fda
commit
c3176aa5e5
@ -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);
|
||||
fRedBitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
|
||||
create_circle_texture(&fRedBitmap, SK_ColorRED);
|
||||
|
||||
SkCanvas canvas(fBitmap);
|
||||
canvas.clear(0xFF000000);
|
||||
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorRED);
|
||||
paint.setStrokeWidth(3);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
SkBitmap* dst, SkIPoint* offset) const override;
|
||||
bool onFilterBounds(const SkIRect& src, const SkMatrix&,
|
||||
SkIRect* dst) const override;
|
||||
void computeFastBounds(const SkRect& src, SkRect* dst) const override;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTileImageFilter)
|
||||
|
@ -93,6 +93,12 @@ bool SkTileImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkTileImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const {
|
||||
// This is a workaround for skia:3194.
|
||||
*dst = src;
|
||||
dst->join(fDstRect);
|
||||
}
|
||||
|
||||
SkFlattenable* SkTileImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
|
||||
SkRect src, dst;
|
||||
|
Loading…
Reference in New Issue
Block a user