-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LibWeb: Support blending in CSS and the canvas #3267
base: master
Are you sure you want to change the base?
Conversation
Canvas now supports compositing and various blending modes via the `globalCompositeOperation` attribute.
825c620
to
0c677b7
Compare
I adapted the code to use blender instead of blend mode. However I am not sure if "plus-darken" works correctly, as the Spec seems to have an incorrect formula, the implementation differs between popular Browsers, and and I don't know how it should look like. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh! neatly structured! 👍🏻
Libraries/LibGfx/PainterSkia.cpp
Outdated
if (current_compositing_and_blending_operator == "plus-darker"sv) { | ||
return SkRuntimeEffect::MakeForBlender(SkString(R"( | ||
vec4 main(vec4 source, vec4 destination) { | ||
return max(vec4(0.0), source + destination - vec4(1.0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this behave?
return max(vec4(0.0), source + destination - vec4(1.0)); | |
return max(vec4(0.0), vec4(1.0) - ((vec4(1.0) - destination) + (vec4(1.0) - source)))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, this does not work either...
I failed to find an implementation of this mode using Skia on Github. Even WebKit, the only Engine that supports it, has no implementation using Skia. I think the problem is the transparent black background, but I currently have no workaround.
This adds support for the `mix-blend-mode` CSS property.
a4f17d8
to
ea53d58
Compare
globalCompositionOperation
attribute
I extended the scope of this PR and also implemented the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that it is enough to
- pass
.isolate = computed_values.isolation() == CSS::Isolation::Isolate
inpush_stacking_context_params
, - propagate from there to
PushStackingContext
, and - use in
DisplayListPlayerSkia
like this
if (command.opacity < 1 || command.mix_blend_mode != "normal"sv || command.isolate) {
to have working isolation on the mdn page you mentioned.
// FIXME: This value is only correctly supported by Safari in combination with Core Graphics. | ||
// It looks like the spec is wrong about the formula. We therefore use the one from | ||
// https://developer.apple.com/documentation/coregraphics/cgblendmode/plusdarker for now. | ||
// However it also does not work. | ||
return SkRuntimeEffect::MakeForBlender(SkString(R"( | ||
vec4 main(vec4 source, vec4 destination) { | ||
return max(vec4(0.0), source + destination - vec4(1.0)); | ||
} | ||
)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you try the following?
// FIXME: This value is only correctly supported by Safari in combination with Core Graphics. | |
// It looks like the spec is wrong about the formula. We therefore use the one from | |
// https://developer.apple.com/documentation/coregraphics/cgblendmode/plusdarker for now. | |
// However it also does not work. | |
return SkRuntimeEffect::MakeForBlender(SkString(R"( | |
vec4 main(vec4 source, vec4 destination) { | |
return max(vec4(0.0), source + destination - vec4(1.0)); | |
} | |
)")) | |
return SkRuntimeEffect::MakeForBlender(SkString(R"( | |
vec4 main(vec4 source, vec4 destination) { | |
return saturate(saturate(destination.a + source.a) - saturate(destination.a - destination) - saturate(source.a - source)); | |
} | |
)")) | |
.effect->makeBlender(nullptr); |
vec4 main(vec4 source, vec4 destination) { | ||
return min(vec4(1.0), source + destination); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: to align with hinted code, you can also switch to
vec4 main(vec4 source, vec4 destination) { | |
return min(vec4(1.0), source + destination); | |
} | |
vec4 main(vec4 source, vec4 destination) { | |
return saturate(source + destination); | |
} |
This PR adds support for the
mix-blend-mode
CSS property.It also implements compositing and various blending modes via the
globalCompositeOperation
attribute in the canvas.This makes some more tests in https://wpt.fyi/results/html/canvas/element/compositing pass.