LibWeb/CSS: Implement mix-blend-mode

This adds support for the `mix-blend-mode` CSS property.
This commit is contained in:
Glenn Skrzypczak 2025-01-22 09:50:49 +01:00 committed by Sam Atkins
commit 0fe30886f5
Notes: github-actions[bot] 2025-02-05 11:28:01 +00:00
24 changed files with 311 additions and 57 deletions

View file

@ -23,6 +23,8 @@
#include <pathops/SkPathOps.h>
#include <LibGfx/Font/ScaledFont.h>
#include <LibGfx/PainterSkia.h>
#include <LibGfx/PathSkia.h>
#include <LibGfx/SkiaUtils.h>
#include <LibWeb/CSS/ComputedValues.h>
#include <LibWeb/Painting/DisplayListPlayerSkia.h>
@ -195,11 +197,15 @@ void DisplayListPlayerSkia::push_stacking_context(PushStackingContext const& com
.translate(-command.transform.origin);
auto matrix = to_skia_matrix(new_transform);
if (command.opacity < 1) {
if (command.opacity < 1 || command.compositing_and_blending_operator != Gfx::CompositingAndBlendingOperator::Normal || command.isolate) {
auto source_paintable_rect = to_skia_rect(command.source_paintable_rect);
SkRect dest;
matrix.mapRect(&dest, source_paintable_rect);
canvas.saveLayerAlphaf(&dest, command.opacity);
SkPaint paint;
paint.setAlphaf(command.opacity);
paint.setBlender(Gfx::to_skia_blender(command.compositing_and_blending_operator));
canvas.saveLayer(&dest, &paint);
} else {
canvas.save();
}
@ -878,6 +884,14 @@ void DisplayListPlayerSkia::apply_opacity(ApplyOpacity const& command)
canvas.saveLayer(nullptr, &paint);
}
void DisplayListPlayerSkia::apply_composite_and_blending_operator(ApplyCompositeAndBlendingOperator const& command)
{
auto& canvas = surface().canvas();
SkPaint paint;
paint.setBlender(Gfx::to_skia_blender(command.compositing_and_blending_operator));
canvas.saveLayer(nullptr, &paint);
}
void DisplayListPlayerSkia::apply_filters(ApplyFilters const& command)
{
if (command.filter.is_empty()) {