File: 0007-Fix-644-Images-fail-to-render-on-MacOS.patch

package info (click to toggle)
geeqie 1%3A1.6-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 17,112 kB
  • sloc: ansic: 103,819; xml: 12,121; cpp: 2,087; sh: 1,056; makefile: 601; awk: 160; perl: 140
file content (317 lines) | stat: -rw-r--r-- 9,938 bytes parent folder | download
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
From: Colin Clark <colin.clark@cclark.uk>
Date: Sat, 6 Mar 2021 13:23:46 +0000
Subject: Fix #644: Images fail to render on MacOS

https://github.com/BestImageViewer/geeqie/issues/644

Change the way the "draw" signal is handled.

Overlay guidelines are disabled.

This patch also fixes showing the image on Wayland, without it we often
only get a white rectangle where the image was supposed to show.

---
 src/image-overlay.c  |  51 +++++++++++----------
 src/renderer-tiles.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 143 insertions(+), 35 deletions(-)

diff --git a/src/image-overlay.c b/src/image-overlay.c
index 6116b5a..ff377e8 100644
--- a/src/image-overlay.c
+++ b/src/image-overlay.c
@@ -202,7 +202,6 @@ gint image_osd_histogram_get_mode(ImageWindow *imd)
 void image_osd_toggle(ImageWindow *imd)
 {
 	OsdShowFlags show;
-
 	if (!imd) return;
 
 	show = image_osd_get(imd);
@@ -522,30 +521,32 @@ static GdkPixbuf *image_osd_guidelines_render(OverlayStateData *osd)
 	GdkPixbuf *rectangles;
 	ImageWindow *imd = osd->imd;
 
-	pixbuf_renderer_get_scaled_size((PixbufRenderer *)imd->pr, &width, &height);
-
-	if (width && height)
-		{
-		rectangles = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
-		if (rectangles)
-			{
-			pixbuf_set_rect_fill(rectangles, 0, 0, width, height, 255, 255, 255, 0);
-			pixbuf_set_rect(rectangles, 0, 0 + (height / 3), width, height / 3,
-								0, 0, 0, 255,
-								1, 1, 1, 1);
-			pixbuf_set_rect(rectangles, 0, 0 + (height / 3 + 1), width, height / 3 - 2,
-								255, 255, 255, 255,
-								1, 1, 1, 1);
-
-			pixbuf_set_rect(rectangles, 0 + width / 3, 0 , width / 3, height,
-								0, 0, 0, 255,
-								1, 1, 1, 1);
-			pixbuf_set_rect(rectangles, 0 + width / 3 + 1, 0, width / 3 - 2, height,
-								255, 255, 255, 255,
-								1, 1, 1, 1);
-			return rectangles;
-			}
-		}
+/* FIXME: guidelines does not work with revised draw signal handling
+ */
+	//~ pixbuf_renderer_get_scaled_size((PixbufRenderer *)imd->pr, &width, &height);
+
+	//~ if (width && height)
+		//~ {
+		//~ rectangles = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+		//~ if (rectangles)
+			//~ {
+			//~ pixbuf_set_rect_fill(rectangles, 0, 0, width, height, 255, 255, 255, 0);
+			//~ pixbuf_set_rect(rectangles, 0, 0 + (height / 3), width, height / 3,
+								//~ 0, 0, 0, 255,
+								//~ 1, 1, 1, 1);
+			//~ pixbuf_set_rect(rectangles, 0, 0 + (height / 3 + 1), width, height / 3 - 2,
+								//~ 255, 255, 255, 255,
+								//~ 1, 1, 1, 1);
+
+			//~ pixbuf_set_rect(rectangles, 0 + width / 3, 0 , width / 3, height,
+								//~ 0, 0, 0, 255,
+								//~ 1, 1, 1, 1);
+			//~ pixbuf_set_rect(rectangles, 0 + width / 3 + 1, 0, width / 3 - 2, height,
+								//~ 255, 255, 255, 255,
+								//~ 1, 1, 1, 1);
+			//~ return rectangles;
+			//~ }
+		//~ }
 
 	return NULL;
 }
diff --git a/src/renderer-tiles.c b/src/renderer-tiles.c
index 9b4f049..cc0483a 100644
--- a/src/renderer-tiles.c
+++ b/src/renderer-tiles.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2006 John Ellis
- * Copyright (C) 2008 - 2016 The Geeqie Team
+ * Copyright (C) 2008 - 2021 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -135,6 +135,7 @@ struct _RendererTiles
 
 	GList *overlay_list;
 	cairo_surface_t *overlay_buffer;
