1 /*
2 * Copyright © 2011 Kristian Høgsberg
3 * Copyright © 2011 Benjamin Franzke
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Kristian Høgsberg <krh@bitplanet.net>
27 * Benjamin Franzke <benjaminfranzke@googlemail.com>
28 */
29
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "wayland-egl.h"
34 #include "wayland-egl-backend.h"
35 #include "wayland-util.h"
36
37
38 WL_EXPORT void
wl_egl_window_resize(struct wl_egl_window * egl_window,int width,int height,int dx,int dy)39 wl_egl_window_resize(struct wl_egl_window *egl_window,
40 int width, int height,
41 int dx, int dy)
42 {
43 if (width <= 0 || height <= 0)
44 return;
45
46 egl_window->width = width;
47 egl_window->height = height;
48 egl_window->dx = dx;
49 egl_window->dy = dy;
50
51 if (egl_window->resize_callback)
52 egl_window->resize_callback(egl_window, egl_window->driver_private);
53 }
54
55 WL_EXPORT struct wl_egl_window *
wl_egl_window_create(struct wl_surface * surface,int width,int height)56 wl_egl_window_create(struct wl_surface *surface,
57 int width, int height)
58 {
59 struct wl_egl_window *egl_window;
60
61 if (width <= 0 || height <= 0)
62 return NULL;
63
64 egl_window = calloc(1, sizeof *egl_window);
65 if (!egl_window)
66 return NULL;
67
68 /* Cast away the constness to set the version number.
69 *
70 * We want the const notation since it gives an explicit
71 * feedback to the backend implementation, should it try to
72 * change it.
73 *
74 * The latter in itself is not too surprising as these days APIs
75 * tend to provide bidirectional version field.
76 */
77 intptr_t *version = (intptr_t *)&egl_window->version;
78 *version = WL_EGL_WINDOW_VERSION;
79
80 egl_window->surface = surface;
81
82 egl_window->width = width;
83 egl_window->height = height;
84
85 return egl_window;
86 }
87
88 WL_EXPORT void
wl_egl_window_destroy(struct wl_egl_window * egl_window)89 wl_egl_window_destroy(struct wl_egl_window *egl_window)
90 {
91 if (egl_window->destroy_window_callback)
92 egl_window->destroy_window_callback(egl_window->driver_private);
93 free(egl_window);
94 }
95
96 WL_EXPORT void
wl_egl_window_get_attached_size(struct wl_egl_window * egl_window,int * width,int * height)97 wl_egl_window_get_attached_size(struct wl_egl_window *egl_window,
98 int *width, int *height)
99 {
100 if (width)
101 *width = egl_window->attached_width;
102 if (height)
103 *height = egl_window->attached_height;
104 }
105