Просмотр исходного кода

libobs: Define DARRAY macro types

To avoid passing `struct darray *` type, which cannot hold the type
information, this commit defines array types and uses that types on the
function parameters.
Norihiro Kamae 2 лет назад
Родитель
Сommit
8169188f89
3 измененных файлов с 29 добавлено и 29 удалено
  1. 6 4
      libobs/obs-internal.h
  2. 5 5
      libobs/obs-module.c
  3. 18 20
      libobs/obs-scene.c

+ 6 - 4
libobs/obs-internal.h

@@ -461,14 +461,16 @@ struct obs_core_hotkeys {
 	char *sceneitem_hide;
 };
 
+typedef DARRAY(struct obs_source_info) obs_source_info_array_t;
+
 struct obs_core {
 	struct obs_module *first_module;
 	DARRAY(struct obs_module_path) module_paths;
 
-	DARRAY(struct obs_source_info) source_types;
-	DARRAY(struct obs_source_info) input_types;
-	DARRAY(struct obs_source_info) filter_types;
-	DARRAY(struct obs_source_info) transition_types;
+	obs_source_info_array_t source_types;
+	obs_source_info_array_t input_types;
+	obs_source_info_array_t filter_types;
+	obs_source_info_array_t transition_types;
 	DARRAY(struct obs_output_info) output_types;
 	DARRAY(struct obs_encoder_info) encoder_types;
 	DARRAY(struct obs_service_info) service_types;

+ 5 - 5
libobs/obs-module.c

@@ -716,14 +716,14 @@ cleanup:
 void obs_register_source_s(const struct obs_source_info *info, size_t size)
 {
 	struct obs_source_info data = {0};
-	struct darray *array = NULL;
+	obs_source_info_array_t *array = NULL;
 
 	if (info->type == OBS_SOURCE_TYPE_INPUT) {
-		array = &obs->input_types.da;
+		array = &obs->input_types;
 	} else if (info->type == OBS_SOURCE_TYPE_FILTER) {
-		array = &obs->filter_types.da;
+		array = &obs->filter_types;
 	} else if (info->type == OBS_SOURCE_TYPE_TRANSITION) {
-		array = &obs->transition_types.da;
+		array = &obs->transition_types;
 	} else if (info->type != OBS_SOURCE_TYPE_SCENE) {
 		source_warn("Tried to register unknown source type: %u",
 			    info->type);
@@ -811,7 +811,7 @@ void obs_register_source_s(const struct obs_source_info *info, size_t size)
 	}
 
 	if (array)
-		darray_push_back(sizeof(struct obs_source_info), array, &data);
+		da_push_back(*array, &data);
 	da_push_back(obs->source_types, &data);
 	return;
 

+ 18 - 20
libobs/obs-scene.c

@@ -35,6 +35,8 @@ static inline bool item_texture_enabled(const struct obs_scene_item *item);
 static void init_hotkeys(obs_scene_t *scene, obs_sceneitem_t *item,
 			 const char *name);
 
+typedef DARRAY(struct obs_scene_item *) obs_scene_item_ptr_array_t;
+
 /* NOTE: For proper mutex lock order (preventing mutual cross-locks), never
  * lock the graphics mutex inside either of the scene mutexes.
  *
@@ -214,7 +216,7 @@ static inline void remove_without_release(struct obs_scene_item *item)
 static void remove_all_items(struct obs_scene *scene)
 {
 	struct obs_scene_item *item;
-	DARRAY(struct obs_scene_item *) items;
+	obs_scene_item_ptr_array_t items;
 
 	da_init(items);
 
@@ -852,7 +854,7 @@ static void scene_video_tick(void *data, float seconds)
 /* assumes video lock */
 static void
 update_transforms_and_prune_sources(obs_scene_t *scene,
-				    struct darray *remove_items,
+				    obs_scene_item_ptr_array_t *remove_items,
 				    obs_sceneitem_t *group_sceneitem)
 {
 	struct obs_scene_item *item = scene->first_item;
@@ -866,8 +868,7 @@ update_transforms_and_prune_sources(obs_scene_t *scene,
 			item = item->next;
 
 			remove_without_release(del_item);
-			darray_push_back(sizeof(struct obs_scene_item *),
-					 remove_items, &del_item);
+			da_push_back(*remove_items, &del_item);
 			rebuild_group = true;
 			continue;
 		}
@@ -897,7 +898,7 @@ update_transforms_and_prune_sources(obs_scene_t *scene,
 
 static void scene_video_render(void *data, gs_effect_t *effect)
 {
-	DARRAY(struct obs_scene_item *) remove_items;
+	obs_scene_item_ptr_array_t remove_items;
 	struct obs_scene *scene = data;
 	struct obs_scene_item *item;
 
@@ -906,8 +907,7 @@ static void scene_video_render(void *data, gs_effect_t *effect)
 	video_lock(scene);
 
 	if (!scene->is_group) {
-		update_transforms_and_prune_sources(scene, &remove_items.da,
-						    NULL);
+		update_transforms_and_prune_sources(scene, &remove_items, NULL);
 	}
 
 	gs_blend_state_push();
@@ -1603,21 +1603,19 @@ static obs_source_t *get_child_at_idx(obs_scene_t *scene, size_t idx)
 	return item ? item->source : NULL;
 }
 
-static inline obs_source_t *dup_child(struct darray *array, size_t idx,
-				      obs_scene_t *new_scene, bool private)
+static inline obs_source_t *dup_child(obs_scene_item_ptr_array_t *old_items,
+				      size_t idx, obs_scene_t *new_scene,
+				      bool private)
 {
-	DARRAY(struct obs_scene_item *) old_items;
 	obs_source_t *source;
 
-	old_items.da = *array;
-
-	source = old_items.array[idx]->source;
+	source = old_items->array[idx]->source;
 
 	/* if the old item is referenced more than once in the old scene,
 	 * make sure they're referenced similarly in the new scene to reduce
 	 * load times */
 	for (size_t i = 0; i < idx; i++) {
-		struct obs_scene_item *item = old_items.array[i];
+		struct obs_scene_item *item = old_items->array[i];
 		if (item->source == source) {
 			source = get_child_at_idx(new_scene, i);
 			return obs_source_get_ref(source);
@@ -1704,7 +1702,7 @@ obs_scene_t *obs_scene_duplicate(obs_scene_t *scene, const char *name,
 {
 	bool make_unique = ((int)type & (1 << 0)) != 0;
 	bool make_private = ((int)type & (1 << 1)) != 0;
-	DARRAY(struct obs_scene_item *) items;
+	obs_scene_item_ptr_array_t items;
 	struct obs_scene *new_scene;
 	struct obs_scene_item *item;
 	struct obs_source *source;
@@ -1744,9 +1742,9 @@ obs_scene_t *obs_scene_duplicate(obs_scene_t *scene, const char *name,
 
 	for (size_t i = 0; i < items.num; i++) {
 		item = items.array[i];
-		source = make_unique ? dup_child(&items.da, i, new_scene,
-						 make_private)
-				     : new_ref(item->source);
+		source = make_unique
+				 ? dup_child(&items, i, new_scene, make_private)
+				 : new_ref(item->source);
 
 		if (source) {
 			struct obs_scene_item *new_item =
@@ -3955,11 +3953,11 @@ obs_data_t *obs_sceneitem_transition_save(struct obs_scene_item *item,
 
 void obs_scene_prune_sources(obs_scene_t *scene)
 {
-	DARRAY(struct obs_scene_item *) remove_items;
+	obs_scene_item_ptr_array_t remove_items;
 	da_init(remove_items);
 
 	video_lock(scene);
-	update_transforms_and_prune_sources(scene, &remove_items.da, NULL);
+	update_transforms_and_prune_sources(scene, &remove_items, NULL);
 	video_unlock(scene);
 
 	for (size_t i = 0; i < remove_items.num; i++)