]> git.cworth.org Git - apitrace/blob - wrappers/xtrace.cpp
stash: Trace and replay of gnome-shell works
[apitrace] / wrappers / xtrace.cpp
1 /* Check that our prototypes match */
2 #include <X11/X.h>
3
4 #include "trace_writer_local.hpp"
5
6 #include <cairo/cairo-xlib.h>
7
8 #include "glproc.hpp"
9
10 #ifdef _WIN32
11 #  include <malloc.h> // alloca
12 #  ifndef alloca
13 #    define alloca _alloca
14 #  endif
15 #else
16 #  include <alloca.h> // alloca
17 #endif
18
19 #include "trace.hpp"
20
21 static std::map<void *, void *> g_WrappedObjects;
22
23
24 static const char * _XCreatePixmap_args[5] = {"dpy", "d", "width", "height", "depth"};
25 static const trace::FunctionSig _XCreatePixmap_sig = {2466, "XCreatePixmap", 5, _XCreatePixmap_args};
26
27 static const char * _XFreePixmap_args[2] = {"dpy", "pixmap"};
28 static const trace::FunctionSig _XFreePixmap_sig = {2467, "XFreePixmap", 2, _XFreePixmap_args};
29
30 static const char * _PutImageData_args[8] = {"drawable", "data", "width", "height", "depth", "bits_per_pixel", "bytes_per_line", "byte_order"};
31 static const trace::FunctionSig _PutImageData_sig = {2468, "PutImageData", 8, _PutImageData_args};
32
33 void
34 emit_fake_put_image_data(Display *dpy, Drawable pixmap)
35 {
36     Window root;
37     int x_ignore, y_ignore;
38     unsigned width, height, depth, border_width_ignore;
39
40     XGetGeometry(dpy, pixmap, &root, &x_ignore, &y_ignore,
41                  &width, &height, &border_width_ignore, &depth);
42
43     {
44         static int count = 0;
45         char filename[] = "image-data-X.png";
46         cairo_surface_t *surface;
47
48         surface = cairo_xlib_surface_create(dpy, pixmap, DefaultVisual(dpy, DefaultScreen(dpy)), width, height);
49
50         filename[11] = '0' + count;
51         cairo_surface_write_to_png(surface, filename);
52
53         cairo_surface_destroy(surface);
54         count++;
55     }
56
57
58     XImage *image = XGetImage(dpy, pixmap, 0, 0, width, height, AllPlanes, ZPixmap);
59     unsigned _call = trace::localWriter.beginEnter(&_PutImageData_sig);
60     trace::localWriter.beginArg(0);
61     trace::localWriter.writeUInt(pixmap);
62     trace::localWriter.endArg();
63     trace::localWriter.beginArg(1);
64     trace::localWriter.writeBlob(image->data, image->bytes_per_line * image->height);
65     trace::localWriter.endArg();
66     trace::localWriter.beginArg(2);
67     trace::localWriter.writeSInt(width);
68     trace::localWriter.endArg();
69     trace::localWriter.beginArg(3);
70     trace::localWriter.writeSInt(height);
71     trace::localWriter.endArg();
72     trace::localWriter.beginArg(4);
73     trace::localWriter.writeSInt(image->depth);
74     trace::localWriter.endArg();
75     trace::localWriter.beginArg(5);
76     trace::localWriter.writeSInt(image->bits_per_pixel);
77     trace::localWriter.endArg();
78     trace::localWriter.beginArg(6);
79     trace::localWriter.writeSInt(image->bytes_per_line);
80     trace::localWriter.endArg();
81     trace::localWriter.beginArg(7);
82     trace::localWriter.writeSInt(image->byte_order);
83     trace::localWriter.endArg();
84     trace::localWriter.endEnter();
85     trace::localWriter.beginLeave(_call);
86     trace::localWriter.endLeave();
87 }
88
89 void
90 emit_fake_x_create_pixmap(Display *dpy, Drawable pixmap)
91 {
92     Window root;
93     int x_ignore, y_ignore;
94     unsigned width, height, depth, border_width_ignore;
95     XGetGeometry(dpy, pixmap, &root, &x_ignore, &y_ignore,
96                  &width, &height, &border_width_ignore, &depth);
97     unsigned _call = trace::localWriter.beginEnter(&_XCreatePixmap_sig);
98     printf("Yes, really emitting fake XCreatePixmap (call no. %d)\n", _call);
99     trace::localWriter.beginArg(0);
100     trace::localWriter.writePointer((uintptr_t)dpy);
101     trace::localWriter.endArg();
102     trace::localWriter.beginArg(1);
103     trace::localWriter.writeUInt(root);
104     trace::localWriter.endArg();
105     trace::localWriter.beginArg(2);
106     trace::localWriter.writeUInt(width);
107     trace::localWriter.endArg();
108     trace::localWriter.beginArg(3);
109     trace::localWriter.writeUInt(height);
110     trace::localWriter.endArg();
111     trace::localWriter.beginArg(4);
112     trace::localWriter.writeUInt(depth);
113     trace::localWriter.endArg();
114     trace::localWriter.endEnter();
115     trace::localWriter.beginLeave(_call);
116     trace::localWriter.beginReturn();
117     trace::localWriter.writeUInt(pixmap);
118     trace::localWriter.endReturn();
119     trace::localWriter.endLeave();
120 }
121
122 #if 0
123 extern "C" PUBLIC
124 Pixmap XCreatePixmap(Display * dpy, Drawable d, unsigned int width, unsigned int height, unsigned int depth) {
125     Pixmap _result;
126     if (!trace::isTracingEnabled()) {
127     _result = _XCreatePixmap(dpy, d, width, height, depth);
128         return _result;
129     }
130     unsigned _call = trace::localWriter.beginEnter(&_XCreatePixmap_sig);
131     trace::localWriter.beginArg(0);
132     trace::localWriter.writePointer((uintptr_t)dpy);
133     trace::localWriter.endArg();
134     trace::localWriter.beginArg(1);
135     trace::localWriter.writeUInt(d);
136     trace::localWriter.endArg();
137     trace::localWriter.beginArg(2);
138     trace::localWriter.writeUInt(width);
139     trace::localWriter.endArg();
140     trace::localWriter.beginArg(3);
141     trace::localWriter.writeUInt(height);
142     trace::localWriter.endArg();
143     trace::localWriter.beginArg(4);
144     trace::localWriter.writeUInt(depth);
145     trace::localWriter.endArg();
146     trace::localWriter.endEnter();
147     _result = _XCreatePixmap(dpy, d, width, height, depth);
148     trace::localWriter.beginLeave(_call);
149     if (true) {
150     }
151     trace::localWriter.beginReturn();
152     trace::localWriter.writeUInt(_result);
153     trace::localWriter.endReturn();
154     trace::localWriter.endLeave();
155     return _result;
156 }
157
158 extern "C" PUBLIC
159 int XFreePixmap(Display * dpy, Drawable pixmap) {
160     int _result;
161     if (!trace::isTracingEnabled()) {
162     _result = _XFreePixmap(dpy, pixmap);
163         return _result;
164     }
165     unsigned _call = trace::localWriter.beginEnter(&_XFreePixmap_sig);
166     trace::localWriter.beginArg(0);
167     trace::localWriter.writePointer((uintptr_t)dpy);
168     trace::localWriter.endArg();
169     trace::localWriter.beginArg(1);
170     trace::localWriter.writeUInt(pixmap);
171     trace::localWriter.endArg();
172     trace::localWriter.endEnter();
173     _result = _XFreePixmap(dpy, pixmap);
174     trace::localWriter.beginLeave(_call);
175     if (true) {
176     }
177     trace::localWriter.beginReturn();
178     trace::localWriter.writeSInt(_result);
179     trace::localWriter.endReturn();
180     trace::localWriter.endLeave();
181     return _result;
182 }
183 #endif