diff options
author | reed <reed@google.com> | 2015-12-16 08:38:15 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-16 08:38:16 -0800 |
commit | da420b976e61071cfe5de10556b4b23e519091d6 (patch) | |
tree | 79cba010f59bd353e51cbdc2494ff9f1ff423fce /gm | |
parent | 32704674f64cb6a14356dfebe060cd3484c06cc7 (diff) |
Reland of move drawSprite from canvas (patchset #1 id:1 of https://codereview.chromium.org/1529803004/ )
Reason for revert:
guard has landed in chrome
Original issue's description:
> Revert of remove drawSprite from canvas (patchset #4 id:60001 of https://codereview.chromium.org/1534443003/ )
>
> Reason for revert:
> need to remove an override in chrome
>
> Original issue's description:
> > remove drawSprite from canvas
> >
> > BUG=skia:
> >
> > Committed: https://skia.googlesource.com/skia/+/4657ce2324ea197507c4ba728d81138f56da13b1
>
> TBR=fmalita@chromium.org,robertphillips@google.com,senorblanco@chromium.org,mtklein@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/32704674f64cb6a14356dfebe060cd3484c06cc7
TBR=fmalita@chromium.org,robertphillips@google.com,senorblanco@chromium.org,mtklein@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1530203002
Diffstat (limited to 'gm')
-rw-r--r-- | gm/dropshadowimagefilter.cpp | 25 | ||||
-rw-r--r-- | gm/imagefiltersbase.cpp | 21 | ||||
-rw-r--r-- | gm/imagefilterscropped.cpp | 25 | ||||
-rw-r--r-- | gm/spritebitmap.cpp | 186 |
4 files changed, 8 insertions, 249 deletions
diff --git a/gm/dropshadowimagefilter.cpp b/gm/dropshadowimagefilter.cpp index 81824ab797..512c82de01 100644 --- a/gm/dropshadowimagefilter.cpp +++ b/gm/dropshadowimagefilter.cpp @@ -67,29 +67,6 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { canvas->restore(); } -static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { - SkPaint paint; - - SkIRect bounds; - r.roundOut(&bounds); - - SkBitmap bm; - bm.allocN32Pixels(bounds.width(), bounds.height()); - bm.eraseColor(SK_ColorRED); - SkCanvas c(bm); - - SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44); - paint.setColor(SK_ColorGREEN); - c.drawRect(SkRect::Make(cropRect), paint); - - paint.setImageFilter(imf); - SkPoint loc = { r.fLeft, r.fTop }; - canvas->getTotalMatrix().mapPoints(&loc, 1); - canvas->drawSprite(bm, - SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), - &paint); -} - /////////////////////////////////////////////////////////////////////////////// class DropShadowImageFilterGM : public skiagm::GM { @@ -113,7 +90,7 @@ protected: virtual void onDraw(SkCanvas* canvas) { void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { - draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text + draw_bitmap, draw_path, draw_paint, draw_text }; SkAutoTUnref<SkColorFilter> cf( diff --git a/gm/imagefiltersbase.cpp b/gm/imagefiltersbase.cpp index 0101a9c2a0..fbe4681da4 100644 --- a/gm/imagefiltersbase.cpp +++ b/gm/imagefiltersbase.cpp @@ -165,26 +165,6 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { canvas->drawBitmap(bm, 0, 0, &paint); } -static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { - SkPaint paint; - paint.setImageFilter(imf); - - SkIRect bounds; - r.roundOut(&bounds); - - SkBitmap bm; - bm.allocN32Pixels(bounds.width(), bounds.height()); - bm.eraseColor(SK_ColorTRANSPARENT); - SkCanvas c(bm); - draw_path(&c, r, nullptr); - - SkPoint loc = { r.fLeft, r.fTop }; - canvas->getTotalMatrix().mapPoints(&loc, 1); - canvas->drawSprite(bm, - SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), - &paint); -} - /////////////////////////////////////////////////////////////////////////////// class ImageFiltersBaseGM : public skiagm::GM { @@ -210,7 +190,6 @@ protected: draw_paint, draw_line, draw_rect, draw_path, draw_text, draw_bitmap, - draw_sprite }; SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED, diff --git a/gm/imagefilterscropped.cpp b/gm/imagefilterscropped.cpp index 745e8984db..4c6ef62356 100644 --- a/gm/imagefilterscropped.cpp +++ b/gm/imagefilterscropped.cpp @@ -65,29 +65,6 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { canvas->drawBitmap(bm, 0, 0, &paint); } -static void draw_sprite(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { - SkPaint paint; - - SkIRect bounds; - r.roundOut(&bounds); - - SkBitmap bm; - bm.allocN32Pixels(bounds.width(), bounds.height()); - bm.eraseColor(SK_ColorRED); - SkCanvas c(bm); - - SkIRect cropRect = SkIRect::MakeXYWH(10, 10, 44, 44); - paint.setColor(SK_ColorGREEN); - c.drawRect(SkRect::Make(cropRect), paint); - - paint.setImageFilter(imf); - SkPoint loc = { r.fLeft, r.fTop }; - canvas->getTotalMatrix().mapPoints(&loc, 1); - canvas->drawSprite(bm, - SkScalarRoundToInt(loc.fX), SkScalarRoundToInt(loc.fY), - &paint); -} - /////////////////////////////////////////////////////////////////////////////// class ImageFiltersCroppedGM : public skiagm::GM { @@ -135,7 +112,7 @@ protected: virtual void onDraw(SkCanvas* canvas) override { void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { - draw_sprite, draw_bitmap, draw_path, draw_paint, draw_text + draw_bitmap, draw_path, draw_paint, draw_text }; SkAutoTUnref<SkColorFilter> cf( diff --git a/gm/spritebitmap.cpp b/gm/spritebitmap.cpp index b199371e89..4f221d49fc 100644 --- a/gm/spritebitmap.cpp +++ b/gm/spritebitmap.cpp @@ -22,8 +22,8 @@ static void make_bm(SkBitmap* bm) { canvas.drawCircle(50, 50, 50, paint); } -static void draw_2_bitmaps(SkCanvas* canvas, const SkBitmap& bm, bool doClip, - int dx, int dy, SkImageFilter* filter = nullptr) { +static void draw_1_bitmap(SkCanvas* canvas, const SkBitmap& bm, bool doClip, + int dx, int dy, SkImageFilter* filter = nullptr) { SkAutoCanvasRestore acr(canvas, true); SkPaint paint; @@ -35,15 +35,6 @@ static void draw_2_bitmaps(SkCanvas* canvas, const SkBitmap& bm, bool doClip, paint.setImageFilter(filter); clipR.inset(5, 5); - if (doClip) { - canvas->save(); - canvas->clipRect(clipR); - } - canvas->drawSprite(bm, dx, dy, &paint); - if (doClip) { - canvas->restore(); - } - canvas->translate(SkIntToScalar(bm.width() + 20), 0); if (doClip) { @@ -83,13 +74,13 @@ protected: SkScalar sigma = 8; SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(sigma, sigma)); - draw_2_bitmaps(canvas, bm, false, dx, dy); + draw_1_bitmap(canvas, bm, false, dx, dy); dy += bm.height() + 20; - draw_2_bitmaps(canvas, bm, false, dx, dy, filter); + draw_1_bitmap(canvas, bm, false, dx, dy, filter); dy += bm.height() + 20; - draw_2_bitmaps(canvas, bm, true, dx, dy); + draw_1_bitmap(canvas, bm, true, dx, dy); dy += bm.height() + 20; - draw_2_bitmaps(canvas, bm, true, dx, dy, filter); + draw_1_bitmap(canvas, bm, true, dx, dy, filter); } private: @@ -196,22 +187,6 @@ protected: canvas->translate(spacer, 0); show_image(canvas, image2, offset2); // not snug - // Try drawing the original w/ the filter, to see that it "draws" the same as - // when we have manually applied the filter (above). - { - SkPaint paint; - paint.setImageFilter(filter); - - SkBitmap bm; - image0->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode); - SkPoint loc = { 0, 0 }; - canvas->translate(spacer, 0); - canvas->getTotalMatrix().mapPoints(&loc, 1); - canvas->drawSprite(bm, (int)loc.x(), (int)loc.y(), &paint); // like snug - - canvas->translate(spacer, 0); - canvas->drawImage(image0, 0, 0, &paint); // like not snug - } canvas->restore(); canvas->translate(0, spacer); @@ -222,152 +197,3 @@ private: typedef GM INHERITED; }; DEF_GM( return new ApplyFilterGM; ) - -////////////////////// - -#include "SkDisplacementMapEffect.h" -#include "SkMatrixConvolutionImageFilter.h" - -static SkPMColor max_component(SkPMColor a, SkPMColor b) { - int dr = SkAbs32(SkGetPackedR32(a) - SkGetPackedR32(b)); - int dg = SkAbs32(SkGetPackedG32(a) - SkGetPackedG32(b)); - int db = SkAbs32(SkGetPackedB32(a) - SkGetPackedB32(b)); - int d = SkTMax(dr, SkTMax(dg, db)); - d = 0xFF - d; - return SkPackARGB32(0xFF, d, d, d); -} - -static SkImage* compute_diff(SkImage* a, SkImage* b) { - SkASSERT(a->width() == b->width() && a->height() == b->height()); - const SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height()); - SkBitmap bma, bmb, bmdiff; - bma.allocPixels(info); - bmb.allocPixels(info); - bmdiff.allocPixels(info); - - a->readPixels(info, bma.getPixels(), bma.rowBytes(), 0, 0); - b->readPixels(info, bmb.getPixels(), bmb.rowBytes(), 0, 0); - for (int y = 0; y < info.height(); ++y) { - for (int x = 0; x < info.width(); ++x) { - *bmdiff.getAddr32(x, y) = max_component(*bma.getAddr32(x, y), *bmb.getAddr32(x, y)); - } - } - bmdiff.setImmutable(); // avoid the copy - return SkImage::NewFromBitmap(bmdiff); -} - -static SkImage* make_native_red_oval(SkCanvas* rootCanvas) { - SkImageInfo info = SkImageInfo::MakeN32Premul(160, 90); - SkAutoTUnref<SkSurface> surface(rootCanvas->newSurface(info)); - if (!surface) { - surface.reset(SkSurface::NewRaster(info)); - } - - SkPaint paint; - paint.setAntiAlias(true); - paint.setColor(SK_ColorRED); - surface->getCanvas()->drawOval(SkRect::MakeWH(160, 90), paint); - return surface->newImageSnapshot(); -} - - -static SkSurface* make_surface(SkCanvas* factory, const SkImageInfo& info) { - SkSurface* surface = factory->newSurface(info); - if (!surface) { - surface = SkSurface::NewRaster(info); - } - return surface; -} - -template <typename DrawProc> SkImage* snapshot(SkCanvas* canvas, const SkImageInfo& info, - DrawProc p) { - SkAutoTUnref<SkSurface> surface(make_surface(canvas, info)); - p(surface->getCanvas()); - return surface->newImageSnapshot(); -} - -/** - * Try drawing an image+imagefilter in two different ways - * 1. as drawSprite - * 2. as drawImage + clipped to image bounds - * The two should draw the same. To try to visualize this, we draw a 4th column of the difference - * between the two versions. If it is all black (where there is alpha), they drew the same! - */ -class DrawWithFilterGM : public skiagm::GM { -public: - DrawWithFilterGM() {} - -protected: - SkString onShortName() override { - return SkString("draw-with-filter"); - } - - SkISize onISize() override { - return SkISize::Make(780, 780); - } - - void onDraw(SkCanvas* canvas) override { - SkAutoTUnref<SkImage> image0(make_native_red_oval(canvas)); - SkAutoTUnref<SkImage> image1(make_native_red_oval(canvas)); - - const ImageFilterFactory factories[] = { - IFCCast([]{ return SkBlurImageFilter::Create(8, 8); }), - IFCCast([]{ SkAutoTUnref<SkColorFilter> cf(SkModeColorFilter::Create(SK_ColorBLUE, - SkXfermode::kSrcIn_Mode)); - return SkColorFilterImageFilter::Create(cf); - }), - IFCCast([]{ return SkDilateImageFilter::Create(8, 8); }), - IFCCast([]{ return SkErodeImageFilter::Create(8, 8); }), - IFCCast([]{ return SkOffsetImageFilter::Create(8, 8); }), - - IFCCast([]{ return (SkImageFilter*)SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kG_ChannelSelectorType, - 10, nullptr); }), - IFCCast([]{ - const SkScalar kernel[] = { 1, 1, 1, 1, -7, 1, 1, 1, 1 }; - return (SkImageFilter*)SkMatrixConvolutionImageFilter::Create( - SkISize::Make(3, 3), - kernel, 1, 0, - SkIPoint::Make(0, 0), - SkMatrixConvolutionImageFilter::kClamp_TileMode, - true); }), - }; - - const SkScalar dx = 180; - const SkScalar dy = 110; - const SkImageInfo info = SkImageInfo::MakeN32Premul(image0->width(), image0->height()); - - canvas->translate(20, 20); - for (auto&& factory : factories) { - SkAutoTUnref<SkImageFilter> filter(factory()); - SkPaint paint; - paint.setImageFilter(filter); - - SkAutoTUnref<SkImage> snap0(snapshot(canvas, info, [&](SkCanvas* c) { - c->drawImage(image0, 0, 0, &paint); - })); - canvas->drawImage(snap0, 0, 0); - - SkAutoTUnref<SkImage> snap1(snapshot(canvas, info, [&](SkCanvas* c) { - SkBitmap bm; - image1->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode); - c->drawSprite(bm, 0, 0, &paint); - })); - canvas->drawImage(snap1, dx, 0); - - SkAutoTUnref<SkImage> diff(snapshot(canvas, info, [&](SkCanvas* c) { - SkAutoTUnref<SkImage> diff(compute_diff(snap0, snap1)); - c->drawImage(diff, 0, 0); - })); - canvas->drawImage(diff, 2*dx, 0); - - canvas->translate(0, dy); - } - } - -private: - typedef GM INHERITED; -}; -DEF_GM( return new DrawWithFilterGM; ) - |