mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 03:22:04 +00:00
monitor-transform: Add meta_monitor_transform_transform() helper
Intended to replace various manual monitor transform enum math here and there. Tests added as well, to test some hand picked transforms. https://gitlab.gnome.org/GNOME/mutter/merge_requests/1064
This commit is contained in:
parent
d495dc6c63
commit
e6913d1471
@ -39,3 +39,17 @@ meta_monitor_transform_invert (MetaMonitorTransform transform)
|
||||
g_assert_not_reached ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
MetaMonitorTransform
|
||||
meta_monitor_transform_transform (MetaMonitorTransform transform,
|
||||
MetaMonitorTransform other)
|
||||
{
|
||||
MetaMonitorTransform new_transform;
|
||||
|
||||
new_transform = (transform + other) % META_MONITOR_TRANSFORM_FLIPPED;
|
||||
if (meta_monitor_transform_is_flipped (transform) !=
|
||||
meta_monitor_transform_is_flipped (other))
|
||||
new_transform += META_MONITOR_TRANSFORM_FLIPPED;
|
||||
|
||||
return new_transform;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "backends/meta-backend-types.h"
|
||||
#include "core/util-private.h"
|
||||
|
||||
enum _MetaMonitorTransform
|
||||
{
|
||||
@ -48,9 +49,13 @@ meta_monitor_transform_is_rotated (MetaMonitorTransform transform)
|
||||
static inline gboolean
|
||||
meta_monitor_transform_is_flipped (MetaMonitorTransform transform)
|
||||
{
|
||||
return (transform >= META_MONITOR_TRANSFORM_FLIPPED);
|
||||
return (abs(transform) >= META_MONITOR_TRANSFORM_FLIPPED);
|
||||
}
|
||||
|
||||
MetaMonitorTransform meta_monitor_transform_invert (MetaMonitorTransform transform);
|
||||
|
||||
META_EXPORT_TEST
|
||||
MetaMonitorTransform meta_monitor_transform_transform (MetaMonitorTransform transform,
|
||||
MetaMonitorTransform other);
|
||||
|
||||
#endif /* META_MONITOR_TRANSFORM_H */
|
||||
|
@ -88,6 +88,8 @@ unit_tests = executable('mutter-test-unit-tests',
|
||||
'monitor-store-unit-tests.h',
|
||||
'monitor-test-utils.c',
|
||||
'monitor-test-utils.h',
|
||||
'monitor-transform-tests.c',
|
||||
'monitor-transform-tests.h',
|
||||
'monitor-unit-tests.c',
|
||||
'monitor-unit-tests.h',
|
||||
'wayland-unit-tests.c',
|
||||
|
100
src/tests/monitor-transform-tests.c
Normal file
100
src/tests/monitor-transform-tests.c
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Red Hat Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "tests/monitor-transform-tests.h"
|
||||
|
||||
#include "backends/meta-monitor-transform.h"
|
||||
|
||||
static void
|
||||
test_transform (void)
|
||||
{
|
||||
const struct
|
||||
{
|
||||
MetaMonitorTransform transform;
|
||||
MetaMonitorTransform other;
|
||||
MetaMonitorTransform expect;
|
||||
} tests[] = {
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_NORMAL,
|
||||
.other = META_MONITOR_TRANSFORM_90,
|
||||
.expect = META_MONITOR_TRANSFORM_90,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_NORMAL,
|
||||
.other = META_MONITOR_TRANSFORM_FLIPPED_90,
|
||||
.expect = META_MONITOR_TRANSFORM_FLIPPED_90,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_90,
|
||||
.other = META_MONITOR_TRANSFORM_90,
|
||||
.expect = META_MONITOR_TRANSFORM_180,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_FLIPPED_90,
|
||||
.other = META_MONITOR_TRANSFORM_90,
|
||||
.expect = META_MONITOR_TRANSFORM_FLIPPED_180,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_FLIPPED_90,
|
||||
.other = META_MONITOR_TRANSFORM_180,
|
||||
.expect = META_MONITOR_TRANSFORM_FLIPPED_270,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_FLIPPED_180,
|
||||
.other = META_MONITOR_TRANSFORM_FLIPPED_180,
|
||||
.expect = META_MONITOR_TRANSFORM_NORMAL,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_NORMAL,
|
||||
.other = -META_MONITOR_TRANSFORM_90,
|
||||
.expect = META_MONITOR_TRANSFORM_270,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_FLIPPED,
|
||||
.other = -META_MONITOR_TRANSFORM_90,
|
||||
.expect = META_MONITOR_TRANSFORM_FLIPPED_270,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_FLIPPED_180,
|
||||
.other = -META_MONITOR_TRANSFORM_270,
|
||||
.expect = META_MONITOR_TRANSFORM_FLIPPED_270,
|
||||
},
|
||||
{
|
||||
.transform = META_MONITOR_TRANSFORM_FLIPPED_180,
|
||||
.other = -META_MONITOR_TRANSFORM_FLIPPED_180,
|
||||
.expect = META_MONITOR_TRANSFORM_NORMAL,
|
||||
},
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
||||
{
|
||||
MetaMonitorTransform result;
|
||||
|
||||
result = meta_monitor_transform_transform (tests[i].transform,
|
||||
tests[i].other);
|
||||
g_assert_cmpint (result, ==, tests[i].expect);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_monitor_transform_tests (void)
|
||||
{
|
||||
g_test_add_func ("/util/monitor-transform/transform", test_transform);
|
||||
}
|
23
src/tests/monitor-transform-tests.h
Normal file
23
src/tests/monitor-transform-tests.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MONITOR_TRANSFORM_UNIT_TESTS_H
|
||||
#define MONITOR_TRANSFORM_UNIT_TESTS_H
|
||||
|
||||
void init_monitor_transform_tests (void);
|
||||
|
||||
#endif /* MONITOR_TRANSFORM_TESTS_H */
|
@ -33,6 +33,7 @@
|
||||
#include "tests/monitor-config-migration-unit-tests.h"
|
||||
#include "tests/monitor-unit-tests.h"
|
||||
#include "tests/monitor-store-unit-tests.h"
|
||||
#include "tests/monitor-transform-tests.h"
|
||||
#include "tests/test-utils.h"
|
||||
#include "tests/wayland-unit-tests.h"
|
||||
#include "wayland/meta-wayland.h"
|
||||
@ -254,6 +255,7 @@ init_tests (int argc, char **argv)
|
||||
init_monitor_tests ();
|
||||
init_boxes_tests ();
|
||||
init_wayland_tests ();
|
||||
init_monitor_transform_tests ();
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user