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" |
11 #include "SkColorMatrixFilter.h" | 11 #include "SkColorMatrixFilter.h" |
12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
13 #include "SkDashPathEffect.h" | 13 #include "SkDashPathEffect.h" |
14 #include "SkData.h" | 14 #include "SkData.h" |
15 #include "SkDecodingImageGenerator.h" | 15 #include "SkDecodingImageGenerator.h" |
16 #include "SkError.h" | 16 #include "SkError.h" |
17 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
18 #include "SkImageGenerator.h" | 18 #include "SkImageGenerator.h" |
19 #include "SkLayerInfo.h" | 19 #include "SkLayerInfo.h" |
20 #include "SkPaint.h" | 20 #include "SkPaint.h" |
21 #include "SkPicture.h" | 21 #include "SkPicture.h" |
22 #include "SkPictureRecorder.h" | 22 #include "SkPictureRecorder.h" |
23 #include "SkPictureUtils.h" | 23 #include "SkPictureUtils.h" |
24 #include "SkPixelRef.h" | 24 #include "SkPixelRef.h" |
25 #include "SkRRect.h" | 25 #include "SkRRect.h" |
26 #include "SkRandom.h" | 26 #include "SkRandom.h" |
| 27 #include "SkRecord.h" |
27 #include "SkShader.h" | 28 #include "SkShader.h" |
28 #include "SkStream.h" | 29 #include "SkStream.h" |
29 | 30 |
30 #if SK_SUPPORT_GPU | 31 #if SK_SUPPORT_GPU |
31 #include "SkSurface.h" | 32 #include "SkSurface.h" |
32 #include "GrContextFactory.h" | 33 #include "GrContextFactory.h" |
33 #endif | 34 #endif |
34 #include "Test.h" | 35 #include "Test.h" |
35 | 36 |
36 #include "SkLumaColorFilter.h" | 37 #include "SkLumaColorFilter.h" |
(...skipping 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 SkCanvas* canvas = recorder.beginRecording(1, 1); | 1715 SkCanvas* canvas = recorder.beginRecording(1, 1); |
1715 canvas->drawARGB(255, 255, 255, 255); | 1716 canvas->drawARGB(255, 255, 255, 255); |
1716 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); | 1717 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); |
1717 // picture should have a non-zero id after recording | 1718 // picture should have a non-zero id after recording |
1718 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); | 1719 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); |
1719 | 1720 |
1720 // both pictures should have different ids | 1721 // both pictures should have different ids |
1721 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); | 1722 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); |
1722 } | 1723 } |
1723 | 1724 |
| 1725 static void test_bytes_used(skiatest::Reporter* reporter) { |
| 1726 SkPictureRecorder recorder; |
| 1727 |
| 1728 recorder.beginRecording(0, 0); |
| 1729 SkAutoTUnref<SkPicture> empty(recorder.endRecording()); |
| 1730 |
| 1731 // Sanity check to make sure we aren't under-measuring. |
| 1732 REPORTER_ASSERT(reporter, SkPictureUtils::ApproximateBytesUsed(empty.get())
>= |
| 1733 sizeof(SkPicture) + sizeof(SkRecord)); |
| 1734 |
| 1735 // Protect against any unintentional bloat. |
| 1736 REPORTER_ASSERT(reporter, SkPictureUtils::ApproximateBytesUsed(empty.get())
<= 184); |
| 1737 |
| 1738 // Sanity check of nested SkPictures. |
| 1739 SkPictureRecorder r2; |
| 1740 r2.beginRecording(0, 0); |
| 1741 r2.getRecordingCanvas()->drawPicture(empty.get()); |
| 1742 SkAutoTUnref<SkPicture> nested(r2.endRecording()); |
| 1743 |
| 1744 REPORTER_ASSERT(reporter, SkPictureUtils::ApproximateBytesUsed(nested.get())
> |
| 1745 SkPictureUtils::ApproximateBytesUsed(empty.get()))
; |
| 1746 } |
| 1747 |
1724 DEF_TEST(Picture, reporter) { | 1748 DEF_TEST(Picture, reporter) { |
1725 #ifdef SK_DEBUG | 1749 #ifdef SK_DEBUG |
1726 test_deleting_empty_picture(); | 1750 test_deleting_empty_picture(); |
1727 test_serializing_empty_picture(); | 1751 test_serializing_empty_picture(); |
1728 #else | 1752 #else |
1729 test_bad_bitmap(); | 1753 test_bad_bitmap(); |
1730 #endif | 1754 #endif |
1731 test_unbalanced_save_restores(reporter); | 1755 test_unbalanced_save_restores(reporter); |
1732 test_peephole(); | 1756 test_peephole(); |
1733 #if SK_SUPPORT_GPU | 1757 #if SK_SUPPORT_GPU |
1734 test_gpu_veto(reporter); | 1758 test_gpu_veto(reporter); |
1735 #endif | 1759 #endif |
1736 test_has_text(reporter); | 1760 test_has_text(reporter); |
1737 test_analysis(reporter); | 1761 test_analysis(reporter); |
1738 test_gatherpixelrefs(reporter); | 1762 test_gatherpixelrefs(reporter); |
1739 test_gatherpixelrefsandrects(reporter); | 1763 test_gatherpixelrefsandrects(reporter); |
1740 test_bitmap_with_encoded_data(reporter); | 1764 test_bitmap_with_encoded_data(reporter); |
1741 test_clip_bound_opt(reporter); | 1765 test_clip_bound_opt(reporter); |
1742 test_clip_expansion(reporter); | 1766 test_clip_expansion(reporter); |
1743 test_hierarchical(reporter); | 1767 test_hierarchical(reporter); |
1744 test_gen_id(reporter); | 1768 test_gen_id(reporter); |
1745 test_savelayer_extraction(reporter); | 1769 test_savelayer_extraction(reporter); |
| 1770 test_bytes_used(reporter); |
1746 } | 1771 } |
1747 | 1772 |
1748 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { | 1773 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { |
1749 const SkPaint paint; | 1774 const SkPaint paint; |
1750 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; | 1775 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; |
1751 const SkIRect irect = { 2, 2, 3, 3 }; | 1776 const SkIRect irect = { 2, 2, 3, 3 }; |
1752 | 1777 |
1753 // Don't care what these record, as long as they're legal. | 1778 // Don't care what these record, as long as they're legal. |
1754 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); | 1779 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); |
1755 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr
awBitmapRectFlag); | 1780 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 { | 1855 struct CountingBBH : public SkBBoxHierarchy { |
1831 mutable int searchCalls; | 1856 mutable int searchCalls; |
1832 | 1857 |
1833 CountingBBH() : searchCalls(0) {} | 1858 CountingBBH() : searchCalls(0) {} |
1834 | 1859 |
1835 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const
SK_OVERRIDE { | 1860 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const
SK_OVERRIDE { |
1836 this->searchCalls++; | 1861 this->searchCalls++; |
1837 } | 1862 } |
1838 | 1863 |
1839 virtual void insert(SkAutoTMalloc<SkRect>*, int) SK_OVERRIDE {} | 1864 virtual void insert(SkAutoTMalloc<SkRect>*, int) SK_OVERRIDE {} |
| 1865 virtual size_t bytesUsed() const { return 0; } |
1840 }; | 1866 }; |
1841 | 1867 |
1842 class SpoonFedBBHFactory : public SkBBHFactory { | 1868 class SpoonFedBBHFactory : public SkBBHFactory { |
1843 public: | 1869 public: |
1844 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} | 1870 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} |
1845 virtual SkBBoxHierarchy* operator()(int width, int height) const { | 1871 virtual SkBBoxHierarchy* operator()(int width, int height) const { |
1846 return SkRef(fBBH); | 1872 return SkRef(fBBH); |
1847 } | 1873 } |
1848 private: | 1874 private: |
1849 SkBBoxHierarchy* fBBH; | 1875 SkBBoxHierarchy* fBBH; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1887 | 1913 |
1888 // The picture shares the immutable pixels but copies the mutable ones. | 1914 // The picture shares the immutable pixels but copies the mutable ones. |
1889 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1915 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1890 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1916 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
1891 | 1917 |
1892 // When the picture goes away, it's just our bitmaps holding the refs. | 1918 // When the picture goes away, it's just our bitmaps holding the refs. |
1893 pic.reset(NULL); | 1919 pic.reset(NULL); |
1894 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1920 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1895 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1921 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1896 } | 1922 } |
OLD | NEW |