Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
| 9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 if (!found) { | 571 if (!found) { |
| 572 SkData* data = SkPictureUtils::GatherPixelRefs(pic, r); | 572 SkData* data = SkPictureUtils::GatherPixelRefs(pic, r); |
| 573 size_t dataSize = data ? data->size() : 0; | 573 size_t dataSize = data ? data->size() : 0; |
| 574 } | 574 } |
| 575 #endif | 575 #endif |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 } | 579 } |
| 580 | 580 |
| 581 #define GENERATE_CANVAS(recorder, x) \ | |
| 582 (x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \ | |
| 583 : recorder.beginRecording(100,100); | |
| 584 | |
| 585 /* Hit a few SkPicture::Analysis cases not handled elsewhere. */ | |
| 586 static void test_analysis(skiatest::Reporter* reporter, bool useNewPath) { | |
| 587 SkPictureRecorder recorder; | |
| 588 | |
| 589 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath); | |
| 590 { | |
| 591 canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ()); | |
| 592 } | |
| 593 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | |
| 594 REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps()); | |
| 595 | |
| 596 canvas = GENERATE_CANVAS(recorder, useNewPath); | |
| 597 { | |
| 598 SkPaint paint; | |
| 599 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad er | |
| 600 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here . | |
| 601 SkBitmap bitmap; | |
| 602 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); | |
| 603 bitmap.eraseColor(SK_ColorBLUE); | |
| 604 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN; | |
| 605 SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp _TileMode, | |
| 606 SkShader::kClamp_TileMod e); | |
| 607 paint.setShader(shader)->unref(); | |
| 608 REPORTER_ASSERT(reporter, | |
| 609 shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefaul t_BitmapType); | |
| 610 | |
| 611 canvas->drawRect(SkRect::MakeWH(10, 10), paint); | |
| 612 } | |
| 613 picture.reset(recorder.endRecording()); | |
| 614 REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps()); | |
| 615 } | |
| 616 | |
| 617 #undef GENERATE_CANVAS | |
| 618 | |
| 581 static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) { | 619 static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) { |
| 582 const int IW = 32; | 620 const int IW = 32; |
| 583 const int IH = IW; | 621 const int IH = IW; |
| 584 const SkScalar W = SkIntToScalar(IW); | 622 const SkScalar W = SkIntToScalar(IW); |
| 585 const SkScalar H = W; | 623 const SkScalar H = W; |
| 586 | 624 |
| 587 static const int N = 4; | 625 static const int N = 4; |
| 588 SkBitmap bm[2*N]; | 626 SkBitmap bm[2*N]; |
| 589 SkPixelRef* refs[2*N]; | 627 SkPixelRef* refs[2*N]; |
| 590 SkTDArray<SkPixelRef*> analytic[N]; | 628 SkTDArray<SkPixelRef*> analytic[N]; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 canvas->restore(); | 736 canvas->restore(); |
| 699 } else if (unit <= 0.9) { | 737 } else if (unit <= 0.9) { |
| 700 // SkDebugf("clip\n"); | 738 // SkDebugf("clip\n"); |
| 701 canvas->clipRect(rect); | 739 canvas->clipRect(rect); |
| 702 } else { | 740 } else { |
| 703 // SkDebugf("draw\n"); | 741 // SkDebugf("draw\n"); |
| 704 canvas->drawPaint(paint); | 742 canvas->drawPaint(paint); |
| 705 } | 743 } |
| 706 } | 744 } |
| 707 | 745 |
| 708 #if SK_SUPPORT_GPU | 746 #if SK_SUPPORT_GPU |
|
robertphillips
2014/08/19 12:27:59
Can we just define this once and move the first #u
| |
| 709 static void test_gpu_veto(skiatest::Reporter* reporter) { | 747 #define GENERATE_CANVAS(recorder, x) \ |
| 748 (x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \ | |
| 749 : recorder.beginRecording(100,100); | |
| 750 | |
|
robertphillips
2014/08/19 12:27:59
All on 1 line ?
| |
| 751 static void test_gpu_veto(skiatest::Reporter* reporter, | |
| 752 bool useNewPath) { | |
| 710 | 753 |
| 711 SkPictureRecorder recorder; | 754 SkPictureRecorder recorder; |
| 712 | 755 |
| 713 SkCanvas* canvas = recorder.beginRecording(100, 100); | 756 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath); |
| 714 { | 757 { |
| 715 SkPath path; | 758 SkPath path; |
| 716 path.moveTo(0, 0); | 759 path.moveTo(0, 0); |
| 717 path.lineTo(50, 50); | 760 path.lineTo(50, 50); |
| 718 | 761 |
| 719 SkScalar intervals[] = { 1.0f, 1.0f }; | 762 SkScalar intervals[] = { 1.0f, 1.0f }; |
| 720 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0)); | 763 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0)); |
| 721 | 764 |
| 722 SkPaint paint; | 765 SkPaint paint; |
| 723 paint.setStyle(SkPaint::kStroke_Style); | 766 paint.setStyle(SkPaint::kStroke_Style); |
| 724 paint.setPathEffect(dash); | 767 paint.setPathEffect(dash); |
| 725 | 768 |
| 726 canvas->drawPath(path, paint); | 769 canvas->drawPath(path, paint); |
| 727 } | 770 } |
| 728 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 771 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 729 // path effects currently render an SkPicture undesireable for GPU rendering | 772 // path effects currently render an SkPicture undesireable for GPU rendering |
| 730 | 773 |
| 731 const char *reason = NULL; | 774 const char *reason = NULL; |
| 732 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso n)); | 775 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso n)); |
| 733 REPORTER_ASSERT(reporter, NULL != reason); | 776 REPORTER_ASSERT(reporter, NULL != reason); |
| 734 | 777 |
| 735 canvas = recorder.beginRecording(100, 100); | 778 canvas = GENERATE_CANVAS(recorder, useNewPath); |
| 736 { | 779 { |
| 737 SkPath path; | 780 SkPath path; |
| 738 | 781 |
| 739 path.moveTo(0, 0); | 782 path.moveTo(0, 0); |
| 740 path.lineTo(0, 50); | 783 path.lineTo(0, 50); |
| 741 path.lineTo(25, 25); | 784 path.lineTo(25, 25); |
| 742 path.lineTo(50, 50); | 785 path.lineTo(50, 50); |
| 743 path.lineTo(50, 0); | 786 path.lineTo(50, 0); |
| 744 path.close(); | 787 path.close(); |
| 745 REPORTER_ASSERT(reporter, !path.isConvex()); | 788 REPORTER_ASSERT(reporter, !path.isConvex()); |
| 746 | 789 |
| 747 SkPaint paint; | 790 SkPaint paint; |
| 748 paint.setAntiAlias(true); | 791 paint.setAntiAlias(true); |
| 749 for (int i = 0; i < 50; ++i) { | 792 for (int i = 0; i < 50; ++i) { |
| 750 canvas->drawPath(path, paint); | 793 canvas->drawPath(path, paint); |
| 751 } | 794 } |
| 752 } | 795 } |
| 753 picture.reset(recorder.endRecording()); | 796 picture.reset(recorder.endRecording()); |
| 754 // A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering | 797 // A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering |
| 755 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); | 798 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); |
| 756 | 799 |
| 757 canvas = recorder.beginRecording(100, 100); | 800 canvas = GENERATE_CANVAS(recorder, useNewPath); |
| 758 { | 801 { |
| 759 SkPath path; | 802 SkPath path; |
| 760 | 803 |
| 761 path.moveTo(0, 0); | 804 path.moveTo(0, 0); |
| 762 path.lineTo(0, 50); | 805 path.lineTo(0, 50); |
| 763 path.lineTo(25, 25); | 806 path.lineTo(25, 25); |
| 764 path.lineTo(50, 50); | 807 path.lineTo(50, 50); |
| 765 path.lineTo(50, 0); | 808 path.lineTo(50, 0); |
| 766 path.close(); | 809 path.close(); |
| 767 REPORTER_ASSERT(reporter, !path.isConvex()); | 810 REPORTER_ASSERT(reporter, !path.isConvex()); |
| 768 | 811 |
| 769 SkPaint paint; | 812 SkPaint paint; |
| 770 paint.setAntiAlias(true); | 813 paint.setAntiAlias(true); |
| 771 paint.setStyle(SkPaint::kStroke_Style); | 814 paint.setStyle(SkPaint::kStroke_Style); |
| 772 paint.setStrokeWidth(0); | 815 paint.setStrokeWidth(0); |
| 773 for (int i = 0; i < 50; ++i) { | 816 for (int i = 0; i < 50; ++i) { |
| 774 canvas->drawPath(path, paint); | 817 canvas->drawPath(path, paint); |
| 775 } | 818 } |
| 776 } | 819 } |
| 777 picture.reset(recorder.endRecording()); | 820 picture.reset(recorder.endRecording()); |
| 778 // hairline stroked AA concave paths are fine for GPU rendering | 821 // hairline stroked AA concave paths are fine for GPU rendering |
| 779 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); | 822 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); |
| 823 | |
| 824 canvas = GENERATE_CANVAS(recorder, useNewPath); | |
| 825 { | |
| 826 SkPaint paint; | |
| 827 SkScalar intervals [] = { 10, 20 }; | |
| 828 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25); | |
| 829 paint.setPathEffect(pe)->unref(); | |
| 830 | |
| 831 SkPoint points [2] = { { 0, 0 }, { 100, 0 } }; | |
| 832 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint); | |
| 833 } | |
| 834 picture.reset(recorder.endRecording()); | |
| 835 // fast-path dashed effects are fine for GPU rendering ... | |
| 836 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); | |
| 837 | |
| 838 canvas = GENERATE_CANVAS(recorder, useNewPath); | |
| 839 { | |
| 840 SkPaint paint; | |
| 841 SkScalar intervals [] = { 10, 20 }; | |
| 842 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25); | |
| 843 paint.setPathEffect(pe)->unref(); | |
| 844 | |
| 845 canvas->drawRect(SkRect::MakeWH(10, 10), paint); | |
| 846 } | |
| 847 picture.reset(recorder.endRecording()); | |
| 848 // ... but only when applied to drawPoint() calls | |
| 849 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); | |
| 780 } | 850 } |
| 781 | 851 |
| 852 #undef GENERATE_CANVAS | |
| 853 | |
| 782 static void test_gpu_picture_optimization(skiatest::Reporter* reporter, | 854 static void test_gpu_picture_optimization(skiatest::Reporter* reporter, |
| 783 GrContextFactory* factory) { | 855 GrContextFactory* factory) { |
| 784 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 856 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 785 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; | 857 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; |
| 786 | 858 |
| 787 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 859 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
| 788 continue; | 860 continue; |
| 789 } | 861 } |
| 790 | 862 |
| 791 GrContext* context = factory->get(glCtxType); | 863 GrContext* context = factory->get(glCtxType); |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1610 DEF_TEST(Picture, reporter) { | 1682 DEF_TEST(Picture, reporter) { |
| 1611 #ifdef SK_DEBUG | 1683 #ifdef SK_DEBUG |
| 1612 test_deleting_empty_picture(); | 1684 test_deleting_empty_picture(); |
| 1613 test_serializing_empty_picture(); | 1685 test_serializing_empty_picture(); |
| 1614 #else | 1686 #else |
| 1615 test_bad_bitmap(); | 1687 test_bad_bitmap(); |
| 1616 #endif | 1688 #endif |
| 1617 test_unbalanced_save_restores(reporter); | 1689 test_unbalanced_save_restores(reporter); |
| 1618 test_peephole(); | 1690 test_peephole(); |
| 1619 #if SK_SUPPORT_GPU | 1691 #if SK_SUPPORT_GPU |
| 1620 test_gpu_veto(reporter); | 1692 test_gpu_veto(reporter, false); |
| 1693 test_gpu_veto(reporter, true); | |
| 1621 #endif | 1694 #endif |
| 1622 test_has_text(reporter); | 1695 test_has_text(reporter); |
| 1696 test_analysis(reporter, false); | |
| 1697 test_analysis(reporter, true); | |
| 1623 test_gatherpixelrefs(reporter); | 1698 test_gatherpixelrefs(reporter); |
| 1624 test_gatherpixelrefsandrects(reporter); | 1699 test_gatherpixelrefsandrects(reporter); |
| 1625 test_bitmap_with_encoded_data(reporter); | 1700 test_bitmap_with_encoded_data(reporter); |
| 1626 test_draw_empty(reporter); | 1701 test_draw_empty(reporter); |
| 1627 test_clip_bound_opt(reporter); | 1702 test_clip_bound_opt(reporter); |
| 1628 test_clip_expansion(reporter); | 1703 test_clip_expansion(reporter); |
| 1629 test_hierarchical(reporter); | 1704 test_hierarchical(reporter); |
| 1630 test_gen_id(reporter); | 1705 test_gen_id(reporter); |
| 1631 } | 1706 } |
| 1632 | 1707 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1756 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 1831 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
| 1757 | 1832 |
| 1758 SkCanvas big(640, 480), small(300, 200); | 1833 SkCanvas big(640, 480), small(300, 200); |
| 1759 | 1834 |
| 1760 picture->draw(&big); | 1835 picture->draw(&big); |
| 1761 REPORTER_ASSERT(r, bbh.searchCalls == 0); | 1836 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
| 1762 | 1837 |
| 1763 picture->draw(&small); | 1838 picture->draw(&small); |
| 1764 REPORTER_ASSERT(r, bbh.searchCalls == 1); | 1839 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
| 1765 } | 1840 } |
| OLD | NEW |