Commit graph

174 commits

Author SHA1 Message Date
Simon Hausmann
2b891b6097 winit: Remove the html canvas element from the GL context
It's not needed anymore. We can pass the canvas
element to the renderer once
and then we don't need it anymore.
2023-06-07 11:30:43 +02:00
Simon Hausmann
ff2a4ecb4e Cleanup: Use winit's HTML Canvas accessor instead of our own 2023-06-07 11:30:43 +02:00
Simon Hausmann
879e09922f Begin renderer API cleanup: Remove size argument from WinitCompatibleRenderer::render()
We would pass `physical_size_to_slint(&self.winit_window().inner_size())`, which is
identical to `slint::Window::size()`, which
calls `size()` on the WindowAdapter, which
returns the above.
2023-05-26 10:46:59 +02:00
Simon Hausmann
459f810bd8 winit: Clean up implementation of WinitWindowAdapter::show() and hide()
show() used to create the window, which required access to the event
loop (target), which in turn required workarounds like in #1603.  Since
the winit window exists now in show(), we don't need this workaround
anymore.

The same applies to hide(), we don't need an event loop target, all we
need is the event loop proxy to dispatch a WindowHidden event.
2023-05-24 15:59:56 +02:00
Simon Hausmann
fe4a434ce4 Remove the WindowAdapter from the renderer constructor
This allows disentangling the native window creation from the renderer
creation, which is rather ugly and complicated on the C++ side.
2023-05-21 14:40:43 +02:00
Simon Hausmann
7fe4cb39aa Cleanup: Remove unnecessary WinitWindow trait
WindowAdapter is not generic anymore, we can use it directly.
2023-05-11 10:42:09 +02:00
Simon Hausmann
7ab90857d5 Fix winit backend tests
Don't run them on macOS/wasm, but attempt to enable their use via the
winit threaded extension.
2023-05-11 10:42:09 +02:00
Simon Hausmann
12e6e322d9 Make the WinitWindowAdapter non-generic
This isn't necessary anymore
2023-05-11 10:42:09 +02:00
Simon Hausmann
e0bcfff0ab Fix doctests
Don't run them with the winit backend, and that'll try to create an
event loop in a thread.
2023-05-11 10:42:09 +02:00
Simon Hausmann
f10e3a35bc Disable winit accessor tests
Now that we always create a window, we end up also creating an event
loop, and that's inherently incompatible with the rust test harness that
creates threads.

We can try to re-enable this later on platforms where we can run an
event loop in a thread. I have a local WIP patch for that.
2023-05-11 10:42:09 +02:00
Simon Hausmann
c3cee1c3d9 winit: Simplify internal renderer trait
Don't require the creation of an Rc<winit window>, leave
that to the caller.
2023-05-11 10:42:09 +02:00
Simon Hausmann
a3a13c727a winit: Cleanup, move the winit window out of the individual renderers 2023-05-11 10:42:09 +02:00
Simon Hausmann
7df902b53c winit: Create a winit window at renderer creation time
This simplifies the logic for how to apply window related requests as
they can be applied to the winit window immediately.

It also simplifies the state handling in the WinitWindowAdapter, as
there's no more distinction between mapped and unmapped. We always map
now (winit does).

