]> git.tdb.fi Git - geometrycompositor.git/commitdiff
Render root pixmap if available
authorMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2015 19:02:31 +0000 (21:02 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2015 19:02:31 +0000 (21:02 +0200)
source/main.c

index 185c6b4b7bd609e35cfaaa8f28cd7e77fda2e87b..a1bfe6a3dc5373e16f15c1a09e121df006ebdad7 100644 (file)
@@ -71,6 +71,9 @@ typedef struct CompositedScreen
        unsigned window_vertex_array;
        unsigned framebuffer;
        unsigned fb_texture;
+       Pixmap root_pixmap;
+       GLXPixmap root_glx_pixmap;
+       unsigned root_texture;
        CompositedWindow *windows;
        unsigned nwindows;
        unsigned windows_capacity;
@@ -89,6 +92,7 @@ typedef struct Compositor
        PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB;
        PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT;
        PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT;
+       Atom root_pmap_atom;
        Atom correction_atom;
        Atom monitors_atom;
        int dirty;
@@ -325,6 +329,8 @@ int create_gl_resources(CompositedScreen *screen)
        glDepthMask(GL_FALSE);
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
 
+       screen->root_texture = create_2d_texture();
+
        return 1;
 }
 
@@ -357,17 +363,11 @@ CompositedWindow *find_window_global(Compositor *compositor, Window w, Composite
        return NULL;
 }
 
-void create_window_pixmap(Compositor *compositor, CompositedScreen *screen, CompositedWindow *window)
+GLXPixmap pixmap_to_glx_pixmap(Compositor *compositor, CompositedScreen *screen, Pixmap pixmap)
 {
        int attribs[5];
        unsigned i;
 
-       if(window->pixmap)
-       {
-               glXDestroyPixmap(compositor->display, window->glx_pixmap);
-               XFreePixmap(compositor->display, window->pixmap);
-       }
-
        i = 0;
        attribs[i++] = GLX_TEXTURE_TARGET_EXT;
        attribs[i++] = GLX_TEXTURE_2D_EXT;
@@ -375,8 +375,19 @@ void create_window_pixmap(Compositor *compositor, CompositedScreen *screen, Comp
        attribs[i++] = GLX_TEXTURE_FORMAT_RGBA_EXT;
        attribs[i++] = None;
 
+       return glXCreatePixmap(compositor->display, screen->fbconfig, pixmap, attribs);
+}
+
+void create_window_pixmap(Compositor *compositor, CompositedScreen *screen, CompositedWindow *window)
+{
+       if(window->pixmap)
+       {
+               glXDestroyPixmap(compositor->display, window->glx_pixmap);
+               XFreePixmap(compositor->display, window->pixmap);
+       }
+
        window->pixmap = XCompositeNameWindowPixmap(compositor->display, window->window);
-       window->glx_pixmap = glXCreatePixmap(compositor->display, screen->fbconfig, window->pixmap, attribs);
+       window->glx_pixmap = pixmap_to_glx_pixmap(compositor, screen, window->pixmap);
        window->recreate_pixmap = 0;
 }
 
@@ -796,6 +807,33 @@ void update_geometry_correction(Compositor *compositor, CompositedScreen *screen
        XFree(values);
 }
 
+void update_root_pixmap(Compositor *compositor, CompositedScreen *screen)
+{
+       Atom prop_type;
+       int prop_format;
+       unsigned long overflow;
+       unsigned long length;
+       long *pixmap;
+
+       XGetWindowProperty(compositor->display, screen->root, compositor->root_pmap_atom, 0, 1, False, XA_PIXMAP,
+               &prop_type, &prop_format, &length, &overflow, (unsigned char **)&pixmap);
+       if(prop_type!=XA_PIXMAP || prop_format!=32)
+       {
+               screen->root_pixmap = 0;
+               if(screen->root_glx_pixmap)
+               {
+                       glXDestroyPixmap(compositor->display, screen->root_glx_pixmap);
+                       screen->root_glx_pixmap = 0;
+               }
+               return;
+       }
+
+       screen->root_pixmap = pixmap[0];
+       screen->root_glx_pixmap = pixmap_to_glx_pixmap(compositor, screen, screen->root_pixmap);
+
+       XFree(pixmap);
+}
+
 int initialize_screen(Compositor *compositor, unsigned number)
 {
        CompositedScreen *screen;
@@ -842,6 +880,7 @@ int initialize_screen(Compositor *compositor, unsigned number)
        XRRFreeScreenResources(xrr_res);
 
        update_geometry_correction(compositor, screen);
+       update_root_pixmap(compositor, screen);
 
        XQueryTree(compositor->display, screen->root, &dummy_root, &dummy_parent, &children, &nchildren);
 
@@ -912,6 +951,7 @@ int initialize_compositor(Compositor *compositor)
        compositor->glXBindTexImageEXT = (PFNGLXBINDTEXIMAGEEXTPROC)glXGetProcAddress((unsigned char *)"glXBindTexImageEXT");
        compositor->glXReleaseTexImageEXT = (PFNGLXRELEASETEXIMAGEEXTPROC)glXGetProcAddress((unsigned char *)"glXReleaseTexImageEXT");
 
+       compositor->root_pmap_atom = XInternAtom(compositor->display, "_XROOTPMAP_ID", False);
        compositor->correction_atom = XInternAtom(compositor->display, "GEOMETRY_CORRECTION", False);
        compositor->monitors_atom = XInternAtom(compositor->display, "GEOMETRY_CORRECTION_MONITORS", False);
 
@@ -1204,11 +1244,25 @@ void refresh_screen(Compositor *compositor, CompositedScreen *screen)
 
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, screen->framebuffer);
 
-       glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
-       glClear(GL_COLOR_BUFFER_BIT);
-
        use_mask = -1;
        glBindVertexArray(screen->window_vertex_array);
+
+       if(screen->root_pixmap)
+       {
+               use_mask = 0;
+               glUseProgram(screen->program);
+               glBindTexture(GL_TEXTURE_2D, screen->root_texture);
+               compositor->glXBindTexImageEXT(compositor->display, screen->root_glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
+               glUniform4f(screen->geometry_loc, 0.0f, 0.0f, 1.0f, 1.0f);
+               glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+               compositor->glXReleaseTexImageEXT(compositor->display, screen->root_glx_pixmap, GLX_FRONT_LEFT_EXT);
+       }
+       else
+       {
+               glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
+               glClear(GL_COLOR_BUFFER_BIT);
+       }
+
        for(i=0; i<screen->nwindows; ++i)
        {
                CompositedWindow *window;