| 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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" | 
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" | 
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" | 
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 296     *usedPixRefs->append() = bm.pixelRef(); | 296     *usedPixRefs->append() = bm.pixelRef(); | 
| 297 } | 297 } | 
| 298 | 298 | 
| 299 // Return a picture with the bitmaps drawn at the specified positions. | 299 // Return a picture with the bitmaps drawn at the specified positions. | 
| 300 static SkPicture* record_bitmaps(const SkBitmap bm[], | 300 static SkPicture* record_bitmaps(const SkBitmap bm[], | 
| 301                                  const SkPoint pos[], | 301                                  const SkPoint pos[], | 
| 302                                  SkTDArray<SkPixelRef*> analytic[], | 302                                  SkTDArray<SkPixelRef*> analytic[], | 
| 303                                  int count, | 303                                  int count, | 
| 304                                  DrawBitmapProc proc) { | 304                                  DrawBitmapProc proc) { | 
| 305     SkPictureRecorder recorder; | 305     SkPictureRecorder recorder; | 
| 306     SkCanvas* canvas = recorder.beginRecording(1000, 1000); | 306     SkCanvas* canvas = recorder.beginRecording(1000, 1000, NULL, 0); | 
| 307     for (int i = 0; i < count; ++i) { | 307     for (int i = 0; i < count; ++i) { | 
| 308         analytic[i].rewind(); | 308         analytic[i].rewind(); | 
| 309         canvas->save(); | 309         canvas->save(); | 
| 310         SkRect clipRect = SkRect::MakeXYWH(pos[i].fX, pos[i].fY, | 310         SkRect clipRect = SkRect::MakeXYWH(pos[i].fX, pos[i].fY, | 
| 311                                            SkIntToScalar(bm[i].width()), | 311                                            SkIntToScalar(bm[i].width()), | 
| 312                                            SkIntToScalar(bm[i].height())); | 312                                            SkIntToScalar(bm[i].height())); | 
| 313         canvas->clipRect(clipRect, SkRegion::kIntersect_Op); | 313         canvas->clipRect(clipRect, SkRegion::kIntersect_Op); | 
| 314         proc(canvas, bm[i], bm[count+i], pos[i], &analytic[i]); | 314         proc(canvas, bm[i], bm[count+i], pos[i], &analytic[i]); | 
| 315         canvas->restore(); | 315         canvas->restore(); | 
| 316     } | 316     } | 
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 652         } | 652         } | 
| 653     } | 653     } | 
| 654 } | 654 } | 
| 655 | 655 | 
| 656 #ifdef SK_DEBUG | 656 #ifdef SK_DEBUG | 
| 657 // Ensure that deleting SkPicturePlayback does not assert. Asserts only fire in 
      debug mode, so only | 657 // Ensure that deleting SkPicturePlayback does not assert. Asserts only fire in 
      debug mode, so only | 
| 658 // run in debug mode. | 658 // run in debug mode. | 
| 659 static void test_deleting_empty_playback() { | 659 static void test_deleting_empty_playback() { | 
| 660     SkPictureRecorder recorder; | 660     SkPictureRecorder recorder; | 
| 661     // Creates an SkPictureRecord | 661     // Creates an SkPictureRecord | 
| 662     recorder.beginRecording(0, 0); | 662     recorder.beginRecording(0, 0, NULL, 0); | 
| 663     // Turns that into an SkPicturePlayback | 663     // Turns that into an SkPicturePlayback | 
| 664     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 664     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 665     // Deletes the old SkPicturePlayback, and creates a new SkPictureRecord | 665     // Deletes the old SkPicturePlayback, and creates a new SkPictureRecord | 
| 666     recorder.beginRecording(0, 0); | 666     recorder.beginRecording(0, 0, NULL, 0); | 
| 667 } | 667 } | 
| 668 | 668 | 
| 669 // Ensure that serializing an empty picture does not assert. Likewise only runs 
      in debug mode. | 669 // Ensure that serializing an empty picture does not assert. Likewise only runs 
      in debug mode. | 
