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()); |
+} |