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 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 SkCanvas* canvas = recorder.beginRecording(1, 1); | 1691 SkCanvas* canvas = recorder.beginRecording(1, 1); |
1692 canvas->drawARGB(255, 255, 255, 255); | 1692 canvas->drawARGB(255, 255, 255, 255); |
1693 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); | 1693 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); |
1694 // picture should have a non-zero id after recording | 1694 // picture should have a non-zero id after recording |
1695 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); | 1695 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); |
1696 | 1696 |
1697 // both pictures should have different ids | 1697 // both pictures should have different ids |
1698 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); | 1698 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); |
1699 } | 1699 } |
1700 | 1700 |
| 1701 static void test_bytes_used(skiatest::Reporter* reporter) { |
| 1702 SkPictureRecorder recorder; |
| 1703 |
| 1704 recorder.beginRecording(0, 0); |
| 1705 SkAutoTUnref<SkPicture> empty(recorder.endRecording()); |
| 1706 |
| 1707 // A SkPicture also has SkRecord and possibly SkBBHierarchy as members. |
| 1708 REPORTER_ASSERT(reporter, SkPictureUtils::approximateBytesUsed(empty.get())
>= |
| 1709 sizeof(SkPicture)); |
| 1710 } |
| 1711 |
1701 DEF_TEST(Picture, reporter) { | 1712 DEF_TEST(Picture, reporter) { |
1702 #ifdef SK_DEBUG | 1713 #ifdef SK_DEBUG |
1703 test_deleting_empty_picture(); | 1714 test_deleting_empty_picture(); |
1704 test_serializing_empty_picture(); | 1715 test_serializing_empty_picture(); |
1705 #else | 1716 #else |
1706 test_bad_bitmap(); | 1717 test_bad_bitmap(); |
1707 #endif | 1718 #endif |
1708 test_unbalanced_save_restores(reporter); | 1719 test_unbalanced_save_restores(reporter); |
1709 test_peephole(); | 1720 test_peephole(); |
1710 #if SK_SUPPORT_GPU | 1721 #if SK_SUPPORT_GPU |
1711 test_gpu_veto(reporter, false); | 1722 test_gpu_veto(reporter, false); |
1712 test_gpu_veto(reporter, true); | 1723 test_gpu_veto(reporter, true); |
1713 #endif | 1724 #endif |
1714 test_has_text(reporter, false); | 1725 test_has_text(reporter, false); |
1715 test_has_text(reporter, true); | 1726 test_has_text(reporter, true); |
1716 test_analysis(reporter, false); | 1727 test_analysis(reporter, false); |
1717 test_analysis(reporter, true); | 1728 test_analysis(reporter, true); |
1718 test_gatherpixelrefs(reporter); | 1729 test_gatherpixelrefs(reporter); |
1719 test_gatherpixelrefsandrects(reporter); | 1730 test_gatherpixelrefsandrects(reporter); |
1720 test_bitmap_with_encoded_data(reporter); | 1731 test_bitmap_with_encoded_data(reporter); |
1721 test_draw_empty(reporter); | 1732 test_draw_empty(reporter); |
1722 test_clip_bound_opt(reporter); | 1733 test_clip_bound_opt(reporter); |
1723 test_clip_expansion(reporter); | 1734 test_clip_expansion(reporter); |
1724 test_hierarchical(reporter); | 1735 test_hierarchical(reporter); |
1725 test_gen_id(reporter); | 1736 test_gen_id(reporter); |
| 1737 test_bytes_used(reporter); |
1726 } | 1738 } |
1727 | 1739 |
1728 #if SK_SUPPORT_GPU | 1740 #if SK_SUPPORT_GPU |
1729 DEF_GPUTEST(GPUPicture, reporter, factory) { | 1741 DEF_GPUTEST(GPUPicture, reporter, factory) { |
1730 test_gpu_picture_optimization(reporter, factory); | 1742 test_gpu_picture_optimization(reporter, factory); |
1731 } | 1743 } |
1732 #endif | 1744 #endif |
1733 | 1745 |
1734 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { | 1746 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { |
1735 const SkPaint paint; | 1747 const SkPaint paint; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1822 this->searchCalls++; | 1834 this->searchCalls++; |
1823 } | 1835 } |
1824 | 1836 |
1825 // All other methods unimplemented. | 1837 // All other methods unimplemented. |
1826 virtual void insert(void* data, const SkIRect& bounds, bool defer) {} | 1838 virtual void insert(void* data, const SkIRect& bounds, bool defer) {} |
1827 virtual void flushDeferredInserts() {} | 1839 virtual void flushDeferredInserts() {} |
1828 virtual void clear() {} | 1840 virtual void clear() {} |
1829 virtual int getCount() const { return 0; } | 1841 virtual int getCount() const { return 0; } |
1830 virtual int getDepth() const { return 0; } | 1842 virtual int getDepth() const { return 0; } |
1831 virtual void rewindInserts() {} | 1843 virtual void rewindInserts() {} |
| 1844 virtual size_t bytesUsed() const { return 0; } |
1832 }; | 1845 }; |
1833 | 1846 |
1834 class SpoonFedBBHFactory : public SkBBHFactory { | 1847 class SpoonFedBBHFactory : public SkBBHFactory { |
1835 public: | 1848 public: |
1836 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} | 1849 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} |
1837 virtual SkBBoxHierarchy* operator()(int width, int height) const { | 1850 virtual SkBBoxHierarchy* operator()(int width, int height) const { |
1838 return SkRef(fBBH); | 1851 return SkRef(fBBH); |
1839 } | 1852 } |
1840 private: | 1853 private: |
1841 SkBBoxHierarchy* fBBH; | 1854 SkBBoxHierarchy* fBBH; |
1842 }; | 1855 }; |
1843 | 1856 |
1844 // When the canvas clip covers the full picture, we don't need to call the BBH. | 1857 // When the canvas clip covers the full picture, we don't need to call the BBH. |
1845 DEF_TEST(Picture_SkipBBH, r) { | 1858 DEF_TEST(Picture_SkipBBH, r) { |
1846 CountingBBH bbh; | 1859 CountingBBH bbh; |
1847 SpoonFedBBHFactory factory(&bbh); | 1860 SpoonFedBBHFactory factory(&bbh); |
1848 | 1861 |
1849 SkPictureRecorder recorder; | 1862 SkPictureRecorder recorder; |
1850 recorder.beginRecording(320, 240, &factory); | 1863 recorder.beginRecording(320, 240, &factory); |
1851 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 1864 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
1852 | 1865 |
1853 SkCanvas big(640, 480), small(300, 200); | 1866 SkCanvas big(640, 480), small(300, 200); |
1854 | 1867 |
1855 picture->draw(&big); | 1868 picture->draw(&big); |
1856 REPORTER_ASSERT(r, bbh.searchCalls == 0); | 1869 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
1857 | 1870 |
1858 picture->draw(&small); | 1871 picture->draw(&small); |
1859 REPORTER_ASSERT(r, bbh.searchCalls == 1); | 1872 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
1860 } | 1873 } |
OLD | NEW |