| 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" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 | 462 |
| 463 for (int y = 0; y < height; y++) { | 463 for (int y = 0; y < height; y++) { |
| 464 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res
ult1.rowBytes()); | 464 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res
ult1.rowBytes()); |
| 465 REPORTER_ASSERT(reporter, !diffs); | 465 REPORTER_ASSERT(reporter, !diffs); |
| 466 if (diffs) { | 466 if (diffs) { |
| 467 break; | 467 break; |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 static SkImageFilter* makeBlur(SkImageFilter* input = NULL) { | |
| 473 return SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, input); | |
| 474 } | |
| 475 | |
| 476 static SkImageFilter* makeDropShadow(SkImageFilter* input = NULL) { | |
| 477 return SkDropShadowImageFilter::Create( | |
| 478 SkIntToScalar(100), SkIntToScalar(100), | |
| 479 SkIntToScalar(10), SkIntToScalar(10), | |
| 480 SK_ColorBLUE, input); | |
| 481 } | |
| 482 | |
| 483 DEF_TEST(ImageFilterBlurThenShadowBounds, reporter) { | |
| 484 SkAutoTUnref<SkImageFilter> filter1(makeBlur()); | |
| 485 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); | |
| 486 | |
| 487 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); | |
| 488 SkIRect expectedBounds = SkIRect::MakeXYWH(-133, -133, 236, 236); | |
| 489 filter2->filterBounds(bounds, SkMatrix(), &bounds); | |
| 490 | |
| 491 REPORTER_ASSERT(reporter, bounds == expectedBounds); | |
| 492 } | |
| 493 | |
| 494 DEF_TEST(ImageFilterShadowThenBlurBounds, reporter) { | |
| 495 SkAutoTUnref<SkImageFilter> filter1(makeDropShadow()); | |
| 496 SkAutoTUnref<SkImageFilter> filter2(makeBlur(filter1.get())); | |
| 497 | |
| 498 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); | |
| 499 SkIRect expectedBounds = SkIRect::MakeXYWH(-133, -133, 236, 236); | |
| 500 filter2->filterBounds(bounds, SkMatrix(), &bounds); | |
| 501 | |
| 502 REPORTER_ASSERT(reporter, bounds == expectedBounds); | |
| 503 } | |
| 504 | |
| 505 DEF_TEST(ImageFilterDilateThenBlurBounds, reporter) { | |
| 506 SkAutoTUnref<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2)); | |
| 507 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); | |
| 508 | |
| 509 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); | |
| 510 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); | |
| 511 filter2->filterBounds(bounds, SkMatrix(), &bounds); | |
| 512 | |
| 513 REPORTER_ASSERT(reporter, bounds == expectedBounds); | |
| 514 } | |
| 515 | |
| 516 static void drawBlurredRect(SkCanvas* canvas) { | 472 static void drawBlurredRect(SkCanvas* canvas) { |
| 517 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); | 473 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); |
| 518 SkPaint filterPaint; | 474 SkPaint filterPaint; |
| 519 filterPaint.setColor(SK_ColorWHITE); | 475 filterPaint.setColor(SK_ColorWHITE); |
| 520 filterPaint.setImageFilter(filter); | 476 filterPaint.setImageFilter(filter); |
| 521 canvas->saveLayer(NULL, &filterPaint); | 477 canvas->saveLayer(NULL, &filterPaint); |
| 522 SkPaint whitePaint; | 478 SkPaint whitePaint; |
| 523 whitePaint.setColor(SK_ColorWHITE); | 479 whitePaint.setColor(SK_ColorWHITE); |
| 524 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); | 480 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); |
| 525 canvas->restore(); | 481 canvas->restore(); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 } | 909 } |
| 954 | 910 |
| 955 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { | 911 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { |
| 956 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 912 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
| 957 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 913 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
| 958 SkImageInfo::MakeN32Pre
mul(1, 1), | 914 SkImageInfo::MakeN32Pre
mul(1, 1), |
| 959 0)); | 915 0)); |
| 960 test_xfermode_cropped_input(device, reporter); | 916 test_xfermode_cropped_input(device, reporter); |
| 961 } | 917 } |
| 962 #endif | 918 #endif |
| OLD | NEW |