OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkMallocPixelRef.h" | 8 #include "SkMallocPixelRef.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 193 } |
194 | 194 |
195 void SkMallocPixelRef::onUnlockPixels() { | 195 void SkMallocPixelRef::onUnlockPixels() { |
196 // nothing to do | 196 // nothing to do |
197 } | 197 } |
198 | 198 |
199 size_t SkMallocPixelRef::getAllocatedSizeInBytes() const { | 199 size_t SkMallocPixelRef::getAllocatedSizeInBytes() const { |
200 return this->info().getSafeSize(fRB); | 200 return this->info().getSafeSize(fRB); |
201 } | 201 } |
202 | 202 |
203 void SkMallocPixelRef::flatten(SkWriteBuffer& buffer) const { | 203 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE |
204 this->INHERITED::flatten(buffer); | |
205 | |
206 buffer.write32(SkToU32(fRB)); | |
207 | |
208 // TODO: replace this bulk write with a chunky one that can trim off any | |
209 // trailing bytes on each scanline (in case rowbytes > width*size) | |
210 size_t size = this->info().getSafeSize(fRB); | |
211 buffer.writeByteArray(fStorage, size); | |
212 buffer.writeBool(fCTable != NULL); | |
213 if (fCTable) { | |
214 fCTable->writeToBuffer(buffer); | |
215 } | |
216 } | |
217 | |
218 SkMallocPixelRef::SkMallocPixelRef(SkReadBuffer& buffer) | 204 SkMallocPixelRef::SkMallocPixelRef(SkReadBuffer& buffer) |
219 : INHERITED(buffer, NULL) | 205 : INHERITED(buffer, NULL) |
220 , fReleaseProc(sk_free_releaseproc) | 206 , fReleaseProc(sk_free_releaseproc) |
221 , fReleaseProcContext(NULL) | 207 , fReleaseProcContext(NULL) |
222 { | 208 { |
223 fRB = buffer.read32(); | 209 fRB = buffer.read32(); |
224 size_t size = buffer.isValid() ? this->info().getSafeSize(fRB) : 0; | 210 size_t size = buffer.isValid() ? this->info().getSafeSize(fRB) : 0; |
225 if (buffer.validateAvailable(size)) { | 211 if (buffer.validateAvailable(size)) { |
226 fStorage = sk_malloc_throw(size); | 212 fStorage = sk_malloc_throw(size); |
227 buffer.readByteArray(fStorage, size); | 213 buffer.readByteArray(fStorage, size); |
228 } else { | 214 } else { |
229 fStorage = NULL; | 215 fStorage = NULL; |
230 } | 216 } |
231 | 217 |
232 if (buffer.readBool()) { | 218 if (buffer.readBool()) { |
233 fCTable = SkNEW_ARGS(SkColorTable, (buffer)); | 219 fCTable = SkNEW_ARGS(SkColorTable, (buffer)); |
234 } else { | 220 } else { |
235 fCTable = NULL; | 221 fCTable = NULL; |
236 } | 222 } |
237 | 223 |
238 this->setPreLocked(fStorage, fRB, fCTable); | 224 this->setPreLocked(fStorage, fRB, fCTable); |
239 } | 225 } |
| 226 #endif |
240 | 227 |
241 /////////////////////////////////////////////////////////////////////////////// | 228 /////////////////////////////////////////////////////////////////////////////// |
242 | 229 |
243 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t
rowBytes, | 230 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, size_t
rowBytes, |
244 SkColorTable* ctable) { | 231 SkColorTable* ctable) { |
245 return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable); | 232 return SkMallocPixelRef::NewAllocate(info, rowBytes, ctable); |
246 } | 233 } |
OLD | NEW |