2013-12-31 22:19:51 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 17:06:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2012-2014 - OV2
|
2013-12-31 22:19:51 +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/>.
|
|
|
|
*/
|
|
|
|
|
2015-04-12 18:00:49 +00:00
|
|
|
#ifdef _XBOX
|
|
|
|
#include <xtl.h>
|
|
|
|
#endif
|
|
|
|
|
2015-01-07 21:23:45 +00:00
|
|
|
#include "../d3d/d3d.h"
|
2015-04-09 03:16:02 +00:00
|
|
|
#include "../common/win32_common.h"
|
2014-03-08 03:13:20 +00:00
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
#include "../../runloop.h"
|
2015-11-23 11:14:53 +00:00
|
|
|
#include "../../verbosity.h"
|
2013-12-31 22:19:51 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#ifndef _XBOX
|
|
|
|
#pragma comment( lib, "d3d9" )
|
|
|
|
#pragma comment( lib, "d3dx9" )
|
|
|
|
#pragma comment( lib, "cgd3d9" )
|
|
|
|
#pragma comment( lib, "dxguid" )
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2014-03-08 03:13:20 +00:00
|
|
|
#if defined(_XBOX1)
|
|
|
|
#define XBOX_PRESENTATIONINTERVAL D3DRS_PRESENTATIONINTERVAL
|
|
|
|
#define PresentationInterval FullScreen_PresentationInterval
|
|
|
|
#elif defined(_XBOX360)
|
|
|
|
#define XBOX_PRESENTATIONINTERVAL D3DRS_PRESENTINTERVAL
|
|
|
|
#endif
|
|
|
|
|
2014-10-02 19:45:09 +00:00
|
|
|
#ifdef _XBOX
|
|
|
|
static bool widescreen_mode = false;
|
|
|
|
#endif
|
|
|
|
|
2015-11-11 18:48:24 +00:00
|
|
|
void *curD3D = NULL;
|
|
|
|
void *dinput;
|
2014-01-18 19:49:57 +00:00
|
|
|
|
2016-01-06 23:58:33 +00:00
|
|
|
static bool gfx_ctx_d3d_set_resize(void *data, unsigned new_width, unsigned new_height)
|
2014-01-18 19:49:57 +00:00
|
|
|
{
|
2015-01-10 16:51:00 +00:00
|
|
|
d3d_video_t *d3d = (d3d_video_t*)curD3D;
|
|
|
|
|
2016-01-07 00:10:37 +00:00
|
|
|
if (!d3d->dev)
|
|
|
|
return;
|
|
|
|
|
2016-01-06 23:58:33 +00:00
|
|
|
/* No changes? */
|
|
|
|
if (new_width == d3d->video_info.width && new_height == d3d->video_info.height)
|
|
|
|
return false;
|
2014-01-18 19:49:57 +00:00
|
|
|
|
2016-01-06 23:58:33 +00:00
|
|
|
RARCH_LOG("[D3D]: Resize %ux%u.\n", new_width, new_height);
|
|
|
|
d3d->video_info.width = new_width;
|
|
|
|
d3d->video_info.height = new_height;
|
|
|
|
video_driver_set_size(&new_width, &new_height);
|
2014-01-18 19:49:57 +00:00
|
|
|
|
2016-01-06 23:58:33 +00:00
|
|
|
return true;
|
2014-01-18 19:49:57 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_d3d_swap_buffers(void *data)
|
2014-01-09 18:05:31 +00:00
|
|
|
{
|
2015-01-10 16:51:00 +00:00
|
|
|
d3d_video_t *d3d = (d3d_video_t*)data;
|
2014-03-07 18:34:17 +00:00
|
|
|
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;
|
2014-03-07 20:14:56 +00:00
|
|
|
|
2014-09-12 15:36:22 +00:00
|
|
|
d3d_swap(d3d, d3dr);
|
2014-01-18 17:43:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_d3d_update_title(void *data)
|
2014-01-18 17:43:07 +00:00
|
|
|
{
|
2015-06-13 00:10:06 +00:00
|
|
|
char buf[128] = {0};
|
|
|
|
char buffer_fps[128] = {0};
|
2015-03-20 21:08:36 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-11-17 08:41:18 +00:00
|
|
|
HWND window = win32_get_window();
|
2014-03-07 20:14:56 +00:00
|
|
|
|
2015-01-18 19:03:33 +00:00
|
|
|
if (video_monitor_get_fps(buf, sizeof(buf),
|
2015-03-07 22:03:56 +00:00
|
|
|
buffer_fps, sizeof(buffer_fps)))
|
2015-11-17 08:33:27 +00:00
|
|
|
{
|
|
|
|
#ifndef _XBOX
|
2015-11-17 08:41:18 +00:00
|
|
|
SetWindowText(window, buf);
|
2015-11-17 08:33:27 +00:00
|
|
|
#endif
|
|
|
|
}
|
2014-01-09 18:05:31 +00:00
|
|
|
|
2015-03-20 21:08:36 +00:00
|
|
|
if (settings->fps_show)
|
2014-03-07 20:14:56 +00:00
|
|
|
{
|
|
|
|
#ifdef _XBOX
|
|
|
|
MEMORYSTATUS stat;
|
2015-06-13 00:10:06 +00:00
|
|
|
char mem[128] = {0};
|
|
|
|
|
2014-03-07 20:14:56 +00:00
|
|
|
GlobalMemoryStatus(&stat);
|
2014-10-27 13:35:23 +00:00
|
|
|
snprintf(mem, sizeof(mem), "|| MEM: %.2f/%.2fMB",
|
|
|
|
stat.dwAvailPhys/(1024.0f*1024.0f), stat.dwTotalPhys/(1024.0f*1024.0f));
|
2014-03-07 20:14:56 +00:00
|
|
|
strlcat(buffer_fps, mem, sizeof(buffer_fps));
|
|
|
|
#endif
|
2015-12-07 14:32:14 +00:00
|
|
|
runloop_msg_queue_push(buffer_fps, 1, 1, false);
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
2014-01-09 18:05:31 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_d3d_show_mouse(void *data, bool state)
|
2014-01-09 20:27:53 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2015-04-10 07:30:18 +00:00
|
|
|
win32_show_cursor(state);
|
2014-01-09 20:27:53 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_d3d_check_window(void *data, bool *quit,
|
2015-04-05 14:15:14 +00:00
|
|
|
bool *resize, unsigned *width,
|
|
|
|
unsigned *height, unsigned frame_count)
|
2014-01-09 20:27:53 +00:00
|
|
|
{
|
2015-11-11 18:41:32 +00:00
|
|
|
win32_check_window(quit, resize, width, height);
|
2014-01-18 17:43:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static bool gfx_ctx_d3d_has_focus(void *data)
|
2014-01-18 17:43:07 +00:00
|
|
|
{
|
2015-11-17 07:58:49 +00:00
|
|
|
return win32_has_focus();
|
2014-01-18 17:43:07 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 21:32:14 +00:00
|
|
|
static bool gfx_ctx_d3d_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
2015-10-10 06:13:58 +00:00
|
|
|
return win32_suppress_screensaver(data, enable);
|
2015-01-18 21:32:14 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static bool gfx_ctx_d3d_has_windowed(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
#ifdef _XBOX
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-10-27 13:35:23 +00:00
|
|
|
static bool gfx_ctx_d3d_bind_api(void *data,
|
|
|
|
enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2014-01-18 17:43:07 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2014-01-18 17:43:07 +00:00
|
|
|
(void)major;
|
|
|
|
(void)minor;
|
|
|
|
(void)api;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2015-04-05 14:15:14 +00:00
|
|
|
#if defined(HAVE_D3D8)
|
2014-01-18 17:43:07 +00:00
|
|
|
return api == GFX_CTX_DIRECT3D8_API;
|
2014-10-27 13:35:23 +00:00
|
|
|
#else
|
|
|
|
/* As long as we don't have a D3D11 implementation, we default to this */
|
2014-01-18 17:43:07 +00:00
|
|
|
return api == GFX_CTX_DIRECT3D9_API;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-12-08 15:18:57 +00:00
|
|
|
static void *gfx_ctx_d3d_init(void *video_driver)
|
2014-01-18 17:43:07 +00:00
|
|
|
{
|
2015-11-11 16:57:15 +00:00
|
|
|
win32_monitor_init();
|
|
|
|
|
2015-12-20 22:07:37 +00:00
|
|
|
return video_driver;
|
2014-01-15 16:24:24 +00:00
|
|
|
}
|
2014-01-18 17:43:07 +00:00
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_d3d_destroy(void *data)
|
2014-03-08 04:21:36 +00:00
|
|
|
{
|
2014-03-09 16:11:06 +00:00
|
|
|
(void)data;
|
2014-03-08 04:21:36 +00:00
|
|
|
}
|
|
|
|
|
2014-10-27 13:35:23 +00:00
|
|
|
static void gfx_ctx_d3d_input_driver(void *data,
|
|
|
|
const input_driver_t **input, void **input_data)
|
2014-01-18 19:49:57 +00:00
|
|
|
{
|
2014-03-07 20:14:56 +00:00
|
|
|
#ifdef _XBOX
|
|
|
|
void *xinput = input_xinput.init();
|
2015-04-05 14:15:14 +00:00
|
|
|
*input = xinput ? (const input_driver_t*)&input_xinput : NULL;
|
|
|
|
*input_data = xinput;
|
2014-03-07 20:14:56 +00:00
|
|
|
#else
|
2015-04-05 14:15:14 +00:00
|
|
|
dinput = input_dinput.init();
|
|
|
|
*input = dinput ? &input_dinput : NULL;
|
|
|
|
*input_data = dinput;
|
2014-03-07 20:14:56 +00:00
|
|
|
#endif
|
2015-04-05 14:15:14 +00:00
|
|
|
(void)data;
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 04:01:37 +00:00
|
|
|
static bool gfx_ctx_d3d_set_video_mode(void *data,
|
2015-11-11 04:00:09 +00:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
|
|
|
{
|
|
|
|
win32_show_cursor(!fullscreen);
|
2015-11-11 04:01:37 +00:00
|
|
|
|
|
|
|
return true;
|
2015-11-11 04:00:09 +00:00
|
|
|
}
|
|
|
|
|
2014-10-27 13:35:23 +00:00
|
|
|
static void gfx_ctx_d3d_get_video_size(void *data,
|
|
|
|
unsigned *width, unsigned *height)
|
2014-03-07 20:14:56 +00:00
|
|
|
{
|
2015-09-29 15:35:28 +00:00
|
|
|
#ifdef _XBOX
|
2015-01-03 19:54:49 +00:00
|
|
|
d3d_video_t *d3d = (d3d_video_t*)data;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2014-03-07 20:14:56 +00:00
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
#if defined(_XBOX360)
|
|
|
|
XVIDEO_MODE video_mode;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
2014-03-07 20:14:56 +00:00
|
|
|
XGetVideoMode(&video_mode);
|
|
|
|
|
|
|
|
*width = video_mode.dwDisplayWidth;
|
|
|
|
*height = video_mode.dwDisplayHeight;
|
|
|
|
|
2014-10-03 20:26:29 +00:00
|
|
|
d3d->resolution_hd_enable = false;
|
2014-10-02 19:57:01 +00:00
|
|
|
|
2014-03-07 20:14:56 +00:00
|
|
|
if(video_mode.fIsHiDef)
|
|
|
|
{
|
|
|
|
*width = 1280;
|
|
|
|
*height = 720;
|
2014-10-03 20:26:29 +00:00
|
|
|
d3d->resolution_hd_enable = true;
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-04 02:10:15 +00:00
|
|
|
*width = 640;
|
|
|
|
*height = 480;
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 19:45:09 +00:00
|
|
|
widescreen_mode = video_mode.fIsWideScreen;
|
2014-03-07 20:14:56 +00:00
|
|
|
#elif defined(_XBOX1)
|
|
|
|
DWORD video_mode = XGetVideoFlags();
|
|
|
|
|
2015-04-03 00:18:33 +00:00
|
|
|
*width = 640;
|
|
|
|
*height = 480;
|
2014-03-07 20:14:56 +00:00
|
|
|
|
2015-04-03 00:18:33 +00:00
|
|
|
widescreen_mode = false;
|
2015-01-10 16:51:00 +00:00
|
|
|
|
|
|
|
/* Only valid in PAL mode, not valid for HDTV modes! */
|
|
|
|
|
2014-03-07 20:14:56 +00:00
|
|
|
if(XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I)
|
|
|
|
{
|
2014-10-02 19:45:09 +00:00
|
|
|
/* Check for 16:9 mode (PAL REGION) */
|
2014-03-07 20:14:56 +00:00
|
|
|
if(video_mode & XC_VIDEO_FLAGS_WIDESCREEN)
|
|
|
|
{
|
2014-10-02 19:45:09 +00:00
|
|
|
*width = 720;
|
2014-09-04 02:10:15 +00:00
|
|
|
//60 Hz, 720x480i
|
2014-03-07 20:14:56 +00:00
|
|
|
if(video_mode & XC_VIDEO_FLAGS_PAL_60Hz)
|
|
|
|
*height = 480;
|
2014-09-04 02:10:15 +00:00
|
|
|
else //50 Hz, 720x576i
|
2014-03-07 20:14:56 +00:00
|
|
|
*height = 576;
|
2014-10-02 19:45:09 +00:00
|
|
|
widescreen_mode = true;
|
2014-09-04 02:10:15 +00:00
|
|
|
}
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-02 19:45:09 +00:00
|
|
|
/* Check for 16:9 mode (NTSC REGIONS) */
|
2014-03-07 20:14:56 +00:00
|
|
|
if(video_mode & XC_VIDEO_FLAGS_WIDESCREEN)
|
|
|
|
{
|
|
|
|
*width = 720;
|
|
|
|
*height = 480;
|
2014-10-02 19:45:09 +00:00
|
|
|
widescreen_mode = true;
|
2014-09-04 02:10:15 +00:00
|
|
|
}
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(XGetAVPack() == XC_AV_PACK_HDTV)
|
|
|
|
{
|
|
|
|
if(video_mode & XC_VIDEO_FLAGS_HDTV_480p)
|
|
|
|
{
|
2014-09-04 02:10:15 +00:00
|
|
|
*width = 640;
|
2014-03-07 20:14:56 +00:00
|
|
|
*height = 480;
|
2014-10-02 19:45:09 +00:00
|
|
|
widescreen_mode = false;
|
2014-10-22 00:05:01 +00:00
|
|
|
d3d->resolution_hd_enable = true;
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
2014-09-04 02:10:15 +00:00
|
|
|
else if(video_mode & XC_VIDEO_FLAGS_HDTV_720p)
|
2014-03-07 20:14:56 +00:00
|
|
|
{
|
2014-09-04 02:10:15 +00:00
|
|
|
*width = 1280;
|
2014-03-07 20:14:56 +00:00
|
|
|
*height = 720;
|
2014-10-02 19:45:09 +00:00
|
|
|
widescreen_mode = true;
|
2014-10-22 00:05:01 +00:00
|
|
|
d3d->resolution_hd_enable = true;
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
2014-09-04 02:10:15 +00:00
|
|
|
else if(video_mode & XC_VIDEO_FLAGS_HDTV_1080i)
|
2014-03-07 20:14:56 +00:00
|
|
|
{
|
2014-09-04 02:10:15 +00:00
|
|
|
*width = 1920;
|
2014-03-07 20:14:56 +00:00
|
|
|
*height = 1080;
|
2014-10-02 19:45:09 +00:00
|
|
|
widescreen_mode = true;
|
2014-10-22 00:05:01 +00:00
|
|
|
d3d->resolution_hd_enable = true;
|
2014-03-07 20:14:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:11:06 +00:00
|
|
|
static void gfx_ctx_d3d_swap_interval(void *data, unsigned interval)
|
2014-03-07 20:14:56 +00:00
|
|
|
{
|
2015-01-10 16:51:00 +00:00
|
|
|
d3d_video_t *d3d = (d3d_video_t*)data;
|
2014-06-08 02:29:25 +00:00
|
|
|
#ifdef _XBOX
|
2014-10-27 13:35:23 +00:00
|
|
|
unsigned d3d_interval = interval ?
|
|
|
|
D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
2014-03-07 20:14:56 +00:00
|
|
|
|
2015-11-17 10:33:24 +00:00
|
|
|
d3d_set_render_state(d3d->dev, XBOX_PRESENTATIONINTERVAL, d3d_interval);
|
2014-03-07 20:14:56 +00:00
|
|
|
#endif
|
2014-01-18 19:49:57 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 20:06:33 +00:00
|
|
|
static bool gfx_ctx_d3d_get_metrics(void *data,
|
|
|
|
enum display_metric_types type, float *value)
|
|
|
|
{
|
2015-04-09 03:19:29 +00:00
|
|
|
return win32_get_metrics(data, type, value);
|
2015-04-08 20:06:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-14 04:45:47 +00:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_d3d = {
|
2014-01-18 19:49:57 +00:00
|
|
|
gfx_ctx_d3d_init,
|
2014-03-08 04:21:36 +00:00
|
|
|
gfx_ctx_d3d_destroy,
|
2014-01-18 19:49:57 +00:00
|
|
|
gfx_ctx_d3d_bind_api,
|
2014-03-07 20:14:56 +00:00
|
|
|
gfx_ctx_d3d_swap_interval,
|
2015-11-11 04:00:09 +00:00
|
|
|
gfx_ctx_d3d_set_video_mode,
|
2014-03-07 20:14:56 +00:00
|
|
|
gfx_ctx_d3d_get_video_size,
|
2015-02-24 20:36:23 +00:00
|
|
|
NULL, /* get_video_output_size */
|
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-04-08 20:06:33 +00:00
|
|
|
gfx_ctx_d3d_get_metrics,
|
2015-02-24 18:58:14 +00:00
|
|
|
NULL,
|
2014-01-18 19:49:57 +00:00
|
|
|
gfx_ctx_d3d_update_title,
|
|
|
|
gfx_ctx_d3d_check_window,
|
2016-01-06 23:58:33 +00:00
|
|
|
gfx_ctx_d3d_set_resize,
|
2014-01-18 19:49:57 +00:00
|
|
|
gfx_ctx_d3d_has_focus,
|
2015-01-18 21:32:14 +00:00
|
|
|
gfx_ctx_d3d_suppress_screensaver,
|
2014-10-08 15:23:02 +00:00
|
|
|
gfx_ctx_d3d_has_windowed,
|
2014-01-18 19:49:57 +00:00
|
|
|
gfx_ctx_d3d_swap_buffers,
|
|
|
|
gfx_ctx_d3d_input_driver,
|
|
|
|
NULL,
|
2014-09-16 00:16:36 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-01-18 19:49:57 +00:00
|
|
|
gfx_ctx_d3d_show_mouse,
|
2014-03-07 20:22:59 +00:00
|
|
|
"d3d",
|
2014-01-18 17:43:07 +00:00
|
|
|
};
|