Commit graph

413 commits

Author SHA1 Message Date
Tobias Hunger
a3b86690ff [reorg]: Move the rendering backends into internal 2022-01-31 16:00:50 +01:00
Simon Hausmann
f31f4201c6 Improve sixtyfps::Image::size() API for consistency
Make size() return an unsigned integer size type instead of floats.

cc #431
2022-01-27 22:15:29 +01:00
Tobias Hunger
43e4b262c2
janitor: Remove some more unnecessary clone() calls 2022-01-09 14:34:03 +01:00
Tobias Hunger
3e448f75eb
janitor: Remove some unnecessary references
These are immediently dereferenced by the compiler according to clippy.

Remove some now unnecessary muts to make things build again.
2022-01-04 18:22:15 +01:00
Tobias Hunger
bfca0e3573 Mass update copyright messages to be more REUSE compliant 2021-12-22 10:06:12 +01:00
Simon Hausmann
215cf68152 Add a simple frames per second counter to the GL and Qt backend
It can be activated using the `SIXTYFPS_DEBUG_PERFORMANCE` environment
variable, which takes a comma separated list of options.

This could be extended in the future with different locations for the
overlay (corner_top_left, corner_top_right, etc.) - but this is a simple
start.

cc #728
2021-12-20 15:32:20 +01:00
Simon Hausmann
5b31fa97a1 Fix formatting 2021-12-13 15:51:28 +01:00
Jocelyn Turcotte
93c28d12db wasm32: Fix reentrancy issues with invoke_from_event_loop
If it's called on top of the an event processed on the event loop,
it might be that GLOBAL_PROXY is already borrowed further down
the stack.
2021-12-13 15:51:28 +01:00
Simon Hausmann
d8988cae6c Prospective fix for making invoke_from_event_loop work better in WASM
When called from inside some winit event handler, we'd go straight to
`with_window_target` to get hold of the event proxy and send it. However
when called through some external event handler (DOM), the scoped
CURRENT_WINDOW_TARGET would not be set and MAYBE_LOOP_INSTANCE would
also be empty because `run` takes it. So instead we'd end up creating an
new event loop instance and the event would sit in there forever.

Instead, this change brings WASM in line with the other platforms by
using the dedicated event loop proxy (global_proxy). Because of the lack
of threading the dance of storage for that is a little different though.
2021-12-13 15:51:28 +01:00
Simon Hausmann
d1ae109296 Fix SVGs not being re-rendered when the scale factor changes
This issue was caused by two bugs:

 * The scale factor was not a property dependency of the Image cache entry's property tracker
 * The texture cache key for SVGs should include the target size that's scaled to.

Fixes #734
2021-12-10 22:26:15 +01:00
Simon Hausmann
2dae2a01d2 Internal cleanup in the GL renderer
Separate the image cache from the texture cache.
The latter needs additional data in the key. The two have less in common that it seemed.

This also fixes a small issue with `CachedImage::upload_to_gpu` that for
SVGs would return a decoded (rendered) SVG image, instead of a texture.
That was harmless because we always call `ensure_uploaded_to_gpu`
later, but now we assert that the texture cache only holds textures,
because clear() (former remove_textures()) just clears everything.
2021-12-10 22:26:15 +01:00
Simon Hausmann
957186acb7 Fix drop shadow offset handling with the GL renderer
The cached shadow image should just be the cache of the shadow. This
removes a visible "edge" from the shadow sometimes and brings the
rendering in line with the Qt backend.
2021-12-07 13:06:31 +01:00
Simon Hausmann
8de52f1b70 GL backend cleanup
Move the OpenGLContext helper into a module of its own, for future sharing.
2021-11-11 11:47:54 +01:00
Simon Hausmann
3c0607276c Make the GL backends' winit driven event loop a reusable module
Abstract away the dependency to the former GraphicsWindow by

(1) Renaming GraphicsWindow to GLWindow
(2) Introducing a WinitWindow trait
2021-11-11 11:45:56 +01:00
Simon Hausmann
0e8efea2ff Further speed up font handling in the GL backend
Use the new fontdb API:

* When registering embedded fonts, we don't need to make a copy of the
  embedded font data anymore.
* We don't have to mmap the font files ourselves anymore, fontdb can
  do this now for us.
