From 25ea6beb39a7949d33620750d18a934b12bcf96b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 20 Jan 2024 09:38:53 -0500 Subject: [PATCH 1/6] inspector: Fix a typo --- gtk/inspector/logs.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/inspector/logs.ui b/gtk/inspector/logs.ui index e94853743f..9b0c82b921 100644 --- a/gtk/inspector/logs.ui +++ b/gtk/inspector/logs.ui @@ -159,7 +159,7 @@ - + Verbose From 9ebaafa2af0a4252d38eb8c91cad7b9138b5448f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 20 Jan 2024 11:00:33 -0500 Subject: [PATCH 2/6] gsk: Inline some more rect functions When we use graphene_rect_scale, the rect is always normalized, so we can avoid some overhead here. --- gsk/gskrectprivate.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gsk/gskrectprivate.h b/gsk/gskrectprivate.h index b6c2f517fe..cf062accd6 100644 --- a/gsk/gskrectprivate.h +++ b/gsk/gskrectprivate.h @@ -132,3 +132,20 @@ gsk_rect_round_larger (graphene_rect_t *rect) ceil (rect->origin.y + rect->size.height) - y); } +static inline void +gsk_rect_scale (const graphene_rect_t *r, + float sx, + float sy, + graphene_rect_t *res) +{ + if (G_UNLIKELY (sx < 0 || sy < 0)) + { + graphene_rect_scale (r, sx, sy, res); + return; + } + + res->origin.x = r->origin.x * sx; + res->origin.y = r->origin.y * sy; + res->size.width = r->size.width * sx; + res->size.height = r->size.height * sy; +} From 0d7761269c7a18ae470d8ec57dc11ab95da224b3 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 20 Jan 2024 11:01:37 -0500 Subject: [PATCH 3/6] gpu: Use gsk_rect_scale --- gsk/gpu/gskgpunodeprocessor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gsk/gpu/gskgpunodeprocessor.c b/gsk/gpu/gskgpunodeprocessor.c index 9f56416bbf..90a005416c 100644 --- a/gsk/gpu/gskgpunodeprocessor.c +++ b/gsk/gpu/gskgpunodeprocessor.c @@ -3015,8 +3015,8 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self, &glyph_bounds, &glyph_offset); - graphene_rect_scale (&GRAPHENE_RECT_INIT (-glyph_bounds.origin.x, -glyph_bounds.origin.y, gsk_gpu_image_get_width (image), gsk_gpu_image_get_height (image)), inv_scale, inv_scale, &glyph_tex_rect); - graphene_rect_scale (&GRAPHENE_RECT_INIT(0, 0, glyph_bounds.size.width, glyph_bounds.size.height), inv_scale, inv_scale, &glyph_bounds); + gsk_rect_scale (&GRAPHENE_RECT_INIT (-glyph_bounds.origin.x, -glyph_bounds.origin.y, gsk_gpu_image_get_width (image), gsk_gpu_image_get_height (image)), inv_scale, inv_scale, &glyph_tex_rect); + gsk_rect_scale (&GRAPHENE_RECT_INIT(0, 0, glyph_bounds.size.width, glyph_bounds.size.height), inv_scale, inv_scale, &glyph_bounds); glyph_offset = GRAPHENE_POINT_INIT (offset.x - glyph_offset.x * inv_scale + (float) glyphs[i].geometry.x_offset / PANGO_SCALE, offset.y - glyph_offset.y * inv_scale + (float) glyphs[i].geometry.y_offset / PANGO_SCALE); descriptor = gsk_gpu_node_processor_add_image (self, image, GSK_GPU_SAMPLER_DEFAULT); From 56b955f819b7886a5005c1a698facd1898edcf40 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 20 Jan 2024 11:12:26 -0500 Subject: [PATCH 4/6] roundedrect: Use fabsf The arguments are floats. --- gsk/gskroundedrect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gsk/gskroundedrect.c b/gsk/gskroundedrect.c index 2e3d8380c0..76477c290d 100644 --- a/gsk/gskroundedrect.c +++ b/gsk/gskroundedrect.c @@ -311,8 +311,8 @@ gsk_rounded_rect_scale_affine (GskRoundedRect *dest, graphene_rect_scale (&src->bounds, scale_x, scale_y, &dest->bounds); graphene_rect_offset (&dest->bounds, dx, dy); - scale_x = fabs (scale_x); - scale_y = fabs (scale_y); + scale_x = fabsf (scale_x); + scale_y = fabsf (scale_y); for (guint i = 0; i < 4; i++) { From f01208ad9482cf93850ea2a6f159690b6a615446 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 20 Jan 2024 11:02:26 -0500 Subject: [PATCH 5/6] gpu: Consistently use ceilf There was a mix of ceil() and ceilf() calls here, but the arguments are always floats, so use ceilf() throughout. --- gsk/gpu/gskgpunodeprocessor.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gsk/gpu/gskgpunodeprocessor.c b/gsk/gpu/gskgpunodeprocessor.c index 90a005416c..b736e51d32 100644 --- a/gsk/gpu/gskgpunodeprocessor.c +++ b/gsk/gpu/gskgpunodeprocessor.c @@ -322,8 +322,8 @@ rect_round_to_pixels (const graphene_rect_t *src, *dest = GRAPHENE_RECT_INIT ( x * inv_xscale - pixel_offset->x, y * inv_yscale - pixel_offset->y, - (ceil ((src->origin.x + pixel_offset->x + src->size.width) * xscale) - x) * inv_xscale, - (ceil ((src->origin.y + pixel_offset->y + src->size.height) * yscale) - y) * inv_yscale); + (ceilf ((src->origin.x + pixel_offset->x + src->size.width) * xscale) - x) * inv_xscale, + (ceilf ((src->origin.y + pixel_offset->y + src->size.height) * yscale) - y) * inv_yscale); } static GskGpuImage * @@ -338,8 +338,8 @@ gsk_gpu_node_processor_init_draw (GskGpuNodeProcessor *self, area.x = 0; area.y = 0; - area.width = ceil (graphene_vec2_get_x (scale) * viewport->size.width); - area.height = ceil (graphene_vec2_get_y (scale) * viewport->size.height); + area.width = ceilf (graphene_vec2_get_x (scale) * viewport->size.width); + area.height = ceilf (graphene_vec2_get_y (scale) * viewport->size.height); image = gsk_gpu_device_create_offscreen_image (gsk_gpu_frame_get_device (frame), FALSE, @@ -994,8 +994,8 @@ gsk_gpu_node_processor_blur_op (GskGpuNodeProcessor *self, if (!gsk_rect_intersection (rect, &clip_rect, &intermediate_rect)) return; - width = ceil (graphene_vec2_get_x (&self->scale) * intermediate_rect.size.width); - height = ceil (graphene_vec2_get_y (&self->scale) * intermediate_rect.size.height); + width = ceilf (graphene_vec2_get_x (&self->scale) * intermediate_rect.size.width); + height = ceilf (graphene_vec2_get_y (&self->scale) * intermediate_rect.size.height); intermediate = gsk_gpu_device_create_offscreen_image (gsk_gpu_frame_get_device (self->frame), FALSE, @@ -1814,10 +1814,10 @@ gsk_gpu_node_processor_add_color_node (GskGpuNodeProcessor *self, if (shader_clip != GSK_GPU_SHADER_CLIP_NONE) { gsk_rounded_rect_get_largest_cover (&self->clip.rect, &clipped, &cover); - int_clipped.x = ceil (cover.origin.x * scale_x); - int_clipped.y = ceil (cover.origin.y * scale_y); - int_clipped.width = floor ((cover.origin.x + cover.size.width) * scale_x) - int_clipped.x; - int_clipped.height = floor ((cover.origin.y + cover.size.height) * scale_y) - int_clipped.y; + int_clipped.x = ceilf (cover.origin.x * scale_x); + int_clipped.y = ceilf (cover.origin.y * scale_y); + int_clipped.width = floorf ((cover.origin.x + cover.size.width) * scale_x) - int_clipped.x; + int_clipped.height = floorf ((cover.origin.y + cover.size.height) * scale_y) - int_clipped.y; if (int_clipped.width == 0 || int_clipped.height == 0) { gsk_gpu_color_op (self->frame, From a91a0720f5e404e8756ecc426f1f4479a51831a7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 20 Jan 2024 11:52:42 -0500 Subject: [PATCH 6/6] gl: Consistently use float apis --- gsk/gl/gskglrenderjob.c | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/gsk/gl/gskglrenderjob.c b/gsk/gl/gskglrenderjob.c index 796e946bb6..31b22d947c 100644 --- a/gsk/gl/gskglrenderjob.c +++ b/gsk/gl/gskglrenderjob.c @@ -830,8 +830,8 @@ rounded_rect_scale_corners (const GskRoundedRect *rect, { for (guint i = 0; i < G_N_ELEMENTS (out_rect->corner); i++) { - out_rect->corner[i].width = rect->corner[i].width * fabs (scale_x); - out_rect->corner[i].height = rect->corner[i].height * fabs (scale_y); + out_rect->corner[i].width = rect->corner[i].width * fabsf (scale_x); + out_rect->corner[i].height = rect->corner[i].height * fabsf (scale_y); } if (scale_x < 0) @@ -1173,8 +1173,8 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job, { float scale_x = job->scale_x; float scale_y = job->scale_y; - int surface_width = ceilf (node->bounds.size.width * fabs (scale_x)); - int surface_height = ceilf (node->bounds.size.height * fabs (scale_y)); + int surface_width = ceilf (node->bounds.size.width * fabsf (scale_x)); + int surface_height = ceilf (node->bounds.size.height * fabsf (scale_y)); GdkTexture *texture; cairo_surface_t *surface; cairo_surface_t *rendered_surface; @@ -1203,7 +1203,7 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job, surface_width, surface_height); - cairo_surface_set_device_scale (rendered_surface, fabs (scale_x), fabs (scale_y)); + cairo_surface_set_device_scale (rendered_surface, fabsf (scale_x), fabsf (scale_y)); cr = cairo_create (rendered_surface); cairo_save (cr); @@ -1217,16 +1217,16 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job, surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, surface_width, surface_height); - cairo_surface_set_device_scale (surface, fabs (scale_x), fabs (scale_y)); + cairo_surface_set_device_scale (surface, fabsf (scale_x), fabsf (scale_y)); cr = cairo_create (surface); /* We draw upside down here, so it matches what GL does. */ cairo_save (cr); cairo_scale (cr, scale_x < 0 ? -1 : 1, scale_y < 0 ? 1 : -1); - cairo_translate (cr, scale_x < 0 ? - surface_width / fabs (scale_x) : 0, - scale_y < 0 ? 0 : - surface_height / fabs (scale_y)); + cairo_translate (cr, scale_x < 0 ? - surface_width / fabsf (scale_x) : 0, + scale_y < 0 ? 0 : - surface_height / fabsf (scale_y)); cairo_set_source_surface (cr, rendered_surface, 0, 0); - cairo_rectangle (cr, 0, 0, surface_width / fabs (scale_x), surface_height / fabs (scale_y)); + cairo_rectangle (cr, 0, 0, surface_width / fabsf (scale_x), surface_height / fabsf (scale_y)); cairo_fill (cr); cairo_restore (cr); cairo_destroy (cr); @@ -1432,10 +1432,10 @@ blur_node (GskGLRenderJob *job, offscreen->texture_id = blur_offscreen (job, offscreen, - texture_width * fabs (scale_x), - texture_height * fabs (scale_y), - blur_radius * fabs (scale_x), - blur_radius * fabs (scale_y)); + texture_width * fabsf (scale_x), + texture_height * fabsf (scale_y), + blur_radius * fabsf (scale_x), + blur_radius * fabsf (scale_y)); init_full_texture_region (offscreen); } @@ -2019,9 +2019,9 @@ result_is_axis_aligned (GskTransform *transform, for (guint i = 0; i < 4; i++) { p = graphene_quad_get_point (&q, i); - if (fabs (p->x - b1.x) > FLT_EPSILON && fabs (p->x - b2.x) > FLT_EPSILON) + if (fabsf (p->x - b1.x) > FLT_EPSILON && fabsf (p->x - b2.x) > FLT_EPSILON) return FALSE; - if (fabs (p->y - b1.y) > FLT_EPSILON && fabs (p->y - b2.y) > FLT_EPSILON) + if (fabsf (p->y - b1.y) > FLT_EPSILON && fabsf (p->y - b2.y) > FLT_EPSILON) return FALSE; } @@ -2304,8 +2304,8 @@ gsk_gl_render_job_visit_blurred_inset_shadow_node (GskGLRenderJob *job, &offscreen, texture_width, texture_height, - blur_radius * fabs (scale_x), - blur_radius * fabs (scale_y)); + blur_radius * fabsf (scale_x), + blur_radius * fabsf (scale_y)); gsk_gl_driver_release_render_target (job->driver, render_target, TRUE); @@ -2501,8 +2501,8 @@ gsk_gl_render_job_visit_blurred_outset_shadow_node (GskGLRenderJob *job, do_slicing = TRUE; } - texture_width = (int)ceil ((scaled_outline.bounds.size.width + blur_extra) * scale_x); - texture_height = (int)ceil ((scaled_outline.bounds.size.height + blur_extra) * scale_y); + texture_width = (int)ceilf ((scaled_outline.bounds.size.width + blur_extra) * scale_x); + texture_height = (int)ceilf ((scaled_outline.bounds.size.height + blur_extra) * scale_y); scaled_outline.bounds.origin.x = extra_blur_pixels_x; scaled_outline.bounds.origin.y = extra_blur_pixels_y; @@ -2577,8 +2577,8 @@ gsk_gl_render_job_visit_blurred_outset_shadow_node (GskGLRenderJob *job, &offscreen, texture_width, texture_height, - blur_radius * fabs (scale_x), - blur_radius * fabs (scale_y)); + blur_radius * fabsf (scale_x), + blur_radius * fabsf (scale_y)); gsk_gl_shadow_library_insert (job->driver->shadows_library, &scaled_outline, @@ -2834,7 +2834,7 @@ gsk_gl_render_job_visit_cross_fade_node (GskGLRenderJob *job, offscreen_end.reset_clip = TRUE; offscreen_end.bounds = &node->bounds; - gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabs (job->scale_x), fabs (job->scale_y))); + gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabsf (job->scale_x), fabsf (job->scale_y))); if (!gsk_gl_render_job_visit_node_with_offscreen (job, start_node, &offscreen_start)) { @@ -2964,7 +2964,7 @@ gsk_gl_render_job_visit_text_node (GskGLRenderJob *job, const PangoFont *font = gsk_text_node_get_font (node); const PangoGlyphInfo *glyphs = gsk_text_node_get_glyphs (node, NULL); const graphene_point_t *offset = gsk_text_node_get_offset (node); - float text_scale = MAX (fabs (job->scale_x), fabs (job->scale_y)); /* TODO: Fix for uneven scales? */ + float text_scale = MAX (fabsf (job->scale_x), fabsf (job->scale_y)); /* TODO: Fix for uneven scales? */ guint num_glyphs = gsk_text_node_get_num_glyphs (node); float x = offset->x + job->offset_x; float y = offset->y + job->offset_y; @@ -3263,7 +3263,7 @@ gsk_gl_render_job_visit_blend_node (GskGLRenderJob *job, bottom_offscreen.force_offscreen = TRUE; bottom_offscreen.reset_clip = TRUE; - gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabs (job->scale_x), fabs (job->scale_y))); + gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabsf (job->scale_x), fabsf (job->scale_y))); /* TODO: We create 2 textures here as big as the blend node, but both the * start and the end node might be a lot smaller than that. */ @@ -3344,8 +3344,8 @@ gsk_gl_render_job_texture_mask_for_color (GskGLRenderJob *job, gboolean use_mipmap; guint16 cc[4]; - use_mipmap = (scale_x * fabs (job->scale_x)) < 0.5 || - (scale_y * fabs (job->scale_y)) < 0.5; + use_mipmap = (scale_x * fabsf (job->scale_x)) < 0.5 || + (scale_y * fabsf (job->scale_y)) < 0.5; rgba_to_half (rgba, cc); gsk_gl_render_job_upload_texture (job, texture, use_mipmap, &offscreen); @@ -3396,7 +3396,7 @@ gsk_gl_render_job_visit_mask_node (GskGLRenderJob *job, mask_offscreen.reset_clip = TRUE; mask_offscreen.do_not_cache = TRUE; - gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabs (job->scale_x), fabs (job->scale_y))); + gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabsf (job->scale_x), fabsf (job->scale_y))); /* TODO: We create 2 textures here as big as the mask node, but both * nodes might be a lot smaller than that. @@ -3664,8 +3664,8 @@ gsk_gl_render_job_visit_texture (GskGLRenderJob *job, float scale_y = bounds->size.height / texture->height; gboolean use_mipmap; - use_mipmap = (scale_x * fabs (job->scale_x)) < 0.5 || - (scale_y * fabs (job->scale_y)) < 0.5; + use_mipmap = (scale_x * fabsf (job->scale_x)) < 0.5 || + (scale_y * fabsf (job->scale_y)) < 0.5; if G_LIKELY (texture->width <= max_texture_size && texture->height <= max_texture_size)