Compare commits

..

505 Commits

Author SHA1 Message Date
Matthias Clasen
8b3957f20f css: Port border rendering 2024-06-16 17:05:31 -04:00
Matthias Clasen
12e67c644c css: Port the rest of background rendering
Now that gradients are handled, pass background color along
properly to gsk as well.
2024-06-16 16:12:41 -04:00
Matthias Clasen
f94bdbeedb css: Implement gradient interpolation
Pass the interpolation color space down to gsk.
2024-06-16 16:12:41 -04:00
Matthias Clasen
8dc4faac96 Start porting the inspector to new snapshot apis 2024-06-16 16:10:25 -04:00
Matthias Clasen
6aeb0ef751 Port GtkIconTheme to new snapshot apis 2024-06-16 16:10:25 -04:00
Matthias Clasen
f622f21c0f Port GtkGraphicsOffload to new snapshot apis: 2024-06-16 16:10:25 -04:00
Matthias Clasen
74ad081dd8 Port GtkCssShadowValue to new snapshot apis 2024-06-16 16:10:25 -04:00
Matthias Clasen
b3aff6570d Port gtkCssImageFfallback to new snapshot apis 2024-06-16 16:10:25 -04:00
Matthias Clasen
fcffe94259 Port GtkColorSwatch to new snapshot apis 2024-06-16 16:10:25 -04:00
Matthias Clasen
37e12d1fa1 Port GtkColorPlane to new snapshot apis 2024-06-16 16:10:25 -04:00
Matthias Clasen
e083ff1fed css: Add some utilities
Add functions to translate from css types to gdk and gsk ones
for colors and color spaces.
2024-06-16 16:10:10 -04:00
Matthias Clasen
6d2f311942 snapshot: Port to GdkColor
Add a full family of -2 apis that replace GdkRGBA, GskColorStop
and GskShadow with GdkColor, GskColorStop2 and GskShadow2.

The implementation of gtk_snapshot_append_layout() is not
completely converted yet.
2024-06-16 16:05:49 -04:00
Matthias Clasen
5765b0d795 testsuite: Ignore deprecations
Not porting these tests to -2 apis right now, let them continue
to test the old apis.
2024-06-16 16:05:49 -04:00
Matthias Clasen
8eec8f8234 gl: Ignore deprecations
Not going to fix up all this code right now.
2024-06-16 16:05:49 -04:00
Matthias Clasen
7d62a85825 Deprecate all the old rendernode apis
Deprecate everything where we added a -2 version recently.
2024-06-16 16:05:49 -04:00
Matthias Clasen
e444cdae9d Try a new approach
Instead of caching converted textures and maintaining color state
information in the cache, always store textures as-is, and give
all shaders that operate on images variations to deal with color
state conversion.
2024-06-16 15:58:27 -04:00
Matthias Clasen
fd17c4a425 Fix gradients
Now that we allow different color states in color stops, we need
to take care of converting them.
2024-06-16 15:57:26 -04:00
Matthias Clasen
c3cc3cdacc gpu: Improve texture caching
Keep up to two different images per texture - that is enough to
keep the original uploaded image and the one that has been converted
to the compositing colorstate.
2024-06-16 15:57:26 -04:00
Matthias Clasen
0402a350e7 Make display colorstate settable
Just for debugging
2024-06-16 15:57:25 -04:00
Matthias Clasen
74460f148b gpu: Complete porting away from GdkRGBA apis 2024-06-16 15:57:25 -04:00
Matthias Clasen
89609ec412 inspector: Port to GdkColor 2024-06-16 15:57:25 -04:00
Matthias Clasen
598874dc7b More conversion work
Move from GdkRGBA to GdkColor in many places.
2024-06-16 15:57:25 -04:00
Matthias Clasen
ea6b5b4425 Allow border nodes to carry color states 2024-06-16 15:57:25 -04:00
Matthias Clasen
b415e74dbd Allow shadow nodes to carry a color state 2024-06-16 15:57:25 -04:00
Matthias Clasen
8d9532d204 Fix patterns for color and text nodes 2024-06-16 15:57:25 -04:00
Matthias Clasen
0764cfe566 Gradients for the pattern shader 2024-06-16 15:57:25 -04:00
Matthias Clasen
1f1e41bdaa Introduce GskColorStop2 2024-06-16 15:57:25 -04:00
Matthias Clasen
c690079ee5 Let text nodes carry a color state
We use the same approach as for color nodes, and make a union
of GdkRGBA and GdkColor.
2024-06-16 15:57:25 -04:00
Matthias Clasen
c59b7bde2a Let color nodes carry a color state
We make a union of GdkRGBA and GdkColor, and add new getters.
2024-06-16 15:57:25 -04:00
Matthias Clasen
74f5bcdd4a rendernodeparser: Allow more colors
Parse colors like color(XXX x y z / alpha). Unlike css, we allow
all our named color spaces here, with the same ranges as defined
for css. Percentages are allowed, but things like currentcolor,
relative colors, missing components, calc() are not.
2024-06-16 15:57:25 -04:00
Matthias Clasen
a7c2c7c041 gpu: Handle color states for gradients
The plan is to convert the color stops into the interpolation
color state, let the shader to the interpolation, and convert
from the interpolation color state to the compositing color
state afterwards. This isn't hooked up yet, since we don't have
interpolation color states in the render nodes yet.
2024-06-16 15:57:25 -04:00
Matthias Clasen
537f8ec69b gpu: Use the clip for color conversion
When creating the offscreen for color conversion, take the clip
into account - we don't need a bigger offscreen than that.
2024-06-16 15:57:25 -04:00
Matthias Clasen
134ec9343d gpu: Avoid an offscreen when possible 2024-06-16 15:57:25 -04:00
Matthias Clasen
79c214e75d gpu: Convert colors to the right color state
Currently, all the colors in render nodes are srgb. Convert them
to the compositing color state before using them. We store the
converted colors in a GdkRGBA (somewhat against its definition),
since all the op apis are expecting GdkRGBA for colors. This should
be cleaned up later.
2024-06-16 15:57:25 -04:00
Matthias Clasen
f271049263 gpu: Use stem darkening for linear composited glyphs
When the compositing color state is linear, apply the freetype
stem darkening hack.
2024-06-16 15:57:25 -04:00
Matthias Clasen
fb5d69fc02 gpu: Take color state into account for glyph lookup
Add a 'linear' bit to the glyph cache key, so we can get have
separate cached images for the two cases. Note that the image
tagging with color state is ignored here - we simply copy the
glyph image out of the atlas as-is, and rely on the cache to
give use the right color state.
2024-06-16 15:57:25 -04:00
Matthias Clasen
b27eaa344b gpu: Track color state in the texture cache
Keep the color state information around for cached images and
handle the necessary conversions when using them.
2024-06-16 15:57:25 -04:00
Matthias Clasen
d245674c1f gpu: Use the right depth when creating offscreens 2024-06-16 15:57:25 -04:00
Matthias Clasen
4c7526ad99 gpu: Convert textures to the right color state
Add function to convert an image from one color state to another,
and call it whenever we upload a texture.
2024-06-16 15:57:25 -04:00
Matthias Clasen
d83643d6fc gpu: Add a color convert shader
This shader converts between named color states, by using the
same functions that we use on the cpu. The conversion to perform
is passed as an integer encoding the pair of color states. If
we don't have a direction function for going from the first to
the second, we go via XYZ.
2024-06-16 15:57:25 -04:00
Matthias Clasen
e979595280 Make compositing colorstate settable
This helps for debugging.
2024-06-16 15:57:25 -04:00
Matthias Clasen
6b76c13bcc gpu: Pass compositing color states around
Make the node processor and the pattern writer track the current
compositing color state. Color state nodes change it. We pass
the surface color state down via the frame apis.
2024-06-16 15:57:25 -04:00
Matthias Clasen
5ab831215e testsuite: Replay color state nodes 2024-06-16 15:57:25 -04:00
Matthias Clasen
1e404f6625 Add gtk_snapshot_push_color_state 2024-06-16 15:57:25 -04:00
Matthias Clasen
2dc85d7e5f Add a color state node 2024-06-16 15:57:25 -04:00
Matthias Clasen
5f706c73fd testsuite: Compare textures properly
When compoaring textures, we now need to look
at the colorspace as well.
2024-06-16 15:57:25 -04:00
Matthias Clasen
208e5a9931 gtk-demo: Add a color space demo
This is using test images from http://displaycal.net/.
2024-06-16 15:57:25 -04:00
Benjamin Otte
421e8dcbc8 widget-factory: Add gradient rendering test
Test how GTK draws gradients, by adding an sRGB and a linear colorspace
gradient and draw one with CSS.

Have a look which one (if any) matches.
2024-06-16 15:57:25 -04:00
Matthias Clasen
2bc12a8b27 cairo: Use stem darkening for glyphs
This involves tweaking a freetype driver property
directly, since cairo font options don't cover this.

So the code is a bit ugly, but it does make text
appear darker.
2024-06-16 15:57:25 -04:00
Matthias Clasen
bfca93eafc Port gsk_render_node_draw to GdkColor
Use GdkColor when using cairo for rendering. This makes it so that
the rendering happens in a color-managed way when a color state has
been attached to the target.
2024-06-16 15:57:25 -04:00
Matthias Clasen
bd2ac3e897 cairo: Use GdkColor 2024-06-16 15:57:25 -04:00
Matthias Clasen
1e1c8d1a6d Add crude color management impl for cairo
Use linear compositing with cairo if LINEAR_COMPOSITING=1 is
set in the environment.
2024-06-16 15:57:25 -04:00
Matthias Clasen
7b4f08eea6 Add gdk_cairo_set_source_color 2024-06-16 15:57:25 -04:00
Benjamin Otte
baefbc5259 Add color space get/set for cairo
Add a centralized place to attach color space to.

Nothing uses that information yet, but all the
backends do set it.
2024-06-16 15:57:25 -04:00
Matthias Clasen
81da727a9c gdk: Introduce GdkColor
GdkColor represents a color in the real world, by combining a color
profile, an alpha value and N component values.
2024-06-16 15:57:25 -04:00
Benjamin Otte
13e3242e7d gdk: Add GDK_DEBUG=srgb
Disables gdk_surface_set_color_profile() for backends and forces
sRGB.

This does not change any GSK renderers, it just turns off any backends
trying to hand us color profiles.
2024-06-16 15:57:25 -04:00
Benjamin Otte
afb02f2d54 x11: Implement support for color states
Stole the implementation from eog.

This doesn't yet update the color state when it changes though.
2024-06-16 15:57:25 -04:00
Matthias Clasen
c53772908c Give surfaces a color state
Add api to get the color state of a surface.
2024-06-16 15:57:25 -04:00
Matthias Clasen
83523d88f6 Add color state to texture download methods 2024-06-16 15:57:25 -04:00
Matthias Clasen
b5e4bf7a70 Add color states to gdk_memory_convert
This lets us perform color space conversions at the same time
as memory format changes.
2024-06-16 15:57:25 -04:00
Matthias Clasen
1c1d52cc59 pixbuf: Add color state support
When creating a GdkTexture from a GdkPixbuf, see if it has an
icc profile attached, and if so, use it.
2024-06-16 15:57:25 -04:00
Matthias Clasen
6b600a2bd8 tiff: Add color state support
When loading or saving tiff files, translate between embedded
icc profiles and color state objects.
2024-06-16 15:57:25 -04:00
Benjamin Otte
e3100bde3b png: Add color state support
When loading or saving png files, translate between embedded
icc profiles or cicp data and color state objects.
2024-06-16 15:57:25 -04:00
Benjamin Otte
5395e839a3 jpeg: Add color state support
When loading or saving jpeg files, translate between embedded
icc profiles and color state objects.
2024-06-16 15:57:25 -04:00
Matthias Clasen
9cbe82d7fe dmabuf texture: color state support 2024-06-16 15:57:25 -04:00
Matthias Clasen
8ed427dab9 gl texture: color state support 2024-06-16 15:57:25 -04:00
Matthias Clasen
47fe542e62 memory texture: color state support 2024-06-16 15:57:25 -04:00
Matthias Clasen
67e3afe42e Give textures a color state 2024-06-16 15:57:25 -04:00
Matthias Clasen
b2e72700e8 Add some colorstate tests
This is very minimal, but it is enough to do
a very basic check of the gdk_color_space_equal
implementation.
2024-06-16 15:57:25 -04:00
Matthias Clasen
ae1e2a13d1 Add GdkColorState
This is just an empty shell for now.
2024-06-16 15:57:25 -04:00
Matthias Clasen
76a80d8f45 Merge branch 'docs-drawing-overview' into 'main'
docs: gtk_widget_queue_draw() is a single function, not a set anymore

See merge request GNOME/gtk!7362
2024-06-16 18:16:42 +00:00
Matthias Clasen
153b8399f7 Merge branch 'matthiasc/for-main' into 'main'
css: Move the color space enums to a better place

See merge request GNOME/gtk!7363
2024-06-16 18:14:01 +00:00
Matthias Clasen
da41271dd5 css: Parse interpolation for conic gradients
Parse things like "in hsl hue longer". For details, see the
CSS Images Module Level 4, https://www.w3.org/TR/css-images-4.

This commit fixes preexisting brokenness in conic-gradient parsing
and printing as well, and includes the relevant test changes.

Tests included.

Gradient interpolation color spaces aren't supported for
rendering yet.
2024-06-16 13:22:36 -04:00
Matthias Clasen
5610af1b77 css: Parse interpolation for radial gradients
Parse things like "in hsl hue longer". For details, see the
CSS Images Module Level 4, https://www.w3.org/TR/css-images-4.

Tests included.

Gradient interpolation color spaces aren't supported for
rendering yet.
2024-06-16 13:22:27 -04:00
Matthias Clasen
8da70fec91 css: Parse interpolation for linear gradients
Parse things like "in hsl hue longer". For details, see the
CSS Images Module Level 4, https://www.w3.org/TR/css-images-4.

Tests included.

Gradient interpolation color spaces aren't supported for
rendering yet.
2024-06-16 13:21:56 -04:00
Matthias Clasen
f9cd30a859 css: Better error reporting
I seem to mix up the order of 'longer hue' occasionally, so lets
throw a helpful error message if we see 'hue' first.
2024-06-16 13:04:58 -04:00
Matthias Clasen
763d620a23 css: Parse all supported color spaces
The code parsing interpolation methods hadn't learned about
or latest color space additions. While we're at it, improve
the error reporting a bit.

Tests included.
2024-06-16 13:04:52 -04:00
Matthias Clasen
500a3a6dee css: Add a helper function for parsing
This will be helpful in gradient parsing code, where the color
interpolation is optional.
2024-06-16 13:04:44 -04:00
Matthias Clasen
57073e1057 css: Move the color space enums to a better place
These will be used in the gradient code too, so put them into
a more better place.
2024-06-16 13:04:13 -04:00
Daniel Rusek
6bbfd2f62a Update Czech translation 2024-06-16 13:32:33 +00:00
Gabor Karsay
6c69a96cd7 docs: link some methods in drawing model overview 2024-06-16 10:30:44 +00:00
Gabor Karsay
fa247d5a84 docs: gtk_widget_queue_draw() is a single function, not a set anymore 2024-06-16 10:02:32 +00:00
Matthias Clasen
0320c4ac14 Merge branch 'matthiasc/for-main' into 'main'
gpu: Print some more details

See merge request GNOME/gtk!7360
2024-06-15 21:59:14 +00:00
Matthias Clasen
36993ac707 gpu: Print some more details
Print the variations of mask and blendmode operations.
Just because we can.
2024-06-15 14:00:46 -04:00
Matthias Clasen
2f93eb4a28 Merge branch 'matthiasc/for-main' into 'main'
Fix a copy-paste error

See merge request GNOME/gtk!7358
2024-06-14 23:18:55 +00:00
Matthias Clasen
5a2982ac31 testsuite: Fix one nodeparser error 2024-06-14 14:11:54 -04:00
Matthias Clasen
441b704afd testsuite: Stop relying on xpms
gdk-pixbuf isn't loading those anymore, by default.
2024-06-14 14:11:22 -04:00
Matthias Clasen
abf6ebd7fe label: Only put alpha in attributes when needed
It does not do much harm, but it broke some of our tests.
2024-06-14 14:04:23 -04:00
Matthias Clasen
34fb08af6e Fix a copy-paste error
This was obviously meant to compare two different colors.
2024-06-14 12:30:06 -04:00
Matthias Clasen
0b9dfdd41f Merge branch 'wip/alice/color-fix' into 'main'
More color clamping and redraw fixes

See merge request GNOME/gtk!7357
2024-06-14 11:07:49 +00:00
Alice Mikhaylenko
701e0812e4 treeview: Clamp tree line and grid line colors 2024-06-14 03:04:54 +04:00
Alice Mikhaylenko
4918a46172 textview: Redraw selection on style changes 2024-06-14 03:04:54 +04:00
Alice Mikhaylenko
ef5e3fae64 aboutdialog: Update link colors on css changes 2024-06-14 03:04:54 +04:00
Alice Mikhaylenko
9fcf55571e textlayout: Clamp colors before passing them to Pango 2024-06-14 03:04:54 +04:00
Alice Mikhaylenko
260898ecf6 text: Redraw when selection style changes 2024-06-14 01:41:22 +04:00
Alice Mikhaylenko
66c9132abe label: Update selection on css changes too 2024-06-14 01:41:22 +04:00
Alice Mikhaylenko
c5abdfb72b label: Fix critical when updating styles
Noticed when testing with libadwaita styles instead of GTK styles.
2024-06-13 23:36:38 +04:00
Matthias Clasen
4fe37847ba Merge branch 'wip/alice/color-fix' into 'main'
Fix GtkLabel link color

Closes #6781

See merge request GNOME/gtk!7355
2024-06-13 13:28:58 +00:00
Alice Mikhaylenko
c99a0b0518 label: Track link style changes
If we're gonna have system accents, would be nice to update links reliably
and not wait for other changes like changing color of the label itself.
2024-06-13 16:28:06 +04:00
Alice Mikhaylenko
31f3edec5c label: Clamp out-of-gamut link color
Support alpha too while we're here.

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/6781
2024-06-13 16:28:05 +04:00
Emmanuele Bassi
dee372c08e Merge branch 'ebassi/docs-for-master' into 'main'
docs: Fix link to DragIcon.get_for_drag()

See merge request GNOME/gtk!7347
2024-06-13 11:27:28 +00:00
Matthias Clasen
8c0a4e5a6e Merge branch 'matthiasc/for-main' into 'main'
Silence a compiler warning

See merge request GNOME/gtk!7354
2024-06-12 03:24:29 +00:00
Matthias Clasen
7195514fb5 Silence a compiler warning 2024-06-11 17:47:48 -04:00
Matthias Clasen
420bd5bc16 Merge branch 'more-css-color-spaces' into 'main'
css: Add more color spaces

See merge request GNOME/gtk!7352
2024-06-11 21:05:06 +00:00
Matthias Clasen
f024ee1adf Add more tests for css colors 2024-06-11 16:41:22 -04:00
Matthias Clasen
18c2c71cd5 css: Add support for rec2100-pq colors
This is our first HDR color space. Yay!!

The conversion between rec2020-linear and rec2100-linear
assumes that SDR 1,1,1 has a luminance of 203 cd/m².
2024-06-11 16:41:22 -04:00
Matthias Clasen
2d1bfc84b9 Expose more colorutils
We may want to have a rec2020-linear space available on the gsk
level, so expose the conversion functions for it.
2024-06-11 16:41:22 -04:00
Matthias Clasen
8edfa759fb css: Add support for rec2020 colors
Another extremely wide gamut color space.
2024-06-11 16:41:22 -04:00
Matthias Clasen
2d1e978599 css: Add support for xyz colors
This is somewhat central, and we have all the pieces to support
it, so we might as well add the css syntax for it.
2024-06-11 16:41:22 -04:00
Matthias Clasen
d71fc41152 css: Add support for display-p3 colors
A wide-gamut colorspace.
2024-06-11 16:41:22 -04:00
Matthias Clasen
d141cb7b72 Fix an oversight
This snuck in as part of 098d67f8befdb00d75.
2024-06-11 16:41:22 -04:00
Matthias Clasen
7010067884 Merge branch 'vulkan-high-depth' into 'main'
gpu: Print more info for renderpasses

See merge request GNOME/gtk!7351
2024-06-09 21:10:25 +00:00
Matthias Clasen
0ec29c4176 gsk: Pass the memory format for back buffer
We can now get this information from the Vulkan context,
so use it to accurately represent the back buffer.

Related: #6767
2024-06-09 15:59:56 -04:00
Matthias Clasen
42c6e0249f vulkan: Fix updating swap chains
gdk_vulkan_context_check_swapchain uses priv->current_format,
so we must update it first, and undo that if check_swapchain
falls. This fixes handling of high-depth back buffers in gsk.
2024-06-09 15:59:56 -04:00
Matthias Clasen
54eb85f814 vulkan: Add a getter for the memory format
We need this to accurately set up the gpu image for the
backbuffer in gsk.
2024-06-09 15:59:56 -04:00
Matthias Clasen
18b3b4feed gpu: Print more info for images
Show the memory format.

This helps debugging our depth selection.
2024-06-09 15:59:32 -04:00
Matthias Clasen
0045ac839b Give memory formats a name
This is useful in debugging.

The names I chose are shortened a bit from the enum values. We
use just a single depth, * for premultiplied, and f for float.
2024-06-09 15:59:27 -04:00
Matthias Clasen
a9da807de3 Merge branch 'cmurtag/fix_harfbuzz_subset_wrap' into 'main'
Fix Harfbuzz subset dependency not found in wrap

See merge request GNOME/gtk!7349
2024-06-08 10:26:12 +00:00
cameron
366639b7e4 Fix Harfbuzz subset dependency not found in wrap
Add harfbuzz subset to the harfbuzz wrap file so Meson can find the
dependency.
2024-06-08 13:54:21 +10:00
Emmanuele Bassi
7d2e2171be docs: Fix link to DragIcon.get_for_drag()
It has been marked as a constructor in commit 13013053f7.
2024-06-07 13:33:32 +02:00
Matthias Clasen
e3ceda15ac Merge branch 'gsktransform-improve-docs' into 'main'
gsktransform: Document consuming functions

See merge request GNOME/gtk!7342
2024-06-06 10:53:17 +00:00
Matthias Clasen
7291a21a85 Merge branch 'wip/alice/css' into 'main'
CSS fixes and more tests

See merge request GNOME/gtk!7345
2024-06-05 20:54:12 +00:00
Matthias Clasen
888afe3e46 Merge branch 'wip/alice/opacity' into 'main'
css: Allow percents in opacity

See merge request GNOME/gtk!7346
2024-06-05 20:53:55 +00:00
Alice Mikhaylenko
171bfde133 csscolorvalue: Fix percentage ranges for relative colors
Add tests as well, now that they can be computed at parse time.
2024-06-06 00:35:52 +04:00
Alice Mikhaylenko
82d1fdb714 csscolorvalue: Resolve relative colors at parse time when possible 2024-06-06 00:35:52 +04:00
Alice Mikhaylenko
82b19daa7e csscolorvalue: Don't serialize relative colors as rgb()
Spec says it should be color(srgb).
2024-06-06 00:35:52 +04:00
Alice Mikhaylenko
dc1ff3c2e3 csscolorvalue: Fix oklab() percentage range 2024-06-06 00:35:52 +04:00
Alice Mikhaylenko
6602ac5eae testsuite: Fix css tests
There are a bunch of new deprecations, and some tests weren't in
meson.build.
2024-06-06 00:35:52 +04:00
Alice Mikhaylenko
5dab5bf0e9 css: Allow percents in opacity
Add another missing feature from web css. It's nice to be able to use the
same variables in color-mix() and here.
2024-06-06 00:22:19 +04:00
Matthijs Velsink
721be8fe9f gsktransform: Document consuming functions
Since GskTransform is immutable, a lot of the documented "methods" are
more like "functions", in the sense that they don't keep the instance
alive but rather consume it.

This is annotated with `(transfer full)`, but since these functions are
listed as methods, their first argument is not shown.

Instead, let's add a line to the docs of each consuming function that
clarifies this behavior.
2024-06-05 15:59:49 +02:00
Matthias Clasen
58fe590eae Merge branch 'matthiasc/for-main' into 'main'
css: Plug a memory leak

See merge request GNOME/gtk!7341
2024-06-05 12:18:50 +00:00
Matthias Clasen
c18a7ff5cf css: Plug a memory leak
This snuck in when the relative color support was merged.
2024-06-05 07:22:47 -04:00
Matthias Clasen
24fc38b287 Merge branch 'matthiasc/for-main' into 'main'
docs: Improve css color migration docs

See merge request GNOME/gtk!7340
2024-06-04 18:47:21 +00:00
Matthias Clasen
aa03c50f05 theme: Use better replacements for color expressions
These match what we recommend for migration.
2024-06-04 12:54:41 -04:00
Matthias Clasen
03e971b2e3 Revert "theme: Stop using alpha() and shade()"
This reverts commit 0e94e5ecda.
2024-06-04 12:48:55 -04:00
Matthias Clasen
a595133b77 docs: Improve css color migration docs
With relative colors, we can do better.
2024-06-04 12:39:40 -04:00
Matthias Clasen
e50f4ecccf NEWS: Updates 2024-06-04 12:00:02 -04:00
Matthias Clasen
67913e4af0 docs: Add more details about CSS colors 2024-06-04 12:00:02 -04:00
Matthias Clasen
b3d1795327 Merge branch 'file-chooser-shortcut-new-folder' into 'main'
gtkfilechooserwidget: Add shortcut to create a new folder

Closes #5527

See merge request GNOME/gtk!7338
2024-06-04 15:38:38 +00:00
Matthias Clasen
6edcc8f256 Merge branch 'css-relative-colors' into 'main'
css: Support relative colors

See merge request GNOME/gtk!7326
2024-06-04 14:59:00 +00:00
Matthias Clasen
d5e5f47666 css: Add tests for relative colors 2024-06-04 10:47:54 -04:00
Matthias Clasen
0524c40640 css: Support relative colors
Parse the various color(from <color> ...) syntaxes, and implement
them.

Add a new 'relative color' subtype for color values, and a new
'color coord' subtype for number values. Use these for relative
colors where the original color can't be resolved at parse time.
2024-06-04 10:47:54 -04:00
Matthias Clasen
b5fd894f77 css: Add a function to get color coords
This will be used in the implementation of relative colors.
2024-06-04 10:47:21 -04:00
Matthias Clasen
d8492121aa css: Rewrite the color parsing code
Make this more uniform, and easier to extend.

Also, use gtk_css_number_value_parse_with_context, since we
are going to add context here in the future.
2024-06-04 10:47:21 -04:00
Matthias Clasen
4a0bf603d7 css: Add context for parsing numbers
In the future, parsing numbers will depend one some context, so
add a context struct to the involved apis. This is not used yet.
2024-06-04 10:47:21 -04:00
Matthias Clasen
02fa89df9e css: Change the api for resolving colors
We will need to compute other values in here in the future, and for
that we need all the arguments that get passed to compute(), so carry
them along.

Update all callers.
2024-06-04 10:47:21 -04:00
Martin
5b6dde9a73 Update Slovenian translation 2024-06-04 07:27:42 +00:00
Automeris naranja
e9d8ebdfc9 gtkfilechooserwidget: Add shortcut to create a new folder
Closes https://gitlab.gnome.org/GNOME/gtk/-/issues/5527
2024-06-03 22:49:11 -03:00
Matthias Clasen
366efc3d61 Merge branch 'css-color-deprecations2' into 'main'
css: Deprecate our own color functions

See merge request GNOME/gtk!7311
2024-06-04 00:41:44 +00:00
Matthias Clasen
3b890fd3c1 css: Document replacements for color stuff
Document how named colors and non-standard color expressions
can be replaced.
2024-06-03 20:37:52 -04:00
Matthias Clasen
5de373a14b css: Deprecate our own color functions
We will soon have new standards-conformant color functions from
the css-colors-5 spec, so these can be phased out.
2024-06-03 20:37:52 -04:00
Matthias Clasen
24cb9d2437 docs: Fix the 4to5 migration guide
This was referring to a nonexisting api.
2024-06-03 20:37:52 -04:00
Matthias Clasen
83aa176466 docs: Add the 4to5 migration guide to the docs
Adding this to the built docs ensures that it is buildable.
2024-06-03 20:37:52 -04:00
Matthias Clasen
0e94e5ecda theme: Stop using alpha() and shade()
These are being phased out in favor of color-mix().
2024-06-03 20:37:52 -04:00
Matthias Clasen
130485a583 Merge branch 'wip/alice/colors-2' into 'main'
Implement color-mix()

See merge request GNOME/gtk!7336
2024-06-03 21:17:54 +00:00
Alice Mikhaylenko
f34c10abb5 csscolorvalue: Get rid of the literal type
Just use color with srgb color space and serialize_as_rgb=TRUE.
2024-06-03 23:59:44 +04:00
Alice Mikhaylenko
48b00f0ac1 testsuite: Add color-mix() tests 2024-06-03 23:59:44 +04:00
Alice Mikhaylenko
743329a3af csscolorvalue: Implement color-mix() 2024-06-03 23:59:44 +04:00
Alice Mikhaylenko
f5783f1637 csscolor: Add functions for parsing and printing interpolation method 2024-06-03 23:59:44 +04:00
Matthias Clasen
67f61a8d39 Merge branch 'matthiasc/for-main' into 'main'
Fix the build

See merge request GNOME/gtk!7337
2024-06-03 19:16:22 +00:00
Matthias Clasen
f7df663dea Fix the build
I typoed in a2223c0884.
2024-06-03 15:10:19 -04:00
Alice Mikhaylenko
c99278aa58 csscolor: Allow printing hsl and hwb as color() too 2024-06-03 22:09:26 +04:00
Alice Mikhaylenko
1765e1b7c2 testsuite: Add GTK_DEBUG=css
Make named color tests work, since they expect deprecation warnings atm.
2024-06-03 21:53:52 +04:00
Matthias Clasen
bf1a434d5c Merge branch 'font-subsetting-in-node-files' into 'main'
Use font subsetting in serialized nodes

See merge request GNOME/gtk!7227
2024-06-03 12:47:59 +00:00
Matthias Clasen
9256b5b552 rendernode tool: Add an extract command
This lets one extract the data urls from a node file.
2024-06-03 08:28:21 -04:00
Matthias Clasen
577e4afb3c Improve font deserialization
Even if we disable font fallback, after adding Cantarell Regular
to the custom fontmap, fontconfig will helpfully synthesize
Cantarell Bold for us. So, just don't check for the font at all.
If there is a url, add it to the fontmap and leave it up to the
serializing code to ensure that we don't end up with duplicate
fonts.
2024-06-03 07:45:57 -04:00
Matthias Clasen
2a05c04db7 Use the hb face as key when tracking fonts
The hb face is is a wrapper around the font file, which is what
we need to track here, since we want to subset and serialize each
used font file exactly once.
2024-06-03 07:44:16 -04:00
Matthias Clasen
a6ffd6b3b2 nodeparser: Subset fonts
When serializing nodes, collect the glyphs that are used from
each font, subset the font to that set of glyphs, and embed it
into the node file. We are careful to preserve the glyph IDs,
so our text nodes transparently work with the subsettted fonts.
2024-06-03 07:38:51 -04:00
Matthias Clasen
24eba7c4c1 Merge branch 'matthiasc/for-main' into 'main'
Drop redundant GLib version check

See merge request GNOME/gtk!7334
2024-06-03 00:22:16 +00:00
Matthias Clasen
80de844922 Cosmetics 2024-06-02 20:07:33 -04:00
Matthias Clasen
a2223c0884 Drop redundant GLib version check
We require GLib 2.76 now.
2024-06-02 20:07:33 -04:00
Matthias Clasen
5ffa2b757c Merge branch 'less-vulkan' into 'main'
Don't use Vulkan without dmabufs

See merge request GNOME/gtk!7220
2024-06-02 23:58:24 +00:00
Matthias Clasen
b660fa27d3 Merge branch 'fix-missing-listeners' into 'main'
wayland: Add missing listeners

See merge request GNOME/gtk!7331
2024-06-02 20:42:13 +00:00
Matthias Clasen
77f0e5e1ba wayland: Add missing listeners
Now that we are using version 6 of the compositor interface,
we need to have preferred scale and bufer transform callbacks
everywhere.
2024-06-02 12:07:51 -04:00
Matthias Clasen
1080822ffa Merge branch 'matthiasc/css-deprecation-warning' into 'main'
css: Emit deprecation warnings only under debug

See merge request GNOME/gtk!7330
2024-06-02 15:33:32 +00:00
Matthias Clasen
3fef45683c css: Emit deprecation warnings only under debug 2024-06-02 15:33:32 +00:00
Matthias Clasen
cfcc5c5c0b Merge branch 'docs-add-missing-returns-args' into 'main'
docs: Add missing returns and parameter annotations

See merge request GNOME/gtk!7325
2024-06-02 15:26:50 +00:00
Matthias Clasen
856f1808de Merge branch 'matthiasc/for-main' into 'main'
Fix a bug in color conversion

See merge request GNOME/gtk!7328
2024-06-02 15:24:09 +00:00
Matthias Clasen
4341344545 css: Add a utility for color space coords 2024-06-02 11:08:35 -04:00
Matthias Clasen
20392e8840 Cosmetics 2024-06-02 10:48:21 -04:00
Matthias Clasen
426fefff81 Merge branch 'bilelmoussaoui/gi-constructor' into 'main'
gtk: Mark DragIcon.get_for_drag as constructor

See merge request GNOME/gtk!7329
2024-06-02 14:43:29 +00:00
Bilal Elmoussaoui
13013053f7 gtk: Mark DragIcon.get_for_drag as constructor
Fixes downstream issue: https://github.com/gtk-rs/gtk4-rs/issues/1748
2024-06-02 16:54:17 +03:00
Matthias Clasen
62b9a4af75 Drop an unused static 2024-06-02 09:19:22 -04:00
Matthias Clasen
76caf2c812 color value: Organize the code
Add some sections, so I can find my way around.
2024-06-02 08:46:56 -04:00
Matthias Clasen
3d5fce1b9f Fix a bug in color conversion
The linear space corresponding to oklab is oklab, not srgb-linear.
2024-06-02 08:46:33 -04:00
Matthias Clasen
bfe8adbee4 Merge branch 'fix-obvious-doc-issues' into 'main'
Fix obvious docstring issues

See merge request GNOME/gtk!7320
2024-06-02 12:02:06 +00:00
Matthias Clasen
827642303c Merge branch 'fix-getter-for-dropdown' into 'main'
gtkdropdown: Use proper attribute

See merge request GNOME/gtk!7327
2024-06-02 11:56:53 +00:00
Maximiliano Sandoval
6b6a0e1257 docs: Fix {g,s}et_property attributes annotations
Do not use set_property on getters and vice versa.
2024-06-02 13:49:45 +02:00
Martin
7a98176a02 Update Slovenian translation 2024-06-01 08:53:47 +00:00
Maximiliano Sandoval
a93a986ef2 gtkiconview: docs: Add missing return annotation 2024-06-01 10:01:20 +02:00
Maximiliano Sandoval
39dbc5ea87 gtkcombobox: Document popdown signal return value 2024-06-01 10:01:20 +02:00
Maximiliano Sandoval
cf4d13bee3 gdkevents: gdk_event_get_position return value 2024-06-01 10:01:20 +02:00
Maximiliano Sandoval
0bacde8e0a gskpathbuilder: Document add_cairo_path path arg 2024-06-01 10:01:19 +02:00
Maximiliano Sandoval
949cd45bb7 gskstroke: Add missing return annotations 2024-06-01 10:01:19 +02:00
Maximiliano Sandoval
2e9e216641 gtkicontheme: Document lockup_icon arguments 2024-06-01 10:01:19 +02:00
Maximiliano Sandoval
1ab8ffaceb gtktextchild: Document new_with_replacement arg 2024-06-01 10:01:19 +02:00
Maximiliano Sandoval
3cc1726856 gtkstringlist: Document strings property 2024-06-01 10:01:19 +02:00
Maximiliano Sandoval
30eaa2c3cc gtk: Add missing return annotations 2024-06-01 10:01:19 +02:00
Maximiliano Sandoval
ba5993195a filedialog: Document get_accept_label 2024-06-01 10:01:19 +02:00
Maximiliano Sandoval
bf42351ebf cellrendererspinner: Fix active signal docs 2024-06-01 09:04:01 +02:00
Maximiliano Sandoval
ee277f4d92 gtksectionmodel: Fix typo in sections-changed link 2024-06-01 09:04:01 +02:00
Maximiliano Sandoval
00acc7957f gdkcursor: Fix typo in GdkCursorGetTestureCallback 2024-06-01 09:04:00 +02:00
Maximiliano Sandoval
a931335f24 gskglshader: Correct typo in source property 2024-06-01 09:04:00 +02:00
Maximiliano Sandoval
1ef320a9ec gsktransform: Document constructor 2024-06-01 09:04:00 +02:00
Maximiliano Sandoval
411b7f12b5 gtkicontheme: Fix typo in return annotation 2024-06-01 09:03:59 +02:00
Maximiliano Sandoval
611fcfb1c7 gtkgraphicsoffload: Fix typo in prop name 2024-06-01 09:03:59 +02:00
Maximiliano Sandoval
6257a51f4f gtkflowbox: Fix typos in annotations 2024-06-01 09:03:58 +02:00
Maximiliano Sandoval
e24630bd18 gtkenums: Correctly document AnnouncementPriority 2024-06-01 09:03:58 +02:00
Maximiliano Sandoval
6b0b3a4db7 gtkprintsettings: Delete extra whitespace 2024-06-01 09:03:58 +02:00
Maximiliano Sandoval
fd19c7c2ab gtkscrolledwindow: Fix typo in docstring 2024-06-01 09:03:57 +02:00
Maximiliano Sandoval
4aa2206699 gtktextview: Fix typo Textview in docstrings 2024-06-01 09:03:57 +02:00
Maximiliano Sandoval
eae23ebf69 gtkbuilderscope: Correct the argument values
These should match the function arguments.
2024-06-01 09:03:56 +02:00
Maximiliano Sandoval
ecd27f6c3c entry: Fix typos in tabs and show-emoji-icon 2024-06-01 09:03:56 +02:00
Maximiliano Sandoval
01f3c72338 sectionsmodel: Fix typo in docstring 2024-06-01 09:03:55 +02:00
Matthias Clasen
87be414c05 Merge branch 'color-fixes' into 'main'
Fix oklch conversion

