DeferredImageDecoder: early-out onGetYUV8Planes when possible
Ganesh rendering will query onGetYUV8Planes when rendering GIF frames, and other image formats, that do not support YUV image decoding. Since the type of image decoded is known when a DecodingImageGenerator is created, store that type in DecodingImageGenerator, and use that to early-out requests for YUV decoding to avoid wasting time. ImageFrameGenerator::getYUVComponentSizes no longer needs to check for "jpg" since it is now done earlier in DecodingImageGenerator. No change in behavior, no new tests. BUG=566885, 476531 Review URL: https://codereview.chromium.org/1508683002 Cr-Commit-Position: refs/heads/master@{#363727}
This commit is contained in:
third_party/WebKit/Source/platform/graphics
@ -27,7 +27,6 @@
|
||||
#include "platform/graphics/DecodingImageGenerator.h"
|
||||
|
||||
#include "platform/PlatformInstrumentation.h"
|
||||
#include "platform/RuntimeEnabledFeatures.h"
|
||||
#include "platform/SharedBuffer.h"
|
||||
#include "platform/TraceEvent.h"
|
||||
#include "platform/graphics/ImageFrameGenerator.h"
|
||||
@ -41,6 +40,7 @@ DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f
|
||||
, m_frameGenerator(frameGenerator)
|
||||
, m_frameIndex(index)
|
||||
, m_generationId(0)
|
||||
, m_canYUVDecode(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -63,8 +63,7 @@ SkData* DecodingImageGenerator::onRefEncodedData()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
|
||||
SkPMColor ctable[], int* ctableCount)
|
||||
bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount)
|
||||
{
|
||||
TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", static_cast<int>(m_frameIndex));
|
||||
|
||||
@ -73,8 +72,8 @@ bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
|
||||
return false;
|
||||
|
||||
if (info.colorType() != getInfo().colorType()) {
|
||||
// ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlphaType after sniffing the encoded data, so if we see a request
|
||||
// for opaque, that is ok even if our initial alphatype was not opaque.
|
||||
// blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlphaType after fully decoding the image frame,
|
||||
// so if we see a request for opaque, that is ok even if our initial alpha type was not opaque.
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -87,7 +86,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 (!RuntimeEnabledFeatures::decodeToYUVEnabled())
|
||||
if (!m_canYUVDecode)
|
||||
return false;
|
||||
|
||||
bool requestingYUVSizes = !planes || !planes[0];
|
||||
@ -97,11 +96,12 @@ bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3],
|
||||
if (requestingYUVSizes)
|
||||
return m_frameGenerator->getYUVComponentSizes(sizes);
|
||||
|
||||
if (colorSpace)
|
||||
*colorSpace = kJPEG_SkYUVColorSpace;
|
||||
|
||||
PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId);
|
||||
bool decoded = m_frameGenerator->decodeToYUV(sizes, planes, rowBytes);
|
||||
PlatformInstrumentation::didDecodeLazyPixelRef();
|
||||
if (colorSpace)
|
||||
*colorSpace = kJPEG_SkYUVColorSpace;
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
~DecodingImageGenerator() override;
|
||||
|
||||
void setGenerationId(size_t id) { m_generationId = id; }
|
||||
void setCanYUVDecode(bool yes) { m_canYUVDecode = yes; }
|
||||
|
||||
protected:
|
||||
SkData* onRefEncodedData() override;
|
||||
@ -64,6 +65,7 @@ private:
|
||||
RefPtr<ImageFrameGenerator> m_frameGenerator;
|
||||
size_t m_frameIndex;
|
||||
size_t m_generationId;
|
||||
bool m_canYUVDecode;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "config.h"
|
||||
#include "platform/graphics/DeferredImageDecoder.h"
|
||||
|
||||
#include "platform/RuntimeEnabledFeatures.h"
|
||||
#include "platform/graphics/DecodingImageGenerator.h"
|
||||
#include "platform/graphics/FrameData.h"
|
||||
#include "platform/graphics/ImageDecodingStore.h"
|
||||
@ -58,6 +59,7 @@ DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode
|
||||
, m_actualDecoder(actualDecoder)
|
||||
, m_repetitionCount(cAnimationNone)
|
||||
, m_hasColorProfile(false)
|
||||
, m_canYUVDecode(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -214,9 +216,13 @@ void DeferredImageDecoder::activateLazyDecoding()
|
||||
{
|
||||
if (m_frameGenerator)
|
||||
return;
|
||||
|
||||
m_size = m_actualDecoder->size();
|
||||
m_filenameExtension = m_actualDecoder->filenameExtension();
|
||||
// JPEG images support YUV decoding: other decoders do not, WEBP could in future.
|
||||
m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && (m_filenameExtension == "jpg");
|
||||
m_hasColorProfile = m_actualDecoder->hasColorProfile();
|
||||
|
||||
const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationNone || (m_allDataReceived && m_actualDecoder->frameCount() == 1u);
|
||||
m_frameGenerator = ImageFrameGenerator::create(SkISize::Make(m_actualDecoder->decodedSize().width(), m_actualDecoder->decodedSize().height()), m_data, m_allDataReceived, !isSingleFrame);
|
||||
}
|
||||
@ -271,11 +277,13 @@ PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index,
|
||||
ASSERT(decodedSize.height() > 0);
|
||||
|
||||
DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenerator, imageInfoFrom(decodedSize, knownToBeOpaque), index);
|
||||
RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator));
|
||||
RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator)); // SkImage takes ownership of the generator.
|
||||
if (!image)
|
||||
return nullptr;
|
||||
|
||||
generator->setGenerationId(image->uniqueID());
|
||||
generator->setCanYUVDecode(m_canYUVDecode);
|
||||
|
||||
return image.release();
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,7 @@ private:
|
||||
IntSize m_size;
|
||||
int m_repetitionCount;
|
||||
bool m_hasColorProfile;
|
||||
bool m_canYUVDecode;
|
||||
|
||||
// Carries only frame state and other information. Does not carry bitmap.
|
||||
Vector<FrameData> m_frameData;
|
||||
|
@ -354,7 +354,7 @@ bool ImageFrameGenerator::getYUVComponentSizes(SkISize componentSizes[3])
|
||||
{
|
||||
ASSERT(componentSizes);
|
||||
|
||||
TRACE_EVENT2("webkit", "ImageFrameGenerator::getYUVComponentSizes", "width", m_fullSize.width(), "height", m_fullSize.height());
|
||||
TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width", m_fullSize.width(), "height", m_fullSize.height());
|
||||
|
||||
SharedBuffer* data = 0;
|
||||
bool allDataReceived = false;
|
||||
@ -368,11 +368,6 @@ bool ImageFrameGenerator::getYUVComponentSizes(SkISize componentSizes[3])
|
||||
if (!decoder)
|
||||
return false;
|
||||
|
||||
// JPEG images support YUV decoding: other decoders do not. So don't pump data into decoders
|
||||
// that always return false to updateYUVComponentSizes() requests.
|
||||
if (decoder->filenameExtension() != "jpg")
|
||||
return false;
|
||||
|
||||
// Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding.
|
||||
decoder->setData(data, allDataReceived);
|
||||
OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes);
|
||||
|
Reference in New Issue
Block a user