diff --git a/libobs/obs-display.c b/libobs/obs-display.c index 96c57d64f..e1a789bc7 100644 --- a/libobs/obs-display.c +++ b/libobs/obs-display.c @@ -48,7 +48,7 @@ obs_display_t obs_display_create(struct gs_init_data *graphics_data) { struct obs_display *display = bzalloc(sizeof(struct obs_display)); - gs_entercontext(obs_graphics()); + gs_entercontext(obs->video.graphics); if (!graphics_data->num_backbuffers) graphics_data->num_backbuffers = 1; @@ -91,9 +91,9 @@ void obs_display_destroy(obs_display_t display) display->next->prev_next = display->prev_next; pthread_mutex_unlock(&obs->data.displays_mutex); - gs_entercontext(obs_graphics()); + obs_enter_graphics(); obs_display_free(display); - gs_leavecontext(); + obs_leave_graphics(); bfree(display); } diff --git a/libobs/obs-video.c b/libobs/obs-video.c index 8c90d042e..1cfe6649f 100644 --- a/libobs/obs-video.c +++ b/libobs/obs-video.c @@ -56,7 +56,7 @@ static inline void render_displays(void) if (!obs->data.valid) return; - gs_entercontext(obs_graphics()); + gs_entercontext(obs->video.graphics); /* render extra displays/swaps */ pthread_mutex_lock(&obs->data.displays_mutex); @@ -411,7 +411,7 @@ static inline void output_frame(uint64_t timestamp) memset(&frame, 0, sizeof(struct video_data)); frame.timestamp = timestamp; - gs_entercontext(obs_graphics()); + gs_entercontext(video->graphics); render_video(video, cur_texture, prev_texture); frame_ready = download_frame(video, prev_texture, &frame); diff --git a/libobs/obs.c b/libobs/obs.c index b7bd0d713..ea4fb9670 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -808,9 +808,16 @@ bool obs_enum_service_types(size_t idx, const char **id) return true; } -graphics_t obs_graphics(void) +void obs_enter_graphics(void) { - return (obs != NULL) ? obs->video.graphics : NULL; + if (obs && obs->video.graphics) + gs_entercontext(obs->video.graphics); +} + +void obs_leave_graphics(void) +{ + if (obs && obs->video.graphics) + gs_leavecontext(); } audio_t obs_audio(void) diff --git a/libobs/obs.h b/libobs/obs.h index bd84ff92e..bff4ed58e 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -380,8 +380,11 @@ EXPORT bool obs_enum_encoder_types(size_t idx, const char **id); /** Enumerates all available service types. */ EXPORT bool obs_enum_service_types(size_t idx, const char **id); -/** Gets the main graphics context for this OBS context */ -EXPORT graphics_t obs_graphics(void); +/** Helper function for entering the OBS graphics context */ +EXPORT void obs_enter_graphics(void); + +/** Helper function for leaving the OBS graphics context */ +EXPORT void obs_leave_graphics(void); /** Gets the main audio output handler for this OBS context */ EXPORT audio_t obs_audio(void); diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index ff3e422e1..ba2b463f1 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -491,7 +491,7 @@ void OBSBasic::InitOBSCallbacks() void OBSBasic::InitPrimitives() { - gs_entercontext(obs_graphics()); + obs_enter_graphics(); gs_renderstart(true); gs_vertex2f(0.0f, 0.0f); @@ -508,7 +508,7 @@ void OBSBasic::InitPrimitives() } circle = gs_rendersave(); - gs_leavecontext(); + obs_leave_graphics(); } void OBSBasic::OBSInit() @@ -588,10 +588,10 @@ OBSBasic::~OBSBasic() ui->sources->clear(); ui->scenes->clear(); - gs_entercontext(obs_graphics()); + obs_enter_graphics(); vertexbuffer_destroy(box); vertexbuffer_destroy(circle); - gs_leavecontext(); + obs_leave_graphics(); obs_shutdown(); diff --git a/plugins/image-source/image-source.c b/plugins/image-source/image-source.c index 687c7043c..e3daf812d 100644 --- a/plugins/image-source/image-source.c +++ b/plugins/image-source/image-source.c @@ -22,7 +22,7 @@ static void image_source_update(void *data, obs_data_t settings) struct image_source *context = data; const char *file = obs_data_getstring(settings, "file"); - gs_entercontext(obs_graphics()); + obs_enter_graphics(); if (context->tex) { texture_destroy(context->tex); @@ -41,7 +41,7 @@ static void image_source_update(void *data, obs_data_t settings) } } - gs_leavecontext(); + obs_leave_graphics(); } static void *image_source_create(obs_data_t settings, obs_source_t source) @@ -57,9 +57,9 @@ static void image_source_destroy(void *data) { struct image_source *context = data; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); texture_destroy(context->tex); - gs_leavecontext(); + obs_leave_graphics(); bfree(context); } diff --git a/plugins/linux-xcomposite/xcompcap-helper.cpp b/plugins/linux-xcomposite/xcompcap-helper.cpp index ef24baa06..7d43cedc0 100644 --- a/plugins/linux-xcomposite/xcompcap-helper.cpp +++ b/plugins/linux-xcomposite/xcompcap-helper.cpp @@ -335,10 +335,10 @@ void XErrorLock::resetError() ObsGsContextHolder::ObsGsContextHolder() { - gs_entercontext(obs_graphics()); + obs_enter_graphics(); } ObsGsContextHolder::~ObsGsContextHolder() { - gs_leavecontext(); + obs_leave_graphics(); } diff --git a/plugins/linux-xcomposite/xcompcap-main.cpp b/plugins/linux-xcomposite/xcompcap-main.cpp index a49d27b15..1234a770e 100644 --- a/plugins/linux-xcomposite/xcompcap-main.cpp +++ b/plugins/linux-xcomposite/xcompcap-main.cpp @@ -414,7 +414,7 @@ void XCompcapMain::tick(float seconds) if (!p->tex || !p->gltex) return; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); if (p->lockX) { XLockDisplay(xdisp); @@ -427,7 +427,7 @@ void XCompcapMain::tick(float seconds) if (p->lockX) XUnlockDisplay(xdisp); - gs_leavecontext(); + obs_leave_graphics(); } void XCompcapMain::render(effect_t effect) diff --git a/plugins/linux-xshm/xshm-input.c b/plugins/linux-xshm/xshm-input.c index 01e3de2df..79cb66a4f 100644 --- a/plugins/linux-xshm/xshm-input.c +++ b/plugins/linux-xshm/xshm-input.c @@ -50,14 +50,14 @@ struct xshm_data { */ static void xshm_resize_texture(struct xshm_data *data) { - gs_entercontext(obs_graphics()); + obs_enter_graphics(); if (data->texture) texture_destroy(data->texture); data->texture = gs_create_texture(data->width, data->height, GS_BGRA, 1, NULL, GS_DYNAMIC); - gs_leavecontext(); + obs_leave_graphics(); } /** @@ -183,14 +183,14 @@ static void xshm_destroy(void *vptr) if (!data) return; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); if (data->texture) texture_destroy(data->texture); if (data->cursor) xcursor_destroy(data->cursor); - gs_leavecontext(); + obs_leave_graphics(); if (data->xshm) xshm_detach(data->xshm); @@ -222,9 +222,9 @@ static void *xshm_create(obs_data_t settings, obs_source_t source) data->use_xinerama = xinerama_is_active(data->dpy) ? true : false; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); data->cursor = xcursor_init(data->dpy); - gs_leavecontext(); + obs_leave_graphics(); xshm_update(data, settings); @@ -245,7 +245,7 @@ static void xshm_video_tick(void *vptr, float seconds) if (!data->xshm) return; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); XShmGetImage(data->dpy, XRootWindowOfScreen(data->screen), data->xshm->image, data->x_org, data->y_org, AllPlanes); @@ -254,7 +254,7 @@ static void xshm_video_tick(void *vptr, float seconds) xcursor_tick(data->cursor); - gs_leavecontext(); + obs_leave_graphics(); } /** diff --git a/plugins/mac-capture/mac-display-capture.m b/plugins/mac-capture/mac-display-capture.m index 1d1f7eefc..b0584cfaa 100644 --- a/plugins/mac-capture/mac-display-capture.m +++ b/plugins/mac-capture/mac-display-capture.m @@ -63,7 +63,7 @@ static void display_capture_destroy(void *data) if (!dc) return; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); destroy_display_stream(dc); @@ -72,7 +72,7 @@ static void display_capture_destroy(void *data) if (dc->draw_effect) effect_destroy(dc->draw_effect); - gs_leavecontext(); + obs_leave_graphics(); pthread_mutex_destroy(&dc->mutex); bfree(dc); @@ -168,7 +168,7 @@ static void *display_capture_create(obs_data_t settings, dc->source = source; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); struct gs_sampler_info info = { .filter = GS_FILTER_LINEAR, @@ -187,7 +187,7 @@ static void *display_capture_create(obs_data_t settings, if (!dc->draw_effect) goto fail; - gs_leavecontext(); + obs_leave_graphics(); dc->display = obs_data_getint(settings, "display"); pthread_mutex_init(&dc->mutex, NULL); @@ -198,7 +198,7 @@ static void *display_capture_create(obs_data_t settings, return dc; fail: - gs_leavecontext(); + obs_leave_graphics(); display_capture_destroy(dc); return NULL; } @@ -222,12 +222,12 @@ static void display_capture_video_tick(void *data, float seconds) if (prev_prev == dc->prev) return; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); if (dc->tex) texture_rebind_iosurface(dc->tex, dc->prev); else dc->tex = gs_create_texture_from_iosurface(dc->prev); - gs_leavecontext(); + obs_leave_graphics(); if (prev_prev) { IOSurfaceDecrementUseCount(prev_prev); @@ -288,14 +288,14 @@ static void display_capture_update(void *data, obs_data_t settings) if (dc->display == display && dc->hide_cursor != show_cursor) return; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); destroy_display_stream(dc); dc->display = display; dc->hide_cursor = !show_cursor; init_display_stream(dc); - gs_leavecontext(); + obs_leave_graphics(); } static obs_properties_t display_capture_properties(void) diff --git a/plugins/win-capture/dc-capture.c b/plugins/win-capture/dc-capture.c index 090ba809a..8ac57aee7 100644 --- a/plugins/win-capture/dc-capture.c +++ b/plugins/win-capture/dc-capture.c @@ -36,7 +36,7 @@ void dc_capture_init(struct dc_capture *capture, int x, int y, capture->height = height; capture->capture_cursor = cursor; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); if (!gs_gdi_texture_available()) compatibility = true; @@ -46,7 +46,7 @@ void dc_capture_init(struct dc_capture *capture, int x, int y, init_textures(capture); - gs_leavecontext(); + obs_leave_graphics(); if (!capture->valid) return; @@ -76,12 +76,12 @@ void dc_capture_free(struct dc_capture *capture) DeleteObject(capture->bmp); } - gs_entercontext(obs_graphics()); + obs_enter_graphics(); for (int i = 0; i < capture->num_textures; i++) texture_destroy(capture->textures[i]); - gs_leavecontext(); + obs_leave_graphics(); memset(capture, 0, sizeof(struct dc_capture)); } @@ -223,7 +223,7 @@ effect_t create_opaque_effect(void) return false; } - gs_entercontext(obs_graphics()); + obs_enter_graphics(); opaque_effect = gs_create_effect_from_file(effect_file, &error_string); @@ -240,7 +240,7 @@ effect_t create_opaque_effect(void) bfree(effect_file); bfree(error_string); - gs_leavecontext(); + obs_leave_graphics(); return opaque_effect; } diff --git a/plugins/win-capture/monitor-capture.c b/plugins/win-capture/monitor-capture.c index 94359f886..2066c4784 100644 --- a/plugins/win-capture/monitor-capture.c +++ b/plugins/win-capture/monitor-capture.c @@ -92,12 +92,12 @@ static void monitor_capture_destroy(void *data) { struct monitor_capture *capture = data; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); dc_capture_free(&capture->data); effect_destroy(capture->opaque_effect); - gs_leavecontext(); + obs_leave_graphics(); bfree(capture); } @@ -130,9 +130,9 @@ static void monitor_capture_tick(void *data, float seconds) { struct monitor_capture *capture = data; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); dc_capture_capture(&capture->data, NULL); - gs_leavecontext(); + obs_leave_graphics(); UNUSED_PARAMETER(seconds); } diff --git a/plugins/win-capture/window-capture.c b/plugins/win-capture/window-capture.c index 9ec54be62..a25ac4df3 100644 --- a/plugins/win-capture/window-capture.c +++ b/plugins/win-capture/window-capture.c @@ -334,9 +334,9 @@ static void wc_destroy(void *data) bfree(wc->class); bfree(wc->executable); - gs_entercontext(obs_graphics()); + obs_enter_graphics(); effect_destroy(wc->opaque_effect); - gs_leavecontext(); + obs_leave_graphics(); bfree(wc); } @@ -413,7 +413,7 @@ static void wc_tick(void *data, float seconds) return; } - gs_entercontext(obs_graphics()); + obs_enter_graphics(); GetClientRect(wc->window, &rect); @@ -438,7 +438,7 @@ static void wc_tick(void *data, float seconds) } dc_capture_capture(&wc->capture, wc->window); - gs_leavecontext(); + obs_leave_graphics(); } static void wc_render(void *data, effect_t effect) diff --git a/test/test-input/test-filter.c b/test/test-input/test-filter.c index 1c4d170d3..4c23196d0 100644 --- a/test/test-input/test-filter.c +++ b/test/test-input/test-filter.c @@ -15,12 +15,12 @@ static void filter_destroy(void *data) struct test_filter *tf = data; if (tf) { - gs_entercontext(obs_graphics()); + obs_enter_graphics(); effect_destroy(tf->whatever); bfree(tf); - gs_leavecontext(); + obs_leave_graphics(); } } @@ -29,7 +29,7 @@ static void *filter_create(obs_data_t settings, obs_source_t source) struct test_filter *tf = bzalloc(sizeof(struct test_filter)); char *effect_file; - gs_entercontext(obs_graphics()); + obs_enter_graphics(); effect_file = obs_module_file("test.effect"); @@ -41,7 +41,7 @@ static void *filter_create(obs_data_t settings, obs_source_t source) return NULL; } - gs_leavecontext(); + obs_leave_graphics(); UNUSED_PARAMETER(settings); return tf;