浏览代码

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 年之前
父节点
当前提交
ebfe477caf
共有 3 个文件被更改,包括 17 次插入1 次删除
  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;
 		return false;
 	}
 	}
 
 
+	display->enabled = true;
 	return true;
 	return true;
 }
 }
 
 
@@ -170,7 +171,7 @@ static inline void render_display_end()
 
 
 void render_display(struct obs_display *display)
 void render_display(struct obs_display *display)
 {
 {
-	if (!display) return;
+	if (!display || !display->enabled) return;
 
 
 	render_display_begin(display);
 	render_display_begin(display);
 
 
@@ -187,3 +188,14 @@ void render_display(struct obs_display *display)
 
 
 	render_display_end();
 	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 {
 struct obs_display {
 	bool                            size_changed;
 	bool                            size_changed;
+	bool                            enabled;
 	uint32_t                        cx, cy;
 	uint32_t                        cx, cy;
 	gs_swapchain_t                  *swap;
 	gs_swapchain_t                  *swap;
 	pthread_mutex_t                 draw_callbacks_mutex;
 	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 (*draw)(void *param, uint32_t cx, uint32_t cy),
 		void *param);
 		void *param);
 
 
+EXPORT void obs_display_set_enabled(obs_display_t *display, bool enable);
+EXPORT bool obs_display_enabled(obs_display_t *display);
+
 
 
 /* ------------------------------------------------------------------------- */
 /* ------------------------------------------------------------------------- */
 /* Sources */
 /* Sources */