xglcomp
changeset 7:03ca0fd49916
merged
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 30 Jan 2016 07:48:51 +0200 |
parents | 3f908f812ec7 |
children | b0081a0c211f |
files | src/cwin.cc src/cwin.h src/main.cc |
diffstat | 3 files changed, 37 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- a/src/cwin.cc Fri Jan 29 10:23:08 2016 +0200 1.2 +++ b/src/cwin.cc Sat Jan 30 07:48:51 2016 +0200 1.3 @@ -1,9 +1,13 @@ 1.4 #include <string.h> 1.5 #include <vector> 1.6 #include <algorithm> 1.7 +#include <X11/Xlib.h> 1.8 +#include <X11/extensions/Xdamage.h> 1.9 #include "cwin.h" 1.10 #include "logger.h" 1.11 1.12 +extern Display *dpy; 1.13 + 1.14 static std::vector<CompWindow*> cwinlist; 1.15 1.16 CompWindow::CompWindow(Window xid) 1.17 @@ -12,6 +16,17 @@ 1.18 xpixmap = 0; 1.19 memset(&attr, 0, sizeof attr); 1.20 mapped = false; 1.21 + damage = 0; 1.22 +} 1.23 + 1.24 +CompWindow::~CompWindow() 1.25 +{ 1.26 + if(xpixmap) { 1.27 + XFreePixmap(dpy, xpixmap); 1.28 + } 1.29 + if(damage) { 1.30 + XDamageDestroy(dpy, damage); 1.31 + } 1.32 } 1.33 1.34 void add_window(CompWindow *cwin) 1.35 @@ -21,6 +36,11 @@ 1.36 return; 1.37 } 1.38 1.39 + // create the damage structure to track dirty regions in this window 1.40 + if(!cwin->damage) { 1.41 + cwin->damage = XDamageCreate(dpy, cwin->xwin, XDamageReportNonEmpty); 1.42 + } 1.43 + 1.44 cwinlist.push_back(cwin); 1.45 } 1.46
2.1 --- a/src/cwin.h Fri Jan 29 10:23:08 2016 +0200 2.2 +++ b/src/cwin.h Sat Jan 30 07:48:51 2016 +0200 2.3 @@ -2,6 +2,7 @@ 2.4 #define COMP_WIN_H_ 2.5 2.6 #include <X11/Xlib.h> 2.7 +#include <X11/extensions/Xdamage.h> 2.8 #include "texture.h" 2.9 2.10 class CompWindow { 2.11 @@ -12,9 +13,13 @@ 2.12 XWindowAttributes attr; 2.13 bool mapped; 2.14 2.15 + Damage damage; 2.16 + XRectangle damage_rect; 2.17 + 2.18 Texture tex; 2.19 2.20 CompWindow(Window xid = 0); 2.21 + ~CompWindow(); 2.22 }; 2.23 2.24 void add_window(CompWindow *cwin);
3.1 --- a/src/main.cc Fri Jan 29 10:23:08 2016 +0200 3.2 +++ b/src/main.cc Sat Jan 30 07:48:51 2016 +0200 3.3 @@ -16,6 +16,7 @@ 3.4 static void start_comp(); 3.5 static void manage_window(Window xwin); 3.6 static void unmanage_window(Window xwin); 3.7 +static void damage_window(XDamageNotifyEvent *ev); 3.8 static void redraw(); 3.9 static void draw_window(CompWindow *cwin); 3.10 static void reshape(int x, int y); 3.11 @@ -108,6 +109,7 @@ 3.12 3.13 default: 3.14 if(ev.type == xdmg_ev_base + XDamageNotify) { 3.15 + damage_window((XDamageNotifyEvent*)&ev); 3.16 } 3.17 } 3.18 3.19 @@ -217,14 +219,20 @@ 3.20 CompWindow *cwin = find_window_xid(xwin); 3.21 if(!cwin) return; 3.22 3.23 - if(cwin->xpixmap) { 3.24 - XFreePixmap(dpy, cwin->xpixmap); 3.25 - } 3.26 - 3.27 remove_window(cwin); 3.28 delete cwin; 3.29 } 3.30 3.31 +static void damage_window(XDamageNotifyEvent *ev) 3.32 +{ 3.33 + XserverRegion region; 3.34 + CompWindow *cwin = find_window_xid(ev->drawable); 3.35 + if(!cwin) return; 3.36 + 3.37 + region = XFixesCreateRegion(dpy, 0, 0); 3.38 + XDamageSubtract(dpy, cwin->damage, None, region); 3.39 +} 3.40 + 3.41 static void redraw() 3.42 { 3.43 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);