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

Side by Side 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 unified diff | Download patch
« include/core/SkWriter32.h ('K') | « src/core/SkPicturePlayback.cpp ('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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 fCapacity = 4096 + SkTMax(size, fCapacity + (fCapacity / 2)); 69 fCapacity = 4096 + SkTMax(size, fCapacity + (fCapacity / 2));
70 fInternal.realloc(fCapacity); 70 fInternal.realloc(fCapacity);
71 fData = fInternal.get(); 71 fData = fInternal.get();
72 72
73 if (wasExternal) { 73 if (wasExternal) {
74 // we were external, so copy in the data 74 // we were external, so copy in the data
75 memcpy(fData, fExternal, fUsed); 75 memcpy(fData, fExternal, fUsed);
76 } 76 }
77 } 77 }
78
79 SkData* SkWriter32::snapshotAsData() {
80 // we use size change detection to invalidate the cached data
81 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
82 fSnapshot.reset(NULL);
83 }
84 if (fSnapshot.get() == NULL) {
85 uint8_t* buffer = NULL;
86 if ((fExternal != NULL) && (fData == fExternal)) {
87 // We need to copy to an allocated buffer before returning.
88 buffer = (uint8_t*)sk_malloc_throw(fUsed);
89 memcpy(buffer, fData, fUsed);
90 } else {
91 buffer = fInternal.detach();
92 // prepare us to do copy on write, by pretending the data buffer
93 // 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.
94 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
95 fCapacity = fUsed;
96 fExternal = buffer;
97 }
98 fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed));
99 }
100 return SkRef(fSnapshot.get());
101 }
OLDNEW
« 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