One related change in core is that the window properties are now sent to
the backend before calling show(), instead of after.
2023-05-11 10:42:09 +02:00
Simon Hausmann
481288d489 Initial support for rendering with Skia and Vulkan
Closes #1546
2023-05-09 08:58:35 +02:00
Simon Hausmann
098a078008 Make it possible for the window adapter creation to fail
The creation of the renderer might fail, for example if we tried to
create an OpenGL renderer on a display that doesn't support OpenGL. We
should catch that in the future and fall back to the software renderer.
2023-04-27 17:37:36 +02:00
Simon Hausmann
af8e71dacc Minor cleanup
Replace qualifier with use.
2023-04-27 17:37:36 +02:00
Simon Hausmann
1abc599be5 Seal the WinitWindowAccessor trait
so that only we can implement it
2023-04-24 12:59:06 +02:00
Simon Hausmann
93dcd90c74 winit: Add API to provide access to the event loop and the winit Window
To avoid exposing the internal custom event, this also wraps the enum in
a public SlintUserEvent enum.
2023-04-24 12:59:06 +02:00
Simon Hausmann
04262414b1 winit: Fix documentation for the crate
Despite this being an internal crate, provide some better docs and links
so that we _can_ recommend folks to use it.
2023-04-24 12:59:06 +02:00
Simon Hausmann
ab051680e5 janitor: Rename GLWindow to WinitWindowAdapter
It's no more an "OpenGL Window", it's the type that adapts winit to our windowing
system abstraction.
2023-04-05 11:04:19 +02:00
Simon Hausmann
8ffb5131c7
Introduce error handling in the FemtoVG and Skia renderers (#2402)
Avoid unwrap() and expect() and instead propagate errors all the way
down to run_event_loop(), show(), and hide() in the Slint AIP.
2023-03-24 14:18:11 +01:00
Simon Hausmann
c54e1cba43 Fix support on GLX displays with FemtoVG
In order for GLX support to work, we need to create the X11 window with
the same visual as in the GLX configuration. That requires delaying
the creation of the window.

This is done in four parts:

- The window builder is re-introduced in the winit backend create
  internal renderer interface.
- The glcontext helper code for wasm was moved into a separate function
  (less indentation).
- The loop over different display preferences was replaced with a
  preference to the "window system native GL interface" over EGL,
  which should achieve the same as the fix for #2162. Upstream glutin
  defaults to this and so do various downstream projects.
- Use glutin-winit for the actual display selection.

This covers the FemtoVG bits of #2269
2023-03-23 15:36:42 +01:00
Simon Hausmann
6d968aa329 Extract the FemtoVG renderer into a separate crate
This will be needed for a future experiment. Unlike the Skia renderer,
which operates on raw window handles, the FemtoVG renderer exposes a
different interface where it assumes that the caller takes care of the
OpenGL context state. This means more boilerplate remains in the winit
backend, including the glutin dependency. The upside is that it will
allow using the FemtoVG renderer in environments without glutin.

In order to work in an environment without fontconfig or memmap, the
crate has two features:

  - fontconfig (set when we anticipate fontconfig to be available at
    run-time and libloading being available at compile time).
  - diskfonts (set when we want to be able to load fonts from disk)

The winit crate enables fontconfig on "Linux" and diskfonts on !wasm.
2023-03-06 11:45:28 +01:00
Olivier Goffart
6889dfa5f5 Rust: Make new(), run() and show() report errors from the backend
Fixes #2198
2023-02-10 05:00:03 +01:00
Olivier Goffart
a19efc30db
Replace the MAX_BUFFER_AGE const generic with a runtime enum
Having a const generic for that didn't turn to be a good API.
Also made the C++ side more difficult

(Also renamed buffer_stride to pixel_stride)

Closes #2135
2023-02-08 14:44:01 +01:00
Olivier Goffart
f34b1bda2e Add primary keyboard support on unix (selection copy, middle click paste)
Closes #2146
2023-01-31 16:39:22 +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
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
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
Olivier Goffart
6d29a66b52 winit: Fix build with the mcu simulator
the renderer-winit-software feature enable femtovg without the
renderer-winit-femtovg feature, and need the open gl context
2022-11-16 09:38:42 +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
Olivier Goffart
0ba468c236 Use a builtin function to access the dark-style
instead of a property on NativeStyleMetrics
2022-10-19 15:23:41 +02:00
Simon Hausmann
dbe9f33bb4 janitor: Fix warning about unused functions/modules when compiling with Skia and D3d or Metal
When using Metal or D3D, we don't need the glcontext module.
2022-09-22 14:35:17 +02:00
Olivier Goffart
8850959a2c Rename the backend feature flags 2022-09-07 17:11:57 +02:00
Olivier Goffart
b2c1d89e2f Fix compile when only the renderer-software is enabled 2022-09-07 11:06:51 +02:00
Olivier Goffart
b3605cb4ec Fix errors and warnings in the wasm build 2022-09-07 10:13:58 +02:00
Olivier Goffart
6ede77436b api: Return an error from invoke_from_event_loop and quit_event_loop 2022-09-07 10:13:58 +02:00
Olivier Goffart
4706d529e2 Rename BUFFER_COUNT to MAX_BUFFER_AGE
and remove the default value from the SoftwareRenderer
2022-09-06 18:30:45 +02:00
Simon Hausmann
3a1817de3f Skia: Make it possible to explicitly select the OpenGL backend of Skia
When opting into the Skia renderer, we default to metal on macOS and D3D on Windows.
However if you want to develop a cross-platform application with Skia and
for example rely on OpenGL to be able to implement an OpenGL underlay or overlay,
then we need the ability to explicitly opt into skia's GL renderer.

cc #1445
2022-09-05 14:07:27 +02:00
Olivier Goffart
3f1324cc61 Allow to run the software backend without the femtovg backend 2022-09-02 16:38:35 +02:00