| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkWriteBuffer.h" | 8 #include "SkWriteBuffer.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // the size of the encoded data. A non-zero size signifies that encoded d
ata was written. | 137 // the size of the encoded data. A non-zero size signifies that encoded d
ata was written. |
| 138 // 2. Call SkBitmap::flatten. After writing a boolean value of false, signif
ying that a heap was | 138 // 2. Call SkBitmap::flatten. After writing a boolean value of false, signif
ying that a heap was |
| 139 // not used, write a zero to signify that the data was not encoded. | 139 // not used, write a zero to signify that the data was not encoded. |
| 140 | 140 |
| 141 // Write a bool to indicate that we did not use an SkBitmapHeap. That featur
e is deprecated. | 141 // Write a bool to indicate that we did not use an SkBitmapHeap. That featur
e is deprecated. |
| 142 this->writeBool(false); | 142 this->writeBool(false); |
| 143 | 143 |
| 144 SkPixelRef* pixelRef = bitmap.pixelRef(); | 144 SkPixelRef* pixelRef = bitmap.pixelRef(); |
| 145 if (pixelRef) { | 145 if (pixelRef) { |
| 146 // see if the pixelref already has an encoded version | 146 // see if the pixelref already has an encoded version |
| 147 SkAutoDataUnref existingData(pixelRef->refEncodedData()); | 147 sk_sp<SkData> existingData(pixelRef->refEncodedData()); |
| 148 if (existingData.get() != nullptr) { | 148 if (existingData) { |
| 149 // Assumes that if the client did not set a serializer, they are | 149 // Assumes that if the client did not set a serializer, they are |
| 150 // happy to get the encoded data. | 150 // happy to get the encoded data. |
| 151 if (!fPixelSerializer || fPixelSerializer->useEncodedData(existingDa
ta->data(), | 151 if (!fPixelSerializer || fPixelSerializer->useEncodedData(existingDa
ta->data(), |
| 152 existingDa
ta->size())) { | 152 existingDa
ta->size())) { |
| 153 write_encoded_bitmap(this, existingData, bitmap.pixelRefOrigin()
); | 153 write_encoded_bitmap(this, existingData.get(), bitmap.pixelRefOr
igin()); |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 // see if the caller wants to manually encode | 158 // see if the caller wants to manually encode |
| 159 SkAutoPixmapUnlock result; | 159 SkAutoPixmapUnlock result; |
| 160 if (fPixelSerializer && bitmap.requestLock(&result)) { | 160 if (fPixelSerializer && bitmap.requestLock(&result)) { |
| 161 SkAutoDataUnref data(fPixelSerializer->encode(result.pixmap())); | 161 sk_sp<SkData> data(fPixelSerializer->encode(result.pixmap())); |
| 162 if (data.get() != nullptr) { | 162 if (data) { |
| 163 // if we have to "encode" the bitmap, then we assume there is no | 163 // if we have to "encode" the bitmap, then we assume there is no |
| 164 // offset to share, since we are effectively creating a new pixe
lref | 164 // offset to share, since we are effectively creating a new pixe
lref |
| 165 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); | 165 write_encoded_bitmap(this, data.get(), SkIPoint::Make(0, 0)); |
| 166 return; | 166 return; |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 this->writeUInt(0); // signal raw pixels | 171 this->writeUInt(0); // signal raw pixels |
| 172 SkBitmap::WriteRawPixels(this, bitmap); | 172 SkBitmap::WriteRawPixels(this, bitmap); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void SkBinaryWriteBuffer::writeImage(const SkImage* image) { | 175 void SkBinaryWriteBuffer::writeImage(const SkImage* image) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // make room for the size of the flattened object | 275 // make room for the size of the flattened object |
| 276 (void)fWriter.reserve(sizeof(uint32_t)); | 276 (void)fWriter.reserve(sizeof(uint32_t)); |
| 277 // record the current size, so we can subtract after the object writes. | 277 // record the current size, so we can subtract after the object writes. |
| 278 size_t offset = fWriter.bytesWritten(); | 278 size_t offset = fWriter.bytesWritten(); |
| 279 // now flatten the object | 279 // now flatten the object |
| 280 flattenable->flatten(*this); | 280 flattenable->flatten(*this); |
| 281 size_t objSize = fWriter.bytesWritten() - offset; | 281 size_t objSize = fWriter.bytesWritten() - offset; |
| 282 // record the obj's size | 282 // record the obj's size |
| 283 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); | 283 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); |
| 284 } | 284 } |
| OLD | NEW |