Chromium Code Reviews| 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 if (!m_allDataReceived) |
| 58 return nullptr; | |
| 59 | |
| 60 return m_data->getAsSkData().leakRef(); | |
|
Peter Kasting
2016/03/25 06:24:36
Nit: Shorter:
return m_allDataReceived ? m_da
scroggo
2016/03/25 15:49:52
Done.
| |
| 55 } | 61 } |
| 56 | 62 |
| 57 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount) | 63 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount) |
| 58 { | 64 { |
| 59 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st atic_cast<int>(m_frameIndex)); | 65 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st atic_cast<int>(m_frameIndex)); |
| 60 | 66 |
| 61 // Implementation doesn't support scaling yet so make sure we're not given a different size. | 67 // 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() ) | 68 if (info.width() != getInfo().width() || info.height() != getInfo().height() ) |
| 63 return false; | 69 return false; |
| 64 | 70 |
| 65 if (info.colorType() != getInfo().colorType()) { | 71 if (info.colorType() != getInfo().colorType()) { |
| 66 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkA lphaType after fully decoding the image frame, | 72 // 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. | 73 // so if we see a request for opaque, that is ok even if our initial alp ha type was not opaque. |
| 68 return false; | 74 return false; |
| 69 } | 75 } |
| 70 | 76 |
| 71 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); | 77 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
| 72 bool decoded = m_frameGenerator->decodeAndScale(m_frameIndex, getInfo(), pix els, rowBytes); | 78 bool decoded = m_frameGenerator->decodeAndScale(m_data.get(), m_allDataRecei ved, m_frameIndex, getInfo(), pixels, rowBytes); |
| 73 PlatformInstrumentation::didDecodeLazyPixelRef(); | 79 PlatformInstrumentation::didDecodeLazyPixelRef(); |
| 74 | 80 |
| 75 return decoded; | 81 return decoded; |
| 76 } | 82 } |
| 77 | 83 |
| 78 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpac e* colorSpace) const | 84 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpac e* colorSpace) const |
| 79 { | 85 { |
| 80 if (!m_canYUVDecode) | 86 // YUV decoding does not currently support progressive decoding. See comment in ImageFrameGenerator.h |
|
Peter Kasting
2016/03/25 06:24:36
Nit: Trailing period (2 places)
scroggo
2016/03/25 15:49:52
Done.
| |
| 87 if (!m_canYUVDecode || !m_allDataReceived) | |
| 81 return false; | 88 return false; |
| 82 | 89 |
| 83 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", static_c ast<int>(m_frameIndex)); | 90 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", static_c ast<int>(m_frameIndex)); |
| 84 | 91 |
| 85 if (colorSpace) | 92 if (colorSpace) |
| 86 *colorSpace = kJPEG_SkYUVColorSpace; | 93 *colorSpace = kJPEG_SkYUVColorSpace; |
| 87 | 94 |
| 88 return m_frameGenerator->getYUVComponentSizes(sizeInfo); | 95 return m_frameGenerator->getYUVComponentSizes(m_data.get(), sizeInfo); |
| 89 } | 96 } |
| 90 | 97 |
| 91 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void * planes[3]) | 98 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void * planes[3]) |
| 92 { | 99 { |
| 93 ASSERT(m_canYUVDecode); | 100 // YUV decoding does not currently support progressive decoding. See comment in ImageFrameGenerator.h |
| 101 ASSERT(m_canYUVDecode && m_allDataReceived); | |
| 94 | 102 |
| 95 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index" , static_cast<int>(m_frameIndex)); | 103 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index" , static_cast<int>(m_frameIndex)); |
| 96 | 104 |
| 97 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); | 105 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
| 98 bool decoded = m_frameGenerator->decodeToYUV(m_frameIndex, sizeInfo.fSizes, planes, sizeInfo.fWidthBytes); | 106 bool decoded = m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, siz eInfo.fSizes, planes, sizeInfo.fWidthBytes); |
| 99 PlatformInstrumentation::didDecodeLazyPixelRef(); | 107 PlatformInstrumentation::didDecodeLazyPixelRef(); |
| 100 | 108 |
| 101 return decoded; | 109 return decoded; |
| 102 } | 110 } |
| 103 | 111 |
| 104 SkImageGenerator* DecodingImageGenerator::create(SkData* data) | 112 SkImageGenerator* DecodingImageGenerator::create(SkData* data) |
| 105 { | 113 { |
| 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 | 114 // 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. | 115 // 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); | 116 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(static_cast<const char*> (data->data()), data->size(), |
| 117 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl ied); | |
| 111 if (!decoder) | 118 if (!decoder) |
| 112 return 0; | 119 return 0; |
| 113 | 120 |
| 114 decoder->setData(buffer.get(), true); | 121 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(data); |
| 122 decoder->setData(segmentReader.get(), true); | |
| 115 if (!decoder->isSizeAvailable()) | 123 if (!decoder->isSizeAvailable()) |
| 116 return 0; | 124 return 0; |
| 117 | 125 |
| 118 const IntSize size = decoder->size(); | 126 const IntSize size = decoder->size(); |
| 119 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t()); | 127 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t()); |
| 120 | 128 |
| 121 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), buffer, true, false); | 129 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), false); |
| 122 if (!frame) | 130 if (!frame) |
| 123 return 0; | 131 return 0; |
| 124 | 132 |
| 125 return new DecodingImageGenerator(frame, info, 0); | 133 return new DecodingImageGenerator(frame, info, segmentReader.release(), true , 0); |
| 126 } | 134 } |
| 127 | 135 |
| 128 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |