mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 00:39:53 +00:00
[UWP] Add ANGLE context
This commit is contained in:
parent
7cbdd845ad
commit
bfe167fae8
361
gfx/drivers_context/uwp_egl_ctx.c
Normal file
361
gfx/drivers_context/uwp_egl_ctx.c
Normal file
@ -0,0 +1,361 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
||||
*
|
||||
* 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 <math.h>
|
||||
|
||||
/* UWP/ANGLE EGL context. */
|
||||
|
||||
/* necessary for mingw32 multimon defines: */
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0500 //_WIN32_WINNT_WIN2K
|
||||
#endif
|
||||
|
||||
#include <tchar.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <dynamic/dylib.h>
|
||||
#include <string/stdstring.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../../config.h"
|
||||
#endif
|
||||
|
||||
#include "../../uwp/uwp_func.h"
|
||||
#include "gfx/common/win32_common.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../dynamic.h"
|
||||
#include "../../retroarch.h"
|
||||
#include "../../verbosity.h"
|
||||
#include "../../frontend/frontend_driver.h"
|
||||
|
||||
#include "../common/egl_common.h"
|
||||
#include "../common/angle_common.h"
|
||||
#include "../common/gl_common.h"
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
static dylib_t dll_handle = NULL; /* Handle to libGLESv2.dll */
|
||||
#endif
|
||||
|
||||
static void gfx_ctx_uwp_destroy(void *data);
|
||||
|
||||
static egl_ctx_data_t uwp_egl;
|
||||
static int uwp_interval = 0;
|
||||
static enum gfx_ctx_api uwp_api = GFX_CTX_OPENGL_ES_API;
|
||||
|
||||
typedef struct gfx_ctx_cgl_data
|
||||
{
|
||||
void *empty;
|
||||
} gfx_ctx_uwp_data_t;
|
||||
|
||||
bool create_gles_context(void* corewindow)
|
||||
{
|
||||
EGLint n, major, minor;
|
||||
EGLint format;
|
||||
EGLint attribs[] = {
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_ALPHA_SIZE, 8,
|
||||
EGL_DEPTH_SIZE, 16,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint context_attributes[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
if (!angle_init_context(&uwp_egl, EGL_DEFAULT_DISPLAY,
|
||||
&major, &minor, &n, attribs, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!egl_get_native_visual_id(&uwp_egl, &format))
|
||||
goto error;
|
||||
|
||||
if (!egl_create_context(&uwp_egl, context_attributes))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!uwp_egl_create_surface(&uwp_egl))
|
||||
goto error;
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
return false;
|
||||
}
|
||||
|
||||
static void gfx_ctx_uwp_swap_interval(void *data, int interval)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
switch (uwp_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
if (uwp_interval != interval)
|
||||
{
|
||||
uwp_interval = interval;
|
||||
egl_set_swap_interval(&uwp_egl, uwp_interval);
|
||||
}
|
||||
break;
|
||||
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void gfx_ctx_uwp_check_window(void *data, bool *quit,
|
||||
bool *resize, unsigned *width, unsigned *height,
|
||||
bool is_shutdown)
|
||||
{
|
||||
win32_check_window(quit, resize, width, height);
|
||||
}
|
||||
|
||||
|
||||
static gfx_ctx_proc_t gfx_ctx_uwp_get_proc_address(const char* symbol)
|
||||
{
|
||||
#ifdef HAVE_DYNAMIC
|
||||
return (gfx_ctx_proc_t)GetProcAddress((HINSTANCE)dll_handle, symbol);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void gfx_ctx_uwp_swap_buffers(void *data, void *data2)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
switch (uwp_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
egl_swap_buffers(&uwp_egl);
|
||||
break;
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static bool gfx_ctx_uwp_set_resize(void *data,
|
||||
unsigned width, unsigned height)
|
||||
{
|
||||
(void)data;
|
||||
(void)width;
|
||||
(void)height;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void gfx_ctx_uwp_get_video_size(void *data,
|
||||
unsigned *width, unsigned *height)
|
||||
{
|
||||
bool quit;
|
||||
bool resize;
|
||||
win32_check_window(&quit, &resize, width, height);
|
||||
}
|
||||
|
||||
static void *gfx_ctx_uwp_init(video_frame_info_t *video_info, void *video_driver)
|
||||
{
|
||||
gfx_ctx_uwp_data_t *uwp = (gfx_ctx_uwp_data_t*)calloc(1, sizeof(*uwp));
|
||||
|
||||
if (!uwp)
|
||||
return NULL;
|
||||
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
dll_handle = dylib_load("libGLESv2.dll");
|
||||
#endif
|
||||
|
||||
return uwp;
|
||||
}
|
||||
|
||||
static void gfx_ctx_uwp_destroy(void *data)
|
||||
{
|
||||
gfx_ctx_uwp_data_t *wgl = (gfx_ctx_uwp_data_t*)data;
|
||||
|
||||
switch (uwp_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
egl_destroy(&uwp_egl);
|
||||
break;
|
||||
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
dylib_close(dll_handle);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static bool gfx_ctx_uwp_set_video_mode(void *data,
|
||||
video_frame_info_t *video_info,
|
||||
unsigned width, unsigned height,
|
||||
bool fullscreen)
|
||||
{
|
||||
if (!win32_set_video_mode(NULL, width, height, fullscreen))
|
||||
{
|
||||
RARCH_ERR("[UWP EGL]: win32_set_video_mode failed.\n");
|
||||
}
|
||||
|
||||
if (!create_gles_context(uwp_get_corewindow())) {
|
||||
RARCH_ERR("[UWP EGL]: create_gles_context failed.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
gfx_ctx_uwp_swap_interval(data, uwp_interval);
|
||||
return true;
|
||||
|
||||
error:
|
||||
gfx_ctx_uwp_destroy(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void gfx_ctx_uwp_input_driver(void *data,
|
||||
const char *joypad_name,
|
||||
input_driver_t **input, void **input_data)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
/* Plain xinput is supported on UWP, but it
|
||||
* supports joypad only (uwp driver was added later) */
|
||||
if (string_is_equal(settings->arrays.input_driver, "xinput"))
|
||||
{
|
||||
void* xinput = input_xinput.init(joypad_name);
|
||||
*input = xinput ? (input_driver_t*)&input_xinput : NULL;
|
||||
*input_data = xinput;
|
||||
}
|
||||
else
|
||||
{
|
||||
void* uwp = input_uwp.init(joypad_name);
|
||||
*input = uwp ? (input_driver_t*)&input_uwp : NULL;
|
||||
*input_data = uwp;
|
||||
}
|
||||
}
|
||||
|
||||
static bool gfx_ctx_uwp_has_focus(void *data)
|
||||
{
|
||||
return win32_has_focus();
|
||||
}
|
||||
|
||||
static void gfx_ctx_uwp_show_mouse(void* data, bool state)
|
||||
{
|
||||
(void)data;
|
||||
win32_show_cursor(state);
|
||||
}
|
||||
|
||||
static enum gfx_ctx_api gfx_ctx_uwp_get_api(void *data)
|
||||
{
|
||||
return uwp_api;
|
||||
}
|
||||
|
||||
static bool gfx_ctx_uwp_bind_api(void *data,
|
||||
enum gfx_ctx_api api, unsigned major, unsigned minor)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
if (api == GFX_CTX_OPENGL_ES_API)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static void gfx_ctx_uwp_bind_hw_render(void *data, bool enable)
|
||||
{
|
||||
switch (uwp_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
egl_bind_hw_render(&uwp_egl, enable);
|
||||
break;
|
||||
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t gfx_ctx_uwp_get_flags(void *data)
|
||||
{
|
||||
uint32_t flags = 0;
|
||||
|
||||
switch (uwp_api)
|
||||
{
|
||||
case GFX_CTX_OPENGL_ES_API:
|
||||
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
|
||||
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_SLANG);
|
||||
#endif
|
||||
#ifdef HAVE_GLSL
|
||||
BIT32_SET(flags, GFX_CTX_FLAGS_SHADERS_GLSL);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case GFX_CTX_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
const gfx_ctx_driver_t gfx_ctx_uwp = {
|
||||
gfx_ctx_uwp_init,
|
||||
gfx_ctx_uwp_destroy,
|
||||
gfx_ctx_uwp_get_api,
|
||||
gfx_ctx_uwp_bind_api,
|
||||
gfx_ctx_uwp_swap_interval,
|
||||
gfx_ctx_uwp_set_video_mode,
|
||||
gfx_ctx_uwp_get_video_size,
|
||||
NULL, /* get refresh rate */
|
||||
NULL, /* get video output size */
|
||||
NULL, /* get video output prev */
|
||||
NULL, /* get video output next */
|
||||
win32_get_metrics,
|
||||
NULL,
|
||||
NULL, /* update title */
|
||||
gfx_ctx_uwp_check_window,
|
||||
gfx_ctx_uwp_set_resize,
|
||||
gfx_ctx_uwp_has_focus,
|
||||
NULL, /* suppress screensaver */
|
||||
true, /* has_windowed */
|
||||
gfx_ctx_uwp_swap_buffers,
|
||||
gfx_ctx_uwp_input_driver,
|
||||
gfx_ctx_uwp_get_proc_address,
|
||||
NULL,
|
||||
NULL,
|
||||
gfx_ctx_uwp_show_mouse,
|
||||
"uwp",
|
||||
gfx_ctx_uwp_get_flags, /* get flags */
|
||||
NULL, /* set flags */
|
||||
gfx_ctx_uwp_bind_hw_render,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
@ -279,6 +279,10 @@ VIDEO CONTEXT
|
||||
#include "../gfx/common/angle_common.c"
|
||||
#endif
|
||||
|
||||
#if defined(__WINRT__)
|
||||
#include "../gfx/drivers_context/uwp_egl_ctx.c"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_X11)
|
||||
|
@ -477,6 +477,9 @@ static const gfx_ctx_driver_t *gfx_ctx_drivers[] = {
|
||||
#if defined(_WIN32) && !defined(__WINRT__) && (defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE) || defined(HAVE_VULKAN))
|
||||
&gfx_ctx_wgl,
|
||||
#endif
|
||||
#if defined(__WINRT__) && defined(HAVE_OPENGLES)
|
||||
&gfx_ctx_uwp,
|
||||
#endif
|
||||
#if defined(HAVE_WAYLAND)
|
||||
&gfx_ctx_wayland,
|
||||
#endif
|
||||
|
@ -22,6 +22,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
#include "../gfx/common/egl_common.h"
|
||||
bool uwp_egl_create_surface(egl_ctx_data_t* egl);
|
||||
#endif
|
||||
|
||||
extern char uwp_dir_install[PATH_MAX_LENGTH];
|
||||
extern char uwp_dir_data[PATH_MAX_LENGTH];
|
||||
extern char uwp_device_family[128];
|
||||
|
@ -581,6 +581,44 @@ extern "C" {
|
||||
CoreWindow::GetForCurrentThread()->PointerCursor = state ? ref new CoreCursor(CoreCursorType::Arrow, 0) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool win32_get_metrics(void* data,
|
||||
enum display_metric_types type, float* value)
|
||||
{
|
||||
int pixels_x = DisplayInformation::GetForCurrentView()->ScreenWidthInRawPixels;
|
||||
int pixels_y = DisplayInformation::GetForCurrentView()->ScreenHeightInRawPixels;
|
||||
int raw_dpi_x = DisplayInformation::GetForCurrentView()->RawDpiX;
|
||||
int raw_dpi_y = DisplayInformation::GetForCurrentView()->RawDpiY;
|
||||
int physical_width = pixels_x / raw_dpi_x;
|
||||
int physical_height = pixels_y / raw_dpi_y;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DISPLAY_METRIC_PIXEL_WIDTH:
|
||||
*value = pixels_x;
|
||||
return true;
|
||||
case DISPLAY_METRIC_PIXEL_HEIGHT:
|
||||
*value = pixels_y;
|
||||
return true;
|
||||
case DISPLAY_METRIC_MM_WIDTH:
|
||||
/* 25.4 mm in an inch. */
|
||||
*value = 254 * physical_width / 10;
|
||||
return true;
|
||||
case DISPLAY_METRIC_MM_HEIGHT:
|
||||
/* 25.4 mm in an inch. */
|
||||
*value = 254 * physical_height / 10;
|
||||
return true;
|
||||
case DISPLAY_METRIC_DPI:
|
||||
*value = raw_dpi_x;
|
||||
return true;
|
||||
case DISPLAY_METRIC_NONE:
|
||||
default:
|
||||
*value = 0;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void win32_check_window(bool *quit, bool *resize, unsigned *width, unsigned *height)
|
||||
{
|
||||
*quit = App::GetInstance()->IsWindowClosed();
|
||||
@ -598,6 +636,37 @@ extern "C" {
|
||||
return (void*)CoreWindow::GetForCurrentThread();
|
||||
}
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
/* A special version of egl_create_surface to properly handle DPI scaling. */
|
||||
bool uwp_egl_create_surface(egl_ctx_data_t* egl)
|
||||
{
|
||||
EGLint window_attribs[] = {
|
||||
EGL_RENDER_BUFFER, EGL_BACK_BUFFER,
|
||||
EGL_NONE,
|
||||
};
|
||||
|
||||
double scale = DisplayInformation::GetForCurrentView()->RawPixelsPerViewPixel;
|
||||
|
||||
/* Why Microsoft uses a WinRT class for sending parameters to EGL?! */
|
||||
PropertySet^ prop = ref new PropertySet();
|
||||
prop->Insert(L"EGLNativeWindowTypeProperty", CoreWindow::GetForCurrentThread());
|
||||
prop->Insert(L"EGLRenderResolutionScaleProperty", PropertyValue::CreateSingle(scale));
|
||||
|
||||
egl->surf = eglCreateWindowSurface(egl->dpy, egl->config, (EGLNativeWindowType)(prop), window_attribs);
|
||||
|
||||
if (egl->surf == EGL_NO_SURFACE)
|
||||
return false;
|
||||
|
||||
/* Connect the context to the surface. */
|
||||
if (!eglMakeCurrent(egl->dpy, egl->surf, egl->surf, egl->ctx))
|
||||
return false;
|
||||
|
||||
RARCH_LOG("[EGL]: Current context: %p.\n", (void*)eglGetCurrentContext());
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void uwp_fill_installed_core_packages(struct string_list *list)
|
||||
{
|
||||
for (auto package : Windows::ApplicationModel::Package::Current->Dependencies)
|
||||
|
Loading…
x
Reference in New Issue
Block a user