Commit Graph

2312 Commits

Author SHA1 Message Date
Matthias Clasen
d849a53b98 contour: Fix get_closest_point for circles 2023-09-20 22:11:47 -04:00
Matthias Clasen
cc904698a6 Merge branch 'matthiasc/for-main' into 'main'
contour: Make circles and rounded rects match

See merge request GNOME/gtk!6405
2023-09-18 11:14:39 +00:00
Benjamin Otte
95865cb1bf gsk: Fix clipping error when drawing shadows
When shadows were offset - in particular when offset so the original
source was out of bounds of the result - the drawing code would create a
pattern for it that didn't include enough of it to compose a shadow.

Fix that by not creating those patterns anymore, but instead drawing the
source (potentially multiple times) at the required offsets.

While that does more drawing, it simplifies the shadow node draw code,
and that's the primary goal of the Cairo rendering.

Test included.
2023-09-18 07:53:03 +02:00
Benjamin Otte
0b813de72a gl: gradients should transition in unpremultiplied space
So make the gradient shaders do that.
2023-09-18 07:53:03 +02:00
Matthias Clasen
9c159cf129 path: Tweak printing a bit more
We are dealing with floats here, so using
g_ascii_dtostr isn't really the best.

Update affected tests.
2023-09-17 22:35:33 -04:00
Matthias Clasen
957d494090 contour: Make circles and rounded rects match
Make sure that we print the weights in the
same way (as floats).

Update affected tests.
2023-09-17 20:32:32 -04:00
Matthias Clasen
f67c57b1f8 path: Fix parsing rounded rects
We were messing up the bottom left corner.

Test included.
2023-09-17 17:01:44 -04:00
Matthias Clasen
8f1d8d7cb5 path: Split off gskpathparse.c
This is a standalone piece of code,
and nicely fits into its own source file.
2023-09-17 12:29:46 -04:00
Matthias Clasen
5777587e7a docs: Add details for GskPathBuilder
Mention that GskPathBuilder will simplify
added Bézier curves.
2023-09-17 09:31:59 -04:00
Matthias Clasen
7e13cfea91 path builder: Handle degenerate cubics
Replace cubics by lines or quadratics
when possible, and split at cusps.
2023-09-17 00:23:53 -04:00
Matthias Clasen
68b4d9c35e Add gsk_curve_get_cusps 2023-09-17 00:23:53 -04:00
Matthias Clasen
1f3b69e7db path builder: Handle degenerate conics
Do the same we do for quads here. Also,
conics with weight 1 are just quads.
2023-09-17 00:23:53 -04:00
Matthias Clasen
ca63552cf8 path builder: Handle degenerate quads
Quads that have a cusp need to be replaced by
two lines.
2023-09-17 00:23:53 -04:00
Matthias Clasen
a6d2d983b8 Add gsk_bounding_box_get_corner
This will be used in the following commits.
2023-09-16 21:57:31 -04:00
Matthias Clasen
7cd97192e5 pathbuilder: Simplify degenerate curves
When a quadratic or conic has identical points,
replace it with a line.
2023-09-16 14:32:12 -04:00
Matthias Clasen
4d71ff6da1 contour: Fixes for circles
Make circle contours use 'foreach coordinates' for
its points. This works here, but not for general
conics. As with the other custom contours, avoid
emitting collapsed conics.
2023-09-16 08:27:18 -04:00
Matthias Clasen
6d001f79f9 contour: Fixes for rounded rects
Similar to the fixes for rect contours:
Handle all the special cases where empty curves
are omitted, and omit 'empty' curves in foreach.
2023-09-15 16:31:09 -04:00
Matthias Clasen
abebd92b19 contour: Fixes for rect contours
Handle all the special cases (zero width and/or height),
and omit 'empty' curves in foreach.
2023-09-15 16:31:09 -04:00
Matthias Clasen
014ca76334 docs: Add details
Spell out what gsk_path_point_get_tangent does
if there is no tangent: we return 0,0.
2023-09-15 16:31:09 -04:00
Matthias Clasen
a520f9fcf7 pathbuilder: Skip trivial curves
Don't add quads, cubics or conics that collapse
to a single point. This matches what we do for
lines.
2023-09-15 16:31:09 -04:00
Matthias Clasen
de724b2a57 contour: Fix some corner cases
Adding segments of rects or rounded rects was
not working right in cases where some of the
curves are trivial. Fix that.
2023-09-15 16:31:09 -04:00
Matthias Clasen
061637f4eb contour: Small refactoring
Move some utilities out.
2023-09-15 16:31:09 -04:00
Matthias Clasen
dab1897d4e contour: Circle cosmetics 2023-09-15 16:31:09 -04:00
Benjamin Otte
5152c13081 vulkan: Change rounded_rect_shrink()
Same fix as with the GL renderer
2023-09-15 16:34:00 +02:00
Benjamin Otte
e9089f65e3 gl: Change rounded_rect_shrink()
The code now follows gsk_rounded_rect_shrink() and with it the behavior
of the Cairo renderer and Webkit.

The old code did what the GL renderer and Cairo do, but I consider that
wrong.

I did not test Chrome.

Test attached
2023-09-15 16:34:00 +02:00
Benjamin Otte
1c971c595f glrenderer: Shadows without offset do exist
Not for opaque contents, but stuff can be semi-transparent.

Testcase included.
2023-09-15 03:46:27 +02:00
Benjamin Otte
f8627755b5 rendernode: Shadow nodes need offscreen for opacity
Otherwise the shadow will not be properly computed as opaque regions
become translucent after applying opacity.

Testcase included.
2023-09-15 03:46:27 +02:00
Benjamin Otte
55ae8dc39e gsk: Move GskRoundedRect typedef
typedef should go into *types.h headers so that other headers only need
to include those.
2023-09-15 03:46:27 +02:00
Matthias Clasen
ec1a1d0e34 gl renderer: Don't assume an atlas
The source uniform may or may not point
to a glyph atlas. The optimization we do
for color nodes is only possible if it does,
so check this.

Fixes: #6094
2023-09-13 16:56:47 -04:00
Matthias Clasen
8f4fb45715 gl renderer: Keep track of source
We have an optimization that depends on having
the source be a glyph atlas, so keep track of
that information in the render job.
2023-09-13 16:55:01 -04:00
Matthias Clasen
1502c21e97 rendernode: Fix handling of color glyphs
The rendernode parser was mixing up its flags.

Test included.

Related: #6075
2023-09-13 15:37:57 -04:00
Benjamin Otte
a05a021fd1 rendernode: Fix Cairo rendering of repeating gradients
Cairo and the GL renderer have a different idea of how to handle
transitioning of colors outside the defined range.

Consider these stops:
  black 50%, white 50%

What color is at 0%?

Cairo would transition between the last and first stop, ie it'd do a
white-to-black transition and end up at rgb(0.5,0.5,0.5) at 0%.
GL would behave as it would for non-repeating gradients and use black
for the range [0%..50%] and white for [50%..100%].
The web would rescale the range so the first stop would be at 0% and
the last stop would be at 100%, so this gradient would be illegal.

Considering that it's possible for code to transition between the
different behaviors by adding explicit stops at 0%/100%, I could choose
any method.
So I chose the simplest one, which is what the GL renderer does and
which treats repeating and non-repeating gradients the same.

Tests attached.
2023-09-07 16:19:20 +02:00
Benjamin Otte
9ffd7840ba pathpoint: Add G_GNUC_EXTENSION to struct definition
This allows compilation with gcc -pedantic.

GTKmm uses this as part of their recommended compiler flags.

Fixes #6083
2023-09-07 16:19:20 +02:00
Matthias Clasen
ea7fd1ff5a contour: Fixup for 1-point contours
If we return a path point for a 1-point contour,
make it { n, 0, 1 }.
2023-09-04 00:55:21 +02:00
Matthias Clasen
9bd9b6f2ca contour: Make sure stroke bounds are sufficient 2023-09-03 23:04:47 +02:00
Matthias Clasen
360b77cc50 curve: Add a vfunc for get_at_length
We can do this precisely for lines, so lets do it.
2023-08-29 22:09:59 -04:00
Matthias Clasen
90ee05ae64 gsk: Clean up standalone headers
We require folks to include gskglrenderer.h in order
to create a GL renderer. So we be careful to only
include header in gskglrenderer.h that won't trigger
ugly warnings.

See !6363
2023-08-29 12:58:30 -04:00
Matthias Clasen
f3312f677b measure: Cosmetics 2023-08-28 21:14:28 -04:00
Matthias Clasen
05547d98d6 path: Cosmetics
Reorganize this source file into sections.
2023-08-28 21:13:58 -04:00
Matthias Clasen
11b219bc61 Drop tolerance from gsk_contour_foreach
There is no decomposition going on for any contours,
and the tolerance argument is entirely unused.
Decomposition and tolerance is handled entirely
in gskpath.c by its trampoline.
2023-08-28 20:52:22 -04:00
Matthias Clasen
827bbc0cc1 Change gsk_path_get_closest_point to return distance
We already compute it, so lets return it.
Bindings seems fine with this change - they
already return (success, point) as a tuple
anyway.
2023-08-28 11:22:30 -04:00
Matthias Clasen
5a3ed65ad8 Improve precondition checks for path points
Add a helper function for checking that a
path point is valid for a path, and use it.
2023-08-28 00:07:50 -04:00
Matthias Clasen
2e24a9ece4 Make GskPathPoint public
The contents are still /*< private >*/, but we
let our tests and the debugger see them, which
helps.
2023-08-28 00:07:50 -04:00
Matthias Clasen
2a17320314 Limit rect variation in path builder
Make gsk_path_builder_add_rect always
produce a clockwise rectangle. This matches
what we do for circles and rounded rects,
which also go clockwise. Note that we
still need to allow negative widths in
the contour code, to implement reverse().
2023-08-28 00:07:50 -04:00
Matthias Clasen
0dbff14555 Allow circles with radius of zero
Not very useful, but we allow rects with
width and height of zero, so lets be consistent.
Curvature is infinite for such contours.

Tests included.
2023-08-28 00:07:50 -04:00
Matthias Clasen
6f3be310f4 contour: Simplify gsk_circle_contour_foreach
Use the same approach as the rounded rect contour.
2023-08-27 21:31:40 -04:00
Matthias Clasen
2ca9982b91 rect contour: Avoid nans in corner cases
The length of rect contours can be zero,
so we much check before we divide.
2023-08-27 19:17:02 -04:00
Matthias Clasen
a40282b2fb Add gsk_path_point_print
Another private debug API.
2023-08-27 19:06:39 -04:00
Matthias Clasen
ad9fb1e101 Improve quad and conic decomposition
If the control point is equal to either
start or end, just emit a line. This improves
the rendering of rounded rectangles with such
corners.
2023-08-27 16:57:03 -04:00
Matthias Clasen
02a9652af4 Use a more compact representation for circles
Print circles as M-o-o-o-o-z.
2023-08-27 14:32:21 -04:00