From cd56f812e09fdd8f8322c5c28cbc4423a74b9a0a Mon Sep 17 00:00:00 2001 From: fmalita Date: Mon, 14 Sep 2015 13:31:18 -0700 Subject: SkImageSource Blink is migrating away from SkBitmaps, so we need an SkImage-based SkImageFilter source. This is pretty much a 1-1 equivalent of SkBitmapSource. To avoid duplication, relocate the SkImage deserialization logic from SkPictureData to SkReadBuffer. R=reed@google.com,robertphillips@google.com,senorblanco@chromium.org Review URL: https://codereview.chromium.org/1343703005 --- tests/ImageFilterTest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 8c3206680a..8444bd38c3 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -17,6 +17,7 @@ #include "SkDropShadowImageFilter.h" #include "SkFlattenableSerialization.h" #include "SkGradientShader.h" +#include "SkImageSource.h" #include "SkLightingImageFilter.h" #include "SkMatrixConvolutionImageFilter.h" #include "SkMergeImageFilter.h" @@ -30,6 +31,7 @@ #include "SkReadBuffer.h" #include "SkRect.h" #include "SkRectShaderImageFilter.h" +#include "SkSurface.h" #include "SkTableColorFilter.h" #include "SkTileImageFilter.h" #include "SkXfermodeImageFilter.h" @@ -1212,6 +1214,30 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds()); } +// Verify that SkImageSource survives serialization +DEF_TEST(ImageFilterImageSourceSerialization, reporter) { + SkAutoTUnref surface(SkSurface::NewRasterN32Premul(10, 10)); + surface->getCanvas()->clear(SK_ColorGREEN); + SkAutoTUnref image(surface->newImageSnapshot()); + SkAutoTUnref filter(SkImageSource::Create(image)); + + SkAutoTUnref data(SkValidatingSerializeFlattenable(filter)); + SkAutoTUnref flattenable(SkValidatingDeserializeFlattenable( + data->data(), data->size(), SkImageFilter::GetFlattenableType())); + SkImageFilter* unflattenedFilter = static_cast(flattenable.get()); + REPORTER_ASSERT(reporter, unflattenedFilter); + + SkBitmap bm; + bm.allocN32Pixels(10, 10); + SkPaint paint; + paint.setColor(SK_ColorRED); + paint.setImageFilter(unflattenedFilter); + + SkCanvas canvas(bm); + canvas.drawRect(SkRect::MakeWH(10, 10), paint); + REPORTER_ASSERT(reporter, *bm.getAddr32(0, 0) == SkPreMultiplyColor(SK_ColorGREEN)); +} + #if SK_SUPPORT_GPU DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { -- cgit v1.2.3