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

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

Issue 2201323003: add pipecanvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add test for writeImage Created 4 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 * 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkDeduper.h"
9 #include "SkErrorInternals.h" 10 #include "SkErrorInternals.h"
10 #include "SkImage.h" 11 #include "SkImage.h"
11 #include "SkImageDeserializer.h" 12 #include "SkImageDeserializer.h"
12 #include "SkImageGenerator.h" 13 #include "SkImageGenerator.h"
13 #include "SkReadBuffer.h" 14 #include "SkReadBuffer.h"
14 #include "SkStream.h" 15 #include "SkStream.h"
15 #include "SkTypeface.h" 16 #include "SkTypeface.h"
16 17
17 namespace { 18 namespace {
18 19
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 bitmap.setImmutable(); 252 bitmap.setImmutable();
252 return SkImage::MakeFromBitmap(bitmap); 253 return SkImage::MakeFromBitmap(bitmap);
253 } 254 }
254 } 255 }
255 } 256 }
256 // Could not read the SkBitmap. Use a placeholder bitmap. 257 // Could not read the SkBitmap. Use a placeholder bitmap.
257 return nullptr; 258 return nullptr;
258 } 259 }
259 260
260 sk_sp<SkImage> SkReadBuffer::readImage() { 261 sk_sp<SkImage> SkReadBuffer::readImage() {
262 if (fInflator) {
263 SkImage* img = fInflator->getImage(this->read32());
264 return img ? sk_ref_sp(img) : nullptr;
265 }
266
261 int width = this->read32(); 267 int width = this->read32();
262 int height = this->read32(); 268 int height = this->read32();
263 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension 269 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension
264 this->validate(false); 270 this->validate(false);
265 return nullptr; 271 return nullptr;
266 } 272 }
267 273
268 uint32_t encoded_size = this->getArrayCount(); 274 uint32_t encoded_size = this->getArrayCount();
269 if (encoded_size == 0) { 275 if (encoded_size == 0) {
270 // The image could not be encoded at serialization time - return an empt y placeholder. 276 // The image could not be encoded at serialization time - return an empt y placeholder.
(...skipping 20 matching lines...) Expand all
291 return nullptr; 297 return nullptr;
292 } 298 }
293 299
294 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height); 300 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height);
295 301
296 sk_sp<SkImage> image = fImageDeserializer->makeFromData(encoded.get(), &subs et); 302 sk_sp<SkImage> image = fImageDeserializer->makeFromData(encoded.get(), &subs et);
297 return image ? image : MakeEmptyImage(width, height); 303 return image ? image : MakeEmptyImage(width, height);
298 } 304 }
299 305
300 sk_sp<SkTypeface> SkReadBuffer::readTypeface() { 306 sk_sp<SkTypeface> SkReadBuffer::readTypeface() {
307 if (fInflator) {
308 return sk_ref_sp(fInflator->getTypeface(this->read32()));
309 }
310
301 uint32_t index = fReader.readU32(); 311 uint32_t index = fReader.readU32();
302 if (0 == index || index > (unsigned)fTFCount) { 312 if (0 == index || index > (unsigned)fTFCount) {
303 return nullptr; 313 return nullptr;
304 } else { 314 } else {
305 SkASSERT(fTFArray); 315 SkASSERT(fTFArray);
306 return sk_ref_sp(fTFArray[index - 1]); 316 return sk_ref_sp(fTFArray[index - 1]);
307 } 317 }
308 } 318 }
309 319
310 SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) { 320 SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
311 // 321 //
312 // TODO: confirm that ft matches the factory we decide to use 322 // TODO: confirm that ft matches the factory we decide to use
313 // 323 //
314 324
315 SkFlattenable::Factory factory = nullptr; 325 SkFlattenable::Factory factory = nullptr;
316 326
317 if (fFactoryCount > 0) { 327 if (fInflator) {
328 factory = fInflator->getFactory(this->read32());
329 if (!factory) {
330 return nullptr;
331 }
332 } else if (fFactoryCount > 0) {
318 int32_t index = fReader.readU32(); 333 int32_t index = fReader.readU32();
319 if (0 == index) { 334 if (0 == index) {
320 return nullptr; // writer failed to give us the flattenable 335 return nullptr; // writer failed to give us the flattenable
321 } 336 }
322 index -= 1; // we stored the index-base-1 337 index -= 1; // we stored the index-base-1
323 if ((unsigned)index >= (unsigned)fFactoryCount) { 338 if ((unsigned)index >= (unsigned)fFactoryCount) {
324 this->validate(false); 339 this->validate(false);
325 return nullptr; 340 return nullptr;
326 } 341 }
327 factory = fFactoryArray[index]; 342 factory = fFactoryArray[index];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 if (sizeRecorded != sizeRead) { 382 if (sizeRecorded != sizeRead) {
368 this->validate(false); 383 this->validate(false);
369 return nullptr; 384 return nullptr;
370 } 385 }
371 } else { 386 } else {
372 // we must skip the remaining data 387 // we must skip the remaining data
373 fReader.skip(sizeRecorded); 388 fReader.skip(sizeRecorded);
374 } 389 }
375 return obj.release(); 390 return obj.release();
376 } 391 }
OLDNEW
« src/core/SkPipe.h ('K') | « src/core/SkReadBuffer.h ('k') | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698