mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 19:20:35 +00:00
tabs -> 3 spaces
This commit is contained in:
parent
8e360138d3
commit
55b7267694
554
gfx/rpi.c
554
gfx/rpi.c
@ -36,395 +36,395 @@ typedef struct linuxraw_input linuxraw_input_t;
|
|||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
EGLDisplay mDisplay;
|
EGLDisplay mDisplay;
|
||||||
EGLSurface mSurface;
|
EGLSurface mSurface;
|
||||||
EGLContext mContext;
|
EGLContext mContext;
|
||||||
uint32_t mScreenWidth;
|
uint32_t mScreenWidth;
|
||||||
uint32_t mScreenHeight;
|
uint32_t mScreenHeight;
|
||||||
float mScreenAspect;
|
float mScreenAspect;
|
||||||
bool mKeepAspect;
|
bool mKeepAspect;
|
||||||
unsigned mTextureWidth;
|
unsigned mTextureWidth;
|
||||||
unsigned mTextureHeight;
|
unsigned mTextureHeight;
|
||||||
unsigned mRenderWidth;
|
unsigned mRenderWidth;
|
||||||
unsigned mRenderHeight;
|
unsigned mRenderHeight;
|
||||||
unsigned x1, y1, x2, y2;
|
unsigned x1, y1, x2, y2;
|
||||||
VGImageFormat mTexType;
|
VGImageFormat mTexType;
|
||||||
VGImage mImage;
|
VGImage mImage;
|
||||||
VGfloat mTransformMatrix[9];
|
VGfloat mTransformMatrix[9];
|
||||||
VGint scissor[4];
|
VGint scissor[4];
|
||||||
|
|
||||||
#ifdef HAVE_FREETYPE
|
#ifdef HAVE_FREETYPE
|
||||||
char *mLastMsg;
|
char *mLastMsg;
|
||||||
uint32_t mFontHeight;
|
uint32_t mFontHeight;
|
||||||
VGFont mFont;
|
VGFont mFont;
|
||||||
font_renderer_t *mFontRenderer;
|
font_renderer_t *mFontRenderer;
|
||||||
bool mFontsOn;
|
bool mFontsOn;
|
||||||
VGuint mMsgLength;
|
VGuint mMsgLength;
|
||||||
VGuint mGlyphIndices[1024];
|
VGuint mGlyphIndices[1024];
|
||||||
VGPaint mPaintFg;
|
VGPaint mPaintFg;
|
||||||
VGPaint mPaintBg;
|
VGPaint mPaintBg;
|
||||||
#endif
|
#endif
|
||||||
} rpi_t;
|
} rpi_t;
|
||||||
|
|
||||||
static void rpi_set_nonblock_state(void *data, bool state)
|
static void rpi_set_nonblock_state(void *data, bool state)
|
||||||
{
|
{
|
||||||
rpi_t *rpi = (rpi_t*)data;
|
rpi_t *rpi = (rpi_t*)data;
|
||||||
eglSwapInterval(rpi->mDisplay, state ? 0 : 1);
|
eglSwapInterval(rpi->mDisplay, state ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *rpi_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
static void *rpi_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
||||||
{
|
{
|
||||||
int32_t success;
|
int32_t success;
|
||||||
EGLBoolean result;
|
EGLBoolean result;
|
||||||
EGLint num_config;
|
EGLint num_config;
|
||||||
rpi_t *rpi = (rpi_t*)calloc(1, sizeof(rpi_t));
|
rpi_t *rpi = (rpi_t*)calloc(1, sizeof(rpi_t));
|
||||||
*input = NULL;
|
*input = NULL;
|
||||||
|
|
||||||
static EGL_DISPMANX_WINDOW_T nativewindow;
|
static EGL_DISPMANX_WINDOW_T nativewindow;
|
||||||
|
|
||||||
DISPMANX_ELEMENT_HANDLE_T dispman_element;
|
DISPMANX_ELEMENT_HANDLE_T dispman_element;
|
||||||
DISPMANX_DISPLAY_HANDLE_T dispman_display;
|
DISPMANX_DISPLAY_HANDLE_T dispman_display;
|
||||||
DISPMANX_UPDATE_HANDLE_T dispman_update;
|
DISPMANX_UPDATE_HANDLE_T dispman_update;
|
||||||
DISPMANX_MODEINFO_T dispman_modeinfo;
|
DISPMANX_MODEINFO_T dispman_modeinfo;
|
||||||
VC_RECT_T dst_rect;
|
VC_RECT_T dst_rect;
|
||||||
VC_RECT_T src_rect;
|
VC_RECT_T src_rect;
|
||||||
|
|
||||||
static const EGLint attribute_list[] =
|
static const EGLint attribute_list[] =
|
||||||
{
|
{
|
||||||
EGL_RED_SIZE, 8,
|
EGL_RED_SIZE, 8,
|
||||||
EGL_GREEN_SIZE, 8,
|
EGL_GREEN_SIZE, 8,
|
||||||
EGL_BLUE_SIZE, 8,
|
EGL_BLUE_SIZE, 8,
|
||||||
EGL_ALPHA_SIZE, 8,
|
EGL_ALPHA_SIZE, 8,
|
||||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
EGLConfig config;
|
EGLConfig config;
|
||||||
|
|
||||||
bcm_host_init();
|
bcm_host_init();
|
||||||
|
|
||||||
// get an EGL display connection
|
// get an EGL display connection
|
||||||
rpi->mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
rpi->mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
assert(rpi->mDisplay != EGL_NO_DISPLAY);
|
assert(rpi->mDisplay != EGL_NO_DISPLAY);
|
||||||
|
|
||||||
// initialize the EGL display connection
|
// initialize the EGL display connection
|
||||||
result = eglInitialize(rpi->mDisplay, NULL, NULL);
|
result = eglInitialize(rpi->mDisplay, NULL, NULL);
|
||||||
assert(result != EGL_FALSE);
|
assert(result != EGL_FALSE);
|
||||||
eglBindAPI(EGL_OPENVG_API);
|
eglBindAPI(EGL_OPENVG_API);
|
||||||
|
|
||||||
// get an appropriate EGL frame buffer configuration
|
// get an appropriate EGL frame buffer configuration
|
||||||
result = eglChooseConfig(rpi->mDisplay, attribute_list, &config, 1, &num_config);
|
result = eglChooseConfig(rpi->mDisplay, attribute_list, &config, 1, &num_config);
|
||||||
assert(result != EGL_FALSE);
|
assert(result != EGL_FALSE);
|
||||||
|
|
||||||
// create an EGL rendering context
|
// create an EGL rendering context
|
||||||
rpi->mContext = eglCreateContext(rpi->mDisplay, config, EGL_NO_CONTEXT, NULL);
|
rpi->mContext = eglCreateContext(rpi->mDisplay, config, EGL_NO_CONTEXT, NULL);
|
||||||
assert(rpi->mContext != EGL_NO_CONTEXT);
|
assert(rpi->mContext != EGL_NO_CONTEXT);
|
||||||
|
|
||||||
// create an EGL window surface
|
// create an EGL window surface
|
||||||
success = graphics_get_display_size(0 /* LCD */, &rpi->mScreenWidth, &rpi->mScreenHeight);
|
success = graphics_get_display_size(0 /* LCD */, &rpi->mScreenWidth, &rpi->mScreenHeight);
|
||||||
assert(success >= 0);
|
assert(success >= 0);
|
||||||
|
|
||||||
dst_rect.x = 0;
|
dst_rect.x = 0;
|
||||||
dst_rect.y = 0;
|
dst_rect.y = 0;
|
||||||
dst_rect.width = rpi->mScreenWidth;
|
dst_rect.width = rpi->mScreenWidth;
|
||||||
dst_rect.height = rpi->mScreenHeight;
|
dst_rect.height = rpi->mScreenHeight;
|
||||||
|
|
||||||
src_rect.x = 0;
|
src_rect.x = 0;
|
||||||
src_rect.y = 0;
|
src_rect.y = 0;
|
||||||
src_rect.width = rpi->mScreenWidth << 16;
|
src_rect.width = rpi->mScreenWidth << 16;
|
||||||
src_rect.height = rpi->mScreenHeight << 16;
|
src_rect.height = rpi->mScreenHeight << 16;
|
||||||
|
|
||||||
dispman_display = vc_dispmanx_display_open(0 /* LCD */);
|
dispman_display = vc_dispmanx_display_open(0 /* LCD */);
|
||||||
vc_dispmanx_display_get_info(dispman_display, &dispman_modeinfo);
|
vc_dispmanx_display_get_info(dispman_display, &dispman_modeinfo);
|
||||||
dispman_update = vc_dispmanx_update_start(0);
|
dispman_update = vc_dispmanx_update_start(0);
|
||||||
|
|
||||||
dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display,
|
dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display,
|
||||||
0/*layer*/, &dst_rect, 0/*src*/,
|
0/*layer*/, &dst_rect, 0/*src*/,
|
||||||
&src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, DISPMANX_NO_ROTATE);
|
&src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, DISPMANX_NO_ROTATE);
|
||||||
|
|
||||||
nativewindow.element = dispman_element;
|
nativewindow.element = dispman_element;
|
||||||
nativewindow.width = rpi->mScreenWidth;
|
nativewindow.width = rpi->mScreenWidth;
|
||||||
nativewindow.height = rpi->mScreenHeight;
|
nativewindow.height = rpi->mScreenHeight;
|
||||||
vc_dispmanx_update_submit_sync(dispman_update);
|
vc_dispmanx_update_submit_sync(dispman_update);
|
||||||
|
|
||||||
rpi->mSurface = eglCreateWindowSurface(rpi->mDisplay, config, &nativewindow, NULL);
|
rpi->mSurface = eglCreateWindowSurface(rpi->mDisplay, config, &nativewindow, NULL);
|
||||||
assert(rpi->mSurface != EGL_NO_SURFACE);
|
assert(rpi->mSurface != EGL_NO_SURFACE);
|
||||||
|
|
||||||
// connect the context to the surface
|
// connect the context to the surface
|
||||||
result = eglMakeCurrent(rpi->mDisplay, rpi->mSurface, rpi->mSurface, rpi->mContext);
|
result = eglMakeCurrent(rpi->mDisplay, rpi->mSurface, rpi->mSurface, rpi->mContext);
|
||||||
assert(result != EGL_FALSE);
|
assert(result != EGL_FALSE);
|
||||||
|
|
||||||
rpi->mTexType = video->rgb32 ? VG_sABGR_8888 : VG_sARGB_1555;
|
rpi->mTexType = video->rgb32 ? VG_sABGR_8888 : VG_sARGB_1555;
|
||||||
rpi->mKeepAspect = video->force_aspect;
|
rpi->mKeepAspect = video->force_aspect;
|
||||||
|
|
||||||
// check for SD televisions: they should always be 4:3
|
// check for SD televisions: they should always be 4:3
|
||||||
if (dispman_modeinfo.width == 720 && (dispman_modeinfo.height == 480 || dispman_modeinfo.height == 576))
|
if (dispman_modeinfo.width == 720 && (dispman_modeinfo.height == 480 || dispman_modeinfo.height == 576))
|
||||||
rpi->mScreenAspect = 4.0f / 3.0f;
|
rpi->mScreenAspect = 4.0f / 3.0f;
|
||||||
else
|
else
|
||||||
rpi->mScreenAspect = (float) dispman_modeinfo.width / dispman_modeinfo.height;
|
rpi->mScreenAspect = (float) dispman_modeinfo.width / dispman_modeinfo.height;
|
||||||
|
|
||||||
VGfloat clearColor[4] = {0, 0, 0, 1};
|
VGfloat clearColor[4] = {0, 0, 0, 1};
|
||||||
vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
|
vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
|
||||||
|
|
||||||
rpi->mTextureWidth = rpi->mTextureHeight = video->input_scale * RARCH_SCALE_BASE;
|
rpi->mTextureWidth = rpi->mTextureHeight = video->input_scale * RARCH_SCALE_BASE;
|
||||||
// We can't use the native format because there's no sXRGB_1555 type and
|
// We can't use the native format because there's no sXRGB_1555 type and
|
||||||
// emulation cores can send 0 in the top bit. We lose some speed on
|
// emulation cores can send 0 in the top bit. We lose some speed on
|
||||||
// conversion but I doubt it has any real affect, since we are only drawing
|
// conversion but I doubt it has any real affect, since we are only drawing
|
||||||
// one image at the end of the day. Still keep the alpha channel for ABGR.
|
// one image at the end of the day. Still keep the alpha channel for ABGR.
|
||||||
rpi->mImage = vgCreateImage(video->rgb32 ? VG_sABGR_8888 : VG_sXBGR_8888, rpi->mTextureWidth, rpi->mTextureHeight, video->smooth ? VG_IMAGE_QUALITY_BETTER : VG_IMAGE_QUALITY_NONANTIALIASED);
|
rpi->mImage = vgCreateImage(video->rgb32 ? VG_sABGR_8888 : VG_sXBGR_8888, rpi->mTextureWidth, rpi->mTextureHeight, video->smooth ? VG_IMAGE_QUALITY_BETTER : VG_IMAGE_QUALITY_NONANTIALIASED);
|
||||||
rpi_set_nonblock_state(rpi, !video->vsync);
|
rpi_set_nonblock_state(rpi, !video->vsync);
|
||||||
|
|
||||||
linuxraw_input_t *linuxraw_input = (linuxraw_input_t *)input_linuxraw.init();
|
linuxraw_input_t *linuxraw_input = (linuxraw_input_t *)input_linuxraw.init();
|
||||||
if (linuxraw_input)
|
if (linuxraw_input)
|
||||||
{
|
{
|
||||||
*input = (const input_driver_t *)&input_linuxraw;
|
*input = (const input_driver_t *)&input_linuxraw;
|
||||||
*input_data = linuxraw_input;
|
*input_data = linuxraw_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FREETYPE
|
#ifdef HAVE_FREETYPE
|
||||||
if (g_settings.video.font_enable)
|
if (g_settings.video.font_enable)
|
||||||
{
|
{
|
||||||
rpi->mFont = vgCreateFont(0);
|
rpi->mFont = vgCreateFont(0);
|
||||||
rpi->mFontHeight = g_settings.video.font_size * (g_settings.video.font_scale ? (float) rpi->mScreenWidth / 1280.0f : 1.0f);
|
rpi->mFontHeight = g_settings.video.font_size * (g_settings.video.font_scale ? (float) rpi->mScreenWidth / 1280.0f : 1.0f);
|
||||||
|
|
||||||
const char *path = g_settings.video.font_path;
|
const char *path = g_settings.video.font_path;
|
||||||
if (!*path || !path_file_exists(path))
|
if (!*path || !path_file_exists(path))
|
||||||
path = font_renderer_get_default_font();
|
path = font_renderer_get_default_font();
|
||||||
|
|
||||||
rpi->mFontRenderer = font_renderer_new(path, rpi->mFontHeight);
|
rpi->mFontRenderer = font_renderer_new(path, rpi->mFontHeight);
|
||||||
|
|
||||||
if (rpi->mFont != VG_INVALID_HANDLE && rpi->mFontRenderer)
|
if (rpi->mFont != VG_INVALID_HANDLE && rpi->mFontRenderer)
|
||||||
{
|
{
|
||||||
rpi->mFontsOn = true;
|
rpi->mFontsOn = true;
|
||||||
|
|
||||||
rpi->mPaintFg = vgCreatePaint();
|
rpi->mPaintFg = vgCreatePaint();
|
||||||
rpi->mPaintBg = vgCreatePaint();
|
rpi->mPaintBg = vgCreatePaint();
|
||||||
VGfloat paintFg[] = { g_settings.video.msg_color_r, g_settings.video.msg_color_g, g_settings.video.msg_color_b, 1.0f };
|
VGfloat paintFg[] = { g_settings.video.msg_color_r, g_settings.video.msg_color_g, g_settings.video.msg_color_b, 1.0f };
|
||||||
VGfloat paintBg[] = { g_settings.video.msg_color_r / 2.0f, g_settings.video.msg_color_g / 2.0f, g_settings.video.msg_color_b / 2.0f, 0.5f };
|
VGfloat paintBg[] = { g_settings.video.msg_color_r / 2.0f, g_settings.video.msg_color_g / 2.0f, g_settings.video.msg_color_b / 2.0f, 0.5f };
|
||||||
|
|
||||||
vgSetParameteri(rpi->mPaintFg, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
|
vgSetParameteri(rpi->mPaintFg, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
|
||||||
vgSetParameterfv(rpi->mPaintFg, VG_PAINT_COLOR, 4, paintFg);
|
vgSetParameterfv(rpi->mPaintFg, VG_PAINT_COLOR, 4, paintFg);
|
||||||
|
|
||||||
vgSetParameteri(rpi->mPaintBg, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
|
vgSetParameteri(rpi->mPaintBg, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
|
||||||
vgSetParameterfv(rpi->mPaintBg, VG_PAINT_COLOR, 4, paintBg);
|
vgSetParameterfv(rpi->mPaintBg, VG_PAINT_COLOR, 4, paintBg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return rpi;
|
return rpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rpi_free(void *data)
|
static void rpi_free(void *data)
|
||||||
{
|
{
|
||||||
rpi_t *rpi = (rpi_t*)data;
|
rpi_t *rpi = (rpi_t*)data;
|
||||||
|
|
||||||
vgDestroyImage(rpi->mImage);
|
vgDestroyImage(rpi->mImage);
|
||||||
|
|
||||||
#ifdef HAVE_FREETYPE
|
#ifdef HAVE_FREETYPE
|
||||||
if (rpi->mFontsOn)
|
if (rpi->mFontsOn)
|
||||||
{
|
{
|
||||||
vgDestroyFont(rpi->mFont);
|
vgDestroyFont(rpi->mFont);
|
||||||
font_renderer_free(rpi->mFontRenderer);
|
font_renderer_free(rpi->mFontRenderer);
|
||||||
vgDestroyPaint(rpi->mPaintFg);
|
vgDestroyPaint(rpi->mPaintFg);
|
||||||
vgDestroyPaint(rpi->mPaintBg);
|
vgDestroyPaint(rpi->mPaintBg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Release EGL resources
|
// Release EGL resources
|
||||||
eglMakeCurrent(rpi->mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
eglMakeCurrent(rpi->mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
eglDestroySurface(rpi->mDisplay, rpi->mSurface);
|
eglDestroySurface(rpi->mDisplay, rpi->mSurface);
|
||||||
eglDestroyContext(rpi->mDisplay, rpi->mContext);
|
eglDestroyContext(rpi->mDisplay, rpi->mContext);
|
||||||
eglTerminate(rpi->mDisplay);
|
eglTerminate(rpi->mDisplay);
|
||||||
|
|
||||||
free(rpi);
|
free(rpi);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FREETYPE
|
#ifdef HAVE_FREETYPE
|
||||||
|
|
||||||
static void rpi_render_message(rpi_t *rpi, const char *msg)
|
static void rpi_render_message(rpi_t *rpi, const char *msg)
|
||||||
{
|
{
|
||||||
free(rpi->mLastMsg);
|
free(rpi->mLastMsg);
|
||||||
rpi->mLastMsg = strdup(msg);
|
rpi->mLastMsg = strdup(msg);
|
||||||
|
|
||||||
if(rpi->mMsgLength)
|
if(rpi->mMsgLength)
|
||||||
{
|
{
|
||||||
while (--rpi->mMsgLength)
|
while (--rpi->mMsgLength)
|
||||||
vgClearGlyph(rpi->mFont, rpi->mMsgLength);
|
vgClearGlyph(rpi->mFont, rpi->mMsgLength);
|
||||||
|
|
||||||
vgClearGlyph(rpi->mFont, 0);
|
vgClearGlyph(rpi->mFont, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct font_output_list out;
|
struct font_output_list out;
|
||||||
font_renderer_msg(rpi->mFontRenderer, msg, &out);
|
font_renderer_msg(rpi->mFontRenderer, msg, &out);
|
||||||
struct font_output *head = out.head;
|
struct font_output *head = out.head;
|
||||||
|
|
||||||
while (head)
|
while (head)
|
||||||
{
|
{
|
||||||
if (rpi->mMsgLength >= 1024)
|
if (rpi->mMsgLength >= 1024)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
VGfloat origin[2], escapement[2];
|
VGfloat origin[2], escapement[2];
|
||||||
VGImage img;
|
VGImage img;
|
||||||
|
|
||||||
escapement[0] = (VGfloat) (head->advance_x);
|
escapement[0] = (VGfloat) (head->advance_x);
|
||||||
escapement[1] = (VGfloat) (head->advance_y);
|
escapement[1] = (VGfloat) (head->advance_y);
|
||||||
origin[0] = (VGfloat) (-head->char_off_x);
|
origin[0] = (VGfloat) (-head->char_off_x);
|
||||||
origin[1] = (VGfloat) (head->char_off_y);
|
origin[1] = (VGfloat) (head->char_off_y);
|
||||||
|
|
||||||
img = vgCreateImage(VG_A_8, head->width, head->height, VG_IMAGE_QUALITY_NONANTIALIASED);
|
img = vgCreateImage(VG_A_8, head->width, head->height, VG_IMAGE_QUALITY_NONANTIALIASED);
|
||||||
|
|
||||||
// flip it
|
// flip it
|
||||||
for (unsigned i = 0; i < head->height; i++)
|
for (unsigned i = 0; i < head->height; i++)
|
||||||
vgImageSubData(img, head->output + head->pitch * i, head->pitch, VG_A_8, 0, head->height - i - 1, head->width, 1);
|
vgImageSubData(img, head->output + head->pitch * i, head->pitch, VG_A_8, 0, head->height - i - 1, head->width, 1);
|
||||||
|
|
||||||
vgSetGlyphToImage(rpi->mFont, rpi->mMsgLength, img, origin, escapement);
|
vgSetGlyphToImage(rpi->mFont, rpi->mMsgLength, img, origin, escapement);
|
||||||
vgDestroyImage(img);
|
vgDestroyImage(img);
|
||||||
|
|
||||||
rpi->mMsgLength++;
|
rpi->mMsgLength++;
|
||||||
head = head->next;
|
head = head->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
font_renderer_free_output(&out);
|
font_renderer_free_output(&out);
|
||||||
|
|
||||||
for (unsigned i = 0; i < rpi->mMsgLength; i++)
|
for (unsigned i = 0; i < rpi->mMsgLength; i++)
|
||||||
rpi->mGlyphIndices[i] = i;
|
rpi->mGlyphIndices[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rpi_draw_message(rpi_t *rpi, const char *msg)
|
static void rpi_draw_message(rpi_t *rpi, const char *msg)
|
||||||
{
|
{
|
||||||
if (!rpi->mLastMsg || strcmp(rpi->mLastMsg, msg))
|
if (!rpi->mLastMsg || strcmp(rpi->mLastMsg, msg))
|
||||||
rpi_render_message(rpi, msg);
|
rpi_render_message(rpi, msg);
|
||||||
|
|
||||||
vgSeti(VG_SCISSORING, VG_FALSE);
|
vgSeti(VG_SCISSORING, VG_FALSE);
|
||||||
vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
|
vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
|
||||||
|
|
||||||
VGfloat origins[] = { rpi->mScreenWidth * g_settings.video.msg_pos_x - 2.0f, rpi->mScreenHeight * g_settings.video.msg_pos_y - 2.0f };
|
VGfloat origins[] = { rpi->mScreenWidth * g_settings.video.msg_pos_x - 2.0f, rpi->mScreenHeight * g_settings.video.msg_pos_y - 2.0f };
|
||||||
vgSetfv(VG_GLYPH_ORIGIN, 2, origins);
|
vgSetfv(VG_GLYPH_ORIGIN, 2, origins);
|
||||||
vgSetPaint(rpi->mPaintBg, VG_FILL_PATH);
|
vgSetPaint(rpi->mPaintBg, VG_FILL_PATH);
|
||||||
vgDrawGlyphs(rpi->mFont, rpi->mMsgLength, rpi->mGlyphIndices, NULL, NULL, VG_FILL_PATH, VG_TRUE);
|
vgDrawGlyphs(rpi->mFont, rpi->mMsgLength, rpi->mGlyphIndices, NULL, NULL, VG_FILL_PATH, VG_TRUE);
|
||||||
origins[0] += 2.0f;
|
origins[0] += 2.0f;
|
||||||
origins[1] += 2.0f;
|
origins[1] += 2.0f;
|
||||||
vgSetfv(VG_GLYPH_ORIGIN, 2, origins);
|
vgSetfv(VG_GLYPH_ORIGIN, 2, origins);
|
||||||
vgSetPaint(rpi->mPaintFg, VG_FILL_PATH);
|
vgSetPaint(rpi->mPaintFg, VG_FILL_PATH);
|
||||||
vgDrawGlyphs(rpi->mFont, rpi->mMsgLength, rpi->mGlyphIndices, NULL, NULL, VG_FILL_PATH, VG_TRUE);
|
vgDrawGlyphs(rpi->mFont, rpi->mMsgLength, rpi->mGlyphIndices, NULL, NULL, VG_FILL_PATH, VG_TRUE);
|
||||||
|
|
||||||
vgSeti(VG_SCISSORING, VG_TRUE);
|
vgSeti(VG_SCISSORING, VG_TRUE);
|
||||||
vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
|
vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void rpi_calculate_quad(rpi_t *rpi)
|
static void rpi_calculate_quad(rpi_t *rpi)
|
||||||
{
|
{
|
||||||
// set viewport for aspect ratio, taken from the OpenGL driver
|
// set viewport for aspect ratio, taken from the OpenGL driver
|
||||||
if (rpi->mKeepAspect)
|
if (rpi->mKeepAspect)
|
||||||
{
|
{
|
||||||
float desired_aspect = g_settings.video.aspect_ratio;
|
float desired_aspect = g_settings.video.aspect_ratio;
|
||||||
|
|
||||||
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
|
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
|
||||||
// assume they are actually equal.
|
// assume they are actually equal.
|
||||||
if (fabs(rpi->mScreenAspect - desired_aspect) < 0.0001)
|
if (fabs(rpi->mScreenAspect - desired_aspect) < 0.0001)
|
||||||
{
|
{
|
||||||
rpi->x1 = 0;
|
rpi->x1 = 0;
|
||||||
rpi->y1 = 0;
|
rpi->y1 = 0;
|
||||||
rpi->x2 = rpi->mScreenWidth;
|
rpi->x2 = rpi->mScreenWidth;
|
||||||
rpi->y2 = rpi->mScreenHeight;
|
rpi->y2 = rpi->mScreenHeight;
|
||||||
}
|
}
|
||||||
else if (rpi->mScreenAspect > desired_aspect)
|
else if (rpi->mScreenAspect > desired_aspect)
|
||||||
{
|
{
|
||||||
float delta = (desired_aspect / rpi->mScreenAspect - 1.0) / 2.0 + 0.5;
|
float delta = (desired_aspect / rpi->mScreenAspect - 1.0) / 2.0 + 0.5;
|
||||||
rpi->x1 = rpi->mScreenWidth * (0.5 - delta);
|
rpi->x1 = rpi->mScreenWidth * (0.5 - delta);
|
||||||
rpi->y1 = 0;
|
rpi->y1 = 0;
|
||||||
rpi->x2 = 2.0 * rpi->mScreenWidth * delta + rpi->x1;
|
rpi->x2 = 2.0 * rpi->mScreenWidth * delta + rpi->x1;
|
||||||
rpi->y2 = rpi->mScreenHeight + rpi->y1;
|
rpi->y2 = rpi->mScreenHeight + rpi->y1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float delta = (rpi->mScreenAspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
float delta = (rpi->mScreenAspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
||||||
rpi->x1 = 0;
|
rpi->x1 = 0;
|
||||||
rpi->y1 = rpi->mScreenHeight * (0.5 - delta);
|
rpi->y1 = rpi->mScreenHeight * (0.5 - delta);
|
||||||
rpi->x2 = rpi->mScreenWidth + rpi->x1;
|
rpi->x2 = rpi->mScreenWidth + rpi->x1;
|
||||||
rpi->y2 = 2.0 * rpi->mScreenHeight * delta + rpi->y1;
|
rpi->y2 = 2.0 * rpi->mScreenHeight * delta + rpi->y1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rpi->x1 = 0;
|
rpi->x1 = 0;
|
||||||
rpi->y1 = 0;
|
rpi->y1 = 0;
|
||||||
rpi->x2 = rpi->mScreenWidth;
|
rpi->x2 = rpi->mScreenWidth;
|
||||||
rpi->y2 = rpi->mScreenHeight;
|
rpi->y2 = rpi->mScreenHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
rpi->scissor[0] = rpi->x1;
|
rpi->scissor[0] = rpi->x1;
|
||||||
rpi->scissor[1] = rpi->y1;
|
rpi->scissor[1] = rpi->y1;
|
||||||
rpi->scissor[2] = rpi->x2 - rpi->x1;
|
rpi->scissor[2] = rpi->x2 - rpi->x1;
|
||||||
rpi->scissor[3] = rpi->y2 - rpi->y1;
|
rpi->scissor[3] = rpi->y2 - rpi->y1;
|
||||||
|
|
||||||
vgSetiv(VG_SCISSOR_RECTS, 4, rpi->scissor);
|
vgSetiv(VG_SCISSOR_RECTS, 4, rpi->scissor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rpi_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
|
static bool rpi_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
|
||||||
{
|
{
|
||||||
rpi_t *rpi = (rpi_t*)data;
|
rpi_t *rpi = (rpi_t*)data;
|
||||||
|
|
||||||
if (width != rpi->mRenderWidth || height != rpi->mRenderHeight)
|
if (width != rpi->mRenderWidth || height != rpi->mRenderHeight)
|
||||||
{
|
{
|
||||||
rpi->mRenderWidth = width;
|
rpi->mRenderWidth = width;
|
||||||
rpi->mRenderHeight = height;
|
rpi->mRenderHeight = height;
|
||||||
rpi_calculate_quad(rpi);
|
rpi_calculate_quad(rpi);
|
||||||
vguComputeWarpQuadToQuad(
|
vguComputeWarpQuadToQuad(
|
||||||
rpi->x1, rpi->y1, rpi->x2, rpi->y1, rpi->x2, rpi->y2, rpi->x1, rpi->y2,
|
rpi->x1, rpi->y1, rpi->x2, rpi->y1, rpi->x2, rpi->y2, rpi->x1, rpi->y2,
|
||||||
// needs to be flipped, Khronos loves their bottom-left origin
|
// needs to be flipped, Khronos loves their bottom-left origin
|
||||||
0, height, width, height, width, 0, 0, 0,
|
0, height, width, height, width, 0, 0, 0,
|
||||||
rpi->mTransformMatrix);
|
rpi->mTransformMatrix);
|
||||||
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
|
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
|
||||||
vgLoadMatrix(rpi->mTransformMatrix);
|
vgLoadMatrix(rpi->mTransformMatrix);
|
||||||
}
|
}
|
||||||
vgSeti(VG_SCISSORING, VG_FALSE);
|
vgSeti(VG_SCISSORING, VG_FALSE);
|
||||||
vgClear(0, 0, rpi->mScreenWidth, rpi->mScreenHeight);
|
vgClear(0, 0, rpi->mScreenWidth, rpi->mScreenHeight);
|
||||||
vgSeti(VG_SCISSORING, VG_TRUE);
|
vgSeti(VG_SCISSORING, VG_TRUE);
|
||||||
|
|
||||||
vgImageSubData(rpi->mImage, frame, pitch, rpi->mTexType, 0, 0, width, height);
|
vgImageSubData(rpi->mImage, frame, pitch, rpi->mTexType, 0, 0, width, height);
|
||||||
vgDrawImage(rpi->mImage);
|
vgDrawImage(rpi->mImage);
|
||||||
|
|
||||||
#ifdef HAVE_FREETYPE
|
#ifdef HAVE_FREETYPE
|
||||||
if (msg && rpi->mFontsOn)
|
if (msg && rpi->mFontsOn)
|
||||||
rpi_draw_message(rpi, msg);
|
rpi_draw_message(rpi, msg);
|
||||||
#else
|
#else
|
||||||
(void)msg;
|
(void)msg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
eglSwapBuffers(rpi->mDisplay, rpi->mSurface);
|
eglSwapBuffers(rpi->mDisplay, rpi->mSurface);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rpi_alive(void *data)
|
static bool rpi_alive(void *data)
|
||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rpi_focus(void *data)
|
static bool rpi_focus(void *data)
|
||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rpi_set_rotation(void *data, unsigned rotation)
|
static void rpi_set_rotation(void *data, unsigned rotation)
|
||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
(void)rotation;
|
(void)rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
const video_driver_t video_rpi = {
|
const video_driver_t video_rpi = {
|
||||||
rpi_init,
|
rpi_init,
|
||||||
rpi_frame,
|
rpi_frame,
|
||||||
rpi_set_nonblock_state,
|
rpi_set_nonblock_state,
|
||||||
rpi_alive,
|
rpi_alive,
|
||||||
rpi_focus,
|
rpi_focus,
|
||||||
NULL,
|
NULL,
|
||||||
rpi_free,
|
rpi_free,
|
||||||
"rpi",
|
"rpi",
|
||||||
rpi_set_rotation,
|
rpi_set_rotation,
|
||||||
};
|
};
|
||||||
|
@ -31,272 +31,272 @@ static struct termios oldTerm, newTerm;
|
|||||||
|
|
||||||
struct key_bind
|
struct key_bind
|
||||||
{
|
{
|
||||||
uint8_t x;
|
uint8_t x;
|
||||||
enum rarch_key sk;
|
enum rarch_key sk;
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned keysym_lut[SK_LAST];
|
static unsigned keysym_lut[SK_LAST];
|
||||||
static const struct key_bind lut_binds[] = {
|
static const struct key_bind lut_binds[] = {
|
||||||
{ KEY_ESC, SK_ESCAPE },
|
{ KEY_ESC, SK_ESCAPE },
|
||||||
{ KEY_1, SK_1 },
|
{ KEY_1, SK_1 },
|
||||||
{ KEY_2, SK_2 },
|
{ KEY_2, SK_2 },
|
||||||
{ KEY_3, SK_3},
|
{ KEY_3, SK_3},
|
||||||
{ KEY_4, SK_4 },
|
{ KEY_4, SK_4 },
|
||||||
{ KEY_5, SK_5 },
|
{ KEY_5, SK_5 },
|
||||||
{ KEY_6, SK_6 },
|
{ KEY_6, SK_6 },
|
||||||
{ KEY_7, SK_7 },
|
{ KEY_7, SK_7 },
|
||||||
{ KEY_8, SK_8 },
|
{ KEY_8, SK_8 },
|
||||||
{ KEY_9, SK_9 },
|
{ KEY_9, SK_9 },
|
||||||
{ KEY_0, SK_0 },
|
{ KEY_0, SK_0 },
|
||||||
{ KEY_MINUS, SK_MINUS },
|
{ KEY_MINUS, SK_MINUS },
|
||||||
{ KEY_EQUAL, SK_EQUALS },
|
{ KEY_EQUAL, SK_EQUALS },
|
||||||
{ KEY_BACKSPACE, SK_BACKSPACE },
|
{ KEY_BACKSPACE, SK_BACKSPACE },
|
||||||
{ KEY_TAB, SK_TAB },
|
{ KEY_TAB, SK_TAB },
|
||||||
{ KEY_Q, SK_q },
|
{ KEY_Q, SK_q },
|
||||||
{ KEY_W, SK_w },
|
{ KEY_W, SK_w },
|
||||||
{ KEY_E, SK_e },
|
{ KEY_E, SK_e },
|
||||||
{ KEY_R, SK_r },
|
{ KEY_R, SK_r },
|
||||||
{ KEY_T, SK_t },
|
{ KEY_T, SK_t },
|
||||||
{ KEY_Y, SK_y },
|
{ KEY_Y, SK_y },
|
||||||
{ KEY_U, SK_u },
|
{ KEY_U, SK_u },
|
||||||
{ KEY_I, SK_i },
|
{ KEY_I, SK_i },
|
||||||
{ KEY_O, SK_o },
|
{ KEY_O, SK_o },
|
||||||
{ KEY_P, SK_p },
|
{ KEY_P, SK_p },
|
||||||
{ KEY_LEFTBRACE, SK_LEFTBRACKET },
|
{ KEY_LEFTBRACE, SK_LEFTBRACKET },
|
||||||
{ KEY_RIGHTBRACE, SK_RIGHTBRACKET },
|
{ KEY_RIGHTBRACE, SK_RIGHTBRACKET },
|
||||||
{ KEY_ENTER, SK_RETURN },
|
{ KEY_ENTER, SK_RETURN },
|
||||||
{ KEY_LEFTCTRL, SK_LCTRL },
|
{ KEY_LEFTCTRL, SK_LCTRL },
|
||||||
{ KEY_A, SK_a },
|
{ KEY_A, SK_a },
|
||||||
{ KEY_S, SK_s },
|
{ KEY_S, SK_s },
|
||||||
{ KEY_D, SK_d },
|
{ KEY_D, SK_d },
|
||||||
{ KEY_F, SK_f },
|
{ KEY_F, SK_f },
|
||||||
{ KEY_G, SK_g },
|
{ KEY_G, SK_g },
|
||||||
{ KEY_H, SK_h },
|
{ KEY_H, SK_h },
|
||||||
{ KEY_J, SK_j },
|
{ KEY_J, SK_j },
|
||||||
{ KEY_K, SK_k },
|
{ KEY_K, SK_k },
|
||||||
{ KEY_L, SK_l },
|
{ KEY_L, SK_l },
|
||||||
{ KEY_SEMICOLON, SK_SEMICOLON },
|
{ KEY_SEMICOLON, SK_SEMICOLON },
|
||||||
{ KEY_APOSTROPHE, SK_QUOTE },
|
{ KEY_APOSTROPHE, SK_QUOTE },
|
||||||
{ KEY_GRAVE, SK_BACKQUOTE },
|
{ KEY_GRAVE, SK_BACKQUOTE },
|
||||||
{ KEY_LEFTSHIFT, SK_LSHIFT },
|
{ KEY_LEFTSHIFT, SK_LSHIFT },
|
||||||
{ KEY_BACKSLASH, SK_BACKSLASH },
|
{ KEY_BACKSLASH, SK_BACKSLASH },
|
||||||
{ KEY_Z, SK_z },
|
{ KEY_Z, SK_z },
|
||||||
{ KEY_X, SK_x },
|
{ KEY_X, SK_x },
|
||||||
{ KEY_C, SK_c },
|
{ KEY_C, SK_c },
|
||||||
{ KEY_V, SK_v },
|
{ KEY_V, SK_v },
|
||||||
{ KEY_B, SK_b },
|
{ KEY_B, SK_b },
|
||||||
{ KEY_N, SK_n },
|
{ KEY_N, SK_n },
|
||||||
{ KEY_M, SK_m },
|
{ KEY_M, SK_m },
|
||||||
{ KEY_COMMA, SK_COMMA },
|
{ KEY_COMMA, SK_COMMA },
|
||||||
{ KEY_DOT, SK_PERIOD },
|
{ KEY_DOT, SK_PERIOD },
|
||||||
{ KEY_SLASH, SK_SLASH },
|
{ KEY_SLASH, SK_SLASH },
|
||||||
{ KEY_RIGHTSHIFT, SK_RSHIFT },
|
{ KEY_RIGHTSHIFT, SK_RSHIFT },
|
||||||
{ KEY_KPASTERISK, SK_KP_MULTIPLY },
|
{ KEY_KPASTERISK, SK_KP_MULTIPLY },
|
||||||
{ KEY_LEFTALT, SK_LALT },
|
{ KEY_LEFTALT, SK_LALT },
|
||||||
{ KEY_SPACE, SK_SPACE },
|
{ KEY_SPACE, SK_SPACE },
|
||||||
{ KEY_CAPSLOCK, SK_CAPSLOCK },
|
{ KEY_CAPSLOCK, SK_CAPSLOCK },
|
||||||
{ KEY_F1, SK_F1 },
|
{ KEY_F1, SK_F1 },
|
||||||
{ KEY_F2, SK_F2 },
|
{ KEY_F2, SK_F2 },
|
||||||
{ KEY_F3, SK_F3 },
|
{ KEY_F3, SK_F3 },
|
||||||
{ KEY_F4, SK_F4 },
|
{ KEY_F4, SK_F4 },
|
||||||
{ KEY_F5, SK_F5 },
|
{ KEY_F5, SK_F5 },
|
||||||
{ KEY_F6, SK_F6 },
|
{ KEY_F6, SK_F6 },
|
||||||
{ KEY_F7, SK_F7 },
|
{ KEY_F7, SK_F7 },
|
||||||
{ KEY_F8, SK_F8 },
|
{ KEY_F8, SK_F8 },
|
||||||
{ KEY_F9, SK_F9 },
|
{ KEY_F9, SK_F9 },
|
||||||
{ KEY_F10, SK_F10 },
|
{ KEY_F10, SK_F10 },
|
||||||
{ KEY_NUMLOCK, SK_NUMLOCK },
|
{ KEY_NUMLOCK, SK_NUMLOCK },
|
||||||
{ KEY_SCROLLLOCK, SK_SCROLLOCK },
|
{ KEY_SCROLLLOCK, SK_SCROLLOCK },
|
||||||
{ KEY_KP7, SK_KP7 },
|
{ KEY_KP7, SK_KP7 },
|
||||||
{ KEY_KP8, SK_KP8 },
|
{ KEY_KP8, SK_KP8 },
|
||||||
{ KEY_KP9, SK_KP9 },
|
{ KEY_KP9, SK_KP9 },
|
||||||
{ KEY_KPMINUS, SK_KP_MINUS },
|
{ KEY_KPMINUS, SK_KP_MINUS },
|
||||||
{ KEY_KP4, SK_KP4 },
|
{ KEY_KP4, SK_KP4 },
|
||||||
{ KEY_KP5, SK_KP5 },
|
{ KEY_KP5, SK_KP5 },
|
||||||
{ KEY_KP6, SK_KP6 },
|
{ KEY_KP6, SK_KP6 },
|
||||||
{ KEY_KPPLUS, SK_KP_PLUS },
|
{ KEY_KPPLUS, SK_KP_PLUS },
|
||||||
{ KEY_KP1, SK_KP1 },
|
{ KEY_KP1, SK_KP1 },
|
||||||
{ KEY_KP2, SK_KP2 },
|
{ KEY_KP2, SK_KP2 },
|
||||||
{ KEY_KP3, SK_KP3 },
|
{ KEY_KP3, SK_KP3 },
|
||||||
{ KEY_KP0, SK_KP0 },
|
{ KEY_KP0, SK_KP0 },
|
||||||
{ KEY_KPDOT, SK_KP_PERIOD },
|
{ KEY_KPDOT, SK_KP_PERIOD },
|
||||||
|
|
||||||
{ KEY_F11, SK_F11 },
|
{ KEY_F11, SK_F11 },
|
||||||
{ KEY_F12, SK_F12 },
|
{ KEY_F12, SK_F12 },
|
||||||
|
|
||||||
{ KEY_KPENTER, SK_KP_ENTER },
|
{ KEY_KPENTER, SK_KP_ENTER },
|
||||||
{ KEY_RIGHTCTRL, SK_RCTRL },
|
{ KEY_RIGHTCTRL, SK_RCTRL },
|
||||||
{ KEY_KPSLASH, SK_KP_DIVIDE },
|
{ KEY_KPSLASH, SK_KP_DIVIDE },
|
||||||
{ KEY_SYSRQ, SK_PRINT },
|
{ KEY_SYSRQ, SK_PRINT },
|
||||||
{ KEY_RIGHTALT, SK_RALT },
|
{ KEY_RIGHTALT, SK_RALT },
|
||||||
|
|
||||||
{ KEY_HOME, SK_HOME },
|
{ KEY_HOME, SK_HOME },
|
||||||
{ KEY_UP, SK_UP },
|
{ KEY_UP, SK_UP },
|
||||||
{ KEY_PAGEUP, SK_PAGEUP },
|
{ KEY_PAGEUP, SK_PAGEUP },
|
||||||
{ KEY_LEFT, SK_LEFT },
|
{ KEY_LEFT, SK_LEFT },
|
||||||
{ KEY_RIGHT, SK_RIGHT },
|
{ KEY_RIGHT, SK_RIGHT },
|
||||||
{ KEY_END, SK_END },
|
{ KEY_END, SK_END },
|
||||||
{ KEY_DOWN, SK_DOWN },
|
{ KEY_DOWN, SK_DOWN },
|
||||||
{ KEY_PAGEDOWN, SK_PAGEDOWN },
|
{ KEY_PAGEDOWN, SK_PAGEDOWN },
|
||||||
{ KEY_INSERT, SK_INSERT },
|
{ KEY_INSERT, SK_INSERT },
|
||||||
{ KEY_DELETE, SK_DELETE },
|
{ KEY_DELETE, SK_DELETE },
|
||||||
|
|
||||||
{ KEY_PAUSE, SK_PAUSE },
|
{ KEY_PAUSE, SK_PAUSE },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void init_lut(void)
|
static void init_lut(void)
|
||||||
{
|
{
|
||||||
memset(keysym_lut, 0, sizeof(keysym_lut));
|
memset(keysym_lut, 0, sizeof(keysym_lut));
|
||||||
for (unsigned i = 0; i < sizeof(lut_binds) / sizeof(lut_binds[0]); i++)
|
for (unsigned i = 0; i < sizeof(lut_binds) / sizeof(lut_binds[0]); i++)
|
||||||
keysym_lut[lut_binds[i].sk] = lut_binds[i].x;
|
keysym_lut[lut_binds[i].sk] = lut_binds[i].x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void linuxraw_resetKbmd()
|
static void linuxraw_resetKbmd()
|
||||||
{
|
{
|
||||||
if (oldKbmd != 0xFFFF)
|
if (oldKbmd != 0xFFFF)
|
||||||
{
|
{
|
||||||
ioctl(0, KDSKBMODE, oldKbmd);
|
ioctl(0, KDSKBMODE, oldKbmd);
|
||||||
tcsetattr(0, TCSAFLUSH, &oldTerm);
|
tcsetattr(0, TCSAFLUSH, &oldTerm);
|
||||||
oldKbmd = 0xFFFF;
|
oldKbmd = 0xFFFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void linuxraw_exitGracefully(int sig)
|
static void linuxraw_exitGracefully(int sig)
|
||||||
{
|
{
|
||||||
linuxraw_resetKbmd();
|
linuxraw_resetKbmd();
|
||||||
signal(sig, SIG_DFL);
|
signal(sig, SIG_DFL);
|
||||||
kill(getpid(), sig);
|
kill(getpid(), sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *linuxraw_input_init(void)
|
static void *linuxraw_input_init(void)
|
||||||
{
|
{
|
||||||
// only work on terminals
|
// only work on terminals
|
||||||
if (!isatty(0))
|
if (!isatty(0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
linuxraw_input_t *linuxraw = (linuxraw_input_t*)calloc(1, sizeof(*linuxraw));
|
linuxraw_input_t *linuxraw = (linuxraw_input_t*)calloc(1, sizeof(*linuxraw));
|
||||||
if (!linuxraw)
|
if (!linuxraw)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (oldKbmd == 0xFFFF)
|
if (oldKbmd == 0xFFFF)
|
||||||
{
|
{
|
||||||
tcgetattr(0, &oldTerm);
|
tcgetattr(0, &oldTerm);
|
||||||
newTerm = oldTerm;
|
newTerm = oldTerm;
|
||||||
newTerm.c_lflag &= ~(ECHO | ICANON | ISIG);
|
newTerm.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||||
newTerm.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
|
newTerm.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
|
||||||
newTerm.c_cc[VMIN] = 0;
|
newTerm.c_cc[VMIN] = 0;
|
||||||
newTerm.c_cc[VTIME] = 0;
|
newTerm.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
if (ioctl(0, KDGKBMODE, &oldKbmd) != 0)
|
if (ioctl(0, KDGKBMODE, &oldKbmd) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tcsetattr(0, TCSAFLUSH, &newTerm);
|
tcsetattr(0, TCSAFLUSH, &newTerm);
|
||||||
|
|
||||||
if (ioctl(0, KDSKBMODE, K_MEDIUMRAW) != 0)
|
if (ioctl(0, KDSKBMODE, K_MEDIUMRAW) != 0)
|
||||||
{
|
{
|
||||||
linuxraw_resetKbmd();
|
linuxraw_resetKbmd();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// trap some standard termination codes so we can restore the keyboard before we lose control
|
// trap some standard termination codes so we can restore the keyboard before we lose control
|
||||||
signal(SIGABRT, linuxraw_exitGracefully);
|
signal(SIGABRT, linuxraw_exitGracefully);
|
||||||
signal(SIGBUS, linuxraw_exitGracefully);
|
signal(SIGBUS, linuxraw_exitGracefully);
|
||||||
signal(SIGFPE, linuxraw_exitGracefully);
|
signal(SIGFPE, linuxraw_exitGracefully);
|
||||||
signal(SIGILL, linuxraw_exitGracefully);
|
signal(SIGILL, linuxraw_exitGracefully);
|
||||||
signal(SIGINT, linuxraw_exitGracefully);
|
signal(SIGINT, linuxraw_exitGracefully);
|
||||||
signal(SIGQUIT, linuxraw_exitGracefully);
|
signal(SIGQUIT, linuxraw_exitGracefully);
|
||||||
signal(SIGSEGV, linuxraw_exitGracefully);
|
signal(SIGSEGV, linuxraw_exitGracefully);
|
||||||
signal(SIGTERM, linuxraw_exitGracefully);
|
signal(SIGTERM, linuxraw_exitGracefully);
|
||||||
|
|
||||||
atexit(linuxraw_resetKbmd);
|
atexit(linuxraw_resetKbmd);
|
||||||
|
|
||||||
linuxraw->sdl = (sdl_input_t*)input_sdl.init();
|
linuxraw->sdl = (sdl_input_t*)input_sdl.init();
|
||||||
if (!linuxraw->sdl)
|
if (!linuxraw->sdl)
|
||||||
{
|
{
|
||||||
linuxraw_resetKbmd();
|
linuxraw_resetKbmd();
|
||||||
free(linuxraw);
|
free(linuxraw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_lut();
|
init_lut();
|
||||||
|
|
||||||
linuxraw->sdl->use_keyboard = false;
|
linuxraw->sdl->use_keyboard = false;
|
||||||
return linuxraw;
|
return linuxraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool linuxraw_key_pressed(linuxraw_input_t *linuxraw, int key)
|
static bool linuxraw_key_pressed(linuxraw_input_t *linuxraw, int key)
|
||||||
{
|
{
|
||||||
return linuxraw->state[keysym_lut[key]];
|
return linuxraw->state[keysym_lut[key]];
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool linuxraw_is_pressed(linuxraw_input_t *linuxraw, const struct snes_keybind *binds, unsigned id)
|
static bool linuxraw_is_pressed(linuxraw_input_t *linuxraw, const struct snes_keybind *binds, unsigned id)
|
||||||
{
|
{
|
||||||
if (id < RARCH_BIND_LIST_END)
|
if (id < RARCH_BIND_LIST_END)
|
||||||
{
|
{
|
||||||
const struct snes_keybind *bind = &binds[id];
|
const struct snes_keybind *bind = &binds[id];
|
||||||
return bind->valid && linuxraw_key_pressed(linuxraw, binds[id].key);
|
return bind->valid && linuxraw_key_pressed(linuxraw, binds[id].key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool linuxraw_bind_button_pressed(void *data, int key)
|
static bool linuxraw_bind_button_pressed(void *data, int key)
|
||||||
{
|
{
|
||||||
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
||||||
return linuxraw_is_pressed(linuxraw, g_settings.input.binds[0], key) ||
|
return linuxraw_is_pressed(linuxraw, g_settings.input.binds[0], key) ||
|
||||||
input_sdl.key_pressed(linuxraw->sdl, key);
|
input_sdl.key_pressed(linuxraw->sdl, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int16_t linuxraw_input_state(void *data, const struct snes_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id)
|
static int16_t linuxraw_input_state(void *data, const struct snes_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id)
|
||||||
{
|
{
|
||||||
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
||||||
|
|
||||||
switch (device)
|
switch (device)
|
||||||
{
|
{
|
||||||
case RETRO_DEVICE_JOYPAD:
|
case RETRO_DEVICE_JOYPAD:
|
||||||
return linuxraw_is_pressed(linuxraw, binds[port], id) ||
|
return linuxraw_is_pressed(linuxraw, binds[port], id) ||
|
||||||
input_sdl.input_state(linuxraw->sdl, binds, port, device, index, id);
|
input_sdl.input_state(linuxraw->sdl, binds, port, device, index, id);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void linuxraw_input_free(void *data)
|
static void linuxraw_input_free(void *data)
|
||||||
{
|
{
|
||||||
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
||||||
input_sdl.free(linuxraw->sdl);
|
input_sdl.free(linuxraw->sdl);
|
||||||
linuxraw_resetKbmd();
|
linuxraw_resetKbmd();
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void linuxraw_input_poll(void *data)
|
static void linuxraw_input_poll(void *data)
|
||||||
{
|
{
|
||||||
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
uint16_t t;
|
uint16_t t;
|
||||||
|
|
||||||
while (read(0, &c, 1))
|
while (read(0, &c, 1))
|
||||||
{
|
{
|
||||||
bool pressed = !(c & 0x80);
|
bool pressed = !(c & 0x80);
|
||||||
c &= ~0x80;
|
c &= ~0x80;
|
||||||
|
|
||||||
// ignore extended scancodes
|
// ignore extended scancodes
|
||||||
if (!c)
|
if (!c)
|
||||||
read(0, &t, 2);
|
read(0, &t, 2);
|
||||||
|
|
||||||
linuxraw->state[c] = pressed;
|
linuxraw->state[c] = pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_sdl.poll(linuxraw->sdl);
|
input_sdl.poll(linuxraw->sdl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const input_driver_t input_linuxraw = {
|
const input_driver_t input_linuxraw = {
|
||||||
linuxraw_input_init,
|
linuxraw_input_init,
|
||||||
linuxraw_input_poll,
|
linuxraw_input_poll,
|
||||||
linuxraw_input_state,
|
linuxraw_input_state,
|
||||||
linuxraw_bind_button_pressed,
|
linuxraw_bind_button_pressed,
|
||||||
linuxraw_input_free,
|
linuxraw_input_free,
|
||||||
"linuxraw"
|
"linuxraw"
|
||||||
};
|
};
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
typedef struct linuxraw_input
|
typedef struct linuxraw_input
|
||||||
{
|
{
|
||||||
sdl_input_t *sdl;
|
sdl_input_t *sdl;
|
||||||
bool state[0x80];
|
bool state[0x80];
|
||||||
} linuxraw_input_t;
|
} linuxraw_input_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user