Commit graph

244 commits

Author SHA1 Message Date
Simon Hausmann
868173cc20 Disambiguate the type name SkiaRenderer
- Use WinitSkiaRenderer for the adapter in the winit backend (similar to WinitSoftwareRenderer)
- Use SkiaItemRenderer for the impl of the ItemRenderer trait
2023-07-31 17:11:43 +02:00
Simon Hausmann
f60b2ebde9 Add slint::platform::OpenGLInterface
This allows for the use of the FemtoVG renderer but delegate the GL implementation to the user.
2023-07-27 16:48:57 +02:00
Simon Hausmann
3b29bfe2f6 Change OpenGLContextWrapper to return a generic Error
This is in preparation for making the trait public.
2023-07-27 16:48:57 +02:00
Simon Hausmann
4e7ebdceba Improve zero-size OpenGL surface handling
- Use NonZeroU32 in the OpenGLContextWrapper interface (correct API for the future)
- Don't render zero sized windows with the software renderer and FemtoVG
2023-07-27 16:48:57 +02:00
Olivier Goffart
49485dbf7d SoftwareRenderer: add API to construct and change the buffer type 2023-07-27 14:44:28 +02:00
Simon Hausmann
f15bc6147e Simplify FemtoVG and Skia renderer APIs: remove resize()
We can convey the new physical window size from the run-time
through the private renderer API
when a window resize event is dispatched.
2023-07-25 19:33:26 +02:00
Simon Hausmann
7649153b3e janitor: silence rust warning 2023-07-25 17:58:46 +02:00
Simon Hausmann
7d136b6568 Remove the window parameter from the render() function of all the renderers
This makes for a slimmer API and instead we can create the renderer <-> window association
behind the scenes ourselves,
in set_component.
2023-07-25 17:28:08 +02:00
Simon Hausmann
507428b03e
Simplify FemtoVG and Skia renderer API (#3153)
Fold show() into the first time render() is invoked,
and hide() into the Drop implementation.
2023-07-25 17:17:40 +02:00
Aurindam Jana
5a4a7fee63
Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +02:00
Tobias Hunger
8345c6cd79 Do automatic clippy fixes 2023-06-28 14:22:30 +02:00
Simon Hausmann
a181fe0196 Port to softbuffer 0.3.0 2023-06-22 08:11:16 +02:00
Simon Hausmann
7c36121082 Sanity check that the OpenGL context we have provides what we need
On Windows without OpenGL, wgl might succeed all the way, but get_proc_address will fail.
2023-06-16 12:52:15 +02:00
Olivier Goffart
11dea135f7 Domain: slint-ui.com -> slint.dev 2023-06-16 10:55:08 +02:00
Aurindam Jana
039e54a5de
Add royalty free license to files except examples and docs (#2888) 2023-06-15 11:20:50 +02:00
Simon Hausmann
fb1d37286f Clean up the Skia renderer API
Accept display and window handles with life time, instead of &dyn
HasRaw*Handle.
2023-06-07 12:20:57 +02:00
Simon Hausmann
af6b49a47d Simplify FemtoVG renderer API
For wasm builds, just require the canvas element.
2023-06-07 11:30:43 +02:00
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
599d86e4e1 Simplify Skia renderer API
Remove the size argument from render().
2023-05-26 10:46:59 +02:00
Simon Hausmann
f9b8592eba Simplify FemtoVG Renderer API
Remove the size argument from render().
2023-05-26 10:46:59 +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
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
20d206dc6b Mark the OpenGLContextWrapper trait as unsafe
There's on guarantee that the pointers returned by get_proc_address are
always valid. Our implementation might, but since the trait isn't
sealed, somebody else could implement it badly.
2023-05-17 09:01:02 +02:00
Simon Hausmann
9c1e5efb43 Clean up FemtoVG renderer interface
Accept the OpenGL context as trait impl. This means we can also move the rendering notifier
into the femtovg renderer create and get rid of
the proxy Renderer trait impl.
2023-05-17 09:01:02 +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
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
0475b91daf skia: Simplify renderer API
Remove the generic window handle owner part of the API. Instead assume
that the caller provides safety for the given window handles, like we do
for FemtoVG and like softbuffer does it in its public API.
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
d0cdc462c7 Simplify Skia Renderer
Allocate the renderer's surface type in the constructor.

This also changes the C++ API to match this, which complicates some code
a little bit.
2023-05-11 10:42:09 +02:00
Simon Hausmann
0466ea139c Simplify state handling in the FemtoVG renderer
Create the OpenGL context and FemtoVG canvas in the renderer constructor. This allows
elimiating various levels of interior mutability.
2023-05-11 10:42:09 +02:00
Simon Hausmann
721e74238f winit: Simplify softbuffer handling
Allocate the softbuffer in the constructor
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
Olivier Goffart
98747cd385 Winit software renderer: Fix transparent background
Despite the documentation of softbuffer claiming that the high bits
should be 0, it seems to be interpreted as an alpha value when the
window is actually transparent.
And the values are considered as premultiplied alpha

Also use a Premultiplied aplha for the buffer so we can even have
transparent window with the software renderer
2023-05-03 19:29:51 +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
7144b75adf Fix support for transparent windows on macOS when using OpenGL
CGL supports it as-is but with glutin this is only propagated onto the context
when it's set to true in the config template builder.
2023-04-27 17:11:41 +02:00
Simon Hausmann
278d650d7d Fix error messages when supplying invalid sizes to Skia and FemtoVG
Apply the same error message as for
https://github.com/slint-ui/slint/pull/2402#discussion_r1146657846
2023-03-27 12:47:31 +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
ef07da4893 Add comment about resizing tweak on macOS 2023-03-23 15:36:42 +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
Simon Hausmann
fdb719a65e femtovg: Fix panic when rendering colorized image with transparent global alpha
This is reproducible in the energy monitor when scrolling down in the
settings page.

In the helper function to colorize an image, we did not expect
brush_to_paint() to fail. The condition of a transparent colorize color
was handled earlier, but it turns out that brush_to_paint() also checked
the global state as an optimization.

This optimization is wrong, as the cached colorized image should not
depend on the untracked global transparency.

So this patch adds a graceful handling of brush_to_paint returning None
for defensive measures, but also moves the early return on an global
transparent alpha to the call sites where it makes sense.
2023-03-03 15:22:28 +01:00
Olivier Goffart
ed51f6b7b6 Femtovg backend: fix text_input_cursor_rect_for_byte_offset for the last glyph
It was on the wrong line if not a \n, and on the wrong position if a \n
2023-02-17 15:51:14 +01:00
Simon Hausmann
59e0723793 Improved fix for panic when using OpenGL with the winit backend on Linux
Replace the patch with use of the glutin API as advised upstream (and
also implemented in glutin-winit).

Closes #2215
2023-02-09 16:16:36 +01:00
Simon Hausmann
476300ded7 Prospective fix for preview panicing on Linux v2
Avoid unwrap in the display/context selection try function.
2023-02-09 14:24:20 +01:00
Simon Hausmann
e8439061e8 Prospective fix for vscode extension preview not working on Linux
The CI build vsix panics on line 84 in glcontext.rs. There's no unwrap()
there but there's one nearby. I wasn't able to reproduce this with a
local build, so this is a prospective attempt, assuming that this is due
to the attempt of glx-over-egl display configuration finding.
2023-02-09 09:45:54 +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
Simon Hausmann
860f318f7c
Bump femtovg, rustybuzz, ttf-parser, and fontdb dependencies (#2191)
Mostly bugfix changes upstream with some minor API changes. FemtoVG is
no more limited to 24 gradient stops for the paint.
2023-02-08 09:56:53 +01:00
Simon Hausmann
ed8ea3c85c Prospective fix for Linux systems that don't support EGL with X11
As the surface creation may fail with Egl later, then display preference
EglThenGlx is not sufficient and we need to completely re-do the glutin
initialization and try with GLX.

cc #2162
2023-02-03 17:12:59 +01:00