2021-10-04 15:11:55 +02:00
Simon Hausmann
684fcc8dff Fix support for OpenGL ES 2.0
We default to querying GlLatest from glutin, which might run into a code
path in glutin's `bind_and_get_api` in `egl/mod.rs` that will return
None as version and pass that to `choose_fbconfig`. That function will
panic with unimplemented() if the bound API is GLES, because we need to
know which version of GLES. The bound API in turn might be GLES if
desktop GL is not supported.

To accomodate for this situation, this patch changes the GL context
creation logic to first try explicitly GLES 2.0 and then fall back to
the GlLatest variants.

In addition this pulls in a newer version of femtovg to fix FBO
rendering with stencil with GLES 2.0.
2021-09-30 11:10:42 +02:00
Olivier Goffart
3f13c69ca8 Hide the cursor of the disabled TextEdit
Fixes #513
2021-09-23 12:39:57 +02:00
Simon Hausmann
7edf19d5b2 Fix GL backend build without x11
Copypasta's wayland clipboard requires a different API that we don't cater to yet, so
for now to fix the build, disable the clipboard (use in-app nop).
2021-09-22 11:52:42 +02:00
Simon Hausmann
ac0cc85d33 Simplify font resolution in the GL backend
The font resolution function querying fontdb is fast now, so we can
always call it when rendering text. That way we don't need all the
indirection in the text_size(), etc. functions, we don't need an entry
in the item graphics cache for the font and we can avoid a lot of
property dependencies.
2021-09-21 10:10:45 +02:00
Simon Hausmann
ed3d848d02 Fix native widget rendering when the window is inactive
Set QStyle::State_Active conditional to whether the window is active,
which maps to Qt's active window concept and winit's has-focus (until we
render popups differently).
2021-09-15 15:34:34 +02:00
Simon Hausmann
37464a45c5 Fix rustdoc build in the CI
The nightly has become a bit more picky about seemingly unused variables
:-)
2021-09-13 14:19:17 +02:00
Simon Hausmann
011a9ffb83 GL backend: Prospective fix for panic when trying to create window with AMD GL driver
The srgb workaround from commit a0e827e200
appears to work with the AMD GL driver, without which the GL context
creation works (as tested by the reporter).

So instead of panicing, fall back to the glutin default with possibly an
srgb framebuffer, when trying to create a GL context. If that also
fails, provide a better error message than "called unwrap on an err".

cc #481
2021-09-09 11:53:19 +02:00
Simon Hausmann
df4e06be98 GL backend: render the cursor also for an empty text input if requested 2021-09-07 11:33:28 +02:00
Simon Hausmann
dd043fc51b Fix texture caching for images with the same source but different image-rendering properties
As tests/cases/examples/image_rendering.60 itself demonstrates, the png file
should be loaded into the CPU side image cache once, but the two textures
should be cached independently.

cc #465
2021-09-06 13:47:41 +02:00
Ryan Van Gilder
e7245cd0af cargo fmt and remove uneeded HorizontalLayout import 2021-09-06 10:03:51 +02:00
Ryan Van Gilder
4d1d0e73a4 Rename image-scaling to image-rendering to align with CSS 2021-09-06 10:03:51 +02:00
Ryan Van Gilder
a03a27ae0d Add image-scaling property to Images to control how they are scaled
Like CSS image-rendering it has "smooth" and "pixelated" options.
Only OpenGL has been tested right now, have not tested WASM or Qt.
Right now the first instance of a @image-url() will set the scaling
for that specific image. The same image used from memory on the otherhand
can all have a different scaling property.
2021-09-06 10:03:51 +02:00
Simon Hausmann
baa55e8824 Internal cleanup: Remove canvas dependency from text layout code
We can use the non-canvas bound TextContext and need the canvas only
in the closure when painting.
2021-09-02 11:09:32 +02:00
Simon Hausmann
040775173b Clean up GL backend code
Remove GLRenderer and GLRendererData. Most of the fields fold nicely
into the MappedWindow.
2021-09-02 09:48:04 +02:00
Simon Hausmann
5dff29ef67 Internal cleanup: Centralize code to determine default font properties
If the root item is a Window, then we use the default-font-* properties as the basis
for all unspecified font properties in text rendering.

This patch centralizes the code for retrieving that in the runtime window.

