9701ea14531a1be70ecea12ce422c118c09b3ec7
[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 struct wl_egl_window_v2 {
65 struct wl_surface *surface;
66
67 int width;
68 int height;
69 int dx;
70 int dy;
71
72 int attached_width;
73 int attached_height;
74
75 void *private;
76 void (*resize_callback)(struct wl_egl_window *, void *);
77 void (*destroy_window_callback)(void *);
78 };
79
80
81 /* This program checks we keep a backwards-compatible struct wl_egl_window
82 * definition whenever it is modified in wayland-egl-priv.h.
83 *
84 * The previous definition should be added above as a new struct
85 * wl_egl_window_vN, and the appropriate checks should be added below
86 */
87
88 #define MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
89
90 #define CHECK_MEMBERS(a_ver, b_ver, a_member, b_member) \
91 do { \
92 if (offsetof(struct wl_egl_window ## a_ver, a_member) != \
93 offsetof(struct wl_egl_window ## b_ver, b_member)) { \
94 printf("Backards incompatible change detected!\n " \
95 "offsetof(struct wl_egl_window" #a_ver "::" #a_member ") != " \
96 "offsetof(struct wl_egl_window" #b_ver "::" #b_member ")\n"); \
97 return 1; \
98 } \
99 \
100 if (MEMBER_SIZE(struct wl_egl_window ## a_ver, a_member) != \
101 MEMBER_SIZE(struct wl_egl_window ## b_ver, b_member)) { \
102 printf("Backards incompatible change detected!\n " \
103 "MEMBER_SIZE(struct wl_egl_window" #a_ver "::" #a_member ") != " \
104 "MEMBER_SIZE(struct wl_egl_window" #b_ver "::" #b_member ")\n"); \
105 return 1; \
106 } \
107 } while (0)
108
109 #define CHECK_MEMBER(a_ver, b_ver, member) CHECK_MEMBERS(a_ver, b_ver, member, member)
110 #define CHECK_MEMBER_CURRENT(a_ver, member) CHECK_MEMBER(a_ver,, member)
111
112 #define CHECK_SIZE(a_ver, b_ver) \
113 do { \
114 if (sizeof(struct wl_egl_window ## a_ver) > \
115 sizeof(struct wl_egl_window ## b_ver)) { \
116 printf("Backards incompatible change detected!\n " \
117 "sizeof(struct wl_egl_window" #a_ver ") > " \
118 "sizeof(struct wl_egl_window" #b_ver ")\n"); \
119 return 1; \
120 } \
121 } while (0)
122
123 #define CHECK_SIZE_CURRENT(a_ver) \
124 do { \
125 if (sizeof(struct wl_egl_window ## a_ver) != \
126 sizeof(struct wl_egl_window)) { \
127 printf("Backards incompatible change detected!\n " \
128 "sizeof(struct wl_egl_window" #a_ver ") != " \
129 "sizeof(struct wl_egl_window)\n"); \
130 return 1; \
131 } \
132 } while (0)
133
134 int main(int argc, char **argv)
135 {
136 /* Check wl_egl_window_v1 ABI against wl_egl_window_v0 */
137 CHECK_MEMBER(_v0, _v1, surface);
138 CHECK_MEMBER(_v0, _v1, width);
139 CHECK_MEMBER(_v0, _v1, height);
140 CHECK_MEMBER(_v0, _v1, dx);
141 CHECK_MEMBER(_v0, _v1, dy);
142 CHECK_MEMBER(_v0, _v1, attached_width);
143 CHECK_MEMBER(_v0, _v1, attached_height);
144
145 CHECK_SIZE(_v0, _v1);
146
147 /* Check wl_egl_window_v2 ABI against wl_egl_window_v1 */
148 CHECK_MEMBER(_v1, _v2, surface);
149 CHECK_MEMBER(_v1, _v2, width);
150 CHECK_MEMBER(_v1, _v2, height);
151 CHECK_MEMBER(_v1, _v2, dx);
152 CHECK_MEMBER(_v1, _v2, dy);
153 CHECK_MEMBER(_v1, _v2, attached_width);
154 CHECK_MEMBER(_v1, _v2, attached_height);
155 CHECK_MEMBER(_v1, _v2, private);
156 CHECK_MEMBER(_v1, _v2, resize_callback);
157
158 CHECK_SIZE(_v1, _v2);
159
160 /* Check current wl_egl_window ABI against wl_egl_window_v2 */
161 CHECK_MEMBER_CURRENT(_v2, surface);
162 CHECK_MEMBER_CURRENT(_v2, width);
163 CHECK_MEMBER_CURRENT(_v2, height);
164 CHECK_MEMBER_CURRENT(_v2, dx);
165 CHECK_MEMBER_CURRENT(_v2, dy);
166 CHECK_MEMBER_CURRENT(_v2, attached_width);
167 CHECK_MEMBER_CURRENT(_v2, attached_height);
168 CHECK_MEMBER_CURRENT(_v2, private);
169 CHECK_MEMBER_CURRENT(_v2, resize_callback);
170 CHECK_MEMBER_CURRENT(_v2, destroy_window_callback);
171
172 CHECK_SIZE_CURRENT(_v2);
173
174 return 0;
175 }