Commit graph

376 commits

Author SHA1 Message Date
Simon Hausmann
43127cb059 Implement releasing of textures when items are destroyed
This means going back to an immutable renderer reference and interior
mutability for the canvas and the gpu cache. This is because while
traversing the item tree for rendering we may end up destroying
other items due to the lazyness of the models.
2021-01-14 08:52:22 +01:00
Simon Hausmann
1f9ba94c59 Rename the image cache
... to a more general gpu_cache and store an enum. That way we can
encapsulate the resource releasing - in the future - entirely in the
backend through run-time polymorphism in the backend (gpu cache data
enum) instead of a vtable method in the item to destruct the correct
type of data.
2021-01-14 08:52:22 +01:00
Olivier Goffart
6d316185fc Fix Painting of native widget
the cx and cy needs to be the same as the widget position
2021-01-14 08:52:22 +01:00
Olivier Goffart
b157648ab2 More work towards getting native widget with the femtovg backend 2021-01-14 08:52:22 +01:00
Simon Hausmann
7643174f28 Use interior mutability for the canvas
We're going to need it later for the resource releasing
2021-01-14 08:52:22 +01:00
Olivier Goffart
f7c8d53e7a Port the Qt Native item to the new API
this mostly restores code that was removed in commit 1a260b9dce13db38128f1f489633ba96f264d461
2021-01-14 08:52:22 +01:00
Simon Hausmann
d159a3b523 Implement caching of images
Don't re-load/decode the image every frame (and leak it), just load it
once per source change.
2021-01-14 08:52:22 +01:00
Simon Hausmann
8cfcc9bbf9 Fix image positioning, part 2
Don't forget the item's origin
2021-01-14 08:52:22 +01:00
Simon Hausmann
9b72081f01 Fix image scaling
Scale only the image if requested, not its position
2021-01-14 08:52:22 +01:00
Simon Hausmann
d92fe445d5 Remove the old GL renderer
and try to stub in the hooks to trigger the new one
2021-01-14 08:52:22 +01:00
Simon Hausmann
607fecdb18 Simplify rendering interface
Instead of passing through a generic transformation matrix, let's just
pass through what we actually use: a translation point
2021-01-14 08:52:22 +01:00
Simon Hausmann
d4f603246c WIP: Start a femtovg backend 2021-01-14 08:52:22 +01:00
Simon Hausmann
ca1fb8ab0d Fix GPU primitive vs. rendering variable division for Rectangle
Changing the border radius or border width does not require uploading a new geometry.
Therefore these can become rendering variables.
2020-12-15 18:08:33 +01:00
Olivier Goffart
aea1b3393d Fix wasm build 2020-12-15 12:38:42 +01:00
Olivier Goffart
2b5213c408 Refactor the rendering variables in a enum instead of an array
And finish the ImageFit::contain implementation
2020-12-15 12:16:44 +01:00
Simon Hausmann
d9a92aea81 Prospective fix for WebGL rendering performance on Windows
Disable anti-aliasing on the GL context, as that's often implemented
multi-sampling and it appears generally slow with Angle on Windows.Since
we do anti-aliasing ourselves, so it is not needed.
2020-12-10 09:41:29 +01:00
Simon Hausmann
8314fbbb86 Simplify the texture width/height calculation a little bit 2020-12-08 16:01:53 +01:00
Simon Hausmann
1b2261c562 Fix two compiler warnings about unsued code paths when targeting wasm 2020-12-08 12:09:44 +01:00
Simon Hausmann
49112cda9b Fix deprecation warning from image-rs
Bump to the latest version and use the non-deprecated API
2020-11-26 10:56:21 +01:00
Simon Hausmann
fc4656571f Tweak the html canvas handling
Refresh the canvas size if the browser window gets resized, for example due to orientation changes.
2020-11-26 10:42:04 +01:00
Simon Hausmann
f0289192b7 More font handling cleanup
Group all fields we need to determine a physical font into one FontRequest
structure and use that throughout.

