| Index: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h
|
| diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h
|
| index 2b00aa0e76c36796887ca12abff14001fd828d5a..f12e86c9fa8397d2ca65028fa236775eda0dc902 100644
|
| --- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h
|
| +++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h
|
| @@ -43,6 +43,7 @@
|
| #include "platform/wtf/Vector.h"
|
| #include "platform/wtf/text/WTFString.h"
|
| #include "public/platform/Platform.h"
|
| +#include "third_party/skia/include/codec/SkCodec.h"
|
|
|
| namespace blink {
|
|
|
| @@ -77,7 +78,7 @@ class PLATFORM_EXPORT ImagePlanes final {
|
| // ImageDecoder is a base for all format-specific decoders
|
| // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache.
|
| //
|
| -class PLATFORM_EXPORT ImageDecoder {
|
| +class PLATFORM_EXPORT ImageDecoder final {
|
| WTF_MAKE_NONCOPYABLE(ImageDecoder);
|
| USING_FAST_MALLOC(ImageDecoder);
|
|
|
| @@ -87,7 +88,7 @@ class PLATFORM_EXPORT ImageDecoder {
|
|
|
| enum AlphaOption { kAlphaPremultiplied, kAlphaNotPremultiplied };
|
|
|
| - virtual ~ImageDecoder() {}
|
| + ~ImageDecoder() {}
|
|
|
| // Returns a caller-owned decoder of the appropriate type. Returns nullptr if
|
| // we can't sniff a supported type from the provided data (possibly
|
| @@ -106,15 +107,10 @@ class PLATFORM_EXPORT ImageDecoder {
|
| data_complete, alphaoption, color_behavior);
|
| }
|
|
|
| - virtual String FilenameExtension() const = 0;
|
| + virtual String FilenameExtension() { return ""; }
|
|
|
| bool IsAllDataReceived() const { return is_all_data_received_; }
|
|
|
| - // Returns true if the buffer holds enough data to instantiate a decoder.
|
| - // This is useful for callers to determine whether a decoder instantiation
|
| - // failure is due to insufficient or bad data.
|
| - static bool HasSufficientDataToSniffImageType(const SharedBuffer&);
|
| -
|
| void SetData(PassRefPtr<SegmentReader> data, bool all_data_received) {
|
| if (failed_)
|
| return;
|
| @@ -128,7 +124,7 @@ class PLATFORM_EXPORT ImageDecoder {
|
| all_data_received);
|
| }
|
|
|
| - virtual void OnSetData(SegmentReader* data) {}
|
| + void OnSetData(SegmentReader* data);
|
|
|
| bool IsSizeAvailable() {
|
| if (failed_)
|
| @@ -140,22 +136,22 @@ class PLATFORM_EXPORT ImageDecoder {
|
|
|
| bool IsDecodedSizeAvailable() const { return !failed_ && size_available_; }
|
|
|
| - virtual IntSize Size() const { return size_; }
|
| + IntSize Size() const { return size_; }
|
|
|
| // Decoders which downsample images should override this method to
|
| // return the actual decoded size.
|
| - virtual IntSize DecodedSize() const { return Size(); }
|
| + IntSize DecodedSize() const { return Size(); }
|
|
|
| // Image decoders that support YUV decoding must override this to
|
| // provide the size of each component.
|
| - virtual IntSize DecodedYUVSize(int component) const {
|
| + IntSize DecodedYUVSize(int component) const {
|
| NOTREACHED();
|
| return IntSize();
|
| }
|
|
|
| // Image decoders that support YUV decoding must override this to
|
| // return the width of each row of the memory allocation.
|
| - virtual size_t DecodedYUVWidthBytes(int component) const {
|
| + size_t DecodedYUVWidthBytes(int component) const {
|
| NOTREACHED();
|
| return 0;
|
| }
|
| @@ -165,11 +161,11 @@ class PLATFORM_EXPORT ImageDecoder {
|
| // sizes. This does NOT differ from size() for GIF or WebP, since
|
| // decoding GIF or WebP composites any smaller frames against previous
|
| // frames to create full-size frames.
|
| - virtual IntSize FrameSizeAtIndex(size_t) const { return Size(); }
|
| + IntSize FrameSizeAtIndex(size_t) const { return Size(); }
|
|
|
| // Returns whether the size is legal (i.e. not going to result in
|
| // overflow elsewhere). If not, marks decoding as failed.
|
| - virtual bool SetSize(unsigned width, unsigned height) {
|
| + bool SetSize(unsigned width, unsigned height) {
|
| if (SizeCalculationMayOverflow(width, height))
|
| return SetFailed();
|
|
|
| @@ -178,34 +174,33 @@ class PLATFORM_EXPORT ImageDecoder {
|
| return true;
|
| }
|
|
|
| - // Calls DecodeFrameCount() to get the frame count (if possible), without
|
| - // decoding the individual frames. Resizes |frame_buffer_cache_| to the
|
| - // correct size and returns its size.
|
| + // To get the frame count, without decoding the individual frames.
|
| + // Resizes |frame_buffer_cache_| to correct size and returns its size.
|
| size_t FrameCount();
|
|
|
| - virtual int RepetitionCount() const { return kAnimationNone; }
|
| + int RepetitionCount();
|
|
|
| // Decodes as much of the requested frame as possible, and returns an
|
| // ImageDecoder-owned pointer.
|
| ImageFrame* FrameBufferAtIndex(size_t);
|
|
|
| // Whether the requested frame has alpha.
|
| - virtual bool FrameHasAlphaAtIndex(size_t) const;
|
| + bool FrameHasAlphaAtIndex(size_t) const;
|
|
|
| // Whether or not the frame is fully received.
|
| - virtual bool FrameIsCompleteAtIndex(size_t) const;
|
| + bool FrameIsCompleteAtIndex(size_t) const;
|
|
|
| // Returns true if a cached complete decode is available.
|
| bool FrameIsDecodedAtIndex(size_t) const;
|
|
|
| // Duration for displaying a frame in milliseconds. This method is only used
|
| // by animated images.
|
| - virtual float FrameDurationAtIndex(size_t) const { return 0; }
|
| + float FrameDurationAtIndex(size_t) const;
|
|
|
| // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't
|
| // have this frame cached (either because it hasn't been decoded, or because
|
| // it has been cleared).
|
| - virtual size_t FrameBytesAtIndex(size_t) const;
|
| + size_t FrameBytesAtIndex(size_t) const;
|
|
|
| ImageOrientation Orientation() const { return orientation_; }
|
|
|
| @@ -237,10 +232,7 @@ class PLATFORM_EXPORT ImageDecoder {
|
| // many callers want to return false after calling this), returns false
|
| // to enable easy tailcalling. Subclasses may override this to also
|
| // clean up any local data.
|
| - virtual bool SetFailed() {
|
| - failed_ = true;
|
| - return false;
|
| - }
|
| + bool SetFailed();
|
|
|
| bool Failed() const { return failed_; }
|
|
|
| @@ -259,11 +251,11 @@ class PLATFORM_EXPORT ImageDecoder {
|
| // ImageFrameGeneratorTest::ClearMultiFrameDecode. The test needs to
|
| // be modified since two frames may be kept in cache, instead of
|
| // always just one, with this ClearCacheExceptFrame implementation.
|
| - virtual size_t ClearCacheExceptFrame(size_t);
|
| + size_t ClearCacheExceptFrame(size_t);
|
|
|
| // If the image has a cursor hot-spot, stores it in the argument
|
| // and returns true. Otherwise returns false.
|
| - virtual bool HotSpot(IntPoint&) const { return false; }
|
| + bool HotSpot(IntPoint&) const { return false; }
|
|
|
| void SetMemoryAllocator(SkBitmap::Allocator* allocator) {
|
| // FIXME: this doesn't work for images with multiple frames.
|
| @@ -277,18 +269,14 @@ class PLATFORM_EXPORT ImageDecoder {
|
| frame_buffer_cache_[0].SetMemoryAllocator(allocator);
|
| }
|
|
|
| - virtual bool CanDecodeToYUV() { return false; }
|
| - virtual bool DecodeToYUV() { return false; }
|
| - virtual void SetImagePlanes(std::unique_ptr<ImagePlanes>) {}
|
| + bool CanDecodeToYUV() { return false; }
|
| + bool DecodeToYUV() { return false; }
|
| + void SetImagePlanes(std::unique_ptr<ImagePlanes>) {}
|
|
|
| protected:
|
| ImageDecoder(AlphaOption alpha_option,
|
| const ColorBehavior& color_behavior,
|
| - size_t max_decoded_bytes)
|
| - : premultiply_alpha_(alpha_option == kAlphaPremultiplied),
|
| - color_behavior_(color_behavior),
|
| - max_decoded_bytes_(max_decoded_bytes),
|
| - purge_aggressively_(false) {}
|
| + size_t max_decoded_bytes);
|
|
|
| // Calculates the most recent frame whose image data may be needed in
|
| // order to decode frame |frame_index|, based on frame disposal methods
|
| @@ -313,14 +301,10 @@ class PLATFORM_EXPORT ImageDecoder {
|
| // This is called by ClearCacheExceptFrame() if that method decides it wants
|
| // to preserve another frame, to avoid unnecessary redecoding.
|
| size_t ClearCacheExceptTwoFrames(size_t, size_t);
|
| - virtual void ClearFrameBuffer(size_t frame_index);
|
| + void ClearFrameBuffer(size_t frame_index);
|
|
|
| // Decodes the image sufficiently to determine the image size.
|
| - virtual void DecodeSize() = 0;
|
| -
|
| - // Decodes the image sufficiently to determine the number of frames and
|
| - // returns that number.
|
| - virtual size_t DecodeFrameCount() { return 1; }
|
| + void DecodeSize() {}
|
|
|
| // Called to initialize the frame buffer with the given index, based on the
|
| // provided and previous frame's characteristics. Returns true on success.
|
| @@ -332,10 +316,10 @@ class PLATFORM_EXPORT ImageDecoder {
|
|
|
| // Performs any additional setup of the requested frame after it has been
|
| // initially created, e.g. setting a duration or disposal method.
|
| - virtual void InitializeNewFrame(size_t) {}
|
| + void InitializeNewFrame(size_t);
|
|
|
| // Decodes the requested frame.
|
| - virtual void Decode(size_t) = 0;
|
| + void Decode(size_t);
|
|
|
| // This method is only required for animated images. It returns a vector with
|
| // all frame indices that need to be decoded in order to succesfully decode
|
| @@ -396,7 +380,7 @@ class PLATFORM_EXPORT ImageDecoder {
|
| //
|
| // Before calling this, verify that frame |index| exists by checking that
|
| // |index| is smaller than |frame_buffer_cache_|.size().
|
| - virtual bool FrameStatusSufficientForSuccessors(size_t index) {
|
| + bool FrameStatusSufficientForSuccessors(size_t index) {
|
| DCHECK(index < frame_buffer_cache_.size());
|
| return frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameEmpty;
|
| }
|
| @@ -414,11 +398,11 @@ class PLATFORM_EXPORT ImageDecoder {
|
|
|
| // This methods gets called at the end of InitFrameBuffer. Subclasses can do
|
| // format specific initialization, for e.g. alpha settings, here.
|
| - virtual void OnInitFrameBuffer(size_t){};
|
| + void OnInitFrameBuffer(size_t);
|
|
|
| // Called by InitFrameBuffer to determine if it can take the bitmap of the
|
| // previous frame. This condition is different for GIF and WEBP.
|
| - virtual bool CanReusePreviousFrameBuffer(size_t) const { return false; }
|
| + bool CanReusePreviousFrameBuffer(size_t) const;
|
|
|
| IntSize size_;
|
| bool size_available_ = false;
|
| @@ -429,6 +413,7 @@ class PLATFORM_EXPORT ImageDecoder {
|
| sk_sp<SkColorSpace> embedded_color_space_ = nullptr;
|
| bool source_to_target_color_transform_needs_update_ = false;
|
| std::unique_ptr<SkColorSpaceXform> source_to_target_color_transform_;
|
| + std::unique_ptr<SkCodec> codec_;
|
| };
|
|
|
| } // namespace blink
|
|
|