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

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

Issue 2201323003: add pipecanvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: initial reader Created 4 years, 4 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 * 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"
11 #include "SkDeduper.h"
11 #include "SkPixelRef.h" 12 #include "SkPixelRef.h"
12 #include "SkPtrRecorder.h" 13 #include "SkPtrRecorder.h"
13 #include "SkStream.h" 14 #include "SkStream.h"
14 #include "SkTypeface.h" 15 #include "SkTypeface.h"
15 16
17 bool SkWriteBuffer::newWriteImage(const SkImage* image) {
18 if (fImageDeduper) {
19 this->write32(fImageDeduper->findOrDefine((void*)image));
20 return true;
21 }
22 return false;
23 }
24
25 bool SkWriteBuffer::newWriteTypeface(SkTypeface* typeface) {
26 if (fTypefaceDeduper) {
27 this->write32(fTypefaceDeduper->findOrDefine(typeface));
28 return true;
29 }
30 return false;
31 }
32
33 //////////////////////////////////////////////////////////////////////////////// ///////////////////
34
16 SkBinaryWriteBuffer::SkBinaryWriteBuffer(uint32_t flags) 35 SkBinaryWriteBuffer::SkBinaryWriteBuffer(uint32_t flags)
17 : fFlags(flags) 36 : fFlags(flags)
18 , fFactorySet(nullptr) 37 , fFactorySet(nullptr)
19 , fTFSet(nullptr) { 38 , fTFSet(nullptr) {
20 } 39 }
21 40
22 SkBinaryWriteBuffer::SkBinaryWriteBuffer(void* storage, size_t storageSize, uint 32_t flags) 41 SkBinaryWriteBuffer::SkBinaryWriteBuffer(void* storage, size_t storageSize, uint 32_t flags)
23 : fFlags(flags) 42 : fFlags(flags)
24 , fFactorySet(nullptr) 43 , fFactorySet(nullptr)
25 , fWriter(storage, storageSize) 44 , fWriter(storage, storageSize)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return; 185 return;
167 } 186 }
168 } 187 }
169 } 188 }
170 189
171 this->writeUInt(0); // signal raw pixels 190 this->writeUInt(0); // signal raw pixels
172 SkBitmap::WriteRawPixels(this, bitmap); 191 SkBitmap::WriteRawPixels(this, bitmap);
173 } 192 }
174 193
175 void SkBinaryWriteBuffer::writeImage(const SkImage* image) { 194 void SkBinaryWriteBuffer::writeImage(const SkImage* image) {
195 if (this->newWriteImage(image)) {
196 return;
197 }
198
176 this->writeInt(image->width()); 199 this->writeInt(image->width());
177 this->writeInt(image->height()); 200 this->writeInt(image->height());
178 201
179 sk_sp<SkData> encoded(image->encode(this->getPixelSerializer())); 202 sk_sp<SkData> encoded(image->encode(this->getPixelSerializer()));
180 if (encoded && encoded->size() > 0) { 203 if (encoded && encoded->size() > 0) {
181 write_encoded_bitmap(this, encoded.get(), SkIPoint::Make(0, 0)); 204 write_encoded_bitmap(this, encoded.get(), SkIPoint::Make(0, 0));
182 return; 205 return;
183 } 206 }
184 207
185 SkBitmap bm; 208 SkBitmap bm;
186 if (image->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode)) { 209 if (image->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode)) {
187 this->writeUInt(1); // signal raw pixels. 210 this->writeUInt(1); // signal raw pixels.
188 SkBitmap::WriteRawPixels(this, bm); 211 SkBitmap::WriteRawPixels(this, bm);
189 return; 212 return;
190 } 213 }
191 214
192 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data) 215 this->writeUInt(0); // signal no pixels (in place of the size of the encoded data)
193 } 216 }
194 217
195 void SkBinaryWriteBuffer::writeTypeface(SkTypeface* obj) { 218 void SkBinaryWriteBuffer::writeTypeface(SkTypeface* obj) {
219 if (this->newWriteTypeface(obj)) {
220 return;
221 }
222
196 if (nullptr == obj || nullptr == fTFSet) { 223 if (nullptr == obj || nullptr == fTFSet) {
197 fWriter.write32(0); 224 fWriter.write32(0);
198 } else { 225 } else {
199 fWriter.write32(fTFSet->add(obj)); 226 fWriter.write32(fTFSet->add(obj));
200 } 227 }
201 } 228 }
202 229
203 void SkBinaryWriteBuffer::writePaint(const SkPaint& paint) { 230 void SkBinaryWriteBuffer::writePaint(const SkPaint& paint) {
204 paint.flatten(*this); 231 paint.flatten(*this);
205 } 232 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // make room for the size of the flattened object 302 // make room for the size of the flattened object
276 (void)fWriter.reserve(sizeof(uint32_t)); 303 (void)fWriter.reserve(sizeof(uint32_t));
277 // record the current size, so we can subtract after the object writes. 304 // record the current size, so we can subtract after the object writes.
278 size_t offset = fWriter.bytesWritten(); 305 size_t offset = fWriter.bytesWritten();
279 // now flatten the object 306 // now flatten the object
280 flattenable->flatten(*this); 307 flattenable->flatten(*this);
281 size_t objSize = fWriter.bytesWritten() - offset; 308 size_t objSize = fWriter.bytesWritten() - offset;
282 // record the obj's size 309 // record the obj's size
283 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); 310 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize));
284 } 311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698