(API Change) Remove obs_graphics()

API Removed:
- graphics_t obs_graphics();
Replaced With:
- void obs_enter_graphics();
- void obs_leave_graphics();

Description:
  obs_graphics() was somewhat of a pointless function.  The only time
that it was ever necessary was to pass it as a parameter to
gs_entercontext() followed by a subsequent gs_leavecontext() call after
that.  So, I felt that it made a bit more sense just to implement
obs_enter_graphics() and obs_leave_graphics() functions to do the exact
same thing without having to repeat that code.  There's really no need
to ever "hold" the graphics pointer, though I suppose that could change
in the future so having a similar function come back isn't out of the
question.

Still, this at least reduces the amount of unnecessary repeated code for
the time being.
master
jp9000 2014-08-04 05:48:58 -07:00
parent b007c6b139
commit 41176eef27
14 changed files with 66 additions and 56 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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();

View File

@ -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);
}

View File

@ -335,10 +335,10 @@ void XErrorLock::resetError()
ObsGsContextHolder::ObsGsContextHolder()
{
gs_entercontext(obs_graphics());
obs_enter_graphics();
}
ObsGsContextHolder::~ObsGsContextHolder()
{
gs_leavecontext();
obs_leave_graphics();
}

View File

@ -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)

View File

@ -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();
}
/**

View File

@ -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)

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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)

View File

@ -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;