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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 414 } |
415 } | 415 } |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 419 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
420 SkSafeUnref(filters[i].fFilter); | 420 SkSafeUnref(filters[i].fFilter); |
421 } | 421 } |
422 } | 422 } |
423 | 423 |
424 static void drawSaveLayerPicture(int width, int height, int tileSize, SkBBHFacto
ry* factory, SkBitmap* result) { | 424 static void draw_saveLayer_picture(int width, int height, int tileSize, |
| 425 SkBBHFactory* factory, SkBitmap* result) { |
425 | 426 |
426 SkMatrix matrix; | 427 SkMatrix matrix; |
427 matrix.setTranslate(SkIntToScalar(50), 0); | 428 matrix.setTranslate(SkIntToScalar(50), 0); |
428 | 429 |
429 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorWHITE
, SkXfermode::kSrc_Mode)); | 430 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorWHITE
, SkXfermode::kSrc_Mode)); |
430 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()))
; | 431 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()))
; |
431 SkAutoTUnref<SkImageFilter> imageFilter(SkMatrixImageFilter::Create(matrix,
SkPaint::kNone_FilterLevel, cfif.get())); | 432 SkAutoTUnref<SkImageFilter> imageFilter(SkMatrixImageFilter::Create(matrix,
SkPaint::kNone_FilterLevel, cfif.get())); |
432 | 433 |
433 SkPaint paint; | 434 SkPaint paint; |
434 paint.setImageFilter(imageFilter.get()); | 435 paint.setImageFilter(imageFilter.get()); |
435 SkPictureRecorder recorder; | 436 SkPictureRecorder recorder; |
436 SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50)); | 437 SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50)); |
437 SkCanvas* recordingCanvas = recorder.beginRecording(width, height, factory,
0); | 438 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width), |
| 439 SkIntToScalar(height), |
| 440 factory, 0); |
438 recordingCanvas->translate(-55, 0); | 441 recordingCanvas->translate(-55, 0); |
439 recordingCanvas->saveLayer(&bounds, &paint); | 442 recordingCanvas->saveLayer(&bounds, &paint); |
440 recordingCanvas->restore(); | 443 recordingCanvas->restore(); |
441 SkAutoTUnref<SkPicture> picture1(recorder.endRecording()); | 444 SkAutoTUnref<SkPicture> picture1(recorder.endRecording()); |
442 | 445 |
443 result->allocN32Pixels(width, height); | 446 result->allocN32Pixels(width, height); |
444 SkCanvas canvas(*result); | 447 SkCanvas canvas(*result); |
445 canvas.clear(0); | 448 canvas.clear(0); |
446 canvas.clipRect(SkRect::Make(SkIRect::MakeWH(tileSize, tileSize))); | 449 canvas.clipRect(SkRect::Make(SkIRect::MakeWH(tileSize, tileSize))); |
447 canvas.drawPicture(picture1.get()); | 450 canvas.drawPicture(picture1.get()); |
448 } | 451 } |
449 | 452 |
450 DEF_TEST(ImageFilterDrawMatrixBBH, reporter) { | 453 DEF_TEST(ImageFilterDrawMatrixBBH, reporter) { |
451 // Check that matrix filter when drawn tiled with BBH exactly | 454 // Check that matrix filter when drawn tiled with BBH exactly |
452 // matches the same thing drawn without BBH. | 455 // matches the same thing drawn without BBH. |
453 // Tests pass by not asserting. | 456 // Tests pass by not asserting. |
454 | 457 |
455 const int width = 200, height = 200; | 458 const int width = 200, height = 200; |
456 const int tileSize = 100; | 459 const int tileSize = 100; |
457 SkBitmap result1, result2; | 460 SkBitmap result1, result2; |
458 SkRTreeFactory factory; | 461 SkRTreeFactory factory; |
459 | 462 |
460 drawSaveLayerPicture(width, height, tileSize, &factory, &result1); | 463 draw_saveLayer_picture(width, height, tileSize, &factory, &result1); |
461 drawSaveLayerPicture(width, height, tileSize, NULL, &result2); | 464 draw_saveLayer_picture(width, height, tileSize, NULL, &result2); |
462 | 465 |
463 for (int y = 0; y < height; y++) { | 466 for (int y = 0; y < height; y++) { |
464 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res
ult1.rowBytes()); | 467 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res
ult1.rowBytes()); |
465 REPORTER_ASSERT(reporter, !diffs); | 468 REPORTER_ASSERT(reporter, !diffs); |
466 if (diffs) { | 469 if (diffs) { |
467 break; | 470 break; |
468 } | 471 } |
469 } | 472 } |
470 } | 473 } |
471 | 474 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 SkAutoTUnref<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2)); | 509 SkAutoTUnref<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2)); |
507 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); | 510 SkAutoTUnref<SkImageFilter> filter2(makeDropShadow(filter1.get())); |
508 | 511 |
509 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); | 512 SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
510 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); | 513 SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); |
511 filter2->filterBounds(bounds, SkMatrix::I(), &bounds); | 514 filter2->filterBounds(bounds, SkMatrix::I(), &bounds); |
512 | 515 |
513 REPORTER_ASSERT(reporter, bounds == expectedBounds); | 516 REPORTER_ASSERT(reporter, bounds == expectedBounds); |
514 } | 517 } |
515 | 518 |
516 static void drawBlurredRect(SkCanvas* canvas) { | 519 static void draw_blurred_rect(SkCanvas* canvas) { |
517 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); | 520 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); |
518 SkPaint filterPaint; | 521 SkPaint filterPaint; |
519 filterPaint.setColor(SK_ColorWHITE); | 522 filterPaint.setColor(SK_ColorWHITE); |
520 filterPaint.setImageFilter(filter); | 523 filterPaint.setImageFilter(filter); |
521 canvas->saveLayer(NULL, &filterPaint); | 524 canvas->saveLayer(NULL, &filterPaint); |
522 SkPaint whitePaint; | 525 SkPaint whitePaint; |
523 whitePaint.setColor(SK_ColorWHITE); | 526 whitePaint.setColor(SK_ColorWHITE); |
524 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); | 527 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); |
525 canvas->restore(); | 528 canvas->restore(); |
526 } | 529 } |
527 | 530 |
528 static void drawPictureClipped(SkCanvas* canvas, const SkRect& clipRect, const S
kPicture* picture) { | 531 static void draw_picture_clipped(SkCanvas* canvas, const SkRect& clipRect, const
SkPicture* picture) { |
529 canvas->save(); | 532 canvas->save(); |
530 canvas->clipRect(clipRect); | 533 canvas->clipRect(clipRect); |
531 canvas->drawPicture(picture); | 534 canvas->drawPicture(picture); |
532 canvas->restore(); | 535 canvas->restore(); |
533 } | 536 } |
534 | 537 |
535 DEF_TEST(ImageFilterDrawTiledBlurRTree, reporter) { | 538 DEF_TEST(ImageFilterDrawTiledBlurRTree, reporter) { |
536 // Check that the blur filter when recorded with RTree acceleration, | 539 // Check that the blur filter when recorded with RTree acceleration, |
537 // and drawn tiled (with subsequent clip rects) exactly | 540 // and drawn tiled (with subsequent clip rects) exactly |
538 // matches the same filter drawn with without RTree acceleration. | 541 // matches the same filter drawn with without RTree acceleration. |
539 // This tests that the "bleed" from the blur into the otherwise-blank | 542 // This tests that the "bleed" from the blur into the otherwise-blank |
540 // tiles is correctly rendered. | 543 // tiles is correctly rendered. |
541 // Tests pass by not asserting. | 544 // Tests pass by not asserting. |
542 | 545 |
543 int width = 16, height = 8; | 546 int width = 16, height = 8; |
544 SkBitmap result1, result2; | 547 SkBitmap result1, result2; |
545 result1.allocN32Pixels(width, height); | 548 result1.allocN32Pixels(width, height); |
546 result2.allocN32Pixels(width, height); | 549 result2.allocN32Pixels(width, height); |
547 SkCanvas canvas1(result1); | 550 SkCanvas canvas1(result1); |
548 SkCanvas canvas2(result2); | 551 SkCanvas canvas2(result2); |
549 int tileSize = 8; | 552 int tileSize = 8; |
550 | 553 |
551 canvas1.clear(0); | 554 canvas1.clear(0); |
552 canvas2.clear(0); | 555 canvas2.clear(0); |
553 | 556 |
554 SkRTreeFactory factory; | 557 SkRTreeFactory factory; |
555 | 558 |
556 SkPictureRecorder recorder1, recorder2; | 559 SkPictureRecorder recorder1, recorder2; |
557 // The only difference between these two pictures is that one has RTree acel
eration. | 560 // The only difference between these two pictures is that one has RTree acel
eration. |
558 SkCanvas* recordingCanvas1 = recorder1.beginRecording(width, height, NULL, 0
); | 561 SkCanvas* recordingCanvas1 = recorder1.beginRecording(SkIntToScalar(width), |
559 SkCanvas* recordingCanvas2 = recorder2.beginRecording(width, height, &factor
y, 0); | 562 SkIntToScalar(height),
|
560 drawBlurredRect(recordingCanvas1); | 563 NULL, 0); |
561 drawBlurredRect(recordingCanvas2); | 564 SkCanvas* recordingCanvas2 = recorder2.beginRecording(SkIntToScalar(width), |
| 565 SkIntToScalar(height),
|
| 566 &factory, 0); |
| 567 draw_blurred_rect(recordingCanvas1); |
| 568 draw_blurred_rect(recordingCanvas2); |
562 SkAutoTUnref<SkPicture> picture1(recorder1.endRecording()); | 569 SkAutoTUnref<SkPicture> picture1(recorder1.endRecording()); |
563 SkAutoTUnref<SkPicture> picture2(recorder2.endRecording()); | 570 SkAutoTUnref<SkPicture> picture2(recorder2.endRecording()); |
564 for (int y = 0; y < height; y += tileSize) { | 571 for (int y = 0; y < height; y += tileSize) { |
565 for (int x = 0; x < width; x += tileSize) { | 572 for (int x = 0; x < width; x += tileSize) { |
566 SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, til
eSize)); | 573 SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, til
eSize)); |
567 drawPictureClipped(&canvas1, tileRect, picture1); | 574 draw_picture_clipped(&canvas1, tileRect, picture1); |
568 drawPictureClipped(&canvas2, tileRect, picture2); | 575 draw_picture_clipped(&canvas2, tileRect, picture2); |
569 } | 576 } |
570 } | 577 } |
571 for (int y = 0; y < height; y++) { | 578 for (int y = 0; y < height; y++) { |
572 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res
ult1.rowBytes()); | 579 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res
ult1.rowBytes()); |
573 REPORTER_ASSERT(reporter, !diffs); | 580 REPORTER_ASSERT(reporter, !diffs); |
574 if (diffs) { | 581 if (diffs) { |
575 break; | 582 break; |
576 } | 583 } |
577 } | 584 } |
578 } | 585 } |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 } | 960 } |
954 | 961 |
955 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { | 962 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { |
956 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 963 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
957 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 964 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
958 SkImageInfo::MakeN32Pre
mul(1, 1), | 965 SkImageInfo::MakeN32Pre
mul(1, 1), |
959 0)); | 966 0)); |
960 test_xfermode_cropped_input(device, reporter); | 967 test_xfermode_cropped_input(device, reporter); |
961 } | 968 } |
962 #endif | 969 #endif |
OLD | NEW |