From 5e4647994b34f63c80b2f73fc8edd68ddda41145 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 8 Apr 2015 22:06:33 +0200 Subject: [PATCH] (Windows) Implement get_metrics for D3D and WGL context drivers --- gfx/drivers_context/d3d_ctx.cpp | 38 ++++++++++++++++++++++++++++++++- gfx/drivers_context/wgl_ctx.c | 35 +++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/gfx/drivers_context/d3d_ctx.cpp b/gfx/drivers_context/d3d_ctx.cpp index 288cbc52ab..db34f6b3d4 100644 --- a/gfx/drivers_context/d3d_ctx.cpp +++ b/gfx/drivers_context/d3d_ctx.cpp @@ -492,6 +492,42 @@ static void gfx_ctx_d3d_swap_interval(void *data, unsigned interval) #endif } +static bool gfx_ctx_d3d_get_metrics(void *data, + enum display_metric_types type, float *value) +{ +#ifdef _XBOX + return false; +#else + HDC monitor = GetDC(NULL); + int pixels_x = GetDeviceCaps(monitor, HORZRES); + int pixels_y = GetDeviceCaps(monitor, VERTRES); + int physical_width = GetDeviceCaps(monitor, HORZSIZE); + int physical_height = GetDeviceCaps(monitor, VERTSIZE); + + ReleaseDC(NULL, monitor); + + switch (type) + { + case DISPLAY_METRIC_MM_WIDTH: + *value = physical_width; + break; + case DISPLAY_METRIC_MM_HEIGHT: + *value = physical_height; + break; + case DISPLAY_METRIC_DPI: + /* 25.4 mm in an inch. */ + *value = 254 * pixels_x / physical_width / 10; + break; + case DISPLAY_METRIC_NONE: + default: + *value = 0; + return false; + } + + return true; +#endif +} + const gfx_ctx_driver_t gfx_ctx_d3d = { gfx_ctx_d3d_init, gfx_ctx_d3d_destroy, @@ -502,7 +538,7 @@ const gfx_ctx_driver_t gfx_ctx_d3d = { NULL, /* get_video_output_size */ NULL, /* get_video_output_prev */ NULL, /* get_video_output_next */ - NULL, /* get_metrics */ + gfx_ctx_d3d_get_metrics, NULL, gfx_ctx_d3d_update_title, gfx_ctx_d3d_check_window, diff --git a/gfx/drivers_context/wgl_ctx.c b/gfx/drivers_context/wgl_ctx.c index 2aee1caa89..5deae8ccb1 100644 --- a/gfx/drivers_context/wgl_ctx.c +++ b/gfx/drivers_context/wgl_ctx.c @@ -664,6 +664,39 @@ static gfx_ctx_proc_t gfx_ctx_wgl_get_proc_address(const char *symbol) return (gfx_ctx_proc_t)GetProcAddress(dll_handle, symbol); } +static bool gfx_ctx_wgl_get_metrics(void *data, + enum display_metric_types type, float *value) +{ + bool ret = true; + HDC monitor = GetDC(NULL); + int pixels_x = GetDeviceCaps(monitor, HORZRES); + int pixels_y = GetDeviceCaps(monitor, VERTRES); + int physical_width = GetDeviceCaps(monitor, HORZSIZE); + int physical_height = GetDeviceCaps(monitor, VERTSIZE); + + ReleaseDC(NULL, monitor); + + switch (type) + { + case DISPLAY_METRIC_MM_WIDTH: + *value = physical_width; + break; + case DISPLAY_METRIC_MM_HEIGHT: + *value = physical_height; + break; + case DISPLAY_METRIC_DPI: + /* 25.4 mm in an inch. */ + *value = 254 * pixels_x / physical_width / 10; + break; + case DISPLAY_METRIC_NONE: + default: + *value = 0; + return false; + } + + return true; +} + static bool gfx_ctx_wgl_bind_api(void *data, enum gfx_ctx_api api, unsigned major, unsigned minor) { @@ -699,7 +732,7 @@ const gfx_ctx_driver_t gfx_ctx_wgl = { NULL, /* get_video_output_size */ NULL, /* get_video_output_prev */ NULL, /* get_video_output_next */ - NULL, /* get_metrics */ + gfx_ctx_wgl_get_metrics, NULL, gfx_ctx_wgl_update_window_title, gfx_ctx_wgl_check_window,