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

Unified Diff: src/image/SkSurface_Base.h

Issue 1686163002: Allow client to force an SkImage snapshot to be unique (and uniquely own its backing store). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix enum to bool warning Created 4 years, 10 months 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 side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « src/image/SkSurface.cpp ('k') | src/image/SkSurface_Gpu.h » ('j') | src/image/SkSurface_Gpu.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698