Changeset 294694 in webkit
- Timestamp:
- May 23, 2022, 4:28:36 PM (4 years ago)
- Location:
- branches/safari-7613.3.1.0-branch/Source
- Files:
-
- 7 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (modified) (1 diff)
-
WebCore/platform/graphics/BitmapImage.cpp (modified) (3 diffs)
-
WebCore/platform/graphics/BitmapImage.h (modified) (2 diffs)
-
WebCore/platform/graphics/ImageSource.cpp (modified) (3 diffs)
-
WebCore/platform/graphics/ImageSource.h (modified) (5 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-7613.3.1.0-branch/Source/WebCore/ChangeLog
r294672 r294694 85 85 (WebCore::AccessibilityObject::accessibilityIsIgnored const): 86 86 Don't call ignoredFromModalPresence if we're in the midst of computing the current modal. 87 88 2022-05-23 Alan Coon <alancoon@apple.com>89 90 Cherry-pick r294280. rdar://problem/8798054391 92 REGRESSION(r249162): CanvasRenderingContext2DBase::drawImage() crashes if the image is animated and the first frame cannot be decoded93 https://bugs.webkit.org/show_bug.cgi?id=23911394 rdar://8798054395 96 Reviewed by Simon Fraser.97 98 Source/WebCore:99 100 CanvasRenderingContext2DBase::drawImage() needs to ensure the first frame101 of the animated image can be decoded correctly before creating the temporary102 static image. If the first frame can't be decoded, this function should return103 immediately. This matches the behavior of this function before r249162.104 105 The animated image decodes its frames asynchronously in a work queue. But106 the first frame has to be decoded synchronously in the main run loop. So107 to avoid running the image decoder in two different threads we are going108 to keep the first and the current frame cached when we receive a memory109 pressure warning. This should not increase the memory allocation of the110 animated image because the numbers of cached frames increases quickly and111 we keep all of them till a memory warning is received. But the memory112 pressure warning will be received a little bit more often. This depends113 on the memory size of the first frame.114 115 To make the code more robust, make ImageSource take a Ref<NativeImage>116 instead of taking a RefPtr<NativeImage>.117 118 * html/canvas/CanvasRenderingContext2DBase.cpp:119 (WebCore::CanvasRenderingContext2DBase::drawImage):120 * platform/graphics/BitmapImage.cpp:121 (WebCore::BitmapImage::BitmapImage):122 (WebCore::BitmapImage::destroyDecodedData):123 * platform/graphics/BitmapImage.h:124 * platform/graphics/ImageSource.cpp:125 (WebCore::ImageSource::ImageSource):126 (WebCore::ImageSource::destroyDecodedData):127 (WebCore::ImageSource::setNativeImage):128 * platform/graphics/ImageSource.h:129 (WebCore::ImageSource::create):130 (WebCore::ImageSource::isDecoderAvailable const):131 (WebCore::ImageSource::destroyAllDecodedData): Deleted.132 (WebCore::ImageSource::destroyAllDecodedDataExcludeFrame): Deleted.133 (WebCore::ImageSource::destroyDecodedDataBeforeFrame): Deleted.134 135 Source/WebKit:136 137 * GPUProcess/graphics/RemoteDisplayListRecorder.cpp:138 (WebKit::RemoteDisplayListRecorder::drawSystemImage):139 140 Canonical link: https://commits.webkit.org/250624@main141 git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294280 268f45cc-cd09-0410-ab3c-d52691b4dbfc142 143 2022-05-16 Said Abou-Hallawa <said@apple.com>144 145 REGRESSION(r249162): CanvasRenderingContext2DBase::drawImage() crashes if the image is animated and the first frame cannot be decoded146 https://bugs.webkit.org/show_bug.cgi?id=239113147 rdar://87980543148 149 Reviewed by Simon Fraser.150 151 CanvasRenderingContext2DBase::drawImage() needs to ensure the first frame152 of the animated image can be decoded correctly before creating the temporary153 static image. If the first frame can't be decoded, this function should return154 immediately. This matches the behavior of this function before r249162.155 156 The animated image decodes its frames asynchronously in a work queue. But157 the first frame has to be decoded synchronously in the main run loop. So158 to avoid running the image decoder in two different threads we are going159 to keep the first and the current frame cached when we receive a memory160 pressure warning. This should not increase the memory allocation of the161 animated image because the numbers of cached frames increases quickly and162 we keep all of them till a memory warning is received. But the memory163 pressure warning will be received a little bit more often. This depends164 on the memory size of the first frame.165 166 To make the code more robust, make ImageSource take a Ref<NativeImage>167 instead of taking a RefPtr<NativeImage>.168 169 * html/canvas/CanvasRenderingContext2DBase.cpp:170 (WebCore::CanvasRenderingContext2DBase::drawImage):171 * platform/graphics/BitmapImage.cpp:172 (WebCore::BitmapImage::BitmapImage):173 (WebCore::BitmapImage::destroyDecodedData):174 * platform/graphics/BitmapImage.h:175 * platform/graphics/ImageSource.cpp:176 (WebCore::ImageSource::ImageSource):177 (WebCore::ImageSource::destroyDecodedData):178 (WebCore::ImageSource::setNativeImage):179 * platform/graphics/ImageSource.h:180 (WebCore::ImageSource::create):181 (WebCore::ImageSource::isDecoderAvailable const):182 (WebCore::ImageSource::destroyAllDecodedData): Deleted.183 (WebCore::ImageSource::destroyAllDecodedDataExcludeFrame): Deleted.184 (WebCore::ImageSource::destroyDecodedDataBeforeFrame): Deleted.185 87 186 88 2022-05-23 Alan Coon <alancoon@apple.com> -
branches/safari-7613.3.1.0-branch/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
r294669 r294694 1546 1546 if (image->isBitmapImage()) { 1547 1547 // Drawing an animated image to a canvas should draw the first frame (except for a few layout tests) 1548 if (image->isAnimated() && !document.settings().animatedImageDebugCanvasDrawingEnabled()) {1548 if (image->isAnimated() && !document.settings().animatedImageDebugCanvasDrawingEnabled()) 1549 1549 image = BitmapImage::create(image->nativeImage()); 1550 if (!image)1551 return { };1552 }1553 1550 downcast<BitmapImage>(*image).updateFromSettings(document.settings()); 1554 1551 } -
branches/safari-7613.3.1.0-branch/Source/WebCore/platform/graphics/BitmapImage.cpp
r294669 r294694 53 53 } 54 54 55 BitmapImage::BitmapImage(Ref<NativeImage>&& image) 56 : m_source(ImageSource::create(WTFMove(image))) 55 BitmapImage::BitmapImage(RefPtr<NativeImage>&& image, ImageObserver* observer) 56 : Image(observer) 57 , m_source(ImageSource::create(WTFMove(image))) 57 58 { 58 59 } … … 77 78 LOG(Images, "BitmapImage::%s - %p - url: %s", __FUNCTION__, this, sourceURL().string().utf8().data()); 78 79 79 if (!destroyAll) { 80 // Destroy all the frames between frame0 and m_currentFrame. 81 m_source->destroyDecodedData(1, m_currentFrame); 82 } else if (!canDestroyDecodedData()) { 83 // Destroy all the frames except frame0 and m_currentFrame. 84 m_source->destroyDecodedData(1, m_currentFrame); 85 m_source->destroyDecodedData(m_currentFrame + 1, frameCount()); 86 } else { 87 m_source->destroyDecodedData(0, frameCount()); 80 if (!destroyAll) 81 m_source->destroyDecodedDataBeforeFrame(m_currentFrame); 82 else if (!canDestroyDecodedData()) 83 m_source->destroyAllDecodedDataExcludeFrame(m_currentFrame); 84 else { 85 m_source->destroyAllDecodedData(); 88 86 m_currentFrameDecodingStatus = DecodingStatus::Invalid; 89 87 } … … 231 229 return ImageDrawResult::DidNothing; 232 230 231 233 232 auto srcRect = requestedSrcRect; 234 233 auto preferredSize = size(); -
branches/safari-7613.3.1.0-branch/Source/WebCore/platform/graphics/BitmapImage.h
r294669 r294694 54 54 class BitmapImage final : public Image { 55 55 public: 56 static Ref Ptr<BitmapImage> create(PlatformImagePtr&& platformImage)56 static Ref<BitmapImage> create(PlatformImagePtr&& platformImage, ImageObserver* observer = nullptr) 57 57 { 58 return create(NativeImage::create(WTFMove(platformImage)));58 return adoptRef(*new BitmapImage(NativeImage::create(WTFMove(platformImage)), observer)); 59 59 } 60 static Ref Ptr<BitmapImage> create(RefPtr<NativeImage>&& nativeImage)60 static Ref<BitmapImage> create(RefPtr<NativeImage>&& nativeImage, ImageObserver* observer = nullptr) 61 61 { 62 if (!nativeImage) 63 return nullptr; 64 return create(nativeImage.releaseNonNull()); 65 } 66 static Ref<BitmapImage> create(Ref<NativeImage>&& nativeImage) 67 { 68 return adoptRef(*new BitmapImage(WTFMove(nativeImage))); 62 return adoptRef(*new BitmapImage(WTFMove(nativeImage), observer)); 69 63 } 70 64 static Ref<BitmapImage> create(ImageObserver* observer = nullptr) … … 161 155 162 156 private: 163 WEBCORE_EXPORT BitmapImage(Ref <NativeImage>&&);157 WEBCORE_EXPORT BitmapImage(RefPtr<NativeImage>&&, ImageObserver* = nullptr); 164 158 WEBCORE_EXPORT BitmapImage(ImageObserver* = nullptr); 165 159 -
branches/safari-7613.3.1.0-branch/Source/WebCore/platform/graphics/ImageSource.cpp
r294669 r294694 45 45 } 46 46 47 ImageSource::ImageSource(Ref <NativeImage>&& nativeImage)47 ImageSource::ImageSource(RefPtr<NativeImage>&& nativeImage) 48 48 : m_runLoop(RunLoop::current()) 49 49 { … … 121 121 } 122 122 123 void ImageSource::destroyDecodedData(size_t begin, size_t end) 124 { 125 if (begin >= end) 126 return; 127 128 ASSERT(end <= m_frames.size()); 129 123 void ImageSource::destroyDecodedData(size_t frameCount, size_t excludeFrame) 124 { 130 125 unsigned decodedSize = 0; 131 126 132 for (size_t index = begin; index < end; ++index) 127 ASSERT(frameCount <= m_frames.size()); 128 129 for (size_t index = 0; index < frameCount; ++index) { 130 if (index == excludeFrame) 131 continue; 133 132 decodedSize += m_frames[index].clearImage(); 133 } 134 134 135 135 decodedSizeReset(decodedSize); … … 233 233 } 234 234 235 void ImageSource::setNativeImage(Ref <NativeImage>&& nativeImage)235 void ImageSource::setNativeImage(RefPtr<NativeImage>&& nativeImage) 236 236 { 237 237 ASSERT(m_frames.size() == 1); -
branches/safari-7613.3.1.0-branch/Source/WebCore/platform/graphics/ImageSource.h
r294669 r294694 52 52 } 53 53 54 static Ref<ImageSource> create(Ref <NativeImage>&& nativeImage)54 static Ref<ImageSource> create(RefPtr<NativeImage>&& nativeImage) 55 55 { 56 56 return adoptRef(*new ImageSource(WTFMove(nativeImage))); … … 63 63 64 64 unsigned decodedSize() const { return m_decodedSize; } 65 void destroyDecodedData(size_t begin, size_t end); 65 void destroyAllDecodedData() { destroyDecodedData(frameCount(), frameCount()); } 66 void destroyAllDecodedDataExcludeFrame(size_t excludeFrame) { destroyDecodedData(frameCount(), excludeFrame); } 67 void destroyDecodedDataBeforeFrame(size_t beforeFrame) { destroyDecodedData(beforeFrame, beforeFrame); } 66 68 void destroyIncompleteDecodedData(); 67 69 void clearFrameBufferCache(size_t beforeFrame); … … 127 129 private: 128 130 ImageSource(BitmapImage*, AlphaOption = AlphaOption::Premultiplied, GammaAndColorProfileOption = GammaAndColorProfileOption::Applied); 129 ImageSource(Ref <NativeImage>&&);131 ImageSource(RefPtr<NativeImage>&&); 130 132 131 133 enum class MetadataType { … … 152 154 bool ensureDecoderAvailable(FragmentedSharedBuffer* data); 153 155 bool isDecoderAvailable() const { return m_decoder; } 156 void destroyDecodedData(size_t frameCount, size_t excludeFrame); 154 157 void decodedSizeChanged(long long decodedSize); 155 158 void didDecodeProperties(unsigned decodedPropertiesSize); … … 159 162 void encodedDataStatusChanged(EncodedDataStatus); 160 163 161 void setNativeImage(Ref <NativeImage>&&);164 void setNativeImage(RefPtr<NativeImage>&&); 162 165 void cacheMetadataAtIndex(size_t, SubsamplingLevel, DecodingStatus = DecodingStatus::Invalid); 163 166 void cachePlatformImageAtIndex(PlatformImagePtr&&, size_t, SubsamplingLevel, const DecodingOptions&, DecodingStatus = DecodingStatus::Invalid); -
branches/safari-7613.3.1.0-branch/Source/WebKit/ChangeLog
r294669 r294694 1 2022-05-23 Alan Coon <alancoon@apple.com>2 3 Cherry-pick r294280. rdar://problem/879805434 5 REGRESSION(r249162): CanvasRenderingContext2DBase::drawImage() crashes if the image is animated and the first frame cannot be decoded6 https://bugs.webkit.org/show_bug.cgi?id=2391137 rdar://879805438 9 Reviewed by Simon Fraser.10 11 Source/WebCore:12 13 CanvasRenderingContext2DBase::drawImage() needs to ensure the first frame14 of the animated image can be decoded correctly before creating the temporary15 static image. If the first frame can't be decoded, this function should return16 immediately. This matches the behavior of this function before r249162.17 18 The animated image decodes its frames asynchronously in a work queue. But19 the first frame has to be decoded synchronously in the main run loop. So20 to avoid running the image decoder in two different threads we are going21 to keep the first and the current frame cached when we receive a memory22 pressure warning. This should not increase the memory allocation of the23 animated image because the numbers of cached frames increases quickly and24 we keep all of them till a memory warning is received. But the memory25 pressure warning will be received a little bit more often. This depends26 on the memory size of the first frame.27 28 To make the code more robust, make ImageSource take a Ref<NativeImage>29 instead of taking a RefPtr<NativeImage>.30 31 * html/canvas/CanvasRenderingContext2DBase.cpp:32 (WebCore::CanvasRenderingContext2DBase::drawImage):33 * platform/graphics/BitmapImage.cpp:34 (WebCore::BitmapImage::BitmapImage):35 (WebCore::BitmapImage::destroyDecodedData):36 * platform/graphics/BitmapImage.h:37 * platform/graphics/ImageSource.cpp:38 (WebCore::ImageSource::ImageSource):39 (WebCore::ImageSource::destroyDecodedData):40 (WebCore::ImageSource::setNativeImage):41 * platform/graphics/ImageSource.h:42 (WebCore::ImageSource::create):43 (WebCore::ImageSource::isDecoderAvailable const):44 (WebCore::ImageSource::destroyAllDecodedData): Deleted.45 (WebCore::ImageSource::destroyAllDecodedDataExcludeFrame): Deleted.46 (WebCore::ImageSource::destroyDecodedDataBeforeFrame): Deleted.47 48 Source/WebKit:49 50 * GPUProcess/graphics/RemoteDisplayListRecorder.cpp:51 (WebKit::RemoteDisplayListRecorder::drawSystemImage):52 53 Canonical link: https://commits.webkit.org/250624@main54 git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294280 268f45cc-cd09-0410-ab3c-d52691b4dbfc55 56 2022-05-16 Said Abou-Hallawa <said@apple.com>57 58 REGRESSION(r249162): CanvasRenderingContext2DBase::drawImage() crashes if the image is animated and the first frame cannot be decoded59 https://bugs.webkit.org/show_bug.cgi?id=23911360 rdar://8798054361 62 Reviewed by Simon Fraser.63 64 * GPUProcess/graphics/RemoteDisplayListRecorder.cpp:65 (WebKit::RemoteDisplayListRecorder::drawSystemImage):66 67 1 2022-05-02 Alan Coon <alancoon@apple.com> 68 2
Note:
See TracChangeset
for help on using the changeset viewer.