| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); | 211 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); |
| 212 return; | 212 return; |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 this->writeUInt(0); // signal raw pixels | 217 this->writeUInt(0); // signal raw pixels |
| 218 SkBitmap::WriteRawPixels(this, bitmap); | 218 SkBitmap::WriteRawPixels(this, bitmap); |
| 219 } | 219 } |
| 220 | 220 |
| 221 static bool try_write_encoded(SkWriteBuffer* buffer, SkData* encoded) { |
| 222 SkPixelSerializer* ps = buffer->getPixelSerializer(); |
| 223 // Assumes that if the client did not set a serializer, they are |
| 224 // happy to get the encoded data. |
| 225 if (!ps || ps->useEncodedData(encoded->data(), encoded->size())) { |
| 226 write_encoded_bitmap(buffer, encoded, SkIPoint::Make(0, 0)); |
| 227 return true; |
| 228 } |
| 229 return false; |
| 230 } |
| 231 |
| 232 void SkWriteBuffer::writeImage(const SkImage* image) { |
| 233 this->writeInt(image->width()); |
| 234 this->writeInt(image->height()); |
| 235 |
| 236 SkAutoTUnref<SkData> encoded(image->refEncoded()); |
| 237 if (encoded && try_write_encoded(this, encoded)) { |
| 238 return; |
| 239 } |
| 240 |
| 241 encoded.reset(image->encode(SkImageEncoder::kPNG_Type, 100)); |
| 242 if (encoded && try_write_encoded(this, encoded)) { |
| 243 return; |
| 244 } |
| 245 |
| 246 this->writeUInt(0); // signal no pixels (in place of the size of the encoded
data) |
| 247 } |
| 248 |
| 221 void SkWriteBuffer::writeTypeface(SkTypeface* obj) { | 249 void SkWriteBuffer::writeTypeface(SkTypeface* obj) { |
| 222 if (NULL == obj || NULL == fTFSet) { | 250 if (NULL == obj || NULL == fTFSet) { |
| 223 fWriter.write32(0); | 251 fWriter.write32(0); |
| 224 } else { | 252 } else { |
| 225 fWriter.write32(fTFSet->add(obj)); | 253 fWriter.write32(fTFSet->add(obj)); |
| 226 } | 254 } |
| 227 } | 255 } |
| 228 | 256 |
| 229 SkFactorySet* SkWriteBuffer::setFactoryRecorder(SkFactorySet* rec) { | 257 SkFactorySet* SkWriteBuffer::setFactoryRecorder(SkFactorySet* rec) { |
| 230 SkRefCnt_SafeAssign(fFactorySet, rec); | 258 SkRefCnt_SafeAssign(fFactorySet, rec); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // make room for the size of the flattened object | 349 // make room for the size of the flattened object |
| 322 (void)fWriter.reserve(sizeof(uint32_t)); | 350 (void)fWriter.reserve(sizeof(uint32_t)); |
| 323 // record the current size, so we can subtract after the object writes. | 351 // record the current size, so we can subtract after the object writes. |
| 324 size_t offset = fWriter.bytesWritten(); | 352 size_t offset = fWriter.bytesWritten(); |
| 325 // now flatten the object | 353 // now flatten the object |
| 326 flattenable->flatten(*this); | 354 flattenable->flatten(*this); |
| 327 size_t objSize = fWriter.bytesWritten() - offset; | 355 size_t objSize = fWriter.bytesWritten() - offset; |
| 328 // record the obj's size | 356 // record the obj's size |
| 329 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); | 357 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); |
| 330 } | 358 } |
| OLD | NEW |