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 "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 (info, addr, rowBytes, ctable, NULL, NULL)); | 48 (info, addr, rowBytes, ctable, NULL, NULL)); |
49 } | 49 } |
50 | 50 |
51 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info, | 51 SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info, |
52 size_t requestedRowBytes, | 52 size_t requestedRowBytes, |
53 SkColorTable* ctable) { | 53 SkColorTable* ctable) { |
54 if (!is_valid(info, ctable)) { | 54 if (!is_valid(info, ctable)) { |
55 return NULL; | 55 return NULL; |
56 } | 56 } |
57 | 57 |
58 int32_t minRB = info.minRowBytes(); | 58 int32_t minRB = SkToS32(info.minRowBytes()); |
59 if (minRB < 0) { | 59 if (minRB < 0) { |
60 return NULL; // allocation will be too large | 60 return NULL; // allocation will be too large |
61 } | 61 } |
62 if (requestedRowBytes > 0 && (int32_t)requestedRowBytes < minRB) { | 62 if (requestedRowBytes > 0 && (int32_t)requestedRowBytes < minRB) { |
63 return NULL; // cannot meet requested rowbytes | 63 return NULL; // cannot meet requested rowbytes |
64 } | 64 } |
65 | 65 |
66 int32_t rowBytes; | 66 int32_t rowBytes; |
67 if (requestedRowBytes) { | 67 if (requestedRowBytes) { |
68 rowBytes = requestedRowBytes; | 68 rowBytes = SkToS32(requestedRowBytes); |
69 } else { | 69 } else { |
70 rowBytes = minRB; | 70 rowBytes = minRB; |
71 } | 71 } |
72 | 72 |
73 int64_t bigSize = (int64_t)info.fHeight * rowBytes; | 73 int64_t bigSize = (int64_t)info.fHeight * rowBytes; |
74 if (!sk_64_isS32(bigSize)) { | 74 if (!sk_64_isS32(bigSize)) { |
75 return NULL; | 75 return NULL; |
76 } | 76 } |
77 | 77 |
78 size_t size = sk_64_asS32(bigSize); | 78 size_t size = sk_64_asS32(bigSize); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // nothing to do | 197 // nothing to do |
198 } | 198 } |
199 | 199 |
200 size_t SkMallocPixelRef::getAllocatedSizeInBytes() const { | 200 size_t SkMallocPixelRef::getAllocatedSizeInBytes() const { |
201 return this->info().getSafeSize(fRB); | 201 return this->info().getSafeSize(fRB); |
202 } | 202 } |
203 | 203 |
204 void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { | 204 void SkMallocPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const { |
205 this->INHERITED::flatten(buffer); | 205 this->INHERITED::flatten(buffer); |
206 | 206 |
207 buffer.write32(fRB); | 207 buffer.write32(SkToU32(fRB)); |
208 | 208 |
209 // TODO: replace this bulk write with a chunky one that can trim off any | 209 // TODO: replace this bulk write with a chunky one that can trim off any |
210 // trailing bytes on each scanline (in case rowbytes > width*size) | 210 // trailing bytes on each scanline (in case rowbytes > width*size) |
211 size_t size = this->info().getSafeSize(fRB); | 211 size_t size = this->info().getSafeSize(fRB); |
212 buffer.writeByteArray(fStorage, size); | 212 buffer.writeByteArray(fStorage, size); |
213 buffer.writeBool(fCTable != NULL); | 213 buffer.writeBool(fCTable != NULL); |
214 if (fCTable) { | 214 if (fCTable) { |
215 fCTable->writeToBuffer(buffer); | 215 fCTable->writeToBuffer(buffer); |
216 } | 216 } |
217 } | 217 } |
(...skipping 21 matching lines...) Expand all Loading... |
239 this->setPreLocked(fStorage, fRB, fCTable); | 239 this->setPreLocked(fStorage, fRB, fCTable); |
240 } | 240 } |
241 | 241 |
242 /////////////////////////////////////////////////////////////////////////////// | 242 /////////////////////////////////////////////////////////////////////////////// |
243 | 243 |
244 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, | 244 SkPixelRef* SkMallocPixelRef::PRFactory::create(const SkImageInfo& info, |
245 SkColorTable* ctable) { | 245 SkColorTable* ctable) { |
246 return SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), ctable); | 246 return SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), ctable); |
247 } | 247 } |
248 | 248 |
OLD | NEW |