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