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 class EmptyImageGenerator final : public SkImageGenerator { | |
reed1
2015/09/04 18:17:27
// This guy intentionally should always fail on al
f(malita)
2015/09/04 18:23:54
Done.
| |
440 public: | |
441 EmptyImageGenerator(const SkImageInfo& info) : INHERITED(info) { } | |
442 | |
443 private: | |
444 typedef SkImageGenerator INHERITED; | |
445 }; | |
446 | |
447 } // anonymous namespace | |
448 | |
436 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) { | 449 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) { |
437 int width = buffer.read32(); | 450 int width = buffer.read32(); |
438 int height = buffer.read32(); | 451 int height = buffer.read32(); |
439 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension | 452 if (width <= 0 || height <= 0) { // SkImage never has a zero dimension |
440 buffer.validate(false); | 453 buffer.validate(false); |
441 return nullptr; | 454 return nullptr; |
442 } | 455 } |
443 | 456 |
444 SkAutoTUnref<SkData> encoded(buffer.readByteArrayAsData()); | 457 SkAutoTUnref<SkData> encoded(buffer.readByteArrayAsData()); |
458 if (encoded->size() == 0) { | |
459 // The image could not be encoded at serialization time - return an empt y placeholder. | |
460 return SkImage::NewFromGenerator( | |
461 new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))); | |
462 } | |
463 | |
445 int originX = buffer.read32(); | 464 int originX = buffer.read32(); |
446 int originY = buffer.read32(); | 465 int originY = buffer.read32(); |
447 if (0 == encoded->size() || originX < 0 || originY < 0) { | 466 if (originX < 0 || originY < 0) { |
448 buffer.validate(false); | 467 buffer.validate(false); |
449 return nullptr; | 468 return nullptr; |
450 } | 469 } |
451 | 470 |
452 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height); | 471 const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height); |
453 return SkImage::NewFromEncoded(encoded, &subset); | 472 return SkImage::NewFromEncoded(encoded, &subset); |
454 } | 473 } |
455 | 474 |
456 // Need a shallow wrapper to return const SkPicture* to match the other factorie s, | 475 // Need a shallow wrapper to return const SkPicture* to match the other factorie s, |
457 // as SkPicture::CreateFromBuffer() returns SkPicture* | 476 // as SkPicture::CreateFromBuffer() returns SkPicture* |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 } | 653 } |
635 } | 654 } |
636 | 655 |
637 bool SkPictureData::suitableForLayerOptimization() const { | 656 bool SkPictureData::suitableForLayerOptimization() const { |
638 return fContentInfo.numLayers() > 0; | 657 return fContentInfo.numLayers() > 0; |
639 } | 658 } |
640 #endif | 659 #endif |
641 /////////////////////////////////////////////////////////////////////////////// | 660 /////////////////////////////////////////////////////////////////////////////// |
642 | 661 |
643 | 662 |
OLD | NEW |