Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkImageRef.h" | 8 #include "SkImageRef.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 : INHERITED(info, mutex), fErrorInDecoding(false) | 23 : INHERITED(info, mutex), fErrorInDecoding(false) |
| 24 { | 24 { |
| 25 SkASSERT(stream); | 25 SkASSERT(stream); |
| 26 stream->ref(); | 26 stream->ref(); |
| 27 fStream = stream; | 27 fStream = stream; |
| 28 fSampleSize = sampleSize; | 28 fSampleSize = sampleSize; |
| 29 fDoDither = true; | 29 fDoDither = true; |
| 30 fPrev = fNext = NULL; | 30 fPrev = fNext = NULL; |
| 31 fFactory = NULL; | 31 fFactory = NULL; |
| 32 | 32 |
| 33 // This sets the colortype/alphatype to exactly match our info, so that this | |
| 34 // can get communicated down to the codec. | |
|
scroggo
2014/02/19 20:05:43
nit: I'd find this easier to follow if it stated t
djsollen
2014/02/19 20:25:33
We actually need it to be the actual config and no
| |
| 35 fBitmap.setConfig(info); | |
| 36 | |
| 33 #ifdef DUMP_IMAGEREF_LIFECYCLE | 37 #ifdef DUMP_IMAGEREF_LIFECYCLE |
| 34 SkDebugf("add ImageRef %p [%d] data=%d\n", | 38 SkDebugf("add ImageRef %p [%d] data=%d\n", |
| 35 this, this->info().fColorType, (int)stream->getLength()); | 39 this, this->info().fColorType, (int)stream->getLength()); |
| 36 #endif | 40 #endif |
| 37 } | 41 } |
| 38 | 42 |
| 39 SkImageRef::~SkImageRef() { | 43 SkImageRef::~SkImageRef() { |
| 40 | 44 |
| 41 #ifdef DUMP_IMAGEREF_LIFECYCLE | 45 #ifdef DUMP_IMAGEREF_LIFECYCLE |
| 42 SkDebugf("delete ImageRef %p [%d] data=%d\n", | 46 SkDebugf("delete ImageRef %p [%d] data=%d\n", |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 } else { | 115 } else { |
| 112 codec = SkImageDecoder::Factory(fStream); | 116 codec = SkImageDecoder::Factory(fStream); |
| 113 } | 117 } |
| 114 | 118 |
| 115 if (codec) { | 119 if (codec) { |
| 116 SkAutoTDelete<SkImageDecoder> ad(codec); | 120 SkAutoTDelete<SkImageDecoder> ad(codec); |
| 117 | 121 |
| 118 codec->setSampleSize(fSampleSize); | 122 codec->setSampleSize(fSampleSize); |
| 119 codec->setDitherImage(fDoDither); | 123 codec->setDitherImage(fDoDither); |
| 120 if (this->onDecode(codec, fStream, &fBitmap, fBitmap.config(), mode)) { | 124 if (this->onDecode(codec, fStream, &fBitmap, fBitmap.config(), mode)) { |
| 125 if (kOpaque_SkAlphaType == fBitmap.alphaType()) { | |
| 126 this->changeAlphaType(kOpaque_SkAlphaType); | |
| 127 } | |
| 128 SkASSERT(this->info().fWidth == fBitmap.width()); | |
| 129 SkASSERT(this->info().fHeight == fBitmap.height()); | |
|
scroggo
2014/02/19 20:05:43
Also the color type?
djsollen
2014/02/19 20:12:41
Didn't put the colortype here is there is no easy
| |
| 121 return true; | 130 return true; |
| 122 } | 131 } |
| 123 } | 132 } |
| 124 | 133 |
| 125 #ifdef DUMP_IMAGEREF_LIFECYCLE | 134 #ifdef DUMP_IMAGEREF_LIFECYCLE |
| 126 if (NULL == codec) { | 135 if (NULL == codec) { |
| 127 SkDebugf("--- ImageRef: <%s> failed to find codec\n", this->getURI()); | 136 SkDebugf("--- ImageRef: <%s> failed to find codec\n", this->getURI()); |
| 128 } else { | 137 } else { |
| 129 SkDebugf("--- ImageRef: <%s> failed in codec for %d mode\n", | 138 SkDebugf("--- ImageRef: <%s> failed in codec for %d mode\n", |
| 130 this->getURI(), mode); | 139 this->getURI(), mode); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 size_t length = buffer.getArrayCount(); | 180 size_t length = buffer.getArrayCount(); |
| 172 if (buffer.validateAvailable(length)) { | 181 if (buffer.validateAvailable(length)) { |
| 173 fStream = SkNEW_ARGS(SkMemoryStream, (length)); | 182 fStream = SkNEW_ARGS(SkMemoryStream, (length)); |
| 174 buffer.readByteArray((void*)fStream->getMemoryBase(), length); | 183 buffer.readByteArray((void*)fStream->getMemoryBase(), length); |
| 175 } else { | 184 } else { |
| 176 fStream = NULL; | 185 fStream = NULL; |
| 177 } | 186 } |
| 178 | 187 |
| 179 fPrev = fNext = NULL; | 188 fPrev = fNext = NULL; |
| 180 fFactory = NULL; | 189 fFactory = NULL; |
| 190 | |
| 191 // This sets the colortype/alphatype to exactly match our info, so that this | |
| 192 // can get communicated down to the codec. | |
| 193 fBitmap.setConfig(this->info()); | |
| 181 } | 194 } |
| 182 | 195 |
| 183 void SkImageRef::flatten(SkWriteBuffer& buffer) const { | 196 void SkImageRef::flatten(SkWriteBuffer& buffer) const { |
| 184 this->INHERITED::flatten(buffer); | 197 this->INHERITED::flatten(buffer); |
| 185 | 198 |
| 186 buffer.writeInt(fSampleSize); | 199 buffer.writeInt(fSampleSize); |
| 187 buffer.writeBool(fDoDither); | 200 buffer.writeBool(fDoDither); |
| 188 // FIXME: Consider moving this logic should go into writeStream itself. | 201 // FIXME: Consider moving this logic should go into writeStream itself. |
| 189 // writeStream currently has no other callers, so this may be fine for | 202 // writeStream currently has no other callers, so this may be fine for |
| 190 // now. | 203 // now. |
| 191 if (!fStream->rewind()) { | 204 if (!fStream->rewind()) { |
| 192 SkDEBUGF(("Failed to rewind SkImageRef stream!")); | 205 SkDEBUGF(("Failed to rewind SkImageRef stream!")); |
| 193 buffer.write32(0); | 206 buffer.write32(0); |
| 194 } else { | 207 } else { |
| 195 // FIXME: Handle getLength properly here. Perhaps this class should | 208 // FIXME: Handle getLength properly here. Perhaps this class should |
| 196 // take an SkStreamAsset. | 209 // take an SkStreamAsset. |
| 197 buffer.writeStream(fStream, fStream->getLength()); | 210 buffer.writeStream(fStream, fStream->getLength()); |
| 198 } | 211 } |
| 199 } | 212 } |
| OLD | NEW |