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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 buffer.writeMatrix(fExpectedMatrix); | 72 buffer.writeMatrix(fExpectedMatrix); |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 skiatest::Reporter* fReporter; | 76 skiatest::Reporter* fReporter; |
77 SkMatrix fExpectedMatrix; | 77 SkMatrix fExpectedMatrix; |
78 | 78 |
79 typedef SkImageFilter INHERITED; | 79 typedef SkImageFilter INHERITED; |
80 }; | 80 }; |
81 | 81 |
| 82 void draw_gradient_circle(SkCanvas* canvas, int width, int height) { |
| 83 SkScalar x = SkIntToScalar(width / 2); |
| 84 SkScalar y = SkIntToScalar(height / 2); |
| 85 SkScalar radius = SkMinScalar(x, y) * 0.8f; |
| 86 canvas->clear(0x00000000); |
| 87 SkColor colors[2]; |
| 88 colors[0] = SK_ColorWHITE; |
| 89 colors[1] = SK_ColorBLACK; |
| 90 sk_sp<SkShader> shader( |
| 91 SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullpt
r, 2, |
| 92 SkShader::kClamp_TileMode) |
| 93 ); |
| 94 SkPaint paint; |
| 95 paint.setShader(shader); |
| 96 canvas->drawCircle(x, y, radius, paint); |
| 97 } |
| 98 |
| 99 SkBitmap make_gradient_circle(int width, int height) { |
| 100 SkBitmap bitmap; |
| 101 bitmap.allocN32Pixels(width, height); |
| 102 SkCanvas canvas(bitmap); |
| 103 draw_gradient_circle(&canvas, width, height); |
| 104 return bitmap; |
| 105 } |
| 106 |
| 107 class FilterList { |
| 108 public: |
| 109 FilterList(SkImageFilter* input = nullptr, const SkImageFilter::CropRect* cr
opRect = nullptr) { |
| 110 auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mo
de)); |
| 111 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 112 SkScalar kernel[9] = { |
| 113 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 114 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), |
| 115 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 116 }; |
| 117 const SkISize kernelSize = SkISize::Make(3, 3); |
| 118 const SkScalar gain = SK_Scalar1, bias = 0; |
| 119 const SkScalar five = SkIntToScalar(5); |
| 120 |
| 121 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circl
e(64, 64))); |
| 122 SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradien
tImage.get())); |
| 123 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, i
nput)); |
| 124 SkMatrix matrix; |
| 125 |
| 126 matrix.setTranslate(SK_Scalar1, SK_Scalar1); |
| 127 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); |
| 128 |
| 129 SkRTreeFactory factory; |
| 130 SkPictureRecorder recorder; |
| 131 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0)
; |
| 132 |
| 133 SkPaint greenPaint; |
| 134 greenPaint.setColor(SK_ColorGREEN); |
| 135 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)
), greenPaint); |
| 136 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
| 137 SkAutoTUnref<SkImageFilter> pictureFilter(SkPictureImageFilter::Create(p
icture.get())); |
| 138 SkAutoTUnref<SkShader> shader(SkPerlinNoiseShader::CreateTurbulence( |
| 139 SK_Scalar1, SK_Scalar1, 1, 0)); |
| 140 |
| 141 SkPaint paint; |
| 142 paint.setShader(shader); |
| 143 SkAutoTUnref<SkImageFilter> paintFilter(SkPaintImageFilter::Create(paint
)); |
| 144 |
| 145 sk_sp<SkShader> greenColorShader(SkShader::MakeColorShader(SK_ColorGREEN
)); |
| 146 SkPaint greenColorShaderPaint; |
| 147 greenColorShaderPaint.setShader(greenColorShader); |
| 148 SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64))
; |
| 149 SkAutoTUnref<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Create( |
| 150 greenColorShaderPaint, &leftSideCropRect)); |
| 151 SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32, 64
)); |
| 152 SkAutoTUnref<SkImageFilter> paintFilterRight(SkPaintImageFilter::Create( |
| 153 greenColorShaderPaint, &rightSideCropRect)); |
| 154 |
| 155 this->addFilter("color filter", |
| 156 SkColorFilterImageFilter::Create(cf.get(), input, cropRect)); |
| 157 this->addFilter("displacement map", SkDisplacementMapEffect::Create( |
| 158 SkDisplacementMapEffect::kR_ChannelSelectorType, |
| 159 SkDisplacementMapEffect::kB_ChannelSelectorType, |
| 160 20.0f, gradientSource.get(), input, cropRect)); |
| 161 this->addFilter("blur", SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1
, input, cropRect)); |
| 162 this->addFilter("drop shadow", SkDropShadowImageFilter::Create( |
| 163 SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, |
| 164 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
input, cropRect)); |
| 165 this->addFilter("diffuse lighting", SkLightingImageFilter::CreatePointLi
tDiffuse( |
| 166 location, SK_ColorGREEN, 0, 0, input, cropRect)); |
| 167 this->addFilter("specular lighting", |
| 168 SkLightingImageFilter::CreatePointLitSpecular(location, SK_Col
orGREEN, 0, 0, 0, |
| 169 input, cropRect)
); |
| 170 this->addFilter("matrix convolution", |
| 171 SkMatrixConvolutionImageFilter::Create( |
| 172 kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), |
| 173 SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, i
nput, cropRect)); |
| 174 this->addFilter("merge", SkMergeImageFilter::Create(input, input, SkXfer
mode::kSrcOver_Mode, |
| 175 cropRect)); |
| 176 this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Create
( |
| 177 paintFilterLeft, paintFilterRight, SkXfermode::kSrcOver_Mode,
cropRect)); |
| 178 this->addFilter("offset", |
| 179 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, inpu
t, cropRect)); |
| 180 this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropR
ect)); |
| 181 this->addFilter("erode", SkErodeImageFilter::Create(2, 3, input, cropRec
t)); |
| 182 this->addFilter("tile", SkTileImageFilter::Create( |
| 183 SkRect::MakeXYWH(0, 0, 50, 50), |
| 184 cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100), |
| 185 input)); |
| 186 if (!cropRect) { |
| 187 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter( |
| 188 matrix, kLow_SkFilterQuality, input)); |
| 189 } |
| 190 this->addFilter("blur and offset", SkOffsetImageFilter::Create( |
| 191 five, five, blur.get(), cropRect)); |
| 192 this->addFilter("picture and blur", SkBlurImageFilter::Create( |
| 193 five, five, pictureFilter.get(), cropRect)); |
| 194 this->addFilter("paint and blur", SkBlurImageFilter::Create( |
| 195 five, five, paintFilter.get(), cropRect)); |
| 196 this->addFilter("xfermode", SkXfermodeImageFilter::Create( |
| 197 SkXfermode::Create(SkXfermode::kSrc_Mode), input, input, cropRect)); |
| 198 } |
| 199 int count() const { return fFilters.count(); } |
| 200 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g
et(); } |
| 201 const char* getName(int index) const { return fFilters[index].fName; } |
| 202 private: |
| 203 struct Filter { |
| 204 Filter() : fName(nullptr), fFilter(nullptr) {} |
| 205 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f
ilter) {} |
| 206 const char* fName; |
| 207 sk_sp<SkImageFilter> fFilter; |
| 208 }; |
| 209 void addFilter(const char* name, SkImageFilter* filter) { |
| 210 fFilters.push_back(Filter(name, filter)); |
| 211 } |
| 212 |
| 213 SkTArray<Filter> fFilters; |
| 214 }; |
| 215 |
82 } | 216 } |
83 | 217 |
84 SkFlattenable* MatrixTestImageFilter::CreateProc(SkReadBuffer& buffer) { | 218 SkFlattenable* MatrixTestImageFilter::CreateProc(SkReadBuffer& buffer) { |
85 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 219 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
86 skiatest::Reporter* reporter = (skiatest::Reporter*)buffer.readFunctionPtr()
; | 220 skiatest::Reporter* reporter = (skiatest::Reporter*)buffer.readFunctionPtr()
; |
87 SkMatrix matrix; | 221 SkMatrix matrix; |
88 buffer.readMatrix(&matrix); | 222 buffer.readMatrix(&matrix); |
89 return new MatrixTestImageFilter(reporter, matrix); | 223 return new MatrixTestImageFilter(reporter, matrix); |
90 } | 224 } |
91 | 225 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // Check that all filters offset to their absolute crop rect, | 446 // Check that all filters offset to their absolute crop rect, |
313 // unaffected by the input crop rect. | 447 // unaffected by the input crop rect. |
314 // Tests pass by not asserting. | 448 // Tests pass by not asserting. |
315 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100)
); | 449 sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 100)
); |
316 SkASSERT(srcImg); | 450 SkASSERT(srcImg); |
317 | 451 |
318 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); | 452 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); |
319 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); | 453 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); |
320 SkAutoTUnref<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect)); | 454 SkAutoTUnref<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect)); |
321 | 455 |
322 auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode))
; | 456 FilterList filters(input.get(), &cropRect); |
323 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | |
324 SkScalar kernel[9] = { | |
325 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | |
326 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | |
327 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | |
328 }; | |
329 SkISize kernelSize = SkISize::Make(3, 3); | |
330 SkScalar gain = SK_Scalar1, bias = 0; | |
331 | 457 |
332 SkImageFilter* filters[] = { | 458 for (int i = 0; i < filters.count(); ++i) { |
333 SkColorFilterImageFilter::Create(cf.get(), input.get(), &cropRect), | 459 SkImageFilter* filter = filters.getFilter(i); |
334 SkDisplacementMapEffect::Create(SkDisplacementMapEffect::kR_ChannelSelec
torType, | |
335 SkDisplacementMapEffect::kB_ChannelSelec
torType, | |
336 40.0f, input.get(), input.get(), &cropRe
ct), | |
337 SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRect
), | |
338 SkDropShadowImageFilter::Create(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_S
calar1, | |
339 SK_ColorGREEN, SkDropShadowImageFilter::kDrawShadowAndForeground_Sha
dowMode, | |
340 input.get(), &cropRect), | |
341 SkLightingImageFilter::CreatePointLitDiffuse(location, SK_ColorGREEN, 0,
0, input.get(), &cropRect), | |
342 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0
, 0, 0, input.get(), &cropRect), | |
343 SkMatrixConvolutionImageFilter::Create(kernelSize, kernel, gain, bias, S
kIPoint::Make(1, 1), SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, in
put.get(), &cropRect), | |
344 SkMergeImageFilter::Create(input.get(), input.get(), SkXfermode::kSrcOve
r_Mode, &cropRect), | |
345 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe
ct), | |
346 SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input.get(), &cropRe
ct), | |
347 SkDilateImageFilter::Create(3, 2, input.get(), &cropRect), | |
348 SkErodeImageFilter::Create(2, 3, input.get(), &cropRect), | |
349 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g
et()), | |
350 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo
de), input.get(), input.get(), &cropRect), | |
351 }; | |
352 | |
353 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | |
354 SkImageFilter* filter = filters[i]; | |
355 SkIPoint offset; | 460 SkIPoint offset; |
356 SkString str; | |
357 str.printf("filter %d", static_cast<int>(i)); | |
358 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul
lptr); | 461 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nul
lptr); |
359 SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(),
ctx, &offset)); | 462 SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(),
ctx, &offset)); |
360 REPORTER_ASSERT_MESSAGE(reporter, resultImg, str.c_str()); | 463 REPORTER_ASSERT_MESSAGE(reporter, resultImg, filters.getName(i)); |
361 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); | 464 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, fi
lters.getName(i)); |
362 } | |
363 | |
364 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | |
365 SkSafeUnref(filters[i]); | |
366 } | 465 } |
367 } | 466 } |
368 | 467 |
369 static SkBitmap make_gradient_circle(int width, int height) { | |
370 SkBitmap bitmap; | |
371 SkScalar x = SkIntToScalar(width / 2); | |
372 SkScalar y = SkIntToScalar(height / 2); | |
373 SkScalar radius = SkMinScalar(x, y) * 0.8f; | |
374 bitmap.allocN32Pixels(width, height); | |
375 SkCanvas canvas(bitmap); | |
376 canvas.clear(0x00000000); | |
377 SkColor colors[2]; | |
378 colors[0] = SK_ColorWHITE; | |
379 colors[1] = SK_ColorBLACK; | |
380 SkPaint paint; | |
381 paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, co
lors, nullptr, 2, | |
382 SkShader::kClamp_TileMode)); | |
383 canvas.drawCircle(x, y, radius, paint); | |
384 return bitmap; | |
385 } | |
386 | |
387 | |
388 | |
389 static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy, | 468 static void test_negative_blur_sigma(SkImageFilter::Proxy* proxy, |
390 skiatest::Reporter* reporter, | 469 skiatest::Reporter* reporter, |
391 GrContext* context) { | 470 GrContext* context) { |
392 // Check that SkBlurImageFilter will accept a negative sigma, either in | 471 // Check that SkBlurImageFilter will accept a negative sigma, either in |
393 // the given arguments or after CTM application. | 472 // the given arguments or after CTM application. |
394 const int width = 32, height = 32; | 473 const int width = 32, height = 32; |
395 const SkScalar five = SkIntToScalar(5); | 474 const SkScalar five = SkIntToScalar(5); |
396 | 475 |
397 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f
ive)); | 476 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f
ive)); |
398 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five,
five)); | 477 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five,
five)); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestZeroBlurSigma_Gpu, reporter, context) { | 635 DEF_GPUTEST_FOR_NATIVE_CONTEXT(TestZeroBlurSigma_Gpu, reporter, context) { |
557 run_gpu_test(reporter, context, 100, test_zero_blur_sigma); | 636 run_gpu_test(reporter, context, 100, test_zero_blur_sigma); |
558 } | 637 } |
559 #endif | 638 #endif |
560 | 639 |
561 DEF_TEST(ImageFilterDrawTiled, reporter) { | 640 DEF_TEST(ImageFilterDrawTiled, reporter) { |
562 // Check that all filters when drawn tiled (with subsequent clip rects) exac
tly | 641 // Check that all filters when drawn tiled (with subsequent clip rects) exac
tly |
563 // match the same filters drawn with a single full-canvas bitmap draw. | 642 // match the same filters drawn with a single full-canvas bitmap draw. |
564 // Tests pass by not asserting. | 643 // Tests pass by not asserting. |
565 | 644 |
566 auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode))
; | 645 FilterList filters; |
567 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | |
568 SkScalar kernel[9] = { | |
569 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | |
570 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | |
571 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | |
572 }; | |
573 const SkISize kernelSize = SkISize::Make(3, 3); | |
574 const SkScalar gain = SK_Scalar1, bias = 0; | |
575 const SkScalar five = SkIntToScalar(5); | |
576 | |
577 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circle(64
, 64))); | |
578 SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradientIma
ge.get())); | |
579 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five)); | |
580 SkMatrix matrix; | |
581 | |
582 matrix.setTranslate(SK_Scalar1, SK_Scalar1); | |
583 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); | |
584 | |
585 SkRTreeFactory factory; | |
586 SkPictureRecorder recorder; | |
587 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0); | |
588 | |
589 SkPaint greenPaint; | |
590 greenPaint.setColor(SK_ColorGREEN); | |
591 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), g
reenPaint); | |
592 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); | |
593 SkAutoTUnref<SkImageFilter> pictureFilter(SkPictureImageFilter::Create(pictu
re.get())); | |
594 SkAutoTUnref<SkShader> shader(SkPerlinNoiseShader::CreateTurbulence(SK_Scala
r1, SK_Scalar1, 1, 0)); | |
595 SkPaint noisePaint; | |
596 noisePaint.setShader(shader); | |
597 | |
598 SkAutoTUnref<SkImageFilter> paintFilter(SkPaintImageFilter::Create(noisePain
t)); | |
599 | |
600 SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64)); | |
601 SkAutoTUnref<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Create(green
Paint, &leftSideCropRect)); | |
602 SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32, 64)); | |
603 SkAutoTUnref<SkImageFilter> paintFilterRight(SkPaintImageFilter::Create(gree
nPaint, &rightSideCropRect)); | |
604 | |
605 struct { | |
606 const char* fName; | |
607 SkImageFilter* fFilter; | |
608 } filters[] = { | |
609 { "color filter", SkColorFilterImageFilter::Create(cf.get()) }, | |
610 { "displacement map", SkDisplacementMapEffect::Create( | |
611 SkDisplacementMapEffect::kR_ChannelSelectorType, | |
612 SkDisplacementMapEffect::kB_ChannelSelectorType, | |
613 20.0f, gradientSource.get()) }, | |
614 { "blur", SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1) }, | |
615 { "drop shadow", SkDropShadowImageFilter::Create( | |
616 SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, | |
617 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode) }, | |
618 { "diffuse lighting", SkLightingImageFilter::CreatePointLitDiffuse( | |
619 location, SK_ColorGREEN, 0, 0) }, | |
620 { "specular lighting", | |
621 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGR
EEN, 0, 0, 0) }, | |
622 { "matrix convolution", | |
623 SkMatrixConvolutionImageFilter::Create( | |
624 kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), | |
625 SkMatrixConvolutionImageFilter::kRepeat_TileMode, false) }, | |
626 { "merge", SkMergeImageFilter::Create(nullptr, nullptr, SkXfermode::kSrc
Over_Mode) }, | |
627 { "merge with disjoint inputs", SkMergeImageFilter::Create( | |
628 paintFilterLeft, paintFilterRight, SkXfermode::kSrcOver_Mode) }, | |
629 { "offset", SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1) }, | |
630 { "dilate", SkDilateImageFilter::Create(3, 2) }, | |
631 { "erode", SkErodeImageFilter::Create(2, 3) }, | |
632 { "tile", SkTileImageFilter::Create(SkRect::MakeXYWH(0, 0, 50, 50), | |
633 SkRect::MakeXYWH(0, 0, 100, 100), nu
llptr) }, | |
634 { "matrix", SkImageFilter::CreateMatrixFilter(matrix, kLow_SkFilterQuali
ty) }, | |
635 { "blur and offset", SkOffsetImageFilter::Create(five, five, blur.get())
}, | |
636 { "picture and blur", SkBlurImageFilter::Create(five, five, pictureFilte
r.get()) }, | |
637 { "paint and blur", SkBlurImageFilter::Create(five, five, paintFilter.ge
t()) }, | |
638 }; | |
639 | 646 |
640 SkBitmap untiledResult, tiledResult; | 647 SkBitmap untiledResult, tiledResult; |
641 const int width = 64, height = 64; | 648 const int width = 64, height = 64; |
642 untiledResult.allocN32Pixels(width, height); | 649 untiledResult.allocN32Pixels(width, height); |
643 tiledResult.allocN32Pixels(width, height); | 650 tiledResult.allocN32Pixels(width, height); |
644 SkCanvas tiledCanvas(tiledResult); | 651 SkCanvas tiledCanvas(tiledResult); |
645 SkCanvas untiledCanvas(untiledResult); | 652 SkCanvas untiledCanvas(untiledResult); |
646 int tileSize = 8; | 653 int tileSize = 8; |
647 | 654 |
648 for (int scale = 1; scale <= 2; ++scale) { | 655 for (int scale = 1; scale <= 2; ++scale) { |
649 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 656 for (int i = 0; i < filters.count(); ++i) { |
650 tiledCanvas.clear(0); | 657 tiledCanvas.clear(0); |
651 untiledCanvas.clear(0); | 658 untiledCanvas.clear(0); |
652 SkPaint paint; | 659 SkPaint paint; |
653 paint.setImageFilter(filters[i].fFilter); | 660 paint.setImageFilter(filters.getFilter(i)); |
654 paint.setTextSize(SkIntToScalar(height)); | 661 paint.setTextSize(SkIntToScalar(height)); |
655 paint.setColor(SK_ColorWHITE); | 662 paint.setColor(SK_ColorWHITE); |
656 SkString str; | 663 SkString str; |
657 const char* text = "ABC"; | 664 const char* text = "ABC"; |
658 SkScalar ypos = SkIntToScalar(height); | 665 SkScalar ypos = SkIntToScalar(height); |
659 untiledCanvas.save(); | 666 untiledCanvas.save(); |
660 untiledCanvas.scale(SkIntToScalar(scale), SkIntToScalar(scale)); | 667 untiledCanvas.scale(SkIntToScalar(scale), SkIntToScalar(scale)); |
661 untiledCanvas.drawText(text, strlen(text), 0, ypos, paint); | 668 untiledCanvas.drawText(text, strlen(text), 0, ypos, paint); |
662 untiledCanvas.restore(); | 669 untiledCanvas.restore(); |
663 for (int y = 0; y < height; y += tileSize) { | 670 for (int y = 0; y < height; y += tileSize) { |
664 for (int x = 0; x < width; x += tileSize) { | 671 for (int x = 0; x < width; x += tileSize) { |
665 tiledCanvas.save(); | 672 tiledCanvas.save(); |
666 tiledCanvas.clipRect(SkRect::Make(SkIRect::MakeXYWH(x, y, ti
leSize, tileSize))); | 673 tiledCanvas.clipRect(SkRect::Make(SkIRect::MakeXYWH(x, y, ti
leSize, tileSize))); |
667 tiledCanvas.scale(SkIntToScalar(scale), SkIntToScalar(scale)
); | 674 tiledCanvas.scale(SkIntToScalar(scale), SkIntToScalar(scale)
); |
668 tiledCanvas.drawText(text, strlen(text), 0, ypos, paint); | 675 tiledCanvas.drawText(text, strlen(text), 0, ypos, paint); |
669 tiledCanvas.restore(); | 676 tiledCanvas.restore(); |
670 } | 677 } |
671 } | 678 } |
672 untiledCanvas.flush(); | 679 untiledCanvas.flush(); |
673 tiledCanvas.flush(); | 680 tiledCanvas.flush(); |
674 for (int y = 0; y < height; y++) { | 681 for (int y = 0; y < height; y++) { |
675 int diffs = memcmp(untiledResult.getAddr32(0, y), tiledResult.ge
tAddr32(0, y), untiledResult.rowBytes()); | 682 int diffs = memcmp(untiledResult.getAddr32(0, y), tiledResult.ge
tAddr32(0, y), untiledResult.rowBytes()); |
676 REPORTER_ASSERT_MESSAGE(reporter, !diffs, filters[i].fName); | 683 REPORTER_ASSERT_MESSAGE(reporter, !diffs, filters.getName(i)); |
677 if (diffs) { | 684 if (diffs) { |
678 break; | 685 break; |
679 } | 686 } |
680 } | 687 } |
681 } | 688 } |
682 } | 689 } |
683 | |
684 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | |
685 SkSafeUnref(filters[i].fFilter); | |
686 } | |
687 } | 690 } |
688 | 691 |
689 static void draw_saveLayer_picture(int width, int height, int tileSize, | 692 static void draw_saveLayer_picture(int width, int height, int tileSize, |
690 SkBBHFactory* factory, SkBitmap* result) { | 693 SkBBHFactory* factory, SkBitmap* result) { |
691 | 694 |
692 SkMatrix matrix; | 695 SkMatrix matrix; |
693 matrix.setTranslate(SkIntToScalar(50), 0); | 696 matrix.setTranslate(SkIntToScalar(50), 0); |
694 | 697 |
695 auto cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode))
; | 698 auto cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode))
; |
696 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()))
; | 699 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()))
; |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 test_xfermode_cropped_input(&canvas, reporter); | 1596 test_xfermode_cropped_input(&canvas, reporter); |
1594 } | 1597 } |
1595 | 1598 |
1596 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { | 1599 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { |
1597 SkAutoTUnref<SkSurface> surface( | 1600 SkAutoTUnref<SkSurface> surface( |
1598 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, | 1601 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, |
1599 SkImageInfo::MakeN32Premul(100, 100))); | 1602 SkImageInfo::MakeN32Premul(100, 100))); |
1600 test_large_blur_input(reporter, surface->getCanvas()); | 1603 test_large_blur_input(reporter, surface->getCanvas()); |
1601 } | 1604 } |
1602 #endif | 1605 #endif |
OLD | NEW |