| 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 "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkDashPathEffect.h" | 12 #include "SkDashPathEffect.h" |
| 13 #include "SkData.h" | 13 #include "SkData.h" |
| 14 #include "SkDecodingImageGenerator.h" | 14 #include "SkDecodingImageGenerator.h" |
| 15 #include "SkError.h" | 15 #include "SkError.h" |
| 16 #include "SkImageEncoder.h" | 16 #include "SkImageEncoder.h" |
| 17 #include "SkImageGenerator.h" | 17 #include "SkImageGenerator.h" |
| 18 #include "SkPaint.h" | 18 #include "SkPaint.h" |
| 19 #include "SkPicture.h" | 19 #include "SkPicture.h" |
| 20 #include "SkPictureRecorder.h" | 20 #include "SkPictureRecorder.h" |
| 21 #include "SkPictureUtils.h" | 21 #include "SkPictureUtils.h" |
| 22 #include "SkPixelRef.h" |
| 22 #include "SkRRect.h" | 23 #include "SkRRect.h" |
| 23 #include "SkRandom.h" | 24 #include "SkRandom.h" |
| 24 #include "SkShader.h" | 25 #include "SkShader.h" |
| 25 #include "SkStream.h" | 26 #include "SkStream.h" |
| 26 | 27 |
| 27 #if SK_SUPPORT_GPU | 28 #if SK_SUPPORT_GPU |
| 28 #include "SkSurface.h" | 29 #include "SkSurface.h" |
| 29 #include "GrContextFactory.h" | 30 #include "GrContextFactory.h" |
| 30 #include "GrPictureUtils.h" | 31 #include "GrPictureUtils.h" |
| 31 #endif | 32 #endif |
| (...skipping 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 1842 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
| 1842 | 1843 |
| 1843 SkCanvas big(640, 480), small(300, 200); | 1844 SkCanvas big(640, 480), small(300, 200); |
| 1844 | 1845 |
| 1845 picture->draw(&big); | 1846 picture->draw(&big); |
| 1846 REPORTER_ASSERT(r, bbh.searchCalls == 0); | 1847 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
| 1847 | 1848 |
| 1848 picture->draw(&small); | 1849 picture->draw(&small); |
| 1849 REPORTER_ASSERT(r, bbh.searchCalls == 1); | 1850 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
| 1850 } | 1851 } |
| 1852 |
| 1853 DEF_TEST(Picture_BitmapLeak, r) { |
| 1854 SkBitmap mut, immut; |
| 1855 mut.allocN32Pixels(300, 200); |
| 1856 immut.allocN32Pixels(300, 200); |
| 1857 immut.setImmutable(); |
| 1858 SkASSERT(!mut.isImmutable()); |
| 1859 SkASSERT(immut.isImmutable()); |
| 1860 |
| 1861 // No one can hold a ref on our pixels yet. |
| 1862 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1863 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
| 1864 |
| 1865 SkPictureRecorder rec; |
| 1866 SkCanvas* canvas = rec.beginRecording(1920, 1200); |
| 1867 canvas->drawBitmap(mut, 0, 0); |
| 1868 canvas->drawBitmap(immut, 800, 600); |
| 1869 SkAutoTDelete<const SkPicture> pic(rec.endRecording()); |
| 1870 |
| 1871 // The picture shares the immutable pixels but copies the mutable ones. |
| 1872 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1873 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
| 1874 |
| 1875 // When the picture goes away, it's just our bitmaps holding the refs. |
| 1876 pic.reset(NULL); |
| 1877 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1878 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
| 1879 } |
| OLD | NEW |