diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index 6863037577..26d1943840 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -374,6 +374,31 @@ static void d3d_set_viewport(d3d_video_t *d3d, int x, int y, d3d_set_font_rect(d3d, NULL); } + +static void d3d_set_viewport_wrap(void *data, + unsigned width, unsigned height, + bool force_fullscreen, + bool allow_rotate) +{ + D3DVIEWPORT vp_full; + LPDIRECT3DDEVICE d3dr; + d3d_video_t *d3d = (d3d_video_t*)data; + + vp_full.X = 0; + vp_full.Y = 0; + vp_full.Width = width; + vp_full.Height = height; + vp_full.MinZ = 0.0f; + vp_full.MaxZ = 1.0f; + + d3dr = (LPDIRECT3DDEVICE)d3d->dev; + + if (force_fullscreen) + d3d_set_viewport(d3dr, &vp_full); + else + d3d_set_viewport(d3dr, &d3d->final_viewport); +} + bool d3d_restore(d3d_video_t *d3d) { d3d_deinitialize(d3d); @@ -1973,6 +1998,7 @@ video_driver_t video_d3d = { d3d_set_shader, d3d_free, "d3d", + d3d_set_viewport_wrap, d3d_set_rotation, d3d_viewport_info, d3d_read_viewport, diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index a5f2a5daa3..6309aee971 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -553,7 +553,7 @@ video_driver_t video_ctr = ctr_set_shader, ctr_free, "ctr", - + NULL, /* set_viewport */ ctr_set_rotation, ctr_viewport_info, ctr_read_viewport, diff --git a/gfx/drivers/dispmanx_gfx.c b/gfx/drivers/dispmanx_gfx.c index 1c82791b2c..d1f0f12c3d 100644 --- a/gfx/drivers/dispmanx_gfx.c +++ b/gfx/drivers/dispmanx_gfx.c @@ -651,7 +651,7 @@ video_driver_t video_dispmanx = { dispmanx_gfx_set_shader, dispmanx_gfx_free, "dispmanx", - + NULL, /* set_viewport */ dispmanx_gfx_set_rotation, dispmanx_gfx_viewport_info, dispmanx_gfx_read_viewport, diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index b6ca4c9346..b316cc863f 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -1675,6 +1675,7 @@ video_driver_t video_exynos = { exynos_gfx_set_shader, exynos_gfx_free, "exynos", + NULL, /* set_viewport */ exynos_gfx_set_rotation, exynos_gfx_viewport_info, exynos_gfx_read_viewport, diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 590bbd9f99..17f24ca023 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -771,7 +771,7 @@ static void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotat matrix_4x4_multiply(&gl->mvp, &rot, &gl->mvp_no_rot); } -void gl_set_viewport(gl_t *gl, unsigned width, +static void gl_set_viewport(void *data, unsigned width, unsigned height, bool force_full, bool allow_rotate) { int x = 0, y = 0; @@ -779,6 +779,7 @@ void gl_set_viewport(gl_t *gl, unsigned width, struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); + gl_t *gl = (gl_t*)data; gfx_ctx_translate_aspect(gl, &device_aspect, width, height); @@ -3224,6 +3225,7 @@ video_driver_t video_gl = { gl_free, "gl", + gl_set_viewport, gl_set_rotation, gl_viewport_info, diff --git a/gfx/drivers/gl_common.h b/gfx/drivers/gl_common.h index 3e9405dd32..0d83d41cc6 100644 --- a/gfx/drivers/gl_common.h +++ b/gfx/drivers/gl_common.h @@ -392,9 +392,6 @@ static INLINE bool gl_check_error(void) return false; } -void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, - bool force_full, bool allow_rotate); - void gl_load_texture_data(GLuint id, enum gfx_wrap_type wrap_type, enum texture_filter_type filter_type, diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 92139c7939..3e900b825d 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -1510,6 +1510,7 @@ video_driver_t video_gx = { gx_set_shader, gx_free, "gx", + NULL, /* set_viewport */ gx_set_rotation, gx_viewport_info, gx_read_viewport, diff --git a/gfx/drivers/nullgfx.c b/gfx/drivers/nullgfx.c index 78fb9c0d3b..a9c92ce0bb 100644 --- a/gfx/drivers/nullgfx.c +++ b/gfx/drivers/nullgfx.c @@ -127,6 +127,7 @@ video_driver_t video_null = { null_gfx_set_shader, null_gfx_free, "null", + NULL, /* set_viewport */ null_gfx_set_rotation, null_gfx_viewport_info, null_gfx_read_viewport, diff --git a/gfx/drivers/omap_gfx.c b/gfx/drivers/omap_gfx.c index 1e233efd25..d416cec178 100644 --- a/gfx/drivers/omap_gfx.c +++ b/gfx/drivers/omap_gfx.c @@ -1174,7 +1174,7 @@ video_driver_t video_omap = { omap_gfx_set_shader, omap_gfx_free, "omap", - + NULL, /* set_viewport */ omap_gfx_set_rotation, omap_gfx_viewport_info, omap_gfx_read_viewport, diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index a2e8303e15..aca60b0308 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -969,7 +969,7 @@ video_driver_t video_psp1 = { psp_set_shader, psp_free, "psp1", - + NULL, /* set_viewport */ psp_set_rotation, psp_viewport_info, psp_read_viewport, diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index be0f80ec50..9b38d44e5b 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -764,6 +764,7 @@ video_driver_t video_sdl2 = { sdl2_gfx_free, "sdl2", + NULL, sdl2_gfx_set_rotation, sdl2_gfx_viewport_info, sdl2_gfx_read_viewport, diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index eac9f51708..aff012b8ae 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -574,6 +574,7 @@ video_driver_t video_sdl = { sdl_gfx_set_shader, sdl_gfx_free, "sdl", + NULL, sdl_gfx_set_rotation, sdl_gfx_viewport_info, sdl_gfx_read_viewport, diff --git a/gfx/drivers/sunxi_gfx.c b/gfx/drivers/sunxi_gfx.c index ea69b26652..40769df328 100644 --- a/gfx/drivers/sunxi_gfx.c +++ b/gfx/drivers/sunxi_gfx.c @@ -965,6 +965,7 @@ video_driver_t video_sunxi = { sunxi_gfx_set_shader, sunxi_gfx_free, "sunxi", + NULL, /* set_viewport */ sunxi_gfx_set_rotation, sunxi_gfx_viewport_info, NULL, /* read_viewport */ diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index 84234941bf..f22d2007ae 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -491,6 +491,7 @@ video_driver_t video_vg = { vg_set_shader, vg_free, "vg", + NULL, /* set_viewport */ vg_set_rotation, vg_viewport_info, vg_read_viewport, diff --git a/gfx/drivers/xenon360_gfx.c b/gfx/drivers/xenon360_gfx.c index 3f220c4a3e..549fd1ff37 100644 --- a/gfx/drivers/xenon360_gfx.c +++ b/gfx/drivers/xenon360_gfx.c @@ -320,6 +320,7 @@ video_driver_t video_xenon360 = { xenon360_gfx_set_shader, xenon360_gfx_free, "xenon360", + NULL, /* set_viewport */ xenon360_gfx_set_rotation, xenon360_gfx_viewport_info, xenon360_gfx_read_viewport, diff --git a/gfx/drivers/xvideo.c b/gfx/drivers/xvideo.c index 8e382859ef..e2c5d61adc 100644 --- a/gfx/drivers/xvideo.c +++ b/gfx/drivers/xvideo.c @@ -947,6 +947,7 @@ video_driver_t video_xvideo = { xv_set_shader, xv_free, "xvideo", + NULL, /* set_viewport */ xv_set_rotation, xv_viewport_info, xv_read_viewport, diff --git a/gfx/drivers_font/gl_raster_font.c b/gfx/drivers_font/gl_raster_font.c index 9639eb6f9e..a294587f66 100644 --- a/gfx/drivers_font/gl_raster_font.c +++ b/gfx/drivers_font/gl_raster_font.c @@ -263,7 +263,8 @@ static void gl_raster_font_setup_viewport(gl_raster_t *font, bool full_screen) if (!gl) return; - gl_set_viewport(gl, global->video_data.width, global->video_data.height, full_screen, false); + video_driver_set_viewport(global->video_data.width, + global->video_data.height, full_screen, false); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -282,7 +283,8 @@ static void gl_raster_font_restore_viewport(gl_t *gl) glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glDisable(GL_BLEND); - gl_set_viewport(gl, global->video_data.width, global->video_data.height, false, true); + video_driver_set_viewport(global->video_data.width, + global->video_data.height, false, true); } static void gl_raster_font_render_msg(void *data, const char *msg, diff --git a/gfx/video_driver.c b/gfx/video_driver.c index f32b14b909..74a263b9bd 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -613,6 +613,21 @@ void video_driver_set_nonblock_state(bool toggle) video->set_nonblock_state(driver->video_data, toggle); } +bool video_driver_set_viewport(unsigned width, unsigned height, + bool force_fullscreen, bool allow_rotate) +{ + driver_t *driver = driver_get_ptr(); + const video_driver_t *video = video_driver_ctx_get_ptr(); + + if (video->set_viewport) + { + video->set_viewport(driver->video_data, width, height, + force_fullscreen, allow_rotate); + return true; + } + return false; +} + bool video_driver_set_rotation(unsigned rotation) { driver_t *driver = driver_get_ptr(); diff --git a/gfx/video_driver.h b/gfx/video_driver.h index ee757d651c..af7bd8c0db 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -166,6 +166,9 @@ typedef struct video_driver /* Human-readable identifier. */ const char *ident; + void (*set_viewport)(void *data, unsigned width, unsigned height, + bool force_full, bool allow_rotate); + void (*set_rotation)(void *data, unsigned rotation); void (*viewport_info)(void *data, struct video_viewport *vp); @@ -333,6 +336,9 @@ bool video_driver_suppress_screensaver(bool enable); const char *video_driver_get_ident(void); +bool video_driver_set_viewport(unsigned width, unsigned height, + bool force_fullscreen, bool allow_rotate); + #ifdef __cplusplus } #endif diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index ccb328c2a5..74610b4875 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -128,6 +128,16 @@ static void thread_loop(void *data) thread_reply(thr, CMD_FREE); return; + case CMD_SET_VIEWPORT: + if (thr->driver && thr->driver->set_viewport) + thr->driver->set_viewport(thr->driver_data, + thr->cmd_data.set_viewport.width, + thr->cmd_data.set_viewport.height, + thr->cmd_data.set_viewport.force_full, + thr->cmd_data.set_viewport.allow_rotate); + thread_reply(thr, CMD_SET_VIEWPORT); + break; + case CMD_SET_ROTATION: if (thr->driver && thr->driver->set_rotation) thr->driver->set_rotation(thr->driver_data, thr->cmd_data.i); @@ -607,6 +617,23 @@ static bool thread_set_shader(void *data, return thr->cmd_data.b; } +static void thread_set_viewport(void *data, unsigned width, + unsigned height, bool force_full, bool allow_rotate) +{ + thread_video_t *thr = (thread_video_t*)data; + + if (!thr) + return; + + thr->cmd_data.set_viewport.width = width; + thr->cmd_data.set_viewport.height = height; + thr->cmd_data.set_viewport.force_full = force_full; + thr->cmd_data.set_viewport.allow_rotate = allow_rotate; + + thread_send_cmd(thr, CMD_SET_VIEWPORT); + thread_wait_reply(thr, CMD_SET_VIEWPORT); +} + static void thread_set_rotation(void *data, unsigned rotation) { thread_video_t *thr = (thread_video_t*)data; @@ -979,6 +1006,7 @@ static const video_driver_t video_thread = { thread_set_shader, thread_free, "Thread wrapper", + thread_set_viewport, thread_set_rotation, thread_viewport_info, thread_read_viewport, @@ -997,6 +1025,8 @@ static void thread_set_callbacks(thread_video_t *thr, /* Disable optional features if not present. */ if (!drv->read_viewport) thr->video_thread.read_viewport = NULL; + if (!drv->set_viewport) + thr->video_thread.set_viewport = NULL; if (!drv->set_rotation) thr->video_thread.set_rotation = NULL; if (!drv->set_shader) diff --git a/gfx/video_thread_wrapper.h b/gfx/video_thread_wrapper.h index c07f0627d5..c98d4cc6b3 100644 --- a/gfx/video_thread_wrapper.h +++ b/gfx/video_thread_wrapper.h @@ -30,6 +30,7 @@ enum thread_cmd CMD_SET_SHADER, CMD_FREE, CMD_ALIVE, /* Blocking alive check. Used when paused. */ + CMD_SET_VIEWPORT, CMD_SET_ROTATION, CMD_READ_VIEWPORT, @@ -126,6 +127,14 @@ typedef struct thread_video const char *path; } set_shader; + struct + { + unsigned width; + unsigned height; + bool force_full; + bool allow_rotate; + } set_viewport; + struct { unsigned index; diff --git a/menu/menu_display.c b/menu/menu_display.c index 472680b629..7fbeb83688 100644 --- a/menu/menu_display.c +++ b/menu/menu_display.c @@ -164,63 +164,15 @@ bool menu_display_font_flush_block(menu_handle_t *menu, void menu_display_set_viewport(menu_handle_t *menu) { global_t *global = global_get_ptr(); - driver_t *driver = driver_get_ptr(); - const char *ident = video_driver_get_ident(); -#ifdef HAVE_OPENGL - if (!strcmp(ident, "gl")) - { - gl_set_viewport(driver->video_data, - global->video_data.width, - global->video_data.height, true, false); - return; - } -#endif -#ifdef HAVE_D3D - if (!strcmp(ident, "d3d")) - { - D3DVIEWPORT vp_full; - LPDIRECT3DDEVICE d3dr; - d3d_video_t *d3d = (d3d_video_t*)driver->video_data; - - vp_full.X = 0; - vp_full.Y = 0; - vp_full.Width = global->video_data.width; - vp_full.Height = global->video_data.height; - vp_full.MinZ = 0.0f; - vp_full.MaxZ = 1.0f; - - d3dr = (LPDIRECT3DDEVICE)d3d->dev; - - d3d_set_viewport(d3dr, &vp_full); - return; - } -#endif + video_driver_set_viewport(global->video_data.width, + global->video_data.height, true, false); } void menu_display_unset_viewport(menu_handle_t *menu) { - driver_t *driver = driver_get_ptr(); global_t *global = global_get_ptr(); - const char *ident = video_driver_get_ident(); -#ifdef HAVE_OPENGL - if (!strcmp(ident, "gl")) - { - gl_set_viewport(driver->video_data, - global->video_data.width, - global->video_data.height, - false, true); - return; - } -#endif -#ifdef HAVE_D3D - if (!strcmp(ident, "d3d")) - { - d3d_video_t *d3d = (d3d_video_t*)driver->video_data; - LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; - d3d_set_viewport(d3dr, &d3d->final_viewport); - return; - } -#endif + video_driver_set_viewport(global->video_data.width, + global->video_data.height, false, true); }