Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: tests/ImageFilterTest.cpp

Issue 920513003: Make filters use SkImage instead of SkBitmap Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/SkDeferredCanvas.cpp ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageFilterTest.cpp
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 87aabd1c8df000abfe41848a066e746755e49a74..6e34a7581341e1dad5a636b5461dbf2adcad19fa 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -18,6 +18,8 @@
#include "SkDropShadowImageFilter.h"
#include "SkFlattenableSerialization.h"
#include "SkGradientShader.h"
+#include "SkImagePriv.h"
+#include "SkImage_Base.h"
#include "SkLightingImageFilter.h"
#include "SkMatrixConvolutionImageFilter.h"
#include "SkMergeImageFilter.h"
@@ -49,9 +51,10 @@ public:
: SkImageFilter(0, NULL), fReporter(reporter), fExpectedMatrix(expectedMatrix) {
}
- virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context& ctx,
- SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE {
+ virtual bool onFilterImage(Proxy*, const SkImage* src, const Context& ctx,
+ SkAutoTUnref<const SkImage>& result, SkIPoint* offset) const SK_OVERRIDE {
REPORTER_ASSERT(fReporter, ctx.ctm() == fExpectedMatrix);
+ result.reset(SkRef(src));
return true;
}
@@ -269,9 +272,14 @@ static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
// Check that all filters offset to their absolute crop rect,
// unaffected by the input crop rect.
// Tests pass by not asserting.
- SkBitmap bitmap;
- bitmap.allocN32Pixels(100, 100);
- bitmap.eraseARGB(0, 0, 0, 0);
+ SkAutoTUnref<SkImage> image;
+ {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(100, 100);
+ bitmap.eraseARGB(0, 0, 0, 0);
+ image.reset(SkNewImageFromBitmap(bitmap, NULL));
+ REPORTER_ASSERT(reporter, image != NULL);
+ }
SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
@@ -312,13 +320,13 @@ static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
SkImageFilter* filter = filters[i];
- SkBitmap result;
+ SkAutoTUnref<const SkImage> result;
SkIPoint offset;
SkString str;
str.printf("filter %d", static_cast<int>(i));
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL);
- REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, ctx,
- &result, &offset), str.c_str());
+ REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, image, ctx,
+ result, &offset), str.c_str());
REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, str.c_str());
}
@@ -348,6 +356,7 @@ static SkBitmap make_gradient_circle(int width, int height) {
return bitmap;
}
+
static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* reporter) {
// Check that SkBlurImageFilter will accept a negative sigma, either in
// the given arguments or after CTM application.
@@ -363,18 +372,28 @@ static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r
SkBlurImageFilter::Create(-five, five)
);
- SkBitmap gradient = make_gradient_circle(width, height);
SkBitmap positiveResult1, negativeResult1;
SkBitmap positiveResult2, negativeResult2;
- SkIPoint offset;
- SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL);
- positiveFilter->filterImage(&proxy, gradient, ctx, &positiveResult1, &offset);
- negativeFilter->filterImage(&proxy, gradient, ctx, &negativeResult1, &offset);
- SkMatrix negativeScale;
- negativeScale.setScale(-SK_Scalar1, SK_Scalar1);
- SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest(), NULL);
- positiveFilter->filterImage(&proxy, gradient, negativeCTX, &negativeResult2, &offset);
- negativeFilter->filterImage(&proxy, gradient, negativeCTX, &positiveResult2, &offset);
+ {
+ SkAutoTUnref<SkImage> gradient(
+ SkNewImageFromBitmap(make_gradient_circle(width, height), NULL));
+ SkAutoTUnref<const SkImage> positiveResult1i, negativeResult1i;
+ SkAutoTUnref<const SkImage> positiveResult2i, negativeResult2i;
+ SkIPoint offset;
+ SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL);
+ positiveFilter->filterImage(&proxy, gradient, ctx, positiveResult1i, &offset);
+ negativeFilter->filterImage(&proxy, gradient, ctx, negativeResult1i, &offset);
+ SkMatrix negativeScale;
+ negativeScale.setScale(-SK_Scalar1, SK_Scalar1);
+ SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest(), NULL);
+ positiveFilter->filterImage(&proxy, gradient, negativeCTX, negativeResult2i, &offset);
+ negativeFilter->filterImage(&proxy, gradient, negativeCTX, positiveResult2i, &offset);
+ REPORTER_ASSERT(reporter, as_IB(positiveResult1i)->getROPixels(&positiveResult1));
+ REPORTER_ASSERT(reporter, as_IB(positiveResult2i)->getROPixels(&positiveResult2));
+ REPORTER_ASSERT(reporter, as_IB(negativeResult1i)->getROPixels(&negativeResult1));
+ REPORTER_ASSERT(reporter, as_IB(negativeResult2i)->getROPixels(&negativeResult2));
+ }
+
SkAutoLockPixels lockP1(positiveResult1);
SkAutoLockPixels lockP2(positiveResult2);
SkAutoLockPixels lockN1(negativeResult1);
@@ -874,14 +893,16 @@ DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) {
SkAutoTUnref<SkImageFilter> imageFilter(
SkPictureImageFilter::Create(picture.get()));
- SkBitmap result;
+ SkAutoTUnref<const SkImage> result;
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), NULL);
+ SkAutoTUnref<const SkImage> image;
SkBitmap bitmap;
bitmap.allocN32Pixels(2, 2);
+ image.reset(SkNewImageFromBitmap(bitmap, NULL));
SkBitmapDevice device(bitmap);
SkDeviceImageFilterProxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
- REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &result, &offset));
+ REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, image, ctx, result, &offset));
}
DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
@@ -1124,15 +1145,15 @@ DEF_TEST(ComposedImageFilterOffset, reporter) {
bitmap.eraseARGB(0, 0, 0, 0);
SkBitmapDevice device(bitmap);
SkDeviceImageFilterProxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
-
+ SkAutoTUnref<const SkImage> image(SkNewImageFromBitmap(bitmap, NULL));
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, NULL, &cropRect));
SkAutoTUnref<SkImageFilter> blurFilter(makeBlur());
SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blurFilter, offsetFilter.get()));
- SkBitmap result;
+ SkAutoTUnref<const SkImage> result;
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL);
- REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &result, &offset));
+ REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, image, ctx, result, &offset));
REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0);
}
« no previous file with comments | « src/utils/SkDeferredCanvas.cpp ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698