Commit graph

327 commits

Author SHA1 Message Date
Simon Hausmann
d73e7e48d3 GL backend: Fix GPU memory leak with layers
Delete any FBOs before making the context not current. Ooops!

Fixes #211
2021-04-29 09:23:07 +02:00
Simon Hausmann
1ef1e79b93 GL backend: Fix round corner clip radius
Rendering tests/cases/examples/rectangle_clip.60 shows a border radius
for the clipped area that's not identical with the border radius of the
inner edge of the rectangle stroke.

It appears that the stroke's inner radius is not exactly the difference
of the line (border) width but rather scaled by kappa.
2021-04-26 17:34:00 +02:00
Olivier Goffart
a61935568a Fix text alignment with multiple lines
Broken by d8ebd42712
for issue #207
2021-04-26 10:13:38 +02:00
Olivier Goffart
d8ebd42712 GL backend: fix vertical alignment of text
Fix issue in
https://github.com/sixtyfpsui/sixtyfps/issues/207#issuecomment-825780094

For the purpose of alignment, we need to use the font height, not the actual
text height, because otherwise it does not look visualy centered if the
text does not have letters that goes under the baseline
2021-04-25 14:20:35 +02:00
Olivier Goffart
74e0a98105 Adapt the GL backend to the logical/physical pixel changes 2021-04-21 17:44:53 +02:00
Simon Hausmann
db705c0104 GL backend: Fix image colorization
Commit f50d573120 accidentally changed the
composition mode for the colorization - it should of course be SourceIn.
2021-04-20 22:34:35 +02:00
Simon Hausmann
dbfa5cadde Fix text rendering with path-clipping
When rendering into a layer, we applied the y coordinate system flip
using a transform. That transform is incompatible with
Canvas::fill/stroke_text, which uses transform_point to transform the
glyph quads. That appears to not work, as opposed to the
y-flip in the main vertex shader.

Fortunately we can work around it by doing the flip when rendering the
layer image (as part of the fill).

Closes #199
2021-04-20 22:25:59 +02:00
Simon Hausmann
29425c5138 GL backend: fix texture leak when using path clipping
Make sure to release the layer images after flushing. The shared data remains alive beyond the flush.
2021-04-20 15:07:08 +02:00
Simon Hausmann
f50d573120 GL backend: Add support for path clipping, used for rounded rects
Render the sub-tree of items into an intermediate image and fill the
clip path with that image.

Fixes #199
2021-04-20 10:26:11 +02:00
Olivier Goffart
ea5e611f41 Properly combine the alpha in the GL backend 2021-04-15 15:55:14 +02:00
Simon Hausmann
6d7f8b6bab Fix handling of border width for clip in the GL backend
Similar to commit 48e6d2f48b, share the rect adjustment
code between the rectangle drawing code and the clipping.
2021-04-15 15:43:49 +02:00
Olivier Goffart
3bf3761450 Implement the Opacity filter.
Notice that the GL implementation currently don't combine the opacity
2021-04-15 10:17:52 +02:00
Simon Hausmann
fad4ef677f Improve colorize effect with the GL backend
As reported in issue #176 , there is a difference between the rendering
with Qt and femtovg. It appears that this is due to incorrect
assumptions about whether the rgb values in the intermediate buffer
image for colorization have the alpha-channel pre-multiplied or not.

When rendering into the image buffer, we would pre-multiply the alpha,
but when rendering the buffer itself, femtovg's fragment shader would
assume texture type 2 and multiply the alpha again. Therefore set the
image flag to avoid that.
2021-04-14 19:17:55 +02:00
Simon Hausmann
48e6d2f48b Fix handling of non-zero border width in clip-enabled Rectangles
The border should be visible (as in the included test case), which this
patch fixes for Qt by subtracting the border width just like when drawing.
2021-04-14 13:34:51 +02:00
Simon Hausmann
0883d15a92 GL renderer: Cache the result of the font resolution in the item rendering cache
For rendering itself as well as font_metrics() queries, store the result
in the item's rendering cache. This will be needed as the lookup is
about to become more expensive due to the need of calling OS functions
that do text analysis to determine a list of fallback fonts.

