canvas_x11.cpp
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using namespace std;
#include <cstdlib>
#include "canvas_x11.h"
#include "../canvas_imps/canvas_imp_rgb.h"
canvas_x11::canvas_x11(unsigned xs, unsigned ys) : canvas(xs, ys) {
disp=new xdisplay();
scr=disp->defaultscreen();
win=new xwindow(scr->getrootwin(), 100, 100, 1, x_size, y_size);
win->map();
switch(scr->getvisual()->c_class) {
XVisualInfo vi;
int result;
case TrueColor:
result=XMatchVisualInfo(disp->getdisplay(), disp->defaultscreenid(),
scr->getdepth(), TrueColor, &vi);
if(result)
sinfo=new canvas_imp_rgb(scr->getvisual()->red_mask,
scr->getvisual()->green_mask,
scr->getvisual()->blue_mask,
scr->getbytespp(), vi.depth/8);
else {
exit(EXIT_FAILURE);
}
break;
case PseudoColor:
case StaticColor:
case GrayScale:
case StaticGray:
case DirectColor:
exit(EXIT_FAILURE);
}
sinfo->p_screenbuf=new unsigned char[x_size*y_size*scr->getbytespp()];
ximg=XCreateImage(disp->getdisplay(), scr->getvisual(), scr->getdepth(),
ZPixmap, 0, (char*)sinfo->p_screenbuf,
x_size, y_size, scr->getscanlinepad(), 0);
}
canvas_x11::~canvas_x11() {
delete sinfo;
if(ximg) {
XDestroyImage(ximg);
ximg=NULL;
}
delete disp;
}
void canvas_x11::create_buffer(void) {
// wenn ich factorys habe sollte ich irgendwie das buffer erzeugen
// auslagern, da ich bei shm den buffer aus dem ximg erzeuge und
// ansonsten andersherum, sonst hab ich noch keine rechte idee wie
// ich das konsistent bewerkstelligen kann...
}
void canvas_x11::blit_screen(void) {
while(blit != NO_BLIT) {}
blit=BLIT;
XPutImage(disp->getdisplay(), win->getwindow(), scr->getgc(),
ximg, 0,0,0,0, x_size, y_size);
blit=NO_BLIT;
}