2012-10-26 19:09:30 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 00:37:37 +00:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2012-11-14 00:13:08 +00:00
|
|
|
* Copyright (C) 2012 - OV2
|
2012-10-26 19:09:30 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "d3d9.hpp"
|
2013-12-31 22:19:51 +00:00
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
#include "../gfx_common.h"
|
|
|
|
#include "../../compat/posix_string.h"
|
2012-11-03 23:14:43 +00:00
|
|
|
#include "../../performance.h"
|
2012-10-26 19:09:30 +00:00
|
|
|
|
2013-11-05 19:49:04 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
#endif
|
2013-12-31 20:24:17 +00:00
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
static bool d3d9_frame(void *data, const void *frame,
|
|
|
|
unsigned width, unsigned height, unsigned pitch,
|
|
|
|
const char *msg)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->frame(frame,
|
|
|
|
width, height, pitch, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_set_nonblock_state(void *data, bool state)
|
|
|
|
{
|
|
|
|
reinterpret_cast<D3DVideo*>(data)->set_nonblock_state(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d9_alive(void *data)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->alive();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d9_focus(void *data)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_set_rotation(void *data, unsigned rot)
|
|
|
|
{
|
|
|
|
reinterpret_cast<D3DVideo*>(data)->set_rotation(rot);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_free(void *data)
|
|
|
|
{
|
|
|
|
delete reinterpret_cast<D3DVideo*>(data);
|
|
|
|
}
|
|
|
|
|
2012-10-27 22:38:31 +00:00
|
|
|
static void d3d9_viewport_info(void *data, struct rarch_viewport *vp)
|
2012-10-26 19:09:30 +00:00
|
|
|
{
|
2012-10-27 22:38:31 +00:00
|
|
|
reinterpret_cast<D3DVideo*>(data)->viewport_info(*vp);
|
2012-10-26 19:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d9_read_viewport(void *data, uint8_t *buffer)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->read_viewport(buffer);
|
|
|
|
}
|
|
|
|
|
2013-04-07 11:00:21 +00:00
|
|
|
static bool d3d9_set_shader(void *data, enum rarch_shader_type type, const char *path)
|
2012-10-31 15:28:09 +00:00
|
|
|
{
|
2013-04-13 15:04:28 +00:00
|
|
|
std::string shader = "";
|
2013-04-21 12:14:43 +00:00
|
|
|
if (path && type == RARCH_SHADER_CG)
|
2013-04-13 15:04:28 +00:00
|
|
|
shader = path;
|
|
|
|
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->set_shader(shader);
|
2012-10-31 15:28:09 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 03:36:16 +00:00
|
|
|
#ifdef HAVE_MENU
|
2013-04-07 17:34:44 +00:00
|
|
|
static void d3d9_get_poke_interface(void *data, const video_poke_interface_t **iface);
|
|
|
|
#endif
|
|
|
|
|
2013-03-27 14:55:59 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-12-31 18:03:58 +00:00
|
|
|
static bool d3d9_overlay_load(void *data, const texture_image *images, unsigned num_images)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_load(images, num_images);
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_overlay_tex_geom(void *data,
|
2013-10-21 11:26:23 +00:00
|
|
|
unsigned index,
|
2013-03-27 14:55:59 +00:00
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_tex_geom(index, x, y, w, h);
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_overlay_vertex_geom(void *data,
|
2013-10-21 11:26:23 +00:00
|
|
|
unsigned index,
|
2013-03-27 14:55:59 +00:00
|
|
|
float x, float y,
|
|
|
|
float w, float h)
|
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_vertex_geom(index, x, y, w, h);
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_overlay_enable(void *data, bool state)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_enable(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_overlay_full_screen(void *data, bool enable)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_full_screen(enable);
|
|
|
|
}
|
|
|
|
|
2013-10-21 11:26:23 +00:00
|
|
|
static void d3d9_overlay_set_alpha(void *data, unsigned index, float mod)
|
2013-03-27 14:55:59 +00:00
|
|
|
{
|
2013-10-21 11:26:23 +00:00
|
|
|
return reinterpret_cast<D3DVideo*>(data)->overlay_set_alpha(index, mod);
|
2013-03-27 14:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const video_overlay_interface_t d3d9_overlay_interface = {
|
|
|
|
d3d9_overlay_enable,
|
|
|
|
d3d9_overlay_load,
|
|
|
|
d3d9_overlay_tex_geom,
|
|
|
|
d3d9_overlay_vertex_geom,
|
|
|
|
d3d9_overlay_full_screen,
|
|
|
|
d3d9_overlay_set_alpha,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void d3d9_get_overlay_interface(void *data, const video_overlay_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &d3d9_overlay_interface;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-21 09:20:56 +00:00
|
|
|
static void d3d9_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
|
2013-04-07 17:34:44 +00:00
|
|
|
{
|
2013-04-21 09:20:56 +00:00
|
|
|
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
|
|
|
|
|
|
|
switch (aspect_ratio_idx)
|
|
|
|
{
|
|
|
|
case ASPECT_RATIO_SQUARE:
|
2013-06-05 20:00:38 +00:00
|
|
|
gfx_set_square_pixel_viewport(g_extern.system.av_info.geometry.base_width, g_extern.system.av_info.geometry.base_height);
|
2013-04-21 09:20:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CORE:
|
|
|
|
gfx_set_core_viewport();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CONFIG:
|
|
|
|
gfx_set_config_viewport();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_extern.system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value;
|
|
|
|
d3d->info().force_aspect = true;
|
2013-04-21 12:04:16 +00:00
|
|
|
d3d->should_resize = true;
|
2013-04-07 17:34:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_apply_state_changes(void *data)
|
|
|
|
{
|
2013-04-21 09:20:56 +00:00
|
|
|
D3DVideo *d3d = reinterpret_cast<D3DVideo*>(data);
|
2013-04-21 12:04:16 +00:00
|
|
|
d3d->should_resize = true;
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_set_osd_msg(void *data, const char *msg, void *userdata)
|
|
|
|
{
|
|
|
|
font_params_t *params = (font_params_t*)userdata;
|
2013-04-21 09:20:56 +00:00
|
|
|
reinterpret_cast<D3DVideo*>(data)->render_msg(msg, params);
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void d3d9_show_mouse(void *data, bool state)
|
|
|
|
{
|
2013-12-31 22:19:51 +00:00
|
|
|
reinterpret_cast<D3DVideo*>(data)->show_cursor(state);
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 03:36:16 +00:00
|
|
|
#ifdef HAVE_MENU
|
2013-04-07 17:34:44 +00:00
|
|
|
static void d3d9_set_rgui_texture_frame(void *data,
|
|
|
|
const void *frame, bool rgb32, unsigned width, unsigned height,
|
|
|
|
float alpha)
|
|
|
|
{
|
|
|
|
reinterpret_cast<D3DVideo*>(data)->set_rgui_texture_frame(frame, rgb32, width, height, alpha);
|
|
|
|
}
|
|
|
|
|
2013-04-13 14:48:03 +00:00
|
|
|
static void d3d9_set_rgui_texture_enable(void *data, bool state, bool full_screen)
|
2013-04-07 17:34:44 +00:00
|
|
|
{
|
2013-04-13 14:58:05 +00:00
|
|
|
reinterpret_cast<D3DVideo*>(data)->set_rgui_texture_enable(state, full_screen);
|
2013-04-07 17:34:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const video_poke_interface_t d3d9_poke_interface = {
|
2013-04-20 22:54:25 +00:00
|
|
|
NULL,
|
2013-04-07 17:34:44 +00:00
|
|
|
#ifdef HAVE_FBO
|
2013-04-20 22:54:25 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2013-04-07 17:34:44 +00:00
|
|
|
#endif
|
|
|
|
d3d9_set_aspect_ratio,
|
|
|
|
d3d9_apply_state_changes,
|
2013-11-08 03:36:16 +00:00
|
|
|
#ifdef HAVE_MENU
|
2013-04-07 17:34:44 +00:00
|
|
|
d3d9_set_rgui_texture_frame,
|
|
|
|
d3d9_set_rgui_texture_enable,
|
|
|
|
#endif
|
|
|
|
d3d9_set_osd_msg,
|
|
|
|
|
|
|
|
d3d9_show_mouse,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void d3d9_get_poke_interface(void *data, const video_poke_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &d3d9_poke_interface;
|
|
|
|
}
|
|
|
|
|
2013-12-31 22:19:51 +00:00
|
|
|
static void *d3d9_init(const video_info_t *info, const input_driver_t **input,
|
|
|
|
void **input_data)
|
|
|
|
{
|
|
|
|
D3DVideo *vid = new D3DVideo(info, input, input_data);
|
|
|
|
|
|
|
|
if (!vid)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D]: Failed to init D3D.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vid;
|
|
|
|
}
|
|
|
|
|
2012-10-26 19:09:30 +00:00
|
|
|
const video_driver_t video_d3d9 = {
|
|
|
|
d3d9_init,
|
|
|
|
d3d9_frame,
|
|
|
|
d3d9_set_nonblock_state,
|
|
|
|
d3d9_alive,
|
|
|
|
d3d9_focus,
|
|
|
|
d3d9_set_shader,
|
|
|
|
d3d9_free,
|
|
|
|
"d3d9",
|
2013-11-08 03:36:16 +00:00
|
|
|
#ifdef HAVE_MENU
|
2013-12-31 20:24:17 +00:00
|
|
|
NULL,
|
2013-03-24 01:24:53 +00:00
|
|
|
#endif
|
2012-10-26 19:09:30 +00:00
|
|
|
d3d9_set_rotation,
|
2012-10-27 22:38:31 +00:00
|
|
|
d3d9_viewport_info,
|
2012-10-26 19:09:30 +00:00
|
|
|
d3d9_read_viewport,
|
2013-03-27 14:55:59 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
d3d9_get_overlay_interface,
|
|
|
|
#endif
|
2013-04-07 17:34:44 +00:00
|
|
|
d3d9_get_poke_interface
|
2012-10-26 19:09:30 +00:00
|
|
|
};
|