Browse Source

Various changes to writePixmap

master
Wesley Kerfoot 5 years ago
parent
commit
edc65f6def
  1. 73
      blit_xcb.c

73
blit_xcb.c

@ -13,6 +13,14 @@ typedef struct {
unsigned short b; unsigned short b;
} color_t; } color_t;
typedef struct {
xcb_point_t *points;
uint16_t width;
uint16_t height;
uint16_t x_origin;
uint16_t y_origin;
} points_t;
xcb_alloc_color_reply_t* xcb_alloc_color_reply_t*
getColorFromCmap(xcb_connection_t*, getColorFromCmap(xcb_connection_t*,
xcb_colormap_t, xcb_colormap_t,
@ -190,20 +198,24 @@ updateGCColor(xcb_connection_t *display,
values); values);
} }
xcb_point_t* points_t
genPoints(uint16_t width, genPoints(uint16_t width,
uint16_t height) { uint16_t height,
uint16_t x_offset,
uint16_t y_offset) {
/* Fills the entire screen with pixels */ /* Fills the entire screen with pixels */
xcb_point_t *points = malloc( sizeof(xcb_point_t) * height * width); xcb_point_t *points = malloc( sizeof(xcb_point_t) * height * width);
xcb_point_t point; xcb_point_t point;
points_t points_ret;
int i = 0; int i = 0;
for (uint16_t x = 0; x < width; x++) { for (uint16_t x = 0; x < width; x++) {
for(uint16_t y = 0; y < height; y++) { for(uint16_t y = 0; y < height; y++) {
point.x = x; point.x = x + x_offset;
point.y = y; point.y = y + y_offset;
points[i] = point; points[i] = point;
i++; i++;
} }
@ -211,7 +223,13 @@ genPoints(uint16_t width,
assert(i == (width*height)); assert(i == (width*height));
return points; points_ret.x_origin = x_offset;
points_ret.y_origin = y_offset;
points_ret.points = points;
points_ret.height = height;
points_ret.width = width;
return points_ret;
} }
void void
@ -219,7 +237,7 @@ displayBuffer(xcb_pixmap_t pixmap_buffer,
xcb_connection_t *display, xcb_connection_t *display,
xcb_window_t window, xcb_window_t window,
xcb_gcontext_t gc, xcb_gcontext_t gc,
xcb_expose_event_t *event) { points_t points) {
/* Note that x = 0, y = 0, is the top left of the screen */ /* Note that x = 0, y = 0, is the top left of the screen */
xcb_copy_area(display, xcb_copy_area(display,
pixmap_buffer, pixmap_buffer,
@ -227,10 +245,10 @@ displayBuffer(xcb_pixmap_t pixmap_buffer,
gc, gc,
0, /* top left x coord */ 0, /* top left x coord */
0, /* top left y coord */ 0, /* top left y coord */
event->x, /* top left x coord of dest*/ points.x_origin, /* top left x coord of dest*/
event->y, /* top left y coord of dest*/ points.y_origin, /* top left y coord of dest*/
event->width, /* pixel width of source */ points.width, /* pixel width of source */
event->height /* pixel height of source */ points.height /* pixel height of source */
); );
xcb_flush(display); xcb_flush(display);
@ -240,11 +258,10 @@ void
writePixmap(xcb_pixmap_t pixmap_buffer, writePixmap(xcb_pixmap_t pixmap_buffer,
color_t color, color_t color,
xcb_colormap_t colormap, xcb_colormap_t colormap,
xcb_point_t *points, points_t points,
xcb_gcontext_t gc, xcb_gcontext_t gc,
xcb_connection_t *display, xcb_connection_t *display,
xcb_window_t window, xcb_window_t window) {
xcb_expose_event_t *event) {
printf("Drawing pixmap\nr = %u, g = %u, b = %u\n", color.r, color.g, color.b); printf("Drawing pixmap\nr = %u, g = %u, b = %u\n", color.r, color.g, color.b);
updateGCColor(display, updateGCColor(display,
@ -256,14 +273,14 @@ writePixmap(xcb_pixmap_t pixmap_buffer,
XCB_COORD_MODE_ORIGIN, /* Coordinate mode, usually set to XCB_COORD_MODE_ORIGIN */ XCB_COORD_MODE_ORIGIN, /* Coordinate mode, usually set to XCB_COORD_MODE_ORIGIN */
pixmap_buffer, pixmap_buffer,
gc, gc,
event->width*event->height, points.width*points.height,
points); points.points);
displayBuffer(pixmap_buffer, displayBuffer(pixmap_buffer,
display, display,
window, window,
gc, gc,
event); points);
} }
@ -347,6 +364,11 @@ main(void) {
int was_exposed = 0; int was_exposed = 0;
int side = 0;
points_t points;
uint16_t x_offset = 0;
uint16_t y_offset = 0;
while (1) { while (1) {
event = xcb_poll_for_event(display); event = xcb_poll_for_event(display);
@ -357,25 +379,28 @@ main(void) {
case XCB_EXPOSE: { case XCB_EXPOSE: {
expose = (xcb_expose_event_t *)event; expose = (xcb_expose_event_t *)event;
window_width = expose->width; window_width = expose->width;
window_height = expose->height; window_height = expose->height;
printf("Window %u exposed. Region to be redrawn at location (%u,%u), with dimension (%u,%u)\n", printf("Window %u exposed. Region to be redrawn at location (%u,%u), with dimension (%u,%u)\n",
expose->window, expose->x, expose->window, expose->x,
expose->y, expose->y,
expose->width, expose->width,
expose->height); expose->height);
xcb_point_t *points = genPoints(window_width, window_height); points = genPoints(window_width/2, window_height/2, x_offset, y_offset++);
writePixmap(pixmap_buffer, writePixmap(pixmap_buffer,
draw_color, draw_color,
colormap, colormap,
points, points,
gc, gc,
display, display,
window, window);
expose);
was_exposed = 1; was_exposed = 1;
free(points); free(points.points);
break; break;
} }
@ -389,7 +414,7 @@ main(void) {
} }
} }
if (was_exposed) { if (was_exposed) {
xcb_point_t *points = genPoints(window_width, window_height); points = genPoints(window_width/2, window_height/2, x_offset, y_offset++);
writePixmap(pixmap_buffer, writePixmap(pixmap_buffer,
draw_color, draw_color,
@ -397,16 +422,14 @@ main(void) {
points, points,
gc, gc,
display, display,
window, window);
expose);
free(points); free(points.points);
} }
draw_color.r += 100; draw_color.r += 100;
draw_color.g -= 100; draw_color.g -= 100;
/* General strategy for writing to buffer /* General strategy for writing to buffer
* Function should take point(s), color, and write it * Function should take point(s), color, and write it
*/ */

Loading…
Cancel
Save