| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 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 25 matching lines...) Expand all Loading... |
| 36 #include "platform/graphics/ImageOrientation.h" | 36 #include "platform/graphics/ImageOrientation.h" |
| 37 #include "platform/image-decoders/ImageAnimation.h" | 37 #include "platform/image-decoders/ImageAnimation.h" |
| 38 #include "platform/image-decoders/ImageFrame.h" | 38 #include "platform/image-decoders/ImageFrame.h" |
| 39 #include "platform/image-decoders/SegmentReader.h" | 39 #include "platform/image-decoders/SegmentReader.h" |
| 40 #include "platform/wtf/Assertions.h" | 40 #include "platform/wtf/Assertions.h" |
| 41 #include "platform/wtf/RefPtr.h" | 41 #include "platform/wtf/RefPtr.h" |
| 42 #include "platform/wtf/Threading.h" | 42 #include "platform/wtf/Threading.h" |
| 43 #include "platform/wtf/Vector.h" | 43 #include "platform/wtf/Vector.h" |
| 44 #include "platform/wtf/text/WTFString.h" | 44 #include "platform/wtf/text/WTFString.h" |
| 45 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
| 46 #include "third_party/skia/include/codec/SkCodec.h" |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 | 49 |
| 49 #if SK_B32_SHIFT | 50 #if SK_B32_SHIFT |
| 50 inline SkColorSpaceXform::ColorFormat XformColorFormat() { | 51 inline SkColorSpaceXform::ColorFormat XformColorFormat() { |
| 51 return SkColorSpaceXform::kRGBA_8888_ColorFormat; | 52 return SkColorSpaceXform::kRGBA_8888_ColorFormat; |
| 52 } | 53 } |
| 53 #else | 54 #else |
| 54 inline SkColorSpaceXform::ColorFormat XformColorFormat() { | 55 inline SkColorSpaceXform::ColorFormat XformColorFormat() { |
| 55 return SkColorSpaceXform::kBGRA_8888_ColorFormat; | 56 return SkColorSpaceXform::kBGRA_8888_ColorFormat; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 70 size_t RowBytes(int) const; | 71 size_t RowBytes(int) const; |
| 71 | 72 |
| 72 private: | 73 private: |
| 73 void* planes_[3]; | 74 void* planes_[3]; |
| 74 size_t row_bytes_[3]; | 75 size_t row_bytes_[3]; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 // ImageDecoder is a base for all format-specific decoders | 78 // ImageDecoder is a base for all format-specific decoders |
| 78 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache. | 79 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache. |
| 79 // | 80 // |
| 80 class PLATFORM_EXPORT ImageDecoder { | 81 class PLATFORM_EXPORT ImageDecoder final { |
| 81 WTF_MAKE_NONCOPYABLE(ImageDecoder); | 82 WTF_MAKE_NONCOPYABLE(ImageDecoder); |
| 82 USING_FAST_MALLOC(ImageDecoder); | 83 USING_FAST_MALLOC(ImageDecoder); |
| 83 | 84 |
| 84 public: | 85 public: |
| 85 static const size_t kNoDecodedImageByteLimit = | 86 static const size_t kNoDecodedImageByteLimit = |
| 86 Platform::kNoDecodedImageByteLimit; | 87 Platform::kNoDecodedImageByteLimit; |
| 87 | 88 |
| 88 enum AlphaOption { kAlphaPremultiplied, kAlphaNotPremultiplied }; | 89 enum AlphaOption { kAlphaPremultiplied, kAlphaNotPremultiplied }; |
| 89 | 90 |
| 90 virtual ~ImageDecoder() {} | 91 ~ImageDecoder() {} |
| 91 | 92 |
| 92 // Returns a caller-owned decoder of the appropriate type. Returns nullptr if | 93 // Returns a caller-owned decoder of the appropriate type. Returns nullptr if |
| 93 // we can't sniff a supported type from the provided data (possibly | 94 // we can't sniff a supported type from the provided data (possibly |
| 94 // because there isn't enough data yet). | 95 // because there isn't enough data yet). |
| 95 // Sets |max_decoded_bytes_| to Platform::MaxImageDecodedBytes(). | 96 // Sets |max_decoded_bytes_| to Platform::MaxImageDecodedBytes(). |
| 96 static std::unique_ptr<ImageDecoder> Create(RefPtr<SegmentReader> data, | 97 static std::unique_ptr<ImageDecoder> Create(RefPtr<SegmentReader> data, |
| 97 bool data_complete, | 98 bool data_complete, |
| 98 AlphaOption, | 99 AlphaOption, |
| 99 const ColorBehavior&); | 100 const ColorBehavior&); |
| 100 static std::unique_ptr<ImageDecoder> Create( | 101 static std::unique_ptr<ImageDecoder> Create( |
| 101 PassRefPtr<SharedBuffer> data, | 102 PassRefPtr<SharedBuffer> data, |
| 102 bool data_complete, | 103 bool data_complete, |
| 103 AlphaOption alphaoption, | 104 AlphaOption alphaoption, |
| 104 const ColorBehavior& color_behavior) { | 105 const ColorBehavior& color_behavior) { |
| 105 return Create(SegmentReader::CreateFromSharedBuffer(std::move(data)), | 106 return Create(SegmentReader::CreateFromSharedBuffer(std::move(data)), |
| 106 data_complete, alphaoption, color_behavior); | 107 data_complete, alphaoption, color_behavior); |
| 107 } | 108 } |
| 108 | 109 |
| 109 virtual String FilenameExtension() const = 0; | 110 virtual String FilenameExtension() { return ""; } |
| 110 | 111 |
| 111 bool IsAllDataReceived() const { return is_all_data_received_; } | 112 bool IsAllDataReceived() const { return is_all_data_received_; } |
| 112 | 113 |
| 113 // Returns true if the buffer holds enough data to instantiate a decoder. | |
| 114 // This is useful for callers to determine whether a decoder instantiation | |
| 115 // failure is due to insufficient or bad data. | |
| 116 static bool HasSufficientDataToSniffImageType(const SharedBuffer&); | |
| 117 | |
| 118 void SetData(PassRefPtr<SegmentReader> data, bool all_data_received) { | 114 void SetData(PassRefPtr<SegmentReader> data, bool all_data_received) { |
| 119 if (failed_) | 115 if (failed_) |
| 120 return; | 116 return; |
| 121 data_ = std::move(data); | 117 data_ = std::move(data); |
| 122 is_all_data_received_ = all_data_received; | 118 is_all_data_received_ = all_data_received; |
| 123 OnSetData(data_.Get()); | 119 OnSetData(data_.Get()); |
| 124 } | 120 } |
| 125 | 121 |
| 126 void SetData(PassRefPtr<SharedBuffer> data, bool all_data_received) { | 122 void SetData(PassRefPtr<SharedBuffer> data, bool all_data_received) { |
| 127 SetData(SegmentReader::CreateFromSharedBuffer(std::move(data)), | 123 SetData(SegmentReader::CreateFromSharedBuffer(std::move(data)), |
| 128 all_data_received); | 124 all_data_received); |
| 129 } | 125 } |
| 130 | 126 |
| 131 virtual void OnSetData(SegmentReader* data) {} | 127 void OnSetData(SegmentReader* data); |
| 132 | 128 |
| 133 bool IsSizeAvailable() { | 129 bool IsSizeAvailable() { |
| 134 if (failed_) | 130 if (failed_) |
| 135 return false; | 131 return false; |
| 136 if (!size_available_) | 132 if (!size_available_) |
| 137 DecodeSize(); | 133 DecodeSize(); |
| 138 return IsDecodedSizeAvailable(); | 134 return IsDecodedSizeAvailable(); |
| 139 } | 135 } |
| 140 | 136 |
| 141 bool IsDecodedSizeAvailable() const { return !failed_ && size_available_; } | 137 bool IsDecodedSizeAvailable() const { return !failed_ && size_available_; } |
| 142 | 138 |
| 143 virtual IntSize Size() const { return size_; } | 139 IntSize Size() const { return size_; } |
| 144 | 140 |
| 145 // Decoders which downsample images should override this method to | 141 // Decoders which downsample images should override this method to |
| 146 // return the actual decoded size. | 142 // return the actual decoded size. |
| 147 virtual IntSize DecodedSize() const { return Size(); } | 143 IntSize DecodedSize() const { return Size(); } |
| 148 | 144 |
| 149 // Image decoders that support YUV decoding must override this to | 145 // Image decoders that support YUV decoding must override this to |
| 150 // provide the size of each component. | 146 // provide the size of each component. |
| 151 virtual IntSize DecodedYUVSize(int component) const { | 147 IntSize DecodedYUVSize(int component) const { |
| 152 NOTREACHED(); | 148 NOTREACHED(); |
| 153 return IntSize(); | 149 return IntSize(); |
| 154 } | 150 } |
| 155 | 151 |
| 156 // Image decoders that support YUV decoding must override this to | 152 // Image decoders that support YUV decoding must override this to |
| 157 // return the width of each row of the memory allocation. | 153 // return the width of each row of the memory allocation. |
| 158 virtual size_t DecodedYUVWidthBytes(int component) const { | 154 size_t DecodedYUVWidthBytes(int component) const { |
| 159 NOTREACHED(); | 155 NOTREACHED(); |
| 160 return 0; | 156 return 0; |
| 161 } | 157 } |
| 162 | 158 |
| 163 // This will only differ from size() for ICO (where each frame is a | 159 // This will only differ from size() for ICO (where each frame is a |
| 164 // different icon) or other formats where different frames are different | 160 // different icon) or other formats where different frames are different |
| 165 // sizes. This does NOT differ from size() for GIF or WebP, since | 161 // sizes. This does NOT differ from size() for GIF or WebP, since |
| 166 // decoding GIF or WebP composites any smaller frames against previous | 162 // decoding GIF or WebP composites any smaller frames against previous |
| 167 // frames to create full-size frames. | 163 // frames to create full-size frames. |
| 168 virtual IntSize FrameSizeAtIndex(size_t) const { return Size(); } | 164 IntSize FrameSizeAtIndex(size_t) const { return Size(); } |
| 169 | 165 |
| 170 // Returns whether the size is legal (i.e. not going to result in | 166 // Returns whether the size is legal (i.e. not going to result in |
| 171 // overflow elsewhere). If not, marks decoding as failed. | 167 // overflow elsewhere). If not, marks decoding as failed. |
| 172 virtual bool SetSize(unsigned width, unsigned height) { | 168 bool SetSize(unsigned width, unsigned height) { |
| 173 if (SizeCalculationMayOverflow(width, height)) | 169 if (SizeCalculationMayOverflow(width, height)) |
| 174 return SetFailed(); | 170 return SetFailed(); |
| 175 | 171 |
| 176 size_ = IntSize(width, height); | 172 size_ = IntSize(width, height); |
| 177 size_available_ = true; | 173 size_available_ = true; |
| 178 return true; | 174 return true; |
| 179 } | 175 } |
| 180 | 176 |
| 181 // Calls DecodeFrameCount() to get the frame count (if possible), without | 177 // To get the frame count, without decoding the individual frames. |
| 182 // decoding the individual frames. Resizes |frame_buffer_cache_| to the | 178 // Resizes |frame_buffer_cache_| to correct size and returns its size. |
| 183 // correct size and returns its size. | |
| 184 size_t FrameCount(); | 179 size_t FrameCount(); |
| 185 | 180 |
| 186 virtual int RepetitionCount() const { return kAnimationNone; } | 181 int RepetitionCount(); |
| 187 | 182 |
| 188 // Decodes as much of the requested frame as possible, and returns an | 183 // Decodes as much of the requested frame as possible, and returns an |
| 189 // ImageDecoder-owned pointer. | 184 // ImageDecoder-owned pointer. |
| 190 ImageFrame* FrameBufferAtIndex(size_t); | 185 ImageFrame* FrameBufferAtIndex(size_t); |
| 191 | 186 |
| 192 // Whether the requested frame has alpha. | 187 // Whether the requested frame has alpha. |
| 193 virtual bool FrameHasAlphaAtIndex(size_t) const; | 188 bool FrameHasAlphaAtIndex(size_t) const; |
| 194 | 189 |
| 195 // Whether or not the frame is fully received. | 190 // Whether or not the frame is fully received. |
| 196 virtual bool FrameIsCompleteAtIndex(size_t) const; | 191 bool FrameIsCompleteAtIndex(size_t) const; |
| 197 | 192 |
| 198 // Returns true if a cached complete decode is available. | 193 // Returns true if a cached complete decode is available. |
| 199 bool FrameIsDecodedAtIndex(size_t) const; | 194 bool FrameIsDecodedAtIndex(size_t) const; |
| 200 | 195 |
| 201 // Duration for displaying a frame in milliseconds. This method is only used | 196 // Duration for displaying a frame in milliseconds. This method is only used |
| 202 // by animated images. | 197 // by animated images. |
| 203 virtual float FrameDurationAtIndex(size_t) const { return 0; } | 198 float FrameDurationAtIndex(size_t) const; |
| 204 | 199 |
| 205 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't | 200 // Number of bytes in the decoded frame. Returns 0 if the decoder doesn't |
| 206 // have this frame cached (either because it hasn't been decoded, or because | 201 // have this frame cached (either because it hasn't been decoded, or because |
| 207 // it has been cleared). | 202 // it has been cleared). |
| 208 virtual size_t FrameBytesAtIndex(size_t) const; | 203 size_t FrameBytesAtIndex(size_t) const; |
| 209 | 204 |
| 210 ImageOrientation Orientation() const { return orientation_; } | 205 ImageOrientation Orientation() const { return orientation_; } |
| 211 | 206 |
| 212 bool IgnoresColorSpace() const { return color_behavior_.IsIgnore(); } | 207 bool IgnoresColorSpace() const { return color_behavior_.IsIgnore(); } |
| 213 const ColorBehavior& GetColorBehavior() const { return color_behavior_; } | 208 const ColorBehavior& GetColorBehavior() const { return color_behavior_; } |
| 214 | 209 |
| 215 // This returns the color space that will be included in the SkImageInfo of | 210 // This returns the color space that will be included in the SkImageInfo of |
| 216 // SkImages created from this decoder. This will be nullptr unless the | 211 // SkImages created from this decoder. This will be nullptr unless the |
| 217 // decoder was created with the option ColorSpaceTagged. | 212 // decoder was created with the option ColorSpaceTagged. |
| 218 sk_sp<SkColorSpace> ColorSpaceForSkImages() const; | 213 sk_sp<SkColorSpace> ColorSpaceForSkImages() const; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 230 SkColorSpaceXform* ColorTransform(); | 225 SkColorSpaceXform* ColorTransform(); |
| 231 | 226 |
| 232 AlphaOption GetAlphaOption() const { | 227 AlphaOption GetAlphaOption() const { |
| 233 return premultiply_alpha_ ? kAlphaPremultiplied : kAlphaNotPremultiplied; | 228 return premultiply_alpha_ ? kAlphaPremultiplied : kAlphaNotPremultiplied; |
| 234 } | 229 } |
| 235 | 230 |
| 236 // Sets the "decode failure" flag. For caller convenience (since so | 231 // Sets the "decode failure" flag. For caller convenience (since so |
| 237 // many callers want to return false after calling this), returns false | 232 // many callers want to return false after calling this), returns false |
| 238 // to enable easy tailcalling. Subclasses may override this to also | 233 // to enable easy tailcalling. Subclasses may override this to also |
| 239 // clean up any local data. | 234 // clean up any local data. |
| 240 virtual bool SetFailed() { | 235 bool SetFailed(); |
| 241 failed_ = true; | |
| 242 return false; | |
| 243 } | |
| 244 | 236 |
| 245 bool Failed() const { return failed_; } | 237 bool Failed() const { return failed_; } |
| 246 | 238 |
| 247 // Clears decoded pixel data from all frames except the provided frame. If | 239 // Clears decoded pixel data from all frames except the provided frame. If |
| 248 // subsequent frames depend on this frame's required previous frame, then that | 240 // subsequent frames depend on this frame's required previous frame, then that |
| 249 // frame is also kept in cache to prevent re-decoding from the beginning. | 241 // frame is also kept in cache to prevent re-decoding from the beginning. |
| 250 // Callers may pass WTF::kNotFound to clear all frames. | 242 // Callers may pass WTF::kNotFound to clear all frames. |
| 251 // Note: If |frame_buffer_cache_| contains only one frame, it won't be | 243 // Note: If |frame_buffer_cache_| contains only one frame, it won't be |
| 252 // cleared. Returns the number of bytes of frame data actually cleared. | 244 // cleared. Returns the number of bytes of frame data actually cleared. |
| 253 // | 245 // |
| 254 // This is a virtual method because MockImageDecoder needs to override it in | 246 // This is a virtual method because MockImageDecoder needs to override it in |
| 255 // order to run the test ImageFrameGeneratorTest::ClearMultiFrameDecode. | 247 // order to run the test ImageFrameGeneratorTest::ClearMultiFrameDecode. |
| 256 // | 248 // |
| 257 // @TODO Let MockImageDecoder override ImageFrame::ClearFrameBuffer instead, | 249 // @TODO Let MockImageDecoder override ImageFrame::ClearFrameBuffer instead, |
| 258 // so this method can be made non-virtual. It is used in the test | 250 // so this method can be made non-virtual. It is used in the test |
| 259 // ImageFrameGeneratorTest::ClearMultiFrameDecode. The test needs to | 251 // ImageFrameGeneratorTest::ClearMultiFrameDecode. The test needs to |
| 260 // be modified since two frames may be kept in cache, instead of | 252 // be modified since two frames may be kept in cache, instead of |
| 261 // always just one, with this ClearCacheExceptFrame implementation. | 253 // always just one, with this ClearCacheExceptFrame implementation. |
| 262 virtual size_t ClearCacheExceptFrame(size_t); | 254 size_t ClearCacheExceptFrame(size_t); |
| 263 | 255 |
| 264 // If the image has a cursor hot-spot, stores it in the argument | 256 // If the image has a cursor hot-spot, stores it in the argument |
| 265 // and returns true. Otherwise returns false. | 257 // and returns true. Otherwise returns false. |
| 266 virtual bool HotSpot(IntPoint&) const { return false; } | 258 bool HotSpot(IntPoint&) const { return false; } |
| 267 | 259 |
| 268 void SetMemoryAllocator(SkBitmap::Allocator* allocator) { | 260 void SetMemoryAllocator(SkBitmap::Allocator* allocator) { |
| 269 // FIXME: this doesn't work for images with multiple frames. | 261 // FIXME: this doesn't work for images with multiple frames. |
| 270 if (frame_buffer_cache_.IsEmpty()) { | 262 if (frame_buffer_cache_.IsEmpty()) { |
| 271 // Ensure that InitializeNewFrame is called, after parsing if | 263 // Ensure that InitializeNewFrame is called, after parsing if |
| 272 // necessary. | 264 // necessary. |
| 273 if (!FrameCount()) | 265 if (!FrameCount()) |
| 274 return; | 266 return; |
| 275 } | 267 } |
| 276 | 268 |
| 277 frame_buffer_cache_[0].SetMemoryAllocator(allocator); | 269 frame_buffer_cache_[0].SetMemoryAllocator(allocator); |
| 278 } | 270 } |
| 279 | 271 |
| 280 virtual bool CanDecodeToYUV() { return false; } | 272 bool CanDecodeToYUV() { return false; } |
| 281 virtual bool DecodeToYUV() { return false; } | 273 bool DecodeToYUV() { return false; } |
| 282 virtual void SetImagePlanes(std::unique_ptr<ImagePlanes>) {} | 274 void SetImagePlanes(std::unique_ptr<ImagePlanes>) {} |
| 283 | 275 |
| 284 protected: | 276 protected: |
| 285 ImageDecoder(AlphaOption alpha_option, | 277 ImageDecoder(AlphaOption alpha_option, |
| 286 const ColorBehavior& color_behavior, | 278 const ColorBehavior& color_behavior, |
| 287 size_t max_decoded_bytes) | 279 size_t max_decoded_bytes); |
| 288 : premultiply_alpha_(alpha_option == kAlphaPremultiplied), | |
| 289 color_behavior_(color_behavior), | |
| 290 max_decoded_bytes_(max_decoded_bytes), | |
| 291 purge_aggressively_(false) {} | |
| 292 | 280 |
| 293 // Calculates the most recent frame whose image data may be needed in | 281 // Calculates the most recent frame whose image data may be needed in |
| 294 // order to decode frame |frame_index|, based on frame disposal methods | 282 // order to decode frame |frame_index|, based on frame disposal methods |
| 295 // and |frame_rect_is_opaque|, where |frame_rect_is_opaque| signifies whether | 283 // and |frame_rect_is_opaque|, where |frame_rect_is_opaque| signifies whether |
| 296 // the rectangle of frame at |frame_index| is known to be opaque. | 284 // the rectangle of frame at |frame_index| is known to be opaque. |
| 297 // If no previous frame's data is required, returns WTF::kNotFound. | 285 // If no previous frame's data is required, returns WTF::kNotFound. |
| 298 // | 286 // |
| 299 // This function requires that the previous frame's | 287 // This function requires that the previous frame's |
| 300 // |required_previous_frame_index_| member has been set correctly. The | 288 // |required_previous_frame_index_| member has been set correctly. The |
| 301 // easiest way to ensure this is for subclasses to call this method and | 289 // easiest way to ensure this is for subclasses to call this method and |
| 302 // store the result on the frame via SetRequiredPreviousFrameIndex() | 290 // store the result on the frame via SetRequiredPreviousFrameIndex() |
| 303 // as soon as the frame has been created and parsed sufficiently to | 291 // as soon as the frame has been created and parsed sufficiently to |
| 304 // determine the disposal method; assuming this happens for all frames | 292 // determine the disposal method; assuming this happens for all frames |
| 305 // in order, the required invariant will hold. | 293 // in order, the required invariant will hold. |
| 306 // | 294 // |
| 307 // Image formats which do not use more than one frame do not need to | 295 // Image formats which do not use more than one frame do not need to |
| 308 // worry about this; see comments on | 296 // worry about this; see comments on |
| 309 // ImageFrame::required_previous_frame+index_. | 297 // ImageFrame::required_previous_frame+index_. |
| 310 size_t FindRequiredPreviousFrame(size_t frame_index, | 298 size_t FindRequiredPreviousFrame(size_t frame_index, |
| 311 bool frame_rect_is_opaque); | 299 bool frame_rect_is_opaque); |
| 312 | 300 |
| 313 // This is called by ClearCacheExceptFrame() if that method decides it wants | 301 // This is called by ClearCacheExceptFrame() if that method decides it wants |
| 314 // to preserve another frame, to avoid unnecessary redecoding. | 302 // to preserve another frame, to avoid unnecessary redecoding. |
| 315 size_t ClearCacheExceptTwoFrames(size_t, size_t); | 303 size_t ClearCacheExceptTwoFrames(size_t, size_t); |
| 316 virtual void ClearFrameBuffer(size_t frame_index); | 304 void ClearFrameBuffer(size_t frame_index); |
| 317 | 305 |
| 318 // Decodes the image sufficiently to determine the image size. | 306 // Decodes the image sufficiently to determine the image size. |
| 319 virtual void DecodeSize() = 0; | 307 void DecodeSize() {} |
| 320 | |
| 321 // Decodes the image sufficiently to determine the number of frames and | |
| 322 // returns that number. | |
| 323 virtual size_t DecodeFrameCount() { return 1; } | |
| 324 | 308 |
| 325 // Called to initialize the frame buffer with the given index, based on the | 309 // Called to initialize the frame buffer with the given index, based on the |
| 326 // provided and previous frame's characteristics. Returns true on success. | 310 // provided and previous frame's characteristics. Returns true on success. |
| 327 // Before calling this method, the caller must verify that the frame exists. | 311 // Before calling this method, the caller must verify that the frame exists. |
| 328 // On failure, the client should call SetFailed. This method does not call | 312 // On failure, the client should call SetFailed. This method does not call |
| 329 // SetFailed itself because that might delete the object directly making this | 313 // SetFailed itself because that might delete the object directly making this |
| 330 // call. | 314 // call. |
| 331 bool InitFrameBuffer(size_t); | 315 bool InitFrameBuffer(size_t); |
| 332 | 316 |
| 333 // Performs any additional setup of the requested frame after it has been | 317 // Performs any additional setup of the requested frame after it has been |
| 334 // initially created, e.g. setting a duration or disposal method. | 318 // initially created, e.g. setting a duration or disposal method. |
| 335 virtual void InitializeNewFrame(size_t) {} | 319 void InitializeNewFrame(size_t); |
| 336 | 320 |
| 337 // Decodes the requested frame. | 321 // Decodes the requested frame. |
| 338 virtual void Decode(size_t) = 0; | 322 void Decode(size_t); |
| 339 | 323 |
| 340 // This method is only required for animated images. It returns a vector with | 324 // This method is only required for animated images. It returns a vector with |
| 341 // all frame indices that need to be decoded in order to succesfully decode | 325 // all frame indices that need to be decoded in order to succesfully decode |
| 342 // the provided frame. The indices are returned in reverse order, so the | 326 // the provided frame. The indices are returned in reverse order, so the |
| 343 // last frame needs to be decoded first. Before calling this method, the | 327 // last frame needs to be decoded first. Before calling this method, the |
| 344 // caller must verify that the frame exists. | 328 // caller must verify that the frame exists. |
| 345 Vector<size_t> FindFramesToDecode(size_t) const; | 329 Vector<size_t> FindFramesToDecode(size_t) const; |
| 346 | 330 |
| 347 // This is called by Decode() after decoding a frame in an animated image. | 331 // This is called by Decode() after decoding a frame in an animated image. |
| 348 // Before calling this method, the caller must verify that the frame exists. | 332 // Before calling this method, the caller must verify that the frame exists. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // yet sufficiently decoded. | 373 // yet sufficiently decoded. |
| 390 // | 374 // |
| 391 // The default condition is that the frame status needs to be FramePartial or | 375 // The default condition is that the frame status needs to be FramePartial or |
| 392 // FrameComplete, since the data of previous frames is copied in | 376 // FrameComplete, since the data of previous frames is copied in |
| 393 // InitFrameBuffer() before setting the status to FramePartial. For WebP, | 377 // InitFrameBuffer() before setting the status to FramePartial. For WebP, |
| 394 // however, the status needs to be FrameComplete since the complete buffer is | 378 // however, the status needs to be FrameComplete since the complete buffer is |
| 395 // used to do alpha blending in WEBPImageDecoder::ApplyPostProcessing(). | 379 // used to do alpha blending in WEBPImageDecoder::ApplyPostProcessing(). |
| 396 // | 380 // |
| 397 // Before calling this, verify that frame |index| exists by checking that | 381 // Before calling this, verify that frame |index| exists by checking that |
| 398 // |index| is smaller than |frame_buffer_cache_|.size(). | 382 // |index| is smaller than |frame_buffer_cache_|.size(). |
| 399 virtual bool FrameStatusSufficientForSuccessors(size_t index) { | 383 bool FrameStatusSufficientForSuccessors(size_t index) { |
| 400 DCHECK(index < frame_buffer_cache_.size()); | 384 DCHECK(index < frame_buffer_cache_.size()); |
| 401 return frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameEmpty; | 385 return frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameEmpty; |
| 402 } | 386 } |
| 403 | 387 |
| 404 private: | 388 private: |
| 405 // Some code paths compute the size of the image as "width * height * 4" | 389 // Some code paths compute the size of the image as "width * height * 4" |
| 406 // and return it as a (signed) int. Avoid overflow. | 390 // and return it as a (signed) int. Avoid overflow. |
| 407 static bool SizeCalculationMayOverflow(unsigned width, unsigned height) { | 391 static bool SizeCalculationMayOverflow(unsigned width, unsigned height) { |
| 408 unsigned long long total_size = static_cast<unsigned long long>(width) * | 392 unsigned long long total_size = static_cast<unsigned long long>(width) * |
| 409 static_cast<unsigned long long>(height); | 393 static_cast<unsigned long long>(height); |
| 410 return total_size > ((1 << 29) - 1); | 394 return total_size > ((1 << 29) - 1); |
| 411 } | 395 } |
| 412 | 396 |
| 413 bool purge_aggressively_; | 397 bool purge_aggressively_; |
| 414 | 398 |
| 415 // This methods gets called at the end of InitFrameBuffer. Subclasses can do | 399 // This methods gets called at the end of InitFrameBuffer. Subclasses can do |
| 416 // format specific initialization, for e.g. alpha settings, here. | 400 // format specific initialization, for e.g. alpha settings, here. |
| 417 virtual void OnInitFrameBuffer(size_t){}; | 401 void OnInitFrameBuffer(size_t); |
| 418 | 402 |
| 419 // Called by InitFrameBuffer to determine if it can take the bitmap of the | 403 // Called by InitFrameBuffer to determine if it can take the bitmap of the |
| 420 // previous frame. This condition is different for GIF and WEBP. | 404 // previous frame. This condition is different for GIF and WEBP. |
| 421 virtual bool CanReusePreviousFrameBuffer(size_t) const { return false; } | 405 bool CanReusePreviousFrameBuffer(size_t) const; |
| 422 | 406 |
| 423 IntSize size_; | 407 IntSize size_; |
| 424 bool size_available_ = false; | 408 bool size_available_ = false; |
| 425 bool is_all_data_received_ = false; | 409 bool is_all_data_received_ = false; |
| 426 bool failed_ = false; | 410 bool failed_ = false; |
| 427 bool has_histogrammed_color_space_ = false; | 411 bool has_histogrammed_color_space_ = false; |
| 428 | 412 |
| 429 sk_sp<SkColorSpace> embedded_color_space_ = nullptr; | 413 sk_sp<SkColorSpace> embedded_color_space_ = nullptr; |
| 430 bool source_to_target_color_transform_needs_update_ = false; | 414 bool source_to_target_color_transform_needs_update_ = false; |
| 431 std::unique_ptr<SkColorSpaceXform> source_to_target_color_transform_; | 415 std::unique_ptr<SkColorSpaceXform> source_to_target_color_transform_; |
| 416 std::unique_ptr<SkCodec> codec_; |
| 432 }; | 417 }; |
| 433 | 418 |
| 434 } // namespace blink | 419 } // namespace blink |
| 435 | 420 |
| 436 #endif | 421 #endif |
| OLD | NEW |