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