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 "SkFlattenableBuffers.h" | 10 #include "SkReadBuffer.h" |
| 11 #include "SkWriteBuffer.h" |
11 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
12 #include "SkStream.h" | 13 #include "SkStream.h" |
13 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
14 #include "SkThread.h" | 15 #include "SkThread.h" |
15 | 16 |
16 //#define DUMP_IMAGEREF_LIFECYCLE | 17 //#define DUMP_IMAGEREF_LIFECYCLE |
17 | 18 |
18 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
19 | 20 |
20 SkImageRef::SkImageRef(const SkImageInfo& info, SkStreamRewindable* stream, | 21 SkImageRef::SkImageRef(const SkImageInfo& info, SkStreamRewindable* stream, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 size = fBitmap.getSize(); | 156 size = fBitmap.getSize(); |
156 if (fBitmap.getColorTable()) { | 157 if (fBitmap.getColorTable()) { |
157 size += fBitmap.getColorTable()->count() * sizeof(SkPMColor); | 158 size += fBitmap.getColorTable()->count() * sizeof(SkPMColor); |
158 } | 159 } |
159 } | 160 } |
160 return size; | 161 return size; |
161 } | 162 } |
162 | 163 |
163 /////////////////////////////////////////////////////////////////////////////// | 164 /////////////////////////////////////////////////////////////////////////////// |
164 | 165 |
165 SkImageRef::SkImageRef(SkFlattenableReadBuffer& buffer, SkBaseMutex* mutex) | 166 SkImageRef::SkImageRef(SkReadBuffer& buffer, SkBaseMutex* mutex) |
166 : INHERITED(buffer, mutex), fErrorInDecoding(false) { | 167 : INHERITED(buffer, mutex), fErrorInDecoding(false) { |
167 fSampleSize = buffer.readInt(); | 168 fSampleSize = buffer.readInt(); |
168 fDoDither = buffer.readBool(); | 169 fDoDither = buffer.readBool(); |
169 | 170 |
170 size_t length = buffer.getArrayCount(); | 171 size_t length = buffer.getArrayCount(); |
171 if (buffer.validateAvailable(length)) { | 172 if (buffer.validateAvailable(length)) { |
172 fStream = SkNEW_ARGS(SkMemoryStream, (length)); | 173 fStream = SkNEW_ARGS(SkMemoryStream, (length)); |
173 buffer.readByteArray((void*)fStream->getMemoryBase(), length); | 174 buffer.readByteArray((void*)fStream->getMemoryBase(), length); |
174 } else { | 175 } else { |
175 fStream = NULL; | 176 fStream = NULL; |
176 } | 177 } |
177 | 178 |
178 fPrev = fNext = NULL; | 179 fPrev = fNext = NULL; |
179 fFactory = NULL; | 180 fFactory = NULL; |
180 } | 181 } |
181 | 182 |
182 void SkImageRef::flatten(SkFlattenableWriteBuffer& buffer) const { | 183 void SkImageRef::flatten(SkWriteBuffer& buffer) const { |
183 this->INHERITED::flatten(buffer); | 184 this->INHERITED::flatten(buffer); |
184 | 185 |
185 buffer.writeInt(fSampleSize); | 186 buffer.writeInt(fSampleSize); |
186 buffer.writeBool(fDoDither); | 187 buffer.writeBool(fDoDither); |
187 // FIXME: Consider moving this logic should go into writeStream itself. | 188 // FIXME: Consider moving this logic should go into writeStream itself. |
188 // writeStream currently has no other callers, so this may be fine for | 189 // writeStream currently has no other callers, so this may be fine for |
189 // now. | 190 // now. |
190 if (!fStream->rewind()) { | 191 if (!fStream->rewind()) { |
191 SkDEBUGF(("Failed to rewind SkImageRef stream!")); | 192 SkDEBUGF(("Failed to rewind SkImageRef stream!")); |
192 buffer.write32(0); | 193 buffer.write32(0); |
193 } else { | 194 } else { |
194 // FIXME: Handle getLength properly here. Perhaps this class should | 195 // FIXME: Handle getLength properly here. Perhaps this class should |
195 // take an SkStreamAsset. | 196 // take an SkStreamAsset. |
196 buffer.writeStream(fStream, fStream->getLength()); | 197 buffer.writeStream(fStream, fStream->getLength()); |
197 } | 198 } |
198 } | 199 } |
OLD | NEW |