Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tests/PictureTest.cpp

Issue 490253003: Implement SkPicture::bytesUsed() for SkRecord backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix minor edit error in SkTileGrid::bytesUsed Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()) <= 168);
1737 }
1738
1724 DEF_TEST(Picture, reporter) { 1739 DEF_TEST(Picture, reporter) {
1725 #ifdef SK_DEBUG 1740 #ifdef SK_DEBUG
1726 test_deleting_empty_picture(); 1741 test_deleting_empty_picture();
1727 test_serializing_empty_picture(); 1742 test_serializing_empty_picture();
1728 #else 1743 #else
1729 test_bad_bitmap(); 1744 test_bad_bitmap();
1730 #endif 1745 #endif
1731 test_unbalanced_save_restores(reporter); 1746 test_unbalanced_save_restores(reporter);
1732 test_peephole(); 1747 test_peephole();
1733 #if SK_SUPPORT_GPU 1748 #if SK_SUPPORT_GPU
1734 test_gpu_veto(reporter); 1749 test_gpu_veto(reporter);
1735 #endif 1750 #endif
1736 test_has_text(reporter); 1751 test_has_text(reporter);
1737 test_analysis(reporter); 1752 test_analysis(reporter);
1738 test_gatherpixelrefs(reporter); 1753 test_gatherpixelrefs(reporter);
1739 test_gatherpixelrefsandrects(reporter); 1754 test_gatherpixelrefsandrects(reporter);
1740 test_bitmap_with_encoded_data(reporter); 1755 test_bitmap_with_encoded_data(reporter);
1741 test_clip_bound_opt(reporter); 1756 test_clip_bound_opt(reporter);
1742 test_clip_expansion(reporter); 1757 test_clip_expansion(reporter);
1743 test_hierarchical(reporter); 1758 test_hierarchical(reporter);
1744 test_gen_id(reporter); 1759 test_gen_id(reporter);
1745 test_savelayer_extraction(reporter); 1760 test_savelayer_extraction(reporter);
1761 test_bytes_used(reporter);
1746 } 1762 }
1747 1763
1748 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { 1764 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) {
1749 const SkPaint paint; 1765 const SkPaint paint;
1750 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; 1766 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f };
1751 const SkIRect irect = { 2, 2, 3, 3 }; 1767 const SkIRect irect = { 2, 2, 3, 3 };
1752 1768
1753 // Don't care what these record, as long as they're legal. 1769 // Don't care what these record, as long as they're legal.
1754 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); 1770 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint);
1755 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag); 1771 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 struct CountingBBH : public SkBBoxHierarchy { 1846 struct CountingBBH : public SkBBoxHierarchy {
1831 mutable int searchCalls; 1847 mutable int searchCalls;
1832 1848
1833 CountingBBH() : searchCalls(0) {} 1849 CountingBBH() : searchCalls(0) {}
1834 1850
1835 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE { 1851 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE {
1836 this->searchCalls++; 1852 this->searchCalls++;
1837 } 1853 }
1838 1854
1839 virtual void insert(SkAutoTMalloc<SkRect>*, int) SK_OVERRIDE {} 1855 virtual void insert(SkAutoTMalloc<SkRect>*, int) SK_OVERRIDE {}
1856 virtual size_t bytesUsed() const { return 0; }
1840 }; 1857 };
1841 1858
1842 class SpoonFedBBHFactory : public SkBBHFactory { 1859 class SpoonFedBBHFactory : public SkBBHFactory {
1843 public: 1860 public:
1844 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} 1861 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {}
1845 virtual SkBBoxHierarchy* operator()(int width, int height) const { 1862 virtual SkBBoxHierarchy* operator()(int width, int height) const {
1846 return SkRef(fBBH); 1863 return SkRef(fBBH);
1847 } 1864 }
1848 private: 1865 private:
1849 SkBBoxHierarchy* fBBH; 1866 SkBBoxHierarchy* fBBH;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 1904
1888 // The picture shares the immutable pixels but copies the mutable ones. 1905 // The picture shares the immutable pixels but copies the mutable ones.
1889 REPORTER_ASSERT(r, mut.pixelRef()->unique()); 1906 REPORTER_ASSERT(r, mut.pixelRef()->unique());
1890 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); 1907 REPORTER_ASSERT(r, !immut.pixelRef()->unique());
1891 1908
1892 // When the picture goes away, it's just our bitmaps holding the refs. 1909 // When the picture goes away, it's just our bitmaps holding the refs.
1893 pic.reset(NULL); 1910 pic.reset(NULL);
1894 REPORTER_ASSERT(r, mut.pixelRef()->unique()); 1911 REPORTER_ASSERT(r, mut.pixelRef()->unique());
1895 REPORTER_ASSERT(r, immut.pixelRef()->unique()); 1912 REPORTER_ASSERT(r, immut.pixelRef()->unique());
1896 } 1913 }
OLDNEW
« src/core/SkRTree.h ('K') | « src/utils/SkPictureUtils.cpp ('k') | tests/RecordDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698