Bug Summary

File:Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResource.cpp
Warning:line 56, column 9
Call argument for 'this' parameter is unchecked 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 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
5 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
6 * Copyright (C) 2023-2026 Apple Inc. All rights reserved.
7 * Copyright (C) 2014 Google Inc. All rights reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25#include "config.h"
26#include "LegacyRenderSVGResource.h"
27
28#include "ContainerNodeInlines.h"
29#include "LegacyRenderSVGResourceClipper.h"
30#include "LegacyRenderSVGResourceFilter.h"
31#include "LegacyRenderSVGResourceMasker.h"
32#include "LegacyRenderSVGResourceSolidColor.h"
33#include "LegacyRenderSVGRoot.h"
34#include "LegacyRenderSVGShape.h"
35#include "LocalFrame.h"
36#include "LocalFrameView.h"
37#include "RenderElementInlines.h"
38#include "RenderObjectInlines.h"
39#include "RenderSVGRoot.h"
40#include "RenderSVGShape.h"
41#include "RenderView.h"
42#include "SVGResourceElementClient.h"
43#include "SVGResources.h"
44#include "SVGResourcesCache.h"
45#include "SVGURIReference.h"
46#include "Settings.h"
47#include "StyleComputedStyle+InitialInlines.h"
48
49namespace WebCore {
50
51static inline LegacyRenderSVGResource* requestPaintingResource(RenderSVGResourceMode mode, RenderElement& renderer, const RenderStyle& style, Color& fallbackColor)
52{
53 bool applyToFill = mode == RenderSVGResourceMode::ApplyToFill;
54
55 // When rendering the mask for a LegacyRenderSVGResourceClipper, always use the initial fill paint server.
56 if (renderer.view().frameView().paintBehavior().contains(PaintBehavior::RenderingSVGClipOrMask)) {
Call argument for 'this' parameter is unchecked and unsafe
57 // Ignore stroke.
58 if (!applyToFill)
59 return nullptr;
60
61 // But always use the initial fill paint server.
62 LegacyRenderSVGResourceSolidColor* colorResource = LegacyRenderSVGResource::sharedSolidPaintingResource();
63 colorResource->setColor(Style::ComputedStyle::initialFill().colorDisregardingType().resolvedColor());
64 return colorResource;
65 }
66
67 const auto& paint = applyToFill ? style.fill() : style.stroke();
68
69 // If we have no fill/stroke, return nullptr.
70 if (paint.isNone())
71 return nullptr;
72
73 Style::ColorResolver colorResolver { style };
74
75 Color color;
76 if (auto paintColor = paint.tryAnyColor())
77 color = colorResolver.colorResolvingCurrentColor(*paintColor);
78
79 if (style.insideLink() == InsideLink::InsideVisited) {
80 // FIXME: This code doesn't support the uri component of the visited link paint, https://bugs.webkit.org/show_bug.cgi?id=70006
81 auto& visitedPaint = applyToFill ? style.visitedLinkFill() : style.visitedLinkStroke();
82
83 if (auto visitedPaintColor = visitedPaint.tryColor()) {
84 if (visitedPaintColor->isCurrentColor())
85 color = style.visitedLinkColor();
86 else if (auto visitedColor = colorResolver.colorResolvingCurrentColor(*visitedPaintColor); visitedColor.isValid())
87 color = visitedColor.colorWithAlpha(color.alphaAsFloat());
88 }
89 }
90
91 // If the primary resource is just a color, return immediately.
92 auto* colorResource = LegacyRenderSVGResource::sharedSolidPaintingResource();
93 if (paint.isColor()) {
94 colorResource->setColor(color);
95 return colorResource;
96 }
97
98 // FIXME: [LBSE] Add support for non-solid color resources in LBSE (gradient/pattern).
99 SVGResources* resources = nullptr;
100 if (!renderer.document().settings().layerBasedSVGEngineEnabled())
101 resources = SVGResourcesCache::cachedResourcesForRenderer(renderer);
102
103 LegacyRenderSVGResource* uriResource = nullptr;
104 if (resources)
105 uriResource = mode == RenderSVGResourceMode::ApplyToFill ? resources->fill() : resources->stroke();
106
107 // If the requested resource is not available, return the color resource or 'none'.
108 if (!uriResource) {
109 // The fallback is 'none'. (SVG2 say 'none' is implied when no fallback is specified.)
110 if (paint.isURLNone())
111 return nullptr;
112
113 colorResource->setColor(color);
114 return colorResource;
115 }
116
117 // The paint server resource exists, though it may be invalid (pattern with width/height=0). Pass the fallback color to our caller
118 // so it can use the solid color painting resource, if applyResource() on the URI resource failed.
119 fallbackColor = color;
120 return uriResource;
121}
122
123void LegacyRenderSVGResource::removeAllClientsFromCacheAndMarkForInvalidation(bool markForInvalidation)
124{
125 SingleThreadWeakHashSet<RenderObject> visitedRenderers;
126 removeAllClientsFromCacheAndMarkForInvalidationIfNeeded(markForInvalidation, &visitedRenderers);
127}
128
129LegacyRenderSVGResource* LegacyRenderSVGResource::fillPaintingResource(RenderElement& renderer, const RenderStyle& style, Color& fallbackColor)
130{
131 return requestPaintingResource(RenderSVGResourceMode::ApplyToFill, renderer, style, fallbackColor);
132}
133
134LegacyRenderSVGResource* LegacyRenderSVGResource::strokePaintingResource(RenderElement& renderer, const RenderStyle& style, Color& fallbackColor)
135{
136 return requestPaintingResource(RenderSVGResourceMode::ApplyToStroke, renderer, style, fallbackColor);
137}
138
139LegacyRenderSVGResourceSolidColor* LegacyRenderSVGResource::sharedSolidPaintingResource()
140{
141 static LegacyRenderSVGResourceSolidColor* s_sharedSolidPaintingResource = 0;
142 if (!s_sharedSolidPaintingResource)
143 s_sharedSolidPaintingResource = new LegacyRenderSVGResourceSolidColor;
144 return s_sharedSolidPaintingResource;
145}
146
147static void removeFromCacheAndInvalidateDependencies(RenderElement& renderer, bool needsLayout, SingleThreadWeakHashSet<RenderObject>* visitedRenderers)
148{
149 if (auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer)) {
150 if (LegacyRenderSVGResourceFilter* filter = resources->filter())
151 filter->removeClientFromCacheAndMarkForInvalidation(renderer);
152
153 if (LegacyRenderSVGResourceMasker* masker = resources->masker())
154 masker->removeClientFromCacheAndMarkForInvalidation(renderer);
155
156 if (LegacyRenderSVGResourceClipper* clipper = resources->clipper())
157 clipper->removeClientFromCacheAndMarkForInvalidation(renderer);
158 }
159
160 auto svgElement = dynamicDowncast<SVGElement>(protect(renderer.element()));
161 if (!svgElement)
162 return;
163
164 for (auto& element : svgElement->referencingElements()) {
165 if (auto* renderer = element->renderer()) {
166 // We allow cycles in SVGDocumentExtensions reference sets in order to avoid expensive
167 // reference graph adjustments on changes, so we need to break possible cycles here.
168 static NeverDestroyed<WeakHashSet<SVGElement, WeakPtrImplWithEventTargetData>> invalidatingDependencies;
169 if (!invalidatingDependencies.get().add(element.get()).isNewEntry) [[unlikely]] {
170 // Reference cycle: we are in process of invalidating this dependant.
171 continue;
172 }
173 LegacyRenderSVGResource::markForLayoutAndParentResourceInvalidationIfNeeded(*renderer, needsLayout, visitedRenderers);
174 invalidatingDependencies.get().remove(element.get());
175 }
176 }
177
178 for (auto& cssClient : svgElement->referencingCSSClients()) {
179 if (!cssClient)
180 continue;
181 cssClient->resourceChanged(*svgElement);
182 }
183}
184
185void LegacyRenderSVGResource::markForLayoutAndParentResourceInvalidation(RenderObject& object, bool needsLayout)
186{
187 SingleThreadWeakHashSet<RenderObject> visitedRenderers;
188 markForLayoutAndParentResourceInvalidationIfNeeded(object, needsLayout, &visitedRenderers);
189}
190
191void LegacyRenderSVGResource::markForLayoutAndParentResourceInvalidationIfNeeded(RenderObject& object, bool needsLayout, SingleThreadWeakHashSet<RenderObject>* visitedRenderers)
192{
193 ASSERT(object.node())((void)0);
194 if (object.document().settings().layerBasedSVGEngineEnabled()) {
195 RELEASE_ASSERT_NOT_REACHED()do { WTF::isIntegralOrPointerType(); compilerFenceForCrash();
WTFCrashWithInfo(195, "/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResource.cpp"
, __PRETTY_FUNCTION__ ); } while (false)
;
196 return;
197 }
198
199 if (visitedRenderers) {
200 auto addResult = visitedRenderers->add(object);
201 if (!addResult.isNewEntry)
202 return;
203 }
204
205 if (needsLayout && !object.renderTreeBeingDestroyed()) {
206 // If we are inside the layout of an LegacyRenderSVGRoot, do not cross the SVG boundary to
207 // invalidate the ancestor renderer because it may have finished its layout already.
208 if (CheckedPtr svgRoot = dynamicDowncast<LegacyRenderSVGRoot>(object); svgRoot && svgRoot->isInLayout())
209 svgRoot->setNeedsLayout(MarkOnlyThis);
210 else {
211 if (CheckedPtr element = dynamicDowncast<RenderElement>(object)) {
212 auto svgRoot = SVGRenderSupport::findTreeRootObject(*element);
213 if (!svgRoot || !svgRoot->isInLayout())
214 element->setNeedsLayout(MarkContainingBlockChain);
215 else {
216 // We just want to re-layout the ancestors up to the RenderSVGRoot.
217 element->setNeedsLayout(MarkOnlyThis);
218 for (auto current = element->parent(); current != svgRoot; current = current->parent())
219 current->setNeedsLayout(MarkOnlyThis);
220 svgRoot->setNeedsLayout(MarkOnlyThis);
221 }
222 } else
223 object.setNeedsLayout(MarkOnlyThis);
224 }
225 }
226
227 if (CheckedPtr element = dynamicDowncast<RenderElement>(object))
228 removeFromCacheAndInvalidateDependencies(*element, needsLayout, visitedRenderers);
229
230 // Invalidate resources in ancestor chain, if needed.
231 auto current = object.parent();
232 while (current) {
233 removeFromCacheAndInvalidateDependencies(*current, needsLayout, visitedRenderers);
234
235 if (CheckedPtr container = dynamicDowncast<LegacyRenderSVGResourceContainer>(*current)) {
236 // This will process the rest of the ancestors.
237 bool markForInvalidation = true;
238 container->removeAllClientsFromCacheAndMarkForInvalidationIfNeeded(markForInvalidation, visitedRenderers);
239 break;
240 }
241
242 current = current->parent();
243 }
244}
245
246void LegacyRenderSVGResource::fillAndStrokePathOrShape(GraphicsContext& context, OptionSet<RenderSVGResourceMode> resourceMode, const Path* path, const RenderElement* shape)
247{
248 if (shape) {
249 ASSERT(shape->isRenderOrLegacyRenderSVGShape())((void)0);
250
251 if (resourceMode.contains(RenderSVGResourceMode::ApplyToFill)) {
252 if (CheckedPtr svgShape = dynamicDowncast<LegacyRenderSVGShape>(shape))
253 svgShape->fillShape(context);
254 else if (CheckedPtr svgShape = dynamicDowncast<RenderSVGShape>(shape))
255 svgShape->fillShape(context);
256 }
257
258 if (resourceMode.contains(RenderSVGResourceMode::ApplyToStroke)) {
259 if (CheckedPtr svgShape = dynamicDowncast<LegacyRenderSVGShape>(shape))
260 svgShape->strokeShape(context);
261 else if (CheckedPtr svgShape = dynamicDowncast<RenderSVGShape>(shape))
262 svgShape->strokeShape(context);
263 }
264
265 return;
266 }
267
268 if (!path)
269 return;
270
271 if (resourceMode.contains(RenderSVGResourceMode::ApplyToFill))
272 context.fillPath(*path);
273 if (resourceMode.contains(RenderSVGResourceMode::ApplyToStroke))
274 context.strokePath(*path);
275}
276
277}