]> Dogcows Code - chaz/openbox/blob - otk/surface.cc
set the log domain for each plugin properly
[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 #include <cstring>
13 }
14
15 namespace otk {
16
17 Surface::Surface(int screen, const Size &size)
18 : _screen(screen),
19 _size(size),
20 _pixel_data(new pixel32[size.width()*size.height()]),
21 _pixmap(None),
22 _xftdraw(0)
23 {
24 }
25
26 Surface::~Surface()
27 {
28 destroyObjects();
29 freePixelData();
30 }
31
32 void Surface::freePixelData()
33 {
34 if (_pixel_data) {
35 delete [] _pixel_data;
36 _pixel_data = 0;
37 }
38 }
39
40 void Surface::setPixmap(const RenderColor &color)
41 {
42 assert(_pixel_data);
43 if (_pixmap == None)
44 createObjects();
45
46 XFillRectangle(**display, _pixmap, color.gc(), 0, 0,
47 _size.width(), _size.height());
48
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)
53 _pixel_data[i] = val;
54 }
55
56 void Surface::setPixmap(XImage *image)
57 {
58 assert(_pixel_data);
59 assert(image->width == _size.width());
60 assert(image->height == _size.height());
61
62 if (_pixmap == None)
63 createObjects();
64
65 XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
66 image, 0, 0, 0, 0, _size.width(), _size.height());
67 }
68
69 void Surface::createObjects()
70 {
71 assert(_pixmap == None); assert(!_xftdraw);
72
73 const ScreenInfo *info = display->screenInfo(_screen);
74
75 _pixmap = XCreatePixmap(**display, info->rootWindow(),
76 _size.width(), _size.height(), info->depth());
77 assert(_pixmap != None);
78
79 _xftdraw = XftDrawCreate(**display, _pixmap,
80 info->visual(), info->colormap());
81 assert(_xftdraw);
82 }
83
84 void Surface::destroyObjects()
85 {
86 if (_xftdraw) {
87 XftDrawDestroy(_xftdraw);
88 _xftdraw = 0;
89 }
90
91 if (_pixmap != None) {
92 XFreePixmap(**display, _pixmap);
93 _pixmap = None;
94 }
95 }
96
97 }
This page took 0.037666 seconds and 4 git commands to generate.