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

Unified Diff: src/core/SkWriter32.cpp

Issue 875403005: Make SkWriter32::snapshotAsData() a dumb copy. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « include/core/SkWriter32.h ('k') | tests/Writer32Test.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkWriter32.cpp
diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp
index 00c46368b6040d721f665f67a63fb20c52a6b64e..a1a8b8800a2dd26c7d52d11ec44122ceea92c446 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -74,32 +74,8 @@ void SkWriter32::growToAtLeast(size_t size) {
// we were external, so copy in the data
memcpy(fData, fExternal, fUsed);
}
- // Invalidate the snapshot, we know it is no longer useful.
- fSnapshot.reset(NULL);
}
SkData* SkWriter32::snapshotAsData() const {
- // get a non const version of this, we are only conceptually const
- SkWriter32& mutable_this = *const_cast<SkWriter32*>(this);
- // we use size change detection to invalidate the cached data
- if ((fSnapshot.get() != NULL) && (fSnapshot->size() != fUsed)) {
- mutable_this.fSnapshot.reset(NULL);
- }
- if (fSnapshot.get() == NULL) {
- uint8_t* buffer = NULL;
- if ((fExternal != NULL) && (fData == fExternal)) {
- // We need to copy to an allocated buffer before returning.
- buffer = (uint8_t*)sk_malloc_throw(fUsed);
- memcpy(buffer, fData, fUsed);
- } else {
- buffer = mutable_this.fInternal.detach();
- // prepare us to do copy on write, by pretending the data buffer
- // is external and size limited
- mutable_this.fData = buffer;
- mutable_this.fCapacity = fUsed;
- mutable_this.fExternal = buffer;
- }
- mutable_this.fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed));
- }
- return SkRef(fSnapshot.get()); // Take an extra ref for the caller.
+ return SkData::NewWithCopy(fData, fUsed);
}
« no previous file with comments | « include/core/SkWriter32.h ('k') | tests/Writer32Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698