OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1362 DEF_TEST(ComposedImageFilterOffset, reporter) { | 1362 DEF_TEST(ComposedImageFilterOffset, reporter) { |
1363 run_raster_test(reporter, 100, test_composed_imagefilter_offset); | 1363 run_raster_test(reporter, 100, test_composed_imagefilter_offset); |
1364 } | 1364 } |
1365 | 1365 |
1366 #if SK_SUPPORT_GPU | 1366 #if SK_SUPPORT_GPU |
1367 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ComposedImageFilterOffset_Gpu, reporter, context) { | 1367 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ComposedImageFilterOffset_Gpu, reporter, context) { |
1368 run_gpu_test(reporter, context, 100, test_composed_imagefilter_offset); | 1368 run_gpu_test(reporter, context, 100, test_composed_imagefilter_offset); |
1369 } | 1369 } |
1370 #endif | 1370 #endif |
1371 | 1371 |
1372 static void test_composed_imagefilter_bounds(SkImageFilter::Proxy* proxy, | |
1373 skiatest::Reporter* reporter, | |
1374 GrContext* context) { | |
1375 // The bounds passed to the inner filter must be filtered by the outer | |
reed1
2016/03/19 14:28:49
Some version of this comment might be useful in th
jbroman
2016/03/20 01:12:12
Copied the first three lines to SkComposeImageFilt
| |
1376 // filter, so that the inner filter produces the pixels that the outer | |
1377 // filter requires as input. This matters if the outer filter moves pixels. | |
1378 // Here, accounting for the outer offset is necessary so that the green | |
1379 // pixels of the picture are not clipped. | |
1380 | |
1381 SkPictureRecorder recorder; | |
1382 recorder.beginRecording(SkRect::MakeWH(200, 100)); | |
reed1
2016/03/19 14:28:49
btw -- beginRecording returns the canvas, so you d
jbroman
2016/03/20 01:12:12
Done.
| |
1383 SkCanvas* recordingCanvas = recorder.getRecordingCanvas(); | |
1384 recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); | |
1385 recordingCanvas->clear(SK_ColorGREEN); | |
1386 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | |
1387 sk_sp<SkImageFilter> pictureFilter( | |
1388 SkPictureImageFilter::Create(picture.get())); | |
1389 SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100)); | |
1390 sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(-100, 0, nullp tr, &cropRect)); | |
1391 sk_sp<SkImageFilter> composedFilter( | |
1392 SkComposeImageFilter::Create(offsetFilter.get(), pictureFilter.get())); | |
1393 | |
1394 sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, proxy, 100)); | |
1395 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); | |
1396 SkIPoint offset; | |
1397 sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(), ctx, &offset)); | |
1398 REPORTER_ASSERT(reporter, offset.isZero()); | |
1399 REPORTER_ASSERT(reporter, result); | |
1400 REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100) ); | |
1401 | |
1402 SkBitmap resultBM; | |
1403 TestingSpecialImageAccess::GetROPixels(result.get(), &resultBM); | |
1404 SkAutoLockPixels lock(resultBM); | |
1405 REPORTER_ASSERT(reporter, resultBM.getColor(50, 50) == SK_ColorGREEN); | |
1406 } | |
1407 | |
1408 DEF_TEST(ComposedImageFilterBounds, reporter) { | |
1409 run_raster_test(reporter, 100, test_composed_imagefilter_bounds); | |
1410 } | |
1411 | |
1412 #if SK_SUPPORT_GPU | |
1413 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ComposedImageFilterBounds_Gpu, reporter, context) { | |
1414 run_gpu_test(reporter, context, 100, test_composed_imagefilter_bounds); | |
1415 } | |
1416 #endif | |
1417 | |
1372 static void test_partial_crop_rect(SkImageFilter::Proxy* proxy, | 1418 static void test_partial_crop_rect(SkImageFilter::Proxy* proxy, |
1373 skiatest::Reporter* reporter, | 1419 skiatest::Reporter* reporter, |
1374 GrContext* context) { | 1420 GrContext* context) { |
1375 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) ); | 1421 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100) ); |
1376 | 1422 |
1377 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), | 1423 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), |
1378 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); | 1424 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k HasHeight_CropEdge); |
1379 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); | 1425 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); |
1380 SkIPoint offset; | 1426 SkIPoint offset; |
1381 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); | 1427 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr ); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1554 test_xfermode_cropped_input(&canvas, reporter); | 1600 test_xfermode_cropped_input(&canvas, reporter); |
1555 } | 1601 } |
1556 | 1602 |
1557 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1603 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
1558 SkAutoTUnref<SkSurface> surface( | 1604 SkAutoTUnref<SkSurface> surface( |
1559 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, | 1605 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, |
1560 SkImageInfo::MakeN32Premul(100, 100))); | 1606 SkImageInfo::MakeN32Premul(100, 100))); |
1561 test_large_blur_input(reporter, surface->getCanvas()); | 1607 test_large_blur_input(reporter, surface->getCanvas()); |
1562 } | 1608 } |
1563 #endif | 1609 #endif |
OLD | NEW |