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

gsk: Add a test for transform_bounds

See merge request GNOME/gtk!3966
This commit is contained in:
Matthias Clasen 2021-09-17 16:22:04 +00:00
commit 37a54eb9fc
6 changed files with 76 additions and 21 deletions

View File

@ -198,6 +198,7 @@
<child>
<object class="GtkPicture" id="picture">
<property name="can-shrink">0</property>
<property name="keep-aspect-ratio">1</property>
<property name="halign">center</property>
<property name="valign">center</property>
<child>

View File

@ -1530,6 +1530,13 @@ gsk_transform_to_2d (GskTransform *self,
*
* Converts a `GskTransform` to 2D affine transformation factors.
*
* To recreate an equivalent transform from the factors returned
* by this function, use
*
* gsk_transform_scale (gsk_transform_translate (NULL,
* &GRAPHENE_POINT_T (dx, dy)),
* sx, sy)
*
* @self must be a 2D transformation. If you are not
* sure, use
*

View File

@ -453,10 +453,21 @@ extract_matrix_metadata (GskNglRenderModelview *modelview)
&modelview->dx, &modelview->dy);
break;
case GSK_TRANSFORM_CATEGORY_2D:
{
float xx, xy, yx, yy, dx, dy;
gsk_transform_to_2d (modelview->transform,
&xx, &xy, &yx, &yy, &dx, &dy);
modelview->scale_x = sqrtf (xx * xx + xy * xy);
modelview->scale_y = sqrtf (yx * yx + yy * yy);
}
break;
case GSK_TRANSFORM_CATEGORY_UNKNOWN:
case GSK_TRANSFORM_CATEGORY_ANY:
case GSK_TRANSFORM_CATEGORY_3D:
case GSK_TRANSFORM_CATEGORY_2D:
{
graphene_vec3_t col1;
graphene_vec3_t col2;

View File

@ -87,6 +87,17 @@ gtk_render_node_paintable_paintable_get_intrinsic_height (GdkPaintable *paintabl
return ceilf (self->bounds.size.height);
}
static double
gtk_render_node_paintable_paintable_get_intrinsic_aspect_ratio (GdkPaintable *paintable)
{
GtkRenderNodePaintable *self = GTK_RENDER_NODE_PAINTABLE (paintable);
if (self->bounds.size.height != 0)
return self->bounds.size.width / self->bounds.size.height;
return 0;
}
static void
gtk_render_node_paintable_paintable_init (GdkPaintableInterface *iface)
{
@ -94,6 +105,7 @@ gtk_render_node_paintable_paintable_init (GdkPaintableInterface *iface)
iface->get_flags = gtk_render_node_paintable_paintable_get_flags;
iface->get_intrinsic_width = gtk_render_node_paintable_paintable_get_intrinsic_width;
iface->get_intrinsic_height = gtk_render_node_paintable_paintable_get_intrinsic_height;
iface->get_intrinsic_aspect_ratio = gtk_render_node_paintable_paintable_get_intrinsic_aspect_ratio;
}
G_DEFINE_TYPE_EXTENDED (GtkRenderNodePaintable, gtk_render_node_paintable, G_TYPE_OBJECT, 0,

View File

@ -10,36 +10,39 @@ clipboard_client = executable('clipboard-client',
install_dir: testexecdir)
tests = [
'array',
'cairo',
'clipboard',
'contentformats',
'contentserializer',
'cursor',
'display',
'displaymanager',
'encoding',
'keysyms',
'memorytexture',
'pixbuf',
'rectangle',
'rgba',
'seat',
'texture',
'texture-threads',
{ 'name': 'array' },
{ 'name': 'cairo' },
{ 'name': 'clipboard', 'parallel': false, },
{ 'name': 'contentformats' },
{ 'name': 'contentserializer' },
{ 'name': 'cursor' },
{ 'name': 'display' },
{ 'name': 'displaymanager' },
{ 'name': 'encoding' },
{ 'name': 'keysyms' },
{ 'name': 'memorytexture' },
{ 'name': 'pixbuf' },
{ 'name': 'rectangle' },
{ 'name': 'rgba' },
{ 'name': 'seat' },
{ 'name': 'texture' },
{ 'name': 'texture-threads' },
]
foreach t : tests
test_exe = executable(t, '@0@.c'.format(t),
test_name = t.get('name')
test_exe = executable(test_name,
sources: '@0@.c'.format(test_name),
c_args: common_cflags,
dependencies: libgtk_dep,
install: get_option('install-tests'),
install_dir: testexecdir,
)
test(t, test_exe,
test(test_name, test_exe,
args: [ '--tap', '-k' ],
protocol: 'tap',
is_parallel: t.get('parallel', false),
env: [
'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
@ -76,9 +79,10 @@ endforeach
if get_option('install-tests')
foreach t : tests
test_name = t.get('name')
test_cdata = configuration_data()
test_cdata.set('testexecdir', testexecdir)
test_cdata.set('test', t)
test_cdata.set('test', test_name)
configure_file(input: 'gdk.test.in',
output: '@0@.test'.format(t),
configuration: test_cdata,

View File

@ -565,6 +565,25 @@ test_to_affine (void)
g_assert_cmpfloat (dy, ==, 5.0);
}
static void
test_transform_bounds (void)
{
GskTransform *t = gsk_transform_translate (NULL, &GRAPHENE_POINT_INIT (50, 50));
graphene_rect_t bounds = GRAPHENE_RECT_INIT (0, 0, 100, 100);
graphene_rect_t out;
gsk_transform_transform_bounds (t, &bounds, &out);
g_assert_true (graphene_rect_equal (&out, &GRAPHENE_RECT_INIT(50, 50, 100, 100)));
t = gsk_transform_rotate (t, 180);
gsk_transform_transform_bounds (t, &bounds, &out);
g_assert_true (graphene_rect_equal (&out, &GRAPHENE_RECT_INIT(-50, -50, 100, 100)));
t = gsk_transform_translate (t, &GRAPHENE_POINT_INIT (-50, -50));
gsk_transform_transform_bounds (t, &bounds, &out);
g_assert_true (graphene_rect_equal (&out, &GRAPHENE_RECT_INIT(0, 0, 100, 100)));
}
int
main (int argc,
char *argv[])
@ -579,6 +598,7 @@ main (int argc,
g_test_add_func ("/transform/print-parse", test_print_parse);
g_test_add_func ("/transform/check-axis-aligneness", test_axis_aligned);
g_test_add_func ("/transform/to-affine", test_to_affine);
g_test_add_func ("/transform/bounds", test_transform_bounds);
return g_test_run ();
}