| 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 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 } | 875 } |
| 876 | 876 |
| 877 static const int kWidth = 100; | 877 static const int kWidth = 100; |
| 878 static const int kHeight = 100; | 878 static const int kHeight = 100; |
| 879 | 879 |
| 880 SkAutoTUnref<SkPicture> pict, child; | 880 SkAutoTUnref<SkPicture> pict, child; |
| 881 | 881 |
| 882 { | 882 { |
| 883 SkPictureRecorder recorder; | 883 SkPictureRecorder recorder; |
| 884 | 884 |
| 885 SkCanvas* c = recorder.beginRecording(kWidth, kHeight); | 885 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntTo
Scalar(kHeight)); |
| 886 | 886 |
| 887 c->saveLayer(NULL, NULL); | 887 c->saveLayer(NULL, NULL); |
| 888 c->restore(); | 888 c->restore(); |
| 889 | 889 |
| 890 child.reset(recorder.endRecording()); | 890 child.reset(recorder.endRecording()); |
| 891 } | 891 } |
| 892 | 892 |
| 893 // create a picture with the structure: | 893 // create a picture with the structure: |
| 894 // 1) | 894 // 1) |
| 895 // SaveLayer | 895 // SaveLayer |
| (...skipping 11 matching lines...) Expand all 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(kWidth, kHeight); | 917 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), |
| 918 SkIntToScalar(kHeight)); |
| 918 // 1) | 919 // 1) |
| 919 c->saveLayer(NULL, NULL); // layer #0 | 920 c->saveLayer(NULL, NULL); // layer #0 |
| 920 c->restore(); | 921 c->restore(); |
| 921 | 922 |
| 922 // 2) | 923 // 2) |
| 923 c->saveLayer(NULL, NULL); // layer #1 | 924 c->saveLayer(NULL, NULL); // layer #1 |
| 924 c->translate(kWidth/2.0f, kHeight/2.0f); | 925 c->translate(kWidth/2.0f, kHeight/2.0f); |
| 925 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); | 926 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); |
| 926 c->saveLayer(&r, NULL); // layer #2 | 927 c->saveLayer(&r, NULL); // layer #2 |
| 927 c->restore(); | 928 c->restore(); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 unsigned int fSaveCount; | 1181 unsigned int fSaveCount; |
| 1181 unsigned int fSaveLayerCount; | 1182 unsigned int fSaveLayerCount; |
| 1182 unsigned int fRestoreCount; | 1183 unsigned int fRestoreCount; |
| 1183 | 1184 |
| 1184 typedef SkCanvas INHERITED; | 1185 typedef SkCanvas INHERITED; |
| 1185 }; | 1186 }; |
| 1186 | 1187 |
| 1187 void check_save_state(skiatest::Reporter* reporter, SkPicture* picture, | 1188 void check_save_state(skiatest::Reporter* reporter, SkPicture* picture, |
| 1188 unsigned int numSaves, unsigned int numSaveLayers, | 1189 unsigned int numSaves, unsigned int numSaveLayers, |
| 1189 unsigned int numRestores) { | 1190 unsigned int numRestores) { |
| 1190 SaveCountingCanvas canvas(picture->width(), picture->height()); | 1191 SaveCountingCanvas canvas(SkScalarCeilToInt(picture->cullRect().width()), |
| 1192 SkScalarCeilToInt(picture->cullRect().height())); |
| 1191 | 1193 |
| 1192 picture->draw(&canvas); | 1194 picture->draw(&canvas); |
| 1193 | 1195 |
| 1194 REPORTER_ASSERT(reporter, numSaves == canvas.getSaveCount()); | 1196 REPORTER_ASSERT(reporter, numSaves == canvas.getSaveCount()); |
| 1195 REPORTER_ASSERT(reporter, numSaveLayers == canvas.getSaveLayerCount()); | 1197 REPORTER_ASSERT(reporter, numSaveLayers == canvas.getSaveLayerCount()); |
| 1196 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); | 1198 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); |
| 1197 } | 1199 } |
| 1198 | 1200 |
| 1199 // This class exists so SkPicture can friend it and give it access to | 1201 // This class exists so SkPicture can friend it and give it access to |
| 1200 // the 'partialReplay' method. | 1202 // the 'partialReplay' method. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 canvas.drawPicture(picture); | 1438 canvas.drawPicture(picture); |
| 1437 } | 1439 } |
| 1438 #endif | 1440 #endif |
| 1439 | 1441 |
| 1440 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { | 1442 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { |
| 1441 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | 1443 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
| 1442 } | 1444 } |
| 1443 | 1445 |
| 1444 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 1446 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { |
| 1445 SkPictureRecorder recorder; | 1447 SkPictureRecorder recorder; |
| 1446 SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height()); | 1448 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), |
| 1449 SkIntToScalar(bitmap.height())); |
| 1447 canvas->drawBitmap(bitmap, 0, 0); | 1450 canvas->drawBitmap(bitmap, 0, 0); |
| 1448 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1451 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 1449 | 1452 |
| 1450 SkDynamicMemoryWStream wStream; | 1453 SkDynamicMemoryWStream wStream; |
| 1451 picture->serialize(&wStream, &encode_bitmap_to_data); | 1454 picture->serialize(&wStream, &encode_bitmap_to_data); |
| 1452 return wStream.copyToData(); | 1455 return wStream.copyToData(); |
| 1453 } | 1456 } |
| 1454 | 1457 |
| 1455 struct ErrorContext { | 1458 struct ErrorContext { |
| 1456 int fErrors; | 1459 int fErrors; |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 | 1941 |
| 1939 // The picture shares the immutable pixels but copies the mutable ones. | 1942 // The picture shares the immutable pixels but copies the mutable ones. |
| 1940 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1943 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1941 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1944 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
| 1942 | 1945 |
| 1943 // When the picture goes away, it's just our bitmaps holding the refs. | 1946 // When the picture goes away, it's just our bitmaps holding the refs. |
| 1944 pic.reset(NULL); | 1947 pic.reset(NULL); |
| 1945 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1948 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1946 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1949 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
| 1947 } | 1950 } |
| OLD | NEW |