+	cairo_surface_t *surface;
 
 	guint draw_idle_id; /* event source id */
 
@@ -210,8 +211,11 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h)
 
 	if (!window) return;
 
+#if GTK_CHECK_VERSION(3,0,0)
+	cr = cairo_create(rt->surface);
+#else
 	cr = gdk_cairo_create(window);
-
+#endif
 
 	if (!pr->pixbuf && !pr->source_tiles_enabled)
 		{
@@ -602,7 +606,9 @@ static void rt_overlay_init_window(RendererTiles *rt, OverlayData *od)
 	od->window = gdk_window_new(gtk_widget_get_window(GTK_WIDGET(pr)), &attributes, attributes_mask);
 	gdk_window_set_user_data(od->window, pr);
 	gdk_window_move(od->window, px + rt->stereo_off_x, py + rt->stereo_off_y);
+#if !GTK_CHECK_VERSION(3,0,0)
 	gdk_window_show(od->window);
+#endif
 }
 
 static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h,
@@ -786,7 +792,11 @@ gint renderer_tiles_overlay_add(void *renderer, GdkPixbuf *pixbuf, gint x, gint
 
 	rt->overlay_list = g_list_append(rt->overlay_list, od);
 
+#if GTK_CHECK_VERSION(3,0,0)
+	gtk_widget_queue_draw(GTK_WIDGET(rt->pr));
+#else
 	rt_overlay_queue_draw(rt, od, 0, 0, 0, 0);
+#endif
 
 	return od->id;
 }
@@ -834,6 +844,30 @@ static void rt_overlay_list_reset_window(RendererTiles *rt)
 		}
 }
 
+#if GTK_CHECK_VERSION(3,0,0)
+void renderer_tiles_overlay_set(void *renderer, gint id, GdkPixbuf *pixbuf, gint x, gint y)
+{
+	RendererTiles *rc = (RendererTiles *)renderer;
+	PixbufRenderer *pr = rc->pr;
+	OverlayData *od;
+
+	g_return_if_fail(IS_PIXBUF_RENDERER(pr));
+
+	od = rt_overlay_find(rc, id);
+	if (!od) return;
+
+	if (pixbuf)
+		{
+		g_object_ref(G_OBJECT(pixbuf));
+		g_object_unref(G_OBJECT(od->pixbuf));
+		od->pixbuf = pixbuf;
+		}
+	else
+		{
+		rt_overlay_free(rc, od);
+		}
+}
+#else
 void renderer_tiles_overlay_set(void *renderer, gint id, GdkPixbuf *pixbuf, gint x, gint y)
 {
 	RendererTiles *rt = (RendererTiles *) renderer;
@@ -868,6 +902,7 @@ void renderer_tiles_overlay_set(void *renderer, gint id, GdkPixbuf *pixbuf, gint
 		rt_overlay_free(rt, od);
 		}
 }
+#endif
 
 gboolean renderer_tiles_overlay_get(void *renderer, gint id, GdkPixbuf **pixbuf, gint *x, gint *y)
 {
@@ -1520,7 +1555,11 @@ static void rt_tile_expose(RendererTiles *rt, ImageTile *it,
 	box = GTK_WIDGET(pr);
 	window = gtk_widget_get_window(box);
 
+#if GTK_CHECK_VERSION(3,0,0)
+	cr = cairo_create(rt->surface);
+#else
 	cr = gdk_cairo_create(window);
+#endif
 	cairo_set_source_surface(cr, it->surface, pr->x_offset + (it->x - rt->x_scroll) + rt->stereo_off_x, pr->y_offset + (it->y - rt->y_scroll) + rt->stereo_off_y);
 	cairo_rectangle (cr, pr->x_offset + (it->x - rt->x_scroll) + x + rt->stereo_off_x, pr->y_offset + (it->y - rt->y_scroll) + y + rt->stereo_off_y, w, h);
 	cairo_fill (cr);
@@ -1533,6 +1572,10 @@ static void rt_tile_expose(RendererTiles *rt, ImageTile *it,
 				w, h,
 				it);
 		}
+
+#if GTK_CHECK_VERSION(3,0,0)
+	gtk_widget_queue_draw(GTK_WIDGET(rt->pr));
+#endif
 }
 
 
@@ -1958,11 +2001,16 @@ static void rt_scroll(void *renderer, gint x_off, gint y_off)
 			y2 = abs(y_off);
 			}
 
