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 | |
476 DEF_TEST(ImageFilterMatrixConvolution, reporter) { | 412 DEF_TEST(ImageFilterMatrixConvolution, reporter) { |
477 // Check that a 1x3 filter does not cause a spurious assert. | 413 // Check that a 1x3 filter does not cause a spurious assert. |
478 SkScalar kernel[3] = { | 414 SkScalar kernel[3] = { |
479 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 415 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
480 }; | 416 }; |
481 SkISize kernelSize = SkISize::Make(1, 3); | 417 SkISize kernelSize = SkISize::Make(1, 3); |
482 SkScalar gain = SK_Scalar1, bias = 0; | 418 SkScalar gain = SK_Scalar1, bias = 0; |
483 SkIPoint kernelOffset = SkIPoint::Make(0, 0); | 419 SkIPoint kernelOffset = SkIPoint::Make(0, 0); |
484 | 420 |
485 SkAutoTUnref<SkImageFilter> filter( | 421 SkAutoTUnref<SkImageFilter> filter( |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 } | 761 } |
826 | 762 |
827 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { | 763 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { |
828 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 764 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
829 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 765 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
830 SkImageInfo::MakeN32Pre
mul(1, 1), | 766 SkImageInfo::MakeN32Pre
mul(1, 1), |
831 0)); | 767 0)); |
832 test_xfermode_cropped_input(device, reporter); | 768 test_xfermode_cropped_input(device, reporter); |
833 } | 769 } |
834 #endif | 770 #endif |
OLD | NEW |