| 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 "SkWriteBuffer.h" | 9 #include "SkWriteBuffer.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // unflattened (i.e. stale) instance of a similar flattenable is in the
dictionary | 179 // unflattened (i.e. stale) instance of a similar flattenable is in the
dictionary |
| 180 // and the instance currently being written is re-using the same slot fr
om the | 180 // and the instance currently being written is re-using the same slot fr
om the |
| 181 // bitmap heap. | 181 // bitmap heap. |
| 182 fWriter.write32(bitmap.getGenerationID()); | 182 fWriter.write32(bitmap.getGenerationID()); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 | 185 |
| 186 SkPixelRef* pixelRef = bitmap.pixelRef(); | 186 SkPixelRef* pixelRef = bitmap.pixelRef(); |
| 187 if (pixelRef) { | 187 if (pixelRef) { |
| 188 // see if the pixelref already has an encoded version | 188 // see if the pixelref already has an encoded version |
| 189 SkAutoDataUnref encodedData(pixelRef->refEncodedData()); | 189 SkAutoDataUnref existingData(pixelRef->refEncodedData()); |
| 190 if (encodedData) { | 190 if (existingData.get() != nullptr) { |
| 191 // Assumes that if the client did not set a serializer, they are | 191 // Assumes that if the client did not set a serializer, they are |
| 192 // happy to get the encoded data. | 192 // happy to get the encoded data. |
| 193 if (fPixelSerializer) { | 193 if (!fPixelSerializer || fPixelSerializer->useEncodedData(existingDa
ta->data(), |
| 194 encodedData.reset(fPixelSerializer->reencodeData(encodedData)); | 194 existingDa
ta->size())) { |
| 195 } | 195 write_encoded_bitmap(this, existingData, bitmap.pixelRefOrigin()
); |
| 196 if (encodedData) { | |
| 197 write_encoded_bitmap(this, encodedData, bitmap.pixelRefOrigin())
; | |
| 198 return; | 196 return; |
| 199 } | 197 } |
| 200 } | 198 } |
| 201 | 199 |
| 202 // see if the caller wants to manually encode | 200 // see if the caller wants to manually encode |
| 203 SkAutoPixmapUnlock result; | 201 SkAutoPixmapUnlock result; |
| 204 if (fPixelSerializer && bitmap.requestLock(&result)) { | 202 if (fPixelSerializer && bitmap.requestLock(&result)) { |
| 203 const SkPixmap& pmap = result.pixmap(); |
| 205 SkASSERT(nullptr == fBitmapHeap); | 204 SkASSERT(nullptr == fBitmapHeap); |
| 206 SkAutoDataUnref data(fPixelSerializer->encodePixels(result.pixmap())
); | 205 SkAutoDataUnref data(fPixelSerializer->encodePixels(pmap.info(), |
| 207 if (data) { | 206 pmap.addr(), |
| 207 pmap.rowBytes())
); |
| 208 if (data.get() != nullptr) { |
| 208 // if we have to "encode" the bitmap, then we assume there is no | 209 // if we have to "encode" the bitmap, then we assume there is no |
| 209 // offset to share, since we are effectively creating a new pixe
lref | 210 // offset to share, since we are effectively creating a new pixe
lref |
| 210 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); | 211 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); |
| 211 return; | 212 return; |
| 212 } | 213 } |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 this->writeUInt(0); // signal raw pixels | 217 this->writeUInt(0); // signal raw pixels |
| 217 SkBitmap::WriteRawPixels(this, bitmap); | 218 SkBitmap::WriteRawPixels(this, bitmap); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // make room for the size of the flattened object | 334 // make room for the size of the flattened object |
| 334 (void)fWriter.reserve(sizeof(uint32_t)); | 335 (void)fWriter.reserve(sizeof(uint32_t)); |
| 335 // record the current size, so we can subtract after the object writes. | 336 // record the current size, so we can subtract after the object writes. |
| 336 size_t offset = fWriter.bytesWritten(); | 337 size_t offset = fWriter.bytesWritten(); |
| 337 // now flatten the object | 338 // now flatten the object |
| 338 flattenable->flatten(*this); | 339 flattenable->flatten(*this); |
| 339 size_t objSize = fWriter.bytesWritten() - offset; | 340 size_t objSize = fWriter.bytesWritten() - offset; |
| 340 // record the obj's size | 341 // record the obj's size |
| 341 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); | 342 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); |
| 342 } | 343 } |
| OLD | NEW |