Index: src/image/SkSurface_Base.h |
diff --git a/src/image/SkSurface_Base.h b/src/image/SkSurface_Base.h |
index 7658409ad764eb78cdcb330d5ea13897d986c83f..aaa19cf5922d7f3ac5e0788a561dbea387d0ca67 100644 |
--- a/src/image/SkSurface_Base.h |
+++ b/src/image/SkSurface_Base.h |
@@ -9,6 +9,7 @@ |
#define SkSurface_Base_DEFINED |
#include "SkCanvas.h" |
+#include "SkImagePriv.h" |
#include "SkSurface.h" |
#include "SkSurfacePriv.h" |
@@ -42,7 +43,7 @@ public: |
* must faithfully represent the current contents, even if the surface |
* is changed after this called (e.g. it is drawn to via its canvas). |
*/ |
- virtual SkImage* onNewImageSnapshot(Budgeted) = 0; |
+ virtual SkImage* onNewImageSnapshot(Budgeted, ForceCopyMode) = 0; |
/** |
* Default implementation: |
@@ -75,7 +76,7 @@ public: |
virtual void onRestoreBackingMutability() {} |
inline SkCanvas* getCachedCanvas(); |
- inline SkImage* getCachedImage(Budgeted); |
+ inline SkImage* refCachedImage(Budgeted, ForceUnique); |
bool hasCachedImage() const { return fCachedImage != nullptr; } |
@@ -108,12 +109,23 @@ SkCanvas* SkSurface_Base::getCachedCanvas() { |
return fCachedCanvas; |
} |
-SkImage* SkSurface_Base::getCachedImage(Budgeted budgeted) { |
- if (nullptr == fCachedImage) { |
- fCachedImage = this->onNewImageSnapshot(budgeted); |
- SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); |
+SkImage* SkSurface_Base::refCachedImage(Budgeted budgeted, ForceUnique unique) { |
+ SkImage* snap = fCachedImage; |
+ if (kYes_ForceUnique == unique && snap && !snap->unique()) { |
+ snap = nullptr; |
} |
- return fCachedImage; |
+ if (snap) { |
+ return SkRef(snap); |
+ } |
+ ForceCopyMode fcm = (kYes_ForceUnique == unique) ? kYes_ForceCopyMode : |
+ kNo_ForceCopyMode; |
+ snap = this->onNewImageSnapshot(budgeted, fcm); |
+ if (kNo_ForceUnique == unique) { |
+ SkASSERT(!fCachedImage); |
+ fCachedImage = SkSafeRef(snap); |
+ } |
+ SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this); |
+ return snap; |
} |
#endif |