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 | |
619 static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) { | 581 static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) { |
620 const int IW = 32; | 582 const int IW = 32; |
621 const int IH = IW; | 583 const int IH = IW; |
622 const SkScalar W = SkIntToScalar(IW); | 584 const SkScalar W = SkIntToScalar(IW); |
623 const SkScalar H = W; | 585 const SkScalar H = W; |
624 | 586 |
625 static const int N = 4; | 587 static const int N = 4; |
626 SkBitmap bm[2*N]; | 588 SkBitmap bm[2*N]; |
627 SkPixelRef* refs[2*N]; | 589 SkPixelRef* refs[2*N]; |
628 SkTDArray<SkPixelRef*> analytic[N]; | 590 SkTDArray<SkPixelRef*> analytic[N]; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 } else if (unit <= 0.9) { | 699 } else if (unit <= 0.9) { |
738 // SkDebugf("clip\n"); | 700 // SkDebugf("clip\n"); |
739 canvas->clipRect(rect); | 701 canvas->clipRect(rect); |
740 } else { | 702 } else { |
741 // SkDebugf("draw\n"); | 703 // SkDebugf("draw\n"); |
742 canvas->drawPaint(paint); | 704 canvas->drawPaint(paint); |
743 } | 705 } |
744 } | 706 } |
745 | 707 |
746 #if SK_SUPPORT_GPU | 708 #if SK_SUPPORT_GPU |
747 #define GENERATE_CANVAS(recorder, x) \ | 709 static void test_gpu_veto(skiatest::Reporter* reporter) { |
748 (x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \ | |
749 : recorder.beginRecording(100,100); | |
750 | |
751 static void test_gpu_veto(skiatest::Reporter* reporter, | |
752 bool useNewPath) { | |
753 | 710 |
754 SkPictureRecorder recorder; | 711 SkPictureRecorder recorder; |
755 | 712 |
756 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath); | 713 SkCanvas* canvas = recorder.beginRecording(100, 100); |
757 { | 714 { |
758 SkPath path; | 715 SkPath path; |
759 path.moveTo(0, 0); | 716 path.moveTo(0, 0); |
760 path.lineTo(50, 50); | 717 path.lineTo(50, 50); |
761 | 718 |
762 SkScalar intervals[] = { 1.0f, 1.0f }; | 719 SkScalar intervals[] = { 1.0f, 1.0f }; |
763 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals,
2, 0)); | 720 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals,
2, 0)); |
764 | 721 |
765 SkPaint paint; | 722 SkPaint paint; |
766 paint.setStyle(SkPaint::kStroke_Style); | 723 paint.setStyle(SkPaint::kStroke_Style); |
767 paint.setPathEffect(dash); | 724 paint.setPathEffect(dash); |
768 | 725 |
769 canvas->drawPath(path, paint); | 726 canvas->drawPath(path, paint); |
770 } | 727 } |
771 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 728 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
772 // path effects currently render an SkPicture undesireable for GPU rendering | 729 // path effects currently render an SkPicture undesireable for GPU rendering |
773 | 730 |
774 const char *reason = NULL; | 731 const char *reason = NULL; |
775 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso
n)); | 732 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso
n)); |
776 REPORTER_ASSERT(reporter, NULL != reason); | 733 REPORTER_ASSERT(reporter, NULL != reason); |
777 | 734 |
778 canvas = GENERATE_CANVAS(recorder, useNewPath); | 735 canvas = recorder.beginRecording(100, 100); |
779 { | 736 { |
780 SkPath path; | 737 SkPath path; |
781 | 738 |
782 path.moveTo(0, 0); | 739 path.moveTo(0, 0); |
783 path.lineTo(0, 50); | 740 path.lineTo(0, 50); |
784 path.lineTo(25, 25); | 741 path.lineTo(25, 25); |
785 path.lineTo(50, 50); | 742 path.lineTo(50, 50); |
786 path.lineTo(50, 0); | 743 path.lineTo(50, 0); |
787 path.close(); | 744 path.close(); |
788 REPORTER_ASSERT(reporter, !path.isConvex()); | 745 REPORTER_ASSERT(reporter, !path.isConvex()); |
789 | 746 |
790 SkPaint paint; | 747 SkPaint paint; |
791 paint.setAntiAlias(true); | 748 paint.setAntiAlias(true); |
792 for (int i = 0; i < 50; ++i) { | 749 for (int i = 0; i < 50; ++i) { |
793 canvas->drawPath(path, paint); | 750 canvas->drawPath(path, paint); |
794 } | 751 } |
795 } | 752 } |
796 picture.reset(recorder.endRecording()); | 753 picture.reset(recorder.endRecording()); |
797 // A lot of AA concave paths currently render an SkPicture undesireable for
GPU rendering | 754 // A lot of AA concave paths currently render an SkPicture undesireable for
GPU rendering |
798 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); | 755 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); |
799 | 756 |
800 canvas = GENERATE_CANVAS(recorder, useNewPath); | 757 canvas = recorder.beginRecording(100, 100); |
801 { | 758 { |
802 SkPath path; | 759 SkPath path; |
803 | 760 |
804 path.moveTo(0, 0); | 761 path.moveTo(0, 0); |
805 path.lineTo(0, 50); | 762 path.lineTo(0, 50); |
806 path.lineTo(25, 25); | 763 path.lineTo(25, 25); |
807 path.lineTo(50, 50); | 764 path.lineTo(50, 50); |
808 path.lineTo(50, 0); | 765 path.lineTo(50, 0); |
809 path.close(); | 766 path.close(); |
810 REPORTER_ASSERT(reporter, !path.isConvex()); | 767 REPORTER_ASSERT(reporter, !path.isConvex()); |
811 | 768 |
812 SkPaint paint; | 769 SkPaint paint; |
813 paint.setAntiAlias(true); | 770 paint.setAntiAlias(true); |
814 paint.setStyle(SkPaint::kStroke_Style); | 771 paint.setStyle(SkPaint::kStroke_Style); |
815 paint.setStrokeWidth(0); | 772 paint.setStrokeWidth(0); |
816 for (int i = 0; i < 50; ++i) { | 773 for (int i = 0; i < 50; ++i) { |
817 canvas->drawPath(path, paint); | 774 canvas->drawPath(path, paint); |
818 } | 775 } |
819 } | 776 } |
820 picture.reset(recorder.endRecording()); | 777 picture.reset(recorder.endRecording()); |
821 // hairline stroked AA concave paths are fine for GPU rendering | 778 // hairline stroked AA concave paths are fine for GPU rendering |
822 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); | 779 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)); | |
850 } | 780 } |
851 | 781 |
852 #undef GENERATE_CANVAS | |
853 | |
854 static void test_gpu_picture_optimization(skiatest::Reporter* reporter, | 782 static void test_gpu_picture_optimization(skiatest::Reporter* reporter, |
855 GrContextFactory* factory) { | 783 GrContextFactory* factory) { |
856 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 784 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
857 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; | 785 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; |
858 | 786 |
859 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 787 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
860 continue; | 788 continue; |
861 } | 789 } |
862 | 790 |
863 GrContext* context = factory->get(glCtxType); | 791 GrContext* context = factory->get(glCtxType); |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 DEF_TEST(Picture, reporter) { | 1610 DEF_TEST(Picture, reporter) { |
1683 #ifdef SK_DEBUG | 1611 #ifdef SK_DEBUG |
1684 test_deleting_empty_picture(); | 1612 test_deleting_empty_picture(); |
1685 test_serializing_empty_picture(); | 1613 test_serializing_empty_picture(); |
1686 #else | 1614 #else |
1687 test_bad_bitmap(); | 1615 test_bad_bitmap(); |
1688 #endif | 1616 #endif |
1689 test_unbalanced_save_restores(reporter); | 1617 test_unbalanced_save_restores(reporter); |
1690 test_peephole(); | 1618 test_peephole(); |
1691 #if SK_SUPPORT_GPU | 1619 #if SK_SUPPORT_GPU |
1692 test_gpu_veto(reporter, false); | 1620 test_gpu_veto(reporter); |
1693 test_gpu_veto(reporter, true); | |
1694 #endif | 1621 #endif |
1695 test_has_text(reporter); | 1622 test_has_text(reporter); |
1696 test_analysis(reporter, false); | |
1697 test_analysis(reporter, true); | |
1698 test_gatherpixelrefs(reporter); | 1623 test_gatherpixelrefs(reporter); |
1699 test_gatherpixelrefsandrects(reporter); | 1624 test_gatherpixelrefsandrects(reporter); |
1700 test_bitmap_with_encoded_data(reporter); | 1625 test_bitmap_with_encoded_data(reporter); |
1701 test_draw_empty(reporter); | 1626 test_draw_empty(reporter); |
1702 test_clip_bound_opt(reporter); | 1627 test_clip_bound_opt(reporter); |
1703 test_clip_expansion(reporter); | 1628 test_clip_expansion(reporter); |
1704 test_hierarchical(reporter); | 1629 test_hierarchical(reporter); |
1705 test_gen_id(reporter); | 1630 test_gen_id(reporter); |
1706 } | 1631 } |
1707 | 1632 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 1756 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
1832 | 1757 |
1833 SkCanvas big(640, 480), small(300, 200); | 1758 SkCanvas big(640, 480), small(300, 200); |
1834 | 1759 |
1835 picture->draw(&big); | 1760 picture->draw(&big); |
1836 REPORTER_ASSERT(r, bbh.searchCalls == 0); | 1761 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
1837 | 1762 |
1838 picture->draw(&small); | 1763 picture->draw(&small); |
1839 REPORTER_ASSERT(r, bbh.searchCalls == 1); | 1764 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
1840 } | 1765 } |
OLD | NEW |