| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "platform/graphics/DecodingImageGenerator.h" | 26 #include "platform/graphics/DecodingImageGenerator.h" |
| 27 | 27 |
| 28 #include "platform/PlatformInstrumentation.h" | 28 #include "platform/PlatformInstrumentation.h" |
| 29 #include "platform/SharedBuffer.h" | 29 #include "platform/SharedBuffer.h" |
| 30 #include "platform/TraceEvent.h" | 30 #include "platform/TraceEvent.h" |
| 31 #include "platform/graphics/ImageFrameGenerator.h" | 31 #include "platform/graphics/ImageFrameGenerator.h" |
| 32 #include "platform/image-decoders/ImageDecoder.h" | 32 #include "platform/image-decoders/ImageDecoder.h" |
| 33 #include "platform/image-decoders/SegmentReader.h" |
| 33 #include "third_party/skia/include/core/SkData.h" | 34 #include "third_party/skia/include/core/SkData.h" |
| 34 | 35 |
| 35 namespace blink { | 36 namespace blink { |
| 36 | 37 |
| 37 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f
rameGenerator, const SkImageInfo& info, size_t index) | 38 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f
rameGenerator, const SkImageInfo& info, PassRefPtr<SegmentReader> data, bool all
DataReceived, size_t index) |
| 38 : SkImageGenerator(info) | 39 : SkImageGenerator(info) |
| 39 , m_frameGenerator(frameGenerator) | 40 , m_frameGenerator(frameGenerator) |
| 41 , m_data(data) |
| 42 , m_allDataReceived(allDataReceived) |
| 40 , m_frameIndex(index) | 43 , m_frameIndex(index) |
| 41 , m_generationId(0) | 44 , m_generationId(0) |
| 42 , m_canYUVDecode(false) | 45 , m_canYUVDecode(false) |
| 43 { | 46 { |
| 44 } | 47 } |
| 45 | 48 |
| 46 DecodingImageGenerator::~DecodingImageGenerator() | 49 DecodingImageGenerator::~DecodingImageGenerator() |
| 47 { | 50 { |
| 48 } | 51 } |
| 49 | 52 |
| 50 SkData* DecodingImageGenerator::onRefEncodedData() | 53 SkData* DecodingImageGenerator::onRefEncodedData() |
| 51 { | 54 { |
| 52 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); | 55 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); |
| 53 | 56 |
| 54 return m_frameGenerator->refEncodedData(); | 57 return m_allDataReceived ? m_data->getAsSkData().leakRef() : nullptr; |
| 55 } | 58 } |
| 56 | 59 |
| 57 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
size_t rowBytes, SkPMColor table[], int* tableCount) | 60 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
size_t rowBytes, SkPMColor table[], int* tableCount) |
| 58 { | 61 { |
| 59 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st
atic_cast<int>(m_frameIndex)); | 62 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st
atic_cast<int>(m_frameIndex)); |
| 60 | 63 |
| 61 // Implementation doesn't support scaling yet so make sure we're not given a
different size. | 64 // Implementation doesn't support scaling yet so make sure we're not given a
different size. |
| 62 if (info.width() != getInfo().width() || info.height() != getInfo().height()
) | 65 if (info.width() != getInfo().width() || info.height() != getInfo().height()
) |
| 63 return false; | 66 return false; |
| 64 | 67 |
| 65 if (info.colorType() != getInfo().colorType()) { | 68 if (info.colorType() != getInfo().colorType()) { |
| 66 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkA
lphaType after fully decoding the image frame, | 69 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkA
lphaType after fully decoding the image frame, |
| 67 // so if we see a request for opaque, that is ok even if our initial alp
ha type was not opaque. | 70 // so if we see a request for opaque, that is ok even if our initial alp
ha type was not opaque. |
| 68 return false; | 71 return false; |
| 69 } | 72 } |
| 70 | 73 |
| 71 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); | 74 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
| 72 bool decoded = m_frameGenerator->decodeAndScale(m_frameIndex, getInfo(), pix
els, rowBytes); | 75 bool decoded = m_frameGenerator->decodeAndScale(m_data.get(), m_allDataRecei
ved, m_frameIndex, getInfo(), pixels, rowBytes); |
| 73 PlatformInstrumentation::didDecodeLazyPixelRef(); | 76 PlatformInstrumentation::didDecodeLazyPixelRef(); |
| 74 | 77 |
| 75 return decoded; | 78 return decoded; |
| 76 } | 79 } |
| 77 | 80 |
| 78 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpac
e* colorSpace) const | 81 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpac
e* colorSpace) const |
| 79 { | 82 { |
| 80 if (!m_canYUVDecode) | 83 // YUV decoding does not currently support progressive decoding. See comment
in ImageFrameGenerator.h. |
| 84 if (!m_canYUVDecode || !m_allDataReceived) |
| 81 return false; | 85 return false; |
| 82 | 86 |
| 83 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", static_c
ast<int>(m_frameIndex)); | 87 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", static_c
ast<int>(m_frameIndex)); |
| 84 | 88 |
| 85 if (colorSpace) | 89 if (colorSpace) |
| 86 *colorSpace = kJPEG_SkYUVColorSpace; | 90 *colorSpace = kJPEG_SkYUVColorSpace; |
| 87 | 91 |
| 88 return m_frameGenerator->getYUVComponentSizes(sizeInfo); | 92 return m_frameGenerator->getYUVComponentSizes(m_data.get(), sizeInfo); |
| 89 } | 93 } |
| 90 | 94 |
| 91 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void
* planes[3]) | 95 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void
* planes[3]) |
| 92 { | 96 { |
| 93 ASSERT(m_canYUVDecode); | 97 // YUV decoding does not currently support progressive decoding. See comment
in ImageFrameGenerator.h. |
| 98 ASSERT(m_canYUVDecode && m_allDataReceived); |
| 94 | 99 |
| 95 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index"
, static_cast<int>(m_frameIndex)); | 100 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index"
, static_cast<int>(m_frameIndex)); |
| 96 | 101 |
| 97 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); | 102 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
| 98 bool decoded = m_frameGenerator->decodeToYUV(m_frameIndex, sizeInfo.fSizes,
planes, sizeInfo.fWidthBytes); | 103 bool decoded = m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, siz
eInfo.fSizes, planes, sizeInfo.fWidthBytes); |
| 99 PlatformInstrumentation::didDecodeLazyPixelRef(); | 104 PlatformInstrumentation::didDecodeLazyPixelRef(); |
| 100 | 105 |
| 101 return decoded; | 106 return decoded; |
| 102 } | 107 } |
| 103 | 108 |
| 104 SkImageGenerator* DecodingImageGenerator::create(SkData* data) | 109 SkImageGenerator* DecodingImageGenerator::create(SkData* data) |
| 105 { | 110 { |
| 106 RefPtr<SharedBuffer> buffer = SharedBuffer::create(data->bytes(), data->size
()); | |
| 107 | |
| 108 // We just need the size of the image, so we have to temporarily create an I
mageDecoder. Since | 111 // We just need the size of the image, so we have to temporarily create an I
mageDecoder. Since |
| 109 // we only need the size, it doesn't really matter about premul or not, or g
amma settings. | 112 // we only need the size, it doesn't really matter about premul or not, or g
amma settings. |
| 110 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*buffer.get(), ImageDeco
der::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); | 113 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(static_cast<const char*>
(data->data()), data->size(), |
| 114 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl
ied); |
| 111 if (!decoder) | 115 if (!decoder) |
| 112 return 0; | 116 return 0; |
| 113 | 117 |
| 114 decoder->setData(buffer.get(), true); | 118 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(data); |
| 119 decoder->setData(segmentReader.get(), true); |
| 115 if (!decoder->isSizeAvailable()) | 120 if (!decoder->isSizeAvailable()) |
| 116 return 0; | 121 return 0; |
| 117 | 122 |
| 118 const IntSize size = decoder->size(); | 123 const IntSize size = decoder->size(); |
| 119 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh
t()); | 124 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh
t()); |
| 120 | 125 |
| 121 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak
e(size.width(), size.height()), buffer, true, false); | 126 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak
e(size.width(), size.height()), false); |
| 122 if (!frame) | 127 if (!frame) |
| 123 return 0; | 128 return 0; |
| 124 | 129 |
| 125 return new DecodingImageGenerator(frame, info, 0); | 130 return new DecodingImageGenerator(frame, info, segmentReader.release(), true
, 0); |
| 126 } | 131 } |
| 127 | 132 |
| 128 } // namespace blink | 133 } // namespace blink |
| OLD | NEW |