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" |
| 11 #include "SkColorMatrixFilter.h" |
11 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
12 #include "SkDashPathEffect.h" | 13 #include "SkDashPathEffect.h" |
13 #include "SkData.h" | 14 #include "SkData.h" |
14 #include "SkDecodingImageGenerator.h" | 15 #include "SkDecodingImageGenerator.h" |
15 #include "SkError.h" | 16 #include "SkError.h" |
16 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
17 #include "SkImageGenerator.h" | 18 #include "SkImageGenerator.h" |
18 #include "SkPaint.h" | 19 #include "SkPaint.h" |
19 #include "SkPicture.h" | 20 #include "SkPicture.h" |
20 #include "SkPictureRecorder.h" | 21 #include "SkPictureRecorder.h" |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 | 860 |
860 GrContext* context = factory->get(glCtxType); | 861 GrContext* context = factory->get(glCtxType); |
861 | 862 |
862 if (NULL == context) { | 863 if (NULL == context) { |
863 continue; | 864 continue; |
864 } | 865 } |
865 | 866 |
866 static const int kWidth = 100; | 867 static const int kWidth = 100; |
867 static const int kHeight = 100; | 868 static const int kHeight = 100; |
868 | 869 |
| 870 // Create complex paint that the bounding box computation code can't |
| 871 // optimize away |
| 872 SkScalar blueToRedMatrix[20] = { 0 }; |
| 873 blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; |
| 874 SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueTo
RedMatrix)); |
| 875 SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blue
ToRed.get())); |
| 876 |
| 877 SkPaint complexPaint; |
| 878 complexPaint.setImageFilter(filter); |
| 879 |
869 SkAutoTUnref<SkPicture> pict, child; | 880 SkAutoTUnref<SkPicture> pict, child; |
870 | 881 |
871 { | 882 { |
872 SkPictureRecorder recorder; | 883 SkPictureRecorder recorder; |
873 | 884 |
874 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntTo
Scalar(kHeight)); | 885 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntTo
Scalar(kHeight)); |
875 | 886 |
876 c->saveLayer(NULL, NULL); | 887 c->saveLayer(NULL, &complexPaint); |
877 c->restore(); | 888 c->restore(); |
878 | 889 |
879 child.reset(recorder.endRecording()); | 890 child.reset(recorder.endRecording()); |
880 } | 891 } |
881 | 892 |
882 // create a picture with the structure: | 893 // create a picture with the structure: |
883 // 1) | 894 // 1) |
884 // SaveLayer | 895 // SaveLayer |
885 // Restore | 896 // Restore |
886 // 2) | 897 // 2) |
(...skipping 12 matching lines...) Expand all Loading... |
899 // 5) | 910 // 5) |
900 // SaveLayer | 911 // SaveLayer |
901 // DrawPicture with Matrix & Paint (with SaveLayer/Restore pair
) | 912 // DrawPicture with Matrix & Paint (with SaveLayer/Restore pair
) |
902 // Restore | 913 // Restore |
903 { | 914 { |
904 SkPictureRecorder recorder; | 915 SkPictureRecorder recorder; |
905 | 916 |
906 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), | 917 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), |
907 SkIntToScalar(kHeight)); | 918 SkIntToScalar(kHeight)); |
908 // 1) | 919 // 1) |
909 c->saveLayer(NULL, NULL); // layer #0 | 920 c->saveLayer(NULL, &complexPaint); // layer #0 |
910 c->restore(); | 921 c->restore(); |
911 | 922 |
912 // 2) | 923 // 2) |
913 c->saveLayer(NULL, NULL); // layer #1 | 924 c->saveLayer(NULL, NULL); // layer #1 |
914 c->translate(kWidth/2.0f, kHeight/2.0f); | 925 c->translate(kWidth/2.0f, kHeight/2.0f); |
915 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); | 926 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); |
916 c->saveLayer(&r, NULL); // layer #2 | 927 c->saveLayer(&r, &complexPaint); // layer #2 |
917 c->restore(); | 928 c->restore(); |
918 c->restore(); | 929 c->restore(); |
919 | 930 |
920 // 3) | 931 // 3) |
921 { | 932 { |
922 SkPaint p; | 933 c->saveLayer(NULL, &complexPaint); // layer #3 |
923 p.setColor(SK_ColorRED); | |
924 c->saveLayer(NULL, &p); // layer #3 | |
925 c->restore(); | 934 c->restore(); |
926 } | 935 } |
927 | 936 |
928 SkPaint layerPaint; | 937 SkPaint layerPaint; |
929 layerPaint.setColor(SK_ColorRED); // Non-alpha only to avoid SaveLa
yerDrawRestoreNooper | 938 layerPaint.setColor(SK_ColorRED); // Non-alpha only to avoid SaveLa
yerDrawRestoreNooper |
930 // 4) | 939 // 4) |
931 { | 940 { |
932 c->saveLayer(NULL, &layerPaint); // layer #4 | 941 c->saveLayer(NULL, &layerPaint); // layer #4 |
933 c->drawPicture(child); // layer #5 inside picture | 942 c->drawPicture(child); // layer #5 inside picture |
934 c->restore(); | 943 c->restore(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 // The parent/child layers appear in reverse order | 988 // The parent/child layers appear in reverse order |
980 const GrAccelData::SaveLayerInfo& info6 = gpuData->saveLayerInfo(7); | 989 const GrAccelData::SaveLayerInfo& info6 = gpuData->saveLayerInfo(7); |
981 const GrAccelData::SaveLayerInfo& info7 = gpuData->saveLayerInfo(6); | 990 const GrAccelData::SaveLayerInfo& info7 = gpuData->saveLayerInfo(6); |
982 | 991 |
983 REPORTER_ASSERT(reporter, NULL == info0.fPicture); | 992 REPORTER_ASSERT(reporter, NULL == info0.fPicture); |
984 REPORTER_ASSERT(reporter, kWidth == info0.fBounds.width() && | 993 REPORTER_ASSERT(reporter, kWidth == info0.fBounds.width() && |
985 kHeight == info0.fBounds.height()); | 994 kHeight == info0.fBounds.height()); |
986 REPORTER_ASSERT(reporter, info0.fLocalMat.isIdentity()); | 995 REPORTER_ASSERT(reporter, info0.fLocalMat.isIdentity()); |
987 REPORTER_ASSERT(reporter, info0.fPreMat.isIdentity()); | 996 REPORTER_ASSERT(reporter, info0.fPreMat.isIdentity()); |
988 REPORTER_ASSERT(reporter, 0 == info0.fBounds.fLeft && 0 == info0.fBo
unds.fTop); | 997 REPORTER_ASSERT(reporter, 0 == info0.fBounds.fLeft && 0 == info0.fBo
unds.fTop); |
989 REPORTER_ASSERT(reporter, NULL == info0.fPaint); | 998 REPORTER_ASSERT(reporter, NULL != info0.fPaint); |
990 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayer
s); | 999 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayer
s); |
991 | 1000 |
992 REPORTER_ASSERT(reporter, NULL == info1.fPicture); | 1001 REPORTER_ASSERT(reporter, NULL == info1.fPicture); |
993 REPORTER_ASSERT(reporter, kWidth == info1.fBounds.width() && | 1002 REPORTER_ASSERT(reporter, kWidth == info1.fBounds.width() && |
994 kHeight == info1.fBounds.height()); | 1003 kHeight == info1.fBounds.height()); |
995 REPORTER_ASSERT(reporter, info1.fLocalMat.isIdentity()); | 1004 REPORTER_ASSERT(reporter, info1.fLocalMat.isIdentity()); |
996 REPORTER_ASSERT(reporter, info1.fPreMat.isIdentity()); | 1005 REPORTER_ASSERT(reporter, info1.fPreMat.isIdentity()); |
997 REPORTER_ASSERT(reporter, 0 == info1.fBounds.fLeft && 0 == info1.fBo
unds.fTop); | 1006 REPORTER_ASSERT(reporter, 0 == info1.fBounds.fLeft && 0 == info1.fBo
unds.fTop); |
998 REPORTER_ASSERT(reporter, NULL == info1.fPaint); | 1007 REPORTER_ASSERT(reporter, NULL == info1.fPaint); |
999 REPORTER_ASSERT(reporter, !info1.fIsNested && | 1008 REPORTER_ASSERT(reporter, !info1.fIsNested && |
1000 info1.fHasNestedLayers); // has a nested S
L | 1009 info1.fHasNestedLayers); // has a nested S
L |
1001 | 1010 |
1002 REPORTER_ASSERT(reporter, NULL == info2.fPicture); | 1011 REPORTER_ASSERT(reporter, NULL == info2.fPicture); |
1003 REPORTER_ASSERT(reporter, kWidth / 2 == info2.fBounds.width() && | 1012 REPORTER_ASSERT(reporter, kWidth / 2 == info2.fBounds.width() && |
1004 kHeight / 2 == info2.fBounds.height()); //
bound reduces size | 1013 kHeight / 2 == info2.fBounds.height()); //
bound reduces size |
1005 REPORTER_ASSERT(reporter, !info2.fLocalMat.isIdentity()); | 1014 REPORTER_ASSERT(reporter, !info2.fLocalMat.isIdentity()); |
1006 REPORTER_ASSERT(reporter, info2.fPreMat.isIdentity()); | 1015 REPORTER_ASSERT(reporter, info2.fPreMat.isIdentity()); |
1007 REPORTER_ASSERT(reporter, kWidth / 2 == info2.fBounds.fLeft && //
translated | 1016 REPORTER_ASSERT(reporter, kWidth / 2 == info2.fBounds.fLeft && //
translated |
1008 kHeight / 2 == info2.fBounds.fTop); | 1017 kHeight / 2 == info2.fBounds.fTop); |
1009 REPORTER_ASSERT(reporter, NULL == info1.fPaint); | 1018 REPORTER_ASSERT(reporter, NULL != info2.fPaint); |
1010 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers
); // is nested | 1019 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers
); // is nested |
1011 | 1020 |
1012 REPORTER_ASSERT(reporter, NULL == info3.fPicture); | 1021 REPORTER_ASSERT(reporter, NULL == info3.fPicture); |
1013 REPORTER_ASSERT(reporter, kWidth == info3.fBounds.width() && | 1022 REPORTER_ASSERT(reporter, kWidth == info3.fBounds.width() && |
1014 kHeight == info3.fBounds.height()); | 1023 kHeight == info3.fBounds.height()); |
1015 REPORTER_ASSERT(reporter, info3.fLocalMat.isIdentity()); | 1024 REPORTER_ASSERT(reporter, info3.fLocalMat.isIdentity()); |
1016 REPORTER_ASSERT(reporter, info3.fPreMat.isIdentity()); | 1025 REPORTER_ASSERT(reporter, info3.fPreMat.isIdentity()); |
1017 REPORTER_ASSERT(reporter, 0 == info3.fBounds.fLeft && 0 == info3.fBo
unds.fTop); | 1026 REPORTER_ASSERT(reporter, 0 == info3.fBounds.fLeft && 0 == info3.fBo
unds.fTop); |
1018 REPORTER_ASSERT(reporter, info3.fPaint); | 1027 REPORTER_ASSERT(reporter, info3.fPaint); |
1019 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayer
s); | 1028 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayer
s); |
1020 | 1029 |
1021 REPORTER_ASSERT(reporter, NULL == info4.fPicture); | 1030 REPORTER_ASSERT(reporter, NULL == info4.fPicture); |
1022 REPORTER_ASSERT(reporter, kWidth == info4.fBounds.width() && | 1031 REPORTER_ASSERT(reporter, kWidth == info4.fBounds.width() && |
1023 kHeight == info4.fBounds.height()); | 1032 kHeight == info4.fBounds.height()); |
1024 REPORTER_ASSERT(reporter, 0 == info4.fBounds.fLeft && 0 == info4.fBo
unds.fTop); | 1033 REPORTER_ASSERT(reporter, 0 == info4.fBounds.fLeft && 0 == info4.fBo
unds.fTop); |
1025 REPORTER_ASSERT(reporter, info4.fLocalMat.isIdentity()); | 1034 REPORTER_ASSERT(reporter, info4.fLocalMat.isIdentity()); |
1026 REPORTER_ASSERT(reporter, info4.fPreMat.isIdentity()); | 1035 REPORTER_ASSERT(reporter, info4.fPreMat.isIdentity()); |
1027 REPORTER_ASSERT(reporter, info4.fPaint); | 1036 REPORTER_ASSERT(reporter, info4.fPaint); |
1028 REPORTER_ASSERT(reporter, !info4.fIsNested && | 1037 REPORTER_ASSERT(reporter, !info4.fIsNested && |
1029 info4.fHasNestedLayers); // has a nested S
L | 1038 info4.fHasNestedLayers); // has a nested S
L |
1030 | 1039 |
1031 REPORTER_ASSERT(reporter, child == info5.fPicture); // in a child pi
cture | 1040 REPORTER_ASSERT(reporter, child == info5.fPicture); // in a child pi
cture |
1032 REPORTER_ASSERT(reporter, kWidth == info5.fBounds.width() && | 1041 REPORTER_ASSERT(reporter, kWidth == info5.fBounds.width() && |
1033 kHeight == info5.fBounds.height()); | 1042 kHeight == info5.fBounds.height()); |
1034 REPORTER_ASSERT(reporter, 0 == info5.fBounds.fLeft && 0 == info5.fBo
unds.fTop); | 1043 REPORTER_ASSERT(reporter, 0 == info5.fBounds.fLeft && 0 == info5.fBo
unds.fTop); |
1035 REPORTER_ASSERT(reporter, info5.fLocalMat.isIdentity()); | 1044 REPORTER_ASSERT(reporter, info5.fLocalMat.isIdentity()); |
1036 REPORTER_ASSERT(reporter, info5.fPreMat.isIdentity()); | 1045 REPORTER_ASSERT(reporter, info5.fPreMat.isIdentity()); |
1037 REPORTER_ASSERT(reporter, NULL == info5.fPaint); | 1046 REPORTER_ASSERT(reporter, NULL != info5.fPaint); |
1038 REPORTER_ASSERT(reporter, info5.fIsNested && !info5.fHasNestedLayers
); // is nested | 1047 REPORTER_ASSERT(reporter, info5.fIsNested && !info5.fHasNestedLayers
); // is nested |
1039 | 1048 |
1040 REPORTER_ASSERT(reporter, NULL == info6.fPicture); | 1049 REPORTER_ASSERT(reporter, NULL == info6.fPicture); |
1041 REPORTER_ASSERT(reporter, kWidth == info6.fBounds.width() && | 1050 REPORTER_ASSERT(reporter, kWidth-10 == info6.fBounds.width() && |
1042 kHeight == info6.fBounds.height()); | 1051 kHeight-10 == info6.fBounds.height()); |
1043 REPORTER_ASSERT(reporter, 0 == info6.fBounds.fLeft && 0 == info6.fBo
unds.fTop); | 1052 REPORTER_ASSERT(reporter, 10 == info6.fBounds.fLeft && 10 == info6.f
Bounds.fTop); |
1044 REPORTER_ASSERT(reporter, info6.fLocalMat.isIdentity()); | 1053 REPORTER_ASSERT(reporter, info6.fLocalMat.isIdentity()); |
1045 REPORTER_ASSERT(reporter, info6.fPreMat.isIdentity()); | 1054 REPORTER_ASSERT(reporter, info6.fPreMat.isIdentity()); |
1046 REPORTER_ASSERT(reporter, info6.fPaint); | 1055 REPORTER_ASSERT(reporter, info6.fPaint); |
1047 REPORTER_ASSERT(reporter, !info6.fIsNested && | 1056 REPORTER_ASSERT(reporter, !info6.fIsNested && |
1048 info6.fHasNestedLayers); // has a nested S
L | 1057 info6.fHasNestedLayers); // has a nested S
L |
1049 | 1058 |
1050 REPORTER_ASSERT(reporter, child == info7.fPicture); // in a child pi
cture | 1059 REPORTER_ASSERT(reporter, child == info7.fPicture); // in a child pi
cture |
1051 REPORTER_ASSERT(reporter, kWidth == info7.fBounds.width() && | 1060 REPORTER_ASSERT(reporter, kWidth == info7.fBounds.width() && |
1052 kHeight == info7.fBounds.height()); | 1061 kHeight == info7.fBounds.height()); |
1053 REPORTER_ASSERT(reporter, 0 == info7.fBounds.fLeft && 0 == info7.fBo
unds.fTop); | 1062 REPORTER_ASSERT(reporter, 0 == info7.fBounds.fLeft && 0 == info7.fBo
unds.fTop); |
1054 REPORTER_ASSERT(reporter, info7.fLocalMat.isIdentity()); | 1063 REPORTER_ASSERT(reporter, info7.fLocalMat.isIdentity()); |
1055 REPORTER_ASSERT(reporter, info7.fPreMat.isIdentity()); | 1064 REPORTER_ASSERT(reporter, info7.fPreMat.isIdentity()); |
1056 REPORTER_ASSERT(reporter, NULL == info7.fPaint); | 1065 REPORTER_ASSERT(reporter, NULL != info7.fPaint); |
1057 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers
); // is nested | 1066 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers
); // is nested |
1058 } | 1067 } |
1059 } | 1068 } |
1060 } | 1069 } |
1061 | 1070 |
1062 #endif | 1071 #endif |
1063 | 1072 |
1064 static void test_has_text(skiatest::Reporter* reporter) { | 1073 static void test_has_text(skiatest::Reporter* reporter) { |
1065 SkPictureRecorder recorder; | 1074 SkPictureRecorder recorder; |
1066 | 1075 |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1878 | 1887 |
1879 // The picture shares the immutable pixels but copies the mutable ones. | 1888 // The picture shares the immutable pixels but copies the mutable ones. |
1880 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1889 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1881 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1890 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
1882 | 1891 |
1883 // When the picture goes away, it's just our bitmaps holding the refs. | 1892 // When the picture goes away, it's just our bitmaps holding the refs. |
1884 pic.reset(NULL); | 1893 pic.reset(NULL); |
1885 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1894 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1886 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1895 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1887 } | 1896 } |
OLD | NEW |