Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 } | |
| OLD | NEW |