| 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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 // SaveLayer | 907 // SaveLayer |
| 908 // DrawPicture (which has a SaveLayer/Restore pair) | 908 // DrawPicture (which has a SaveLayer/Restore pair) |
| 909 // Restore | 909 // Restore |
| 910 // 5) | 910 // 5) |
| 911 // SaveLayer | 911 // SaveLayer |
| 912 // DrawPicture with Matrix & Paint (with SaveLayer/Restore pair
) | 912 // DrawPicture with Matrix & Paint (with SaveLayer/Restore pair
) |
| 913 // Restore | 913 // Restore |
| 914 { | 914 { |
| 915 SkPictureRecorder recorder; | 915 SkPictureRecorder recorder; |
| 916 | 916 |
| 917 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), | 917 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), |
| 918 SkIntToScalar(kHeight)); | 918 SkIntToScalar(kHeight)); |
| 919 // 1) | 919 // 1) |
| 920 c->saveLayer(NULL, NULL); // layer #0 | 920 c->saveLayer(NULL, NULL); // layer #0 |
| 921 c->restore(); | 921 c->restore(); |
| 922 | 922 |
| 923 // 2) | 923 // 2) |
| 924 c->saveLayer(NULL, NULL); // layer #1 | 924 c->saveLayer(NULL, NULL); // layer #1 |
| 925 c->translate(kWidth/2.0f, kHeight/2.0f); | 925 c->translate(kWidth/2.0f, kHeight/2.0f); |
| 926 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); | 926 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); |
| 927 c->saveLayer(&r, NULL); // layer #2 | 927 c->saveLayer(&r, NULL); // layer #2 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 // The parent/child layers appear in reverse order | 983 // The parent/child layers appear in reverse order |
| 984 const GrAccelData::SaveLayerInfo& info4 = gpuData->saveLayerInfo(5); | 984 const GrAccelData::SaveLayerInfo& info4 = gpuData->saveLayerInfo(5); |
| 985 const GrAccelData::SaveLayerInfo& info5 = gpuData->saveLayerInfo(4); | 985 const GrAccelData::SaveLayerInfo& info5 = gpuData->saveLayerInfo(4); |
| 986 | 986 |
| 987 // The parent/child layers appear in reverse order | 987 // The parent/child layers appear in reverse order |
| 988 const GrAccelData::SaveLayerInfo& info6 = gpuData->saveLayerInfo(7); | 988 const GrAccelData::SaveLayerInfo& info6 = gpuData->saveLayerInfo(7); |
| 989 const GrAccelData::SaveLayerInfo& info7 = gpuData->saveLayerInfo(6); | 989 const GrAccelData::SaveLayerInfo& info7 = gpuData->saveLayerInfo(6); |
| 990 | 990 |
| 991 REPORTER_ASSERT(reporter, info0.fValid); | 991 REPORTER_ASSERT(reporter, info0.fValid); |
| 992 REPORTER_ASSERT(reporter, pict->uniqueID() == info0.fPictureID); | 992 REPORTER_ASSERT(reporter, pict->uniqueID() == info0.fPictureID); |
| 993 REPORTER_ASSERT(reporter, kWidth == info0.fSize.fWidth && | 993 REPORTER_ASSERT(reporter, kWidth == info0.fSize.fWidth && |
| 994 kHeight == info0.fSize.fHeight); | 994 kHeight == info0.fSize.fHeight); |
| 995 REPORTER_ASSERT(reporter, info0.fOriginXform.isIdentity()); | 995 REPORTER_ASSERT(reporter, info0.fOriginXform.isIdentity()); |
| 996 REPORTER_ASSERT(reporter, 0 == info0.fOffset.fX && 0 == info0.fOffse
t.fY); | 996 REPORTER_ASSERT(reporter, 0 == info0.fOffset.fX && 0 == info0.fOffse
t.fY); |
| 997 REPORTER_ASSERT(reporter, NULL == info0.fPaint); | 997 REPORTER_ASSERT(reporter, NULL == info0.fPaint); |
| 998 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayer
s); | 998 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayer
s); |
| 999 | 999 |
| 1000 REPORTER_ASSERT(reporter, info1.fValid); | 1000 REPORTER_ASSERT(reporter, info1.fValid); |
| 1001 REPORTER_ASSERT(reporter, pict->uniqueID() == info1.fPictureID); | 1001 REPORTER_ASSERT(reporter, pict->uniqueID() == info1.fPictureID); |
| 1002 REPORTER_ASSERT(reporter, kWidth == info1.fSize.fWidth && | 1002 REPORTER_ASSERT(reporter, kWidth == info1.fSize.fWidth && |
| 1003 kHeight == info1.fSize.fHeight); | 1003 kHeight == info1.fSize.fHeight); |
| 1004 REPORTER_ASSERT(reporter, info1.fOriginXform.isIdentity()); | 1004 REPORTER_ASSERT(reporter, info1.fOriginXform.isIdentity()); |
| 1005 REPORTER_ASSERT(reporter, 0 == info1.fOffset.fX && 0 == info1.fOffse
t.fY); | 1005 REPORTER_ASSERT(reporter, 0 == info1.fOffset.fX && 0 == info1.fOffse
t.fY); |
| 1006 REPORTER_ASSERT(reporter, NULL == info1.fPaint); | 1006 REPORTER_ASSERT(reporter, NULL == info1.fPaint); |
| 1007 REPORTER_ASSERT(reporter, !info1.fIsNested && | 1007 REPORTER_ASSERT(reporter, !info1.fIsNested && |
| 1008 info1.fHasNestedLayers); // has a nested S
L | 1008 info1.fHasNestedLayers); // has a nested S
L |
| 1009 | 1009 |
| 1010 REPORTER_ASSERT(reporter, info2.fValid); | 1010 REPORTER_ASSERT(reporter, info2.fValid); |
| 1011 REPORTER_ASSERT(reporter, pict->uniqueID() == info2.fPictureID); | 1011 REPORTER_ASSERT(reporter, pict->uniqueID() == info2.fPictureID); |
| 1012 REPORTER_ASSERT(reporter, kWidth / 2 == info2.fSize.fWidth && | 1012 REPORTER_ASSERT(reporter, kWidth / 2 == info2.fSize.fWidth && |
| 1013 kHeight/2 == info2.fSize.fHeight); // boun
d reduces size | 1013 kHeight/2 == info2.fSize.fHeight); // boun
d reduces size |
| 1014 REPORTER_ASSERT(reporter, info2.fOriginXform.isIdentity()); | 1014 REPORTER_ASSERT(reporter, info2.fOriginXform.isIdentity()); |
| 1015 REPORTER_ASSERT(reporter, kWidth/2 == info2.fOffset.fX && // trans
lated | 1015 REPORTER_ASSERT(reporter, kWidth/2 == info2.fOffset.fX && // trans
lated |
| 1016 kHeight/2 == info2.fOffset.fY); | 1016 kHeight/2 == info2.fOffset.fY); |
| 1017 REPORTER_ASSERT(reporter, NULL == info1.fPaint); | 1017 REPORTER_ASSERT(reporter, NULL == info1.fPaint); |
| 1018 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers
); // is nested | 1018 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers
); // is nested |
| 1019 | 1019 |
| 1020 REPORTER_ASSERT(reporter, info3.fValid); | 1020 REPORTER_ASSERT(reporter, info3.fValid); |
| 1021 REPORTER_ASSERT(reporter, pict->uniqueID() == info3.fPictureID); | 1021 REPORTER_ASSERT(reporter, pict->uniqueID() == info3.fPictureID); |
| 1022 REPORTER_ASSERT(reporter, kWidth == info3.fSize.fWidth && | 1022 REPORTER_ASSERT(reporter, kWidth == info3.fSize.fWidth && |
| 1023 kHeight == info3.fSize.fHeight); | 1023 kHeight == info3.fSize.fHeight); |
| 1024 REPORTER_ASSERT(reporter, info3.fOriginXform.isIdentity()); | 1024 REPORTER_ASSERT(reporter, info3.fOriginXform.isIdentity()); |
| 1025 REPORTER_ASSERT(reporter, 0 == info3.fOffset.fX && 0 == info3.fOffse
t.fY); | 1025 REPORTER_ASSERT(reporter, 0 == info3.fOffset.fX && 0 == info3.fOffse
t.fY); |
| 1026 REPORTER_ASSERT(reporter, NULL != info3.fPaint); | 1026 REPORTER_ASSERT(reporter, NULL != info3.fPaint); |
| 1027 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayer
s); | 1027 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayer
s); |
| 1028 | 1028 |
| 1029 REPORTER_ASSERT(reporter, info4.fValid); | 1029 REPORTER_ASSERT(reporter, info4.fValid); |
| 1030 REPORTER_ASSERT(reporter, pict->uniqueID() == info4.fPictureID); | 1030 REPORTER_ASSERT(reporter, pict->uniqueID() == info4.fPictureID); |
| 1031 REPORTER_ASSERT(reporter, kWidth == info4.fSize.fWidth && | 1031 REPORTER_ASSERT(reporter, kWidth == info4.fSize.fWidth && |
| 1032 kHeight == info4.fSize.fHeight); | 1032 kHeight == info4.fSize.fHeight); |
| 1033 REPORTER_ASSERT(reporter, 0 == info4.fOffset.fX && 0 == info4.fOffse
t.fY); | 1033 REPORTER_ASSERT(reporter, 0 == info4.fOffset.fX && 0 == info4.fOffse
t.fY); |
| 1034 REPORTER_ASSERT(reporter, info4.fOriginXform.isIdentity()); | 1034 REPORTER_ASSERT(reporter, info4.fOriginXform.isIdentity()); |
| 1035 REPORTER_ASSERT(reporter, NULL == info4.fPaint); | 1035 REPORTER_ASSERT(reporter, NULL == info4.fPaint); |
| 1036 REPORTER_ASSERT(reporter, !info4.fIsNested && | 1036 REPORTER_ASSERT(reporter, !info4.fIsNested && |
| 1037 info4.fHasNestedLayers); // has a nested S
L | 1037 info4.fHasNestedLayers); // has a nested S
L |
| 1038 | 1038 |
| 1039 REPORTER_ASSERT(reporter, info5.fValid); | 1039 REPORTER_ASSERT(reporter, info5.fValid); |
| 1040 REPORTER_ASSERT(reporter, child->uniqueID() == info5.fPictureID); //
in a child picture | 1040 REPORTER_ASSERT(reporter, child->uniqueID() == info5.fPictureID); //
in a child picture |
| 1041 REPORTER_ASSERT(reporter, kWidth == info5.fSize.fWidth && | 1041 REPORTER_ASSERT(reporter, kWidth == info5.fSize.fWidth && |
| 1042 kHeight == info5.fSize.fHeight); | 1042 kHeight == info5.fSize.fHeight); |
| 1043 REPORTER_ASSERT(reporter, 0 == info5.fOffset.fX && 0 == info5.fOffse
t.fY); | 1043 REPORTER_ASSERT(reporter, 0 == info5.fOffset.fX && 0 == info5.fOffse
t.fY); |
| 1044 REPORTER_ASSERT(reporter, info5.fOriginXform.isIdentity()); | 1044 REPORTER_ASSERT(reporter, info5.fOriginXform.isIdentity()); |
| 1045 REPORTER_ASSERT(reporter, NULL == info5.fPaint); | 1045 REPORTER_ASSERT(reporter, NULL == info5.fPaint); |
| 1046 REPORTER_ASSERT(reporter, info5.fIsNested && !info5.fHasNestedLayers
); // is nested | 1046 REPORTER_ASSERT(reporter, info5.fIsNested && !info5.fHasNestedLayers
); // is nested |
| 1047 | 1047 |
| 1048 REPORTER_ASSERT(reporter, info6.fValid); | 1048 REPORTER_ASSERT(reporter, info6.fValid); |
| 1049 REPORTER_ASSERT(reporter, pict->uniqueID() == info6.fPictureID); | 1049 REPORTER_ASSERT(reporter, pict->uniqueID() == info6.fPictureID); |
| 1050 REPORTER_ASSERT(reporter, kWidth == info6.fSize.fWidth && | 1050 REPORTER_ASSERT(reporter, kWidth == info6.fSize.fWidth && |
| 1051 kHeight == info6.fSize.fHeight); | 1051 kHeight == info6.fSize.fHeight); |
| 1052 REPORTER_ASSERT(reporter, 0 == info6.fOffset.fX && 0 == info6.fOffse
t.fY); | 1052 REPORTER_ASSERT(reporter, 0 == info6.fOffset.fX && 0 == info6.fOffse
t.fY); |
| 1053 REPORTER_ASSERT(reporter, info6.fOriginXform.isIdentity()); | 1053 REPORTER_ASSERT(reporter, info6.fOriginXform.isIdentity()); |
| 1054 REPORTER_ASSERT(reporter, NULL == info6.fPaint); | 1054 REPORTER_ASSERT(reporter, NULL == info6.fPaint); |
| 1055 REPORTER_ASSERT(reporter, !info6.fIsNested && | 1055 REPORTER_ASSERT(reporter, !info6.fIsNested && |
| 1056 info6.fHasNestedLayers); // has a nested S
L | 1056 info6.fHasNestedLayers); // has a nested S
L |
| 1057 | 1057 |
| 1058 REPORTER_ASSERT(reporter, info7.fValid); | 1058 REPORTER_ASSERT(reporter, info7.fValid); |
| 1059 REPORTER_ASSERT(reporter, child->uniqueID() == info7.fPictureID); //
in a child picture | 1059 REPORTER_ASSERT(reporter, child->uniqueID() == info7.fPictureID); //
in a child picture |
| 1060 REPORTER_ASSERT(reporter, kWidth == info7.fSize.fWidth && | 1060 REPORTER_ASSERT(reporter, kWidth == info7.fSize.fWidth && |
| 1061 kHeight == info7.fSize.fHeight); | 1061 kHeight == info7.fSize.fHeight); |
| 1062 REPORTER_ASSERT(reporter, 0 == info7.fOffset.fX && 0 == info7.fOffse
t.fY); | 1062 REPORTER_ASSERT(reporter, 0 == info7.fOffset.fX && 0 == info7.fOffse
t.fY); |
| 1063 REPORTER_ASSERT(reporter, info7.fOriginXform.isIdentity()); | 1063 REPORTER_ASSERT(reporter, info7.fOriginXform.isIdentity()); |
| 1064 REPORTER_ASSERT(reporter, NULL == info7.fPaint); | 1064 REPORTER_ASSERT(reporter, NULL == info7.fPaint); |
| 1065 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers
); // is nested | 1065 REPORTER_ASSERT(reporter, info7.fIsNested && !info7.fHasNestedLayers
); // is nested |
| 1066 } | 1066 } |
| 1067 } | 1067 } |
| 1068 } | 1068 } |
| 1069 | 1069 |
| 1070 #endif | 1070 #endif |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 unsigned int fSaveCount; | 1181 unsigned int fSaveCount; |
| 1182 unsigned int fSaveLayerCount; | 1182 unsigned int fSaveLayerCount; |
| 1183 unsigned int fRestoreCount; | 1183 unsigned int fRestoreCount; |
| 1184 | 1184 |
| 1185 typedef SkCanvas INHERITED; | 1185 typedef SkCanvas INHERITED; |
| 1186 }; | 1186 }; |
| 1187 | 1187 |
| 1188 void check_save_state(skiatest::Reporter* reporter, SkPicture* picture, | 1188 void check_save_state(skiatest::Reporter* reporter, SkPicture* picture, |
| 1189 unsigned int numSaves, unsigned int numSaveLayers, | 1189 unsigned int numSaves, unsigned int numSaveLayers, |
| 1190 unsigned int numRestores) { | 1190 unsigned int numRestores) { |
| 1191 SaveCountingCanvas canvas(SkScalarCeilToInt(picture->cullRect().width()), | 1191 SaveCountingCanvas canvas(SkScalarCeilToInt(picture->cullRect().width()), |
| 1192 SkScalarCeilToInt(picture->cullRect().height())); | 1192 SkScalarCeilToInt(picture->cullRect().height())); |
| 1193 | 1193 |
| 1194 picture->playback(&canvas); | 1194 picture->playback(&canvas); |
| 1195 | 1195 |
| 1196 REPORTER_ASSERT(reporter, numSaves == canvas.getSaveCount()); | 1196 // Optimizations may have removed these, |
| 1197 REPORTER_ASSERT(reporter, numSaveLayers == canvas.getSaveLayerCount()); | 1197 // so expect to have seen no more than num{Saves,SaveLayers,Restores}. |
| 1198 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); | 1198 REPORTER_ASSERT(reporter, numSaves >= canvas.getSaveCount()); |
| 1199 REPORTER_ASSERT(reporter, numSaveLayers >= canvas.getSaveLayerCount()); |
| 1200 REPORTER_ASSERT(reporter, numRestores >= canvas.getRestoreCount()); |
| 1199 } | 1201 } |
| 1200 | 1202 |
| 1201 // This class exists so SkPicture can friend it and give it access to | 1203 // This class exists so SkPicture can friend it and give it access to |
| 1202 // the 'partialReplay' method. | 1204 // the 'partialReplay' method. |
| 1203 class SkPictureRecorderReplayTester { | 1205 class SkPictureRecorderReplayTester { |
| 1204 public: | 1206 public: |
| 1205 static SkPicture* Copy(SkPictureRecorder* recorder) { | 1207 static SkPicture* Copy(SkPictureRecorder* recorder) { |
| 1206 SkPictureRecorder recorder2; | 1208 SkPictureRecorder recorder2; |
| 1207 | 1209 |
| 1208 SkCanvas* canvas = recorder2.beginRecording(10, 10); | 1210 SkCanvas* canvas = recorder2.beginRecording(10, 10); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 canvas.drawPicture(picture); | 1440 canvas.drawPicture(picture); |
| 1439 } | 1441 } |
| 1440 #endif | 1442 #endif |
| 1441 | 1443 |
| 1442 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { | 1444 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { |
| 1443 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | 1445 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
| 1444 } | 1446 } |
| 1445 | 1447 |
| 1446 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 1448 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { |
| 1447 SkPictureRecorder recorder; | 1449 SkPictureRecorder recorder; |
| 1448 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), | 1450 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), |
| 1449 SkIntToScalar(bitmap.height())); | 1451 SkIntToScalar(bitmap.height())); |
| 1450 canvas->drawBitmap(bitmap, 0, 0); | 1452 canvas->drawBitmap(bitmap, 0, 0); |
| 1451 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1453 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 1452 | 1454 |
| 1453 SkDynamicMemoryWStream wStream; | 1455 SkDynamicMemoryWStream wStream; |
| 1454 picture->serialize(&wStream, &encode_bitmap_to_data); | 1456 picture->serialize(&wStream, &encode_bitmap_to_data); |
| 1455 return wStream.copyToData(); | 1457 return wStream.copyToData(); |
| 1456 } | 1458 } |
| 1457 | 1459 |
| 1458 struct ErrorContext { | 1460 struct ErrorContext { |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 | 1943 |
| 1942 // The picture shares the immutable pixels but copies the mutable ones. | 1944 // The picture shares the immutable pixels but copies the mutable ones. |
| 1943 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1945 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1944 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1946 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
| 1945 | 1947 |
| 1946 // When the picture goes away, it's just our bitmaps holding the refs. | 1948 // When the picture goes away, it's just our bitmaps holding the refs. |
| 1947 pic.reset(NULL); | 1949 pic.reset(NULL); |
| 1948 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1950 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1949 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1951 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
| 1950 } | 1952 } |
| OLD | NEW |