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

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: separate encode method 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
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
225 SkPixelSerializer* ps = this->getPixelSerializer();
226
236 SkAutoTUnref<SkData> encoded(image->refEncoded()); 227 SkAutoTUnref<SkData> encoded(image->refEncoded());
237 if (encoded && try_write_encoded(this, encoded)) { 228 if (encoded && (!ps || ps->useEncodedData(encoded->data(), encoded->size())) ) {
229 // Assumes that if the client did not set a serializer, they are
230 // happy to get the encoded data.
231 write_encoded_bitmap(this, encoded, SkIPoint::Make(0, 0));
238 return; 232 return;
239 } 233 }
240 234
241 encoded.reset(image->encode(SkImageEncoder::kPNG_Type, 100)); 235 encoded.reset(image->encode(ps));
242 if (encoded && try_write_encoded(this, encoded)) { 236 if (encoded) {
237 write_encoded_bitmap(this, encoded, SkIPoint::Make(0, 0));
243 return; 238 return;
244 } 239 }
245 240
246 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data) 241 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data)
247 } 242 }
248 243
249 void SkWriteBuffer::writeTypeface(SkTypeface* obj) { 244 void SkWriteBuffer::writeTypeface(SkTypeface* obj) {
250 if (nullptr == obj || nullptr == fTFSet) { 245 if (nullptr == obj || nullptr == fTFSet) {
251 fWriter.write32(0); 246 fWriter.write32(0);
252 } else { 247 } else {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // make room for the size of the flattened object 344 // make room for the size of the flattened object
350 (void)fWriter.reserve(sizeof(uint32_t)); 345 (void)fWriter.reserve(sizeof(uint32_t));
351 // record the current size, so we can subtract after the object writes. 346 // record the current size, so we can subtract after the object writes.
352 size_t offset = fWriter.bytesWritten(); 347 size_t offset = fWriter.bytesWritten();
353 // now flatten the object 348 // now flatten the object
354 flattenable->flatten(*this); 349 flattenable->flatten(*this);
355 size_t objSize = fWriter.bytesWritten() - offset; 350 size_t objSize = fWriter.bytesWritten() - offset;
356 // record the obj's size 351 // record the obj's size
357 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); 352 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize));
358 } 353 }
OLDNEW
« include/core/SkImage.h ('K') | « include/core/SkImage.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698