| 670 static void test_serializing_empty_picture() { | 670 static void test_serializing_empty_picture() { | 
| 671     SkPictureRecorder recorder; | 671     SkPictureRecorder recorder; | 
| 672     recorder.beginRecording(0, 0); | 672     recorder.beginRecording(0, 0, NULL, 0); | 
| 673     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 673     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 674     SkDynamicMemoryWStream stream; | 674     SkDynamicMemoryWStream stream; | 
| 675     picture->serialize(&stream); | 675     picture->serialize(&stream); | 
| 676 } | 676 } | 
| 677 #endif | 677 #endif | 
| 678 | 678 | 
| 679 static void rand_op(SkCanvas* canvas, SkRandom& rand) { | 679 static void rand_op(SkCanvas* canvas, SkRandom& rand) { | 
| 680     SkPaint paint; | 680     SkPaint paint; | 
| 681     SkRect rect = SkRect::MakeWH(50, 50); | 681     SkRect rect = SkRect::MakeWH(50, 50); | 
| 682 | 682 | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 709 | 709 | 
| 710     REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 710     REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 
| 711 | 711 | 
| 712     SkPaint paint; | 712     SkPaint paint; | 
| 713     SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); | 713     SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); | 
| 714 | 714 | 
| 715     SkPictureRecorder recorder; | 715     SkPictureRecorder recorder; | 
| 716 | 716 | 
| 717     { | 717     { | 
| 718         // Create picture with 2 unbalanced saves | 718         // Create picture with 2 unbalanced saves | 
| 719         SkCanvas* canvas = recorder.beginRecording(100, 100); | 719         SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 
| 720         canvas->save(); | 720         canvas->save(); | 
| 721         canvas->translate(10, 10); | 721         canvas->translate(10, 10); | 
| 722         canvas->drawRect(rect, paint); | 722         canvas->drawRect(rect, paint); | 
| 723         canvas->save(); | 723         canvas->save(); | 
| 724         canvas->translate(10, 10); | 724         canvas->translate(10, 10); | 
| 725         canvas->drawRect(rect, paint); | 725         canvas->drawRect(rect, paint); | 
| 726         SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording()); | 726         SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording()); | 
| 727 | 727 | 
| 728         testCanvas.drawPicture(*extraSavePicture); | 728         testCanvas.drawPicture(*extraSavePicture); | 
| 729         REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 729         REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 
| 730     } | 730     } | 
| 731 | 731 | 
| 732     set_canvas_to_save_count_4(&testCanvas); | 732     set_canvas_to_save_count_4(&testCanvas); | 
| 733 | 733 | 
| 734     { | 734     { | 
| 735         // Create picture with 2 unbalanced restores | 735         // Create picture with 2 unbalanced restores | 
| 736         SkCanvas* canvas = recorder.beginRecording(100, 100); | 736         SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 
| 737         canvas->save(); | 737         canvas->save(); | 
| 738         canvas->translate(10, 10); | 738         canvas->translate(10, 10); | 
| 739         canvas->drawRect(rect, paint); | 739         canvas->drawRect(rect, paint); | 
| 740         canvas->save(); | 740         canvas->save(); | 
| 741         canvas->translate(10, 10); | 741         canvas->translate(10, 10); | 
| 742         canvas->drawRect(rect, paint); | 742         canvas->drawRect(rect, paint); | 
| 743         canvas->restore(); | 743         canvas->restore(); | 
| 744         canvas->restore(); | 744         canvas->restore(); | 
| 745         canvas->restore(); | 745         canvas->restore(); | 
| 746         canvas->restore(); | 746         canvas->restore(); | 
| 747         SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording()); | 747         SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording()); | 
| 748 | 748 | 
| 749         testCanvas.drawPicture(*extraRestorePicture); | 749         testCanvas.drawPicture(*extraRestorePicture); | 
| 750         REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 750         REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 
| 751     } | 751     } | 
| 752 | 752 | 
| 753     set_canvas_to_save_count_4(&testCanvas); | 753     set_canvas_to_save_count_4(&testCanvas); | 
| 754 | 754 | 
| 755     { | 755     { | 
| 756         SkCanvas* canvas = recorder.beginRecording(100, 100); | 756         SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 
| 757         canvas->translate(10, 10); | 757         canvas->translate(10, 10); | 
| 758         canvas->drawRect(rect, paint); | 758         canvas->drawRect(rect, paint); | 
| 759         SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); | 759         SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); | 
| 760 | 760 | 
| 761         testCanvas.drawPicture(*noSavePicture); | 761         testCanvas.drawPicture(*noSavePicture); | 
| 762         REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 762         REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 
| 763         REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); | 763         REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); | 
| 764     } | 764     } | 
| 765 } | 765 } | 
| 766 | 766 | 
| 767 static void test_peephole() { | 767 static void test_peephole() { | 
| 768     SkRandom rand; | 768     SkRandom rand; | 
| 769 | 769 | 
| 770     SkPictureRecorder recorder; | 770     SkPictureRecorder recorder; | 
| 771 | 771 | 
| 772     for (int j = 0; j < 100; j++) { | 772     for (int j = 0; j < 100; j++) { | 
| 773         SkRandom rand2(rand); // remember the seed | 773         SkRandom rand2(rand); // remember the seed | 
| 774 | 774 | 
| 775         SkCanvas* canvas = recorder.beginRecording(100, 100); | 775         SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 
| 776 | 776 | 
| 777         for (int i = 0; i < 1000; ++i) { | 777         for (int i = 0; i < 1000; ++i) { | 
| 778             rand_op(canvas, rand); | 778             rand_op(canvas, rand); | 
| 779         } | 779         } | 
| 780         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 780         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 781 | 781 | 
| 782         rand = rand2; | 782         rand = rand2; | 
| 783     } | 783     } | 
| 784 | 784 | 
| 785     { | 785     { | 
| 786         SkCanvas* canvas = recorder.beginRecording(100, 100); | 786         SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 
| 787         SkRect rect = SkRect::MakeWH(50, 50); | 787         SkRect rect = SkRect::MakeWH(50, 50); | 
| 788 | 788 | 
| 789         for (int i = 0; i < 100; ++i) { | 789         for (int i = 0; i < 100; ++i) { | 
| 790             canvas->save(); | 790             canvas->save(); | 
| 791         } | 791         } | 
| 792         while (canvas->getSaveCount() > 1) { | 792         while (canvas->getSaveCount() > 1) { | 
| 793             canvas->clipRect(rect); | 793             canvas->clipRect(rect); | 
| 794             canvas->restore(); | 794             canvas->restore(); | 
| 795         } | 795         } | 
| 796         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 796         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 797     } | 797     } | 
| 798 } | 798 } | 
| 799 | 799 | 
| 800 #ifndef SK_DEBUG | 800 #ifndef SK_DEBUG | 
| 801 // Only test this is in release mode. We deliberately crash in debug mode, since
       a valid caller | 801 // Only test this is in release mode. We deliberately crash in debug mode, since
       a valid caller | 
| 802 // should never do this. | 802 // should never do this. | 
| 803 static void test_bad_bitmap() { | 803 static void test_bad_bitmap() { | 
| 804     // This bitmap has a width and height but no pixels. As a result, attempting
       to record it will | 804     // This bitmap has a width and height but no pixels. As a result, attempting
       to record it will | 
| 805     // fail. | 805     // fail. | 
| 806     SkBitmap bm; | 806     SkBitmap bm; | 
| 807     bm.setConfig(SkImageInfo::MakeN32Premul(100, 100)); | 807     bm.setConfig(SkImageInfo::MakeN32Premul(100, 100)); | 
| 808     SkPictureRecorder recorder; | 808     SkPictureRecorder recorder; | 
| 809     SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); | 809     SkCanvas* recordingCanvas = recorder.beginRecording(100, 100, NULL, 0); | 
| 810     recordingCanvas->drawBitmap(bm, 0, 0); | 810     recordingCanvas->drawBitmap(bm, 0, 0); | 
| 811     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 811     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 812 | 812 | 
| 813     SkCanvas canvas; | 813     SkCanvas canvas; | 
| 814     canvas.drawPicture(*picture); | 814     canvas.drawPicture(*picture); | 
| 815 } | 815 } | 
| 816 #endif | 816 #endif | 
| 817 | 817 | 
| 818 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { | 818 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { | 
| 819     return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | 819     return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | 
| 820 } | 820 } | 
| 821 | 821 | 
| 822 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 822 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 
| 823     SkPictureRecorder recorder; | 823     SkPictureRecorder recorder; | 
| 824     SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height()); | 824     SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height(), 
      NULL, 0); | 
| 825     canvas->drawBitmap(bitmap, 0, 0); | 825     canvas->drawBitmap(bitmap, 0, 0); | 
| 826     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 826     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 827 | 827 | 
| 828     SkDynamicMemoryWStream wStream; | 828     SkDynamicMemoryWStream wStream; | 
| 829     picture->serialize(&wStream, &encode_bitmap_to_data); | 829     picture->serialize(&wStream, &encode_bitmap_to_data); | 
| 830     return wStream.copyToData(); | 830     return wStream.copyToData(); | 
| 831 } | 831 } | 
| 832 | 832 | 
| 833 struct ErrorContext { | 833 struct ErrorContext { | 
| 834     int fErrors; | 834     int fErrors; | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 880     SkClearLastError(); | 880     SkClearLastError(); | 
| 881     SkSetErrorCallback(NULL, NULL); | 881     SkSetErrorCallback(NULL, NULL); | 
| 882 } | 882 } | 
| 883 | 883 | 
| 884 static void test_clone_empty(skiatest::Reporter* reporter) { | 884 static void test_clone_empty(skiatest::Reporter* reporter) { | 
| 885     // This is a regression test for crbug.com/172062 | 885     // This is a regression test for crbug.com/172062 | 
| 886     // Before the fix, we used to crash accessing a null pointer when we | 886     // Before the fix, we used to crash accessing a null pointer when we | 
| 887     // had a picture with no paints. This test passes by not crashing. | 887     // had a picture with no paints. This test passes by not crashing. | 
| 888     { | 888     { | 
| 889         SkPictureRecorder recorder; | 889         SkPictureRecorder recorder; | 
| 890         recorder.beginRecording(1, 1); | 890         recorder.beginRecording(1, 1, NULL, 0); | 
| 891         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 891         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 892         SkAutoTUnref<SkPicture> destPicture(picture->clone()); | 892         SkAutoTUnref<SkPicture> destPicture(picture->clone()); | 
| 893         REPORTER_ASSERT(reporter, NULL != destPicture); | 893         REPORTER_ASSERT(reporter, NULL != destPicture); | 
| 894     } | 894     } | 
| 895 } | 895 } | 
| 896 | 896 | 
| 897 static void test_draw_empty(skiatest::Reporter* reporter) { | 897 static void test_draw_empty(skiatest::Reporter* reporter) { | 
| 898     SkBitmap result; | 898     SkBitmap result; | 
| 899     make_bm(&result, 2, 2, SK_ColorBLACK, false); | 899     make_bm(&result, 2, 2, SK_ColorBLACK, false); | 
| 900 | 900 | 
| 901     SkCanvas canvas(result); | 901     SkCanvas canvas(result); | 
| 902 | 902 | 
| 903     { | 903     { | 
| 904         // stock SkPicture | 904         // stock SkPicture | 
| 905         SkPictureRecorder recorder; | 905         SkPictureRecorder recorder; | 
| 906         recorder.beginRecording(1, 1); | 906         recorder.beginRecording(1, 1, NULL, 0); | 
| 907         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 907         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 908 | 908 | 
| 909         canvas.drawPicture(*picture); | 909         canvas.drawPicture(*picture); | 
| 910     } | 910     } | 
| 911 | 911 | 
| 912     { | 912     { | 
| 913         // tile grid | 913         // tile grid | 
| 914         SkTileGridPicture::TileGridInfo gridInfo; | 914         SkTileGridFactory::TileGridInfo gridInfo; | 
| 915         gridInfo.fMargin.setEmpty(); | 915         gridInfo.fMargin.setEmpty(); | 
| 916         gridInfo.fOffset.setZero(); | 916         gridInfo.fOffset.setZero(); | 
| 917         gridInfo.fTileInterval.set(1, 1); | 917         gridInfo.fTileInterval.set(1, 1); | 
| 918 | 918 | 
| 919         SkAutoTUnref<SkPictureFactory> factory(SkNEW_ARGS(SkTileGridPictureFacto
      ry, (gridInfo))); | 919         SkTileGridFactory factory(gridInfo); | 
| 920         SkPictureRecorder recorder(factory); | 920         SkPictureRecorder recorder; | 
| 921         recorder.beginRecording(1, 1); | 921         recorder.beginRecording(1, 1, &factory, 0); | 
| 922         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 922         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 923 | 923 | 
| 924         canvas.drawPicture(*picture); | 924         canvas.drawPicture(*picture); | 
| 925     } | 925     } | 
| 926 | 926 | 
| 927     { | 927     { | 
| 928         // RTree | 928         // RTree | 
| 929         SkAutoTUnref<SkPictureFactory> factory(SkNEW(SkRTreePictureFactory)); | 929         SkRTreeFactory factory; | 
| 930         SkPictureRecorder recorder(factory); | 930         SkPictureRecorder recorder; | 
| 931         recorder.beginRecording(1, 1); | 931         recorder.beginRecording(1, 1, &factory, 0); | 
| 932         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 932         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 933 | 933 | 
| 934         canvas.drawPicture(*picture); | 934         canvas.drawPicture(*picture); | 
| 935     } | 935     } | 
| 936 | 936 | 
| 937     { | 937     { | 
| 938         // quad tree | 938         // quad tree | 
| 939         SkAutoTUnref<SkPictureFactory> factory(SkNEW(SkQuadTreePictureFactory)); | 939         SkQuadTreeFactory factory; | 
| 940         SkPictureRecorder recorder(factory); | 940         SkPictureRecorder recorder; | 
| 941         recorder.beginRecording(1, 1); | 941         recorder.beginRecording(1, 1, &factory, 0); | 
| 942         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 942         SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 943 | 943 | 
| 944         canvas.drawPicture(*picture); | 944         canvas.drawPicture(*picture); | 
| 945     } | 945     } | 
| 946 } | 946 } | 
| 947 | 947 | 
| 948 static void test_clip_bound_opt(skiatest::Reporter* reporter) { | 948 static void test_clip_bound_opt(skiatest::Reporter* reporter) { | 
| 949     // Test for crbug.com/229011 | 949     // Test for crbug.com/229011 | 
| 950     SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), | 950     SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), | 
| 951                                     SkIntToScalar(2), SkIntToScalar(2)); | 951                                     SkIntToScalar(2), SkIntToScalar(2)); | 
| 952     SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), | 952     SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), | 
| 953                                     SkIntToScalar(1), SkIntToScalar(1)); | 953                                     SkIntToScalar(1), SkIntToScalar(1)); | 
| 954     SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), | 954     SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), | 
| 955                                     SkIntToScalar(1), SkIntToScalar(1)); | 955                                     SkIntToScalar(1), SkIntToScalar(1)); | 
| 956 | 956 | 
| 957     SkPath invPath; | 957     SkPath invPath; | 
| 958     invPath.addOval(rect1); | 958     invPath.addOval(rect1); | 
| 959     invPath.setFillType(SkPath::kInverseEvenOdd_FillType); | 959     invPath.setFillType(SkPath::kInverseEvenOdd_FillType); | 
| 960     SkPath path; | 960     SkPath path; | 
| 961     path.addOval(rect2); | 961     path.addOval(rect2); | 
| 962     SkPath path2; | 962     SkPath path2; | 
| 963     path2.addOval(rect3); | 963     path2.addOval(rect3); | 
| 964     SkIRect clipBounds; | 964     SkIRect clipBounds; | 
| 965     SkPictureRecorder recorder; | 965     SkPictureRecorder recorder; | 
| 966     // Minimalist test set for 100% code coverage of | 966     // Minimalist test set for 100% code coverage of | 
| 967     // SkPictureRecord::updateClipConservativelyUsingBounds | 967     // SkPictureRecord::updateClipConservativelyUsingBounds | 
| 968     { | 968     { | 
| 969         SkCanvas* canvas = recorder.beginRecording(10, 10, | 969         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 
| 970             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 970             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 
| 971         canvas->clipPath(invPath, SkRegion::kIntersect_Op); | 971         canvas->clipPath(invPath, SkRegion::kIntersect_Op); | 
| 972         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 972         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 
| 973         REPORTER_ASSERT(reporter, true == nonEmpty); | 973         REPORTER_ASSERT(reporter, true == nonEmpty); | 
| 974         REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 974         REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 
| 975         REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 975         REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 
| 976         REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 976         REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 
| 977         REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 977         REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 
| 978     } | 978     } | 
| 979     { | 979     { | 
| 980         SkCanvas* canvas = recorder.beginRecording(10, 10, | 980         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 
| 981             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 981             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 
| 982         canvas->clipPath(path, SkRegion::kIntersect_Op); | 982         canvas->clipPath(path, SkRegion::kIntersect_Op); | 
| 983         canvas->clipPath(invPath, SkRegion::kIntersect_Op); | 983         canvas->clipPath(invPath, SkRegion::kIntersect_Op); | 
| 984         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 984         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 
| 985         REPORTER_ASSERT(reporter, true == nonEmpty); | 985         REPORTER_ASSERT(reporter, true == nonEmpty); | 
| 986         REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); | 986         REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); | 
| 987         REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); | 987         REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); | 
| 988         REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 988         REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 
| 989         REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 989         REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 
| 990     } | 990     } | 
| 991     { | 991     { | 
| 992         SkCanvas* canvas = recorder.beginRecording(10, 10, | 992         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 
| 993             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 993             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 
| 994         canvas->clipPath(path, SkRegion::kIntersect_Op); | 994         canvas->clipPath(path, SkRegion::kIntersect_Op); | 
| 995         canvas->clipPath(invPath, SkRegion::kUnion_Op); | 995         canvas->clipPath(invPath, SkRegion::kUnion_Op); | 
| 996         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 996         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 
| 997         REPORTER_ASSERT(reporter, true == nonEmpty); | 997         REPORTER_ASSERT(reporter, true == nonEmpty); | 
| 998         REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 998         REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 
| 999         REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 999         REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 
| 1000         REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 1000         REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 
| 1001         REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 1001         REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 
| 1002     } | 1002     } | 
| 1003     { | 1003     { | 
| 1004         SkCanvas* canvas = recorder.beginRecording(10, 10, | 1004         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 
| 1005             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 1005             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 
| 1006         canvas->clipPath(path, SkRegion::kDifference_Op); | 1006         canvas->clipPath(path, SkRegion::kDifference_Op); | 
| 1007         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1007         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 
| 1008         REPORTER_ASSERT(reporter, true == nonEmpty); | 1008         REPORTER_ASSERT(reporter, true == nonEmpty); | 
| 1009         REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 1009         REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 
| 1010         REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 1010         REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 
| 1011         REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 1011         REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 
| 1012         REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 1012         REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 
| 1013     } | 1013     } | 
| 1014     { | 1014     { | 
| 1015         SkCanvas* canvas = recorder.beginRecording(10, 10, | 1015         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 
| 1016             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 1016             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 
| 1017         canvas->clipPath(path, SkRegion::kReverseDifference_Op); | 1017         canvas->clipPath(path, SkRegion::kReverseDifference_Op); | 
| 1018         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1018         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 
| 1019         // True clip is actually empty in this case, but the best | 1019         // True clip is actually empty in this case, but the best | 
| 1020         // determination we can make using only bounds as input is that the | 1020         // determination we can make using only bounds as input is that the | 
| 1021         // clip is included in the bounds of 'path'. | 1021         // clip is included in the bounds of 'path'. | 
| 1022         REPORTER_ASSERT(reporter, true == nonEmpty); | 1022         REPORTER_ASSERT(reporter, true == nonEmpty); | 
| 1023         REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); | 1023         REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); | 
| 1024         REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); | 1024         REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); | 
| 1025         REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 1025         REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 
| 1026         REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 1026         REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 
| 1027     } | 1027     } | 
| 1028     { | 1028     { | 
| 1029         SkCanvas* canvas = recorder.beginRecording(10, 10, | 1029         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 
| 1030             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 1030             SkPicture::kUsePathBoundsForClip_RecordingFlag); | 
| 1031         canvas->clipPath(path, SkRegion::kIntersect_Op); | 1031         canvas->clipPath(path, SkRegion::kIntersect_Op); | 
| 1032         canvas->clipPath(path2, SkRegion::kXOR_Op); | 1032         canvas->clipPath(path2, SkRegion::kXOR_Op); | 
| 1033         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1033         bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 
| 1034         REPORTER_ASSERT(reporter, true == nonEmpty); | 1034         REPORTER_ASSERT(reporter, true == nonEmpty); | 
| 1035         REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); | 1035         REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); | 
| 1036         REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); | 1036         REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); | 
| 1037         REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 1037         REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 
| 1038         REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 1038         REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 
| 1039     } | 1039     } | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1078     unsigned getClipCount() const { return fClipCount; } | 1078     unsigned getClipCount() const { return fClipCount; } | 
| 1079 | 1079 | 
| 1080 private: | 1080 private: | 
| 1081     unsigned fClipCount; | 1081     unsigned fClipCount; | 
| 1082 | 1082 | 
| 1083     typedef SkCanvas INHERITED; | 1083     typedef SkCanvas INHERITED; | 
| 1084 }; | 1084 }; | 
| 1085 | 1085 | 
| 1086 static void test_clip_expansion(skiatest::Reporter* reporter) { | 1086 static void test_clip_expansion(skiatest::Reporter* reporter) { | 
| 1087     SkPictureRecorder recorder; | 1087     SkPictureRecorder recorder; | 
| 1088     SkCanvas* canvas = recorder.beginRecording(10, 10, 0); | 1088     SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 
| 1089 | 1089 | 
| 1090     canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); | 1090     canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); | 
| 1091     // The following expanding clip should not be skipped. | 1091     // The following expanding clip should not be skipped. | 
| 1092     canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); | 1092     canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); | 
| 1093     // Draw something so the optimizer doesn't just fold the world. | 1093     // Draw something so the optimizer doesn't just fold the world. | 
| 1094     SkPaint p; | 1094     SkPaint p; | 
| 1095     p.setColor(SK_ColorBLUE); | 1095     p.setColor(SK_ColorBLUE); | 
| 1096     canvas->drawPaint(p); | 1096     canvas->drawPaint(p); | 
| 1097     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1097     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 1098 | 1098 | 
| 1099     ClipCountingCanvas testCanvas(10, 10); | 1099     ClipCountingCanvas testCanvas(10, 10); | 
| 1100     picture->draw(&testCanvas); | 1100     picture->draw(&testCanvas); | 
| 1101 | 1101 | 
| 1102     // Both clips should be present on playback. | 1102     // Both clips should be present on playback. | 
| 1103     REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); | 1103     REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); | 
| 1104 } | 1104 } | 
| 1105 | 1105 | 
| 1106 static void test_hierarchical(skiatest::Reporter* reporter) { | 1106 static void test_hierarchical(skiatest::Reporter* reporter) { | 
| 1107     SkBitmap bm; | 1107     SkBitmap bm; | 
| 1108     make_bm(&bm, 10, 10, SK_ColorRED, true); | 1108     make_bm(&bm, 10, 10, SK_ColorRED, true); | 
| 1109 | 1109 | 
| 1110     SkPictureRecorder recorder; | 1110     SkPictureRecorder recorder; | 
| 1111 | 1111 | 
| 1112     recorder.beginRecording(10, 10); | 1112     recorder.beginRecording(10, 10, NULL, 0); | 
| 1113     SkAutoTUnref<SkPicture> childPlain(recorder.endRecording()); | 1113     SkAutoTUnref<SkPicture> childPlain(recorder.endRecording()); | 
| 1114     REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 | 1114     REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 | 
| 1115 | 1115 | 
| 1116     recorder.beginRecording(10, 10)->drawBitmap(bm, 0, 0); | 1116     recorder.beginRecording(10, 10, NULL, 0)->drawBitmap(bm, 0, 0); | 
| 1117     SkAutoTUnref<SkPicture> childWithBitmap(recorder.endRecording()); | 1117     SkAutoTUnref<SkPicture> childWithBitmap(recorder.endRecording()); | 
| 1118     REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 | 1118     REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 | 
| 1119 | 1119 | 
| 1120     { | 1120     { | 
| 1121         SkCanvas* canvas = recorder.beginRecording(10, 10); | 1121         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 
| 1122         canvas->drawPicture(*childPlain); | 1122         canvas->drawPicture(*childPlain); | 
| 1123         SkAutoTUnref<SkPicture> parentPP(recorder.endRecording()); | 1123         SkAutoTUnref<SkPicture> parentPP(recorder.endRecording()); | 
| 1124         REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 | 1124         REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 | 
| 1125     } | 1125     } | 
| 1126     { | 1126     { | 
| 1127         SkCanvas* canvas = recorder.beginRecording(10, 10); | 1127         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 
| 1128         canvas->drawPicture(*childWithBitmap); | 1128         canvas->drawPicture(*childWithBitmap); | 
| 1129         SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording()); | 1129         SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording()); | 
| 1130         REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 | 1130         REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 | 
| 1131     } | 1131     } | 
| 1132     { | 1132     { | 
| 1133         SkCanvas* canvas = recorder.beginRecording(10, 10); | 1133         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 
| 1134         canvas->drawBitmap(bm, 0, 0); | 1134         canvas->drawBitmap(bm, 0, 0); | 
| 1135         canvas->drawPicture(*childPlain); | 1135         canvas->drawPicture(*childPlain); | 
| 1136         SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording()); | 1136         SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording()); | 
| 1137         REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 | 1137         REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 | 
| 1138     } | 1138     } | 
| 1139     { | 1139     { | 
| 1140         SkCanvas* canvas = recorder.beginRecording(10, 10); | 1140         SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 
| 1141         canvas->drawBitmap(bm, 0, 0); | 1141         canvas->drawBitmap(bm, 0, 0); | 
| 1142         canvas->drawPicture(*childWithBitmap); | 1142         canvas->drawPicture(*childWithBitmap); | 
| 1143         SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording()); | 1143         SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording()); | 
| 1144         REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 | 1144         REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 | 
| 1145     } | 1145     } | 
| 1146 } | 1146 } | 
| 1147 | 1147 | 
| 1148 static void test_gen_id(skiatest::Reporter* reporter) { | 1148 static void test_gen_id(skiatest::Reporter* reporter) { | 
| 1149 | 1149 | 
| 1150     SkPicture empty; | 1150     SkPicture empty; | 
| 1151 | 1151 | 
| 1152     // Empty pictures should still have a valid ID | 1152     // Empty pictures should still have a valid ID | 
| 1153     REPORTER_ASSERT(reporter, empty.uniqueID() != SK_InvalidGenID); | 1153     REPORTER_ASSERT(reporter, empty.uniqueID() != SK_InvalidGenID); | 
| 1154 | 1154 | 
| 1155     SkPictureRecorder recorder; | 1155     SkPictureRecorder recorder; | 
| 1156 | 1156 | 
| 1157     SkCanvas* canvas = recorder.beginRecording(1, 1); | 1157     SkCanvas* canvas = recorder.beginRecording(1, 1, NULL, 0); | 
| 1158     canvas->drawARGB(255, 255, 255, 255); | 1158     canvas->drawARGB(255, 255, 255, 255); | 
| 1159     SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); | 1159     SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); | 
| 1160     // picture should have a non-zero id after recording | 1160     // picture should have a non-zero id after recording | 
| 1161     REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); | 1161     REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); | 
| 1162 | 1162 | 
| 1163     // both pictures should have different ids | 1163     // both pictures should have different ids | 
| 1164     REPORTER_ASSERT(reporter, hasData->uniqueID() != empty.uniqueID()); | 1164     REPORTER_ASSERT(reporter, hasData->uniqueID() != empty.uniqueID()); | 
| 1165 | 1165 | 
| 1166     // test out copy constructor | 1166     // test out copy constructor | 
| 1167     SkPicture copyWithData(*hasData); | 1167     SkPicture copyWithData(*hasData); | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1225 | 1225 | 
| 1226 static void test_draw_bitmaps(SkCanvas* canvas) { | 1226 static void test_draw_bitmaps(SkCanvas* canvas) { | 
| 1227     SkBitmap empty; | 1227     SkBitmap empty; | 
| 1228     draw_bitmaps(empty, canvas); | 1228     draw_bitmaps(empty, canvas); | 
| 1229     empty.setConfig(SkImageInfo::MakeN32Premul(10, 10)); | 1229     empty.setConfig(SkImageInfo::MakeN32Premul(10, 10)); | 
| 1230     draw_bitmaps(empty, canvas); | 1230     draw_bitmaps(empty, canvas); | 
| 1231 } | 1231 } | 
| 1232 | 1232 | 
| 1233 DEF_TEST(Picture_EmptyBitmap, r) { | 1233 DEF_TEST(Picture_EmptyBitmap, r) { | 
| 1234     SkPictureRecorder recorder; | 1234     SkPictureRecorder recorder; | 
| 1235     test_draw_bitmaps(recorder.beginRecording(10, 10)); | 1235     test_draw_bitmaps(recorder.beginRecording(10, 10, NULL, 0)); | 
| 1236     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1236     SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 
| 1237 } | 1237 } | 
| 1238 | 1238 | 
| 1239 DEF_TEST(Canvas_EmptyBitmap, r) { | 1239 DEF_TEST(Canvas_EmptyBitmap, r) { | 
| 1240     SkBitmap dst; | 1240     SkBitmap dst; | 
| 1241     dst.allocN32Pixels(10, 10); | 1241     dst.allocN32Pixels(10, 10); | 
| 1242     SkCanvas canvas(dst); | 1242     SkCanvas canvas(dst); | 
| 1243 | 1243 | 
| 1244     test_draw_bitmaps(&canvas); | 1244     test_draw_bitmaps(&canvas); | 
| 1245 } | 1245 } | 
| OLD | NEW | 
|---|