e7cea895ece160b29a4e513e3b10c9d5a03f34ce
[mesa.git] / src / egl / wayland / wayland-egl / wayland-egl.c
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
36 /* GCC visibility */
37 #if defined(__GNUC__)
38 #define WL_EGL_EXPORT __attribute__ ((visibility("default")))
39 #else
40 #define WL_EGL_EXPORT
41 #endif
42
43 WL_EGL_EXPORT void
44 wl_egl_window_resize(struct wl_egl_window *egl_window,
45 int width, int height,
46 int dx, int dy)
47 {
48 if (width <= 0 || height <= 0)
49 return;
50
51 egl_window->width = width;
52 egl_window->height = height;
53 egl_window->dx = dx;
54 egl_window->dy = dy;
55
56 if (egl_window->resize_callback)
57 egl_window->resize_callback(egl_window, egl_window->private);
58 }
59
60 WL_EGL_EXPORT struct wl_egl_window *
61 wl_egl_window_create(struct wl_surface *surface,
62 int width, int height)
63 {
64 struct wl_egl_window *egl_window;
65
66 if (width <= 0 || height <= 0)
67 return NULL;
68
69 egl_window = calloc(1, sizeof *egl_window);
70 if (!egl_window)
71 return NULL;
72
73 /* Cast away the constness to set the version number.
74 *
75 * We want the const notation since it gives an explicit
76 * feedback to the backend implementation, should it try to
77 * change it.
78 *
79 * The latter in itself is not too surprising as these days APIs
80 * tend to provide bidirectional version field.
81 */
82 intptr_t *version = (intptr_t *)&egl_window->version;
83 *version = WL_EGL_WINDOW_VERSION;
84
85 egl_window->surface = surface;
86
87 egl_window->width = width;
88 egl_window->height = height;
89
90 return egl_window;
91 }
92
93 WL_EGL_EXPORT void
94 wl_egl_window_destroy(struct wl_egl_window *egl_window)
95 {
96 if (egl_window->destroy_window_callback)
97 egl_window->destroy_window_callback(egl_window->private);
98 free(egl_window);
99 }
100
101 WL_EGL_EXPORT void
102 wl_egl_window_get_attached_size(struct wl_egl_window *egl_window,
103 int *width, int *height)
104 {
105 if (width)
106 *width = egl_window->attached_width;
107 if (height)
108 *height = egl_window->attached_height;
109 }