OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include <new> | 7 #include <new> |
8 #include "SkImageGenerator.h" | |
8 #include "SkPictureData.h" | 9 #include "SkPictureData.h" |
9 #include "SkPictureRecord.h" | 10 #include "SkPictureRecord.h" |
10 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
11 #include "SkTextBlob.h" | 12 #include "SkTextBlob.h" |
12 #include "SkTypeface.h" | 13 #include "SkTypeface.h" |
13 #include "SkWriteBuffer.h" | 14 #include "SkWriteBuffer.h" |
14 | 15 |
15 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
16 #include "GrContext.h" | 17 #include "GrContext.h" |
17 #endif | 18 #endif |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 } | 427 } |
427 if (!buffer.isValid()) { | 428 if (!buffer.isValid()) { |
428 return false; | 429 return false; |
429 } | 430 } |
430 SkDEBUGCODE(haveBuffer = true;) | 431 SkDEBUGCODE(haveBuffer = true;) |
431 } break; | 432 } break; |
432 } | 433 } |
433 return true; // success | 434 return true; // success |
434 } | 435 } |
435 | 436 |
437 namespace { | |
438 | |
439 // This generator intentionally should always fail on all attempts to get its pi xels, | |
scroggo
2015/09/04 18:48:20
FWIW, we used to show deserialize such failed enco
| |
440 // simulating a bad or empty codec stream. | |
441 class EmptyImageGenerator final : public SkImageGenerator { | |
442 public: | |
443 EmptyImageGenerator(const SkImageInfo& info) : INHERITED(info) { } | |
444 | |
445 private: | |
446 typedef SkImageGenerator INHERITED; | |
447 }; | |
448 | |
449 } // anonymous namespace | |
450 | |
436 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) { | 451 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) { |
437 int width = buffer.read32(); | 452 int width = buffer.read32(); |
438 int height = buffer.read32(); | 453 int height = buffer.read32(); |
439 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension | 454 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension |
440 buffer.validate(false); | 455 buffer.validate(false); |
441 return nullptr; | 456 return nullptr; |
442 } | 457 } |
443 | 458 |
444 SkAutoTUnref<SkData> encoded(buffer.readByteArrayAsData()); | 459 SkAutoTUnref<SkData> encoded(buffer.readByteArrayAsData()); |
460 if (encoded->size() == 0) { | |
461 // The image could not be encoded at serialization time - return an empt y placeholder. | |
462 return SkImage::NewFromGenerator( | |
463 new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))); | |
464 } | |
465 | |
445 int originX = buffer.read32(); | 466 int originX = buffer.read32(); |
446 int originY = buffer.read32(); | 467 int originY = buffer.read32(); |
447 if (0 == encoded->size() || originX < 0 || originY < 0) { | 468 if (originX < 0 || originY < 0) { |
448 buffer.validate(false); | 469 buffer.validate(false); |
449 return nullptr; | 470 return nullptr; |
450 } | 471 } |
451 | 472 |
452 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height); | 473 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height); |
453 return SkImage::NewFromEncoded(encoded, &subset); | 474 return SkImage::NewFromEncoded(encoded, &subset); |
454 } | 475 } |
455 | 476 |
456 // Need a shallow wrapper to return const SkPicture* to match the other factorie s, | 477 // Need a shallow wrapper to return const SkPicture* to match the other factorie s, |
457 // as SkPicture::CreateFromBuffer() returns SkPicture* | 478 // as SkPicture::CreateFromBuffer() returns SkPicture* |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 } | 655 } |
635 } | 656 } |
636 | 657 |
637 bool SkPictureData::suitableForLayerOptimization() const { | 658 bool SkPictureData::suitableForLayerOptimization() const { |
638 return fContentInfo.numLayers() > 0; | 659 return fContentInfo.numLayers() > 0; |
639 } | 660 } |
640 #endif | 661 #endif |
641 /////////////////////////////////////////////////////////////////////////////// | 662 /////////////////////////////////////////////////////////////////////////////// |
642 | 663 |
643 | 664 |
OLD | NEW |