mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	Use glReadPixels() for the screen shooter
"Those who don't understand OpenGL are bound to reimplement it badly..."
This commit is contained in:
		
							parent
							
								
									f13eb14711
								
							
						
					
					
						commit
						c0b44328d2
					
				
					 2 changed files with 20 additions and 6 deletions
				
			
		| 
						 | 
					@ -47,7 +47,7 @@ terminal : LDLIBS += -lutil
 | 
				
			||||||
$(clients) : CFLAGS += @CLIENT_CFLAGS@
 | 
					$(clients) : CFLAGS += @CLIENT_CFLAGS@
 | 
				
			||||||
$(clients) : LDLIBS += -L. -lwayland @CLIENT_LIBS@ -lrt
 | 
					$(clients) : LDLIBS += -L. -lwayland @CLIENT_LIBS@ -lrt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install : $(libs)
 | 
					install : $(libs) $(compositors)
 | 
				
			||||||
	install -d @libdir@ @libdir@/pkgconfig ${udev_rules_dir}
 | 
						install -d @libdir@ @libdir@/pkgconfig ${udev_rules_dir}
 | 
				
			||||||
	install $(libs) @libdir@
 | 
						install $(libs) @libdir@
 | 
				
			||||||
	install wayland-server.pc wayland.pc @libdir@/pkgconfig
 | 
						install wayland-server.pc wayland.pc @libdir@/pkgconfig
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,9 +153,8 @@ screenshooter_shoot(struct wl_client *client, struct screenshooter *shooter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct egl_compositor *ec = shooter->ec;
 | 
						struct egl_compositor *ec = shooter->ec;
 | 
				
			||||||
	struct wlsc_output *output;
 | 
						struct wlsc_output *output;
 | 
				
			||||||
	GLuint stride;
 | 
					 | 
				
			||||||
	char buffer[256];
 | 
						char buffer[256];
 | 
				
			||||||
	GdkPixbuf *pixbuf;
 | 
						GdkPixbuf *pixbuf, *normal;
 | 
				
			||||||
	GError *error = NULL;
 | 
						GError *error = NULL;
 | 
				
			||||||
	void *data;
 | 
						void *data;
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
| 
						 | 
					@ -164,11 +163,25 @@ screenshooter_shoot(struct wl_client *client, struct screenshooter *shooter)
 | 
				
			||||||
	output = container_of(ec->output_list.next, struct wlsc_output, link);
 | 
						output = container_of(ec->output_list.next, struct wlsc_output, link);
 | 
				
			||||||
	while (&output->link != &ec->output_list) {
 | 
						while (&output->link != &ec->output_list) {
 | 
				
			||||||
		snprintf(buffer, sizeof buffer, "wayland-screenshot-%d.png", i++);
 | 
							snprintf(buffer, sizeof buffer, "wayland-screenshot-%d.png", i++);
 | 
				
			||||||
		data = eglReadBuffer(ec->display, output->surface, GL_FRONT_LEFT, &stride);
 | 
							data = malloc(output->width * output->height * 4);
 | 
				
			||||||
 | 
							if (data == NULL) {
 | 
				
			||||||
 | 
								fprintf(stderr, "couldn't allocate image buffer\n");
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							glReadBuffer(GL_FRONT);
 | 
				
			||||||
 | 
							glPixelStorei(GL_PACK_ALIGNMENT, 1);
 | 
				
			||||||
 | 
							glReadPixels(0, 0, output->width, output->height,
 | 
				
			||||||
 | 
								     GL_RGBA, GL_UNSIGNED_BYTE, data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE,
 | 
							pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE,
 | 
				
			||||||
						  8, output->width, output->height, stride,
 | 
											  8, output->width, output->height, output->width * 4,
 | 
				
			||||||
						  NULL, NULL);
 | 
											  NULL, NULL);
 | 
				
			||||||
		gdk_pixbuf_save(pixbuf, buffer, "png", &error, NULL);
 | 
							normal = gdk_pixbuf_flip(pixbuf, FALSE);
 | 
				
			||||||
 | 
							gdk_pixbuf_save(normal, buffer, "png", &error, NULL);
 | 
				
			||||||
 | 
							gdk_pixbuf_unref(normal);
 | 
				
			||||||
 | 
							gdk_pixbuf_unref(pixbuf);
 | 
				
			||||||
 | 
							free(data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		output = container_of(output->link.next,
 | 
							output = container_of(output->link.next,
 | 
				
			||||||
				      struct wlsc_output, link);
 | 
									      struct wlsc_output, link);
 | 
				
			||||||
| 
						 | 
					@ -788,6 +801,7 @@ init_egl(struct egl_compositor *ec, struct udev_device *device)
 | 
				
			||||||
		EGL_DEPTH_SIZE, 0,
 | 
							EGL_DEPTH_SIZE, 0,
 | 
				
			||||||
		EGL_STENCIL_SIZE, 0,
 | 
							EGL_STENCIL_SIZE, 0,
 | 
				
			||||||
		EGL_CONFIG_CAVEAT, EGL_NONE,
 | 
							EGL_CONFIG_CAVEAT, EGL_NONE,
 | 
				
			||||||
 | 
							EGL_RED_SIZE, 8,
 | 
				
			||||||
		EGL_NONE		
 | 
							EGL_NONE		
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue