From 1fa152092cd6031185c6c1fe1f4419180058611c Mon Sep 17 00:00:00 2001 From: jpark37 Date: Fri, 4 Jun 2021 01:20:57 -0700 Subject: [PATCH] libobs: Plumb linear alpha flag Use union for backwards compatibility. --- libobs/obs-internal.h | 1 + libobs/obs-source.c | 20 ++++++++++++-------- libobs/obs.h | 13 +++++++++++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 83037fc25..a8e1ee8a2 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -685,6 +685,7 @@ struct obs_source { int async_channel_count; long async_rotation; bool async_flip; + bool async_linear_alpha; bool async_active; bool async_update_texture; bool async_unbuffered; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 9ebf04d61..b6b2ab9dd 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -2019,7 +2019,9 @@ bool update_async_textures(struct obs_source *source, { enum convert_type type; - source->async_flip = frame->flip; + source->async_flip = (frame->flags & OBS_SOURCE_FRAME_FLIP) != 0; + source->async_linear_alpha = + (frame->flags & OBS_SOURCE_FRAME_LINEAR_ALPHA) != 0; if (source->async_gpu_conversion && texrender) return update_async_texrender(source, frame, tex, texrender); @@ -2070,9 +2072,11 @@ static void obs_source_draw_async_texture(struct obs_source *source) if (def_draw) { effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); - const bool linear = gs_get_linear_srgb(); - const char *tech_name = linear ? "DrawNonlinearAlpha" : "Draw"; - premultiplied = linear; + const bool nonlinear_alpha = gs_get_linear_srgb() && + !source->async_linear_alpha; + const char *tech_name = nonlinear_alpha ? "DrawNonlinearAlpha" + : "Draw"; + premultiplied = nonlinear_alpha; tech = gs_effect_get_technique(effect, tech_name); gs_technique_begin(tech); gs_technique_begin_pass(tech, 0); @@ -2720,7 +2724,7 @@ static inline void copy_frame_data_plane(struct obs_source_frame *dst, static void copy_frame_data(struct obs_source_frame *dst, const struct obs_source_frame *src) { - dst->flip = src->flip; + dst->flags = src->flags; dst->full_range = src->full_range; dst->timestamp = src->timestamp; memcpy(dst->color_matrix, src->color_matrix, sizeof(float) * 16); @@ -2951,7 +2955,7 @@ void obs_source_output_video2(obs_source_t *source, new_frame.timestamp = frame->timestamp; new_frame.format = frame->format; new_frame.full_range = range == VIDEO_RANGE_FULL; - new_frame.flip = frame->flip; + new_frame.flags = frame->flags; memcpy(&new_frame.color_matrix, &frame->color_matrix, sizeof(frame->color_matrix)); @@ -3082,7 +3086,7 @@ void obs_source_preload_video2(obs_source_t *source, new_frame.timestamp = frame->timestamp; new_frame.format = frame->format; new_frame.full_range = range == VIDEO_RANGE_FULL; - new_frame.flip = frame->flip; + new_frame.flags = frame->flags; memcpy(&new_frame.color_matrix, &frame->color_matrix, sizeof(frame->color_matrix)); @@ -3186,7 +3190,7 @@ void obs_source_set_video_frame2(obs_source_t *source, new_frame.timestamp = frame->timestamp; new_frame.format = frame->format; new_frame.full_range = range == VIDEO_RANGE_FULL; - new_frame.flip = frame->flip; + new_frame.flags = frame->flags; memcpy(&new_frame.color_matrix, &frame->color_matrix, sizeof(frame->color_matrix)); diff --git a/libobs/obs.h b/libobs/obs.h index 00ed7fdd3..28be4d93a 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -219,6 +219,9 @@ struct obs_source_cea_708 { uint64_t timestamp; }; +#define OBS_SOURCE_FRAME_FLIP (1 << 0) +#define OBS_SOURCE_FRAME_LINEAR_ALPHA (1 << 1) + /** * Source asynchronous video output structure. Used with * obs_source_output_video to output asynchronous video. Video is buffered as @@ -244,7 +247,10 @@ struct obs_source_frame { bool full_range; float color_range_min[3]; float color_range_max[3]; - bool flip; + union { + uint8_t flip : 1; /* deprecated */ + uint8_t flags; + }; /* used internally by libobs */ volatile long refs; @@ -263,7 +269,10 @@ struct obs_source_frame2 { float color_matrix[16]; float color_range_min[3]; float color_range_max[3]; - bool flip; + union { + uint8_t flip : 1; /* deprecated */ + uint8_t flags; + }; }; /** Access to the argc/argv used to start OBS. What you see is what you get. */