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

Side by Side 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: Change pointer init to use NULL 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 unified diff | Download patch
« src/core/SkPicturePlayback.cpp ('K') | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkReader32.h" 8 #include "SkReader32.h"
9 #include "SkString.h" 9 #include "SkString.h"
10 #include "SkWriter32.h" 10 #include "SkWriter32.h"
11 #include "SkData.h"
11 12
12 /* 13 /*
13 * Strings are stored as: length[4-bytes] + string_data + '\0' + pad_to_mul_4 14 * Strings are stored as: length[4-bytes] + string_data + '\0' + pad_to_mul_4
14 */ 15 */
15 16
16 const char* SkReader32::readString(size_t* outLen) { 17 const char* SkReader32::readString(size_t* outLen) {
17 size_t len = this->readInt(); 18 size_t len = this->readInt();
18 const void* ptr = this->peek(); 19 const void* ptr = this->peek();
19 20
20 // skip over the string + '\0' and then pad to a multiple of 4 21 // skip over the string + '\0' and then pad to a multiple of 4
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // cause the buffer to grow 78 // cause the buffer to grow
78 fInternal.setCountExact(fCapacity); 79 fInternal.setCountExact(fCapacity);
79 fData = fInternal.begin(); 80 fData = fInternal.begin();
80 if (wasExternal) { 81 if (wasExternal) {
81 // we were external, so copy in the data 82 // we were external, so copy in the data
82 memcpy(fData, fExternal, fUsed); 83 memcpy(fData, fExternal, fUsed);
83 } 84 }
84 SkASSERT(fInternal.count() == (int)fCapacity); 85 SkASSERT(fInternal.count() == (int)fCapacity);
85 SkASSERT(fInternal.reserved() == (int)fCapacity); 86 SkASSERT(fInternal.reserved() == (int)fCapacity);
86 } 87 }
88
89 SkData* SkWriter32::detatchAsData() {
90 uint8_t* buffer = NULL;
91 if ((fExternal != NULL) && (fData == fExternal)) {
92 // We need to copy to an allocated buffer before returning.
93 buffer = (uint8_t*)sk_malloc_throw(fUsed);
94 memcpy(buffer, fData, fUsed);
95 } else {
96 buffer = fInternal.detach();
97 }
98 SkData* data = SkData::NewFromMalloc(buffer, fUsed);
99 fData = NULL;
100 fCapacity = 0;
101 fUsed = 0;
102 fExternal = NULL;
103 return data;
104 }
OLDNEW
« src/core/SkPicturePlayback.cpp ('K') | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698