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

Side by Side Diff: src/images/SkDecodingImageGenerator.cpp

Issue 568683002: use SkData::NewUninitialized (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add SkStream::readIntoData 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkData.h" 8 #include "SkData.h"
9 #include "SkDecodingImageGenerator.h" 9 #include "SkDecodingImageGenerator.h"
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 SkData* DecodingImageGenerator::onRefEncodedData() { 132 SkData* DecodingImageGenerator::onRefEncodedData() {
133 // This functionality is used in `gm --serialize` 133 // This functionality is used in `gm --serialize`
134 // Does not encode options. 134 // Does not encode options.
135 if (NULL == fData) { 135 if (NULL == fData) {
136 // TODO(halcanary): SkStreamRewindable needs a refData() function 136 // TODO(halcanary): SkStreamRewindable needs a refData() function
137 // which returns a cheap copy of the underlying data. 137 // which returns a cheap copy of the underlying data.
138 if (!fStream->rewind()) { 138 if (!fStream->rewind()) {
139 return NULL; 139 return NULL;
140 } 140 }
141 size_t length = fStream->getLength(); 141 size_t length = fStream->getLength();
142 if (0 == length) { 142 if (length) {
143 return NULL; 143 fData = fStream->readIntoData(length);
144 } 144 }
145 fData = SkData::NewUninitialized(length);
146 SkCheckResult(fStream->read(fData->writable_data(), length), length);
147 } 145 }
148 return SkRef(fData); 146 return SkSafeRef(fData);
149 } 147 }
150 148
151 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, 149 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info,
152 void* pixels, size_t rowBytes, 150 void* pixels, size_t rowBytes,
153 SkPMColor ctableEntries[], int* ctableC ount) { 151 SkPMColor ctableEntries[], int* ctableC ount) {
154 if (fInfo != info) { 152 if (fInfo != info) {
155 // The caller has specified a different info. This is an 153 // The caller has specified a different info. This is an
156 // error for this kind of SkImageGenerator. Use the Options 154 // error for this kind of SkImageGenerator. Use the Options
157 // to change the settings. 155 // to change the settings.
158 return false; 156 return false;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 SkStreamRewindable* stream, 273 SkStreamRewindable* stream,
276 const SkDecodingImageGenerator::Options& opts) { 274 const SkDecodingImageGenerator::Options& opts) {
277 SkASSERT(stream != NULL); 275 SkASSERT(stream != NULL);
278 SkASSERT(stream->unique()); 276 SkASSERT(stream->unique());
279 if ((stream == NULL) || !stream->unique()) { 277 if ((stream == NULL) || !stream->unique()) {
280 SkSafeUnref(stream); 278 SkSafeUnref(stream);
281 return NULL; 279 return NULL;
282 } 280 }
283 return CreateDecodingImageGenerator(NULL, stream, opts); 281 return CreateDecodingImageGenerator(NULL, stream, opts);
284 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698