code: drawterm

Download patch

ref: 6b448b9bd61307ef3bd3ed69270c8a02100ff40d
parent: efe20ef776810a233bf008901ad02144bbc5736e
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Mar 2 12:07:49 EST 2022

wayland: clean up, copy less and remove locking on frame done callback (a bit faster redrawing)

--- a/gui-wl/wl-cb.c
+++ b/gui-wl/wl-cb.c
@@ -79,10 +79,8 @@
 	wl = data;
 	wl_callback_destroy(cb);
 	cb = wl_surface_frame(wl->surface);
-	qlock(&drawlock);
-	wlflush(wl);
-	qunlock(&drawlock);
 	wl_callback_add_listener(cb, &wl_surface_frame_listener, wl);
+	wlflush(wl);
 }
 
 static void
@@ -93,7 +91,7 @@
 	Wlwin *wl;
 
 	wl = data;
-	keymap_string = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+	keymap_string = mmap(nil, size, PROT_READ, MAP_SHARED, fd, 0);
 	xkb_keymap_unref(keymap);
 	keymap = xkb_keymap_new_from_string(wl->xkb_context, keymap_string, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
 	munmap(keymap_string, size);
@@ -477,9 +475,8 @@
 	int fds[2];
 
 	// An application has set the clipboard contents
-	if (offer == NULL) {
+	if(offer == nil)
 		return;
-	}
 
 	wl = data;
 	pipe2(fds, O_CLOEXEC);
--- a/gui-wl/wl-screen.c
+++ b/gui-wl/wl-screen.c
@@ -47,14 +47,17 @@
 void
 wlflush(Wlwin *wl)
 {
-	if(wl->dirty == 1)
-		memcpy(wl->shm_data, gscreen->data->bdata, wl->dx*wl->dy*4);
+	Point p;
 
 	wl_surface_attach(wl->surface, wl->screenbuffer, 0, 0);
-	if(wl->dirty)
-		wl_surface_damage(wl->surface, wl->r.min.x, wl->r.min.y, Dx(wl->r), Dy(wl->r));
+	if(wl->dirty){
+		p.x = wl->r.min.x;
+		for(p.y = wl->r.min.y; p.y < wl->r.max.y; p.y++)
+			memcpy(wl->shm_data+(p.y*wl->dx+p.x)*4, byteaddr(gscreen, p), Dx(wl->r)*4);
+		wl_surface_damage(wl->surface, p.x, wl->r.min.y, Dx(wl->r), Dy(wl->r));
+		wl->dirty = 0;
+	}
 	wl_surface_commit(wl->surface);
-	wl->dirty = 0;
 }
 
 void
@@ -86,9 +89,8 @@
 {
 	Wlwin *wl;
 	wl = a;
-	for(;wl->runing == 1;){
+	while(wl->runing)
 		wl_display_dispatch(wl->display);
-	}
 }
 
 static Wlwin*
@@ -99,7 +101,7 @@
 
 	wl = newwlwin();
 	gwin = wl;
-	wl->display = wl_display_connect(NULL);
+	wl->display = wl_display_connect(nil);
 	if(wl->display == nil)
 		sysfatal("could not connect to display");
 
@@ -151,19 +153,15 @@
 void
 flushmemscreen(Rectangle r)
 {
-	Wlwin *wl;
-
-	wl = gwin;
-	wl->dirty = 1;
-	wl->r = r;
-	wlflush(wl);
+	gwin->dirty = 1;
+	gwin->r = r;
+	wlflush(gwin);
 }
 
 void
 screensize(Rectangle r, ulong chan)
 {
-	gwin->dirty = 1;
-	gwin->r = r;
+	flushmemscreen(r);
 }
 
 void