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

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: Add reset and comment Created 6 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
« include/core/SkWriter32.h ('K') | « src/core/SkPicturePlayback.cpp ('k') | no next file » | 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..a43d0e07cb33da8ae51bfc88c379dfa9b92260ec 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -75,3 +75,27 @@ void SkWriter32::growToAtLeast(size_t size) {
memcpy(fData, fExternal, fUsed);
}
}
+
+SkData* SkWriter32::snapshotAsData() {
+ // we use size change detection to invalidate the cached data
+ if ((fSnapshot.get() != NULL) && (fSnapshot->size() != fUsed)) {
reed1 2014/02/14 17:31:08 I wonder if we should consider invalidating this c
iancottrell 2014/02/14 18:28:36 Yes, I did consider that alternative. Basically we
ian_cottrell 2014/02/17 14:29:57 I added the snapshot drop in the growth code, but
+ 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 = fInternal.detach();
+ // prepare us to do copy on write, by pretending the data buffer
+ // is external and size limited
mtklein 2014/02/14 17:42:18 Have I got this right, that we're detaching and re
iancottrell 2014/02/14 18:28:36 Exactly, yes.
iancottrell 2014/02/27 20:16:19 I looked at doing this, and it turns out to be awk
mtklein 2014/03/06 18:58:07 Thanks for investigating.
+ fData = buffer;
reed1 2014/02/14 17:35:27 What if someone does a readAt(), and the snapshot
iancottrell 2014/02/14 18:28:36 no, so long as we hold a ref the buffer should be
+ fCapacity = fUsed;
+ fExternal = buffer;
+ }
+ fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed));
+ }
+ return SkRef(fSnapshot.get());
+}
« include/core/SkWriter32.h ('K') | « src/core/SkPicturePlayback.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698