Commit graph

109 commits

Author SHA1 Message Date
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
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
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
Florian Blasius
c58c704f16
Change type of Window background from color to brush (#1755) 2022-10-21 16:17:22 +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
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
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
Simon Hausmann
57fe1b9c47 Replace manual calls to LogicalLength::new() for item fields with logical_XXX getters 2022-09-30 13:00:37 +02:00
Simon Hausmann
a52d633b59 Change FontRequest to be a generic over the length
The API uses a logical length for pixel sizes and letter spacing,
but the renderer will need the physical length eventually.
2022-09-30 13:00:37 +02:00
Simon Hausmann
1624a66ebc Change the Renderer trait's text related functions to explicitly operate on logical lengths 2022-09-30 13:00:37 +02:00
Simon Hausmann
7f6a6aa57b Skia: centralized duplicated vertical alignment computation 2022-09-30 09:03:02 +02:00
Simon Hausmann
dc048a11db Port the Skia renderer to use different types for logical and physical lengths 2022-09-30 09:03:02 +02:00
Simon Hausmann
743a980e21 Skia: add support for rendering text selections
cc #1480
2022-09-22 09:04:27 +02:00
Simon Hausmann
74d3bf07e7 Skia: Fix text cursor at end of text and in empty text inputs
At end of text, take the right edge of the glyph cluster; otherwise the left edge
of what's to the right of the cursor.

For empty text inputs, just return the height of the text to be.

cc #1480
2022-09-22 09:04:27 +02:00
Olivier Goffart
4b0af4bea3 Skia: fix the cursor computations
Skia understands glyph offsets, not byte offsets, so the conversion must
be made
2022-09-13 15:37:53 +02:00
Simon Hausmann
2a26be5c94 WIP: Skia: Begin with support for text input
This puts the basics in place for text input. There are a few missing pieces (and probably more not yet discovered):

* Selections are not rendered yet.
* The cursor is not show at end of text.
* Cursor up and down doesn't work correctly in preserving the x position.

cc #1480
2022-09-12 11:26:49 +02:00
Simon Hausmann
7967bf1ab0 Replace the internal WindowHandleAccess trait with a helper function on WindowInner
The reversal of ownership removes the need for the glue trait in the
publicly visible API.
2022-09-06 16:17:06 +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
Simon Hausmann
3ebdb1b86d Add debug info about the Skia back buffer color depths
Include the number of bits per pixel in the existing output
2022-09-05 13:53:04 +02:00
Olivier Goffart
3f1324cc61 Allow to run the software backend without the femtovg backend 2022-09-02 16:38:35 +02:00
Tobias Hunger
1e6ffeaa0f API cleanup: Rename PlatformWindow to WindowAdapter 2022-08-29 16:53:47 +02:00
Simon Hausmann
1a8a295e38 Skia/FemtoVG: implement re-use of box shadow textures
When using box shadows in repeaters, we end up creating multiple
distinct textures of the drop shadow. That's a waste of precious texture
memory if they have the same properties.

Instead, when creating box shadows in a frame, see if they can be
re-used across images.  The texture still persistent in the image_cache,
via the explicitly shared skia_safe::Image and Rc<Texture>.

This works well when rendering repeated elements new top-down, but it's
not perfect.  For example if a bunch of repeated elements are in a
flickable, only a portion of them are visible and the view is scroll up,
then the top-down rendering will not find a cache hit for the newly
visible element with drop shadows. Yet this is simple enough to help
with sharing in many cases.
2022-08-23 15:27:34 +02:00
Olivier Goffart
a27806aca8 Add a feature to use the sofware renderer with the winit backend
Currently, you still need to pass some env variable at build time so it
embeds the font.
2022-08-22 19:02:28 +02:00
Simon Hausmann
74289deb25 Remove the PlatformWindowWeak alias
... and use Weak<dyn PlatformWindow> directly.
2022-08-19 15:07:27 +02:00
Simon Hausmann
af86f36157 Invert slint:🪟:WindowInner and PlatformWindow ownership
Previously: Window is an Rc<WindowInner>, which has an Rc<dyn
PLatformWindow> - and weak references the other way around.

Now: Rc<dyn PlatformWindow> is the root of window ownership. The impl
PlatformWindow has a slint::api::Window, which just holds a WindowInner.

This change is incomplete on a few levels, mainly that neither of the
code generators nor the interpreter is ported.
2022-08-19 15:07:27 +02:00
Simon Hausmann
262c96af8c Simplify receiver for WindowInner
Use &self consistently, instead of Rc<Self>, so that in the future we can
replace Window(Rc<WindowInner>) with Window(WindowInner).
2022-08-19 15:07:27 +02:00
Olivier Goffart
a1724602e6 Skia: Cache the Skia image in the core image cache
Because re-generating the Skia image is slow and there is no point
storing both the image buffer and the SkiaImage in the cache as it
is basically the same information.
2022-08-16 11:22:11 +02:00
Simon Hausmann
40ab058b5e Fix build with --all-features on Windows
Remove the renderer-skia-opengl "dev" feature again, as on Windows with a
--all-features build in the CI it'll cause
Skia to be built from source. That's not possible in the CI due to long paths as the skia submodule is checked out.
2022-08-12 16:07:42 +02:00
Simon Hausmann
65acadd14a Add support for rendering with Skia and Direct3D on Windows 2022-08-12 16:07:42 +02:00
Simon Hausmann
cc49ee1824 Add support for rendering with Skia and Metal on macOS
Fixes #1470
2022-08-12 08:17:03 +02:00
Simon Hausmann
48b7054254 winit: simplify shutdown logic
Remove release_graphics_resources() as it's always connected to dropping
the entire renderer's canvas. That one in turn is already prepared, i.e.
for femtovg it makes sure that the context is current.
2022-08-10 17:02:15 +02:00
Simon Hausmann
351a1b6448 Move set_rendering_notifier from the (to be public) PlatformWindow to the (private) Renderer trait 2022-08-10 13:07:07 +02:00
Simon Hausmann
6a1bc23321 winit: Clean up rendering notifier handling
Move the rendering notifier into the Renderer. This duplicates a little bit of code, but it

   (1) Allows for avoiding the flush of femtovg/skia if no rendering notifier is
   registered
   (2) Paves the way of gracefully handling the situation where the renderer doesn't support this yet
2022-08-10 13:07:07 +02:00
Simon Hausmann
f4ddfa5ef6 winit: separate rendering from surface resizing
Resize the glutin context when we receive a resize event from winit.
This is the approach recommended by glutin/winit's documentation.

This approach also avoids jitter when rendering with metal (not
implemented yet, but tested locally :)
2022-08-09 16:20:53 +02:00
Simon Hausmann
d02a94eb7c Move the OpenGL specific Skia surface handling into a separate module 2022-08-09 16:20:53 +02:00
Simon Hausmann
50d315437c Skia: encapsulate the OpenGL handling further in a OpenGLSurface type 2022-08-09 16:20:53 +02:00
Simon Hausmann
704985cb7e winit: Move the OpenGL context into the FemtoVGCanvas
This simplifies the "GL" Window type a little, the render() signature
and prepares for supporting rendering with non-GL.
2022-08-09 16:20:53 +02:00
Simon Hausmann
8f0ddd7ad7 Remove unused variable 2022-08-02 12:00:56 +02:00
Simon Hausmann
e8c7cf32db Implement release_graphics_resources() for Skia 2022-08-02 12:00:56 +02:00
Simon Hausmann
dacf083162 Silence unused paramter warnings 2022-08-02 12:00:56 +02:00
Simon Hausmann
4d73d50664 Don't use deprecated Skia functions 2022-08-02 12:00:56 +02:00