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 "SkBitmapHeap.h" | 10 #include "SkBitmapHeap.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 129 } |
130 return bytesWritten; | 130 return bytesWritten; |
131 } | 131 } |
132 | 132 |
133 bool SkWriteBuffer::writeToStream(SkWStream* stream) { | 133 bool SkWriteBuffer::writeToStream(SkWStream* stream) { |
134 return fWriter.writeToStream(stream); | 134 return fWriter.writeToStream(stream); |
135 } | 135 } |
136 | 136 |
137 static void write_encoded_bitmap(SkWriteBuffer* buffer, SkData* data, | 137 static void write_encoded_bitmap(SkWriteBuffer* buffer, SkData* data, |
138 const SkIPoint& origin) { | 138 const SkIPoint& origin) { |
139 buffer->writeUInt(SkToU32(data->size())); | 139 buffer->writeDataAsByteArray(data); |
140 buffer->getWriter32()->writePad(data->data(), data->size()); | |
141 buffer->write32(origin.fX); | 140 buffer->write32(origin.fX); |
142 buffer->write32(origin.fY); | 141 buffer->write32(origin.fY); |
143 } | 142 } |
144 | 143 |
145 void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) { | 144 void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) { |
146 // Record the width and height. This way if readBitmap fails a dummy bitmap
can be drawn at the | 145 // Record the width and height. This way if readBitmap fails a dummy bitmap
can be drawn at the |
147 // right size. | 146 // right size. |
148 this->writeInt(bitmap.width()); | 147 this->writeInt(bitmap.width()); |
149 this->writeInt(bitmap.height()); | 148 this->writeInt(bitmap.height()); |
150 | 149 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // make room for the size of the flattened object | 309 // make room for the size of the flattened object |
311 (void)fWriter.reserve(sizeof(uint32_t)); | 310 (void)fWriter.reserve(sizeof(uint32_t)); |
312 // record the current size, so we can subtract after the object writes. | 311 // record the current size, so we can subtract after the object writes. |
313 size_t offset = fWriter.bytesWritten(); | 312 size_t offset = fWriter.bytesWritten(); |
314 // now flatten the object | 313 // now flatten the object |
315 flattenable->flatten(*this); | 314 flattenable->flatten(*this); |
316 size_t objSize = fWriter.bytesWritten() - offset; | 315 size_t objSize = fWriter.bytesWritten() - offset; |
317 // record the obj's size | 316 // record the obj's size |
318 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); | 317 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); |
319 } | 318 } |
OLD | NEW |