Skip to content

Support CSS mix-blend-mode rendering#515

Merged
wieslawsoltes merged 6 commits into
masterfrom
fix/issue-310-mix-blend-mode
May 9, 2026
Merged

Support CSS mix-blend-mode rendering#515
wieslawsoltes merged 6 commits into
masterfrom
fix/issue-310-mix-blend-mode

Conversation

@wieslawsoltes
Copy link
Copy Markdown
Owner

PR Summary: Support CSS mix-blend-mode

Summary

This PR adds a focused compatibility implementation for issue #310, where SVG content that uses CSS mix-blend-mode rendered without blend behavior in Svg.Skia. The implementation keeps the scope limited to CSS style declarations and does not treat mix-blend-mode or isolation as SVG presentation/XML attributes.

Changes

  • Stores CSS-only mix-blend-mode and isolation declarations from inline styles and stylesheets in custom attributes so retained scene compilation can inspect them after style resolution.
  • Maps supported mix-blend-mode keywords to SKBlendMode values:
    • multiply
    • screen
    • overlay
    • darken
    • lighten
    • color-dodge
    • color-burn
    • hard-light
    • soft-light
    • difference
    • exclusion
    • hue
    • saturation
    • color
    • luminosity
  • Applies blend modes during retained scene rendering through SaveLayer paint state.
  • Supports isolation:isolate for container nodes by rendering isolated groups through an intermediate layer.
  • Mirrors the same blend and isolation behavior in static animation layer rendering.
  • Leaves XML/presentation attributes such as mix-blend-mode="overlay" and isolation="isolate" ignored, matching browser behavior for the relevant resvg SVG2 fixtures.

Tests And References

  • Added retained scene graph tests covering:
    • inline style mix-blend-mode on an image node
    • stylesheet mix-blend-mode on a shape node
    • ignored XML/presentation mix-blend-mode
    • stylesheet isolation:isolate on a container node
  • Added Chrome reference overrides for the affected resvg blend and isolation fixtures:
    • a-isolation-001
    • a-isolation-002
    • a-mix-blend-mode-001 through a-mix-blend-mode-020

Validation

  • git diff --check
  • dotnet test tests/Svg.Skia.UnitTests/Svg.Skia.UnitTests.csproj -f net10.0 -c Release --no-restore --filter "FullyQualifiedName~SvgRetainedSceneGraphTests"
  • dotnet test tests/Svg.Skia.UnitTests/Svg.Skia.UnitTests.csproj -f net10.0 -c Release --no-restore --filter "FullyQualifiedName~resvgTests.a_mix_blend_mode|FullyQualifiedName~resvgTests.a_isolation"
  • dotnet build Svg.Skia.slnx -c Release
  • dotnet test Svg.Skia.slnx -c Release

dotnet format Svg.Skia.slnx --no-restore was attempted before committing, but it stalled after workspace-load warnings and had to be stopped. No solution-format process remains running.

@wieslawsoltes wieslawsoltes marked this pull request as ready for review May 9, 2026 10:51
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a18abfef0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2644 to +2645
element.IsContainerElement() &&
TryParseIsolation(element))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor isolation on expanded use nodes

When isolation:isolate is styled on a <use> element, this guard drops it because SvgUse is not included in IsContainerElement(), even though TryCompileDirectUseNode expands the referenced content as children of the use scene node. In that case any referenced child using mix-blend-mode still blends against the external backdrop instead of the isolated <use> group; remove or broaden this container check so scene nodes that actually contain generated children can form isolation layers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5a9e6c5ec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

var enableOpacity = !ignoreAttributes.HasFlag(DrawAttributes.Opacity) && !ignoreCurrentOpacity;
var enableFilter = !ignoreAttributes.HasFlag(DrawAttributes.Filter) && !ignoreCurrentFilter;
if (IsStateFreeNode(node, enableTransform, enableClip, enableMask, enableOpacity, enableFilter))
var enableBlendMode = node.BlendModePaint is not null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep mix-blend-mode out of filter SourceGraphic

When a node has both filter and mix-blend-mode, SvgSceneFilterSource.SourceGraphic() renders the target with ignoreRootFilter: true to build the filter input, but this new unconditional check still enables the blend layer. That means the filter's SourceGraphic is no longer the element's pre-compositing pixels; it is first composited with the temporary transparent filter canvas, so e.g. filter="url(#blur)" plus style="mix-blend-mode:multiply" can feed the blur an already-blended/transparent result instead of the original graphic. The blend should be skipped when rendering filter sources, similar to the existing root opacity/mask/filter ignores.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant