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

Unified Diff: src/core/SkWriter32.cpp

Issue 167113003: Add capture snapshot as data to SkWriter32, use it to optimise record->playback. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clarified the snapshotAsData api comment. Created 6 years, 9 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 | « src/core/SkPicturePlayback.cpp ('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 fe33e4a39cf011d1ce54d1d9a08c321d99f707fe..c7bfd92d56aafd832868c42f2690f3bcd8082ef3 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -74,4 +74,32 @@ 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.
}
« no previous file with comments | « src/core/SkPicturePlayback.cpp ('k') | tests/Writer32Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698