]> git.cworth.org Git - apitrace/blobdiff - wrappers/xtrace.cpp
stash: Trace and replay of glx-tfp works
[apitrace] / wrappers / xtrace.cpp
diff --git a/wrappers/xtrace.cpp b/wrappers/xtrace.cpp
new file mode 100644 (file)
index 0000000..3ca8463
--- /dev/null
@@ -0,0 +1,183 @@
+/* Check that our prototypes match */
+#include <X11/X.h>
+
+#include "trace_writer_local.hpp"
+
+#include <cairo/cairo-xlib.h>
+
+#include "glproc.hpp"
+
+#ifdef _WIN32
+#  include <malloc.h> // alloca
+#  ifndef alloca
+#    define alloca _alloca
+#  endif
+#else
+#  include <alloca.h> // alloca
+#endif
+
+#include "trace.hpp"
+
+static std::map<void *, void *> g_WrappedObjects;
+
+
+static const char * _XCreatePixmap_args[5] = {"dpy", "d", "width", "height", "depth"};
+static const trace::FunctionSig _XCreatePixmap_sig = {2466, "XCreatePixmap", 5, _XCreatePixmap_args};
+
+static const char * _XFreePixmap_args[2] = {"dpy", "pixmap"};
+static const trace::FunctionSig _XFreePixmap_sig = {2467, "XFreePixmap", 2, _XFreePixmap_args};
+
+static const char * _PutImageData_args[8] = {"drawable", "data", "width", "height", "depth", "bits_per_pixel", "bytes_per_line", "byte_order"};
+static const trace::FunctionSig _PutImageData_sig = {2468, "PutImageData", 8, _PutImageData_args};
+
+void
+emit_fake_put_image_data(Display *dpy, Drawable pixmap)
+{
+    Window root;
+    int x_ignore, y_ignore;
+    unsigned width, height, depth, border_width_ignore;
+
+    XGetGeometry(dpy, pixmap, &root, &x_ignore, &y_ignore,
+                 &width, &height, &border_width_ignore, &depth);
+
+    {
+        static int count = 0;
+        char filename[] = "image-data-X.png";
+        cairo_surface_t *surface;
+
+        surface = cairo_xlib_surface_create(dpy, pixmap, DefaultVisual(dpy, DefaultScreen(dpy)), width, height);
+
+        filename[11] = '0' + count;
+        cairo_surface_write_to_png(surface, filename);
+
+        cairo_surface_destroy(surface);
+        count++;
+    }
+
+
+    XImage *image = XGetImage(dpy, pixmap, 0, 0, width, height, AllPlanes, ZPixmap);
+    unsigned _call = trace::localWriter.beginEnter(&_PutImageData_sig);
+    trace::localWriter.beginArg(0);
+    trace::localWriter.writeUInt(pixmap);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(1);
+    trace::localWriter.writeBlob(image->data, image->bytes_per_line * image->height);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(2);
+    trace::localWriter.writeSInt(width);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(3);
+    trace::localWriter.writeSInt(height);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(4);
+    trace::localWriter.writeSInt(image->depth);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(5);
+    trace::localWriter.writeSInt(image->bits_per_pixel);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(6);
+    trace::localWriter.writeSInt(image->bytes_per_line);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(7);
+    trace::localWriter.writeSInt(image->byte_order);
+    trace::localWriter.endArg();
+    trace::localWriter.endEnter();
+    trace::localWriter.beginLeave(_call);
+    trace::localWriter.endLeave();
+}
+
+void
+emit_fake_x_create_pixmap(Display *dpy, Drawable pixmap)
+{
+    Window root;
+    int x_ignore, y_ignore;
+    unsigned width, height, depth, border_width_ignore;
+    XGetGeometry(dpy, pixmap, &root, &x_ignore, &y_ignore,
+                 &width, &height, &border_width_ignore, &depth);
+    unsigned _call = trace::localWriter.beginEnter(&_XCreatePixmap_sig);
+    printf("Yes, really emitting fake XCreatePixmap (call no. %d)\n", _call);
+    trace::localWriter.beginArg(0);
+    trace::localWriter.writePointer((uintptr_t)dpy);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(1);
+    trace::localWriter.writeUInt(root);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(2);
+    trace::localWriter.writeUInt(width);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(3);
+    trace::localWriter.writeUInt(height);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(4);
+    trace::localWriter.writeUInt(depth);
+    trace::localWriter.endArg();
+    trace::localWriter.endEnter();
+    trace::localWriter.beginLeave(_call);
+    trace::localWriter.beginReturn();
+    trace::localWriter.writeUInt(pixmap);
+    trace::localWriter.endReturn();
+    trace::localWriter.endLeave();
+}
+
+#if 0
+extern "C" PUBLIC
+Pixmap XCreatePixmap(Display * dpy, Drawable d, unsigned int width, unsigned int height, unsigned int depth) {
+    Pixmap _result;
+    if (!trace::isTracingEnabled()) {
+    _result = _XCreatePixmap(dpy, d, width, height, depth);
+        return _result;
+    }
+    unsigned _call = trace::localWriter.beginEnter(&_XCreatePixmap_sig);
+    trace::localWriter.beginArg(0);
+    trace::localWriter.writePointer((uintptr_t)dpy);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(1);
+    trace::localWriter.writeUInt(d);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(2);
+    trace::localWriter.writeUInt(width);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(3);
+    trace::localWriter.writeUInt(height);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(4);
+    trace::localWriter.writeUInt(depth);
+    trace::localWriter.endArg();
+    trace::localWriter.endEnter();
+    _result = _XCreatePixmap(dpy, d, width, height, depth);
+    trace::localWriter.beginLeave(_call);
+    if (true) {
+    }
+    trace::localWriter.beginReturn();
+    trace::localWriter.writeUInt(_result);
+    trace::localWriter.endReturn();
+    trace::localWriter.endLeave();
+    return _result;
+}
+
+extern "C" PUBLIC
+int XFreePixmap(Display * dpy, Drawable pixmap) {
+    int _result;
+    if (!trace::isTracingEnabled()) {
+    _result = _XFreePixmap(dpy, pixmap);
+        return _result;
+    }
+    unsigned _call = trace::localWriter.beginEnter(&_XFreePixmap_sig);
+    trace::localWriter.beginArg(0);
+    trace::localWriter.writePointer((uintptr_t)dpy);
+    trace::localWriter.endArg();
+    trace::localWriter.beginArg(1);
+    trace::localWriter.writeUInt(pixmap);
+    trace::localWriter.endArg();
+    trace::localWriter.endEnter();
+    _result = _XFreePixmap(dpy, pixmap);
+    trace::localWriter.beginLeave(_call);
+    if (true) {
+    }
+    trace::localWriter.beginReturn();
+    trace::localWriter.writeSInt(_result);
+    trace::localWriter.endReturn();
+    trace::localWriter.endLeave();
+    return _result;
+}
+#endif