libobs, image-source: Fix ABI break in image_file_t structure

In commit a776a6cf07, the image_file_t structure (which is a public
structure) had a member variable added to it, which broke ABI.
This commit is contained in:
jp9000
2019-03-28 22:30:20 -07:00
parent eb672d7725
commit d18c62b2b5
3 changed files with 81 additions and 34 deletions
+29 -11
View File
@@ -59,13 +59,16 @@ static inline int get_full_decoded_gif_size(gs_image_file_t *image)
return image->gif.width * image->gif.height * 4 * image->gif.frame_count;
}
static inline void *alloc_mem(gs_image_file_t *image, size_t size)
static inline void *alloc_mem(gs_image_file_t *image, uint64_t *mem_usage,
size_t size)
{
image->mem_usage += size;
if (mem_usage)
*mem_usage += size;
return bzalloc(size);
}
static bool init_animated_gif(gs_image_file_t *image, const char *path)
static bool init_animated_gif(gs_image_file_t *image, const char *path,
uint64_t *mem_usage)
{
bool is_animated_gif = true;
gif_result result;
@@ -127,9 +130,9 @@ static bool init_animated_gif(gs_image_file_t *image, const char *path)
if (image->is_animated_gif) {
gif_decode_frame(&image->gif, 0);
image->animation_frame_cache = alloc_mem(image,
image->animation_frame_cache = alloc_mem(image, mem_usage,
image->gif.frame_count * sizeof(uint8_t*));
image->animation_frame_data = alloc_mem(image,
image->animation_frame_data = alloc_mem(image, mem_usage,
get_full_decoded_gif_size(image));
for (unsigned int i = 0; i < image->gif.frame_count; i++) {
@@ -144,8 +147,10 @@ static bool init_animated_gif(gs_image_file_t *image, const char *path)
image->cy = (uint32_t)image->gif.height;
image->format = GS_RGBA;
image->mem_usage += image->cx * image->cy * 4;
image->mem_usage += size;
if (mem_usage) {
*mem_usage += image->cx * image->cy * 4;
*mem_usage += size;
}
} else {
gif_finalise(&image->gif);
bfree(image->gif_data);
@@ -166,7 +171,8 @@ not_animated:
return is_animated_gif;
}
void gs_image_file_init(gs_image_file_t *image, const char *file)
static void gs_image_file_init_internal(gs_image_file_t *image,
const char *file, uint64_t *mem_usage)
{
size_t len;
@@ -181,15 +187,17 @@ void gs_image_file_init(gs_image_file_t *image, const char *file)
len = strlen(file);
if (len > 4 && strcmp(file + len - 4, ".gif") == 0) {
if (init_animated_gif(image, file))
if (init_animated_gif(image, file, mem_usage))
return;
}
image->texture_data = gs_create_texture_file_data(file,
&image->format, &image->cx, &image->cy);
image->mem_usage += image->cx * image->cy *
gs_get_format_bpp(image->format) / 8;
if (mem_usage) {
*mem_usage += image->cx * image->cy *
gs_get_format_bpp(image->format) / 8;
}
image->loaded = !!image->texture_data;
if (!image->loaded) {
@@ -198,6 +206,11 @@ void gs_image_file_init(gs_image_file_t *image, const char *file)
}
}
void gs_image_file_init(gs_image_file_t *image, const char *file)
{
gs_image_file_init_internal(image, file, NULL);
}
void gs_image_file_free(gs_image_file_t *image)
{
if (!image)
@@ -218,6 +231,11 @@ void gs_image_file_free(gs_image_file_t *image)
memset(image, 0, sizeof(*image));
}
void gs_image_file2_init(gs_image_file2_t *if2, const char *file)
{
gs_image_file_init_internal(&if2->image, file, &if2->mem_usage);
}
void gs_image_file_init_texture(gs_image_file_t *image)
{
if (!image->loaded)
+30 -1
View File
@@ -38,7 +38,6 @@ struct gs_image_file {
uint8_t **animation_frame_cache;
uint8_t *animation_frame_data;
uint64_t cur_time;
uint64_t mem_usage;
int cur_frame;
int cur_loop;
int last_decoded_frame;
@@ -47,7 +46,13 @@ struct gs_image_file {
gif_bitmap_callback_vt bitmap_callbacks;
};
struct gs_image_file2 {
struct gs_image_file image;
uint64_t mem_usage;
};
typedef struct gs_image_file gs_image_file_t;
typedef struct gs_image_file2 gs_image_file2_t;
EXPORT void gs_image_file_init(gs_image_file_t *image, const char *file);
EXPORT void gs_image_file_free(gs_image_file_t *image);
@@ -57,6 +62,30 @@ EXPORT bool gs_image_file_tick(gs_image_file_t *image,
uint64_t elapsed_time_ns);
EXPORT void gs_image_file_update_texture(gs_image_file_t *image);
EXPORT void gs_image_file2_init(gs_image_file2_t *if2, const char *file);
static void gs_image_file2_free(gs_image_file2_t *if2)
{
gs_image_file_free(&if2->image);
if2->mem_usage = 0;
}
static inline void gs_image_file2_init_texture(gs_image_file2_t *if2)
{
gs_image_file_init_texture(&if2->image);
}
static inline bool gs_image_file2_tick(gs_image_file2_t *if2,
uint64_t elapsed_time_ns)
{
return gs_image_file_tick(&if2->image, elapsed_time_ns);
}
static inline void gs_image_file2_update_texture(gs_image_file2_t *if2)
{
gs_image_file_update_texture(&if2->image);
}
#ifdef __cplusplus
}
#endif
+22 -22
View File
@@ -25,7 +25,7 @@ struct image_source {
uint64_t last_time;
bool active;
gs_image_file_t image;
gs_image_file2_t if2;
};
@@ -48,20 +48,20 @@ static void image_source_load(struct image_source *context)
char *file = context->file;
obs_enter_graphics();
gs_image_file_free(&context->image);
gs_image_file2_free(&context->if2);
obs_leave_graphics();
if (file && *file) {
debug("loading texture '%s'", file);
context->file_timestamp = get_modified_timestamp(file);
gs_image_file_init(&context->image, file);
gs_image_file2_init(&context->if2, file);
context->update_time_elapsed = 0;
obs_enter_graphics();
gs_image_file_init_texture(&context->image);
gs_image_file2_init_texture(&context->if2);
obs_leave_graphics();
if (!context->image.loaded)
if (!context->if2.image.loaded)
warn("failed to load texture '%s'", file);
}
}
@@ -69,7 +69,7 @@ static void image_source_load(struct image_source *context)
static void image_source_unload(struct image_source *context)
{
obs_enter_graphics();
gs_image_file_free(&context->image);
gs_image_file2_free(&context->if2);
obs_leave_graphics();
}
@@ -135,26 +135,26 @@ static void image_source_destroy(void *data)
static uint32_t image_source_getwidth(void *data)
{
struct image_source *context = data;
return context->image.cx;
return context->if2.image.cx;
}
static uint32_t image_source_getheight(void *data)
{
struct image_source *context = data;
return context->image.cy;
return context->if2.image.cy;
}
static void image_source_render(void *data, gs_effect_t *effect)
{
struct image_source *context = data;
if (!context->image.texture)
if (!context->if2.image.texture)
return;
gs_effect_set_texture(gs_effect_get_param_by_name(effect, "image"),
context->image.texture);
gs_draw_sprite(context->image.texture, 0,
context->image.cx, context->image.cy);
context->if2.image.texture);
gs_draw_sprite(context->if2.image.texture, 0,
context->if2.image.cx, context->if2.image.cy);
}
static void image_source_tick(void *data, float seconds)
@@ -175,20 +175,20 @@ static void image_source_tick(void *data, float seconds)
if (obs_source_active(context->source)) {
if (!context->active) {
if (context->image.is_animated_gif)
if (context->if2.image.is_animated_gif)
context->last_time = frame_time;
context->active = true;
}
} else {
if (context->active) {
if (context->image.is_animated_gif) {
context->image.cur_frame = 0;
context->image.cur_loop = 0;
context->image.cur_time = 0;
if (context->if2.image.is_animated_gif) {
context->if2.image.cur_frame = 0;
context->if2.image.cur_loop = 0;
context->if2.image.cur_time = 0;
obs_enter_graphics();
gs_image_file_update_texture(&context->image);
gs_image_file2_update_texture(&context->if2);
obs_leave_graphics();
}
@@ -198,13 +198,13 @@ static void image_source_tick(void *data, float seconds)
return;
}
if (context->last_time && context->image.is_animated_gif) {
if (context->last_time && context->if2.image.is_animated_gif) {
uint64_t elapsed = frame_time - context->last_time;
bool updated = gs_image_file_tick(&context->image, elapsed);
bool updated = gs_image_file2_tick(&context->if2, elapsed);
if (updated) {
obs_enter_graphics();
gs_image_file_update_texture(&context->image);
gs_image_file2_update_texture(&context->if2);
obs_leave_graphics();
}
}
@@ -253,7 +253,7 @@ static obs_properties_t *image_source_properties(void *data)
uint64_t image_source_get_memory_usage(void *data)
{
struct image_source *s = data;
return s->image.mem_usage;
return s->if2.mem_usage;
}
static struct obs_source_info image_source_info = {