]> Dogcows Code - chaz/openbox/blob - otk/surface.cc
remove unused apply
[chaz/openbox] / otk / surface.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #include "config.h"
4
5 #include "surface.hh"
6 #include "display.hh"
7 #include "screeninfo.hh"
8 #include "rendercolor.hh"
9
10 extern "C" {
11 #include <X11/Xutil.h>
12 }
13
14 namespace otk {
15
16 Surface::Surface(int screen, const Size &size)
17 : _screen(screen),
18 _size(size),
19 _pixmap(None),
20 _xftdraw(0)
21 {
22 }
23
24 Surface::~Surface()
25 {
26 destroyObjects();
27 }
28
29 void Surface::setPixmap(const RenderColor &color)
30 {
31 if (_pixmap == None)
32 createObjects();
33
34 XFillRectangle(**display, _pixmap, color.gc(), 0, 0,
35 _size.width(), _size.height());
36 }
37
38 void Surface::setPixmap(XImage *image)
39 {
40 assert(image->width == _size.width());
41 assert(image->height == _size.height());
42
43 if (_pixmap == None)
44 createObjects();
45
46 XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
47 image, 0, 0, 0, 0, _size.width(), _size.height());
48 }
49
50 void Surface::createObjects()
51 {
52 assert(_pixmap == None); assert(!_xftdraw);
53
54 const ScreenInfo *info = display->screenInfo(_screen);
55
56 _pixmap = XCreatePixmap(**display, info->rootWindow(),
57 _size.width(), _size.height(), info->depth());
58 assert(_pixmap != None);
59
60 _xftdraw = XftDrawCreate(**display, _pixmap,
61 info->visual(), info->colormap());
62 assert(_xftdraw);
63 }
64
65 void Surface::destroyObjects()
66 {
67 if (_xftdraw) {
68 XftDrawDestroy(_xftdraw);
69 _xftdraw = 0;
70 }
71
72 if (_pixmap != None) {
73 XFreePixmap(**display, _pixmap);
74 _pixmap = None;
75 }
76 }
77
78 }
This page took 0.036408 seconds and 4 git commands to generate.