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

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

Issue 2039813007: Add raw pixel serialization fallback for SkImages that cannot be encoded. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixed only on Mac Created 4 years, 6 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 | « src/core/SkReadBuffer.cpp ('k') | tools/dm_flags.json » ('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 * 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 void SkBinaryWriteBuffer::writeImage(const SkImage* image) { 175 void SkBinaryWriteBuffer::writeImage(const SkImage* image) {
176 this->writeInt(image->width()); 176 this->writeInt(image->width());
177 this->writeInt(image->height()); 177 this->writeInt(image->height());
178 178
179 SkAutoTUnref<SkData> encoded(image->encode(this->getPixelSerializer())); 179 SkAutoTUnref<SkData> encoded(image->encode(this->getPixelSerializer()));
180 if (encoded && encoded->size() > 0) { 180 if (encoded && encoded->size() > 0) {
181 write_encoded_bitmap(this, encoded, SkIPoint::Make(0, 0)); 181 write_encoded_bitmap(this, encoded, SkIPoint::Make(0, 0));
182 return; 182 return;
183 } 183 }
184 184
185 SkBitmap bm;
186 if (image->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode)) {
187 this->writeUInt(1); // signal raw pixels.
188 SkBitmap::WriteRawPixels(this, bm);
189 return;
190 }
191
185 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data) 192 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data)
186 } 193 }
187 194
188 void SkBinaryWriteBuffer::writeTypeface(SkTypeface* obj) { 195 void SkBinaryWriteBuffer::writeTypeface(SkTypeface* obj) {
189 if (nullptr == obj || nullptr == fTFSet) { 196 if (nullptr == obj || nullptr == fTFSet) {
190 fWriter.write32(0); 197 fWriter.write32(0);
191 } else { 198 } else {
192 fWriter.write32(fTFSet->add(obj)); 199 fWriter.write32(fTFSet->add(obj));
193 } 200 }
194 } 201 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // make room for the size of the flattened object 275 // make room for the size of the flattened object
269 (void)fWriter.reserve(sizeof(uint32_t)); 276 (void)fWriter.reserve(sizeof(uint32_t));
270 // 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.
271 size_t offset = fWriter.bytesWritten(); 278 size_t offset = fWriter.bytesWritten();
272 // now flatten the object 279 // now flatten the object
273 flattenable->flatten(*this); 280 flattenable->flatten(*this);
274 size_t objSize = fWriter.bytesWritten() - offset; 281 size_t objSize = fWriter.bytesWritten() - offset;
275 // record the obj's size 282 // record the obj's size
276 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); 283 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize));
277 } 284 }
OLDNEW
« no previous file with comments | « src/core/SkReadBuffer.cpp ('k') | tools/dm_flags.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698