libobs: Add obs_display_update_color_space

This commit is contained in:
jpark37 2022-02-07 23:21:06 -08:00
parent cd22df09c9
commit 01c0486aad
3 changed files with 29 additions and 3 deletions

View File

@ -124,6 +124,18 @@ void obs_display_resize(obs_display_t *display, uint32_t cx, uint32_t cy)
pthread_mutex_unlock(&display->draw_info_mutex); pthread_mutex_unlock(&display->draw_info_mutex);
} }
void obs_display_update_color_space(obs_display_t *display)
{
if (!display)
return;
pthread_mutex_lock(&display->draw_info_mutex);
display->update_color_space = true;
pthread_mutex_unlock(&display->draw_info_mutex);
}
void obs_display_add_draw_callback(obs_display_t *display, void obs_display_add_draw_callback(obs_display_t *display,
void (*draw)(void *param, uint32_t cx, void (*draw)(void *param, uint32_t cx,
uint32_t cy), uint32_t cy),
@ -155,7 +167,8 @@ void obs_display_remove_draw_callback(obs_display_t *display,
} }
static inline void render_display_begin(struct obs_display *display, static inline void render_display_begin(struct obs_display *display,
uint32_t cx, uint32_t cy) uint32_t cx, uint32_t cy,
bool update_color_space)
{ {
struct vec4 clear_color; struct vec4 clear_color;
@ -165,11 +178,16 @@ static inline void render_display_begin(struct obs_display *display,
gs_resize(cx, cy); gs_resize(cx, cy);
display->cx = cx; display->cx = cx;
display->cy = cy; display->cy = cy;
} else if (update_color_space) {
gs_update_color_space();
} }
gs_begin_scene(); gs_begin_scene();
vec4_from_rgba(&clear_color, display->background_color); if (gs_get_color_space() == GS_CS_SRGB)
vec4_from_rgba(&clear_color, display->background_color);
else
vec4_from_rgba_srgb(&clear_color, display->background_color);
clear_color.w = 1.0f; clear_color.w = 1.0f;
gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH | GS_CLEAR_STENCIL, gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH | GS_CLEAR_STENCIL,
@ -191,6 +209,7 @@ static inline void render_display_end()
void render_display(struct obs_display *display) void render_display(struct obs_display *display)
{ {
uint32_t cx, cy; uint32_t cx, cy;
bool update_color_space;
if (!display || !display->enabled) if (!display || !display->enabled)
return; return;
@ -203,12 +222,15 @@ void render_display(struct obs_display *display)
cx = display->next_cx; cx = display->next_cx;
cy = display->next_cy; cy = display->next_cy;
update_color_space = display->update_color_space;
display->update_color_space = false;
pthread_mutex_unlock(&display->draw_info_mutex); pthread_mutex_unlock(&display->draw_info_mutex);
/* -------------------------------------------- */ /* -------------------------------------------- */
render_display_begin(display, cx, cy); render_display_begin(display, cx, cy, update_color_space);
pthread_mutex_lock(&display->draw_callbacks_mutex); pthread_mutex_lock(&display->draw_callbacks_mutex);

View File

@ -204,6 +204,7 @@ extern void obs_view_free(struct obs_view *view);
/* displays */ /* displays */
struct obs_display { struct obs_display {
bool update_color_space;
bool enabled; bool enabled;
uint32_t cx, cy; uint32_t cx, cy;
uint32_t next_cx, next_cy; uint32_t next_cx, next_cy;

View File

@ -887,6 +887,9 @@ EXPORT void obs_display_destroy(obs_display_t *display);
EXPORT void obs_display_resize(obs_display_t *display, uint32_t cx, EXPORT void obs_display_resize(obs_display_t *display, uint32_t cx,
uint32_t cy); uint32_t cy);
/** Updates the color space of this display */
EXPORT void obs_display_update_color_space(obs_display_t *display);
/** /**
* Adds a draw callback for this display context * Adds a draw callback for this display context
* *