summaryrefslogtreecommitdiffstats
path: root/bsp/meta-synopsys/recipes-graphics/wayland/weston/1011-xwm-move-FILE-to-the-callers-of-dump_property.patch
blob: 693bff29d1e0cda6e4f38d91a5fecdbddd4f5fcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
From b3b006559856037ab97200b93641640b88ec7db8 Mon Sep 17 00:00:00 2001
From: Pekka Paalanen <pq@iki.fi>
Date: Thu, 12 Oct 2017 13:18:13 +0200
Subject: [PATCH 11/46] xwm: move FILE to the callers of dump_property()

This is preparation for using the weston-debug infrastructure for
WM_DEBUG. dump_property() may be called from different debugging
contexts and often needs to be prefixed with more information.

An alternative to this patch would be to pass in the weston_debug_scope
as an argument to dump_property(), but then all callers would need to be
converted to weston-debug infra in a single commit.

Therefore require the callers to provide the FILE* to print to.

Signed-off-by: Pekka Paalanen <pq@iki.fi>
Signed-off-by: Maniraj Devadoss <Maniraj.Devadoss@in.bosch.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
---
 xwayland/selection.c      | 39 ++++++++++++++++++++++++---
 xwayland/window-manager.c | 67 +++++++++++++++++++----------------------------
 xwayland/xwayland.h       |  3 ++-
 3 files changed, 65 insertions(+), 44 deletions(-)

diff --git a/xwayland/selection.c b/xwayland/selection.c
index 59702246..e0eb3ffc 100644
--- a/xwayland/selection.c
+++ b/xwayland/selection.c
@@ -34,6 +34,12 @@
 #include "xwayland.h"
 #include "shared/helpers.h"
 
