aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authornotaz2012-11-17 02:09:49 +0200
committernotaz2012-11-18 01:40:00 +0200
commita83762012066e4799394f63d08a161a45f982ab6 (patch)
tree5208240ef496b97d4ff010d84020fc86bec0f3f7 /frontend
parent07bd309f731eefa49208d77a35507a7b7448ffb6 (diff)
downloadpcsx_rearmed-a83762012066e4799394f63d08a161a45f982ab6.tar.gz
pcsx_rearmed-a83762012066e4799394f63d08a161a45f982ab6.tar.bz2
pcsx_rearmed-a83762012066e4799394f63d08a161a45f982ab6.zip
frontend: initial sdl overlay implementation
Diffstat (limited to 'frontend')
-rw-r--r--frontend/320240/ui_gp2x.h2
m---------frontend/libpicofe0
-rw-r--r--frontend/main.c3
-rw-r--r--frontend/main.h1
-rw-r--r--frontend/menu.c14
-rw-r--r--frontend/menu.h1
-rw-r--r--frontend/pandora/ui_feat.h2
-rw-r--r--frontend/plat_dummy.c19
-rw-r--r--frontend/plat_sdl.c184
9 files changed, 178 insertions, 48 deletions
diff --git a/frontend/320240/ui_gp2x.h b/frontend/320240/ui_gp2x.h
index 075e2e2..0fef431 100644
--- a/frontend/320240/ui_gp2x.h
+++ b/frontend/320240/ui_gp2x.h
@@ -3,11 +3,13 @@
#define MENU_BIOS_PATH "pcsx_rearmed/bios/"
#define MENU_SHOW_VARSCALER 0
+#define MENU_SHOW_VIDOVERLAY 0
#define MENU_SHOW_SCALER2 1
#define MENU_SHOW_NUBS_BTNS 0
#define MENU_SHOW_VIBRATION 1
#define MENU_SHOW_DEADZONE 1
#define MENU_SHOW_MINIMIZE 0
+#define MENU_SHOW_FULLSCREEN 0
#define MENU_SHOW_VOLUME 1
#endif // UI_FEATURES_H
diff --git a/frontend/libpicofe b/frontend/libpicofe
-Subproject a4025790b5eded4501bb659c682004202880a76
+Subproject 9227a7770e0d144109ee34ae34a270c6d06b9f8
diff --git a/frontend/main.c b/frontend/main.c
index 4aa8968..29df6d9 100644
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -261,6 +261,9 @@ do_state_slot:
else
g_opts |= OPT_SHOWFPS;
break;
+ case SACTION_TOGGLE_FULLSCREEN:
+ g_fullscreen = !g_fullscreen;
+ break;
case SACTION_SCREENSHOT:
{
char buf[MAXPATHLEN];
diff --git a/frontend/main.h b/frontend/main.h
index 04489f6..45e0aeb 100644
--- a/frontend/main.h
+++ b/frontend/main.h
@@ -72,6 +72,7 @@ enum sched_action {
SACTION_VOLUME_DOWN,
SACTION_MINIMIZE,
SACTION_TOGGLE_FPS,
+ SACTION_TOGGLE_FULLSCREEN,
SACTION_GUN_TRIGGER = 16,
SACTION_GUN_A,
SACTION_GUN_B,
diff --git a/frontend/menu.c b/frontend/menu.c
index f3d4d63..57c8d17 100644
--- a/frontend/menu.c
+++ b/frontend/menu.c
@@ -79,6 +79,7 @@ typedef enum
MA_OPT_HWFILTER,
MA_OPT_SWFILTER,
MA_OPT_GAMMA,
+ MA_OPT_VIDOVERLAY,
} menu_id;
static int last_vout_w, last_vout_h, last_vout_bpp;
@@ -90,6 +91,7 @@ static int psx_clock;
static int memcard1_sel, memcard2_sel;
int g_opts, g_scaler, g_gamma = 100;
int soft_scaling, analog_deadzone; // for Caanoo
+int g_use_overlay, g_fullscreen;
int filter, soft_filter;
#ifdef __ARM_ARCH_7A__
@@ -115,11 +117,13 @@ static int bios_sel, gpu_plugsel, spu_plugsel;
#ifndef UI_FEATURES_H
#define MENU_BIOS_PATH "bios/"
#define MENU_SHOW_VARSCALER 0
+#define MENU_SHOW_VIDOVERLAY 1
#define MENU_SHOW_SCALER2 0
#define MENU_SHOW_NUBS_BTNS 0
#define MENU_SHOW_VIBRATION 0
#define MENU_SHOW_DEADZONE 0
#define MENU_SHOW_MINIMIZE 0
+#define MENU_SHOW_FULLSCREEN 1
#define MENU_SHOW_VOLUME 0
#endif
@@ -227,6 +231,8 @@ static void menu_set_defconfig(void)
analog_deadzone = 50;
soft_scaling = 1;
soft_filter = 0;
+ g_use_overlay = 1;
+ g_fullscreen = 0;
psx_clock = DEFAULT_PSX_CLOCK;
region = 0;
@@ -292,6 +298,8 @@ static const struct {
CE_INTVAL(g_layer_h),
CE_INTVAL(filter),
CE_INTVAL(soft_filter),
+ CE_INTVAL(g_use_overlay),
+ CE_INTVAL(g_fullscreen),
CE_INTVAL(state_slot),
CE_INTVAL(cpu_clock),
CE_INTVAL(g_opts),
@@ -697,6 +705,9 @@ me_bind_action emuctrl_actions[] =
#if MENU_SHOW_MINIMIZE
{ "Minimize ", 1 << SACTION_MINIMIZE },
#endif
+#if MENU_SHOW_FULLSCREEN
+ { "Toggle fullscreen", 1 << SACTION_TOGGLE_FULLSCREEN },
+#endif
{ "Enter Menu ", 1 << SACTION_ENTER_MENU },
{ "Gun Trigger ", 1 << SACTION_GUN_TRIGGER },
{ "Gun A button ", 1 << SACTION_GUN_A },
@@ -1074,6 +1085,7 @@ static const char *men_soft_filter[] = { "None",
static const char *men_dummy[] = { NULL };
static const char h_cscaler[] = "Displays the scaler layer, you can resize it\n"
"using d-pad or move it using R+d-pad";
+static const char h_overlay[] = "Overlay provides hardware accelerated scaling";
static const char h_soft_filter[] = "Works only if game uses low resolution modes";
static const char h_gamma[] = "Gamma/brightness adjustment (default 100)";
@@ -1132,6 +1144,7 @@ static int menu_loop_cscaler(int id, int keys)
static menu_entry e_menu_gfx_options[] =
{
mee_enum ("Scaler", MA_OPT_VARSCALER, g_scaler, men_scaler),
+ mee_onoff_h ("Use video overlay", MA_OPT_VIDOVERLAY, g_use_overlay, 1, h_overlay),
mee_onoff ("Software Scaling", MA_OPT_SCALER2, soft_scaling, 1),
mee_enum ("Hardware Filter", MA_OPT_HWFILTER, filter, men_dummy),
mee_enum_h ("Software Filter", MA_OPT_SWFILTER, soft_filter, men_soft_filter, h_soft_filter),
@@ -2311,6 +2324,7 @@ void menu_init(void)
me_enable(e_menu_gfx_options, MA_OPT_SWFILTER, 0);
#endif
me_enable(e_menu_gfx_options, MA_OPT_VARSCALER, MENU_SHOW_VARSCALER);
+ me_enable(e_menu_gfx_options, MA_OPT_VIDOVERLAY, MENU_SHOW_VIDOVERLAY);
me_enable(e_menu_gfx_options, MA_OPT_VARSCALER_C, MENU_SHOW_VARSCALER);
me_enable(e_menu_gfx_options, MA_OPT_SCALER2, MENU_SHOW_SCALER2);
me_enable(e_menu_keyconfig, MA_CTRL_NUBS_BTNS, MENU_SHOW_NUBS_BTNS);
diff --git a/frontend/menu.h b/frontend/menu.h
index 3c09abe..c6c1ab1 100644
--- a/frontend/menu.h
+++ b/frontend/menu.h
@@ -29,6 +29,7 @@ enum g_soft_filter_opts {
extern int g_opts, g_scaler, g_gamma;
extern int soft_scaling, analog_deadzone;
+extern int g_use_overlay, g_fullscreen;
extern int filter, soft_filter;
extern int g_menuscreen_w;
diff --git a/frontend/pandora/ui_feat.h b/frontend/pandora/ui_feat.h
index e0117d3..7564e17 100644
--- a/frontend/pandora/ui_feat.h
+++ b/frontend/pandora/ui_feat.h
@@ -4,11 +4,13 @@
#define MENU_BIOS_PATH "<SD card>/pandora/appdata/pcsx_rearmed/bios/"
#define BOOT_MSG "Booting up... (press SPACE for menu)"
#define MENU_SHOW_VARSCALER 1
+#define MENU_SHOW_VIDOVERLAY 0
#define MENU_SHOW_SCALER2 0
#define MENU_SHOW_NUBS_BTNS 1
#define MENU_SHOW_VIBRATION 0
#define MENU_SHOW_DEADZONE 0
#define MENU_SHOW_MINIMIZE 1
+#define MENU_SHOW_FULLSCREEN 0
#define MENU_SHOW_VOLUME 0
#endif // UI_FEATURES_H
diff --git a/frontend/plat_dummy.c b/frontend/plat_dummy.c
index 5b0adf1..baed0d5 100644
--- a/frontend/plat_dummy.c
+++ b/frontend/plat_dummy.c
@@ -54,25 +54,6 @@ void *plat_prepare_screenshot(int *w, int *h, int *bpp)
return 0;
}
-int plat_cpu_clock_get(void)
-{
- return -1;
-}
-
-int plat_cpu_clock_apply(int cpu_clock)
-{
- return -1;
-}
-
-int plat_get_bat_capacity(void)
-{
- return -1;
-}
-
-void plat_step_volume(int is_up)
-{
-}
-
void plat_trigger_vibrate(int is_strong)
{
}
diff --git a/frontend/plat_sdl.c b/frontend/plat_sdl.c
index 1a1ceec..a899c15 100644
--- a/frontend/plat_sdl.c
+++ b/frontend/plat_sdl.c
@@ -16,6 +16,7 @@
#include "libpicofe/menu.h"
#include "plugin_lib.h"
#include "main.h"
+#include "menu.h"
#include "plat.h"
#include "revision.h"
@@ -43,27 +44,101 @@ static const struct in_default_bind in_sdl_defbinds[] = {
{ SDLK_F6, IN_BINDTYPE_EMU, SACTION_SCREENSHOT },
{ SDLK_F7, IN_BINDTYPE_EMU, SACTION_TOGGLE_FPS },
{ SDLK_F8, IN_BINDTYPE_EMU, SACTION_SWITCH_DISPMODE },
+ { SDLK_F11, IN_BINDTYPE_EMU, SACTION_TOGGLE_FULLSCREEN },
{ SDLK_BACKSPACE, IN_BINDTYPE_EMU, SACTION_FAST_FORWARD },
{ 0, 0, 0 }
};
+// XXX: maybe determine this instead..
+#define WM_DECORATION_H 32
+
static SDL_Surface *screen;
+static SDL_Overlay *overlay;
+static int window_w, window_h;
+static int fs_w, fs_h;
+static int psx_w, psx_h;
static void *menubg_img;
+static int in_menu, pending_resize, old_fullscreen;
static int change_video_mode(int w, int h)
{
- screen = SDL_SetVideoMode(w, h, 16, 0);
- if (screen == NULL) {
- fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
- return -1;
+ psx_w = w;
+ psx_h = h;
+
+ if (overlay != NULL) {
+ SDL_FreeYUVOverlay(overlay);
+ overlay = NULL;
+ }
+
+ if (g_use_overlay && !in_menu) {
+ Uint32 flags = SDL_RESIZABLE;
+ int win_w = window_w;
+ int win_h = window_h;
+
+ if (g_fullscreen) {
+ flags |= SDL_FULLSCREEN;
+ win_w = fs_w;
+ win_h = fs_h;
+ }
+
+ screen = SDL_SetVideoMode(win_w, win_h, 0, flags);
+ if (screen == NULL) {
+ fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
+ return -1;
+ }
+
+ overlay = SDL_CreateYUVOverlay(w, h, SDL_UYVY_OVERLAY, screen);
+ if (overlay != NULL) {
+ /*printf("overlay: fmt %x, planes: %d, pitch: %d, hw: %d\n",
+ overlay->format, overlay->planes, *overlay->pitches,
+ overlay->hw_overlay);*/
+
+ if ((long)overlay->pixels[0] & 3)
+ fprintf(stderr, "warning: overlay pointer is unaligned\n");
+ if (!overlay->hw_overlay)
+ fprintf(stderr, "warning: video overlay is not hardware accelerated,"
+ " you may want to disable it.\n");
+ }
+ else {
+ fprintf(stderr, "warning: could not create overlay.\n");
+ }
}
+ if (overlay == NULL) {
+ screen = SDL_SetVideoMode(w, h, 16, 0);
+ if (screen == NULL) {
+ fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
+ return -1;
+ }
+
+ if (!in_menu) {
+ window_w = screen->w;
+ window_h = screen->h;
+ }
+ }
+
+ old_fullscreen = g_fullscreen;
return 0;
}
+static void event_handler(void *event_)
+{
+ SDL_Event *event = event_;
+
+ if (event->type == SDL_VIDEORESIZE) {
+ //printf("%dx%d\n", event->resize.w, event->resize.h);
+ if (overlay != NULL && !g_fullscreen && !old_fullscreen) {
+ window_w = event->resize.w;
+ window_h = event->resize.h;
+ pending_resize = 1;
+ }
+ }
+}
+
void plat_init(void)
{
- int ret;
+ const SDL_VideoInfo *info;
+ int ret, h;
ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
if (ret != 0) {
@@ -71,8 +146,25 @@ void plat_init(void)
exit(1);
}
+ info = SDL_GetVideoInfo();
+ if (info != NULL) {
+ fs_w = info->current_w;
+ fs_h = info->current_h;
+ }
+
+ in_menu = 1;
g_menuscreen_w = 640;
+ if (fs_w != 0 && g_menuscreen_w > fs_w)
+ g_menuscreen_w = fs_w;
g_menuscreen_h = 480;
+ if (fs_h != 0) {
+ h = fs_h;
+ if (info && info->wm_available && h > WM_DECORATION_H)
+ h -= WM_DECORATION_H;
+ if (g_menuscreen_h > h)
+ g_menuscreen_h = h;
+ }
+
ret = change_video_mode(g_menuscreen_w, g_menuscreen_h);
if (ret != 0) {
ret = change_video_mode(0, 0);
@@ -84,16 +176,17 @@ void plat_init(void)
screen->w, screen->h);
goto fail;
}
- g_menuscreen_w = screen->w;
- g_menuscreen_h = screen->h;
}
+ g_menuscreen_w = window_w = screen->w;
+ g_menuscreen_h = window_h = screen->h;
+
SDL_WM_SetCaption("PCSX-ReARMed " REV, NULL);
menubg_img = malloc(640 * 512 * 2);
if (menubg_img == NULL)
goto fail;
- in_sdl_init(in_sdl_defbinds);
+ in_sdl_init(in_sdl_defbinds, event_handler);
in_probe();
pl_rearmed_cbs.only_16bpp = 1;
return;
@@ -120,10 +213,58 @@ void *plat_gvideo_set_mode(int *w, int *h, int *bpp)
return screen->pixels;
}
+static void test_convert(void *d, const void *s, int pixels)
+{
+ unsigned int *dst = d;
+ const unsigned short *src = s;
+ int r0, g0, b0, r1, g1, b1;
+ int y0, y1, u, v;
+
+ for (; pixels > 0; src += 2, dst++, pixels -= 2) {
+ r0 = src[0] >> 11;
+ g0 = (src[0] >> 6) & 0x1f;
+ b0 = src[0] & 0x1f;
+ r1 = src[1] >> 11;
+ g1 = (src[1] >> 6) & 0x1f;
+ b1 = src[1] & 0x1f;
+ y0 = (int)((0.299f * r0) + (0.587f * g0) + (0.114f * b0));
+ y1 = (int)((0.299f * r1) + (0.587f * g1) + (0.114f * b1));
+ //u = (int)(((-0.169f * r0) + (-0.331f * g0) + ( 0.499f * b0)) * 8) + 128;
+ //v = (int)((( 0.499f * r0) + (-0.418f * g0) + (-0.0813f * b0)) * 8) + 128;
+ u = (int)(8 * 0.565f * (b0 - y0)) + 128;
+ v = (int)(8 * 0.713f * (r0 - y0)) + 128;
+ // valid Y range seems to be 16..235
+ y0 = 16 + 219 * y0 / 31;
+ y1 = 16 + 219 * y1 / 31;
+
+ if (y0 < 0 || y0 > 255 || y1 < 0 || y1 > 255
+ || u < 0 || u > 255 || v < 0 || v > 255)
+ {
+ printf("oor: %d, %d, %d, %d\n", y0, y1, u, v);
+ }
+ *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;
+ }
+}
+
/* XXX: missing SDL_LockSurface() */
void *plat_gvideo_flip(void)
{
- SDL_Flip(screen);
+ if (!in_menu && overlay != NULL) {
+ SDL_Rect dstrect = { 0, 0, screen->w, screen->h };
+ SDL_LockYUVOverlay(overlay);
+ test_convert(overlay->pixels[0], screen->pixels, overlay->w * overlay->h);
+ SDL_UnlockYUVOverlay(overlay);
+ SDL_DisplayYUVOverlay(overlay, &dstrect);
+ }
+ else
+ SDL_Flip(screen);
+
+ if (pending_resize || g_fullscreen != old_fullscreen) {
+ // must be done here so that correct buffer is returned
+ change_video_mode(psx_w, psx_h);
+ pending_resize = 0;
+ }
+
return screen->pixels;
}
@@ -133,8 +274,11 @@ void plat_gvideo_close(void)
void plat_video_menu_enter(int is_rom_loaded)
{
+ in_menu = 1;
+
/* surface will be lost, must adjust pl_vout_buf for menu bg */
- memcpy(menubg_img, screen->pixels, screen->w * screen->h * 2);
+ // FIXME?
+ memcpy(menubg_img, screen->pixels, psx_w * psx_h * 2);
pl_vout_buf = menubg_img;
change_video_mode(g_menuscreen_w, g_menuscreen_h);
@@ -155,6 +299,7 @@ void plat_video_menu_end(void)
void plat_video_menu_leave(void)
{
+ in_menu = 0;
}
/* unused stuff */
@@ -163,25 +308,6 @@ void *plat_prepare_screenshot(int *w, int *h, int *bpp)
return 0;
}
-int plat_cpu_clock_get(void)
-{
- return -1;
-}
-
-int plat_cpu_clock_apply(int cpu_clock)
-{
- return -1;
-}
-
-int plat_get_bat_capacity(void)
-{
- return -1;
-}
-
-void plat_step_volume(int is_up)
-{
-}
-
void plat_trigger_vibrate(int is_strong)
{
}