| 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 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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->draw(&canvas); | 1194 picture->playback(&canvas); |
| 1195 | 1195 |
| 1196 REPORTER_ASSERT(reporter, numSaves == canvas.getSaveCount()); | 1196 REPORTER_ASSERT(reporter, numSaves == canvas.getSaveCount()); |
| 1197 REPORTER_ASSERT(reporter, numSaveLayers == canvas.getSaveLayerCount()); | 1197 REPORTER_ASSERT(reporter, numSaveLayers == canvas.getSaveLayerCount()); |
| 1198 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); | 1198 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); |
| 1199 } | 1199 } |
| 1200 | 1200 |
| 1201 // 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 |
| 1202 // the 'partialReplay' method. | 1202 // the 'partialReplay' method. |
| 1203 class SkPictureRecorderReplayTester { | 1203 class SkPictureRecorderReplayTester { |
| 1204 public: | 1204 public: |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); | 1686 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); |
| 1687 // The following expanding clip should not be skipped. | 1687 // The following expanding clip should not be skipped. |
| 1688 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); | 1688 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); |
| 1689 // Draw something so the optimizer doesn't just fold the world. | 1689 // Draw something so the optimizer doesn't just fold the world. |
| 1690 SkPaint p; | 1690 SkPaint p; |
| 1691 p.setColor(SK_ColorBLUE); | 1691 p.setColor(SK_ColorBLUE); |
| 1692 canvas->drawPaint(p); | 1692 canvas->drawPaint(p); |
| 1693 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1693 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 1694 | 1694 |
| 1695 ClipCountingCanvas testCanvas(10, 10); | 1695 ClipCountingCanvas testCanvas(10, 10); |
| 1696 picture->draw(&testCanvas); | 1696 picture->playback(&testCanvas); |
| 1697 | 1697 |
| 1698 // Both clips should be present on playback. | 1698 // Both clips should be present on playback. |
| 1699 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); | 1699 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); |
| 1700 } | 1700 } |
| 1701 | 1701 |
| 1702 static void test_hierarchical(skiatest::Reporter* reporter) { | 1702 static void test_hierarchical(skiatest::Reporter* reporter) { |
| 1703 SkBitmap bm; | 1703 SkBitmap bm; |
| 1704 make_bm(&bm, 10, 10, SK_ColorRED, true); | 1704 make_bm(&bm, 10, 10, SK_ColorRED, true); |
| 1705 | 1705 |
| 1706 SkPictureRecorder recorder; | 1706 SkPictureRecorder recorder; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 canvas->drawBitmap(redBM, 50, 50); | 1859 canvas->drawBitmap(redBM, 50, 50); |
| 1860 canvas->restore(); | 1860 canvas->restore(); |
| 1861 | 1861 |
| 1862 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1862 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 1863 | 1863 |
| 1864 // Now replay the picture back on another canvas | 1864 // Now replay the picture back on another canvas |
| 1865 // and check a couple of its pixels. | 1865 // and check a couple of its pixels. |
| 1866 SkBitmap replayBM; | 1866 SkBitmap replayBM; |
| 1867 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); | 1867 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); |
| 1868 SkCanvas replayCanvas(replayBM); | 1868 SkCanvas replayCanvas(replayBM); |
| 1869 picture->draw(&replayCanvas); | 1869 picture->playback(&replayCanvas); |
| 1870 replayCanvas.flush(); | 1870 replayCanvas.flush(); |
| 1871 | 1871 |
| 1872 // With the bug present, at (55, 55) we would get a fully opaque red | 1872 // With the bug present, at (55, 55) we would get a fully opaque red |
| 1873 // intead of a dark red. | 1873 // intead of a dark red. |
| 1874 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); | 1874 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); |
| 1875 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); | 1875 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); |
| 1876 } | 1876 } |
| 1877 | 1877 |
| 1878 struct CountingBBH : public SkBBoxHierarchy { | 1878 struct CountingBBH : public SkBBoxHierarchy { |
| 1879 mutable int searchCalls; | 1879 mutable int searchCalls; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1907 DEF_TEST(Picture_SkipBBH, r) { | 1907 DEF_TEST(Picture_SkipBBH, r) { |
| 1908 CountingBBH bbh; | 1908 CountingBBH bbh; |
| 1909 SpoonFedBBHFactory factory(&bbh); | 1909 SpoonFedBBHFactory factory(&bbh); |
| 1910 | 1910 |
| 1911 SkPictureRecorder recorder; | 1911 SkPictureRecorder recorder; |
| 1912 recorder.beginRecording(320, 240, &factory); | 1912 recorder.beginRecording(320, 240, &factory); |
| 1913 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 1913 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
| 1914 | 1914 |
| 1915 SkCanvas big(640, 480), small(300, 200); | 1915 SkCanvas big(640, 480), small(300, 200); |
| 1916 | 1916 |
| 1917 picture->draw(&big); | 1917 picture->playback(&big); |
| 1918 REPORTER_ASSERT(r, bbh.searchCalls == 0); | 1918 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
| 1919 | 1919 |
| 1920 picture->draw(&small); | 1920 picture->playback(&small); |
| 1921 REPORTER_ASSERT(r, bbh.searchCalls == 1); | 1921 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
| 1922 } | 1922 } |
| 1923 | 1923 |
| 1924 DEF_TEST(Picture_BitmapLeak, r) { | 1924 DEF_TEST(Picture_BitmapLeak, r) { |
| 1925 SkBitmap mut, immut; | 1925 SkBitmap mut, immut; |
| 1926 mut.allocN32Pixels(300, 200); | 1926 mut.allocN32Pixels(300, 200); |
| 1927 immut.allocN32Pixels(300, 200); | 1927 immut.allocN32Pixels(300, 200); |
| 1928 immut.setImmutable(); | 1928 immut.setImmutable(); |
| 1929 SkASSERT(!mut.isImmutable()); | 1929 SkASSERT(!mut.isImmutable()); |
| 1930 SkASSERT(immut.isImmutable()); | 1930 SkASSERT(immut.isImmutable()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1941 | 1941 |
| 1942 // The picture shares the immutable pixels but copies the mutable ones. | 1942 // The picture shares the immutable pixels but copies the mutable ones. |
| 1943 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1943 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1944 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1944 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
| 1945 | 1945 |
| 1946 // 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. |
| 1947 pic.reset(NULL); | 1947 pic.reset(NULL); |
| 1948 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1948 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1949 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1949 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
| 1950 } | 1950 } |
| OLD | NEW |