Commit graph

244 commits

Author SHA1 Message Date
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
59368363c9 Change the ItemRenderer trait to use logical lengths 2022-09-30 13:00:37 +02:00
Simon Hausmann
f66a2a5775
Port the FemtoVG renderer to use different types for logical and physical lengths (#1696) 2022-09-30 09:31:11 +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
1af05c41d5 Skia: fix quality of SVG images when using scale factor
Suppose we render an SVG at 100px x 100px with a screen scale factor of 2.
Consequently we should be rendering the SVG at 200phx x 200phx, not 100x100.

Do this by applying the scale factor, just like it is done in the femtovg renderer.
2022-09-28 22:32:09 +02:00
Simon Hausmann
4a1e2e2eaf janitor: remove obsolete commit
Commit 743a980e21 added text selection drawing.
2022-09-22 13:14:01 +02:00
Simon Hausmann
d26b7f9428 Skia: fix height of empty text lines
Apply the text style with font, etc. as default on the paragraph style, so that it applies to empty lines.

cc #1480
2022-09-22 09:56:53 +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
Olivier Goffart
e708f5c903 femtovg backend: fix the cursor position when the text ends with '\n'
Fixes #1318
2022-09-07 15:25:13 +02:00
Simon Hausmann
b78b6ab723 Fix non-SVG images with transparency being rendered incorrectly in WASM builds
Commit 05b16bed89 introduced an exception
for SVGs images to treat them as premultiplied, but commit
3ef35c5ef9 accidentally applied the flag
to all HTML images, which is wrong.
2022-09-07 10:15:27 +02:00
Tobias Hunger
639dcaf702 api: Rename module swrenderer to software_renderer
Also rename the `swrenderer` feature to `software-renderer`.
2022-09-07 10:11:11 +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
Simon Hausmann
7e5de3d5d3 Remove use of euclid types and tags for logical/physical position and size in the public API
Instead provide our own types.
2022-09-02 11:05:53 +02:00
Simon Hausmann
85461d380d Remove euclid from the public re-export of the Slint crate 2022-09-02 11:05:53 +02:00
Olivier Goffart
e0f1fdf298 Rgb565Pixel: remove color accessor, add conversion to Rgb8Pixel
Closes #1540

(Went or Rgb8Pixel instead of color, because color can have alpha)
2022-09-01 13:58:38 +02:00
Simon Hausmann
c1dbf47d15 Fix appearance of drop shadows with Skia
Similar to commit 957186acb7 we need to take the blur into account in the box shadow image:

We add blur margins around the entire image, but we also need to start drawing at (blur, blur) instead of (0, 0).
The same offset needs to be subtracted again when drawing the cached image.
2022-08-31 11:36:04 +02:00
Simon Hausmann
7fd0af8b63 Fix box shadow not rendering correctly when using scale factors != 1
Despite the blur being an abstract float, in reality in femtovg as well
as Skia it's a pixel radius. Commit
1a8a295e38 removed the scaling to physical
pixels, which was wrong.  This restores it and along with it the same
appearance as before.
2022-08-31 11:36:04 +02:00
Simon Hausmann
9338d31535 Remove the use of euclid types from the software renderer public API
Closes #1538
2022-08-31 09:23:38 +02:00
Tobias Hunger
38350db9a0 Fixes pointed out by Olivier and CI 2022-08-29 16:53:47 +02:00
Tobias Hunger
107e3ed2e2 janitor: Fix some typos 2022-08-29 16:53:47 +02:00
Tobias Hunger
1e6ffeaa0f API cleanup: Rename PlatformWindow to WindowAdapter 2022-08-29 16:53:47 +02:00
Olivier Goffart
344f5c437b swrenderer: Move the DirtyTracking enum into a const generic
Closes: 1541
2022-08-29 14:13:55 +02:00
Olivier Goffart
1eaa4e1517 winit with swrenderer: don't call window.draw_contents twice.
The render function of the swrendrer already call that.
2022-08-29 11:42:10 +02:00
Olivier Goffart
4f0e2608d2 Sofware renderer: keep a Weak of the Window
Closes #1545

Not that `SoftwareRenderer::new()`  takes the Weak by value instead of
by reference, because coercing a reference to a `Weak` to a `&Weak<dyn>`
is not possible, while converting a Weak to a `Weak<dyn>` just works.
2022-08-29 11:07:05 +02:00
Olivier Goffart
f271ebbf21 Add an env variable to test the line by line renderer
This also test the 16 bit mode on the desktop
2022-08-27 15:05:06 +02:00
Simon Hausmann
a116f58b0c Decouple our femtovg dependency from glutin
This will allow updating glutin without femtovg
2022-08-25 16:49:59 +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
fd026a3991 Change itemtable to use &PlatformWindowRc instead of &WindowInner
The former is cbindgen friendly, the latter is entirely Rust internal.
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
Olivier Goffart
ff1400ab6b Skia: Fix drawing of images with source clip, but no colorize
Colorize property with transparent value means no coloration is applied

CC #1445
2022-08-15 12:41:36 +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
7b50e38e53 Skia: Implement rotation support 2022-08-11 13:32:40 +02:00
Simon Hausmann
3b9309a0dd Skia: Simplify OpenGL setup
Avoid re-creating a glow context every time we resize the context/window. Instead query
framebuffer info once (it's 0 anyway...) and keep it around.
2022-08-10 17:02:15 +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