Commit graph

244 commits

Author SHA1 Message Date
Simon Hausmann
04ceb63433 Update to FemtoVG 4.0
Not big changes, just API and Cargo feature cleanups
2023-01-27 12:03:33 +01:00
Simon Hausmann
52fb1ab9fe Fix signature of get_proc_address in Rust GraphicsAPI
Use a CStr instead of str, to avoid an extra CString allocation. The underlying operating system API for
this expects a zero terminated C String.

Fixes #1943
2023-01-26 11:55:10 +01:00
Simon Hausmann
5ff0278185 Simplify path event extraction
Return the path events for rendering as an Option, so that if the path is empty,
we simply return.

This avoids a double property dependency in the (likely) event the path is not empty.
2023-01-21 13:10:19 +01:00
Olivier Goffart
d6b66a0690 Skia/femtfovg rectangle with transluscent border: set minimum radius
Set the minimum radius of the background to limit the artifact when
drawing the border
2023-01-20 14:12:43 +01:00
Simon Hausmann
911d0e42a9 Fix FemtoVG's drawing of the border rectangle with non-opaque borders (#2079)
Also fix the border radius to be the outer radius of the rectangle

FemtoVG renderer part of #1988 (minus clipping)
2023-01-19 12:13:11 +01:00
Florian Blasius
ed67f3aabb
bump soft-buffer to 0.2 (#2038) 2023-01-09 09:08:59 +01:00
Simon Hausmann
9b2726f0eb Further cleanups in Femtovg renderer's GL context handling
Make with_graphics_api robus by ensuring that the context is always current (similar to commit a124f4b8fe)
and remove the with_current_context boilerplate.
2022-12-22 09:15:47 +01:00
Simon Hausmann
1505826e7d Simplify glutin context handling in the femtovg renderer
Similar to commit a124f4b8fe,
always use a PossiblyCurrentContext
and use glutin's interior mutability to ensure that the context is current.
2022-12-22 09:15:47 +01:00
Simon Hausmann
4c1eff5812 Move the glutin context wrapper into the femtovg renderer
It's only needed there.
2022-12-22 09:15:47 +01:00
Olivier Goffart
5cd38adb14 Move the colorize property to the Image item
Instead of the ClippedImage. Because we use the colorize property more
often than the source property, and these are soon going to be even more
expensive
2022-12-20 08:42:47 -08:00
Olivier Goffart
80a834f489 Janitor: fix warning about unusd function
Move the function in the module that uses it (which can be disabled with
features)
2022-12-15 15:15:04 +01:00
Simon Hausmann
aea216fb49 Fix rendering of border widths with FemtoVG and Skia
Commit f66a2a5775 and dc048a11db introduced
the regression of issue #1985 where in adjust_rect_and_border_for_inner_drawing
instead of subtracting the entire border width from the size,
only half of it was subtracted,
leaving an inner area of the rectangle visible.

Fixes #1985
2022-12-14 15:32:53 +01:00
Simon Hausmann
14350a970b Cleanup: consume the original pixel buffer in the conversion for softbuffer 2022-12-13 16:51:26 +01:00
Simon Hausmann
5820db6088 Remove the OpenGL dependency for renderer-winit-software
Use softbuffer to bring pixels produced by the software renderer to the screen.
2022-12-13 16:51:26 +01:00
Simon Hausmann
a4e4863669 Fix SkiaRenderer::new to take the window adapter weak by value
... for consistency with the software renderer API.
2022-12-12 12:01:12 +01:00
Simon Hausmann
7b4a3cd29a Improve the safety of the skia renderer API
Claim a strong reference (ownership or RC) on the value that provides the raw window handle.
2022-12-12 11:59:50 +01:00
Simon Hausmann
01d2efce4e Move the Skia renderer into a separate crate
The crate is an internal crate until the API has been polished and
documented, after which we can call slint-renderer-skia for example.

This also duplicates a little bit of the glutin setup code, because
that would otherwise have to go into another shared crate.
2022-12-09 17:04:54 +01:00
Simon Hausmann
b2ebac63c2 Remove component_destroyed from winit's internal renderer interface
The default impl of unregister_component in WindowAdapterSealed would call free_graphics_resources
on the rendere. Any re-implementation would have to do the same,
which the winit backend forwarded through
the winit backend specific internal renderer interface.

Instead, the original call site for unregister_component now calls
free_graphics_resources and unregister_component (for accessibility tree dirty notification).
2022-12-09 09:03:27 +01:00
Simon Hausmann
f5bbca9fce Remove default_font_size() from internal winit renderer interface
Replace register_root_component in the WindowAdapterSealed altogether with
a default font size getter on the renderer.

This is overall simpler and allows removing the doc-hidden getter in the software renderer.
2022-12-09 09:03:27 +01:00
Simon Hausmann
06f7f76b69 Reduce the renderer interface further in the winit backend
Move the canvas into the renderer entirely as interior state.

This complicates the implementation but paves the way for an easy-to-use API.
2022-12-09 09:03:27 +01:00
Simon Hausmann
6c22af4247 Wrap the software renderer into a struct
This is in preparation for internalizing the canvas state.
2022-12-09 09:03:27 +01:00
Simon Hausmann
ff119eab4f Minimize the WinitCompatibleRenderer trait a little
Replace the raw-window-handle traits with a winit window. It's okay to
use winit one level into the renderer (the part that lives in this
crate).
2022-12-09 09:03:27 +01:00
Simon Hausmann
2fd8bf426a Move the box shadow cache helpers to core::graphics::boxshadowcache
This way the box shadow cache can also be used from the Skia renderer,
which is to be moved into a different crate.
2022-12-09 09:03:27 +01:00
Simon Hausmann
307636d652 Remove winit dependency from the renderers
GLWindow (yes, misnomed) is now responsible to creating and owing the
winit:🪟:Window.
2022-12-08 12:12:11 +01:00
Simon Hausmann
d9185053eb Implement windowing system name helper function by means of raw_window_handle 2022-12-08 12:12:11 +01:00
Simon Hausmann
26ff1f6a79 Cleanup: simplify internal render() signature by removing adapter argument
We can unwrap internally.
2022-12-08 12:12:11 +01:00
Simon Hausmann
18bf24e7bf cleanup: simplify access to the winit window
We can now return a reference.
2022-12-06 14:15:56 +01:00
Simon Hausmann
8dd28d232e Port to new major glutin version 2022-12-06 14:15:56 +01:00
Simon Hausmann
755cd66398 Revert "Prospective build fix for arm cross build" and "With Rust 1.64 we can use core:ffi types instead of depending on libc"
This reverts commit 000d95670b and commit
d764796e0c to fix arm cross build and
x86-64 linux.

Let's use the core::ffi types when fontconfig-sys switches to it.
2022-12-06 09:16:03 +01:00
Simon Hausmann
000d95670b Prospective build fix for arm cross build
Use the `c_char` type that adapts to the signedness
2022-12-06 09:07:48 +01:00
Simon Hausmann
d764796e0c With Rust 1.64 we can use core:ffi types instead of depending on libc 2022-12-05 10:33:50 +01:00
Simon Hausmann
39121994ca Always set Window.default-font-size
Permit the style metrics to provide a `default-font-size` and bind that
to the `Window` if set. If not provided, then the backend can set a
`default-font-size`. By ensuring that the value is non-zero at run-time,
we can later introduce a rem unit that can act as factor relative to
this non-zero font size.
2022-11-03 17:15:44 +01:00
Simon Hausmann
ea4ad7297b Always build the Metal and D3d backends on macOS/Windows when Skia is enabled
Their dependencies are always pulled in and for improved CI build coverage
let's always build them.
2022-10-27 13:56:07 +02:00
Olivier Goffart
e4994f9e9a femtovg renderer: don't draw svg if they are empty
Otherwise computing the fit_size will lead to NaN and then panic.

The size is empty in the wasm case when loading an html image and it
isn't loaded yet. We will be called again because the htmlimage has an
internal property that will be changed when it is loaded
2022-10-27 09:38:47 +02:00
Simon Hausmann
ee39f3802e janitor: Fix warning about use of deprecated functions from ttf-parser 2022-10-24 17:51:36 +02:00
Simon Hausmann
c16253d29f Use Property<LogicalLength> instead of Property<Coord>
This removes the special code for the generated property getters and
ensures type safety in the run-time library for property value setting.

In the Rust generated code we continue to do arithmetic on the scalar
values, that means we immediately extract the scalar, do arithmetic and
rely on the compiler to only allow compatible units.

Danger zone alert: In the interpreter Value::Number can now be converted
to LogicalLength as-is.
2022-10-24 12:49:37 +02:00
Olivier Goffart
2e08b7dd1e Fix the rendering size of svg
- On the web, to return the image size, we need to use the natural size
   of the image, and not its dom size, as the later get modified since
   commit  b727aba4a0

 - The target size did not take in account the image fit, that's because
   former version of resvg could only render by respecting the aspect
   ratio. But since the web don't have this limitation, we now need to
   take it into account. And new version of resvg can also scale with
   any aspect ratio
2022-10-24 10:05:38 +02:00
Florian Blasius
c58c704f16
Change type of Window background from color to brush (#1755) 2022-10-21 16:17:22 +02:00
Simon Hausmann
b727aba4a0
Fix quality of SVG rendering in the online editor (#1740)
SVGs are rendered using HTML image elements, that are converted to textures.
The size of the texture defaults to the SVGs viewbox, which may be small - despite
it being possible to render the SVG at a higher resolution with great quality.

Similar to the native code path, this patch also uses the target image size
and propagates it to the DOM HTML image element to instruct the browser to
render the SVG at a higher resolution.

Co-authored-by: Olivier Goffart <olivier.goffart@slint-ui.com>
2022-10-18 14:43:33 +02:00
Simon Hausmann
0577d8a20d Use physical lengths for the image cache rendering
This avoids accidental use of logical pixels, esp. for SVG, elimiates
one call to `to_untyped()` as well as an untyped scale factor in the
femtovg renderer.
2022-10-13 17:02:18 +02:00
Simon Hausmann
c11b4305c1 Change Item::geometry() to return a LogicalRect 2022-10-13 17:02:18 +02:00
Simon Hausmann
299325370d Change generated accessor functions for Property<Coord> getters to return LogicalLength 2022-10-13 17:02:18 +02:00
Simon Hausmann
8cba0622f5 Initial input method support for the winit backend and the FemtoVG/Skia renderers
Known caveats:

- winit doesn't forward mouse events to the IME, so clicking
  with the mouse while composing results in funny effects such
  as the pre-edit text following the cursor.
- With FemtoVG there's no text decoration support, thus no underlining
  of the preedit area.
2022-10-07 11:16:36 +02:00
Be
ecb6fd5309 switch to yeslogic-fontconfig-sys from servo-fontconfig
This allows setting the RUST_FONTCONFIG_DLOPEN environment variable
to dlopen fontconfig at runtime rather than linking it at build
time. This is helpful for cross compiling to Linux, particularly
because fontconfig has lots of C dependencies. Building a vendored
copy of fontconfig does not work as expected:
https://github.com/slint-ui/slint/issues/88
2022-10-05 15:21:54 +02:00
Simon Hausmann
2da2511f13
Use a vector for ItemRenderer::translate (#1700)
This simplifes call sites and implementations.
2022-10-02 10:06:20 +02:00
Simon Hausmann
37a8c50c12 Simplify FontRequest
It doesn't have to be generic as mostly the frontend code creates it with logical lengths.
2022-09-30 23:31:32 +02:00
Simon Hausmann
2278ac3581 Remove two more uses of LogicalRect::from_untyped 2022-09-30 13:00:37 +02:00
Simon Hausmann
cc8ff56d98 Remove more uses of LogicalRect::from_untyped() 2022-09-30 13:00:37 +02:00
Simon Hausmann
f95311bb3f Skia: Simplify item_rect implementation 2022-09-30 13:00:37 +02:00
Simon Hausmann
f40fc6500f Skia: make textlayout operate entirely on physical coordinates
This simplifes the call sites a little and allows conversion from logical to physical to be done earlier.
2022-09-30 13:00:37 +02:00