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