canvas_x11.cpp 2.03 KB
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;
}