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

Unified Diff: src/images/SkDecodingImageGenerator.cpp

Issue 560653004: SkData can allocate room for its contents in the same block (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update dox, change fPtr to non const Created 6 years, 3 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/SkStream.cpp ('k') | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkDecodingImageGenerator.cpp
diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp
index 1d91bcc0f98e359c95b59cac8ac73d79feacdecf..359eb370adc29c240f48338fc574fe33376c9017 100644
--- a/src/images/SkDecodingImageGenerator.cpp
+++ b/src/images/SkDecodingImageGenerator.cpp
@@ -132,22 +132,20 @@ DecodingImageGenerator::~DecodingImageGenerator() {
SkData* DecodingImageGenerator::onRefEncodedData() {
// This functionality is used in `gm --serialize`
// Does not encode options.
- if (fData != NULL) {
- return SkSafeRef(fData);
- }
- // TODO(halcanary): SkStreamRewindable needs a refData() function
- // which returns a cheap copy of the underlying data.
- if (!fStream->rewind()) {
- return NULL;
- }
- size_t length = fStream->getLength();
- if (0 == length) {
- return NULL;
+ if (NULL == fData) {
+ // TODO(halcanary): SkStreamRewindable needs a refData() function
+ // which returns a cheap copy of the underlying data.
+ if (!fStream->rewind()) {
+ return NULL;
+ }
+ size_t length = fStream->getLength();
+ if (0 == length) {
+ return NULL;
+ }
+ fData = SkData::NewUninitialized(length);
+ SkCheckResult(fStream->read(fData->writable_data(), length), length);
}
- void* buffer = sk_malloc_flags(length, 0);
- SkCheckResult(fStream->read(buffer, length), length);
- fData = SkData::NewFromMalloc(buffer, length);
- return SkSafeRef(fData);
+ return SkRef(fData);
}
bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info,
« no previous file with comments | « src/core/SkStream.cpp ('k') | src/pdf/SkPDFFont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698