Fix broken CRLF, and minor fixes for VC12.

This commit is contained in:
Themaister 2012-10-24 17:17:01 +02:00
parent 53868033b7
commit c2674328ec
3 changed files with 1406 additions and 1416 deletions

1367
file.c

File diff suppressed because it is too large Load Diff

View File

@ -1,456 +1,449 @@
/* RetroArch - A frontend for libretro. /* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen * Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* Copyright (C) 2011-2012 - Daniel De Matteis * Copyright (C) 2011-2012 - Daniel De Matteis
* *
* RetroArch is free software: you can redistribute it and/or modify it under the terms * 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- * 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. * 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; * 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 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details. * 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. * You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
// Win32/WGL context. // Win32/WGL context.
// TODO: Rewrite initializer lists - not supported on MSVC 2010/2012 #include "../../driver.h"
#include "../gfx_context.h"
#include "../../driver.h" #include "../gl_common.h"
#include "../gfx_context.h" #include "../gfx_common.h"
#include "../gl_common.h" #include <windows.h>
#include "../gfx_common.h" #include <string.h>
#include <windows.h>
#define IDI_ICON 1
#define IDI_ICON 1 #define MAX_MONITORS 9
#define MAX_MONITORS 9
static HWND g_hwnd;
static HWND g_hwnd; static HGLRC g_hrc;
static HGLRC g_hrc; static HDC g_hdc;
static HDC g_hdc; static HMONITOR g_last_hm;
static HMONITOR g_last_hm; static HMONITOR g_all_hms[MAX_MONITORS];
static HMONITOR g_all_hms[MAX_MONITORS]; static unsigned g_num_mons;
static unsigned g_num_mons;
static bool g_quit;
static bool g_quit; static bool g_inited;
static bool g_inited; static unsigned g_interval;
static unsigned g_interval;
static unsigned g_resize_width;
static unsigned g_resize_width; static unsigned g_resize_height;
static unsigned g_resize_height; static bool g_resized;
static bool g_resized;
static bool g_restore_desktop;
static bool g_restore_desktop;
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height);
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height); static void gfx_ctx_destroy(void);
static void gfx_ctx_destroy(void);
static BOOL (APIENTRY *p_swap_interval)(int);
static BOOL (APIENTRY *p_swap_interval)(int);
static void setup_pixel_format(HDC hdc)
static void setup_pixel_format(HDC hdc) {
{ PIXELFORMATDESCRIPTOR pfd = {0};
PIXELFORMATDESCRIPTOR pfd = {0}; pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1;
pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA;
pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32;
pfd.cColorBits = 32; pfd.cDepthBits = 0;
pfd.cDepthBits = 0; pfd.cStencilBits = 0;
pfd.cStencilBits = 0; pfd.iLayerType = PFD_MAIN_PLANE;
pfd.iLayerType = PFD_MAIN_PLANE;
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd); }
}
static void create_gl_context(HWND hwnd)
static void create_gl_context(HWND hwnd) {
{ g_hdc = GetDC(hwnd);
g_hdc = GetDC(hwnd); setup_pixel_format(g_hdc);
setup_pixel_format(g_hdc);
g_hrc = wglCreateContext(g_hdc);
g_hrc = wglCreateContext(g_hdc); if (g_hrc)
if (g_hrc) {
{ if (wglMakeCurrent(g_hdc, g_hrc))
if (wglMakeCurrent(g_hdc, g_hrc)) g_inited = true;
g_inited = true; else
else g_quit = true;
g_quit = true; }
} else
else g_quit = true;
g_quit = true; }
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
WPARAM wparam, LPARAM lparam) {
{ switch (message)
switch (message) {
{ case WM_SYSCOMMAND:
case WM_SYSCOMMAND: // Prevent screensavers, etc, while running.
// Prevent screensavers, etc, while running. switch (wparam)
switch (wparam) {
{ case SC_SCREENSAVE:
case SC_SCREENSAVE: case SC_MONITORPOWER:
case SC_MONITORPOWER: return 0;
return 0; }
} break;
break;
case WM_SYSKEYDOWN:
case WM_SYSKEYDOWN: switch (wparam)
switch (wparam) {
{ case VK_F10:
case VK_F10: case VK_MENU:
case VK_MENU: case VK_RSHIFT:
case VK_RSHIFT: return 0;
return 0; }
} break;
break;
case WM_CREATE:
case WM_CREATE: create_gl_context(hwnd);
create_gl_context(hwnd); return 0;
return 0;
case WM_CLOSE:
case WM_CLOSE: case WM_DESTROY:
case WM_DESTROY: case WM_QUIT:
case WM_QUIT: g_quit = true;
g_quit = true; return 0;
return 0;
case WM_SIZE:
case WM_SIZE: // Do not send resize message if we minimize.
// Do not send resize message if we minimize. if (wparam != SIZE_MAXHIDE && wparam != SIZE_MINIMIZED)
if (wparam != SIZE_MAXHIDE && wparam != SIZE_MINIMIZED) {
{ g_resize_width = LOWORD(lparam);
g_resize_width = LOWORD(lparam); g_resize_height = HIWORD(lparam);
g_resize_height = HIWORD(lparam); g_resized = true;
g_resized = true; }
} return 0;
return 0; }
}
return DefWindowProc(hwnd, message, wparam, lparam);
return DefWindowProc(hwnd, message, wparam, lparam); }
}
static void gfx_ctx_swap_interval(unsigned interval)
static void gfx_ctx_swap_interval(unsigned interval) {
{ g_interval = interval;
g_interval = interval;
if (g_hrc && p_swap_interval)
if (g_hrc && p_swap_interval) {
{ RARCH_LOG("[WGL]: wglSwapInterval(%u)\n", g_interval);
RARCH_LOG("[WGL]: wglSwapInterval(%u)\n", g_interval); if (!p_swap_interval(g_interval))
if (!p_swap_interval(g_interval)) RARCH_WARN("[WGL]: wglSwapInterval() failed.\n");
RARCH_WARN("[WGL]: wglSwapInterval() failed.\n"); }
} }
}
static void gfx_ctx_check_window(bool *quit,
static void gfx_ctx_check_window(bool *quit, bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
bool *resize, unsigned *width, unsigned *height, unsigned frame_count) {
{ (void)frame_count;
(void)frame_count;
MSG msg;
MSG msg; while (PeekMessage(&msg, g_hwnd, 0, 0, PM_REMOVE))
while (PeekMessage(&msg, g_hwnd, 0, 0, PM_REMOVE)) {
{ TranslateMessage(&msg);
TranslateMessage(&msg); DispatchMessage(&msg);
DispatchMessage(&msg); }
}
*quit = g_quit;
*quit = g_quit; if (g_resized)
if (g_resized) {
{ *resize = true;
*resize = true; *width = g_resize_width;
*width = g_resize_width; *height = g_resize_height;
*height = g_resize_height; g_resized = false;
g_resized = false; }
} }
}
static void gfx_ctx_swap_buffers(void)
static void gfx_ctx_swap_buffers(void) {
{ SwapBuffers(g_hdc);
SwapBuffers(g_hdc); }
}
static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_set_resize(unsigned width, unsigned height) {
{ (void)width;
(void)width; (void)height;
(void)height; }
}
static void gfx_ctx_update_window_title(bool reset)
static void gfx_ctx_update_window_title(bool reset) {
{ if (reset)
if (reset) gfx_window_title_reset();
gfx_window_title_reset();
char buf[128];
char buf[128]; if (gfx_window_title(buf, sizeof(buf)))
if (gfx_window_title(buf, sizeof(buf))) SetWindowText(g_hwnd, buf);
SetWindowText(g_hwnd, buf); }
}
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height) {
{ if (!g_hwnd)
if (!g_hwnd) {
{ RECT screen_rect;
RECT screen_rect; GetClientRect(GetDesktopWindow(), &screen_rect);
GetClientRect(GetDesktopWindow(), &screen_rect); *width = screen_rect.right - screen_rect.left;
*width = screen_rect.right - screen_rect.left; *height = screen_rect.bottom - screen_rect.top;
*height = screen_rect.bottom - screen_rect.top; }
} else
else {
{ *width = g_resize_width;
*width = g_resize_width; *height = g_resize_height;
*height = g_resize_height; }
} }
}
BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
{ g_all_hms[g_num_mons++] = hMonitor;
g_all_hms[g_num_mons++] = hMonitor; return TRUE;
return TRUE; }
}
static bool gfx_ctx_init(void)
static bool gfx_ctx_init(void) {
{ if (g_inited)
if (g_inited) return false;
return false;
g_quit = false;
g_quit = false; g_restore_desktop = false;
g_restore_desktop = false;
g_num_mons = 0;
g_num_mons = 0; EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0);
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0);
WNDCLASSEX wndclass = {0};
WNDCLASSEX wndclass = {0}; wndclass.cbSize = sizeof(wndclass);
wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wndclass.lpfnWndProc = WndProc;
wndclass.lpfnWndProc = WndProc; wndclass.hInstance = GetModuleHandle(NULL);
wndclass.hInstance = GetModuleHandle(NULL); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.lpszClassName = "RetroArch";
wndclass.lpszClassName = "RetroArch"; wndclass.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON));
wndclass.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON)); wndclass.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
wndclass.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);
if (!RegisterClassEx(&wndclass))
if (!RegisterClassEx(&wndclass)) return false;
return false;
return true;
return true; }
}
static bool set_fullscreen(unsigned width, unsigned height, char *dev_name)
static bool set_fullscreen(unsigned width, unsigned height, char *dev_name) {
{ DEVMODE devmode;
DEVMODE devmode; memset(&devmode, 0, sizeof(devmode));
memset(&devmode, 0, sizeof(devmode)); devmode.dmSize = sizeof(DEVMODE);
devmode.dmSize = sizeof(DEVMODE); devmode.dmPelsWidth = width;
devmode.dmPelsWidth = width; devmode.dmPelsHeight = height;
devmode.dmPelsHeight = height; devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
RARCH_LOG("[WGL]: Setting fullscreen to %ux%u on device %s.\n", width, height, dev_name);
RARCH_LOG("[WGL]: Setting fullscreen to %ux%u on device %s.\n", width, height, dev_name); return ChangeDisplaySettingsEx(dev_name, &devmode, NULL, CDS_FULLSCREEN, NULL) == DISP_CHANGE_SUCCESSFUL;
return ChangeDisplaySettingsEx(dev_name, &devmode, NULL, CDS_FULLSCREEN, NULL) == DISP_CHANGE_SUCCESSFUL; }
}
static void show_cursor(bool show)
static void show_cursor(bool show) {
{ if (show)
if (show) while (ShowCursor(TRUE) < 0);
while (ShowCursor(TRUE) < 0); else
else while (ShowCursor(FALSE) >= 0);
while (ShowCursor(FALSE) >= 0); }
}
static bool gfx_ctx_set_video_mode(
static bool gfx_ctx_set_video_mode( unsigned width, unsigned height,
unsigned width, unsigned height, unsigned bits, bool fullscreen)
unsigned bits, bool fullscreen) {
{ (void)bits;
(void)bits;
DWORD style;
DWORD style; MONITORINFOEX current_mon;
#if defined(_WIN32) memset(&current_mon, 0, sizeof(current_mon));
MONITORINFOEX current_mon; current_mon.cbSize = sizeof(MONITORINFOEX);
#else if (!g_last_hm)
MONITORINFOEX current_mon = {{0}}; g_last_hm = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTONEAREST);
#endif HMONITOR hm_to_use = g_last_hm;
current_mon.cbSize = sizeof(MONITORINFOEX);
if (!g_last_hm) unsigned fs_monitor = g_settings.video.monitor_index;
g_last_hm = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTONEAREST); if (fs_monitor && fs_monitor <= g_num_mons && g_all_hms[fs_monitor - 1])
HMONITOR hm_to_use = g_last_hm; hm_to_use = g_all_hms[fs_monitor - 1];
unsigned fs_monitor = g_settings.video.monitor_index; GetMonitorInfo(hm_to_use, (MONITORINFO*)&current_mon);
if (fs_monitor && fs_monitor <= g_num_mons && g_all_hms[fs_monitor - 1])
hm_to_use = g_all_hms[fs_monitor - 1]; g_resize_width = width;
g_resize_height = height;
GetMonitorInfo(hm_to_use, (MONITORINFO*)&current_mon);
bool windowed_full = g_settings.video.windowed_fullscreen;
g_resize_width = width; if (fullscreen)
g_resize_height = height; {
if (windowed_full)
bool windowed_full = g_settings.video.windowed_fullscreen; {
if (fullscreen) style = WS_EX_TOPMOST | WS_POPUP;
{ g_resize_width = width = current_mon.rcMonitor.right - current_mon.rcMonitor.left;
if (windowed_full) g_resize_height = height = current_mon.rcMonitor.bottom - current_mon.rcMonitor.top;
{ }
style = WS_EX_TOPMOST | WS_POPUP; else
g_resize_width = width = current_mon.rcMonitor.right - current_mon.rcMonitor.left; {
g_resize_height = height = current_mon.rcMonitor.bottom - current_mon.rcMonitor.top; style = WS_POPUP | WS_VISIBLE;
}
else if (!set_fullscreen(width, height, current_mon.szDevice))
{ goto error;
style = WS_POPUP | WS_VISIBLE;
// display settings might have changed, get new coordinates
if (!set_fullscreen(width, height, current_mon.szDevice)) GetMonitorInfo(hm_to_use, (MONITORINFO*)&current_mon);
goto error; g_restore_desktop = true;
}
// display settings might have changed, get new coordinates }
GetMonitorInfo(hm_to_use, (MONITORINFO*)&current_mon); else
g_restore_desktop = true; {
} style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
} RECT rect = {0};
else rect.right = width;
{ rect.bottom = height;
style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; AdjustWindowRect(&rect, style, FALSE);
RECT rect = {0}; width = rect.right - rect.left;
rect.right = width; height = rect.bottom - rect.top;
rect.bottom = height; }
AdjustWindowRect(&rect, style, FALSE);
width = rect.right - rect.left; g_hwnd = CreateWindowEx(0, "RetroArch", "RetroArch", style,
height = rect.bottom - rect.top; fullscreen ? current_mon.rcMonitor.left : CW_USEDEFAULT,
} fullscreen ? current_mon.rcMonitor.top : CW_USEDEFAULT,
width, height,
g_hwnd = CreateWindowEx(0, "RetroArch", "RetroArch", style, NULL, NULL, NULL, NULL);
fullscreen ? current_mon.rcMonitor.left : CW_USEDEFAULT,
fullscreen ? current_mon.rcMonitor.top : CW_USEDEFAULT, if (!g_hwnd)
width, height, goto error;
NULL, NULL, NULL, NULL);
gfx_ctx_update_window_title(true);
if (!g_hwnd)
goto error; if (!fullscreen || windowed_full)
{
gfx_ctx_update_window_title(true); ShowWindow(g_hwnd, SW_RESTORE);
UpdateWindow(g_hwnd);
if (!fullscreen || windowed_full) SetForegroundWindow(g_hwnd);
{ SetFocus(g_hwnd);
ShowWindow(g_hwnd, SW_RESTORE); }
UpdateWindow(g_hwnd);
SetForegroundWindow(g_hwnd); show_cursor(!fullscreen);
SetFocus(g_hwnd);
} // Wait until GL context is created (or failed to do so ...)
MSG msg;
show_cursor(!fullscreen); while (!g_inited && !g_quit && GetMessage(&msg, g_hwnd, 0, 0))
{
// Wait until GL context is created (or failed to do so ...) TranslateMessage(&msg);
MSG msg; DispatchMessage(&msg);
while (!g_inited && !g_quit && GetMessage(&msg, g_hwnd, 0, 0)) }
{
TranslateMessage(&msg); if (g_quit)
DispatchMessage(&msg); goto error;
}
p_swap_interval = (BOOL (APIENTRY *)(int))wglGetProcAddress("wglSwapIntervalEXT");
if (g_quit)
goto error; gfx_ctx_swap_interval(g_interval);
p_swap_interval = (BOOL (APIENTRY *)(int))wglGetProcAddress("wglSwapIntervalEXT"); driver.display_type = RARCH_DISPLAY_WIN32;
driver.video_display = 0;
gfx_ctx_swap_interval(g_interval); driver.video_window = (uintptr_t)g_hwnd;
driver.display_type = RARCH_DISPLAY_WIN32; return true;
driver.video_display = 0;
driver.video_window = (uintptr_t)g_hwnd; error:
gfx_ctx_destroy();
return true; return false;
}
error:
gfx_ctx_destroy(); static void gfx_ctx_destroy(void)
return false; {
} if (g_hrc)
{
static void gfx_ctx_destroy(void) wglMakeCurrent(NULL, NULL);
{ wglDeleteContext(g_hrc);
if (g_hrc) g_hrc = NULL;
{ }
wglMakeCurrent(NULL, NULL);
wglDeleteContext(g_hrc); if (g_hwnd && g_hdc)
g_hrc = NULL; {
} ReleaseDC(g_hwnd, g_hdc);
g_hdc = NULL;
if (g_hwnd && g_hdc) }
{
ReleaseDC(g_hwnd, g_hdc); if (g_hwnd)
g_hdc = NULL; {
} g_last_hm = MonitorFromWindow(g_hwnd, MONITOR_DEFAULTTONEAREST);
DestroyWindow(g_hwnd);
if (g_hwnd) UnregisterClass("RetroArch", GetModuleHandle(NULL));
{ g_hwnd = NULL;
g_last_hm = MonitorFromWindow(g_hwnd, MONITOR_DEFAULTTONEAREST); }
DestroyWindow(g_hwnd);
UnregisterClass("RetroArch", GetModuleHandle(NULL)); if (g_restore_desktop)
g_hwnd = NULL; {
} MONITORINFOEX current_mon;
memset(&current_mon, 0, sizeof(current_mon));
if (g_restore_desktop) current_mon.cbSize = sizeof(MONITORINFOEX);
{ GetMonitorInfo(g_last_hm, (MONITORINFO*)&current_mon);
#if defined(_WIN32) ChangeDisplaySettingsEx(current_mon.szDevice, NULL, NULL, 0, NULL);
MONITORINFOEX current_mon; g_restore_desktop = false;
#else }
MONITORINFOEX current_mon = {{0}};
#endif g_inited = false;
current_mon.cbSize = sizeof(MONITORINFOEX); }
GetMonitorInfo(g_last_hm, (MONITORINFO*)&current_mon);
ChangeDisplaySettingsEx(current_mon.szDevice, NULL, NULL, 0, NULL); static void gfx_ctx_input_driver(const input_driver_t **input, void **input_data)
g_restore_desktop = false; {
} void *dinput = input_dinput.init();
*input = dinput ? &input_dinput : NULL;
g_inited = false; *input_data = dinput;
} }
static void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) static bool gfx_ctx_has_focus(void)
{ {
void *dinput = input_dinput.init(); if (!g_inited)
*input = dinput ? &input_dinput : NULL; return false;
*input_data = dinput;
} return GetFocus() == g_hwnd;
}
static bool gfx_ctx_has_focus(void)
{ static gfx_ctx_proc_t gfx_ctx_get_proc_address(const char *symbol)
if (!g_inited) {
return false; return (gfx_ctx_proc_t)wglGetProcAddress(symbol);
}
return GetFocus() == g_hwnd;
} static bool gfx_ctx_bind_api(enum gfx_ctx_api api)
{
static gfx_ctx_proc_t gfx_ctx_get_proc_address(const char *symbol) return api == GFX_CTX_OPENGL_API;
{ }
return (gfx_ctx_proc_t)wglGetProcAddress(symbol);
} static bool gfx_ctx_init_egl_image_buffer(const video_info_t *video)
{
static bool gfx_ctx_bind_api(enum gfx_ctx_api api) return false;
{ }
return api == GFX_CTX_OPENGL_API;
} static bool gfx_ctx_write_egl_image(const void *frame, unsigned width, unsigned height, unsigned pitch, bool rgb32, unsigned index, void **image_handle)
{
static bool gfx_ctx_init_egl_image_buffer(const video_info_t *video) return false;
{ }
return false;
} const gfx_ctx_driver_t gfx_ctx_wgl = {
gfx_ctx_init,
static bool gfx_ctx_write_egl_image(const void *frame, unsigned width, unsigned height, unsigned pitch, bool rgb32, unsigned index, void **image_handle) gfx_ctx_destroy,
{ gfx_ctx_bind_api,
return false; gfx_ctx_swap_interval,
} gfx_ctx_set_video_mode,
gfx_ctx_get_video_size,
const gfx_ctx_driver_t gfx_ctx_wgl = { NULL,
gfx_ctx_init, gfx_ctx_update_window_title,
gfx_ctx_destroy, gfx_ctx_check_window,
gfx_ctx_bind_api, gfx_ctx_set_resize,
gfx_ctx_swap_interval, gfx_ctx_has_focus,
gfx_ctx_set_video_mode, gfx_ctx_swap_buffers,
gfx_ctx_get_video_size, gfx_ctx_input_driver,
NULL, gfx_ctx_get_proc_address,
gfx_ctx_update_window_title, gfx_ctx_init_egl_image_buffer,
gfx_ctx_check_window, gfx_ctx_write_egl_image,
gfx_ctx_set_resize, "wgl",
gfx_ctx_has_focus, };
gfx_ctx_swap_buffers,
gfx_ctx_input_driver,
gfx_ctx_get_proc_address,
gfx_ctx_init_egl_image_buffer,
gfx_ctx_write_egl_image,
"wgl",
};

View File

@ -1,275 +1,275 @@
/* RetroArch - A frontend for libretro. /* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen * Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* *
* RetroArch is free software: you can redistribute it and/or modify it under the terms * 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- * 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. * 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; * 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 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details. * 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. * You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "scaler_int.h" #include "scaler_int.h"
#ifdef SCALER_NO_SIMD #ifdef SCALER_NO_SIMD
#undef __SSE2__ #undef __SSE2__
#endif #endif
#if defined(__SSE2__) #if defined(__SSE2__)
#include <emmintrin.h> #include <emmintrin.h>
#endif #endif
static inline uint64_t build_argb64(uint16_t a, uint16_t r, uint16_t g, uint16_t b) static inline uint64_t build_argb64(uint16_t a, uint16_t r, uint16_t g, uint16_t b)
{ {
return ((uint64_t)a << 48) | ((uint64_t)r << 32) | ((uint64_t)g << 16) | ((uint64_t)b << 0); return ((uint64_t)a << 48) | ((uint64_t)r << 32) | ((uint64_t)g << 16) | ((uint64_t)b << 0);
} }
static inline uint8_t clamp_8bit(int16_t col) static inline uint8_t clamp_8bit(int16_t col)
{ {
if (col > 255) if (col > 255)
return 255; return 255;
else if (col < 0) else if (col < 0)
return 0; return 0;
else else
return (uint8_t)col; return (uint8_t)col;
} }
// ARGB8888 scaler is split in two: // ARGB8888 scaler is split in two:
// //
// First, horizontal scaler is applied. // First, horizontal scaler is applied.
// Here, all 8-bit channels are expanded to 16-bit. Values are then shifted 7 to left to occupy 15 bits. // Here, all 8-bit channels are expanded to 16-bit. Values are then shifted 7 to left to occupy 15 bits.
// The sign bit is kept empty as we have to do signed multiplication for the filter. // The sign bit is kept empty as we have to do signed multiplication for the filter.
// A mulhi [(a * b) >> 16] is applied which loses some precision, but is very efficient for SIMD. // A mulhi [(a * b) >> 16] is applied which loses some precision, but is very efficient for SIMD.
// It is accurate enough for 8-bit purposes. // It is accurate enough for 8-bit purposes.
// //
// The fixed point 1.0 for filter is (1 << 14). After horizontal scale, the output is kept // The fixed point 1.0 for filter is (1 << 14). After horizontal scale, the output is kept
// with 16-bit channels, and will now have 13 bits of precision as [(a * (1 << 14)) >> 16] is effectively a right shift by 2. // with 16-bit channels, and will now have 13 bits of precision as [(a * (1 << 14)) >> 16] is effectively a right shift by 2.
// //
// Vertical scaler takes the 13 bit channels, and performs the same mulhi steps. // Vertical scaler takes the 13 bit channels, and performs the same mulhi steps.
// Another 2 bits of precision is lost, which ends up as 11 bits. // Another 2 bits of precision is lost, which ends up as 11 bits.
// Scaling is now complete. Channels are shifted right by 3, and saturated into 8-bit values. // Scaling is now complete. Channels are shifted right by 3, and saturated into 8-bit values.
// //
// The C version of scalers perform the exact same operations as the SIMD code for testing purposes. // The C version of scalers perform the exact same operations as the SIMD code for testing purposes.
#if defined(__SSE2__) #if defined(__SSE2__)
void scaler_argb8888_vert(const struct scaler_ctx *ctx, void *output_, int stride) void scaler_argb8888_vert(const struct scaler_ctx *ctx, void *output_, int stride)
{ {
const uint64_t *input = ctx->scaled.frame; const uint64_t *input = ctx->scaled.frame;
uint32_t *output = (uint32_t*)output_; uint32_t *output = (uint32_t*)output_;
const int16_t *filter_vert = ctx->vert.filter; const int16_t *filter_vert = ctx->vert.filter;
for (int h = 0; h < ctx->out_height; h++, filter_vert += ctx->vert.filter_stride, output += stride >> 2) for (int h = 0; h < ctx->out_height; h++, filter_vert += ctx->vert.filter_stride, output += stride >> 2)
{ {
const uint64_t *input_base = input + ctx->vert.filter_pos[h] * (ctx->scaled.stride >> 3); const uint64_t *input_base = input + ctx->vert.filter_pos[h] * (ctx->scaled.stride >> 3);
for (int w = 0; w < ctx->out_width; w++) for (int w = 0; w < ctx->out_width; w++)
{ {
__m128i res = _mm_setzero_si128(); __m128i res = _mm_setzero_si128();
const uint64_t *input_base_y = input_base + w; const uint64_t *input_base_y = input_base + w;
size_t y; size_t y;
for (y = 0; (y + 1) < ctx->vert.filter_len; y += 2, input_base_y += (ctx->scaled.stride >> 2)) for (y = 0; (y + 1) < ctx->vert.filter_len; y += 2, input_base_y += (ctx->scaled.stride >> 2))
{ {
__m128i coeff = _mm_set_epi64x(filter_vert[y + 1] * 0x0001000100010001ll, filter_vert[y + 0] * 0x0001000100010001ll); __m128i coeff = _mm_set_epi64x(filter_vert[y + 1] * 0x0001000100010001ll, filter_vert[y + 0] * 0x0001000100010001ll);
__m128i col = _mm_set_epi64x(input_base_y[ctx->scaled.stride >> 3], input_base_y[0]); __m128i col = _mm_set_epi64x(input_base_y[ctx->scaled.stride >> 3], input_base_y[0]);
res = _mm_adds_epi16(_mm_mulhi_epi16(col, coeff), res); res = _mm_adds_epi16(_mm_mulhi_epi16(col, coeff), res);
} }
for (; y < ctx->vert.filter_len; y++, input_base_y += (ctx->scaled.stride >> 3)) for (; y < ctx->vert.filter_len; y++, input_base_y += (ctx->scaled.stride >> 3))
{ {
__m128i coeff = _mm_set_epi64x(0, filter_vert[y] * 0x0001000100010001ll); __m128i coeff = _mm_set_epi64x(0, filter_vert[y] * 0x0001000100010001ll);
__m128i col = _mm_set_epi64x(0, input_base_y[0]); __m128i col = _mm_set_epi64x(0, input_base_y[0]);
res = _mm_adds_epi16(_mm_mulhi_epi16(col, coeff), res); res = _mm_adds_epi16(_mm_mulhi_epi16(col, coeff), res);
} }
res = _mm_adds_epi16(_mm_srli_si128(res, 8), res); res = _mm_adds_epi16(_mm_srli_si128(res, 8), res);
res = _mm_srai_epi16(res, (7 - 2 - 2)); res = _mm_srai_epi16(res, (7 - 2 - 2));
__m128i final = _mm_packus_epi16(res, res); __m128i final = _mm_packus_epi16(res, res);
output[w] = _mm_cvtsi128_si32(final); output[w] = _mm_cvtsi128_si32(final);
} }
} }
} }
#else #else
void scaler_argb8888_vert(const struct scaler_ctx *ctx, void *output_, int stride) void scaler_argb8888_vert(const struct scaler_ctx *ctx, void *output_, int stride)
{ {
const uint64_t *input = ctx->scaled.frame; const uint64_t *input = ctx->scaled.frame;
uint32_t *output = (uint32_t*)output_; uint32_t *output = (uint32_t*)output_;
const int16_t *filter_vert = ctx->vert.filter; const int16_t *filter_vert = ctx->vert.filter;
for (int h = 0; h < ctx->out_height; h++, filter_vert += ctx->vert.filter_stride, output += stride >> 2) for (int h = 0; h < ctx->out_height; h++, filter_vert += ctx->vert.filter_stride, output += stride >> 2)
{ {
const uint64_t *input_base = input + ctx->vert.filter_pos[h] * (ctx->scaled.stride >> 3); const uint64_t *input_base = input + ctx->vert.filter_pos[h] * (ctx->scaled.stride >> 3);
for (int w = 0; w < ctx->out_width; w++) for (int w = 0; w < ctx->out_width; w++)
{ {
int16_t res_a = 0; int16_t res_a = 0;
int16_t res_r = 0; int16_t res_r = 0;
int16_t res_g = 0; int16_t res_g = 0;
int16_t res_b = 0; int16_t res_b = 0;
const uint64_t *input_base_y = input_base + w; const uint64_t *input_base_y = input_base + w;
for (size_t y = 0; y < ctx->vert.filter_len; y++, input_base_y += (ctx->scaled.stride >> 3)) for (size_t y = 0; y < ctx->vert.filter_len; y++, input_base_y += (ctx->scaled.stride >> 3))
{ {
uint64_t col = *input_base_y; uint64_t col = *input_base_y;
int16_t a = (col >> 48) & 0xffff; int16_t a = (col >> 48) & 0xffff;
int16_t r = (col >> 32) & 0xffff; int16_t r = (col >> 32) & 0xffff;
int16_t g = (col >> 16) & 0xffff; int16_t g = (col >> 16) & 0xffff;
int16_t b = (col >> 0) & 0xffff; int16_t b = (col >> 0) & 0xffff;
int16_t coeff = filter_vert[y]; int16_t coeff = filter_vert[y];
res_a += (a * coeff) >> 16; res_a += (a * coeff) >> 16;
res_r += (r * coeff) >> 16; res_r += (r * coeff) >> 16;
res_g += (g * coeff) >> 16; res_g += (g * coeff) >> 16;
res_b += (b * coeff) >> 16; res_b += (b * coeff) >> 16;
} }
res_a >>= (7 - 2 - 2); res_a >>= (7 - 2 - 2);
res_r >>= (7 - 2 - 2); res_r >>= (7 - 2 - 2);
res_g >>= (7 - 2 - 2); res_g >>= (7 - 2 - 2);
res_b >>= (7 - 2 - 2); res_b >>= (7 - 2 - 2);
output[w] = (clamp_8bit(res_a) << 24) | (clamp_8bit(res_r) << 16) | (clamp_8bit(res_g) << 8) | (clamp_8bit(res_b) << 0); output[w] = (clamp_8bit(res_a) << 24) | (clamp_8bit(res_r) << 16) | (clamp_8bit(res_g) << 8) | (clamp_8bit(res_b) << 0);
} }
} }
} }
#endif #endif
#if defined(__SSE2__) #if defined(__SSE2__)
void scaler_argb8888_horiz(const struct scaler_ctx *ctx, const void *input_, int stride) void scaler_argb8888_horiz(const struct scaler_ctx *ctx, const void *input_, int stride)
{ {
const uint32_t *input = (const uint32_t*)input_; const uint32_t *input = (const uint32_t*)input_;
uint64_t *output = ctx->scaled.frame; uint64_t *output = ctx->scaled.frame;
for (int h = 0; h < ctx->scaled.height; h++, input += stride >> 2, output += ctx->scaled.stride >> 3) for (int h = 0; h < ctx->scaled.height; h++, input += stride >> 2, output += ctx->scaled.stride >> 3)
{ {
const int16_t *filter_horiz = ctx->horiz.filter; const int16_t *filter_horiz = ctx->horiz.filter;
for (int w = 0; w < ctx->scaled.width; w++, filter_horiz += ctx->horiz.filter_stride) for (int w = 0; w < ctx->scaled.width; w++, filter_horiz += ctx->horiz.filter_stride)
{ {
__m128i res = _mm_setzero_si128(); __m128i res = _mm_setzero_si128();
const uint32_t *input_base_x = input + ctx->horiz.filter_pos[w]; const uint32_t *input_base_x = input + ctx->horiz.filter_pos[w];
size_t x; size_t x;
for (x = 0; (x + 1) < ctx->horiz.filter_len; x += 2) for (x = 0; (x + 1) < ctx->horiz.filter_len; x += 2)
{ {
__m128i coeff = _mm_set_epi64x(filter_horiz[x + 1] * 0x0001000100010001ll, filter_horiz[x + 0] * 0x0001000100010001ll); __m128i coeff = _mm_set_epi64x(filter_horiz[x + 1] * 0x0001000100010001ll, filter_horiz[x + 0] * 0x0001000100010001ll);
__m128i col = _mm_unpacklo_epi8(_mm_set_epi64x(0, __m128i col = _mm_unpacklo_epi8(_mm_set_epi64x(0,
((uint64_t)input_base_x[x + 1] << 32) | input_base_x[x + 0]), _mm_setzero_si128()); ((uint64_t)input_base_x[x + 1] << 32) | input_base_x[x + 0]), _mm_setzero_si128());
col = _mm_slli_epi16(col, 7); col = _mm_slli_epi16(col, 7);
res = _mm_adds_epi16(_mm_mulhi_epi16(col, coeff), res); res = _mm_adds_epi16(_mm_mulhi_epi16(col, coeff), res);
} }
for (; x < ctx->horiz.filter_len; x++) for (; x < ctx->horiz.filter_len; x++)
{ {
__m128i coeff = _mm_set_epi64x(0, filter_horiz[x] * 0x0001000100010001ll); __m128i coeff = _mm_set_epi64x(0, filter_horiz[x] * 0x0001000100010001ll);
__m128i col = _mm_unpacklo_epi8(_mm_set_epi32(0, 0, 0, input_base_x[x]), _mm_setzero_si128()); __m128i col = _mm_unpacklo_epi8(_mm_set_epi32(0, 0, 0, input_base_x[x]), _mm_setzero_si128());
col = _mm_slli_epi16(col, 7); col = _mm_slli_epi16(col, 7);
res = _mm_adds_epi16(_mm_mulhi_epi16(col, coeff), res); res = _mm_adds_epi16(_mm_mulhi_epi16(col, coeff), res);
} }
res = _mm_adds_epi16(_mm_srli_si128(res, 8), res); res = _mm_adds_epi16(_mm_srli_si128(res, 8), res);
#ifdef __x86_64__ #ifdef __x86_64__
output[w] = _mm_cvtsi128_si64(res); output[w] = _mm_cvtsi128_si64(res);
#else // 32-bit doesn't have si64. Do it in two steps. #else // 32-bit doesn't have si64. Do it in two steps.
union union
{ {
uint32_t *u32; uint32_t *u32;
uint64_t *u64; uint64_t *u64;
} u; } u;
u.u64 = output + w; u.u64 = output + w;
u.u32[0] = _mm_cvtsi128_si32(res); u.u32[0] = _mm_cvtsi128_si32(res);
u.u32[1] = _mm_cvtsi128_si32(_mm_srli_si128(res, 4)); u.u32[1] = _mm_cvtsi128_si32(_mm_srli_si128(res, 4));
#endif #endif
} }
} }
} }
#else #else
void scaler_argb8888_horiz(const struct scaler_ctx *ctx, const void *input_, int stride) void scaler_argb8888_horiz(const struct scaler_ctx *ctx, const void *input_, int stride)
{ {
const uint32_t *input = (uint32_t*)input_; const uint32_t *input = (uint32_t*)input_;
uint64_t *output = ctx->scaled.frame; uint64_t *output = ctx->scaled.frame;
for (int h = 0; h < ctx->scaled.height; h++, input += stride >> 2, output += ctx->scaled.stride >> 3) for (int h = 0; h < ctx->scaled.height; h++, input += stride >> 2, output += ctx->scaled.stride >> 3)
{ {
const int16_t *filter_horiz = ctx->horiz.filter; const int16_t *filter_horiz = ctx->horiz.filter;
for (int w = 0; w < ctx->scaled.width; w++, filter_horiz += ctx->horiz.filter_stride) for (int w = 0; w < ctx->scaled.width; w++, filter_horiz += ctx->horiz.filter_stride)
{ {
const uint32_t *input_base_x = input + ctx->horiz.filter_pos[w]; const uint32_t *input_base_x = input + ctx->horiz.filter_pos[w];
int16_t res_a = 0; int16_t res_a = 0;
int16_t res_r = 0; int16_t res_r = 0;
int16_t res_g = 0; int16_t res_g = 0;
int16_t res_b = 0; int16_t res_b = 0;
for (size_t x = 0; x < ctx->horiz.filter_len; x++) for (size_t x = 0; x < ctx->horiz.filter_len; x++)
{ {
uint32_t col = input_base_x[x]; uint32_t col = input_base_x[x];
int16_t a = (col >> (24 - 7)) & (0xff << 7); int16_t a = (col >> (24 - 7)) & (0xff << 7);
int16_t r = (col >> (16 - 7)) & (0xff << 7); int16_t r = (col >> (16 - 7)) & (0xff << 7);
int16_t g = (col >> ( 8 - 7)) & (0xff << 7); int16_t g = (col >> ( 8 - 7)) & (0xff << 7);
int16_t b = (col << ( 0 + 7)) & (0xff << 7); int16_t b = (col << ( 0 + 7)) & (0xff << 7);
int16_t coeff = filter_horiz[x]; int16_t coeff = filter_horiz[x];
res_a += (a * coeff) >> 16; res_a += (a * coeff) >> 16;
res_r += (r * coeff) >> 16; res_r += (r * coeff) >> 16;
res_g += (g * coeff) >> 16; res_g += (g * coeff) >> 16;
res_b += (b * coeff) >> 16; res_b += (b * coeff) >> 16;
} }
output[w] = build_argb64(res_a, res_r, res_g, res_b); output[w] = build_argb64(res_a, res_r, res_g, res_b);
} }
} }
} }
#endif #endif
void scaler_argb8888_point_special(const struct scaler_ctx *ctx, void scaler_argb8888_point_special(const struct scaler_ctx *ctx,
void *output_, const void *input_, void *output_, const void *input_,
int out_width, int out_height, int out_width, int out_height,
int in_width, int in_height, int in_width, int in_height,
int out_stride, int in_stride) int out_stride, int in_stride)
{ {
(void)ctx; (void)ctx;
int x_pos = (1 << 15) * in_width / out_width - (1 << 15); int x_pos = (1 << 15) * in_width / out_width - (1 << 15);
int x_step = (1 << 16) * in_width / out_width; int x_step = (1 << 16) * in_width / out_width;
int y_pos = (1 << 15) * in_height / out_height - (1 << 15); int y_pos = (1 << 15) * in_height / out_height - (1 << 15);
int y_step = (1 << 16) * in_height / out_height; int y_step = (1 << 16) * in_height / out_height;
if (x_pos < 0) if (x_pos < 0)
x_pos = 0; x_pos = 0;
if (y_pos < 0) if (y_pos < 0)
y_pos = 0; y_pos = 0;
const uint32_t *input = (const uint32_t*)input_; const uint32_t *input = (const uint32_t*)input_;
uint32_t *output = (uint32_t*)output_; uint32_t *output = (uint32_t*)output_;
for (int h = 0; h < out_height; h++, y_pos += y_step, output += out_stride >> 2) for (int h = 0; h < out_height; h++, y_pos += y_step, output += out_stride >> 2)
{ {
int x = x_pos; int x = x_pos;
const uint32_t *inp = input + (y_pos >> 16) * (in_stride >> 2); const uint32_t *inp = input + (y_pos >> 16) * (in_stride >> 2);
for (int w = 0; w < out_width; w++, x += x_step) for (int w = 0; w < out_width; w++, x += x_step)
output[w] = inp[x >> 16]; output[w] = inp[x >> 16];
} }
} }