Chromium Code Reviews| Index: third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp |
| diff --git a/third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp b/third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp |
| index 64d6223d6af84d4c2aaed13b95cd5ae9f5164a10..1c68086bf7700f6c7f1da84fcbfc3bb5388cf4af 100644 |
| --- a/third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp |
| +++ b/third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp |
| @@ -30,13 +30,17 @@ |
| #include "platform/TraceEvent.h" |
| #include "platform/graphics/ImageFrameGenerator.h" |
| #include "platform/image-decoders/ImageDecoder.h" |
| +#include "platform/image-decoders/SkDataSegmentReader.h" |
| #include "third_party/skia/include/core/SkData.h" |
| +#include "third_party/skia/src/core/SkRWBuffer.h" |
| namespace blink { |
| -DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> frameGenerator, const SkImageInfo& info, size_t index) |
| +DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> frameGenerator, const SkImageInfo& info, PassRefPtr<SegmentReader> data, bool allDataReceived, size_t index) |
| : SkImageGenerator(info) |
| , m_frameGenerator(frameGenerator) |
| + , m_data(data) |
| + , m_allDataReceived(allDataReceived) |
| , m_frameIndex(index) |
| , m_generationId(0) |
| , m_canYUVDecode(false) |
| @@ -51,7 +55,10 @@ SkData* DecodingImageGenerator::onRefEncodedData() |
| { |
| TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); |
| - return m_frameGenerator->refEncodedData(); |
| + if (!m_allDataReceived) |
| + return nullptr; |
| + |
| + return m_data->getAsSkData().leakRef(); |
|
scroggo_chromium
2016/03/22 20:18:41
When combined with crrev.com/1567623002 (which fir
Peter Kasting
2016/03/23 02:42:57
Can we pass this out as a smart object and thus av
f(malita)
2016/03/23 16:41:57
This is part of the SkImageGenerator interface (ca
|
| } |
| bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount) |
| @@ -69,7 +76,7 @@ bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, |
| } |
| PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
| - bool decoded = m_frameGenerator->decodeAndScale(m_frameIndex, getInfo(), pixels, rowBytes); |
| + bool decoded = m_frameGenerator->decodeAndScale(m_data.get(), m_allDataReceived, m_frameIndex, getInfo(), pixels, rowBytes); |
| PlatformInstrumentation::didDecodeLazyPixelRef(); |
| return decoded; |
| @@ -77,7 +84,7 @@ bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, |
| bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], SkYUVColorSpace* colorSpace) |
| { |
| - if (!m_canYUVDecode) |
| + if (!m_canYUVDecode || !m_allDataReceived) |
|
Peter Kasting
2016/03/23 02:42:58
Why is it important to not YUV decode when we don'
scroggo_chromium
2016/03/24 13:59:44
I'm not very familiar with the YUV code, but there
Peter Kasting
2016/03/24 22:05:43
Ah. Maybe it makes sense to have a comment here s
scroggo_chromium
2016/03/25 01:05:10
Done.
|
| return false; |
| bool requestingYUVSizes = !planes || !planes[0]; |
| @@ -85,13 +92,13 @@ bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], |
| TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", requestingYUVSizes ? "sizes" : "frame index", static_cast<int>(m_frameIndex)); |
| if (requestingYUVSizes) |
| - return m_frameGenerator->getYUVComponentSizes(sizes); |
| + return m_frameGenerator->getYUVComponentSizes(m_data.get(), sizes); |
| if (colorSpace) |
| *colorSpace = kJPEG_SkYUVColorSpace; |
| PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); |
| - bool decoded = m_frameGenerator->decodeToYUV(m_frameIndex, sizes, planes, rowBytes); |
| + bool decoded = m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, sizes, planes, rowBytes); |
| PlatformInstrumentation::didDecodeLazyPixelRef(); |
| return decoded; |
| @@ -99,26 +106,28 @@ bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], |
| SkImageGenerator* DecodingImageGenerator::create(SkData* data) |
|
f(malita)
2016/03/23 16:41:57
Not new to this CL, but I think this factory is tr
scroggo_chromium
2016/03/24 13:59:44
That's correct. This method gets passed to SetImag
|
| { |
| - RefPtr<SharedBuffer> buffer = SharedBuffer::create(data->bytes(), data->size()); |
| + if (!data) |
| + return 0; |
|
Peter Kasting
2016/03/23 02:42:57
Is there a particular reason this explicit check n
scroggo_chromium
2016/03/24 13:59:44
I have not added any calls that might pass null, s
|
| + RefPtr<SegmentReader> segmentReader = adoptRef(new SkDataSegmentReader(data)); |
| // We just need the size of the image, so we have to temporarily create an ImageDecoder. Since |
| // we only need the size, it doesn't really matter about premul or not, or gamma settings. |
| - OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*buffer.get(), ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); |
| + OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*segmentReader.get(), ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); |
| if (!decoder) |
| return 0; |
| - decoder->setData(buffer.get(), true); |
| + decoder->setData(segmentReader.get(), true); |
| if (!decoder->isSizeAvailable()) |
| return 0; |
| const IntSize size = decoder->size(); |
| const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); |
| - RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Make(size.width(), size.height()), buffer, true, false); |
| + RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Make(size.width(), size.height()), false); |
| if (!frame) |
| return 0; |
| - return new DecodingImageGenerator(frame, info, 0); |
| + return new DecodingImageGenerator(frame, info, segmentReader, true, 0); |
|
f(malita)
2016/03/23 16:41:57
segmentReader.release()
(to minimize refcount chu
scroggo_chromium
2016/03/24 13:59:44
Done.
|
| } |
| } // namespace blink |