See merge request GNOME/gtk!7324
2024-06-01 01:42:45 +00:00
Matthias Clasen
f6d676cc8a inspector: Use gdk_rgba_print when suitable 2024-05-31 21:39:32 -04:00
Matthias Clasen
4961241f26 gsk: Use gdk_rgba_print when suitable 2024-05-31 21:39:04 -04:00
Matthias Clasen
60c944bb94 Add tests for color conversion and interpolation
Add some tests for gtk_css_color_convert and
gtk_css_color_interpolate, mostly based on examples
in the spec.
2024-05-31 21:29:49 -04:00
Matthias Clasen
740c10282f Add gtk_css_color_print and gtk_css_color_to_string
These are useful for testing and debugging.
2024-05-31 21:29:49 -04:00
Matthias Clasen
3a4c69f370 gdk: Add gdk_rgba_print 2024-05-31 21:29:49 -04:00
Matthias Clasen
c3083572fb css: Small api fix
This should have been const.
2024-05-31 21:29:49 -04:00
Matthias Clasen
8ecb00be66 css: Export some color value api for tests
Export enough api to test color conversion and interpolation.
2024-05-31 21:29:49 -04:00
Matthias Clasen
48e707aceb css: Color interpolation fixes
Some minor gotchas and oversights.
2024-05-31 21:29:49 -04:00
Matthias Clasen
e2f9ff2304 Fix oklch conversion
The pseudo-code in the spec is broken.
2024-05-31 21:27:22 -04:00
Matthias Clasen
fa3a72c8f6 Fix oklch conversion
We want to normalize angles to be in [0, 360).
2024-05-31 21:25:54 -04:00
Matthias Clasen
fc45d90834 css: Fix oklab parsing 2024-05-31 19:33:56 -04:00
Matthias Clasen
fcd95cd5c6 css: Fix oklab conversion 2024-05-31 19:33:22 -04:00
Matthias Clasen
b8c1ac41d2 Merge branch 'css-color-missing-components' into 'main'
css: Add GtkCssColor

See merge request GNOME/gtk!7323
2024-05-31 21:05:24 +00:00
Matthias Clasen
90e1ce0906 Merge branch 'new-docstrings' into 'main'
Add missing docstrings

See merge request GNOME/gtk!7321
2024-05-31 19:57:53 +00:00
Matthias Clasen
d121fd5b7d css: Tweak compute for color values
Make color values carry their srgb equivalent and don't turn them
into literals at compute time. This is necessary so we can use their
original color space values in interpolation.

This makes color values a bit larger, but they still fit into one
cacheline.

We don't change handling of named colors and our color expressions.
They still get turned into literal colors.
2024-05-31 15:51:02 -04:00
Matthias Clasen
4d88fcc1db css: Use gtk_css_color_convert
Use gtk_css_color_convert for going to srgb and stop relying on
GdkRGBA for printing.
2024-05-31 15:51:02 -04:00
Matthias Clasen
85fcda178e css: Implement color interpolation
Implement gtk_css_color_convert, which is an attempt to implement
most of https://www.w3.org/TR/css-color-4/#interpolation for the
color spaces we support.
2024-05-31 15:51:02 -04:00
Matthias Clasen
ecc678454b css: Implement color conversion
Implement gtk_css_color_convert, which is an attempt to
implement https://www.w3.org/TR/css-color-4/#color-conversion
for the color spaces we support.

Missing:
- white point adaptation
- gamut mapping
2024-05-31 15:51:02 -04:00
Matthias Clasen
5a85bc691e css: Split off GtkCssColor
Break out a GtkCssColor struct.
2024-05-31 15:51:02 -04:00
Matthias Clasen
d506a5eea8 colorutils: Add some more utils
Add oklab<>srgb-linear and rgb<>hls conversions.
2024-05-31 15:51:02 -04:00
Matthias Clasen
aefa79413b css: Implement missing components in colors
Add support for parsing none for color components, and preserve
that information for serialization. We currently don't use it
for other things, but we should.
2024-05-31 15:51:02 -04:00
Matthias Clasen
73e4eb7552 css: gtk_css_color_value_new_literal static too
This function is only used inside gtkcsscolorvalue.c as well.
2024-05-31 15:50:43 -04:00
Matthias Clasen
dff340530a Merge branch 'matthiasc/for-main' into 'main'
css: Make some color value functions static

See merge request GNOME/gtk!7319
2024-05-31 16:40:33 +00:00
Matthias Clasen
f6ea3e1684 inspector: Make css deprecations opt-in
Add a button to show deprecation warnings (since those will
unfortunately be common for while, due to backwards compat).
2024-05-31 11:25:11 -04:00
Matthias Clasen
f790441505 colorutils: Add some more utils
Add oklab<>srgb-linear and hsl<>rgb conversions.
2024-05-31 10:13:35 -04:00
Matthias Clasen
0c307f7563 css: Make some color value functions static
These aren't used outside of gtkcsscolorvalue.c, so don't export
them.
2024-05-31 10:13:35 -04:00
Matthias Clasen
f89dc9644c Cosmetics 2024-05-31 10:12:28 -04:00
Matthias Clasen
735455b523 Merge branch 'memoryfix' into 'main'
Changes to fix the memorytexture regression

Closes #6260

See merge request GNOME/gtk!7111
2024-05-31 10:35:39 +00:00
Maximiliano Sandoval
d037cfaf44 Add docstrings for deprecated classes 2024-05-31 11:48:24 +02:00
Maximiliano Sandoval
293d63425a gtkiconview: Add missing docstrings 2024-05-31 11:48:24 +02:00
Maximiliano Sandoval
38f9bb87bc gtkentrycompletion: Document missing properties 2024-05-31 11:48:24 +02:00
Maximiliano Sandoval
64abadb370 gtkcolorchooserdialog: Document show-editor 2024-05-31 11:48:23 +02:00
Maximiliano Sandoval
6f85827fcb gtkfilechooserwidget: Document missing props 2024-05-31 11:48:23 +02:00
Maximiliano Sandoval
b0e321cfb8 gtkstylecontext: Document display property 2024-05-31 11:48:23 +02:00
Maximiliano Sandoval
46d0569365 gtktypes: Document GtkCssStyleChange
This is used in the css_changed virtual function of GtkWidget.
2024-05-31 11:48:19 +02:00
Maximiliano Sandoval
2eea911a0f gdktoplevel: Document TitlebarGesture 2024-05-31 11:47:30 +02:00
Maximiliano Sandoval
ee4a817121 gdk: docs: Document error quarks 2024-05-31 11:47:30 +02:00
Maximiliano Sandoval
3d1f914271 gskglrenderer: Document GL renderers 2024-05-31 11:47:30 +02:00
Maximiliano Sandoval
7bb0639a75 gskrendernode: Document serialization error quark 2024-05-31 11:47:29 +02:00
Maximiliano Sandoval
f8f38aab63 gskpathpoint: Document copy and free 2024-05-31 11:47:29 +02:00
Maximiliano Sandoval
75c2bd53aa gtkcsslocation: Document struct 2024-05-31 11:47:29 +02:00
Maximiliano Sandoval
83921750ae gtknotebook: Document signals 2024-05-31 11:47:29 +02:00
Maximiliano Sandoval
413512eba7 gtkheaderbar: Document title-widget property 2024-05-31 11:47:29 +02:00
Maximiliano Sandoval
e824764dc3 gtktexttag: Document properties 2024-05-31 11:47:28 +02:00
Maximiliano Sandoval
61b12abdab gtkshortcutssection: Document change-current-page 2024-05-31 11:47:28 +02:00
Maximiliano Sandoval
07bd5c7b05 gtkscale: Document FormatValueFunc 2024-05-31 11:47:28 +02:00
Maximiliano Sandoval
1dc20eda28 gtk: Document constants 2024-05-31 11:47:28 +02:00
Maximiliano Sandoval
5a9299f626 gtklistbox: Document signals
The docs of move-cursor is taken from FlowBox's.
2024-05-31 11:47:28 +02:00
Maximiliano Sandoval
9c86c67f06 gtkpadcontroller: Document properties 2024-05-31 11:47:27 +02:00
Maximiliano Sandoval
e6ca7668be gtkdebug: Document DEBUG_CHECK 2024-05-31 11:47:27 +02:00
Maximiliano Sandoval
0b540b9ad1 gtkactionable: Document properties 2024-05-31 11:47:25 +02:00
Maximiliano Sandoval
514cdf7398 gtk: Document PrintSettingsFunc 2024-05-31 10:22:44 +02:00
Maximiliano Sandoval
2ab52d73ab gtkprintsettings: Document constants
The docstring is taken form existing constants and their getters
docstring.
2024-05-31 10:22:38 +02:00
Maximiliano Sandoval
b3ae172c1e gtk: Document error quark functions 2024-05-31 10:22:23 +02:00
Maximiliano Sandoval
a6d1df66ec messagedialog: Document buttons property 2024-05-31 10:22:05 +02:00
gayathri.berli@ibm.com
ba92ce342e Merge branch 'main' into memoryfix 2024-05-30 18:21:06 +05:30
Matthias Clasen
9f4c715516 Merge branch 'css-color-minor' into 'main'
css: Simplify color values

See merge request GNOME/gtk!7316
2024-05-30 03:57:31 +00:00
Matthias Clasen
5aa47b6e45 Merge branch 'ebassi/doc-overview-link' into 'main'
docs: Fix link to the Pango reference

See merge request GNOME/gtk!7315
2024-05-30 03:45:13 +00:00
Matthias Clasen
3b40d95581 css: Fix currentcolor serialization
According to css specs, the serialization is supposed to be
all lowercase.
2024-05-29 21:45:10 -04:00
Matthias Clasen
3ad2d91e1c Cosmetics
Fix minor style issues in gtkcsscolorvalue.c.
2024-05-29 21:44:47 -04:00
Matthias Clasen
d4c586e882 css: Simplify color values
Drop the last_value. We don't do that for any other types of
values, so lets not do it here either.
2024-05-29 21:36:10 -04:00
Emmanuele Bassi
612c547ed3 docs: Fix link to the Pango reference
Reported at: https://discourse.gnome.org/t/broken-link-https-docs-gtk-org-gtk4-overview-html/21223
2024-05-30 02:10:48 +01:00
Matthias Clasen
1a777ce7f3 Merge branch 'online-man-pages' into 'main'
docs: Install man pages as html

See merge request GNOME/gtk!7314
2024-05-30 00:18:01 +00:00
Matthias Clasen
7ec4f6e297 Merge branch 'wip/xdg-dialog' into 'main'
gdk/wayland: Implement support for xdg-dialog Wayland protocol

See merge request GNOME/gtk!6837
2024-05-29 23:40:39 +00:00
Matthias Clasen
afaa0f3afd docs: Install man pages as html
This will let us link to them from the docs.
2024-05-29 19:30:09 -04:00
Matthias Clasen
8841a002ed Merge branch 'build-with-unicode' into 'main'
Windows: Build with UNICODE

