window – 如何在xcb中使用shm pixmap?
发布时间:2020-12-14 01:57:14 所属栏目:Windows 来源:网络整理
导读:我尝试学习如何在xcb库中使用共享内存pixmaps.您是否有过这方面的经验并希望分享示例代码和/或信息?这将非常有帮助. 谢谢 解决方法 经过一些研究,我发现了如何在xcb中使用共享内存pixmaps. 这是我的测试代码: #include stdlib.h#include stdio.h#include s
我尝试学习如何在xcb库中使用共享内存pixmaps.您是否有过这方面的经验并希望分享示例代码和/或信息?这将非常有帮助.
谢谢 解决方法
经过一些研究,我发现了如何在xcb中使用共享内存pixmaps.
这是我的测试代码: #include <stdlib.h> #include <stdio.h> #include <sys/ipc.h> #include <sys/shm.h> #include <xcb/xcb.h> #include <xcb/shm.h> #include <xcb/xcb_image.h> #define WID 512 #define HEI 512 int main(){ xcb_connection_t* connection; xcb_window_t window; xcb_screen_t* screen; xcb_gcontext_t gcontext; xcb_generic_event_t* event; uint32_t value_mask; uint32_t value_list[2]; //connect to the X server and get screen connection = xcb_connect(NULL,NULL); screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data; //create a window value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; value_list[0] = screen->black_pixel; value_list[1] = XCB_EVENT_MASK_EXPOSURE; window = xcb_generate_id(connection); xcb_create_window( connection,screen->root_depth,window,screen->root,WID,HEI,XCB_WINDOW_CLASS_INPUT_OUTPUT,screen->root_visual,value_mask,value_list ); //create a graphic context value_mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; value_list[0] = screen->black_pixel; value_list[1] = 0; gcontext = xcb_generate_id(connection); xcb_create_gc(connection,gcontext,value_list); //map the window onto the screen xcb_map_window(connection,window); xcb_flush(connection); //Shm test xcb_shm_query_version_reply_t* reply; xcb_shm_segment_info_t info; reply = xcb_shm_query_version_reply( connection,xcb_shm_query_version(connection),NULL ); if(!reply || !reply->shared_pixmaps){ printf("Shm error...n"); exit(0); } info.shmid = shmget(IPC_PRIVATE,WID*HEI*4,IPC_CREAT | 0777); info.shmaddr = shmat(info.shmid,0); info.shmseg = xcb_generate_id(connection); xcb_shm_attach(connection,info.shmseg,info.shmid,0); shmctl(info.shmid,IPC_RMID,0); uint32_t* data = info.shmaddr; xcb_pixmap_t pix = xcb_generate_id(connection); xcb_shm_create_pixmap( connection,pix,0 ); int i = 0; while(1){ usleep(10000); data[i] = 0xFFFFFF; i++; xcb_copy_area( connection,HEI ); xcb_flush(connection); } xcb_shm_detach(connection,info.shmseg); shmdt(info.shmaddr); xcb_free_pixmap(connection,pix); xcb_destroy_window(connection,window); xcb_disconnect(connection); return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- hyper-v – 个人虚拟桌面集:用户分配
- Windows+R快捷键
- ssh – 如何将文件从Bluemix上的Liberty文件复制到Windows?
- windows – 重命名文件的脚本
- windows-server-2008 – IIS SMTP服务器是否足以满足生产服
- Windows API一日一练 31 MoveToEx和LineTo函数
- 如何在Windows域中确定用户帐户的OU?
- Windows上的PHP错误日志文件格式(php.ini error_log指令)
- 当用户更改密码时,Windows计划任务失败的解决方法
- windows-server-2012 – 如何通过Windows Server 2012中的终
推荐文章
站长推荐
热点阅读