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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
11 #include "SkBlurImageFilter.h" | 11 #include "SkBlurImageFilter.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkColorFilterImageFilter.h" | 13 #include "SkColorFilterImageFilter.h" |
14 #include "SkColorMatrixFilter.h" | 14 #include "SkColorMatrixFilter.h" |
| 15 #include "SkComposeImageFilter.h" |
15 #include "SkDeviceImageFilterProxy.h" | 16 #include "SkDeviceImageFilterProxy.h" |
16 #include "SkDisplacementMapEffect.h" | 17 #include "SkDisplacementMapEffect.h" |
17 #include "SkDropShadowImageFilter.h" | 18 #include "SkDropShadowImageFilter.h" |
18 #include "SkFlattenableSerialization.h" | 19 #include "SkFlattenableSerialization.h" |
19 #include "SkGradientShader.h" | 20 #include "SkGradientShader.h" |
20 #include "SkLightingImageFilter.h" | 21 #include "SkLightingImageFilter.h" |
21 #include "SkMatrixConvolutionImageFilter.h" | 22 #include "SkMatrixConvolutionImageFilter.h" |
22 #include "SkMatrixImageFilter.h" | 23 #include "SkMatrixImageFilter.h" |
23 #include "SkMergeImageFilter.h" | 24 #include "SkMergeImageFilter.h" |
24 #include "SkMorphologyImageFilter.h" | 25 #include "SkMorphologyImageFilter.h" |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 SkAutoTUnref<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2)); | 578 SkAutoTUnref<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2)); |
578 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); | 579 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); |
579 | 580 |
580 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); | 581 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
581 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); | 582 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); |
582 filter2->filterBounds(bounds, SkMatrix::I(), &bounds); | 583 filter2->filterBounds(bounds, SkMatrix::I(), &bounds); |
583 | 584 |
584 REPORTER_ASSERT(reporter, bounds == expectedBounds); | 585 REPORTER_ASSERT(reporter, bounds == expectedBounds); |
585 } | 586 } |
586 | 587 |
| 588 DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) { |
| 589 SkAutoTUnref<SkImageFilter> filter1(makeBlur()); |
| 590 SkAutoTUnref<SkImageFilter> filter2(makeBlur()); |
| 591 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(filt
er1.get(), filter2.get())); |
| 592 |
| 593 SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 594 SkRect expectedBounds = SkRect::MakeXYWH( |
| 595 SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar(
112)); |
| 596 SkRect boundsDst = SkRect::MakeEmpty(); |
| 597 composedFilter->computeFastBounds(boundsSrc, &boundsDst); |
| 598 |
| 599 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); |
| 600 } |
| 601 |
587 static void draw_blurred_rect(SkCanvas* canvas) { | 602 static void draw_blurred_rect(SkCanvas* canvas) { |
588 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); | 603 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); |
589 SkPaint filterPaint; | 604 SkPaint filterPaint; |
590 filterPaint.setColor(SK_ColorWHITE); | 605 filterPaint.setColor(SK_ColorWHITE); |
591 filterPaint.setImageFilter(filter); | 606 filterPaint.setImageFilter(filter); |
592 canvas->saveLayer(NULL, &filterPaint); | 607 canvas->saveLayer(NULL, &filterPaint); |
593 SkPaint whitePaint; | 608 SkPaint whitePaint; |
594 whitePaint.setColor(SK_ColorWHITE); | 609 whitePaint.setColor(SK_ColorWHITE); |
595 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); | 610 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); |
596 canvas->restore(); | 611 canvas->restore(); |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); | 1076 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
1062 } | 1077 } |
1063 | 1078 |
1064 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { | 1079 DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { |
1065 SkBitmap temp; | 1080 SkBitmap temp; |
1066 temp.allocN32Pixels(100, 100); | 1081 temp.allocN32Pixels(100, 100); |
1067 SkBitmapDevice device(temp); | 1082 SkBitmapDevice device(temp); |
1068 test_xfermode_cropped_input(&device, reporter); | 1083 test_xfermode_cropped_input(&device, reporter); |
1069 } | 1084 } |
1070 | 1085 |
| 1086 DEF_TEST(ComposedImageFilterOffset, reporter) { |
| 1087 SkBitmap bitmap; |
| 1088 bitmap.allocN32Pixels(100, 100); |
| 1089 bitmap.eraseARGB(0, 0, 0, 0); |
| 1090 SkBitmapDevice device(bitmap); |
| 1091 SkDeviceImageFilterProxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLega
cyFontHost_InitType)); |
| 1092 |
| 1093 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
| 1094 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, N
ULL, &cropRect)); |
| 1095 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(make
Blur(), offsetFilter.get())); |
| 1096 SkBitmap result; |
| 1097 SkIPoint offset; |
| 1098 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL); |
| 1099 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &
result, &offset)); |
| 1100 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
| 1101 } |
| 1102 |
1071 #if SK_SUPPORT_GPU | 1103 #if SK_SUPPORT_GPU |
1072 const SkSurfaceProps gProps = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_Ini
tType); | 1104 const SkSurfaceProps gProps = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_Ini
tType); |
1073 | 1105 |
1074 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { | 1106 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { |
1075 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 1107 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
1076 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1108 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
1077 SkSurface::kNo_Budgeted
, | 1109 SkSurface::kNo_Budgeted
, |
1078 SkImageInfo::MakeN32Pre
mul(100, 100), | 1110 SkImageInfo::MakeN32Pre
mul(100, 100), |
1079 0, | 1111 0, |
1080 &gProps)); | 1112 &gProps)); |
(...skipping 23 matching lines...) Expand all Loading... |
1104 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { | 1136 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { |
1105 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 1137 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
1106 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1138 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
1107 SkSurface::kNo_Budgeted
, | 1139 SkSurface::kNo_Budgeted
, |
1108 SkImageInfo::MakeN32Pre
mul(1, 1), | 1140 SkImageInfo::MakeN32Pre
mul(1, 1), |
1109 0, | 1141 0, |
1110 &gProps)); | 1142 &gProps)); |
1111 test_negative_blur_sigma(device, reporter); | 1143 test_negative_blur_sigma(device, reporter); |
1112 } | 1144 } |
1113 #endif | 1145 #endif |
OLD | NEW |