Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(696)

Unified Diff: third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp

Issue 1403393004: JPEGImageDecoder RGB565 and downsample support and related Skia imagegenerator changes Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp b/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
index b332fd9d54f678d45843a7c906dc1d3ff6805cb7..3b29a47ee3e6abb65d0afd9fc57f98248844b922 100644
--- a/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
@@ -143,7 +143,7 @@ bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index,
m_externalAllocator = adoptPtr(new ExternalMemoryAllocator(info, pixels, rowBytes));
- SkBitmap bitmap = tryToResumeDecode(scaledSize, index);
+ SkBitmap bitmap = tryToResumeDecode(scaledSize, index, info.colorType());
if (bitmap.isNull())
return false;
@@ -205,7 +205,7 @@ bool ImageFrameGenerator::decodeToYUV(SkISize componentSizes[3], void* planes[3]
return yuvDecoded;
}
-SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_t index)
+SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_t index, SkColorType outType)
{
TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "index", static_cast<int>(index));
@@ -214,7 +214,7 @@ SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_
ASSERT(!resumeDecoding || decoder);
SkBitmap fullSizeImage;
- bool complete = decode(index, &decoder, &fullSizeImage);
+ bool complete = decode(index, &decoder, &fullSizeImage, outType);
if (!decoder)
return SkBitmap();
@@ -280,19 +280,17 @@ void ImageFrameGenerator::setHasAlpha(size_t index, bool hasAlpha)
m_hasAlpha[index] = hasAlpha;
}
-bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap* bitmap)
+bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap* bitmap, SkColorType outType)
{
TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.width(), "height", m_fullSize.height());
ASSERT(decoder);
SharedBuffer* data = 0;
bool allDataReceived = false;
- bool newDecoder = false;
m_data.data(&data, &allDataReceived);
// Try to create an ImageDecoder if we are not given one.
if (!*decoder) {
- newDecoder = true;
if (m_imageDecoderFactory)
*decoder = m_imageDecoderFactory->create().leakPtr();
@@ -303,15 +301,23 @@ bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap*
return false;
}
- if (!m_isMultiFrame && newDecoder && allDataReceived) {
+ if (!m_isMultiFrame && allDataReceived) {
scroggo_chromium 2015/10/19 20:41:36 It seems like removing newDecoder is a separate be
aleksandar.stojiljkovic 2015/10/20 09:51:12 Yes. That code was originally contributed here: ht
scroggo_chromium 2015/10/20 15:06:41 Does it need to be tied to the change to support 5
aleksandar.stojiljkovic 2015/10/20 18:28:41 It makes this use case possible: images originally
aleksandar.stojiljkovic 2015/10/20 18:57:56 It is also required for decode to display resoluti
// If we're using an external memory allocator that means we're decoding
// directly into the output memory and we can save one memcpy.
ASSERT(m_externalAllocator.get());
(*decoder)->setMemoryAllocator(m_externalAllocator.get());
}
(*decoder)->setData(data, allDataReceived);
-
+ if (outType == kRGB_565_SkColorType) {
+ if (!(*decoder)->setDecodeRGB565Enabled(true)) {
+ ASSERT(false);
+ return false;
+ }
+ }
ImageFrame* frame = (*decoder)->frameBufferAtIndex(index);
+ // restore back to default
+ (*decoder)->setDecodeRGB565Enabled(false);
scroggo_chromium 2015/10/19 20:41:36 What happens if the caller tries to switch back an
aleksandar.stojiljkovic 2015/10/20 09:51:12 clear the image frame happens in call to ImageFram
scroggo_chromium 2015/10/20 15:06:41 Agreed. But ImageDecoder only calls setSize if it
aleksandar.stojiljkovic 2015/10/20 18:28:41 It is something I've seen happening every time on
+
// For multi-frame image decoders, we need to know how many frames are
// in that image in order to release the decoder when all frames are
// decoded. frameCount() is reliable only if all data is received and set in
@@ -379,4 +385,27 @@ bool ImageFrameGenerator::getYUVComponentSizes(SkISize componentSizes[3])
return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder::SizeForMemoryAllocation);
}
+bool ImageFrameGenerator::canDecodeToRGB565()
+{
+ // as the same buffer could be used to store consecutive frames, avoid the complexity
+ // since some of consecutive frames could have alpha
+ if (m_isMultiFrame)
+ return false;
+
+ // FIXME check how much this cost (decoder creation) and, also for getYUVComponentSizes,
+ // cache it in ImageDecodingStore for the real decode
+ SharedBuffer* data = 0;
+ bool allDataReceived = false;
+ m_data.data(&data, &allDataReceived);
+
+ // partially received data needs to have alpha
+ if (!allDataReceived)
+ return false;
+
+ OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied);
+ if (!decoder)
+ return false;
+ return decoder->canDecodeToRGB565();
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698