+#ifdef WM_DEBUG
+#define wm_log(...) weston_log(__VA_ARGS__)
+#else
+#define wm_log(...) do {} while (0)
+#endif
+
 static int
 writable_callback(int fd, uint32_t mask, void *data)
 {
@@ -102,6 +108,9 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
 {
 	xcb_get_property_cookie_t cookie;
 	xcb_get_property_reply_t *reply;
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
 
 	cookie = xcb_get_property(wm->conn,
 				  0, /* delete */
@@ -115,7 +124,13 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
 	if (reply == NULL)
 		return;
 
-	dump_property(wm, wm->atom.wl_selection, reply);
+	fp = open_memstream(&logstr, &logsize);
+	if (fp) {
+		dump_property(fp, wm, wm->atom.wl_selection, reply);
+		if (fclose(fp) == 0)
+			wm_log("%s", logstr);
+		free(logstr);
+	}
 
 	if (xcb_get_property_value_length(reply) > 0) {
 		/* reply's ownership is transferred to wm, which is responsible
@@ -178,6 +193,9 @@ weston_wm_get_selection_targets(struct weston_wm *wm)
 	xcb_atom_t *value;
 	char **p;
 	uint32_t i;
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
 
 	cookie = xcb_get_property(wm->conn,
 				  1, /* delete */
@@ -191,7 +209,13 @@ weston_wm_get_selection_targets(struct weston_wm *wm)
 	if (reply == NULL)
 		return;
 
-	dump_property(wm, wm->atom.wl_selection, reply);
+	fp = open_memstream(&logstr, &logsize);
+	if (fp) {
+		dump_property(fp, wm, wm->atom.wl_selection, reply);
+		if (fclose(fp) == 0)
+			wm_log("%s", logstr);
+		free(logstr);
+	}
 
 	if (reply->type != XCB_ATOM_ATOM) {
 		free(reply);
@@ -232,6 +256,9 @@ weston_wm_get_selection_data(struct weston_wm *wm)
 {
 	xcb_get_property_cookie_t cookie;
 	xcb_get_property_reply_t *reply;
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
 
 	cookie = xcb_get_property(wm->conn,
 				  1, /* delete */
@@ -243,7 +270,13 @@ weston_wm_get_selection_data(struct weston_wm *wm)
 
 	reply = xcb_get_property_reply(wm->conn, cookie, NULL);
 
-	dump_property(wm, wm->atom.wl_selection, reply);
+	fp = open_memstream(&logstr, &logsize);
+	if (fp) {
+		dump_property(fp, wm, wm->atom.wl_selection, reply);
+		if (fclose(fp) == 0)
+			wm_log("%s", logstr);
+		free(logstr);
+	}
 
 	if (reply == NULL) {
 		return;
diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c
index 3bf323a4..4a26f6e7 100644
--- a/xwayland/window-manager.c
+++ b/xwayland/window-manager.c
@@ -210,23 +210,6 @@ wm_log(const char *fmt, ...)
 #endif
 }
 
-static int __attribute__ ((format (printf, 1, 2)))
-wm_log_continue(const char *fmt, ...)
-{
-#ifdef WM_DEBUG
-	int l;
-	va_list argp;
-
-	va_start(argp, fmt);
-	l = weston_vlog_continue(fmt, argp);
-	va_end(argp);
-
-	return l;
-#else
-	return 0;
-#endif
-}
-
 static void
 weston_output_weak_ref_init(struct weston_output_weak_ref *ref)
 {
@@ -430,7 +413,7 @@ dump_cardinal_array(FILE *fp, xcb_get_property_reply_t *reply)
 }
 
 void
-dump_property(struct weston_wm *wm,
+dump_property(FILE *fp, struct weston_wm *wm,
 	      xcb_atom_t property, xcb_get_property_reply_t *reply)
 {
 	int32_t *incr_value;
@@ -439,18 +422,11 @@ dump_property(struct weston_wm *wm,
 	xcb_window_t *window_value;
 	int width, len;
 	uint32_t i;
-	FILE *fp;
-	char *logstr;
-	size_t logsize;
-
-	fp = open_memstream(&logstr, &logsize);
-	if (!fp)
-		return;
 
 	width = fprintf(fp, "%s: ", get_atom_name(wm->conn, property));
 	if (reply == NULL) {
 		fprintf(fp, "(no reply)\n");
-		goto out;
+		return;
 	}
 
 	width += fprintf(fp, "%s/%d, length %d (value_len %d): ",
@@ -492,15 +468,10 @@ dump_property(struct weston_wm *wm,
 	} else {
 		fprintf(fp, "huh?\n");
 	}
-
-out:
-	if (fclose(fp) == 0)
-		wm_log_continue("%s", logstr);
-	free(logstr);
 }
 
 static void
-read_and_dump_property(struct weston_wm *wm,
+read_and_dump_property(FILE *fp, struct weston_wm *wm,
 		       xcb_window_t window, xcb_atom_t property)
 {
 	xcb_get_property_reply_t *reply;
@@ -510,7 +481,7 @@ read_and_dump_property(struct weston_wm *wm,
 				  property, XCB_ATOM_ANY, 0, 2048);
 	reply = xcb_get_property_reply(wm->conn, cookie, NULL);
 
-	dump_property(wm, property, reply);
+	dump_property(fp, wm, property, reply);
 
 	free(reply);
 }
@@ -1389,19 +1360,35 @@ weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *even
 	xcb_property_notify_event_t *property_notify =
 		(xcb_property_notify_event_t *) event;
 	struct weston_wm_window *window;
+	FILE *fp;
+	char *logstr;
+	size_t logsize;
 
 	if (!wm_lookup_window(wm, property_notify->window, &window))
 		return;
 
 	window->properties_dirty = 1;
 
-	wm_log("XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
-	if (property_notify->state == XCB_PROPERTY_DELETE)
-		wm_log_continue("deleted %s\n",
-				get_atom_name(wm->conn, property_notify->atom));
-	else
-		read_and_dump_property(wm, property_notify->window,
-				       property_notify->atom);
+	fp = open_memstream(&logstr, &logsize);
+	if (fp) {
+		fprintf(fp, "XCB_PROPERTY_NOTIFY: window %d, ", property_notify->window);
+		if (property_notify->state == XCB_PROPERTY_DELETE)
+			fprintf(fp, "deleted %s\n",
+					get_atom_name(wm->conn, property_notify->atom));
+		else
+			read_and_dump_property(fp, wm, property_notify->window,
+					       property_notify->atom);
+
+		if (fclose(fp) == 0)
+			wm_log("%s", logstr);
+		free(logstr);
+	} else {
+		/* read_and_dump_property() is a X11 roundtrip.
+		 * Mimic it to maintain ordering semantics between debug
+		 * and non-debug paths.
+		 */
+		get_atom_name(wm->conn, property_notify->atom);
+	}
 
 	if (property_notify->atom == wm->atom.net_wm_name ||
 	    property_notify->atom == XCB_ATOM_WM_NAME)
diff --git a/xwayland/xwayland.h b/xwayland/xwayland.h
index ca75f5b7..52da6786 100644
--- a/xwayland/xwayland.h
+++ b/xwayland/xwayland.h
@@ -23,6 +23,7 @@
  * SOFTWARE.
  */
 
+#include <stdio.h>
 #include <wayland-server.h>
 #include <xcb/xcb.h>
 #include <xcb/xfixes.h>
@@ -159,7 +160,7 @@ struct weston_wm {
 };
 
 void
-dump_property(struct weston_wm *wm, xcb_atom_t property,
+dump_property(FILE *fp, struct weston_wm *wm, xcb_atom_t property,
 	      xcb_get_property_reply_t *reply);
 
 const char *
-- 
2.16.2