Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/core/SkWriteBuffer.cpp

Issue 1310633006: Add a SkPixelSerializer SkImage encode variant (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: moar comment tweaks Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkImage.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) { 221 void SkWriteBuffer::writeImage(const SkImage* image) {
233 this->writeInt(image->width()); 222 this->writeInt(image->width());
234 this->writeInt(image->height()); 223 this->writeInt(image->height());
235 224
236 SkAutoTUnref<SkData> encoded(image->refEncoded()); 225 SkAutoTUnref<SkData> encoded(image->encode(this->getPixelSerializer()));
237 if (encoded && try_write_encoded(this, encoded)) { 226 if (encoded) {
227 write_encoded_bitmap(this, encoded, SkIPoint::Make(0, 0));
238 return; 228 return;
239 } 229 }
240 230
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) 231 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data)
247 } 232 }
248 233
249 void SkWriteBuffer::writeTypeface(SkTypeface* obj) { 234 void SkWriteBuffer::writeTypeface(SkTypeface* obj) {
250 if (nullptr == obj || nullptr == fTFSet) { 235 if (nullptr == obj || nullptr == fTFSet) {
251 fWriter.write32(0); 236 fWriter.write32(0);
252 } else { 237 } else {
253 fWriter.write32(fTFSet->add(obj)); 238 fWriter.write32(fTFSet->add(obj));
254 } 239 }
255 } 240 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // make room for the size of the flattened object 334 // make room for the size of the flattened object
350 (void)fWriter.reserve(sizeof(uint32_t)); 335 (void)fWriter.reserve(sizeof(uint32_t));
351 // 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.
352 size_t offset = fWriter.bytesWritten(); 337 size_t offset = fWriter.bytesWritten();
353 // now flatten the object 338 // now flatten the object
354 flattenable->flatten(*this); 339 flattenable->flatten(*this);
355 size_t objSize = fWriter.bytesWritten() - offset; 340 size_t objSize = fWriter.bytesWritten() - offset;
356 // record the obj's size 341 // record the obj's size
357 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); 342 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize));
358 } 343 }
OLDNEW
« no previous file with comments | « include/core/SkImage.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698