When text hasn't changed but we re-render items or re-do the layout, we
need that to be cached.
2021-04-13 15:31:58 +02:00
Simon Hausmann
104eee2527 Simplify GLFontMetrics
Store the GLFont directly as in the future that'll come out of the item cache.
2021-04-13 15:31:09 +02:00
Simon Hausmann
47a255eea5 Further preparation for more aggressive font caching
Pass everything needed for delayed evaluation for
`PlatformWindow::font_metrics()` to permit caching the font matching
result in the Text/TextInput's rendering cache.
2021-04-13 15:30:33 +02:00
Simon Hausmann
a48b81022b Prepare for font caching in text items in the GL renderer
We query text metrics frequently for text items, for example when in
layouts. This requires font resolution, which is about to become more
much more expensive due to analysis of the underlying text. To speed
this up, the objective is to use the item rendering cache. Making that
work in turn requires querying all related properties inside a property
tracker. That means we need to delay querying anything related to that,
including the font request needed for the `font_metrics()` function on
the PlatformWindow trait.
2021-04-13 15:02:57 +02:00
Simon Hausmann
2c97e84e54 Minor speedup & cleanup for text input rendering in the GL backend
Avoid re-doing the font matching, the caller of draw_text_impl() has already done that.
2021-04-13 14:09:11 +02:00
Simon Hausmann
58fc93d352 Prepare for improved font fallback handling in the GL backend
In order to determine the best list of fallback fonts for text
rendering, we need to know what text we're going to render. That's why
this patch passes the text through all the way.
2021-04-13 14:09:11 +02:00
Simon Hausmann
ccca2742c3 Prepare for caching font selection in the GL renderer
Cache the default font properties in a Property<FontRequest>, so that we
can query it in the future when determining the GLFont for text
rendering. When that will happen through a property tracker, the dirty
propagation should mark the item cache dirty when default font
properties change.
2021-04-13 14:09:11 +02:00
Simon Hausmann
f42d759131 Remove dead code
The height method on FontMetrics is not needed anymore. We call `text_size` nowadays.
2021-04-13 11:26:26 +02:00
Olivier Goffart
1773f9143b Add a border-radius property to the Clip
So that `clip: true` used on a Rectangle with border radius can be clipped
with that radius

Only the Qt backend is implemented for now
2021-04-12 19:47:18 +02:00
Simon Hausmann
1e4921de13 Fix LSP server staying alive when closing preview window
* Provide an internal behavior parameter to run_event_loop() that we can use
from the preview to not quit when the last window was closed.
* Fix Drop for the winit event loop GraphicsWindow to drop the backend window correctly
  when unmapping, not when the graphics window dies. Otherwise QuitOnLastWindowClosed doesn't work.
2021-04-06 12:11:55 +02:00
Simon Hausmann
b81803774b Start the LSP thread when the gui thread is ready
This way we can serve preview requests immediately.

This basically makes post_event safe to call before the event loop is entered.
The events will be queued up and sent when the event loop
is created and we have access
to the proxy, which will take over the queue.
2021-04-06 11:40:17 +02:00
Olivier Goffart
723b39c59a Wasm don't have threads anyway, so don't create a GLOBAL_PROXY that needs to be sync 2021-04-04 16:58:26 +02:00
Olivier Goffart
c3046f5a55 Add a way to send an event to the GUI thread from any thread
The idea is that the callback is meant to be run in the gui thread

(untested)
2021-04-03 10:00:12 +02:00
Simon Hausmann
4cbcf2611f Fix recurring C++ timers
* sixtyfps_timer_start needs to *take* the timer id out of the Rust
  timer to avoid that the subsequent drop stops the timer again
* For the Qt event loop, call `timer_event()` once before entering
  QCoreApplication::exec(), to schedule any timers that were started
  beforehand.
* Added a way to quit the event loop gently, in order to use that
  from the C++ unit test.
