Merge branch 'matthiasc/for-main' into 'main'

inspector: Clean up refcounting in the recorder

Closes #6634

See merge request GNOME/gtk!7149
This commit is contained in:
Matthias Clasen 2024-04-18 00:33:17 +00:00
commit ee67edbe3a
5 changed files with 90 additions and 70 deletions

5
NEWS
View File

@ -7,6 +7,9 @@ Overview of Changes in 4.15.0, xx-xx-xxxx
* GtkGLArea: * GtkGLArea:
- Produce dmabuf textures, so graphics offload is possible - Produce dmabuf textures, so graphics offload is possible
* GtkGraphicsOffload:
- Add a black-background property
* Accessibility: * Accessibility:
- Add support for GetRangeExtents to GtkAccessibleText - Add support for GetRangeExtents to GtkAccessibleText
- Add support for GetOffsetAtPoint to GtkAccessibleText - Add support for GetOffsetAtPoint to GtkAccessibleText
@ -22,6 +25,8 @@ Overview of Changes in 4.15.0, xx-xx-xxxx
* X11: * X11:
- Fix some confusing debug messages - Fix some confusing debug messages
- Drop a no-longer-relevant optimization that was interfering with
getting the current window manager capabilities
* macOS: * macOS:
- Implement the color picker for macOS 10.15+ - Implement the color picker for macOS 10.15+

View File

