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()]),
32 void Surface::freePixelData()
35 delete [] _pixel_data;
40 void Surface::setPixmap(const RenderColor &color)
46 XFillRectangle(**display, _pixmap, color.gc(), 0, 0,
47 _size.width(), _size.height());
49 pixel32 val = 0; // XXX set this from the color and shift amounts!
50 for (unsigned int i = 0, s = _size.width() * _size.height(); i < s; ++i) {
51 unsigned char *p = (unsigned char*)&_pixel_data[i];
52 *p = (unsigned char) (val >> 24);
53 *++p = (unsigned char) (val >> 16);
54 *++p = (unsigned char) (val >> 8);
55 *++p = (unsigned char) val;
59 void Surface::setPixmap(XImage *image)
62 assert(image->width == _size.width());
63 assert(image->height == _size.height());
68 XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
69 image, 0, 0, 0, 0, _size.width(), _size.height());
72 void Surface::createObjects()
74 assert(_pixmap == None); assert(!_xftdraw);
76 const ScreenInfo *info = display->screenInfo(_screen);
78 _pixmap = XCreatePixmap(**display, info->rootWindow(),
79 _size.width(), _size.height(), info->depth());
80 assert(_pixmap != None);
82 _xftdraw = XftDrawCreate(**display, _pixmap,
83 info->visual(), info->colormap());
87 void Surface::destroyObjects()
90 XftDrawDestroy(_xftdraw);
94 if (_pixmap != None) {
95 XFreePixmap(**display, _pixmap);