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 existingData(pixelRef->refEncodedData()); | 189 SkAutoDataUnref encodedData(pixelRef->refEncodedData()); |
190 if (existingData.get() != nullptr) { | 190 if (encodedData) { |
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 || fPixelSerializer->useEncodedData(existingDa
ta->data(), | 193 if (fPixelSerializer) { |
194 existingDa
ta->size())) { | 194 encodedData.reset(fPixelSerializer->reencodeData(encodedData)); |
195 write_encoded_bitmap(this, existingData, bitmap.pixelRefOrigin()
); | 195 } |
| 196 if (encodedData) { |
| 197 write_encoded_bitmap(this, encodedData, bitmap.pixelRefOrigin())
; |
196 return; | 198 return; |
197 } | 199 } |
198 } | 200 } |
199 | 201 |
200 // see if the caller wants to manually encode | 202 // see if the caller wants to manually encode |
201 SkAutoPixmapUnlock result; | 203 SkAutoPixmapUnlock result; |
202 if (fPixelSerializer && bitmap.requestLock(&result)) { | 204 if (fPixelSerializer && bitmap.requestLock(&result)) { |
203 const SkPixmap& pmap = result.pixmap(); | |
204 SkASSERT(nullptr == fBitmapHeap); | 205 SkASSERT(nullptr == fBitmapHeap); |
205 SkAutoDataUnref data(fPixelSerializer->encodePixels(pmap.info(), | 206 SkAutoDataUnref data(fPixelSerializer->encodePixels(result.pixmap())
); |
206 pmap.addr(), | 207 if (data) { |
207 pmap.rowBytes())
); | |
208 if (data.get() != nullptr) { | |
209 // if we have to "encode" the bitmap, then we assume there is no | 208 // if we have to "encode" the bitmap, then we assume there is no |
210 // offset to share, since we are effectively creating a new pixe
lref | 209 // offset to share, since we are effectively creating a new pixe
lref |
211 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); | 210 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); |
212 return; | 211 return; |
213 } | 212 } |
214 } | 213 } |
215 } | 214 } |
216 | 215 |
217 this->writeUInt(0); // signal raw pixels | 216 this->writeUInt(0); // signal raw pixels |
218 SkBitmap::WriteRawPixels(this, bitmap); | 217 SkBitmap::WriteRawPixels(this, bitmap); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // make room for the size of the flattened object | 333 // make room for the size of the flattened object |
335 (void)fWriter.reserve(sizeof(uint32_t)); | 334 (void)fWriter.reserve(sizeof(uint32_t)); |
336 // record the current size, so we can subtract after the object writes. | 335 // record the current size, so we can subtract after the object writes. |
337 size_t offset = fWriter.bytesWritten(); | 336 size_t offset = fWriter.bytesWritten(); |
338 // now flatten the object | 337 // now flatten the object |
339 flattenable->flatten(*this); | 338 flattenable->flatten(*this); |
340 size_t objSize = fWriter.bytesWritten() - offset; | 339 size_t objSize = fWriter.bytesWritten() - offset; |
341 // record the obj's size | 340 // record the obj's size |
342 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); | 341 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); |
343 } | 342 } |
OLD | NEW |