blob: edc5d9f68499e78a729aca7332d8f81c357ed82c [file] [log] [blame]
U. Artie Eoffd6901752012-09-28 06:39:31 -07001/*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010023#include "config.h"
24
U. Artie Eoffd6901752012-09-28 06:39:31 -070025#include <assert.h>
26
Kristian Høgsberg15be01e2012-12-11 23:22:16 -050027#include "../src/compositor.h"
U. Artie Eoffd6901752012-09-28 06:39:31 -070028
Kristian Høgsberg15be01e2012-12-11 23:22:16 -050029static void
30surface_to_from_global(void *data)
U. Artie Eoffd6901752012-09-28 06:39:31 -070031{
Kristian Høgsberg15be01e2012-12-11 23:22:16 -050032 struct weston_compositor *compositor = data;
U. Artie Eoffd6901752012-09-28 06:39:31 -070033 struct weston_surface *surface;
Jason Ekstranda7af7042013-10-12 22:38:11 -050034 struct weston_view *view;
Kristian Høgsbergf3dfe712012-11-14 14:42:51 -050035 float x, y;
U. Artie Eoffd6901752012-09-28 06:39:31 -070036 wl_fixed_t fx, fy;
37 int32_t ix, iy;
38
39 surface = weston_surface_create(compositor);
Kristian Høgsberg3b7d8412013-10-09 13:37:43 -070040 assert(surface);
Jason Ekstranda7af7042013-10-12 22:38:11 -050041 view = weston_view_create(surface);
42 assert(view);
Jason Ekstrand918f2dd2013-12-02 21:01:53 -060043 surface->width = 50;
44 surface->height = 50;
45 weston_view_set_position(view, 5, 10);
Jason Ekstranda7af7042013-10-12 22:38:11 -050046 weston_view_update_transform(view);
U. Artie Eoffd6901752012-09-28 06:39:31 -070047
Jason Ekstranda7af7042013-10-12 22:38:11 -050048 weston_view_to_global_float(view, 33, 22, &x, &y);
U. Artie Eoffd6901752012-09-28 06:39:31 -070049 assert(x == 38 && y == 32);
50
Jason Ekstranda7af7042013-10-12 22:38:11 -050051 weston_view_to_global_float(view, -8, -2, &x, &y);
U. Artie Eoffd6901752012-09-28 06:39:31 -070052 assert(x == -3 && y == 8);
53
Jason Ekstranda7af7042013-10-12 22:38:11 -050054 weston_view_to_global_fixed(view, wl_fixed_from_int(12),
U. Artie Eoffd6901752012-09-28 06:39:31 -070055 wl_fixed_from_int(5), &fx, &fy);
56 assert(fx == wl_fixed_from_int(17) && fy == wl_fixed_from_int(15));
57
Jason Ekstranda7af7042013-10-12 22:38:11 -050058 weston_view_from_global_float(view, 38, 32, &x, &y);
U. Artie Eoffd6901752012-09-28 06:39:31 -070059 assert(x == 33 && y == 22);
60
Jason Ekstranda7af7042013-10-12 22:38:11 -050061 weston_view_from_global_float(view, 42, 5, &x, &y);
U. Artie Eoffd6901752012-09-28 06:39:31 -070062 assert(x == 37 && y == -5);
63
Jason Ekstranda7af7042013-10-12 22:38:11 -050064 weston_view_from_global_fixed(view, wl_fixed_from_int(21),
U. Artie Eoffd6901752012-09-28 06:39:31 -070065 wl_fixed_from_int(100), &fx, &fy);
U. Artie Eoff209e8f12013-01-29 15:30:09 -080066 assert(fx == wl_fixed_from_int(16) && fy == wl_fixed_from_int(90));
U. Artie Eoffd6901752012-09-28 06:39:31 -070067
Jason Ekstranda7af7042013-10-12 22:38:11 -050068 weston_view_from_global(view, 0, 0, &ix, &iy);
U. Artie Eoffd6901752012-09-28 06:39:31 -070069 assert(ix == -5 && iy == -10);
70
Jason Ekstranda7af7042013-10-12 22:38:11 -050071 weston_view_from_global(view, 5, 10, &ix, &iy);
U. Artie Eoffd6901752012-09-28 06:39:31 -070072 assert(ix == 0 && iy == 0);
73
74 wl_display_terminate(compositor->wl_display);
75}
Kristian Høgsberg15be01e2012-12-11 23:22:16 -050076
77WL_EXPORT int
U. Artie Eoff173ff532013-05-17 06:12:50 -070078module_init(struct weston_compositor *compositor, int *argc, char *argv[])
Kristian Høgsberg15be01e2012-12-11 23:22:16 -050079{
80 struct wl_event_loop *loop;
81
82 loop = wl_display_get_event_loop(compositor->wl_display);
83
84 wl_event_loop_add_idle(loop, surface_to_from_global, compositor);
85
86 return 0;
87}