See merge request GNOME/gtk!7230
2024-05-29 23:20:01 +00:00
Matthias Clasen
6da606aaad Merge branch 'issue-6401-legacy' into 'main'
Win32 GL: Also force not to use depth/stencil/accum bits on legacy contexts (for issue #6401)

See merge request GNOME/gtk!7176
2024-05-29 23:18:04 +00:00
Matthias Clasen
51bd155670 Merge branch 'css-error-fixes' into 'main'
css: Propagate errors properly

See merge request GNOME/gtk!7313
2024-05-29 23:13:14 +00:00
Matthias Clasen
8fa16ec1cc Merge branch '6332_fix_scale_highlight_clip' into 'main'
range: fix highlight clipping

Closes #6332

See merge request GNOME/gtk!7297
2024-05-29 21:03:11 +00:00
Matthias Clasen
04e5a0006d Merge branch '6332_fix_progressbar_highlight_clip' into 'main'
progressbar: fix highlight clipping

Closes #6332

See merge request GNOME/gtk!7312
2024-05-29 20:54:04 +00:00
Matthias Clasen
a1d2169992 Document GTK_DEBUG_CSS
This was overlooked in b603479fe2.
2024-05-29 15:47:40 -04:00
Matthias Clasen
778976f8da css: Propagate errors properly
We should not change the domain and code when we propagate errors
that happen while parsing variable references.

Pointed out in https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/7308.
2024-05-29 15:47:40 -04:00
g.willems
f81dea58a2 range: fix highlight clipping
Clipping on padding box prevents the scale highlight to fully paint itself
over the scale trough, including its border.
Use the border box instead.

Fixes #6332
2024-05-29 21:16:34 +02:00
g.willems
e82606a538 progressbar: fix highlight clipping
Clipping using OVERFLOW_HIDDEN relies on widget's padding box.
This prevents the highlight to paint itself over the trough's borders.

Use the border box instead, with a custom snapshot implementation.

Fixes #6332
2024-05-29 21:14:32 +02:00
Matthias Clasen
fe5b28f5b8 Merge branch 'bilelmoussaoui/add-since-annotations' into 'main'
gtk: Add missing docs blob to CssSection

See merge request GNOME/gtk!7296
2024-05-29 19:09:07 +00:00
Matthias Clasen
82fd0d7eef Merge branch 'matthiasc/for-main' into 'main'
css: Fix serialization of oklab() etc

Closes #6748, #6732, and #6735

See merge request GNOME/gtk!7310
2024-05-29 17:08:38 +00:00
Matthias Clasen
16761fcb49 Merge branch 'wip/alice/color-func' into 'main'
csscolorvalue: Add color() support

See merge request GNOME/gtk!7286
2024-05-29 17:02:13 +00:00
Matthias Clasen
4fac5680fb Merge branch 'css-error-docs' into 'main'
css: Clarify docs for GtkCssProvider::parser-error

See merge request GNOME/gtk!7309
2024-05-29 16:41:55 +00:00
Matthias Clasen
4ec4280e51 css: Clarify docs for GtkCssProvider::parser-error
Some of these errors should not be fatal.

Related: #6736
2024-05-29 12:35:14 -04:00
Matthias Clasen
15bb77472d css: Add some parser tests for oklab() etc 2024-05-29 12:05:28 -04:00
Matthias Clasen
5c92d5e081 css: Fix serialization of oklab() etc
The spec requires that oklab() and oklch() are serialized as these
functions, while hwb() is serialized as rgb().

Fixes: #6748
2024-05-29 12:04:20 -04:00
Emmanuele Bassi
1626c5f1e7 css: Create a section if the variable does not have one
In case a variable definition does not have a CSS section associated to
it, we fall back to the previous behaviour of creating a CSS section
with the bounds of the error.

See: https://gitlab.gnome.org/GNOME/gnome-build-meta/-/issues/841
2024-05-29 12:04:20 -04:00
Michael Weghorn
3b5f0ed05e a11y: Use text instead of label for GtkLabel's a11y name
Update the `GTK_ACCESSIBLE_PROPERTY_LABEL` property
in `gtk_label_set_text_internal` using the new text
instead of using the label in
`gtk_label_set_label_internal`.

While the `label` "includes any embedded underlines
indicating mnemonics and Pango markup" [1], the
`text` is the "text is as it appears on screen" [2],
which is more suitable for the accessible name.

With this in place, the text is reported as the
accessible name again after

    commit d5b34aecdd
    Date:   Wed Jan 17 12:49:38 2024 +0100

        a11y: Remove special handling of accessible names for static text widgets

[1] https://docs.gtk.org/gtk4/method.Label.get_label.html
[2] https://docs.gtk.org/gtk4/method.Label.get_text.html

Fixes: #6732
Fixes: #6735
2024-05-29 12:04:20 -04:00
Chun-wei Fan
d2298f1c8f gskvulkandevice.c: Put Vk[Pipeline|RenderPass] in structures
This way, we can simply duplicate the keys as separate pointers to store
the corresponding Vulkan handles so that we can safely hash them, as
Vulkan handles may or may not be pointers depending on the target
platform.

This will fix builds on 32-bit Windows at least.
2024-05-29 12:04:20 -04:00
Chun-wei Fan
085062ab89 gdkvulkancontext.c: Use pointers to hash VkShaderModule
VkShaderModule's may or may not be pointers depending on the target
platform, so use pointers to hash those handles to be safe, and retrieve
them from hashes accordingly.

Fixes build on 32-bit Windows at least.
2024-05-29 12:04:20 -04:00
Chun-wei Fan
9741082467 gskvulkanmemory.c: Use VK_NULL_HANDLE for VkDeviceMemory
...rather than NULL, so that things will build fine on non-LLP, non-64-bit
systems.
2024-05-29 12:04:20 -04:00
Benjamin Otte
3db4a05493 testsuite: Shrink maximum texture size in test
1MB textures can lead to 20s runtimes - which with asan CI being a lot
slower can be a loooong time and cause timeouts.

Limiting them to 16kB still allows hitting max texture size sometimes
but makes sure the test only runs for 3-4s worst case.
I hope that doesn't trigger timeouts even under asan.
2024-05-29 12:04:20 -04:00
Georges Basile Stavracas Neto
e3b9df2cec filechooserwidget: Plug a bunch of GtkBitset leaks
gtk_selection_model_get_selection() is transfer full, and the returned
bitset must be freed by the caller. GtkFileChooserWidget freed none of
them.

Unref the bitsets.

Related: https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/issues/91
2024-05-29 12:04:20 -04:00
Yosef Or Boczko
4a4e445a35 Update Hebrew translation 2024-05-29 12:04:20 -04:00
Chun-wei Fan
db0f9b60ac gsk: Call glDeleteSync() directly
This function does not use the standard __cdecl calling convention on
Windows, meaning using g_clear_pointer() on it directly will cause
crashes on 32-bit Windows.  Just call it directly if the GLsync it uses
exists.
2024-05-29 12:04:20 -04:00
Alice Mikhaylenko
d51de390ba csscolorvalue: Add color() support
Currently we only have sRGB, so it's a bit redundant, but we'll need this
for color-mix()

Once we have more color spaces, they should be added here (presumably the
enum would be in GDK instead, and instead of GdkRGBA these colors would
have a GdkColor.
2024-05-29 19:28:31 +04:00
Matthias Clasen
c14e167a11 Merge branch 'ebassi/css-section-warning' into 'main'
css: Create a section if the variable does not have one

See merge request GNOME/gtk!7306
2024-05-29 14:01:55 +00:00
Emmanuele Bassi
2837a85461 Merge branch 'michaelweghorn/a11y_label_name' into 'main'
a11y: Update label's accessible name on text update

Closes #6732 and #6735

See merge request GNOME/gtk!7293
2024-05-29 12:35:40 +00:00
Benjamin Otte
282510e113 Merge branch 'vulkan-windows-32' into 'main'
Vulkan: Fix build on 32-bit Windows (and likely other non-64-bit LLP platforms)

See merge request GNOME/gtk!7299
2024-05-29 10:34:42 +00:00
Emmanuele Bassi
accabe3eee css: Create a section if the variable does not have one
In case a variable definition does not have a CSS section associated to
it, we fall back to the previous behaviour of creating a CSS section
with the bounds of the error.

See: https://gitlab.gnome.org/GNOME/gnome-build-meta/-/issues/841
2024-05-29 11:29:13 +01:00
Chun-wei Fan
9dbdbaca43 gskvulkandevice.c: Put Vk[Pipeline|RenderPass] in structures
This way, we can simply duplicate the keys as separate pointers to store
the corresponding Vulkan handles so that we can safely hash them, as
Vulkan handles may or may not be pointers depending on the target
platform.

This will fix builds on 32-bit Windows at least.
2024-05-29 18:16:22 +08:00
Chun-wei Fan
5935bc95b7 gdkvulkancontext.c: Use pointers to hash VkShaderModule
VkShaderModule's may or may not be pointers depending on the target
platform, so use pointers to hash those handles to be safe, and retrieve
them from hashes accordingly.

Fixes build on 32-bit Windows at least.
2024-05-29 18:03:13 +08:00
Chun-wei Fan
4c677e4dcd gskvulkanmemory.c: Use VK_NULL_HANDLE for VkDeviceMemory
...rather than NULL, so that things will build fine on non-LLP, non-64-bit
systems.
2024-05-29 12:57:07 +08:00
Benjamin Otte
d4c25c9ec0 Merge branch 'wip/otte/for-main' into 'main'
testsuite: Shrink maximum texture size in test

See merge request GNOME/gtk!7303
2024-05-28 15:31:08 +00:00
Benjamin Otte
b69df2bc4d testsuite: Shrink maximum texture size in test
1MB textures can lead to 20s runtimes - which with asan CI being a lot
slower can be a loooong time and cause timeouts.

Limiting them to 16kB still allows hitting max texture size sometimes
but makes sure the test only runs for 3-4s worst case.
I hope that doesn't trigger timeouts even under asan.
2024-05-28 16:51:03 +02:00
Luca Bacci
7f9363d471 Windows: Build with UNICODE
Build with UNICODE (and _UNICODE) defined when targeting Windows.
2024-05-28 16:37:48 +02:00
Emmanuele Bassi
01d86eab66 Merge branch 'gbsneto/bitset-filechooser-leaks' into 'main'
filechooserwidget: Plug a bunch of GtkBitset leaks

See merge request GNOME/gtk!7302
2024-05-28 13:16:39 +00:00
Yosef Or Boczko
09e85aa809 Update Hebrew translation 2024-05-28 08:54:43 +00:00
Georges Basile Stavracas Neto
d49816d2e6 filechooserwidget: Plug a bunch of GtkBitset leaks
gtk_selection_model_get_selection() is transfer full, and the returned
bitset must be freed by the caller. GtkFileChooserWidget freed none of
them.

Unref the bitsets.

Related: https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/issues/91
2024-05-28 10:24:27 +02:00
Benjamin Otte
59a00d6768 Merge branch 'ngl-windows-32' into 'main'
Fix using the NGL renderer on 32-bit Windows

See merge request GNOME/gtk!7294
2024-05-28 04:39:43 +00:00
Alice Mikhaylenko
6bd6c6acba colorutils: Add linear srgb conversion functions 2024-05-27 15:50:50 +04:00
Chun-wei Fan
be2ff60787 gsk: Call glDeleteSync() directly
This function does not use the standard __cdecl calling convention on
Windows, meaning using g_clear_pointer() on it directly will cause
crashes on 32-bit Windows.  Just call it directly if the GLsync it uses
exists.
2024-05-25 11:07:37 +08:00
Bilal Elmoussaoui
070b9a87b6 gtk: Add missing docs blob to CssSection
For the missing Since annotations mostly.
2024-05-24 12:05:51 +02:00
Emmanuele Bassi
ecbe6a421e Merge branch 'bilelmoussaoui/no-async-finish-docs' into 'main'
docs: Drop _finish blobs

See merge request GNOME/gtk!7295
2024-05-24 05:14:56 +00:00
Michael Weghorn
317e68a58c a11y: Use text instead of label for GtkLabel's a11y name
Update the `GTK_ACCESSIBLE_PROPERTY_LABEL` property
in `gtk_label_set_text_internal` using the new text
instead of using the label in
`gtk_label_set_label_internal`.

While the `label` "includes any embedded underlines
indicating mnemonics and Pango markup" [1], the
`text` is the "text is as it appears on screen" [2],
which is more suitable for the accessible name.

With this in place, the text is reported as the
accessible name again after

    commit d5b34aecdd
    Date:   Wed Jan 17 12:49:38 2024 +0100

        a11y: Remove special handling of accessible names for static text widgets

[1] https://docs.gtk.org/gtk4/method.Label.get_label.html
[2] https://docs.gtk.org/gtk4/method.Label.get_text.html

Fixes: #6732
Fixes: #6735
2024-05-24 05:48:22 +02:00
Bilal Elmoussaoui
9b42377347 docs: Drop _finish blobs
As they are generated by gi-docgen thanks to the newly added async annotations.
It allows bindings that don't expose the _finish
functions to propose less-confusing docs
2024-05-23 20:39:50 +02:00
Andre Klapper
7372a845fb Correct GNOME HIG 404 URI 2024-05-23 16:31:20 +02:00
Carlos Garnacho
cf8c3be030 gdk/wayland: Implement support for xdg-dialog Wayland protocol
This protocol lifts some functionality from the gtk-shell protocol,
namely the ability to tag dialogs as modal. Ensure to use this
new protocol if available for the task, instead of the gtk-shell
protocol.
2024-05-23 12:40:39 +02:00
Carlos Garnacho
4eb715cf81 build: Support in-tree copies of wayland protocols
Make the info about the required protocols an array of definitions
again (a dict instead of an array this time) and add a field that
may be used for version checks of the wayland-protocols found.

Also, make it possible to have versioned protocols in-tree. Both
of these things will allow us to ship in-tree copies of wayland-protocols
without necessarily having to bump the version we depend on.
2024-05-23 12:40:19 +02:00
Luca Bacci
d4899fdf1f Merge branch 'gdk4_win32_fix_dnd_move_cursor' into 'main'
gdk4-win32: Guarantee dnd-move as a cursor name

See merge request GNOME/gtk!7289
2024-05-23 10:16:30 +00:00
Emmanuele Bassi
4142c4d79e Merge branch 'mcatanzaro/#6734' into 'main'
text: fix critical in paste_received

Closes #6734

See merge request GNOME/gtk!7290
2024-05-22 23:17:15 +00:00
Matthias Clasen
ca442f8641 Merge branch 'css-color-spaces' into 'main'
gdk: Add support for some color conversions

See merge request GNOME/gtk!7285
2024-05-22 22:32:52 +00:00
Benjamin Otte
3c1491423a Merge branch 'wip/otte/for-main' into 'main'
gsk: use the correct memory type index

See merge request GNOME/gtk!7287
2024-05-22 21:47:44 +00:00
Michael Catanzaro
eb4993d3fb text: fix critical in paste_received
Here we calculate the length only in the truncate_multiline condition.
Then we pass pos - 1 to gtk_accessible_text_update_contents() as the end
position, triggering this critical that checks to ensure start <= end.
Fix it by always calculating the length of the string that we insert.

This is the first bug fixed as a result of enabling fatal criticals by
default in Epiphany! 🎉

Fixes #6734
2024-05-22 16:06:09 -05:00
g.willems
aa057da1ca win32: Guarantee dnd-move as a cursor name
gdk currently falls back to the default cursor, which may not be
approriate for rendering a DnD move.
2024-05-22 20:55:21 +02:00
Matthias Clasen
1de09d59fb css: Support some color spaces
Support the hwb(), oklab() and oklch() functions for specifying
colors in these color spaces.

See https://bottosson.github.io/posts/oklab/ and
https://www.w3.org/TR/css-color-4/.

Some tests included.
2024-05-22 14:31:56 -04:00
Alejandro Piñeiro
130a6fe0cf gsk: use the correct memory type index
https://gitlab.gnome.org/GNOME/gtk/-/issues/6726
2024-05-22 19:43:03 +02:00
Matthias Clasen
e1f7c027d7 Merge branch 'css-color-docs' into 'main'
css: Update docs slightly

See merge request GNOME/gtk!7281
2024-05-22 17:25:47 +00:00
Arjan Molenaar
396ef5ebe5 Merge branch 'macos-popup-shadows' into 'main'
macos: Take shadows into account when positioning popups

See merge request GNOME/gtk!7266
2024-05-22 13:15:34 +00:00
Emmanuele Bassi
840a20db3b Merge branch 'macos-surface-critical' into 'main'
gdkmacossurface: Set surface before accessing it

See merge request GNOME/gtk!7267
2024-05-22 09:10:35 +00:00
Matthias Clasen
8c6f7d1ae9 Merge branch 'matthiasc/for-main' into 'main'
4.15.1

See merge request GNOME/gtk!7283
2024-05-22 00:00:21 +00:00
Matthias Clasen
c69fa6221b Post-release version bump 2024-05-21 19:54:53 -04:00
Matthias Clasen
3c92c81705 4.15.1 2024-05-21 19:52:12 -04:00
Matthias Clasen
297de981c4 css: Update docs slightly
Add more details about units and calc(), mention new color
syntax and deprecations.
2024-05-21 17:11:30 -04:00
Matthias Clasen
53beb054b6 Merge branch 'wip/alice/colors' into 'main'
csscolorvalue: Actually discard invalid rgb() colors

See merge request GNOME/gtk!7282
2024-05-21 19:31:31 +00:00
Matthias Clasen
0431492284 Merge branch 'wip/alice/spinner' into 'main'
spinner: Only set :checked state when mapped

See merge request GNOME/gtk!7280
2024-05-21 18:54:17 +00:00
Alice Mikhaylenko
aed9cc1874 csscolorvalue: Actually discard invalid rgb() colors 2024-05-21 22:25:20 +04:00
Alice Mikhaylenko
c15804d124 spinner: Only set :checked state when mapped
Avoid doing the animation while it's invisible.

See https://gitlab.gnome.org/GNOME/gtk/-/issues/1025
2024-05-21 19:33:52 +04:00
Matthias Clasen
1bd208d937 Merge branch 'wip/alice/colors' into 'main'
Add modern rgb() and hsl() syntax

See merge request GNOME/gtk!7278
2024-05-21 14:50:08 +00:00
Alice Mikhaylenko
b70bcd6bfe csscolorvalue: Add modern rgb() and hsl() syntax
Make calc() work in colors too, since we need to support degrees for hsl()
hue anyway and it goes through the same machinery. Make that work for
legacy syntax too, matching the spec.

Ignore missing components/none for now.

Ignore gdk_rgba_parser_parse(), that's also used outside css.
2024-05-21 16:32:52 +04:00
Alice Mikhaylenko
74a1d45238 cssnumbervalue: Add get_canonical()
We'll need it to get angle values in degrees for color parsing.
2024-05-21 16:31:26 +04:00
Alice Mikhaylenko
3ada35460d doc: Mention the rad unit
It was missing.
2024-05-21 16:31:26 +04:00
Matthias Clasen
1f133c3d64 Merge branch 'css-color-deprecations' into 'main'
Add gtk_css_parser_warn_deprecated

See merge request GNOME/gtk!7270
2024-05-21 10:57:12 +00:00
Matthias Clasen
4440ce874e Merge branch 'nieldsg/font-filter' into 'main'
gtk: Introduce private GtkFontFilter helper

See merge request GNOME/gtk!7262
2024-05-21 01:22:38 +00:00
Matthias Clasen
db302df82a Merge branch 'fix-a-css-crash' into 'main'
Fix an oversight

See merge request GNOME/gtk!7276
2024-05-21 00:58:02 +00:00
Matthias Clasen
b550b58e8f Merge branch 'css-var-speedup' into 'main'
css: Speed up checking for var()

See merge request GNOME/gtk!7274
2024-05-21 00:57:47 +00:00
Matthias Clasen
ed889b951b css: Deprecate named colors
Warn for uses of @name colors, since these should be replaced with
CSS variables and custom properties. We don't issue deprecation
warnings for @define-color uses, since we may want to keep these
around in theme CSS for a while, for backwards compatibility.

Update all affected tests.
2024-05-20 16:19:30 -04:00
Matthias Clasen
b603479fe2 Add a debug flag for CSS deprecations
It seems better not to spam everybody with this all the time.
2024-05-20 16:02:38 -04:00
Matthias Clasen
7c39b2cea3 Add gtk_css_parser_warn_deprecated
This will come in handy when we start deprecating our homegrown
CSS extensions.
2024-05-20 16:02:38 -04:00
Matthias Clasen
b1bce7a62b Fix an oversight
GtkCssVariableValues are not GtkCssValues. Oops.
2024-05-20 16:02:38 -04:00
Matthias Clasen
fa73e17fba Fix an oversight
GtkCssVariableValues are not GtkCssValues. Oops.
2024-05-20 15:56:40 -04:00
Matthias Clasen
dee2150a04 css: Speed up checking for var()
gtk_css_parser_has_references is meant to be a quick check for
whether a property value contains a variable reference, it just
returns a boolean and doesn't need to report any errors, so lets
not parse the property value any more than we need to.
2024-05-20 13:56:52 -04:00
Matthias Clasen
f647fc3fe2 Merge branch 'css-animation-optimization' into 'main'
css: Avoid more recomputation during animation

See merge request GNOME/gtk!7273
2024-05-20 17:06:10 +00:00
Matthias Clasen
6bae80c331 css: Avoid more recomputation during animation
Don't trigger recomputation if the values didn't change. We only
do this for custom values, since those are animated with a flip
at 50%, so it is likely that we see no-change updates.
2024-05-20 11:59:46 -04:00
Matthias Clasen
2aeb80f490 Merge branch 'ccs-math' into 'main'
css: Implement math functions

See merge request GNOME/gtk!7249
2024-05-20 14:40:48 +00:00
Matthias Clasen
8a2f434443 Merge branch 'css-animation-optimization' into 'main'
css: Less recomputation in animation

See merge request GNOME/gtk!7263
2024-05-20 14:26:18 +00:00
Matthias Clasen
d4134430fc Merge branch 'matthiasc/for-main' into 'main'
css: Avoid a possible memory leak

See merge request GNOME/gtk!7272
2024-05-20 13:49:53 +00:00
Matthias Clasen
73f64971c8 css: Avoid a possible memory leak
Currently, style->variables is always NULL when we get here, but
better to be safe than sorry, and clear the fields before we
overwrite it.
2024-05-20 08:57:28 -04:00
Matthias Clasen
ecc2c953e5 css: Avoid more recomputation
Pass a reason into gtk_css_animated_style_recompute, and avoid
recomputing properties that aren't affected. The possible reasons
for now are that variables of color changes. Better tracking
for currentColor in properties will allow us to improve this
later.
2024-05-20 08:48:20 -04:00
Matthias Clasen
e353117937 css: Make animation recomputation more efficient
Use the same shorthand-keeping trick we do when computing
static styles.
2024-05-20 08:27:47 -04:00
Matthias Clasen
492ae6df35 css: Less recomputation in animation
Only recompute the animated style once all the custom variables
have been updated.
2024-05-20 08:27:47 -04:00
Matthias Clasen
a19d0471e9 Merge branch 'css-var-syntax-errors' into 'main'
css: Report some var() syntax errors

See merge request GNOME/gtk!7264
2024-05-20 12:21:18 +00:00
Matthias Clasen
5b5ba36999 Merge branch 'matthiasc/for-main' into 'main'
css: Add some more variables tests

See merge request GNOME/gtk!7268
2024-05-20 10:21:21 +00:00
Balázs Úr
89b64cbf47 Update Hungarian translation 2024-05-19 23:47:50 +00:00
Matthias Clasen
e65d1f2122 Cosmetics 2024-05-19 18:57:24 -04:00
Matthias Clasen
2756496d47 css: Cosmetics
Don't set the same field twice.
2024-05-19 18:04:20 -04:00
Matthias Clasen
8b653f21cc Drop more underscores
Drop the remaining _'s from css number value apis.
2024-05-19 17:27:37 -04:00
Matthias Clasen
4e6759a126 css: Implement math functions
Implement the functions described in the "Mathematical
Expressions" section of the "CSS Values and Units Module
Level 4" spec, https://www.w3.org/TR/css-values-4/.

Beyond calc(), which we already had, this includes
min(), max(), clamp(),
round(), rem(), mod(),
sin(), cos(), tan(), asin(), acos(), atan(), atan2(),
pow(), sqrt(), hypot(), log(), exp(),
abs(), sign(),
e, pi, infinity and NaN.

Some tests included.
2024-05-19 17:27:37 -04:00
Matthias Clasen
d20e0b0370 Merge branch 'gtk-4-macos-dock-quit' into 'main'
[GTK 4] macOS: Dock "Quit" invokes "app.quit" action

See merge request GNOME/gtk!7265
2024-05-19 21:06:11 +00:00
Mat
ed8255993f gdkmacossurface: Set surface before accessing it
Silences the following critial:
_gdk_macos_surface_update_fullscreen_state: assertion
'GDK_IS_MACOS_SURFACE (self)' failed
2024-05-19 23:58:35 +03:00
Matthias Clasen
f5d69fa0c5 css: Add some more variables tests
Add a test mixing color expressions with variables, and
empty fallback values.
2024-05-19 16:39:02 -04:00
Mat
e1431f31c1 macos: Take shadows into account when positioning popups
Otherwise popups will be misaligned. This becomes noticeable when larger
shadows are used, like in libadwaita.

Regression in 08216dcee9
2024-05-19 23:35:18 +03:00
Thomas Holder
f191fc0047 macOS: Dock "Quit" invokes "app.quit" action
Allows the application to handle "Dock icon > Quit" the same as
"Application menu > Quit".

Requires GtkApplication's `register-session` property.

Suitable replacement for gtk-mac-integration's
`NSApplicationBlockTermination` signal.
2024-05-19 23:10:31 +03:00
Matthias Clasen
b60c60f03b css: Report some var() syntax errors
Detect cases such as var(), var(-), var("a") or var(21) early
and report them as syntax errors.

Test included.

Related: #6715
2024-05-19 15:56:26 -04:00
Matthias Clasen
af0c277bba Merge branch 'matthiasc/for-main' into 'main'
css: Lose more underscores

See merge request GNOME/gtk!7261
2024-05-19 05:14:05 +00:00
Niels De Graef
88203fbf4d gtk: Introduce private GtkFontFilter helper
Extract the "user filter" code from the `GtkFontChooserWidget`, for a
couple of reasons:

* If we want to expand the filter in the future (e.g. to filter on
  variable fonts, or check for multiple languages), we have a nice place
  to put this.
* It simplifies the font chooser widget a tiny bit, as it's a pretty big
  file which can be hard to follow.
* With a custom `GtkFilter` subclass, we can actually avoid doing a bit
  of work when initially showing the widget, as we can return
  `GTK_FILTER_MATCH_ALL` when nothing is selected yet (which is not
  possible with a `GtkCustomFilter'). It's not much, but it's still nice
2024-05-18 15:34:13 +02:00
Matthias Clasen
970c9eef63 css: Use an anonymous union for color values
We already do this for number values, and it looks less messy.
2024-05-18 09:23:40 -04:00
Matthias Clasen
2439876bd3 css: Simplify color resolving a bit
We know the initial value of the color property, no need to
resolve it again.
2024-05-18 09:09:21 -04:00
Matthias Clasen
97582ae9ad css: Simplify color resolving
The cycle argument is purely a detail of the internal implementation,
no need to have it in the api.
2024-05-18 09:03:57 -04:00
Matthias Clasen
a5b85f0dc5 css: Lose more underscores
Drop the _ from the color value apis. Update all callers.
2024-05-18 08:59:24 -04:00
Matthias Clasen
aefb16510b Merge branch 'css-fiddling' into 'main'
css: Lose some underscores

See merge request GNOME/gtk!7255
2024-05-16 01:49:52 +00:00
Benjamin Otte
4360d433b5 Merge branch 'wip/otte/for-main' into 'main'
columnview: Actually check the listview in return_if_fail()

See merge request GNOME/gtk!7254
2024-05-16 01:30:20 +00:00
Matthias Clasen
5927319589 css: Inline a few functions
These are just operating on the value base and can easily be inlined.
2024-05-15 20:54:45 -04:00
Matthias Clasen
25db645f65 css: Lose some underscores
Drop the _ from all the gtk_css_value apis.
2024-05-15 20:54:43 -04:00
Benjamin Otte
b3c6a98132 vulkan: Add a missing extension
We need to enable this one, too.

Thanks validation layers!
2024-05-16 02:24:17 +02:00
Benjamin Otte
031109aec3 columnview: Actually check the listview in return_if_fail()
This was missed when adding return_if_fail()s in
172cdf8e21.

Related: !7240
2024-05-16 02:24:17 +02:00
Jordi Mas i Hernandez
18d2f9c8a4 Update Catalan translation
(cherry picked from commit 27d75be15e)
2024-05-15 19:53:58 +00:00
Jordi Mas i Hernandez
0ae721f144 Update Catalan translation
(cherry picked from commit 8ccc36c389)
2024-05-15 18:02:53 +00:00
Matthias Clasen
7898d1b46d Merge branch 'wip/sophie-h/print' into 'main'
printdialog: Fix some annotiations

Closes #6709

See merge request GNOME/gtk!7251
2024-05-14 20:51:54 +00:00
Sophie Herold
3648398f6d printsetup: Remove nullable from settings getters
GtkPrintSetup is initialized with the values returned from the portal.
Therefore the page setup and the print settings can never be NULL.
2024-05-14 22:21:19 +02:00
Sophie Herold
019916c5b9 printdialog: Remove nullable for GError functions
Functions that set a GError should not be marked as nullable if they
only return NULL on error.
2024-05-14 22:12:04 +02:00
Sophie Herold
ebb31590ae printdialog: Add missing nullable to getters
The initial values are NULL.
2024-05-14 22:10:29 +02:00
Benjamin Otte
32ea1cf32d Merge branch 'wip/kabus/scroll_to_null_tile' into 'main'
listbase: Fix a null dereference

See merge request GNOME/gtk!7240
2024-05-14 19:48:42 +00:00
Khalid Abu Shawarib
172cdf8e21 listbase: Return early on non-existent scroll position 2024-05-14 15:27:38 +03:00
Matthias Clasen
dc07bcf3a3 Merge branch 'michaelweghorn/a11y_atspi_map_level_property' into 'main'
a11y atspi: Map GTK_ACCESSIBLE_PROPERTY_LEVEL to AT-SPI attr

See merge request GNOME/gtk!6549
2024-05-13 16:02:53 +00:00
Matthias Clasen
bd96c10563 Merge branch 'matthiasc/for-main' into 'main'
testsuite: Improve test-css-parser

See merge request GNOME/gtk!7248
2024-05-13 14:57:15 +00:00
Matthias Clasen
76299396cf testsuite: Improve test-css-parser
Make it so that --generate parse produces output that can be
directly pasted into the ref.css file.
2024-05-13 10:04:28 -04:00
Ekaterine Papava
a96dd2ad0a Update Georgian translation 2024-05-13 00:45:14 +00:00
Matthias Clasen
1e210e83bb Merge branch 'structcleanup' into 'main'
gdk: Remove unused struct 'XPointerUngrabInfo'

See merge request GNOME/gtk!7245
2024-05-12 04:52:19 +00:00
Dr. David Alan Gilbert
14f1a91bff gdk: Remove unused struct 'XPointerUngrabInfo'
'XPointerUngrabInfo' appears unused since
commit 26cbf87d7d ("New approach for grab tracking code")
Remove it.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
2024-05-12 01:06:31 +01:00
Matthias Clasen
3f2bcdf82e Merge branch 'matthiasc/for-main' into 'main'
wayland: Tweak cursor sizing code

See merge request GNOME/gtk!7244
2024-05-11 03:40:53 +00:00
Matthias Clasen
c61d8bc188 wayland: Tweak cursor sizing code
We want to take advantage of a viewporter also for named cursors.
2024-05-10 23:10:50 -04:00
Matthias Clasen
4e5976427b NEWS: Updates 2024-05-10 21:47:44 -04:00
Matthias Clasen
7fcdb0205f Merge branch 'wip/alice/css-variables' into 'main'
CSS custom properties/variables

See merge request GNOME/gtk!6540
2024-05-11 01:38:10 +00:00
Benjamin Otte
4814c5f653 array: Don't overflow array size
Copy what gcc's libstdc++ does for vectors to avoid overflows:

1. Define a max size macro and assert against it
   Note that we don't assert but actually check, because this needs
   to abort even if assertions are disabled.
2. Don't do fancy math to compute new capacity.
   Just size *= 2 instead and be careful about overflow.
2024-05-10 21:22:03 -04:00
Alice Mikhaylenko
eb24e3548f inspector: Sort GTK CSS properties between standard and custom ones 2024-05-10 18:29:48 +04:00
Alice Mikhaylenko
87f0f374a9 inspector: Show custom properties for css nodes 2024-05-10 18:29:48 +04:00
Alice Mikhaylenko
0cd95951e6 testsuite: Add css variables tests 2024-05-10 18:29:48 +04:00
Matthias Clasen
c45815c217 css: Improve error reporting for variables
Emit errors for all the variables that were being expanded
if an error occurs while parsing a property value at compute time.

Include the variables that are being expanded in the error message.
2024-05-10 18:29:48 +04:00
Matthias Clasen
b914869715 css parser: Keep variables for tokenizers
Add a function that gets the names of the variables that the
parser is currently in the process of expanding. This will
be used for error reporting.
2024-05-10 18:29:48 +04:00
Matthias Clasen
ff5699e097 css parser: Inline the tokenizer array
This is in preparation of associating more data with the token streams.
2024-05-10 18:29:47 +04:00
Matthias Clasen
8846f85874 css provider: Set bytes on sections
Pass the bytes we're parsing to the sections, and keep a pointer
to them around, so we can compare them in the has_section
implementation.

This commit also corrects some of the location information that
we add into the section for variables to be more accurate.
2024-05-10 18:29:47 +04:00
Matthias Clasen
fc1c6cfb1a css parser: Add gtk_css_parser_get_bytes
Gets the bytes that the parser is operating on.
2024-05-10 18:29:47 +04:00
Matthias Clasen
77028362ab css provider: Set sections on all variable values
We were doing it in one case, but forgetting it in another.
These sections are necessary to report meaningful error locations
when parsing property values at compute time.
2024-05-10 18:29:47 +04:00
Matthias Clasen
496aee5b02 style cascade: Propagate errors
When we compute values, the provider we use ends up being the
style cascade. If we hit a parser error when parsing variable-bearing
property values at compute time, we emit the error on that provider.

By making the cascade propagate the error back to the proper css
provider that contains the section in question, we get it reported
back to the css editor in the inspector.
2024-05-10 18:29:47 +04:00
Matthias Clasen
b2fb624496 style provider: Add a has_section api
Add gtk_style_provider_has_section and implement it for
GtkCssProvider. This will be used later to direct error
emissions to the right provider.
2024-05-10 18:29:47 +04:00
Matthias Clasen
f2ef5d85ea css parser: Add bytes to sections
We will use this later to link sections back to the providers
they come from.
2024-05-10 18:29:47 +04:00
Matthias Clasen
7eca32edf0 css parser: Add gtk_css_parser_skip_whitespace
Does what it says.
2024-05-10 18:29:47 +04:00
Matthias Clasen
7775bcf2fb css: Don't accept junk
Check that there is no junk at the end of the property value
when parsing variable-bearing properties at compute time.
2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
ed35f6f8b8 css: Condense compute parameters into GtkCssComputeContext
That list is getting out of hand, let's make it a struct.
2024-05-10 18:29:47 +04:00
Matthias Clasen
307942e1f7 css: Only compute shorthand values once
When computing a style, only compute the shorthand value once.
2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
92b7231168 csskeyframes: Support variables 2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
14d7eb97d2 cssanimation: Recompute values while playing
This will be necessary for supporting variables in animations.

For this we need to pass all the gtk_css_value_compute() parameters into
GtkCssAnimatedStyle: parent style and provider.
2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
fed1c3d3fc cssstaticstyle: Split property lists into a separate header
We'll need to use them in GtkCssAnimatedStyle too.
2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
e1ac97a185 cssvalue: Pass an extra GtkCssVariableSet to compute()
We'll need this to support variables in @keyframes, since styles will
need to combine their own variables and the ones from the keyframes.

See the next commit, this one is split out to avoid a huge diff.
2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
08a48dd97e Implement basic support for CSS variables 2024-05-10 18:29:47 +04:00
Matthias Clasen
50df3ebb46 css: Give shorthand properties an ID
This will be used in future commits.
2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
df77f22740 cssvalue: Add contains_variables()
We'll need this to know which values to recompute for animations.

It will be used in the next commit, it's separate to avoid the diff
being too large.
2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
2437a551ec csstokenizer: Add save() and restore()
We'll need that to check if property values contain variables.
2024-05-10 18:29:47 +04:00
Alice Mikhaylenko
46ab71fc8a cssprovider: Copy bytes when loading
We'll need to keep accessing them later to compute values with variables,
so we can't avoid this anymore.
2024-05-10 18:29:47 +04:00
Matthias Clasen
f922ff8597 Merge branch 'speed-up-cairo-icons' into 'main'
gsk: Speed up mask nodes with cairo

Closes #6700

See merge request GNOME/gtk!7243
2024-05-10 14:10:18 +00:00
Matthias Clasen
690c06109e gsk: Speed up mask nodes with cairo
Switch symbolc icon drawing from color-matrix to mask nodes
make the performance of the iconscroll demo crater (from 60fps
to 10fps).

Apply the same optimization we already have for color-matrix
nodes when drawing mask nodes. This gets us back to 60fps.

Fixes: #6700
2024-05-10 07:24:25 -04:00
Matthias Clasen
94505987fe Merge branch 'matthiasc/for-main' into 'main'
css parser: Fix a typo

See merge request GNOME/gtk!7241
2024-05-10 04:11:08 +00:00
Matthias Clasen
c6d7b704cb css parser: Fix a typo
Due to an ARAY vs ARRAY mishap, we weren't actually preallocating
any blocks. Fix that, and reduce the number of preallocated blocks
to 12. That seems sufficient, since parsing the Default theme never
needs more than 5 blocks.
2024-05-09 23:26:55 -04:00
Hugo Carvalho
349509c332 Update Portuguese translation
(cherry picked from commit 40e99590e7)
2024-05-09 16:01:52 +00:00
Matthias Clasen
84fd420271 Merge branch '6674_fix_flickering_tooltip' into 'main'
tooltip: query tooltip on widget under pointer only

Closes #6674

See merge request GNOME/gtk!7237
2024-05-08 00:43:05 +00:00
Matthias Clasen
0c40defaf1 Merge branch 'realize_accessible_before_add_event_emission' into 'main'
a11y: Realize the AT context before firing a children added event for it

See merge request GNOME/gtk!7229
2024-05-08 00:42:33 +00:00
Matthias Clasen
cda1733fc7 Merge branch 'css-parser-block-array' into 'main'
css parser: Use a GdkArray for blocks

See merge request GNOME/gtk!7236
2024-05-07 23:15:31 +00:00
Matthias Clasen
0ee851c8c7 Merge branch 'matthiasc/for-main' into 'main'
icontheme: Clarify docs a bit

See merge request GNOME/gtk!7234
2024-05-07 18:57:24 +00:00
g.willems
d665274eb1 tooltip: query tooltip on widget under pointer only
When changing the tooltip text or markup of widget A, we simulate a
motion event on that widget to update the display.
But if there is an active tooltip on widget B, then the current code
belives we moved the pointer from B to A thus hides/shows the tooltip
of B alternatively.

Instead, simulate the motion event on the widget currently under the pointer.
This will avoid flickering if we keep the pointer over widget B.

Fixes #6674
Closes #6674
2024-05-07 19:32:15 +02:00
Matthias Clasen
ed3b73871f css parser: Small optimization
Avoid creating a GFile until it is needed.
2024-05-07 12:34:37 -04:00
Matthias Clasen
e570eb4f86 css parser: Use a GdkArray for blocks
This avoids some allocations, and is typesafe.
2024-05-07 12:34:36 -04:00
Lukáš Tyrychtr
81b6251073 a11y: Realize the AT context before firing a children added event for it
This allows, with some other changes, AdwToasts to be read on appearance by Orca.
2024-05-07 15:49:59 +02:00
Matthias Clasen
cfaf619620 icontheme: Clarify docs a bit
Mention that 'desired size' is in application pixels.

Related: !7056
2024-05-06 20:37:34 -04:00
Benjamin Otte
de5b6764bc Merge branch 'wip/otte/for-6694' into 'main'
dmabuf: Ref previous context

Closes #6694

See merge request GNOME/gtk!7232
2024-05-06 22:56:05 +00:00
Benjamin Otte
bc17dfa83d dmabuf: Ref previous context
In case the context's only reference was held by being the current
context, setting the new context would free it.

Resetting it later would then be a use-after-free.

Fixes #6694
2024-05-07 00:34:47 +02:00
Matthias Clasen
84a98f74c1 Merge branch 'fix-test-breakage' into 'main'
Fix recent test breakage

See merge request GNOME/gtk!7233
2024-05-06 21:56:13 +00:00
Matthias Clasen
50facedc47 Fix recent test breakage
I neglected to fix affected tests in 76b0687467, since
ci was down at the time. Sorry about that.
2024-05-06 17:11:44 -04:00
Matthias Clasen
32a4f805b8 gsk: Require dmabuf support for Vulkan
Don't use the Vulkan renderer if Vulkan doesn't support any
dmabuf formats.
2024-05-05 15:19:17 -04:00
Matthias Clasen
200cacc3ad Merge branch 'matthiasc/for-main' into 'main'
inspector: Show more key event details

See merge request GNOME/gtk!7224
2024-05-05 17:29:29 +00:00
Matthias Clasen
eed3cab29f Merge branch 'list-item-factory-docs' into 'main'
docs: Clarify types for BuilderListItemFactory

See merge request GNOME/gtk!7226
2024-05-05 15:00:49 +00:00
Matthias Clasen
76b0687467 Put newlines before base64 blobs
This makes things look a bit cleaner in the node editor, since
the first line no longer sticks out.
2024-05-05 10:16:01 -04:00
Matthias Clasen
5039dc40f8 Merge branch 'main' into 'main'
vulkan: Don't queue presentation if image acquisition fails

See merge request GNOME/gtk!7204
2024-05-05 04:06:44 +00:00
Doğukan Korkmaztürk
7c3de4a2da vulkan: Recreate swapchain when it is necessary or beneficial
Currently, GTK does not check the result of vkAcquireNextImageKHR() and
assumes that it always succeeds. As a result, the vkQueuePresentKHR() is
unconditionally set to wait for the semaphore passed to
vkAcquireNextImageKHR() earlier.

However, if vkAcquireNextImageKHR() fails for some reason, the semaphore
passed to it does not get signalled. This causes the presentation
command to wait for the semaphore to be signalled indefinitely, which
causes GTK to hang.

This change adds error handling around vkAcquireNextImageKHR() to make
GTK recreate the Vulkan swapchain when it is necessary or beneficial and
helps avoiding situations that could cause indefinite waits.
2024-05-04 22:14:33 -04:00
Matthias Clasen
b486e9b760 inspector: Show more key event details
Consumed modifiers are relevant to understanding why shortcut
do or do not match, so show them.
2024-05-04 21:29:40 -04:00
Matthias Clasen
ce2fd8a0d0 NEWS: Updates 2024-05-04 21:29:40 -04:00
Hugo Carvalho
99b1b26fdb Update Portuguese translation
(cherry picked from commit a249b58094)
2024-05-04 22:23:06 +00:00
James Westman
b7e4bbaf74 docs: Clarify types for BuilderListItemFactory
The docs for GtkBuilderListItemFactory previously stated that the
template must extend GtkListItem. However, this is not always true.
GtkListView has headers which must extend GtkListHeader, and
GtkColumnView has its own types.

Clarified this in the GtkBuilderListItemFactory docs, and specified the
expected types in the GtkColumnView, GtkListView, and GtkGridView docs.
2024-05-04 13:20:41 -05:00
Matthias Clasen
f579b171a9 Merge branch 'gbsneto/more-win32-cleanups' into 'main'
Various cleanups around Win32

See merge request GNOME/gtk!7223
2024-05-03 17:27:05 +00:00
Georges Basile Stavracas Neto
f9929d15eb gtk-demo: Remove set-but-unused variable 2024-05-03 12:30:39 -03:00
Georges Basile Stavracas Neto
c45a6ad52d gsk/gpu: Use G_GSIZE_FORMAT for printing gsizes
On Windows, gsize is a long long unsigned. The compiler complains about
that.

Use G_GSIZE_FORMAT which translates to %llu on Windows, %lu on most
platforms, and sometimes just %u on rare cases.
2024-05-03 12:30:39 -03:00
Matthias Clasen
7233e38aa8 Merge branch 'gbsneto/cleanup-meson-profiler' into 'main'
testsuite: Remove leftover code from meson.build

See merge request GNOME/gtk!7222
2024-05-03 13:44:07 +00:00
Benjamin Otte
73ba97acd9 Merge branch 'duplicate-gl-version' into 'main'
glcontext: Remove duplicate check for GL version

See merge request GNOME/gtk!7221
2024-05-03 13:42:03 +00:00
Georges Basile Stavracas Neto
7d2ad604d2 win32/vulkancontext: Remove unused variable
Silences a compiler warning.
2024-05-03 09:52:57 -03:00
Georges Basile Stavracas Neto
45e64b915c win32/wgl: Initialize hwnd to NULL
Otherwise there's a valid code path that may return it uninitialized.
2024-05-03 09:51:46 -03:00
Georges Basile Stavracas Neto
ebaef9f18b win32/cursor: Ignore GdkPixbuf deprecation warning
Seems harmless to ignore this for now, other bits of code also ignore
this.
2024-05-03 09:49:46 -03:00
Robert Ancell
c73fe8ac4a glcontext: Remove duplicate check for GL version 2024-05-03 16:40:01 +12:00
Georges Basile Stavracas Neto
8ed8f883d1 testsuite: Remove leftover code from meson.build
Performance tests were dropped at 5dd0d39a6b. The 'profiler' option
was renamed to 'sysprof' by commit e915a1aa7f.
2024-05-02 20:28:27 -03:00
Matthias Clasen
032a5afc20 Merge branch 'accessible_help_text' into 'main'
accessible help text

See merge request GNOME/gtk!6992
2024-05-02 17:20:17 +00:00
Matthias Clasen
0064500146 Merge branch 'michaelweghorn/a11y_role_mapping' into 'main'
a11y atspi: Improve mapping for container roles

See merge request GNOME/gtk!7209
2024-05-02 01:33:02 +00:00
Matthias Clasen
4582ddcad9 Merge branch 'matthiasc/for-main' into 'main'
gtk-demo: Name some idles

See merge request GNOME/gtk!7218
2024-05-02 01:30:42 +00:00
Matthias Clasen
8bb2720494 icontheme: Move css style code where it belongs
Move gtk_icon_theme_lookup_symbolic_colors to gtkcssstyle.c, and
rename it to gtk_css_style_lookup_symbolic_colors.

Update all callers.
2024-05-01 16:06:16 -04:00
Matthias Clasen
3b8218a99e gtk-demo: Name some idles
These show up in profiles, so give them a name.
2024-05-01 16:06:16 -04:00
Matthias Clasen
9a8fa8dd82 Merge branch 'wip/chergert/fix-6684' into 'main'
undo: fix off-by-one when prepending to inline string

Closes #6684

See merge request GNOME/gtk!7217
2024-05-01 19:50:23 +00:00
Matthias Clasen
d6892c85dc Merge branch 'serialize-hint-metrics' into 'main'
gsk: Serialize hint metrics too

See merge request GNOME/gtk!7215
2024-05-01 18:40:13 +00:00
Christian Hergert
d3c20c3269 undo: fix off-by-one when prepending to inline string
This fixes the conditional in istring_prepend() to match other uses,
notably to match istring_append().

Fixes #6684
2024-05-01 11:28:55 -07:00
Matthias Clasen
9904259661 gsk: Serialize hint metrics too
We need this to ensure that we properly roundtrip text nodes
without any changes.
2024-05-01 14:00:18 -04:00
Emin Tufan Çetin
a8fcde11de Update Turkish translation 2024-05-01 16:19:02 +00:00
Matthias Clasen
d2d4cd64cd Merge branch 'no-a11y-focus-events' into 'main'
a11y: Stop emitting Focus events

See merge request GNOME/gtk!7213
2024-05-01 15:18:42 +00:00
Matthias Clasen
2c7e68d98f Merge branch 'matthiasc/for-main' into 'main'
Revert "gdk/frameclock: add mark when we discover frames may drop"

See merge request GNOME/gtk!7214
2024-05-01 12:43:52 +00:00
Matthias Clasen
6f42f8ef2c Revert "gdk/frameclock: add mark when we discover frames may drop"
This reverts commit 84a304e66e.

This produces marks that are confusing to me. They don't correlate
with actual gaps in the frame cycle and often overlap with regular
'window presented' marks. Also, the function we are emitting these
marks from is called from the get_frame_time getter, and we
definitely don't want to emit marks from there.
2024-05-01 08:03:16 -04:00
Matthias Clasen
152dd70cde a11y: Drop the Focus event from the interface too
We don't use it anymore.
2024-05-01 07:57:19 -04:00
Matthias Clasen
8ec1045c87 a11y: Stop emitting Focus events
These have been deprecated for a long time, and we have been asked
to stop emitting them.

Related: #454
2024-05-01 07:55:47 -04:00
Michael Weghorn
ad8613876c a11y atspi: Improve mapping for container roles
GTK_ACCESSIBLE_ROLE_GENERIC is for
"a nameless container that has no semantic meaning of its own",
for which AT-SPI role ATSPI_ROLE_PANEL [1]
("A generic container that is often used to group
objects.") fits better than ATSPI_ROLE_FILLER
("A object that fills up space in a user interface."),
so map to this one.

With this in place, widgets like GtkBox are again
reported with the panel role on AT-SPI level after
commit a86923de94
("a11y: Change the role for many containers"),
whose commit message suggests that the change
on the AT-SPI level was unintended.

For GTK_ACCESSIBLE_ROLE_GROUP, use the corresponding
ATSPI_ROLE_GROUPING ("A group of related widgets.
This group typically has a label.").

[1] https://docs.gtk.org/atspi2/enum.Role.html
2024-04-30 14:44:11 +02:00
Emmanuele Bassi
f537a55b71 Coding style fixes 2024-04-24 11:57:00 +01:00
Chun-wei Fan
54a86a2a7e Win32 GL: Also force not to use depth/stencil/accum bits on legacy contexts
For completeness' sake, also specifiy in the PIXELFORMATDESCRIPTOR to use no
depth, stencil and accum bits to initializing WGL when we can't (yet) use
wglChoosePixelFormatARB(), as we must always fist have a base legacy WGL
context using ChoosePixelFormat() before we can use that to use
wglChoosePixelFormatARB(), or if wglChoosePixelFormatARB() is somehow not
available for us.

Some drivers, however, enforces enabling depth buffers, so if we can't
acquire a pixel format that disables depth buffers, retry acquiring one
with that, which sadly is not optimal but we must make do.

Attempts to complete fix for issue #6401.
2024-04-24 16:23:17 +08:00
Lukáš Tyrychtr
b0450d4b1b Do not perform a changed help-text check twice 2024-04-23 11:40:51 +02:00
Lukáš Tyrychtr
91ff8bf336 The new member needs a separate docblock 2024-04-23 11:40:51 +02:00
Emmanuele Bassi
7b145f72dc Apply review feedback fixes 2024-04-23 11:40:51 +02:00
Lukáš Tyrychtr
0dcc21b605 4.14 did not cut it 2024-04-23 11:40:51 +02:00
Lukáš Tyrychtr
bd43a9e868 Document the new property 2024-04-23 11:40:51 +02:00
Lukáš Tyrychtr
9bf23d80a1 Test the new property and fix oversights found by the test 2024-04-23 11:40:51 +02:00
Lukáš Tyrychtr
38fd66dc04 a11y: Support setting the accessible help text
This adds support for setting a string used to describe the operation of a control,
if there's something special about it.

This is mapped to the HelpText property in the AT-SPI2 backend,
and has equivalent in others.
2024-04-23 11:40:51 +02:00
gayathri.berli@ibm.com
06351844bb changes to fix the memorytexture regression 2024-04-18 17:13:41 +05:30
Michael Weghorn
bcf78aeb39 a11y atspi: Map GTK_ACCESSIBLE_PROPERTY_LEVEL to AT-SPI attr
Map GTK_ACCESSIBLE_PROPERTY_LEVEL to the corresponding
AT-SPI object attribute "level", as it is specified
e.g. in the Core Accessibility Mappings 1.2 for the
"aria-level" attribute, for both, headings [1] and
non-headings [2].

This e.g. makes reporting the header level via
AT-SPI work for the gtk4-based LibreOffice variant
when combined with the corresponding LibreOffice
change [3] to set the GTK_ACCESSIBLE_PROPERTY_LEVEL
property.

For a related discussion, see issue #6196.

[1] https://www.w3.org/TR/core-aam-1.2/#ariaLevelHeading
[2] https://www.w3.org/TR/core-aam-1.2/#ariaLevel
[3] https://gerrit.libreoffice.org/c/core/+/159216
2023-11-09 17:21:00 +01:00
565 changed files with 27687 additions and 7289 deletions

View File

@@ -459,6 +459,7 @@ reference:
- mv _build/docs/reference/gdk/gdk4-wayland/ _reference/gdk4-wayland/
- mv _build/docs/reference/gsk/gsk4/ _reference/gsk4/
- mv _build/docs/reference/gtk/gtk4/ _reference/gtk4/
- mv _build/docs/reference/gtk/*.html _reference/gtk4/
- mv _build/subprojects/pango/docs/Pango/ _reference/Pango/
- mv _build/subprojects/pango/docs/PangoCairo/ _reference/PangoCairo/
- mv _build/subprojects/pango/docs/PangoFc/ _reference/PangoFc/

View File

@@ -35,7 +35,11 @@ pacman --noconfirm -S --needed \
mingw-w64-$MSYS2_ARCH-python-gobject \
mingw-w64-$MSYS2_ARCH-shaderc \
mingw-w64-$MSYS2_ARCH-vulkan \
mingw-w64-$MSYS2_ARCH-vulkan-headers
mingw-w64-$MSYS2_ARCH-vulkan-headers \
mingw-w64-$MSYS2_ARCH-libpng \
mingw-w64-$MSYS2_ARCH-libjpeg-turbo \
mingw-w64-$MSYS2_ARCH-libtiff \
mingw-w64-$MSYS2_ARCH-lcms2
mkdir -p _ccache
export CCACHE_BASEDIR="$(pwd)"

105
NEWS
View File

@@ -1,6 +1,109 @@
Overview of Changes in 4.15.1, xx-xx-xxxx
Overview of Changes in 4.15.2, xx-xx-xxxx
=========================================
* GtkFileChooserWidget:
- Plug some memory leaks
- Make Ctrl-Shift-N create a new folder
* CSS:
- Support color(), oklab(), etc (https://www.w3.org/TR/css-color-4/)
- Support color-mix() (https://www.w3.org/TR/css-color-5/)
- Support relative colors (https://www.w3.org/TR/css-color-5/)
* Accessibility:
- Avoid markup when reading labels
* GSK:
- Subset fonts when serializing node trees
* Wayland:
- Use xdg-dialog protocol for attached dialogs
* Windows:
- Build with UNICODE
* Debugging:
- Add GTK_DEBUG=css for warning about deprecated css syntax
* Tools:
- nodeparser: Add an extract command for data urls
* Deprecations:
- CSS Color functions shade(), lighter(), darker(), alpha(), mix()
* Translation updates:
Hebrew
Overview of Changes in 4.15.1, 21-05-2024
=========================================
* GtkGraphicsOffload:
- Don't crash without a child
* GtkSpinner:
- Don't animate when unmapped
* CSS:
- Support the :root selector
- Support variables and custom properties (https://www.w3.org/TR/css-variables-1/)
- Implement math functions (https://www.w3.org/TR/css-values-4/)
- Support modern syntax and calc in rgb() and hsl()
* Icontheme:
- Make symbolic svg loading more efficient
- Handle color-free symbolics more efficiently
* Accessibility:
- Make the gtk-demo sidebar search more accessible
- Stop emitting focus events
- Realize child contexts when necessary
* GDK:
- Support XDG_ACTIVATION_TOKEN
- dmabuf: Be more defensive when importing unknown formats to GL
- dmabuf: Use narrow range for YUV
- vulkan: Recreate swapchains when necessary or beneficial
* GSK:
- Improve logging for GDK_DEBUG=offload
- Improve logging for GSK_DEBUG=renderer
- gpu: Warn about inefficient texture import
- gpu: Handle tiny offscreens correctly
- vulkan: Add profiler marks in various places
- vulkan: Fix a problem with imported dmabufs showing up black
- cairo: Speed up mask nodes, since we use them for symbolic icons
* Wayland:
- Use wl_compositor version 6
* X11:
- Implement a missing method
* Build:
- Fix many ubsan warnings
* Debugging:
- Show more texture details in the recorder
- Use GTK_DEBUG=css to see CSS deprecations
* macOS:
- Fix problems with events handed back to the OS
- Respect GDK_DEBUG=default-settings
- Allow applictions to handle Dock > Quit
* Deprecations:
- Use of @name colors in CSS
* Translation updates:
Catalan
Georgian
Hungarian
Korean
Portuguese
Turkish
Overview of Changes in 4.15.0, 21-04-2024
=========================================

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

View File

@@ -0,0 +1,86 @@
/* Color Spaces
*
* Demonstrates support for color spaces.
*
* The test images used here are taken from http://displaycal.net/icc-color-management-test/
* and are licensed under the Creative Commons BY-SA 4.0 International License
*/
#include <gtk/gtk.h>
static GtkWidget *jpeg;
static GtkWidget *png;
static GtkWidget *tiff;
static GtkWidget *noprofile;
static GtkWidget *test1;
static GtkWidget *test2;
static void
on_changed (GtkCheckButton *button,
gpointer user_data)
{
GdkTexture *texture;
const char *extension = NULL;
char *path;
if (!gtk_check_button_get_active (GTK_CHECK_BUTTON (button)))
return;
if (gtk_check_button_get_active (GTK_CHECK_BUTTON (jpeg)))
extension = ".jpg";
else if (gtk_check_button_get_active (GTK_CHECK_BUTTON (png)))
extension = ".png";
else if (gtk_check_button_get_active (GTK_CHECK_BUTTON (tiff)))
extension = ".tif";
else if (gtk_check_button_get_active (GTK_CHECK_BUTTON (noprofile)))
extension = "-expected-result-no-cm.png";
path = g_strconcat ("/colorspaces/sRGB_Gray", extension, NULL);
texture = gdk_texture_new_from_resource (path);
gtk_picture_set_paintable (GTK_PICTURE (test1), GDK_PAINTABLE (texture));
g_object_unref (texture);
path = g_strconcat ("/colorspaces/ICC-Rendering-Intent-Test", extension, NULL);
texture = gdk_texture_new_from_resource (path);
gtk_picture_set_paintable (GTK_PICTURE (test2), GDK_PAINTABLE (texture));
g_object_unref (texture);
}
GtkWidget*
do_colorspaces (GtkWidget *do_widget)
{
static GtkWidget *window;
if (!window)
{
GtkBuilder *builder;
GtkBuilderScope *scope;
scope = gtk_builder_cscope_new ();
gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope),
"on_changed", G_CALLBACK (on_changed));
builder = gtk_builder_new ();
gtk_builder_set_scope (builder, scope);
gtk_builder_add_from_resource (builder, "/colorspaces/colorspaces.ui", NULL);
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
jpeg = GTK_WIDGET (gtk_builder_get_object (builder, "jpeg"));
png = GTK_WIDGET (gtk_builder_get_object (builder, "png"));
tiff = GTK_WIDGET (gtk_builder_get_object (builder, "tiff"));
noprofile = GTK_WIDGET (gtk_builder_get_object (builder, "noprofile"));
test1 = GTK_WIDGET (gtk_builder_get_object (builder, "test1"));
test2 = GTK_WIDGET (gtk_builder_get_object (builder, "test2"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
g_object_unref (builder);
g_object_unref (scope);
}
if (!gtk_widget_get_visible (window))
gtk_window_present (GTK_WINDOW (window));
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@@ -0,0 +1,94 @@
<interface>
<object class="GtkWindow" id="window">
<property name="default-width">660</property>
<property name="default-height">660</property>
<property name="resizable">false</property>
<property name="title">Color Profiles</property>
<child>
<object class="GtkScrolledWindow">
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<child>
<object class="GtkBox">
<property name="spacing">10</property>
<child>
<object class="GtkLabel">
<property name="label">File format:</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="jpeg">
<property name="label">JPEG</property>
<property name="active">1</property>
<signal name="notify::active" handler="on_changed"/>
</object>
</child>
<child>
<object class="GtkCheckButton" id="png">
<property name="label">PNG</property>
<property name="group">jpeg</property>
<signal name="notify::active" handler="on_changed"/>
</object>
</child>
<child>
<object class="GtkCheckButton" id="tiff">
<property name="label">TIFF</property>
<property name="group">png</property>
<signal name="notify::active" handler="on_changed"/>
</object>
</child>
<child>
<object class="GtkCheckButton" id="noprofile">
<property name="label">No profile</property>
<property name="group">tiff</property>
<signal name="notify::active" handler="on_changed"/>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Test 1: Matrix-based profile</property>
<style>
<class name="title-3"/>
</style>
</object>
</child>
<child>
<object class="GtkPicture" id="test1">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<property name="can-shrink">1</property>
<property name="keep-aspect-ratio">1</property>
<property name="file">resource:///colorprofiles/sRGB_Gray.jpg</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Test 2: Lookup table-based profile</property>
<style>
<class name="title-3"/>
</style>
</object>
</child>
<child>
<object class="GtkPicture" id="test2">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<property name="can-shrink">1</property>
<property name="keep-aspect-ratio">1</property>
<property name="file">resource:///colorprofiles/ICC-Rendering-Intent-Test.jpg</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@@ -19,6 +19,17 @@
<file>demoimage.c</file>
<file>demoimage.h</file>
</gresource>
<gresource prefix="/colorspaces">
<file>colorspaces.ui</file>
<file>sRGB_Gray.jpg</file>
<file>sRGB_Gray.png</file>
<file>sRGB_Gray.tif</file>
<file>sRGB_Gray-expected-result-no-cm.png</file>
<file>ICC-Rendering-Intent-Test.png</file>
<file>ICC-Rendering-Intent-Test.jpg</file>
<file>ICC-Rendering-Intent-Test.tif</file>
<file>ICC-Rendering-Intent-Test-expected-result-no-cm.png</file>
</gresource>
<gresource prefix="/constraints_builder">
<file>constraints_builder.ui</file>
</gresource>
@@ -265,6 +276,7 @@
<file>assistant.c</file>
<file>builder.c</file>
<file>clipboard.c</file>
<file>colorspaces.c</file>
<file>combobox.c</file>
<file>constraints.c</file>
<file>constraints_interactive.c</file>

View File

@@ -363,7 +363,9 @@ insert_markup_idle (gpointer data)
if (g_get_monotonic_time () - begin > G_TIME_SPAN_MILLISECOND)
{
g_idle_add (insert_markup_idle, data);
guint id;
id = g_idle_add (insert_markup_idle, data);
g_source_set_name_by_id (id, "[gtk-demo] insert_markup_idle");
return G_SOURCE_REMOVE;
}
@@ -398,7 +400,9 @@ parse_markup_idle (gpointer data)
do {
if (g_get_monotonic_time () - begin > G_TIME_SPAN_MILLISECOND)
{
g_idle_add (parse_markup_idle, data);
guint id;
id = g_idle_add (parse_markup_idle, data);
g_source_set_name_by_id (id, "[gtk-demo] parse_markup_idle");
return G_SOURCE_REMOVE;
}

View File

@@ -40,7 +40,7 @@ get_win32_all_locales_scripts (LPWSTR locale_w, DWORD flags, LPARAM param)
{
wchar_t *langname_w = NULL;
wchar_t locale_abbrev_w[9];
gchar *langname, *locale_abbrev, *locale, *p;
gchar *langname, *locale_abbrev, *locale;
gint i;
const LCTYPE iso639_lctypes[] = { LOCALE_SISO639LANGNAME, LOCALE_SISO639LANGNAME2 };
GHashTable *ht_scripts_langs = (GHashTable *) param;
@@ -59,7 +59,6 @@ get_win32_all_locales_scripts (LPWSTR locale_w, DWORD flags, LPARAM param)
GetLocaleInfoEx (locale_w, LOCALE_SLOCALIZEDDISPLAYNAME, langname_w, langname_size);
langname = g_utf16_to_utf8 (langname_w, -1, NULL, NULL, NULL);
locale = g_utf16_to_utf8 (locale_w, -1, NULL, NULL, NULL);
p = strchr (locale, '-');
lang = pango_language_from_string (locale);
if (g_hash_table_lookup (ht_scripts_langs, lang) == NULL)
g_hash_table_insert (ht_scripts_langs, lang, langname);

View File

@@ -5,6 +5,7 @@ demos = files([
'assistant.c',
'builder.c',
'clipboard.c',
'colorspaces.c',
'combobox.c',
'constraints.c',
'constraints_interactive.c',

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

View File

@@ -117,16 +117,27 @@ should be aware that the allowed values are meant to be used on 3D transformatio
so their naming might appear awkward. However, it is always possible to use the
matrix3d() production to specify all 16 values individually.
### color-state
| property | syntax | default | printed |
| ----------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| color-state | `<ident>|<url>` | srgb | always |
Creates a node like `gsk_color_state_node_new()` with the given properties.
### conic-gradient
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| center | `<point>` | 25, 25 | always |
| rotation | `<number>` | 0 | always |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
| property | syntax | default | printed |
| ----------------- | ----------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| center | `<point>` | 25, 25 | always |
| rotation | `<number>` | 0 | always |
| color-state | `<ident>`|`<url>` | srgb | non-default |
| hue-interpolation | `<ident>` | shorter | non-default |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
Creates a node like `gsk_conic_gradient_node_new()` with the given properties.
Creates a node like `gsk_conic_gradient_node_new_in()` with the given properties.
### cross-fade
@@ -192,14 +203,16 @@ Creates a node like `gsk_inset_shadow_node_new()` with the given properties.
### linear-gradient
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| start | `<point>` | 0 0 | always |
| end | `<point>` | 0 50 | always |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
| property | syntax | default | printed |
| ----------------- | ----------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| start | `<point>` | 0 0 | always |
| end | `<point>` | 0 50 | always |
| color-state | `<ident>`|`<url>` | srgb | non-default |
| hue-interpolation | `<ident>` | shorter | non-default |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
Creates a node like `gsk_linear_gradient_node_new()` with the given properties.
Creates a node like `gsk_linear_gradient_node_new_in()` with the given properties.
### mask
@@ -235,15 +248,17 @@ Creates a node like `gsk_outset_shadow_node_new()` with the given properties.
### radial-gradient
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| center | `<point>` | 25 25 | always |
| hradius | `<number>` | 25 | always |
| vradius | `<number>` | 25 | always |
| start | `<number>` | 0 | always |
| end | `<number>` | 1 | always |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
| property | syntax | default | printed |
| ----------------- | ----------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| center | `<point>` | 25 25 | always |
| hradius | `<number>` | 25 | always |
| vradius | `<number>` | 25 | always |
| start | `<number>` | 0 | always |
| end | `<number>` | 1 | always |
| color-state | `<ident>`|`<url>` | srgb | non-default |
| hue-interpolation | `<ident>` | shorter | non-default |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
Creates a node like `gsk_radial_gradient_node_new()` with the given properties.
@@ -259,29 +274,33 @@ Creates a node like `gsk_repeat_node_new()` with the given properties.
### repeating-linear-gradient
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| start | `<point>` | 0 0 | always |
| end | `<point>` | 0 50 | always |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
| property | syntax | default | printed |
| ----------------- | ----------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| start | `<point>` | 0 0 | always |
| end | `<point>` | 0 50 | always |
| color-state | `<ident>`|`<url>` | srgb | non-default |
| hue-interpolation | `<ident>` | shorter | non-default |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
Creates a node like `gsk_repeating_linear_gradient_node_new()` with the given
Creates a node like `gsk_repeating_linear_gradient_node_new_in()` with the given
properties.
### repeating radial-gradient
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| center | `<point>` | 25 25 | always |
| hradius | `<number>` | 25 | always |
| vradius | `<number>` | 25 | always |
| start | `<number>` | 0 | always |
| end | `<number>` | 1 | always |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
| property | syntax | default | printed |
| ----------------- | ----------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| center | `<point>` | 25 25 | always |
| hradius | `<number>` | 25 | always |
| vradius | `<number>` | 25 | always |
| start | `<number>` | 0 | always |
| end | `<number>` | 1 | always |
| color-state | `<ident>`|`<url>` | srgb | non-default |
| hue-interpolation | `<ident>` | shorter | non-default |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
Creates a node like `gsk_repeating_radial_gradient_node_new()` with the given
Creates a node like `gsk_repeating_radial_gradient_node_new_in()` with the given
properties.
### rounded-clip
@@ -330,6 +349,7 @@ stroke bounds of the path.
| offset | `<point>` | 0 0 | non-default |
| hint-style | `<hint style>` | slight | non-default |
| antialias | `<antialias>` | gray | non-default |
| hint-metrics | `<hint metrics>` | off | non-default |
Creates a node like `gsk_text_node_new()` with the given properties.
@@ -346,6 +366,7 @@ font, an error node will be returned.
Possible values for hint-style are none, slight or full.
Possible value for antialias are none or gray.
Possible value for hint-metrics are on or off.
### texture

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

View File

@@ -6,3 +6,10 @@
.toolbar {
-gtk-icon-style: symbolic;
}
.gtk-gradient-color {
background: linear-gradient(to right, lime, red);
}
.gtk-gradient-monochrome {
background: linear-gradient(to right, black, white);
}

View File

@@ -117,5 +117,9 @@
<file>portland-rose.jpg</file>
<file>nyc.jpg</file>
<file>beach.jpg</file>
<file>linear-gradient-color.png</file>
<file>linear-gradient-monochrome.png</file>
<file>srgb-gradient-color.png</file>
<file>srgb-gradient-monochrome.png</file>
</gresource>
</gresources>

View File

@@ -1344,13 +1344,173 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
<child>
<object class="GtkNotebookPage">
<property name="child">
<object class="GtkBox" id="box8">
<property name="orientation">1</property>
<object class="GtkGrid">
<property name="hexpand">0</property>
<property name="row-spacing">6</property>
<property name="column-spacing">6</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="row-homogeneous">1</property>
<property name="valign">start</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">color</property>
<style>
<class name="caption-heading"/>
</style>
<layout>
<property name="column">0</property>
<property name="row">0</property>
<property name="column-span">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">sRGB</property>
<layout>
<property name="column">0</property>
<property name="row">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="file">resource:///org/gtk/WidgetFactory4/srgb-gradient-color.png</property>
<property name="can-shrink">0</property>
<property name="keep-aspect-ratio">0</property>
<property name="hexpand">1</property>
<layout>
<property name="column">1</property>
<property name="row">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">GTK</property>
<layout>
<property name="column">0</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="width-request">128</property>
<property name="keep-aspect-ratio">0</property>
<style>
<class name="gtk-gradient-color"/>
</style>
<layout>
<property name="column">1</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">linear</property>
<layout>
<property name="column">0</property>
<property name="row">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="file">resource:///org/gtk/WidgetFactory4/linear-gradient-color.png</property>
<property name="can-shrink">0</property>
<property name="keep-aspect-ratio">0</property>
<layout>
<property name="column">1</property>
<property name="row">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">monochrome</property>
<style>
<class name="caption-heading"/>
</style>
<layout>
<property name="column">0</property>
<property name="row">4</property>
<property name="column-span">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">sRGB</property>
<layout>
<property name="column">0</property>
<property name="row">5</property>
</layout>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="file">resource:///org/gtk/WidgetFactory4/srgb-gradient-monochrome.png</property>
<property name="can-shrink">0</property>
<property name="keep-aspect-ratio">0</property>
<property name="hexpand">1</property>
<layout>
<property name="column">1</property>
<property name="row">5</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">GTK</property>
<layout>
<property name="column">0</property>
<property name="row">6</property>
</layout>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="width-request">128</property>
<property name="keep-aspect-ratio">0</property>
<style>
<class name="gtk-gradient-monochrome"/>
</style>
<layout>
<property name="column">1</property>
<property name="row">6</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">linear</property>
<layout>
<property name="column">0</property>
<property name="row">7</property>
</layout>
</object>
</child>
<child>
<object class="GtkPicture">
<property name="file">resource:///org/gtk/WidgetFactory4/linear-gradient-monochrome.png</property>
<property name="can-shrink">0</property>
<property name="keep-aspect-ratio">0</property>
<layout>
<property name="column">1</property>
<property name="row">7</property>
</layout>
</object>
</child>
</object>
</property>
<property name="tab">
<object class="GtkLabel" id="label8">
<property name="label" translatable="1">page 1</property>
<property name="label" translatable="1">Gradients</property>
</object>
</property>
</object>

View File

@@ -15,16 +15,16 @@ spec.
The following units are supported for basic datatypes:
Length
: px, pt, em, ex, rem, pc, in, cm, mm, calc()
: px, pt, em, ex, rem, pc, in, cm, mm
Percentage
: %, calc()
: %
Angle
: deg, grad, turn, calc()
: deg, rad, grad, turn
Time
: s, ms, calc()
: s, ms
Length values with the em or ex units are resolved using the font
size value, unless they occur in setting the font-size itself, in
@@ -33,11 +33,15 @@ which case they are resolved using the inherited font size value.
The rem unit is resolved using the initial font size value, which is
not quite the same as the CSS definition of rem.
The calc() notation adds considerable expressive power. There are limits
on what types can be combined in such an expression (e.g. it does not make
sense to add a number and a time). For the full details, see the
[CSS3 Values and Units](https://www.w3.org/TR/css3-values/#calc-notation)
spec.
Length values using physical units (pt, pc, in, cm, mm) are translated
to px using the dpi value specified by the -gtk-dpi property, which is
different from the CSS definition, which uses a fixed dpi of 96.
The calc() notation adds considerable expressive power to all of these
datatypes. There are limits on what types can be combined in such an
expression (e.g. it does not make sense to add a number and a time).
For the full details, see the
[CSS Values and Units](https://www.w3.org/TR/css-values-4/) spec.
A common pattern among shorthand properties (called 'four sides') is one
where one to four values can be specified, to determine a value for each
@@ -56,38 +60,80 @@ follows:
1 value:
: all
## Custom Properties
GTK supports custom properties as defined in the
[CSS Custom Properties for Cascading Variables](https://www.w3.org/TR/css-variables-1)
spec.
Custom properties are defined as follows:
```css
--prop: red;
```
and used via the `var` keyword:
```css
color: var(--prop);
```
Custom properties can have a fallback for when the referred property is invalid:
```css
color: var(--prop, green);
```
## Colors
GTK extends the CSS syntax with several additional ways to specify colors.
### CSS Colors
Colors can be expressed in numerous ways in CSS (see the
[Color Module](https://www.w3.org/TR/css-color-5/). GTK supports
many (but not all) of these.
You can use rgb(), rgba(), hsl() with both the legacy or the modern CSS
syntax, and calc() can be used as well in color expressions. hwb(), oklab(),
oklch(), color(), color-mix() and relative colors are supported as well.
### Non-CSS Colors
GTK extends the CSS syntax with several additional ways to specify colors.
These extensions are deprecated and should be replaced by the equivalent
standard CSS notions.
The first is a reference to a color defined via a @define-color rule in CSS.
The syntax for @define-color rules is as follows:
```
@define-color Name Color
@define-color name color
```
To refer to the color defined by a @define-color rule, prefix the name with @.
The standard CSS mechanisms that should be used instead of @define-color are
custom properties, :root and var().
GTK also supports color expressions, which allow colors to be transformed to
new ones. Color expressions can be nested, providing a rich language to
define colors. Color expressions resemble functions, taking 1 or more colors
and in some cases a number as arguments.
`lighter(Color)`
: produces a brighter variant of Color
`lighter(color)`
: produces a brighter variant of `color`.
`darker(Color)`
: produces a darker variant of Color
`darker(color)`
: produces a darker variant of `color`.
`shade(Color, Number)`
: changes the lightness of Color. The number ranges from 0 for black to 2 for white.
`shade(color, number)`
: changes the lightness of `color`. The `number` ranges from 0 for black to 2 for white.
`alpha(Color, Number)`
: replaces the alpha value of color with number (between 0 and 1)
`alpha(color, number)`
: multiplies the alpha value of `color` by `number` (between 0 and 1).
`mix(Color1, Color2, Number)`
: interpolates between the two colors
`mix(color1, color2, number)`
: interpolates between the two colors.
## Images
@@ -95,7 +141,7 @@ GTK extends the CSS syntax for images and also uses it for specifying icons.
To load a themed icon, use
```
-gtk-icontheme(Name)
-gtk-icontheme(name)
```
The specified icon name is used to look up a themed icon, while taking into
@@ -131,7 +177,7 @@ images can specify normal and hi-resolution variants. From CSS, this can be
done with
```
-gtk-scaled(Image1, Image2)
-gtk-scaled(image1, image2)
```
## GTK CSS Properties

View File

@@ -99,16 +99,15 @@ reaches the requested phase. However, in practice most things
happen at higher levels:
- If you are doing an animation, you can use
gtk_widget_add_tick_callback() which will cause a regular
[method@Gtk.Widget.add_tick_callback] which will cause a regular
beating of the clock with a callback in the Update phase
until you stop the tick.
- If some state changes that causes the size of your widget to
change you call gtk_widget_queue_resize() which will request
change you call [method@Gtk.Widget.queue_resize] which will request
a Layout phase and mark your widget as needing relayout.
- If some state changes so you need to redraw some area of
your widget you use the normal gtk_widget_queue_draw()
set of functions. These will request a Paint phase and
mark the region as needing redraw.
- If some state changes so you need to redraw your widget you
use [method@Gtk.Widget.queue_draw] to request a Paint phase for
your widget.
There are also a lot of implicit triggers of these from the
CSS layer (which does animations, resizes and repaints as needed).

View File

@@ -18,6 +18,7 @@ SYNOPSIS
|
| **gtk4-rendernode-tool** benchmark [OPTIONS...] <FILE>
| **gtk4-rendernode-tool** compare [OPTIONS...] <FILE1> <FILE2>
| **gtk4-rendernode-tool** extract [OPTIONS...] <FILE>
| **gtk4-rendernode-tool** info [OPTIONS...] <FILE>
| **gtk4-rendernode-tool** render [OPTIONS...] <FILE> [<FILE>]
| **gtk4-rendernode-tool** show [OPTIONS...] <FILE>
@@ -99,3 +100,15 @@ exit code is 1. If the images are identical, it is 0.
``--quiet``
Don't write results to stdout.
Extract
^^^^^^^
The ``extract`` command saves all the data urls found in a node file to a given
directory. The file names for the extracted files are derived from the mimetype
of the url.
``--dir=DIRECTORY``
Save extracted files in ``DIRECTORY`` (defaults to the current directory).

View File

@@ -77,11 +77,13 @@ content_files = [
"section-tree-widget.md",
"migrating-2to4.md",
"migrating-3to4.md",
"migrating-4to5.md",
"broadway.md",
"osx.md",
"wayland.md",
"windows.md",
"x11.md",
"tools.md",
"visual_index.md",
]
content_images = [

View File

@@ -14,6 +14,7 @@ expand_content_md_files = [
'running.md',
'migrating-2to4.md',
'migrating-3to4.md',
'migrating-4to5.md',
'actions.md',
'input-handling.md',
'drawing-model.md',
@@ -25,7 +26,8 @@ expand_content_md_files = [
'section-tree-widget.md',
'section-list-widget.md',
'question_index.md',
'visual_index.md'
'visual_index.md',
'tools.md',
]
gtk_images = []
@@ -60,39 +62,39 @@ if get_option('documentation')
build_by_default: true,
install: true,
install_dir: docs_dir,
install_tag: 'doc',
)
endif
rst2man = find_program('rst2man', 'rst2man.py', required: false)
if get_option('man-pages') and not rst2man.found()
error('No rst2man found, but man pages were explicitly enabled')
rst2man = find_program('rst2man', 'rst2man.py', required: get_option('man-pages'))
rst2html5 = find_program('rst2html5', 'rst2html5.py', required: get_option('documentation'))
rst_files = [
[ 'gtk4-broadwayd', '1' ],
[ 'gtk4-builder-tool', '1' ],
[ 'gtk4-encode-symbolic-svg', '1', ],
[ 'gtk4-launch', '1', ],
[ 'gtk4-query-settings', '1', ],
[ 'gtk4-rendernode-tool', '1' ],
[ 'gtk4-update-icon-cache', '1', ],
[ 'gtk4-path-tool', '1', ],
]
if get_option('build-demos')
rst_files += [
[ 'gtk4-demo', '1', ],
[ 'gtk4-demo-application', '1', ],
[ 'gtk4-widget-factory', '1', ],
[ 'gtk4-icon-browser', '1', ],
[ 'gtk4-node-editor', '1', ],
]
endif
if get_option('man-pages') and rst2man.found()
rst_files = [
[ 'gtk4-broadwayd', '1' ],
[ 'gtk4-builder-tool', '1' ],
[ 'gtk4-encode-symbolic-svg', '1', ],
[ 'gtk4-launch', '1', ],
[ 'gtk4-query-settings', '1', ],
[ 'gtk4-rendernode-tool', '1' ],
[ 'gtk4-update-icon-cache', '1', ],
[ 'gtk4-path-tool', '1', ],
]
rst2x_flags = [
'--syntax-highlight=none',
]
if get_option('build-demos')
rst_files += [
[ 'gtk4-demo', '1', ],
[ 'gtk4-demo-application', '1', ],
[ 'gtk4-widget-factory', '1', ],
[ 'gtk4-icon-browser', '1', ],
[ 'gtk4-node-editor', '1', ],
]
endif
rst2man_flags = [
'--syntax-highlight=none',
]
if get_option('man-pages')
foreach rst: rst_files
man_name = rst[0]
@@ -103,12 +105,34 @@ if get_option('man-pages') and rst2man.found()
output: '@0@.@1@'.format(man_name, man_section),
command: [
rst2man,
rst2man_flags,
rst2x_flags,
'@INPUT@',
],
capture: true,
install: true,
install_dir: get_option('mandir') / 'man@0@'.format(man_section),
install_tag: 'doc',
)
endforeach
endif
if get_option('documentation')
foreach rst: rst_files
man_name = rst[0]
custom_target(
input: '@0@.rst'.format(man_name),
output: '@0@.html'.format(man_name),
command: [
rst2html5,
rst2x_flags,
'@INPUT@',
],
capture: true,
install: true,
install_dir: docs_dir / 'gtk4',
install_tag: 'doc',
)
endforeach
endif

View File

@@ -58,7 +58,7 @@ use a GtkLabel.
If you have a need for custom drawing that fits into the current
(dark or light) theme, e.g. for rendering a graph, you can still
get the current style foreground color, using
[method@Gtk.Widget.get_style_color].
[method@Gtk.Widget.get_color].
## Local stylesheets are going away
@@ -73,6 +73,103 @@ GTK 5 will no longer provide this functionality. The recommendations
is to use a global stylesheet (i.e. gtk_style_context_add_provider_for_display())
and rely on style classes to make your CSS apply only where desired.
## Non-standard CSS extensions are going away
GTK's CSS machinery has a some non-standard extensions around colors:
named colors with \@define-color and color functions: lighter(), darker(),
shade(), alpha(), mix().
GTK now implements equivalent functionality from the CSS specs.
### \@define-color is going away
\@define-color should be replaced by custom properties in the :root scope.
Instead of
```
@define-color fg_color #2e3436
...
box {
color: @fg_color;
}
```
use
```
:root {
--fg-color: #2e3436;
}
...
box {
color: var(--fg-color);
}
```
For more information about custom CSS properties and variables, see the
[CSS Custom Properties for Cascading Variables](https://www.w3.org/TR/css-variables-1/)
spec.
### Color expressions are going away
The color functions can all be replaced by combinations of calc() and color-mix().
ligher(c) and darker(c) are just shade(c, 1.3) or shade(c, 0.7), respectively, and
thus can be handled the same way as shade in the examples below.
Replace
```
a {
color: mix(red, green, 0.8);
}
b {
color: alpha(green, 0.6);
}
c {
color: shade(red, 1.3);
}
d {
color: shade(red, 0.7);
}
```
with
```
a {
color: color-mix(in srgb, red, green 80%);
}
b {
color: rgb(from green, r g b / calc(alpha * 0.6));
}
c {
color: hsl(from red, h calc(s * 1.3) calc(l * 1.3));
}
d {
color: hsl(from red, h calc(s * 0.7) calc(l * 0.7));
}
```
Variations of these replacements are possible.
Note that GTK has historically computed mix() and shade() values in the SRGB and HSL
colorspaces, but using OKLAB instead might yield slightly better results.
For more information about color-mix(), see the
[CSS Color](https://drafts.csswg.org/css-color-5) spec.
## Chooser interfaces are going away
The GtkColorChooser, GtkFontChooser, GtkFileChooser and GtkAppChooser

View File

@@ -64,6 +64,6 @@ GTK is divided into three parts:
[cairo]: https://www.cairographics.org/manual/
[opengl]: https://www.opengl.org/about/
[vulkan]: https://www.vulkan.org/
[pango]: https://docs.gtk.org/pango/
[pango]: https://docs.gtk.org/Pango/
[gdkpixbuf]: https://docs.gtk.org/gdk-pixbuf/
[graphene]: https://ebassi.github.io/graphene/

View File

@@ -155,6 +155,7 @@ Each property name is part of the `GtkAccessibleProperty` enumeration.
| %GTK_ACCESSIBLE_PROPERTY_VALUE_MIN | “aria-valuemin” | double |
| %GTK_ACCESSIBLE_PROPERTY_VALUE_NOW | “aria-valuenow” | double |
| %GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT | “aria-valuetext” | translatable string |
| %GTK_ACCESSIBLE_PROPERTY_HELP_TEXT | N/A | translatable string |
#### List of accessible relations
@@ -216,6 +217,10 @@ are accessible as part of the development process. The GTK Inspector shows
the accessible attributes of each widget, and also provides an overlay that
can highlight accessibility issues.
If you support some non-standard keyboard interactions for a widget, you
**should** set an appropriate `GTK_ACCESSIBLE_PROPERTY_HELP_TEXT` to help
discoverability of the behavior.
It is possible to set accessible attributes in UI files as well:
```xml
<object class="GtkButton" id="button1">

View File

@@ -0,0 +1,18 @@
Title: Tools and Demos
GTK ships with a number of tools and demos that come with their own
documentation in the form of man pages.
- [gtk4-broadwayd](gtk4-broadwayd.html)
- [gtk4-builder-tool](gtk4-builder-tool.html)
- [gtk4-demo](gtk4-demo.html)
- [gtk4-demo-application](gtk4-demo-application.html)
- [gtk4-encode-symbolic-svg](gtk4-encode-symbolic-svg.html)
- [gtk4-icon-browser](gtk4-icon-browser.html)
- [gtk4-launch](gtk4-launch.html)
- [gtk4-node-editor](gtk4-node-editor.html)
- [gtk4-path-tool](gtk4-path-tool.html)
- [gtk4-query-settings](gtk4-query-settings.html)
- [gtk4-rendernode-tool](gtk4-rendernode-tool.html)
- [gtk4-update-icon-cache](gtk4-update-icon-cache.html)
- [gtk4-widget-factory](gtk4-widget-factory.html)

View File

@@ -46,9 +46,10 @@ gdk_broadway_cairo_context_begin_frame (GdkDrawContext *draw_context,
width = gdk_surface_get_width (surface);
height = gdk_surface_get_height (surface);
scale = gdk_surface_get_scale_factor (surface);
self->paint_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
width * scale, height * scale);
cairo_surface_set_device_scale (self->paint_surface, scale, scale);
self->paint_surface = gdk_surface_create_similar_surface (surface,
CAIRO_CONTENT_COLOR_ALPHA,
width * scale, height *scale);
repaint_region = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { 0, 0, width, height });
cairo_region_union (region, repaint_region);

View File

@@ -138,6 +138,7 @@ static const GdkDebugKey gdk_debug_keys[] = {
{ "high-depth", GDK_DEBUG_HIGH_DEPTH, "Use high bit depth rendering if possible" },
{ "no-vsync", GDK_DEBUG_NO_VSYNC, "Repaint instantly (uses 100% CPU with animations)" },
{ "dmabuf-disable", GDK_DEBUG_DMABUF_DISABLE, "Disable dmabuf support" },
{ "srgb", GDK_DEBUG_SRGB, "Force sRRGB rendering and turn off color profiles" },
};

View File

@@ -30,6 +30,8 @@
#include <gdk/gdkcairo.h>
#include <gdk/gdkcairocontext.h>
#include <gdk/gdkclipboard.h>
#include <gdk/gdkcolor.h>
#include <gdk/gdkcolorstate.h>
#include <gdk/gdkconfig.h>
#include <gdk/gdkcontentdeserializer.h>
#include <gdk/gdkcontentformats.h>

View File

@@ -41,8 +41,10 @@ G_BEGIN_DECLS
#ifdef GDK_ARRAY_NULL_TERMINATED
#define GDK_ARRAY_REAL_SIZE(_size) ((_size) + 1)
#define GDK_ARRAY_MAX_SIZE (G_MAXSIZE / sizeof (_T_) - 1)
#else
#define GDK_ARRAY_REAL_SIZE(_size) (_size)
#define GDK_ARRAY_MAX_SIZE (G_MAXSIZE / sizeof (_T_))
#endif
/* make this readable */
@@ -177,18 +179,23 @@ G_GNUC_UNUSED static inline void
gdk_array(reserve) (GdkArray *self,
gsize n)
{
gsize new_size, size;
gsize new_capacity, size, capacity;
if (n <= gdk_array(get_capacity) (self))
return;
if (G_UNLIKELY (n > GDK_ARRAY_MAX_SIZE))
g_error ("requesting array size of %zu, but maximum size is %zu", n, GDK_ARRAY_MAX_SIZE);
capacity = gdk_array(get_capacity) (self);
if (n <= capacity)
return;
size = gdk_array(get_size) (self);
new_size = ((gsize) 1) << g_bit_storage (MAX (GDK_ARRAY_REAL_SIZE (n), 16) - 1);
/* capacity * 2 can overflow, that's why we MAX() */
new_capacity = MAX (GDK_ARRAY_REAL_SIZE (n), capacity * 2);
#ifdef GDK_ARRAY_PREALLOC
if (self->start == self->preallocated)
{
self->start = g_new (_T_, new_size);
self->start = g_new (_T_, new_capacity);
memcpy (self->start, self->preallocated, sizeof (_T_) * GDK_ARRAY_REAL_SIZE (size));
}
else
@@ -196,15 +203,15 @@ gdk_array(reserve) (GdkArray *self,
#ifdef GDK_ARRAY_NULL_TERMINATED
if (self->start == NULL)
{
self->start = g_new (_T_, new_size);
self->start = g_new (_T_, new_capacity);
*self->start = *(_T_[1]) { 0 };
}
else
#endif
self->start = g_renew (_T_, self->start, new_size);
self->start = g_renew (_T_, self->start, new_capacity);
self->end = self->start + size;
self->end_allocation = self->start + new_size;
self->end_allocation = self->start + new_capacity;
#ifdef GDK_ARRAY_NULL_TERMINATED
self->end_allocation--;
#endif
@@ -312,6 +319,7 @@ gdk_array(get) (const GdkArray *self,
#undef gdk_array_paste
#undef gdk_array
#undef GDK_ARRAY_REAL_SIZE
#undef GDK_ARRAY_MAX_SIZE
#undef GDK_ARRAY_BY_VALUE
#undef GDK_ARRAY_ELEMENT_TYPE

View File

@@ -20,7 +20,11 @@
#include "gdkcairo.h"
#include "gdkrgba.h"
#include "gdkcolor.h"
#include "gdktexture.h"
#include "gdkcolorstate.h"
#include "gdkcolorprivate.h"
#include "gdkmemoryformatprivate.h"
#include <math.h>
@@ -35,14 +39,47 @@ void
gdk_cairo_set_source_rgba (cairo_t *cr,
const GdkRGBA *rgba)
{
GdkColor color;
const float *components;
g_return_if_fail (cr != NULL);
g_return_if_fail (rgba != NULL);
gdk_color_convert_rgba (&color, gdk_cairo_get_color_state (cr), rgba);
components = gdk_color_get_components (&color);
cairo_set_source_rgba (cr,
rgba->red,
rgba->green,
rgba->blue,
rgba->alpha);
components[0],
components[1],
components[2],
components[3]);
}
/**
* gdk_cairo_set_source_color:
* @cr: a cairo contet
* @rgba: a `GdkColor`
*
* Sets the specified `GdkColor` as the source color of @cr.
*
* Since: 4.16
*/
void
gdk_cairo_set_source_color (cairo_t *cr,
const GdkColor *color)
{
GdkColor c;
const float *components;
g_return_if_fail (cr != NULL);
g_return_if_fail (color != NULL);
gdk_color_convert (&c, gdk_cairo_get_color_state (cr), color);
components = gdk_color_get_components (&c);
cairo_set_source_rgba (cr,
components[0],
components[1],
components[2],
components[3]);
}
/**
@@ -303,3 +340,98 @@ gdk_cairo_region_create_from_surface (cairo_surface_t *surface)
return region;
}
static cairo_user_data_key_t color_state_key;
/**
* gdk_cairo_surface_set_color_state:
* @surface: a surface
* @color_state: the color state to attach to the surface
*
* Attaches a `GdkColorState` to the Cairo surface.
*
* This is just auxiliary data for use by GTK, no Cairo functions
* do interact with this information.
*
* Note that all Cairo compositing operations are assumed to happen
* in a linear RGB color state, so if you want to use the surface
* as a target for rendering in a color managed way, you should use
* such a color state.
*
* The default color state is assumed to be sRGB, which is not
* linear.
*
* Since: 4.16
*/
void
gdk_cairo_surface_set_color_state (cairo_surface_t *surface,
GdkColorState *color_state)
{
g_return_if_fail (surface != NULL);
g_return_if_fail (color_state != NULL);
cairo_surface_set_user_data (surface,
&color_state_key,
gdk_color_state_ref (color_state),
(cairo_destroy_func_t) gdk_color_state_unref);
}
/**
* gdk_cairo_surface_get_color_state:
* @surface: a surface
*
* Gets the color state GTK assumes for the surface.
*
* See [method@Gdk.CairoSurface.set_color_state] for details.
*
* Returns: (transfer none): the color state
*
* Since: 4.16
*/
GdkColorState *
gdk_cairo_surface_get_color_state (cairo_surface_t *surface)
{
GdkColorState *color_state;
g_return_val_if_fail (surface != NULL, gdk_color_state_get_srgb ());
color_state = cairo_surface_get_user_data (surface, &color_state_key);
if (color_state == NULL)
color_state = gdk_color_state_get_srgb ();
return color_state;
}
/**
* gdk_cairo_get_color_state:
* @cr: a cairo context
*
* Gets the color state GTK assumes for the cairo context.
*
* Returns: (transfer none): the color state
*
* Since: 4.16
*/
GdkColorState *
gdk_cairo_get_color_state (cairo_t *cr)
{
GdkColorState *color_state;
cairo_surface_t *surface;
g_return_val_if_fail (cr != NULL, gdk_color_state_get_srgb ());
surface = cairo_get_group_target (cr);
color_state = cairo_surface_get_user_data (surface, &color_state_key);
if (color_state != NULL)
return color_state;
/* theoretically, we should walk the whole group stack, but I don't
* think Cairo lets us do that
*/
surface = cairo_get_target (cr);
color_state = cairo_surface_get_user_data (surface, &color_state_key);
if (color_state != NULL)
return color_state;
return gdk_color_state_get_srgb ();
}

View File

@@ -30,6 +30,11 @@ G_BEGIN_DECLS
GDK_AVAILABLE_IN_ALL
void gdk_cairo_set_source_rgba (cairo_t *cr,
const GdkRGBA *rgba);
GDK_AVAILABLE_IN_4_16
void gdk_cairo_set_source_color (cairo_t *cr,
const GdkColor *color);
GDK_AVAILABLE_IN_ALL
void gdk_cairo_set_source_pixbuf (cairo_t *cr,
const GdkPixbuf *pixbuf,
@@ -44,9 +49,15 @@ void gdk_cairo_region (cairo_t *cr,
const cairo_region_t *region);
GDK_AVAILABLE_IN_ALL
cairo_region_t *
gdk_cairo_region_create_from_surface
(cairo_surface_t *surface);
cairo_region_t * gdk_cairo_region_create_from_surface (cairo_surface_t *surface);
GDK_AVAILABLE_IN_4_16
void gdk_cairo_surface_set_color_state (cairo_surface_t *surface,
GdkColorState *color_state);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_cairo_surface_get_color_state (cairo_surface_t *surface);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_cairo_get_color_state (cairo_t *cr);
GDK_DEPRECATED_IN_4_6_FOR(gdk_gl_texture_new)
void gdk_cairo_draw_from_gl (cairo_t *cr,

View File

@@ -522,8 +522,6 @@ gdk_clipboard_get_content (GdkClipboard *clipboard)
*
* If the clipboard is not local, this function does nothing but report success.
*
* The @callback must call [method@Gdk.Clipboard.store_finish].
*
* The purpose of this call is to preserve clipboard contents beyond the
* lifetime of an application, so this function is typically called on
* exit. Depending on the platform, the functionality may not be available
@@ -638,9 +636,6 @@ gdk_clipboard_read_internal (GdkClipboard *clipboard,
* Asynchronously requests an input stream to read the @clipboard's
* contents from.
*
* When the operation is finished @callback will be called. You must then
* call [method@Gdk.Clipboard.read_finish] to get the result of the operation.
*
* The clipboard will choose the most suitable mime type from the given list
* to fulfill the request, preferring the ones listed first.
*/
@@ -834,9 +829,6 @@ gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
* Asynchronously request the @clipboard contents converted to the given
* @type.
*
* When the operation is finished @callback will be called. You must then call
* [method@Gdk.Clipboard.read_value_finish] to get the resulting `GValue`.
*
* For local clipboard contents that are available in the given `GType`,
* the value will be copied directly. Otherwise, GDK will try to use
* [func@content_deserialize_async] to convert the clipboard's data.
@@ -895,9 +887,6 @@ gdk_clipboard_read_value_finish (GdkClipboard *clipboard,
*
* Asynchronously request the @clipboard contents converted to a `GdkPixbuf`.
*
* When the operation is finished @callback will be called. You must then
* call [method@Gdk.Clipboard.read_texture_finish] to get the result.
*
* This is a simple wrapper around [method@Gdk.Clipboard.read_value_async].
* Use that function or [method@Gdk.Clipboard.read_async] directly if you
* need more control over the operation.
@@ -960,9 +949,6 @@ gdk_clipboard_read_texture_finish (GdkClipboard *clipboard,
*
* Asynchronously request the @clipboard contents converted to a string.
*
* When the operation is finished @callback will be called. You must then
* call [method@Gdk.Clipboard.read_text_finish] to get the result.
*
* This is a simple wrapper around [method@Gdk.Clipboard.read_value_async].
* Use that function or [method@Gdk.Clipboard.read_async] directly if you
* need more control over the operation.

507
gdk/gdkcolor.c Normal file
View File

@@ -0,0 +1,507 @@
/* GDK - The GIMP Drawing Kit
*
* Copyright (C) 2021 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gdkcolorprivate.h"
#include "gdkcolorstateprivate.h"
#include "gdkrgbaprivate.h"
#include <lcms2.h>
/**
* GdkColor:
* @color_state: the color state to interpret the values in
* @values: the 3 coordinates that define the color, followed
* by the alpha value
*
* A `GdkColor` represents a color.
*
* The color state defines the meaning and range of the values.
* E.g., the srgb color state has r, g, b components representing
* red, green and blue with a range of [0,1], while the oklch color
* state has l, c, h components representing luminosity, chromaticity
* and hue, with l ranging from 0 to 1 and c from 0 to about 0.4, while
* h is interpreted as angle in degrees.
*
* value[3] is always the alpha value with a range of [0,1].
*
* Note that `GdkColor` is mainly intended for on-stack use, and does
* not take a reference to the @color_state, unless you use gdk_color_copy().
*/
/* {{{ Boxed type */
G_DEFINE_BOXED_TYPE (GdkColor, gdk_color,
gdk_color_copy, gdk_color_free)
/**
* gdk_color_copy:
* @self: a `GdkColor`
*
* Makes a copy of a `GdkColor`.
*
* The result must be freed through [method@Gdk.Color.free].
*
* Returns: A newly allocated `GdkColor`, with the same contents as @self
*
* Since: 4.16
*/
GdkColor *
gdk_color_copy (const GdkColor *self)
{
GdkColor *copy = g_new0 (GdkColor, 1);
g_set_object (&copy->color_state, self->color_state);
memcpy (copy->values, self->values, sizeof (float) * 4);
return copy;
}
/**
* gdk_color_free:
* @self: a `GdkColor`
*
* Frees a `Gdkcolor`.
*
* Since: 4.16
*/
void
gdk_color_free (GdkColor *self)
{
g_clear_pointer (&self->color_state, gdk_color_state_unref);
g_free (self);
}
/* }}} */
/* {{{ Public API */
void
(gdk_color_init) (GdkColor *self,
GdkColorState *color_state,
const float components[4])
{
_gdk_color_init (self, color_state, components);
}
void
(gdk_color_init_from_rgba) (GdkColor *self,
const GdkRGBA *rgba)
{
_gdk_color_init_from_rgba (self, rgba);
}
GdkColorState *
(gdk_color_get_color_state) (const GdkColor *self)
{
return _gdk_color_get_color_state (self);
}
const float *
(gdk_color_get_components) (const GdkColor *self)
{
return _gdk_color_get_components (self);
}
gboolean
(gdk_color_equal) (const GdkColor *self,
const GdkColor *other)
{
return _gdk_color_equal (self, other);
}
gboolean
(gdk_color_is_black) (const GdkColor *self)
{
return _gdk_color_is_black (self);
}
gboolean
(gdk_color_is_clear) (const GdkColor *self)
{
return _gdk_color_is_clear (self);
}
gboolean
(gdk_color_is_opaque) (const GdkColor *self)
{
return _gdk_color_is_opaque (self);
}
/* }}} */
/**
* gdk_color_convert:
* @self: the `GdkColor` to store the result in
* @color_state: the target color start
* @other: the `GdkColor` to convert
*
* Converts a given `GdkColor` to another color state.
*
* After the conversion, @self will represent the same
* color as @other in @color_state, to the degree possible.
*
* Different color states have different gamuts of colors
* they can represent, and converting a color to a color
* state with a smaller gamut may yield an 'out of gamut'
* result.
*
* Since: 4.16
*/
void
(gdk_color_convert) (GdkColor *self,
GdkColorState *color_state,
const GdkColor *other)
{
GdkColorStateTransform tf;
self->color_state = color_state;
gdk_color_state_transform_init (&tf, other->color_state, color_state, TRUE);
gdk_color_state_transform (&tf, other->values, self->values, 1);
gdk_color_state_transform_finish (&tf);
}
/**
* gdk_color_convert_rgba:
* @self: the `GdkColor` to store the result in
* @color_state: the target color state
* @rgba: the `GdkRGBA` to convert
*
* Converts a given `GdkRGBA` to the target @color_state.
*
* Since: 4.16
*/
void
gdk_color_convert_rgba (GdkColor *self,
GdkColorState *color_state,
const GdkRGBA *rgba)
{
GdkColor tmp = { (GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_SRGB),
{ rgba->red, rgba->green, rgba->blue, rgba->alpha } };
gdk_color_convert (self, color_state, &tmp);
}
/**
* gdk_color_mix:
* @self: the `GdkColor` to store the result in
* @color_start: the target color state
* @src1: the first color
* @src2: the second color
* @progress: the relative amount of @src2, from 0 to 1
*
* Mix two colors.
*
* This operation first converts @src1 and @src2 to the
* target @color_state, and then interpolates between them
* with a position given by @progress.
*
* Since: 4.16
*/
void
gdk_color_mix (GdkColor *self,
GdkColorState *color_state,
const GdkColor *src1,
const GdkColor *src2,
double progress)
{
if (src1->color_state != color_state)
{
GdkColor tmp;
gdk_color_convert (&tmp, color_state, src1);
gdk_color_mix (self, color_state, &tmp, src2, progress);
}
else if (src2->color_state != color_state)
{
GdkColor tmp;
gdk_color_convert (&tmp, color_state, src2);
gdk_color_mix (self, color_state, src1, &tmp, progress);
}
else
{
gsize i;
const float *s1, *s2;
float *d;
self->color_state = color_state;
self->values[3] = src1->values[3] * (1.0 - progress) + src2->values[3] * progress;
d = (float *) gdk_color_get_components (self);
s1 = gdk_color_get_components (src1);
s2 = gdk_color_get_components (src2);
if (self->values[3] == 0)
{
for (i = 0; i < 3; i++)
d[i] = s1[i] * (1.0 - progress) + s2[i] * progress;
}
else
{
for (i = 0; i < 3; i++)
d[i] = (s1[i] * src1->values[3] * (1.0 - progress) + s2[i] * src2->values[3] * progress) / self->values[3];
}
}
}
/*< private >
* gdk_color_parser_parse:
* @parser: the parser
* @color: location to store the parsed color
*
* Parses a string representation of colors that
* is inspired by CSS.
*
* Returns: `TRUE` if parsing succeeded
*
* Since: 4.16
*/
gboolean
gdk_color_parser_parse (GtkCssParser *parser,
GdkColor *color)
{
const GtkCssToken *token;
GdkRGBA rgba;
if (gtk_css_parser_has_function (parser, "color"))
{
GdkColorState *color_state;
float values[4];
const char *coords;
gtk_css_parser_start_block (parser);
if (gtk_css_parser_try_ident (parser, "srgb"))
{
coords = "rgb";
color_state = gdk_color_state_get_srgb ();
}
else if (gtk_css_parser_try_ident (parser, "srgb-linear"))
{
coords = "rgb";
color_state = gdk_color_state_get_srgb_linear ();
}
else if (gtk_css_parser_try_ident (parser, "oklab"))
{
coords = "lab";
color_state = gdk_color_state_get_oklab ();
}
else if (gtk_css_parser_try_ident (parser, "oklch"))
{
coords = "lch";
color_state = gdk_color_state_get_oklch ();
}
else
{
gtk_css_parser_error_syntax (parser, "Expected a valid color state");
gtk_css_parser_end_block (parser);
return FALSE;
}
for (int i = 0; i < 3; i++)
{
token = gtk_css_parser_get_token (parser);
if (gtk_css_token_is (token, GTK_CSS_TOKEN_PERCENTAGE))
{
float v = token->number.number;
switch (coords[i])
{
case 'l':
values[i] = CLAMP (v / 100.0, 0, 1);
break;
case 'a':
case 'b':
values[i] = v * 0.4 / 100.0;
break;
case 'c':
values[i] = MAX (0, v * 0.4 / 100.0);
break;
case 'h':
gtk_css_parser_error_syntax (parser, "Can't use percentage for hue");
gtk_css_parser_end_block (parser);
return FALSE;
default:
values[i] = CLAMP (v / 100.0, 0, 1);
break;
}
gtk_css_parser_consume_token (parser);
}
else if (gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_NUMBER) ||
gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_NUMBER) ||
gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) ||
gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
{
float v = token->number.number;
switch (coords[i])
{
case 'l':
values[i] = CLAMP (v, 0, 1);
break;
case 'a':
case 'b':
case 'h':
values[i] = v;
break;
case 'c':
values[i] = MAX (0, v);
break;
default:
values[i] = CLAMP (v, 0, 1);
break;
}
gtk_css_parser_consume_token (parser);
}
else
{
gtk_css_parser_error_syntax (parser, "Expected a number or percentage");
gtk_css_parser_end_block (parser);
return FALSE;
}
}
token = gtk_css_parser_get_token (parser);
if (gtk_css_token_is (token, GTK_CSS_TOKEN_EOF))
{
values[3] = 1;
}
else if (gtk_css_token_is_delim (token, '/'))
{
gtk_css_parser_consume_token (parser);
token = gtk_css_parser_get_token (parser);
if (gtk_css_token_is (token, GTK_CSS_TOKEN_PERCENTAGE))
{
values[3] = CLAMP (token->number.number / 100.0, 0, 1);
gtk_css_parser_consume_token (parser);
}
else if (gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_NUMBER) ||
gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_NUMBER) ||
gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) ||
gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER))
{
values[3] = CLAMP (token->number.number, 0, 1);
gtk_css_parser_consume_token (parser);
}
else
{
gtk_css_parser_error_syntax (parser, "Expected a number or percentage");
gtk_css_parser_end_block (parser);
return FALSE;
}
token = gtk_css_parser_get_token (parser);
if (!gtk_css_token_is (token, GTK_CSS_TOKEN_EOF))
{
gtk_css_parser_error_syntax (parser, "Garbage at the end of the value");
gtk_css_parser_end_block (parser);
return FALSE;
}
gtk_css_parser_consume_token (parser);
}
else
{
gtk_css_parser_error_syntax (parser, "Expected '/'");
gtk_css_parser_end_block (parser);
return FALSE;
}
gtk_css_parser_end_block (parser);
gdk_color_init (color, color_state, values);
return TRUE;
}
else if (gdk_rgba_parser_parse (parser, &rgba))
{
gdk_color_init_from_rgba (color, &rgba);
return TRUE;
}
return FALSE;
}
/**
* gdk_color_print:
* @self: a `GdkColor`
* @string: the string to print on
*
* Appends a representation of @self to @string.
*
* The representation is inspired by CSS3 colors,
* but not 100% identical, and looks like this:
*
* color(NAME V1 V2 V3 / ALPHA)
*
* where `NAME` is the name of the color state,
* `V1`, `V2`, `V3` and `ALPHA` are the components
* of the color. Alpha may be omitted if it is 1.
*
* Since: 4.16
*/
void
gdk_color_print (const GdkColor *self,
GString *string)
{
char buffer[48];
g_string_append (string, "color(");
g_string_append (string, gdk_color_state_get_name (self->color_state));
g_string_append_c (string, ' ');
g_ascii_dtostr (buffer, sizeof (buffer), self->values[0]);
g_string_append (string, buffer);
g_string_append_c (string, ' ');
g_ascii_dtostr (buffer, sizeof (buffer), self->values[1]);
g_string_append (string, buffer);
g_string_append_c (string, ' ');
g_ascii_dtostr (buffer, sizeof (buffer), self->values[2]);
g_string_append (string, buffer);
if (self->values[3] < 0.999)
{
g_string_append (string, " / ");
g_ascii_dtostr (buffer, sizeof (buffer), self->values[3]);
g_string_append (string, buffer);
}
g_string_append_c (string, ')');
}
/**
* gdk_color_to_string:
* @self: a `GdkColor`
*
* Returns a string representation @self.
*
* See [method@Gdk.Color.print] for details about
* the format.
*
* Returns: (transfer full): a newly allocated string
*
* Since: 4.16
*/
char *
gdk_color_to_string (const GdkColor *self)
{
GString *string = g_string_new ("");
gdk_color_print (self, string);
return g_string_free (string, FALSE);
}
/* vim:set foldmethod=marker expandtab: */

106
gdk/gdkcolor.h Normal file
View File

@@ -0,0 +1,106 @@
/* GDK - The GIMP Drawing Kit
*
* Copyright (C) 2021 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <gdk/gdktypes.h>
#include <gdk/gdkcolorstate.h>
#include <gdk/gdkrgba.h>
/* The interpretation of the first 3 components depends on the color state.
* values[3] is always alpha.
*/
struct _GdkColor
{
GdkColorState *color_state;
float values[4];
};
G_STATIC_ASSERT (sizeof (GdkColor) % sizeof (gpointer) == 0);
#define GDK_TYPE_COLOR (gdk_color_get_type ())
G_BEGIN_DECLS
#define GDK_COLOR_INIT(cs, c1, c2, c3, c4) \
(GdkColor) { (cs), { (c1), (c2), (c3), (c4) } }
#define GDK_COLOR_INIT_SRGB(c1, c2, c3, c4) \
GDK_COLOR_INIT (GDK_COLOR_STATE_SRGB, (c1), (c2), (c3), (c4) )
#define GDK_COLOR_INIT_RGBA(r) \
GDK_COLOR_INIT_SRGB ((r)->red, (r)->green, (r)->blue, (r)->alpha)
GDK_AVAILABLE_IN_4_16
GType gdk_color_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_4_16
GdkColor * gdk_color_copy (const GdkColor *self);
GDK_AVAILABLE_IN_4_16
void gdk_color_free (GdkColor *self);
GDK_AVAILABLE_IN_4_16
void gdk_color_init (GdkColor *self,
GdkColorState *color_state,
const float components[4]);
GDK_AVAILABLE_IN_4_16
void gdk_color_init_from_rgba (GdkColor *self,
const GdkRGBA *rgba);
GDK_AVAILABLE_IN_4_16
void gdk_color_convert (GdkColor *self,
GdkColorState *color_state,
const GdkColor *other);
GDK_AVAILABLE_IN_4_16
void gdk_color_convert_rgba (GdkColor *self,
GdkColorState *color_state,
const GdkRGBA *rgba);
GDK_AVAILABLE_IN_4_16
void gdk_color_mix (GdkColor *self,
GdkColorState *color_state,
const GdkColor *src1,
const GdkColor *src2,
double progress);
GDK_AVAILABLE_IN_4_16
void gdk_color_print (const GdkColor *self,
GString *string);
GDK_AVAILABLE_IN_4_16
char * gdk_color_to_string (const GdkColor *self);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_get_color_state (const GdkColor *self);
GDK_AVAILABLE_IN_4_16
const float * gdk_color_get_components (const GdkColor *self);
GDK_AVAILABLE_IN_4_16
gboolean gdk_color_equal (const GdkColor *color1,
const GdkColor *color2);
GDK_AVAILABLE_IN_4_16
gboolean gdk_color_is_black (const GdkColor *self);
GDK_AVAILABLE_IN_4_16
gboolean gdk_color_is_clear (const GdkColor *self);
GDK_AVAILABLE_IN_4_16
gboolean gdk_color_is_opaque (const GdkColor *self);
#include "gdkcolorimpl.h"
G_END_DECLS

122
gdk/gdkcolorimpl.h Normal file
View File

@@ -0,0 +1,122 @@
/* GDK - The GIMP Drawing Kit
*
* Copyright (C) 2021 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#define gdk_color_init(self, cs, comp) _gdk_color_init ((self), (cs), (comp))
static inline void
_gdk_color_init (GdkColor *self,
GdkColorState *color_state,
const float components[4])
{
self->color_state = color_state;
self->values[0] = components[0];
self->values[1] = components[1];
self->values[2] = components[2];
self->values[3] = components[3];
}
#define gdk_color_init_from_rgb(self, rgba) _gdk_color_init_from_rgba (self, rgba)
static inline void
_gdk_color_init_from_rgba (GdkColor *self,
const GdkRGBA *rgba)
{
self->color_state = GDK_COLOR_STATE_SRGB;
self->values[0] = rgba->red;
self->values[1] = rgba->green;
self->values[2] = rgba->blue;
self->values[3] = rgba->alpha;
}
#define gdk_color_get_color_state(self) _gdk_color_get_color_state (self)
static inline GdkColorState *
_gdk_color_get_color_state (const GdkColor *self)
{
return self->color_state;
}
#define gdk_color_get_components(self) _gdk_color_get_components (self)
static inline const float *
_gdk_color_get_components (const GdkColor *self)
{
return self->values;
}
#define gdk_color_equal(self, other) _gdk_color_equal (self, other)
static inline gboolean
_gdk_color_equal (const GdkColor *self,
const GdkColor *other)
{
return self->values[0] == other->values[0] &&
self->values[1] == other->values[1] &&
self->values[2] == other->values[2] &&
self->values[3] == other->values[3] &&
gdk_color_state_equal (self->color_state, other->color_state);
}
static inline gboolean
all_zero (const GdkColor *c)
{
return c->values[0] == 0 && c->values[1] == 0 && c->values[2] == 0;
}
#define gdk_color_is_black(self) _gdk_color_is_black (self)
static inline gboolean
_gdk_color_is_black (const GdkColor *self)
{
if (gdk_color_state_equal (self->color_state, GDK_COLOR_STATE_SRGB))
return all_zero (self);
else
{
GdkColor c;
gboolean res;
gdk_color_convert (&c, GDK_COLOR_STATE_SRGB, self);
res = all_zero (&c);
return res;
}
}
#define gdk_color_is_clear(self) _gdk_color_is_clear (self)
static inline gboolean
_gdk_color_is_clear (const GdkColor *self)
{
return self->values[3] < ((float) 0x00ff / (float) 0xffff);
}
#define gdk_color_is_opaque(self) _gdk_color_is_opaque (self)
static inline gboolean
_gdk_color_is_opaque (const GdkColor *self)
{
return self->values[3] > ((float)0xff00 / (float)0xffff);
}
#define gdk_color_convert(self, cs, other) _gdk_color_convert (self, cs, other)
static inline void
_gdk_color_convert (GdkColor *self,
GdkColorState *color_state,
const GdkColor *other)
{
if (gdk_color_state_equal (color_state, other->color_state))
{
gdk_color_init (self, color_state, other->values);
return;
}
(gdk_color_convert) (self, color_state, other);
}

27
gdk/gdkcolorprivate.h Normal file
View File

@@ -0,0 +1,27 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 2024, Red Hat, Inc
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "gdkcolor.h"
#include "gtk/css/gtkcssparserprivate.h"
gboolean gdk_color_parser_parse (GtkCssParser *parser,
GdkColor *color);

950
gdk/gdkcolorstate.c Normal file
View File

@@ -0,0 +1,950 @@
/* gdkcolorstate.c
*
* Copyright 2024 Matthias Clasen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gdkcolorstateprivate.h"
#include <glib/gi18n-lib.h>
#include "gtk/gtkcolorutilsprivate.h"
/**
* GdkColorState:
*
* A `GdkColorState` object provides the information to interpret
* colors and pixels in a variety of ways.
*
* They are also known as
* [*color spaces*](https://en.wikipedia.org/wiki/Color_space).
*
* Crucially, GTK knows how to convert colors from one color
* state to another.
*
* `GdkColorState objects are immutable and therefore threadsafe.
*
* Since 4.16
*/
static GdkColorStateClass * get_class (GdkColorState *self);
G_DEFINE_BOXED_TYPE (GdkColorState, gdk_color_state,
gdk_color_state_ref, gdk_color_state_unref);
/* {{{ Public API */
GdkColorState *
(gdk_color_state_ref) (GdkColorState *self)
{
return _gdk_color_state_ref (self);
}
void
(gdk_color_state_unref) (GdkColorState *self)
{
_gdk_color_state_unref (self);
}
GdkColorState *
(gdk_color_state_get_srgb) (void)
{
return _gdk_color_state_get_srgb ();
}
GdkColorState *
(gdk_color_state_get_srgb_linear) (void)
{
return _gdk_color_state_get_srgb_linear ();
}
GdkColorState *
(gdk_color_state_get_hsl) (void)
{
return _gdk_color_state_get_hsl ();
}
GdkColorState *
(gdk_color_state_get_hwb) (void)
{
return _gdk_color_state_get_hwb ();
}
GdkColorState *
(gdk_color_state_get_oklab) (void)
{
return _gdk_color_state_get_oklab ();
}
GdkColorState *
(gdk_color_state_get_oklch) (void)
{
return _gdk_color_state_get_oklch ();
}
GdkColorState *
(gdk_color_state_get_display_p3) (void)
{
return _gdk_color_state_get_display_p3 ();
}
GdkColorState *
(gdk_color_state_get_xyz) (void)
{
return _gdk_color_state_get_xyz ();
}
GdkColorState *
(gdk_color_state_get_rec2020) (void)
{
return _gdk_color_state_get_rec2020 ();
}
GdkColorState *
(gdk_color_state_get_rec2100_pq) (void)
{
return _gdk_color_state_get_rec2100_pq ();
}
GdkColorState *
(gdk_color_state_get_rec2100_linear) (void)
{
return _gdk_color_state_get_rec2100_linear ();
}
/**
* gdk_color_state_equal:
* @self: a `GdkColorState`
* @other: another `GdkColorStatee`
*
* Compares two `GdkColorStates` for equality.
*
* Note that this function is not guaranteed to be perfect and two objects
* describing the same color state may compare not equal. However, different
* color states will never compare equal.
*
* Returns: %TRUE if the two color states compare equal
*
* Since: 4.16
*/
gboolean
(gdk_color_state_equal) (GdkColorState *self,
GdkColorState *other)
{
return _gdk_color_state_equal (self, other);
}
/**
* gdk_color_state_is_linear:
* @self: a `GdkColorState`
*
* Returns whether the color state is linear.
*
* Returns: `TRUE` if the color state is linear
* Since: 4.16
*/
gboolean
gdk_color_state_is_linear (GdkColorState *self)
{
return get_class (self)->is_linear (self);
}
/**
* gdk_color_state_save_to_icc_profile:
* @self: a `GdkColorState`
* @error: Return location for an error
*
* Saves the color state to an
* [ICC profile](https://en.wikipedia.org/wiki/ICC_profile).
*
* Some color states cannot be represented as ICC profiles.
* In that case, @error will be set and %NULL will be returned.
*
* Returns: (nullable): A new `GBytes` containing the ICC profile
*
* Since: 4.16
*/
GBytes *
gdk_color_state_save_to_icc_profile (GdkColorState *self,
GError **error)
{
return get_class (self)->save_to_icc_profile (self, error);
}
/**
* gdk_color_state_save_to_cicp_data:
* @self: a `GdkColorState`
* @color_primaries: return location for color primaries
* @transfer_characteristics: return location for transfer characteristics
* @matrix_coefficients: return location for matrix_coefficients
* @full_range: return location for the full range flag
* @error: Return location for an error
*
* Saves the color state as
* [CICP](https://en.wikipedia.org/wiki/Coding-independent_code_points)
* data.
*
* Some color states cannot be represented as CICP data.
* In that case, @error will be set and `FALSE` will be returned.
*
* Returns: (nullable): `TRUE` if the out arguments were set
*
* Since: 4.16
*/
gboolean
gdk_color_state_save_to_cicp_data (GdkColorState *self,
int *color_primaries,
int *transfer_characteristics,
int *matrix_coefficients,
gboolean *full_range,
GError **error)
{
return get_class (self)->save_to_cicp_data (self,
color_primaries,
transfer_characteristics,
matrix_coefficients,
full_range,
error);
}
/* }}} */
/* {{{ ICC implementation */
#define GDK_LCMS_COLOR_STATE(c) ((GdkLcmsColorState *)(c))
typedef struct {
GdkColorState state;
cmsHPROFILE lcms_profile;
} GdkLcmsColorState;
/* {{{ Helpers */
static cmsHPROFILE
gdk_lcms_color_state_get_lcms_profile (GdkColorState *self)
{
g_return_val_if_fail (GDK_IS_LCMS_COLOR_STATE (self), NULL);
return GDK_LCMS_COLOR_STATE (self)->lcms_profile;
}
static cmsHPROFILE
gdk_lcms_get_srgb_profile (void)
{
return cmsCreate_sRGBProfile ();
}
static cmsHPROFILE
gdk_lcms_get_srgb_linear_profile (void)
{
cmsToneCurve *curve;
cmsHPROFILE profile;
curve = cmsBuildGamma (NULL, 1.0);
profile = cmsCreateRGBProfile (&(cmsCIExyY) {
0.3127, 0.3290, 1.0
},
&(cmsCIExyYTRIPLE) {
{ 0.6400, 0.3300, 1.0 },
{ 0.3000, 0.6000, 1.0 },
{ 0.1500, 0.0600, 1.0 }
},
(cmsToneCurve*[3]) { curve, curve, curve });
cmsFreeToneCurve (curve);
return profile;
}
static GBytes *
gdk_lcms_save_profile (cmsHPROFILE profile,
GError **error)
{
cmsUInt32Number size;
guchar *data;
size = 0;
if (!cmsSaveProfileToMem (profile, NULL, &size))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Could not prepare ICC profile"));
return NULL;
}
data = g_malloc (size);
if (!cmsSaveProfileToMem (profile, data, &size))
{
g_free (data);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Failed to save ICC profile"));
return NULL;
}
return g_bytes_new_take (data, size);
}
/* }}} */
/* {{{ GdkColorState vfuncs */
static void
gdk_lcms_color_state_free (GdkColorState *state)
{
GdkLcmsColorState *self = (GdkLcmsColorState *) state;
cmsCloseProfile (self->lcms_profile);
g_free (self);
}
static gboolean
gdk_lcms_color_state_equal (GdkColorState *state1,
GdkColorState *state2)
{
GBytes *icc1, *icc2;
gboolean res;
icc1 = gdk_color_state_save_to_icc_profile (state1, NULL);
icc2 = gdk_color_state_save_to_icc_profile (state2, NULL);
res = g_bytes_equal (icc1, icc2);
g_bytes_unref (icc1);
g_bytes_unref (icc2);
return res;
}
static gboolean
gdk_lcms_color_state_is_linear (GdkColorState *state)
{
return FALSE; /* FIXME */
}
static GBytes *
gdk_lcms_color_state_save_to_icc_profile (GdkColorState *state,
GError **error)
{
GdkLcmsColorState *self = GDK_LCMS_COLOR_STATE (state);
return gdk_lcms_save_profile (self->lcms_profile, error);
}
static gboolean
gdk_lcms_color_state_save_to_cicp_data (GdkColorState *self,
int *color_primaries,
int *transfer_characteristics,
int *matrix_coefficients,
gboolean *full_range,
GError **error)
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
_("This color state does not support CICP data"));
return FALSE;
}
static const char *
gdk_lcms_color_state_get_name (GdkColorState *self)
{
static char buffer[48];
g_snprintf (buffer, sizeof (buffer), "lcms color state %p", self);
return buffer;
}
static guint
gdk_lcms_color_state_get_min_depth (GdkColorState *self)
{
return GDK_MEMORY_U16; /* ? */
}
static int
gdk_lcms_color_state_get_hue_coord (GdkColorState *self)
{
return -1;
}
static GdkColorStateClass LCMS_COLOR_STATE_CLASS =
{
GDK_TYPE_LCMS_COLOR_STATE,
gdk_lcms_color_state_free,
gdk_lcms_color_state_equal,
gdk_lcms_color_state_is_linear,
gdk_lcms_color_state_save_to_icc_profile,
gdk_lcms_color_state_save_to_cicp_data,
gdk_lcms_color_state_get_name,
gdk_lcms_color_state_get_min_depth,
gdk_lcms_color_state_get_hue_coord,
};
/* }}} */
/* {{{ Private API */
GdkColorState *
gdk_color_state_new_from_lcms_profile (cmsHPROFILE lcms_profile)
{
GdkLcmsColorState *self;
self= g_new0 (GdkLcmsColorState, 1);
self->state.klass = &LCMS_COLOR_STATE_CLASS;
self->state.ref_count = 1;
self->lcms_profile = lcms_profile;
return (GdkColorState *) self;
}
/* }}} */
/* {{{ Public API */
/**
* gdk_color_state_new_from_icc_profile:
* @icc_profile: The ICC profiles given as a `GBytes`
* @error: Return location for an error
*
* Creates a new color state for the given ICC profile data.
*
* if the profile is not valid, %NULL is returned and an error
* is raised.
*
* Returns: a new `GdkColorState` or %NULL on error
*
* Since: 4.16
*/
GdkColorState *
gdk_color_state_new_from_icc_profile (GBytes *icc_profile,
GError **error)
{
cmsHPROFILE lcms_profile;
const guchar *data;
gsize size;
g_return_val_if_fail (icc_profile != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
data = g_bytes_get_data (icc_profile, &size);
lcms_profile = cmsOpenProfileFromMem (data, size);
if (lcms_profile == NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Failed to load ICC profile"));
return NULL;
}
return gdk_color_state_new_from_lcms_profile (lcms_profile);
}
/* }}} */
/* }}} */
/* {{{ Named implementation */
static gboolean
gdk_named_color_state_is_linear (GdkColorState *self)
{
switch (GDK_NAMED_COLOR_STATE_ID (self))
{
case GDK_COLOR_STATE_ID_SRGB_LINEAR:
case GDK_COLOR_STATE_ID_OKLAB:
case GDK_COLOR_STATE_ID_OKLCH:
case GDK_COLOR_STATE_ID_XYZ:
case GDK_COLOR_STATE_ID_REC2100_LINEAR:
return TRUE;
case GDK_COLOR_STATE_ID_SRGB:
case GDK_COLOR_STATE_ID_HSL:
case GDK_COLOR_STATE_ID_HWB:
case GDK_COLOR_STATE_ID_DISPLAY_P3:
case GDK_COLOR_STATE_ID_REC2020:
case GDK_COLOR_STATE_ID_REC2100_PQ:
return FALSE;
default:
g_assert_not_reached ();
}
}
static GBytes *
gdk_named_color_state_save_to_icc_profile (GdkColorState *self,
GError **error)
{
cmsHPROFILE profile;
switch (GDK_NAMED_COLOR_STATE_ID (self))
{
case GDK_COLOR_STATE_ID_SRGB:
profile = gdk_lcms_get_srgb_profile ();
break;
case GDK_COLOR_STATE_ID_SRGB_LINEAR:
profile = gdk_lcms_get_srgb_linear_profile ();
break;
case GDK_COLOR_STATE_ID_OKLAB:
case GDK_COLOR_STATE_ID_OKLCH:
case GDK_COLOR_STATE_ID_HSL:
case GDK_COLOR_STATE_ID_HWB:
case GDK_COLOR_STATE_ID_DISPLAY_P3:
case GDK_COLOR_STATE_ID_XYZ:
case GDK_COLOR_STATE_ID_REC2020:
case GDK_COLOR_STATE_ID_REC2100_PQ:
case GDK_COLOR_STATE_ID_REC2100_LINEAR:
profile = NULL;
break;
default:
g_assert_not_reached ();
}
if (profile)
{
GBytes *bytes;
bytes = gdk_lcms_save_profile (profile, error);
cmsCloseProfile (profile);
return bytes;
}
else
{
g_set_error (error,
G_IO_ERROR, G_IO_ERROR_FAILED,
_("ICC profile not supported for this color state"));
return NULL;
}
}
static gboolean
gdk_named_color_state_save_to_cicp_data (GdkColorState *self,
int *color_primaries,
int *transfer_characteristics,
int *matrix_coefficients,
gboolean *full_range,
GError **error)
{
switch (GDK_NAMED_COLOR_STATE_ID (self))
{
case GDK_COLOR_STATE_ID_SRGB:
*color_primaries = 0;
*transfer_characteristics = 13;
*matrix_coefficients = 0;
*full_range = TRUE;
return TRUE;
case GDK_COLOR_STATE_ID_SRGB_LINEAR:
*color_primaries = 0;
*transfer_characteristics = 8;
*matrix_coefficients = 0;
*full_range = TRUE;
return TRUE;
case GDK_COLOR_STATE_ID_REC2100_PQ:
*color_primaries = 9;
*transfer_characteristics = 16;
*matrix_coefficients = 0;
*full_range = TRUE;
return TRUE;
case GDK_COLOR_STATE_ID_REC2100_LINEAR:
*color_primaries = 9;
*transfer_characteristics = 8;
*matrix_coefficients = 0;
*full_range = TRUE;
return TRUE;
case GDK_COLOR_STATE_ID_DISPLAY_P3:
*color_primaries = 12;
*transfer_characteristics = 13;
*matrix_coefficients = 0;
*full_range = TRUE;
return TRUE;
case GDK_COLOR_STATE_ID_HSL:
case GDK_COLOR_STATE_ID_HWB:
case GDK_COLOR_STATE_ID_OKLAB:
case GDK_COLOR_STATE_ID_OKLCH:
case GDK_COLOR_STATE_ID_XYZ:
case GDK_COLOR_STATE_ID_REC2020:
break;
default:
g_assert_not_reached ();
}
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
_("This color state does not support CICP data"));
return FALSE;
}
const char *
gdk_color_state_get_name_from_id (GdkColorStateId id)
{
const char *names[] = {
"srgb", "srgb-linear", "hsl", "hwb",
"oklab", "oklch", "display-p3", "xyz",
"rec2020", "rec2100-pq", "rec2100-linear",
};
return names[(id - 1) >> 1];
}
static const char *
gdk_named_color_state_get_name (GdkColorState *self)
{
return gdk_color_state_get_name_from_id (GDK_NAMED_COLOR_STATE_ID (self));
}
static guint
gdk_named_color_state_get_min_depth (GdkColorState *self)
{
switch (GDK_NAMED_COLOR_STATE_ID (self))
{
case GDK_COLOR_STATE_ID_OKLAB:
case GDK_COLOR_STATE_ID_OKLCH:
case GDK_COLOR_STATE_ID_HSL:
case GDK_COLOR_STATE_ID_HWB:
case GDK_COLOR_STATE_ID_DISPLAY_P3:
case GDK_COLOR_STATE_ID_XYZ:
case GDK_COLOR_STATE_ID_REC2020:
case GDK_COLOR_STATE_ID_REC2100_PQ:
case GDK_COLOR_STATE_ID_REC2100_LINEAR:
case GDK_COLOR_STATE_ID_SRGB_LINEAR:
return GDK_MEMORY_FLOAT16;
case GDK_COLOR_STATE_ID_SRGB:
return GDK_MEMORY_U8;
default:
g_assert_not_reached ();
}
}
static int
gdk_named_color_state_get_hue_coord (GdkColorState *in)
{
switch (GDK_NAMED_COLOR_STATE_ID (in))
{
case GDK_COLOR_STATE_ID_SRGB:
case GDK_COLOR_STATE_ID_SRGB_LINEAR:
case GDK_COLOR_STATE_ID_OKLAB:
case GDK_COLOR_STATE_ID_DISPLAY_P3:
case GDK_COLOR_STATE_ID_XYZ:
case GDK_COLOR_STATE_ID_REC2020:
case GDK_COLOR_STATE_ID_REC2100_PQ:
case GDK_COLOR_STATE_ID_REC2100_LINEAR:
return -1;
case GDK_COLOR_STATE_ID_HSL:
case GDK_COLOR_STATE_ID_HWB:
return 0;
case GDK_COLOR_STATE_ID_OKLCH:
return 2;
default:
g_assert_not_reached ();
}
}
static GdkColorStateClass NAMED_COLOR_STATE_CLASS =
{
GDK_TYPE_NAMED_COLOR_STATE,
NULL,
NULL,
gdk_named_color_state_is_linear,
gdk_named_color_state_save_to_icc_profile,
gdk_named_color_state_save_to_cicp_data,
gdk_named_color_state_get_name,
gdk_named_color_state_get_min_depth,
gdk_named_color_state_get_hue_coord,
};
/* }}} */
/* {{{ CICP support */
GdkColorState *
gdk_color_state_new_from_cicp_data (int color_primaries,
int transfer_characteristics,
int matrix_coefficients,
gboolean full_range)
{
/* FIXME We don't support these */
if (!full_range || matrix_coefficients != 0)
return NULL;
/* Look for cases we can handle */
if (color_primaries == 0 && transfer_characteristics == 13)
return gdk_color_state_get_srgb ();
else if (color_primaries == 0 && transfer_characteristics == 8)
return gdk_color_state_get_srgb_linear ();
else if (color_primaries == 9 && transfer_characteristics == 16)
return gdk_color_state_get_rec2100_pq ();
else if (color_primaries == 9 && transfer_characteristics == 8)
return gdk_color_state_get_rec2100_linear ();
else if (color_primaries == 12 && transfer_characteristics == 13)
return gdk_color_state_get_display_p3 ();
return NULL;
}
/* }}} */
/* {{{ Private API */
static GdkColorStateClass *
get_class (GdkColorState *self)
{
if (GDK_IS_NAMED_COLOR_STATE (self))
return &NAMED_COLOR_STATE_CLASS;
return self->klass;
}
GdkMemoryDepth
gdk_color_state_get_min_depth (GdkColorState *self)
{
return (GdkMemoryDepth) get_class (self)->get_min_depth (self);
}
const char *
gdk_color_state_get_name (GdkColorState *self)
{
return get_class (self)->get_name (self);
}
int
gdk_color_state_get_hue_coord (GdkColorState *self)
{
return get_class (self)->get_hue_coord (self);
}
/* }}} */
/* {{{ Conversion */
#define two_step(name, func1, func2) \
static void \
name (float r, float g, float b, \
float *x, float *y, float *z) \
{ \
func1 (r, g, b, x, y, z); \
func2 (*x, *y, *z, x, y, z); \
}
/* A full complement of xyz <> anything step functions */
two_step (srgb_to_xyz, gtk_rgb_to_linear_srgb, gtk_linear_srgb_to_xyz)
two_step (xyz_to_srgb, gtk_xyz_to_linear_srgb, gtk_linear_srgb_to_rgb)
two_step (hsl_to_xyz, gtk_hsl_to_rgb, srgb_to_xyz)
two_step (xyz_to_hsl, xyz_to_srgb, gtk_rgb_to_hsl)
two_step (hwb_to_xyz, gtk_hwb_to_rgb, srgb_to_xyz)
two_step (xyz_to_hwb, xyz_to_srgb, gtk_rgb_to_hwb)
two_step (oklab_to_xyz, gtk_oklab_to_linear_srgb, gtk_linear_srgb_to_xyz)
two_step (xyz_to_oklab, gtk_xyz_to_linear_srgb, gtk_linear_srgb_to_oklab)
two_step (oklch_to_xyz, gtk_oklch_to_oklab, oklab_to_xyz)
two_step (xyz_to_oklch, xyz_to_oklab, gtk_oklab_to_oklch)
two_step (p3_to_xyz, gtk_p3_to_rgb, srgb_to_xyz)
two_step (xyz_to_p3, xyz_to_srgb, gtk_rgb_to_p3)
two_step (rec2100_linear_to_xyz, gtk_rec2100_linear_to_rec2020_linear, gtk_rec2020_linear_to_xyz)
two_step (xyz_to_rec2100_linear, gtk_xyz_to_rec2020_linear, gtk_rec2020_linear_to_rec2100_linear)
two_step (rec2100_pq_to_xyz, gtk_rec2100_pq_to_rec2100_linear, rec2100_linear_to_xyz)
two_step (xyz_to_rec2100_pq, xyz_to_rec2100_linear, gtk_rec2100_linear_to_rec2100_pq)
static struct {
GdkColorStateId n1;
GdkColorStateId n2;
StepFunc func;
} functions[] = {
{ GDK_COLOR_STATE_ID_SRGB, GDK_COLOR_STATE_ID_SRGB_LINEAR, gtk_rgb_to_linear_srgb },
{ GDK_COLOR_STATE_ID_SRGB, GDK_COLOR_STATE_ID_HSL, gtk_rgb_to_hsl },
{ GDK_COLOR_STATE_ID_SRGB, GDK_COLOR_STATE_ID_HWB, gtk_rgb_to_hwb },
{ GDK_COLOR_STATE_ID_SRGB, GDK_COLOR_STATE_ID_OKLAB, gtk_rgb_to_oklab },
{ GDK_COLOR_STATE_ID_SRGB, GDK_COLOR_STATE_ID_DISPLAY_P3, gtk_rgb_to_p3 },
{ GDK_COLOR_STATE_ID_SRGB, GDK_COLOR_STATE_ID_XYZ, srgb_to_xyz },
{ GDK_COLOR_STATE_ID_SRGB_LINEAR, GDK_COLOR_STATE_ID_SRGB, gtk_linear_srgb_to_rgb },
{ GDK_COLOR_STATE_ID_SRGB_LINEAR, GDK_COLOR_STATE_ID_OKLAB, gtk_linear_srgb_to_oklab },
{ GDK_COLOR_STATE_ID_SRGB_LINEAR, GDK_COLOR_STATE_ID_XYZ, gtk_linear_srgb_to_xyz },
{ GDK_COLOR_STATE_ID_HSL, GDK_COLOR_STATE_ID_SRGB, gtk_hsl_to_rgb },
{ GDK_COLOR_STATE_ID_HSL, GDK_COLOR_STATE_ID_XYZ, hsl_to_xyz },
{ GDK_COLOR_STATE_ID_HWB, GDK_COLOR_STATE_ID_SRGB, gtk_hwb_to_rgb },
{ GDK_COLOR_STATE_ID_HWB, GDK_COLOR_STATE_ID_XYZ, hwb_to_xyz },
{ GDK_COLOR_STATE_ID_OKLAB, GDK_COLOR_STATE_ID_SRGB, gtk_oklab_to_rgb },
{ GDK_COLOR_STATE_ID_OKLAB, GDK_COLOR_STATE_ID_SRGB_LINEAR, gtk_oklab_to_linear_srgb },
{ GDK_COLOR_STATE_ID_OKLAB, GDK_COLOR_STATE_ID_OKLCH, gtk_oklab_to_oklch },
{ GDK_COLOR_STATE_ID_OKLAB, GDK_COLOR_STATE_ID_XYZ, oklab_to_xyz },
{ GDK_COLOR_STATE_ID_OKLCH, GDK_COLOR_STATE_ID_OKLAB, gtk_oklch_to_oklab },
{ GDK_COLOR_STATE_ID_OKLCH, GDK_COLOR_STATE_ID_XYZ, oklch_to_xyz },
{ GDK_COLOR_STATE_ID_DISPLAY_P3, GDK_COLOR_STATE_ID_SRGB, gtk_p3_to_rgb },
{ GDK_COLOR_STATE_ID_DISPLAY_P3, GDK_COLOR_STATE_ID_XYZ, p3_to_xyz },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_SRGB, xyz_to_srgb },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_SRGB_LINEAR, gtk_xyz_to_linear_srgb },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_HSL, xyz_to_hsl },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_HWB, xyz_to_hwb },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_OKLAB, xyz_to_oklab },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_OKLCH, xyz_to_oklch },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_DISPLAY_P3, xyz_to_p3 },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_REC2020, gtk_xyz_to_rec2020 },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_REC2100_PQ, xyz_to_rec2100_pq },
{ GDK_COLOR_STATE_ID_XYZ, GDK_COLOR_STATE_ID_REC2100_LINEAR, xyz_to_rec2100_linear },
{ GDK_COLOR_STATE_ID_REC2020, GDK_COLOR_STATE_ID_XYZ, gtk_rec2020_to_xyz },
{ GDK_COLOR_STATE_ID_REC2100_PQ, GDK_COLOR_STATE_ID_XYZ, rec2100_pq_to_xyz },
{ GDK_COLOR_STATE_ID_REC2100_PQ, GDK_COLOR_STATE_ID_REC2100_LINEAR, gtk_rec2100_pq_to_rec2100_linear },
{ GDK_COLOR_STATE_ID_REC2100_LINEAR, GDK_COLOR_STATE_ID_REC2100_PQ, gtk_rec2100_linear_to_rec2100_pq },
{ GDK_COLOR_STATE_ID_REC2100_LINEAR, GDK_COLOR_STATE_ID_XYZ, rec2100_linear_to_xyz },
};
static StepFunc
find_function (GdkColorStateId n1, GdkColorStateId n2)
{
for (int k = 0; k < G_N_ELEMENTS (functions); k++)
{
if (functions[k].n1 == n1 && functions[k].n2 == n2)
return functions[k].func;
}
return NULL;
}
void
gdk_color_state_transform_init (GdkColorStateTransform *tf,
GdkColorState *from,
GdkColorState *to,
gboolean copy_alpha)
{
memset (tf, 0, sizeof (GdkColorStateTransform));
if (GDK_IS_NAMED_COLOR_STATE (from) &&
GDK_IS_NAMED_COLOR_STATE (to))
{
tf->step1 = find_function (GDK_NAMED_COLOR_STATE_ID (from),
GDK_NAMED_COLOR_STATE_ID (to));
if (tf->step1 == NULL && from != to)
{
tf->step1 = find_function (GDK_NAMED_COLOR_STATE_ID (from),
GDK_COLOR_STATE_ID_XYZ);
tf->step2 = find_function (GDK_COLOR_STATE_ID_XYZ,
GDK_NAMED_COLOR_STATE_ID (to));
}
}
else
{
cmsHPROFILE profile1, profile2;
if (GDK_IS_LCMS_COLOR_STATE (from))
profile1 = gdk_lcms_color_state_get_lcms_profile (from);
else
profile1 = NULL;
if (GDK_IS_LCMS_COLOR_STATE (to))
profile2 = gdk_lcms_color_state_get_lcms_profile (to);
else
profile2 = NULL;
if (profile1 && profile2)
{
tf->transform = cmsCreateTransform (profile1,
TYPE_RGBA_FLT,
profile2,
TYPE_RGBA_FLT,
INTENT_PERCEPTUAL,
copy_alpha ? cmsFLAGS_COPY_ALPHA : 0);
}
else if (GDK_IS_NAMED_COLOR_STATE (from) && profile2)
{
tf->step1 = find_function (GDK_NAMED_COLOR_STATE_ID (from),
GDK_COLOR_STATE_ID_XYZ);
profile1 = cmsCreateXYZProfile ();
tf->transform = cmsCreateTransform (profile1,
TYPE_RGBA_FLT,
profile2,
TYPE_RGBA_FLT,
INTENT_PERCEPTUAL,
copy_alpha ? cmsFLAGS_COPY_ALPHA : 0);
tf->cms_first = FALSE;
}
else if (profile1 && GDK_IS_NAMED_COLOR_STATE (to))
{
profile2 = cmsCreateXYZProfile ();
tf->transform = cmsCreateTransform (profile1,
TYPE_RGBA_FLT,
profile2,
TYPE_RGBA_FLT,
INTENT_PERCEPTUAL,
copy_alpha ? cmsFLAGS_COPY_ALPHA : 0);
tf->step1 = find_function (GDK_COLOR_STATE_ID_XYZ,
GDK_NAMED_COLOR_STATE_ID (to));
tf->cms_first = TRUE;
}
else
g_assert_not_reached ();
g_clear_pointer (&profile1, cmsCloseProfile);
g_clear_pointer (&profile2, cmsCloseProfile);
}
tf->copy_alpha = copy_alpha;
}
void
gdk_color_state_transform_finish (GdkColorStateTransform *tf)
{
if (tf->transform)
cmsDeleteTransform (tf->transform);
}
void
gdk_color_state_transform (GdkColorStateTransform *tf,
const float *src,
float *dst,
int width)
{
if (tf->copy_alpha)
memcpy (dst, src, sizeof (float) * 4 * width);
else
{
for (int i = 0; i < width * 4; i += 4)
{
dst[i] = src[i];
dst[i + 1] = src[i + 1];
dst[i + 2] = src[i + 2];
}
}
if (tf->cms_first && tf->transform)
cmsDoTransform (tf->transform, dst, dst, width);
if (tf->step1 && tf->step2)
{
for (int i = 0; i < width * 4; i += 4)
{
tf->step1 (dst[i], dst[i+1], dst[i+2], &dst[i], &dst[i+1], &dst[i+2]);
tf->step2 (dst[i], dst[i+1], dst[i+2], &dst[i], &dst[i+1], &dst[i+2]);
}
}
else if (tf->step1)
{
for (int i = 0; i < width * 4; i += 4)
tf->step1 (dst[i], dst[i+1], dst[i+2], &dst[i], &dst[i+1], &dst[i+2]);
}
if (!tf->cms_first && tf->transform)
cmsDoTransform (tf->transform, dst, dst, width);
}
/* }}} */
/* vim:set foldmethod=marker expandtab: */

