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

Side by Side Diff: tests/PictureTest.cpp

Issue 504393002: Switch GPU Optimization code to SkRecord (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 6 years, 3 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 | « src/gpu/SkGpuDevice.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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 869
870 GrContext* context = factory->get(glCtxType); 870 GrContext* context = factory->get(glCtxType);
871 871
872 if (NULL == context) { 872 if (NULL == context) {
873 continue; 873 continue;
874 } 874 }
875 875
876 static const int kWidth = 100; 876 static const int kWidth = 100;
877 static const int kHeight = 100; 877 static const int kHeight = 100;
878 878
879 SkAutoTUnref<SkPicture> pict; 879 SkAutoTUnref<SkPicture> pict, child;
880
881 {
882 SkPictureRecorder recorder;
883
884 SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
885
886 c->saveLayer(NULL, NULL);
887 c->restore();
888
889 child.reset(recorder.endRecording());
890 }
880 891
881 // create a picture with the structure: 892 // create a picture with the structure:
882 // 1) 893 // 1)
883 // SaveLayer 894 // SaveLayer
884 // Restore 895 // Restore
885 // 2) 896 // 2)
886 // SaveLayer 897 // SaveLayer
887 // Translate 898 // Translate
888 // SaveLayer w/ bound 899 // SaveLayer w/ bound
889 // Restore 900 // Restore
890 // Restore 901 // Restore
891 // 3) 902 // 3)
892 // SaveLayer w/ copyable paint 903 // SaveLayer w/ copyable paint
893 // Restore 904 // Restore
894 // 4) 905 // 4)
895 // SaveLayer w/ non-copyable paint 906 // SaveLayer
907 // DrawPicture (which has a SaveLayer/Restore pair)
908 // Restore
909 // 5)
910 // SaveLayer
911 // DrawPicture with Matrix & Paint (with SaveLayer/Restore pair )
896 // Restore 912 // Restore
897 { 913 {
898 SkPictureRecorder recorder; 914 SkPictureRecorder recorder;
899 915
900 SkCanvas* c = recorder.DEPRECATED_beginRecording(kWidth, kHeight); 916 SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
901 // 1) 917 // 1)
902 c->saveLayer(NULL, NULL); 918 c->saveLayer(NULL, NULL); // layer #0
903 c->restore(); 919 c->restore();
904 920
905 // 2) 921 // 2)
906 c->saveLayer(NULL, NULL); 922 c->saveLayer(NULL, NULL); // layer #1
907 c->translate(kWidth/2, kHeight/2); 923 c->translate(kWidth/2.0f, kHeight/2.0f);
908 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); 924 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2);
909 c->saveLayer(&r, NULL); 925 c->saveLayer(&r, NULL); // layer #2
910 c->restore(); 926 c->restore();
911 c->restore(); 927 c->restore();
912 928
913 // 3) 929 // 3)
914 { 930 {
915 SkPaint p; 931 SkPaint p;
916 p.setColor(SK_ColorRED); 932 p.setColor(SK_ColorRED);
917 c->saveLayer(NULL, &p); 933 c->saveLayer(NULL, &p); // layer #3
918 c->restore(); 934 c->restore();
919 } 935 }
920 // 4) 936 // 4)
921 // TODO: this case will need to be removed once the paint's are immu table 937 {
938 c->saveLayer(NULL, NULL); // layer #4
939 c->drawPicture(child); // layer #5 inside picture
940 c->restore();
941 }
942 // 5
922 { 943 {
923 SkPaint p; 944 SkPaint p;
924 SkAutoTUnref<SkColorFilter> cf(SkLumaColorFilter::Create()); 945 SkMatrix trans;
925 p.setImageFilter(SkColorFilterImageFilter::Create(cf.get()))->un ref(); 946 trans.setTranslate(10, 10);
926 c->saveLayer(NULL, &p); 947
948 c->saveLayer(NULL, NULL); // layer #6
949 c->drawPicture(child, &trans, &p); // layer #7 inside pictur e
927 c->restore(); 950 c->restore();
928 } 951 }
929 952
930 pict.reset(recorder.endRecording()); 953 pict.reset(recorder.endRecording());
931 } 954 }
932 955
933 // Now test out the SaveLayer extraction 956 // Now test out the SaveLayer extraction
934 { 957 {
935 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); 958 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
936 959
937 SkAutoTUnref<SkSurface> surface(SkSurface::NewScratchRenderTarget(co ntext, info)); 960 SkAutoTUnref<SkSurface> surface(SkSurface::NewScratchRenderTarget(co ntext, info));
938 961
939 SkCanvas* canvas = surface->getCanvas(); 962 SkCanvas* canvas = surface->getCanvas();
940 963
941 canvas->EXPERIMENTAL_optimize(pict); 964 canvas->EXPERIMENTAL_optimize(pict);
942 965
943 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); 966 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
944 967
945 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(k ey); 968 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(k ey);
946 REPORTER_ASSERT(reporter, NULL != data); 969 REPORTER_ASSERT(reporter, NULL != data);
947 970
948 const GrAccelData *gpuData = static_cast<const GrAccelData*>(data); 971 const GrAccelData *gpuData = static_cast<const GrAccelData*>(data);
949 REPORTER_ASSERT(reporter, 5 == gpuData->numSaveLayers()); 972 REPORTER_ASSERT(reporter, 8 == gpuData->numSaveLayers());
950 973
951 const GrAccelData::SaveLayerInfo& info0 = gpuData->saveLayerInfo(0); 974 const GrAccelData::SaveLayerInfo& info0 = gpuData->saveLayerInfo(0);
952 // The parent/child layer appear in reverse order 975 // The parent/child layers appear in reverse order
953 const GrAccelData::SaveLayerInfo& info1 = gpuData->saveLayerInfo(2); 976 const GrAccelData::SaveLayerInfo& info1 = gpuData->saveLayerInfo(2);
954 const GrAccelData::SaveLayerInfo& info2 = gpuData->saveLayerInfo(1); 977 const GrAccelData::SaveLayerInfo& info2 = gpuData->saveLayerInfo(1);
978
955 const GrAccelData::SaveLayerInfo& info3 = gpuData->saveLayerInfo(3); 979 const GrAccelData::SaveLayerInfo& info3 = gpuData->saveLayerInfo(3);
956 // const GrAccelData::SaveLayerInfo& info4 = gpuData->saveLayerInfo(4); 980
981 // The parent/child layers appear in reverse order
982 const GrAccelData::SaveLayerInfo& info4 = gpuData->saveLayerInfo(5);
983 const GrAccelData::SaveLayerInfo& info5 = gpuData->saveLayerInfo(4);
984
985 // The parent/child layers appear in reverse order
986 const GrAccelData::SaveLayerInfo& info6 = gpuData->saveLayerInfo(7);
987 const GrAccelData::SaveLayerInfo& info7 = gpuData->saveLayerInfo(6);
957 988
958 REPORTER_ASSERT(reporter, info0.fValid); 989 REPORTER_ASSERT(reporter, info0.fValid);
959 REPORTER_ASSERT(reporter, kWidth == info0.fSize.fWidth && kHeight == info0.fSize.fHeight); 990 REPORTER_ASSERT(reporter, pict->uniqueID() == info0.fPictureID);
960 REPORTER_ASSERT(reporter, info0.fCTM.isIdentity()); 991 REPORTER_ASSERT(reporter, kWidth == info0.fSize.fWidth &&
992 kHeight == info0.fSize.fHeight);
993 REPORTER_ASSERT(reporter, info0.fOriginXform.isIdentity());
961 REPORTER_ASSERT(reporter, 0 == info0.fOffset.fX && 0 == info0.fOffse t.fY); 994 REPORTER_ASSERT(reporter, 0 == info0.fOffset.fX && 0 == info0.fOffse t.fY);
962 REPORTER_ASSERT(reporter, NULL != info0.fPaint); 995 REPORTER_ASSERT(reporter, NULL == info0.fPaint);
963 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayer s); 996 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayer s);
964 997
965 REPORTER_ASSERT(reporter, info1.fValid); 998 REPORTER_ASSERT(reporter, info1.fValid);
966 REPORTER_ASSERT(reporter, kWidth == info1.fSize.fWidth && kHeight == info1.fSize.fHeight); 999 REPORTER_ASSERT(reporter, pict->uniqueID() == info1.fPictureID);
967 REPORTER_ASSERT(reporter, info1.fCTM.isIdentity()); 1000 REPORTER_ASSERT(reporter, kWidth == info1.fSize.fWidth &&
1001 kHeight == info1.fSize.fHeight);
1002 REPORTER_ASSERT(reporter, info1.fOriginXform.isIdentity());
968 REPORTER_ASSERT(reporter, 0 == info1.fOffset.fX && 0 == info1.fOffse t.fY); 1003 REPORTER_ASSERT(reporter, 0 == info1.fOffset.fX && 0 == info1.fOffse t.fY);
969 REPORTER_ASSERT(reporter, NULL != info1.fPaint); 1004 REPORTER_ASSERT(reporter, NULL == info1.fPaint);
970 REPORTER_ASSERT(reporter, !info1.fIsNested && info1.fHasNestedLayers ); // has a nested SL 1005 REPORTER_ASSERT(reporter, !info1.fIsNested &&
1006 info1.fHasNestedLayers); // has a nested S L
971 1007
972 REPORTER_ASSERT(reporter, info2.fValid); 1008 REPORTER_ASSERT(reporter, info2.fValid);
973 REPORTER_ASSERT(reporter, kWidth/2 == info2.fSize.fWidth && 1009 REPORTER_ASSERT(reporter, pict->uniqueID() == info2.fPictureID);
1010 REPORTER_ASSERT(reporter, kWidth / 2 == info2.fSize.fWidth &&
974 kHeight/2 == info2.fSize.fHeight); // boun d reduces size 1011 kHeight/2 == info2.fSize.fHeight); // boun d reduces size
975 REPORTER_ASSERT(reporter, info2.fCTM.isIdentity()); // trans lated 1012 REPORTER_ASSERT(reporter, info2.fOriginXform.isIdentity());
976 REPORTER_ASSERT(reporter, kWidth/2 == info2.fOffset.fX && 1013 REPORTER_ASSERT(reporter, kWidth/2 == info2.fOffset.fX && // trans lated
977 kHeight/2 == info2.fOffset.fY); 1014 kHeight/2 == info2.fOffset.fY);
978 REPORTER_ASSERT(reporter, NULL != info1.fPaint); 1015 REPORTER_ASSERT(reporter, NULL == info1.fPaint);
979 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers ); // is nested 1016 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers ); // is nested
980 1017
981 REPORTER_ASSERT(reporter, info3.fValid); 1018 REPORTER_ASSERT(reporter, info3.fValid);
982 REPORTER_ASSERT(reporter, kWidth == info3.fSize.fWidth && kHeight == info3.fSize.fHeight); 1019 REPORTER_ASSERT(reporter, pict->uniqueID() == info3.fPictureID);
983 REPORTER_ASSERT(reporter, info3.fCTM.isIdentity()); 1020 REPORTER_ASSERT(reporter, kWidth == info3.fSize.fWidth &&
1021 kHeight == info3.fSize.fHeight);
1022 REPORTER_ASSERT(reporter, info3.fOriginXform.isIdentity());
984 REPORTER_ASSERT(reporter, 0 == info3.fOffset.fX && 0 == info3.fOffse t.fY); 1023 REPORTER_ASSERT(reporter, 0 == info3.fOffset.fX && 0 == info3.fOffse t.fY);
985 REPORTER_ASSERT(reporter, NULL != info3.fPaint); 1024 REPORTER_ASSERT(reporter, NULL != info3.fPaint);
986 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayer s); 1025 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayer s);
987 1026
988 #if 0 // needs more though for GrGatherCanvas 1027 REPORTER_ASSERT(reporter, info4.fValid);
989 REPORTER_ASSERT(reporter, !info4.fValid); // paint i s/was uncopyable 1028 REPORTER_ASSERT(reporter, pict->uniqueID() == info4.fPictureID);
990 REPORTER_ASSERT(reporter, kWidth == info4.fSize.fWidth && kHeight == info4.fSize.fHeight); 1029 REPORTER_ASSERT(reporter, kWidth == info4.fSize.fWidth &&
1030 kHeight == info4.fSize.fHeight);
991 REPORTER_ASSERT(reporter, 0 == info4.fOffset.fX && 0 == info4.fOffse t.fY); 1031 REPORTER_ASSERT(reporter, 0 == info4.fOffset.fX && 0 == info4.fOffse t.fY);
992 REPORTER_ASSERT(reporter, info4.fCTM.isIdentity()); 1032 REPORTER_ASSERT(reporter, info4.fOriginXform.isIdentity());
993 REPORTER_ASSERT(reporter, NULL == info4.fPaint); // paint is/was uncopyable 1033 REPORTER_ASSERT(reporter, NULL == info4.fPaint);
994 REPORTER_ASSERT(reporter, !info4.fIsNested && !info4.fHasNestedLayer s); 1034 REPORTER_ASSERT(reporter, !info4.fIsNested &&
995 #endif 1035 info4.fHasNestedLayers); // has a nested S L
1036
1037 REPORTER_ASSERT(reporter, info5.fValid);
1038 REPORTER_ASSERT(reporter, child->uniqueID() == info5.fPictureID); // in a child picture
1039 REPORTER_ASSERT(reporter, kWidth == info5.fSize.fWidth &&
1040 kHeight == info5.fSize.fHeight);
1041 REPORTER_ASSERT(reporter, 0 == info5.fOffset.fX && 0 == info5.fOffse t.fY);
1042 REPORTER_ASSERT(reporter, info5.fOriginXform.isIdentity());
1043 REPORTER_ASSERT(reporter, NULL == info5.fPaint);
1044 REPORTER_ASSERT(reporter, info5.fIsNested && !info5.fHasNestedLayers ); // is nested
1045
1046 REPORTER_ASSERT(reporter, info6.fValid);
1047 REPORTER_ASSERT(reporter, pict->uniqueID() == info6.fPictureID);
1048 REPORTER_ASSERT(reporter, kWidth == info6.fSize.fWidth &&
1049 kHeight == info6.fSize.fHeight);
1050 REPORTER_ASSERT(reporter, 0 == info6.fOffset.fX && 0 == info6.fOffse t.fY);
1051 REPORTER_ASSERT(reporter, info6.fOriginXform.isIdentity());
1052 REPORTER_ASSERT(reporter, NULL == info6.fPaint);
1053 REPORTER_ASSERT(reporter, !info6.fIsNested &&
1054 info6.fHasNestedLayers); // has a nested S L
1055
1056 REPORTER_ASSERT(reporter, info7.fValid);
1057 REPORTER_ASSERT(reporter, child->uniqueID() == info7.fPictureID); // in a child picture
1058 REPORTER_ASSERT(reporter, kWidth == info7.fSize.fWidth &&
1059 kHeight == info7.fSize.fHeight);
1060 REPORTER_ASSERT(reporter, 0 == info7.fOffset.fX && 0 == info7.fOffse t.fY);
1061 REPORTER_ASSERT(reporter, info7.fOriginXform.isIdentity());
1062 REPORTER_ASSERT(reporter, NULL == info7.fPaint);
1063 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers ); // is nested
996 } 1064 }
997 } 1065 }
998 } 1066 }
999 1067
1000 #endif 1068 #endif
1001 1069
1002 static void test_has_text(skiatest::Reporter* reporter, bool useNewPath) { 1070 static void test_has_text(skiatest::Reporter* reporter, bool useNewPath) {
1003 SkPictureRecorder recorder; 1071 SkPictureRecorder recorder;
1004 #define BEGIN_RECORDING useNewPath ? recorder.EXPERIMENTAL_beginRecording(100, 1 00) \ 1072 #define BEGIN_RECORDING useNewPath ? recorder.EXPERIMENTAL_beginRecording(100, 1 00) \
1005 : recorder. DEPRECATED_beginRecording(100, 1 00) 1073 : recorder. DEPRECATED_beginRecording(100, 1 00)
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); 1909 SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
1842 1910
1843 SkCanvas big(640, 480), small(300, 200); 1911 SkCanvas big(640, 480), small(300, 200);
1844 1912
1845 picture->draw(&big); 1913 picture->draw(&big);
1846 REPORTER_ASSERT(r, bbh.searchCalls == 0); 1914 REPORTER_ASSERT(r, bbh.searchCalls == 0);
1847 1915
1848 picture->draw(&small); 1916 picture->draw(&small);
1849 REPORTER_ASSERT(r, bbh.searchCalls == 1); 1917 REPORTER_ASSERT(r, bbh.searchCalls == 1);
1850 } 1918 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698