Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: tests/PictureTest.cpp

Issue 618303002: Remove DEPRECATED_beginRecording(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix up benches Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/CanvasTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 if (!found) { 572 if (!found) {
573 SkData* data = SkPictureUtils::GatherPixelRefs(pic, r); 573 SkData* data = SkPictureUtils::GatherPixelRefs(pic, r);
574 size_t dataSize = data ? data->size() : 0; 574 size_t dataSize = data ? data->size() : 0;
575 } 575 }
576 #endif 576 #endif
577 } 577 }
578 } 578 }
579 } 579 }
580 } 580 }
581 581
582 #define GENERATE_CANVAS(recorder, x) \
583 (x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \
584 : recorder. DEPRECATED_beginRecording(100,100);
585
586 /* Hit a few SkPicture::Analysis cases not handled elsewhere. */ 582 /* Hit a few SkPicture::Analysis cases not handled elsewhere. */
587 static void test_analysis(skiatest::Reporter* reporter, bool useNewPath) { 583 static void test_analysis(skiatest::Reporter* reporter) {
588 SkPictureRecorder recorder; 584 SkPictureRecorder recorder;
589 585
590 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath); 586 SkCanvas* canvas = recorder.beginRecording(100, 100);
591 { 587 {
592 canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ()); 588 canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ());
593 } 589 }
594 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 590 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
595 REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps()); 591 REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps());
596 592
597 canvas = GENERATE_CANVAS(recorder, useNewPath); 593 canvas = recorder.beginRecording(100, 100);
598 { 594 {
599 SkPaint paint; 595 SkPaint paint;
600 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad er 596 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad er
601 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here . 597 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here .
602 SkBitmap bitmap; 598 SkBitmap bitmap;
603 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); 599 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
604 bitmap.eraseColor(SK_ColorBLUE); 600 bitmap.eraseColor(SK_ColorBLUE);
605 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN; 601 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN;
606 SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp _TileMode, 602 SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp _TileMode,
607 SkShader::kClamp_TileMod e); 603 SkShader::kClamp_TileMod e);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 // SkDebugf("clip\n"); 734 // SkDebugf("clip\n");
739 canvas->clipRect(rect); 735 canvas->clipRect(rect);
740 } else { 736 } else {
741 // SkDebugf("draw\n"); 737 // SkDebugf("draw\n");
742 canvas->drawPaint(paint); 738 canvas->drawPaint(paint);
743 } 739 }
744 } 740 }
745 741
746 #if SK_SUPPORT_GPU 742 #if SK_SUPPORT_GPU
747 743
748 static void test_gpu_veto(skiatest::Reporter* reporter, 744 static void test_gpu_veto(skiatest::Reporter* reporter) {
749 bool useNewPath) {
750
751 SkPictureRecorder recorder; 745 SkPictureRecorder recorder;
752 746
753 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath); 747 SkCanvas* canvas = recorder.beginRecording(100, 100);
754 { 748 {
755 SkPath path; 749 SkPath path;
756 path.moveTo(0, 0); 750 path.moveTo(0, 0);
757 path.lineTo(50, 50); 751 path.lineTo(50, 50);
758 752
759 SkScalar intervals[] = { 1.0f, 1.0f }; 753 SkScalar intervals[] = { 1.0f, 1.0f };
760 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0)); 754 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0));
761 755
762 SkPaint paint; 756 SkPaint paint;
763 paint.setStyle(SkPaint::kStroke_Style); 757 paint.setStyle(SkPaint::kStroke_Style);
764 paint.setPathEffect(dash); 758 paint.setPathEffect(dash);
765 759
766 canvas->drawPath(path, paint); 760 canvas->drawPath(path, paint);
767 } 761 }
768 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 762 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
769 // path effects currently render an SkPicture undesireable for GPU rendering 763 // path effects currently render an SkPicture undesireable for GPU rendering
770 764
771 const char *reason = NULL; 765 const char *reason = NULL;
772 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso n)); 766 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso n));
773 REPORTER_ASSERT(reporter, reason); 767 REPORTER_ASSERT(reporter, reason);
774 768
775 canvas = GENERATE_CANVAS(recorder, useNewPath); 769 canvas = recorder.beginRecording(100, 100);
776 { 770 {
777 SkPath path; 771 SkPath path;
778 772
779 path.moveTo(0, 0); 773 path.moveTo(0, 0);
780 path.lineTo(0, 50); 774 path.lineTo(0, 50);
781 path.lineTo(25, 25); 775 path.lineTo(25, 25);
782 path.lineTo(50, 50); 776 path.lineTo(50, 50);
783 path.lineTo(50, 0); 777 path.lineTo(50, 0);
784 path.close(); 778 path.close();
785 REPORTER_ASSERT(reporter, !path.isConvex()); 779 REPORTER_ASSERT(reporter, !path.isConvex());
786 780
787 SkPaint paint; 781 SkPaint paint;
788 paint.setAntiAlias(true); 782 paint.setAntiAlias(true);
789 for (int i = 0; i < 50; ++i) { 783 for (int i = 0; i < 50; ++i) {
790 canvas->drawPath(path, paint); 784 canvas->drawPath(path, paint);
791 } 785 }
792 } 786 }
793 picture.reset(recorder.endRecording()); 787 picture.reset(recorder.endRecording());
794 // A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering 788 // A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering
795 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); 789 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
796 790
797 canvas = GENERATE_CANVAS(recorder, useNewPath); 791 canvas = recorder.beginRecording(100, 100);
798 { 792 {
799 SkPath path; 793 SkPath path;
800 794
801 path.moveTo(0, 0); 795 path.moveTo(0, 0);
802 path.lineTo(0, 50); 796 path.lineTo(0, 50);
803 path.lineTo(25, 25); 797 path.lineTo(25, 25);
804 path.lineTo(50, 50); 798 path.lineTo(50, 50);
805 path.lineTo(50, 0); 799 path.lineTo(50, 0);
806 path.close(); 800 path.close();
807 REPORTER_ASSERT(reporter, !path.isConvex()); 801 REPORTER_ASSERT(reporter, !path.isConvex());
808 802
809 SkPaint paint; 803 SkPaint paint;
810 paint.setAntiAlias(true); 804 paint.setAntiAlias(true);
811 paint.setStyle(SkPaint::kStroke_Style); 805 paint.setStyle(SkPaint::kStroke_Style);
812 paint.setStrokeWidth(0); 806 paint.setStrokeWidth(0);
813 for (int i = 0; i < 50; ++i) { 807 for (int i = 0; i < 50; ++i) {
814 canvas->drawPath(path, paint); 808 canvas->drawPath(path, paint);
815 } 809 }
816 } 810 }
817 picture.reset(recorder.endRecording()); 811 picture.reset(recorder.endRecording());
818 // hairline stroked AA concave paths are fine for GPU rendering 812 // hairline stroked AA concave paths are fine for GPU rendering
819 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); 813 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
820 814
821 canvas = GENERATE_CANVAS(recorder, useNewPath); 815 canvas = recorder.beginRecording(100, 100);
822 { 816 {
823 SkPaint paint; 817 SkPaint paint;
824 SkScalar intervals [] = { 10, 20 }; 818 SkScalar intervals [] = { 10, 20 };
825 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25); 819 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25);
826 paint.setPathEffect(pe)->unref(); 820 paint.setPathEffect(pe)->unref();
827 821
828 SkPoint points [2] = { { 0, 0 }, { 100, 0 } }; 822 SkPoint points [2] = { { 0, 0 }, { 100, 0 } };
829 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint); 823 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint);
830 } 824 }
831 picture.reset(recorder.endRecording()); 825 picture.reset(recorder.endRecording());
832 // fast-path dashed effects are fine for GPU rendering ... 826 // fast-path dashed effects are fine for GPU rendering ...
833 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); 827 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
834 828
835 canvas = GENERATE_CANVAS(recorder, useNewPath); 829 canvas = recorder.beginRecording(100, 100);
836 { 830 {
837 SkPaint paint; 831 SkPaint paint;
838 SkScalar intervals [] = { 10, 20 }; 832 SkScalar intervals [] = { 10, 20 };
839 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25); 833 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25);
840 paint.setPathEffect(pe)->unref(); 834 paint.setPathEffect(pe)->unref();
841 835
842 canvas->drawRect(SkRect::MakeWH(10, 10), paint); 836 canvas->drawRect(SkRect::MakeWH(10, 10), paint);
843 } 837 }
844 picture.reset(recorder.endRecording()); 838 picture.reset(recorder.endRecording());
845 // ... but only when applied to drawPoint() calls 839 // ... but only when applied to drawPoint() calls
846 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); 840 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
847 841
848 // Nest the previous picture inside a new one. 842 // Nest the previous picture inside a new one.
849 // This doesn't work in the old backend. 843 canvas = recorder.beginRecording(100, 100);
850 if (useNewPath) { 844 {
851 canvas = GENERATE_CANVAS(recorder, useNewPath); 845 canvas->drawPicture(picture.get());
852 {
853 canvas->drawPicture(picture.get());
854 }
855 picture.reset(recorder.endRecording());
856 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
857 } 846 }
847 picture.reset(recorder.endRecording());
848 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
858 } 849 }
859 850
860 #undef GENERATE_CANVAS
861
862 static void test_gpu_picture_optimization(skiatest::Reporter* reporter, 851 static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
863 GrContextFactory* factory) { 852 GrContextFactory* factory) {
864 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 853 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
865 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; 854 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
866 855
867 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 856 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
868 continue; 857 continue;
869 } 858 }
870 859
871 GrContext* context = factory->get(glCtxType); 860 GrContext* context = factory->get(glCtxType);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 REPORTER_ASSERT(reporter, 0 == info7.fOffset.fX && 0 == info7.fOffse t.fY); 1054 REPORTER_ASSERT(reporter, 0 == info7.fOffset.fX && 0 == info7.fOffse t.fY);
1066 REPORTER_ASSERT(reporter, info7.fOriginXform.isIdentity()); 1055 REPORTER_ASSERT(reporter, info7.fOriginXform.isIdentity());
1067 REPORTER_ASSERT(reporter, NULL == info7.fPaint); 1056 REPORTER_ASSERT(reporter, NULL == info7.fPaint);
1068 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers ); // is nested 1057 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers ); // is nested
1069 } 1058 }
1070 } 1059 }
1071 } 1060 }
1072 1061
1073 #endif 1062 #endif
1074 1063
1075 static void test_has_text(skiatest::Reporter* reporter, bool useNewPath) { 1064 static void test_has_text(skiatest::Reporter* reporter) {
1076 SkPictureRecorder recorder; 1065 SkPictureRecorder recorder;
1077 #define BEGIN_RECORDING useNewPath ? recorder.EXPERIMENTAL_beginRecording(100, 1 00) \
1078 : recorder. DEPRECATED_beginRecording(100, 1 00)
1079 1066
1080 SkCanvas* canvas = BEGIN_RECORDING; 1067 SkCanvas* canvas = recorder.beginRecording(100,100);
1081 { 1068 {
1082 canvas->drawRect(SkRect::MakeWH(20, 20), SkPaint()); 1069 canvas->drawRect(SkRect::MakeWH(20, 20), SkPaint());
1083 } 1070 }
1084 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1071 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1085 REPORTER_ASSERT(reporter, !picture->hasText()); 1072 REPORTER_ASSERT(reporter, !picture->hasText());
1086 1073
1087 SkPoint point = SkPoint::Make(10, 10); 1074 SkPoint point = SkPoint::Make(10, 10);
1088 canvas = BEGIN_RECORDING; 1075 canvas = recorder.beginRecording(100,100);
1089 { 1076 {
1090 canvas->drawText("Q", 1, point.fX, point.fY, SkPaint()); 1077 canvas->drawText("Q", 1, point.fX, point.fY, SkPaint());
1091 } 1078 }
1092 picture.reset(recorder.endRecording()); 1079 picture.reset(recorder.endRecording());
1093 REPORTER_ASSERT(reporter, picture->hasText()); 1080 REPORTER_ASSERT(reporter, picture->hasText());
1094 1081
1095 canvas = BEGIN_RECORDING; 1082 canvas = recorder.beginRecording(100,100);
1096 { 1083 {
1097 canvas->drawPosText("Q", 1, &point, SkPaint()); 1084 canvas->drawPosText("Q", 1, &point, SkPaint());
1098 } 1085 }
1099 picture.reset(recorder.endRecording()); 1086 picture.reset(recorder.endRecording());
1100 REPORTER_ASSERT(reporter, picture->hasText()); 1087 REPORTER_ASSERT(reporter, picture->hasText());
1101 1088
1102 canvas = BEGIN_RECORDING; 1089 canvas = recorder.beginRecording(100,100);
1103 { 1090 {
1104 canvas->drawPosTextH("Q", 1, &point.fX, point.fY, SkPaint()); 1091 canvas->drawPosTextH("Q", 1, &point.fX, point.fY, SkPaint());
1105 } 1092 }
1106 picture.reset(recorder.endRecording()); 1093 picture.reset(recorder.endRecording());
1107 REPORTER_ASSERT(reporter, picture->hasText()); 1094 REPORTER_ASSERT(reporter, picture->hasText());
1108 1095
1109 canvas = BEGIN_RECORDING; 1096 canvas = recorder.beginRecording(100,100);
1110 { 1097 {
1111 SkPath path; 1098 SkPath path;
1112 path.moveTo(0, 0); 1099 path.moveTo(0, 0);
1113 path.lineTo(50, 50); 1100 path.lineTo(50, 50);
1114 1101
1115 canvas->drawTextOnPathHV("Q", 1, path, point.fX, point.fY, SkPaint()); 1102 canvas->drawTextOnPathHV("Q", 1, path, point.fX, point.fY, SkPaint());
1116 } 1103 }
1117 picture.reset(recorder.endRecording()); 1104 picture.reset(recorder.endRecording());
1118 REPORTER_ASSERT(reporter, picture->hasText()); 1105 REPORTER_ASSERT(reporter, picture->hasText());
1119 1106
1120 canvas = BEGIN_RECORDING; 1107 canvas = recorder.beginRecording(100,100);
1121 { 1108 {
1122 SkPath path; 1109 SkPath path;
1123 path.moveTo(0, 0); 1110 path.moveTo(0, 0);
1124 path.lineTo(50, 50); 1111 path.lineTo(50, 50);
1125 1112
1126 canvas->drawTextOnPath("Q", 1, path, NULL, SkPaint()); 1113 canvas->drawTextOnPath("Q", 1, path, NULL, SkPaint());
1127 } 1114 }
1128 picture.reset(recorder.endRecording()); 1115 picture.reset(recorder.endRecording());
1129 REPORTER_ASSERT(reporter, picture->hasText()); 1116 REPORTER_ASSERT(reporter, picture->hasText());
1130 1117
1131 // Nest the previous picture inside a new one. 1118 // Nest the previous picture inside a new one.
1132 // This doesn't work in the old backend. 1119 canvas = recorder.beginRecording(100,100);
1133 if (useNewPath) { 1120 {
1134 canvas = BEGIN_RECORDING; 1121 canvas->drawPicture(picture.get());
1135 {
1136 canvas->drawPicture(picture.get());
1137 }
1138 picture.reset(recorder.endRecording());
1139 REPORTER_ASSERT(reporter, picture->hasText());
1140 } 1122 }
1141 #undef BEGIN_RECORDING 1123 picture.reset(recorder.endRecording());
1124 REPORTER_ASSERT(reporter, picture->hasText());
1142 } 1125 }
1143 1126
1144 static void set_canvas_to_save_count_4(SkCanvas* canvas) { 1127 static void set_canvas_to_save_count_4(SkCanvas* canvas) {
1145 canvas->restoreToCount(1); 1128 canvas->restoreToCount(1);
1146 canvas->save(); 1129 canvas->save();
1147 canvas->save(); 1130 canvas->save();
1148 canvas->save(); 1131 canvas->save();
1149 } 1132 }
1150 1133
1151 /** 1134 /**
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 DEF_TEST(Picture, reporter) { 1751 DEF_TEST(Picture, reporter) {
1769 #ifdef SK_DEBUG 1752 #ifdef SK_DEBUG
1770 test_deleting_empty_picture(); 1753 test_deleting_empty_picture();
1771 test_serializing_empty_picture(); 1754 test_serializing_empty_picture();
1772 #else 1755 #else
1773 test_bad_bitmap(); 1756 test_bad_bitmap();
1774 #endif 1757 #endif
1775 test_unbalanced_save_restores(reporter); 1758 test_unbalanced_save_restores(reporter);
1776 test_peephole(); 1759 test_peephole();
1777 #if SK_SUPPORT_GPU 1760 #if SK_SUPPORT_GPU
1778 test_gpu_veto(reporter, false); 1761 test_gpu_veto(reporter);
1779 test_gpu_veto(reporter, true);
1780 #endif 1762 #endif
1781 test_has_text(reporter, false); 1763 test_has_text(reporter);
1782 test_has_text(reporter, true); 1764 test_analysis(reporter);
1783 test_analysis(reporter, false);
1784 test_analysis(reporter, true);
1785 test_gatherpixelrefs(reporter); 1765 test_gatherpixelrefs(reporter);
1786 test_gatherpixelrefsandrects(reporter); 1766 test_gatherpixelrefsandrects(reporter);
1787 test_bitmap_with_encoded_data(reporter); 1767 test_bitmap_with_encoded_data(reporter);
1788 test_draw_empty(reporter); 1768 test_draw_empty(reporter);
1789 test_clip_bound_opt(reporter); 1769 test_clip_bound_opt(reporter);
1790 test_clip_expansion(reporter); 1770 test_clip_expansion(reporter);
1791 test_hierarchical(reporter); 1771 test_hierarchical(reporter);
1792 test_gen_id(reporter); 1772 test_gen_id(reporter);
1793 } 1773 }
1794 1774
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 1926
1947 // The picture shares the immutable pixels but copies the mutable ones. 1927 // The picture shares the immutable pixels but copies the mutable ones.
1948 REPORTER_ASSERT(r, mut.pixelRef()->unique()); 1928 REPORTER_ASSERT(r, mut.pixelRef()->unique());
1949 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); 1929 REPORTER_ASSERT(r, !immut.pixelRef()->unique());
1950 1930
1951 // When the picture goes away, it's just our bitmaps holding the refs. 1931 // When the picture goes away, it's just our bitmaps holding the refs.
1952 pic.reset(NULL); 1932 pic.reset(NULL);
1953 REPORTER_ASSERT(r, mut.pixelRef()->unique()); 1933 REPORTER_ASSERT(r, mut.pixelRef()->unique());
1954 REPORTER_ASSERT(r, immut.pixelRef()->unique()); 1934 REPORTER_ASSERT(r, immut.pixelRef()->unique());
1955 } 1935 }
OLDNEW
« no previous file with comments | « tests/CanvasTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698