Commit graph

181 commits

Author SHA1 Message Date
Simon Hausmann
4970742f88 Fix support for text in SVGs
This feature was lost in the move of the image decoding to core.

Fixes #2646
2023-05-19 10:40:51 +02:00
Simon Hausmann
7f45d180a9 Clean up internal RenderingMetricsCollector API
Don't require passing a dyn WindowAdapter. This was only used for
calling request_redraw(), which a proper window adapter should do anyway
if has_active_animations() is true.
2023-05-17 09:01:02 +02:00
Yuyi Wang
fa690fe0db
Add Image::load_from_svg_data. (#2638) 2023-04-26 15:33:30 +02:00
Simon Hausmann
6c8fa5f215
Fix duplicated loading/embedding of images (#2612)
For .slint files that are included, we canonicalize the path before
adding it into the import stack, to avoid duplicates. We didn't do that
for images in the global_embedded_resources.

Ensure this by canonicalizing as early as possible.

Fixes #2608
2023-04-21 13:15:22 +02:00
Olivier Goffart
3213ca079e
Docs: Image and threads
Closes #1649
2023-04-20 10:05:26 +02:00
Arthur Araruna
3c9d6c8b70 Round values when converting from f32 to u8 in RgbaColor 2023-04-18 13:48:27 +02:00
Simon Hausmann
2cb0b2233a Attempt at making the C/C++ ABI more robust
Add explicit enum values for repr(C) enums that have attributes like
cfg, so that even if there's a cfg gap in an enum (say cfg(feature =
"svg")) it won't break the ABI.

See also 004dce6c0b
2023-04-14 14:57:47 +02:00
Olivier Goffart
977b1cc23a Update resvg dependency
Don't import all the dependent crate, use the re-export

And use a workspace dependency
2023-03-28 15:55:27 +02:00
Olivier Goffart
b4e5345a7e Femtovg: fix panic when rendering layer or shadow with negative size
Reproducer:

```
export component Test {
    width: 200px;
    height: 200px;
    Rectangle {
        clip: true;
        background: red;
        border-radius: 5px;
        height: -12px; //<- negative size
        width: 100%;
        Rectangle { background: green; }
        drop-shadow-color: #8888;
        drop-shadow-blur: 5px;
    }
}

```
2023-03-27 20:52:37 +02:00
Olivier Goffart
c82bb1515e C++ image: add some docs
Note: Don't use cbindgen to generate `operator==` for public types.
Because it doesn't have docs and the documentation show warnings
otherwise
2023-03-20 17:22:56 +01:00
Olivier Goffart
be47c8464c C++: implement creation of image from raw data
Issue #616
2023-03-20 17:22:56 +01:00
Tobias Hunger
3ac01c3f07 clippy: Fix clippy warnings 2023-03-09 09:35:29 +01:00
Simon Hausmann
8c807cb1da
Remove slint::Image::stride() (#2147)
cc #2138
2023-01-30 13:59:31 +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
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
Olivier Goffart
69df22e2fb Update resvg dependencies 2022-12-18 08:49:19 -08:00
Olivier Goffart
ccf3e8e9e9 C++: Generate image texture data for software renderer 2022-12-09 09:25:48 +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
c0a22e790e internal: Add missing alpha field for Rgba8Pixel as seen by cbindgen 2022-12-08 15:58:34 +01:00
Simon Hausmann
7122d22c88 janitor: use the new default attribute for enums 2022-12-05 10:20:39 +01:00
Simon Hausmann
65e4e7bf15 Bump resvg/usvg/tiny-skia dependencies 2022-11-01 10:44:33 +01: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
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
Olivier Goffart
36845dcbab
Support drawing embedded textures with the non-software renderers 2022-09-07 18:44:14 +02:00
Olivier Goffart
b3605cb4ec Fix errors and warnings in the wasm build 2022-09-07 10:13:58 +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
7417422e3c Make the PlatformAbstraction not Send using a EventLoopProxy trait
This changes the way the platform abstraction is initialized
2022-08-24 11:32:21 +02:00
Olivier Goffart
2e5ab86bea Rename backend module to platform
and the Backend trait into PlatfromAbstraction trait
2022-08-23 19:39:49 +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
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
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
dd081758b0 Upgrade to lyon 1.0 2022-07-22 19:27:49 +02:00
Olivier Goffart
29404e3f2c Rename i_slint_core:🪟:Window into WindowInner
We already have `api::Window` and also the Window element (`WindowItem`),
So rename the inner part to avoid confusion
2022-07-22 18:12:00 +02:00
Simon Hausmann
e5e7c61414 Simplify the rendering metrics collector API
Instead of a new() function and a start() and no stop() function, create the collector
when we want to measure and drop it when we're done.

This will also make it possible to move the collector into the renderer
in the future.
2022-07-22 15:18:13 +02:00
Simon Hausmann
26b3505542 Fix memory leak in rendering metrics collector
Avoid a cycling reference
2022-07-22 15:18:13 +02:00
Olivier Goffart
ac4f3e97ad Change slint enum values to be PascalCase in rust
... while still being kebab-case in .slint

Some enums might become public API and we want to have them as
PascalCase to respect the rust conventions
2022-07-22 12:23:52 +02:00
Simon Hausmann
650fd2c6ba Simplify internal svg rendering API a little bit
Since there is only one call site now, we can also return the correct
type without inconveniencing any other code.
2022-07-20 12:57:37 +02:00
Olivier Goffart
847a532732 Move the SVG rendering to a buffer in core 2022-07-20 12:57:37 +02:00
Simon Hausmann
b4b7b27db8 Add bounds to the decoded image cache
This defaults to 5 MB right now and SVGs aren't counted properly.
2022-07-20 12:57:37 +02:00
Simon Hausmann
5619abb878 Move ImageCacheKey into the image module
That way it'll be eaiser to deal with the code with image-decoders disabled
2022-07-20 12:57:37 +02:00
Simon Hausmann
34dc0a80e7 Fix duplicated images when building with embedded images
For embedded images the path is empty but we unconditionally used it to create a TextureCacheKey,
which clashes.

Instead, preserve and store the ImageCacheKey in the ImageInner variants.
2022-07-20 12:57:37 +02:00
Simon Hausmann
71d6717b68 Simplify image cache API
Make the image cache return Image, instead of ImageInner
2022-07-20 12:57:37 +02:00
Olivier Goffart
b8e3d2af89 HTML image in core 2022-07-20 12:57:37 +02:00
Olivier Goffart
c404194a8d Cleanup an unwanted impl From on Image 2022-07-20 12:57:37 +02:00
Simon Hausmann
b56a5581ed Fix build of generated MCU code 2022-07-20 12:57:37 +02:00
Simon Hausmann
4bb3fee04e Fix doc warnings 2022-07-20 12:57:37 +02:00
Simon Hausmann
3ef35c5ef9 WIP: compile the GL backend without image cache and its own image decoding 2022-07-20 12:57:37 +02:00