3
G_DEFINE_TYPE (WsPixmap, ws_pixmap, WS_TYPE_DRAWABLE);
5
static WsFormat ws_pixmap_get_format (WsDrawable *drawable);
6
static GObject *ws_pixmap_constructor (GType type,
7
guint n_construct_properties,
8
GObjectConstructParam *construct_params);
11
ws_pixmap_finalize (GObject *object)
13
WsPixmap *pixmap = WS_PIXMAP (object);
15
/* FIXME: Deal with foreign objects correctly */
17
g_print ("finalizing %p\n", object);
22
glXReleaseTexImageEXT (WS_RESOURCE_XDISPLAY (pixmap),
26
glXDestroyGLXPixmap (WS_RESOURCE_XDISPLAY (pixmap),
30
g_print ("deleting texture %d\n", pixmap->texture);
33
glDeleteTextures (1, &pixmap->texture);
36
g_assert (pixmap->damage);
38
XDamageDestroy (WS_RESOURCE_XDISPLAY (pixmap), pixmap->damage);
39
_ws_display_unregister_damage (WS_RESOURCE (pixmap)->display,
42
XFreePixmap (WS_RESOURCE_XDISPLAY (object),
43
WS_RESOURCE_XID (object));
45
G_OBJECT_CLASS (ws_pixmap_parent_class)->finalize (object);
49
ws_pixmap_class_init (WsPixmapClass *class)
51
GObjectClass *object_class = G_OBJECT_CLASS (class);
52
WsDrawableClass *drawable_class = WS_DRAWABLE_CLASS (class);
54
object_class->finalize = ws_pixmap_finalize;
55
object_class->constructor = ws_pixmap_constructor;
56
drawable_class->get_format = ws_pixmap_get_format;
60
repair_pixmap (WsPixmap *pixmap)
62
/* Note that it is important to clear the damage _before_
63
* updating the texture. Otherwise, we will miss any damage
64
* that arrives after updating, but before clearing.
67
XDamageSubtract (WS_RESOURCE_XDISPLAY (pixmap),
74
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, pixmap->texture);
76
ws_drawable_query_geometry (WS_DRAWABLE (pixmap), &geometry);
79
g_print ("bind size; %d %d (%d bytes)\n", geometry.width, geometry.height, geometry.width * geometry.height * 4);
82
glXBindTexImageEXT (WS_RESOURCE_XDISPLAY (pixmap),
84
GLX_FRONT_LEFT_EXT, NULL);
87
if (pixmap->damage_callback)
88
pixmap->damage_callback (pixmap, pixmap->damage_data);
92
on_damage (WsDisplay *display,
96
WsPixmap *pixmap = data;
99
g_print ("processing damage on %lx\n", WS_RESOURCE_XID (pixmap));
102
if (pixmap->do_updates)
103
repair_pixmap (pixmap);
107
ws_pixmap_get_format (WsDrawable *drawable)
109
WsPixmap *pixmap = WS_PIXMAP (drawable);
111
return pixmap->format;
115
ws_pixmap_constructor (GType type,
116
guint n_construct_properties,
117
GObjectConstructParam *construct_params)
122
object = G_OBJECT_CLASS (ws_pixmap_parent_class)->constructor (
123
type, n_construct_properties, construct_params);
125
pixmap = WS_PIXMAP (object);
127
pixmap->damage = XDamageCreate (WS_RESOURCE_XDISPLAY (pixmap),
128
WS_RESOURCE_XID (pixmap),
129
XDamageReportNonEmpty);
131
XDamageSubtract (WS_RESOURCE_XDISPLAY (pixmap),
135
g_assert (pixmap->damage);
137
_ws_display_register_damage (WS_RESOURCE (pixmap)->display,
145
ws_pixmap_init (WsPixmap *pixmap)
147
pixmap->damage_callback = NULL;
148
pixmap->damage_data = NULL;
149
pixmap->do_updates = TRUE;
153
pixmap_new (WsDisplay *display,
157
WsPixmap *pixmap = g_object_new (WS_TYPE_PIXMAP,
163
g_print ("allocating pixmap %lx\n", WS_RESOURCE_XID (pixmap));
166
pixmap->format = format;
168
g_assert (xid == WS_RESOURCE_XID (pixmap));
174
ws_pixmap_new (WsDrawable *drawable,
182
g_return_val_if_fail (WS_IS_DRAWABLE (drawable), NULL);
183
g_return_val_if_fail (
184
ws_format_is_viewable (ws_drawable_get_format (drawable)), NULL);
186
format = ws_drawable_get_format (drawable);
188
xdisplay = WS_RESOURCE_XDISPLAY (drawable);
190
pixmap = XCreatePixmap (xdisplay,
191
WS_RESOURCE_XID (drawable),
192
width, height, ws_format_get_depth (format));
194
return pixmap_new (WS_RESOURCE (drawable)->display,
199
_ws_pixmap_ensure (WsDisplay *display,
204
g_hash_table_lookup (display->xresources, (gpointer)xid);
207
pixmap = pixmap_new (display, xid, format);
213
create_glx_pixmap (WsPixmap *pixmap)
215
Display *xdisplay = WS_RESOURCE_XDISPLAY (pixmap);
216
int screen_no = WS_DRAWABLE_XSCREEN_NO (pixmap);
217
WsFormat format = ws_drawable_get_format (WS_DRAWABLE (pixmap));
218
XVisualInfo *vis_infos;
220
XVisualInfo template;
222
template.screen = screen_no;
223
template.depth = ws_format_get_depth (format);
224
template.class = TrueColor;
226
ws_format_get_masks (format,
228
&template.green_mask,
229
&template.blue_mask);
231
vis_infos = XGetVisualInfo (xdisplay,
236
VisualGreenMaskMask |
238
&template, &n_infos);
242
g_warning ("No XVisualInfos found - will likely crash");
246
/* All of the XVisualInfos returned should be ok, so just pick
250
return glXCreateGLXPixmap (
251
xdisplay, vis_infos, WS_RESOURCE_XID (pixmap));
255
ws_pixmap_get_texture (WsPixmap *pixmap)
257
g_return_val_if_fail (WS_IS_PIXMAP (pixmap), 0);
259
if (!pixmap->texture)
261
WsRectangle geometry;
262
pixmap->glx_pixmap = create_glx_pixmap (pixmap);
264
if (!pixmap->glx_pixmap)
266
g_warning ("Could not create a GLXpixmap for %lx\n",
267
WS_RESOURCE_XID (pixmap));
272
/* FIXME: at this point we are just assuming that texture from
273
* drawable is available. At some point we should reinstate the
274
* XGetImage() code. At that point configure.ac needs to be
275
* changed to not report an error.
277
glGenTextures (1, &pixmap->texture);
279
ws_drawable_query_geometry (WS_DRAWABLE (pixmap), &geometry);
282
g_print ("creating texture %d\n", pixmap->texture);
283
g_print ("size; %d %d (%d bytes)\n", geometry.width, geometry.height, geometry.width * geometry.height * 4);
286
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, pixmap->texture);
288
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
289
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
290
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
291
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
292
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP);
295
/* XXX JX experimental stuffs */
296
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
297
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
298
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_CONSTANT_ARB);
299
/* and then need to set a glColor somewhere... */
302
glXBindTexImageEXT (WS_RESOURCE_XDISPLAY (pixmap),
304
GLX_FRONT_LEFT_EXT, NULL);
307
g_print ("creating damage: %lx on %lx\n", pixmap->damage,
308
WS_RESOURCE_XID (pixmap));
312
return pixmap->texture;
316
ws_pixmap_set_damage_callback (WsPixmap *pixmap,
320
pixmap->damage_callback = cb;
321
pixmap->damage_data = data;
325
ws_pixmap_set_updates (WsPixmap *pixmap, gboolean updates)
327
pixmap->do_updates = !!updates;
329
if (pixmap->do_updates)
330
repair_pixmap (pixmap);
334
ws_pixmap_get_updates (WsPixmap *pixmap)
336
return pixmap->do_updates;