Skip to content

Commit

Permalink
[view-transitions] https://pokedex-dev.vercel.app/pokemons has super …
Browse files Browse the repository at this point in the history
…low framerate.

https://bugs.webkit.org/show_bug.cgi?id=274439
<rdar://128030956>

Reviewed by Tim Nguyen.

We invalidate the stylesheet every frame, resulting in way too much painting.

Instead, only invalidate the stylesheet if we actually inserted new styles.
Also invalidate layout, and the layer configuration for the pseudo if we
change those.

* Source/WebCore/css/MutableStyleProperties.cpp:
(WebCore::MutableStyleProperties::mergeAndOverrideOnConflict):
* Source/WebCore/css/MutableStyleProperties.h:
* Source/WebCore/dom/ViewTransition.cpp:
(WebCore::ViewTransition::updatePseudoElementStyles):
* Source/WebCore/rendering/RenderViewTransitionCapture.cpp:
(WebCore::RenderViewTransitionCapture::setSize):
* Source/WebCore/rendering/RenderViewTransitionCapture.h:

Canonical link: https://commits.webkit.org/279049@main
  • Loading branch information
mattwoodrow committed May 21, 2024
1 parent 8e3653b commit a3c5034
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Source/WebCore/css/MutableStyleProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,12 @@ bool MutableStyleProperties::addParsedProperty(const CSSProperty& property)
return setProperty(property);
}

void MutableStyleProperties::mergeAndOverrideOnConflict(const StyleProperties& other)
bool MutableStyleProperties::mergeAndOverrideOnConflict(const StyleProperties& other)
{
bool changed = false;
for (auto property : other)
addParsedProperty(property.toCSSProperty());
changed |= addParsedProperty(property.toCSSProperty());
return changed;
}

void MutableStyleProperties::clear()
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/MutableStyleProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MutableStyleProperties final : public StyleProperties {
bool removeProperty(CSSPropertyID, String* returnText = nullptr);
bool removeProperties(std::span<const CSSPropertyID>);

void mergeAndOverrideOnConflict(const StyleProperties&);
bool mergeAndOverrideOnConflict(const StyleProperties&);

void clear();
bool parseDeclaration(const String& styleDeclaration, CSSParserContext);
Expand Down
15 changes: 11 additions & 4 deletions Source/WebCore/dom/ViewTransition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ Ref<MutableStyleProperties> ViewTransition::copyElementBaseProperties(RenderLaye
ExceptionOr<void> ViewTransition::updatePseudoElementStyles()
{
Ref resolver = protectedDocument()->styleScope().resolver();
bool changed = false;

for (auto& [name, capturedElement] : m_namedElements.map()) {
RefPtr<MutableStyleProperties> properties;
Expand All @@ -701,11 +702,15 @@ ExceptionOr<void> ViewTransition::updatePseudoElementStyles()
if (RefPtr documentElement = document()->documentElement()) {
Styleable styleable(*documentElement, Style::PseudoElementIdentifier { PseudoId::ViewTransitionNew, name });
if (CheckedPtr viewTransitionCapture = dynamicDowncast<RenderViewTransitionCapture>(styleable.renderer())) {
viewTransitionCapture->setSize(boxSize, overflowRect);
if (viewTransitionCapture->setSize(boxSize, overflowRect))
viewTransitionCapture->setNeedsLayout();

RefPtr<ImageBuffer> image;
if (RefPtr frame = document()->frame(); !viewTransitionCapture->canUseExistingLayers())
if (RefPtr frame = document()->frame(); !viewTransitionCapture->canUseExistingLayers()) {
image = snapshotElementVisualOverflowClippedToViewport(*frame, *renderer, overflowRect);
changed = true;
} else if (CheckedPtr layer = renderer->layer())
layer->setNeedsCompositingGeometryUpdate();
viewTransitionCapture->setImage(image);
}
}
Expand All @@ -717,12 +722,14 @@ ExceptionOr<void> ViewTransition::updatePseudoElementStyles()
if (!capturedElement->groupStyleProperties) {
capturedElement->groupStyleProperties = properties;
resolver->setViewTransitionStyles(CSSSelector::PseudoElement::ViewTransitionGroup, name, *properties);
changed = true;
} else
capturedElement->groupStyleProperties->mergeAndOverrideOnConflict(*properties);
changed |= capturedElement->groupStyleProperties->mergeAndOverrideOnConflict(*properties);
}
}

protectedDocument()->styleScope().didChangeStyleSheetContents();
if (changed)
protectedDocument()->styleScope().didChangeStyleSheetContents();
return { };
}

Expand Down
5 changes: 4 additions & 1 deletion Source/WebCore/rendering/RenderViewTransitionCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ void RenderViewTransitionCapture::setImage(RefPtr<ImageBuffer> oldImage)
m_oldImage = oldImage;
}

void RenderViewTransitionCapture::setSize(const LayoutSize& size, const LayoutRect& overflowRect)
bool RenderViewTransitionCapture::setSize(const LayoutSize& size, const LayoutRect& overflowRect)
{
if (m_overflowRect == overflowRect && intrinsicSize() == size)
return false;
setIntrinsicSize(size);
m_overflowRect = overflowRect;
return true;
}

void RenderViewTransitionCapture::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/RenderViewTransitionCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RenderViewTransitionCapture final : public RenderReplaced {
virtual ~RenderViewTransitionCapture();

void setImage(RefPtr<ImageBuffer>);
void setSize(const LayoutSize&, const LayoutRect& overflowRect);
bool setSize(const LayoutSize&, const LayoutRect& overflowRect);

void paintReplaced(PaintInfo&, const LayoutPoint& paintOffset) override;

Expand Down

0 comments on commit a3c5034

Please sign in to comment.