OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBicubicImageFilter.h" | 8 #include "SkBicubicImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 static const int kBitmapSize = 4; | 36 static const int kBitmapSize = 4; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 class MatrixTestImageFilter : public SkImageFilter { | 40 class MatrixTestImageFilter : public SkImageFilter { |
41 public: | 41 public: |
42 MatrixTestImageFilter(skiatest::Reporter* reporter, const SkMatrix& expected
Matrix) | 42 MatrixTestImageFilter(skiatest::Reporter* reporter, const SkMatrix& expected
Matrix) |
43 : SkImageFilter(0), fReporter(reporter), fExpectedMatrix(expectedMatrix) { | 43 : SkImageFilter(0), fReporter(reporter), fExpectedMatrix(expectedMatrix) { |
44 } | 44 } |
45 | 45 |
46 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm, | 46 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context& ctx, |
47 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { | 47 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE { |
48 REPORTER_ASSERT(fReporter, ctm == fExpectedMatrix); | 48 REPORTER_ASSERT(fReporter, ctx.ctm() == fExpectedMatrix); |
49 return true; | 49 return true; |
50 } | 50 } |
51 | 51 |
52 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(MatrixTestImageFilter) | 52 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(MatrixTestImageFilter) |
53 | 53 |
54 protected: | 54 protected: |
55 explicit MatrixTestImageFilter(SkReadBuffer& buffer) : SkImageFilter(0) { | 55 explicit MatrixTestImageFilter(SkReadBuffer& buffer) : SkImageFilter(0) { |
56 fReporter = static_cast<skiatest::Reporter*>(buffer.readFunctionPtr()); | 56 fReporter = static_cast<skiatest::Reporter*>(buffer.readFunctionPtr()); |
57 buffer.readMatrix(&fExpectedMatrix); | 57 buffer.readMatrix(&fExpectedMatrix); |
58 } | 58 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 { | 183 { |
184 // This tests for scale bringing width to 0 | 184 // This tests for scale bringing width to 0 |
185 SkSize scale = SkSize::Make(-0.001f, SK_Scalar1); | 185 SkSize scale = SkSize::Make(-0.001f, SK_Scalar1); |
186 SkAutoTUnref<SkImageFilter> bmSrc(SkBitmapSource::Create(bitmap)); | 186 SkAutoTUnref<SkImageFilter> bmSrc(SkBitmapSource::Create(bitmap)); |
187 SkAutoTUnref<SkBicubicImageFilter> bicubic( | 187 SkAutoTUnref<SkBicubicImageFilter> bicubic( |
188 SkBicubicImageFilter::CreateMitchell(scale, bmSrc)); | 188 SkBicubicImageFilter::CreateMitchell(scale, bmSrc)); |
189 SkBitmapDevice device(bitmap); | 189 SkBitmapDevice device(bitmap); |
190 SkDeviceImageFilterProxy proxy(&device); | 190 SkDeviceImageFilterProxy proxy(&device); |
191 SkIPoint loc = SkIPoint::Make(0, 0); | 191 SkIPoint loc = SkIPoint::Make(0, 0); |
192 // An empty input should early return and return false | 192 // An empty input should early return and return false |
| 193 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeEmpty()); |
193 REPORTER_ASSERT(reporter, | 194 REPORTER_ASSERT(reporter, |
194 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(),
&result, &loc)); | 195 !bicubic->filterImage(&proxy, bitmap, ctx, &result,
&loc)); |
195 } | 196 } |
196 } | 197 } |
197 } | 198 } |
198 | 199 |
199 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ | 200 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ |
200 // Check that all filters offset to their absolute crop rect, | 201 // Check that all filters offset to their absolute crop rect, |
201 // unaffected by the input crop rect. | 202 // unaffected by the input crop rect. |
202 // Tests pass by not asserting. | 203 // Tests pass by not asserting. |
203 SkBitmap bitmap; | 204 SkBitmap bitmap; |
204 bitmap.allocN32Pixels(100, 100); | 205 bitmap.allocN32Pixels(100, 100); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g
et()), | 239 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g
et()), |
239 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo
de), input.get(), input.get(), &cropRect), | 240 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo
de), input.get(), input.get(), &cropRect), |
240 }; | 241 }; |
241 | 242 |
242 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 243 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
243 SkImageFilter* filter = filters[i]; | 244 SkImageFilter* filter = filters[i]; |
244 SkBitmap result; | 245 SkBitmap result; |
245 SkIPoint offset; | 246 SkIPoint offset; |
246 SkString str; | 247 SkString str; |
247 str.printf("filter %d", static_cast<int>(i)); | 248 str.printf("filter %d", static_cast<int>(i)); |
248 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, Sk
Matrix::I(), &result, &offset), str.c_str()); | 249 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeEmpty()); |
| 250 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, ct
x, &result, &offset), str.c_str()); |
249 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); | 251 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); |
250 } | 252 } |
251 | 253 |
252 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 254 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
253 SkSafeUnref(filters[i]); | 255 SkSafeUnref(filters[i]); |
254 } | 256 } |
255 } | 257 } |
256 | 258 |
257 DEF_TEST(ImageFilterCropRect, reporter) { | 259 DEF_TEST(ImageFilterCropRect, reporter) { |
258 SkBitmap temp; | 260 SkBitmap temp; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 297 |
296 #if SK_SUPPORT_GPU | 298 #if SK_SUPPORT_GPU |
297 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { | 299 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { |
298 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 300 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
299 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 301 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
300 SkImageInfo::MakeN32Pre
mul(100, 100), | 302 SkImageInfo::MakeN32Pre
mul(100, 100), |
301 0)); | 303 0)); |
302 test_crop_rects(device, reporter); | 304 test_crop_rects(device, reporter); |
303 } | 305 } |
304 #endif | 306 #endif |
OLD | NEW |