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 = (color.red() << default_red_shift) |
50 (color.green() << default_green_shift) |
51 (color.blue() << default_blue_shift);
52 for (unsigned int i = 0, s = _size.width() * _size.height(); i < s; ++i)
56 void Surface::setPixmap(XImage *image)
59 assert(image->width == _size.width());
60 assert(image->height == _size.height());
65 XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
66 image, 0, 0, 0, 0, _size.width(), _size.height());
69 void Surface::createObjects()
71 assert(_pixmap == None); assert(!_xftdraw);
73 const ScreenInfo *info = display->screenInfo(_screen);
75 _pixmap = XCreatePixmap(**display, info->rootWindow(),
76 _size.width(), _size.height(), info->depth());
77 assert(_pixmap != None);
79 _xftdraw = XftDrawCreate(**display, _pixmap,
80 info->visual(), info->colormap());
84 void Surface::destroyObjects()
87 XftDrawDestroy(_xftdraw);
91 if (_pixmap != None) {
92 XFreePixmap(**display, _pixmap);