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

Unified Diff: tests/ImageFilterTest.cpp

Issue 153113003: Fix image filter crop offsets for GPU path. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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
« src/core/SkImageFilter.cpp ('K') | « src/effects/SkBlurImageFilter.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 f936a7a3000f3a5631aaaf553cbd05601a6a85ee..5a411077344221184d4bee3bf6b991aefdc9777f 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -26,6 +26,11 @@
#include "SkXfermodeImageFilter.h"
#include "Test.h"
+#if SK_SUPPORT_GPU
+#include "GrContextFactory.h"
+#include "SkGpuDevice.h"
+#endif
+
static const int kBitmapSize = 4;
static void make_small_bitmap(SkBitmap& bitmap) {
@@ -156,64 +161,77 @@ DEF_TEST(ImageFilter, reporter) {
!bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &loc));
}
}
+}
- {
- // Check that all filters offset to their absolute crop rect,
- // unaffected by the input crop rect.
- // Tests pass by not asserting.
- SkBitmap bitmap, temp;
- bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
- bitmap.allocPixels();
- temp.allocPixels();
- bitmap.eraseARGB(0, 0, 0, 0);
- SkBitmapDevice device(temp);
- SkDeviceImageFilterProxy proxy(&device);
-
- SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
- SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
- SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect));
-
- SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
- SkPoint3 location(0, 0, SK_Scalar1);
- SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1);
- SkScalar kernel[9] = {
- SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
- SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
- SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
- };
- SkISize kernelSize = SkISize::Make(3, 3);
- SkScalar gain = SK_Scalar1, bias = 0;
-
- SkImageFilter* filters[] = {
- SkColorFilterImageFilter::Create(cf.get(), input.get(), &cropRect),
- new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelectorType,
- SkDisplacementMapEffect::kB_ChannelSelectorType,
- 40.0f, input.get(), input.get(), &cropRect),
- new SkBlurImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect),
- new SkDropShadowImageFilter(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, input.get(), &cropRect),
- SkLightingImageFilter::CreatePointLitDiffuse(location, SK_ColorGREEN, 0, 0, input.get(), &cropRect),
- SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0, 0, 0, input.get(), &cropRect),
- new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, input.get(), &cropRect),
- new SkMergeImageFilter(input.get(), input.get(), SkXfermode::kSrcOver_Mode, &cropRect),
- new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect),
- new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect),
- new SkDilateImageFilter(3, 2, input.get(), &cropRect),
- new SkErodeImageFilter(2, 3, input.get(), &cropRect),
- new SkTileImageFilter(inputCropRect.rect(), cropRect.rect(), input.get()),
- new SkXfermodeImageFilter(SkXfermode::Create(SkXfermode::kSrcOver_Mode), input.get(), input.get(), &cropRect),
- };
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
- SkImageFilter* filter = filters[i];
- SkBitmap result;
- SkIPoint offset;
- REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &offset));
- REPORTER_ASSERT(reporter, offset.fX == 20 && offset.fY == 30);
- }
+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.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
+ bitmap.allocPixels();
+ bitmap.eraseARGB(0, 0, 0, 0);
+ SkDeviceImageFilterProxy proxy(device);
+
+ SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
+ SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
+ SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect));
+
+ SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
+ SkPoint3 location(0, 0, SK_Scalar1);
+ SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1);
+ SkScalar kernel[9] = {
+ SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
+ SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
+ SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
+ };
+ SkISize kernelSize = SkISize::Make(3, 3);
+ SkScalar gain = SK_Scalar1, bias = 0;
+
+ SkImageFilter* filters[] = {
+ SkColorFilterImageFilter::Create(cf.get(), input.get(), &cropRect),
+ new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelectorType,
+ SkDisplacementMapEffect::kB_ChannelSelectorType,
+ 40.0f, input.get(), input.get(), &cropRect),
+ new SkBlurImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect),
+ new SkDropShadowImageFilter(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, input.get(), &cropRect),
+ SkLightingImageFilter::CreatePointLitDiffuse(location, SK_ColorGREEN, 0, 0, input.get(), &cropRect),
+ SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0, 0, 0, input.get(), &cropRect),
+ new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, input.get(), &cropRect),
+ new SkMergeImageFilter(input.get(), input.get(), SkXfermode::kSrcOver_Mode, &cropRect),
+ new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect),
+ new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect),
+ new SkDilateImageFilter(3, 2, input.get(), &cropRect),
+ new SkErodeImageFilter(2, 3, input.get(), &cropRect),
+ new SkTileImageFilter(inputCropRect.rect(), cropRect.rect(), input.get()),
+ new SkXfermodeImageFilter(SkXfermode::Create(SkXfermode::kSrcOver_Mode), input.get(), input.get(), &cropRect),
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
+ SkImageFilter* filter = filters[i];
+ SkBitmap result;
+ SkIPoint offset;
+ SkString str;
+ str.printf("filter %ld", i);
+ REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &offset), str.c_str());
+ REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, str.c_str());
+ }
- for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
- SkSafeUnref(filters[i]);
- }
+ for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
+ SkSafeUnref(filters[i]);
}
}
+
+DEF_TEST(ImageFilterCropRect, reporter) {
+ SkBitmap temp;
+ temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
+ temp.allocPixels();
+ SkBitmapDevice device(temp);
+ test_crop_rects(&device, reporter);
+}
+
+DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) {
+ GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(0));
+ SkGpuDevice device(context, SkBitmap::kARGB_8888_Config, 100, 100);
+ test_crop_rects(&device, reporter);
+}
« src/core/SkImageFilter.cpp ('K') | « src/effects/SkBlurImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698