[Xcb] Only blurred content, when i draw on pixmap
Moritz Bruder
shortcut.mb at web.de
Mon Jan 25 08:28:50 PST 2010
Hi,
I only get blurred content when I draw on a pixmap and copy it on a
window, can someone tell me why or what I am doing wrong? (When drawing
with cairo and only with x the same behaviour appears)
#include <xcb/xcb.h>
#include <cairo/cairo-xcb.h>
#include <unistd.h>
#include <iostream>
int main()
{
xcb_connection_t * c = xcb_connect(0, 0);
xcb_screen_t * screen =
xcb_setup_roots_iterator(xcb_get_setup(c)).data;
xcb_window_t w = xcb_generate_id(c);
uint32_t values[2] = { screen->white_pixel, XCB_EVENT_MASK_EXPOSURE
| XCB_EVENT_MASK_BUTTON_PRESS };
xcb_create_window(c, XCB_COPY_FROM_PARENT , w, screen->root, 0, 0,
400, 300, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual, XCB_CW_BACK_PIXEL |
XCB_CW_EVENT_MASK, values);
xcb_pixmap_t window_pixmap = xcb_generate_id(c);
xcb_create_pixmap(c, screen->root_depth, window_pixmap,
screen->root, 400, 300);
xcb_gcontext_t gc = xcb_generate_id(c);
uint32_t attributes[2] = { screen->black_pixel,
screen->white_pixel };
xcb_create_gc(c, gc, window_pixmap, XCB_GC_FOREGROUND |
XCB_GC_BACKGROUND, attributes);
cairo_surface_t * window_surface;
window_surface = cairo_xcb_surface_create_for_bitmap(c,
window_pixmap, screen, 400, 300);
if (!window_surface)
{
std::cerr << "error creating xcb surface" << std::endl;
}
cairo_t * cr = cairo_create(window_surface);
xcb_map_window(c, w);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_move_to(cr, 0, 0);
cairo_line_to(cr, 1, 1);
cairo_move_to(cr, 1, 0);
cairo_line_to(cr, 0, 1);
cairo_set_line_width(cr, 0.2);
cairo_stroke(cr);
cairo_surface_flush(window_surface);
xcb_flush(c);
xcb_generic_event_t * event;
bool go_on = true;
while (go_on && (event = xcb_wait_for_event(c)))
{
switch(event->response_type & ~0x80)
{
case XCB_BUTTON_PRESS:
{
go_on = false;
}
break;
case XCB_EXPOSE:
{
xcb_expose_event_t * expose_event =
reinterpret_cast<xcb_expose_event_t *>(event);
std::cout << "drawing again" << std::endl;
xcb_copy_area(c, window_pixmap, w, gc, expose_event->x,
expose_event->y, expose_event->x, expose_event->y,expose_event->width,
expose_event->height);
xcb_flush(c);
}
}
}
xcb_free_pixmap(c, window_pixmap);
xcb_disconnect(c);
cairo_destroy(cr);
}
More information about the Xcb
mailing list