Merge branch 'better-masks' into 'main'

gsk: Avoid some offscreens

See merge request GNOME/gtk!5921
This commit is contained in:
Matthias Clasen
2023-05-05 15:56:16 +00:00
3 changed files with 4 additions and 264 deletions

View File

@@ -1750,22 +1750,13 @@ gsk_gl_render_job_visit_rounded_clip_node (GskGLRenderJob *job,
if (job->clip->len <= 1)
need_offscreen = FALSE;
else if (rounded_inner_rect_contains_rect (&job->current_clip->rect, &transformed_clip.bounds))
else if (gsk_rounded_rect_contains_rect (&job->current_clip->rect, &transformed_clip.bounds))
need_offscreen = FALSE;
else
need_offscreen = TRUE;
if (!need_offscreen)
{
/* If the new clip entirely contains the current clip, the intersection is simply
* the current clip, so we can ignore the new one.
*/
if (rounded_inner_rect_contains_rect (&transformed_clip, &job->current_clip->rect.bounds))
{
gsk_gl_render_job_visit_node (job, child);
return;
}
gsk_gl_render_job_push_clip (job, &transformed_clip);
gsk_gl_render_job_visit_node (job, child);
gsk_gl_render_job_pop_clip (job);
@@ -2833,7 +2824,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, NULL);
gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabs (job->scale_x), fabs (job->scale_y)));
if (!gsk_gl_render_job_visit_node_with_offscreen (job, start_node, &offscreen_start))
{
@@ -3252,7 +3243,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, NULL);
gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabs (job->scale_x), fabs (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. */
@@ -3321,7 +3312,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, NULL);
gsk_gl_render_job_set_modelview (job, gsk_transform_scale (NULL, fabs (job->scale_x), fabs (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.

View File

@@ -104,9 +104,6 @@ tests = [
{ 'name': 'revealer-size' },
{ 'name': 'widgetorder' },
{ 'name': 'widget-refcount' },
# This test was disabled for long enough that it no longer compiles
#{ 'name': 'window',
# 'suites': ['failing'] },
]
# Tests that test private apis and therefore are linked against libgtk-4.a

View File

@@ -1,248 +0,0 @@
#include <gtk/gtk.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/x11/gdkx.h>
#include <X11/Xatom.h>
#endif
static gboolean interactive = FALSE;
static gboolean
stop_main (gpointer data)
{
gboolean *done = data;
*done = TRUE;
g_main_context_wakeup (NULL);
return G_SOURCE_REMOVE;
}
static void
on_draw (GtkDrawingArea *da,
cairo_t *cr,
int width,
int height,
gpointer data)
{
int i, j;
for (i = 0; 20 * i < width; i++)
{
for (j = 0; 20 * j < height; j++)
{
if ((i + j) % 2 == 1)
cairo_set_source_rgb (cr, 1., 1., 1.);
else
cairo_set_source_rgb (cr, 0., 0., 0.);
cairo_rectangle (cr, 20. * i, 20. *j, 20., 20.);
cairo_fill (cr);
}
}
}
static gboolean
on_keypress (GtkEventControllerKey *key,
guint keyval,
guint keycode,
GdkModifierType state,
gpointer data)
{
gboolean *done = data;
*done = TRUE;
g_main_context_wakeup (NULL);
return GDK_EVENT_PROPAGATE;
}
static void
test_default_size (void)
{
GtkWidget *window;
GtkWidget *da;
int w, h;
gboolean done;
window = gtk_window_new ();
if (interactive)
{
GtkEventController *controller = gtk_event_controller_key_new ();
g_signal_connect (controller, "key-pressed", G_CALLBACK (on_keypress), &done);
gtk_widget_add_controller (window, controller);
}
da = gtk_drawing_area_new ();
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), on_draw, NULL, NULL);
gtk_window_set_child (GTK_WINDOW (window), da);
/* check that default size is unset initially */
gtk_window_get_default_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, -1);
g_assert_cmpint (h, ==, -1);
/* check that setting default size before realize works */
gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
gtk_window_get_default_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, 300);
g_assert_cmpint (h, ==, 300);
/* check that the window size is also reported accordingly */
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, 300);
g_assert_cmpint (h, ==, 300);
gtk_window_present (GTK_WINDOW (window));
done = FALSE;
if (!interactive)
g_timeout_add (200, stop_main, &done);
while (!done)
g_main_context_iteration (NULL, TRUE);
/* check that the window and its content actually gets the right size */
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, 300);
g_assert_cmpint (h, ==, 300);
g_assert_cmpint (gtk_widget_get_allocated_width (da), ==, 300);
g_assert_cmpint (gtk_widget_get_allocated_height (da), ==, 300);
/* check that setting default size after the fact does not change
* window size
*/
gtk_window_set_default_size (GTK_WINDOW (window), 100, 600);
gtk_window_get_default_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, 100);
g_assert_cmpint (h, ==, 600);
done = FALSE;
if (!interactive)
g_timeout_add (200, stop_main, &done);
while (!done)
g_main_context_iteration (NULL, TRUE);
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, 300);
g_assert_cmpint (h, ==, 300);
/* check that even hide/show does not pull in the new default */
gtk_widget_set_visible (window, FALSE);
gtk_widget_set_visible (window, TRUE);
done = FALSE;
if (!interactive)
g_timeout_add (200, stop_main, &done);
while (!done)
g_main_context_iteration (NULL, TRUE);
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, 300);
g_assert_cmpint (h, ==, 300);
gtk_window_destroy (GTK_WINDOW (window));
}
static void
test_resize_popup (void)
{
GtkWidget *window;
int w, h;
gboolean done;
/* testcase for the dnd window */
window = gtk_window_new ();
gtk_window_set_decorated (GTK_WINDOW (window), FALSE);
gtk_window_set_default_size (GTK_WINDOW (window), 1, 1);
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, 1);
g_assert_cmpint (h, ==, 1);
gtk_window_present (GTK_WINDOW (window));
done = FALSE;
if (!interactive)
g_timeout_add (200, stop_main, &done);
while (!done)
g_main_context_iteration (NULL, TRUE);
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
g_assert_cmpint (w, ==, 1);
g_assert_cmpint (h, ==, 1);
gtk_window_destroy (GTK_WINDOW (window));
}
static void
test_show_hide (void)
{
GtkWidget *window;
int w, h, w1, h1;
gboolean done;
/*http://bugzilla.gnome.org/show_bug.cgi?id=696882 */
/* test that hide/show does not affect the size */
window = gtk_window_new ();
gtk_window_present (GTK_WINDOW (window));
done = FALSE;
if (!interactive)
g_timeout_add (200, stop_main, &done);
while (!done)
g_main_context_iteration (NULL, TRUE);
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
gtk_widget_hide (window);
done = FALSE;
if (!interactive)
g_timeout_add (200, stop_main, &done);
while (!done)
g_main_context_iteration (NULL, TRUE);
gtk_window_get_size (GTK_WINDOW (window), &w1, &h1);
g_assert_cmpint (w, ==, w1);
g_assert_cmpint (h, ==, h1);
gtk_window_present (GTK_WINDOW (window));
done = FALSE;
if (!interactive)
g_timeout_add (200, stop_main, &done);
while (!done)
g_main_context_iteration (NULL, TRUE);
gtk_window_get_size (GTK_WINDOW (window), &w1, &h1);
g_assert_cmpint (w, ==, w1);
g_assert_cmpint (h, ==, h1);
gtk_window_destroy (GTK_WINDOW (window));
}
int
main (int argc, char *argv[])
{
int i;
gtk_test_init (&argc, &argv);
for (i = 0; i < argc; i++)
{
if (g_strcmp0 (argv[i], "--interactive") == 0)
interactive = TRUE;
}
g_test_add_func ("/window/default-size", test_default_size);
g_test_add_func ("/window/resize-popup", test_resize_popup);
g_test_add_func ("/window/show-hide", test_show_hide);
return g_test_run ();
}