1*84e872a0SLloyd Pique /*
2*84e872a0SLloyd Pique * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3*84e872a0SLloyd Pique *
4*84e872a0SLloyd Pique * Permission is hereby granted, free of charge, to any person obtaining a
5*84e872a0SLloyd Pique * copy of this software and associated documentation files (the "Software"),
6*84e872a0SLloyd Pique * to deal in the Software without restriction, including without limitation
7*84e872a0SLloyd Pique * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*84e872a0SLloyd Pique * and/or sell copies of the Software, and to permit persons to whom the
9*84e872a0SLloyd Pique * Software is furnished to do so, subject to the following conditions:
10*84e872a0SLloyd Pique *
11*84e872a0SLloyd Pique * The above copyright notice and this permission notice shall be included in
12*84e872a0SLloyd Pique * all copies or substantial portions of the Software.
13*84e872a0SLloyd Pique *
14*84e872a0SLloyd Pique * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*84e872a0SLloyd Pique * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*84e872a0SLloyd Pique * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*84e872a0SLloyd Pique * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18*84e872a0SLloyd Pique * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19*84e872a0SLloyd Pique * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20*84e872a0SLloyd Pique * DEALINGS IN THE SOFTWARE.
21*84e872a0SLloyd Pique */
22*84e872a0SLloyd Pique
23*84e872a0SLloyd Pique #include <stddef.h> /* offsetof */
24*84e872a0SLloyd Pique #include <stdio.h> /* printf */
25*84e872a0SLloyd Pique
26*84e872a0SLloyd Pique #include "wayland-egl-backend.h" /* Current struct wl_egl_window implementation */
27*84e872a0SLloyd Pique
28*84e872a0SLloyd Pique /*
29*84e872a0SLloyd Pique * Following are previous implementations of wl_egl_window.
30*84e872a0SLloyd Pique *
31*84e872a0SLloyd Pique * DO NOT EVER CHANGE!
32*84e872a0SLloyd Pique */
33*84e872a0SLloyd Pique
34*84e872a0SLloyd Pique /* From: 214fc6e850 - Benjamin Franzke : egl: Implement libwayland-egl */
35*84e872a0SLloyd Pique struct wl_egl_window_v0 {
36*84e872a0SLloyd Pique struct wl_surface *surface;
37*84e872a0SLloyd Pique
38*84e872a0SLloyd Pique int width;
39*84e872a0SLloyd Pique int height;
40*84e872a0SLloyd Pique int dx;
41*84e872a0SLloyd Pique int dy;
42*84e872a0SLloyd Pique
43*84e872a0SLloyd Pique int attached_width;
44*84e872a0SLloyd Pique int attached_height;
45*84e872a0SLloyd Pique };
46*84e872a0SLloyd Pique
47*84e872a0SLloyd Pique /* From: ca3ed3e024 - Ander Conselvan de Oliveira : egl/wayland: Don't invalidate drawable on swap buffers */
48*84e872a0SLloyd Pique struct wl_egl_window_v1 {
49*84e872a0SLloyd Pique struct wl_surface *surface;
50*84e872a0SLloyd Pique
51*84e872a0SLloyd Pique int width;
52*84e872a0SLloyd Pique int height;
53*84e872a0SLloyd Pique int dx;
54*84e872a0SLloyd Pique int dy;
55*84e872a0SLloyd Pique
56*84e872a0SLloyd Pique int attached_width;
57*84e872a0SLloyd Pique int attached_height;
58*84e872a0SLloyd Pique
59*84e872a0SLloyd Pique void *private;
60*84e872a0SLloyd Pique void (*resize_callback)(struct wl_egl_window *, void *);
61*84e872a0SLloyd Pique };
62*84e872a0SLloyd Pique
63*84e872a0SLloyd Pique /* From: 690ead4a13 - Stencel, Joanna : egl/wayland-egl: Fix for segfault in dri2_wl_destroy_surface. */
64*84e872a0SLloyd Pique #define WL_EGL_WINDOW_VERSION_v2 2
65*84e872a0SLloyd Pique struct wl_egl_window_v2 {
66*84e872a0SLloyd Pique struct wl_surface *surface;
67*84e872a0SLloyd Pique
68*84e872a0SLloyd Pique int width;
69*84e872a0SLloyd Pique int height;
70*84e872a0SLloyd Pique int dx;
71*84e872a0SLloyd Pique int dy;
72*84e872a0SLloyd Pique
73*84e872a0SLloyd Pique int attached_width;
74*84e872a0SLloyd Pique int attached_height;
75*84e872a0SLloyd Pique
76*84e872a0SLloyd Pique void *private;
77*84e872a0SLloyd Pique void (*resize_callback)(struct wl_egl_window *, void *);
78*84e872a0SLloyd Pique void (*destroy_window_callback)(void *);
79*84e872a0SLloyd Pique };
80*84e872a0SLloyd Pique
81*84e872a0SLloyd Pique /* From: 2d5d61bc49 - Miguel A. Vico : wayland-egl: Make wl_egl_window a versioned struct */
82*84e872a0SLloyd Pique #define WL_EGL_WINDOW_VERSION_v3 3
83*84e872a0SLloyd Pique struct wl_egl_window_v3 {
84*84e872a0SLloyd Pique const intptr_t version;
85*84e872a0SLloyd Pique
86*84e872a0SLloyd Pique int width;
87*84e872a0SLloyd Pique int height;
88*84e872a0SLloyd Pique int dx;
89*84e872a0SLloyd Pique int dy;
90*84e872a0SLloyd Pique
91*84e872a0SLloyd Pique int attached_width;
92*84e872a0SLloyd Pique int attached_height;
93*84e872a0SLloyd Pique
94*84e872a0SLloyd Pique void *driver_private;
95*84e872a0SLloyd Pique void (*resize_callback)(struct wl_egl_window *, void *);
96*84e872a0SLloyd Pique void (*destroy_window_callback)(void *);
97*84e872a0SLloyd Pique
98*84e872a0SLloyd Pique struct wl_surface *surface;
99*84e872a0SLloyd Pique };
100*84e872a0SLloyd Pique
101*84e872a0SLloyd Pique
102*84e872a0SLloyd Pique /* This program checks we keep a backwards-compatible struct wl_egl_window
103*84e872a0SLloyd Pique * definition whenever it is modified in wayland-egl-backend.h.
104*84e872a0SLloyd Pique *
105*84e872a0SLloyd Pique * The previous definition should be added above as a new struct
106*84e872a0SLloyd Pique * wl_egl_window_vN, and the appropriate checks should be added below
107*84e872a0SLloyd Pique */
108*84e872a0SLloyd Pique
109*84e872a0SLloyd Pique #define MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
110*84e872a0SLloyd Pique
111*84e872a0SLloyd Pique #define CHECK_RENAMED_MEMBER(a_ver, b_ver, a_member, b_member) \
112*84e872a0SLloyd Pique do { \
113*84e872a0SLloyd Pique if (offsetof(struct wl_egl_window ## a_ver, a_member) != \
114*84e872a0SLloyd Pique offsetof(struct wl_egl_window ## b_ver, b_member)) { \
115*84e872a0SLloyd Pique printf("Backwards incompatible change detected!\n " \
116*84e872a0SLloyd Pique "offsetof(struct wl_egl_window" #a_ver "::" #a_member ") != " \
117*84e872a0SLloyd Pique "offsetof(struct wl_egl_window" #b_ver "::" #b_member ")\n"); \
118*84e872a0SLloyd Pique return 1; \
119*84e872a0SLloyd Pique } \
120*84e872a0SLloyd Pique \
121*84e872a0SLloyd Pique if (MEMBER_SIZE(struct wl_egl_window ## a_ver, a_member) != \
122*84e872a0SLloyd Pique MEMBER_SIZE(struct wl_egl_window ## b_ver, b_member)) { \
123*84e872a0SLloyd Pique printf("Backwards incompatible change detected!\n " \
124*84e872a0SLloyd Pique "MEMBER_SIZE(struct wl_egl_window" #a_ver "::" #a_member ") != " \
125*84e872a0SLloyd Pique "MEMBER_SIZE(struct wl_egl_window" #b_ver "::" #b_member ")\n"); \
126*84e872a0SLloyd Pique return 1; \
127*84e872a0SLloyd Pique } \
128*84e872a0SLloyd Pique } while (0)
129*84e872a0SLloyd Pique
130*84e872a0SLloyd Pique #define CHECK_MEMBER(a_ver, b_ver, member) CHECK_RENAMED_MEMBER(a_ver, b_ver, member, member)
131*84e872a0SLloyd Pique #define CHECK_MEMBER_CURRENT(a_ver, member) CHECK_MEMBER(a_ver,, member)
132*84e872a0SLloyd Pique
133*84e872a0SLloyd Pique #define CHECK_SIZE(a_ver, b_ver) \
134*84e872a0SLloyd Pique do { \
135*84e872a0SLloyd Pique if (sizeof(struct wl_egl_window ## a_ver) > \
136*84e872a0SLloyd Pique sizeof(struct wl_egl_window ## b_ver)) { \
137*84e872a0SLloyd Pique printf("Backwards incompatible change detected!\n " \
138*84e872a0SLloyd Pique "sizeof(struct wl_egl_window" #a_ver ") > " \
139*84e872a0SLloyd Pique "sizeof(struct wl_egl_window" #b_ver ")\n"); \
140*84e872a0SLloyd Pique return 1; \
141*84e872a0SLloyd Pique } \
142*84e872a0SLloyd Pique } while (0)
143*84e872a0SLloyd Pique
144*84e872a0SLloyd Pique #define CHECK_SIZE_CURRENT(a_ver) \
145*84e872a0SLloyd Pique do { \
146*84e872a0SLloyd Pique if (sizeof(struct wl_egl_window ## a_ver) != \
147*84e872a0SLloyd Pique sizeof(struct wl_egl_window)) { \
148*84e872a0SLloyd Pique printf("Backwards incompatible change detected!\n " \
149*84e872a0SLloyd Pique "sizeof(struct wl_egl_window" #a_ver ") != " \
150*84e872a0SLloyd Pique "sizeof(struct wl_egl_window)\n"); \
151*84e872a0SLloyd Pique return 1; \
152*84e872a0SLloyd Pique } \
153*84e872a0SLloyd Pique } while (0)
154*84e872a0SLloyd Pique
155*84e872a0SLloyd Pique #define CHECK_VERSION(a_ver, b_ver) \
156*84e872a0SLloyd Pique do { \
157*84e872a0SLloyd Pique if ((WL_EGL_WINDOW_VERSION ## a_ver) >= \
158*84e872a0SLloyd Pique (WL_EGL_WINDOW_VERSION ## b_ver)) { \
159*84e872a0SLloyd Pique printf("Backwards incompatible change detected!\n " \
160*84e872a0SLloyd Pique "WL_EGL_WINDOW_VERSION" #a_ver " >= " \
161*84e872a0SLloyd Pique "WL_EGL_WINDOW_VERSION" #b_ver "\n"); \
162*84e872a0SLloyd Pique return 1; \
163*84e872a0SLloyd Pique } \
164*84e872a0SLloyd Pique } while (0)
165*84e872a0SLloyd Pique
166*84e872a0SLloyd Pique #define CHECK_VERSION_CURRENT(a_ver) \
167*84e872a0SLloyd Pique do { \
168*84e872a0SLloyd Pique if ((WL_EGL_WINDOW_VERSION ## a_ver) != \
169*84e872a0SLloyd Pique (WL_EGL_WINDOW_VERSION)) { \
170*84e872a0SLloyd Pique printf("Backwards incompatible change detected!\n " \
171*84e872a0SLloyd Pique "WL_EGL_WINDOW_VERSION" #a_ver " != " \
172*84e872a0SLloyd Pique "WL_EGL_WINDOW_VERSION\n"); \
173*84e872a0SLloyd Pique return 1; \
174*84e872a0SLloyd Pique } \
175*84e872a0SLloyd Pique } while (0)
176*84e872a0SLloyd Pique
main(int argc,char ** argv)177*84e872a0SLloyd Pique int main(int argc, char **argv)
178*84e872a0SLloyd Pique {
179*84e872a0SLloyd Pique /* Check wl_egl_window_v1 ABI against wl_egl_window_v0 */
180*84e872a0SLloyd Pique CHECK_MEMBER(_v0, _v1, surface);
181*84e872a0SLloyd Pique CHECK_MEMBER(_v0, _v1, width);
182*84e872a0SLloyd Pique CHECK_MEMBER(_v0, _v1, height);
183*84e872a0SLloyd Pique CHECK_MEMBER(_v0, _v1, dx);
184*84e872a0SLloyd Pique CHECK_MEMBER(_v0, _v1, dy);
185*84e872a0SLloyd Pique CHECK_MEMBER(_v0, _v1, attached_width);
186*84e872a0SLloyd Pique CHECK_MEMBER(_v0, _v1, attached_height);
187*84e872a0SLloyd Pique
188*84e872a0SLloyd Pique CHECK_SIZE(_v0, _v1);
189*84e872a0SLloyd Pique
190*84e872a0SLloyd Pique /* Check wl_egl_window_v2 ABI against wl_egl_window_v1 */
191*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, surface);
192*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, width);
193*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, height);
194*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, dx);
195*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, dy);
196*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, attached_width);
197*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, attached_height);
198*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, private);
199*84e872a0SLloyd Pique CHECK_MEMBER(_v1, _v2, resize_callback);
200*84e872a0SLloyd Pique
201*84e872a0SLloyd Pique CHECK_SIZE(_v1, _v2);
202*84e872a0SLloyd Pique
203*84e872a0SLloyd Pique /* Check wl_egl_window_v3 ABI against wl_egl_window_v2 */
204*84e872a0SLloyd Pique CHECK_RENAMED_MEMBER(_v2, _v3, surface, version);
205*84e872a0SLloyd Pique CHECK_MEMBER (_v2, _v3, width);
206*84e872a0SLloyd Pique CHECK_MEMBER (_v2, _v3, height);
207*84e872a0SLloyd Pique CHECK_MEMBER (_v2, _v3, dx);
208*84e872a0SLloyd Pique CHECK_MEMBER (_v2, _v3, dy);
209*84e872a0SLloyd Pique CHECK_MEMBER (_v2, _v3, attached_width);
210*84e872a0SLloyd Pique CHECK_MEMBER (_v2, _v3, attached_height);
211*84e872a0SLloyd Pique CHECK_RENAMED_MEMBER(_v2, _v3, private, driver_private);
212*84e872a0SLloyd Pique CHECK_MEMBER (_v2, _v3, resize_callback);
213*84e872a0SLloyd Pique CHECK_MEMBER (_v2, _v3, destroy_window_callback);
214*84e872a0SLloyd Pique
215*84e872a0SLloyd Pique CHECK_SIZE (_v2, _v3);
216*84e872a0SLloyd Pique CHECK_VERSION(_v2, _v3);
217*84e872a0SLloyd Pique
218*84e872a0SLloyd Pique /* Check current wl_egl_window ABI against wl_egl_window_v3 */
219*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, version);
220*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, width);
221*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, height);
222*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, dx);
223*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, dy);
224*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, attached_width);
225*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, attached_height);
226*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, driver_private);
227*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, resize_callback);
228*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, destroy_window_callback);
229*84e872a0SLloyd Pique CHECK_MEMBER_CURRENT(_v3, surface);
230*84e872a0SLloyd Pique
231*84e872a0SLloyd Pique CHECK_SIZE_CURRENT (_v3);
232*84e872a0SLloyd Pique CHECK_VERSION_CURRENT(_v3);
233*84e872a0SLloyd Pique
234*84e872a0SLloyd Pique return 0;
235*84e872a0SLloyd Pique }
236