If this becomes a performance bottleneck, then we could cache it in a
box-pinned property in the run-time window.
2021-09-01 18:20:23 +02:00
Simon Hausmann
549fcb049b Internal cleanup: Move the scale factor property into the shared runtime Window 2021-09-01 18:20:23 +02:00
Simon Hausmann
2e8378801d GL backend: internal cleanups
Remove the indirection between the GraphicsWindow and the femtovg renderer.
2021-09-01 18:20:23 +02:00
Olivier Goffart
6e12b4504a A few fixup for the multi-line edit
- Have the cursor at the right place when clicking on end of line
 - make sure not to render new lines if there are some when in single-line mode
 - Enter should make a new line
2021-09-01 16:52:37 +02:00
Olivier Goffart
b2392c25c7 Basic support for Multi-line TextInput 2021-09-01 16:52:37 +02:00
Simon Hausmann
90765a97ce Further clean up item graphics cache handling
The RenderCache (slab and generation) is always in a refcell, so we can
just pass that through. This also eliminates the ItemGraphicsCache
wrapper in the GL backend.

This will allow more fine grained borrowing in the future.
2021-08-26 13:46:37 +02:00
Simon Hausmann
ea07d21560 Internal cleanup
Remove unnecessary wrapper function for the item graphics cache in the GL backend.
2021-08-26 13:31:15 +02:00
Olivier Goffart
a094ce7a2a Add a warning on the internal crates documentation that we don't follow semver 2021-08-16 18:26:33 +02:00
Olivier Goffart
0b5e87b66b TextInput: Properly align the cursor and selection rect with different vertical alignment 2021-08-11 16:02:25 +02:00
Simon Hausmann
8a3a68a4fa Add API to Rust sixtyfps::Image to enable creation from user supplied image buffers
This adds an ImageBuffer and PixelBuffer type for SharedVector
backed images. The documentation explains how to use this
with low-level rendering functions and the popular image crate.

Fixes #387
2021-08-10 15:56:01 +02:00
Simon Hausmann
9f4fa3599a internal cleanup: make the GL backend cSpell clean 2021-08-05 13:52:55 +02:00
Simon Hausmann
3ec2274365 internal cleanup: rename the eventloop module to event_loop
That's consistent with graphics_window and silences cSpell
2021-08-05 13:46:42 +02:00
Tobias Hunger
24a2021226 Janitor: Fix clippy::needless_borrow 2021-08-04 22:50:35 +02:00
Simon Hausmann
601e93b9f5 Style fixup: Avoid a huge match expression
Instead merging the match with a variable declared later down is easier to read.
2021-08-03 16:47:23 +02:00
Simon Hausmann
25fac2bcd5 GL backend: Avoid run-time opengl errors with clipped zero width or height rectangles
If a Rectangle has a border-radius and clipping, we use an FBO to render
the children and then use femtovg's stencil clipping. If the Rectangle
has a zero width or height, we would end up trying to create a texture
with such dimensions, which produces run-time opengl errors.

We can detect this situation and avoid it early on. The same might happen for shadows.

Fixes #377
2021-08-03 16:47:23 +02:00
Simon Hausmann
d867d7b58a Fix rendering of text selection with combining characters with the GL backend
When the text selection end follows right after a grapheme that uses less
glyphs than characters, then there may not be a matching glyph with the byte
index, therefore we wouldn't set the selection_end_x and draw incorrectly.
Take the visual tail of the last glyph then.
2021-08-01 09:35:19 +02:00
Tobias Hunger
34d461cb2b Janitor: Fix clippy::clone_on_copy 2021-07-30 09:27:48 +02:00
Tobias Hunger
2cdc5848a2 Janitor: Replace float comparison dance with approx_eq from euclid
Sixtyfps uses euclid already, so let's use euclid for float comparisons
as well.

I changed the code to decide whether a number is a positive integer to
make do without a comparison along the way.
2021-07-23 13:48:52 +02:00
Tobias Hunger
27b42687fa Janitor: Fix clippy::redundant_closure 2021-07-23 13:48:52 +02:00
Tobias Hunger
1c21ba89ee Janitor: Fix clippy::if_let_some_result 2021-07-23 13:48:52 +02:00
Tobias Hunger
8d83ce88d7 Janitor: Fix clippy::excessive_precision 2021-07-23 13:48:52 +02:00