2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
2012-07-25 05:22:49 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-03-26 17:34:58 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-03-26 17:34:58 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-03-26 17:34:58 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gfx_common.h"
|
2011-11-30 16:27:47 +00:00
|
|
|
#include "../general.h"
|
2013-02-05 08:41:10 +00:00
|
|
|
#include "../performance.h"
|
2011-12-24 23:59:46 +00:00
|
|
|
|
2013-12-17 18:10:21 +00:00
|
|
|
static inline float time_to_fps(retro_time_t last_time, retro_time_t new_time, int frames)
|
2011-12-24 23:59:46 +00:00
|
|
|
{
|
2013-02-05 08:41:10 +00:00
|
|
|
return (1000000.0f * frames) / (new_time - last_time);
|
2011-03-26 17:34:58 +00:00
|
|
|
}
|
|
|
|
|
2013-02-10 00:42:56 +00:00
|
|
|
#define FPS_UPDATE_INTERVAL 256
|
2013-10-07 19:54:29 +00:00
|
|
|
bool gfx_get_fps(char *buf, size_t size, char *buf_fps, size_t size_fps)
|
2011-03-26 17:34:58 +00:00
|
|
|
{
|
2013-12-17 18:10:21 +00:00
|
|
|
static retro_time_t time;
|
|
|
|
static retro_time_t fps_time;
|
2012-11-15 16:30:31 +00:00
|
|
|
static float last_fps;
|
2011-03-26 17:34:58 +00:00
|
|
|
bool ret = false;
|
2013-02-10 13:25:02 +00:00
|
|
|
*buf = '\0';
|
2011-03-26 17:34:58 +00:00
|
|
|
|
2013-12-17 18:10:21 +00:00
|
|
|
retro_time_t new_time = rarch_get_time_usec();
|
2013-02-10 00:42:56 +00:00
|
|
|
if (g_extern.frame_count)
|
2011-03-26 17:34:58 +00:00
|
|
|
{
|
2013-02-10 00:42:56 +00:00
|
|
|
unsigned write_index = g_extern.measure_data.frame_time_samples_count++ &
|
|
|
|
(MEASURE_FRAME_TIME_SAMPLES_COUNT - 1);
|
|
|
|
g_extern.measure_data.frame_time_samples[write_index] = new_time - fps_time;
|
|
|
|
fps_time = new_time;
|
2011-03-26 17:34:58 +00:00
|
|
|
|
2013-02-10 13:20:42 +00:00
|
|
|
if ((g_extern.frame_count % FPS_UPDATE_INTERVAL) == 0)
|
|
|
|
{
|
|
|
|
last_fps = time_to_fps(time, new_time, FPS_UPDATE_INTERVAL);
|
|
|
|
time = new_time;
|
2013-02-04 20:46:56 +00:00
|
|
|
|
2013-02-10 13:20:42 +00:00
|
|
|
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, last_fps, g_extern.frame_count);
|
|
|
|
ret = true;
|
|
|
|
}
|
2013-10-07 19:54:29 +00:00
|
|
|
|
|
|
|
if (buf_fps)
|
2013-10-07 18:17:07 +00:00
|
|
|
snprintf(buf_fps, size_fps, "FPS: %6.1f || Frames: %d", last_fps, g_extern.frame_count);
|
2013-02-10 13:20:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time = fps_time = new_time;
|
2013-10-07 19:54:29 +00:00
|
|
|
strlcpy(buf, g_extern.title_buf, size);
|
|
|
|
if (buf_fps)
|
|
|
|
strlcpy(buf_fps, "N/A", size_fps);
|
2013-02-10 13:20:42 +00:00
|
|
|
ret = true;
|
2012-11-15 16:30:31 +00:00
|
|
|
}
|
2011-03-26 17:34:58 +00:00
|
|
|
|
2012-07-15 16:37:34 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-15 17:12:58 +00:00
|
|
|
#if defined(_WIN32) && !defined(_XBOX)
|
2011-08-07 13:00:34 +00:00
|
|
|
#include <windows.h>
|
2011-12-24 23:59:46 +00:00
|
|
|
#include "../dynamic.h"
|
2011-08-07 20:31:59 +00:00
|
|
|
// We only load this library once, so we let it be unloaded at application shutdown,
|
|
|
|
// since unloading it early seems to cause issues on some systems.
|
|
|
|
|
|
|
|
static dylib_t dwmlib = NULL;
|
|
|
|
|
|
|
|
static void gfx_dwm_shutdown(void)
|
|
|
|
{
|
|
|
|
if (dwmlib)
|
2013-02-05 08:41:10 +00:00
|
|
|
{
|
2011-08-07 20:31:59 +00:00
|
|
|
dylib_close(dwmlib);
|
2013-02-05 08:41:10 +00:00
|
|
|
dwmlib = NULL;
|
|
|
|
}
|
2011-08-07 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
2011-08-07 19:15:50 +00:00
|
|
|
void gfx_set_dwm(void)
|
2011-08-07 13:00:34 +00:00
|
|
|
{
|
|
|
|
static bool inited = false;
|
|
|
|
if (inited)
|
|
|
|
return;
|
|
|
|
inited = true;
|
|
|
|
|
2011-08-07 20:31:59 +00:00
|
|
|
dwmlib = dylib_load("dwmapi.dll");
|
|
|
|
if (!dwmlib)
|
2011-08-07 13:00:34 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Did not find dwmapi.dll.\n");
|
2011-08-07 13:00:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-08-07 20:31:59 +00:00
|
|
|
atexit(gfx_dwm_shutdown);
|
2011-08-07 13:00:34 +00:00
|
|
|
|
2011-08-07 20:31:59 +00:00
|
|
|
HRESULT (WINAPI *mmcss)(BOOL) = (HRESULT (WINAPI*)(BOOL))dylib_proc(dwmlib, "DwmEnableMMCSS");
|
2011-08-07 19:15:50 +00:00
|
|
|
if (mmcss)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Setting multimedia scheduling for DWM.\n");
|
2011-08-07 19:15:50 +00:00
|
|
|
mmcss(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_settings.video.disable_composition)
|
2011-08-07 20:31:59 +00:00
|
|
|
return;
|
2011-08-07 19:15:50 +00:00
|
|
|
|
2011-08-07 20:31:59 +00:00
|
|
|
HRESULT (WINAPI *composition_enable)(UINT) = (HRESULT (WINAPI*)(UINT))dylib_proc(dwmlib, "DwmEnableComposition");
|
2011-08-07 13:00:34 +00:00
|
|
|
if (!composition_enable)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Did not find DwmEnableComposition ...\n");
|
2011-08-07 13:00:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT ret = composition_enable(0);
|
|
|
|
if (FAILED(ret))
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to set composition state ...\n");
|
2011-08-07 13:00:34 +00:00
|
|
|
}
|
2011-08-11 03:59:32 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-29 18:28:33 +00:00
|
|
|
void gfx_scale_integer(struct rarch_viewport *vp, unsigned width, unsigned height, float aspect_ratio, bool keep_aspect)
|
|
|
|
{
|
2013-04-20 10:48:33 +00:00
|
|
|
int padding_x = 0;
|
|
|
|
int padding_y = 0;
|
|
|
|
|
|
|
|
if (g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
2013-01-29 18:28:33 +00:00
|
|
|
{
|
2013-04-20 10:48:33 +00:00
|
|
|
const struct rarch_viewport *custom =
|
|
|
|
&g_extern.console.screen.viewports.custom_vp;
|
|
|
|
|
|
|
|
padding_x = width - custom->width;
|
|
|
|
padding_y = height - custom->height;
|
|
|
|
width = custom->width;
|
|
|
|
height = custom->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use system reported sizes as these define the geometry for the "normal" case.
|
|
|
|
unsigned base_height = g_extern.system.av_info.geometry.base_height;
|
|
|
|
// Account for non-square pixels.
|
|
|
|
// This is sort of contradictory with the goal of integer scale,
|
|
|
|
// but it is desirable in some cases.
|
|
|
|
// If square pixels are used, base_height will be equal to g_extern.system.av_info.base_height.
|
|
|
|
unsigned base_width = (unsigned)roundf(base_height * aspect_ratio);
|
|
|
|
|
|
|
|
// Make sure that we don't get 0x scale ...
|
|
|
|
if (width >= base_width && height >= base_height)
|
2013-01-29 18:28:33 +00:00
|
|
|
{
|
2013-04-20 10:48:33 +00:00
|
|
|
if (keep_aspect) // X/Y scale must be same.
|
|
|
|
{
|
|
|
|
unsigned max_scale = min(width / base_width, height / base_height);
|
|
|
|
padding_x = width - base_width * max_scale;
|
|
|
|
padding_y = height - base_height * max_scale;
|
|
|
|
}
|
|
|
|
else // X/Y can be independent, each scaled as much as possible.
|
|
|
|
{
|
|
|
|
padding_x = width % base_width;
|
|
|
|
padding_y = height % base_height;
|
|
|
|
}
|
2013-01-29 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 10:48:33 +00:00
|
|
|
width -= padding_x;
|
|
|
|
height -= padding_y;
|
|
|
|
}
|
2013-01-29 18:28:33 +00:00
|
|
|
|
|
|
|
vp->width = width;
|
|
|
|
vp->height = height;
|
2013-04-20 10:48:33 +00:00
|
|
|
vp->x = padding_x / 2;
|
|
|
|
vp->y = padding_y / 2;
|
2013-01-29 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 02:20:33 +00:00
|
|
|
struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = {
|
2013-04-20 08:56:04 +00:00
|
|
|
{ "4:3", 1.3333f },
|
|
|
|
{ "16:9", 1.7778f },
|
|
|
|
{ "16:10", 1.6f },
|
|
|
|
{ "16:15", 16.0f / 15.0f },
|
|
|
|
#ifdef RARCH_CONSOLE
|
2013-03-09 02:20:33 +00:00
|
|
|
{ "1:1", 1.0f },
|
|
|
|
{ "2:1", 2.0f },
|
|
|
|
{ "3:2", 1.5f },
|
|
|
|
{ "3:4", 0.75f },
|
|
|
|
{ "4:1", 4.0f },
|
|
|
|
{ "4:4", 1.0f },
|
|
|
|
{ "5:4", 1.25f },
|
|
|
|
{ "6:5", 1.2f },
|
|
|
|
{ "7:9", 0.7777f },
|
|
|
|
{ "8:3", 2.6666f },
|
|
|
|
{ "8:7", 1.1428f },
|
|
|
|
{ "19:12", 1.5833f },
|
|
|
|
{ "19:14", 1.3571f },
|
|
|
|
{ "30:17", 1.7647f },
|
|
|
|
{ "32:9", 3.5555f },
|
2013-04-20 08:56:04 +00:00
|
|
|
#endif
|
|
|
|
{ "Config", 0.0f },
|
|
|
|
{ "Square pixel", 1.0f },
|
|
|
|
{ "Core provided", 1.0f },
|
2013-03-09 02:20:33 +00:00
|
|
|
{ "Custom", 0.0f }
|
|
|
|
};
|
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
char rotation_lut[4][32] =
|
2013-03-09 02:20:33 +00:00
|
|
|
{
|
|
|
|
"Normal",
|
2013-04-21 16:25:30 +00:00
|
|
|
"90 deg",
|
|
|
|
"180 deg",
|
|
|
|
"270 deg"
|
2013-03-09 02:20:33 +00:00
|
|
|
};
|
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
void gfx_set_square_pixel_viewport(unsigned width, unsigned height)
|
2013-03-09 02:20:33 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
unsigned len, highest, i;
|
2013-03-10 00:16:56 +00:00
|
|
|
if (width == 0 || height == 0)
|
2013-03-09 02:20:33 +00:00
|
|
|
return;
|
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
len = min(width, height);
|
|
|
|
highest = 1;
|
|
|
|
for (i = 1; i < len; i++)
|
2013-03-09 02:20:33 +00:00
|
|
|
{
|
|
|
|
if ((width % i) == 0 && (height % i) == 0)
|
|
|
|
highest = i;
|
|
|
|
}
|
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
unsigned aspect_x = width / highest;
|
|
|
|
unsigned aspect_y = height / highest;
|
2013-03-09 02:20:33 +00:00
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
snprintf(aspectratio_lut[ASPECT_RATIO_SQUARE].name,
|
|
|
|
sizeof(aspectratio_lut[ASPECT_RATIO_SQUARE].name),
|
|
|
|
"%u:%u (1:1 PAR)", aspect_x, aspect_y);
|
2013-03-10 00:16:56 +00:00
|
|
|
|
2013-04-20 08:56:04 +00:00
|
|
|
aspectratio_lut[ASPECT_RATIO_SQUARE].value = (float)aspect_x / aspect_y;
|
2013-03-09 02:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_set_core_viewport(void)
|
|
|
|
{
|
2013-04-20 08:56:04 +00:00
|
|
|
const struct retro_game_geometry *geom = &g_extern.system.av_info.geometry;
|
2013-10-26 16:29:47 +00:00
|
|
|
if (geom->base_width <= 0.0f || geom->base_height <= 0.0f)
|
|
|
|
return;
|
2013-04-20 08:56:04 +00:00
|
|
|
|
|
|
|
// Fallback to 1:1 pixel ratio if none provided
|
|
|
|
if (geom->aspect_ratio > 0.0f)
|
|
|
|
aspectratio_lut[ASPECT_RATIO_CORE].value = geom->aspect_ratio;
|
|
|
|
else
|
|
|
|
aspectratio_lut[ASPECT_RATIO_CORE].value = (float)geom->base_width / geom->base_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_set_config_viewport(void)
|
|
|
|
{
|
|
|
|
if (g_settings.video.aspect_ratio < 0.0f)
|
|
|
|
{
|
|
|
|
const struct retro_game_geometry *geom = &g_extern.system.av_info.geometry;
|
|
|
|
if (geom->aspect_ratio > 0.0f && g_settings.video.aspect_ratio_auto)
|
|
|
|
aspectratio_lut[ASPECT_RATIO_CONFIG].value = geom->aspect_ratio;
|
|
|
|
else
|
|
|
|
aspectratio_lut[ASPECT_RATIO_CONFIG].value = (float)geom->base_width / geom->base_height; // 1:1 PAR.
|
|
|
|
}
|
2013-03-09 02:20:33 +00:00
|
|
|
else
|
2013-04-20 08:56:04 +00:00
|
|
|
aspectratio_lut[ASPECT_RATIO_CONFIG].value = g_settings.video.aspect_ratio;
|
2013-03-09 02:20:33 +00:00
|
|
|
}
|
|
|
|
|