From 3d0c23597d1d8fdb22921e6c273e7ccd99cbd77f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 15 Jul 2021 16:40:13 -0400 Subject: [PATCH 1/2] ngl: Handle negative scales Scale factors can be negative, but we were not looking out for that, triggering an assertion when trying to create a render target with negative width of height. Avoid that. Fixes: #4096 --- gsk/ngl/gsknglrenderjob.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c index 3e823dedab..02f8bcc4b8 100644 --- a/gsk/ngl/gsknglrenderjob.c +++ b/gsk/ngl/gsknglrenderjob.c @@ -3573,19 +3573,23 @@ gsk_ngl_render_job_visit_node_with_offscreen (GskNglRenderJob *job, { int max_texture_size = job->command_queue->max_texture_size; - scaled_width = ceilf (offscreen->bounds->size.width * job->scale_x); + scaled_width = ceilf (offscreen->bounds->size.width * fabs (job->scale_x)); if (scaled_width > max_texture_size) { downscale_x = (float)max_texture_size / scaled_width; scaled_width = max_texture_size; } + if (job->scale_x < 0) + downscale_x = -downscale_x; - scaled_height = ceilf (offscreen->bounds->size.height * job->scale_y); + scaled_height = ceilf (offscreen->bounds->size.height * fabs (job->scale_y)); if (scaled_height > max_texture_size) { downscale_y = (float)max_texture_size / scaled_height; scaled_height = max_texture_size; } + if (job->scale_y < 0) + downscale_y = -downscale_y; } GskNglRenderTarget *render_target; From 14df31b5090372a612fac6996bfb864dfac7f507 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 15 Jul 2021 23:33:54 +0200 Subject: [PATCH 2/2] testsuite: Add test for crasher Test for the crasher in !4096 --- .../compare/scale-textures-negative-ngl.node | 48 ++++++++++++++++++ .../compare/scale-textures-negative-ngl.png | Bin 0 -> 265 bytes testsuite/gsk/meson.build | 1 + 3 files changed, 49 insertions(+) create mode 100644 testsuite/gsk/compare/scale-textures-negative-ngl.node create mode 100644 testsuite/gsk/compare/scale-textures-negative-ngl.png diff --git a/testsuite/gsk/compare/scale-textures-negative-ngl.node b/testsuite/gsk/compare/scale-textures-negative-ngl.node new file mode 100644 index 0000000000..fbf1d8205e --- /dev/null +++ b/testsuite/gsk/compare/scale-textures-negative-ngl.node @@ -0,0 +1,48 @@ +transform { + transform: scale(1, 1); + child: opacity { + opacity: 0.6; + child: container { + texture { + bounds: 0 0 50 50; + texture: url("data:,"); + } + } + } +} +transform { + transform: scale(1, -1); + child: opacity { + opacity: 0.6; + child: container { + texture { + bounds: 0 0 50 50; + texture: url("data:,"); + } + } + } +} +transform { + transform: scale(-1, -1); + child: opacity { + opacity: 0.6; + child: container { + texture { + bounds: 0 0 50 50; + texture: url("data:,"); + } + } + } +} +transform { + transform: scale(-1, 1); + child: opacity { + opacity: 0.6; + child: container { + texture { + bounds: 0 0 50 50; + texture: url("data:,"); + } + } + } +} diff --git a/testsuite/gsk/compare/scale-textures-negative-ngl.png b/testsuite/gsk/compare/scale-textures-negative-ngl.png new file mode 100644 index 0000000000000000000000000000000000000000..8624e6c403dc52515a4c822b6d18493131912346 GIT binary patch literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^DImdkk?lPI_5vEU&h$Dts&a@xAF0{-+xMr-zfeQzWy@%k6s1C zrXw6e${syLGnjxjp@aI3-&l(mWuMhu7XE!kT&;{_5=*C`irWMU;u+7lXZdqXmXc8g Pd6B`>)z4*}Q$iB}eY#M` literal 0 HcmV?d00001 diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build index edb06ad154..c3f674599e 100644 --- a/testsuite/gsk/meson.build +++ b/testsuite/gsk/meson.build @@ -56,6 +56,7 @@ compare_render_tests = [ 'outset_shadow_rounded_top', 'outset_shadow_simple', 'scaled-cairo', + 'scale-textures-negative-ngl', 'shadow-in-opacity', 'texture-url', 'color-matrix-identity',