mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 06:32:48 +00:00
xshm: Allow to operate without shm extension
In most cases it doesn't make a nice gameplay but is still useful for debugging on remote system and xnest
This commit is contained in:
parent
c4b4961ed1
commit
62bb1d4da4
@ -33,15 +33,16 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../../configuration.h"
|
#include "../../configuration.h"
|
||||||
|
|
||||||
#include "../font_driver.h"
|
#include "../font_driver.h"
|
||||||
|
|
||||||
#include "../common/x11_common.h"
|
#include "../common/x11_common.h"
|
||||||
|
#include "../../verbosity.h"
|
||||||
|
|
||||||
typedef struct xshm
|
typedef struct xshm
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
|
bool use_shm;
|
||||||
|
uint8_t *fbptr;
|
||||||
|
|
||||||
XShmSegmentInfo shmInfo;
|
XShmSegmentInfo shmInfo;
|
||||||
XImage* image;
|
XImage* image;
|
||||||
@ -58,6 +59,14 @@ static void *xshm_gfx_init(const video_info_t *video,
|
|||||||
|
|
||||||
g_x11_dpy = XOpenDisplay(NULL);
|
g_x11_dpy = XOpenDisplay(NULL);
|
||||||
|
|
||||||
|
xshm->use_shm = true;
|
||||||
|
|
||||||
|
if (!XShmQueryExtension(g_x11_dpy))
|
||||||
|
{
|
||||||
|
RARCH_LOG("[X11]: XShm extension not found.\n");
|
||||||
|
xshm->use_shm = false;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef RARCH_INTERNAL
|
#ifdef RARCH_INTERNAL
|
||||||
parent = DefaultRootWindow(g_x11_dpy);
|
parent = DefaultRootWindow(g_x11_dpy);
|
||||||
#else
|
#else
|
||||||
@ -71,16 +80,28 @@ static void *xshm_gfx_init(const video_info_t *video,
|
|||||||
XSetWindowBackground(g_x11_dpy, g_x11_win, 0);
|
XSetWindowBackground(g_x11_dpy, g_x11_win, 0);
|
||||||
XMapWindow(g_x11_dpy, g_x11_win);
|
XMapWindow(g_x11_dpy, g_x11_win);
|
||||||
|
|
||||||
xshm->shmInfo.shmid = shmget(IPC_PRIVATE, sizeof(uint32_t) * video->width * video->height,
|
if (xshm->use_shm)
|
||||||
IPC_CREAT|0600);
|
{
|
||||||
if (xshm->shmInfo.shmid<0) abort();//seems like an out of memory situation... let's just blow up
|
xshm->shmInfo.shmid = shmget(IPC_PRIVATE, sizeof(uint32_t) * video->width * video->height,
|
||||||
|
IPC_CREAT|0600);
|
||||||
|
if (xshm->shmInfo.shmid<0) abort();//seems like an out of memory situation... let's just blow up
|
||||||
|
|
||||||
xshm->shmInfo.shmaddr = (char*)shmat(xshm->shmInfo.shmid, 0, 0);
|
xshm->shmInfo.shmaddr = (char*)shmat(xshm->shmInfo.shmid, 0, 0);
|
||||||
xshm->shmInfo.readOnly = False;
|
xshm->shmInfo.readOnly = False;
|
||||||
XShmAttach(g_x11_dpy, &xshm->shmInfo);
|
XShmAttach(g_x11_dpy, &xshm->shmInfo);
|
||||||
XSync(g_x11_dpy, False);//no idea why this is required, but I get weird errors without it
|
XSync(g_x11_dpy, False);//no idea why this is required, but I get weird errors without it
|
||||||
xshm->image = XShmCreateImage(g_x11_dpy, NULL, 24, ZPixmap,
|
xshm->image = XShmCreateImage(g_x11_dpy, NULL, 24, ZPixmap,
|
||||||
xshm->shmInfo.shmaddr, &xshm->shmInfo, video->width, video->height);
|
xshm->shmInfo.shmaddr, &xshm->shmInfo, video->width, video->height);
|
||||||
|
xshm->fbptr = (uint8_t*)xshm->shmInfo.shmaddr;
|
||||||
|
} else {
|
||||||
|
size_t pitch = video->width * 4;
|
||||||
|
void *data = malloc (pitch * video->height);
|
||||||
|
if (!data) abort();//seems like an out of memory situation... let's just blow up
|
||||||
|
xshm->image = XCreateImage(g_x11_dpy, NULL, 24, ZPixmap, 0,
|
||||||
|
data, video->width, video->height, 8, pitch);
|
||||||
|
xshm->fbptr = data;
|
||||||
|
XSync(g_x11_dpy, False);
|
||||||
|
}
|
||||||
|
|
||||||
xshm->gc = XCreateGC(g_x11_dpy, g_x11_win, 0, NULL);
|
xshm->gc = XCreateGC(g_x11_dpy, g_x11_win, 0, NULL);
|
||||||
|
|
||||||
@ -119,15 +140,19 @@ static bool xshm_gfx_frame(void *data, const void *frame, unsigned width,
|
|||||||
bool menu_is_alive = video_info->menu_is_alive;
|
bool menu_is_alive = video_info->menu_is_alive;
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
memcpy((uint8_t*)xshm->shmInfo.shmaddr + sizeof(uint32_t)*xshm->width*y,
|
memcpy(xshm->fbptr + sizeof(uint32_t)*xshm->width*y,
|
||||||
(uint8_t*)frame + pitch*y, pitch);
|
(uint8_t*)frame + pitch*y, pitch);
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
menu_driver_frame(menu_is_alive, video_info);
|
menu_driver_frame(menu_is_alive, video_info);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
XShmPutImage(g_x11_dpy, g_x11_win, xshm->gc, xshm->image,
|
if (xshm->use_shm)
|
||||||
0, 0, 0, 0, xshm->width, xshm->height, False);
|
XShmPutImage(g_x11_dpy, g_x11_win, xshm->gc, xshm->image,
|
||||||
|
0, 0, 0, 0, xshm->width, xshm->height, False);
|
||||||
|
else
|
||||||
|
XPutImage(g_x11_dpy, g_x11_win, xshm->gc, xshm->image,
|
||||||
|
0, 0, 0, 0, xshm->width, xshm->height);
|
||||||
XFlush(g_x11_dpy);
|
XFlush(g_x11_dpy);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user