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

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, 10 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
« include/core/SkImageFilter.h ('K') | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | 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 55499d74c37058e79b035ec230743c6996c61899..c75db176ea92e4c72043d1d5a266672e0a08a459 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -17,6 +17,8 @@
#include "SkDropShadowImageFilter.h"
#include "SkFlattenableSerialization.h"
#include "SkGradientShader.h"
+#include "SkImagePriv.h"
+#include "SkImage_Base.h"
#include "SkLightingImageFilter.h"
#include "SkMatrixConvolutionImageFilter.h"
#include "SkMatrixImageFilter.h"
@@ -233,9 +235,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, true, NULL));
+ REPORTER_ASSERT(reporter, image != NULL);
+ }
SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
@@ -276,13 +283,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<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());
}
@@ -312,6 +319,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.
@@ -327,18 +335,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), true, NULL));
+ SkAutoTUnref<SkImage> positiveResult1i, negativeResult1i;
+ SkAutoTUnref<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);
@@ -824,14 +842,16 @@ DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) {
SkAutoTUnref<SkImageFilter> imageFilter(
SkPictureImageFilter::Create(picture.get()));
- SkBitmap result;
+ SkAutoTUnref<SkImage> result;
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), NULL);
+ SkAutoTUnref<SkImage> image;
SkBitmap bitmap;
bitmap.allocN32Pixels(2, 2);
+ image.reset(SkNewImageFromBitmap(bitmap, true, 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) {
« include/core/SkImageFilter.h ('K') | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698