1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
7 #include "screeninfo.hh"
8 #include "rendercolor.hh"
11 #include <X11/Xutil.h>
17 Surface::Surface(int screen, const Size &size)
20 _pixel_data(new pixel32[size.width()*size.height()]),
29 delete [] _pixel_data;
32 void Surface::setPixmap(const RenderColor &color)
37 XFillRectangle(**display, _pixmap, color.gc(), 0, 0,
38 _size.width(), _size.height());
40 pixel32 val = 0; // XXX set this from the color and shift amounts!
41 for (unsigned int i = 0, s = _size.width() * _size.height(); i < s; ++i) {
42 unsigned char *p = (unsigned char*)&_pixel_data[i];
43 *p = (unsigned char) (val >> 24);
44 *++p = (unsigned char) (val >> 16);
45 *++p = (unsigned char) (val >> 8);
46 *++p = (unsigned char) val;
50 void Surface::setPixmap(XImage *image)
52 assert(image->width == _size.width());
53 assert(image->height == _size.height());
58 XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
59 image, 0, 0, 0, 0, _size.width(), _size.height());
62 void Surface::createObjects()
64 assert(_pixmap == None); assert(!_xftdraw);
66 const ScreenInfo *info = display->screenInfo(_screen);
68 _pixmap = XCreatePixmap(**display, info->rootWindow(),
69 _size.width(), _size.height(), info->depth());
70 assert(_pixmap != None);
72 _xftdraw = XftDrawCreate(**display, _pixmap,
73 info->visual(), info->colormap());
77 void Surface::destroyObjects()
80 XftDrawDestroy(_xftdraw);
84 if (_pixmap != None) {
85 XFreePixmap(**display, _pixmap);