@ -4013,7 +4013,7 @@ gsk_gl_render_job_visit_subsurface_node (GskGLRenderJob *job,
/* Clear the area so we can see through */ /* Clear the area so we can see through */
GskGLCommandBatch *batch; GskGLCommandBatch *batch;
guint16 color[4]; guint16 color[4];
rgba_to_half (&GDK_RGBA_BLACK, color); rgba_to_half (&GDK_RGBA_TRANSPARENT, color);
batch = gsk_gl_command_queue_get_batch (job->command_queue); batch = gsk_gl_command_queue_get_batch (job->command_queue);
batch->draw.blend = 0; batch->draw.blend = 0;

View File

@ -97,16 +97,16 @@ object_property_finalize (GObject *object)
g_free (self->name); g_free (self->name);
g_free (self->value); g_free (self->value);
g_object_unref (self->texture); g_clear_object (&self->texture);
G_OBJECT_CLASS (object_property_parent_class)->finalize (object); G_OBJECT_CLASS (object_property_parent_class)->finalize (object);
} }
static void static void
object_property_get_property (GObject *object, object_property_get_property (GObject *object,
guint property_id, guint property_id,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
ObjectProperty *self = OBJECT_PROPERTY (object); ObjectProperty *self = OBJECT_PROPERTY (object);
@ -854,9 +854,12 @@ get_linear_gradient_texture (gsize n_stops, const GskColorStop *stops)
} }
static void static void
list_store_adopt (GListStore *store, list_store_add_object_property (GListStore *store,
gpointer object) const char *name,
const char *value,
GdkTexture *texture)
{ {
gpointer object = object_property_new (name, value, texture);
g_list_store_append (store, object); g_list_store_append (store, object);
g_object_unref (object); g_object_unref (object);
} }
@ -866,7 +869,7 @@ add_text_row (GListStore *store,
const char *name, const char *name,
const char *text) const char *text)
{ {
list_store_adopt (store, object_property_new (name, text, NULL)); list_store_add_object_property (store, name, text, NULL);
} }
static void static void
@ -879,7 +882,7 @@ add_color_row (GListStore *store,
text = gdk_rgba_to_string (color); text = gdk_rgba_to_string (color);
texture = get_color_texture (color); texture = get_color_texture (color);
list_store_adopt (store, object_property_new (name, text, texture)); list_store_add_object_property (store, name, text, texture);
g_free (text); g_free (text);
g_object_unref (texture); g_object_unref (texture);
} }
@ -979,22 +982,23 @@ populate_render_node_properties (GListStore *store,
texture = gdk_texture_new_for_surface (drawn_surface); texture = gdk_texture_new_for_surface (drawn_surface);
cairo_surface_destroy (drawn_surface); cairo_surface_destroy (drawn_surface);
list_store_adopt (store, object_property_new ("Surface", NULL, texture)); list_store_add_object_property (store, "Surface", NULL, texture);
g_object_unref (texture);
} }
break; break;
case GSK_TEXTURE_NODE: case GSK_TEXTURE_NODE:
{ {
GdkTexture *texture = g_object_ref (gsk_texture_node_get_texture (node)); GdkTexture *texture = gsk_texture_node_get_texture (node);
list_store_adopt (store, object_property_new ("Texture", NULL, texture)); list_store_add_object_property (store, "Texture", NULL, texture);
} }
break; break;
case GSK_TEXTURE_SCALE_NODE: case GSK_TEXTURE_SCALE_NODE:
{ {
GdkTexture *texture = g_object_ref (gsk_texture_scale_node_get_texture (node)); GdkTexture *texture = gsk_texture_scale_node_get_texture (node);
GskScalingFilter filter = gsk_texture_scale_node_get_filter (node); GskScalingFilter filter = gsk_texture_scale_node_get_filter (node);
list_store_adopt (store, object_property_new ("Texture", NULL, texture)); list_store_add_object_property (store, "Texture", NULL, texture);
tmp = g_enum_to_string (GSK_TYPE_SCALING_FILTER, filter); tmp = g_enum_to_string (GSK_TYPE_SCALING_FILTER, filter);
add_text_row (store, "Filter", tmp); add_text_row (store, "Filter", tmp);
@ -1030,7 +1034,7 @@ populate_render_node_properties (GListStore *store,
} }
texture = get_linear_gradient_texture (n_stops, stops); texture = get_linear_gradient_texture (n_stops, stops);
list_store_adopt (store, object_property_new ("Color Stops", s->str, texture)); list_store_add_object_property (store, "Color Stops", s->str, texture);
g_object_unref (texture); g_object_unref (texture);
g_string_free (s, TRUE); g_string_free (s, TRUE);
@ -1072,7 +1076,7 @@ populate_render_node_properties (GListStore *store,
} }
texture = get_linear_gradient_texture (n_stops, stops); texture = get_linear_gradient_texture (n_stops, stops);
list_store_adopt (store, object_property_new ("Color Stops", s->str, texture)); list_store_add_object_property (store, "Color Stops", s->str, texture);
g_object_unref (texture); g_object_unref (texture);
g_string_free (s, TRUE); g_string_free (s, TRUE);
@ -1106,7 +1110,7 @@ populate_render_node_properties (GListStore *store,
} }
texture = get_linear_gradient_texture (n_stops, stops); texture = get_linear_gradient_texture (n_stops, stops);
list_store_adopt (store, object_property_new ("Color Stops", s->str, texture)); list_store_add_object_property (store, "Color Stops", s->str, texture);
g_object_unref (texture); g_object_unref (texture);
g_string_free (s, TRUE); g_string_free (s, TRUE);
@ -1155,7 +1159,7 @@ populate_render_node_properties (GListStore *store,
text = gdk_rgba_to_string (&colors[i]); text = gdk_rgba_to_string (&colors[i]);
tmp = g_strdup_printf ("%.2f, %s", widths[i], text); tmp = g_strdup_printf ("%.2f, %s", widths[i], text);
texture = get_color_texture (&colors[i]); texture = get_color_texture (&colors[i]);
list_store_adopt (store, object_property_new (name[i], tmp, texture)); list_store_add_object_property (store, name[i], tmp, texture);
g_object_unref (texture); g_object_unref (texture);
g_free (text); g_free (text);

View File

@ -5,6 +5,7 @@
#include "gtknative.h" #include "gtknative.h"
#include "gdksurfaceprivate.h" #include "gdksurfaceprivate.h"
#include "gdksubsurfaceprivate.h" #include "gdksubsurfaceprivate.h"
#include "gdkrgbaprivate.h"
struct _GtkSubsurfaceOverlay struct _GtkSubsurfaceOverlay
{ {
@ -39,26 +40,26 @@ gtk_subsurface_overlay_snapshot (GtkInspectorOverlay *overlay,
for (gsize i = 0; i < gdk_surface_get_n_subsurfaces (surface); i++) for (gsize i = 0; i < gdk_surface_get_n_subsurfaces (surface); i++)
{ {
GdkSubsurface *subsurface = gdk_surface_get_subsurface (surface, i); GdkSubsurface *subsurface = gdk_surface_get_subsurface (surface, i);
graphene_rect_t dest; graphene_rect_t rect;
GdkRGBA color; GdkRGBA color;
if (gdk_subsurface_get_texture (subsurface) == NULL) if (gdk_subsurface_get_texture (subsurface) == NULL)
continue; continue;
if (gdk_subsurface_is_above_parent (subsurface)) gdk_subsurface_get_texture_rect (subsurface, &rect);
gdk_rgba_parse (&color, "goldenrod");
else
gdk_rgba_parse (&color, "magenta");
gdk_subsurface_get_texture_rect (subsurface, &dest); if (gdk_subsurface_is_above_parent (subsurface))
color = GDK_RGBA ("DAA520"); /* goldenrod */
else
color = GDK_RGBA ("FF00FF"); /* magenta */
/* Use 4 color nodes since a border node overlaps and prevents /* Use 4 color nodes since a border node overlaps and prevents
* the subsurface from being raised. * the subsurface from being raised.
*/ */
gtk_snapshot_append_color (snapshot, &color, &GRAPHENE_RECT_INIT (dest.origin.x - 2, dest.origin.y - 2, 2, dest.size.height + 4)); gtk_snapshot_append_color (snapshot, &color, &GRAPHENE_RECT_INIT (rect.origin.x - 2, rect.origin.y - 2, 2, rect.size.height + 4));
gtk_snapshot_append_color (snapshot, &color, &GRAPHENE_RECT_INIT (dest.origin.x - 2, dest.origin.y - 2, dest.size.width + 4, 2)); gtk_snapshot_append_color (snapshot, &color, &GRAPHENE_RECT_INIT (rect.origin.x - 2, rect.origin.y - 2, rect.size.width + 4, 2));
gtk_snapshot_append_color (snapshot, &color, &GRAPHENE_RECT_INIT (dest.origin.x - 2, dest.origin.y + dest.size.height, dest.size.width + 4, 2)); gtk_snapshot_append_color (snapshot, &color, &GRAPHENE_RECT_INIT (rect.origin.x - 2, rect.origin.y + rect.size.height, rect.size.width + 4, 2));
gtk_snapshot_append_color (snapshot, &color, &GRAPHENE_RECT_INIT (dest.origin.x + dest.size.width, dest.origin.y - 2, 2, dest.size.height + 4)); gtk_snapshot_append_color (snapshot, &color, &GRAPHENE_RECT_INIT (rect.origin.x + rect.size.width, rect.origin.y - 2, 2, rect.size.height + 4));
} }
gtk_snapshot_restore (snapshot); gtk_snapshot_restore (snapshot);

View File

@ -110,6 +110,7 @@ struct _GtkInspectorVisual
GtkInspectorOverlay *subsurface_overlay; GtkInspectorOverlay *subsurface_overlay;
GdkDisplay *display; GdkDisplay *display;
GtkSettings *settings;
}; };
typedef struct _GtkInspectorVisualClass typedef struct _GtkInspectorVisualClass
@ -197,27 +198,22 @@ get_dpi_ratio (GtkInspectorVisual *vis)
static double static double
get_font_scale (GtkInspectorVisual *vis) get_font_scale (GtkInspectorVisual *vis)
{ {
double ratio = get_dpi_ratio (vis);
int dpi_int; int dpi_int;
g_object_get (gtk_settings_get_for_display (vis->display), g_object_get (vis->settings, "gtk-xft-dpi", &dpi_int, NULL);
"gtk-xft-dpi", &dpi_int,
NULL);
return dpi_int / ratio; return dpi_int / get_dpi_ratio (vis);
} }
static void static void
update_font_scale (GtkInspectorVisual *vis, update_font_scale (GtkInspectorVisual *vis,
double factor, double factor,
gboolean update_adjustment, gboolean update_adjustment,
gboolean update_entry) gboolean update_entry,
gboolean write_back)
{ {
double ratio = get_dpi_ratio (vis); if (write_back)
g_object_set (vis->settings, "gtk-xft-dpi", (int)(factor * get_dpi_ratio (vis)), NULL);
g_object_set (gtk_settings_get_for_display (vis->display),
"gtk-xft-dpi", (int)(factor * ratio),
NULL);
if (update_adjustment) if (update_adjustment)
gtk_adjustment_set_value (vis->font_scale_adjustment, factor); gtk_adjustment_set_value (vis->font_scale_adjustment, factor);
@ -238,7 +234,7 @@ font_scale_adjustment_changed (GtkAdjustment *adjustment,
double factor; double factor;
factor = gtk_adjustment_get_value (adjustment); factor = gtk_adjustment_get_value (adjustment);
update_font_scale (vis, factor, FALSE, TRUE); update_font_scale (vis, factor, FALSE, TRUE, TRUE);
} }
static gboolean static gboolean
@ -246,9 +242,7 @@ get_font_aa (GtkInspectorVisual *vis)
{ {
int aa; int aa;
g_object_get (gtk_settings_get_for_display (vis->display), g_object_get (vis->settings, "gtk-xft-antialias", &aa, NULL);
"gtk-xft-antialias", &aa,
NULL);
return aa != 0; return aa != 0;
} }
@ -258,9 +252,7 @@ get_metrics_hinting (GtkInspectorVisual *vis)
{ {
gboolean hinting; gboolean hinting;
g_object_get (gtk_settings_get_for_display (vis->display), g_object_get (vis->settings, "gtk-hint-font-metrics", &hinting, NULL);
"gtk-hint-font-metrics", &hinting,
NULL);
return hinting; return hinting;
} }
@ -272,7 +264,7 @@ get_font_hinting (GtkInspectorVisual *vis)
char *hint_style_str; char *hint_style_str;
unsigned int hint_style; unsigned int hint_style;
g_object_get (gtk_settings_get_for_display (vis->display), g_object_get (vis->settings,
"gtk-xft-hinting", &hinting, "gtk-xft-hinting", &hinting,
"gtk-xft-hintstyle", &hint_style_str, "gtk-xft-hintstyle", &hint_style_str,
NULL); NULL);
@ -304,11 +296,19 @@ update_font_hinting (GtkInspectorVisual *vis,
unsigned int hint_style) unsigned int hint_style)
{ {
const char *styles[] = { "hintnone", "hintslight", "hintmedium", "hintfull" }; const char *styles[] = { "hintnone", "hintslight", "hintmedium", "hintfull" };
int hinting;
const char *style;
g_object_set (gtk_settings_get_for_display (vis->display), g_object_get (vis->settings,
"gtk-xft-hinting", hint_style != 0, "gtk-xft-hinting", &hinting,
"gtk-xft-hintstyle", styles[hint_style], "gtk-xft-hintstyle", &style,
NULL); NULL);
if (hinting != (hint_style != 0) || strcmp (style, styles[hint_style]) != 0)
g_object_set (vis->settings,
"gtk-xft-hinting", hint_style != 0,
"gtk-xft-hintstyle", styles[hint_style],
NULL);
} }
static void static void
@ -316,9 +316,14 @@ font_aa_activate (GtkSwitch *sw,
GParamSpec *pspec, GParamSpec *pspec,
GtkInspectorVisual *vis) GtkInspectorVisual *vis)
{ {
g_object_set (gtk_settings_get_for_display (vis->display), int val, new_val;
"gtk-xft-antialias", gtk_switch_get_active (sw) ? 1 : 0,
NULL); g_object_get (vis->settings, "gtk-xft-antialias", &val, NULL);
new_val = gtk_switch_get_active (sw) ? 1 : 0;
if (val != new_val)
g_object_set (vis->settings, "gtk-xft-antialias", new_val, NULL);
} }
static void static void
@ -326,10 +331,16 @@ metrics_hinting_activate (GtkSwitch *sw,
GParamSpec *pspec, GParamSpec *pspec,
GtkInspectorVisual *vis) GtkInspectorVisual *vis)
{ {
g_object_set (gtk_settings_get_for_display (vis->display), gboolean val, new_val;
"gtk-hint-font-metrics", gtk_switch_get_active (sw),
NULL); g_object_get (vis->settings, "gtk-hint-font-metrics", &val, NULL);
new_val = gtk_switch_get_active (sw);
if (val != new_val)
g_object_set (vis->settings, "gtk-hint-font-metrics", new_val, NULL);
} }
static void static void
font_scale_entry_activated (GtkEntry *entry, font_scale_entry_activated (GtkEntry *entry,
GtkInspectorVisual *vis) GtkInspectorVisual *vis)
@ -339,7 +350,7 @@ font_scale_entry_activated (GtkEntry *entry,
factor = g_strtod (gtk_editable_get_text (GTK_EDITABLE (entry)), &err); factor = g_strtod (gtk_editable_get_text (GTK_EDITABLE (entry)), &err);
if (err != NULL) if (err != NULL)
update_font_scale (vis, factor, TRUE, FALSE); update_font_scale (vis, factor, TRUE, FALSE, TRUE);
} }
static void static void
@ -750,7 +761,7 @@ init_theme (GtkInspectorVisual *vis)
gtk_drop_down_set_model (GTK_DROP_DOWN (vis->theme_combo), G_LIST_MODEL (names)); gtk_drop_down_set_model (GTK_DROP_DOWN (vis->theme_combo), G_LIST_MODEL (names));
g_object_bind_property_full (gtk_settings_get_for_display (vis->display), "gtk-theme-name", g_object_bind_property_full (vis->settings, "gtk-theme-name",
vis->theme_combo, "selected", vis->theme_combo, "selected",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref); theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref);
@ -769,8 +780,7 @@ init_theme (GtkInspectorVisual *vis)
static void static void
init_dark (GtkInspectorVisual *vis) init_dark (GtkInspectorVisual *vis)
{ {
g_object_bind_property (gtk_settings_get_for_display (vis->display), g_object_bind_property (vis->settings, "gtk-application-prefer-dark-theme",
"gtk-application-prefer-dark-theme",
vis->dark_switch, "active", vis->dark_switch, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
@ -854,7 +864,7 @@ init_icons (GtkInspectorVisual *vis)
gtk_drop_down_set_model (GTK_DROP_DOWN (vis->icon_combo), G_LIST_MODEL (names)); gtk_drop_down_set_model (GTK_DROP_DOWN (vis->icon_combo), G_LIST_MODEL (names));
g_object_bind_property_full (gtk_settings_get_for_display (vis->display), "gtk-icon-theme-name", g_object_bind_property_full (vis->settings, "gtk-icon-theme-name",
vis->icon_combo, "selected", vis->icon_combo, "selected",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref); theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref);
@ -928,7 +938,7 @@ init_cursors (GtkInspectorVisual *vis)
gtk_drop_down_set_model (GTK_DROP_DOWN (vis->cursor_combo), G_LIST_MODEL (names)); gtk_drop_down_set_model (GTK_DROP_DOWN (vis->cursor_combo), G_LIST_MODEL (names));
g_object_bind_property_full (gtk_settings_get_for_display (vis->display), "gtk-cursor-theme-name", g_object_bind_property_full (vis->settings, "gtk-cursor-theme-name",
vis->cursor_combo, "selected", vis->cursor_combo, "selected",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref); theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref);
@ -940,7 +950,7 @@ cursor_size_changed (GtkAdjustment *adjustment, GtkInspectorVisual *vis)
int size; int size;
size = gtk_adjustment_get_value (adjustment); size = gtk_adjustment_get_value (adjustment);
g_object_set (gtk_settings_get_for_display (vis->display), "gtk-cursor-theme-size", size, NULL); g_object_set (vis->settings, "gtk-cursor-theme-size", size, NULL);
} }
static void static void
@ -948,7 +958,7 @@ init_cursor_size (GtkInspectorVisual *vis)
{ {
int size; int size;
g_object_get (gtk_settings_get_for_display (vis->display), "gtk-cursor-theme-size", &size, NULL); g_object_get (vis->settings, "gtk-cursor-theme-size", &size, NULL);
if (size == 0) if (size == 0)
size = 32; size = 32;
@ -994,8 +1004,7 @@ name_from_desc (GBinding *binding,
static void static void
init_font (GtkInspectorVisual *vis) init_font (GtkInspectorVisual *vis)
{ {
g_object_bind_property_full (gtk_settings_get_for_display (vis->display), g_object_bind_property_full (vis->settings, "gtk-font-name",
"gtk-font-name",
vis->font_button, "font-desc", vis->font_button, "font-desc",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE, G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE,
name_to_desc, name_to_desc,
@ -1009,7 +1018,7 @@ init_font_scale (GtkInspectorVisual *vis)
double scale; double scale;
scale = get_font_scale (vis); scale = get_font_scale (vis);
update_font_scale (vis, scale, TRUE, TRUE); update_font_scale (vis, scale, TRUE, TRUE, FALSE);
g_signal_connect (vis->font_scale_adjustment, "value-changed", g_signal_connect (vis->font_scale_adjustment, "value-changed",
G_CALLBACK (font_scale_adjustment_changed), vis); G_CALLBACK (font_scale_adjustment_changed), vis);
g_signal_connect (vis->font_scale_entry, "activate", g_signal_connect (vis->font_scale_entry, "activate",
@ -1045,7 +1054,7 @@ init_metrics_hinting (GtkInspectorVisual *vis)
static void static void
init_animation (GtkInspectorVisual *vis) init_animation (GtkInspectorVisual *vis)
{ {
g_object_bind_property (gtk_settings_get_for_display (vis->display), "gtk-enable-animations", g_object_bind_property (vis->settings, "gtk-enable-animations",
vis->animation_switch, "active", vis->animation_switch, "active",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE); G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
} }
@ -1324,10 +1333,11 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
} }
void void
gtk_inspector_visual_set_display (GtkInspectorVisual *vis, gtk_inspector_visual_set_display (GtkInspectorVisual *vis,
GdkDisplay *display) GdkDisplay *display)
{ {
vis->display = display; vis->display = display;
vis->settings = gtk_settings_get_for_display (display);
init_direction (vis); init_direction (vis);
init_theme (vis); init_theme (vis);