| OLD | NEW |
| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 | 126 |
| 127 DecodingImageGenerator::~DecodingImageGenerator() { | 127 DecodingImageGenerator::~DecodingImageGenerator() { |
| 128 SkSafeUnref(fData); | 128 SkSafeUnref(fData); |
| 129 fStream->unref(); | 129 fStream->unref(); |
| 130 } | 130 } |
| 131 | 131 |
| 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 (fData != NULL) { | 135 if (NULL == fData) { |
| 136 return SkSafeRef(fData); | 136 // TODO(halcanary): SkStreamRewindable needs a refData() function |
| 137 // which returns a cheap copy of the underlying data. |
| 138 if (!fStream->rewind()) { |
| 139 return NULL; |
| 140 } |
| 141 size_t length = fStream->getLength(); |
| 142 if (0 == length) { |
| 143 return NULL; |
| 144 } |
| 145 fData = SkData::NewUninitialized(length); |
| 146 SkCheckResult(fStream->read(fData->writable_data(), length), length); |
| 137 } | 147 } |
| 138 // TODO(halcanary): SkStreamRewindable needs a refData() function | 148 return SkRef(fData); |
| 139 // which returns a cheap copy of the underlying data. | |
| 140 if (!fStream->rewind()) { | |
| 141 return NULL; | |
| 142 } | |
| 143 size_t length = fStream->getLength(); | |
| 144 if (0 == length) { | |
| 145 return NULL; | |
| 146 } | |
| 147 void* buffer = sk_malloc_flags(length, 0); | |
| 148 SkCheckResult(fStream->read(buffer, length), length); | |
| 149 fData = SkData::NewFromMalloc(buffer, length); | |
| 150 return SkSafeRef(fData); | |
| 151 } | 149 } |
| 152 | 150 |
| 153 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, | 151 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, |
| 154 void* pixels, size_t rowBytes, | 152 void* pixels, size_t rowBytes, |
| 155 SkPMColor ctableEntries[], int* ctableC
ount) { | 153 SkPMColor ctableEntries[], int* ctableC
ount) { |
| 156 if (fInfo != info) { | 154 if (fInfo != info) { |
| 157 // The caller has specified a different info. This is an | 155 // The caller has specified a different info. This is an |
| 158 // error for this kind of SkImageGenerator. Use the Options | 156 // error for this kind of SkImageGenerator. Use the Options |
| 159 // to change the settings. | 157 // to change the settings. |
| 160 return false; | 158 return false; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 SkStreamRewindable* stream, | 275 SkStreamRewindable* stream, |
| 278 const SkDecodingImageGenerator::Options& opts) { | 276 const SkDecodingImageGenerator::Options& opts) { |
| 279 SkASSERT(stream != NULL); | 277 SkASSERT(stream != NULL); |
| 280 SkASSERT(stream->unique()); | 278 SkASSERT(stream->unique()); |
| 281 if ((stream == NULL) || !stream->unique()) { | 279 if ((stream == NULL) || !stream->unique()) { |
| 282 SkSafeUnref(stream); | 280 SkSafeUnref(stream); |
| 283 return NULL; | 281 return NULL; |
| 284 } | 282 } |
| 285 return CreateDecodingImageGenerator(NULL, stream, opts); | 283 return CreateDecodingImageGenerator(NULL, stream, opts); |
| 286 } | 284 } |
| OLD | NEW |