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

Unified Diff: src/core/SkWriter32.cpp

Issue 155863005: Adding release method to SkWriter32 and using it to not copy the ops data from SkPictureRecord to S… (Closed) Base URL: https://skia.googlesource.com/skia.git@array_growth
Patch Set: Rename to detatchAsData 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
« no previous file with comments | « src/core/SkPictureRecord.h ('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 0de8b20b250addf9059334a225aae0b5d5339fc1..5002a1b033fecbe3bf35ad4159a188086f3b6e5e 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -8,6 +8,7 @@
#include "SkReader32.h"
#include "SkString.h"
#include "SkWriter32.h"
+#include "SkData.h"
/*
* Strings are stored as: length[4-bytes] + string_data + '\0' + pad_to_mul_4
@@ -84,3 +85,20 @@ void SkWriter32::growToAtLeast(size_t size) {
SkASSERT(fInternal.count() == fCapacity);
SkASSERT(fInternal.reserved() == fCapacity);
}
+
+SkData* SkWriter32::detatchAsData() {
+ 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();
+ }
+ SkData* data = SkData::NewFromMalloc(buffer, fUsed);
+ fData = NULL;
tomhudson 2014/02/07 17:15:58 Nit: the constructor uses 0 for all 4 fields. I th
iancottrell 2014/02/11 13:28:40 Done.
+ fCapacity = 0;
+ fUsed = 0;
+ fExternal = NULL;
+ return data;
+}
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698