xglcomp

changeset 12:1c0d056ec360

moving slowly
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 05 Feb 2016 03:33:18 +0200
parents cb636a23f4f2
children 593a5e4a351f
files src/cwin.cc src/cwin.h src/main.cc src/xerr.cc
diffstat 4 files changed, 82 insertions(+), 31 deletions(-) [+]
line diff
     1.1 --- a/src/cwin.cc	Thu Feb 04 04:15:15 2016 +0200
     1.2 +++ b/src/cwin.cc	Fri Feb 05 03:33:18 2016 +0200
     1.3 @@ -2,6 +2,7 @@
     1.4  #include <vector>
     1.5  #include <algorithm>
     1.6  #include <X11/Xlib.h>
     1.7 +#include <X11/extensions/Xcomposite.h>
     1.8  #include <X11/extensions/Xdamage.h>
     1.9  #include "cwin.h"
    1.10  #include "logger.h"
    1.11 @@ -14,9 +15,12 @@
    1.12  {
    1.13  	xwin = xid;
    1.14  	xpixmap = 0;
    1.15 +	pixmap_valid = false;
    1.16  	memset(&attr, 0, sizeof attr);
    1.17  	mapped = false;
    1.18  	damage = 0;
    1.19 +	damaged = false;
    1.20 +	tex_valid = false;
    1.21  }
    1.22  
    1.23  CompWindow::~CompWindow()
    1.24 @@ -29,6 +33,43 @@
    1.25  	}
    1.26  }
    1.27  
    1.28 +bool CompWindow::update_attr()
    1.29 +{
    1.30 +	if(!xwin) return false;
    1.31 +
    1.32 +	XGetWindowAttributes(dpy, xwin, &attr);
    1.33 +	return true;
    1.34 +}
    1.35 +
    1.36 +bool CompWindow::update_pixmap()
    1.37 +{
    1.38 +	if(!xwin) return false;
    1.39 +
    1.40 +	Pixmap pix = XCompositeNameWindowPixmap(dpy, xwin);
    1.41 +	if(!pix) {
    1.42 +		log_error("failed to get window %x pixmap\n", xwin);
    1.43 +		return false;
    1.44 +	}
    1.45 +
    1.46 +	if(pix != xpixmap) {
    1.47 +		if(xpixmap) {
    1.48 +			XFreePixmap(dpy, xpixmap);
    1.49 +		}
    1.50 +		xpixmap = pix;
    1.51 +		tex_valid = false;
    1.52 +	}
    1.53 +	pixmap_valid = true;
    1.54 +	return true;
    1.55 +}
    1.56 +
    1.57 +bool CompWindow::update_texture()
    1.58 +{
    1.59 +	if(!xwin || !xpixmap) return false;
    1.60 +	tex.set_image(dpy, xpixmap);
    1.61 +	tex_valid = true;
    1.62 +	return true;
    1.63 +}
    1.64 +
    1.65  void add_window(CompWindow *cwin)
    1.66  {
    1.67  	if(have_window(cwin)) {
     2.1 --- a/src/cwin.h	Thu Feb 04 04:15:15 2016 +0200
     2.2 +++ b/src/cwin.h	Fri Feb 05 03:33:18 2016 +0200
     2.3 @@ -9,17 +9,24 @@
     2.4  public:
     2.5  	Window xwin;
     2.6  	Pixmap xpixmap;
     2.7 +	bool pixmap_valid;
     2.8  
     2.9  	XWindowAttributes attr;
    2.10  	bool mapped;
    2.11  
    2.12  	Damage damage;
    2.13  	XRectangle damage_rect;
    2.14 +	bool damaged;
    2.15  
    2.16  	Texture tex;
    2.17 +	bool tex_valid;
    2.18  
    2.19  	CompWindow(Window xid = 0);
    2.20  	~CompWindow();
    2.21 +
    2.22 +	bool update_attr();
    2.23 +	bool update_pixmap();
    2.24 +	bool update_texture();
    2.25  };
    2.26  
    2.27  void add_window(CompWindow *cwin);
     3.1 --- a/src/main.cc	Thu Feb 04 04:15:15 2016 +0200
     3.2 +++ b/src/main.cc	Fri Feb 05 03:33:18 2016 +0200
     3.3 @@ -72,10 +72,9 @@
     3.4  			break;
     3.5  
     3.6  		case ConfigureNotify:
     3.7 -			// XXX is this right?
     3.8  			if((cwin = find_window_xid(ev.xconfigure.window))) {
     3.9  				log_debug("updating window attributes for: %x\n", cwin->xwin);
    3.10 -				XGetWindowAttributes(dpy, cwin->xwin, &cwin->attr);
    3.11 +				cwin->update_attr();
    3.12  			}
    3.13  			break;
    3.14  
    3.15 @@ -239,6 +238,7 @@
    3.16  	pop_xerr_handler();
    3.17  
    3.18  	XFixesDestroyRegion(dpy, region);
    3.19 +	cwin->damaged = true;
    3.20  }
    3.21  
    3.22  static void redraw()
    3.23 @@ -272,13 +272,11 @@
    3.24  
    3.25  static void draw_window(CompWindow *cwin)
    3.26  {
    3.27 -	if(!cwin->xpixmap) {
    3.28 -		cwin->xpixmap = XCompositeNameWindowPixmap(dpy, cwin->xwin);
    3.29 -		if(!cwin->xpixmap) {
    3.30 -			log_warning("failed to get pixmap\n");
    3.31 -			return;
    3.32 +	if(!cwin->xpixmap || !cwin->pixmap_valid) {
    3.33 +		cwin->update_pixmap();
    3.34 +		if(!cwin->tex_valid) {
    3.35 +			cwin->update_texture();
    3.36  		}
    3.37 -		cwin->tex.set_image(dpy, cwin->xpixmap);
    3.38  	}
    3.39  
    3.40  	glBindTexture(GL_TEXTURE_2D, cwin->tex.get_id());
    3.41 @@ -294,6 +292,8 @@
    3.42  	glTexCoord2f(0, 1);
    3.43  	glVertex2f(cwin->attr.x, cwin->attr.y + cwin->attr.height);
    3.44  	glEnd();
    3.45 +
    3.46 +	cwin->damaged = false;
    3.47  }
    3.48  
    3.49  static void reshape(int x, int y)
     4.1 --- a/src/xerr.cc	Thu Feb 04 04:15:15 2016 +0200
     4.2 +++ b/src/xerr.cc	Fri Feb 05 03:33:18 2016 +0200
     4.3 @@ -6,14 +6,17 @@
     4.4  #include "xerr.h"
     4.5  #include "logger.h"
     4.6  
     4.7 -static int _XPrintDefaultError( Display *dpy, XErrorEvent *event, FILE *fp);
     4.8 +static int _XPrintDefaultError( Display *dpy, XErrorEvent *event);
     4.9  
    4.10  static std::stack<xerr_handler_type> func_stack;
    4.11  
    4.12  void push_xerr_handler(xerr_handler_type func)
    4.13  {
    4.14 +	xerr_handler_type prev = XSetErrorHandler(func);
    4.15 +	if(func_stack.empty()) {
    4.16 +		func_stack.push(prev);
    4.17 +	}
    4.18  	func_stack.push(func);
    4.19 -	XSetErrorHandler(func);
    4.20  }
    4.21  
    4.22  void pop_xerr_handler()
    4.23 @@ -29,7 +32,7 @@
    4.24  
    4.25  int xerr_debug(Display *dpy, XErrorEvent *err)
    4.26  {
    4.27 -	_XPrintDefaultError(dpy, err, stderr);
    4.28 +	_XPrintDefaultError(dpy, err);
    4.29  	return 0;
    4.30  }
    4.31  
    4.32 @@ -40,7 +43,7 @@
    4.33  
    4.34  typedef struct _XExten _XExtension;
    4.35  
    4.36 -static int _XPrintDefaultError( Display *dpy, XErrorEvent *event, FILE *fp)
    4.37 +static int _XPrintDefaultError(Display *dpy, XErrorEvent *event)
    4.38  {
    4.39  	char buffer[BUFSIZ];
    4.40  	char mesg[BUFSIZ];
    4.41 @@ -51,10 +54,10 @@
    4.42  
    4.43  	XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
    4.44  	XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
    4.45 -	(void) fprintf(fp, "%s:  %s\n  ", mesg, buffer);
    4.46 +	log_error("%s:  %s\n  ", mesg, buffer);
    4.47  	XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
    4.48  			mesg, BUFSIZ);
    4.49 -	(void) fprintf(fp, mesg, event->request_code);
    4.50 +	log_error(mesg, event->request_code);
    4.51  	if (event->request_code < 128) {
    4.52  		sprintf(number, "%d", event->request_code);
    4.53  		XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
    4.54 @@ -69,18 +72,18 @@
    4.55  		} else
    4.56  			buffer[0] = '\0';
    4.57  	}
    4.58 -	(void) fprintf(fp, " (%s)\n", buffer);
    4.59 +	log_error(" (%s)\n", buffer);
    4.60  	if (event->request_code >= 128) {
    4.61  		XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
    4.62  				mesg, BUFSIZ);
    4.63 -		fputs("  ", fp);
    4.64 -		(void) fprintf(fp, mesg, event->minor_code);
    4.65 +		log_error("  ");
    4.66 +		log_error(mesg, event->minor_code);
    4.67  		if (ext) {
    4.68  			sprintf(mesg, "%s.%d", ext->name, event->minor_code);
    4.69  			XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
    4.70 -			(void) fprintf(fp, " (%s)", buffer);
    4.71 +			log_error(" (%s)", buffer);
    4.72  		}
    4.73 -		fputs("\n", fp);
    4.74 +		log_error("\n");
    4.75  	}
    4.76  	if (event->error_code >= 128) {
    4.77  		/* kludge, try to find the extension that caused it */
    4.78 @@ -105,14 +108,14 @@
    4.79  			strcpy(buffer, "Value");
    4.80  		XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
    4.81  		if (mesg[0]) {
    4.82 -			fputs("  ", fp);
    4.83 -			(void) fprintf(fp, mesg, event->resourceid);
    4.84 -			fputs("\n", fp);
    4.85 +			log_error("  ");
    4.86 +			log_error(mesg, event->resourceid);
    4.87 +			log_error("\n");
    4.88  		}
    4.89  		/* let extensions try to print the values */
    4.90  		for (ext = dpy->ext_procs; ext; ext = ext->next) {
    4.91  			if (ext->error_values)
    4.92 -				(*ext->error_values)(dpy, event, fp);
    4.93 +				(*ext->error_values)(dpy, event, stderr);
    4.94  		}
    4.95  	} else if ((event->error_code == BadWindow) ||
    4.96  			(event->error_code == BadPixmap) ||
    4.97 @@ -133,19 +136,19 @@
    4.98  		else
    4.99  			XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
   4.100  					mesg, BUFSIZ);
   4.101 -		fputs("  ", fp);
   4.102 -		(void) fprintf(fp, mesg, event->resourceid);
   4.103 -		fputs("\n", fp);
   4.104 +		log_error("  ");
   4.105 +		log_error(mesg, event->resourceid);
   4.106 +		log_error("\n");
   4.107  	}
   4.108  	XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
   4.109  			mesg, BUFSIZ);
   4.110 -	fputs("  ", fp);
   4.111 -	(void) fprintf(fp, mesg, event->serial);
   4.112 +	log_error("  ");
   4.113 +	log_error(mesg, event->serial);
   4.114  	XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
   4.115  			mesg, BUFSIZ);
   4.116 -	fputs("\n  ", fp);
   4.117 -	(void) fprintf(fp, mesg, dpy->request);
   4.118 -	fputs("\n", fp);
   4.119 +	log_error("\n  ");
   4.120 +	log_error(mesg, dpy->request);
   4.121 +	log_error("\n");
   4.122  	if (event->error_code == BadImplementation) return 0;
   4.123  	return 1;
   4.124  }