Skip to content

Commit

Permalink
Shared memory background
Browse files Browse the repository at this point in the history
  • Loading branch information
jaelpark committed Feb 24, 2019
1 parent 5cebac5 commit 5faaa1c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,10 +991,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL CompositorInterface::ValidationLayerDebugCallback
return VK_FALSE;
}

X11ClientFrame::X11ClientFrame(WManager::Container *pcontainer, const Backend::X11Client::CreateInfo *_pcreateInfo, const char *_pshaderName[Pipeline::SHADER_MODULE_COUNT], CompositorInterface *_pcomp) : X11Client(pcontainer,_pcreateInfo), ClientFrame(rect.w,rect.h,_pshaderName,_pcomp){// : ClientFrame(_pcomp), X11Client(_pcreateInfo){
//
//xcb_composite_redirect_subwindows(pbackend->pcon,window,XCB_COMPOSITE_REDIRECT_MANUAL);
//xcb_composite_redirect_window(pbackend->pcon,window,XCB_COMPOSITE_REDIRECT_MANUAL);
X11ClientFrame::X11ClientFrame(WManager::Container *pcontainer, const Backend::X11Client::CreateInfo *_pcreateInfo, const char *_pshaderName[Pipeline::SHADER_MODULE_COUNT], CompositorInterface *_pcomp) : X11Client(pcontainer,_pcreateInfo), ClientFrame(rect.w,rect.h,_pshaderName,_pcomp){
xcb_composite_redirect_window(pbackend->pcon,window,XCB_COMPOSITE_REDIRECT_AUTOMATIC);

windowPixmap = xcb_generate_id(pbackend->pcon);
Expand All @@ -1004,7 +1001,6 @@ X11ClientFrame::X11ClientFrame(WManager::Container *pcontainer, const Backend::X

damage = xcb_generate_id(pbackend->pcon);
xcb_damage_create(pbackend->pcon,damage,window,XCB_DAMAGE_REPORT_LEVEL_RAW_RECTANGLES);
//xcb_damage_create(pbackend->pcon,damage,window,XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY);
}

X11ClientFrame::~X11ClientFrame(){
Expand Down Expand Up @@ -1111,6 +1107,7 @@ void X11ClientFrame::AdjustSurface1(){

X11Background::X11Background(xcb_pixmap_t _pixmap, uint _w, uint _h, const char *_pshaderName[Pipeline::SHADER_MODULE_COUNT], X11Compositor *_pcomp) : w(_w), h(_h), ClientFrame(_w,_h,_pshaderName,_pcomp), pcomp11(_pcomp), pixmap(_pixmap){
//
segment = xcb_generate_id(pcomp11->pbackend->pcon);
}

X11Background::~X11Background(){
Expand All @@ -1121,26 +1118,51 @@ void X11Background::UpdateContents(const VkCommandBuffer *pcommandBuffer){
if(!fullRegionUpdate)
return;
//
xcb_get_image_cookie_t imageCookie = xcb_get_image_unchecked(pcomp11->pbackend->pcon,XCB_IMAGE_FORMAT_Z_PIXMAP,pixmap,0,0,w,h,~0);
/*xcb_get_image_cookie_t imageCookie = xcb_get_image_unchecked(pcomp11->pbackend->pcon,XCB_IMAGE_FORMAT_Z_PIXMAP,pixmap,0,0,w,h,~0);
xcb_get_image_reply_t *pimageReply = xcb_get_image_reply(pcomp11->pbackend->pcon,imageCookie,0);
if(!pimageReply){
DebugPrintf(stderr,"Failed to receive image reply.\n");
return;
}
unsigned char *pchpixels = xcb_get_image_data(pimageReply);
unsigned char *pdata = (unsigned char *)ptexture->Map();
unsigned char *pchpixels = xcb_get_image_data(pimageReply);*/

sint shmid = shmget(IPC_PRIVATE,w*h*4,IPC_CREAT|0777);
if(shmid == -1){
DebugPrintf(stderr,"Failed to allocate shared memory.\n");
return;
}

xcb_shm_attach(pcomp11->pbackend->pcon,segment,shmid,0);
xcb_shm_get_image_cookie_t imageCookie = xcb_shm_get_image(pcomp11->pbackend->pcon,pixmap,0,0,w,h,~0,XCB_IMAGE_FORMAT_Z_PIXMAP,segment,0);
xcb_shm_detach(pcomp11->pbackend->pcon,segment);

xcb_shm_get_image_reply_t *pimageReply = xcb_shm_get_image_reply(pcomp11->pbackend->pcon,imageCookie,0);
xcb_flush(pcomp11->pbackend->pcon);

if(!pimageReply){
shmctl(shmid,IPC_RMID,0);
DebugPrintf(stderr,"No shared memory.\n");
return;
}

uint depth = pimageReply->depth;
free(pimageReply);

unsigned char *pchpixels = (unsigned char*)shmat(shmid,0,0);
shmctl(shmid,IPC_RMID,0);

unsigned char *pdata = (unsigned char *)ptexture->Map();
memcpy(pdata,pchpixels,w*h*4);
if(pimageReply->depth != 32)
if(depth != 32)
for(uint i = 0; i < w*h; ++i)
pdata[4*i+3] = 255;
fullRegionUpdate = false;

VkRect2D rect1 = {0,0,w,h};
ptexture->Unmap(pcommandBuffer,&rect1,1);

free(pimageReply);
shmdt(pchpixels);
}

X11Compositor::X11Compositor(uint physicalDevIndex, const Backend::X11Backend *_pbackend) : CompositorInterface(physicalDevIndex), pbackend(_pbackend){//, pbackground(0){
Expand Down
1 change: 1 addition & 0 deletions src/compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class X11Background : public ClientFrame{

X11Compositor *pcomp11;
xcb_pixmap_t pixmap;
xcb_shm_seg_t segment;
uint w, h;
};

Expand Down

0 comments on commit 5faaa1c

Please sign in to comment.