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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 } | 403 } |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 407 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
408 SkSafeUnref(filters[i].fFilter); | 408 SkSafeUnref(filters[i].fFilter); |
409 } | 409 } |
410 } | 410 } |
411 | 411 |
| 412 static void drawBlurredRect(SkCanvas* canvas) { |
| 413 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); |
| 414 SkPaint filterPaint; |
| 415 filterPaint.setColor(SK_ColorWHITE); |
| 416 filterPaint.setImageFilter(filter); |
| 417 canvas->saveLayer(NULL, &filterPaint); |
| 418 SkPaint whitePaint; |
| 419 whitePaint.setColor(SK_ColorWHITE); |
| 420 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); |
| 421 canvas->restore(); |
| 422 } |
| 423 |
| 424 static void drawPictureClipped(SkCanvas* canvas, const SkRect& clipRect, const S
kPicture* picture) { |
| 425 canvas->save(); |
| 426 canvas->clipRect(clipRect); |
| 427 canvas->drawPicture(picture); |
| 428 canvas->restore(); |
| 429 } |
| 430 |
| 431 DEF_TEST(ImageFilterDrawTiledBlurRTree, reporter) { |
| 432 // Check that the blur filter when recorded with RTree acceleration, |
| 433 // and drawn tiled (with subsequent clip rects) exactly |
| 434 // matches the same filter drawn with without RTree acceleration. |
| 435 // This tests that the "bleed" from the blur into the otherwise-blank |
| 436 // tiles is correctly rendered. |
| 437 // Tests pass by not asserting. |
| 438 |
| 439 int width = 16, height = 8; |
| 440 SkBitmap result1, result2; |
| 441 result1.allocN32Pixels(width, height); |
| 442 result2.allocN32Pixels(width, height); |
| 443 SkCanvas canvas1(result1); |
| 444 SkCanvas canvas2(result2); |
| 445 int tileSize = 8; |
| 446 |
| 447 canvas1.clear(0); |
| 448 canvas2.clear(0); |
| 449 |
| 450 SkRTreeFactory factory; |
| 451 |
| 452 SkPictureRecorder recorder1, recorder2; |
| 453 // The only difference between these two pictures is that one has RTree acel
eration. |
| 454 SkCanvas* recordingCanvas1 = recorder1.beginRecording(width, height, NULL, 0
); |
| 455 SkCanvas* recordingCanvas2 = recorder2.beginRecording(width, height, &factor
y, 0); |
| 456 drawBlurredRect(recordingCanvas1); |
| 457 drawBlurredRect(recordingCanvas2); |
| 458 SkAutoTUnref<SkPicture> picture1(recorder1.endRecording()); |
| 459 SkAutoTUnref<SkPicture> picture2(recorder2.endRecording()); |
| 460 for (int y = 0; y < height; y += tileSize) { |
| 461 for (int x = 0; x < width; x += tileSize) { |
| 462 SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, til
eSize)); |
| 463 drawPictureClipped(&canvas1, tileRect, picture1); |
| 464 drawPictureClipped(&canvas2, tileRect, picture2); |
| 465 } |
| 466 } |
| 467 for (int y = 0; y < height; y++) { |
| 468 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res
ult1.rowBytes()); |
| 469 REPORTER_ASSERT(reporter, !diffs); |
| 470 if (diffs) { |
| 471 break; |
| 472 } |
| 473 } |
| 474 } |
| 475 |
412 DEF_TEST(ImageFilterMatrixConvolution, reporter) { | 476 DEF_TEST(ImageFilterMatrixConvolution, reporter) { |
413 // Check that a 1x3 filter does not cause a spurious assert. | 477 // Check that a 1x3 filter does not cause a spurious assert. |
414 SkScalar kernel[3] = { | 478 SkScalar kernel[3] = { |
415 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 479 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
416 }; | 480 }; |
417 SkISize kernelSize = SkISize::Make(1, 3); | 481 SkISize kernelSize = SkISize::Make(1, 3); |
418 SkScalar gain = SK_Scalar1, bias = 0; | 482 SkScalar gain = SK_Scalar1, bias = 0; |
419 SkIPoint kernelOffset = SkIPoint::Make(0, 0); | 483 SkIPoint kernelOffset = SkIPoint::Make(0, 0); |
420 | 484 |
421 SkAutoTUnref<SkImageFilter> filter( | 485 SkAutoTUnref<SkImageFilter> filter( |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 } | 825 } |
762 | 826 |
763 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { | 827 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { |
764 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 828 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
765 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 829 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
766 SkImageInfo::MakeN32Pre
mul(1, 1), | 830 SkImageInfo::MakeN32Pre
mul(1, 1), |
767 0)); | 831 0)); |
768 test_xfermode_cropped_input(device, reporter); | 832 test_xfermode_cropped_input(device, reporter); |
769 } | 833 } |
770 #endif | 834 #endif |
OLD | NEW |