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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1714 SkCanvas* canvas = recorder.beginRecording(1, 1); | 1714 SkCanvas* canvas = recorder.beginRecording(1, 1); |
1715 canvas->drawARGB(255, 255, 255, 255); | 1715 canvas->drawARGB(255, 255, 255, 255); |
1716 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); | 1716 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); |
1717 // picture should have a non-zero id after recording | 1717 // picture should have a non-zero id after recording |
1718 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); | 1718 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); |
1719 | 1719 |
1720 // both pictures should have different ids | 1720 // both pictures should have different ids |
1721 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); | 1721 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); |
1722 } | 1722 } |
1723 | 1723 |
1724 static void test_bytes_used(skiatest::Reporter* reporter) { | |
1725 SkPictureRecorder recorder; | |
1726 | |
1727 recorder.beginRecording(0, 0); | |
1728 SkAutoTUnref<SkPicture> empty(recorder.endRecording()); | |
1729 | |
1730 // A SkPicture also has SkRecord and possibly SkBBHierarchy as members. | |
mtklein
2014/11/17 21:43:20
As written, there will be no BBH. Did you want to
| |
1731 REPORTER_ASSERT(reporter, SkPictureUtils::approximateBytesUsed(empty.get()) >= | |
1732 sizeof(SkPicture)); | |
1733 | |
1734 // Protect against any unintentional bloat. | |
1735 REPORTER_ASSERT(reporter, SkPictureUtils::approximateBytesUsed(empty.get()) <= 176); | |
1736 } | |
1737 | |
1724 DEF_TEST(Picture, reporter) { | 1738 DEF_TEST(Picture, reporter) { |
1725 #ifdef SK_DEBUG | 1739 #ifdef SK_DEBUG |
1726 test_deleting_empty_picture(); | 1740 test_deleting_empty_picture(); |
1727 test_serializing_empty_picture(); | 1741 test_serializing_empty_picture(); |
1728 #else | 1742 #else |
1729 test_bad_bitmap(); | 1743 test_bad_bitmap(); |
1730 #endif | 1744 #endif |
1731 test_unbalanced_save_restores(reporter); | 1745 test_unbalanced_save_restores(reporter); |
1732 test_peephole(); | 1746 test_peephole(); |
1733 #if SK_SUPPORT_GPU | 1747 #if SK_SUPPORT_GPU |
1734 test_gpu_veto(reporter); | 1748 test_gpu_veto(reporter); |
1735 #endif | 1749 #endif |
1736 test_has_text(reporter); | 1750 test_has_text(reporter); |
1737 test_analysis(reporter); | 1751 test_analysis(reporter); |
1738 test_gatherpixelrefs(reporter); | 1752 test_gatherpixelrefs(reporter); |
1739 test_gatherpixelrefsandrects(reporter); | 1753 test_gatherpixelrefsandrects(reporter); |
1740 test_bitmap_with_encoded_data(reporter); | 1754 test_bitmap_with_encoded_data(reporter); |
1741 test_clip_bound_opt(reporter); | 1755 test_clip_bound_opt(reporter); |
1742 test_clip_expansion(reporter); | 1756 test_clip_expansion(reporter); |
1743 test_hierarchical(reporter); | 1757 test_hierarchical(reporter); |
1744 test_gen_id(reporter); | 1758 test_gen_id(reporter); |
1745 test_savelayer_extraction(reporter); | 1759 test_savelayer_extraction(reporter); |
1760 test_bytes_used(reporter); | |
1746 } | 1761 } |
1747 | 1762 |
1748 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { | 1763 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { |
1749 const SkPaint paint; | 1764 const SkPaint paint; |
1750 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; | 1765 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; |
1751 const SkIRect irect = { 2, 2, 3, 3 }; | 1766 const SkIRect irect = { 2, 2, 3, 3 }; |
1752 | 1767 |
1753 // Don't care what these record, as long as they're legal. | 1768 // Don't care what these record, as long as they're legal. |
1754 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); | 1769 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); |
1755 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag); | 1770 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1830 struct CountingBBH : public SkBBoxHierarchy { | 1845 struct CountingBBH : public SkBBoxHierarchy { |
1831 mutable int searchCalls; | 1846 mutable int searchCalls; |
1832 | 1847 |
1833 CountingBBH() : searchCalls(0) {} | 1848 CountingBBH() : searchCalls(0) {} |
1834 | 1849 |
1835 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE { | 1850 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE { |
1836 this->searchCalls++; | 1851 this->searchCalls++; |
1837 } | 1852 } |
1838 | 1853 |
1839 virtual void insert(SkAutoTMalloc<SkRect>*, int) SK_OVERRIDE {} | 1854 virtual void insert(SkAutoTMalloc<SkRect>*, int) SK_OVERRIDE {} |
1855 virtual size_t bytesUsed() const { return 0; } | |
1840 }; | 1856 }; |
1841 | 1857 |
1842 class SpoonFedBBHFactory : public SkBBHFactory { | 1858 class SpoonFedBBHFactory : public SkBBHFactory { |
1843 public: | 1859 public: |
1844 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} | 1860 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} |
1845 virtual SkBBoxHierarchy* operator()(int width, int height) const { | 1861 virtual SkBBoxHierarchy* operator()(int width, int height) const { |
1846 return SkRef(fBBH); | 1862 return SkRef(fBBH); |
1847 } | 1863 } |
1848 private: | 1864 private: |
1849 SkBBoxHierarchy* fBBH; | 1865 SkBBoxHierarchy* fBBH; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1887 | 1903 |
1888 // The picture shares the immutable pixels but copies the mutable ones. | 1904 // The picture shares the immutable pixels but copies the mutable ones. |
1889 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1905 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1890 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1906 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
1891 | 1907 |
1892 // When the picture goes away, it's just our bitmaps holding the refs. | 1908 // When the picture goes away, it's just our bitmaps holding the refs. |
1893 pic.reset(NULL); | 1909 pic.reset(NULL); |
1894 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1910 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1895 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1911 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1896 } | 1912 } |
OLD | NEW |