1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/*
* Copyright (C) 2021 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Author: Guido Günther <agx@sigxcpu.org>
*/
#include "monitor/head-priv.h"
PhogHeadMode phone_mode = {
.width = 720,
.height = 1440,
};
PhogHeadMode small_mode = {
.width = 1024,
.height = 768,
};
PhogHeadMode fourk_mode = {
.width = 3840,
.height = 2160,
};
static PhogHead *
stub_head_new (PhogHeadMode *mode)
{
/* We don't use `phog_head_new()` so we don't have to bother about wayland protcols, etc */
PhogHead *head = g_new0 (PhogHead, 1);
head->pending.scale = 1.0;
head->pending.mode = mode;
return head;
}
static void
stub_head_destroy (PhogHead *head)
{
g_free (head);
}
static GPtrArray *
get_layout (float scale)
{
PhogHead *head;
PhogHead *other_head;
GPtrArray *heads;
head = stub_head_new (&small_mode);
head->pending.scale = scale;
other_head = stub_head_new (&fourk_mode);
heads = g_ptr_array_new_with_free_func ((GDestroyNotify) (stub_head_destroy));
g_assert_nonnull (head->pending.mode);
g_assert_nonnull (other_head->pending.mode);
g_ptr_array_add (heads, head);
g_ptr_array_add (heads, other_head);
return heads;
}
static void
test_phog_head_set_transform (void)
{
PhogHead *head;
PhogHead *other_head;
GPtrArray *heads;
/* other_head right of head */
for (float scale = 1.0; scale <= 2.0; scale += 0.5) {
heads = get_layout (scale);
head = g_ptr_array_index (heads, 0);
other_head = g_ptr_array_index (heads, 1);
other_head->pending.x = head->pending.mode->width / scale;
g_assert_cmpint (head->pending.x, ==, 0);
g_assert_cmpint (head->pending.y, ==, 0);
g_assert_cmpint (other_head->pending.x, ==, small_mode.width / scale);
g_assert_cmpint (other_head->pending.y, ==, 0);
phog_head_set_pending_transform (head, PHOG_MONITOR_TRANSFORM_90, heads);
g_assert_cmpint (head->pending.x, ==, 0);
g_assert_cmpint (head->pending.y, ==, 0);
g_assert_cmpint (head->pending.transform, ==, PHOG_MONITOR_TRANSFORM_90);
g_assert_cmpint (other_head->pending.x, ==, small_mode.height / scale);
g_assert_cmpint (other_head->pending.y, ==, 0);
g_ptr_array_free (heads, TRUE);
}
/* other_head below head */
heads = get_layout (1.0);
head = g_ptr_array_index (heads, 0);
other_head = g_ptr_array_index (heads, 1);
other_head->pending.y = head->pending.mode->height;
g_assert_cmpint (head->pending.x, ==, 0);
g_assert_cmpint (head->pending.y, ==, 0);
g_assert_cmpint (other_head->pending.x, ==, 0);
g_assert_cmpint (other_head->pending.y, ==, small_mode.height);
phog_head_set_pending_transform (head, PHOG_MONITOR_TRANSFORM_90, heads);
g_assert_cmpint (head->pending.x, ==, 0);
g_assert_cmpint (head->pending.y, ==, 0);
g_assert_cmpint (head->pending.transform, ==, PHOG_MONITOR_TRANSFORM_90);
g_assert_cmpint (other_head->pending.x, ==, 0);
g_assert_cmpint (other_head->pending.y, ==, small_mode.width);
g_ptr_array_free (heads, TRUE);
/* other_head left of head */
heads = get_layout (1.0);
head = g_ptr_array_index (heads, 0);
other_head = g_ptr_array_index (heads, 1);
head->pending.x = other_head->pending.mode->width;
g_assert_cmpint (head->pending.x, ==, fourk_mode.width);
g_assert_cmpint (head->pending.y, ==, 0);
g_assert_cmpint (other_head->pending.x, ==, 0);
g_assert_cmpint (other_head->pending.y, ==, 0);
phog_head_set_pending_transform (head, PHOG_MONITOR_TRANSFORM_90, heads);
/* Nothing should have changed */
g_assert_cmpint (head->pending.x, ==, fourk_mode.width);
g_assert_cmpint (head->pending.y, ==, 0);
g_assert_cmpint (head->pending.transform, ==, PHOG_MONITOR_TRANSFORM_90);
g_assert_cmpint (other_head->pending.x, ==, 0);
g_assert_cmpint (other_head->pending.y, ==, 0);
g_ptr_array_free (heads, TRUE);
}
static void
test_phog_head_scale_integer (void)
{
int num;
g_autofree float *scales;
scales = phog_head_calculate_supported_mode_scales (NULL, &phone_mode, &num, FALSE);
g_assert_cmpint (num, ==, 2);
g_assert_true (G_APPROX_VALUE (scales[0], 1.0, FLT_EPSILON));
g_assert_true (G_APPROX_VALUE (scales[1], 2.0, FLT_EPSILON));
g_clear_pointer (&scales, g_free);
scales = phog_head_calculate_supported_mode_scales (NULL, &fourk_mode, &num, FALSE);
g_assert_cmpint (num, ==, 4);
g_assert_true (G_APPROX_VALUE (scales[0], 1.0, FLT_EPSILON));
g_assert_true (G_APPROX_VALUE (scales[1], 2.0, FLT_EPSILON));
g_assert_true (G_APPROX_VALUE (scales[2], 3.0, FLT_EPSILON));
g_assert_true (G_APPROX_VALUE (scales[3], 4.0, FLT_EPSILON));
}
static void
test_phog_head_scale_fractional (void)
{
int num;
g_autofree float *scales;
scales = phog_head_calculate_supported_mode_scales (NULL, &phone_mode, &num, TRUE);
g_assert_cmpint (num, ==, 5);
g_assert_true (G_APPROX_VALUE (scales[0], 1.0, FLT_EPSILON));
g_assert_true (G_APPROX_VALUE (scales[1], 1.25, FLT_EPSILON));
g_assert_true (G_APPROX_VALUE (scales[2], 1.5, FLT_EPSILON));
g_assert_cmpfloat (scales[3], >=, 1.75);
g_assert_cmpfloat (scales[3], <=, 1.76);
g_assert_true (G_APPROX_VALUE (scales[4], 2.0, FLT_EPSILON));
g_clear_pointer (&scales, g_free);
scales = phog_head_calculate_supported_mode_scales (NULL, &fourk_mode, &num, TRUE);
g_assert_cmpint (num, ==, 13);
g_assert_true (G_APPROX_VALUE (scales[0], 1.0, FLT_EPSILON));
g_assert_true (G_APPROX_VALUE (scales[1], 1.25, FLT_EPSILON));
/* ... */
g_assert_true (G_APPROX_VALUE (scales[11], 3.75, FLT_EPSILON));
g_assert_true (G_APPROX_VALUE (scales[12], 4.0, FLT_EPSILON));
}
int
main (int argc,
char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func("/phog/head/layout/set_transform", test_phog_head_set_transform);
g_test_add_func("/phog/head/scale/integer", test_phog_head_scale_integer);
g_test_add_func("/phog/head/scale/fractional", test_phog_head_scale_fractional);
return g_test_run();
}
|