test_xcb_image_shm.c | test_xcb_image_shm.c | |||
---|---|---|---|---|
#include <stdlib.h> | #include <stdlib.h> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <sys/ipc.h> | #include <sys/ipc.h> | |||
#include <sys/shm.h> | #include <sys/shm.h> | |||
#include <xcb/xcb.h> | #include <xcb/xcb.h> | |||
#include <xcb/shm.h> | #include <xcb/shm.h> | |||
#include "xcb_aux.h" | #include "../aux/xcb_aux.h" | |||
#include "xcb_image.h" | #include "xcb_image.h" | |||
#define W_W 40 | #define W_W 40 | |||
#define W_H 40 | #define W_H 40 | |||
int | int | |||
main (int argc, char *argv[]) | main (int argc, char *argv[]) | |||
{ | { | |||
xcb_connection_t *c; | xcb_connection_t *c; | |||
xcb_screen_t *screen; | xcb_screen_t *screen; | |||
skipping to change at line 32 | skipping to change at line 32 | |||
xcb_drawable_t rect; | xcb_drawable_t rect; | |||
xcb_rectangle_t rect_coord = { 0, 0, W_W, W_H}; | xcb_rectangle_t rect_coord = { 0, 0, W_W, W_H}; | |||
xcb_gcontext_t bgcolor, fgcolor; | xcb_gcontext_t bgcolor, fgcolor; | |||
xcb_point_t points[2]; | xcb_point_t points[2]; | |||
uint32_t mask; | uint32_t mask; | |||
uint32_t valgc[2]; | uint32_t valgc[2]; | |||
uint32_t valwin[3]; | uint32_t valwin[3]; | |||
int depth; | int depth; | |||
int screen_nbr; | int screen_nbr; | |||
xcb_generic_event_t *e; | xcb_generic_event_t *e; | |||
uint8_t format; | ||||
/* Open the connexion to the X server and get the first screen */ | /* Open the connexion to the X server and get the first screen */ | |||
c = xcb_connect (NULL, &screen_nbr); | c = xcb_connect (NULL, &screen_nbr); | |||
screen = xcb_aux_get_screen (c, screen_nbr); | screen = xcb_aux_get_screen (c, screen_nbr); | |||
depth = xcb_aux_get_depth (c, screen); | depth = xcb_aux_get_depth (c, screen); | |||
/* Create a black graphic context for drawing in the foreground */ | /* Create a black graphic context for drawing in the foreground */ | |||
win = screen->root; | win = screen->root; | |||
fgcolor = xcb_generate_id(c); | fgcolor = xcb_generate_id(c); | |||
skipping to change at line 62 | skipping to change at line 63 | |||
/* Shm test */ | /* Shm test */ | |||
printf ("shm test begin\n"); | printf ("shm test begin\n"); | |||
xcb_image_t *img = 0; | xcb_image_t *img = 0; | |||
xcb_shm_query_version_reply_t *rep; | xcb_shm_query_version_reply_t *rep; | |||
xcb_shm_segment_info_t shminfo; | xcb_shm_segment_info_t shminfo; | |||
rep = xcb_shm_query_version_reply (c, | rep = xcb_shm_query_version_reply (c, | |||
xcb_shm_query_version (c), | xcb_shm_query_version (c), | |||
NULL); | NULL); | |||
if (rep) | if (!rep || !rep->shared_pixmaps || | |||
{ | rep->major_version < 1 || | |||
uint8_t format; | (rep->major_version == 1 && rep->minor_version == 0)) | |||
{ | ||||
if (rep->shared_pixmaps && | printf ("No or insufficient shm support...\n"); | |||
(rep->major_version > 1 || rep->minor_version > 0)) | exit (0); | |||
format = rep->pixmap_format; | } | |||
else | format = rep->pixmap_format; | |||
format = 0; | img = xcb_image_create_native (c, W_W, W_H, format, depth, | |||
img = xcb_image_shm_create (c, depth, format, NULL, W_W, W_H); | 0, ~0, 0); | |||
printf ("Create image summary:\n"); | ||||
printf (" * format..........: %d\n", img->format); | ||||
printf (" * byte order......: %d\n", img->image_byte_order); | ||||
printf (" * bitmap unit.....: %d\n", img->bitmap_format_scanline_unit | ||||
); | ||||
printf (" * bitmap order....: %d\n", img->bitmap_format_bit_order); | ||||
printf (" * bitmap pad......: %d\n", img->bitmap_format_scanline_pad) | ||||
; | ||||
shminfo.shmid = shmget (IPC_PRIVATE, | ||||
img->bytes_per_line*img->height, | ||||
IPC_CREAT|0777); | ||||
shminfo.shmaddr = shmat(shminfo.shmid, 0, 0); | ||||
img->data = shminfo.shmaddr; | ||||
shminfo.shmseg = xcb_generate_id (c); | ||||
xcb_shm_attach(c, shminfo.shmseg, | ||||
shminfo.shmid, 0); | ||||
shmctl(shminfo.shmid, IPC_RMID, 0); | ||||
} | ||||
if (!img) | if (!img) | |||
{ | { | |||
printf ("Can't use shm...\n"); | printf ("Can't create image...\n"); | |||
exit (0); | exit (0); | |||
} | } | |||
printf ("Create image summary:\n"); | ||||
printf (" * format..........: %d\n", img->format); | ||||
printf (" * byte order......: %d\n", img->byte_order); | ||||
printf (" * bitmap unit.....: %d\n", img->bpp); | ||||
printf (" * bitmap order....: %d\n", img->bit_order); | ||||
printf (" * bitmap pad......: %d\n", img->scanline_pad); | ||||
shminfo.shmid = shmget (IPC_PRIVATE, img->size, IPC_CREAT|0777); | ||||
shminfo.shmaddr = shmat(shminfo.shmid, 0, 0); | ||||
img->data = shminfo.shmaddr; | ||||
shminfo.shmseg = xcb_generate_id (c); | ||||
xcb_shm_attach(c, shminfo.shmseg, shminfo.shmid, 0); | ||||
shmctl(shminfo.shmid, IPC_RMID, 0); | ||||
/* Draw in the image */ | /* Draw in the image */ | |||
printf ("put the pixel\n"); | printf ("put the pixel\n"); | |||
xcb_image_put_pixel (img, 20, 20, 65535); | xcb_image_put_pixel (img, 20, 20, 65535); | |||
printf ("fin put pixel\n"); | printf ("fin put pixel\n"); | |||
/* Ask for our window's Id */ | /* Ask for our window's Id */ | |||
win = xcb_generate_id(c); | win = xcb_generate_id(c); | |||
/* Create the window */ | /* Create the window */ | |||
skipping to change at line 134 | skipping to change at line 131 | |||
/* Create a Pixmap that will fill the window */ | /* Create a Pixmap that will fill the window */ | |||
rect = xcb_generate_id (c); | rect = xcb_generate_id (c); | |||
xcb_create_pixmap(c, depth, rect, win, W_W, W_H); | xcb_create_pixmap(c, depth, rect, win, W_W, W_H); | |||
xcb_poly_fill_rectangle(c, rect, bgcolor, 1, &rect_coord); | xcb_poly_fill_rectangle(c, rect, bgcolor, 1, &rect_coord); | |||
points[0].x = 0; | points[0].x = 0; | |||
points[0].y = 0; | points[0].y = 0; | |||
points[1].x = 1; | points[1].x = 1; | |||
points[1].y = 1; | points[1].y = 1; | |||
xcb_poly_line(c, XCB_COORD_MODE_ORIGIN, rect, fgcolor, 2, points); | xcb_poly_line(c, XCB_COORD_MODE_ORIGIN, rect, fgcolor, 2, points); | |||
/* points[0].x = 10; */ | ||||
/* points[0].y = 10; */ | ||||
/* points[1].x = 10; */ | ||||
/* points[1].y = 40; */ | ||||
/* xcb_poly_line(c, XCB_COORD_MODE_ORIGIN, rect, fgcolor, 2, points); */ | ||||
xcb_flush (c); | xcb_flush (c); | |||
while ((e = xcb_wait_for_event(c))) | while ((e = xcb_wait_for_event(c))) | |||
{ | { | |||
switch (e->response_type) | switch (e->response_type) | |||
{ | { | |||
case XCB_EXPOSE: | case XCB_EXPOSE: | |||
{ | { | |||
xcb_copy_area(c, rect, win, bgcolor, | xcb_copy_area(c, rect, win, bgcolor, | |||
End of changes. 5 change blocks. | ||||
41 lines changed or deleted | 31 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |