]> git.cworth.org Git - apitrace/blobdiff - retrace/glws_glx.cpp
stash: Trace and replay of gnome-shell works
[apitrace] / retrace / glws_glx.cpp
index b6175304d29dd1ff8557027a8dab800d4f3373e0..b75945c8e8a8d3becbbf1239366356a9f3718dfb 100644 (file)
@@ -31,6 +31,8 @@
 #include "glproc.hpp"
 #include "glws.hpp"
 
+#include <cairo/cairo-xlib.h>
+
 
 namespace glws {
 
@@ -149,6 +151,12 @@ public:
         glXWaitX();
     }
 
+    GlxDrawable(const unsigned pixmap_id, int width, int height) :
+        Drawable(NULL, width, height, false)
+    {
+        window = pixmap_id;
+    }
+
     void processKeys(void) {
         XEvent event;
         while (XCheckWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event)) {
@@ -220,7 +228,6 @@ public:
     }
 };
 
-
 class GlxContext : public Context
 {
 public:
@@ -238,6 +245,8 @@ public:
 
 void
 init(void) {
+    XInitThreads();
+
     display = XOpenDisplay(NULL);
     if (!display) {
         std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
@@ -396,5 +405,136 @@ processEvents(void) {
     return true;
 }
 
+void
+createWindow(Drawable *drawable, const Visual *_visual)
+{
+    GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+    const GlxVisual *visual = static_cast<const GlxVisual *>(_visual);
+
+    glXCreateWindow(display, visual->fbconfig, glxDrawable->window, NULL);
+}
+
+Drawable *
+createPixmap(unsigned width, unsigned height, unsigned depth)
+{
+    Pixmap pixmap;
+
+    pixmap = XCreatePixmap(display, DefaultRootWindow(display),
+                           width, height, depth);
+
+    return new GlxDrawable(pixmap, width, height);
+}
+
+Drawable *
+createGLPixmap(GLXFBConfig fbconfig, Drawable *_pixmap,
+             unsigned width, unsigned height, int *attrib_list)
+{
+    GlxDrawable *pixmap = static_cast<GlxDrawable *>(_pixmap);
+    Pixmap gl_pixmap;
+
+    gl_pixmap = glXCreatePixmap(display, fbconfig, pixmap->window, attrib_list);
+
+    return new GlxDrawable(gl_pixmap, width, height);
+}
+
+void
+destroyWindow(Drawable *drawable)
+{
+/*
+    GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+
+    glXDestroyWindow(display, glxDrawable->window);
+*/
+}
+
+void
+bindTexImage(Drawable *drawable, int buffer)
+{
+    GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+
+    glXBindTexImageEXT(display, glxDrawable->window, buffer, NULL);
+}
+
+void
+releaseTexImage(Drawable *drawable, int buffer)
+{
+    GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+
+    glXReleaseTexImageEXT(display, glxDrawable->window, buffer);
+}
+
+void
+copySubBuffer(Drawable *drawable, int x, int y, int width, int height)
+{
+    GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+
+    glXCopySubBufferMESA(display, glxDrawable->window, x, y, width, height);
+}
+
+void
+putImageData(glws::Drawable *drawable, char *data,
+             int width, int height, int depth,
+             int bits_per_pixel, int bytes_per_line, int byte_order)
+{
+    GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+    GC gc;
+    XImage image;
+
+    image.width = width;
+    image.height = height;
+    image.format = ZPixmap;
+    image.data = data;
+    image.byte_order = byte_order;
+    image.bitmap_unit = 32;
+    image.bitmap_bit_order = byte_order;
+    image.bitmap_pad = 32;
+    image.depth = depth,
+    image.bytes_per_line = bytes_per_line;
+    image.bits_per_pixel = bits_per_pixel;
+    image.red_mask = 0;
+    image.green_mask = 0;
+    image.blue_mask = 0;
+    image.obdata = 0;
+
+    XInitImage(&image);
+
+    {
+        Window root;
+        int x_ignore, y_ignore;
+        unsigned width, height, depth, border_width_ignore;
+        XGetGeometry(display, glxDrawable->window, &root, &x_ignore, &y_ignore,
+                     &width, &height, &border_width_ignore, &depth);
+    }
+
+    gc = XCreateGC(display, glxDrawable->window, 0, NULL);
+    XPutImage(display, glxDrawable->window, gc, &image, 0, 0, 0, 0, width, height);
+
+    {
+        static int count = 0;
+        char filename[] = "put-image-data-X.png";
+        cairo_surface_t *surface;
+
+        surface = cairo_xlib_surface_create(display, glxDrawable->window, DefaultVisual(display, DefaultScreen(display)), width, height);
+
+        filename[15] = '0' + count;
+        cairo_surface_write_to_png(surface, filename);
+
+        cairo_surface_destroy(surface);
+        count++;
+    }
+
+}
+
+GLXFBConfig
+chooseConfig(int *attrib_list)
+{
+    GLXFBConfig *configs;
+    int nelements;
+    configs = glXChooseFBConfig(display, DefaultScreen(display), attrib_list, &nelements);
+    if (nelements)
+        return configs[nelements - 1];
+    else
+        return NULL;
+}
 
-} /* namespace glws */
+} /* drawable glws */