libobs: Only resize display if dimensions change

master
jpark37 2022-02-08 23:27:42 -08:00 committed by Jim
parent c639255142
commit 5d1261eddb
2 changed files with 17 additions and 17 deletions

View File

@ -33,8 +33,12 @@ bool obs_display_init(struct obs_display *display,
return false; return false;
} }
display->cx = graphics_data->cx; const uint32_t cx = graphics_data->cx;
display->cy = graphics_data->cy; const uint32_t cy = graphics_data->cy;
display->cx = cx;
display->cy = cy;
display->next_cx = cx;
display->next_cy = cy;
} }
if (pthread_mutex_init(&display->draw_callbacks_mutex, NULL) != 0) { if (pthread_mutex_init(&display->draw_callbacks_mutex, NULL) != 0) {
@ -114,9 +118,8 @@ void obs_display_resize(obs_display_t *display, uint32_t cx, uint32_t cy)
pthread_mutex_lock(&display->draw_info_mutex); pthread_mutex_lock(&display->draw_info_mutex);
display->cx = cx; display->next_cx = cx;
display->cy = cy; display->next_cy = cy;
display->size_changed = true;
pthread_mutex_unlock(&display->draw_info_mutex); pthread_mutex_unlock(&display->draw_info_mutex);
} }
@ -152,15 +155,17 @@ 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 size_changed)
{ {
struct vec4 clear_color; struct vec4 clear_color;
gs_load_swapchain(display->swap); gs_load_swapchain(display->swap);
if (size_changed) if ((display->cx != cx) || (display->cy != cy)) {
gs_resize(cx, cy); gs_resize(cx, cy);
display->cx = cx;
display->cy = cy;
}
gs_begin_scene(); gs_begin_scene();
@ -186,7 +191,6 @@ 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 size_changed;
if (!display || !display->enabled) if (!display || !display->enabled)
return; return;
@ -197,18 +201,14 @@ void render_display(struct obs_display *display)
pthread_mutex_lock(&display->draw_info_mutex); pthread_mutex_lock(&display->draw_info_mutex);
cx = display->cx; cx = display->next_cx;
cy = display->cy; cy = display->next_cy;
size_changed = display->size_changed;
if (size_changed)
display->size_changed = false;
pthread_mutex_unlock(&display->draw_info_mutex); pthread_mutex_unlock(&display->draw_info_mutex);
/* -------------------------------------------- */ /* -------------------------------------------- */
render_display_begin(display, cx, cy, size_changed); render_display_begin(display, cx, cy);
pthread_mutex_lock(&display->draw_callbacks_mutex); pthread_mutex_lock(&display->draw_callbacks_mutex);

View File

@ -204,9 +204,9 @@ extern void obs_view_free(struct obs_view *view);
/* displays */ /* displays */
struct obs_display { struct obs_display {
bool size_changed;
bool enabled; bool enabled;
uint32_t cx, cy; uint32_t cx, cy;
uint32_t next_cx, next_cy;
uint32_t background_color; uint32_t background_color;
gs_swapchain_t *swap; gs_swapchain_t *swap;
pthread_mutex_t draw_callbacks_mutex; pthread_mutex_t draw_callbacks_mutex;