| 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 #ifndef SkSurface_Base_DEFINED | 8 #ifndef SkSurface_Base_DEFINED |
| 9 #define SkSurface_Base_DEFINED | 9 #define SkSurface_Base_DEFINED |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Allocate a canvas that will draw into this surface. We will cache this | 31 * Allocate a canvas that will draw into this surface. We will cache this |
| 32 * canvas, to return the same object to the caller multiple times. We | 32 * canvas, to return the same object to the caller multiple times. We |
| 33 * take ownership, and will call unref() on the canvas when we go out of | 33 * take ownership, and will call unref() on the canvas when we go out of |
| 34 * scope. | 34 * scope. |
| 35 */ | 35 */ |
| 36 virtual SkCanvas* onNewCanvas() = 0; | 36 virtual SkCanvas* onNewCanvas() = 0; |
| 37 | 37 |
| 38 virtual SkSurface* onNewSurface(const SkImageInfo&) = 0; | 38 virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&) = 0; |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Allocate an SkImage that represents the current contents of the surface. | 41 * Allocate an SkImage that represents the current contents of the surface. |
| 42 * This needs to be able to outlive the surface itself (if need be), and | 42 * This needs to be able to outlive the surface itself (if need be), and |
| 43 * must faithfully represent the current contents, even if the surface | 43 * must faithfully represent the current contents, even if the surface |
| 44 * is changed after this called (e.g. it is drawn to via its canvas). | 44 * is changed after this called (e.g. it is drawn to via its canvas). |
| 45 */ | 45 */ |
| 46 virtual SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) = 0; | 46 virtual sk_sp<SkImage> onNewImageSnapshot(SkBudgeted, ForceCopyMode) = 0; |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Default implementation: | 49 * Default implementation: |
| 50 * | 50 * |
| 51 * image = this->newImageSnapshot(); | 51 * image = this->newImageSnapshot(); |
| 52 * if (image) { | 52 * if (image) { |
| 53 * image->draw(canvas, ...); | 53 * image->draw(canvas, ...); |
| 54 * image->unref(); | 54 * image->unref(); |
| 55 * } | 55 * } |
| 56 */ | 56 */ |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 sk_sp<SkImage> SkSurface_Base::refCachedImage(SkBudgeted budgeted, ForceUnique u
nique) { | 117 sk_sp<SkImage> SkSurface_Base::refCachedImage(SkBudgeted budgeted, ForceUnique u
nique) { |
| 118 SkImage* snap = fCachedImage; | 118 SkImage* snap = fCachedImage; |
| 119 if (kYes_ForceUnique == unique && snap && !snap->unique()) { | 119 if (kYes_ForceUnique == unique && snap && !snap->unique()) { |
| 120 snap = nullptr; | 120 snap = nullptr; |
| 121 } | 121 } |
| 122 if (snap) { | 122 if (snap) { |
| 123 return sk_ref_sp(snap); | 123 return sk_ref_sp(snap); |
| 124 } | 124 } |
| 125 ForceCopyMode fcm = (kYes_ForceUnique == unique) ? kYes_ForceCopyMode : | 125 ForceCopyMode fcm = (kYes_ForceUnique == unique) ? kYes_ForceCopyMode : |
| 126 kNo_ForceCopyMode; | 126 kNo_ForceCopyMode; |
| 127 snap = this->onNewImageSnapshot(budgeted, fcm); | 127 snap = this->onNewImageSnapshot(budgeted, fcm).release(); |
| 128 if (kNo_ForceUnique == unique) { | 128 if (kNo_ForceUnique == unique) { |
| 129 SkASSERT(!fCachedImage); | 129 SkASSERT(!fCachedImage); |
| 130 fCachedImage = SkSafeRef(snap); | 130 fCachedImage = SkSafeRef(snap); |
| 131 } | 131 } |
| 132 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); | 132 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); |
| 133 return sk_sp<SkImage>(snap); | 133 return sk_sp<SkImage>(snap); |
| 134 } | 134 } |
| 135 | 135 |
| 136 #endif | 136 #endif |
| OLD | NEW |