aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2015-09-14 13:31:18 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-14 13:31:18 -0700
commitcd56f812e09fdd8f8322c5c28cbc4423a74b9a0a (patch)
tree7b4b54c3a4f7b89653635820d28026971b9b076a /tests
parent506c802a3dd3b6dc8a172621ff2a1f9bda202a13 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/ImageFilterTest.cpp26
1 files changed, 26 insertions, 0 deletions
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<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10));
+ surface->getCanvas()->clear(SK_ColorGREEN);
+ SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
+ SkAutoTUnref<SkImageFilter> filter(SkImageSource::Create(image));
+
+ SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter));
+ SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
+ data->data(), data->size(), SkImageFilter::GetFlattenableType()));
+ SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(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) {