Pārlūkot izejas kodu

libobs: Add ability to disable displays

Sometimes it can be useful to turn off rendering to the display in order
to reduce the number of draw calls and present calls.
jp9000 10 gadi atpakaļ
vecāks
revīzija
ebfe477caf
3 mainītis faili ar 17 papildinājumiem un 1 dzēšanām
  1. 13 1
      libobs/obs-display.c
  2. 1 0
      libobs/obs-internal.h
  3. 3 0
      libobs/obs.h

+ 13 - 1
libobs/obs-display.c

@@ -41,6 +41,7 @@ bool obs_display_init(struct obs_display *display,
 		return false;
 	}
 
+	display->enabled = true;
 	return true;
 }
 
@@ -170,7 +171,7 @@ static inline void render_display_end()
 
 void render_display(struct obs_display *display)
 {
-	if (!display) return;
+	if (!display || !display->enabled) return;
 
 	render_display_begin(display);
 
@@ -187,3 +188,14 @@ void render_display(struct obs_display *display)
 
 	render_display_end();
 }
+
+void obs_display_set_enabled(obs_display_t *display, bool enable)
+{
+	if (display)
+		display->enabled = enable;
+}
+
+bool obs_display_enabled(obs_display_t *display)
+{
+	return display ? display->enabled : false;
+}

+ 1 - 0
libobs/obs-internal.h

@@ -112,6 +112,7 @@ extern void obs_view_free(struct obs_view *view);
 
 struct obs_display {
 	bool                            size_changed;
+	bool                            enabled;
 	uint32_t                        cx, cy;
 	gs_swapchain_t                  *swap;
 	pthread_mutex_t                 draw_callbacks_mutex;

+ 3 - 0
libobs/obs.h

@@ -619,6 +619,9 @@ EXPORT void obs_display_remove_draw_callback(obs_display_t *display,
 		void (*draw)(void *param, uint32_t cx, uint32_t cy),
 		void *param);
 
+EXPORT void obs_display_set_enabled(obs_display_t *display, bool enable);
+EXPORT bool obs_display_enabled(obs_display_t *display);
+
 
 /* ------------------------------------------------------------------------- */
 /* Sources */