downstream: ivi-shell: configure the ivi surface when created
[profile/ivi/weston-ivi-shell.git] / tests / surface-global-test.c
1 /*
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
23 #include "config.h"
24
25 #include <assert.h>
26
27 #include "../src/compositor.h"
28
29 static void
30 surface_to_from_global(void *data)
31 {
32         struct weston_compositor *compositor = data;
33         struct weston_surface *surface;
34         struct weston_view *view;
35         float x, y;
36         wl_fixed_t fx, fy;
37         int32_t ix, iy;
38
39         surface = weston_surface_create(compositor);
40         assert(surface);
41         view = weston_view_create(surface);
42         assert(view);
43         surface->width = 50;
44         surface->height = 50;
45         weston_view_set_position(view, 5, 10);
46         weston_view_update_transform(view);
47
48         weston_view_to_global_float(view, 33, 22, &x, &y);
49         assert(x == 38 && y == 32);
50
51         weston_view_to_global_float(view, -8, -2, &x, &y);
52         assert(x == -3 && y == 8);
53
54         weston_view_to_global_fixed(view, wl_fixed_from_int(12),
55                                        wl_fixed_from_int(5), &fx, &fy);
56         assert(fx == wl_fixed_from_int(17) && fy == wl_fixed_from_int(15));
57
58         weston_view_from_global_float(view, 38, 32, &x, &y);
59         assert(x == 33 && y == 22);
60
61         weston_view_from_global_float(view, 42, 5, &x, &y);
62         assert(x == 37 && y == -5);
63
64         weston_view_from_global_fixed(view, wl_fixed_from_int(21),
65                                          wl_fixed_from_int(100), &fx, &fy);
66         assert(fx == wl_fixed_from_int(16) && fy == wl_fixed_from_int(90));
67
68         weston_view_from_global(view, 0, 0, &ix, &iy);
69         assert(ix == -5 && iy == -10);
70
71         weston_view_from_global(view, 5, 10, &ix, &iy);
72         assert(ix == 0 && iy == 0);
73
74         wl_display_terminate(compositor->wl_display);
75 }
76
77 WL_EXPORT int
78 module_init(struct weston_compositor *compositor, int *argc, char *argv[])
79 {
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 }