| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 | 8 |
| 9 #include "SkOrderedWriteBuffer.h" | 9 #include "SkOrderedWriteBuffer.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // The generation ID is not required information. We write it to prevent
collisions | 174 // The generation ID is not required information. We write it to prevent
collisions |
| 175 // in SkFlatDictionary. It is possible to get a collision when a previo
usly | 175 // in SkFlatDictionary. It is possible to get a collision when a previo
usly |
| 176 // unflattened (i.e. stale) instance of a similar flattenable is in the
dictionary | 176 // unflattened (i.e. stale) instance of a similar flattenable is in the
dictionary |
| 177 // and the instance currently being written is re-using the same slot fr
om the | 177 // and the instance currently being written is re-using the same slot fr
om the |
| 178 // bitmap heap. | 178 // bitmap heap. |
| 179 fWriter.write32(bitmap.getGenerationID()); | 179 fWriter.write32(bitmap.getGenerationID()); |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 if (fBitmapEncoder != NULL) { | 182 if (fBitmapEncoder != NULL) { |
| 183 SkASSERT(NULL == fBitmapHeap); | 183 SkASSERT(NULL == fBitmapHeap); |
| 184 size_t offset; | 184 size_t offset = 0; |
| 185 SkAutoDataUnref data(fBitmapEncoder(&offset, bitmap)); | 185 SkAutoDataUnref data(fBitmapEncoder(&offset, bitmap)); |
| 186 if (data.get() != NULL) { | 186 if (data.get() != NULL) { |
| 187 // Write the length to indicate that the bitmap was encoded successf
ully, followed | 187 // Write the length to indicate that the bitmap was encoded successf
ully, followed |
| 188 // by the actual data. | 188 // by the actual data. |
| 189 this->writeUInt(SkToU32(data->size())); | 189 this->writeUInt(SkToU32(data->size())); |
| 190 fWriter.writePad(data->data(), data->size()); | 190 fWriter.writePad(data->data(), data->size()); |
| 191 #ifdef BUMP_PICTURE_VERSION | |
| 192 // Recording this fixes https://code.google.com/p/skia/issues/detail
?id=1301, but | |
| 193 // also requires bumping PICTURE_VERSION, so leaving out for now. | |
| 194 // Store the coordinate of the offset, rather than fPixelRefOffset,
which may be | 191 // Store the coordinate of the offset, rather than fPixelRefOffset,
which may be |
| 195 // different depending on the decoder. | 192 // different depending on the decoder. |
| 196 int32_t x, y; | 193 int32_t x, y; |
| 197 if (0 == offset || !get_upper_left_from_offset(bitmap.config(), offs
et, | 194 if (0 == offset || !get_upper_left_from_offset(bitmap.config(), offs
et, |
| 198 bitmap.rowBytes(), &x
, &y)) { | 195 bitmap.rowBytes(), &x
, &y)) { |
| 199 x = y = 0; | 196 x = y = 0; |
| 200 } | 197 } |
| 201 this->write32(x); | 198 this->write32(x); |
| 202 this->write32(y); | 199 this->write32(y); |
| 203 #endif | |
| 204 return; | 200 return; |
| 205 } | 201 } |
| 206 } | 202 } |
| 207 // Bitmap was not encoded. Record a zero, implying that the reader need not
decode. | 203 // Bitmap was not encoded. Record a zero, implying that the reader need not
decode. |
| 208 this->writeUInt(0); | 204 this->writeUInt(0); |
| 209 bitmap.flatten(*this); | 205 bitmap.flatten(*this); |
| 210 } | 206 } |
| 211 | 207 |
| 212 void SkOrderedWriteBuffer::writeTypeface(SkTypeface* obj) { | 208 void SkOrderedWriteBuffer::writeTypeface(SkTypeface* obj) { |
| 213 if (NULL == obj || NULL == fTFSet) { | 209 if (NULL == obj || NULL == fTFSet) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // make room for the size of the flattened object | 305 // make room for the size of the flattened object |
| 310 (void)fWriter.reserve(sizeof(uint32_t)); | 306 (void)fWriter.reserve(sizeof(uint32_t)); |
| 311 // record the current size, so we can subtract after the object writes. | 307 // record the current size, so we can subtract after the object writes. |
| 312 uint32_t offset = fWriter.size(); | 308 uint32_t offset = fWriter.size(); |
| 313 // now flatten the object | 309 // now flatten the object |
| 314 flattenObject(flattenable, *this); | 310 flattenObject(flattenable, *this); |
| 315 uint32_t objSize = fWriter.size() - offset; | 311 uint32_t objSize = fWriter.size() - offset; |
| 316 // record the obj's size | 312 // record the obj's size |
| 317 *fWriter.peek32(offset - sizeof(uint32_t)) = objSize; | 313 *fWriter.peek32(offset - sizeof(uint32_t)) = objSize; |
| 318 } | 314 } |
| OLD | NEW |