U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 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 <assert.h> |
| 24 | |
Kristian Høgsberg | 15be01e | 2012-12-11 23:22:16 -0500 | [diff] [blame] | 25 | #include "../src/compositor.h" |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 26 | |
Kristian Høgsberg | 15be01e | 2012-12-11 23:22:16 -0500 | [diff] [blame] | 27 | static void |
| 28 | surface_to_from_global(void *data) |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 29 | { |
Kristian Høgsberg | 15be01e | 2012-12-11 23:22:16 -0500 | [diff] [blame] | 30 | struct weston_compositor *compositor = data; |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 31 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 32 | struct weston_view *view; |
Kristian Høgsberg | f3dfe71 | 2012-11-14 14:42:51 -0500 | [diff] [blame] | 33 | float x, y; |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 34 | wl_fixed_t fx, fy; |
| 35 | int32_t ix, iy; |
| 36 | |
| 37 | surface = weston_surface_create(compositor); |
Kristian Høgsberg | 3b7d841 | 2013-10-09 13:37:43 -0700 | [diff] [blame] | 38 | assert(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 39 | view = weston_view_create(surface); |
| 40 | assert(view); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 41 | surface->width = 50; |
| 42 | surface->height = 50; |
| 43 | weston_view_set_position(view, 5, 10); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 44 | weston_view_update_transform(view); |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 45 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 46 | weston_view_to_global_float(view, 33, 22, &x, &y); |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 47 | assert(x == 38 && y == 32); |
| 48 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 49 | weston_view_to_global_float(view, -8, -2, &x, &y); |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 50 | assert(x == -3 && y == 8); |
| 51 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 52 | weston_view_to_global_fixed(view, wl_fixed_from_int(12), |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 53 | wl_fixed_from_int(5), &fx, &fy); |
| 54 | assert(fx == wl_fixed_from_int(17) && fy == wl_fixed_from_int(15)); |
| 55 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 56 | weston_view_from_global_float(view, 38, 32, &x, &y); |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 57 | assert(x == 33 && y == 22); |
| 58 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 59 | weston_view_from_global_float(view, 42, 5, &x, &y); |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 60 | assert(x == 37 && y == -5); |
| 61 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 62 | weston_view_from_global_fixed(view, wl_fixed_from_int(21), |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 63 | wl_fixed_from_int(100), &fx, &fy); |
U. Artie Eoff | 209e8f1 | 2013-01-29 15:30:09 -0800 | [diff] [blame] | 64 | assert(fx == wl_fixed_from_int(16) && fy == wl_fixed_from_int(90)); |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 65 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 66 | weston_view_from_global(view, 0, 0, &ix, &iy); |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 67 | assert(ix == -5 && iy == -10); |
| 68 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 69 | weston_view_from_global(view, 5, 10, &ix, &iy); |
U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame] | 70 | assert(ix == 0 && iy == 0); |
| 71 | |
| 72 | wl_display_terminate(compositor->wl_display); |
| 73 | } |
Kristian Høgsberg | 15be01e | 2012-12-11 23:22:16 -0500 | [diff] [blame] | 74 | |
| 75 | WL_EXPORT int |
U. Artie Eoff | 173ff53 | 2013-05-17 06:12:50 -0700 | [diff] [blame] | 76 | module_init(struct weston_compositor *compositor, int *argc, char *argv[]) |
Kristian Høgsberg | 15be01e | 2012-12-11 23:22:16 -0500 | [diff] [blame] | 77 | { |
| 78 | struct wl_event_loop *loop; |
| 79 | |
| 80 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 81 | |
| 82 | wl_event_loop_add_idle(loop, surface_to_from_global, compositor); |
| 83 | |
| 84 | return 0; |
| 85 | } |