Bug Summary

File:Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore/rendering/svg/legacy/LegacyRenderSVGImage.cpp
Warning:line 131, column 26
Local variable 'cachedImage' is uncounted and unsafe

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple arm64-apple-ios26.2.0-simulator -O3 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name UnifiedSource432.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=osx -analyzer-checker=security.insecureAPI.decodeValueOfObjCType -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -target-sdk-version=26.2 -fdepfile-entry=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/SDKSettings.json -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fno-modulemap-allow-subdirectory-search -fdefine-target-os-macros -enable-tlsdesc -target-cpu apple-m1 -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +ccpp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -target-abi darwinpcs -dwarf-ext-refs -fmodule-format=obj -debug-info-kind=standalone -dwarf-version=5 -debugger-tuning=lldb -fdebug-compilation-dir=/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore -target-linker-version 1230.1 -fcoverage-compilation-dir=/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore -resource-dir /Users/buildbot/Library/Developer/Toolchains/swift-webkit.xctoolchain/usr/lib/clang/21 -dependency-file /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/scan-build-output/StaticAnalyzer/WebCore/WebCore/normal/arm64/UnifiedSource432.d -skip-unused-modulemap-deps -MT dependencies -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk -iquote /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release-iphonesimulator/WebCore.build/WebCore-generated-files.hmap -iquote /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release-iphonesimulator/WebCore.build/WebCore-project-headers.hmap -isystem /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore/PAL/ThirdParty/dav1d/include -isystem /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/SDKAdditions/usr/include -iframework /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/SDKAdditions/System/Library/Frameworks -iframework /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitLibraries/SDKs/iphonesimulator26.0-additions.sdk/System/Library/PrivateFrameworks -iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/System/Library/Frameworks -include-pch /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/PrecompiledHeaders/SharedPrecompiledHeaders/11721353671419897710/WebCorePrefix.h.gch -D _LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D NDEBUG -D BUILDING_WEBKIT -D GL_SILENCE_DEPRECATION=1 -D GLES_SILENCE_DEPRECATION=1 -D __clang_analyzer__ -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release-iphonesimulator/WebCore.build/WebCore-own-target-headers.hmap -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release-iphonesimulator/WebCore.build/WebCore-all-target-headers.hmap -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/include -I PAL -I ForwardingHeaders -I /usr/include/libxslt -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/include/libxml2 -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/DerivedSources/WebCore -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include/WebKitAdditions -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include/WebKitAdditions -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitLibraries/SDKs/iphonesimulator26.0-additions.sdk/usr/local/include -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include/webrtc -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include/webrtc -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include/webm -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include/webm -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/PAL.build/PAL.build/DerivedSources -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/PAL.build/Release-iphonesimulator/PAL.build/DerivedSources -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release-iphonesimulator/WebCore.build/DerivedSources-normal/arm64 -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release-iphonesimulator/WebCore.build/DerivedSources/arm64 -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebCore.build/Release-iphonesimulator/WebCore.build/DerivedSources -F/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator -F/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include -internal-isystem /Users/buildbot/Library/Developer/Toolchains/swift-webkit.xctoolchain/usr/lib/clang/21/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/include -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/System/Library/Frameworks -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/System/Library/SubFrameworks -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/Library/Frameworks -Wno-trigraphs -Werror -Wno-missing-field-initializers -Wmissing-prototypes -Wunreachable-code -Wnon-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wsign-compare -Wno-shorten-64-to-32 -Wnewline-eof -Wno-c++11-extensions -Wno-implicit-fallthrough -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion -Winfinite-recursion -Wmove -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wrange-loop-analysis -Wno-semicolon-before-method-body -Wall -Wc99-designator -Wconditional-uninitialized -Wextra -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion -Wenum-float-conversion -Wfinal-dtor-non-final-class -Wformat=2 -Wmisleading-indentation -Wpointer-to-int-cast -Wreorder-init-list -Wundef -Wunused-but-set-variable -Wvla -Werror=unguarded-availability -Wno-elaborated-enum-base -Wcast-qual -Wchar-subscripts -Wextra-tokens -Winit-self -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wno-unknown-warning-option -Wliteral-conversion -Wthread-safety -Wno-profile-instr-out-of-date -Wno-profile-instr-unprofiled -Wno-backend-plugin -Wunsafe-buffer-usage -std=c++2b -fdeprecated-macro -ferror-limit 19 -fmacro-backtrace-limit=0 -fvisibility=hidden -fvisibility-inlines-hidden -stack-protector 1 -fblocks -fencode-extended-block-signature -fno-rtti -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-cxx-modules -fno-implicit-modules -fskip-odr-check-in-gmf -fpascal-strings -fmax-type-align=16 -fdiagnostics-show-note-include-stack -vectorize-loops -vectorize-slp -fsafe-buffer-usage-suggestions -analyzer-output=html -analyzer-config report-in-main-source-file=true -analyzer-config nullability:NoDiagnoseCallsToSystemHeaders=true -analyzer-checker optin.osx.cocoa.localizability.NonLocalizedStringChecker -analyzer-checker security.insecureAPI.UncheckedReturn -analyzer-checker security.insecureAPI.getpw -analyzer-checker security.insecureAPI.gets -analyzer-checker security.insecureAPI.mkstemp -analyzer-checker security.insecureAPI.mktemp -analyzer-disable-checker security.insecureAPI.rand -analyzer-disable-checker security.insecureAPI.strcpy -analyzer-checker security.insecureAPI.vfork -analyzer-disable-checker alpha,apiModeling,core,cplusplus,deadcode,debug,fuchsia,nullability,optin,osx,security,unix,webkit -analyzer-checker alpha.webkit.ForwardDeclChecker,alpha.webkit.MemoryUnsafeCastChecker,alpha.webkit.NoDeleteChecker,alpha.webkit.NoUncheckedPtrMemberChecker,alpha.webkit.NoUnretainedMemberChecker,alpha.webkit.RetainPtrCtorAdoptChecker,alpha.webkit.UncheckedCallArgsChecker,alpha.webkit.UncheckedLocalVarsChecker,alpha.webkit.UncountedCallArgsChecker,alpha.webkit.UncountedLocalVarsChecker,alpha.webkit.UnretainedCallArgsChecker,alpha.webkit.UnretainedLambdaCapturesChecker,alpha.webkit.UnretainedLocalVarsChecker,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor,webkit.UncountedLambdaCapturesChecker -analyzer-config max-nodes=10000000 -analyzer-config verbose-report-filename=true -fdwarf2-cfi-asm -o /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/scan-build-output/StaticAnalyzer/WebCore/WebCore/normal/arm64/UnifiedSource432.plist -x c++ /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/DerivedSources/WebCore/unified-sources/UnifiedSource432.cpp
1/*
2 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
3 * Copyright (C) 2006 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
5 * Copyright (C) 2007, 2008, 2009 Rob Buis <buis@kde.org>
6 * Copyright (C) 2009 Google, Inc.
7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
8 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25
26#include "config.h"
27#include "LegacyRenderSVGImage.h"
28
29#include "FloatQuad.h"
30#include "GraphicsContext.h"
31#include "HitTestResult.h"
32#include "ImageQualityController.h"
33#include "LayoutRepainter.h"
34#include "LegacyRenderSVGResource.h"
35#include "PointerEventsHitRules.h"
36#include "RenderImageResource.h"
37#include "RenderObjectInlines.h"
38#include "RenderLayer.h"
39#include "SVGElementTypeHelpers.h"
40#include "SVGImageElement.h"
41#include "SVGRenderingContext.h"
42#include "SVGResources.h"
43#include "SVGResourcesCache.h"
44#include "SVGVisitedRendererTracking.h"
45#include <wtf/StackStats.h>
46#include <wtf/TZoneMallocInlines.h>
47
48namespace WebCore {
49
50WTF_MAKE_TZONE_ALLOCATED_IMPL(LegacyRenderSVGImage)::bmalloc::api::HeapRef LegacyRenderSVGImage::s_heapRef; const
TZoneSpecification LegacyRenderSVGImage::s_heapSpec = { &
LegacyRenderSVGImage::s_heapRef, TZoneSpecification::encodeSize
<LegacyRenderSVGImage>(), TZoneSpecification::encodeAlignment
<LegacyRenderSVGImage>(), TZoneSpecification::encodeCategory
<LegacyRenderSVGImage>(), ::bmalloc::api::compactAllocationMode
<LegacyRenderSVGImage>(), TZoneSpecification::encodeDescriptor
<LegacyRenderSVGImage>(), }; void* LegacyRenderSVGImage
::operatorNewSlow(size_t size) { if constexpr (::bmalloc::api
::compactAllocationMode<LegacyRenderSVGImage>() == CompactAllocationMode
::Compact) return ::bmalloc::api::tzoneAllocateCompactSlow(size
, s_heapSpec); return ::bmalloc::api::tzoneAllocateNonCompactSlow
(size, s_heapSpec); } using __makeBtzoneMallocedInlineMacroSemicolonifier
__attribute__((unused)) = int
;
51
52LegacyRenderSVGImage::LegacyRenderSVGImage(SVGImageElement& element, RenderStyle&& style)
53 : LegacyRenderSVGModelObject(Type::LegacySVGImage, element, WTF::move(style), SVGModelObjectFlag::UsesBoundaryCaching)
54 , m_needsBoundariesUpdate(true)
55 , m_needsTransformUpdate(true)
56 , m_imageResource(makeUniqueRef<RenderImageResource>())
57{
58 imageResource().initialize(*this);
59 ASSERT(isLegacyRenderSVGImage())((void)0);
60}
61
62LegacyRenderSVGImage::~LegacyRenderSVGImage() = default;
63
64void LegacyRenderSVGImage::notifyFinished(CachedResource& newImage, const NetworkLoadMetrics& metrics, LoadWillContinueInAnotherProcess loadWillContinueInAnotherProcess)
65{
66 if (renderTreeBeingDestroyed())
67 return;
68
69 if (RefPtr image = dynamicDowncast<SVGImageElement>(LegacyRenderSVGModelObject::element()))
70 page().didFinishLoadingImageForSVGImage(*image);
71
72 LegacyRenderSVGModelObject::notifyFinished(newImage, metrics, loadWillContinueInAnotherProcess);
73}
74
75void LegacyRenderSVGImage::willBeDestroyed()
76{
77 imageResource().willBeDestroyed();
78 LegacyRenderSVGModelObject::willBeDestroyed();
79}
80
81SVGImageElement& LegacyRenderSVGImage::imageElement() const
82{
83 return downcast<SVGImageElement>(LegacyRenderSVGModelObject::element());
84}
85
86FloatRect LegacyRenderSVGImage::calculateObjectBoundingBox() const
87{
88 LayoutSize intrinsicSize;
89 if (CachedImage* cachedImage = imageResource().cachedImage())
90 intrinsicSize = cachedImage->imageSizeForRenderer(nullptr, style().usedZoom());
91
92 Ref imageElement = this->imageElement();
93 SVGLengthContext lengthContext(imageElement.ptr());
94
95 CheckedRef style = this->style();
96 auto& width = style->width();
97 auto& height = style->height();
98 auto usedZoom = style->usedZoomForLength();
99
100 float concreteWidth;
101 if (!width.isAuto())
102 concreteWidth = lengthContext.valueForLength(width, usedZoom, SVGLengthMode::Width);
103 else if (!height.isAuto() && !intrinsicSize.isEmpty())
104 concreteWidth = lengthContext.valueForLength(height, usedZoom, SVGLengthMode::Height) * intrinsicSize.width() / intrinsicSize.height();
105 else
106 concreteWidth = intrinsicSize.width();
107
108 float concreteHeight;
109 if (!height.isAuto())
110 concreteHeight = lengthContext.valueForLength(height, usedZoom, SVGLengthMode::Height);
111 else if (!width.isAuto() && !intrinsicSize.isEmpty())
112 concreteHeight = lengthContext.valueForLength(width, usedZoom, SVGLengthMode::Width) * intrinsicSize.height() / intrinsicSize.width();
113 else
114 concreteHeight = intrinsicSize.height();
115
116 return { imageElement->x().value(lengthContext), imageElement->y().value(lengthContext), concreteWidth, concreteHeight };
117}
118
119bool LegacyRenderSVGImage::updateImageViewport()
120{
121 FloatRect oldBoundaries = m_objectBoundingBox;
122 m_objectBoundingBox = calculateObjectBoundingBox();
123
124 bool updatedViewport = false;
125 URL imageSourceURL = document().completeURL(imageElement().imageSourceURL());
126
127 // Images with preserveAspectRatio=none should force non-uniform scaling. This can be achieved
128 // by setting the image's container size to its intrinsic size.
129 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRatio’ attribute.
130 if (imageElement().preserveAspectRatio().align() == SVGPreserveAspectRatioValue::SVG_PRESERVEASPECTRATIO_NONE) {
131 if (CachedImage* cachedImage = imageResource().cachedImage()) {
Local variable 'cachedImage' is uncounted and unsafe
132 LayoutSize intrinsicSize = cachedImage->imageSizeForRenderer(nullptr, style().usedZoom());
133 if (intrinsicSize != imageResource().imageSize(style().usedZoom())) {
134 imageResource().setContainerContext(roundedIntSize(intrinsicSize), imageSourceURL);
135 updatedViewport = true;
136 }
137 }
138 }
139
140 if (oldBoundaries != m_objectBoundingBox) {
141 if (!updatedViewport)
142 imageResource().setContainerContext(enclosingIntRect(m_objectBoundingBox).size(), imageSourceURL);
143 updatedViewport = true;
144 m_needsBoundariesUpdate = true;
145 }
146
147 return updatedViewport;
148}
149
150void LegacyRenderSVGImage::layout()
151{
152 StackStats::LayoutCheckPoint layoutCheckPoint;
153 ASSERT(needsLayout())((void)0);
154
155 auto checkForRepaintOverride = !selfNeedsLayout() ? LayoutRepainter::CheckForRepaint::No : SVGRenderSupport::checkForSVGRepaintDuringLayout(*this);
156 LayoutRepainter repainter(*this, checkForRepaintOverride, { }, RepaintOutlineBounds::No);
157 updateImageViewport();
158
159 bool transformOrBoundariesUpdate = m_needsTransformUpdate || m_needsBoundariesUpdate;
160 if (m_needsTransformUpdate) {
161 m_localTransform = imageElement().animatedLocalTransform();
162 m_needsTransformUpdate = false;
163 }
164
165 if (m_needsBoundariesUpdate) {
166 m_repaintBoundingBox = m_objectBoundingBox;
167 SVGRenderSupport::intersectRepaintRectWithResources(*this, m_repaintBoundingBox);
168 m_needsBoundariesUpdate = false;
169 }
170
171 // Invalidate all resources of this client if our layout changed.
172 if (everHadLayout() && selfNeedsLayout())
173 SVGResourcesCache::clientLayoutChanged(*this);
174
175 // If our bounds changed, notify the parents.
176 if (transformOrBoundariesUpdate) {
177 if (CheckedPtr parent = this->parent())
178 parent->invalidateCachedBoundaries();
179 }
180
181 repainter.repaintAfterLayout();
182 clearNeedsLayout();
183}
184
185void LegacyRenderSVGImage::paint(PaintInfo& paintInfo, const LayoutPoint&)
186{
187 if (paintInfo.context().paintingDisabled() || paintInfo.phase != PaintPhase::Foreground
188 || style().usedVisibility() == Visibility::Hidden || !imageResource().cachedImage())
189 return;
190
191 FloatRect boundingBox = repaintRectInLocalCoordinates();
192 if (!SVGRenderSupport::paintInfoIntersectsRepaintRect(boundingBox, m_localTransform, paintInfo))
193 return;
194
195 PaintInfo childPaintInfo(paintInfo);
196 GraphicsContextStateSaver stateSaver(childPaintInfo.context());
197 childPaintInfo.applyTransform(m_localTransform);
198
199 if (childPaintInfo.phase == PaintPhase::Foreground) {
200 SVGRenderingContext renderingContext(*this, childPaintInfo);
201
202 if (renderingContext.isRenderingPrepared()) {
203 if (style().bufferedRendering() == BufferedRendering::Static && renderingContext.bufferForeground(m_bufferedForeground))
204 return;
205
206 paintForeground(childPaintInfo);
207 }
208 }
209
210 if (style().usedOutlineWidth())
211 paintOutline(childPaintInfo, IntRect(boundingBox));
212}
213
214void LegacyRenderSVGImage::paintForeground(PaintInfo& paintInfo)
215{
216 RefPtr<Image> image = imageResource().image();
217 if (!image)
218 return;
219
220 FloatRect destRect = m_objectBoundingBox;
221 FloatRect srcRect(0, 0, image->width(), image->height());
222
223 imageElement().preserveAspectRatio().transformRect(destRect, srcRect);
224
225 ImagePaintingOptions options = {
226 imageOrientation(),
227 ImageQualityController::chooseInterpolationQualityForSVG(paintInfo.context(), *this, *image),
228 paintInfo.paintBehavior.contains(PaintBehavior::DrawsHDRContent) ? DrawsHDRContent::Yes : DrawsHDRContent::No,
229 style().dynamicRangeLimit().toPlatformDynamicRangeLimit()
230 };
231
232 auto& context = paintInfo.context();
233 context.drawImage(*image, destRect, srcRect, options);
234
235 auto* cachedImage = imageResource().cachedImage();
236 if (cachedImage && !context.paintingDisabled())
237 protect(document())->didPaintImage(imageElement(), cachedImage, destRect);
238}
239
240void LegacyRenderSVGImage::invalidateBufferedForeground()
241{
242 m_bufferedForeground = nullptr;
243}
244
245bool LegacyRenderSVGImage::nodeAtFloatPoint(const HitTestRequest& request, HitTestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction)
246{
247 // We only draw in the forground phase, so we only hit-test then.
248 if (hitTestAction != HitTestForeground)
249 return false;
250
251 PointerEventsHitRules hitRules(PointerEventsHitRules::HitTestingTargetType::SVGImage, request, usedPointerEvents());
252 if (request.isVisibleForStyle(style()) || !hitRules.requireVisible) {
253 static NeverDestroyed<SVGVisitedRendererTracking::VisitedSet> s_visitedSet;
254
255 SVGVisitedRendererTracking recursionTracking(s_visitedSet);
256 if (recursionTracking.isVisiting(*this))
257 return false;
258
259 SVGVisitedRendererTracking::Scope recursionScope(recursionTracking, *this);
260
261 FloatPoint localPoint = valueOrDefault(localToParentTransform().inverse()).mapPoint(pointInParent);
262 if (!SVGRenderSupport::pointInClippingArea(*this, localPoint))
263 return false;
264
265 if (hitRules.canHitFill) {
266 if (m_objectBoundingBox.contains(localPoint)) {
267 updateHitTestResult(result, LayoutPoint(localPoint));
268 if (result.addNodeToListBasedTestResult(protect(nodeForHitTest()).get(), request, flooredLayoutPoint(localPoint)) == HitTestProgress::Stop)
269 return true;
270 }
271 }
272 }
273
274 return false;
275}
276
277void LegacyRenderSVGImage::imageChanged(WrappedImagePtr, const IntRect*)
278{
279 if (!parent())
280 return;
281 // The image resource defaults to nullImage until the resource arrives.
282 // This empty image may be cached by SVG resources which must be invalidated.
283 if (auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this))
284 resources->removeClientFromCacheAndMarkForInvalidation(*this);
285
286 // Eventually notify parent resources, that we've changed.
287 LegacyRenderSVGResource::markForLayoutAndParentResourceInvalidation(*this, false);
288
289 // Update the SVGImageCache sizeAndScales entry in case image loading finished after layout.
290 // (https://bugs.webkit.org/show_bug.cgi?id=99489)
291 m_objectBoundingBox = FloatRect();
292 if (updateImageViewport())
293 setNeedsLayout();
294
295 invalidateBufferedForeground();
296
297 repaint();
298
299 if (auto* image = imageResource().cachedImage(); image && image->currentFrameIsComplete(this)) {
300 if (auto styleable = Styleable::fromRenderer(*this))
301 protect(document())->didLoadImage(protect(styleable->element).get(), image);
302 }
303}
304
305void LegacyRenderSVGImage::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPoint&, const RenderLayerModelObject*) const
306{
307 // this is called from paint() after the localTransform has already been applied
308 LayoutRect contentRect = LayoutRect(repaintRectInLocalCoordinates());
309 if (!contentRect.isEmpty())
310 rects.append(contentRect);
311}
312
313} // namespace WebCore