-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Use ThorVG instead of NanoSVG for importing SVGs #49645
Conversation
4e3e2af
to
3b43544
Compare
07d606d
to
21bac89
Compare
There's a high velocity in the thorvg project. I posted broken test cases and the team responded the day after. |
f8cd613
to
3a0b665
Compare
@qarmin You may be able to test the svgs using this now in batch style. |
7bf27bf
to
523e0af
Compare
At the computer now, will look at the new commits and optimize the color conversion (it is slow). |
Is there a way in Godot Engine to take an array of string searches and an array of string replacements and does the substitution once rather than per number of searches? Used to convert the svg themes. |
@akien-mga I think we're ready and that it would be appropriate for this pr to be merge and wait for a follow-up but tracked in an issue..
|
Benchmark with OS: Fedora 34 (KDE, X11)
Dark theme❯ hyperfine -w1 -i "godot /tmp/4/project.godot --quit" "godot.vanilla /tmp/4/project.godot --quit"
Benchmark #1: godot /tmp/4/project.godot --quit
Time (mean ± σ): 3.617 s ± 0.355 s [User: 1.852 s, System: 0.245 s]
Range (min … max): 3.092 s … 3.868 s 10 runs
Benchmark #2: godot.vanilla /tmp/4/project.godot --quit
Time (mean ± σ): 3.275 s ± 0.357 s [User: 1.821 s, System: 0.249 s]
Range (min … max): 2.916 s … 3.816 s 10 runs
Summary
'godot.vanilla /tmp/4/project.godot --quit' ran
1.10 ± 0.16 times faster than 'godot /tmp/4/project.godot --quit' Light theme❯ hyperfine -w1 -i "godot /tmp/4/project.godot --quit" "godot.vanilla /tmp/4/project.godot --quit"
Benchmark #1: godot /tmp/4/project.godot --quit
Time (mean ± σ): 3.923 s ± 0.404 s [User: 2.268 s, System: 0.244 s]
Range (min … max): 3.332 s … 4.264 s 10 runs
Benchmark #2: godot.vanilla /tmp/4/project.godot --quit
Time (mean ± σ): 3.202 s ± 0.313 s [User: 1.804 s, System: 0.253 s]
Range (min … max): 2.927 s … 3.787 s 10 runs
Summary
'godot.vanilla /tmp/4/project.godot --quit' ran
1.23 ± 0.17 times faster than 'godot /tmp/4/project.godot --quit' |
a40ac25
to
033f08a
Compare
Modified with a new code for replacing colors. The code subjectively feels 2 s versus 1.5 s in master to change the theme. Thanks @akien-mga. Merged your changes. |
modules/svg/image_loader_svg.cpp
Outdated
Color new_color = n_c; | ||
replace_colors.old_colors.push_back(old_color.to_abgr32()); | ||
replace_colors.new_colors.push_back(new_color.to_abgr32()); | ||
::Color c = ::Color::html(temp_color); |
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.
Does your IDE add this scoping? I don't see why it's needed here.
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.
I'll fix it while doing some testing, I think the color replacement method could still be simplified, we have plenty of methods in String
to do search and replace, doing it char by char seems pretty convoluted.
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.
My clang compile requires the "::" scoping.
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.
What clang is that? Works fine for me and on CI (macOS + iOS + Android all use clang).
We use Color
everywhere in the codebase. What does it conflict with here?
You were also scoping Image
in places but not consistently so it doesn't seem actually needed.
Just noting down some LTO warnings from ThorVG to report upstream (after checking that they're still reproducible in their
Some are internal redefinitions in ThorVG itself, and others are conflicts between the vendored LodePNG versions from Basis Universal and ThorVG. |
Tested current PR with Dark theme
Light theme
So it's pretty much the same for both dark and light theme with both current |
I pushed an update that simplifies the color conversion code by using existing Despite the theoretical micro optimization, that seemed to make no difference at all in color conversion speed. But the code is nicer IMO :) |
I need to do some more testing, I noticed that some assumptions don't work, as some files contain 3-letter color codes like I restored the previous version for now until I figure this out. I think going through |
c4f8657
to
a33ac17
Compare
ThorVG is a platform-independent portable library for drawing vector-based scene and animation. Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
Alright, I think it's ready. I tweaked the color replacement code to make it handle the whole quoted string instead of hardcoding support for only the
While developing, I made it print colors for which it didn't find a conversion, so we can review and assess if some of those are meant to be converted:
No noticeable impact on speed compared to the previous version. |
Thanks! |
The wrongly claimed support for it was removed in godotengine#49645. See also godotengine#56862.
ThorVG is a platform-independent portable library for drawing vector-based scene and animation.
Alternative to #49601.
Resolves the light to dark for fill, stop colors and strokes.
/~https://github.com/Samsung/thorvg
Fixes: #49205
Fixes: #16180 (Due to increased support we are able to resolve SVG issues better).
Fixes: #33641 (Changing SVG libraries replaces old bugs with new bugs.)
Fixes: #41339 (Via thorvg/thorvg#530)
Fixes: #51763
Fixes: godotengine/godot-proposals#2912