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