-
-
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+LibGfx: Canvas2D filters #2876
LibWeb+LibGfx: Canvas2D filters #2876
Conversation
cf1f872
to
40bae37
Compare
Btw might conflict a bit with #2717 |
c279a65
to
81ce26f
Compare
81ce26f
to
d9c8e28
Compare
Ok, I see now. ladybird/UI/Qt/TVGIconEngine.cpp Lines 38 to 49 in ea469fb
|
Yeah I think its better to address it in another PR to prevent this one from being too large, it should be relatively straightforward to implement on top of this pr though |
d9c8e28
to
feec29a
Compare
diff --git a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
index 72fc773daa..54b17b52fb 100644
--- a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
+++ b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
@@ -303,8 +303,12 @@ void CanvasRenderingContext2D::stroke_internal(Gfx::Path const& path)
auto& state = drawing_state();
// FIXME: Honor state's line_cap, line_join, miter_limit, dash_list, and line_dash_offset.
- painter->stroke_path(path, state.stroke_style.to_gfx_paint_style(), state.filters, state.line_width, state.global_alpha);
-
+ // painter->stroke_path(path, state.stroke_style.to_gfx_paint_style(), state.filters, state.line_width, state.global_alpha);
+ if (auto color = state.stroke_style.as_color(); color.has_value()) {
+ painter->stroke_path(path, color->with_opacity(state.global_alpha), state.line_width);
+ } else {
+ painter->stroke_path(path, state.stroke_style.to_gfx_paint_style(), state.filters, state.line_width, state.global_alpha);
+ }
did_draw(path.bounding_box());
}
@@ -339,8 +343,13 @@ void CanvasRenderingContext2D::fill_internal(Gfx::Path const& path, Gfx::Winding
auto path_to_fill = path;
path_to_fill.close_all_subpaths();
auto& state = this->drawing_state();
- painter->fill_path(path_to_fill, state.fill_style.to_gfx_paint_style(), state.filters, state.global_alpha, winding_rule);
-
+ //painter->fill_path(path_to_fill, state.fill_style.to_gfx_paint_style(), state.filters, state.global_alpha, winding_rule);
+ // Restore previous logic:
+ if (auto color = state.fill_style.as_color(); color.has_value()) {
+ painter->fill_path(path_to_fill, color->with_opacity(state.global_alpha), winding_rule);
+ } else {
+ painter->fill_path(path_to_fill, state.fill_style.to_gfx_paint_style(), state.filters, state.global_alpha, winding_rule);
+ }
did_draw(path_to_fill.bounding_box());
} Fixes the test on Mac |
This comment was marked as resolved.
This comment was marked as resolved.
@ananas-dev this looks weird to me as well, but I'm 100% positive that helps |
This comment was marked as resolved.
This comment was marked as resolved.
@shlyakpavel I'm trying desperate stuff but the last difference I see between the 2 code paths is the order of calling of setAntiAlias and setColor, is it possible to try to set the antialias in |
diff --git a/Libraries/LibGfx/PainterSkia.cpp b/Libraries/LibGfx/PainterSkia.cpp
index c14abf71c0..185cc894c7 100644
--- a/Libraries/LibGfx/PainterSkia.cpp
+++ b/Libraries/LibGfx/PainterSkia.cpp
@@ -250,6 +250,7 @@ static SkPaint to_skia_paint(Gfx::PaintStyle const& style, Span<Gfx::Filter> fil
{
SkPaint paint;
+ paint.setAntiAlias(true);
apply_paint_style(paint, style);
apply_filters(paint, filters);
@@ -341,7 +342,7 @@ void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::Color color, float thi
return;
SkPaint paint;
- paint.setAntiAlias(true);
+ //paint.setAntiAlias(true);
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, blur_radius / 2));
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(thickness);
@@ -358,7 +359,7 @@ void PainterSkia::stroke_path(Gfx::Path const& path, Gfx::PaintStyle const& pain
auto sk_path = to_skia_path(path);
auto paint = to_skia_paint(paint_style, filters);
- paint.setAntiAlias(true);
+ //paint.setAntiAlias(true);
paint.setAlphaf(global_alpha);
paint.setStyle(SkPaint::Style::kStroke_Style);
paint.setStrokeWidth(thickness); If that's what you mean, it still fails |
diff --git a/Libraries/LibGfx/PainterSkia.cpp b/Libraries/LibGfx/PainterSkia.cpp
index c14abf71c0..0406229e29 100644
--- a/Libraries/LibGfx/PainterSkia.cpp
+++ b/Libraries/LibGfx/PainterSkia.cpp
@@ -6,6 +6,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include "AK/Assertions.h"
#define AK_DONT_REPLACE_STD
#include <AK/OwnPtr.h>
@@ -74,7 +75,7 @@ static void apply_paint_style(SkPaint& paint, Gfx::PaintStyle const& style)
if (is<Gfx::SolidColorPaintStyle>(style)) {
auto const& solid_color = static_cast<Gfx::SolidColorPaintStyle const&>(style);
auto color = solid_color.sample_color(Gfx::IntPoint(0, 0));
-
+ VERIFY_NOT_REACHED();
paint.setColor(to_skia_color(color));
} else if (is<Gfx::CanvasLinearGradientPaintStyle>(style)) {
auto const& linear_gradient = static_cast<Gfx::CanvasLinearGradientPaintStyle const&>(style); That's never reached lol |
What could go wrong
|
isGfx::SolidColorPaintStyle(style) does not work as expected. It's always false |
0c18879
to
a949a1c
Compare
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.
Non-maintainer opinion: this looks good overall, with some minor suggestions
Libraries/LibGfx/PainterSkia.cpp
Outdated
break; | ||
} | ||
default: | ||
VERIFY_NOT_REACHED(); |
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.
This enum class cannot just get a random non-enum value from unverified source, and compile-time check seems to me to be a more reasonable solution here. I suggest removing this VERIFY_NOT_REACHED default case, so if there's a new enum case not present here, it fails to compile instead of a runtime failure
5696f88
to
2dcacdb
Compare
2dcacdb
to
5190624
Compare
Hello! One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the |
4107b55
to
7b48b8e
Compare
7b48b8e
to
61201a3
Compare
CSS filters work similarly to canvas filters, so it makes sense to have Gfx::Filter that can be used by both libraries in an analogous way as Gfx::Color.
MacOS XCode 16 breaks dynamic_cast on final classes where the base class has a has a virtual destructor defined in the header, which creates a different virtual table per translation unit. This is probably a regression in Apple's Clang that causes final classes to be incorrectly aggressively optimized. https://stackoverflow.com/questions/79192304/macos-xcode-16-breaks-dynamic-cast-for-final-types-defined-in-shared-library
61201a3
to
e4a8a4f
Compare
This is the scaffolding of filters for
CanvasRenderingContext2D
.To make this possible I had to introduce breaking changes to the
Painter
api ofLibGfx
which I'll describe below:Gfx::Filter
object which represents the variant of possible filtersI modified the painter's api to accept filters:
I kept the other versions of
stroke_path
andfill_path
for backwards compatibility with TinyVG because filters are not implemented there yet, it's also useful for drawing shadows with less overhead.