104
gdk/gdkcolorstate.h Normal file
View File

@@ -0,0 +1,104 @@
/* gdkcolorstate.h
*
* Copyright 2024 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gdk/gdk.h> can be included directly."
#endif
#include <gdk/gdktypes.h>
G_BEGIN_DECLS
#define GDK_TYPE_COLOR_STATE (gdk_color_state_get_type ())
GDK_AVAILABLE_IN_4_16
GType gdk_color_state_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_ref (GdkColorState *self);
GDK_AVAILABLE_IN_4_16
void gdk_color_state_unref (GdkColorState *self);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_srgb (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_srgb_linear (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_hsl (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_hwb (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_oklab (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_oklch (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_display_p3 (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_xyz (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_rec2020 (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_rec2100_pq (void);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_get_rec2100_linear (void);
GDK_AVAILABLE_IN_4_16
gboolean gdk_color_state_equal (GdkColorState *self,
GdkColorState *other);
GDK_AVAILABLE_IN_4_16
gboolean gdk_color_state_is_linear (GdkColorState *self);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_new_from_icc_profile (GBytes *icc_profile,
GError **error);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_color_state_new_from_cicp_data (int color_primaries,
int transfer_characteristics,
int matrix_coefficients,
gboolean full_range);
GDK_AVAILABLE_IN_4_16
GBytes * gdk_color_state_save_to_icc_profile (GdkColorState *self,
GError **error);
GDK_AVAILABLE_IN_4_16
gboolean gdk_color_state_save_to_cicp_data (GdkColorState *self,
int *color_primaries,
int *transfer_characteristic,
int *matrix_coefficients,
gboolean *full_range,
GError **error);
#include "gdkcolorstateimpl.h"
G_END_DECLS

204
gdk/gdkcolorstateimpl.h Normal file
View File

@@ -0,0 +1,204 @@
/* gdkcolorstateimpl.h
*
* Copyright 2024 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
typedef enum
{
GDK_COLOR_STATE_ID_SRGB = 1,
GDK_COLOR_STATE_ID_SRGB_LINEAR = 3,
GDK_COLOR_STATE_ID_HSL = 5,
GDK_COLOR_STATE_ID_HWB = 7,
GDK_COLOR_STATE_ID_OKLAB = 9,
GDK_COLOR_STATE_ID_OKLCH = 11,
GDK_COLOR_STATE_ID_DISPLAY_P3 = 13,
GDK_COLOR_STATE_ID_XYZ = 15,
GDK_COLOR_STATE_ID_REC2020 = 17,
GDK_COLOR_STATE_ID_REC2100_PQ = 19,
GDK_COLOR_STATE_ID_REC2100_LINEAR = 21,
} GdkColorStateId;
enum
{
GDK_TYPE_NAMED_COLOR_STATE,
GDK_TYPE_LCMS_COLOR_STATE,
};
typedef struct _GdkColorStateClass GdkColorStateClass;
struct _GdkColorState
{
GdkColorStateClass *klass;
int ref_count;
};
struct _GdkColorStateClass
{
int type;
void (* free) (GdkColorState *self);
gboolean (* equal) (GdkColorState *self,
GdkColorState *other);
gboolean (* is_linear) (GdkColorState *self);
GBytes * (* save_to_icc_profile) (GdkColorState *self,
GError **error);
gboolean (* save_to_cicp_data) (GdkColorState *self,
int *color_primaries,
int *transfer_characteristics,
int *matrix_coefficients,
gboolean *full_range,
GError **error);
const char * (* get_name) (GdkColorState *self);
guint (* get_min_depth) (GdkColorState *self);
int (* get_hue_coord) (GdkColorState *self);
};
#define GDK_NAMED_COLOR_STATE_ID(c) ((GdkColorStateId) (GPOINTER_TO_INT (c)))
#define GDK_IS_NAMED_COLOR_STATE(c) ((GPOINTER_TO_INT(c)) & 1)
#define GDK_IS_LCMS_COLOR_STATE(c) ((c)->klass->type == GDK_TYPE_LCMS_COLOR_STATE)
#define gdk_color_state_ref(self) _gdk_color_state_ref (self)
static inline GdkColorState *
_gdk_color_state_ref (GdkColorState *self)
{
if (GDK_IS_NAMED_COLOR_STATE (self))
return self;
self->ref_count++;
return self;
}
#define gdk_color_state_unref(self) _gdk_color_state_unref (self)
static inline void
_gdk_color_state_unref (GdkColorState *self)
{
if (GDK_IS_NAMED_COLOR_STATE (self))
return;
self->ref_count--;
if (self->ref_count == 0)
self->klass->free (self);
}
#define GDK_COLOR_STATE_SRGB ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_SRGB))
#define GDK_COLOR_STATE_SRGB_LINEAR ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_SRGB_LINEAR))
#define GDK_COLOR_STATE_HSL ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_HSL))
#define GDK_COLOR_STATE_HWB ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_HWB))
#define GDK_COLOR_STATE_OKLAB ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_OKLAB))
#define GDK_COLOR_STATE_OKLCH ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_OKLCH))
#define GDK_COLOR_STATE_DISPLAY_P3 ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_DISPLAY_P3))
#define GDK_COLOR_STATE_XYZ ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_XYZ))
#define GDK_COLOR_STATE_REC2020 ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_REC2020))
#define GDK_COLOR_STATE_REC2100_PQ ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_REC2100_PQ))
#define GDK_COLOR_STATE_REC2100_LINEAR ((GdkColorState *) GINT_TO_POINTER (GDK_COLOR_STATE_ID_REC2100_LINEAR))
#define gdk_color_state_get_srgb() _gdk_color_state_get_srgb ()
static inline GdkColorState *
_gdk_color_state_get_srgb (void)
{
return GDK_COLOR_STATE_SRGB;
}
#define gdk_color_state_get_srgb_linear() _gdk_color_state_get_srgb_linear ()
static inline GdkColorState *
_gdk_color_state_get_srgb_linear (void)
{
return GDK_COLOR_STATE_SRGB_LINEAR;
}
#define gdk_color_state_get_hsl() _gdk_color_state_get_hsl ()
static inline GdkColorState *
_gdk_color_state_get_hsl (void)
{
return GDK_COLOR_STATE_HSL;
}
#define gdk_color_state_get_hwb() _gdk_color_state_get_hwb ()
static inline GdkColorState *
_gdk_color_state_get_hwb (void)
{
return GDK_COLOR_STATE_HWB;
}
#define gdk_color_state_get_oklab() _gdk_color_state_get_oklab ()
static inline GdkColorState *
_gdk_color_state_get_oklab (void)
{
return GDK_COLOR_STATE_OKLAB;
}
#define gdk_color_state_get_oklch() _gdk_color_state_get_oklch ()
static inline GdkColorState *
_gdk_color_state_get_oklch (void)
{
return GDK_COLOR_STATE_OKLCH;
}
#define gdk_color_state_get_display_p3() _gdk_color_state_get_display_p3 ()
static inline GdkColorState *
_gdk_color_state_get_display_p3 (void)
{
return GDK_COLOR_STATE_DISPLAY_P3;
}
#define gdk_color_state_get_xyz() _gdk_color_state_get_xyz ()
static inline GdkColorState *
_gdk_color_state_get_xyz (void)
{
return GDK_COLOR_STATE_XYZ;
}
#define gdk_color_state_get_rec2020() _gdk_color_state_get_rec2020 ()
static inline GdkColorState *
_gdk_color_state_get_rec2020 (void)
{
return GDK_COLOR_STATE_REC2020;
}
#define gdk_color_state_get_rec2100_pq() _gdk_color_state_get_rec2100_pq ()
static inline GdkColorState *
_gdk_color_state_get_rec2100_pq (void)
{
return GDK_COLOR_STATE_REC2100_PQ;
}
#define gdk_color_state_get_rec2100_linear() _gdk_color_state_get_rec2100_linear ()
static inline GdkColorState *
_gdk_color_state_get_rec2100_linear (void)
{
return GDK_COLOR_STATE_REC2100_LINEAR;
}
#define gdk_color_state_equal(a,b) _gdk_color_state_equal ((a), (b))
static inline gboolean
_gdk_color_state_equal (GdkColorState *self,
GdkColorState *other)
{
if (self == other)
return TRUE;
if (GDK_IS_NAMED_COLOR_STATE (self) || GDK_IS_NAMED_COLOR_STATE (other))
return FALSE;
if (self->klass != other->klass)
return FALSE;
return self->klass->equal (self, other);
}

View File

@@ -0,0 +1,39 @@
#pragma once
#include "gdkcolorstate.h"
#include "gdkmemoryformatprivate.h"
#include <lcms2.h>
const char * gdk_color_state_get_name (GdkColorState *color_state);
GdkMemoryDepth gdk_color_state_get_min_depth (GdkColorState *color_state);
int gdk_color_state_get_hue_coord (GdkColorState *color_state);
typedef void (* StepFunc) (float s0, float s1, float s2,
float *d0, float *d1, float *d2);
typedef struct _GdkColorStateTransform GdkColorStateTransform;
struct _GdkColorStateTransform
{
gpointer transform;
StepFunc step1;
StepFunc step2;
gboolean cms_first;
gboolean copy_alpha;
};
void gdk_color_state_transform_init (GdkColorStateTransform *tf,
GdkColorState *from,
GdkColorState *to,
gboolean copy_alpha);
void gdk_color_state_transform_finish (GdkColorStateTransform *tf);
void gdk_color_state_transform (GdkColorStateTransform *tf,
const float *src,
float *dst,
int width);
GdkColorState *gdk_color_state_new_from_lcms_profile (cmsHPROFILE profile);
const char *gdk_color_state_get_name_from_id (GdkColorStateId id);

View File

@@ -540,9 +540,6 @@ deserialize_not_found (GdkContentDeserializer *deserializer)
*
* The default I/O priority is %G_PRIORITY_DEFAULT (i.e. 0), and lower numbers
* indicate a higher priority.
*
* When the operation is finished, @callback will be called. You must then
* call [func@Gdk.content_deserialize_finish] to get the result of the operation.
*/
void
gdk_content_deserialize_async (GInputStream *stream,

View File

@@ -279,10 +279,6 @@ gdk_content_provider_content_changed (GdkContentProvider *provider)
* Asynchronously writes the contents of @provider to @stream in the given
* @mime_type.
*
* When the operation is finished @callback will be called. You must then call
* [method@Gdk.ContentProvider.write_mime_type_finish] to get the result
* of the operation.
*
* The given mime type does not need to be listed in the formats returned by
* [method@Gdk.ContentProvider.ref_formats]. However, if the given `GType` is
* not supported, `G_IO_ERROR_NOT_SUPPORTED` will be reported.

View File

@@ -546,9 +546,6 @@ serialize_not_found (GdkContentSerializer *serializer)
*
* The default I/O priority is %G_PRIORITY_DEFAULT (i.e. 0), and lower numbers
* indicate a higher priority.
*
* When the operation is finished, @callback will be called. You must then
* call [func@Gdk.content_serialize_finish] to get the result of the operation.
*/
void
gdk_content_serialize_async (GOutputStream *stream,

View File

@@ -52,7 +52,7 @@ GdkCursor* gdk_cursor_new_from_name (const char *name,
GdkCursor *fallback);
/**
* GdkCursorGetTestureCallback:
* GdkCursorGetTextureCallback:
* @cursor: the `GdkCursor`
* @cursor_size: the nominal cursor size, in application pixels
* @scale: the device scale

View File

@@ -40,6 +40,7 @@ typedef enum {
GDK_DEBUG_OFFLOAD = 1 << 12,
/* flags below are influencing behavior */
GDK_DEBUG_SRGB = 1 << 13,
GDK_DEBUG_PORTALS = 1 << 14,
GDK_DEBUG_NO_PORTALS = 1 << 15,
GDK_DEBUG_GL_DISABLE = 1 << 16,

View File

@@ -24,6 +24,7 @@
#include "gdkdmabuffourccprivate.h"
#include "gdkdmabuftextureprivate.h"
#include "gdkmemoryformatprivate.h"
#include "gdkcolorstate.h"
#ifdef HAVE_DMABUF
#include <sys/mman.h>
@@ -2062,12 +2063,15 @@ out:
void
gdk_dmabuf_download_mmap (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride)
{
GdkMemoryFormat src_format = gdk_texture_get_format (texture);
GdkColorState *src_color_state = gdk_texture_get_color_state (texture);
if (format == src_format)
if (format == src_format &&
gdk_color_state_equal (color_state, src_color_state))
gdk_dmabuf_do_download_mmap (texture, data, stride);
else
{
@@ -2083,8 +2087,10 @@ gdk_dmabuf_download_mmap (GdkTexture *texture,
gdk_dmabuf_do_download_mmap (texture, src_data, src_stride);
gdk_memory_convert (data, stride, format,
src_data, src_stride, src_format,
gdk_memory_convert (data, stride,
format, color_state,
src_data, src_stride,
src_format, src_color_state,
width, height);
g_free (src_data);

View File

@@ -35,6 +35,7 @@ void
gdk_dmabuf_downloader_download (GdkDmabufDownloader *self,
GdkDmabufTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride)
{
@@ -43,6 +44,6 @@ gdk_dmabuf_downloader_download (GdkDmabufDownloader *self,
g_return_if_fail (GDK_IS_DMABUF_DOWNLOADER (self));
iface = GDK_DMABUF_DOWNLOADER_GET_IFACE (self);
iface->download (self, texture, format, data, stride);
iface->download (self, texture, format, color_state, data, stride);
}

View File

@@ -20,6 +20,7 @@ struct _GdkDmabufDownloaderInterface
void (* download) (GdkDmabufDownloader *downloader,
GdkDmabufTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride);
};
@@ -31,6 +32,7 @@ gboolean gdk_dmabuf_downloader_supports (GdkDmabufDownlo
void gdk_dmabuf_downloader_download (GdkDmabufDownloader *downloader,
GdkDmabufTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride);

View File

@@ -163,6 +163,8 @@ gdk_dmabuf_get_egl_downloader (GdkDisplay *display,
return NULL;
previous = gdk_gl_context_get_current ();
if (previous)
g_object_ref (previous);
formats = gdk_dmabuf_formats_builder_new ();
external = gdk_dmabuf_formats_builder_new ();
@@ -194,7 +196,10 @@ gdk_dmabuf_get_egl_downloader (GdkDisplay *display,
}
if (previous)
gdk_gl_context_make_current (previous);
{
gdk_gl_context_make_current (previous);
g_object_unref (previous);
}
return GDK_DMABUF_DOWNLOADER (renderer);
}

View File

@@ -27,6 +27,7 @@ struct _GdkDmabuf
GdkDmabufFormats * gdk_dmabuf_get_mmap_formats (void) G_GNUC_CONST;
void gdk_dmabuf_download_mmap (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride);

View File

@@ -62,6 +62,13 @@ struct _GdkDmabufTextureClass
GdkTextureClass parent_class;
};
/**
* gdk_dmabuf_error_quark:
*
* Registers an error quark for [class@Gdk.DmabufTexture] errors.
*
* Returns: the error quark
**/
G_DEFINE_QUARK (gdk-dmabuf-error-quark, gdk_dmabuf_error)
G_DEFINE_TYPE (GdkDmabufTexture, gdk_dmabuf_texture, GDK_TYPE_TEXTURE)
@@ -89,6 +96,7 @@ struct _Download
{
GdkDmabufTexture *texture;
GdkMemoryFormat format;
GdkColorState *color_state;
guchar *data;
gsize stride;
volatile int spinlock;
@@ -102,6 +110,7 @@ gdk_dmabuf_texture_invoke_callback (gpointer data)
gdk_dmabuf_downloader_download (download->texture->downloader,
download->texture,
download->format,
download->color_state,
download->data,
download->stride);
@@ -113,16 +122,17 @@ gdk_dmabuf_texture_invoke_callback (gpointer data)
static void
gdk_dmabuf_texture_download (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride)
{
GdkDmabufTexture *self = GDK_DMABUF_TEXTURE (texture);
Download download = { self, format, data, stride, 0 };
Download download = { self, format, color_state, data, stride, 0 };
if (self->downloader == NULL)
{
#ifdef HAVE_DMABUF
gdk_dmabuf_download_mmap (texture, format, data, stride);
gdk_dmabuf_download_mmap (texture, format, color_state, data, stride);
#endif
return;
}
@@ -193,6 +203,7 @@ gdk_dmabuf_texture_new_from_builder (GdkDmabufTextureBuilder *builder,
self = g_object_new (GDK_TYPE_DMABUF_TEXTURE,
"width", width,
"height", height,
"color-state", gdk_dmabuf_texture_builder_get_color_state (builder),
NULL);
g_set_object (&self->display, display);

View File

@@ -24,6 +24,7 @@
#include "gdkdebugprivate.h"
#include "gdkdisplay.h"
#include "gdkenumtypes.h"
#include "gdkcolorstate.h"
#include "gdkdmabuftextureprivate.h"
#include "gdkdmabuftexturebuilderprivate.h"
@@ -41,6 +42,8 @@ struct _GdkDmabufTextureBuilder
GdkDmabuf dmabuf;
GdkColorState *color_state;
GdkTexture *update_texture;
cairo_region_t *update_region;
};
@@ -124,6 +127,7 @@ enum
PROP_MODIFIER,
PROP_PREMULTIPLIED,
PROP_N_PLANES,
PROP_COLOR_STATE,
PROP_UPDATE_REGION,
PROP_UPDATE_TEXTURE,
@@ -141,6 +145,7 @@ gdk_dmabuf_texture_builder_dispose (GObject *object)
g_clear_object (&self->update_texture);
g_clear_pointer (&self->update_region, cairo_region_destroy);
g_clear_pointer (&self->color_state, gdk_color_state_unref);
G_OBJECT_CLASS (gdk_dmabuf_texture_builder_parent_class)->dispose (object);
}
@@ -183,6 +188,10 @@ gdk_dmabuf_texture_builder_get_property (GObject *object,
g_value_set_uint (value, self->dmabuf.n_planes);
break;
case PROP_COLOR_STATE:
g_value_set_boxed (value, self->color_state);
break;
case PROP_UPDATE_REGION:
g_value_set_boxed (value, self->update_region);
break;
@@ -235,6 +244,10 @@ gdk_dmabuf_texture_builder_set_property (GObject *object,
gdk_dmabuf_texture_builder_set_n_planes (self, g_value_get_uint (value));
break;
case PROP_COLOR_STATE:
gdk_dmabuf_texture_builder_set_color_state (self, g_value_get_boxed (value));
break;
case PROP_UPDATE_REGION:
gdk_dmabuf_texture_builder_set_update_region (self, g_value_get_boxed (value));
break;
@@ -347,6 +360,18 @@ gdk_dmabuf_texture_builder_class_init (GdkDmabufTextureBuilderClass *klass)
1, GDK_DMABUF_MAX_PLANES, 1,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GdkDmabufTextureBuilder:color-state: (attributes org.gtk.Property.get=gdk_dmabuf_texture_builder_get_color_state org.gtk.Property.set=gdk_dmabuf_texture_builder_set_color_state)
*
* The color state of the texture.
*
* Since: 4.16
*/
properties[PROP_COLOR_STATE] =
g_param_spec_boxed ("color-state", NULL, NULL,
GDK_TYPE_COLOR_STATE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GdkDmabufTextureBuilder:update-region: (attributes org.gtk.Property.get=gdk_dmabuf_texture_builder_get_update_region org.gtk.Property.set=gdk_dmabuf_texture_builder_set_update_region)
*
@@ -383,6 +408,8 @@ gdk_dmabuf_texture_builder_init (GdkDmabufTextureBuilder *self)
for (int i = 0; i < GDK_DMABUF_MAX_PLANES; i++)
self->dmabuf.planes[i].fd = -1;
self->color_state = gdk_color_state_get_srgb ();
}
/**
@@ -843,6 +870,48 @@ gdk_dmabuf_texture_builder_set_offset (GdkDmabufTextureBuilder *self,
self->dmabuf.planes[plane].offset = offset;
}
/**
* gdk_dmabuf_texture_builder_get_color_state: (attributes org.gtk.Method.get_property=color-state)
* @self: a `GdkDmabufTextureBuilder`
*
* Gets the color state previously set via gdk_dmabuf_texture_builder_set_color_state().
*
* Returns: the color state
*
* Since: 4.16
*/
GdkColorState *
gdk_dmabuf_texture_builder_get_color_state (GdkDmabufTextureBuilder *self)
{
g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), NULL);
return self->color_state;
}
/**
* gdk_dmabuf_texture_builder_set_color_state: (attributes org.gtk.Method.set_property=color-state)
* @self: a `GdkDmabufTextureBuilder`
* @color_state: a `GdkColorState`
*
* Sets the color state for the texture.
*
* Since: 4.16
*/
void
gdk_dmabuf_texture_builder_set_color_state (GdkDmabufTextureBuilder *self,
GdkColorState *color_state)
{
g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self));
g_return_if_fail (color_state != NULL);
if (self->color_state != color_state)
{
g_clear_pointer (&self->color_state, gdk_color_state_unref);
self->color_state = gdk_color_state_ref (color_state);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR_STATE]);
}
}
/**
* gdk_dmabuf_texture_builder_get_update_texture: (attributes org.gtk.Method.get_property=update-texture)
* @self: a `GdkDmabufTextureBuilder`

View File

@@ -100,6 +100,12 @@ void gdk_dmabuf_texture_builder_set_offset (GdkDmabufT
unsigned int plane,
unsigned int offset);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_dmabuf_texture_builder_get_color_state (GdkDmabufTextureBuilder *self);
GDK_AVAILABLE_IN_4_16
void gdk_dmabuf_texture_builder_set_color_state (GdkDmabufTextureBuilder *self,
GdkColorState *color_state);
GDK_AVAILABLE_IN_4_14
GdkTexture * gdk_dmabuf_texture_builder_get_update_texture (GdkDmabufTextureBuilder *self) G_GNUC_PURE;
GDK_AVAILABLE_IN_4_14

View File

@@ -849,10 +849,6 @@ gdk_drop_read_value_internal (GdkDrop *self,
* Asynchronously request the drag operation's contents converted
* to the given @type.
*
* When the operation is finished @callback will be called. You must
* then call [method@Gdk.Drop.read_value_finish] to get the resulting
* `GValue`.
*
* For local drag-and-drop operations that are available in the given
* `GType`, the value will be copied directly. Otherwise, GDK will
* try to use [func@Gdk.content_deserialize_async] to convert the data.

View File

@@ -1371,6 +1371,8 @@ gdk_event_get_modifier_state (GdkEvent *event)
* Extract the event surface relative x/y coordinates from an event.
*
* This position is in [surface coordinates](coordinates.html).
*
* Returns: whether the positions were set
*/
gboolean
gdk_event_get_position (GdkEvent *event,

View File

@@ -192,13 +192,6 @@ compute_smooth_frame_time (GdkFrameClock *clock,
* and new_frame_time >= old_frame_time. */
frames_passed = (new_frame_time - smoothed_frame_time_base + frame_interval / 2) / frame_interval;
if (frames_passed > 1)
gdk_profiler_add_markf ((smoothed_frame_time_base - (frame_interval * (frames_passed-1))) * 1000L,
frame_interval * (frames_passed-1) * 1000L,
"Dropped Frames",
"%u frames may have been dropped",
frames_passed-1);
/* We use an approximately whole number of frames in the future from
* last smoothed frame time. This way we avoid minor jitter in the
* frame times making the animation speed uneven, but still animate

View File

@@ -152,6 +152,13 @@ enum {
static GParamSpec *properties[LAST_PROP] = { NULL, };
/**
* gdk_gl_error_quark:
*
* Registers an error quark for [class@Gdk.GLContext] errors.
*
* Returns: the error quark
**/
G_DEFINE_QUARK (gdk-gl-error-quark, gdk_gl_error)
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkGLContext, gdk_gl_context, GDK_TYPE_DRAW_CONTEXT)
@@ -1956,8 +1963,6 @@ gdk_gl_context_get_glsl_version_string (GdkGLContext *self)
return "#version 310 es";
else if (gdk_gl_version_greater_equal (&priv->gl_version, &GDK_GL_VERSION_INIT (3, 0)))
return "#version 300 es";
else if (gdk_gl_version_greater_equal (&priv->gl_version, &GDK_GL_VERSION_INIT (3, 0)))
return "#version 300 es";
else
return "#version 100";
}

View File

@@ -24,6 +24,7 @@
#include "gdkglcontextprivate.h"
#include "gdkmemoryformatprivate.h"
#include "gdkmemorytextureprivate.h"
#include "gdkcolorstate.h"
#include <epoxy/gl.h>
@@ -136,6 +137,7 @@ typedef struct _Download Download;
struct _Download
{
GdkMemoryFormat format;
GdkColorState *color_state;
guchar *data;
gsize stride;
};
@@ -185,13 +187,15 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
{
GdkTexture *texture = GDK_TEXTURE (self);
GdkMemoryFormat format;
GdkColorState *color_state;
gsize expected_stride;
Download *download = download_;
GLint gl_internal_format;
GLenum gl_format, gl_type;
GLint gl_swizzle[4];
format = gdk_texture_get_format (texture),
format = gdk_texture_get_format (texture);
color_state = gdk_texture_get_color_state (texture);
expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
if (!gdk_gl_context_get_use_es (context) &&
@@ -225,9 +229,11 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
gdk_memory_convert (download->data,
download->stride,
download->format,
download->color_state,
pixels,
stride,
format,
color_state,
texture->width,
texture->height);
@@ -377,9 +383,11 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
gdk_memory_convert (download->data,
download->stride,
download->format,
download->color_state,
pixels,
stride,
actual_format,
color_state,
texture->width,
texture->height);
@@ -393,6 +401,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
static void
gdk_gl_texture_download (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride)
{
@@ -401,11 +410,12 @@ gdk_gl_texture_download (GdkTexture *texture,
if (self->saved)
{
gdk_texture_do_download (self->saved, format, data, stride);
gdk_texture_do_download (self->saved, format, color_state, data, stride);
return;
}
download.format = format;
download.color_state = color_state;
download.data = data;
download.stride = stride;
@@ -471,8 +481,7 @@ gdk_gl_texture_release (GdkGLTexture *self)
g_return_if_fail (self->saved == NULL);
texture = GDK_TEXTURE (self);
self->saved = GDK_TEXTURE (gdk_memory_texture_from_texture (texture,
gdk_texture_get_format (texture)));
self->saved = GDK_TEXTURE (gdk_memory_texture_from_texture (texture));
drop_gl_resources (self);
}
@@ -488,6 +497,7 @@ gdk_gl_texture_new_from_builder (GdkGLTextureBuilder *builder,
self = g_object_new (GDK_TYPE_GL_TEXTURE,
"width", gdk_gl_texture_builder_get_width (builder),
"height", gdk_gl_texture_builder_get_height (builder),
"color-state", gdk_gl_texture_builder_get_color_state (builder),
NULL);
self->context = g_object_ref (gdk_gl_texture_builder_get_context (builder));

View File

@@ -23,6 +23,7 @@
#include "gdkenumtypes.h"
#include "gdkglcontext.h"
#include "gdkcolorstate.h"
#include "gdkgltextureprivate.h"
#include <cairo-gobject.h>
@@ -38,6 +39,7 @@ struct _GdkGLTextureBuilder
GdkMemoryFormat format;
gboolean has_mipmap;
gpointer sync;
GdkColorState *color_state;
GdkTexture *update_texture;
cairo_region_t *update_region;
@@ -75,6 +77,7 @@ enum
PROP_HEIGHT,
PROP_ID,
PROP_SYNC,
PROP_COLOR_STATE,
PROP_UPDATE_REGION,
PROP_UPDATE_TEXTURE,
PROP_WIDTH,
@@ -95,6 +98,7 @@ gdk_gl_texture_builder_dispose (GObject *object)
g_clear_object (&self->update_texture);
g_clear_pointer (&self->update_region, cairo_region_destroy);
g_clear_pointer (&self->color_state, gdk_color_state_unref);
G_OBJECT_CLASS (gdk_gl_texture_builder_parent_class)->dispose (object);
}
@@ -133,6 +137,10 @@ gdk_gl_texture_builder_get_property (GObject *object,
g_value_set_pointer (value, self->sync);
break;
case PROP_COLOR_STATE:
g_value_set_object (value, self->color_state);
break;
case PROP_UPDATE_REGION:
g_value_set_boxed (value, self->update_region);
break;
@@ -185,6 +193,10 @@ gdk_gl_texture_builder_set_property (GObject *object,
gdk_gl_texture_builder_set_sync (self, g_value_get_pointer (value));
break;
case PROP_COLOR_STATE:
gdk_gl_texture_builder_set_color_state (self, g_value_get_object (value));
break;
case PROP_UPDATE_REGION:
gdk_gl_texture_builder_set_update_region (self, g_value_get_boxed (value));
break;
@@ -286,6 +298,18 @@ gdk_gl_texture_builder_class_init (GdkGLTextureBuilderClass *klass)
g_param_spec_pointer ("sync", NULL, NULL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GdkGLTextureBuilder:color-state: (attributes org.gtk.Property.get=gdk_gl_texture_builder_get_color_state org.gtk.Property.set=gdk_gl_texture_builder_set_color_state)
*
* The color state of the texture.
*
* Since: 4.16
*/
properties[PROP_COLOR_STATE] =
g_param_spec_boxed ("color-state", NULL, NULL,
GDK_TYPE_COLOR_STATE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GdkGLTextureBuilder:update-region: (attributes org.gtk.Property.get=gdk_gl_texture_builder_get_update_region org.gtk.Property.set=gdk_gl_texture_builder_set_update_region)
*
@@ -329,6 +353,7 @@ static void
gdk_gl_texture_builder_init (GdkGLTextureBuilder *self)
{
self->format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
self->color_state = gdk_color_state_get_srgb ();
}
/**
@@ -616,6 +641,48 @@ gdk_gl_texture_builder_set_sync (GdkGLTextureBuilder *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SYNC]);
}
/**
* gdk_gl_texture_builder_get_color_state: (attributes org.gtk.Method.get_property=color-state)
* @self: a `GdkGLTextureBuilder`
*
* Gets the color state previously set via gdk_gl_texture_builder_set_color_state().
*
* Returns: the color state
*
* Since: 4.16
*/
GdkColorState *
gdk_gl_texture_builder_get_color_state (GdkGLTextureBuilder *self)
{
g_return_val_if_fail (GDK_IS_GL_TEXTURE_BUILDER (self), NULL);
return self->color_state;
}
/**
* gdk_gl_texture_builder_set_color_state: (attributes org.gtk.Method.set_property=color-state)
* @self: a `GdkGLTextureBuilder`
* @color_state: a `GdkColorState`
*
* Sets the color state for the texture.
*
* Since: 4.16
*/
void
gdk_gl_texture_builder_set_color_state (GdkGLTextureBuilder *self,
GdkColorState *color_state)
{
g_return_if_fail (GDK_IS_GL_TEXTURE_BUILDER (self));
g_return_if_fail (color_state != NULL);
if (self->color_state != color_state)
{
g_clear_pointer (&self->color_state, gdk_color_state_unref);
self->color_state = gdk_color_state_ref (color_state);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR_STATE]);
}
}
/**
* gdk_gl_texture_builder_get_format: (attributes org.gtk.Method.get_property=format)
* @self: a `GdkGLTextureBuilder`

View File

@@ -76,6 +76,12 @@ GDK_AVAILABLE_IN_4_12
void gdk_gl_texture_builder_set_sync (GdkGLTextureBuilder *self,
gpointer sync);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_gl_texture_builder_get_color_state (GdkGLTextureBuilder *self);
GDK_AVAILABLE_IN_4_16
void gdk_gl_texture_builder_set_color_state (GdkGLTextureBuilder *self,
GdkColorState *color_state);
GDK_AVAILABLE_IN_4_12
GdkTexture * gdk_gl_texture_builder_get_update_texture (GdkGLTextureBuilder *self) G_GNUC_PURE;
GDK_AVAILABLE_IN_4_12

View File

@@ -23,8 +23,9 @@
#include "gdkdmabuffourccprivate.h"
#include "gdkglcontextprivate.h"
#include "gdkcolorstateprivate.h"
#include "gsk/gl/fp16private.h"
#include "gtk/gtkcolorutilsprivate.h"
#include <epoxy/gl.h>
@@ -327,6 +328,7 @@ ADD_ALPHA_FUNC(r8g8b8_to_a8b8g8r8, 0, 1, 2, 3, 2, 1, 0)
struct _GdkMemoryFormatDescription
{
const char *name;
GdkMemoryAlpha alpha;
GdkMemoryFormat premultiplied;
GdkMemoryFormat straight;
@@ -366,6 +368,7 @@ struct _GdkMemoryFormatDescription
static const GdkMemoryFormatDescription memory_formats[] = {
[GDK_MEMORY_B8G8R8A8_PREMULTIPLIED] = {
.name = "*BGRA8",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_B8G8R8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_B8G8R8A8,
@@ -394,6 +397,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = b8g8r8a8_premultiplied_from_float,
},
[GDK_MEMORY_A8R8G8B8_PREMULTIPLIED] = {
.name = "*ARGB8",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A8R8G8B8_PREMULTIPLIED,
.straight = GDK_MEMORY_A8R8G8B8,
@@ -422,6 +426,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = a8r8g8b8_premultiplied_from_float,
},
[GDK_MEMORY_R8G8B8A8_PREMULTIPLIED] = {
.name = "*RGBA8",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_R8G8B8A8,
@@ -449,6 +454,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r8g8b8a8_premultiplied_from_float,
},
[GDK_MEMORY_A8B8G8R8_PREMULTIPLIED] = {
.name = "*ABGR8",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A8B8G8R8_PREMULTIPLIED,
.straight = GDK_MEMORY_A8B8G8R8,
@@ -477,6 +483,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = a8b8g8r8_premultiplied_from_float,
},
[GDK_MEMORY_B8G8R8A8] = {
.name = "BGRA8",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_B8G8R8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_B8G8R8A8,
@@ -505,6 +512,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = b8g8r8a8_from_float,
},
[GDK_MEMORY_A8R8G8B8] = {
.name = "ARGB8",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_A8R8G8B8_PREMULTIPLIED,
.straight = GDK_MEMORY_A8R8G8B8,
@@ -533,6 +541,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = a8r8g8b8_from_float,
},
[GDK_MEMORY_R8G8B8A8] = {
.name = "RGBA8",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_R8G8B8A8,
@@ -560,6 +569,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r8g8b8a8_from_float,
},
[GDK_MEMORY_A8B8G8R8] = {
.name = "ABGR8",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_A8B8G8R8_PREMULTIPLIED,
.straight = GDK_MEMORY_A8B8G8R8,
@@ -588,6 +598,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = a8b8g8r8_from_float,
},
[GDK_MEMORY_B8G8R8X8] = {
.name = "BGRX8",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_B8G8R8X8,
.straight = GDK_MEMORY_B8G8R8X8,
@@ -617,6 +628,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = b8g8r8x8_from_float,
},
[GDK_MEMORY_X8R8G8B8] = {
.name = "XRGB8",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_X8R8G8B8,
.straight = GDK_MEMORY_X8R8G8B8,
@@ -646,6 +658,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = x8r8g8b8_from_float,
},
[GDK_MEMORY_R8G8B8X8] = {
.name = "RGBX8",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R8G8B8X8,
.straight = GDK_MEMORY_R8G8B8X8,
@@ -674,6 +687,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r8g8b8x8_from_float,
},
[GDK_MEMORY_X8B8G8R8] = {
.name = "XBGR8",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_X8B8G8R8,
.straight = GDK_MEMORY_X8B8G8R8,
@@ -703,6 +717,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = x8b8g8r8_from_float,
},
[GDK_MEMORY_R8G8B8] = {
.name = "RGB8",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R8G8B8,
.straight = GDK_MEMORY_R8G8B8,
@@ -731,6 +746,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r8g8b8_from_float,
},
[GDK_MEMORY_B8G8R8] = {
.name = "BGR8",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_B8G8R8,
.straight = GDK_MEMORY_B8G8R8,
@@ -760,6 +776,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = b8g8r8_from_float,
},
[GDK_MEMORY_R16G16B16] = {
.name = "RGB16",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R16G16B16,
.straight = GDK_MEMORY_R16G16B16,
@@ -791,6 +808,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r16g16b16_from_float,
},
[GDK_MEMORY_R16G16B16A16_PREMULTIPLIED] = {
.name = "*RGBA16",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_R16G16B16A16_PREMULTIPLIED,
.straight = GDK_MEMORY_R16G16B16A16,
@@ -821,6 +839,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r16g16b16a16_from_float,
},
[GDK_MEMORY_R16G16B16A16] = {
.name = "RGBA16",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_R16G16B16A16_PREMULTIPLIED,
.straight = GDK_MEMORY_R16G16B16A16,
@@ -851,6 +870,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r16g16b16a16_from_float,
},
[GDK_MEMORY_R16G16B16_FLOAT] = {
.name = "RGBA16f",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R16G16B16_FLOAT,
.straight = GDK_MEMORY_R16G16B16_FLOAT,
@@ -881,6 +901,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r16g16b16_float_from_float,
},
[GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED] = {
.name = "*RGBA16f",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED,
.straight = GDK_MEMORY_R16G16B16A16_FLOAT,
@@ -910,6 +931,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r16g16b16a16_float_from_float,
},
[GDK_MEMORY_R16G16B16A16_FLOAT] = {
.name = "RGBA16f",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED,
.straight = GDK_MEMORY_R16G16B16A16_FLOAT,
@@ -939,6 +961,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r16g16b16a16_float_from_float,
},
[GDK_MEMORY_R32G32B32_FLOAT] = {
.name = "RGB32f",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R32G32B32_FLOAT,
.straight = GDK_MEMORY_R32G32B32_FLOAT,
@@ -969,6 +992,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r32g32b32_float_from_float,
},
[GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED] = {
.name = "*RGBA32f",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED,
.straight = GDK_MEMORY_R32G32B32A32_FLOAT,
@@ -998,6 +1022,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r32g32b32a32_float_from_float,
},
[GDK_MEMORY_R32G32B32A32_FLOAT] = {
.name = "RGBA32f",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED,
.straight = GDK_MEMORY_R32G32B32A32_FLOAT,
@@ -1027,6 +1052,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = r32g32b32a32_float_from_float,
},
[GDK_MEMORY_G8A8_PREMULTIPLIED] = {
.name = "*GA8",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_G8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_G8A8,
@@ -1055,6 +1081,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = g8a8_premultiplied_from_float,
},
[GDK_MEMORY_G8A8] = {
.name = "GA8",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_G8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_G8A8,
@@ -1083,6 +1110,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = g8a8_from_float,
},
[GDK_MEMORY_G8] = {
.name = "G8",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_G8,
.straight = GDK_MEMORY_G8,
@@ -1111,6 +1139,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = g8_from_float,
},
[GDK_MEMORY_G16A16_PREMULTIPLIED] = {
.name = "*GA16",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_G16A16_PREMULTIPLIED,
.straight = GDK_MEMORY_G16A16,
@@ -1142,6 +1171,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = g16a16_premultiplied_from_float,
},
[GDK_MEMORY_G16A16] = {
.name = "GA16",
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_G16A16_PREMULTIPLIED,
.straight = GDK_MEMORY_G16A16,
@@ -1173,6 +1203,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = g16a16_from_float,
},
[GDK_MEMORY_G16] = {
.name = "G16",
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_G16,
.straight = GDK_MEMORY_G16,
@@ -1204,6 +1235,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = g16_from_float,
},
[GDK_MEMORY_A8] = {
.name = "A8",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A8,
.straight = GDK_MEMORY_A8,
@@ -1232,6 +1264,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = a8_from_float,
},
[GDK_MEMORY_A16] = {
.name = "A16",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A16,
.straight = GDK_MEMORY_A16,
@@ -1263,6 +1296,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = a16_from_float,
},
[GDK_MEMORY_A16_FLOAT] = {
.name = "A16f",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A16_FLOAT,
.straight = GDK_MEMORY_A16_FLOAT,
@@ -1293,6 +1327,7 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.from_float = a16_float_from_float,
},
[GDK_MEMORY_A32_FLOAT] = {
.name = "A32f",
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A32_FLOAT,
.straight = GDK_MEMORY_A32_FLOAT,
@@ -1661,6 +1696,12 @@ gdk_memory_format_get_dmabuf_fourcc (GdkMemoryFormat format)
#endif
}
const char *
gdk_memory_format_get_name (GdkMemoryFormat format)
{
return memory_formats[format].name;
}
static void
premultiply (float *rgba,
gsize n)
@@ -1694,14 +1735,18 @@ void
gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
GdkMemoryFormat dest_format,
GdkColorState *dest_color_state,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
GdkColorState *src_color_state,
gsize width,
gsize height)
{
const GdkMemoryFormatDescription *dest_desc = &memory_formats[dest_format];
const GdkMemoryFormatDescription *src_desc = &memory_formats[src_format];
GdkColorStateTransform transform;
gboolean has_transform;
float *tmp;
gsize y;
void (*func) (guchar *, const guchar *, gsize) = NULL;
@@ -1709,7 +1754,8 @@ gdk_memory_convert (guchar *dest_data,
g_assert (dest_format < GDK_MEMORY_N_FORMATS);
g_assert (src_format < GDK_MEMORY_N_FORMATS);
if (src_format == dest_format)
if (gdk_color_state_equal (src_color_state, dest_color_state) &&
src_format == dest_format)
{
gsize bytes_per_row = src_desc->bytes_per_pixel * width;
@@ -1729,7 +1775,9 @@ gdk_memory_convert (guchar *dest_data,
return;
}
if (src_format == GDK_MEMORY_R8G8B8A8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
if (!gdk_color_state_equal (src_color_state, dest_color_state))
func = NULL;
else if (src_format == GDK_MEMORY_R8G8B8A8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
func = r8g8b8a8_to_r8g8b8a8_premultiplied;
else if (src_format == GDK_MEMORY_B8G8R8A8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
func = r8g8b8a8_to_b8g8r8a8_premultiplied;
@@ -1777,19 +1825,43 @@ gdk_memory_convert (guchar *dest_data,
return;
}
if (!gdk_color_state_equal (src_color_state, dest_color_state))
{
gdk_color_state_transform_init (&transform, src_color_state, dest_color_state, TRUE);
has_transform = TRUE;
}
else
{
has_transform = FALSE;
}
tmp = g_new (float, width * 4);
for (y = 0; y < height; y++)
{
src_desc->to_float (tmp, src_data, width);
if (src_desc->alpha == GDK_MEMORY_ALPHA_PREMULTIPLIED && dest_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT)
unpremultiply (tmp, width);
else if (src_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT && dest_desc->alpha != GDK_MEMORY_ALPHA_STRAIGHT)
premultiply (tmp, width);
if (has_transform)
{
if (src_desc->alpha == GDK_MEMORY_ALPHA_PREMULTIPLIED)
unpremultiply (tmp, width);
gdk_color_state_transform (&transform, tmp, tmp, width);
if (dest_desc->alpha != GDK_MEMORY_ALPHA_STRAIGHT)
premultiply (tmp, width);
}
else
{
if (src_desc->alpha == GDK_MEMORY_ALPHA_PREMULTIPLIED && dest_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT)
unpremultiply (tmp, width);
else if (src_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT && dest_desc->alpha != GDK_MEMORY_ALPHA_STRAIGHT)
premultiply (tmp, width);
}
dest_desc->from_float (dest_data, tmp, width);
src_data += src_stride;
dest_data += dest_stride;
}
if (has_transform)
gdk_color_state_transform_finish (&transform);
g_free (tmp);
}

View File

@@ -75,14 +75,16 @@ VkFormat gdk_memory_format_vk_rgba_format (GdkMemoryFormat
VkComponentMapping *out_swizzle);
#endif
guint32 gdk_memory_format_get_dmabuf_fourcc (GdkMemoryFormat format);
const char * gdk_memory_format_get_name (GdkMemoryFormat format);
void gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
GdkMemoryFormat dest_format,
GdkColorState *dest_color_state,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
GdkColorState *src_color_state,
gsize width,
gsize height);

View File

@@ -22,6 +22,7 @@
#include "gdkmemorytextureprivate.h"
#include "gdkmemoryformatprivate.h"
#include "gdkcolorstate.h"
#include "gsk/gl/fp16private.h"
/**
@@ -58,6 +59,7 @@ gdk_memory_texture_dispose (GObject *object)
static void
gdk_memory_texture_download (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride)
{
@@ -65,9 +67,11 @@ gdk_memory_texture_download (GdkTexture *texture,
gdk_memory_convert (data, stride,
format,
color_state,
(guchar *) g_bytes_get_data (self->bytes, NULL),
self->stride,
texture->format,
texture->color_state,
gdk_texture_get_width (texture),
gdk_texture_get_height (texture));
}
@@ -131,7 +135,7 @@ gdk_memory_sanitize (GBytes *bytes,
* @bytes: the `GBytes` containing the pixel data
* @stride: rowstride for the data
*
* Creates a new texture for a blob of image data.
* Creates a new texture for a blob of sRGB image data.
*
* The `GBytes` must contain @stride × @height pixels
* in the given format.
@@ -144,11 +148,43 @@ gdk_memory_texture_new (int width,
GdkMemoryFormat format,
GBytes *bytes,
gsize stride)
{
return gdk_memory_texture_new_with_color_state (width, height, format,
gdk_color_state_get_srgb (),
bytes, stride);
}
/**
* gdk_memory_texture_new_with_color_state:
* @width: the width of the texture
* @height: the height of the texture
* @format: the format of the data
* @color_state: a `GdkColorSpace`
* @bytes: the `GBytes` containing the pixel data
* @stride: rowstride for the data
*
* Creates a new texture for a blob of image data with a given color state.
*
* The `GBytes` must contain @stride x @height pixels
* in the given format.
*
* Returns: A newly-created `GdkTexture`
*
* Since: 4.16
*/
GdkTexture *
gdk_memory_texture_new_with_color_state (int width,
int height,
GdkMemoryFormat format,
GdkColorState *color_state,
GBytes *bytes,
gsize stride)
{
GdkMemoryTexture *self;
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
g_return_val_if_fail (color_state != NULL, NULL);
g_return_val_if_fail (bytes != NULL, NULL);
g_return_val_if_fail (stride >= width * gdk_memory_format_bytes_per_pixel (format), NULL);
/* needs to be this complex to support subtexture of the bottom right part */
@@ -159,6 +195,7 @@ gdk_memory_texture_new (int width,
self = g_object_new (GDK_TYPE_MEMORY_TEXTURE,
"width", width,
"height", height,
"color-state", color_state,
NULL);
GDK_TEXTURE (self)->format = format;
@@ -191,19 +228,19 @@ gdk_memory_texture_new_subtexture (GdkMemoryTexture *source,
size = source->stride * (height - 1) + width * bpp;
bytes = g_bytes_new_from_bytes (source->bytes, offset, size);
result = gdk_memory_texture_new (width,
height,
texture->format,
bytes,
source->stride);
result = gdk_memory_texture_new_with_color_state (width,
height,
texture->format,
texture->color_state,
bytes,
source->stride);
g_bytes_unref (bytes);
return result;
}
GdkMemoryTexture *
gdk_memory_texture_from_texture (GdkTexture *texture,
GdkMemoryFormat format)
gdk_memory_texture_from_texture (GdkTexture *texture)
{
GdkTexture *result;
GBytes *bytes;
@@ -213,23 +250,19 @@ gdk_memory_texture_from_texture (GdkTexture *texture,
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
if (GDK_IS_MEMORY_TEXTURE (texture))
{
GdkMemoryTexture *memtex = GDK_MEMORY_TEXTURE (texture);
return g_object_ref (GDK_MEMORY_TEXTURE (texture));
if (gdk_texture_get_format (texture) == format)
return g_object_ref (memtex);
}
stride = texture->width * gdk_memory_format_bytes_per_pixel (format);
stride = texture->width * gdk_memory_format_bytes_per_pixel (texture->format);
data = g_malloc_n (stride, texture->height);
gdk_texture_do_download (texture, format, data, stride);
gdk_texture_do_download (texture, texture->format, texture->color_state, data, stride);
bytes = g_bytes_new_take (data, stride * texture->height);
result = gdk_memory_texture_new (texture->width,
texture->height,
format,
bytes,
stride);
result = gdk_memory_texture_new_with_color_state (texture->width,
texture->height,
texture->format,
texture->color_state,
bytes,
stride);
g_bytes_unref (bytes);
return GDK_MEMORY_TEXTURE (result);

View File

@@ -68,6 +68,14 @@ GdkTexture * gdk_memory_texture_new (int
GBytes *bytes,
gsize stride);
GDK_AVAILABLE_IN_4_16
GdkTexture * gdk_memory_texture_new_with_color_state (int width,
int height,
GdkMemoryFormat format,
GdkColorState *color_state,
GBytes *bytes,
gsize stride);
G_END_DECLS

View File

@@ -28,8 +28,7 @@ G_BEGIN_DECLS
#define GDK_MEMORY_GDK_PIXBUF_OPAQUE GDK_MEMORY_R8G8B8
#define GDK_MEMORY_GDK_PIXBUF_ALPHA GDK_MEMORY_R8G8B8A8
GdkMemoryTexture * gdk_memory_texture_from_texture (GdkTexture *texture,
GdkMemoryFormat format);
GdkMemoryTexture * gdk_memory_texture_from_texture (GdkTexture *texture);
GdkTexture * gdk_memory_texture_new_subtexture (GdkMemoryTexture *texture,
int x,
int y,

View File

@@ -396,10 +396,18 @@ gboolean
*/
char *
gdk_rgba_to_string (const GdkRGBA *rgba)
{
return g_string_free (gdk_rgba_print (rgba, g_string_new ("")), FALSE);
}
GString *
gdk_rgba_print (const GdkRGBA *rgba,
GString *string)
{
if (rgba->alpha > 0.999)
{
return g_strdup_printf ("rgb(%d,%d,%d)",
g_string_append_printf (string,
"rgb(%d,%d,%d)",
(int)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.),
(int)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.),
(int)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.));
@@ -410,12 +418,15 @@ gdk_rgba_to_string (const GdkRGBA *rgba)
g_ascii_formatd (alpha, G_ASCII_DTOSTR_BUF_SIZE, "%g", CLAMP (rgba->alpha, 0, 1));
return g_strdup_printf ("rgba(%d,%d,%d,%s)",
g_string_append_printf (string,
"rgba(%d,%d,%d,%s)",
(int)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.),
(int)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.),
(int)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.),
alpha);
}
return string;
}
static gboolean

View File

@@ -72,5 +72,8 @@ _gdk_rgba_equal (gconstpointer p1,
rgba1->alpha == rgba2->alpha;
}
GString * gdk_rgba_print (const GdkRGBA *rgba,
GString *string);
G_END_DECLS

View File

@@ -30,6 +30,8 @@
#include "gdksurface.h"
#include "gdkprivate.h"
#include "gdkcolorstate.h"
#include "gdkcairo.h"
#include "gdkcontentprovider.h"
#include "gdkdeviceprivate.h"
#include "gdkdisplayprivate.h"
@@ -44,6 +46,7 @@
#include "gdktoplevelprivate.h"
#include "gdkvulkancontext.h"
#include "gdksubsurfaceprivate.h"
#include "gdkcolorstate.h"
#include <math.h>
@@ -89,6 +92,7 @@ enum {
enum {
PROP_0,
PROP_COLOR_STATE,
PROP_CURSOR,
PROP_DISPLAY,
PROP_FRAME_CLOCK,
@@ -484,6 +488,18 @@ gdk_surface_init (GdkSurface *surface)
surface->alpha = 255;
if (g_getenv ("GDK_DISPLAY_COLORSTATE"))
{
const char *env = g_getenv ("GDK_DISPLAY_COLORSTATE");
if (strcmp (env, "srgb") == 0)
surface->color_state = gdk_color_state_get_srgb ();
else if (strcmp (env, "srgb-linear") == 0)
surface->color_state = gdk_color_state_get_srgb_linear ();
}
if (surface->color_state == NULL)
surface->color_state = gdk_color_state_get_srgb ();
surface->device_cursor = g_hash_table_new_full (NULL, NULL,
NULL, g_object_unref);
@@ -528,6 +544,25 @@ gdk_surface_class_init (GdkSurfaceClass *klass)
klass->get_scale = gdk_surface_real_get_scale;
klass->create_subsurface = gdk_surface_real_create_subsurface;
/**
* GdkSurface:color-state: (attributes org.gtk.Property.get=gdk_surface_get_color_state)
*
* The preferred color state for rendering to the surface
*
* This color state is negotiated between GTK and the compositor.
*
* The color state may change as the surface gets moved around - for example
* to different monitors or when the compositor gets reconfigured. As long as
* the surface isn't shown, the color space may not represent the actual color
* state that is going to be used.
*
* Since: 4.16
*/
properties[PROP_COLOR_STATE] =
g_param_spec_boxed ("color-state", NULL, NULL,
GDK_TYPE_COLOR_STATE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GdkSurface:cursor: (attributes org.gtk.Property.get=gdk_surface_get_cursor org.gtk.Property.set=gdk_surface_set_cursor)
*
@@ -786,6 +821,10 @@ gdk_surface_set_property (GObject *object,
switch (prop_id)
{
case PROP_COLOR_STATE:
gdk_surface_set_color_state (surface, g_value_get_object (value));
break;
case PROP_CURSOR:
gdk_surface_set_cursor (surface, g_value_get_object (value));
break;
@@ -819,6 +858,10 @@ gdk_surface_get_property (GObject *object,
switch (prop_id)
{
case PROP_COLOR_STATE:
g_value_set_object (value, gdk_surface_get_color_state (surface));
break;
case PROP_CURSOR:
g_value_set_object (value, gdk_surface_get_cursor (surface));
break;
@@ -2330,6 +2373,7 @@ gdk_surface_create_similar_surface (GdkSurface *surface,
content == CAIRO_CONTENT_ALPHA ? CAIRO_FORMAT_A8 : CAIRO_FORMAT_ARGB32,
width * scale, height * scale);
cairo_surface_set_device_scale (similar_surface, scale, scale);
gdk_cairo_surface_set_color_state (similar_surface, gdk_surface_get_color_state (surface));
return similar_surface;
}
@@ -3076,3 +3120,37 @@ gdk_surface_get_subsurface (GdkSurface *surface,
{
return g_ptr_array_index (surface->subsurfaces, idx);
}
void
gdk_surface_set_color_state (GdkSurface *surface,
GdkColorState *color_state)
{
/* This way we support unsetting, too */
if (G_UNLIKELY (gdk_display_get_debug_flags (surface->display) & GDK_DEBUG_SRGB))
color_state = gdk_color_state_get_srgb ();
if (gdk_color_state_equal (surface->color_state, color_state))
return;
g_set_object (&surface->color_state, color_state);
g_object_notify_by_pspec (G_OBJECT (surface), properties[PROP_COLOR_STATE]);
}
/**
* gdk_surface_get_color_state:
* @self: a `GdkSurface`
*
* Returns the preferred color state for rendering to the given @surface.
*
* Returns: (transfer none): The color state of @surface
*
* Since: 4.16
*/
GdkColorState *
gdk_surface_get_color_state (GdkSurface *surface)
{
g_return_val_if_fail (GDK_IS_SURFACE (surface), gdk_color_state_get_srgb ());
return surface->color_state;
}

View File

@@ -139,6 +139,9 @@ GdkVulkanContext *
gdk_surface_create_vulkan_context(GdkSurface *surface,
GError **error);
GDK_AVAILABLE_IN_4_16
GdkColorState *gdk_surface_get_color_state (GdkSurface *surface);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GdkSurface, g_object_unref)
G_END_DECLS

View File

@@ -105,6 +105,8 @@ struct _GdkSurface
*/
GdkSubsurface *subsurfaces_above;
GdkSubsurface *subsurfaces_below;
GdkColorState *color_state;
};
struct _GdkSurfaceClass
@@ -355,4 +357,7 @@ gsize gdk_surface_get_n_subsurfaces (GdkSurface *surface);
GdkSubsurface * gdk_surface_get_subsurface (GdkSurface *surface,
gsize idx);
void gdk_surface_set_color_state (GdkSurface *surface,
GdkColorState *color_state);
G_END_DECLS

View File

@@ -44,12 +44,21 @@
#include "gdkmemorytextureprivate.h"
#include "gdkpaintable.h"
#include "gdksnapshot.h"
#include "gdkcolorstate.h"
#include "gdkcairo.h"
#include <graphene.h>
#include "loaders/gdkpngprivate.h"
#include "loaders/gdktiffprivate.h"
#include "loaders/gdkjpegprivate.h"
/**
* gdk_texture_error_quark:
*
* Registers an error quark for [class@Gdk.Texture] errors.
*
* Returns: the error quark
**/
G_DEFINE_QUARK (gdk-texture-error-quark, gdk_texture_error)
/* HACK: So we don't need to include any (not-yet-created) GSK or GTK headers */
@@ -62,6 +71,7 @@ enum {
PROP_0,
PROP_WIDTH,
PROP_HEIGHT,
PROP_COLOR_STATE,
N_PROPS
};
@@ -251,6 +261,7 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkTexture, gdk_texture, G_TYPE_OBJECT,
static void
gdk_texture_default_download (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride)
{
@@ -275,6 +286,12 @@ gdk_texture_set_property (GObject *gobject,
self->height = g_value_get_int (value);
break;
case PROP_COLOR_STATE:
if (self->color_state)
gdk_color_state_unref (self->color_state);
self->color_state = gdk_color_state_ref (g_value_get_boxed (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@@ -299,6 +316,10 @@ gdk_texture_get_property (GObject *gobject,
g_value_set_int (value, self->height);
break;
case PROP_COLOR_STATE:
g_value_set_boxed (value, self->color_state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@@ -337,6 +358,8 @@ gdk_texture_dispose (GObject *object)
gdk_texture_clear_render_data (self);
g_clear_pointer (&self->color_state, gdk_color_state_unref);
G_OBJECT_CLASS (gdk_texture_parent_class)->dispose (object);
}
@@ -381,12 +404,28 @@ gdk_texture_class_init (GdkTextureClass *klass)
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* GdkTexture:color-state: (attributes org.gtk.Property.get=gdk_texture_get_color_state)
*
* The color state of the texture.
*
* Since: 4.16
*/
properties[PROP_COLOR_STATE] =
g_param_spec_boxed ("color-state", NULL, NULL,
GDK_TYPE_COLOR_STATE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
static void
gdk_texture_init (GdkTexture *self)
{
self->color_state = gdk_color_state_get_srgb ();
}
/**
@@ -417,17 +456,42 @@ gdk_texture_new_for_surface (cairo_surface_t *surface)
(GDestroyNotify) cairo_surface_destroy,
cairo_surface_reference (surface));
texture = gdk_memory_texture_new (cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface),
GDK_MEMORY_DEFAULT,
bytes,
cairo_image_surface_get_stride (surface));
texture = gdk_memory_texture_new_with_color_state (cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface),
GDK_MEMORY_DEFAULT,
gdk_cairo_surface_get_color_state (surface),
bytes,
cairo_image_surface_get_stride (surface));
g_bytes_unref (bytes);
return texture;
}
static GdkColorState *
gdk_color_state_from_pixbuf (GdkPixbuf *pixbuf)
{
const char *icc_profile_base64;
GdkColorState *color_state = NULL;
icc_profile_base64 = gdk_pixbuf_get_option (pixbuf, "icc-profile");
if (icc_profile_base64)
{
guchar *icc_data;
gsize icc_len;
GBytes *bytes;
icc_data = g_base64_decode (icc_profile_base64, &icc_len);
bytes = g_bytes_new_take (icc_data, icc_len);
color_state = gdk_color_state_new_from_icc_profile (bytes, NULL);
g_bytes_unref (bytes);
}
if (!color_state)
color_state = gdk_color_state_get_srgb ();
return color_state;
}
/**
* gdk_texture_new_for_pixbuf:
* @pixbuf: a `GdkPixbuf`
@@ -445,24 +509,31 @@ gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf)
{
GdkTexture *texture;
GBytes *bytes;
GdkColorState *color_state;
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
color_state = gdk_color_state_from_pixbuf (pixbuf);
bytes = g_bytes_new_with_free_func (gdk_pixbuf_get_pixels (pixbuf),
gdk_pixbuf_get_height (pixbuf)
* (gsize) gdk_pixbuf_get_rowstride (pixbuf),
g_object_unref,
g_object_ref (pixbuf));
texture = gdk_memory_texture_new (gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_has_alpha (pixbuf)
? GDK_MEMORY_GDK_PIXBUF_ALPHA
: GDK_MEMORY_GDK_PIXBUF_OPAQUE,
bytes,
gdk_pixbuf_get_rowstride (pixbuf));
texture = gdk_memory_texture_new_with_color_state (gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_has_alpha (pixbuf)
? GDK_MEMORY_GDK_PIXBUF_ALPHA
: GDK_MEMORY_GDK_PIXBUF_OPAQUE,
color_state,
bytes,
gdk_pixbuf_get_rowstride (pixbuf));
g_bytes_unref (bytes);
gdk_color_state_unref (color_state);
return texture;
}
@@ -720,13 +791,32 @@ gdk_texture_get_height (GdkTexture *texture)
return texture->height;
}
/**
* gdk_texture_get_color_state: (attributes org.gtk.Method.get_property=color-state)
* @texture: a `GdkTexture`
*
* Returns the color state associsated with @texture.
*
* Returns: (transfer none): the color state of the `GdkTexture`
*
* Since: 4.16
*/
GdkColorState *
gdk_texture_get_color_state (GdkTexture *texture)
{
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
return texture->color_state;
}
void
gdk_texture_do_download (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride)
{
GDK_TEXTURE_GET_CLASS (texture)->download (texture, format, data, stride);
GDK_TEXTURE_GET_CLASS (texture)->download (texture, format, color_state, data, stride);
}
static gboolean
@@ -822,7 +912,8 @@ gdk_texture_set_diff (GdkTexture *self,
}
cairo_surface_t *
gdk_texture_download_surface (GdkTexture *texture)
gdk_texture_download_surface (GdkTexture *texture,
GdkColorState *color_state)
{
cairo_surface_t *surface;
cairo_status_t surface_status;
@@ -834,10 +925,13 @@ gdk_texture_download_surface (GdkTexture *texture)
if (surface_status != CAIRO_STATUS_SUCCESS)
g_warning ("%s: surface error: %s", __FUNCTION__,
cairo_status_to_string (surface_status));
else
gdk_texture_do_download (texture,
GDK_MEMORY_DEFAULT,
color_state,
cairo_image_surface_get_data (surface),
cairo_image_surface_get_stride (surface));
gdk_texture_download (texture,
cairo_image_surface_get_data (surface),
cairo_image_surface_get_stride (surface));
cairo_surface_mark_dirty (surface);
return surface;
@@ -884,6 +978,7 @@ gdk_texture_download (GdkTexture *texture,
gdk_texture_do_download (texture,
GDK_MEMORY_DEFAULT,
gdk_color_state_get_srgb (),
data,
stride);
}

View File

@@ -83,6 +83,9 @@ int gdk_texture_get_height (GdkTexture
GDK_AVAILABLE_IN_4_10
GdkMemoryFormat gdk_texture_get_format (GdkTexture *self) G_GNUC_PURE;
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_texture_get_color_state (GdkTexture *self);
GDK_AVAILABLE_IN_ALL
void gdk_texture_download (GdkTexture *texture,
guchar *data,

View File

@@ -39,6 +39,7 @@
#include "gdkmemoryformatprivate.h"
#include "gdkmemorytextureprivate.h"
#include "gdktextureprivate.h"
#include "gdkcolorstate.h"
G_DEFINE_BOXED_TYPE (GdkTextureDownloader, gdk_texture_downloader,
gdk_texture_downloader_copy,
@@ -51,6 +52,7 @@ gdk_texture_downloader_init (GdkTextureDownloader *self,
{
self->texture = g_object_ref (texture);
self->format = GDK_MEMORY_DEFAULT;
self->color_state = gdk_color_state_get_srgb ();
}
void
@@ -103,6 +105,7 @@ gdk_texture_downloader_copy (const GdkTextureDownloader *self)
copy = gdk_texture_downloader_new (self->texture);
gdk_texture_downloader_set_format (copy, self->format);
gdk_texture_downloader_set_color_state (copy, self->color_state);
return copy;
}
@@ -121,6 +124,8 @@ gdk_texture_downloader_free (GdkTextureDownloader *self)
g_return_if_fail (self != NULL);
gdk_texture_downloader_finish (self);
g_clear_pointer (&self->color_state, gdk_color_state_unref);
g_free (self);
}
@@ -199,6 +204,39 @@ gdk_texture_downloader_get_format (const GdkTextureDownloader *self)
return self->format;
}
/**
* gdk_texture_downloader_set_color_state:
* @self: a texture downloader
* @color_state: the color state to use
*
* Sets the color state that the data will be converted to.
*
* Since: 4.16
*/
void
gdk_texture_downloader_set_color_state (GdkTextureDownloader *self,
GdkColorState *color_state)
{
g_clear_pointer (&self->color_state, gdk_color_state_unref);
self->color_state = gdk_color_state_ref (color_state);
}
/**
* gdk_texture_downloader_get_color_state:
* @self: a texture downloader
*
* Gets the color state that the data will be converted to.
*
* Returns: the color state
*
* Since: 4.16
*/
GdkColorState *
gdk_texture_downloader_get_color_state (const GdkTextureDownloader *self)
{
return self->color_state;
}
/**
* gdk_texture_downloader_download_into:
* @self: a texture downloader
@@ -219,7 +257,7 @@ gdk_texture_downloader_download_into (const GdkTextureDownloader *self,
g_return_if_fail (data != NULL);
g_return_if_fail (stride >= gdk_texture_get_width (self->texture) * gdk_memory_format_bytes_per_pixel (self->format));
gdk_texture_do_download (self->texture, self->format, data, stride);
gdk_texture_do_download (self->texture, self->format, self->color_state, data, stride);
}
/**
@@ -250,7 +288,8 @@ gdk_texture_downloader_download_bytes (const GdkTextureDownloader *self,
g_return_val_if_fail (out_stride != NULL, NULL);
if (GDK_IS_MEMORY_TEXTURE (self->texture) &&
gdk_texture_get_format (self->texture) == self->format)
gdk_texture_get_format (self->texture) == self->format &&
gdk_color_state_equal (self->texture->color_state, self->color_state))
{
GdkMemoryTexture *memtex = GDK_MEMORY_TEXTURE (self->texture);
@@ -260,7 +299,7 @@ gdk_texture_downloader_download_bytes (const GdkTextureDownloader *self,
stride = self->texture->width * gdk_memory_format_bytes_per_pixel (self->format);
data = g_malloc_n (stride, self->texture->height);
gdk_texture_do_download (self->texture, self->format, data, stride);
gdk_texture_do_download (self->texture, self->format, self->color_state, data, stride);
*out_stride = stride;
return g_bytes_new_take (data, stride * self->texture->height);

View File

@@ -49,6 +49,12 @@ void gdk_texture_downloader_set_format (GdkTextureDownl
GDK_AVAILABLE_IN_4_10
GdkMemoryFormat gdk_texture_downloader_get_format (const GdkTextureDownloader *self);
GDK_AVAILABLE_IN_4_16
void gdk_texture_downloader_set_color_state (GdkTextureDownloader *self,
GdkColorState *color_state);
GDK_AVAILABLE_IN_4_16
GdkColorState * gdk_texture_downloader_get_color_state (const GdkTextureDownloader *self);
GDK_AVAILABLE_IN_4_10
void gdk_texture_downloader_download_into (const GdkTextureDownloader *self,

View File

@@ -28,6 +28,7 @@ struct _GdkTextureDownloader
/*< private >*/
GdkTexture *texture;
GdkMemoryFormat format;
GdkColorState *color_state;
};
void gdk_texture_downloader_init (GdkTextureDownloader *self,

View File

@@ -26,6 +26,8 @@ struct _GdkTexture
int width;
int height;
GdkColorState *color_state;
gpointer render_key;
gpointer render_data;
GDestroyNotify render_notify;
@@ -46,6 +48,7 @@ struct _GdkTextureClass {
/* mandatory: Download in the given format into data */
void (* download) (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride);
};
@@ -53,10 +56,12 @@ struct _GdkTextureClass {
gboolean gdk_texture_can_load (GBytes *bytes);
GdkTexture * gdk_texture_new_for_surface (cairo_surface_t *surface);
cairo_surface_t * gdk_texture_download_surface (GdkTexture *texture);
cairo_surface_t * gdk_texture_download_surface (GdkTexture *texture,
GdkColorState *color_state);
void gdk_texture_do_download (GdkTexture *texture,
GdkMemoryFormat format,
GdkColorState *color_state,
guchar *data,
gsize stride);
void gdk_texture_diff (GdkTexture *self,

View File

@@ -767,9 +767,6 @@ gdk_toplevel_titlebar_gesture (GdkToplevel *toplevel,
* This function asynchronously obtains a handle for a toplevel surface
* that can be passed to other processes.
*
* When a handle has been obtained, @callback will be called, and can
* receive the handle via [method@Gdk.Toplevel.export_handle_finish].
*
* It is an error to call this function on a surface that is already
* exported.
*

View File

@@ -118,9 +118,12 @@ typedef enum
/**
* GdkTitlebarGesture:
* @GDK_TITLEBAR_GESTURE_DOUBLE_CLICK:
* @GDK_TITLEBAR_GESTURE_RIGHT_CLICK:
* @GDK_TITLEBAR_GESTURE_MIDDLE_CLICK:
* @GDK_TITLEBAR_GESTURE_DOUBLE_CLICK: double click gesture
* @GDK_TITLEBAR_GESTURE_RIGHT_CLICK: right click gesture
* @GDK_TITLEBAR_GESTURE_MIDDLE_CLICK: middle click gesture
*
* The kind of title bar gesture to emit with
* [method@Gdk.Toplevel.titlebar_gesture].
*
* Since: 4.4
*/

View File

@@ -74,6 +74,8 @@ typedef cairo_rectangle_int_t GdkRectangle;
/* Forward declarations of commonly used types */
typedef struct _GdkRGBA GdkRGBA;
typedef struct _GdkColor GdkColor;
typedef struct _GdkColorState GdkColorState;
typedef struct _GdkContentFormats GdkContentFormats;
typedef struct _GdkContentProvider GdkContentProvider;
typedef struct _GdkCursor GdkCursor;

View File

@@ -30,6 +30,7 @@
#include "gdkdmabuftextureprivate.h"
#include "gdkdisplayprivate.h"
#include "gdkprofilerprivate.h"
#include "gdkmemorytexture.h"
#include <glib/gi18n-lib.h>
#include <math.h>
@@ -94,6 +95,13 @@ enum {
LAST_SIGNAL
};
/**
* gdk_vulkan_error_quark:
*
* Registers an error quark for [class@Gdk.VulkanContext] errors.
*
* Returns: the error quark
**/
G_DEFINE_QUARK (gdk-vulkan-error-quark, gdk_vulkan_error)
static guint signals[LAST_SIGNAL] = { 0 };
@@ -607,7 +615,8 @@ physical_device_check_features (VkPhysicalDevice device)
features |= GDK_VULKAN_FEATURE_YCBCR;
if (physical_device_supports_extension (device, VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME) &&
physical_device_supports_extension (device, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME))
physical_device_supports_extension (device, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) &&
physical_device_supports_extension (device, VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME))
features |= GDK_VULKAN_FEATURE_DMABUF;
if (physical_device_supports_extension (device, VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME))
@@ -632,33 +641,54 @@ gdk_vulkan_context_begin_frame (GdkDrawContext *draw_context,
{
GdkVulkanContext *context = GDK_VULKAN_CONTEXT (draw_context);
GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
VkResult acquire_result;
guint i;
if (depth != priv->current_format)
{
if (priv->formats[depth].gdk_format != priv->formats[priv->current_format].gdk_format)
{
GdkMemoryDepth old_format = priv->current_format;
GError *error = NULL;
priv->current_format = depth;
if (!gdk_vulkan_context_check_swapchain (context, &error))
{
g_warning ("%s", error->message);
g_error_free (error);
priv->current_format = old_format;
return;
}
}
priv->current_format = depth;
}
for (i = 0; i < priv->n_images; i++)
{
cairo_region_union (priv->regions[i], region);
}
GDK_VK_CHECK (vkAcquireNextImageKHR, gdk_vulkan_context_get_device (context),
priv->swapchain,
UINT64_MAX,
priv->draw_semaphore,
VK_NULL_HANDLE,
&priv->draw_index);
acquire_next_image:
acquire_result = GDK_VK_CHECK (vkAcquireNextImageKHR, gdk_vulkan_context_get_device (context),
priv->swapchain,
UINT64_MAX,
priv->draw_semaphore,
VK_NULL_HANDLE,
&priv->draw_index);
if ((acquire_result == VK_ERROR_OUT_OF_DATE_KHR) ||
(acquire_result == VK_SUBOPTIMAL_KHR))
{
GError *error = NULL;
GDK_DEBUG (VULKAN, "Recreating the swapchain");
if (!gdk_vulkan_context_check_swapchain (context, &error))
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
goto acquire_next_image;
}
cairo_region_union (region, priv->regions[priv->draw_index]);
}
@@ -1229,18 +1259,6 @@ gdk_display_vulkan_pipeline_cache_updated (GdkDisplay *display)
NULL);
}
gboolean
gdk_display_vulkan_pipeline_cache_save (GdkDisplay *display)
{
return gdk_vulkan_save_pipeline_cache (display);
}
GFile *
gdk_display_vulkan_pipeline_cache_file (GdkDisplay *display)
{
return gdk_vulkan_get_pipeline_cache_file (display);
}
static void
gdk_display_create_pipeline_cache (GdkDisplay *display)
{
@@ -1280,6 +1298,15 @@ gdk_vulkan_context_get_image_format (GdkVulkanContext *context)
return priv->formats[priv->current_format].vk_format.format;
}
GdkMemoryFormat
gdk_vulkan_context_get_memory_format (GdkVulkanContext *context)
{
GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
g_return_val_if_fail (GDK_IS_VULKAN_CONTEXT (context), GDK_MEMORY_DEFAULT);
return priv->formats[priv->current_format].gdk_format;
}
/**
* gdk_vulkan_context_get_n_images:
* @context: a `GdkVulkanContext`
@@ -1511,6 +1538,7 @@ gdk_display_create_vulkan_device (GdkDisplay *display,
g_ptr_array_add (device_extensions, (gpointer) VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME);
g_ptr_array_add (device_extensions, (gpointer) VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME);
g_ptr_array_add (device_extensions, (gpointer) VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME);
g_ptr_array_add (device_extensions, (gpointer) VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME);
g_ptr_array_add (device_extensions, (gpointer) VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
@@ -1851,8 +1879,9 @@ gdk_display_unref_vulkan (GdkDisplay *display)
{
g_free (key);
vkDestroyShaderModule (display->vk_device,
value,
*((VkShaderModule *)value),
NULL);
g_free (value);
}
g_hash_table_unref (display->vk_shader_modules);
@@ -1980,13 +2009,13 @@ VkShaderModule
gdk_display_get_vk_shader_module (GdkDisplay *self,
const char *resource_name)
{
VkShaderModule shader;
VkShaderModule *shader;
GError *error = NULL;
GBytes *bytes;
shader = g_hash_table_lookup (self->vk_shader_modules, resource_name);
if (shader)
return shader;
return *shader;
bytes = g_resources_lookup_data (resource_name, 0, &error);
if (bytes == NULL)
@@ -1996,6 +2025,7 @@ gdk_display_get_vk_shader_module (GdkDisplay *self,
return VK_NULL_HANDLE;
}
shader = g_new0 (VkShaderModule, 1);
if (GDK_VK_CHECK (vkCreateShaderModule, self->vk_device,
&(VkShaderModuleCreateInfo) {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
@@ -2003,18 +2033,20 @@ gdk_display_get_vk_shader_module (GdkDisplay *self,
.pCode = (uint32_t *) g_bytes_get_data (bytes, NULL),
},
NULL,
&shader) == VK_SUCCESS)
shader) == VK_SUCCESS)
{
g_hash_table_insert (self->vk_shader_modules, g_strdup (resource_name), shader);
}
else
{
shader = VK_NULL_HANDLE;
g_free (shader);
return VK_NULL_HANDLE;
}
g_bytes_unref (bytes);
return shader;
return *shader;
}
#else /* GDK_RENDERING_VULKAN */

View File

@@ -87,8 +87,6 @@ VkShaderModule gdk_display_get_vk_shader_module (GdkDisp
const char *resource_name);
void gdk_display_vulkan_pipeline_cache_updated (GdkDisplay *display);
gboolean gdk_display_vulkan_pipeline_cache_save (GdkDisplay *display);
GFile * gdk_display_vulkan_pipeline_cache_file (GdkDisplay *display);
VkInstance gdk_vulkan_context_get_instance (GdkVulkanContext *context);
VkPhysicalDevice gdk_vulkan_context_get_physical_device (GdkVulkanContext *context);
@@ -96,6 +94,7 @@ VkDevice gdk_vulkan_context_get_device (GdkVulk
VkQueue gdk_vulkan_context_get_queue (GdkVulkanContext *context);
uint32_t gdk_vulkan_context_get_queue_family_index (GdkVulkanContext *context);
VkFormat gdk_vulkan_context_get_image_format (GdkVulkanContext *context);
GdkMemoryFormat gdk_vulkan_context_get_memory_format (GdkVulkanContext *context);
uint32_t gdk_vulkan_context_get_n_images (GdkVulkanContext *context);
VkImage gdk_vulkan_context_get_image (GdkVulkanContext *context,
guint id);

View File

@@ -24,6 +24,8 @@
#include <glib/gi18n-lib.h>
#include "gdktexture.h"
#include "gdktexturedownloaderprivate.h"
#include "gdkcolorstate.h"
#include "gdkmemorytextureprivate.h"
#include "gdkprofilerprivate.h"
@@ -143,9 +145,12 @@ gdk_load_jpeg (GBytes *input_bytes,
guint width, height, stride;
unsigned char *data = NULL;
unsigned char *row[1];
JOCTET *icc_data;
unsigned int icc_len;
GBytes *bytes;
GdkTexture *texture;
GdkMemoryFormat format;
GdkColorState *color_state;
G_GNUC_UNUSED guint64 before = GDK_PROFILER_CURRENT_TIME;
info.err = jpeg_std_error (&jerr.pub);
@@ -169,6 +174,9 @@ gdk_load_jpeg (GBytes *input_bytes,
g_bytes_get_data (input_bytes, NULL),
g_bytes_get_size (input_bytes));
/* save color space */
jpeg_save_markers (&info, JPEG_APP0 + 2, 0xFFFF);
jpeg_read_header (&info, TRUE);
jpeg_start_decompress (&info);
@@ -226,15 +234,31 @@ gdk_load_jpeg (GBytes *input_bytes,
g_assert_not_reached ();
}
if (jpeg_read_icc_profile (&info, &icc_data, &icc_len))
{
GBytes *icc_bytes = g_bytes_new_with_free_func (icc_data, icc_len, free, icc_data);
color_state = gdk_color_state_new_from_icc_profile (icc_bytes, error);
g_bytes_unref (icc_bytes);
}
else
color_state = gdk_color_state_get_srgb ();
jpeg_finish_decompress (&info);
jpeg_destroy_decompress (&info);
bytes = g_bytes_new_take (data, stride * height);
texture = gdk_memory_texture_new (width, height,
format,
bytes, stride);
if (color_state)
{
texture = gdk_memory_texture_new_with_color_state (width, height,
format,
color_state,
bytes, stride);
}
else
texture = NULL;
g_clear_pointer (&color_state, gdk_color_state_unref);
g_bytes_unref (bytes);
gdk_profiler_end_mark (before, "Load jpeg", NULL);
@@ -257,9 +281,12 @@ gdk_save_jpeg (GdkTexture *texture)
gsize texstride;
guchar *row;
int width, height;
GdkColorState *color_state;
GBytes *bytes;
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
color_state = gdk_texture_get_color_state (texture);
info.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = fatal_error_handler;
@@ -298,6 +325,15 @@ gdk_save_jpeg (GdkTexture *texture)
jpeg_start_compress (&info, TRUE);
bytes = gdk_color_state_save_to_icc_profile (color_state, NULL);
if (bytes)
{
jpeg_write_icc_profile (&info,
g_bytes_get_data (bytes, NULL),
g_bytes_get_size (bytes));
g_bytes_unref (bytes);
}
while (info.next_scanline < info.image_height)
{
row = (guchar *) texdata + info.next_scanline * texstride;

View File

@@ -20,11 +20,14 @@
#include "gdkpngprivate.h"
#include <glib/gi18n-lib.h>
#include "gdkcolorstateprivate.h"
#include "gdkcolorstateprivate.h"
#include "gdkmemoryformatprivate.h"
#include "gdkmemorytexture.h"
#include "gdkprofilerprivate.h"
#include "gdktexturedownloaderprivate.h"
#include "gsk/gl/fp16private.h"
#include <png.h>
#include <stdio.h>
@@ -126,6 +129,182 @@ png_simple_warning_callback (png_structp png,
{
}
/* }}} */
/* {{{ Color profile handling */
typedef struct
{
gboolean cicp_chunk_read;
int color_primaries;
int transfer_function;
int matrix_coefficients;
int full_range;
} CICPData;
static int
png_read_chunk_func (png_structp png,
png_unknown_chunkp chunk)
{
if (strcmp ((char *) chunk->name, "cICP") == 0 &&
chunk->size == 4)
{
CICPData *cicp = png_get_user_chunk_ptr (png);
cicp->cicp_chunk_read = TRUE;
cicp->color_primaries = chunk->data[0];
cicp->transfer_function = chunk->data[1];
cicp->matrix_coefficients = chunk->data[2];
cicp->full_range = chunk->data[3];
return 1;
}
return 0;
}
static GdkColorState *
gdk_png_get_color_state (png_struct *png,
png_info *info)
{
GdkColorState *color_state;
guchar *icc_data;
png_uint_32 icc_len;
char *name;
double gamma;
cmsCIExyY whitepoint;
cmsCIExyYTRIPLE primaries;
cmsToneCurve *curve;
cmsHPROFILE lcms_profile;
int intent;
CICPData *cicp;
cicp = png_get_user_chunk_ptr (png);
if (cicp->cicp_chunk_read)
{
color_state = gdk_color_state_new_from_cicp_data (cicp->color_primaries,
cicp->transfer_function,
cicp->matrix_coefficients,
cicp->full_range);
if (color_state)
{
g_debug ("Color state from cICP data: %s\n", gdk_color_state_get_name (color_state));
return color_state;
}
else
{
g_debug ("Failed to create color state from cICP data: %d/%d/%d %d\n",
cicp->color_primaries,
cicp->transfer_function,
cicp->matrix_coefficients,
cicp->full_range);
}
}
if (png_get_iCCP (png, info, &name, NULL, &icc_data, &icc_len))
{
GBytes *bytes = g_bytes_new (icc_data, icc_len);
color_state = gdk_color_state_new_from_icc_profile (bytes, NULL);
g_bytes_unref (bytes);
if (color_state)
return color_state;
}
if (png_get_sRGB (png, info, &intent))
return gdk_color_state_get_srgb ();
/* If neither of those is valid, the result is sRGB */
if (!png_get_valid (png, info, PNG_INFO_gAMA) &&
!png_get_valid (png, info, PNG_INFO_cHRM))
return gdk_color_state_get_srgb ();
if (!png_get_gAMA (png, info, &gamma))
gamma = 2.4;
if (!png_get_cHRM (png, info,
&whitepoint.x, &whitepoint.y,
&primaries.Red.x, &primaries.Red.y,
&primaries.Green.x, &primaries.Green.y,
&primaries.Blue.x, &primaries.Blue.y))
{
if (gamma == 2.4)
return gdk_color_state_get_srgb ();
whitepoint = (cmsCIExyY) { 0.3127, 0.3290, 1.0 };
primaries = (cmsCIExyYTRIPLE) {
{ 0.6400, 0.3300, 1.0 },
{ 0.3000, 0.6000, 1.0 },
{ 0.1500, 0.0600, 1.0 }
};
}
else
{
primaries.Red.Y = 1.0;
primaries.Green.Y = 1.0;
primaries.Blue.Y = 1.0;
}
curve = cmsBuildGamma (NULL, 1.0 / gamma);
lcms_profile = cmsCreateRGBProfile (&whitepoint,
&primaries,
(cmsToneCurve*[3]) { curve, curve, curve });
color_state = gdk_color_state_new_from_lcms_profile (lcms_profile);
/* FIXME: errors? */
if (color_state == NULL)
color_state = gdk_color_state_get_srgb ();
cmsFreeToneCurve (curve);
return color_state;
}
static void
gdk_png_set_color_state (png_struct *png,
png_info *info,
GdkColorState *color_state,
png_byte *chunk_data)
{
int cp, tc, mc;
gboolean fr;
if (gdk_color_state_save_to_cicp_data (color_state, &cp, &tc, &mc, &fr, NULL))
{
png_unknown_chunk chunk = {
.name = { 'c', 'I', 'C', 'P', '\0' },
.data = chunk_data,
.size = 4,
.location = PNG_HAVE_IHDR,
};
chunk_data[0] = (png_byte)cp;
chunk_data[1] = (png_byte)tc;
chunk_data[2] = (png_byte)mc;
chunk_data[3] = (png_byte)fr;
g_debug ("got cicp %d/%d/%d %d\n", cp, tc, mc, fr);
png_set_unknown_chunks (png, info, &chunk, 1);
}
else if (color_state == gdk_color_state_get_srgb ())
{
png_set_sRGB_gAMA_and_cHRM (png, info, /* FIXME */ PNG_sRGB_INTENT_PERCEPTUAL);
}
else
{
GBytes *bytes = gdk_color_state_save_to_icc_profile (color_state, NULL);
if (bytes)
{
png_set_iCCP (png, info,
"ICC profile",
0,
g_bytes_get_data (bytes, NULL),
g_bytes_get_size (bytes));
g_bytes_unref (bytes);
}
}
}
/* }}} */
/* {{{ Public API */
@@ -147,8 +326,11 @@ gdk_load_png (GBytes *bytes,
guchar *buffer = NULL;
guchar **row_pointers = NULL;
GBytes *out_bytes;
GdkColorState *color_state;
GdkTexture *texture;
int bpp;
CICPData cicp = { FALSE, };
G_GNUC_UNUSED gint64 before = GDK_PROFILER_CURRENT_TIME;
io.data = (guchar *)g_bytes_get_data (bytes, &io.size);
@@ -169,6 +351,7 @@ gdk_load_png (GBytes *bytes,
g_error ("Out of memory");
png_set_read_fn (png, &io, png_read_func);
png_set_read_user_chunk_fn (png, &cicp, png_read_chunk_func);
if (sigsetjmp (png_jmpbuf (png), 1))
{
@@ -266,6 +449,8 @@ gdk_load_png (GBytes *bytes,
return NULL;
}
color_state = gdk_png_get_color_state (png, info);
bpp = gdk_memory_format_bytes_per_pixel (format);
if (!g_size_checked_mul (&stride, width, bpp) ||
!g_size_checked_add (&stride, stride, (8 - stride % 8) % 8))
@@ -281,6 +466,7 @@ gdk_load_png (GBytes *bytes,
if (!buffer || !row_pointers)
{
gdk_color_state_unref (color_state);
g_free (buffer);
g_free (row_pointers);
png_destroy_read_struct (&png, &info, NULL);
@@ -297,8 +483,11 @@ gdk_load_png (GBytes *bytes,
png_read_end (png, info);
out_bytes = g_bytes_new_take (buffer, height * stride);
texture = gdk_memory_texture_new (width, height, format, out_bytes, stride);
texture = gdk_memory_texture_new_with_color_state (width, height,
format, color_state,
out_bytes, stride);
g_bytes_unref (out_bytes);
gdk_color_state_unref (color_state);
if (options && png_get_text (png, info, &text, &num_texts))
{
@@ -337,11 +526,14 @@ gdk_save_png (GdkTexture *texture)
GBytes *bytes;
gsize stride;
const guchar *data;
GdkColorState *color_state;
int png_format;
int depth;
png_byte chunk_data[4];
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
color_state = gdk_texture_get_color_state (texture);
format = gdk_texture_get_format (texture);
switch (format)
@@ -436,6 +628,8 @@ gdk_save_png (GdkTexture *texture)
/* 2^31-1 is the maximum size for PNG files */
png_set_user_limits (png, (1u << 31) - 1, (1u << 31) - 1);
png_set_keep_unknown_chunks (png, PNG_HANDLE_CHUNK_ALWAYS, NULL, 0);
info = png_create_info_struct (png);
if (!info)
{
@@ -465,6 +659,8 @@ gdk_save_png (GdkTexture *texture)
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
gdk_png_set_color_state (png, info, color_state, chunk_data);
png_write_info (png, info);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN

View File

@@ -24,6 +24,7 @@
#include "gdkmemorytexture.h"
#include "gdkprofilerprivate.h"
#include "gdktexturedownloaderprivate.h"
#include "gdkcolorstate.h"
#include <tiffio.h>
@@ -219,6 +220,49 @@ tiff_open_write (GBytes **result)
NULL, NULL);
}
/* }}} */
/* {{{ Color profile handling */
static GdkColorState *
gdk_tiff_get_color_state (TIFF *tiff)
{
const char *icc_data;
guint icc_len;
if (TIFFGetField (tiff, TIFFTAG_ICCPROFILE, &icc_len, &icc_data))
{
GBytes *icc_bytes;
GdkColorState *color_state;
icc_bytes = g_bytes_new (icc_data, icc_len);
color_state = gdk_color_state_new_from_icc_profile (icc_bytes, NULL);
g_bytes_unref (icc_bytes);
if (color_state)
return color_state;
}
return gdk_color_state_get_srgb ();
}
static void
gdk_tiff_set_color_state (TIFF *tiff,
GdkColorState *color_state)
{
GBytes *bytes;
bytes = gdk_color_state_save_to_icc_profile (color_state, NULL);
if (bytes)
{
TIFFSetField (tiff, TIFFTAG_ICCPROFILE,
g_bytes_get_size (bytes),
g_bytes_get_data (bytes, NULL));
g_bytes_unref (bytes);
}
}
/* }}} */
/* {{{ Public API */
@@ -282,6 +326,7 @@ gdk_save_tiff (GdkTexture *texture)
GBytes *bytes, *result = NULL;
GdkTextureDownloader downloader;
GdkMemoryFormat format;
GdkColorState *color_state;
const FormatData *fdata = NULL;
tif = tiff_open_write (&result);
@@ -289,6 +334,7 @@ gdk_save_tiff (GdkTexture *texture)
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
format = gdk_texture_get_format (texture);
color_state = gdk_texture_get_color_state (texture);
fdata = &format_data[format];
if (fdata == NULL)
@@ -308,6 +354,8 @@ gdk_save_tiff (GdkTexture *texture)
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, fdata->photometric);
TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
gdk_tiff_set_color_state (tif, color_state);
gdk_texture_downloader_init (&downloader, texture);
gdk_texture_downloader_set_format (&downloader, fdata->format);
bytes = gdk_texture_downloader_download_bytes (&downloader, &stride);
@@ -344,6 +392,7 @@ load_fallback (TIFF *tif,
int width, height;
guchar *data;
GBytes *bytes;
GdkColorState *color_state;
GdkTexture *texture;
TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &width);
@@ -360,12 +409,15 @@ load_fallback (TIFF *tif,
return NULL;
}
color_state = gdk_tiff_get_color_state (tif);
bytes = g_bytes_new_take (data, width * height * 4);
texture = gdk_memory_texture_new (width, height,
GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
bytes,
width * 4);
texture = gdk_memory_texture_new_with_color_state (width, height,
GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
color_state,
bytes,
width * 4);
g_bytes_unref (bytes);
@@ -390,6 +442,7 @@ gdk_load_tiff (GBytes *input_bytes,
gsize stride;
int bpp;
GBytes *bytes;
GdkColorState *color_state;
GdkTexture *texture;
G_GNUC_UNUSED gint64 before = GDK_PROFILER_CURRENT_TIME;
@@ -490,13 +543,16 @@ gdk_load_tiff (GBytes *input_bytes,
line += stride;
}
color_state = gdk_tiff_get_color_state (tif);
bpp = gdk_memory_format_bytes_per_pixel (format);
bytes = g_bytes_new_take (data, width * height * bpp);
texture = gdk_memory_texture_new (width, height,
format,
bytes, width * bpp);
texture = gdk_memory_texture_new_with_color_state (width, height,
format, color_state,
bytes, width * bpp);
g_bytes_unref (bytes);
gdk_color_state_unref (color_state);
TIFFClose (tif);

View File

@@ -96,12 +96,12 @@ _gdk_macos_drag_surface_constructed (GObject *object)
defer:NO
screen:screen];
_gdk_macos_surface_set_native (self, window);
[window setOpaque:NO];
[window setBackgroundColor:[NSColor clearColor]];
[window setDecorated:NO];
_gdk_macos_surface_set_native (self, window);
frame_clock = _gdk_frame_clock_idle_new ();
gdk_surface_set_frame_clock (surface, frame_clock);
g_object_unref (frame_clock);

View File

@@ -52,6 +52,7 @@ gdk_macos_popup_surface_layout (GdkMacosPopupSurface *self,
GdkRectangle bounds;
GdkRectangle final_rect;
int x, y;
int shadow_left, shadow_right, shadow_top, shadow_bottom;
g_assert (GDK_IS_MACOS_POPUP_SURFACE (self));
g_assert (layout != NULL);
@@ -68,10 +69,19 @@ gdk_macos_popup_surface_layout (GdkMacosPopupSurface *self,
monitor = _gdk_macos_surface_get_best_monitor (GDK_MACOS_SURFACE (self));
gdk_macos_monitor_get_workarea (monitor, &bounds);
gdk_popup_layout_get_shadow_width (layout,
&shadow_left,
&shadow_right,
&shadow_top,
&shadow_bottom);
gdk_surface_layout_popup_helper (GDK_SURFACE (self),
width,
height,
0, 0, 0, 0, /* shadow-left/right/top/bottom */
shadow_left,
shadow_right,
shadow_top,
shadow_bottom,
monitor,
&bounds,
self->layout,
@@ -306,14 +316,14 @@ _gdk_macos_popup_surface_constructed (GObject *object)
defer:NO
screen:screen];
_gdk_macos_surface_set_native (GDK_MACOS_SURFACE (self), window);
[window setOpaque:NO];
[window setBackgroundColor:[NSColor clearColor]];
[window setDecorated:NO];
[window setExcludedFromWindowsMenu:YES];
[window setLevel:NSPopUpMenuWindowLevel];
_gdk_macos_surface_set_native (GDK_MACOS_SURFACE (self), window);
gdk_surface_set_frame_clock (surface, gdk_surface_get_frame_clock (surface->parent));
GDK_END_MACOS_ALLOC_POOL;

View File

@@ -591,11 +591,11 @@ _gdk_macos_toplevel_surface_constructed (GObject *object)
defer:NO
screen:screen];
_gdk_macos_surface_set_native (GDK_MACOS_SURFACE (self), window);
/* Allow NSWindow to go fullscreen */
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
_gdk_macos_surface_set_native (GDK_MACOS_SURFACE (self), window);
frame_clock = _gdk_frame_clock_idle_new ();
gdk_surface_set_frame_clock (surface, frame_clock);
g_object_unref (frame_clock);

View File

@@ -6,6 +6,8 @@ gdk_public_sources = files([
'gdkcairo.c',
'gdkcairocontext.c',
'gdkclipboard.c',
'gdkcolor.c',
'gdkcolorstate.c',
'gdkcontentdeserializer.c',
'gdkcontentformats.c',
'gdkcontentprovider.c',
@@ -75,6 +77,9 @@ gdk_public_headers = files([
'gdkcairo.h',
'gdkcairocontext.h',
'gdkclipboard.h',
'gdkcolor.h',
'gdkcolorimpl.h',
'gdkcolorstate.h',
'gdkcontentdeserializer.h',
'gdkcontentformats.h',
'gdkcontentprovider.h',
@@ -128,8 +133,8 @@ install_headers(gdk_deprecated_headers, subdir: 'gtk-4.0/gdk/deprecated')
gdk_sources = gdk_public_sources + gdk_deprecated_sources
gdk_private_h_sources = files([
'gdkeventsprivate.h',
'gdkdevicetoolprivate.h',
'gdkeventsprivate.h',
'gdkhslaprivate.h',
'gdkmonitorprivate.h',
'gdkseatdefaultprivate.h',
@@ -224,6 +229,7 @@ gdk_deps = [
fontconfig_dep,
platform_gio_dep,
pangocairo_dep,
lcms2_dep,
vulkan_dep,
libdrm_dep,
png_dep,

View File

@@ -158,6 +158,9 @@ gdk_wayland_cairo_context_begin_frame (GdkDrawContext *draw_context,
else
self->paint_surface = gdk_wayland_cairo_context_create_surface (self);
gdk_cairo_surface_set_color_state (self->paint_surface,
gdk_surface_get_color_state (gdk_draw_context_get_surface (draw_context)));
surface_region = gdk_wayland_cairo_context_surface_get_region (self->paint_surface);
if (surface_region)
cairo_region_union (region, surface_region);

View File

@@ -165,25 +165,29 @@ _gdk_wayland_cursor_get_buffer (GdkWaylandDisplay *display,
double *scale)
{
GdkTexture *texture;
int desired_scale_factor;
desired_scale_factor = (int) ceil (desired_scale);
if (gdk_cursor_get_name (cursor))
{
struct wl_cursor *c;
int scale_factor;
if (g_str_equal (gdk_cursor_get_name (cursor), "none"))
goto none;
{
*hotspot_x = *hotspot_y = 0;
*width = *height = 0;
*scale = 1;
return NULL;
}
scale_factor = (int) ceil (desired_scale);
c = gdk_wayland_cursor_load_for_name (display,
_gdk_wayland_display_get_cursor_theme (display),
desired_scale_factor,
display->cursor_theme,
scale_factor,
gdk_cursor_get_name (cursor));
if (c && c->image_count > 0)
{
struct wl_cursor_image *image;
int cursor_scale;
if (image_index >= c->image_count)
{
@@ -195,23 +199,23 @@ _gdk_wayland_cursor_get_buffer (GdkWaylandDisplay *display,
image = c->images[image_index];
cursor_scale = desired_scale_factor;
if ((image->width % cursor_scale != 0) ||
(image->height % cursor_scale != 0))
*width = display->cursor_theme_size;
*height = display->cursor_theme_size;
*scale = image->width / (double) *width;
*hotspot_x = image->hotspot_x / scale_factor;
*hotspot_y = image->hotspot_y / scale_factor;
if (*scale != scale_factor && !use_viewporter)
{
g_warning (G_STRLOC " cursor image size (%dx%d) not an integer "
"multiple of scale (%d)", image->width, image->height,
cursor_scale);
cursor_scale = 1;
g_warning (G_STRLOC " cursor image size (%d) not an integer "
"multiple of theme size (%d)", image->width, *width);
*width = image->width;
*height = image->height;
*hotspot_x = image->hotspot_x;
*hotspot_y = image->hotspot_y;
*scale = 1;
}
*hotspot_x = image->hotspot_x / cursor_scale;
*hotspot_y = image->hotspot_y / cursor_scale;
*width = image->width / cursor_scale;
*height = image->height / cursor_scale;
*scale = cursor_scale;
return wl_cursor_image_get_buffer (image);
}
}
@@ -257,7 +261,7 @@ from_texture:
else
{
if (!use_viewporter)
*scale = desired_scale_factor;
*scale = ceil (desired_scale);
else
*scale = desired_scale;
@@ -294,28 +298,23 @@ from_texture:
}
if (gdk_cursor_get_fallback (cursor))
return _gdk_wayland_cursor_get_buffer (display,
gdk_cursor_get_fallback (cursor),
desired_scale,
use_viewporter,
image_index,
hotspot_x, hotspot_y,
width, height,
scale);
{
return _gdk_wayland_cursor_get_buffer (display,
gdk_cursor_get_fallback (cursor),
desired_scale,
use_viewporter,
image_index,
hotspot_x, hotspot_y,
width, height,
scale);
}
else
{
texture = gdk_texture_new_from_resource ("/org/gtk/libgdk/cursor/default");
goto from_texture;
}
none:
*hotspot_x = 0;
*hotspot_y = 0;
*width = 0;
*height = 0;
*scale = 1;
return NULL;
g_assert_not_reached ();
}
guint

View File

@@ -97,6 +97,7 @@
#define OUTPUT_VERSION_WITH_DONE 2
#define NO_XDG_OUTPUT_DONE_SINCE_VERSION 3
#define OUTPUT_VERSION 3
#define XDG_WM_DIALOG_VERSION 1
#ifdef HAVE_TOPLEVEL_STATE_SUSPENDED
#define XDG_WM_BASE_VERSION 6
@@ -382,6 +383,13 @@ gdk_registry_handle_global (void *data,
{
display_wayland->zxdg_shell_v6_id = id;
}
else if (strcmp (interface, "xdg_wm_dialog_v1") == 0)
{
display_wayland->xdg_wm_dialog =
wl_registry_bind (display_wayland->wl_registry, id,
&xdg_wm_dialog_v1_interface,
MIN (version, XDG_WM_DIALOG_VERSION));
}
else if (strcmp (interface, "gtk_shell1") == 0)
{
display_wayland->gtk_shell =

Some files were not shown because too many files have changed in this diff Show More