That way adding more fields will require less changes.
2020-11-24 09:00:07 +01:00
Simon Hausmann
79b7e825bb Minor cleanup of font cache handling
Store the font family as a SharedString, as that allows us to make a
lookup without a string copy.
2020-11-23 18:23:22 +01:00
Simon Hausmann
bad7734c21 Avoid leaking cached texture allocations
Let the texture cache hold weak references and drain them each time
the rendering primitives builder finishes.
2020-11-23 16:26:21 +01:00
Simon Hausmann
ad99dc6475 Add support for image loading caching for embedded images
Extend the texture cache in the GL rendering backend to has by either
the path on disk or by the address of the static data.
2020-11-23 15:50:00 +01:00
Simon Hausmann
fdeda0d0ed Add some basic image loading caching for images loaded from the file system
Place them in a HashMap that's indexed by the path. This needs further
tuning, for example to also be applied to embedded images, and the cache
shouldn't hold a strong reference. But it makes the berlin page
playable.
2020-11-23 15:49:57 +01:00
Simon Hausmann
3d85e45ec3 Add support for source clipping to the Image element
This allows rendering only a sub-rectangle of the original image, which
we can use right away in the sliding puzzle demo.
2020-11-23 15:46:59 +01:00
Simon Hausmann
7583394751 Remove unnecessary image_size field of the Texture low-level primitive
Since our atlas allocator has an alignment of 1, the texture coordinates
(non-normalized) are identical.
2020-11-23 13:53:35 +01:00
Olivier Goffart
2e60afec39 Run cargo fmt 2020-11-23 12:08:23 +01:00
Olivier Goffart
596b740b62 Rename ARGBColor to RgbaColor 2020-11-23 11:47:47 +01:00
Olivier Goffart
62272bd73d Fix canvas size on browser. The size writen in the html is logical 2020-11-13 15:48:26 +01:00
Olivier Goffart
a82c23fc41 Add ability for the native style to export native Globals 2020-11-02 16:13:04 +01:00
Olivier Goffart
608ba95f9e Fix wasm warning 2020-10-31 11:58:10 +01:00
Simon Hausmann
a98da9ecc9 Draw rounded rectangles with anti-aliasing
Draw rounded rectangles using a distance function. This removes the need
to use lyon to tesselate the rounded corners and as a bonus it gives
anti-aliased borders.
2020-10-21 09:35:35 +02:00
Simon Hausmann
ccb57114ce Clean up cursor rectangle handling
Generalize this to be called a normalized rectangle and create it by hand.
2020-10-21 08:15:16 +02:00
Simon Hausmann
6dd08b2109 Fix color blending when using the alpha channel
Given choice of ONE_MINUS_SRC_ALPHA blending function, we assume not
only that textures are pre-multiplied with their alpha (see commit
bf396ad578), the same applies also to
flat colors.

This fixes blending such as this:

    App := Window {
        Text {
            text: "Hello World";
        }
        Rectangle {
            color: #ff335588;
            width: 100%;
            height: 100%;
        }
    }
2020-10-19 17:21:03 +02:00
Olivier Goffart
b60567d7f2 Qt style: Use an QImage that is backed by a SharedArray
This way we have one copy less of the data
2020-10-19 11:35:57 +02:00
Simon Hausmann
93df708d87 Fix clipping in the wasm demos
Enable the stencil buffer on the WebGL context attributes.
2020-10-15 07:42:33 +02:00
Olivier Goffart
d57ad389e0 Default to the native style in the viewer if it is available 2020-10-14 14:51:47 +02:00
Simon Hausmann
51f9fc0e61 Refresh the window when loading of an HTML image completed 2020-10-09 10:44:15 +02:00
Simon Hausmann
f4b6eea646 Implement the rest of the dynamic image loading for the online editor
This works except that there's a mechanism missing for refreshing the
canvas when the image was loaded.
2020-10-09 10:10:48 +02:00
Simon Hausmann
785f23f01a Make the tex__image_2d call work
* Set cross origin for the image to "anonymous" to ask the server for permission
* Pass RGBA as internal format
2020-10-09 09:57:45 +02:00
Olivier Goffart
6c9f0691aa WIP: Attempt to get image loading in wasm
Not working
2020-10-09 09:57:45 +02:00
Simon Hausmann
0f07684fcf Clean up GLFrame::render_primitive
Move the main match out into a separate helper function in GLFrame and
keep render_primitive to just be the loop. This will also make it easier
to implement the dynamic primitives later.
2020-10-09 09:56:32 +02:00
Simon Hausmann
88b94a26ea Add support for clip rectangles in the GL rendering backend 2020-09-29 11:42:02 +02:00
Simon Hausmann
1e450abc9c Change layer contents placement policy to reduce visual mess when resizing
This makes window resizing much smoother. Great advice from an anonymous
Norwegian friend ;-)
2020-09-22 14:30:27 +02:00
Simon Hausmann
4f25b0942f Draw text selections 2020-09-21 18:43:59 +02:00
Simon Hausmann
0d751e6627 Render a text cursor for TextInput items
It doesn't look quite perfect yet, but it's a start.
2020-09-18 17:58:14 +02:00
Simon Hausmann
dd8e487acc Fix discrepancy between Text layout info and rendering
The layout_info() would calculate the text metrics based on a different effective pixel
size compared to the rendering.
2020-09-15 16:15:26 +02:00
Simon Hausmann
c69781ace2 Upgrade glow 2020-09-15 11:14:23 +02:00
Simon Hausmann
19cce012a0 Add ARGBColor<T> to the color API
As discussed in the last API review, this replaces the as_rgba_f32/u8
"accessor" functions by returning a struct with named fields.
2020-09-08 22:11:23 +02:00