From eccde489268ee644640ebcf81b38ff74470294af Mon Sep 17 00:00:00 2001 From: jpark37 Date: Wed, 9 Mar 2022 21:41:23 -0800 Subject: [PATCH] libobs/graphics: Add gs_is_monitor_hdr Only Windows is implemented for now. Mac/Linux return false for now. --- docs/sphinx/reference-libobs-graphics-graphics.rst | 8 ++++++++ libobs-d3d11/d3d11-subsystem.cpp | 6 ++++++ libobs-opengl/gl-cocoa.m | 5 +++++ libobs-opengl/gl-nix.c | 5 +++++ libobs-opengl/gl-windows.c | 5 +++++ libobs/graphics/graphics-imports.c | 2 ++ libobs/graphics/graphics-internal.h | 2 ++ libobs/graphics/graphics.c | 9 +++++++++ libobs/graphics/graphics.h | 2 ++ 9 files changed, 44 insertions(+) diff --git a/docs/sphinx/reference-libobs-graphics-graphics.rst b/docs/sphinx/reference-libobs-graphics-graphics.rst index 4fc8bdd76..b1245acca 100644 --- a/docs/sphinx/reference-libobs-graphics-graphics.rst +++ b/docs/sphinx/reference-libobs-graphics-graphics.rst @@ -1506,6 +1506,14 @@ Display Duplicator (Windows Only) --------------------- +Monitor Functions +--------------------------------- + +.. function:: bool gs_is_monitor_hdr(void *monitor) + +--------------------- + + Render Helper Functions ----------------------- diff --git a/libobs-d3d11/d3d11-subsystem.cpp b/libobs-d3d11/d3d11-subsystem.cpp index 1d90f7c77..3b858b8a1 100644 --- a/libobs-d3d11/d3d11-subsystem.cpp +++ b/libobs-d3d11/d3d11-subsystem.cpp @@ -3047,6 +3047,12 @@ extern "C" EXPORT bool device_p010_available(gs_device_t *device) return device->p010Supported; } +extern "C" EXPORT bool device_is_monitor_hdr(gs_device_t *device, void *monitor) +{ + const HMONITOR hMonitor = static_cast(monitor); + return screen_supports_hdr(device, hMonitor); +} + extern "C" EXPORT void device_debug_marker_begin(gs_device_t *, const char *markername, const float color[4]) diff --git a/libobs-opengl/gl-cocoa.m b/libobs-opengl/gl-cocoa.m index 83a245fe6..81f63ca99 100644 --- a/libobs-opengl/gl-cocoa.m +++ b/libobs-opengl/gl-cocoa.m @@ -310,6 +310,11 @@ void device_present(gs_device_t *device) [device->plat->context makeCurrentContext]; } +bool device_is_monitor_hdr(gs_device_t *device, void *monitor) +{ + return false; +} + void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width, uint32_t *height) { diff --git a/libobs-opengl/gl-nix.c b/libobs-opengl/gl-nix.c index e387eaa4b..e87eb007e 100644 --- a/libobs-opengl/gl-nix.c +++ b/libobs-opengl/gl-nix.c @@ -124,6 +124,11 @@ extern void device_present(gs_device_t *device) gl_vtable->device_present(device); } +extern bool device_is_monitor_hdr(gs_device_t *device, void *monitor) +{ + return false; +} + extern struct gs_texture *device_texture_create_from_dmabuf( gs_device_t *device, unsigned int width, unsigned int height, uint32_t drm_format, enum gs_color_format color_format, diff --git a/libobs-opengl/gl-windows.c b/libobs-opengl/gl-windows.c index 61c80c83c..d9fcd28a2 100644 --- a/libobs-opengl/gl-windows.c +++ b/libobs-opengl/gl-windows.c @@ -598,6 +598,11 @@ extern void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width, } } +EXPORT bool device_is_monitor_hdr(gs_device_t *device, void *monitor) +{ + return false; +} + EXPORT bool device_gdi_texture_available(void) { return false; diff --git a/libobs/graphics/graphics-imports.c b/libobs/graphics/graphics-imports.c index 48b7f8c3b..599a34ba8 100644 --- a/libobs/graphics/graphics-imports.c +++ b/libobs/graphics/graphics-imports.c @@ -195,6 +195,8 @@ bool load_graphics_imports(struct gs_exports *exports, void *module, GRAPHICS_IMPORT_OPTIONAL(device_nv12_available); GRAPHICS_IMPORT_OPTIONAL(device_p010_available); + GRAPHICS_IMPORT(device_is_monitor_hdr); + GRAPHICS_IMPORT(device_debug_marker_begin); GRAPHICS_IMPORT(device_debug_marker_end); diff --git a/libobs/graphics/graphics-internal.h b/libobs/graphics/graphics-internal.h index a6d7e4eb2..8b64d2106 100644 --- a/libobs/graphics/graphics-internal.h +++ b/libobs/graphics/graphics-internal.h @@ -273,6 +273,8 @@ struct gs_exports { bool (*device_nv12_available)(gs_device_t *device); bool (*device_p010_available)(gs_device_t *device); + bool (*device_is_monitor_hdr)(gs_device_t *device, void *monitor); + void (*device_debug_marker_begin)(gs_device_t *device, const char *markername, const float color[4]); diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c index 96f31b65e..7fae78fc8 100644 --- a/libobs/graphics/graphics.c +++ b/libobs/graphics/graphics.c @@ -2840,6 +2840,15 @@ bool gs_p010_available(void) thread_graphics->device); } +bool gs_is_monitor_hdr(void *monitor) +{ + if (!gs_valid("gs_is_monitor_hdr")) + return false; + + return thread_graphics->exports.device_is_monitor_hdr( + thread_graphics->device, monitor); +} + void gs_debug_marker_begin(const float color[4], const char *markername) { if (!gs_valid("gs_debug_marker_begin")) diff --git a/libobs/graphics/graphics.h b/libobs/graphics/graphics.h index e160e909f..aa11dc874 100644 --- a/libobs/graphics/graphics.h +++ b/libobs/graphics/graphics.h @@ -851,6 +851,8 @@ EXPORT bool gs_timer_range_get_data(gs_timer_range_t *range, bool *disjoint, EXPORT bool gs_nv12_available(void); EXPORT bool gs_p010_available(void); +EXPORT bool gs_is_monitor_hdr(void *monitor); + #define GS_USE_DEBUG_MARKERS 0 #if GS_USE_DEBUG_MARKERS static const float GS_DEBUG_COLOR_DEFAULT[] = {0.5f, 0.5f, 0.5f, 1.0f};