2021-03-25 20:07:12 +01:00
Simon Hausmann
e63baa5766 Re-organize Window and PlatformWindow construction and referencing
Initialize the self_weak in the PlatformWindow impl using the
Rc::new_cyclic pattern with a construction parameter.
2021-03-25 09:43:59 +01:00
Olivier Goffart
35cce45cbc Add a fii feature so that we don't compile in the ffi code if not required 2021-03-16 18:09:57 +01:00
Olivier Goffart
6f88d78303 Rename Resource to ImageReference in the runtime 2021-03-11 10:06:23 +01:00
Olivier Goffart
89bbdce88e Polish a bit the Brush API 2021-03-10 16:54:33 +01:00
Olivier Goffart
6f715c5612 Don't call render for items outside of the clip rects 2021-03-05 13:05:02 +01:00
Simon Hausmann
27bdb4d481 Added Window.default-font-family
One step towards getting rid of `DemoText` in the printer demo
2021-03-02 13:25:21 +01:00
Simon Hausmann
f087cc18bc Remove extern "C" functions from wasm module
We don't need these functions and their export. They account for ~20kb in
the optimized .wasm - plus JS glue code.
2021-02-26 17:04:49 +01:00
Simon Hausmann
3ba92bdc6d Add API to the wasm interpreter to download and register fonts 2021-02-17 15:21:30 +01:00
Simon Hausmann
445ddd58d5 API cleanup
Remove the `application` infix from `register_application_font`, to
reduce the changes that it might be interpreted to be a function that
also changes the default font in all text elements.
2021-02-17 14:37:31 +01:00
Simon Hausmann
45fe6c3e8d Add the ability to load application fonts by path
The viewer command line tool also gains the ability to specify them via `--app-font=/path/to/font.ttf` , which can be specified multiple times.
2021-02-17 14:16:52 +01:00
Simon Hausmann
7cea088a2c Add support for letter-spacing in text
This is conveniently supported by femtovg and Qt
2021-02-16 22:14:50 +01:00
Olivier Goffart
c4e7e38590 Workaround the fact that femtovg needs to explicitly set Hole or Solid
the actual wining is lost
2021-02-16 00:20:25 +01:00
Olivier Goffart
c7723a237b GL colorize
reset properly the canvas state (such as the clip and so on)
and rotate the image otherwise it is painted upside down
2021-02-15 21:00:39 +01:00
Olivier Goffart
1a9267aebe Some debugging aide 2021-02-15 20:15:35 +01:00
Simon Hausmann
a61bbb25b7 Fix colorizing images when transformations are in play
When painting intermittendly on the image for colorization, reset the
transformation on the canvas.

Amends commit fd5757bc44
2021-02-15 20:13:47 +01:00
Simon Hausmann
799b3b16b1 GL backend: Fix clipping with transformations applied to the canvas
After commit fd5757bc44 we now need the
upstream fix to `intersect_scissor` for clipping to work
in flickable.

So patch upstream master in for now.
2021-02-15 11:17:14 +01:00
Simon Hausmann
abe95688b9 Avoid re-parsing SVG images when scaling in the GL renderer
This isn't quite 100% clean but keeping a reference to the original svg tree
is maybe a reasonable compromise for now.
2021-02-12 18:59:02 +01:00
Simon Hausmann
fd5757bc44 Simplify coordinate handling for item rendering
Remove the pos parameter to the render functions and instead let
the item renderer apply the transformation on the rendere (femtovg
canvas or QPainter).

So `draw_*` functions in the backend now always operate in item local
coordinates.
2021-02-12 17:12:58 +01:00
Olivier Goffart
9eac131ae5 Add the logo in the docs 2021-02-12 08:24:42 +01:00
Simon Hausmann
7ac288a849 Fix disappearing html images
Commit 8a66af0746 resulted in pending html
images not being strongly referenced anymore through the item's
rendering cache when first queried in the image size query. That means
they initially reported a size (1x1) and after loading they *should*
mark the bindings dirty that depend on the implicit size, but since the
image was deleted (and along with it the notifying property), the image
kept its visible (1x1) size.

Similarly, images would get loaded too much from disk - same cause,
different effect.

To fix this, go back to the earlier design where the renderer's image
cache keeps a strong reference.
2021-02-11 08:17:33 +01:00
Simon Hausmann
12b58af1b1 Support rendering SVGs with a specified size in the GL backend
This is limited to resvg's FitTo::Width though, so the aspect ratio will
always be preserved. This might however be desirable anyway.

Relates to #129
2021-02-10 17:52:34 +01:00
Simon Hausmann
8a66af0746 Clean up image size determination in the rendering backend
Don't use the item's rendering cache to determine the image size, as
that's soley for rendering. The Qt backend doesn't use the item cache
and the GL backend neither after this change. Instead both backends have
a cache for decoded images.
2021-02-10 17:34:29 +01:00