+#if GTK_CHECK_VERSION(3,0,0)
+		cr = cairo_create(rt->surface);
+		surface = rt->surface;
+#else
 		box = GTK_WIDGET(pr);
 		window = gtk_widget_get_window(box);
 
 		cr = gdk_cairo_create(window);
 		surface = cairo_get_target(cr);
+#endif
 		/* clipping restricts the intermediate surface's size, so it's a good idea
 		 * to use it. */
 		cairo_rectangle(cr, x1 + pr->x_offset + rt->stereo_off_x, y1 + pr->y_offset + rt->stereo_off_y, w, h);
@@ -2128,21 +2176,78 @@ static void renderer_free(void *renderer)
 }
 
 #if GTK_CHECK_VERSION(3,0,0)
+static gboolean rt_realize_cb(GtkWidget *widget, gpointer data)
+{
+	RendererTiles *rt = (RendererTiles *)data;
+	cairo_t *cr;
+
+	if (!rt->surface)
+		{
+		rt->surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height(widget));
+
+		cr = cairo_create(rt->surface);
+		cairo_set_source_rgb(cr, (gdouble)options->image.border_color.red  /65535, (gdouble)options->image.border_color.green / 65535, (gdouble)options->image.border_color.blue / 65535);
+		cairo_paint(cr);
+		cairo_destroy(cr);
+		}
+
+	return FALSE;
+}
+
+static gboolean rt_size_allocate_cb(GtkWidget *widget,  GdkRectangle *allocation, gpointer data)
+{
+	RendererTiles *rt = data;
+	cairo_t *cr;
+	cairo_surface_t *old_surface;
+
+	if (gtk_widget_get_realized(GTK_WIDGET(rt->pr)))
+		{
+		old_surface = rt->surface;
+		rt->surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, allocation->width, allocation->height);
+
+		cr = cairo_create(rt->surface);
+
+		cairo_set_source_rgb(cr, (gdouble)options->image.border_color.red / 65535, (gdouble)options->image.border_color.green / 65535, (gdouble)options->image.border_color.blue / 65535);
+		cairo_paint(cr);
+		cairo_set_source_surface(cr, old_surface, 0, 0);
+		cairo_paint(cr);
+		cairo_destroy(cr);
+		cairo_surface_destroy(old_surface);
+
+		renderer_redraw(rt, allocation->x, allocation->y, allocation->width, allocation->height, FALSE, TILE_RENDER_ALL, FALSE, FALSE);
+	}
+
+	return FALSE;
+}
 
 static gboolean rt_draw_cb(GtkWidget *widget, cairo_t *cr, gpointer data)
 {
 	RendererTiles *rt = (RendererTiles *)data;
-	if (gtk_widget_is_drawable(widget))
+	GList *work;
+	OverlayData *od;
+
+	cairo_set_source_surface (cr, rt->surface, 0, 0);
+	cairo_paint(cr);
+
+	work = rt->overlay_list;
+	while (work)
 		{
-		if (gtk_widget_get_has_window(widget))
+		od = work->data;
+		gint px, py, pw, ph;
+		pw = gdk_pixbuf_get_width(od->pixbuf);
+		ph = gdk_pixbuf_get_height(od->pixbuf);
+		px = od->x;
+		py = od->y;
+
+		if (od->flags & OVL_RELATIVE)
 			{
-			GdkRectangle area;
-			if (gdk_cairo_get_clip_rectangle(cr, &area))
-				{
-				renderer_redraw(rt, area.x, area.y, area.width, area.height,
-						FALSE, TILE_RENDER_ALL, FALSE, FALSE);
-				}
+			if (px < 0) px = rt->pr->viewport_width - pw + px;
+			if (py < 0) py = rt->pr->viewport_height - ph + py;
 			}
+
+		gdk_cairo_set_source_pixbuf(cr, od->pixbuf, px, py);
+		cairo_paint(cr);
+		work = work->next;
 		}
 
 	return FALSE;
@@ -2229,6 +2334,8 @@ RendererFuncs *renderer_tiles_new(PixbufRenderer *pr)
 #if GTK_CHECK_VERSION(3,0,0)
 	g_signal_connect(G_OBJECT(pr), "draw",
 	                 G_CALLBACK(rt_draw_cb), rt);
+	g_signal_connect(G_OBJECT(pr), "realize", G_CALLBACK(rt_realize_cb), rt);
+	g_signal_connect(G_OBJECT(pr), "size-allocate", G_CALLBACK(rt_size_allocate_cb), rt);
 #else
 	g_signal_connect(G_OBJECT(pr), "expose_event",
 	                 G_CALLBACK(rt_expose_cb), rt);