From a2e0f714f28559c85082ef039d9f7d829c5afdf3 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 24 Aug 2021 21:57:45 -0500 Subject: Cleanup: Remove unecessary variables Instead of passing separate booleans for whether to store the locations and distances, check if the spans are empty. And instead of passing a separate boolean for whether there is valid tree data, pass a pointer to the data. --- .../geometry/nodes/node_geo_attribute_proximity.cc | 55 +++++++++------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc index d71cb09f1bd..ad017ce7cf3 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc @@ -63,15 +63,10 @@ namespace blender::nodes { static void proximity_calc(MutableSpan distance_span, MutableSpan location_span, const VArray &positions, - BVHTreeFromMesh &tree_data_mesh, - BVHTreeFromPointCloud &tree_data_pointcloud, - const bool bvh_mesh_success, - const bool bvh_pointcloud_success, - const bool store_distances, - const bool store_locations) + BVHTreeFromMesh *tree_data_mesh, + BVHTreeFromPointCloud *tree_data_pointcloud) { - IndexRange range = positions.index_range(); - threading::parallel_for(range, 512, [&](IndexRange range) { + threading::parallel_for(positions.index_range(), 512, [&](IndexRange range) { BVHTreeNearest nearest_from_mesh; BVHTreeNearest nearest_from_pointcloud; @@ -85,12 +80,12 @@ static void proximity_calc(MutableSpan distance_span, /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ nearest_from_mesh.dist_sq = len_squared_v3v3(nearest_from_mesh.co, positions[i]); - if (bvh_mesh_success) { - BLI_bvhtree_find_nearest(tree_data_mesh.tree, + if (tree_data_mesh != nullptr) { + BLI_bvhtree_find_nearest(tree_data_mesh->tree, positions[i], &nearest_from_mesh, - tree_data_mesh.nearest_callback, - &tree_data_mesh); + tree_data_mesh->nearest_callback, + tree_data_mesh); } /* Use the distance to the closest point in the mesh to speedup the pointcloud bvh lookup. @@ -98,27 +93,27 @@ static void proximity_calc(MutableSpan distance_span, * than the mesh. */ nearest_from_pointcloud.dist_sq = nearest_from_mesh.dist_sq; - if (bvh_pointcloud_success) { - BLI_bvhtree_find_nearest(tree_data_pointcloud.tree, + if (tree_data_pointcloud != nullptr) { + BLI_bvhtree_find_nearest(tree_data_pointcloud->tree, positions[i], &nearest_from_pointcloud, - tree_data_pointcloud.nearest_callback, - &tree_data_pointcloud); + tree_data_pointcloud->nearest_callback, + tree_data_pointcloud); } if (nearest_from_pointcloud.dist_sq < nearest_from_mesh.dist_sq) { - if (store_distances) { + if (!distance_span.is_empty()) { distance_span[i] = sqrtf(nearest_from_pointcloud.dist_sq); } - if (store_locations) { + if (!location_span.is_empty()) { location_span[i] = nearest_from_pointcloud.co; } } else { - if (store_distances) { + if (!distance_span.is_empty()) { distance_span[i] = sqrtf(nearest_from_mesh.dist_sq); } - if (store_locations) { + if (!location_span.is_empty()) { location_span[i] = nearest_from_mesh.co; } } @@ -181,20 +176,18 @@ static void attribute_calc_proximity(GeometryComponent &component, } BLI_assert(position_attribute.varray->type().is()); - const bNode &node = params.node(); - const NodeGeometryAttributeProximity &storage = *(const NodeGeometryAttributeProximity *) - node.storage; + const NodeGeometryAttributeProximity &storage = + *(const NodeGeometryAttributeProximity *)params.node().storage; - BVHTreeFromMesh tree_data_mesh; - BVHTreeFromPointCloud tree_data_pointcloud; bool bvh_mesh_success = false; - bool bvh_pointcloud_success = false; - + BVHTreeFromMesh tree_data_mesh; if (geometry_set_target.has_mesh()) { bvh_mesh_success = bvh_from_mesh( geometry_set_target.get_mesh_for_read(), storage.target_geometry_element, tree_data_mesh); } + bool bvh_pointcloud_success = false; + BVHTreeFromPointCloud tree_data_pointcloud; if (geometry_set_target.has_pointcloud() && storage.target_geometry_element == GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS) { @@ -211,12 +204,8 @@ static void attribute_calc_proximity(GeometryComponent &component, proximity_calc(distance_span, location_span, positions, - tree_data_mesh, - tree_data_pointcloud, - bvh_mesh_success, - bvh_pointcloud_success, - distance_attribute, /* Boolean. */ - location_attribute); /* Boolean. */ + bvh_mesh_success ? &tree_data_mesh : nullptr, + bvh_pointcloud_success ? &tree_data_pointcloud : nullptr); if (bvh_mesh_success) { free_bvhtree_from_mesh(&tree_data_mesh); -- cgit v1.2.3 From 891e3e98eb6e4b60132abd93376daf8902b33cb4 Mon Sep 17 00:00:00 2001 From: YimingWu Date: Wed, 25 Aug 2021 11:00:29 +0800 Subject: LineArt: Fix (Unreported) Crash when loading objects. Fix mesh freeing call for obi->original_me so the address is correct. --- source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c index 99e3d59a57f..c71cde8ec43 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c @@ -1692,7 +1692,7 @@ static void lineart_geometry_object_load(LineartObjectInfo *obi, LineartRenderBu } if (obi->free_use_mesh) { - BKE_id_free(NULL, &obi->original_me); + BKE_id_free(NULL, obi->original_me); } if (rb->remove_doubles) { -- cgit v1.2.3 From f80c39b74e3ab9c81572e639201e2a3b79c4b5ec Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 24 Aug 2021 23:40:13 -0500 Subject: Cleanup: Use shorter enum item names --- source/blender/makesdna/DNA_node_types.h | 6 +++--- source/blender/makesrna/intern/rna_nodetree.c | 8 ++++---- .../nodes/geometry/nodes/node_geo_attribute_proximity.cc | 12 +++++------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index fd794ed1b21..361fefa59d2 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -1836,9 +1836,9 @@ typedef enum NodeShaderOutputTarget { /* Geometry Nodes */ typedef enum GeometryNodeAttributeProximityTargetType { - GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS = 0, - GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_EDGES = 1, - GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES = 2, + GEO_NODE_PROXIMITY_TARGET_POINTS = 0, + GEO_NODE_PROXIMITY_TARGET_EDGES = 1, + GEO_NODE_PROXIMITY_TARGET_FACES = 2, } GeometryNodeAttributeProximityTargetType; typedef enum GeometryNodeBooleanOperation { diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index d8ab7c7a61b..8d672e9b570 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -9853,17 +9853,17 @@ static void def_geo_collection_info(StructRNA *srna) static void def_geo_attribute_proximity(StructRNA *srna) { static const EnumPropertyItem target_geometry_element[] = { - {GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS, + {GEO_NODE_PROXIMITY_TARGET_POINTS, "POINTS", ICON_NONE, "Points", "Calculate proximity to the target's points (usually faster than the other two modes)"}, - {GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_EDGES, + {GEO_NODE_PROXIMITY_TARGET_EDGES, "EDGES", ICON_NONE, "Edges", "Calculate proximity to the target's edges"}, - {GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES, + {GEO_NODE_PROXIMITY_TARGET_FACES, "FACES", ICON_NONE, "Faces", @@ -9877,7 +9877,7 @@ static void def_geo_attribute_proximity(StructRNA *srna) prop = RNA_def_property(srna, "target_geometry_element", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, target_geometry_element); - RNA_def_property_enum_default(prop, GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES); + RNA_def_property_enum_default(prop, GEO_NODE_PROXIMITY_TARGET_FACES); RNA_def_property_ui_text( prop, "Target Geometry", "Element of the target geometry to calculate the distance from"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc index ad017ce7cf3..e94267cc936 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc @@ -53,8 +53,7 @@ static void geo_attribute_proximity_init(bNodeTree *UNUSED(ntree), bNode *node) NodeGeometryAttributeProximity *node_storage = (NodeGeometryAttributeProximity *)MEM_callocN( sizeof(NodeGeometryAttributeProximity), __func__); - node_storage->target_geometry_element = - GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES; + node_storage->target_geometry_element = GEO_NODE_PROXIMITY_TARGET_FACES; node->storage = node_storage; } @@ -127,13 +126,13 @@ static bool bvh_from_mesh(const Mesh *target_mesh, { BVHCacheType bvh_type = BVHTREE_FROM_LOOPTRI; switch (target_geometry_element) { - case GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS: + case GEO_NODE_PROXIMITY_TARGET_POINTS: bvh_type = BVHTREE_FROM_VERTS; break; - case GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_EDGES: + case GEO_NODE_PROXIMITY_TARGET_EDGES: bvh_type = BVHTREE_FROM_EDGES; break; - case GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_FACES: + case GEO_NODE_PROXIMITY_TARGET_FACES: bvh_type = BVHTREE_FROM_LOOPTRI; break; } @@ -189,8 +188,7 @@ static void attribute_calc_proximity(GeometryComponent &component, bool bvh_pointcloud_success = false; BVHTreeFromPointCloud tree_data_pointcloud; if (geometry_set_target.has_pointcloud() && - storage.target_geometry_element == - GEO_NODE_ATTRIBUTE_PROXIMITY_TARGET_GEOMETRY_ELEMENT_POINTS) { + storage.target_geometry_element == GEO_NODE_PROXIMITY_TARGET_POINTS) { bvh_pointcloud_success = bvh_from_pointcloud(geometry_set_target.get_pointcloud_for_read(), tree_data_pointcloud); } -- cgit v1.2.3 From 70f890b510562864e8a37d49afb4891bf083bf84 Mon Sep 17 00:00:00 2001 From: Richard Antalik Date: Wed, 25 Aug 2021 06:50:40 +0200 Subject: VSE: Set default sound and video export format Use video format for export instead of image sequence. Settings are same as defined in h264_in_MP4 preset. Sound default is AAC with 256kbit bitrate. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D7916 --- .../bl_app_templates_system/Video_Editing/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py b/release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py index 247a1ec342e..05ecac4d70c 100644 --- a/release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py +++ b/release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py @@ -29,9 +29,28 @@ def update_factory_startup_screens(): params.use_filter_folder = True +def update_factory_startup_ffmpeg_preset(): + preset = "H264_in_MP4" + preset_filepath = bpy.utils.preset_find(preset, preset_path="ffmpeg") + if not preset_filepath: + print("Preset %r not found" % preset) + + for scene in bpy.data.scenes: + render = scene.render + render.image_settings.file_format = 'FFMPEG' + + if preset_filepath: + bpy.ops.script.python_file_run({"scene": scene}, filepath=preset_filepath) + + render.ffmpeg.audio_codec = 'AAC' + render.ffmpeg.audio_bitrate = 256 + + @persistent def load_handler(_): update_factory_startup_screens() + if bpy.app.build_options.codec_ffmpeg: + update_factory_startup_ffmpeg_preset() def register(): -- cgit v1.2.3 From be906f44c6bb51eb492ecb90dbc1e8e0bc01d1ec Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Aug 2021 15:18:57 +1000 Subject: BLI_string_utf8: simplify utf8 stepping logic There were multiple utf8 functions which treated errors slightly differently. Split BLI_str_utf8_as_unicode_step into two functions. - BLI_str_utf8_as_unicode_step_or_error returns error value when decoding fails and doesn't step. - BLI_str_utf8_as_unicode_step always steps forward at least one returning the byte value without decoding (needed to display some latin1 file-paths). Font drawing uses BLI_str_utf8_as_unicode_step and no longer check for error values. --- source/blender/blenfont/intern/blf_font.c | 9 ++-- source/blender/blenlib/BLI_string_utf8.h | 3 ++ source/blender/blenlib/intern/string_utf8.c | 75 +++++++++++++---------------- 3 files changed, 41 insertions(+), 46 deletions(-) diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 5ad48aa08d4..426008c9395 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -309,15 +309,13 @@ BLI_INLINE GlyphBLF *blf_utf8_next_fast( } (*i_p)++; } - else if ((*r_c = BLI_str_utf8_as_unicode_step(str, str_len, i_p)) != BLI_UTF8_ERR) { + else { + *r_c = BLI_str_utf8_as_unicode_step(str, str_len, i_p); g = blf_glyph_search(gc, *r_c); if (UNLIKELY(g == NULL)) { g = blf_glyph_add(font, gc, FT_Get_Char_Index(font->face, *r_c), *r_c); } } - else { - g = NULL; - } return g; } @@ -1202,7 +1200,8 @@ int blf_font_count_missing_chars(FontBLF *font, if ((c = str[i]) < GLYPH_ASCII_TABLE_SIZE) { i++; } - else if ((c = BLI_str_utf8_as_unicode_step(str, str_len, &i)) != BLI_UTF8_ERR) { + else { + c = BLI_str_utf8_as_unicode_step(str, str_len, &i); if (FT_Get_Char_Index((font)->face, c) == 0) { missing++; } diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index b936e39731d..1b12147fe0f 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -46,6 +46,9 @@ unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_NONNULL(1, 3); +unsigned int BLI_str_utf8_as_unicode_step_or_error(const char *__restrict p, + size_t p_len, + size_t *__restrict index) ATTR_NONNULL(1, 3); size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf); size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index dbde5221d7e..06fd3168c24 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -581,73 +581,66 @@ uint BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__r } /** - * Another variant that steps over the index. + * UTF8 decoding that steps over the index (unless an error is encountered). * * \param p: The text to step over. * \param p_len: The length of `p`. * \param index: Index of `p` to step over. - * - * \note currently this also falls back to latin1 for text drawing. + * \return the code-point or #BLI_UTF8_ERR if there is a decoding error. * * \note The behavior for clipped text (where `p_len` limits decoding trailing bytes) * must have the same behavior is encountering a nil byte, * so functions that only use the first part of a string has matching behavior to functions * that null terminate the text. */ -uint BLI_str_utf8_as_unicode_step(const char *__restrict p, - const size_t p_len, - size_t *__restrict index) +uint BLI_str_utf8_as_unicode_step_or_error(const char *__restrict p, + const size_t p_len, + size_t *__restrict index) { int i, len; uint mask = 0; uint result; - const char c = p[*index]; + const unsigned char c = (unsigned char)*(p += *index); BLI_assert(*index < p_len); BLI_assert(c != '\0'); UTF8_COMPUTE(c, mask, len, -1); - if (UNLIKELY(len == -1)) { - const char *p_next = BLI_str_find_next_char_utf8(p + *index, p + p_len); - /* #BLI_str_find_next_char_utf8 ensures the nil byte will terminate. - * so there is no chance this sets the index past the nil byte (assert this is the case). */ - BLI_assert(p_next || (memchr(p + *index, '\0', p_len - *index) == NULL)); - len = (int)((p_next ? (size_t)(p_next - p) : p_len) - *index); - result = BLI_UTF8_ERR; - } - else if (UNLIKELY(*index + (size_t)len > p_len)) { - /* A multi-byte character reads past the buffer bounds, - * match the behavior of encountering an byte with invalid encoding below. */ - len = 1; - result = (uint)c; + if (UNLIKELY(len == -1) || (*index + (size_t)len > p_len)) { + return BLI_UTF8_ERR; } - else { - /* This is tricky since there are a few ways we can bail out of bad unicode - * values, 3 possible solutions. */ - p += *index; -#if 0 - UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR); -#elif 1 - /* WARNING: this is NOT part of glib, or supported by similar functions. - * this is added for text drawing because some filepaths can have latin1 - * characters */ - UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR); - if (result == BLI_UTF8_ERR) { - len = 1; - result = (uint)c; - } - /* end warning! */ -#else - /* Without a fallback like '?', text drawing will stop on this value. */ - UTF8_GET(result, p, i, mask, len, '?'); -#endif + UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR); + if (UNLIKELY(result == BLI_UTF8_ERR)) { + return BLI_UTF8_ERR; } - *index += (size_t)len; BLI_assert(*index <= p_len); return result; } +/** + * UTF8 decoding that steps over the index (unless an error is encountered). + * + * \param p: The text to step over. + * \param p_len: The length of `p`. + * \param index: Index of `p` to step over. + * \return the code-point `(p + *index)` if there is a decoding error. + * + * \note Falls back to `LATIN1` for text drawing. + */ +uint BLI_str_utf8_as_unicode_step(const char *__restrict p, + const size_t p_len, + size_t *__restrict index) +{ + uint result = BLI_str_utf8_as_unicode_step_or_error(p, p_len, index); + if (UNLIKELY(result == BLI_UTF8_ERR)) { + result = (uint)p[*index]; + *index += 1; + } + BLI_assert(*index <= p_len); + return result; +} + /* was g_unichar_to_utf8 */ /** * BLI_str_utf8_from_unicode: -- cgit v1.2.3 From 38630711a02e553f209ace9a8627a7a851820a2d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Aug 2021 15:19:00 +1000 Subject: BLI_string_utf8: remove unnecessary utf8 decoding functions Remove BLI_str_utf8_as_unicode_and_size and BLI_str_utf8_as_unicode_and_size_safe. Use BLI_str_utf8_as_unicode_step instead since it takes a buffer bounds argument to prevent buffer over-reading. --- source/blender/blenkernel/intern/text.c | 15 ++++-- source/blender/blenlib/BLI_string_utf8.h | 4 -- source/blender/blenlib/intern/string_cursor_utf8.c | 20 +++++--- source/blender/blenlib/intern/string_search.cc | 17 +++---- source/blender/blenlib/intern/string_utf8.c | 53 ++++++---------------- .../blender/editors/space_text/text_autocomplete.c | 7 ++- source/blender/makesrna/intern/rna_wm.c | 5 +- 7 files changed, 51 insertions(+), 70 deletions(-) diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index c2ab91251b6..7f1f6590e48 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1888,8 +1888,9 @@ void txt_delete_char(Text *text) } } else { /* Just deleting a char */ - size_t c_len = 0; - c = BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &c_len); + size_t c_len = text->curc; + c = BLI_str_utf8_as_unicode_step(text->curl->line, text->curl->len, &c_len); + c_len -= text->curc; UNUSED_VARS(c); memmove(text->curl->line + text->curc, @@ -1937,9 +1938,11 @@ void txt_backspace_char(Text *text) txt_pop_sel(text); } else { /* Just backspacing a char */ - size_t c_len = 0; const char *prev = BLI_str_prev_char_utf8(text->curl->line + text->curc); - c = BLI_str_utf8_as_unicode_and_size(prev, &c_len); + size_t c_len = prev - text->curl->line; + c = BLI_str_utf8_as_unicode_step(text->curl->line, text->curl->len, &c_len); + c_len -= prev - text->curl->line; + UNUSED_VARS(c); /* source and destination overlap, don't use memcpy() */ @@ -2053,7 +2056,9 @@ bool txt_replace_char(Text *text, unsigned int add) return txt_add_char(text, add); } - del = BLI_str_utf8_as_unicode_and_size(text->curl->line + text->curc, &del_size); + del_size = text->curc; + del = BLI_str_utf8_as_unicode_step(text->curl->line, text->curl->len, &del_size); + del_size -= text->curc; UNUSED_VARS(del); add_size = BLI_str_utf8_from_unicode(add, ch); diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 1b12147fe0f..b97c8748ca4 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -39,10 +39,6 @@ int BLI_str_utf8_size(const char *p) ATTR_NONNULL(); int BLI_str_utf8_size_safe(const char *p) ATTR_NONNULL(); /* copied from glib */ unsigned int BLI_str_utf8_as_unicode(const char *p) ATTR_NONNULL(); -unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index) - ATTR_NONNULL(); -unsigned int BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, - size_t *__restrict index) ATTR_NONNULL(); unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_NONNULL(1, 3); diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index 90fde02b11f..59b9f4eeca0 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -101,11 +101,14 @@ static eStrCursorDelimType cursor_delim_type_unicode(const uint uch) return STRCUR_DELIM_ALPHANUMERIC; /* Not quite true, but ok for now */ } -static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8) +static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8, + const size_t ch_utf8_len, + const int pos) { /* for full unicode support we really need to have large lookup tables to figure * out what's what in every possible char set - and python, glib both have these. */ - uint uch = BLI_str_utf8_as_unicode(ch_utf8); + size_t index = (size_t)pos; + uint uch = BLI_str_utf8_as_unicode_step_or_error(ch_utf8, ch_utf8_len, &index); return cursor_delim_type_unicode(uch); } @@ -157,14 +160,16 @@ void BLI_str_cursor_step_utf8(const char *str, } if (jump != STRCUR_JUMP_NONE) { - const eStrCursorDelimType delim_type = (*pos) < maxlen ? cursor_delim_type_utf8(&str[*pos]) : - STRCUR_DELIM_NONE; + const eStrCursorDelimType delim_type = (*pos) < maxlen ? + cursor_delim_type_utf8(str, maxlen, *pos) : + STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function cursor_delim_type() for complete * list of special character, ctr -> */ while ((*pos) < maxlen) { if (BLI_str_cursor_step_next_utf8(str, maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type_utf8(&str[*pos]))) { + if ((jump != STRCUR_JUMP_ALL) && + (delim_type != cursor_delim_type_utf8(str, maxlen, *pos))) { break; } } @@ -184,7 +189,7 @@ void BLI_str_cursor_step_utf8(const char *str, if (jump != STRCUR_JUMP_NONE) { const eStrCursorDelimType delim_type = (*pos) > 0 ? - cursor_delim_type_utf8(&str[(*pos) - 1]) : + cursor_delim_type_utf8(str, maxlen, *pos - 1) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function cursor_delim_type() for complete @@ -192,7 +197,8 @@ void BLI_str_cursor_step_utf8(const char *str, while ((*pos) > 0) { const int pos_prev = *pos; if (BLI_str_cursor_step_prev_utf8(str, maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type_utf8(&str[*pos]))) { + if ((jump != STRCUR_JUMP_ALL) && + (delim_type != cursor_delim_type_utf8(str, maxlen, (size_t)*pos))) { /* left only: compensate for index/change in direction */ if ((pos_orig - (*pos)) >= 1) { *pos = pos_prev; diff --git a/source/blender/blenlib/intern/string_search.cc b/source/blender/blenlib/intern/string_search.cc index 25a13674932..a466c124073 100644 --- a/source/blender/blenlib/intern/string_search.cc +++ b/source/blender/blenlib/intern/string_search.cc @@ -71,12 +71,12 @@ int damerau_levenshtein_distance(StringRef a, StringRef b) for (const int i : IndexRange(size_a)) { v2[0] = (i + 1) * deletion_cost; - const uint32_t unicode_a = BLI_str_utf8_as_unicode_and_size(a.data() + offset_a, &offset_a); + const uint32_t unicode_a = BLI_str_utf8_as_unicode_step(a.data(), a.size(), &offset_a); uint32_t prev_unicode_b; size_t offset_b = 0; for (const int j : IndexRange(size_b)) { - const uint32_t unicode_b = BLI_str_utf8_as_unicode_and_size(b.data() + offset_b, &offset_b); + const uint32_t unicode_b = BLI_str_utf8_as_unicode_step(b.data(), b.size(), &offset_b); /* Check how costly the different operations would be and pick the cheapest - the one with * minimal cost. */ @@ -202,8 +202,8 @@ static bool match_word_initials(StringRef query, int first_found_word_index = -1; while (query_index < query.size()) { - const uint query_unicode = BLI_str_utf8_as_unicode_and_size(query.data() + query_index, - &query_index); + const uint query_unicode = BLI_str_utf8_as_unicode_step( + query.data(), query.size(), &query_index); while (true) { /* We are at the end of words, no complete match has been found yet. */ if (word_index >= words.size()) { @@ -226,8 +226,8 @@ static bool match_word_initials(StringRef query, StringRef word = words[word_index]; /* Try to match the current character with the current word. */ if (static_cast(char_index) < word.size()) { - const uint32_t char_unicode = BLI_str_utf8_as_unicode_and_size(word.data() + char_index, - &char_index); + const uint32_t char_unicode = BLI_str_utf8_as_unicode_step( + word.data(), word.size(), &char_index); if (query_unicode == char_unicode) { r_word_is_matched[word_index] = true; if (first_found_word_index == -1) { @@ -368,8 +368,9 @@ void extract_normalized_words(StringRef str, size_t word_start = 0; size_t offset = 0; while (offset < str_size_in_bytes) { - size_t size = 0; - uint32_t unicode = BLI_str_utf8_as_unicode_and_size(str.data() + offset, &size); + size_t size = offset; + uint32_t unicode = BLI_str_utf8_as_unicode_step(str.data(), str.size(), &size); + size -= offset; if (is_separator(unicode)) { if (is_in_word) { r_words.append( diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index 06fd3168c24..7a01077bb44 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -546,40 +546,6 @@ uint BLI_str_utf8_as_unicode(const char *p) return result; } -/* variant that increments the length */ -uint BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index) -{ - int i, len; - uint mask = 0; - uint result; - const unsigned char c = (unsigned char)*p; - - UTF8_COMPUTE(c, mask, len, -1); - if (UNLIKELY(len == -1)) { - return BLI_UTF8_ERR; - } - UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR); - *index += (size_t)len; - return result; -} - -uint BLI_str_utf8_as_unicode_and_size_safe(const char *__restrict p, size_t *__restrict index) -{ - int i, len; - uint mask = 0; - uint result; - const unsigned char c = (unsigned char)*p; - - UTF8_COMPUTE(c, mask, len, -1); - if (UNLIKELY(len == -1)) { - *index += 1; - return c; - } - UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR); - *index += (size_t)len; - return result; -} - /** * UTF8 decoding that steps over the index (unless an error is encountered). * @@ -709,16 +675,23 @@ size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, memset(dst_w, 0xff, sizeof(*dst_w) * maxncpy); #endif + const size_t src_c_len = strlen(src_c); + const char *src_c_end = src_c + src_c_len; + size_t index = 0; while (*src_c && len != maxlen) { - size_t step = 0; - uint unicode = BLI_str_utf8_as_unicode_and_size(src_c, &step); + const uint unicode = BLI_str_utf8_as_unicode_step_or_error(src_c, src_c_len, &index); if (unicode != BLI_UTF8_ERR) { *dst_w = unicode; - src_c += step; } else { *dst_w = '?'; - src_c = BLI_str_find_next_char_utf8(src_c, NULL); + const char *src_c_next = BLI_str_find_next_char_utf8(src_c + index, src_c_end); + if (src_c_next != NULL) { + index = (size_t)(src_c_next - src_c); + } + else { + index += 1; + } } dst_w++; len++; @@ -898,7 +871,9 @@ size_t BLI_str_partition_ex_utf8(const char *str, index = 0; *sep >= str && (!end || *sep < end) && **sep != '\0'; *sep = (char *)(from_right ? BLI_str_find_prev_char_utf8(str, *sep) : str + index)) { - const uint c = BLI_str_utf8_as_unicode_and_size(*sep, &index); + size_t index_ofs = 0; + const uint c = BLI_str_utf8_as_unicode_step_or_error(*sep, (size_t)(end - *sep), &index_ofs); + index += index_ofs; if (c == BLI_UTF8_ERR) { *suf = *sep = NULL; diff --git a/source/blender/editors/space_text/text_autocomplete.c b/source/blender/editors/space_text/text_autocomplete.c index a38ed12e53b..32e455f3ac9 100644 --- a/source/blender/editors/space_text/text_autocomplete.c +++ b/source/blender/editors/space_text/text_autocomplete.c @@ -177,13 +177,12 @@ static GHash *text_autocomplete_build(Text *text) i_pos = i_start; while ((i_start < linep->len) && (!text_check_identifier_nodigit_unicode( - BLI_str_utf8_as_unicode_and_size_safe(&linep->line[i_start], &i_pos)))) { + BLI_str_utf8_as_unicode_step(linep->line, linep->len, &i_pos)))) { i_start = i_pos; } i_pos = i_end = i_start; - while ((i_end < linep->len) && - (text_check_identifier_unicode( - BLI_str_utf8_as_unicode_and_size_safe(&linep->line[i_end], &i_pos)))) { + while ((i_end < linep->len) && (text_check_identifier_unicode(BLI_str_utf8_as_unicode_step( + linep->line, linep->len, &i_pos)))) { i_end = i_pos; } diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index b910648495b..21a3c087197 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -649,10 +649,9 @@ static void rna_Event_unicode_get(PointerRNA *ptr, char *value) size_t len = 0; if (event->utf8_buf[0]) { - BLI_str_utf8_as_unicode_and_size(event->utf8_buf, &len); - if (len > 0) { + if (BLI_str_utf8_as_unicode_step_or_error(event->utf8_buf, sizeof(event->utf8_buf), &len) != + BLI_UTF8_ERR) memcpy(value, event->utf8_buf, len); - } } value[len] = '\0'; -- cgit v1.2.3 From 820d50d3cbf3a3995ca5a4051c82e8ee24805796 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Aug 2021 15:36:40 +1000 Subject: Correct error in 38630711a02e553f209ace9a8627a7a851820a2d --- source/blender/blenlib/intern/string_utf8.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index 7a01077bb44..cc6a192f6ba 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -678,7 +678,7 @@ size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const size_t src_c_len = strlen(src_c); const char *src_c_end = src_c + src_c_len; size_t index = 0; - while (*src_c && len != maxlen) { + while ((index < src_c_len) && (len != maxlen)) { const uint unicode = BLI_str_utf8_as_unicode_step_or_error(src_c, src_c_len, &index); if (unicode != BLI_UTF8_ERR) { *dst_w = unicode; -- cgit v1.2.3 From 9df063df19fd7c225518d900f851cdf8ecefd726 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Aug 2021 17:18:26 +1000 Subject: Fix assert caused by 38630711a02e553f209ace9a8627a7a851820a2d --- source/blender/blenlib/intern/string_cursor_utf8.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index 59b9f4eeca0..f76a3114e09 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -168,6 +168,9 @@ void BLI_str_cursor_step_utf8(const char *str, * list of special character, ctr -> */ while ((*pos) < maxlen) { if (BLI_str_cursor_step_next_utf8(str, maxlen, pos)) { + if (*pos == maxlen) { + break; + } if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type_utf8(str, maxlen, *pos))) { break; -- cgit v1.2.3 From b98b9354b2ee52c1286978694f4e3087cfcff9bc Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 25 Aug 2021 09:37:12 +0200 Subject: Cleanup: Fixed compile error in debug code. --- source/blender/editors/space_file/filelist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index f8ae4be9471..1a53d25ad39 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -1590,7 +1590,7 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry preview->flags = entry->typeflag; preview->in_memory_preview = intern_entry->local_data.preview_image; preview->icon_id = 0; - // printf("%s: %d - %s - %p\n", __func__, preview->index, preview->path, preview->img); + // printf("%s: %d - %s\n", __func__, preview->index, preview->path); filelist_cache_preview_ensure_running(cache); -- cgit v1.2.3 From a2597f8b833ccbccd509e90f4527b093a5580b9e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Aug 2021 17:39:50 +1000 Subject: Keymap: repeat was disabled for Ctrl-Backspace in the text editor --- release/scripts/presets/keyconfig/keymap_data/blender_default.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index 55f60329a97..0e5a5b84e81 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -2498,7 +2498,7 @@ def km_text(params): {"properties": [("type", 'PREVIOUS_CHARACTER')]}), ("text.delete", {"type": 'DEL', "value": 'PRESS', "ctrl": True, "repeat": True}, {"properties": [("type", 'NEXT_WORD')]}), - ("text.delete", {"type": 'BACK_SPACE', "value": 'PRESS', "ctrl": True}, + ("text.delete", {"type": 'BACK_SPACE', "value": 'PRESS', "ctrl": True, "repeat": True}, {"properties": [("type", 'PREVIOUS_WORD')]}), ("text.overwrite_toggle", {"type": 'INSERT', "value": 'PRESS'}, None), ("text.scroll_bar", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), -- cgit v1.2.3 From e91fd3b816b6362b1f065f2a46bfcfd5cc545185 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 25 Aug 2021 09:56:07 +0200 Subject: Cleanup: separate IMB_thumb_load_blend in multiple functions. --- source/blender/imbuf/intern/thumbs_blend.c | 99 ++++++++++++++++-------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index 759f96af7c8..878aa44f0d9 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -41,64 +41,73 @@ #include "MEM_guardedalloc.h" -ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id) +static ImBuf *imb_thumb_load_from_blend_id(const char *blen_path, + const char *blen_group, + const char *blen_id) { ImBuf *ima = NULL; + LinkNode *ln, *names, *lp, *previews = NULL; + BlendFileReadReport bf_reports = {.reports = NULL}; + struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports); + int idcode = BKE_idtype_idcode_from_name(blen_group); + int i, nprevs, nnames; + + if (libfiledata == NULL) { + return NULL; + } - if (blen_group && blen_id) { - LinkNode *ln, *names, *lp, *previews = NULL; - BlendFileReadReport bf_reports = {.reports = NULL}; - struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports); - int idcode = BKE_idtype_idcode_from_name(blen_group); - int i, nprevs, nnames; - - if (libfiledata == NULL) { - return ima; - } - - /* NOTE: we should handle all previews for a same group at once, would avoid reopening - * `.blend` file for each and every ID. However, this adds some complexity, - * so keep it for later. */ - names = BLO_blendhandle_get_datablock_names(libfiledata, idcode, false, &nnames); - previews = BLO_blendhandle_get_previews(libfiledata, idcode, &nprevs); - - BLO_blendhandle_close(libfiledata); - - if (!previews || (nnames != nprevs)) { - if (previews != 0) { - /* No previews at all is not a bug! */ - printf("%s: error, found %d items, %d previews\n", __func__, nnames, nprevs); - } - BLI_linklist_free(previews, BKE_previewimg_freefunc); - BLI_linklist_freeN(names); - return ima; - } + /* NOTE: we should handle all previews for a same group at once, would avoid reopening + * `.blend` file for each and every ID. However, this adds some complexity, + * so keep it for later. */ + names = BLO_blendhandle_get_datablock_names(libfiledata, idcode, false, &nnames); + previews = BLO_blendhandle_get_previews(libfiledata, idcode, &nprevs); - for (i = 0, ln = names, lp = previews; i < nnames; i++, ln = ln->next, lp = lp->next) { - const char *blockname = ln->link; - PreviewImage *img = lp->link; + BLO_blendhandle_close(libfiledata); - if (STREQ(blockname, blen_id)) { - if (img) { - ima = BKE_previewimg_to_imbuf(img, ICON_SIZE_PREVIEW); - } - break; - } + if (!previews || (nnames != nprevs)) { + if (previews != 0) { + /* No previews at all is not a bug! */ + printf("%s: error, found %d items, %d previews\n", __func__, nnames, nprevs); } - BLI_linklist_free(previews, BKE_previewimg_freefunc); BLI_linklist_freeN(names); + return NULL; } - else { - BlendThumbnail *data; - data = BLO_thumbnail_from_file(blen_path); - ima = BKE_main_thumbnail_to_imbuf(NULL, data); + for (i = 0, ln = names, lp = previews; i < nnames; i++, ln = ln->next, lp = lp->next) { + const char *blockname = ln->link; + PreviewImage *img = lp->link; - if (data) { - MEM_freeN(data); + if (STREQ(blockname, blen_id)) { + if (img) { + ima = BKE_previewimg_to_imbuf(img, ICON_SIZE_PREVIEW); + } + break; } } + BLI_linklist_free(previews, BKE_previewimg_freefunc); + BLI_linklist_freeN(names); return ima; } + +static ImBuf *imb_thumb_load_from_blendfile(const char *blen_path) +{ + BlendThumbnail *data = BLO_thumbnail_from_file(blen_path); + ImBuf *ima = BKE_main_thumbnail_to_imbuf(NULL, data); + + if (data) { + MEM_freeN(data); + } + return ima; +} + +ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id) +{ + if (blen_group && blen_id) { + return imb_thumb_load_from_blend_id(blen_path, blen_group, blen_id); + } + else { + return imb_thumb_load_from_blendfile(blen_path); + } +} -- cgit v1.2.3 From 8d634c1b27dca7b0b30da461c4be5dccbdbfea9e Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 25 Aug 2021 10:00:18 +0200 Subject: Cleanup: Mentioning incorrect source file in comment. Code mentions that ID_* were defined in DNA_ID.h but are actually defined in DNA_ID_enums.h. --- source/blender/blenkernel/BKE_idtype.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h index 28171b2b363..b0939ec884d 100644 --- a/source/blender/blenkernel/BKE_idtype.h +++ b/source/blender/blenkernel/BKE_idtype.h @@ -114,8 +114,8 @@ typedef struct IDTypeInfo { /* ********** General IDType data. ********** */ /** - * Unique identifier of this type, either as a short or an array of two chars, see DNA_ID.h's - * ID_XX enums. + * Unique identifier of this type, either as a short or an array of two chars, see + * DNA_ID_enums.h's ID_XX enums. */ short id_code; /** -- cgit v1.2.3 From 452cc0193255c9e80ca4f163a2d524ed6bb17ef1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Aug 2021 17:59:47 +1000 Subject: Cleanup: skip saving selection properties set in the keymap Having settings such as "extend" saved between executions causes keymaps that don't include this setting to remember the value between execution. No longer store this setting for selection operations & remove redundant values from the key-maps, see: T90275. --- .../keyconfig/keymap_data/blender_default.py | 135 +++++++++------------ source/blender/editors/armature/pose_select.c | 13 +- source/blender/editors/space_clip/clip_graph_ops.c | 13 +- .../blender/editors/space_clip/tracking_select.c | 11 +- source/blender/editors/space_graph/graph_edit.c | 13 +- source/blender/editors/space_node/node_select.cc | 12 +- 6 files changed, 93 insertions(+), 104 deletions(-) diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index 0e5a5b84e81..6a9306c2eab 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -796,11 +796,11 @@ def km_outliner(params): ("outliner.item_rename", {"type": 'F2', "value": 'PRESS'}, {"properties": [("use_active", True)]}), ("outliner.item_activate", {"type": 'LEFTMOUSE', "value": 'CLICK'}, - {"properties": [("extend", False), ("deselect_all", not params.legacy)]}), + {"properties": [("deselect_all", not params.legacy)]}), ("outliner.item_activate", {"type": 'LEFTMOUSE', "value": 'CLICK', "ctrl": True}, {"properties": [("extend", True), ("deselect_all", not params.legacy)]}), ("outliner.item_activate", {"type": 'LEFTMOUSE', "value": 'CLICK', "shift": True}, - {"properties": [("extend", False), ("extend_range", True), ("deselect_all", not params.legacy)]}), + {"properties": [("extend_range", True), ("deselect_all", not params.legacy)]}), ("outliner.item_activate", {"type": 'LEFTMOUSE', "value": 'CLICK', "ctrl": True, "shift": True}, {"properties": [("extend", True), ("extend_range", True), ("deselect_all", not params.legacy)]}), ("outliner.select_box", {"type": 'B', "value": 'PRESS'}, None), @@ -884,15 +884,13 @@ def km_uv_editor(params): *_template_items_uv_select_mode(params), ("uv.mark_seam", {"type": 'E', "value": 'PRESS', "ctrl": True}, None), ("uv.select", {"type": params.select_mouse, "value": params.select_mouse_value}, - {"properties": [("extend", False), ("deselect_all", not params.legacy)]}), + {"properties": [("deselect_all", not params.legacy)]}), ("uv.select", {"type": params.select_mouse, "value": params.select_mouse_value, "shift": True}, {"properties": [("extend", True)]}), - ("uv.select_loop", {"type": params.select_mouse, "value": params.select_mouse_value, "alt": True}, - {"properties": [("extend", False)]}), + ("uv.select_loop", {"type": params.select_mouse, "value": params.select_mouse_value, "alt": True}, None), ("uv.select_loop", {"type": params.select_mouse, "value": params.select_mouse_value, "shift": True, "alt": True}, {"properties": [("extend", True)]}), - ("uv.select_edge_ring", {"type": params.select_mouse, "value": params.select_mouse_value, "ctrl": True, "alt": True}, - {"properties": [("extend", False)]}), + ("uv.select_edge_ring", {"type": params.select_mouse, "value": params.select_mouse_value, "ctrl": True, "alt": True}, None), ("uv.select_edge_ring", {"type": params.select_mouse, "value": params.select_mouse_value, "ctrl": True, "shift": True, "alt": True}, {"properties": [("extend", True)]}), ("uv.shortest_path_pick", {"type": params.select_mouse, "value": params.select_mouse_value, "ctrl": True}, @@ -913,7 +911,7 @@ def km_uv_editor(params): ("uv.select_linked_pick", {"type": 'L', "value": 'PRESS'}, {"properties": [("extend", True), ("deselect", False)]}), ("uv.select_linked_pick", {"type": 'L', "value": 'PRESS', "shift": True}, - {"properties": [("extend", False), ("deselect", True)]}), + {"properties": [("deselect", True)]}), ("uv.select_more", {"type": 'NUMPAD_PLUS', "value": 'PRESS', "ctrl": True, "repeat": True}, None), ("uv.select_less", {"type": 'NUMPAD_MINUS', "value": 'PRESS', "ctrl": True, "repeat": True}, None), *_template_items_select_actions(params, "uv.select_all"), @@ -957,8 +955,7 @@ def km_uv_editor(params): # Fallback for MMB emulation if params.use_mouse_emulate_3_button and params.select_mouse == 'LEFTMOUSE': items.extend([ - ("uv.select_loop", {"type": params.select_mouse, "value": 'DOUBLE_CLICK'}, - {"properties": [("extend", False)]}), + ("uv.select_loop", {"type": params.select_mouse, "value": 'DOUBLE_CLICK'}, None), ("uv.select_loop", {"type": params.select_mouse, "value": 'DOUBLE_CLICK', "alt": True}, {"properties": [("extend", True)]}), ]) @@ -1354,9 +1351,7 @@ def km_mask_editing(params): # click select keymap it's fine to have the context menu instead. items.extend([ ("mask.select", {"type": 'RIGHTMOUSE', "value": 'PRESS'}, - {"properties": [ - ("extend", False), ("deselect", False), ("toggle", False), - ("deselect_all", not params.legacy)]}), + {"properties": [("deselect_all", not params.legacy)]}), ("transform.translate", {"type": 'EVT_TWEAK_R', "value": 'ANY'}, None), ]) @@ -1370,7 +1365,7 @@ def km_mask_editing(params): ("mask.delete", {"type": 'X', "value": 'PRESS'}, None), ("mask.delete", {"type": 'DEL', "value": 'PRESS'}, None), ("mask.select", {"type": params.select_mouse, "value": 'PRESS', "shift": True}, - {"properties": [("extend", False), ("deselect", False), ("toggle", True)]}), + {"properties": [("toggle", True)]}), *_template_items_select_actions(params, "mask.select_all"), ("mask.select_linked", {"type": 'L', "value": 'PRESS', "ctrl": True}, None), ("mask.select_linked_pick", {"type": 'L', "value": 'PRESS'}, @@ -1390,8 +1385,7 @@ def km_mask_editing(params): {"properties": [("unselected", False)]}), ("mask.hide_view_set", {"type": 'H', "value": 'PRESS', "shift": True}, {"properties": [("unselected", True)]}), - ("clip.select", {"type": params.select_mouse, "value": 'PRESS', "ctrl": True}, - {"properties": [("extend", False)]}), + ("clip.select", {"type": params.select_mouse, "value": 'PRESS', "ctrl": True}, None), ("mask.cyclic_toggle", {"type": 'C', "value": 'PRESS', "alt": True}, None), ("mask.slide_point", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), ("mask.slide_spline_curvature", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), @@ -1446,7 +1440,7 @@ def km_markers(params): ("marker.select", {"type": params.select_mouse, "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), ("marker.select", {"type": params.select_mouse, "value": 'PRESS', "ctrl": True}, - {"properties": [("extend", False), ("camera", True)]}), + {"properties": [("camera", True)]}), ("marker.select", {"type": params.select_mouse, "value": 'PRESS', "shift": True, "ctrl": True}, {"properties": [("extend", True), ("camera", True)]}), ("marker.select_box", {"type": params.select_tweak, "value": 'ANY'}, @@ -1531,29 +1525,27 @@ def km_graph_editor(params): ("wm.context_toggle", {"type": 'H', "value": 'PRESS', "ctrl": True}, {"properties": [("data_path", 'space_data.show_handles')]}), ("graph.clickselect", {"type": params.select_mouse, "value": 'PRESS'}, - {"properties": [ - ("extend", False), ("deselect_all", not params.legacy), - ("column", False), ("curves", False)]}), + {"properties": [("deselect_all", not params.legacy)]}), ("graph.clickselect", {"type": params.select_mouse, "value": 'PRESS', "alt": True}, - {"properties": [("extend", False), ("column", True), ("curves", False)]}), + {"properties": [("column", True)]}), ("graph.clickselect", {"type": params.select_mouse, "value": 'PRESS', "shift": True}, - {"properties": [("extend", True), ("column", False), ("curves", False)]}), + {"properties": [("extend", True)]}), ("graph.clickselect", {"type": params.select_mouse, "value": 'PRESS', "shift": True, "alt": True}, - {"properties": [("extend", True), ("column", True), ("curves", False)]}), + {"properties": [("extend", True), ("column", True)]}), ("graph.clickselect", {"type": params.select_mouse, "value": 'PRESS', "ctrl": True, "alt": True}, - {"properties": [("extend", False), ("column", False), ("curves", True)]}), + {"properties": [("curves", True)]}), ("graph.clickselect", {"type": params.select_mouse, "value": 'PRESS', "shift": True, "ctrl": True, "alt": True}, - {"properties": [("extend", True), ("column", False), ("curves", True)]}), + {"properties": [("extend", True), ("curves", True)]}), ("graph.select_leftright", {"type": params.select_mouse, "value": 'PRESS' if params.legacy else 'CLICK', "ctrl": True}, - {"properties": [("mode", 'CHECK'), ("extend", False)]}), + {"properties": [("mode", 'CHECK')]}), ("graph.select_leftright", {"type": params.select_mouse, "value": 'PRESS' if params.legacy else 'CLICK', "ctrl": True, "shift": True}, {"properties": [("mode", 'CHECK'), ("extend", True)]}), ("graph.select_leftright", {"type": 'LEFT_BRACKET', "value": 'PRESS'}, - {"properties": [("mode", 'LEFT'), ("extend", False)]}), + {"properties": [("mode", 'LEFT')]}), ("graph.select_leftright", {"type": 'RIGHT_BRACKET', "value": 'PRESS'}, - {"properties": [("mode", 'RIGHT'), ("extend", False)]}), + {"properties": [("mode", 'RIGHT')]}), *_template_items_select_actions(params, "graph.select_all"), ("graph.select_box", {"type": 'B', "value": 'PRESS'}, None), ("graph.select_box", {"type": 'B', "value": 'PRESS', "alt": True}, @@ -1597,8 +1589,7 @@ def km_graph_editor(params): ("graph.delete", {"type": 'DEL', "value": 'PRESS'}, {"properties": [("confirm", False)]}), ("graph.duplicate_move", {"type": 'D', "value": 'PRESS', "shift": True}, None), ("graph.keyframe_insert", {"type": 'I', "value": 'PRESS'}, None), - ("graph.click_insert", {"type": params.action_mouse, "value": 'CLICK', "ctrl": True}, - {"properties": [("extend", False)]}), + ("graph.click_insert", {"type": params.action_mouse, "value": 'CLICK', "ctrl": True}, None), ("graph.click_insert", {"type": params.action_mouse, "value": 'CLICK', "shift": True, "ctrl": True}, {"properties": [("extend", True)]}), ("graph.copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None), @@ -1804,13 +1795,10 @@ def km_node_editor(params): def node_select_ops(select_mouse): return [ ("node.select", {"type": select_mouse, "value": 'PRESS'}, - {"properties": [("extend", False), ("deselect_all", True)]}), - ("node.select", {"type": select_mouse, "value": 'PRESS', "ctrl": True}, - {"properties": [("extend", False)]}), - ("node.select", {"type": select_mouse, "value": 'PRESS', "alt": True}, - {"properties": [("extend", False)]}), - ("node.select", {"type": select_mouse, "value": 'PRESS', "ctrl": True, "alt": True}, - {"properties": [("extend", False)]}), + {"properties": [("deselect_all", True)]}), + ("node.select", {"type": select_mouse, "value": 'PRESS', "ctrl": True}, None), + ("node.select", {"type": select_mouse, "value": 'PRESS', "alt": True}, None), + ("node.select", {"type": select_mouse, "value": 'PRESS', "ctrl": True, "alt": True}, None), ("node.select", {"type": select_mouse, "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), ("node.select", {"type": select_mouse, "value": 'PRESS', "shift": True, "ctrl": True}, @@ -1832,7 +1820,7 @@ def km_node_editor(params): items.extend(node_select_ops('RIGHTMOUSE')) items.extend([ ("node.select", {"type": 'LEFTMOUSE', "value": 'PRESS'}, - {"properties": [("extend", False), ("deselect_all", False)]}), + {"properties": [("deselect_all", False)]}), ("node.select", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), ]) @@ -1887,8 +1875,7 @@ def km_node_editor(params): *_template_items_select_actions(params, "node.select_all"), ("node.select_linked_to", {"type": 'L', "value": 'PRESS', "shift": True}, None), ("node.select_linked_from", {"type": 'L', "value": 'PRESS'}, None), - ("node.select_grouped", {"type": 'G', "value": 'PRESS', "shift": True}, - {"properties": [("extend", False)]}), + ("node.select_grouped", {"type": 'G', "value": 'PRESS', "shift": True}, None), ("node.select_grouped", {"type": 'G', "value": 'PRESS', "shift": True, "ctrl": True}, {"properties": [("extend", True)]}), ("node.select_same_type_step", {"type": 'RIGHT_BRACKET', "value": 'PRESS', "shift": True}, @@ -2131,29 +2118,27 @@ def km_dopesheet(params): items.extend([ ("action.clickselect", {"type": params.select_mouse, "value": 'PRESS'}, - {"properties": [ - ("extend", False), ("deselect_all", not params.legacy), - ("column", False), ("channel", False)]}), + {"properties": [("deselect_all", not params.legacy)]}), ("action.clickselect", {"type": params.select_mouse, "value": 'PRESS', "alt": True}, - {"properties": [("extend", False), ("column", True), ("channel", False)]}), + {"properties": [("column", True)]}), ("action.clickselect", {"type": params.select_mouse, "value": 'PRESS', "shift": True}, - {"properties": [("extend", True), ("column", False), ("channel", False)]}), + {"properties": [("extend", True)]}), ("action.clickselect", {"type": params.select_mouse, "value": 'PRESS', "shift": True, "alt": True}, - {"properties": [("extend", True), ("column", True), ("channel", False)]}), + {"properties": [("extend", True), ("column", True)]}), ("action.clickselect", {"type": params.select_mouse, "value": 'PRESS', "ctrl": True, "alt": True}, - {"properties": [("extend", False), ("column", False), ("channel", True)]}), + {"properties": [("channel", True)]}), ("action.clickselect", {"type": params.select_mouse, "value": 'PRESS', "shift": True, "ctrl": True, "alt": True}, - {"properties": [("extend", True), ("column", False), ("channel", True)]}), + {"properties": [("extend", True), ("channel", True)]}), ("action.select_leftright", {"type": params.select_mouse, "value": 'PRESS' if params.legacy else 'CLICK', "ctrl": True}, - {"properties": [("mode", 'CHECK'), ("extend", False)]}), + {"properties": [("mode", 'CHECK')]}), ("action.select_leftright", {"type": params.select_mouse, "value": 'PRESS' if params.legacy else 'CLICK', "ctrl": True, "shift": True}, {"properties": [("mode", 'CHECK'), ("extend", True)]}), ("action.select_leftright", {"type": 'LEFT_BRACKET', "value": 'PRESS'}, - {"properties": [("mode", 'LEFT'), ("extend", False)]}), + {"properties": [("mode", 'LEFT')]}), ("action.select_leftright", {"type": 'RIGHT_BRACKET', "value": 'PRESS'}, - {"properties": [("mode", 'RIGHT'), ("extend", False)]}), + {"properties": [("mode", 'RIGHT')]}), *_template_items_select_actions(params, "action.select_all"), ("action.select_box", {"type": 'B', "value": 'PRESS'}, {"properties": [("axis_range", False)]}), @@ -2264,8 +2249,7 @@ def km_nla_channels(params): ) items.extend([ - ("nla.channels_click", {"type": 'LEFTMOUSE', "value": 'PRESS'}, - {"properties": [("extend", False)]}), + ("nla.channels_click", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), ("nla.channels_click", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), ("nla.tracks_add", {"type": 'A', "value": 'PRESS', "shift": True}, @@ -2290,19 +2274,19 @@ def km_nla_editor(params): items.extend([ ("nla.click_select", {"type": params.select_mouse, "value": 'PRESS'}, - {"properties": [("extend", False), ("deselect_all", not params.legacy)]}), + {"properties": [("deselect_all", not params.legacy)]}), ("nla.click_select", {"type": params.select_mouse, "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), ("nla.select_leftright", {"type": params.select_mouse, "value": 'PRESS' if params.legacy else 'CLICK', "ctrl": True}, - {"properties": [("mode", 'CHECK'), ("extend", False)]}), + {"properties": [("mode", 'CHECK')]}), ("nla.select_leftright", {"type": params.select_mouse, "value": 'PRESS' if params.legacy else 'CLICK', "ctrl": True, "shift": True}, {"properties": [("mode", 'CHECK'), ("extend", True)]}), ("nla.select_leftright", {"type": 'LEFT_BRACKET', "value": 'PRESS'}, - {"properties": [("mode", 'LEFT'), ("extend", False)]}), + {"properties": [("mode", 'LEFT')]}), ("nla.select_leftright", {"type": 'RIGHT_BRACKET', "value": 'PRESS'}, - {"properties": [("mode", 'RIGHT'), ("extend", False)]}), + {"properties": [("mode", 'RIGHT')]}), *_template_items_select_actions(params, "nla.select_all"), ("nla.select_box", {"type": 'B', "value": 'PRESS'}, {"properties": [("axis_range", False)]}), @@ -2638,8 +2622,7 @@ def km_sequencer(params): {"properties": [("side_of_frame", True), ("linked_time", True), ("extend", True)]}), ("sequencer.select_more", {"type": 'NUMPAD_PLUS', "value": 'PRESS', "ctrl": True, "repeat": True}, None), ("sequencer.select_less", {"type": 'NUMPAD_MINUS', "value": 'PRESS', "ctrl": True, "repeat": True}, None), - ("sequencer.select_linked_pick", {"type": 'L', "value": 'PRESS'}, - {"properties": [("extend", False)]}), + ("sequencer.select_linked_pick", {"type": 'L', "value": 'PRESS'}, None), ("sequencer.select_linked_pick", {"type": 'L', "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), ("sequencer.select_linked", {"type": 'L', "value": 'PRESS', "ctrl": True}, None), @@ -2862,7 +2845,7 @@ def km_clip_editor(params): {"properties": [("position", 'PATHSTART')]}), ("clip.change_frame", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), ("clip.select", {"type": params.select_mouse, "value": 'PRESS'}, - {"properties": [("extend", False), ("deselect_all", not params.legacy)]}), + {"properties": [("deselect_all", not params.legacy)]}), ("clip.select", {"type": params.select_mouse, "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), *_template_items_select_actions(params, "clip.select_all"), @@ -2948,8 +2931,7 @@ def km_clip_graph_editor(params): ) items.extend([ - ("clip.graph_select", {"type": params.select_mouse, "value": 'PRESS'}, - {"properties": [("extend", False)]}), + ("clip.graph_select", {"type": params.select_mouse, "value": 'PRESS'}, None), ("clip.graph_select", {"type": params.select_mouse, "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), *_template_items_select_actions(params, "clip.graph_select_all_markers"), @@ -4241,8 +4223,7 @@ def km_paint_curve(params): items.extend([ ("paintcurve.add_point_slide", {"type": params.action_mouse, "value": 'PRESS', "ctrl": True}, None), - ("paintcurve.select", {"type": params.select_mouse, "value": 'PRESS'}, - {"properties": [("extend", False)]}), + ("paintcurve.select", {"type": params.select_mouse, "value": 'PRESS'}, None), ("paintcurve.select", {"type": params.select_mouse, "value": 'PRESS', "shift": True}, {"properties": [("extend", True)]}), ("paintcurve.slide", {"type": params.action_mouse, "value": 'PRESS'}, @@ -4664,15 +4645,13 @@ def km_mesh(params): # Selection modes. *_template_items_editmode_mesh_select_mode(params), # Loop Select with alt. Double click in case MMB emulation is on (below). - ("mesh.loop_select", {"type": params.select_mouse, "value": params.select_mouse_value, "alt": True}, - {"properties": [("extend", False), ("deselect", False), ("toggle", False)]}), + ("mesh.loop_select", {"type": params.select_mouse, "value": params.select_mouse_value, "alt": True}, None), ("mesh.loop_select", {"type": params.select_mouse, "value": params.select_mouse_value, "shift": True, "alt": True}, - {"properties": [("extend", False), ("deselect", False), ("toggle", True)]}), + {"properties": [("toggle", True)]}), # Selection - ("mesh.edgering_select", {"type": params.select_mouse, "value": params.select_mouse_value, "ctrl": True, "alt": True}, - {"properties": [("extend", False), ("deselect", False), ("toggle", False)]}), + ("mesh.edgering_select", {"type": params.select_mouse, "value": params.select_mouse_value, "ctrl": True, "alt": True}, None), ("mesh.edgering_select", {"type": params.select_mouse, "value": params.select_mouse_value, "shift": True, "ctrl": True, "alt": True}, - {"properties": [("extend", False), ("deselect", False), ("toggle", True)]}), + {"properties": [("toggle", True)]}), ("mesh.shortest_path_pick", {"type": params.select_mouse, "value": params.select_mouse_value, "ctrl": True}, {"properties": [("use_fill", False)]}), ("mesh.shortest_path_pick", {"type": params.select_mouse, "value": params.select_mouse_value, "shift": True, "ctrl": True}, @@ -4754,16 +4733,14 @@ def km_mesh(params): if params.use_mouse_emulate_3_button and params.select_mouse == 'LEFTMOUSE': items.extend([ - ("mesh.loop_select", {"type": params.select_mouse, "value": 'DOUBLE_CLICK'}, - {"properties": [("extend", False), ("deselect", False), ("toggle", False)]}), + ("mesh.loop_select", {"type": params.select_mouse, "value": 'DOUBLE_CLICK'}, None), ("mesh.loop_select", {"type": params.select_mouse, "value": 'DOUBLE_CLICK', "shift": True}, - {"properties": [("extend", True), ("deselect", False), ("toggle", False)]}), + {"properties": [("extend", True)]}), ("mesh.loop_select", {"type": params.select_mouse, "value": 'DOUBLE_CLICK', "alt": True}, - {"properties": [("extend", False), ("deselect", True), ("toggle", False)]}), - ("mesh.edgering_select", {"type": params.select_mouse, "value": 'DOUBLE_CLICK', "ctrl": True}, - {"properties": [("extend", False), ("deselect", False), ("toggle", False)]}), + {"properties": [("deselect", True)]}), + ("mesh.edgering_select", {"type": params.select_mouse, "value": 'DOUBLE_CLICK', "ctrl": True}, None), ("mesh.edgering_select", {"type": params.select_mouse, "value": 'DOUBLE_CLICK', "shift": True, "ctrl": True}, - {"properties": [("extend", False), ("deselect", False), ("toggle", True)]}), + {"properties": [("toggle", True)]}), ]) if params.legacy: @@ -5953,7 +5930,7 @@ def km_node_editor_tool_select(params): {"space_type": 'NODE_EDITOR', "region_type": 'WINDOW'}, {"items": [ ("node.select", {"type": params.select_mouse, "value": 'PRESS'}, - {"properties": [("extend", False), ("deselect_all", not params.legacy)]}), + {"properties": [("deselect_all", not params.legacy)]}), ]}, ) @@ -7021,7 +6998,7 @@ def km_sequencer_editor_tool_select(params): {"space_type": 'SEQUENCE_EDITOR', "region_type": 'WINDOW'}, {"items": [ ("sequencer.select", {"type": params.select_mouse, "value": 'PRESS'}, - {"properties": [("extend", False), ("deselect_all", not params.legacy)]}), + {"properties": [("deselect_all", not params.legacy)]}), *_template_items_change_frame(params), ]}, ) diff --git a/source/blender/editors/armature/pose_select.c b/source/blender/editors/armature/pose_select.c index c39fcb790dd..1dbb859fd6c 100644 --- a/source/blender/editors/armature/pose_select.c +++ b/source/blender/editors/armature/pose_select.c @@ -503,6 +503,8 @@ static bool pose_select_linked_pick_poll(bContext *C) void POSE_OT_select_linked_pick(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Select Connected"; ot->idname = "POSE_OT_select_linked_pick"; @@ -517,11 +519,12 @@ void POSE_OT_select_linked_pick(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_boolean(ot->srna, - "extend", - false, - "Extend", - "Extend selection instead of deselecting everything first"); + prop = RNA_def_boolean(ot->srna, + "extend", + false, + "Extend", + "Extend selection instead of deselecting everything first"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } static int pose_select_linked_exec(bContext *C, wmOperator *UNUSED(op)) diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c index 590f8efe105..9a4e0c7f060 100644 --- a/source/blender/editors/space_clip/clip_graph_ops.c +++ b/source/blender/editors/space_clip/clip_graph_ops.c @@ -327,6 +327,8 @@ static int select_invoke(bContext *C, wmOperator *op, const wmEvent *event) void CLIP_OT_graph_select(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Select"; ot->description = "Select graph curves"; @@ -351,11 +353,12 @@ void CLIP_OT_graph_select(wmOperatorType *ot) "Mouse location to select nearest entity", -100.0f, 100.0f); - RNA_def_boolean(ot->srna, - "extend", - 0, - "Extend", - "Extend selection rather than clearing the existing selection"); + prop = RNA_def_boolean(ot->srna, + "extend", + 0, + "Extend", + "Extend selection rather than clearing the existing selection"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /********************** box select operator *********************/ diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index 558c0bec11d..c7f0f4c228f 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -459,11 +459,12 @@ void CLIP_OT_select(wmOperatorType *ot) /* properties */ PropertyRNA *prop; - RNA_def_boolean(ot->srna, - "extend", - 0, - "Extend", - "Extend selection rather than clearing the existing selection"); + prop = RNA_def_boolean(ot->srna, + "extend", + 0, + "Extend", + "Extend selection rather than clearing the existing selection"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); prop = RNA_def_boolean(ot->srna, "deselect_all", false, diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 8bfafc6bef8..2955c4ef7ae 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -417,6 +417,8 @@ static int graphkeys_click_insert_invoke(bContext *C, wmOperator *op, const wmEv void GRAPH_OT_click_insert(wmOperatorType *ot) { + PropertyRNA *prop; + /* Identifiers */ ot->name = "Click-Insert Keyframes"; ot->idname = "GRAPH_OT_click_insert"; @@ -443,11 +445,12 @@ void GRAPH_OT_click_insert(wmOperatorType *ot) RNA_def_float( ot->srna, "value", 1.0f, -FLT_MAX, FLT_MAX, "Value", "Value for keyframe on", 0, 100); - RNA_def_boolean(ot->srna, - "extend", - false, - "Extend", - "Extend selection instead of deselecting everything first"); + prop = RNA_def_boolean(ot->srna, + "extend", + false, + "Extend", + "Extend selection instead of deselecting everything first"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /** \} */ diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index a1068f29624..adff85a2b8c 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -417,6 +417,7 @@ static int node_select_grouped_exec(bContext *C, wmOperator *op) void NODE_OT_select_grouped(wmOperatorType *ot) { + PropertyRNA *prop; static const EnumPropertyItem prop_select_grouped_types[] = { {NODE_SELECT_GROUPED_TYPE, "TYPE", 0, "Type", ""}, {NODE_SELECT_GROUPED_COLOR, "COLOR", 0, "Color", ""}, @@ -439,11 +440,12 @@ void NODE_OT_select_grouped(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_boolean(ot->srna, - "extend", - false, - "Extend", - "Extend selection instead of deselecting everything first"); + prop = RNA_def_boolean(ot->srna, + "extend", + false, + "Extend", + "Extend selection instead of deselecting everything first"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); ot->prop = RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", ""); } -- cgit v1.2.3 From a34652d6f872dab1d5b9f8be191504b0f8c35600 Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Wed, 25 Aug 2021 20:39:01 +0900 Subject: Fix: Incorrect declaration of XrActionMaps RNA This fixes a mistake in the XrActionMaps RNA struct declaration. Originally, the XrActionMaps struct SDNA was set as wmXrData to get access to wmXrRuntimeData. However, this doesn't give a valid pointer and the XrSessionState RNA pointer needs to be passed instead. Since XrSessionState itself does not have SDNA, it is necessary to pass the XrSessionState pointer to the XrActionMaps struct functions (new(), new_from_actionmap(), ...) instead of simply using RNA_def_struct_sdna(). --- source/blender/makesrna/intern/rna_xr.c | 68 ++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c index 4cab92ad878..f24d28d1209 100644 --- a/source/blender/makesrna/intern/rna_xr.c +++ b/source/blender/makesrna/intern/rna_xr.c @@ -39,6 +39,23 @@ # include "WM_api.h" +/* -------------------------------------------------------------------- */ + +# ifdef WITH_XR_OPENXR +static wmXrData *rna_XrSession_wm_xr_data_get(PointerRNA *ptr) +{ + /* Callers could also get XrSessionState pointer through ptr->data, but prefer if we just + * consistently pass wmXrData pointers to the WM_xr_xxx() API. */ + + BLI_assert((ptr->type == &RNA_XrSessionSettings) || (ptr->type == &RNA_XrSessionState)); + + wmWindowManager *wm = (wmWindowManager *)ptr->owner_id; + BLI_assert(wm && (GS(wm->id.name) == ID_WM)); + + return &wm->xr; +} +# endif + /* -------------------------------------------------------------------- */ /** \name XR Action Map * \{ */ @@ -420,29 +437,32 @@ static void rna_XrActionMapItem_update(Main *UNUSED(bmain), Scene *UNUSED(scene) # endif } -static XrActionMap *rna_XrActionMap_new(wmXrData *xr, const char *name, bool replace_existing) +static XrActionMap *rna_XrActionMap_new(PointerRNA *ptr, const char *name, bool replace_existing) { # ifdef WITH_XR_OPENXR + wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr); return WM_xr_actionmap_new(xr->runtime, name, replace_existing); # else - UNUSED_VARS(xr, name, replace_existing); + UNUSED_VARS(ptr, name, replace_existing); return NULL; # endif } -static XrActionMap *rna_XrActionMap_new_from_actionmap(wmXrData *xr, XrActionMap *am_src) +static XrActionMap *rna_XrActionMap_new_from_actionmap(PointerRNA *ptr, XrActionMap *am_src) { # ifdef WITH_XR_OPENXR + wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr); return WM_xr_actionmap_add_copy(xr->runtime, am_src); # else - UNUSED_VARS(xr, am_src); + UNUSED_VARS(ptr, am_src); return NULL; # endif } -static void rna_XrActionMap_remove(wmXrData *xr, ReportList *reports, PointerRNA *actionmap_ptr) +static void rna_XrActionMap_remove(ReportList *reports, PointerRNA *ptr, PointerRNA *actionmap_ptr) { # ifdef WITH_XR_OPENXR + wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr); XrActionMap *actionmap = actionmap_ptr->data; if (WM_xr_actionmap_remove(xr->runtime, actionmap) == false) { BKE_reportf(reports, RPT_ERROR, "ActionMap '%s' cannot be removed", actionmap->name); @@ -450,16 +470,17 @@ static void rna_XrActionMap_remove(wmXrData *xr, ReportList *reports, PointerRNA } RNA_POINTER_INVALIDATE(actionmap_ptr); # else - UNUSED_VARS(xr, reports, actionmap_ptr); + UNUSED_VARS(ptr, reports, actionmap_ptr); # endif } -static XrActionMap *rna_XrActionMap_find(wmXrData *xr, const char *name) +static XrActionMap *rna_XrActionMap_find(PointerRNA *ptr, const char *name) { # ifdef WITH_XR_OPENXR + wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr); return WM_xr_actionmap_find(xr->runtime, name); # else - UNUSED_VARS(xr, name); + UNUSED_VARS(ptr, name); return NULL; # endif } @@ -479,23 +500,6 @@ static void rna_XrActionMap_name_update(Main *bmain, Scene *UNUSED(scene), Point /** \} */ -/* -------------------------------------------------------------------- */ - -# ifdef WITH_XR_OPENXR -static wmXrData *rna_XrSession_wm_xr_data_get(PointerRNA *ptr) -{ - /* Callers could also get XrSessionState pointer through ptr->data, but prefer if we just - * consistently pass wmXrData pointers to the WM_xr_xxx() API. */ - - BLI_assert((ptr->type == &RNA_XrSessionSettings) || (ptr->type == &RNA_XrSessionState)); - - wmWindowManager *wm = (wmWindowManager *)ptr->owner_id; - BLI_assert(wm && (GS(wm->id.name) == ID_WM)); - - return &wm->xr; -} -# endif - /* -------------------------------------------------------------------- */ /** \name XR Session Settings * \{ */ @@ -1136,10 +1140,12 @@ static void rna_def_xr_actionmaps(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_property_srna(cprop, "XrActionMaps"); srna = RNA_def_struct(brna, "XrActionMaps", NULL); - RNA_def_struct_sdna(srna, "wmXrData"); RNA_def_struct_ui_text(srna, "XR Action Maps", "Collection of XR action maps"); func = RNA_def_function(srna, "new", "rna_XrActionMap_new"); + RNA_def_function_flag(func, FUNC_NO_SELF); + parm = RNA_def_pointer(func, "xr_session_state", "XrSessionState", "XR Session State", ""); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); parm = RNA_def_string(func, "name", NULL, MAX_NAME, "Name", ""); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); parm = RNA_def_boolean(func, @@ -1152,6 +1158,9 @@ static void rna_def_xr_actionmaps(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_return(func, parm); func = RNA_def_function(srna, "new_from_actionmap", "rna_XrActionMap_new_from_actionmap"); + RNA_def_function_flag(func, FUNC_NO_SELF); + parm = RNA_def_pointer(func, "xr_session_state", "XrSessionState", "XR Session State", ""); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); parm = RNA_def_pointer( func, "actionmap", "XrActionMap", "Action Map", "Action map to use as a reference"); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); @@ -1159,12 +1168,17 @@ static void rna_def_xr_actionmaps(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_return(func, parm); func = RNA_def_function(srna, "remove", "rna_XrActionMap_remove"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_REPORTS); + parm = RNA_def_pointer(func, "xr_session_state", "XrSessionState", "XR Session State", ""); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); parm = RNA_def_pointer(func, "actionmap", "XrActionMap", "Action Map", "Removed action map"); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0); func = RNA_def_function(srna, "find", "rna_XrActionMap_find"); + RNA_def_function_flag(func, FUNC_NO_SELF); + parm = RNA_def_pointer(func, "xr_session_state", "XrSessionState", "XR Session State", ""); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); parm = RNA_def_string(func, "name", NULL, MAX_NAME, "Name", ""); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); parm = RNA_def_pointer( -- cgit v1.2.3 From cb9c0aa7d02e1b505b9af5d79e8603f70471e9ab Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Wed, 25 Aug 2021 20:45:25 +0900 Subject: Fix: XR action map memory leaks This fixes two memory leaks related to XR action maps. 1. Freeing of action maps needs to be moved from wm_xr_exit() to wm_xr_runtime_data_free() since the runtime may have already been freed when calling wm_xr_exit(). 2. Action bindings for action map items were not being freed. This was mistakenly left out of e844e9e8f3bb since the patch needed to be updated after d3d4be1db3a0. --- source/blender/windowmanager/xr/intern/wm_xr.c | 4 +++- source/blender/windowmanager/xr/intern/wm_xr_actionmap.c | 13 +++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/blender/windowmanager/xr/intern/wm_xr.c b/source/blender/windowmanager/xr/intern/wm_xr.c index 3091a3a19f1..cffe14a2146 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr.c +++ b/source/blender/windowmanager/xr/intern/wm_xr.c @@ -115,7 +115,6 @@ bool wm_xr_init(wmWindowManager *wm) void wm_xr_exit(wmWindowManager *wm) { if (wm->xr.runtime != NULL) { - WM_xr_actionmaps_clear(wm->xr.runtime); wm_xr_runtime_data_free(&wm->xr.runtime); } if (wm->xr.session_settings.shading.prop) { @@ -166,6 +165,9 @@ void wm_xr_runtime_data_free(wmXrRuntimeData **runtime) /* Prevent recursive GHOST_XrContextDestroy() call by NULL'ing the context pointer before the * first call, see comment above. */ (*runtime)->context = NULL; + + WM_xr_actionmaps_clear(*runtime); + GHOST_XrContextDestroy(context); } MEM_SAFE_FREE(*runtime); diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c b/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c index f9ad34b5a9b..673fdfcd602 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c @@ -178,6 +178,12 @@ XrActionMapBinding *WM_xr_actionmap_binding_find(XrActionMapItem *ami, const cha * Item in an XR action map, that maps an XR event to an operator, pose, or haptic output. * \{ */ +static void wm_xr_actionmap_item_bindings_clear(XrActionMapItem *ami) +{ + BLI_freelistN(&ami->bindings); + ami->selbinding = -1; +} + static void wm_xr_actionmap_item_properties_set(XrActionMapItem *ami) { WM_operator_properties_alloc(&(ami->op_properties_ptr), &(ami->op_properties), ami->op); @@ -345,10 +351,8 @@ bool WM_xr_actionmap_item_remove(XrActionMap *actionmap, XrActionMapItem *ami) int idx = BLI_findindex(&actionmap->items, ami); if (idx != -1) { - if (ami->op_properties_ptr) { - WM_operator_properties_free(ami->op_properties_ptr); - MEM_freeN(ami->op_properties_ptr); - } + wm_xr_actionmap_item_bindings_clear(ami); + wm_xr_actionmap_item_properties_free(ami); BLI_freelinkN(&actionmap->items, ami); if (BLI_listbase_is_empty(&actionmap->items)) { @@ -518,6 +522,7 @@ XrActionMap *WM_xr_actionmap_find(wmXrRuntimeData *runtime, const char *name) void WM_xr_actionmap_clear(XrActionMap *actionmap) { LISTBASE_FOREACH (XrActionMapItem *, ami, &actionmap->items) { + wm_xr_actionmap_item_bindings_clear(ami); wm_xr_actionmap_item_properties_free(ami); } -- cgit v1.2.3 From d6ace5a7bbc0782b684cfab4ca4269365dd29285 Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Wed, 25 Aug 2021 20:49:47 +0900 Subject: Fix: Crash on file read with active VR session Add null check for runtime data since it could already have been freed via wm_xr_exit() (called on file read) prior to the session exit callback. Also, fix potential memory leak by freeing session data in wm_xr_runtime_data_free() instead of session exit callback. --- source/blender/windowmanager/xr/intern/wm_xr.c | 1 + source/blender/windowmanager/xr/intern/wm_xr_intern.h | 1 + source/blender/windowmanager/xr/intern/wm_xr_session.c | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/blender/windowmanager/xr/intern/wm_xr.c b/source/blender/windowmanager/xr/intern/wm_xr.c index cffe14a2146..4877addbb77 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr.c +++ b/source/blender/windowmanager/xr/intern/wm_xr.c @@ -166,6 +166,7 @@ void wm_xr_runtime_data_free(wmXrRuntimeData **runtime) * first call, see comment above. */ (*runtime)->context = NULL; + wm_xr_session_data_free(&(*runtime)->session_state); WM_xr_actionmaps_clear(*runtime); GHOST_XrContextDestroy(context); diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h index 4d4df43f796..fc54e261f79 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h +++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h @@ -174,6 +174,7 @@ typedef struct wmXrActionSet { wmXrRuntimeData *wm_xr_runtime_data_create(void); void wm_xr_runtime_data_free(wmXrRuntimeData **runtime); +void wm_xr_session_data_free(wmXrSessionState *state); void wm_xr_session_draw_data_update(const wmXrSessionState *state, const XrSessionSettings *settings, diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index ba30b0dd864..dc15b579e9d 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -68,7 +68,7 @@ static void wm_xr_session_controller_data_free(wmXrSessionState *state) BLI_freelistN(&state->controllers); } -static void wm_xr_session_data_free(wmXrSessionState *state) +void wm_xr_session_data_free(wmXrSessionState *state) { wm_xr_session_controller_data_free(state); } @@ -76,6 +76,9 @@ static void wm_xr_session_data_free(wmXrSessionState *state) static void wm_xr_session_exit_cb(void *customdata) { wmXrData *xr_data = customdata; + if (!xr_data->runtime) { + return; + } xr_data->runtime->session_state.is_started = false; @@ -84,7 +87,6 @@ static void wm_xr_session_exit_cb(void *customdata) } /* Free the entire runtime data (including session state and context), to play safe. */ - wm_xr_session_data_free(&xr_data->runtime->session_state); wm_xr_runtime_data_free(&xr_data->runtime); } -- cgit v1.2.3 From 940ba74024e57899e171c797240ce3fdebc87b16 Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Wed, 25 Aug 2021 20:55:14 +0900 Subject: XR: Improve "Invalid stage ref space" warning Originally mentioned that absolute tracking was disabled, which is wrong because absolute tracking (skipping application of eye offsets) is always available, although it may not give the expected result of persistent tracking origins across sessions if the stage space is unavailable (hence the need for a warning). Now, the warning makes no mention of absolute tracking, instead informing the user that the local space fallback will be used and that they should define tracking bounds via the XR runtime if they wish to use the stage space. --- intern/ghost/intern/GHOST_XrSession.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp index 8b0320ef358..a08b2d6045a 100644 --- a/intern/ghost/intern/GHOST_XrSession.cpp +++ b/intern/ghost/intern/GHOST_XrSession.cpp @@ -148,13 +148,12 @@ static void create_reference_spaces(OpenXRSessionData &oxr, const GHOST_XrPose & if (XR_FAILED(result)) { /* One of the rare cases where we don't want to immediately throw an exception on failure, - * since run-times are not required to support the stage reference space. Although we need the - * stage reference space for absolute tracking, if the runtime doesn't support it then just - * fallback to the local space. */ + * since runtimes are not required to support the stage reference space. If the runtime + * doesn't support it then just fall back to the local space. */ if (result == XR_ERROR_REFERENCE_SPACE_UNSUPPORTED) { printf( - "Warning: XR runtime does not support stage reference space, disabling absolute " - "tracking.\n"); + "Warning: XR runtime does not support stage reference space, falling back to local " + "reference space.\n"); create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; CHECK_XR(xrCreateReferenceSpace(oxr.session, &create_info, &oxr.reference_space), @@ -172,8 +171,9 @@ static void create_reference_spaces(OpenXRSessionData &oxr, const GHOST_XrPose & "Failed to get stage reference space bounds."); if (extents.width == 0.0f || extents.height == 0.0f) { printf( - "Warning: Invalid stage reference space bounds, disabling absolute tracking. To enable " - "absolute tracking, please define a tracking space via the XR runtime.\n"); + "Warning: Invalid stage reference space bounds, falling back to local reference space. " + "To use the stage reference space, please define a tracking space via the XR " + "runtime.\n"); /* Fallback to local space. */ if (oxr.reference_space != XR_NULL_HANDLE) { -- cgit v1.2.3 From 5a0ec2302eeb33a03b36f8021bb2338e0dba2ee4 Mon Sep 17 00:00:00 2001 From: Peter Kim Date: Wed, 25 Aug 2021 21:36:53 +0900 Subject: XR: Enable controller profile extensions Enables all currently documented OpenXR controller profile extensions (Reverb G2, Vive Cosmos, Huawei Controller) in order to support bindings for more VR hardware. This is necessary because, if these extensions are not enabled, the OpenXR runtime will return an error when creating a binding with one of these profiles. Does not bring about any changes for users at the moment, since default controller actions have not yet been exposed to users (will be addressed with D10944, D10948, and D11271). --- intern/ghost/intern/GHOST_XrContext.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp index 2906a6b241e..a7498e9f91f 100644 --- a/intern/ghost/intern/GHOST_XrContext.cpp +++ b/intern/ghost/intern/GHOST_XrContext.cpp @@ -410,6 +410,11 @@ void GHOST_XrContext::getExtensionsToEnable( try_ext.push_back(XR_EXT_DEBUG_UTILS_EXTENSION_NAME); } + /* Try enabling interaction profile extensions. */ + try_ext.push_back(XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME); + try_ext.push_back(XR_HTC_VIVE_COSMOS_CONTROLLER_INTERACTION_EXTENSION_NAME); + try_ext.push_back(XR_HUAWEI_CONTROLLER_INTERACTION_EXTENSION_NAME); + r_ext_names.reserve(try_ext.size() + graphics_binding_types.size()); /* Add graphics binding extensions (may be multiple ones, we'll settle for one to use later, once -- cgit v1.2.3 From 0fd1e6a5f43df8b0f5382c07975c0d031bbbb506 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 25 Aug 2021 14:15:57 +0200 Subject: T90908: Reduce loading times when extracting thumbnails from Blendfiles. Previously when loading an thumbnails for an asset the whole file was read. Reason this was done was perhaps a future idea to load all thumbnails inside a blendfile in a single go. This was never implemented and currently unneeded disk and cpu cycles was spend with finding out what preview to load. This patch adds an early break when the thumbnail that the caller is interested in has been found. This improves the thumbnail extraction when looking into large files. Reviewed By: mont29 Maniphest Tasks: T90908 Differential Revision: https://developer.blender.org/D12312 --- source/blender/blenloader/BLO_readfile.h | 3 + source/blender/blenloader/intern/readblenentry.c | 118 +++++++++++++++++------ source/blender/imbuf/intern/thumbs_blend.c | 42 ++------ 3 files changed, 103 insertions(+), 60 deletions(-) diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index dbdb181281a..4b7f29dd7dc 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -172,6 +172,9 @@ struct LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh, int ofblocktype, int *r_tot_info_items); struct LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_tot_prev); +struct PreviewImage *BLO_blendhandle_get_preview_for_id(BlendHandle *bh, + int ofblocktype, + const char *name); struct LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh); void BLO_blendhandle_close(BlendHandle *bh); diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index 44a26b9bf85..f67ff0f7ac7 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -216,6 +216,96 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh, return infos; } +/** + * Read the preview rects and store in `result`. + * + * `bhead` should point to the block that sourced the `preview_from_file` + * parameter. + * `bhead` parameter is consumed. The correct bhead pointing to the next bhead in the file after + * the preview rects is returned by this function. + * \param fd: The filedata to read the data from. + * \param bhead: should point to the block that sourced the `preview_from_file parameter`. + * bhead is consumed. the new bhead is returned by this function. + * \param result: the Preview Image where the preview rect will be stored. + * \param preview_from_file: The read PreviewImage where the bhead points to. The rects of this + * \return PreviewImage or NULL when no preview Images have been found. Caller owns the returned + */ +static BHead *blo_blendhandle_read_preview_rects(FileData *fd, + BHead *bhead, + PreviewImage *result, + const PreviewImage *preview_from_file) +{ + for (int preview_index = 0; preview_index < NUM_ICON_SIZES; preview_index++) { + if (preview_from_file->rect[preview_index] && preview_from_file->w[preview_index] && + preview_from_file->h[preview_index]) { + bhead = blo_bhead_next(fd, bhead); + BLI_assert((preview_from_file->w[preview_index] * preview_from_file->h[preview_index] * + sizeof(uint)) == bhead->len); + result->rect[preview_index] = BLO_library_read_struct(fd, bhead, "PreviewImage Icon Rect"); + } + else { + /* This should not be needed, but can happen in 'broken' .blend files, + * better handle this gracefully than crashing. */ + BLI_assert(preview_from_file->rect[preview_index] == NULL && + preview_from_file->w[preview_index] == 0 && + preview_from_file->h[preview_index] == 0); + result->rect[preview_index] = NULL; + result->w[preview_index] = result->h[preview_index] = 0; + } + BKE_previewimg_finish(result, preview_index); + } + + return bhead; +} + +/** + * Get the PreviewImage of a single data block in a file. + * (e.g. all the scene previews in a file). + * + * \param bh: The blendhandle to access. + * \param ofblocktype: The type of names to get. + * \param name: Name of the block without the ID_ prefix, to read the preview image from. + * \return PreviewImage or NULL when no preview Images have been found. Caller owns the returned + */ +PreviewImage *BLO_blendhandle_get_preview_for_id(BlendHandle *bh, + int ofblocktype, + const char *name) +{ + FileData *fd = (FileData *)bh; + bool looking = false; + const int sdna_preview_image = DNA_struct_find_nr(fd->filesdna, "PreviewImage"); + + for (BHead *bhead = blo_bhead_first(fd); bhead; bhead = blo_bhead_next(fd, bhead)) { + if (bhead->code == DATA) { + if (looking && bhead->SDNAnr == sdna_preview_image) { + PreviewImage *preview_from_file = BLO_library_read_struct(fd, bhead, "PreviewImage"); + + if (preview_from_file == NULL) { + break; + } + + PreviewImage *result = MEM_dupallocN(preview_from_file); + bhead = blo_blendhandle_read_preview_rects(fd, bhead, result, preview_from_file); + MEM_freeN(preview_from_file); + return result; + } + } + else if (looking || bhead->code == ENDB) { + /* We were looking for a preview image, but didn't find any belonging to block. So it doesn't + * exist. */ + break; + } + else if (bhead->code == ofblocktype) { + const char *idname = blo_bhead_id_name(fd, bhead); + if (STREQ(&idname[2], name)) { + looking = true; + } + } + } + + return NULL; +} + /** * Gets the previews of all the data-blocks in a file of a certain type * (e.g. all the scene previews in a file). @@ -264,33 +354,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_ if (prv) { memcpy(new_prv, prv, sizeof(PreviewImage)); - if (prv->rect[0] && prv->w[0] && prv->h[0]) { - bhead = blo_bhead_next(fd, bhead); - BLI_assert((new_prv->w[0] * new_prv->h[0] * sizeof(uint)) == bhead->len); - new_prv->rect[0] = BLO_library_read_struct(fd, bhead, "PreviewImage Icon Rect"); - } - else { - /* This should not be needed, but can happen in 'broken' .blend files, - * better handle this gracefully than crashing. */ - BLI_assert(prv->rect[0] == NULL && prv->w[0] == 0 && prv->h[0] == 0); - new_prv->rect[0] = NULL; - new_prv->w[0] = new_prv->h[0] = 0; - } - BKE_previewimg_finish(new_prv, 0); - - if (prv->rect[1] && prv->w[1] && prv->h[1]) { - bhead = blo_bhead_next(fd, bhead); - BLI_assert((new_prv->w[1] * new_prv->h[1] * sizeof(uint)) == bhead->len); - new_prv->rect[1] = BLO_library_read_struct(fd, bhead, "PreviewImage Image Rect"); - } - else { - /* This should not be needed, but can happen in 'broken' .blend files, - * better handle this gracefully than crashing. */ - BLI_assert(prv->rect[1] == NULL && prv->w[1] == 0 && prv->h[1] == 0); - new_prv->rect[1] = NULL; - new_prv->w[1] = new_prv->h[1] = 0; - } - BKE_previewimg_finish(new_prv, 1); + bhead = blo_blendhandle_read_preview_rects(fd, bhead, new_prv, prv); MEM_freeN(prv); } } diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index 878aa44f0d9..085620cb785 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -41,53 +41,29 @@ #include "MEM_guardedalloc.h" +/* NOTE: we should handle all previews for a same group at once, would avoid reopening + * `.blend` file for each and every ID. However, this adds some complexity, + * so keep it for later. */ static ImBuf *imb_thumb_load_from_blend_id(const char *blen_path, const char *blen_group, const char *blen_id) { ImBuf *ima = NULL; - LinkNode *ln, *names, *lp, *previews = NULL; BlendFileReadReport bf_reports = {.reports = NULL}; - struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports); - int idcode = BKE_idtype_idcode_from_name(blen_group); - int i, nprevs, nnames; + struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports); if (libfiledata == NULL) { return NULL; } - /* NOTE: we should handle all previews for a same group at once, would avoid reopening - * `.blend` file for each and every ID. However, this adds some complexity, - * so keep it for later. */ - names = BLO_blendhandle_get_datablock_names(libfiledata, idcode, false, &nnames); - previews = BLO_blendhandle_get_previews(libfiledata, idcode, &nprevs); - + int idcode = BKE_idtype_idcode_from_name(blen_group); + PreviewImage *preview = BLO_blendhandle_get_preview_for_id(libfiledata, idcode, blen_id); BLO_blendhandle_close(libfiledata); - if (!previews || (nnames != nprevs)) { - if (previews != 0) { - /* No previews at all is not a bug! */ - printf("%s: error, found %d items, %d previews\n", __func__, nnames, nprevs); - } - BLI_linklist_free(previews, BKE_previewimg_freefunc); - BLI_linklist_freeN(names); - return NULL; + if (preview) { + ima = BKE_previewimg_to_imbuf(preview, ICON_SIZE_PREVIEW); + BKE_previewimg_freefunc(preview); } - - for (i = 0, ln = names, lp = previews; i < nnames; i++, ln = ln->next, lp = lp->next) { - const char *blockname = ln->link; - PreviewImage *img = lp->link; - - if (STREQ(blockname, blen_id)) { - if (img) { - ima = BKE_previewimg_to_imbuf(img, ICON_SIZE_PREVIEW); - } - break; - } - } - - BLI_linklist_free(previews, BKE_previewimg_freefunc); - BLI_linklist_freeN(names); return ima; } -- cgit v1.2.3 From 796035ad930383c26302ab6a57e8e6c90394603b Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 25 Aug 2021 16:00:28 +0200 Subject: Cleanup: else-after-return --- source/blender/imbuf/intern/thumbs_blend.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index 085620cb785..471c1bde383 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -83,7 +83,5 @@ ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const if (blen_group && blen_id) { return imb_thumb_load_from_blend_id(blen_path, blen_group, blen_id); } - else { - return imb_thumb_load_from_blendfile(blen_path); - } + return imb_thumb_load_from_blendfile(blen_path); } -- cgit v1.2.3 From f49d438ced7c5874dbf43976d9901a462176f541 Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Fri, 20 Aug 2021 16:30:34 +0200 Subject: Cleanup and remove SEQ_ALL_BEGIN macro We now use a for_each function with callback to iterate through all sequences in the scene. This has the benefit that we now only loop over the sequences in the scene once. Before we would loop over them twice and allocate memory to store temporary data. The allocation of temporary data lead to unintentional memory leaks if the code used returns to exit out of the iteration loop. The new for_each callback method doesn't allocate any temporary data and only iterates though all sequences once. Reviewed By: Richard Antalik, Bastien Montagne Differential Revision: http://developer.blender.org/D12278 --- source/blender/blenkernel/BKE_scene.h | 8 - source/blender/blenkernel/intern/bpath.c | 74 +++-- source/blender/blenkernel/intern/ipo.c | 100 +++--- source/blender/blenkernel/intern/scene.c | 339 +++------------------ source/blender/blenloader/intern/readfile.c | 6 +- source/blender/blenloader/intern/versioning_250.c | 80 +++-- source/blender/blenloader/intern/versioning_260.c | 96 +++--- source/blender/blenloader/intern/versioning_270.c | 79 ++--- source/blender/blenloader/intern/versioning_280.c | 21 +- .../blender/blenloader/intern/versioning_legacy.c | 32 +- .../depsgraph/intern/builder/deg_builder_nodes.cc | 44 +-- .../intern/builder/deg_builder_relations.cc | 74 +++-- .../eval/deg_eval_runtime_backup_sequencer.cc | 48 +-- source/blender/editors/sound/sound_ops.c | 10 +- .../editors/space_sequencer/sequencer_edit.c | 26 +- source/blender/imbuf/intern/colormanagement.c | 16 +- source/blender/makesrna/intern/rna_color.c | 40 ++- source/blender/makesrna/intern/rna_sequencer.c | 40 +-- source/blender/sequencer/SEQ_iterator.h | 25 +- source/blender/sequencer/SEQ_sequencer.h | 20 ++ source/blender/sequencer/SEQ_utils.h | 6 - source/blender/sequencer/intern/clipboard.c | 2 +- source/blender/sequencer/intern/iterator.c | 57 +++- source/blender/sequencer/intern/proxy.c | 2 +- source/blender/sequencer/intern/sequencer.c | 337 +++++++++++++++++++- source/blender/sequencer/intern/sequencer.h | 5 +- source/blender/sequencer/intern/strip_relations.c | 35 ++- source/blender/sequencer/intern/utils.c | 34 +-- 28 files changed, 918 insertions(+), 738 deletions(-) diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 83ce5e72794..f3edf8e9f64 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -264,14 +264,6 @@ void BKE_scene_cursor_from_mat4(struct View3DCursor *cursor, const float mat[4][4], bool use_compat); -/* Dependency graph evaluation. */ - -/* Evaluate parts of sequences which needs to be done as a part of a dependency graph evaluation. - * This does NOT include actual rendering of the strips, but rather makes them up-to-date for - * animation playback and makes them ready for the sequencer's rendering pipeline to render them. - */ -void BKE_scene_eval_sequencer_sequences(struct Depsgraph *depsgraph, struct Scene *scene); - #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c index 70274de8bff..1684e22dece 100644 --- a/source/blender/blenkernel/intern/bpath.c +++ b/source/blender/blenkernel/intern/bpath.c @@ -534,6 +534,46 @@ static bool rewrite_path_alloc(char **path, return false; } +typedef struct Seq_callback_data { + const char *absbase; + void *bpath_user_data; + BPathVisitor visit_cb; + const int flag; +} Seq_callback_data; + +static bool seq_rewrite_path_callback(Sequence *seq, void *user_data) +{ + if (SEQ_HAS_PATH(seq)) { + StripElem *se = seq->strip->stripdata; + Seq_callback_data *cd = (Seq_callback_data *)user_data; + + if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM) && se) { + rewrite_path_fixed_dirfile( + seq->strip->dir, se->name, cd->visit_cb, cd->absbase, cd->bpath_user_data); + } + else if ((seq->type == SEQ_TYPE_IMAGE) && se) { + /* might want an option not to loop over all strips */ + unsigned int len = (unsigned int)MEM_allocN_len(se) / (unsigned int)sizeof(*se); + unsigned int i; + + if (cd->flag & BKE_BPATH_TRAVERSE_SKIP_MULTIFILE) { + /* only operate on one path */ + len = MIN2(1u, len); + } + + for (i = 0; i < len; i++, se++) { + rewrite_path_fixed_dirfile( + seq->strip->dir, se->name, cd->visit_cb, cd->absbase, cd->bpath_user_data); + } + } + else { + /* simple case */ + rewrite_path_fixed(seq->strip->dir, cd->visit_cb, cd->absbase, cd->bpath_user_data); + } + } + return true; +} + /** * Run visitor function 'visit' on all paths contained in 'id'. */ @@ -701,38 +741,8 @@ void BKE_bpath_traverse_id( case ID_SCE: { Scene *scene = (Scene *)id; if (scene->ed) { - Sequence *seq; - - SEQ_ALL_BEGIN (scene->ed, seq) { - if (SEQ_HAS_PATH(seq)) { - StripElem *se = seq->strip->stripdata; - - if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM) && se) { - rewrite_path_fixed_dirfile( - seq->strip->dir, se->name, visit_cb, absbase, bpath_user_data); - } - else if ((seq->type == SEQ_TYPE_IMAGE) && se) { - /* might want an option not to loop over all strips */ - unsigned int len = (unsigned int)MEM_allocN_len(se) / (unsigned int)sizeof(*se); - unsigned int i; - - if (flag & BKE_BPATH_TRAVERSE_SKIP_MULTIFILE) { - /* only operate on one path */ - len = MIN2(1u, len); - } - - for (i = 0; i < len; i++, se++) { - rewrite_path_fixed_dirfile( - seq->strip->dir, se->name, visit_cb, absbase, bpath_user_data); - } - } - else { - /* simple case */ - rewrite_path_fixed(seq->strip->dir, visit_cb, absbase, bpath_user_data); - } - } - } - SEQ_ALL_END; + Seq_callback_data user_data = {absbase, bpath_user_data, visit_cb, flag}; + SEQ_for_each_callback(&scene->ed->seqbase, seq_rewrite_path_callback, &user_data); } break; } diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 8a70f065e40..aac081991e3 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -2038,6 +2038,58 @@ static void nlastrips_to_animdata(ID *id, ListBase *strips) } } +typedef struct Seq_callback_data { + Main *bmain; + Scene *scene; + AnimData *adt; +} Seq_callback_data; + +static bool seq_convert_callback(Sequence *seq, void *userdata) +{ + IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL; + short adrcode = SEQ_FAC1; + + if (G.debug & G_DEBUG) { + printf("\tconverting sequence strip %s\n", seq->name + 2); + } + + if (ELEM(NULL, seq->ipo, icu)) { + seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE; + return true; + } + + /* patch adrcode, so that we can map + * to different DNA variables later + * (semi-hack (tm) ) + */ + switch (seq->type) { + case SEQ_TYPE_IMAGE: + case SEQ_TYPE_META: + case SEQ_TYPE_SCENE: + case SEQ_TYPE_MOVIE: + case SEQ_TYPE_COLOR: + adrcode = SEQ_FAC_OPACITY; + break; + case SEQ_TYPE_SPEED: + adrcode = SEQ_FAC_SPEED; + break; + } + icu->adrcode = adrcode; + + Seq_callback_data *cd = (Seq_callback_data *)userdata; + + /* convert IPO */ + ipo_to_animdata(cd->bmain, (ID *)cd->scene, seq->ipo, NULL, NULL, seq); + + if (cd->adt->action) { + cd->adt->action->idroot = ID_SCE; /* scene-rooted */ + } + + id_us_min(&seq->ipo->id); + seq->ipo = NULL; + return true; +} + /* *************************************************** */ /* External API - Only Called from do_versions() */ @@ -2286,52 +2338,8 @@ void do_versions_ipos_to_animato(Main *bmain) Scene *scene = (Scene *)id; Editing *ed = scene->ed; if (ed && ed->seqbasep) { - Sequence *seq; - - AnimData *adt = BKE_animdata_ensure_id(id); - - SEQ_ALL_BEGIN (ed, seq) { - IpoCurve *icu = (seq->ipo) ? seq->ipo->curve.first : NULL; - short adrcode = SEQ_FAC1; - - if (G.debug & G_DEBUG) { - printf("\tconverting sequence strip %s\n", seq->name + 2); - } - - if (ELEM(NULL, seq->ipo, icu)) { - seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE; - continue; - } - - /* patch adrcode, so that we can map - * to different DNA variables later - * (semi-hack (tm) ) - */ - switch (seq->type) { - case SEQ_TYPE_IMAGE: - case SEQ_TYPE_META: - case SEQ_TYPE_SCENE: - case SEQ_TYPE_MOVIE: - case SEQ_TYPE_COLOR: - adrcode = SEQ_FAC_OPACITY; - break; - case SEQ_TYPE_SPEED: - adrcode = SEQ_FAC_SPEED; - break; - } - icu->adrcode = adrcode; - - /* convert IPO */ - ipo_to_animdata(bmain, (ID *)scene, seq->ipo, NULL, NULL, seq); - - if (adt->action) { - adt->action->idroot = ID_SCE; /* scene-rooted */ - } - - id_us_min(&seq->ipo->id); - seq->ipo = NULL; - } - SEQ_ALL_END; + Seq_callback_data cb_data = {bmain, scene, BKE_animdata_ensure_id(id)}; + SEQ_for_each_callback(&ed->seqbase, seq_convert_callback, &cb_data); } } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 5a668746956..de82f0832d8 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -113,11 +113,7 @@ #include "SEQ_edit.h" #include "SEQ_iterator.h" -#include "SEQ_modifier.h" -#include "SEQ_proxy.h" -#include "SEQ_relations.h" #include "SEQ_sequencer.h" -#include "SEQ_sound.h" #include "BLO_read_write.h" @@ -702,6 +698,40 @@ static void scene_foreach_layer_collection(LibraryForeachIDData *data, ListBase } } +static bool seq_foreach_member_id_cb(Sequence *seq, void *user_data) +{ + LibraryForeachIDData *data = (LibraryForeachIDData *)user_data; + +#define FOREACHID_PROCESS(_data, _id_super, _cb_flag) \ + { \ + CHECK_TYPE(&((_id_super)->id), ID *); \ + if (!BKE_lib_query_foreachid_process((_data), (ID **)&(_id_super), (_cb_flag))) { \ + return false; \ + } \ + } \ + ((void)0) + + FOREACHID_PROCESS(data, seq->scene, IDWALK_CB_NEVER_SELF); + FOREACHID_PROCESS(data, seq->scene_camera, IDWALK_CB_NOP); + FOREACHID_PROCESS(data, seq->clip, IDWALK_CB_USER); + FOREACHID_PROCESS(data, seq->mask, IDWALK_CB_USER); + FOREACHID_PROCESS(data, seq->sound, IDWALK_CB_USER); + IDP_foreach_property( + seq->prop, IDP_TYPE_FILTER_ID, BKE_lib_query_idpropertiesForeachIDLink_callback, data); + LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) { + FOREACHID_PROCESS(data, smd->mask_id, IDWALK_CB_USER); + } + + if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) { + TextVars *text_data = seq->effectdata; + FOREACHID_PROCESS(data, text_data->text_font, IDWALK_CB_USER); + } + +#undef FOREACHID_PROCESS + + return true; +} + static void scene_foreach_id(ID *id, LibraryForeachIDData *data) { Scene *scene = (Scene *)id; @@ -717,25 +747,7 @@ static void scene_foreach_id(ID *id, LibraryForeachIDData *data) BKE_library_foreach_ID_embedded(data, (ID **)&scene->nodetree); } if (scene->ed) { - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - BKE_LIB_FOREACHID_PROCESS(data, seq->scene, IDWALK_CB_NEVER_SELF); - BKE_LIB_FOREACHID_PROCESS(data, seq->scene_camera, IDWALK_CB_NOP); - BKE_LIB_FOREACHID_PROCESS(data, seq->clip, IDWALK_CB_USER); - BKE_LIB_FOREACHID_PROCESS(data, seq->mask, IDWALK_CB_USER); - BKE_LIB_FOREACHID_PROCESS(data, seq->sound, IDWALK_CB_USER); - IDP_foreach_property( - seq->prop, IDP_TYPE_FILTER_ID, BKE_lib_query_idpropertiesForeachIDLink_callback, data); - LISTBASE_FOREACH (SequenceModifierData *, smd, &seq->modifiers) { - BKE_LIB_FOREACHID_PROCESS(data, smd->mask_id, IDWALK_CB_USER); - } - - if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) { - TextVars *text_data = seq->effectdata; - BKE_LIB_FOREACHID_PROCESS(data, text_data->text_font, IDWALK_CB_USER); - } - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, seq_foreach_member_id_cb, data); } /* This pointer can be NULL during old files reading, better be safe than sorry. */ @@ -883,87 +895,9 @@ static void scene_blend_write(BlendWriter *writer, ID *id, const void *id_addres Editing *ed = sce->ed; if (ed) { - Sequence *seq; - BLO_write_struct(writer, Editing, ed); - /* reset write flags too */ - - SEQ_ALL_BEGIN (ed, seq) { - if (seq->strip) { - seq->strip->done = false; - } - BLO_write_struct(writer, Sequence, seq); - } - SEQ_ALL_END; - - SEQ_ALL_BEGIN (ed, seq) { - if (seq->strip && seq->strip->done == 0) { - /* write strip with 'done' at 0 because readfile */ - - if (seq->effectdata) { - switch (seq->type) { - case SEQ_TYPE_COLOR: - BLO_write_struct(writer, SolidColorVars, seq->effectdata); - break; - case SEQ_TYPE_SPEED: - BLO_write_struct(writer, SpeedControlVars, seq->effectdata); - break; - case SEQ_TYPE_WIPE: - BLO_write_struct(writer, WipeVars, seq->effectdata); - break; - case SEQ_TYPE_GLOW: - BLO_write_struct(writer, GlowVars, seq->effectdata); - break; - case SEQ_TYPE_TRANSFORM: - BLO_write_struct(writer, TransformVars, seq->effectdata); - break; - case SEQ_TYPE_GAUSSIAN_BLUR: - BLO_write_struct(writer, GaussianBlurVars, seq->effectdata); - break; - case SEQ_TYPE_TEXT: - BLO_write_struct(writer, TextVars, seq->effectdata); - break; - case SEQ_TYPE_COLORMIX: - BLO_write_struct(writer, ColorMixVars, seq->effectdata); - break; - } - } - - BLO_write_struct(writer, Stereo3dFormat, seq->stereo3d_format); - - Strip *strip = seq->strip; - BLO_write_struct(writer, Strip, strip); - if (strip->crop) { - BLO_write_struct(writer, StripCrop, strip->crop); - } - if (strip->transform) { - BLO_write_struct(writer, StripTransform, strip->transform); - } - if (strip->proxy) { - BLO_write_struct(writer, StripProxy, strip->proxy); - } - if (seq->type == SEQ_TYPE_IMAGE) { - BLO_write_struct_array(writer, - StripElem, - MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), - strip->stripdata); - } - else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) { - BLO_write_struct(writer, StripElem, strip->stripdata); - } - - strip->done = true; - } - - if (seq->prop) { - IDP_BlendWrite(writer, seq->prop); - } - - SEQ_modifier_blend_write(writer, &seq->modifiers); - } - SEQ_ALL_END; - + SEQ_blend_write(writer, &ed->seqbase); /* new; meta stack too, even when its nasty restore code */ LISTBASE_FOREACH (MetaStack *, ms, &ed->metastack) { BLO_write_struct(writer, MetaStack, ms); @@ -1155,66 +1089,8 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id) /* recursive link sequences, lb will be correctly initialized */ link_recurs_seq(reader, &ed->seqbase); - Sequence *seq; - SEQ_ALL_BEGIN (ed, seq) { - /* Do as early as possible, so that other parts of reading can rely on valid session UUID. */ - SEQ_relations_session_uuid_generate(seq); - - BLO_read_data_address(reader, &seq->seq1); - BLO_read_data_address(reader, &seq->seq2); - BLO_read_data_address(reader, &seq->seq3); - - /* a patch: after introduction of effects with 3 input strips */ - if (seq->seq3 == NULL) { - seq->seq3 = seq->seq2; - } - - BLO_read_data_address(reader, &seq->effectdata); - BLO_read_data_address(reader, &seq->stereo3d_format); - - if (seq->type & SEQ_TYPE_EFFECT) { - seq->flag |= SEQ_EFFECT_NOT_LOADED; - } - - if (seq->type == SEQ_TYPE_TEXT) { - TextVars *t = seq->effectdata; - t->text_blf_id = SEQ_FONT_NOT_LOADED; - } - - BLO_read_data_address(reader, &seq->prop); - IDP_BlendDataRead(reader, &seq->prop); - - BLO_read_data_address(reader, &seq->strip); - if (seq->strip && seq->strip->done == 0) { - seq->strip->done = true; - - if (ELEM(seq->type, - SEQ_TYPE_IMAGE, - SEQ_TYPE_MOVIE, - SEQ_TYPE_SOUND_RAM, - SEQ_TYPE_SOUND_HD)) { - BLO_read_data_address(reader, &seq->strip->stripdata); - } - else { - seq->strip->stripdata = NULL; - } - BLO_read_data_address(reader, &seq->strip->crop); - BLO_read_data_address(reader, &seq->strip->transform); - BLO_read_data_address(reader, &seq->strip->proxy); - if (seq->strip->proxy) { - seq->strip->proxy->anim = NULL; - } - else if (seq->flag & SEQ_USE_PROXY) { - SEQ_proxy_set(seq, true); - } - - /* need to load color balance to it could be converted to modifier */ - BLO_read_data_address(reader, &seq->strip->color_balance); - } - - SEQ_modifier_blend_read_data(reader, &seq->modifiers); - } - SEQ_ALL_END; + /* Read in sequence member data. */ + SEQ_blend_read(reader, &ed->seqbase); /* link metastack, slight abuse of structs here, * have to restore pointer to internal part in struct */ @@ -1461,50 +1337,9 @@ static void scene_blend_read_lib(BlendLibReader *reader, ID *id) } } - Sequence *seq; - SEQ_ALL_BEGIN (sce->ed, seq) { - IDP_BlendReadLib(reader, seq->prop); - - if (seq->ipo) { - /* XXX: deprecated - old animation system. */ - BLO_read_id_address(reader, sce->id.lib, &seq->ipo); - } - seq->scene_sound = NULL; - if (seq->scene) { - BLO_read_id_address(reader, sce->id.lib, &seq->scene); - seq->scene_sound = NULL; - } - if (seq->clip) { - BLO_read_id_address(reader, sce->id.lib, &seq->clip); - } - if (seq->mask) { - BLO_read_id_address(reader, sce->id.lib, &seq->mask); - } - if (seq->scene_camera) { - BLO_read_id_address(reader, sce->id.lib, &seq->scene_camera); - } - if (seq->sound) { - seq->scene_sound = NULL; - if (seq->type == SEQ_TYPE_SOUND_HD) { - seq->type = SEQ_TYPE_SOUND_RAM; - } - else { - BLO_read_id_address(reader, sce->id.lib, &seq->sound); - } - if (seq->sound) { - id_us_plus_no_lib((ID *)seq->sound); - seq->scene_sound = NULL; - } - } - if (seq->type == SEQ_TYPE_TEXT) { - TextVars *t = seq->effectdata; - BLO_read_id_address(reader, sce->id.lib, &t->text_font); - } - BLI_listbase_clear(&seq->anims); - - SEQ_modifier_blend_read_lib(reader, sce, &seq->modifiers); + if (sce->ed) { + SEQ_blend_read_lib(reader, sce, &sce->ed->seqbase); } - SEQ_ALL_END; LISTBASE_FOREACH (TimeMarker *, marker, &sce->markers) { IDP_BlendReadLib(reader, marker->prop); @@ -1619,33 +1454,7 @@ static void scene_blend_read_expand(BlendExpander *expander, ID *id) } if (sce->ed) { - Sequence *seq; - - SEQ_ALL_BEGIN (sce->ed, seq) { - IDP_BlendReadExpand(expander, seq->prop); - - if (seq->scene) { - BLO_expand(expander, seq->scene); - } - if (seq->scene_camera) { - BLO_expand(expander, seq->scene_camera); - } - if (seq->clip) { - BLO_expand(expander, seq->clip); - } - if (seq->mask) { - BLO_expand(expander, seq->mask); - } - if (seq->sound) { - BLO_expand(expander, seq->sound); - } - - if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) { - TextVars *data = seq->effectdata; - BLO_expand(expander, data->text_font); - } - } - SEQ_ALL_END; + SEQ_blend_read_expand(expander, &sce->ed->seqbase); } if (sce->rigidbody_world) { @@ -3781,69 +3590,3 @@ void BKE_scene_cursor_from_mat4(View3DCursor *cursor, const float mat[4][4], boo } /** \} */ - -/* Dependency graph evaluation. */ - -static void scene_sequencer_disable_sound_strips(Scene *scene) -{ - if (scene->sound_scene == NULL) { - return; - } - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->scene_sound != NULL) { - BKE_sound_remove_scene_sound(scene, seq->scene_sound); - seq->scene_sound = NULL; - } - } - SEQ_ALL_END; -} - -void BKE_scene_eval_sequencer_sequences(Depsgraph *depsgraph, Scene *scene) -{ - DEG_debug_print_eval(depsgraph, __func__, scene->id.name, scene); - if (scene->ed == NULL) { - return; - } - BKE_sound_ensure_scene(scene); - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->scene_sound == NULL) { - if (seq->sound != NULL) { - seq->scene_sound = BKE_sound_add_scene_sound_defaults(scene, seq); - } - else if (seq->type == SEQ_TYPE_SCENE) { - if (seq->scene != NULL) { - BKE_sound_ensure_scene(seq->scene); - seq->scene_sound = BKE_sound_scene_add_scene_sound_defaults(scene, seq); - } - } - } - if (seq->scene_sound != NULL) { - /* Make sure changing volume via sequence's properties panel works correct. - * - * Ideally, the entire BKE_scene_update_sound() will happen from a dependency graph, so - * then it is no longer needed to do such manual forced updates. */ - if (seq->type == SEQ_TYPE_SCENE && seq->scene != NULL) { - BKE_sound_set_scene_volume(seq->scene, seq->scene->audio.volume); - if ((seq->flag & SEQ_SCENE_STRIPS) == 0) { - scene_sequencer_disable_sound_strips(seq->scene); - } - } - if (seq->sound != NULL) { - if (scene->id.recalc & ID_RECALC_AUDIO || seq->sound->id.recalc & ID_RECALC_AUDIO) { - BKE_sound_update_scene_sound(seq->scene_sound, seq->sound); - } - } - BKE_sound_set_scene_sound_volume( - seq->scene_sound, seq->volume, (seq->flag & SEQ_AUDIO_VOLUME_ANIMATED) != 0); - BKE_sound_set_scene_sound_pitch( - seq->scene_sound, seq->pitch, (seq->flag & SEQ_AUDIO_PITCH_ANIMATED) != 0); - BKE_sound_set_scene_sound_pan( - seq->scene_sound, seq->pan, (seq->flag & SEQ_AUDIO_PAN_ANIMATED) != 0); - } - } - SEQ_ALL_END; - SEQ_edit_update_muting(scene->ed); - SEQ_sound_update_bounds_all(scene); -} diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 49c3497f996..2ee66206878 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2419,7 +2419,7 @@ static void lib_link_seq_clipboard_pt_restore(ID *id, struct IDNameLib_Map *id_m id->newid = restore_pointer_by_name(id_map, id->newid, USER_REAL); } } -static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt) +static bool lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt) { struct IDNameLib_Map *id_map = arg_pt; @@ -2428,13 +2428,13 @@ static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt) lib_link_seq_clipboard_pt_restore((ID *)seq->clip, id_map); lib_link_seq_clipboard_pt_restore((ID *)seq->mask, id_map); lib_link_seq_clipboard_pt_restore((ID *)seq->sound, id_map); - return 1; + return true; } static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map) { /* update IDs stored in sequencer clipboard */ - SEQ_seqbase_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map); + SEQ_for_each_callback(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map); } static int lib_link_main_data_restore_cb(LibraryIDLinkCallbackData *cb_data) diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 436645c2241..54e673b51eb 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -638,6 +638,46 @@ static void do_versions_socket_default_value_259(bNodeSocket *sock) } } +static bool seq_sound_proxy_update_cb(Sequence *seq, void *user_data) +{ + Main *bmain = (Main *)user_data; + if (seq->type == SEQ_TYPE_SOUND_HD) { + char str[FILE_MAX]; + BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name); + BLI_path_abs(str, BKE_main_blendfile_path(bmain)); + seq->sound = BKE_sound_new_file(bmain, str); + } +#define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) +#define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21) + /* don't know, if anybody used that this way, but just in case, upgrade to new way... */ + if ((seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) && !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)) { + BLI_snprintf(seq->strip->proxy->dir, FILE_MAXDIR, "%s/BL_proxy", seq->strip->dir); + } +#undef SEQ_USE_PROXY_CUSTOM_DIR +#undef SEQ_USE_PROXY_CUSTOM_FILE + return true; +} + +static bool seq_set_volume_cb(Sequence *seq, void *UNUSED(user_data)) +{ + seq->volume = 1.0f; + return true; +} + +static bool seq_set_sat_cb(Sequence *seq, void *UNUSED(user_data)) +{ + if (seq->sat == 0.0f) { + seq->sat = 1.0f; + } + return true; +} + +static bool seq_set_pitch_cb(Sequence *seq, void *UNUSED(user_data)) +{ + seq->pitch = 1.0f; + return true; +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) { @@ -660,7 +700,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) #endif bSound *sound; - Sequence *seq; for (sound = bmain->sounds.first; sound; sound = sound->id.next) { if (sound->newpackedfile) { @@ -671,23 +710,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { if (scene->ed && scene->ed->seqbasep) { - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->type == SEQ_TYPE_SOUND_HD) { - char str[FILE_MAX]; - BLI_join_dirfile(str, sizeof(str), seq->strip->dir, seq->strip->stripdata->name); - BLI_path_abs(str, BKE_main_blendfile_path(bmain)); - seq->sound = BKE_sound_new_file(bmain, str); - } -#define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) -#define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21) - /* don't know, if anybody used that this way, but just in case, upgrade to new way... */ - if ((seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) && !(seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)) { - BLI_snprintf(seq->strip->proxy->dir, FILE_MAXDIR, "%s/BL_proxy", seq->strip->dir); - } -#undef SEQ_USE_PROXY_CUSTOM_DIR -#undef SEQ_USE_PROXY_CUSTOM_FILE - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, seq_sound_proxy_update_cb, bmain); } } @@ -1391,7 +1414,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 250, 17)) { Scene *sce; - Sequence *seq; /* initialize to sane default so toggling on border shows something */ for (sce = bmain->scenes.first; sce; sce = sce->id.next) { @@ -1406,11 +1428,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if ((sce->r.ffcodecdata.flags & FFMPEG_MULTIPLEX_AUDIO) == 0) { sce->r.ffcodecdata.audio_codec = 0x0; /* `CODEC_ID_NONE` */ } - - SEQ_ALL_BEGIN (sce->ed, seq) { - seq->volume = 1.0f; + if (sce->ed) { + SEQ_for_each_callback(&sce->ed->seqbase, seq_set_volume_cb, NULL); } - SEQ_ALL_END; } /* particle brush strength factor was changed from int to float */ @@ -1678,13 +1698,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) } for (scene = bmain->scenes.first; scene; scene = scene->id.next) { - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->sat == 0.0f) { - seq->sat = 1.0f; - } + if (scene->ed) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_set_sat_cb, NULL); } - SEQ_ALL_END; } /* GSOC 2010 Sculpt - New settings for Brush */ @@ -2159,15 +2175,13 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 259, 1)) { { Scene *scene; - Sequence *seq; for (scene = bmain->scenes.first; scene; scene = scene->id.next) { scene->r.ffcodecdata.audio_channels = 2; scene->audio.volume = 1.0f; - SEQ_ALL_BEGIN (scene->ed, seq) { - seq->pitch = 1.0f; + if (scene->ed) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_set_pitch_cb, NULL); } - SEQ_ALL_END; } } diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index 7c644fa3b55..b71dd5a27bb 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -663,6 +663,53 @@ static void do_versions_nodetree_customnodes(bNodeTree *ntree, int UNUSED(is_gro } } +static bool seq_colorbalance_update_cb(Sequence *seq, void *UNUSED(user_data)) +{ + Strip *strip = seq->strip; + + if (strip && strip->color_balance) { + SequenceModifierData *smd; + ColorBalanceModifierData *cbmd; + + smd = SEQ_modifier_new(seq, NULL, seqModifierType_ColorBalance); + cbmd = (ColorBalanceModifierData *)smd; + + cbmd->color_balance = *strip->color_balance; + + /* multiplication with color balance used is handled differently, + * so we need to move multiplication to modifier so files would be + * compatible + */ + cbmd->color_multiply = seq->mul; + seq->mul = 1.0f; + + MEM_freeN(strip->color_balance); + strip->color_balance = NULL; + } + return true; +} + +static bool seq_set_alpha_mode_cb(Sequence *seq, void *UNUSED(user_data)) +{ + enum { SEQ_MAKE_PREMUL = (1 << 6) }; + if (seq->flag & SEQ_MAKE_PREMUL) { + seq->alpha_mode = SEQ_ALPHA_STRAIGHT; + } + else { + SEQ_alpha_mode_from_file_extension(seq); + } + return true; +} + +static bool seq_set_wipe_angle_cb(Sequence *seq, void *UNUSED(user_data)) +{ + if (seq->type == SEQ_TYPE_WIPE) { + WipeVars *wv = seq->effectdata; + wv->angle = DEG2RADF(wv->angle); + } + return true; +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) { @@ -1492,32 +1539,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) for (scene = bmain->scenes.first; scene; scene = scene->id.next) { if (scene->ed) { - Sequence *seq; - - SEQ_ALL_BEGIN (scene->ed, seq) { - Strip *strip = seq->strip; - - if (strip && strip->color_balance) { - SequenceModifierData *smd; - ColorBalanceModifierData *cbmd; - - smd = SEQ_modifier_new(seq, NULL, seqModifierType_ColorBalance); - cbmd = (ColorBalanceModifierData *)smd; - - cbmd->color_balance = *strip->color_balance; - - /* multiplication with color balance used is handled differently, - * so we need to move multiplication to modifier so files would be - * compatible - */ - cbmd->color_multiply = seq->mul; - seq->mul = 1.0f; - - MEM_freeN(strip->color_balance); - strip->color_balance = NULL; - } - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, seq_colorbalance_update_cb, NULL); } } } @@ -1807,18 +1829,9 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) Tex *tex; for (scene = bmain->scenes.first; scene; scene = scene->id.next) { - Sequence *seq; - - SEQ_ALL_BEGIN (scene->ed, seq) { - enum { SEQ_MAKE_PREMUL = (1 << 6) }; - if (seq->flag & SEQ_MAKE_PREMUL) { - seq->alpha_mode = SEQ_ALPHA_STRAIGHT; - } - else { - SEQ_alpha_mode_from_file_extension(seq); - } + if (scene->ed) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_set_alpha_mode_cb, NULL); } - SEQ_ALL_END; if (scene->r.bake_samples == 0) { scene->r.bake_samples = 256; @@ -2450,14 +2463,9 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *bmain) } for (scene = bmain->scenes.first; scene; scene = scene->id.next) { - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->type == SEQ_TYPE_WIPE) { - WipeVars *wv = seq->effectdata; - wv->angle = DEG2RADF(wv->angle); - } + if (scene->ed) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_set_wipe_angle_cb, NULL); } - SEQ_ALL_END; } FOREACH_NODETREE_BEGIN (bmain, ntree, id) { diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 1d46c0d5790..6492f0d1f69 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -425,6 +425,45 @@ static void do_version_bbone_easing_fcurve_fix(ID *UNUSED(id), } } +static bool seq_update_proxy_cb(Sequence *seq, void *UNUSED(user_data)) +{ + seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format"); + +#define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) +#define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21) + if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) { + if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR) { + seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR; + } + if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) { + seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE; + } + } +#undef SEQ_USE_PROXY_CUSTOM_DIR +#undef SEQ_USE_PROXY_CUSTOM_FILE + return true; +} + +static bool seq_update_effectdata_cb(Sequence *seq, void *UNUSED(user_data)) +{ + + if (seq->type != SEQ_TYPE_TEXT) { + return true; + } + + if (seq->effectdata == NULL) { + struct SeqEffectHandle effect_handle = SEQ_effect_handle_get(seq); + effect_handle.init(seq); + } + + TextVars *data = seq->effectdata; + if (data->color[3] == 0.0f) { + copy_v4_fl(data->color, 1.0f); + data->shadow_color[3] = 1.0f; + } + return true; +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) { @@ -908,8 +947,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) Image *ima; for (scene = bmain->scenes.first; scene; scene = scene->id.next) { - Sequence *seq; - BKE_scene_add_render_view(scene, STEREO_LEFT_NAME); srv = scene->r.views.first; BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix)); @@ -918,23 +955,9 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) srv = scene->r.views.last; BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix)); - SEQ_ALL_BEGIN (scene->ed, seq) { - seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo Display 3d Format"); - -#define SEQ_USE_PROXY_CUSTOM_DIR (1 << 19) -#define SEQ_USE_PROXY_CUSTOM_FILE (1 << 21) - if (seq->strip && seq->strip->proxy && !seq->strip->proxy->storage) { - if (seq->flag & SEQ_USE_PROXY_CUSTOM_DIR) { - seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_DIR; - } - if (seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) { - seq->strip->proxy->storage = SEQ_STORAGE_PROXY_CUSTOM_FILE; - } - } -#undef SEQ_USE_PROXY_CUSTOM_DIR -#undef SEQ_USE_PROXY_CUSTOM_FILE + if (scene->ed) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_update_proxy_cb, NULL); } - SEQ_ALL_END; } for (screen = bmain->screens.first; screen; screen = screen->id.next) { @@ -1215,25 +1238,9 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { - Sequence *seq; - - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->type != SEQ_TYPE_TEXT) { - continue; - } - - if (seq->effectdata == NULL) { - struct SeqEffectHandle effect_handle = SEQ_effect_handle_get(seq); - effect_handle.init(seq); - } - - TextVars *data = seq->effectdata; - if (data->color[3] == 0.0f) { - copy_v4_fl(data->color, 1.0f); - data->shadow_color[3] = 1.0f; - } + if (scene->ed) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_update_effectdata_cb, NULL); } - SEQ_ALL_END; } /* Adding "Properties" region to DopeSheet */ diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 9d65488e8d4..f77d0361e51 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -1772,6 +1772,16 @@ static void do_versions_seq_set_cache_defaults(Editing *ed) ed->recycle_max_cost = 10.0f; } +static bool seq_update_flags_cb(Sequence *seq, void *UNUSED(user_data)) +{ + seq->flag &= ~(SEQ_FLAG_UNUSED_6 | SEQ_FLAG_UNUSED_18 | SEQ_FLAG_UNUSED_19 | SEQ_FLAG_UNUSED_21); + if (seq->type == SEQ_TYPE_SPEED) { + SpeedControlVars *s = (SpeedControlVars *)seq->effectdata; + s->flags &= ~(SEQ_SPEED_UNUSED_1); + } + return true; +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) { @@ -3447,16 +3457,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } if (scene->ed) { - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - seq->flag &= ~(SEQ_FLAG_UNUSED_6 | SEQ_FLAG_UNUSED_18 | SEQ_FLAG_UNUSED_19 | - SEQ_FLAG_UNUSED_21); - if (seq->type == SEQ_TYPE_SPEED) { - SpeedControlVars *s = (SpeedControlVars *)seq->effectdata; - s->flags &= ~(SEQ_SPEED_UNUSED_1); - } - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, seq_update_flags_cb, NULL); } } diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 6ba27b6ee9e..62cc2aa3662 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -482,6 +482,22 @@ void blo_do_version_old_trackto_to_constraints(Object *ob) ob->track = NULL; } +static bool seq_set_alpha_mode_cb(Sequence *seq, void *UNUSED(user_data)) +{ + if (ELEM(seq->type, SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE)) { + seq->alpha_mode = SEQ_ALPHA_STRAIGHT; + } + return true; +} + +static bool seq_set_blend_mode_cb(Sequence *seq, void *UNUSED(user_data)) +{ + if (seq->blend_mode == 0) { + seq->blend_opacity = 100.0f; + } + return true; +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) { @@ -1228,7 +1244,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (bmain->versionfile <= 235) { Tex *tex = bmain->textures.first; Scene *sce = bmain->scenes.first; - Sequence *seq; Editing *ed; while (tex) { @@ -1240,12 +1255,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) while (sce) { ed = sce->ed; if (ed) { - SEQ_ALL_BEGIN (sce->ed, seq) { - if (ELEM(seq->type, SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE)) { - seq->alpha_mode = SEQ_ALPHA_STRAIGHT; - } - } - SEQ_ALL_END; + SEQ_for_each_callback(&sce->ed->seqbase, seq_set_alpha_mode_cb, NULL); } sce = sce->id.next; @@ -2404,15 +2414,11 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 245, 14)) { Scene *sce; - Sequence *seq; for (sce = bmain->scenes.first; sce; sce = sce->id.next) { - SEQ_ALL_BEGIN (sce->ed, seq) { - if (seq->blend_mode == 0) { - seq->blend_opacity = 100.0f; - } + if (sce->ed) { + SEQ_for_each_callback(&sce->ed->seqbase, seq_set_blend_mode_cb, NULL); } - SEQ_ALL_END; } } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index 22bce10937d..a739a0fe337 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -112,6 +112,7 @@ #include "DEG_depsgraph_build.h" #include "SEQ_iterator.h" +#include "SEQ_sequencer.h" #include "intern/builder/deg_builder.h" #include "intern/builder/deg_builder_rna.h" @@ -2032,6 +2033,27 @@ void DepsgraphNodeBuilder::build_simulation(Simulation *simulation) }); } +static bool seq_node_build_cb(Sequence *seq, void *user_data) +{ + DepsgraphNodeBuilder *nb = (DepsgraphNodeBuilder *)user_data; + nb->build_idproperties(seq->prop); + if (seq->sound != nullptr) { + nb->build_sound(seq->sound); + } + if (seq->scene != nullptr) { + nb->build_scene_parameters(seq->scene); + } + if (seq->type == SEQ_TYPE_SCENE && seq->scene != nullptr) { + if (seq->flag & SEQ_SCENE_STRIPS) { + nb->build_scene_sequencer(seq->scene); + } + ViewLayer *sequence_view_layer = BKE_view_layer_default_render(seq->scene); + nb->build_scene_speakers(seq->scene, sequence_view_layer); + } + /* TODO(sergey): Movie clip, scene, camera, mask. */ + return true; +} + void DepsgraphNodeBuilder::build_scene_sequencer(Scene *scene) { if (scene->ed == nullptr) { @@ -2046,28 +2068,10 @@ void DepsgraphNodeBuilder::build_scene_sequencer(Scene *scene) NodeType::SEQUENCER, OperationCode::SEQUENCES_EVAL, [scene_cow](::Depsgraph *depsgraph) { - BKE_scene_eval_sequencer_sequences(depsgraph, scene_cow); + SEQ_eval_sequences(depsgraph, scene_cow, &scene_cow->ed->seqbase); }); /* Make sure data for sequences is in the graph. */ - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - build_idproperties(seq->prop); - if (seq->sound != nullptr) { - build_sound(seq->sound); - } - if (seq->scene != nullptr) { - build_scene_parameters(seq->scene); - } - if (seq->type == SEQ_TYPE_SCENE && seq->scene != nullptr) { - if (seq->flag & SEQ_SCENE_STRIPS) { - build_scene_sequencer(seq->scene); - } - ViewLayer *sequence_view_layer = BKE_view_layer_default_render(seq->scene); - build_scene_speakers(seq->scene, sequence_view_layer); - } - /* TODO(sergey): Movie clip, scene, camera, mask. */ - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, seq_node_build_cb, this); } void DepsgraphNodeBuilder::build_scene_audio(Scene *scene) diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index d88e9bc9c04..ab3081cb1ae 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -2769,6 +2769,45 @@ void DepsgraphRelationBuilder::build_simulation(Simulation *simulation) add_relation(nodetree_key, simulation_eval_key, "NodeTree -> Simulation", 0); } +using Seq_build_prop_cb_data = struct Seq_build_prop_cb_data { + DepsgraphRelationBuilder *builder; + ComponentKey sequencer_key; + bool has_audio_strips; +}; + +static bool seq_build_prop_cb(Sequence *seq, void *user_data) +{ + Seq_build_prop_cb_data *cd = (Seq_build_prop_cb_data *)user_data; + + cd->builder->build_idproperties(seq->prop); + if (seq->sound != nullptr) { + cd->builder->build_sound(seq->sound); + ComponentKey sound_key(&seq->sound->id, NodeType::AUDIO); + cd->builder->add_relation(sound_key, cd->sequencer_key, "Sound -> Sequencer"); + cd->has_audio_strips = true; + } + if (seq->scene != nullptr) { + cd->builder->build_scene_parameters(seq->scene); + /* This is to support 3D audio. */ + cd->has_audio_strips = true; + } + if (seq->type == SEQ_TYPE_SCENE && seq->scene != nullptr) { + if (seq->flag & SEQ_SCENE_STRIPS) { + cd->builder->build_scene_sequencer(seq->scene); + ComponentKey sequence_scene_audio_key(&seq->scene->id, NodeType::AUDIO); + cd->builder->add_relation( + sequence_scene_audio_key, cd->sequencer_key, "Sequence Scene Audio -> Sequencer"); + ComponentKey sequence_scene_key(&seq->scene->id, NodeType::SEQUENCER); + cd->builder->add_relation( + sequence_scene_key, cd->sequencer_key, "Sequence Scene -> Sequencer"); + } + ViewLayer *sequence_view_layer = BKE_view_layer_default_render(seq->scene); + cd->builder->build_scene_speakers(seq->scene, sequence_view_layer); + } + /* TODO(sergey): Movie clip, camera, mask. */ + return true; +} + void DepsgraphRelationBuilder::build_scene_sequencer(Scene *scene) { if (scene->ed == nullptr) { @@ -2781,36 +2820,11 @@ void DepsgraphRelationBuilder::build_scene_sequencer(Scene *scene) ComponentKey scene_audio_key(&scene->id, NodeType::AUDIO); /* Make sure dependencies from sequences data goes to the sequencer evaluation. */ ComponentKey sequencer_key(&scene->id, NodeType::SEQUENCER); - Sequence *seq; - bool has_audio_strips = false; - SEQ_ALL_BEGIN (scene->ed, seq) { - build_idproperties(seq->prop); - if (seq->sound != nullptr) { - build_sound(seq->sound); - ComponentKey sound_key(&seq->sound->id, NodeType::AUDIO); - add_relation(sound_key, sequencer_key, "Sound -> Sequencer"); - has_audio_strips = true; - } - if (seq->scene != nullptr) { - build_scene_parameters(seq->scene); - /* This is to support 3D audio. */ - has_audio_strips = true; - } - if (seq->type == SEQ_TYPE_SCENE && seq->scene != nullptr) { - if (seq->flag & SEQ_SCENE_STRIPS) { - build_scene_sequencer(seq->scene); - ComponentKey sequence_scene_audio_key(&seq->scene->id, NodeType::AUDIO); - add_relation(sequence_scene_audio_key, sequencer_key, "Sequence Scene Audio -> Sequencer"); - ComponentKey sequence_scene_key(&seq->scene->id, NodeType::SEQUENCER); - add_relation(sequence_scene_key, sequencer_key, "Sequence Scene -> Sequencer"); - } - ViewLayer *sequence_view_layer = BKE_view_layer_default_render(seq->scene); - build_scene_speakers(seq->scene, sequence_view_layer); - } - /* TODO(sergey): Movie clip, camera, mask. */ - } - SEQ_ALL_END; - if (has_audio_strips) { + + Seq_build_prop_cb_data cb_data = {this, sequencer_key, false}; + + SEQ_for_each_callback(&scene->ed->seqbase, seq_build_prop_cb, &cb_data); + if (cb_data.has_audio_strips) { add_relation(sequencer_key, scene_audio_key, "Sequencer -> Audio"); } } diff --git a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_sequencer.cc b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_sequencer.cc index 34c23740730..166ca37bc35 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_sequencer.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_sequencer.cc @@ -38,33 +38,43 @@ SequencerBackup::SequencerBackup(const Depsgraph *depsgraph) : depsgraph(depsgra { } +static bool seq_init_cb(Sequence *seq, void *user_data) +{ + SequencerBackup *sb = (SequencerBackup *)user_data; + SequenceBackup sequence_backup(sb->depsgraph); + sequence_backup.init_from_sequence(seq); + if (!sequence_backup.isEmpty()) { + const SessionUUID &session_uuid = seq->runtime.session_uuid; + BLI_assert(BLI_session_uuid_is_generated(&session_uuid)); + sb->sequences_backup.add(session_uuid, sequence_backup); + } + return true; +} + void SequencerBackup::init_from_scene(Scene *scene) { - Sequence *sequence; - SEQ_ALL_BEGIN (scene->ed, sequence) { - SequenceBackup sequence_backup(depsgraph); - sequence_backup.init_from_sequence(sequence); - if (!sequence_backup.isEmpty()) { - const SessionUUID &session_uuid = sequence->runtime.session_uuid; - BLI_assert(BLI_session_uuid_is_generated(&session_uuid)); - sequences_backup.add(session_uuid, sequence_backup); - } + if (scene->ed != nullptr) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_init_cb, this); } - SEQ_ALL_END; +} + +static bool seq_restore_cb(Sequence *seq, void *user_data) +{ + SequencerBackup *sb = (SequencerBackup *)user_data; + const SessionUUID &session_uuid = seq->runtime.session_uuid; + BLI_assert(BLI_session_uuid_is_generated(&session_uuid)); + SequenceBackup *sequence_backup = sb->sequences_backup.lookup_ptr(session_uuid); + if (sequence_backup != nullptr) { + sequence_backup->restore_to_sequence(seq); + } + return true; } void SequencerBackup::restore_to_scene(Scene *scene) { - Sequence *sequence; - SEQ_ALL_BEGIN (scene->ed, sequence) { - const SessionUUID &session_uuid = sequence->runtime.session_uuid; - BLI_assert(BLI_session_uuid_is_generated(&session_uuid)); - SequenceBackup *sequence_backup = sequences_backup.lookup_ptr(session_uuid); - if (sequence_backup != nullptr) { - sequence_backup->restore_to_sequence(sequence); - } + if (scene->ed != nullptr) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_restore_cb, this); } - SEQ_ALL_END; /* Cleanup audio while the scene is still known. */ for (SequenceBackup &sequence_backup : sequences_backup.values()) { if (sequence_backup.scene_sound != nullptr) { diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index fe0a53ae964..85f6647ddd0 100644 --- a/source/blender/editors/sound/sound_ops.c +++ b/source/blender/editors/sound/sound_ops.c @@ -207,7 +207,7 @@ static void SOUND_OT_open_mono(wmOperatorType *ot) static void sound_update_animation_flags(Scene *scene); -static int sound_update_animation_flags_fn(Sequence *seq, void *user_data) +static bool sound_update_animation_flags_fn(Sequence *seq, void *user_data) { struct FCurve *fcu; Scene *scene = (Scene *)user_data; @@ -244,24 +244,22 @@ static int sound_update_animation_flags_fn(Sequence *seq, void *user_data) sound_update_animation_flags(seq->scene); } - return 0; + return true; } static void sound_update_animation_flags(Scene *scene) { struct FCurve *fcu; bool driven; - Sequence *seq; if (scene->id.tag & LIB_TAG_DOIT) { return; } scene->id.tag |= LIB_TAG_DOIT; - SEQ_ALL_BEGIN (scene->ed, seq) { - SEQ_recursive_apply(seq, sound_update_animation_flags_fn, scene); + if (scene->ed != NULL) { + SEQ_for_each_callback(&scene->ed->seqbase, sound_update_animation_flags_fn, scene); } - SEQ_ALL_END; fcu = id_data_find_fcurve(&scene->id, scene, &RNA_Scene, "audio_volume", 0, &driven); if (fcu || driven) { diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 694e5fbb41d..935bc97d0b2 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -2980,6 +2980,22 @@ static int sequencer_export_subtitles_invoke(bContext *C, return OPERATOR_RUNNING_MODAL; } +typedef struct Seq_get_text_cb_data { + ListBase *text_seq; + Scene *scene; +} Seq_get_text_cb_data; + +static bool seq_get_text_strip_cb(Sequence *seq, void *user_data) +{ + Seq_get_text_cb_data *cd = (Seq_get_text_cb_data *)user_data; + /* Only text strips that are not muted and don't end with negative frame. */ + if ((seq->type == SEQ_TYPE_TEXT) && ((seq->flag & SEQ_MUTE) == 0) && + (seq->enddisp > cd->scene->r.sfra)) { + BLI_addtail(cd->text_seq, MEM_dupallocN(seq)); + } + return true; +} + static int sequencer_export_subtitles_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); @@ -3011,14 +3027,10 @@ static int sequencer_export_subtitles_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* Only text strips that are not muted and don't end with negative frame. */ - SEQ_ALL_BEGIN (ed, seq) { - if ((seq->type == SEQ_TYPE_TEXT) && ((seq->flag & SEQ_MUTE) == 0) && - (seq->enddisp > scene->r.sfra)) { - BLI_addtail(&text_seq, MEM_dupallocN(seq)); - } + if (ed != NULL) { + Seq_get_text_cb_data cb_data = {&text_seq, scene}; + SEQ_for_each_callback(&ed->seqbase, seq_get_text_strip_cb, &cb_data); } - SEQ_ALL_END; if (BLI_listbase_is_empty(&text_seq)) { BKE_report(op->reports, RPT_ERROR, "No subtitles (text strips) to export"); diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 8b2ac2ed22d..119ef3ff971 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -1185,6 +1185,14 @@ static void colormanage_check_colorspace_settings( (void)what; } +static bool seq_callback(Sequence *seq, void *UNUSED(user_data)) +{ + if (seq->strip) { + colormanage_check_colorspace_settings(&seq->strip->colorspace_settings, "sequencer strip"); + } + return true; +} + void IMB_colormanagement_check_file_config(Main *bmain) { Scene *scene; @@ -1217,13 +1225,9 @@ void IMB_colormanagement_check_file_config(Main *bmain) } /* check sequencer strip input color space settings */ - Sequence *seq; - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->strip) { - colormanage_check_colorspace_settings(&seq->strip->colorspace_settings, "sequencer strip"); - } + if (scene->ed != NULL) { + SEQ_for_each_callback(&scene->ed->seqbase, seq_callback, NULL); } - SEQ_ALL_END; } /* ** check input color space settings ** */ diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c index 5f198a8ed4c..1ac6dd021e9 100644 --- a/source/blender/makesrna/intern/rna_color.c +++ b/source/blender/makesrna/intern/rna_color.c @@ -597,6 +597,27 @@ static const EnumPropertyItem *rna_ColorManagedColorspaceSettings_colorspace_ite return items; } +typedef struct Seq_colorspace_cb_data { + ColorManagedColorspaceSettings *colorspace_settings; + Sequence *r_seq; +} Seq_colorspace_cb_data; + +static bool seq_find_colorspace_settings_cb(Sequence *seq, void *user_data) +{ + Seq_colorspace_cb_data *cd = (Seq_colorspace_cb_data *)user_data; + if (seq->strip && &seq->strip->colorspace_settings == cd->colorspace_settings) { + cd->r_seq = seq; + return false; + } + return true; +} + +static bool seq_free_anim_cb(Sequence *seq, void *UNUSED(user_data)) +{ + SEQ_relations_sequence_free_anim(seq); + return true; +} + static void rna_ColorManagedColorspaceSettings_reload_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) @@ -629,20 +650,14 @@ static void rna_ColorManagedColorspaceSettings_reload_update(Main *bmain, if (scene->ed) { ColorManagedColorspaceSettings *colorspace_settings = (ColorManagedColorspaceSettings *) ptr->data; - Sequence *seq; - bool seq_found = false; + Seq_colorspace_cb_data cb_data = {colorspace_settings, NULL}; if (&scene->sequencer_colorspace_settings != colorspace_settings) { - SEQ_ALL_BEGIN (scene->ed, seq) { - if (seq->strip && &seq->strip->colorspace_settings == colorspace_settings) { - seq_found = true; - break; - } - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, seq_find_colorspace_settings_cb, &cb_data); } + Sequence *seq = cb_data.r_seq; - if (seq_found) { + if (seq) { SEQ_relations_sequence_free_anim(seq); if (seq->strip->proxy && seq->strip->proxy->anim) { @@ -653,10 +668,7 @@ static void rna_ColorManagedColorspaceSettings_reload_update(Main *bmain, SEQ_relations_invalidate_cache_raw(scene, seq); } else { - SEQ_ALL_BEGIN (scene->ed, seq) { - SEQ_relations_sequence_free_anim(seq); - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, seq_free_anim_cb, NULL); } WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL); diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index dad77b4aad5..9dee7bc841c 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -495,15 +495,15 @@ static void rna_Sequence_use_proxy_set(PointerRNA *ptr, bool value) SEQ_proxy_set(seq, value != 0); } -static int transform_seq_cmp_fn(Sequence *seq, void *arg_pt) +static bool transform_seq_cmp_fn(Sequence *seq, void *arg_pt) { SequenceSearchData *data = arg_pt; if (seq->strip && seq->strip->transform == data->data) { data->seq = seq; - return -1; /* done so bail out */ + return false; /* done so bail out */ } - return 1; + return true; } static Sequence *sequence_get_by_transform(Editing *ed, StripTransform *transform) @@ -514,7 +514,7 @@ static Sequence *sequence_get_by_transform(Editing *ed, StripTransform *transfor data.data = transform; /* irritating we need to search for our sequence! */ - SEQ_seqbase_recursive_apply(&ed->seqbase, transform_seq_cmp_fn, &data); + SEQ_for_each_callback(&ed->seqbase, transform_seq_cmp_fn, &data); return data.seq; } @@ -547,15 +547,15 @@ static void rna_SequenceTransform_update(Main *UNUSED(bmain), SEQ_relations_invalidate_cache_preprocessed(scene, seq); } -static int crop_seq_cmp_fn(Sequence *seq, void *arg_pt) +static bool crop_seq_cmp_fn(Sequence *seq, void *arg_pt) { SequenceSearchData *data = arg_pt; if (seq->strip && seq->strip->crop == data->data) { data->seq = seq; - return -1; /* done so bail out */ + return false; /* done so bail out */ } - return 1; + return true; } static Sequence *sequence_get_by_crop(Editing *ed, StripCrop *crop) @@ -566,7 +566,7 @@ static Sequence *sequence_get_by_crop(Editing *ed, StripCrop *crop) data.data = crop; /* irritating we need to search for our sequence! */ - SEQ_seqbase_recursive_apply(&ed->seqbase, crop_seq_cmp_fn, &data); + SEQ_for_each_callback(&ed->seqbase, crop_seq_cmp_fn, &data); return data.seq; } @@ -935,15 +935,15 @@ static void rna_Sequence_sound_update(Main *bmain, Scene *scene, PointerRNA *UNU DEG_relations_tag_update(bmain); } -static int seqproxy_seq_cmp_fn(Sequence *seq, void *arg_pt) +static bool seqproxy_seq_cmp_fn(Sequence *seq, void *arg_pt) { SequenceSearchData *data = arg_pt; if (seq->strip && seq->strip->proxy == data->data) { data->seq = seq; - return -1; /* done so bail out */ + return false; /* done so bail out */ } - return 1; + return true; } static Sequence *sequence_get_by_proxy(Editing *ed, StripProxy *proxy) @@ -953,7 +953,7 @@ static Sequence *sequence_get_by_proxy(Editing *ed, StripProxy *proxy) data.seq = NULL; data.data = proxy; - SEQ_seqbase_recursive_apply(&ed->seqbase, seqproxy_seq_cmp_fn, &data); + SEQ_for_each_callback(&ed->seqbase, seqproxy_seq_cmp_fn, &data); return data.seq; } @@ -988,7 +988,7 @@ static void rna_Sequence_opacity_set(PointerRNA *ptr, float value) seq->blend_opacity = value * 100.0f; } -static int colbalance_seq_cmp_fn(Sequence *seq, void *arg_pt) +static bool colbalance_seq_cmp_fn(Sequence *seq, void *arg_pt) { SequenceSearchData *data = arg_pt; @@ -999,12 +999,12 @@ static int colbalance_seq_cmp_fn(Sequence *seq, void *arg_pt) if (&cbmd->color_balance == data->data) { data->seq = seq; data->smd = smd; - return -1; /* done so bail out */ + return false; /* done so bail out */ } } } - return 1; + return true; } static Sequence *sequence_get_by_colorbalance(Editing *ed, @@ -1018,7 +1018,7 @@ static Sequence *sequence_get_by_colorbalance(Editing *ed, data.data = cb; /* irritating we need to search for our sequence! */ - SEQ_seqbase_recursive_apply(&ed->seqbase, colbalance_seq_cmp_fn, &data); + SEQ_for_each_callback(&ed->seqbase, colbalance_seq_cmp_fn, &data); *r_smd = data.smd; @@ -1122,16 +1122,16 @@ static void rna_SequenceEditor_overlay_frame_set(PointerRNA *ptr, int value) } } -static int modifier_seq_cmp_fn(Sequence *seq, void *arg_pt) +static bool modifier_seq_cmp_fn(Sequence *seq, void *arg_pt) { SequenceSearchData *data = arg_pt; if (BLI_findindex(&seq->modifiers, data->data) != -1) { data->seq = seq; - return -1; /* done so bail out */ + return false; /* done so bail out */ } - return 1; + return true; } static Sequence *sequence_get_by_modifier(Editing *ed, SequenceModifierData *smd) @@ -1142,7 +1142,7 @@ static Sequence *sequence_get_by_modifier(Editing *ed, SequenceModifierData *smd data.data = smd; /* irritating we need to search for our sequence! */ - SEQ_seqbase_recursive_apply(&ed->seqbase, modifier_seq_cmp_fn, &data); + SEQ_for_each_callback(&ed->seqbase, modifier_seq_cmp_fn, &data); return data.seq; } diff --git a/source/blender/sequencer/SEQ_iterator.h b/source/blender/sequencer/SEQ_iterator.h index 3ade7309f89..055db07f646 100644 --- a/source/blender/sequencer/SEQ_iterator.h +++ b/source/blender/sequencer/SEQ_iterator.h @@ -39,23 +39,7 @@ struct Sequence; SEQ_iterator_ensure(collection, &iter, &var) && var != NULL; \ var = SEQ_iterator_yield(&iter)) -#define SEQ_ALL_BEGIN(ed, var) \ - { \ - if (ed != NULL) { \ - SeqCollection *all_strips = SEQ_query_all_strips_recursive(&ed->seqbase); \ - GSetIterator gsi; \ - GSET_ITER (gsi, all_strips->set) { \ - var = (Sequence *)(BLI_gsetIterator_getKey(&gsi)); - -#define SEQ_ALL_END \ - } \ - SEQ_collection_free(all_strips); \ - } \ - } \ - ((void)0) - typedef struct SeqCollection { - struct SeqCollection *next, *prev; struct GSet *set; } SeqCollection; @@ -70,6 +54,11 @@ bool SEQ_iterator_ensure(SeqCollection *collection, struct Sequence **r_seq); struct Sequence *SEQ_iterator_yield(SeqIterator *iterator); +/* Callback format for the for_each function below. */ +typedef bool (*SeqForEachFunc)(struct Sequence *seq, void *user_data); + +void SEQ_for_each_callback(struct ListBase *seqbase, SeqForEachFunc callback, void *user_data); + SeqCollection *SEQ_collection_create(const char *name); SeqCollection *SEQ_collection_duplicate(SeqCollection *collection); uint SEQ_collection_len(const SeqCollection *collection); @@ -90,8 +79,8 @@ SeqCollection *SEQ_query_by_reference(struct Sequence *seq_reference, struct ListBase *seqbase, SeqCollection *collection)); SeqCollection *SEQ_query_selected_strips(struct ListBase *seqbase); -SeqCollection *SEQ_query_all_strips(ListBase *seqbase); -SeqCollection *SEQ_query_all_strips_recursive(ListBase *seqbase); +SeqCollection *SEQ_query_all_strips(struct ListBase *seqbase); +SeqCollection *SEQ_query_all_strips_recursive(struct ListBase *seqbase); void SEQ_query_strip_effect_chain(struct Sequence *seq_reference, struct ListBase *seqbase, SeqCollection *collection); diff --git a/source/blender/sequencer/SEQ_sequencer.h b/source/blender/sequencer/SEQ_sequencer.h index f4338d13c8f..27463379ae0 100644 --- a/source/blender/sequencer/SEQ_sequencer.h +++ b/source/blender/sequencer/SEQ_sequencer.h @@ -29,6 +29,11 @@ extern "C" { #include "DNA_scene_types.h" +struct BlendWriter; +struct BlendDataReader; +struct BlendLibReader; +struct BlendExpander; +struct Depsgraph; struct Editing; struct Scene; struct Sequence; @@ -83,6 +88,21 @@ void SEQ_sequence_base_dupli_recursive(const struct Scene *scene_src, int dupe_flag, const int flag); +/* Read and Write functions for .blend file data */ +void SEQ_blend_write(struct BlendWriter *writer, struct ListBase *seqbase); +void SEQ_blend_read(struct BlendDataReader *reader, struct ListBase *seqbase); + +void SEQ_blend_read_lib(struct BlendLibReader *reader, + struct Scene *scene, + struct ListBase *seqbase); + +void SEQ_blend_read_expand(struct BlendExpander *expander, struct ListBase *seqbase); + +/* Depsgraph update function */ +void SEQ_eval_sequences(struct Depsgraph *depsgraph, + struct Scene *scene, + struct ListBase *seqbase); + /* Defined in sequence_lookup.c */ typedef enum eSequenceLookupTag { diff --git a/source/blender/sequencer/SEQ_utils.h b/source/blender/sequencer/SEQ_utils.h index 99603dc8a3e..09de7bc67e9 100644 --- a/source/blender/sequencer/SEQ_utils.h +++ b/source/blender/sequencer/SEQ_utils.h @@ -56,12 +56,6 @@ void SEQ_set_scale_to_fit(const struct Sequence *seq, const int preview_width, const int preview_height, const eSeqImageFitMethod fit_method); -int SEQ_seqbase_recursive_apply(struct ListBase *seqbase, - int (*apply_fn)(struct Sequence *seq, void *), - void *arg); -int SEQ_recursive_apply(struct Sequence *seq, - int (*apply_fn)(struct Sequence *, void *), - void *arg); void SEQ_ensure_unique_name(struct Sequence *seq, struct Scene *scene); #ifdef __cplusplus diff --git a/source/blender/sequencer/intern/clipboard.c b/source/blender/sequencer/intern/clipboard.c index 9e702a4e60b..05406c50303 100644 --- a/source/blender/sequencer/intern/clipboard.c +++ b/source/blender/sequencer/intern/clipboard.c @@ -71,7 +71,7 @@ void SEQ_clipboard_free(void) for (seq = seqbase_clipboard.first; seq; seq = nseq) { nseq = seq->next; - seq_free_sequence_recurse(NULL, seq, false); + seq_free_sequence_recurse(NULL, seq, false, true); } BLI_listbase_clear(&seqbase_clipboard); } diff --git a/source/blender/sequencer/intern/iterator.c b/source/blender/sequencer/intern/iterator.c index 333a8e46c44..2ac93ccc9d3 100644 --- a/source/blender/sequencer/intern/iterator.c +++ b/source/blender/sequencer/intern/iterator.c @@ -90,6 +90,37 @@ Sequence *SEQ_iterator_yield(SeqIterator *iterator) return seq; } +static bool seq_for_each_recursive(ListBase *seqbase, SeqForEachFunc callback, void *user_data) +{ + LISTBASE_FOREACH (Sequence *, seq, seqbase) { + if (!callback(seq, user_data)) { + /* Callback signaled stop, return. */ + return false; + } + if (seq->type == SEQ_TYPE_META) { + if (!seq_for_each_recursive(&seq->seqbase, callback, user_data)) { + return false; + } + } + } + return true; +} + +/** + * Utility function to recursivily iterate through all sequence strips in a seqbase list. + * Uses callback to do operations on each sequence element. + * The callback can stop the iteration if needed. + * + * \param seqbase: ListBase of sequences to be iterated over + * \param callback: query function callback, returns false if iteration should stop + * \param user_data: pointer to user data that can be used in the callback function + * + */ +void SEQ_for_each_callback(ListBase *seqbase, SeqForEachFunc callback, void *user_data) +{ + seq_for_each_recursive(seqbase, callback, user_data); +} + /** * Free strip collection. * @@ -222,19 +253,15 @@ void SEQ_collection_expand(ListBase *seqbase, SeqCollection *collection)) { /* Collect expanded results for each sequence in provided SeqIteratorCollection. */ - ListBase expand_collections = {0}; + SeqCollection *query_matches = SEQ_collection_create(__func__); Sequence *seq; SEQ_ITERATOR_FOREACH (seq, collection) { - SeqCollection *expand_collection = SEQ_query_by_reference(seq, seqbase, seq_query_func); - BLI_addtail(&expand_collections, expand_collection); + SEQ_collection_merge(query_matches, SEQ_query_by_reference(seq, seqbase, seq_query_func)); } /* Merge all expanded results in provided SeqIteratorCollection. */ - LISTBASE_FOREACH_MUTABLE (SeqCollection *, expand_collection, &expand_collections) { - BLI_remlink(&expand_collections, expand_collection); - SEQ_collection_merge(collection, expand_collection); - } + SEQ_collection_merge(collection, query_matches); } /** @@ -255,6 +282,16 @@ SeqCollection *SEQ_collection_duplicate(SeqCollection *collection) /** \} */ +static void query_all_strips_recursive(ListBase *seqbase, SeqCollection *collection) +{ + LISTBASE_FOREACH (Sequence *, seq, seqbase) { + if (seq->type == SEQ_TYPE_META) { + query_all_strips_recursive(&seq->seqbase, collection); + } + SEQ_collection_append_strip(seq, collection); + } +} + /** * Query all strips in seqbase and nested meta strips. * @@ -266,7 +303,7 @@ SeqCollection *SEQ_query_all_strips_recursive(ListBase *seqbase) SeqCollection *collection = SEQ_collection_create(__func__); LISTBASE_FOREACH (Sequence *, seq, seqbase) { if (seq->type == SEQ_TYPE_META) { - SEQ_collection_merge(collection, SEQ_query_all_strips_recursive(&seq->seqbase)); + query_all_strips_recursive(&seq->seqbase, collection); } SEQ_collection_append_strip(seq, collection); } @@ -282,9 +319,7 @@ SeqCollection *SEQ_query_all_strips_recursive(ListBase *seqbase) SeqCollection *SEQ_query_all_strips(ListBase *seqbase) { SeqCollection *collection = SEQ_collection_create(__func__); - LISTBASE_FOREACH (Sequence *, seq, seqbase) { - SEQ_collection_append_strip(seq, collection); - } + query_all_strips_recursive(seqbase, collection); return collection; } diff --git a/source/blender/sequencer/intern/proxy.c b/source/blender/sequencer/intern/proxy.c index bd7ea5b958c..2bc294c91cd 100644 --- a/source/blender/sequencer/intern/proxy.c +++ b/source/blender/sequencer/intern/proxy.c @@ -576,7 +576,7 @@ void SEQ_proxy_rebuild_finish(SeqIndexBuildContext *context, bool stop) IMB_anim_index_rebuild_finish(context->index_context, stop); } - seq_free_sequence_recurse(NULL, context->seq, true); + seq_free_sequence_recurse(NULL, context->seq, true, true); MEM_freeN(context); } diff --git a/source/blender/sequencer/intern/sequencer.c b/source/blender/sequencer/intern/sequencer.c index 7dc19cf39a6..49d08d0e022 100644 --- a/source/blender/sequencer/intern/sequencer.c +++ b/source/blender/sequencer/intern/sequencer.c @@ -24,11 +24,14 @@ * \ingroup bke */ +#define DNA_DEPRECATED_ALLOW + #include "MEM_guardedalloc.h" #include "DNA_anim_types.h" #include "DNA_scene_types.h" #include "DNA_sequence_types.h" +#include "DNA_sound_types.h" #include "BLI_listbase.h" #include "BLI_string.h" @@ -44,14 +47,19 @@ #include "IMB_colormanagement.h" #include "IMB_imbuf.h" +#include "SEQ_edit.h" #include "SEQ_effects.h" #include "SEQ_iterator.h" #include "SEQ_modifier.h" +#include "SEQ_proxy.h" #include "SEQ_relations.h" #include "SEQ_select.h" #include "SEQ_sequencer.h" +#include "SEQ_sound.h" #include "SEQ_utils.h" +#include "BLO_read_write.h" + #include "image_cache.h" #include "prefetch.h" #include "sequencer.h" @@ -217,16 +225,19 @@ void SEQ_sequence_free(Scene *scene, Sequence *seq, const bool do_clean_animdata /* cache must be freed before calling this function * since it leaves the seqbase in an invalid state */ -void seq_free_sequence_recurse(Scene *scene, Sequence *seq, const bool do_id_user) +void seq_free_sequence_recurse(Scene *scene, + Sequence *seq, + const bool do_id_user, + const bool do_clean_animdata) { Sequence *iseq, *iseq_next; for (iseq = seq->seqbase.first; iseq; iseq = iseq_next) { iseq_next = iseq->next; - seq_free_sequence_recurse(scene, iseq, do_id_user); + seq_free_sequence_recurse(scene, iseq, do_id_user, do_clean_animdata); } - seq_sequence_free_ex(scene, seq, false, do_id_user, true); + seq_sequence_free_ex(scene, seq, false, do_id_user, do_clean_animdata); } Editing *SEQ_editing_get(Scene *scene, bool alloc) @@ -255,7 +266,6 @@ Editing *SEQ_editing_ensure(Scene *scene) void SEQ_editing_free(Scene *scene, const bool do_id_user) { Editing *ed = scene->ed; - Sequence *seq; if (ed == NULL) { return; @@ -264,11 +274,10 @@ void SEQ_editing_free(Scene *scene, const bool do_id_user) seq_prefetch_free(scene); seq_cache_destruct(scene); - SEQ_ALL_BEGIN (ed, seq) { - /* handle cache freeing above */ - seq_sequence_free_ex(scene, seq, false, do_id_user, false); + /* handle cache freeing above */ + LISTBASE_FOREACH_MUTABLE (Sequence *, seq, &ed->seqbase) { + seq_free_sequence_recurse(scene, seq, do_id_user, false); } - SEQ_ALL_END; BLI_freelistN(&ed->metastack); SEQ_sequence_lookup_free(scene); @@ -732,3 +741,315 @@ SequencerToolSettings *SEQ_tool_settings_copy(SequencerToolSettings *tool_settin } /** \} */ + +static bool seq_set_strip_done_cb(Sequence *seq, void *UNUSED(userdata)) +{ + if (seq->strip) { + seq->strip->done = false; + } + return true; +} + +static bool seq_write_data_cb(Sequence *seq, void *userdata) +{ + BlendWriter *writer = (BlendWriter *)userdata; + BLO_write_struct(writer, Sequence, seq); + if (seq->strip && seq->strip->done == 0) { + /* write strip with 'done' at 0 because readfile */ + + // TODO this doesn't depend on the `Strip` data to be present? + if (seq->effectdata) { + switch (seq->type) { + case SEQ_TYPE_COLOR: + BLO_write_struct(writer, SolidColorVars, seq->effectdata); + break; + case SEQ_TYPE_SPEED: + BLO_write_struct(writer, SpeedControlVars, seq->effectdata); + break; + case SEQ_TYPE_WIPE: + BLO_write_struct(writer, WipeVars, seq->effectdata); + break; + case SEQ_TYPE_GLOW: + BLO_write_struct(writer, GlowVars, seq->effectdata); + break; + case SEQ_TYPE_TRANSFORM: + BLO_write_struct(writer, TransformVars, seq->effectdata); + break; + case SEQ_TYPE_GAUSSIAN_BLUR: + BLO_write_struct(writer, GaussianBlurVars, seq->effectdata); + break; + case SEQ_TYPE_TEXT: + BLO_write_struct(writer, TextVars, seq->effectdata); + break; + case SEQ_TYPE_COLORMIX: + BLO_write_struct(writer, ColorMixVars, seq->effectdata); + break; + } + } + + BLO_write_struct(writer, Stereo3dFormat, seq->stereo3d_format); + + Strip *strip = seq->strip; + BLO_write_struct(writer, Strip, strip); + if (strip->crop) { + BLO_write_struct(writer, StripCrop, strip->crop); + } + if (strip->transform) { + BLO_write_struct(writer, StripTransform, strip->transform); + } + if (strip->proxy) { + BLO_write_struct(writer, StripProxy, strip->proxy); + } + if (seq->type == SEQ_TYPE_IMAGE) { + BLO_write_struct_array(writer, + StripElem, + MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), + strip->stripdata); + } + else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) { + BLO_write_struct(writer, StripElem, strip->stripdata); + } + + strip->done = true; + } + + if (seq->prop) { + IDP_BlendWrite(writer, seq->prop); + } + + SEQ_modifier_blend_write(writer, &seq->modifiers); + return true; +} + +void SEQ_blend_write(BlendWriter *writer, ListBase *seqbase) +{ + /* reset write flags */ + SEQ_for_each_callback(seqbase, seq_set_strip_done_cb, NULL); + + SEQ_for_each_callback(seqbase, seq_write_data_cb, writer); +} + +static bool seq_read_data_cb(Sequence *seq, void *user_data) +{ + BlendDataReader *reader = (BlendDataReader *)user_data; + + /* Do as early as possible, so that other parts of reading can rely on valid session UUID. */ + SEQ_relations_session_uuid_generate(seq); + + BLO_read_data_address(reader, &seq->seq1); + BLO_read_data_address(reader, &seq->seq2); + BLO_read_data_address(reader, &seq->seq3); + + /* a patch: after introduction of effects with 3 input strips */ + if (seq->seq3 == NULL) { + seq->seq3 = seq->seq2; + } + + BLO_read_data_address(reader, &seq->effectdata); + BLO_read_data_address(reader, &seq->stereo3d_format); + + if (seq->type & SEQ_TYPE_EFFECT) { + seq->flag |= SEQ_EFFECT_NOT_LOADED; + } + + if (seq->type == SEQ_TYPE_TEXT) { + TextVars *t = seq->effectdata; + t->text_blf_id = SEQ_FONT_NOT_LOADED; + } + + BLO_read_data_address(reader, &seq->prop); + IDP_BlendDataRead(reader, &seq->prop); + + BLO_read_data_address(reader, &seq->strip); + if (seq->strip && seq->strip->done == 0) { + seq->strip->done = true; + + if (ELEM(seq->type, SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) { + BLO_read_data_address(reader, &seq->strip->stripdata); + } + else { + seq->strip->stripdata = NULL; + } + BLO_read_data_address(reader, &seq->strip->crop); + BLO_read_data_address(reader, &seq->strip->transform); + BLO_read_data_address(reader, &seq->strip->proxy); + if (seq->strip->proxy) { + seq->strip->proxy->anim = NULL; + } + else if (seq->flag & SEQ_USE_PROXY) { + SEQ_proxy_set(seq, true); + } + + /* need to load color balance to it could be converted to modifier */ + BLO_read_data_address(reader, &seq->strip->color_balance); + } + + SEQ_modifier_blend_read_data(reader, &seq->modifiers); + return true; +} +void SEQ_blend_read(BlendDataReader *reader, ListBase *seqbase) +{ + SEQ_for_each_callback(seqbase, seq_read_data_cb, reader); +} + +typedef struct Read_lib_data { + BlendLibReader *reader; + Scene *scene; +} Read_lib_data; + +static bool seq_read_lib_cb(Sequence *seq, void *user_data) +{ + Read_lib_data *data = (Read_lib_data *)user_data; + BlendLibReader *reader = data->reader; + Scene *sce = data->scene; + + IDP_BlendReadLib(reader, seq->prop); + + if (seq->ipo) { + /* XXX: deprecated - old animation system. */ + BLO_read_id_address(reader, sce->id.lib, &seq->ipo); + } + seq->scene_sound = NULL; + if (seq->scene) { + BLO_read_id_address(reader, sce->id.lib, &seq->scene); + seq->scene_sound = NULL; + } + if (seq->clip) { + BLO_read_id_address(reader, sce->id.lib, &seq->clip); + } + if (seq->mask) { + BLO_read_id_address(reader, sce->id.lib, &seq->mask); + } + if (seq->scene_camera) { + BLO_read_id_address(reader, sce->id.lib, &seq->scene_camera); + } + if (seq->sound) { + seq->scene_sound = NULL; + if (seq->type == SEQ_TYPE_SOUND_HD) { + seq->type = SEQ_TYPE_SOUND_RAM; + } + else { + BLO_read_id_address(reader, sce->id.lib, &seq->sound); + } + if (seq->sound) { + id_us_plus_no_lib((ID *)seq->sound); + seq->scene_sound = NULL; + } + } + if (seq->type == SEQ_TYPE_TEXT) { + TextVars *t = seq->effectdata; + BLO_read_id_address(reader, sce->id.lib, &t->text_font); + } + BLI_listbase_clear(&seq->anims); + + SEQ_modifier_blend_read_lib(reader, sce, &seq->modifiers); + return true; +} + +void SEQ_blend_read_lib(BlendLibReader *reader, Scene *scene, ListBase *seqbase) +{ + Read_lib_data data = {reader, scene}; + SEQ_for_each_callback(seqbase, seq_read_lib_cb, &data); +} + +static bool seq_blend_read_expand(Sequence *seq, void *user_data) +{ + BlendExpander *expander = (BlendExpander *)user_data; + + IDP_BlendReadExpand(expander, seq->prop); + + if (seq->scene) { + BLO_expand(expander, seq->scene); + } + if (seq->scene_camera) { + BLO_expand(expander, seq->scene_camera); + } + if (seq->clip) { + BLO_expand(expander, seq->clip); + } + if (seq->mask) { + BLO_expand(expander, seq->mask); + } + if (seq->sound) { + BLO_expand(expander, seq->sound); + } + + if (seq->type == SEQ_TYPE_TEXT && seq->effectdata) { + TextVars *data = seq->effectdata; + BLO_expand(expander, data->text_font); + } + return true; +} + +void SEQ_blend_read_expand(BlendExpander *expander, ListBase *seqbase) +{ + SEQ_for_each_callback(seqbase, seq_blend_read_expand, expander); +} + +/* Depsgraph update functions. */ + +static bool seq_disable_sound_strips_cb(Sequence *seq, void *user_data) +{ + Scene *scene = (Scene *)user_data; + if (seq->scene_sound != NULL) { + BKE_sound_remove_scene_sound(scene, seq->scene_sound); + seq->scene_sound = NULL; + } + return true; +} + +static bool seq_update_seq_cb(Sequence *seq, void *user_data) +{ + Scene *scene = (Scene *)user_data; + if (seq->scene_sound == NULL) { + if (seq->sound != NULL) { + seq->scene_sound = BKE_sound_add_scene_sound_defaults(scene, seq); + } + else if (seq->type == SEQ_TYPE_SCENE) { + if (seq->scene != NULL) { + BKE_sound_ensure_scene(seq->scene); + seq->scene_sound = BKE_sound_scene_add_scene_sound_defaults(scene, seq); + } + } + } + if (seq->scene_sound != NULL) { + /* Make sure changing volume via sequence's properties panel works correct. + * + * Ideally, the entire BKE_scene_update_sound() will happen from a dependency graph, so + * then it is no longer needed to do such manual forced updates. */ + if (seq->type == SEQ_TYPE_SCENE && seq->scene != NULL) { + BKE_sound_set_scene_volume(seq->scene, seq->scene->audio.volume); + if ((seq->flag & SEQ_SCENE_STRIPS) == 0 && seq->scene->sound_scene != NULL && + seq->scene->ed != NULL) { + SEQ_for_each_callback(&seq->scene->ed->seqbase, seq_disable_sound_strips_cb, seq->scene); + } + } + if (seq->sound != NULL) { + if (scene->id.recalc & ID_RECALC_AUDIO || seq->sound->id.recalc & ID_RECALC_AUDIO) { + BKE_sound_update_scene_sound(seq->scene_sound, seq->sound); + } + } + BKE_sound_set_scene_sound_volume( + seq->scene_sound, seq->volume, (seq->flag & SEQ_AUDIO_VOLUME_ANIMATED) != 0); + BKE_sound_set_scene_sound_pitch( + seq->scene_sound, seq->pitch, (seq->flag & SEQ_AUDIO_PITCH_ANIMATED) != 0); + BKE_sound_set_scene_sound_pan( + seq->scene_sound, seq->pan, (seq->flag & SEQ_AUDIO_PAN_ANIMATED) != 0); + } + return true; +} + +/* Evaluate parts of sequences which needs to be done as a part of a dependency graph evaluation. + * This does NOT include actual rendering of the strips, but rather makes them up-to-date for + * animation playback and makes them ready for the sequencer's rendering pipeline to render them. + */ +void SEQ_eval_sequences(Depsgraph *depsgraph, Scene *scene, ListBase *seqbase) +{ + DEG_debug_print_eval(depsgraph, __func__, scene->id.name, scene); + BKE_sound_ensure_scene(scene); + + SEQ_for_each_callback(seqbase, seq_update_seq_cb, scene); + + SEQ_edit_update_muting(scene->ed); + SEQ_sound_update_bounds_all(scene); +} diff --git a/source/blender/sequencer/intern/sequencer.h b/source/blender/sequencer/intern/sequencer.h index 928b3edd728..e43535d14ee 100644 --- a/source/blender/sequencer/intern/sequencer.h +++ b/source/blender/sequencer/intern/sequencer.h @@ -30,7 +30,10 @@ extern "C" { struct Scene; struct Sequence; -void seq_free_sequence_recurse(struct Scene *scene, struct Sequence *seq, const bool do_id_user); +void seq_free_sequence_recurse(struct Scene *scene, + struct Sequence *seq, + const bool do_id_user, + const bool do_clean_animdata); #ifdef __cplusplus } diff --git a/source/blender/sequencer/intern/strip_relations.c b/source/blender/sequencer/intern/strip_relations.c index ec70a683da5..b840b19f244 100644 --- a/source/blender/sequencer/intern/strip_relations.c +++ b/source/blender/sequencer/intern/strip_relations.c @@ -476,6 +476,24 @@ void SEQ_relations_session_uuid_generate(struct Sequence *sequence) sequence->runtime.session_uuid = BLI_session_uuid_generate(); } +static bool get_uuids_cb(Sequence *seq, void *user_data) +{ + struct GSet *used_uuids = (struct GSet *)user_data; + const SessionUUID *session_uuid = &seq->runtime.session_uuid; + if (!BLI_session_uuid_is_generated(session_uuid)) { + printf("Sequence %s does not have UUID generated.\n", seq->name); + return true; + } + + if (BLI_gset_lookup(used_uuids, session_uuid) != NULL) { + printf("Sequence %s has duplicate UUID generated.\n", seq->name); + return true; + } + + BLI_gset_insert(used_uuids, (void *)session_uuid); + return true; +} + void SEQ_relations_check_uuids_unique_and_report(const Scene *scene) { if (scene->ed == NULL) { @@ -485,22 +503,7 @@ void SEQ_relations_check_uuids_unique_and_report(const Scene *scene) struct GSet *used_uuids = BLI_gset_new( BLI_session_uuid_ghash_hash, BLI_session_uuid_ghash_compare, "sequencer used uuids"); - const Sequence *sequence; - SEQ_ALL_BEGIN (scene->ed, sequence) { - const SessionUUID *session_uuid = &sequence->runtime.session_uuid; - if (!BLI_session_uuid_is_generated(session_uuid)) { - printf("Sequence %s does not have UUID generated.\n", sequence->name); - continue; - } - - if (BLI_gset_lookup(used_uuids, session_uuid) != NULL) { - printf("Sequence %s has duplicate UUID generated.\n", sequence->name); - continue; - } - - BLI_gset_insert(used_uuids, (void *)session_uuid); - } - SEQ_ALL_END; + SEQ_for_each_callback(&scene->ed->seqbase, get_uuids_cb, used_uuids); BLI_gset_free(used_uuids, NULL); } diff --git a/source/blender/sequencer/intern/utils.c b/source/blender/sequencer/intern/utils.c index f946affe1d8..e4eecaf552c 100644 --- a/source/blender/sequencer/intern/utils.c +++ b/source/blender/sequencer/intern/utils.c @@ -133,12 +133,12 @@ static void seqbase_unique_name(ListBase *seqbasep, SeqUniqueInfo *sui) } } -static int seqbase_unique_name_recursive_fn(Sequence *seq, void *arg_pt) +static bool seqbase_unique_name_recursive_fn(Sequence *seq, void *arg_pt) { if (seq->seqbase.first) { seqbase_unique_name(&seq->seqbase, (SeqUniqueInfo *)arg_pt); } - return 1; + return true; } void SEQ_sequence_base_unique_name_recursive(struct Scene *scene, @@ -167,7 +167,7 @@ void SEQ_sequence_base_unique_name_recursive(struct Scene *scene, while (sui.match) { sui.match = 0; seqbase_unique_name(seqbasep, &sui); - SEQ_seqbase_recursive_apply(seqbasep, seqbase_unique_name_recursive_fn, &sui); + SEQ_for_each_callback(seqbasep, seqbase_unique_name_recursive_fn, &sui); } SEQ_edit_sequence_name_set(scene, seq, sui.name_dest); @@ -573,34 +573,6 @@ void SEQ_set_scale_to_fit(const Sequence *seq, } } -int SEQ_seqbase_recursive_apply(ListBase *seqbase, - int (*apply_fn)(Sequence *seq, void *), - void *arg) -{ - Sequence *iseq; - for (iseq = seqbase->first; iseq; iseq = iseq->next) { - if (SEQ_recursive_apply(iseq, apply_fn, arg) == -1) { - return -1; /* bail out */ - } - } - return 1; -} - -int SEQ_recursive_apply(Sequence *seq, int (*apply_fn)(Sequence *, void *), void *arg) -{ - int ret = apply_fn(seq, arg); - - if (ret == -1) { - return -1; /* bail out */ - } - - if (ret && seq->seqbase.first) { - ret = SEQ_seqbase_recursive_apply(&seq->seqbase, apply_fn, arg); - } - - return ret; -} - /** * Ensure, that provided Sequence has unique name. If animation data exists for this Sequence, it * will be duplicated and mapped onto new name -- cgit v1.2.3 From 0d36439f95c0f3c320ebfd429ee8085dd8a6ebc0 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 25 Aug 2021 12:44:25 -0300 Subject: Fix T90911: Move along axis does not display real distance units Variable was wrongly set to 0. Caused by {rB7192e57d63a5}. --- source/blender/editors/transform/transform_mode_translate.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/editors/transform/transform_mode_translate.c b/source/blender/editors/transform/transform_mode_translate.c index e44e346d3e4..84c036387a7 100644 --- a/source/blender/editors/transform/transform_mode_translate.c +++ b/source/blender/editors/transform/transform_mode_translate.c @@ -234,7 +234,6 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_ if (t->con.mode & CON_APPLY) { int i = 0; - zero_v3(dvec); if (t->con.mode & CON_AXIS0) { dvec[i++] = dvec[0]; } -- cgit v1.2.3 From 8fb91555988d48b6b9d546b0654d5c6274fa1134 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 25 Aug 2021 18:00:00 +0200 Subject: Fix T90248: missing depsgraph update tag for node group The code assumed that when a node group is is at the highest level in the node editor, then it is embedded into another data block and can't be referenced by other node groups. This is true for shader and compositor nodes, but not for geometry nodes. --- source/blender/editors/space_node/node_edit.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index cbf03f553f6..5b1b737751c 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -398,7 +398,7 @@ void snode_dag_update(bContext *C, SpaceNode *snode) Main *bmain = CTX_data_main(C); /* for groups, update all ID's using this */ - if (snode->edittree != snode->nodetree) { + if ((snode->edittree->id.flag & LIB_EMBEDDED_DATA) == 0) { FOREACH_NODETREE_BEGIN (bmain, tntree, id) { if (ntreeHasTree(tntree, snode->edittree)) { DEG_id_tag_update(id, 0); -- cgit v1.2.3 From 05564c8ca61d8fb3c2df32cd4ec60a540a13e4a6 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 25 Aug 2021 13:01:19 -0300 Subject: Fix wrong length value in the header of the Move operator Missed in {rB0d36439f95c0}. --- source/blender/editors/transform/transform_mode_translate.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/editors/transform/transform_mode_translate.c b/source/blender/editors/transform/transform_mode_translate.c index 84c036387a7..82574cffb82 100644 --- a/source/blender/editors/transform/transform_mode_translate.c +++ b/source/blender/editors/transform/transform_mode_translate.c @@ -243,6 +243,9 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_ if (t->con.mode & CON_AXIS2) { dvec[i++] = dvec[2]; } + while (i != 3) { + dvec[i++] = 0.0f; + } } if (t->flag & T_2D_EDIT) { -- cgit v1.2.3 From 518b97e674a9e7cdc91bc4048a89eb8a8b37db0b Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Wed, 25 Aug 2021 10:55:45 -0600 Subject: Windows/Ninja: Optimize linker performance The /Zc:inline flag is by default off in the MSVC compiler however when you build with msbuild it adds it to the build flags on its own. Ninja however does not decide on its own to add flags you didn't ask for and was building without this flag. This change explicitly adds the compiler flag so msbuild and ninja builds are once more building with the same build flags leading to smaller .obj files when building with ninja and lightening the workload for the linker. This flag is available starting MSVC 2013 update 2 so does not need to be guarded with version checks. --- build_files/cmake/platform/platform_win32.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake index d44ef691d1b..e3183fe5b7f 100644 --- a/build_files/cmake/platform/platform_win32.cmake +++ b/build_files/cmake/platform/platform_win32.cmake @@ -151,8 +151,8 @@ if(MSVC_CLANG) # Clangs version of cl doesn't support all flags string(APPEND CMAKE_CXX_FLAGS " ${CXX_WARN_FLAGS} /nologo /J /Gd /EHsc -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /nologo /J /Gd -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference") else() - string(APPEND CMAKE_CXX_FLAGS " /nologo /J /Gd /MP /EHsc /bigobj") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /nologo /J /Gd /MP /bigobj") + string(APPEND CMAKE_CXX_FLAGS " /nologo /J /Gd /MP /EHsc /bigobj /Zc:inline") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /nologo /J /Gd /MP /bigobj /Zc:inline") endif() # X64 ASAN is available and usable on MSVC 16.9 preview 4 and up) -- cgit v1.2.3 From 5b751c95f4e58c5f56b1af61c835b4537f19f43c Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 25 Aug 2021 13:30:00 -0700 Subject: BLF: Remove ASCII-only Code Paths Remove redundant code for drawing text strings that contain only ASCII. See D12293 for much more detail. Differential Revision: https://developer.blender.org/D12293 Reviewed by Campbell Barton --- source/blender/blenfont/BLF_api.h | 5 --- source/blender/blenfont/intern/blf.c | 28 ------------ source/blender/blenfont/intern/blf_default.c | 11 ----- source/blender/blenfont/intern/blf_font.c | 50 ---------------------- .../blender/draw/engines/overlay/overlay_edit_uv.c | 10 +---- .../draw/engines/overlay/overlay_motion_path.c | 2 +- .../blender/draw/intern/draw_manager_profiling.c | 12 +++--- source/blender/draw/intern/draw_manager_text.c | 10 ++--- source/blender/draw/intern/draw_manager_text.h | 2 +- source/blender/editors/interface/view2d_draw.c | 4 +- source/blender/editors/space_image/image_draw.c | 30 ++++++------- source/blender/editors/space_view3d/view3d_draw.c | 10 +---- .../space_view3d/view3d_gizmo_navigate_type.c | 2 +- source/blender/editors/transform/transform.c | 4 -- source/blender/editors/transform/transform_ops.c | 3 +- 15 files changed, 36 insertions(+), 147 deletions(-) diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 4de7e704a7e..78252bdb08b 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -101,9 +101,6 @@ void BLF_batch_draw_end(void); void BLF_draw_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info) ATTR_NONNULL(2); void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); -void BLF_draw_ascii_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info) - ATTR_NONNULL(2); -void BLF_draw_ascii(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2); int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth) ATTR_NONNULL(2); typedef bool (*BLF_GlyphBoundsFn)(const char *str, @@ -257,8 +254,6 @@ void BLF_default_set(int fontid); int BLF_default(void); /* get default font ID so we can pass it to other functions */ /* Draw the string using the default font, size and dpi. */ void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL(); -void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t str_len) - ATTR_NONNULL(); /* Set size and DPI, and return default font ID. */ int BLF_set_default(void); diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 86d67c80fd4..34ddb6f22d2 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -550,34 +550,6 @@ void BLF_draw(int fontid, const char *str, const size_t str_len) BLF_draw_ex(fontid, str, str_len, NULL); } -void BLF_draw_ascii_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info) -{ - FontBLF *font = blf_get(fontid); - - BLF_RESULT_CHECK_INIT(r_info); - - if (font) { - blf_draw_gl__start(font); - if (font->flags & BLF_WORD_WRAP) { - /* Use non-ASCII draw function for word-wrap. */ - blf_font_draw__wrap(font, str, str_len, r_info); - } - else { - blf_font_draw_ascii(font, str, str_len, r_info); - } - blf_draw_gl__end(font); - } -} - -void BLF_draw_ascii(int fontid, const char *str, const size_t str_len) -{ - if (str_len == 0 || str[0] == '\0') { - return; - } - - BLF_draw_ascii_ex(fontid, str, str_len, NULL); -} - int BLF_draw_mono(int fontid, const char *str, const size_t str_len, int cwidth) { if (str_len == 0 || str[0] == '\0') { diff --git a/source/blender/blenfont/intern/blf_default.c b/source/blender/blenfont/intern/blf_default.c index 1b458e8aaef..2bac0bf8904 100644 --- a/source/blender/blenfont/intern/blf_default.c +++ b/source/blender/blenfont/intern/blf_default.c @@ -77,14 +77,3 @@ void BLF_draw_default(float x, float y, float z, const char *str, const size_t s BLF_position(global_font_default, x, y, z); BLF_draw(global_font_default, str, str_len); } - -/* same as above but call 'BLF_draw_ascii' */ -void BLF_draw_default_ascii(float x, float y, float z, const char *str, const size_t str_len) -{ - ASSERT_DEFAULT_SET; - - const uiStyle *style = UI_style_get(); - BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi); - BLF_position(global_font_default, x, y, z); - BLF_draw_ascii(global_font_default, str, str_len); /* XXX, use real length */ -} diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 426008c9395..dbcd1d6016d 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -412,56 +412,6 @@ void blf_font_draw(FontBLF *font, const char *str, const size_t str_len, struct blf_glyph_cache_release(font); } -/* faster version of blf_font_draw, ascii only for view dimensions */ -static void blf_font_draw_ascii_ex( - FontBLF *font, const char *str, size_t str_len, struct ResultBLF *r_info, int pen_y) -{ - unsigned int c, c_prev = BLI_UTF8_ERR; - GlyphBLF *g, *g_prev = NULL; - int pen_x = 0; - - GlyphCacheBLF *gc = blf_glyph_cache_acquire(font); - - blf_batch_draw_begin(font); - - while ((c = *(str++)) && str_len--) { - BLI_assert(c < GLYPH_ASCII_TABLE_SIZE); - g = gc->glyph_ascii_table[c]; - if (UNLIKELY(g == NULL)) { - g = blf_glyph_add(font, gc, FT_Get_Char_Index((font)->face, c), c); - gc->glyph_ascii_table[c] = g; - if (UNLIKELY(g == NULL)) { - continue; - } - } - blf_kerning_step_fast(font, g_prev, g, c_prev, c, &pen_x); - - /* do not return this loop if clipped, we want every character tested */ - blf_glyph_render(font, gc, g, (float)pen_x, (float)pen_y); - - pen_x += g->advance_i; - g_prev = g; - c_prev = c; - } - - blf_batch_draw_end(); - - if (r_info) { - r_info->lines = 1; - r_info->width = pen_x; - } - - blf_glyph_cache_release(font); -} - -void blf_font_draw_ascii(FontBLF *font, - const char *str, - const size_t str_len, - struct ResultBLF *r_info) -{ - blf_font_draw_ascii_ex(font, str, str_len, r_info, 0); -} - /* use fixed column width, but an utf8 character may occupy multiple columns */ int blf_font_draw_mono(FontBLF *font, const char *str, const size_t str_len, int cwidth) { diff --git a/source/blender/draw/engines/overlay/overlay_edit_uv.c b/source/blender/draw/engines/overlay/overlay_edit_uv.c index c2b130163e8..985f8a6785c 100644 --- a/source/blender/draw/engines/overlay/overlay_edit_uv.c +++ b/source/blender/draw/engines/overlay/overlay_edit_uv.c @@ -333,14 +333,8 @@ void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata) BLI_snprintf(text, 5, "%d", tile->tile_number); float tile_location[3] = { ((tile->tile_number - 1001) % 10), ((tile->tile_number - 1001) / 10), 0.0f}; - DRW_text_cache_add(dt, - tile_location, - text, - strlen(text), - 10, - 10, - DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_ASCII, - color); + DRW_text_cache_add( + dt, tile_location, text, strlen(text), 10, 10, DRW_TEXT_CACHE_GLOBALSPACE, color); } } diff --git a/source/blender/draw/engines/overlay/overlay_motion_path.c b/source/blender/draw/engines/overlay/overlay_motion_path.c index e19d99dc597..1b7611e9620 100644 --- a/source/blender/draw/engines/overlay/overlay_motion_path.c +++ b/source/blender/draw/engines/overlay/overlay_motion_path.c @@ -130,7 +130,7 @@ static void motion_path_cache(OVERLAY_Data *vedata, OVERLAY_PrivateData *pd = vedata->stl->pd; const DRWContextState *draw_ctx = DRW_context_state_get(); struct DRWTextStore *dt = DRW_text_cache_ensure(); - int txt_flag = DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_ASCII; + int txt_flag = DRW_TEXT_CACHE_GLOBALSPACE; int cfra = (int)DEG_get_ctime(draw_ctx->depsgraph); bool selected = (pchan) ? (pchan->bone->flag & BONE_SELECTED) : (ob->base_flag & BASE_SELECTED); bool show_keyframes = (avs->path_viewflag & MOTIONPATH_VIEW_KFRAS) != 0; diff --git a/source/blender/draw/intern/draw_manager_profiling.c b/source/blender/draw/intern/draw_manager_profiling.c index 783ec1b1d7d..d9ba2cbf932 100644 --- a/source/blender/draw/intern/draw_manager_profiling.c +++ b/source/blender/draw/intern/draw_manager_profiling.c @@ -209,16 +209,16 @@ void DRW_stats_reset(void) static void draw_stat_5row(const rcti *rect, int u, int v, const char *txt, const int size) { - BLF_draw_default_ascii(rect->xmin + (1 + u * 5) * U.widget_unit, - rect->ymax - (3 + v) * U.widget_unit, - 0.0f, - txt, - size); + BLF_draw_default(rect->xmin + (1 + u * 5) * U.widget_unit, + rect->ymax - (3 + v) * U.widget_unit, + 0.0f, + txt, + size); } static void draw_stat(const rcti *rect, int u, int v, const char *txt, const int size) { - BLF_draw_default_ascii( + BLF_draw_default( rect->xmin + (1 + u) * U.widget_unit, rect->ymax - (3 + v) * U.widget_unit, 0.0f, txt, size); } diff --git a/source/blender/draw/intern/draw_manager_text.c b/source/blender/draw/intern/draw_manager_text.c index 265fdba66fd..cfaa22ba7c6 100644 --- a/source/blender/draw/intern/draw_manager_text.c +++ b/source/blender/draw/intern/draw_manager_text.c @@ -152,11 +152,9 @@ static void drw_text_cache_draw_ex(DRWTextStore *dt, ARegion *region) BLF_position( font_id, (float)(vos->sco[0] + vos->xoffs), (float)(vos->sco[1] + vos->yoffs), 2.0f); - - ((vos->flag & DRW_TEXT_CACHE_ASCII) ? BLF_draw_ascii : BLF_draw)( - font_id, - (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str, - vos->str_len); + BLF_draw(font_id, + (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str, + vos->str_len); } } @@ -235,7 +233,7 @@ void DRW_text_edit_mesh_measure_stats(ARegion *region, * etc.). See bug T36090. */ struct DRWTextStore *dt = DRW_text_cache_ensure(); - const short txt_flag = DRW_TEXT_CACHE_GLOBALSPACE | (unit->system ? 0 : DRW_TEXT_CACHE_ASCII); + const short txt_flag = DRW_TEXT_CACHE_GLOBALSPACE; Mesh *me = ob->data; BMEditMesh *em = me->edit_mesh; float v1[3], v2[3], v3[3], vmid[3], fvec[3]; diff --git a/source/blender/draw/intern/draw_manager_text.h b/source/blender/draw/intern/draw_manager_text.h index f6dff335f1f..760259018bb 100644 --- a/source/blender/draw/intern/draw_manager_text.h +++ b/source/blender/draw/intern/draw_manager_text.h @@ -48,7 +48,7 @@ void DRW_text_edit_mesh_measure_stats(struct ARegion *region, const struct UnitSettings *unit); enum { - DRW_TEXT_CACHE_ASCII = (1 << 0), + // DRW_UNUSED_1 = (1 << 0), /* dirty */ DRW_TEXT_CACHE_GLOBALSPACE = (1 << 1), DRW_TEXT_CACHE_LOCALCLIP = (1 << 2), /* reference the string by pointer */ diff --git a/source/blender/editors/interface/view2d_draw.c b/source/blender/editors/interface/view2d_draw.c index 95427e49495..fd4dba30c1c 100644 --- a/source/blender/editors/interface/view2d_draw.c +++ b/source/blender/editors/interface/view2d_draw.c @@ -349,7 +349,7 @@ static void draw_horizontal_scale_indicators(const ARegion *region, const float text_width = BLF_width(font_id, text, strlen(text)); if (xpos_region - text_width / 2.0f >= xmin && xpos_region + text_width / 2.0f <= xmax) { - BLF_draw_default_ascii(xpos_region - text_width / 2.0f, ypos, 0.0f, text, sizeof(text)); + BLF_draw_default(xpos_region - text_width / 2.0f, ypos, 0.0f, text, sizeof(text)); } } } @@ -411,7 +411,7 @@ static void draw_vertical_scale_indicators(const ARegion *region, const float text_width = BLF_width(font_id, text, strlen(text)); if (ypos_region - text_width / 2.0f >= ymin && ypos_region + text_width / 2.0f <= ymax) { - BLF_draw_default_ascii(xpos, ypos_region - text_width / 2.0f, 0.0f, text, sizeof(text)); + BLF_draw_default(xpos, ypos_region - text_width / 2.0f, 0.0f, text, sizeof(text)); } } diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 92ceb00d5c0..4f66506d28b 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -196,21 +196,21 @@ void ED_image_draw_info(Scene *scene, BLF_color3ub(blf_mono_font, 255, 255, 255); SNPRINTF(str, "X:%-4d Y:%-4d |", x, y); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); if (zp) { BLF_color3ub(blf_mono_font, 255, 255, 255); SNPRINTF(str, " Z:%-.4f |", 0.5f + 0.5f * (((float)*zp) / (float)0x7fffffff)); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); } if (zpf) { BLF_color3ub(blf_mono_font, 255, 255, 255); SNPRINTF(str, " Z:%-.3f |", *zpf); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); } @@ -223,7 +223,7 @@ void ED_image_draw_info(Scene *scene, } BLF_color3ub(blf_mono_font, 255, 255, 255); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); } @@ -239,7 +239,7 @@ void ED_image_draw_info(Scene *scene, STRNCPY(str, " R:-"); } BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); BLF_color3ubv(blf_mono_font, green); @@ -253,7 +253,7 @@ void ED_image_draw_info(Scene *scene, STRNCPY(str, " G:-"); } BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); BLF_color3ubv(blf_mono_font, blue); @@ -267,7 +267,7 @@ void ED_image_draw_info(Scene *scene, STRNCPY(str, " B:-"); } BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); if (channels == 4) { @@ -282,7 +282,7 @@ void ED_image_draw_info(Scene *scene, STRNCPY(str, "- "); } BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); } @@ -307,7 +307,7 @@ void ED_image_draw_info(Scene *scene, SNPRINTF(str, " | CM R:%-.4f G:%-.4f B:%-.4f", rgba[0], rgba[1], rgba[2]); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); } } @@ -429,12 +429,12 @@ void ED_image_draw_info(Scene *scene, SNPRINTF(str, "V:%-.4f", val); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); SNPRINTF(str, " L:%-.4f", lum); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); } else if (channels >= 3) { rgb_to_hsv(finalcol[0], finalcol[1], finalcol[2], &hue, &sat, &val); @@ -442,22 +442,22 @@ void ED_image_draw_info(Scene *scene, SNPRINTF(str, "H:%-.4f", hue); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); SNPRINTF(str, " S:%-.4f", sat); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); SNPRINTF(str, " V:%-.4f", val); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); SNPRINTF(str, " L:%-.4f", lum); BLF_position(blf_mono_font, dx, dy, 0); - BLF_draw_ascii(blf_mono_font, str, sizeof(str)); + BLF_draw(blf_mono_font, str, sizeof(str)); } } void draw_image_sample_line(SpaceImage *sima) diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index ec99affe43b..86f79718a68 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1020,7 +1020,7 @@ static void draw_view_axis(RegionView3D *rv3d, const rcti *rect) const char axis_text[2] = {'x' + i, '\0'}; BLF_color4ubv(BLF_default(), axis_col[i]); - BLF_draw_default_ascii(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1); + BLF_draw_default(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1); } } @@ -1458,9 +1458,7 @@ static void draw_grid_unit_name( BLF_enable(font_id, BLF_SHADOW); BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f}); BLF_shadow_offset(font_id, 1, -1); - BLF_draw_default_ascii( - xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr)); - + BLF_draw_default(xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr)); BLF_disable(font_id, BLF_SHADOW); } } @@ -2548,11 +2546,7 @@ void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset) *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; -#ifdef WITH_INTERNATIONAL BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); -#else - BLF_draw_default_ascii(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); -#endif BLF_disable(font_id, BLF_SHADOW); } diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c index 05ea35f114f..baa54adaa83 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c @@ -300,7 +300,7 @@ static void gizmo_axis_draw(const bContext *C, wmGizmo *gz) text_color[3] = is_active ? 1.0f : 0.9f; } BLF_color4fv(font.id, text_color); - BLF_draw_ascii(font.id, axis_str, 2); + BLF_draw(font.id, axis_str, 2); GPU_matrix_pop(); } } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 7a83fb71c28..7287927a0be 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1372,11 +1372,7 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *region) uchar color[3]; UI_GetThemeColorShade3ubv(TH_TEXT_HI, -50, color); BLF_color3ubv(font_id, color); -#ifdef WITH_INTERNATIONAL BLF_draw_default(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX); -#else - BLF_draw_default_ascii(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX); -#endif /* autokey recording icon... */ GPU_blend(GPU_BLEND_ALPHA); diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index cbc2adf641f..9638ec8750e 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -710,7 +710,8 @@ void Transform_Properties(struct wmOperatorType *ot, int flags) } if (flags & P_VIEW2D_EDGE_PAN) { - prop = RNA_def_boolean(ot->srna, "view2d_edge_pan", false, "Edge Pan", "Enable edge panning in 2D view"); + prop = RNA_def_boolean( + ot->srna, "view2d_edge_pan", false, "Edge Pan", "Enable edge panning in 2D view"); RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } -- cgit v1.2.3 From 70fbdcb6bf5107101e5cbde3b54138f0cc8a2668 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 25 Aug 2021 18:03:24 -0500 Subject: Cleanup: Refactor proximity node to be more data type agnostic Before, distances from each component were handled in the same loop, making it more complicated to add support for more component types in the future (and probably hurting performance by dealing with two BVH trees at the same time, though I didn't test that). Now each component is handled in a separate function, so that adding support for another component type is much simpler. --- .../geometry/nodes/node_geo_attribute_proximity.cc | 219 ++++++++++----------- 1 file changed, 103 insertions(+), 116 deletions(-) diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc index e94267cc936..bfcde288cfb 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc @@ -14,8 +14,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "BLI_kdopbvh.h" -#include "BLI_kdtree.h" #include "BLI_task.hh" #include "BLI_timeit.hh" @@ -59,160 +57,149 @@ static void geo_attribute_proximity_init(bNodeTree *UNUSED(ntree), bNode *node) namespace blender::nodes { -static void proximity_calc(MutableSpan distance_span, - MutableSpan location_span, - const VArray &positions, - BVHTreeFromMesh *tree_data_mesh, - BVHTreeFromPointCloud *tree_data_pointcloud) +static void calculate_mesh_proximity(const VArray &positions, + const Mesh &mesh, + const GeometryNodeAttributeProximityTargetType type, + MutableSpan r_distances, + MutableSpan r_locations) { - threading::parallel_for(positions.index_range(), 512, [&](IndexRange range) { - BVHTreeNearest nearest_from_mesh; - BVHTreeNearest nearest_from_pointcloud; + BVHTreeFromMesh bvh_data; + switch (type) { + case GEO_NODE_PROXIMITY_TARGET_POINTS: + BKE_bvhtree_from_mesh_get(&bvh_data, &mesh, BVHTREE_FROM_VERTS, 2); + break; + case GEO_NODE_PROXIMITY_TARGET_EDGES: + BKE_bvhtree_from_mesh_get(&bvh_data, &mesh, BVHTREE_FROM_EDGES, 2); + break; + case GEO_NODE_PROXIMITY_TARGET_FACES: + BKE_bvhtree_from_mesh_get(&bvh_data, &mesh, BVHTREE_FROM_LOOPTRI, 2); + break; + } - copy_v3_fl(nearest_from_mesh.co, FLT_MAX); - copy_v3_fl(nearest_from_pointcloud.co, FLT_MAX); + if (bvh_data.tree == nullptr) { + return; + } - nearest_from_mesh.index = -1; - nearest_from_pointcloud.index = -1; + threading::parallel_for(positions.index_range(), 512, [&](IndexRange range) { + BVHTreeNearest nearest; + copy_v3_fl(nearest.co, FLT_MAX); + nearest.index = -1; for (int i : range) { /* Use the distance to the last found point as upper bound to speedup the bvh lookup. */ - nearest_from_mesh.dist_sq = len_squared_v3v3(nearest_from_mesh.co, positions[i]); - - if (tree_data_mesh != nullptr) { - BLI_bvhtree_find_nearest(tree_data_mesh->tree, - positions[i], - &nearest_from_mesh, - tree_data_mesh->nearest_callback, - tree_data_mesh); - } + nearest.dist_sq = float3::distance_squared(nearest.co, positions[i]); - /* Use the distance to the closest point in the mesh to speedup the pointcloud bvh lookup. - * This is ok because we only need to find the closest point in the pointcloud if it's closer - * than the mesh. */ - nearest_from_pointcloud.dist_sq = nearest_from_mesh.dist_sq; - - if (tree_data_pointcloud != nullptr) { - BLI_bvhtree_find_nearest(tree_data_pointcloud->tree, - positions[i], - &nearest_from_pointcloud, - tree_data_pointcloud->nearest_callback, - tree_data_pointcloud); - } + BLI_bvhtree_find_nearest( + bvh_data.tree, positions[i], &nearest, bvh_data.nearest_callback, &bvh_data); - if (nearest_from_pointcloud.dist_sq < nearest_from_mesh.dist_sq) { - if (!distance_span.is_empty()) { - distance_span[i] = sqrtf(nearest_from_pointcloud.dist_sq); - } - if (!location_span.is_empty()) { - location_span[i] = nearest_from_pointcloud.co; - } - } - else { - if (!distance_span.is_empty()) { - distance_span[i] = sqrtf(nearest_from_mesh.dist_sq); - } - if (!location_span.is_empty()) { - location_span[i] = nearest_from_mesh.co; + if (nearest.dist_sq < r_distances[i]) { + r_distances[i] = nearest.dist_sq; + if (!r_locations.is_empty()) { + r_locations[i] = nearest.co; } } } }); + + free_bvhtree_from_mesh(&bvh_data); } -static bool bvh_from_mesh(const Mesh *target_mesh, - int target_geometry_element, - BVHTreeFromMesh &r_tree_data_mesh) +static void calculate_pointcloud_proximity(const VArray &positions, + const PointCloud &pointcloud, + MutableSpan r_distances, + MutableSpan r_locations) { - BVHCacheType bvh_type = BVHTREE_FROM_LOOPTRI; - switch (target_geometry_element) { - case GEO_NODE_PROXIMITY_TARGET_POINTS: - bvh_type = BVHTREE_FROM_VERTS; - break; - case GEO_NODE_PROXIMITY_TARGET_EDGES: - bvh_type = BVHTREE_FROM_EDGES; - break; - case GEO_NODE_PROXIMITY_TARGET_FACES: - bvh_type = BVHTREE_FROM_LOOPTRI; - break; + BVHTreeFromPointCloud bvh_data; + BKE_bvhtree_from_pointcloud_get(&bvh_data, &pointcloud, 2); + if (bvh_data.tree == nullptr) { + return; } - BKE_bvhtree_from_mesh_get(&r_tree_data_mesh, target_mesh, bvh_type, 2); - if (r_tree_data_mesh.tree == nullptr) { - return false; - } - return true; -} + threading::parallel_for(positions.index_range(), 512, [&](IndexRange range) { + BVHTreeNearest nearest; + copy_v3_fl(nearest.co, FLT_MAX); + nearest.index = -1; -static bool bvh_from_pointcloud(const PointCloud *target_pointcloud, - BVHTreeFromPointCloud &r_tree_data_pointcloud) -{ - BKE_bvhtree_from_pointcloud_get(&r_tree_data_pointcloud, target_pointcloud, 2); - if (r_tree_data_pointcloud.tree == nullptr) { - return false; - } - return true; + for (int i : range) { + /* Use the distance to the closest point in the mesh to speedup the pointcloud bvh lookup. + * This is ok because we only need to find the closest point in the pointcloud if it's + * closer than the mesh. */ + nearest.dist_sq = r_distances[i]; + + BLI_bvhtree_find_nearest( + bvh_data.tree, positions[i], &nearest, bvh_data.nearest_callback, &bvh_data); + + if (nearest.dist_sq < r_distances[i]) { + r_distances[i] = nearest.dist_sq; + if (!r_locations.is_empty()) { + r_locations[i] = nearest.co; + } + } + } + }); + + free_bvhtree_from_pointcloud(&bvh_data); } static void attribute_calc_proximity(GeometryComponent &component, - GeometrySet &geometry_set_target, + GeometrySet &target, GeoNodeExecParams ¶ms) { - /* This node works on the "point" domain, since that is where positions are stored. */ - const AttributeDomain result_domain = ATTR_DOMAIN_POINT; - - const std::string distance_attribute_name = params.get_input("Distance"); + const std::string distance_name = params.get_input("Distance"); OutputAttribute_Typed distance_attribute = - component.attribute_try_get_for_output_only(distance_attribute_name, result_domain); + component.attribute_try_get_for_output_only(distance_name, ATTR_DOMAIN_POINT); - const std::string location_attribute_name = params.get_input("Position"); + const std::string location_name = params.get_input("Position"); OutputAttribute_Typed location_attribute = - component.attribute_try_get_for_output_only(location_attribute_name, result_domain); + component.attribute_try_get_for_output_only(location_name, ATTR_DOMAIN_POINT); ReadAttributeLookup position_attribute = component.attribute_try_get_for_read("position"); if (!position_attribute || (!distance_attribute && !location_attribute)) { return; } - BLI_assert(position_attribute.varray->type().is()); - + GVArray_Typed positions{*position_attribute.varray}; const NodeGeometryAttributeProximity &storage = *(const NodeGeometryAttributeProximity *)params.node().storage; - bool bvh_mesh_success = false; - BVHTreeFromMesh tree_data_mesh; - if (geometry_set_target.has_mesh()) { - bvh_mesh_success = bvh_from_mesh( - geometry_set_target.get_mesh_for_read(), storage.target_geometry_element, tree_data_mesh); + Array distances_internal; + MutableSpan distances; + if (distance_attribute) { + distances = distance_attribute.as_span(); } - - bool bvh_pointcloud_success = false; - BVHTreeFromPointCloud tree_data_pointcloud; - if (geometry_set_target.has_pointcloud() && - storage.target_geometry_element == GEO_NODE_PROXIMITY_TARGET_POINTS) { - bvh_pointcloud_success = bvh_from_pointcloud(geometry_set_target.get_pointcloud_for_read(), - tree_data_pointcloud); + else { + /* Theoretically it would be possible to avoid using the distance array when it's not required + * and there is only one component. However, this only adds an allocation and a single float + * comparison per vertex, so it's likely not worth it. */ + distances_internal.reinitialize(positions.size()); + distances = distances_internal; } - - GVArray_Typed positions{*position_attribute.varray}; - MutableSpan distance_span = distance_attribute ? distance_attribute.as_span() : - MutableSpan(); - MutableSpan location_span = location_attribute ? location_attribute.as_span() : - MutableSpan(); - - proximity_calc(distance_span, - location_span, - positions, - bvh_mesh_success ? &tree_data_mesh : nullptr, - bvh_pointcloud_success ? &tree_data_pointcloud : nullptr); - - if (bvh_mesh_success) { - free_bvhtree_from_mesh(&tree_data_mesh); + distances.fill(FLT_MAX); + MutableSpan locations = location_attribute ? location_attribute.as_span() : + MutableSpan(); + + if (target.has_mesh()) { + calculate_mesh_proximity( + positions, + *target.get_mesh_for_read(), + static_cast(storage.target_geometry_element), + distances, + locations); } - if (bvh_pointcloud_success) { - free_bvhtree_from_pointcloud(&tree_data_pointcloud); + + if (target.has_pointcloud() && + storage.target_geometry_element == GEO_NODE_PROXIMITY_TARGET_POINTS) { + calculate_pointcloud_proximity( + positions, *target.get_pointcloud_for_read(), distances, locations); } if (distance_attribute) { + /* Squared distances are used above to speed up comparisons, + * so do the square roots now if necessary for the output attribute. */ + threading::parallel_for(distances.index_range(), 2048, [&](IndexRange range) { + for (const int i : range) { + distances[i] = std::sqrt(distances[i]); + } + }); distance_attribute.save(); } if (location_attribute) { -- cgit v1.2.3 From e5a5a251d2dcb1915c3dd37bc22d10868c04a2a6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 11:37:22 +1000 Subject: Fix T90915: outliner select behaves as if Ctrl is held Error in 452cc0193255c9e80ca4f163a2d524ed6bb17ef1 --- source/blender/editors/space_outliner/outliner_select.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index 898e66e7a39..1feecc04ead 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -1682,7 +1682,7 @@ void OUTLINER_OT_item_activate(wmOperatorType *ot) ot->flag |= OPTYPE_REGISTER | OPTYPE_UNDO; PropertyRNA *prop; - prop = RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend selection for activation"); + prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection for activation"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); prop = RNA_def_boolean( ot->srna, "extend_range", false, "Extend Range", "Select a range from active element"); -- cgit v1.2.3 From ff85ac300983bb1f887c071f58b47092682e165c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 12:27:13 +1000 Subject: Cleanup: clang-format --- source/blender/draw/engines/overlay/overlay_extra.c | 7 ++----- source/blender/editors/interface/view2d_edge_pan.c | 6 ++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c index 04d90919a20..8f9db7f6f13 100644 --- a/source/blender/draw/engines/overlay/overlay_extra.c +++ b/source/blender/draw/engines/overlay/overlay_extra.c @@ -861,11 +861,8 @@ typedef union OVERLAY_CameraInstanceData { }; } OVERLAY_CameraInstanceData; -static void camera_view3d_reconstruction(OVERLAY_ExtraCallBuffers *cb, - Scene *scene, - View3D *v3d, - Object *ob, - const float color[4]) +static void camera_view3d_reconstruction( + OVERLAY_ExtraCallBuffers *cb, Scene *scene, View3D *v3d, Object *ob, const float color[4]) { const DRWContextState *draw_ctx = DRW_context_state_get(); const bool is_select = DRW_state_is_select(); diff --git a/source/blender/editors/interface/view2d_edge_pan.c b/source/blender/editors/interface/view2d_edge_pan.c index eaf8ef30311..54e0d8f40ea 100644 --- a/source/blender/editors/interface/view2d_edge_pan.c +++ b/source/blender/editors/interface/view2d_edge_pan.c @@ -176,10 +176,12 @@ static float edge_pan_speed(View2DEdgePanData *vpd, 1.0f; /* Zoom factor increases speed when zooming in and decreases speed when zooming out. */ - const float zoomx = (float)(BLI_rcti_size_x(®ion->winrct) + 1) / BLI_rctf_size_x(®ion->v2d.cur); + const float zoomx = (float)(BLI_rcti_size_x(®ion->winrct) + 1) / + BLI_rctf_size_x(®ion->v2d.cur); const float zoom_factor = 1.0f + CLAMPIS(vpd->zoom_influence, 0.0f, 1.0f) * (zoomx - 1.0f); - return distance_factor * delay_factor * zoom_factor * vpd->max_speed * U.widget_unit * (float)U.dpi_fac; + return distance_factor * delay_factor * zoom_factor * vpd->max_speed * U.widget_unit * + (float)U.dpi_fac; } static void edge_pan_apply_delta(bContext *C, View2DEdgePanData *vpd, float dx, float dy) -- cgit v1.2.3 From afcd06e1e11b1166deb55b0ce05b777706369028 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 12:27:14 +1000 Subject: Cleanup: spelling in comments --- intern/cycles/kernel/closure/bsdf_microfacet.h | 2 +- intern/ghost/intern/GHOST_SystemCocoa.mm | 2 +- intern/ghost/intern/GHOST_SystemX11.cpp | 2 +- source/blender/blenfont/intern/blf_dir.c | 4 ++-- source/blender/draw/engines/image/image_engine.c | 2 +- source/blender/editors/render/render_opengl.c | 2 +- source/blender/editors/transform/transform.c | 2 +- source/blender/gpu/GPU_capabilities.h | 2 +- source/blender/modifiers/intern/MOD_collision.c | 4 ++-- source/blender/sequencer/intern/iterator.c | 9 ++++----- source/blender/sequencer/intern/sequencer.c | 4 ++-- 11 files changed, 17 insertions(+), 18 deletions(-) diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h index aed4b849aca..af03bab39f7 100644 --- a/intern/cycles/kernel/closure/bsdf_microfacet.h +++ b/intern/cycles/kernel/closure/bsdf_microfacet.h @@ -1050,7 +1050,7 @@ ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals *kg, float D, G1i; if (alpha_x == alpha_y) { - /* istropic distribution */ + /* Isotropic distribution. */ float cosThetaM2 = cosThetaM * cosThetaM; float cosThetaM4 = cosThetaM2 * cosThetaM2; float tanThetaM2 = 1 / (cosThetaM2)-1; diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 933e0c70cc8..189e663f91a 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -424,7 +424,7 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) { /* TODO: implement graceful termination through Cocoa mechanism * to avoid session log off to be canceled. */ - /* Note that Cmd+Q is already handled by keyhandler. */ + /* Note that Cmd+Q is already handled by key-handler. */ systemCocoa->handleQuitRequest(); return NSTerminateCancel; } diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index 9422d15692d..10ccb00cc15 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -1922,7 +1922,7 @@ static GHOST_TKey ghost_key_from_keycode(const XkbDescPtr xkb_descr, const KeyCo #undef MAKE_ID -/* from xclip.c xcout() v0.11 */ +/* From `xclip.c` #xcout() v0.11. */ #define XCLIB_XCOUT_NONE 0 /* no context */ #define XCLIB_XCOUT_SENTCONVSEL 1 /* sent a request */ diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index 9520e971148..55c02b34f3d 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -172,12 +172,12 @@ char *blf_dir_metrics_search(const char *filename) s[1] = 'f'; s[2] = 'm'; - /* first check .afm */ + /* First check `.afm`. */ if (BLI_exists(mfile)) { return mfile; } - /* and now check .pfm */ + /* And now check `.pfm`. */ s[0] = 'p'; if (BLI_exists(mfile)) { diff --git a/source/blender/draw/engines/image/image_engine.c b/source/blender/draw/engines/image/image_engine.c index b4c0ade380e..662238df270 100644 --- a/source/blender/draw/engines/image/image_engine.c +++ b/source/blender/draw/engines/image/image_engine.c @@ -120,7 +120,7 @@ static void space_image_gpu_texture_get(Image *image, } if (ibuf->rect == NULL && ibuf->rect_float == NULL) { - /* This codepath is only supposed to happen when drawing a lazily-allocatable render result. + /* This code-path is only supposed to happen when drawing a lazily-allocatable render result. * In all the other cases the `ED_space_image_acquire_buffer()` is expected to return NULL as * an image buffer when it has no pixels. */ diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 749010a5ba3..834c023dde9 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -697,7 +697,7 @@ static void gather_frames_to_render(bContext *C, OGLRender *oglrender) AnimData *adt = BKE_animdata_from_id(id); gather_frames_to_render_for_adt(oglrender, adt); - /* Gather the frames from linked datablocks (materials, shapkeys, etc.). */ + /* Gather the frames from linked data-blocks (materials, shape-keys, etc.). */ BKE_library_foreach_ID_link( NULL, id, gather_frames_to_render_for_id, oglrender, IDWALK_RECURSE); } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 7287927a0be..58491f8c2d3 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1400,7 +1400,7 @@ static void drawTransformPixel(const struct bContext *C, ARegion *region, void * /* draw auto-key-framing hint in the corner * - only draw if enabled (advanced users may be distracted/annoyed), - * for objects that will be autokeyframed (no point otherwise), + * for objects that will be auto-keyframed (no point otherwise), * AND only for the active region (as showing all is too overwhelming) */ if ((U.autokey_flag & AUTOKEY_FLAG_NOWARNING) == 0) { diff --git a/source/blender/gpu/GPU_capabilities.h b/source/blender/gpu/GPU_capabilities.h index 0c054d4f264..5b5d0f16c9f 100644 --- a/source/blender/gpu/GPU_capabilities.h +++ b/source/blender/gpu/GPU_capabilities.h @@ -22,7 +22,7 @@ * * GPU Capabilities & workarounds * This module expose the reported implementation limits & enabled - * workaround for drivers that needs specific codepaths. + * workaround for drivers that needs specific code-paths. */ #pragma once diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index e7d5fe056c5..d94e9a988c6 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -277,8 +277,8 @@ static void blendRead(BlendDataReader *UNUSED(reader), ModifierData *md) { CollisionModifierData *collmd = (CollisionModifierData *)md; #if 0 - // TODO: CollisionModifier should use pointcache - // + have proper reset events before enabling this + /* TODO: #CollisionModifier should use point-cache + * + have proper reset events before enabling this. */ collmd->x = newdataadr(fd, collmd->x); collmd->xnew = newdataadr(fd, collmd->xnew); collmd->mfaces = newdataadr(fd, collmd->mfaces); diff --git a/source/blender/sequencer/intern/iterator.c b/source/blender/sequencer/intern/iterator.c index 2ac93ccc9d3..a9cbf4879f1 100644 --- a/source/blender/sequencer/intern/iterator.c +++ b/source/blender/sequencer/intern/iterator.c @@ -107,14 +107,13 @@ static bool seq_for_each_recursive(ListBase *seqbase, SeqForEachFunc callback, v } /** - * Utility function to recursivily iterate through all sequence strips in a seqbase list. + * Utility function to recursively iterate through all sequence strips in a `seqbase` list. * Uses callback to do operations on each sequence element. * The callback can stop the iteration if needed. * - * \param seqbase: ListBase of sequences to be iterated over - * \param callback: query function callback, returns false if iteration should stop - * \param user_data: pointer to user data that can be used in the callback function - * + * \param seqbase: #ListBase of sequences to be iterated over. + * \param callback: query function callback, returns false if iteration should stop. + * \param user_data: pointer to user data that can be used in the callback function. */ void SEQ_for_each_callback(ListBase *seqbase, SeqForEachFunc callback, void *user_data) { diff --git a/source/blender/sequencer/intern/sequencer.c b/source/blender/sequencer/intern/sequencer.c index 49d08d0e022..2863af8fb2e 100644 --- a/source/blender/sequencer/intern/sequencer.c +++ b/source/blender/sequencer/intern/sequencer.c @@ -755,9 +755,9 @@ static bool seq_write_data_cb(Sequence *seq, void *userdata) BlendWriter *writer = (BlendWriter *)userdata; BLO_write_struct(writer, Sequence, seq); if (seq->strip && seq->strip->done == 0) { - /* write strip with 'done' at 0 because readfile */ + /* Write strip with 'done' at 0 because read-file. */ - // TODO this doesn't depend on the `Strip` data to be present? + /* TODO this doesn't depend on the `Strip` data to be present? */ if (seq->effectdata) { switch (seq->type) { case SEQ_TYPE_COLOR: -- cgit v1.2.3 From 42032db1c220e2a10d2d80879ec0037b4e12257e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 12:27:16 +1000 Subject: Cleanup: remove deprecated flag use in collada --- source/blender/io/collada/AnimationImporter.cpp | 4 ++-- source/blender/io/collada/BCAnimationCurve.cpp | 2 +- source/blender/makesdna/DNA_anim_types.h | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/blender/io/collada/AnimationImporter.cpp b/source/blender/io/collada/AnimationImporter.cpp index e54192abc54..5b6391c1b9c 100644 --- a/source/blender/io/collada/AnimationImporter.cpp +++ b/source/blender/io/collada/AnimationImporter.cpp @@ -58,7 +58,7 @@ template static const char *bc_get_joint_name(T *node) FCurve *AnimationImporter::create_fcurve(int array_index, const char *rna_path) { FCurve *fcu = BKE_fcurve_create(); - fcu->flag = (FCURVE_VISIBLE | FCURVE_AUTO_HANDLES | FCURVE_SELECTED); + fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED); fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path)); fcu->array_index = array_index; return fcu; @@ -102,7 +102,7 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve) for (i = 0; i < dim; i++) { FCurve *fcu = BKE_fcurve_create(); - fcu->flag = (FCURVE_VISIBLE | FCURVE_AUTO_HANDLES | FCURVE_SELECTED); + fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED); fcu->array_index = 0; fcu->auto_smoothing = U.auto_smoothing_new; diff --git a/source/blender/io/collada/BCAnimationCurve.cpp b/source/blender/io/collada/BCAnimationCurve.cpp index 0e31e522ec4..82d8b6e9ff3 100644 --- a/source/blender/io/collada/BCAnimationCurve.cpp +++ b/source/blender/io/collada/BCAnimationCurve.cpp @@ -95,7 +95,7 @@ void BCAnimationCurve::delete_fcurve(FCurve *fcu) FCurve *BCAnimationCurve::create_fcurve(int array_index, const char *rna_path) { FCurve *fcu = BKE_fcurve_create(); - fcu->flag = (FCURVE_VISIBLE | FCURVE_AUTO_HANDLES | FCURVE_SELECTED); + fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED); fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path)); fcu->array_index = array_index; return fcu; diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index a49a76c3f26..5dbed6b4d24 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -658,9 +658,10 @@ typedef enum eFCurve_Flags { /** FCurve will not be evaluated for the next round. */ FCURVE_MUTED = (1 << 4), +#ifdef DNA_DEPRECATED_ALLOW /** fcurve uses 'auto-handles', which stay horizontal... */ - // DEPRECATED - FCURVE_AUTO_HANDLES = (1 << 5), + FCURVE_AUTO_HANDLES = (1 << 5), /* Dirty. */ +#endif FCURVE_MOD_OFF = (1 << 6), /** skip evaluation, as RNA-path cannot be resolved * (similar to muting, but cannot be set by user) */ -- cgit v1.2.3 From 84f048fda566c2098ec1baa2ff1ad6c00b7395d5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 12:27:17 +1000 Subject: Cleanup: use C style comments for descriptive text --- source/blender/blenkernel/BKE_sound.h | 3 +- source/blender/blenkernel/intern/displist.cc | 4 +- source/blender/blenkernel/intern/fluid.c | 10 ++-- source/blender/blenkernel/intern/gpencil_curve.c | 4 +- source/blender/blenkernel/intern/nla.c | 4 +- source/blender/blenkernel/intern/particle_system.c | 8 +-- source/blender/blentranslation/msgfmt/msgfmt.c | 2 +- .../compositor/intern/COM_ExecutionGroup.cc | 2 +- source/blender/compositor/intern/COM_WorkPackage.h | 2 +- .../blender/compositor/nodes/COM_BokehBlurNode.cc | 5 +- .../blender/compositor/nodes/COM_ColorSpillNode.cc | 4 +- .../compositor/nodes/COM_Stabilize2dNode.cc | 4 +- .../operations/COM_ColorCurveOperation.cc | 2 +- .../operations/COM_ColorSpillOperation.cc | 2 +- .../operations/COM_CompositorOperation.cc | 6 +- .../operations/COM_DilateErodeOperation.cc | 2 +- .../operations/COM_GlareFogGlowOperation.cc | 68 +++++++++++----------- .../compositor/operations/COM_InpaintOperation.cc | 2 +- .../compositor/operations/COM_ScaleOperation.cc | 2 +- .../compositor/operations/COM_SplitOperation.cc | 2 +- .../operations/COM_VectorBlurOperation.cc | 4 +- .../compositor/operations/COM_ViewerOperation.cc | 2 +- .../operations/COM_WriteBufferOperation.cc | 8 +-- source/blender/depsgraph/DEG_depsgraph.h | 2 +- .../builder/deg_builder_relations_drivers.cc | 44 +++++++------- .../intern/builder/deg_builder_relations_keys.cc | 2 +- .../depsgraph/intern/debug/deg_time_average.h | 11 ++-- .../depsgraph/intern/depsgraph_query_iter.cc | 16 +++-- .../blender/depsgraph/intern/depsgraph_registry.cc | 2 +- .../depsgraph/intern/node/deg_node_component.cc | 2 +- .../editors/mesh/editmesh_extrude_spin_gizmo.c | 2 +- source/blender/editors/space_graph/graph_view.c | 2 +- source/blender/imbuf/intern/iris.c | 6 +- source/blender/io/alembic/tests/abc_matrix_test.cc | 2 +- source/blender/makesdna/DNA_action_types.h | 4 +- source/blender/makesdna/DNA_armature_types.h | 5 +- source/blender/makesdna/DNA_constraint_types.h | 2 +- 37 files changed, 124 insertions(+), 130 deletions(-) diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 4b257b3b8ab..fa58813c5f8 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -61,8 +61,7 @@ struct bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, bool *r_exists); struct bSound *BKE_sound_new_file_exists(struct Main *bmain, const char *filepath); -// XXX unused currently -#if 0 +#if 0 /* UNUSED */ struct bSound *BKE_sound_new_buffer(struct Main *bmain, struct bSound *source); struct bSound *BKE_sound_new_limiter(struct Main *bmain, diff --git a/source/blender/blenkernel/intern/displist.cc b/source/blender/blenkernel/intern/displist.cc index c97e07ad487..58509e95de6 100644 --- a/source/blender/blenkernel/intern/displist.cc +++ b/source/blender/blenkernel/intern/displist.cc @@ -56,7 +56,7 @@ #include "BKE_modifier.h" #include "BKE_object.h" -#include "BLI_sys_types.h" // for intptr_t support +#include "BLI_sys_types.h" /* For #intptr_t support. */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" @@ -655,7 +655,7 @@ static float displist_calc_taper(Depsgraph *depsgraph, return fp[1]; } } - return fp[-2]; // last y coord + return fp[-2]; /* Last y coordinate. */ } } diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index 799d6553682..87c1f99fd73 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -557,7 +557,7 @@ static bool BKE_fluid_modifier_init( return false; } -// forward declaration +/* Forward declarations. */ static void manta_smoke_calc_transparency(FluidDomainSettings *fds, ViewLayer *view_layer); static float calc_voxel_transp( float *result, const float *input, int res[3], int *pixel, float *t_ray, float correct); @@ -4380,10 +4380,10 @@ static void manta_smoke_calc_transparency(FluidDomainSettings *fds, ViewLayer *v light[2] = (light[2] - fds->p0[2]) / fds->cell_size[2] - 0.5f - (float)fds->res_min[2]; /* Calculate domain bounds in sim cell space. */ - // 0,2,4 = 0.0f - bv[1] = (float)fds->res[0]; // x - bv[3] = (float)fds->res[1]; // y - bv[5] = (float)fds->res[2]; // z + /* 0,2,4 = 0.0f */ + bv[1] = (float)fds->res[0]; /* X */ + bv[3] = (float)fds->res[1]; /* Y */ + bv[5] = (float)fds->res[2]; /* Z */ for (int z = 0; z < fds->res[2]; z++) { size_t index = z * slabsize; diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c index 344be7bc0f5..0752424df71 100644 --- a/source/blender/blenkernel/intern/gpencil_curve.c +++ b/source/blender/blenkernel/intern/gpencil_curve.c @@ -883,7 +883,7 @@ static void gpencil_interpolate_fl_from_to( float *r = point_offset; for (int i = 0; i <= it; i++) { float fac = (float)i / (float)it; - fac = 3.0f * fac * fac - 2.0f * fac * fac * fac; // smooth + fac = 3.0f * fac * fac - 2.0f * fac * fac * fac; /* Smooth. */ *r = interpf(to, from, fac); r = POINTER_OFFSET(r, stride); } @@ -896,7 +896,7 @@ static void gpencil_interpolate_v4_from_to( float *r = point_offset; for (int i = 0; i <= it; i++) { float fac = (float)i / (float)it; - fac = 3.0f * fac * fac - 2.0f * fac * fac * fac; // smooth + fac = 3.0f * fac * fac - 2.0f * fac * fac * fac; /* Smooth. */ interp_v4_v4v4(r, from, to, fac); r = POINTER_OFFSET(r, stride); } diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 7e524da0f53..7ea0d991f4c 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -269,7 +269,7 @@ void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, const ListBase *src, const /* copy each NLA-track, one at a time */ for (nlt = src->first; nlt; nlt = nlt->next) { /* make a copy, and add the copy to the destination list */ - // XXX: we need to fix this sometime + /* XXX: we need to fix this sometime. */ nlt_d = BKE_nlatrack_copy(bmain, nlt, true, flag); BLI_addtail(dst, nlt_d); } @@ -516,7 +516,7 @@ static float nlastrip_get_frame_actionclip(NlaStrip *strip, float cframe, short if (IS_EQF(strip->repeat, 0.0f)) { strip->repeat = 1.0f; } - // repeat = strip->repeat; // UNUSED + // repeat = strip->repeat; /* UNUSED */ /* scaling */ if (IS_EQF(strip->scale, 0.0f)) { diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 60edb78f8ba..8986847a034 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -1638,10 +1638,10 @@ static void sph_springs_modify(ParticleSystem *psys, float dtime) Lij = spring->rest_length; d = yield_ratio * timefix * Lij; - if (rij > Lij + d) { // Stretch + if (rij > Lij + d) { /* Stretch */ spring->rest_length += plasticity * (rij - Lij - d) * timefix; } - else if (rij < Lij - d) { // Compress + else if (rij < Lij - d) { /* Compress */ spring->rest_length -= plasticity * (Lij - d - rij) * timefix; } @@ -2209,7 +2209,7 @@ static void sph_integrate(ParticleSimulationData *sim, SPHData *sphdata) { ParticleSettings *part = sim->psys->part; - // float timestep = psys_get_timestep(sim); // UNUSED + // float timestep = psys_get_timestep(sim); /* UNUSED */ float pa_mass = part->mass * ((part->flag & PART_SIZEMASS) ? pa->size : 1.0f); float dtime = dfra * psys_get_timestep(sim); // int steps = 1; // UNUSED @@ -2218,7 +2218,7 @@ static void sph_integrate(ParticleSimulationData *sim, sphdata->pa = pa; sphdata->mass = pa_mass; sphdata->pass = 0; - // sphdata.element_size and sphdata.flow are set in the callback. + /* #sphdata.element_size and #sphdata.flow are set in the callback. */ /* Restore previous state and treat gravity & effectors as external acceleration. */ sub_v3_v3v3(effector_acceleration, pa->state.vel, pa->prev_state.vel); diff --git a/source/blender/blentranslation/msgfmt/msgfmt.c b/source/blender/blentranslation/msgfmt/msgfmt.c index f95bf2a9037..05c71fd4852 100644 --- a/source/blender/blentranslation/msgfmt/msgfmt.c +++ b/source/blender/blentranslation/msgfmt/msgfmt.c @@ -382,7 +382,7 @@ static int make(const char *input_file_name, const char *output_file_name) } else if (strstr(l, msgstr_kw) == l) { l = l + msgstr_len; - // Now we are in a msgstr section + /* Now we are in a `msgstr` section. */ section = SECTION_STR; if (l[0] == '[') { if (!is_plural) { diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cc b/source/blender/compositor/intern/COM_ExecutionGroup.cc index 68bda8c70d6..a45c453d7ed 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.cc +++ b/source/blender/compositor/intern/COM_ExecutionGroup.cc @@ -561,7 +561,7 @@ bool ExecutionGroup::scheduleChunkWhenPossible(ExecutionSystem *graph, return true; } - // Check if chunk is already executed or scheduled and not yet executed. + /* Check if chunk is already executed or scheduled and not yet executed. */ const int chunk_index = chunk_y * this->m_x_chunks_len + chunk_x; WorkPackage &work_package = m_work_packages[chunk_index]; if (work_package.state == eWorkPackageState::Executed) { diff --git a/source/blender/compositor/intern/COM_WorkPackage.h b/source/blender/compositor/intern/COM_WorkPackage.h index f0f53f300a5..20fca89aa4c 100644 --- a/source/blender/compositor/intern/COM_WorkPackage.h +++ b/source/blender/compositor/intern/COM_WorkPackage.h @@ -30,7 +30,7 @@ #include namespace blender::compositor { -// Forward Declarations. +/* Forward Declarations. */ class ExecutionGroup; /** diff --git a/source/blender/compositor/nodes/COM_BokehBlurNode.cc b/source/blender/compositor/nodes/COM_BokehBlurNode.cc index 1d2a0dae390..c51a98c0f82 100644 --- a/source/blender/compositor/nodes/COM_BokehBlurNode.cc +++ b/source/blender/compositor/nodes/COM_BokehBlurNode.cc @@ -64,9 +64,8 @@ void BokehBlurNode::convertToOperations(NodeConverter &converter, converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0)); converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1)); - // NOTE: on the bokeh blur operation the sockets are switched. - // for this reason the next two lines are correct. - // Fix for T43771 + /* NOTE: on the bokeh blur operation the sockets are switched. + * for this reason the next two lines are correct. Fix for T43771. */ converter.mapInputSocket(getInputSocket(2), operation->getInputSocket(3)); converter.mapInputSocket(getInputSocket(3), operation->getInputSocket(2)); diff --git a/source/blender/compositor/nodes/COM_ColorSpillNode.cc b/source/blender/compositor/nodes/COM_ColorSpillNode.cc index 119cff93e84..6119e635e59 100644 --- a/source/blender/compositor/nodes/COM_ColorSpillNode.cc +++ b/source/blender/compositor/nodes/COM_ColorSpillNode.cc @@ -39,8 +39,8 @@ void ColorSpillNode::convertToOperations(NodeConverter &converter, ColorSpillOperation *operation; operation = new ColorSpillOperation(); operation->setSettings((NodeColorspill *)editorsnode->storage); - operation->setSpillChannel(editorsnode->custom1 - 1); // Channel for spilling - operation->setSpillMethod(editorsnode->custom2); // Channel method + operation->setSpillChannel(editorsnode->custom1 - 1); /* Channel for spilling */ + operation->setSpillMethod(editorsnode->custom2); /* Channel method */ converter.addOperation(operation); converter.mapInputSocket(inputSocketImage, operation->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_Stabilize2dNode.cc b/source/blender/compositor/nodes/COM_Stabilize2dNode.cc index 7b2388bebca..90f62c6d562 100644 --- a/source/blender/compositor/nodes/COM_Stabilize2dNode.cc +++ b/source/blender/compositor/nodes/COM_Stabilize2dNode.cc @@ -101,7 +101,7 @@ void Stabilize2dNode::convertToOperations(NodeConverter &converter, converter.mapOutputSocket(getOutputSocket(), psoperation->getOutputSocket()); if (invert) { - // Translate -> Rotate -> Scale. + /* Translate -> Rotate -> Scale. */ converter.mapInputSocket(imageInput, translateOperation->getInputSocket(0)); converter.addLink(translateOperation->getOutputSocket(), @@ -111,7 +111,7 @@ void Stabilize2dNode::convertToOperations(NodeConverter &converter, converter.addLink(scaleOperation->getOutputSocket(), psoperation->getInputSocket(0)); } else { - // Scale -> Rotate -> Translate. + /* Scale -> Rotate -> Translate. */ converter.mapInputSocket(imageInput, scaleOperation->getInputSocket(0)); converter.addLink(scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0)); diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.cc b/source/blender/compositor/operations/COM_ColorCurveOperation.cc index 1b7ad0ea608..646238460ba 100644 --- a/source/blender/compositor/operations/COM_ColorCurveOperation.cc +++ b/source/blender/compositor/operations/COM_ColorCurveOperation.cc @@ -128,7 +128,7 @@ void ColorCurveOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -// Constant level curve mapping +/* Constant level curve mapping. */ ConstantLevelColorCurveOperation::ConstantLevelColorCurveOperation() { diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.cc b/source/blender/compositor/operations/COM_ColorSpillOperation.cc index 4b0e0520b75..5bf7a9ee9cd 100644 --- a/source/blender/compositor/operations/COM_ColorSpillOperation.cc +++ b/source/blender/compositor/operations/COM_ColorSpillOperation.cc @@ -30,7 +30,7 @@ ColorSpillOperation::ColorSpillOperation() this->m_inputImageReader = nullptr; this->m_inputFacReader = nullptr; - this->m_spillChannel = 1; // GREEN + this->m_spillChannel = 1; /* GREEN */ this->m_spillMethod = 0; flags.can_be_constant = true; } diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cc b/source/blender/compositor/operations/COM_CompositorOperation.cc index 8752d764107..fb9e2e43c60 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.cc +++ b/source/blender/compositor/operations/COM_CompositorOperation.cc @@ -62,7 +62,7 @@ void CompositorOperation::initExecution() return; } - // When initializing the tree during initial load the width and height can be zero. + /* When initializing the tree during initial load the width and height can be zero. */ this->m_imageInput = getInputSocketReader(0); this->m_alphaInput = getInputSocketReader(1); this->m_depthInput = getInputSocketReader(2); @@ -242,8 +242,8 @@ void CompositorOperation::determineResolution(unsigned int resolution[2], int width = this->m_rd->xsch * this->m_rd->size / 100; int height = this->m_rd->ysch * this->m_rd->size / 100; - // check actual render resolution with cropping it may differ with cropped border.rendering - // FIX for: [31777] Border Crop gives black (easy) + /* Check actual render resolution with cropping it may differ with cropped border.rendering + * Fix for T31777 Border Crop gives black (easy). */ Render *re = RE_GetSceneRender(this->m_scene); if (re) { RenderResult *rr = RE_AcquireResultRead(re); diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cc b/source/blender/compositor/operations/COM_DilateErodeOperation.cc index a27148f967d..c459d09f02c 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.cc +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cc @@ -160,7 +160,7 @@ bool DilateErodeThresholdOperation::determineDependingAreaOfInterest( return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } -// Dilate Distance +/* Dilate Distance. */ DilateDistanceOperation::DilateDistanceOperation() { this->addInputSocket(DataType::Value); diff --git a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cc b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cc index 1c1eaebd331..0026615f08b 100644 --- a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cc +++ b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cc @@ -27,7 +27,7 @@ namespace blender::compositor { using fREAL = float; -// returns next highest power of 2 of x, as well its log2 in L2 +/* Returns next highest power of 2 of x, as well its log2 in L2. */ static unsigned int nextPow2(unsigned int x, unsigned int *L2) { unsigned int pw, x_notpow2 = x & (x - 1); @@ -45,8 +45,8 @@ static unsigned int nextPow2(unsigned int x, unsigned int *L2) //------------------------------------------------------------------------------ -// from FXT library by Joerg Arndt, faster in order bitreversal -// use: r = revbin_upd(r, h) where h = N>>1 +/* From FXT library by Joerg Arndt, faster in order bit-reversal + * use: `r = revbin_upd(r, h)` where `h = N>>1`. */ static unsigned int revbin_upd(unsigned int r, unsigned int h) { while (!((r ^= h) & h)) { @@ -127,7 +127,7 @@ static void FHT(fREAL *data, unsigned int M, unsigned int inverse) //------------------------------------------------------------------------------ /* 2D Fast Hartley Transform, Mx/My -> log2 of width/height, * nzp -> the row where zero pad data starts, - * inverse -> see above */ + * inverse -> see above. */ static void FHT2D( fREAL *data, unsigned int Mx, unsigned int My, unsigned int nzp, unsigned int inverse) { @@ -136,14 +136,14 @@ static void FHT2D( Nx = 1 << Mx; Ny = 1 << My; - // rows (forward transform skips 0 pad data) + /* Rows (forward transform skips 0 pad data). */ maxy = inverse ? Ny : nzp; for (j = 0; j < maxy; j++) { FHT(&data[Nx * j], Mx, inverse); } - // transpose data - if (Nx == Ny) { // square + /* Transpose data. */ + if (Nx == Ny) { /* Square. */ for (j = 0; j < Ny; j++) { for (i = j + 1; i < Nx; i++) { unsigned int op = i + (j << Mx), np = j + (i << My); @@ -151,12 +151,12 @@ static void FHT2D( } } } - else { // rectangular + else { /* Rectangular. */ unsigned int k, Nym = Ny - 1, stm = 1 << (Mx + My); for (i = 0; stm > 0; i++) { #define PRED(k) (((k & Nym) << Mx) + (k >> My)) for (j = PRED(i); j > i; j = PRED(j)) { - /* pass */ + /* Pass. */ } if (j < i) { continue; @@ -172,12 +172,12 @@ static void FHT2D( SWAP(unsigned int, Nx, Ny); SWAP(unsigned int, Mx, My); - // now columns == transposed rows + /* Now columns == transposed rows. */ for (j = 0; j < Ny; j++) { FHT(&data[Nx * j], Mx, inverse); } - // finalize + /* Finalize. */ for (j = 0; j <= (Ny >> 1); j++) { unsigned int jm = (Ny - j) & (Ny - 1); unsigned int ji = j << Mx; @@ -199,7 +199,7 @@ static void FHT2D( //------------------------------------------------------------------------------ -/* 2D convolution calc, d1 *= d2, M/N - > log2 of width/height */ +/* 2D convolution calc, d1 *= d2, M/N - > log2 of width/height. */ static void fht_convolve(fREAL *d1, const fREAL *d2, unsigned int M, unsigned int N) { fREAL a, b; @@ -275,18 +275,18 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2) 0, rdst->getWidth() * rdst->getHeight() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float)); - // convolution result width & height + /* Convolution result width & height. */ w2 = 2 * kernelWidth - 1; h2 = 2 * kernelHeight - 1; - // FFT pow2 required size & log2 + /* FFT pow2 required size & log2. */ w2 = nextPow2(w2, &log2_w); h2 = nextPow2(h2, &log2_h); - // alloc space + /* Allocate space. */ data1 = (fREAL *)MEM_callocN(3 * w2 * h2 * sizeof(fREAL), "convolve_fast FHT data1"); data2 = (fREAL *)MEM_callocN(w2 * h2 * sizeof(fREAL), "convolve_fast FHT data2"); - // normalize convolutor + /* Normalize convolutor. */ wt[0] = wt[1] = wt[2] = 0.0f; for (y = 0; y < kernelHeight; y++) { colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_DATA_TYPE_COLOR_CHANNELS]; @@ -310,10 +310,10 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2) } } - // copy image data, unpacking interleaved RGBA into separate channels - // only need to calc data1 once + /* Copy image data, unpacking interleaved RGBA into separate channels + * only need to calc data1 once. */ - // block add-overlap + /* Block add-overlap. */ hw = kernelWidth >> 1; hh = kernelHeight >> 1; xbsz = (w2 + 1) - kernelWidth; @@ -329,13 +329,13 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2) for (ybl = 0; ybl < nyb; ybl++) { for (xbl = 0; xbl < nxb; xbl++) { - // each channel one by one + /* Each channel one by one. */ for (ch = 0; ch < 3; ch++) { fREAL *data1ch = &data1[ch * w2 * h2]; - // only need to calc fht data from in2 once, can re-use for every block + /* Only need to calc fht data from in2 once, can re-use for every block. */ if (!in2done) { - // in2, channel ch -> data1 + /* in2, channel ch -> data1 */ for (y = 0; y < kernelHeight; y++) { fp = &data1ch[y * w2]; colp = (fRGB *)&kernelBuffer[y * kernelWidth * COM_DATA_TYPE_COLOR_CHANNELS]; @@ -345,7 +345,7 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2) } } - // in1, channel ch -> data2 + /* in1, channel ch -> data2 */ memset(data2, 0, w2 * h2 * sizeof(fREAL)); for (y = 0; y < ybsz; y++) { int yy = ybl * ybsz + y; @@ -363,20 +363,20 @@ static void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2) } } - // forward FHT - // zero pad data start is different for each == height+1 + /* Forward FHT + * zero pad data start is different for each == height+1. */ if (!in2done) { FHT2D(data1ch, log2_w, log2_h, kernelHeight + 1, 0); } FHT2D(data2, log2_w, log2_h, kernelHeight + 1, 0); - // FHT2D transposed data, row/col now swapped - // convolve & inverse FHT + /* FHT2D transposed data, row/col now swapped + * convolve & inverse FHT. */ fht_convolve(data2, data1ch, log2_h, log2_w); FHT2D(data2, log2_h, log2_w, 0, 1); - // data again transposed, so in order again + /* Data again transposed, so in order again. */ - // overlap-add result + /* Overlap-add result. */ for (y = 0; y < (int)h2; y++) { const int yy = ybl * ybsz + y - hh; if ((yy < 0) || (yy >= imageHeight)) { @@ -416,8 +416,8 @@ void GlareFogGlowOperation::generateGlare(float *data, unsigned int sz = 1 << settings->size; const float cs_r = 1.0f, cs_g = 1.0f, cs_b = 1.0f; - // temp. src image - // make the convolution kernel + /* Temp. src image + * make the convolution kernel. */ rcti kernelRect; BLI_rcti_init(&kernelRect, 0, sz, 0, sz); ckrn = new MemoryBuffer(DataType::Color, kernelRect); @@ -433,9 +433,9 @@ void GlareFogGlowOperation::generateGlare(float *data, fcol[0] = expf(d * cs_r); fcol[1] = expf(d * cs_g); fcol[2] = expf(d * cs_b); - // linear window good enough here, visual result counts, not scientific analysis - // w = (1.0f-fabs(u))*(1.0f-fabs(v)); - // actually, Hanning window is ok, cos^2 for some reason is slower + /* Linear window good enough here, visual result counts, not scientific analysis: + * `w = (1.0f-fabs(u))*(1.0f-fabs(v));` + * actually, Hanning window is ok, `cos^2` for some reason is slower. */ w = (0.5f + 0.5f * cosf(u * (float)M_PI)) * (0.5f + 0.5f * cosf(v * (float)M_PI)); mul_v3_fl(fcol, w); ckrn->writePixel(x, y, fcol); diff --git a/source/blender/compositor/operations/COM_InpaintOperation.cc b/source/blender/compositor/operations/COM_InpaintOperation.cc index 413ed2694a9..bfcd504177f 100644 --- a/source/blender/compositor/operations/COM_InpaintOperation.cc +++ b/source/blender/compositor/operations/COM_InpaintOperation.cc @@ -28,7 +28,7 @@ namespace blender::compositor { #define ASSERT_XY_RANGE(x, y) \ BLI_assert(x >= 0 && x < this->getWidth() && y >= 0 && y < this->getHeight()) -// Inpaint (simple convolve using average of known pixels) +/* In-paint (simple convolve using average of known pixels). */ InpaintSimpleOperation::InpaintSimpleOperation() { this->addInputSocket(DataType::Color); diff --git a/source/blender/compositor/operations/COM_ScaleOperation.cc b/source/blender/compositor/operations/COM_ScaleOperation.cc index ef34bc7bee6..bbb6de2f39e 100644 --- a/source/blender/compositor/operations/COM_ScaleOperation.cc +++ b/source/blender/compositor/operations/COM_ScaleOperation.cc @@ -262,7 +262,7 @@ bool ScaleAbsoluteOperation::determineDependingAreaOfInterest(rcti *input, return ScaleOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } -// Absolute fixed size +/* Absolute fixed size. */ ScaleFixedSizeOperation::ScaleFixedSizeOperation() : BaseScaleOperation() { this->addInputSocket(DataType::Color, ResizeMode::None); diff --git a/source/blender/compositor/operations/COM_SplitOperation.cc b/source/blender/compositor/operations/COM_SplitOperation.cc index d18ed3b8e14..b2a50e2c740 100644 --- a/source/blender/compositor/operations/COM_SplitOperation.cc +++ b/source/blender/compositor/operations/COM_SplitOperation.cc @@ -40,7 +40,7 @@ SplitOperation::SplitOperation() void SplitOperation::initExecution() { - // When initializing the tree during initial load the width and height can be zero. + /* When initializing the tree during initial load the width and height can be zero. */ this->m_image1Input = getInputSocketReader(0); this->m_image2Input = getInputSocketReader(1); } diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.cc b/source/blender/compositor/operations/COM_VectorBlurOperation.cc index b5b5d426338..df65044afc1 100644 --- a/source/blender/compositor/operations/COM_VectorBlurOperation.cc +++ b/source/blender/compositor/operations/COM_VectorBlurOperation.cc @@ -48,8 +48,8 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove); VectorBlurOperation::VectorBlurOperation() { this->addInputSocket(DataType::Color); - this->addInputSocket(DataType::Value); // ZBUF - this->addInputSocket(DataType::Color); // SPEED + this->addInputSocket(DataType::Value); /* ZBUF */ + this->addInputSocket(DataType::Color); /* SPEED */ this->addOutputSocket(DataType::Color); this->m_settings = nullptr; this->m_cachedInstance = nullptr; diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cc b/source/blender/compositor/operations/COM_ViewerOperation.cc index 37a45ac32cb..a038e8994d8 100644 --- a/source/blender/compositor/operations/COM_ViewerOperation.cc +++ b/source/blender/compositor/operations/COM_ViewerOperation.cc @@ -61,7 +61,7 @@ ViewerOperation::ViewerOperation() void ViewerOperation::initExecution() { - // When initializing the tree during initial load the width and height can be zero. + /* When initializing the tree during initial load the width and height can be zero. */ this->m_imageInput = getInputSocketReader(0); this->m_alphaInput = getInputSocketReader(1); this->m_depthInput = getInputSocketReader(2); diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.cc b/source/blender/compositor/operations/COM_WriteBufferOperation.cc index e2dc6287baf..6380f6bf3df 100644 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.cc +++ b/source/blender/compositor/operations/COM_WriteBufferOperation.cc @@ -126,7 +126,7 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice *device, * * NOTE: list of cl_mem will be filled by 2, and needs to be cleaned up by 4 */ - // STEP 1 + /* STEP 1 */ const unsigned int outputBufferWidth = outputBuffer->getWidth(); const unsigned int outputBufferHeight = outputBuffer->getHeight(); @@ -144,7 +144,7 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice *device, printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } - // STEP 2 + /* STEP 2 */ std::list *clMemToCleanUp = new std::list(); clMemToCleanUp->push_back(clOutputBuffer); std::list *clKernelsToCleanUp = new std::list(); @@ -156,7 +156,7 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice *device, clMemToCleanUp, clKernelsToCleanUp); - // STEP 3 + /* STEP 3 */ size_t origin[3] = {0, 0, 0}; size_t region[3] = {outputBufferWidth, outputBufferHeight, 1}; @@ -185,7 +185,7 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice *device, this->getMemoryProxy()->getBuffer()->fill_from(*outputBuffer); - // STEP 4 + /* STEP 4 */ while (!clMemToCleanUp->empty()) { cl_mem mem = clMemToCleanUp->front(); error = clReleaseMemObject(mem); diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h index 47dad17b482..aa184cce433 100644 --- a/source/blender/depsgraph/DEG_depsgraph.h +++ b/source/blender/depsgraph/DEG_depsgraph.h @@ -82,7 +82,7 @@ extern "C" { /* CRUD ------------------------------------------- */ -// Get main depsgraph instance from context! +/* Get main depsgraph instance from context! */ /* Create new Depsgraph instance */ /* TODO: what args are needed here? What's the building-graph entry point? */ diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_drivers.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_drivers.cc index b9ce29ce8d2..bf3af571f0b 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_drivers.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_drivers.cc @@ -125,13 +125,13 @@ static bool is_reachable(const Node *const from, const Node *const to) return true; } - // Perform a graph walk from 'to' towards its incoming connections. - // Walking from 'from' towards its outgoing connections is 10x slower on the Spring rig. + /* Perform a graph walk from 'to' towards its incoming connections. + * Walking from 'from' towards its outgoing connections is 10x slower on the Spring rig. */ deque queue; Set seen; queue.push_back(to); while (!queue.empty()) { - // Visit the next node to inspect. + /* Visit the next node to inspect. */ const Node *visit = queue.back(); queue.pop_back(); @@ -139,7 +139,7 @@ static bool is_reachable(const Node *const from, const Node *const to) return true; } - // Queue all incoming relations that we haven't seen before. + /* Queue all incoming relations that we haven't seen before. */ for (Relation *relation : visit->inlinks) { const Node *prev_node = relation->from; if (seen.add(prev_node)) { @@ -177,7 +177,7 @@ void DepsgraphRelationBuilder::build_driver_relations(IDNode *id_node) return; } - // Mapping from RNA prefix -> set of driver descriptors: + /* Mapping from RNA prefix -> set of driver descriptors: */ Map> driver_groups; PointerRNA id_ptr; @@ -197,47 +197,47 @@ void DepsgraphRelationBuilder::build_driver_relations(IDNode *id_node) } for (Span prefix_group : driver_groups.values()) { - // For each node in the driver group, try to connect it to another node - // in the same group without creating any cycles. + /* For each node in the driver group, try to connect it to another node + * in the same group without creating any cycles. */ int num_drivers = prefix_group.size(); if (num_drivers < 2) { - // A relation requires two drivers. + /* A relation requires two drivers. */ continue; } for (int from_index = 0; from_index < num_drivers; ++from_index) { const DriverDescriptor &driver_from = prefix_group[from_index]; Node *op_from = get_node(driver_from.depsgraph_key()); - // Start by trying the next node in the group. + /* Start by trying the next node in the group. */ for (int to_offset = 1; to_offset < num_drivers; ++to_offset) { const int to_index = (from_index + to_offset) % num_drivers; const DriverDescriptor &driver_to = prefix_group[to_index]; Node *op_to = get_node(driver_to.depsgraph_key()); - // Duplicate drivers can exist (see T78615), but cannot be distinguished by OperationKey - // and thus have the same depsgraph node. Relations between those drivers should not be - // created. This not something that is expected to happen (both the UI and the Python API - // prevent duplicate drivers), it did happen in a file and it is easy to deal with here. + /* Duplicate drivers can exist (see T78615), but cannot be distinguished by OperationKey + * and thus have the same depsgraph node. Relations between those drivers should not be + * created. This not something that is expected to happen (both the UI and the Python API + * prevent duplicate drivers), it did happen in a file and it is easy to deal with here. */ if (op_from == op_to) { continue; } if (from_index < to_index && driver_from.is_same_array_as(driver_to)) { - // This is for adding a relation like `color[0]` -> `color[1]`. - // When the search for another driver wraps around, we cannot blindly add relations any - // more. + /* This is for adding a relation like `color[0]` -> `color[1]`. + * When the search for another driver wraps around, + * we cannot blindly add relations any more. */ } else { - // Investigate whether this relation would create a dependency cycle. - // Example graph: - // A -> B -> C - // and investigating a potential connection C->A. Because A->C is an - // existing transitive connection, adding C->A would create a cycle. + /* Investigate whether this relation would create a dependency cycle. + * Example graph: + * A -> B -> C + * and investigating a potential connection C->A. Because A->C is an + * existing transitive connection, adding C->A would create a cycle. */ if (is_reachable(op_to, op_from)) { continue; } - // No need to directly connect this node if there is already a transitive connection. + /* No need to directly connect this node if there is already a transitive connection. */ if (is_reachable(op_from, op_to)) { break; } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc index e0a7a42ea4a..bad4e96c60b 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc @@ -28,7 +28,7 @@ namespace blender::deg { //////////////////////////////////////////////////////////////////////////////// -// Time source. +/* Time source. */ TimeSourceKey::TimeSourceKey() : id(nullptr) { diff --git a/source/blender/depsgraph/intern/debug/deg_time_average.h b/source/blender/depsgraph/intern/debug/deg_time_average.h index 838ceff8d96..4ed78fe70cb 100644 --- a/source/blender/depsgraph/intern/debug/deg_time_average.h +++ b/source/blender/depsgraph/intern/debug/deg_time_average.h @@ -26,8 +26,7 @@ namespace blender { namespace deg { -// Utility class which takes care of calculating average of time series, such as -// FPS counters. +/* Utility class which takes care of calculating average of time series, such as FPS counters. */ template class AveragedTimeSampler { public: AveragedTimeSampler() : num_samples_(0), next_sample_index_(0) @@ -38,13 +37,13 @@ template class AveragedTimeSampler { { samples_[next_sample_index_] = value; - // Move to the next index, keeping wrapping at the end of array into account. + /* Move to the next index, keeping wrapping at the end of array into account. */ ++next_sample_index_; if (next_sample_index_ == MaxSamples) { next_sample_index_ = 0; } - // Update number of stored samples. + /* Update number of stored samples. */ if (num_samples_ != MaxSamples) { ++num_samples_; } @@ -62,10 +61,10 @@ template class AveragedTimeSampler { protected: double samples_[MaxSamples]; - // Number of samples which are actually stored in the array. + /* Number of samples which are actually stored in the array. */ int num_samples_; - // Index in the samples_ array under which next sample will be stored. + /* Index in the samples_ array under which next sample will be stored. */ int next_sample_index_; }; diff --git a/source/blender/depsgraph/intern/depsgraph_query_iter.cc b/source/blender/depsgraph/intern/depsgraph_query_iter.cc index df1cf8cc771..770d9775dd3 100644 --- a/source/blender/depsgraph/intern/depsgraph_query_iter.cc +++ b/source/blender/depsgraph/intern/depsgraph_query_iter.cc @@ -51,9 +51,9 @@ # include "intern/eval/deg_eval_copy_on_write.h" #endif -// If defined, all working data will be set to an invalid state, helping -// to catch issues when areas accessing data which is considered to be no -// longer available. +/* If defined, all working data will be set to an invalid state, helping + * to catch issues when areas accessing data which is considered to be no + * longer available. */ #undef INVALIDATE_WORK_DATA #ifndef NDEBUG @@ -79,22 +79,20 @@ void deg_invalidate_iterator_work_data(DEGObjectIterData *data) void verify_id_properties_freed(DEGObjectIterData *data) { if (data->dupli_object_current == nullptr) { - // We didn't enter duplication yet, so we can't have any dangling - // pointers. + /* We didn't enter duplication yet, so we can't have any dangling pointers. */ return; } const Object *dupli_object = data->dupli_object_current->ob; Object *temp_dupli_object = &data->temp_dupli_object; if (temp_dupli_object->id.properties == nullptr) { - // No ID properties in temp data-block -- no leak is possible. + /* No ID properties in temp data-block -- no leak is possible. */ return; } if (temp_dupli_object->id.properties == dupli_object->id.properties) { - // Temp copy of object did not modify ID properties. + /* Temp copy of object did not modify ID properties. */ return; } - // Free memory which is owned by temporary storage which is about to - // get overwritten. + /* Free memory which is owned by temporary storage which is about to get overwritten. */ IDP_FreeProperty(temp_dupli_object->id.properties); temp_dupli_object->id.properties = nullptr; } diff --git a/source/blender/depsgraph/intern/depsgraph_registry.cc b/source/blender/depsgraph/intern/depsgraph_registry.cc index f348ef6e6e9..cc9fcf78292 100644 --- a/source/blender/depsgraph/intern/depsgraph_registry.cc +++ b/source/blender/depsgraph/intern/depsgraph_registry.cc @@ -49,7 +49,7 @@ void unregister_graph(Depsgraph *depsgraph) VectorSet &graphs = graph_registry.lookup(bmain); graphs.remove(depsgraph); - // If this was the last depsgraph associated with the main, remove the main entry as well. + /* If this was the last depsgraph associated with the main, remove the main entry as well. */ if (graphs.is_empty()) { graph_registry.remove(bmain); } diff --git a/source/blender/depsgraph/intern/node/deg_node_component.cc b/source/blender/depsgraph/intern/node/deg_node_component.cc index 431bf536b65..a29618cefa8 100644 --- a/source/blender/depsgraph/intern/node/deg_node_component.cc +++ b/source/blender/depsgraph/intern/node/deg_node_component.cc @@ -237,7 +237,7 @@ void ComponentNode::tag_update(Depsgraph *graph, eUpdateSource source) for (OperationNode *op_node : operations) { op_node->tag_update(graph, source); } - // It is possible that tag happens before finalization. + /* It is possible that tag happens before finalization. */ if (operations_map != nullptr) { for (OperationNode *op_node : operations_map->values()) { op_node->tag_update(graph, source); diff --git a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c index 1af489b60ce..ae37d6c8deb 100644 --- a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c +++ b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c @@ -51,7 +51,7 @@ /** * Orient the handles towards the selection (can be slow with high-poly mesh!). */ -// Disable for now, issues w/ refresh and '+' icons overlap. +/* Disable for now, issues w/ refresh and '+' icons overlap. */ // #define USE_SELECT_CENTER #ifdef USE_SELECT_CENTER diff --git a/source/blender/editors/space_graph/graph_view.c b/source/blender/editors/space_graph/graph_view.c index 036fd354c18..c38c5f09a2a 100644 --- a/source/blender/editors/space_graph/graph_view.c +++ b/source/blender/editors/space_graph/graph_view.c @@ -219,7 +219,7 @@ static int graphkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op)) scene->r.pefra = round_fl_to_int(max); /* Set notifier that things have changed. */ - // XXX Err... there's nothing for frame ranges yet, but this should do fine too. + /* XXX: Err... there's nothing for frame ranges yet, but this should do fine too. */ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene); return OPERATOR_FINISHED; diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index 59a17fcc600..df516d2a5c4 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -72,14 +72,14 @@ BLI_STATIC_ASSERT(sizeof(IMAGE) == HEADER_SIZE, "Invalid header size"); // #define TYPEMASK 0xff00 #define BPPMASK 0x00ff -// #define ITYPE_VERBATIM 0x0000 // UNUSED +// #define ITYPE_VERBATIM 0x0000 /* UNUSED */ #define ITYPE_RLE 0x0100 #define ISRLE(type) (((type)&0xff00) == ITYPE_RLE) // #define ISVERBATIM(type) (((type) & 0xff00) == ITYPE_VERBATIM) #define BPP(type) ((type)&BPPMASK) #define RLE(bpp) (ITYPE_RLE | (bpp)) -// #define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp)) // UNUSED -// #define IBUFSIZE(pixels) ((pixels + (pixels >> 6)) << 2) // UNUSED +// #define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp)) /* UNUSED */ +// #define IBUFSIZE(pixels) ((pixels + (pixels >> 6)) << 2) /* UNUSED */ // #define RLE_NOP 0x00 /* local struct for mem access */ diff --git a/source/blender/io/alembic/tests/abc_matrix_test.cc b/source/blender/io/alembic/tests/abc_matrix_test.cc index c6d7245a52c..2706699d994 100644 --- a/source/blender/io/alembic/tests/abc_matrix_test.cc +++ b/source/blender/io/alembic/tests/abc_matrix_test.cc @@ -1,6 +1,6 @@ #include "testing/testing.h" -// Keep first since utildefines defines AT which conflicts with STL +/* Keep first since utildefines defines AT which conflicts with STL. */ #include "intern/abc_axis_conversion.h" #include "BLI_math.h" diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h index baed2aa2866..e899e6bd3ec 100644 --- a/source/blender/makesdna/DNA_action_types.h +++ b/source/blender/makesdna/DNA_action_types.h @@ -856,11 +856,11 @@ typedef enum eSAction_Flag { /* draw time in seconds instead of time in frames */ SACTION_DRAWTIME = (1 << 2), /* don't filter action channels according to visibility */ - // SACTION_NOHIDE = (1 << 3), /* XXX deprecated... old animation systems. */ + // SACTION_NOHIDE = (1 << 3), /* Deprecated, old animation systems. */ /* don't kill overlapping keyframes after transform */ SACTION_NOTRANSKEYCULL = (1 << 4), /* don't include keyframes that are out of view */ - // SACTION_HORIZOPTIMISEON = (1 << 5), // XXX deprecated... old irrelevant trick + // SACTION_HORIZOPTIMISEON = (1 << 5), /* Deprecated, old irrelevant trick. */ /* show pose-markers (local to action) in Action Editor mode. */ SACTION_POSEMARKERS_SHOW = (1 << 6), /* don't draw action channels using group colors (where applicable) */ diff --git a/source/blender/makesdna/DNA_armature_types.h b/source/blender/makesdna/DNA_armature_types.h index 454d843112a..3b65378f9eb 100644 --- a/source/blender/makesdna/DNA_armature_types.h +++ b/source/blender/makesdna/DNA_armature_types.h @@ -207,9 +207,8 @@ typedef enum eArmature_DeformFlag { ARM_DEF_INVERT_VGROUP = (1 << 4), } eArmature_DeformFlag; -/* armature->pathflag */ -// XXX deprecated... old animation system (armature only viz) -#ifdef DNA_DEPRECATED_ALLOW +#ifdef DNA_DEPRECATED_ALLOW /* Old animation system (armature only viz). */ +/** #bArmature.pathflag */ typedef enum eArmature_PathFlag { ARM_PATH_FNUMS = (1 << 0), ARM_PATH_KFRAS = (1 << 1), diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index 822b8705c9b..4b4c24a7a4e 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -37,7 +37,7 @@ struct Ipo; struct Text; /* channels reside in Object or Action (ListBase) constraintChannels */ -// XXX deprecated... old AnimSys +/* XXX: deprecated... old AnimSys. */ typedef struct bConstraintChannel { struct bConstraintChannel *next, *prev; struct Ipo *ipo; -- cgit v1.2.3 From 4e16e8b6711538256823db936a00787e1e9e8679 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 12:36:13 +1000 Subject: Cleanup: warnings --- intern/cycles/blender/blender_object.cpp | 1 + source/blender/draw/intern/draw_cache_extract.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index a7eae421b55..41871582f66 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -547,6 +547,7 @@ void BlenderSync::sync_procedural(BL::Object &b_ob, #else (void)b_ob; (void)b_mesh_cache; + (void)has_subdivision_modifier; #endif } diff --git a/source/blender/draw/intern/draw_cache_extract.h b/source/blender/draw/intern/draw_cache_extract.h index db96d6a774f..a680cc0d6b7 100644 --- a/source/blender/draw/intern/draw_cache_extract.h +++ b/source/blender/draw/intern/draw_cache_extract.h @@ -304,8 +304,8 @@ typedef struct MeshBatchCache { MBC_EDITUV_EDGES | MBC_EDITUV_VERTS | MBC_EDITUV_FACEDOTS | MBC_WIRE_LOOPS_UVS) void mesh_buffer_cache_create_requested(struct TaskGraph *task_graph, - MeshBatchCache *mbc, - MeshBufferCache *extraction_cache, + MeshBatchCache *cache, + MeshBufferCache *mbc, Mesh *me, const bool is_editmode, const bool is_paint_mode, -- cgit v1.2.3 From cec35060f563e89a567ce252a6a3ebc7fcf3318f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 12:39:45 +1000 Subject: Cleanup: sort struct blocks --- source/blender/blenkernel/BKE_action.hh | 2 +- source/blender/editors/asset/ED_asset_filter.h | 2 +- source/blender/editors/asset/ED_asset_list.h | 2 +- source/blender/editors/asset/ED_asset_list.hh | 4 ++-- source/blender/editors/asset/ED_asset_mark_clear.h | 2 +- source/blender/editors/asset/ED_asset_temp_id_consumer.h | 2 +- source/blender/editors/include/ED_object.h | 2 +- source/blender/editors/include/UI_interface.h | 2 +- source/blender/editors/space_file/filelist.h | 2 +- source/blender/io/gpencil/CMakeLists.txt | 3 +++ source/blender/io/usd/usd.h | 6 +++--- source/blender/sequencer/SEQ_sequencer.h | 4 ++-- source/blender/windowmanager/WM_types.h | 4 ++-- 13 files changed, 20 insertions(+), 17 deletions(-) diff --git a/source/blender/blenkernel/BKE_action.hh b/source/blender/blenkernel/BKE_action.hh index b9f106d367e..9b033713dc7 100644 --- a/source/blender/blenkernel/BKE_action.hh +++ b/source/blender/blenkernel/BKE_action.hh @@ -24,8 +24,8 @@ #include "BLI_function_ref.hh" -struct bAction; struct FCurve; +struct bAction; namespace blender::bke { diff --git a/source/blender/editors/asset/ED_asset_filter.h b/source/blender/editors/asset/ED_asset_filter.h index fb2d3bfb273..340c4c9dbe7 100644 --- a/source/blender/editors/asset/ED_asset_filter.h +++ b/source/blender/editors/asset/ED_asset_filter.h @@ -24,8 +24,8 @@ extern "C" { #endif -struct AssetHandle; struct AssetFilterSettings; +struct AssetHandle; bool ED_asset_filter_matches_asset(const struct AssetFilterSettings *filter, const struct AssetHandle *asset); diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h index 55a0ac0b500..61d7729b651 100644 --- a/source/blender/editors/asset/ED_asset_list.h +++ b/source/blender/editors/asset/ED_asset_list.h @@ -27,8 +27,8 @@ extern "C" { struct AssetFilterSettings; struct AssetHandle; struct AssetLibraryReference; -struct bContext; struct ID; +struct bContext; struct wmNotifier; void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_reference, diff --git a/source/blender/editors/asset/ED_asset_list.hh b/source/blender/editors/asset/ED_asset_list.hh index fee34d929c2..dcc07f54e75 100644 --- a/source/blender/editors/asset/ED_asset_list.hh +++ b/source/blender/editors/asset/ED_asset_list.hh @@ -24,10 +24,10 @@ #include "BLI_function_ref.hh" -struct AssetLibraryReference; struct AssetHandle; -struct bContext; +struct AssetLibraryReference; struct FileDirEntry; +struct bContext; std::string ED_assetlist_asset_filepath_get(const bContext *C, const AssetLibraryReference &library_reference, diff --git a/source/blender/editors/asset/ED_asset_mark_clear.h b/source/blender/editors/asset/ED_asset_mark_clear.h index cdd1f0d080b..7524ec6b02a 100644 --- a/source/blender/editors/asset/ED_asset_mark_clear.h +++ b/source/blender/editors/asset/ED_asset_mark_clear.h @@ -24,8 +24,8 @@ extern "C" { #endif -struct bContext; struct ID; +struct bContext; bool ED_asset_mark_id(const struct bContext *C, struct ID *id); bool ED_asset_clear_id(struct ID *id); diff --git a/source/blender/editors/asset/ED_asset_temp_id_consumer.h b/source/blender/editors/asset/ED_asset_temp_id_consumer.h index 7c10d88262e..9a47e435612 100644 --- a/source/blender/editors/asset/ED_asset_temp_id_consumer.h +++ b/source/blender/editors/asset/ED_asset_temp_id_consumer.h @@ -30,9 +30,9 @@ typedef struct AssetTempIDConsumer AssetTempIDConsumer; struct AssetHandle; struct AssetLibraryReference; -struct bContext; struct Main; struct ReportList; +struct bContext; AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const struct AssetHandle *handle); void ED_asset_temp_id_consumer_free(AssetTempIDConsumer **consumer); diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 3141c8f707b..a9cf04e1ad7 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -50,10 +50,10 @@ struct bContext; struct bFaceMap; struct bPoseChannel; struct uiLayout; +struct wmEvent; struct wmKeyConfig; struct wmOperator; struct wmOperatorType; -struct wmEvent; /* object_edit.c */ /* context.object */ diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 30be3588b5a..7211cf9f893 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -35,8 +35,8 @@ extern "C" { /* Struct Declarations */ struct ARegion; -struct AssetHandle; struct AssetFilterSettings; +struct AssetHandle; struct AutoComplete; struct EnumPropertyItem; struct FileDirEntry; diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h index d67cd89200b..1fb05e0f9ac 100644 --- a/source/blender/editors/space_file/filelist.h +++ b/source/blender/editors/space_file/filelist.h @@ -27,9 +27,9 @@ extern "C" { #endif +struct AssetLibraryReference; struct BlendHandle; struct FileList; -struct AssetLibraryReference; struct FileSelection; struct wmWindowManager; diff --git a/source/blender/io/gpencil/CMakeLists.txt b/source/blender/io/gpencil/CMakeLists.txt index 4af8b506bd5..3ef9fa44ff8 100644 --- a/source/blender/io/gpencil/CMakeLists.txt +++ b/source/blender/io/gpencil/CMakeLists.txt @@ -50,6 +50,9 @@ set(SRC intern/gpencil_io_export_base.hh intern/gpencil_io_import_base.hh intern/gpencil_io_import_svg.hh + + # Only so this file is known by CMake. + ../../../../extern/nanosvg/nanosvg.h ) set(LIB diff --git a/source/blender/io/usd/usd.h b/source/blender/io/usd/usd.h index 6b6b2d37162..2a036c3d398 100644 --- a/source/blender/io/usd/usd.h +++ b/source/blender/io/usd/usd.h @@ -25,11 +25,11 @@ extern "C" { #endif -struct bContext; -struct Object; struct CacheArchiveHandle; -struct CacheReader; struct CacheFile; +struct CacheReader; +struct Object; +struct bContext; struct USDExportParams { bool export_animation; diff --git a/source/blender/sequencer/SEQ_sequencer.h b/source/blender/sequencer/SEQ_sequencer.h index 27463379ae0..54ef37b9049 100644 --- a/source/blender/sequencer/SEQ_sequencer.h +++ b/source/blender/sequencer/SEQ_sequencer.h @@ -29,10 +29,10 @@ extern "C" { #include "DNA_scene_types.h" -struct BlendWriter; struct BlendDataReader; -struct BlendLibReader; struct BlendExpander; +struct BlendLibReader; +struct BlendWriter; struct Depsgraph; struct Editing; struct Scene; diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 843ceca7700..8a1ff67b37c 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -111,11 +111,11 @@ struct ID; struct ImBuf; struct bContext; +struct wmDrag; +struct wmDropBox; struct wmEvent; struct wmOperator; struct wmWindowManager; -struct wmDrag; -struct wmDropBox; #include "BLI_compiler_attrs.h" #include "DNA_listBase.h" -- cgit v1.2.3 From efcac471551ee8fe3a9e0a68eec478a3e1eac089 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 12:41:26 +1000 Subject: Cleanup: soft CMake file lists --- source/blender/blenkernel/CMakeLists.txt | 2 +- source/blender/blenlib/CMakeLists.txt | 2 +- source/blender/editors/asset/CMakeLists.txt | 2 +- source/blender/io/usd/CMakeLists.txt | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index adaef22d5bc..64cfbd8f491 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -78,9 +78,9 @@ set(SRC intern/anim_visualization.c intern/appdir.c intern/armature.c - intern/armature_selection.cc intern/armature_deform.c intern/armature_pose.cc + intern/armature_selection.cc intern/armature_update.c intern/asset.cc intern/attribute.c diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index f98d15ad08b..24178535068 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -199,8 +199,8 @@ set(SRC BLI_enumerable_thread_specific.hh BLI_expr_pylike_eval.h BLI_fileops.h - BLI_filereader.h BLI_fileops_types.h + BLI_filereader.h BLI_float2.hh BLI_float3.hh BLI_float4x4.hh diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt index 7e578b78809..31c07580570 100644 --- a/source/blender/editors/asset/CMakeLists.txt +++ b/source/blender/editors/asset/CMakeLists.txt @@ -51,8 +51,8 @@ set(SRC ) set(LIB - bf_blenloader bf_blenkernel + bf_blenloader ) blender_add_lib(bf_editor_asset "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 5499fe36898..12015bf1698 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -77,8 +77,8 @@ set(SRC intern/usd_reader_nurbs.cc intern/usd_reader_prim.cc intern/usd_reader_stage.cc - intern/usd_reader_xform.cc intern/usd_reader_volume.cc + intern/usd_reader_xform.cc usd.h @@ -102,8 +102,8 @@ set(SRC intern/usd_reader_nurbs.h intern/usd_reader_prim.h intern/usd_reader_stage.h - intern/usd_reader_xform.h intern/usd_reader_volume.h + intern/usd_reader_xform.h ) set(LIB -- cgit v1.2.3 From 2fb57685e393e2d9e59fe9bde02358e28f3e57a3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 12:59:22 +1000 Subject: Fix "Text to Object" creating invisible object Newly created objects would not become visible until another action forced a depsgraph update. --- source/blender/editors/curve/editfont.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index b7deea5069e..d029bb539ba 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -59,6 +59,7 @@ #include "ED_curve.h" #include "ED_object.h" +#include "ED_outliner.h" #include "ED_screen.h" #include "ED_view3d.h" @@ -704,6 +705,7 @@ static void txt_add_object(bContext *C, void ED_text_to_object(bContext *C, const Text *text, const bool split_lines) { + Main *bmain = CTX_data_main(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); const TextLine *line; float offset[3]; @@ -742,6 +744,9 @@ void ED_text_to_object(bContext *C, const Text *text, const bool split_lines) txt_add_object(C, text->lines.first, BLI_listbase_count(&text->lines), offset); } + + DEG_relations_tag_update(bmain); + ED_outliner_select_sync_from_object_tag(C); } /** \} */ -- cgit v1.2.3 From f464cac55a683387ae3511c76d08c8cca0a216c1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 13:53:15 +1000 Subject: Cleanup: redundant update calls adding objects These update calls are already performed by ED_object_add_type_with_obdata. --- source/blender/editors/object/object_add.c | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 34400462d38..2e34284f46e 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -766,8 +766,6 @@ static int lightprobe_add_exec(bContext *C, wmOperator *op) BKE_lightprobe_type_set(probe, type); - DEG_relations_tag_update(CTX_data_main(C)); - return OPERATOR_FINISHED; } @@ -884,8 +882,6 @@ static int effector_add_exec(bContext *C, wmOperator *op) ob->pd = BKE_partdeflect_new(type); - DEG_relations_tag_update(CTX_data_main(C)); - return OPERATOR_FINISHED; } @@ -1015,8 +1011,10 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) if (newob && !enter_editmode) { ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA); } - - WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); + else { + /* Only needed in edit-mode (#ED_object_add_type normally handles this). */ + WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); + } return OPERATOR_FINISHED; } @@ -1067,8 +1065,6 @@ static int object_add_text_exec(bContext *C, wmOperator *op) obedit = ED_object_add_type(C, OB_FONT, NULL, loc, rot, enter_editmode, local_view_bits); BKE_object_obdata_size_init(obedit, RNA_float_get(op->ptr, "radius")); - WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); - return OPERATOR_FINISHED; } @@ -1138,8 +1134,6 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA); } - WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); - return OPERATOR_FINISHED; } @@ -1670,7 +1664,6 @@ static int collection_instance_add_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); /* Avoid dependency cycles. */ @@ -1686,12 +1679,6 @@ static int collection_instance_add_exec(bContext *C, wmOperator *op) ob->transflag |= OB_DUPLICOLLECTION; id_us_plus(&collection->id); - /* works without this except if you try render right after, see: 22027 */ - DEG_relations_tag_update(bmain); - DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); - WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene); - return OPERATOR_FINISHED; } @@ -1784,17 +1771,9 @@ static int object_data_instance_add_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - Scene *scene = CTX_data_scene(C); - ED_object_add_type_with_obdata( C, object_type, id->name + 2, loc, rot, false, local_view_bits, id); - /* Works without this except if you try render right after, see: T22027. */ - DEG_relations_tag_update(bmain); - DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); - WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene); - return OPERATOR_FINISHED; } -- cgit v1.2.3 From 082ddc9379b2bdc963635c1109fbd6c6bce91eed Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 16:02:31 +1000 Subject: ToolSystem: support per-tool gizmo group properties Also add gizmo group example to the tool-template. --- release/scripts/modules/bl_keymap_utils/io.py | 36 ++++++++-------- release/scripts/modules/bpy/utils/__init__.py | 1 + .../startup/bl_ui/space_toolsystem_common.py | 40 +++++++++++++++++- release/scripts/templates_py/ui_tool_simple.py | 24 +++++++++++ .../space_view3d/view3d_gizmo_tool_generic.c | 48 ++++++++++++++++++++-- 5 files changed, 128 insertions(+), 21 deletions(-) diff --git a/release/scripts/modules/bl_keymap_utils/io.py b/release/scripts/modules/bl_keymap_utils/io.py index 7adcd799c0f..96832cbd9c7 100644 --- a/release/scripts/modules/bl_keymap_utils/io.py +++ b/release/scripts/modules/bl_keymap_utils/io.py @@ -22,6 +22,7 @@ # Export Functions __all__ = ( + "_init_properties_from_data", # Shared with gizmo default property initialization. "keyconfig_export_as_data", "keyconfig_import_from_data", "keyconfig_init_from_data", @@ -244,20 +245,24 @@ def keyconfig_export_as_data(wm, kc, filepath, *, all_keymaps=False): # ----------------------------------------------------------------------------- # Import Functions - -def _kmi_props_setattr(kmi_props, attr, value): - if type(value) is list: - kmi_subprop = getattr(kmi_props, attr) - for subattr, subvalue in value: - _kmi_props_setattr(kmi_subprop, subattr, subvalue) - return - - try: - setattr(kmi_props, attr, value) - except AttributeError: - print(f"Warning: property '{attr}' not found in keymap item '{kmi_props.__class__.__name__}'") - except Exception as ex: - print(f"Warning: {ex!r}") +# +# NOTE: unlike export, this runs on startup. +# Take care making changes that could impact performance. + +def _init_properties_from_data(base_props, base_value): + assert(type(base_value) is list) + for attr, value in base_value: + if type(value) is list: + base_props.property_unset(attr) + props = getattr(base_props, attr) + _init_properties_from_data(props, value) + else: + try: + setattr(base_props, attr, value) + except AttributeError: + print(f"Warning: property '{attr}' not found in item '{base_props.__class__.__name__}'") + except Exception as ex: + print(f"Warning: {ex!r}") def keymap_init_from_data(km, km_items, is_modal=False): @@ -271,8 +276,7 @@ def keymap_init_from_data(km, km_items, is_modal=False): if kmi_props_data is not None: kmi_props = kmi.properties assert type(kmi_props_data) is list - for attr, value in kmi_props_data: - _kmi_props_setattr(kmi_props, attr, value) + _init_properties_from_data(kmi_props, kmi_props_data) def keyconfig_init_from_data(kc, keyconfig_data): diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py index 1fe73f50639..afa04a18ef6 100644 --- a/release/scripts/modules/bpy/utils/__init__.py +++ b/release/scripts/modules/bpy/utils/__init__.py @@ -859,6 +859,7 @@ def register_tool(tool_cls, *, after=None, separator=False, group=False): "icon": getattr(tool_cls, "bl_icon", None), "cursor": getattr(tool_cls, "bl_cursor", None), "widget": getattr(tool_cls, "bl_widget", None), + "widget_properties": getattr(tool_cls, "bl_widget_properties", None), "keymap": getattr(tool_cls, "bl_keymap", None), "data_block": getattr(tool_cls, "bl_data_block", None), "operator": getattr(tool_cls, "bl_operator", None), diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index cde430c1e6f..74e0f242299 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -75,6 +75,8 @@ ToolDef = namedtuple( "icon", # An optional cursor to use when this tool is active. "cursor", + # The properties to use for the widget. + "widget_properties", # An optional gizmo group to activate when the tool is set or None for no gizmo. "widget", # Optional key-map for tool, possible values are: @@ -132,6 +134,7 @@ def from_dict(kw_args): "icon": None, "cursor": None, "widget": None, + "widget_properties": None, "keymap": None, "data_block": None, "operator": None, @@ -939,6 +942,21 @@ class WM_MT_toolsystem_submenu(Menu): ).name = item.idname +def _kmi_props_setattr(kmi_props, attr, value): + if type(value) is list: + kmi_subprop = getattr(kmi_props, attr) + for subattr, subvalue in value: + _kmi_props_setattr(kmi_subprop, subattr, subvalue) + return + + try: + setattr(kmi_props, attr, value) + except AttributeError: + print(f"Warning: property '{attr}' not found in keymap item '{kmi_props.__class__.__name__}'") + except Exception as ex: + print(f"Warning: {ex!r}") + + def _activate_by_item(context, space_type, item, index, *, as_fallback=False): cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type) tool = ToolSelectPanelHelper._tool_active_from_context(context, space_type, create=True) @@ -983,11 +1001,13 @@ def _activate_by_item(context, space_type, item, index, *, as_fallback=False): item_fallback, _index = cls._tool_get_active_by_index(context, select_index) # End calculating fallback. + gizmo_group = item.widget or "" + tool.setup( idname=item.idname, keymap=item.keymap[0] if item.keymap is not None else "", cursor=item.cursor or 'DEFAULT', - gizmo_group=item.widget or "", + gizmo_group=gizmo_group, data_block=item.data_block or "", operator=item.operator or "", index=index, @@ -995,6 +1015,24 @@ def _activate_by_item(context, space_type, item, index, *, as_fallback=False): keymap_fallback=(item_fallback and item_fallback.keymap and item_fallback.keymap[0]) or "", ) + if ( + (gizmo_group != "") and + (props := tool.gizmo_group_properties(gizmo_group)) + ): + if props is None: + print("Error:", gizmo_group, "could not access properties!") + else: + for key in props.bl_rna.properties.keys(): + props.property_unset(key) + + gizmo_properties = item.widget_properties + if gizmo_properties is not None: + if not isinstance(gizmo_properties, list): + raise Exception("expected a list, not a %r" % type(gizmo_properties)) + + from bl_keymap_utils.io import _init_properties_from_data + _init_properties_from_data(props, gizmo_properties) + WindowManager = bpy.types.WindowManager handle_map = _activate_by_item._cursor_draw_handle diff --git a/release/scripts/templates_py/ui_tool_simple.py b/release/scripts/templates_py/ui_tool_simple.py index fc239093b9c..fa81b3b58a9 100644 --- a/release/scripts/templates_py/ui_tool_simple.py +++ b/release/scripts/templates_py/ui_tool_simple.py @@ -53,14 +53,38 @@ class MyOtherTool(WorkSpaceTool): layout.prop(props, "mode") +class MyWidgetTool(WorkSpaceTool): + bl_space_type = 'VIEW_3D' + bl_context_mode = 'OBJECT' + + bl_idname = "my_template.my_gizmo_translate" + bl_label = "My Gizmo Tool" + bl_description = "Short description" + bl_icon = "ops.transform.translate" + bl_widget="VIEW3D_GGT_tool_generic_handle_free" + bl_widget_properties=[ + ("radius", 75.0), + ("backdrop_fill_alpha", 0.0), + ] + bl_keymap = ( + ("transform.translate", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None), + ) + + def draw_settings(context, layout, tool): + props = tool.operator_properties("transform.translate") + layout.prop(props, "mode") + + def register(): bpy.utils.register_tool(MyTool, after={"builtin.scale_cage"}, separator=True, group=True) bpy.utils.register_tool(MyOtherTool, after={MyTool.bl_idname}) + bpy.utils.register_tool(MyWidgetTool, after={MyTool.bl_idname}) def unregister(): bpy.utils.unregister_tool(MyTool) bpy.utils.unregister_tool(MyOtherTool) + bpy.utils.unregister_tool(MyWidgetTool) if __name__ == "__main__": diff --git a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c index ad91af73a71..0e0d59764e5 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c @@ -36,6 +36,7 @@ #include "WM_toolsystem.h" #include "RNA_access.h" +#include "RNA_define.h" #include "WM_api.h" #include "WM_message.h" @@ -47,6 +48,9 @@ static const char *handle_normal_id; static const char *handle_free_id; +static const float handle_normal_radius_default = 100.0f; +static const float handle_free_radius_default = 36.0f; + /* -------------------------------------------------------------------- */ /** \name Generic Tool * \{ */ @@ -72,6 +76,7 @@ static bool WIDGETGROUP_tool_generic_poll(const bContext *C, wmGizmoGroupType *g static wmGizmo *tool_generic_create_gizmo(const bContext *C, wmGizmoGroup *gzgroup) { + wmGizmo *gz = WM_gizmo_new("GIZMO_GT_button_2d", gzgroup, NULL); gz->flag |= WM_GIZMO_OPERATOR_TOOL_INIT; @@ -82,8 +87,17 @@ static wmGizmo *tool_generic_create_gizmo(const bContext *C, wmGizmoGroup *gzgro RNA_enum_set(gz->ptr, "icon", ICON_NONE); + bToolRef *tref = WM_toolsystem_ref_from_context((bContext *)C); + PointerRNA gzgt_ptr; + const bool gzgt_ptr_is_valid = WM_toolsystem_ref_properties_get_from_gizmo_group( + tref, gzgroup->type, &gzgt_ptr); + if (gzgroup->type->idname == handle_normal_id) { - gz->scale_basis = 0.12f; + const float radius = (gzgt_ptr_is_valid ? RNA_float_get(&gzgt_ptr, "radius") : + handle_normal_radius_default) / + 12.0f; + + gz->scale_basis = radius / U.gizmo_size; gz->matrix_offset[3][2] -= 12.0; RNA_enum_set(gz->ptr, "draw_options", @@ -91,16 +105,20 @@ static wmGizmo *tool_generic_create_gizmo(const bContext *C, wmGizmoGroup *gzgro ED_GIZMO_BUTTON_SHOW_OUTLINE)); } else { - gz->scale_basis = 0.16f * 3; + const float radius = gzgt_ptr_is_valid ? RNA_float_get(&gzgt_ptr, "radius") : + handle_free_radius_default; + + gz->scale_basis = radius / U.gizmo_size; RNA_enum_set(gz->ptr, "draw_options", ED_GIZMO_BUTTON_SHOW_BACKDROP); /* Make the center low alpha. */ WM_gizmo_set_line_width(gz, 2.0f); - RNA_float_set(gz->ptr, "backdrop_fill_alpha", 0.125f); + RNA_float_set(gz->ptr, + "backdrop_fill_alpha", + gzgt_ptr_is_valid ? RNA_float_get(&gzgt_ptr, "backdrop_fill_alpha") : 0.125f); } - bToolRef *tref = WM_toolsystem_ref_from_context((bContext *)C); wmWindowManager *wm = CTX_wm_manager(C); struct wmKeyConfig *kc = wm->defaultconf; @@ -206,6 +224,16 @@ void VIEW3D_GGT_tool_generic_handle_normal(wmGizmoGroupType *gzgt) gzgt->setup = WIDGETGROUP_tool_generic_setup; gzgt->refresh = WIDGETGROUP_tool_generic_refresh; gzgt->message_subscribe = WIDGETGROUP_gizmo_message_subscribe; + + RNA_def_float(gzgt->srna, + "radius", + handle_normal_radius_default, + 0.0f, + 1000.0, + "Radius", + "Radius in pixels", + 0.0f, + 1000.0f); } void VIEW3D_GGT_tool_generic_handle_free(wmGizmoGroupType *gzgt) @@ -224,6 +252,18 @@ void VIEW3D_GGT_tool_generic_handle_free(wmGizmoGroupType *gzgt) gzgt->setup = WIDGETGROUP_tool_generic_setup; gzgt->refresh = WIDGETGROUP_tool_generic_refresh; gzgt->message_subscribe = WIDGETGROUP_gizmo_message_subscribe; + + RNA_def_float(gzgt->srna, + "radius", + handle_free_radius_default, + 0.0f, + 1000.0, + "Radius", + "Radius in pixels", + 0.0f, + 1000.0f); + RNA_def_float( + gzgt->srna, "backdrop_fill_alpha", 0.125, 0.0f, 1.0f, "Backdrop Alpha", "", 0.0f, 1.0f); } /** \} */ -- cgit v1.2.3 From d3514cd6a79e5d3dd6d18665dea29ee3bed0e23a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 16:02:35 +1000 Subject: ToolSystem: increase the inset tool size The inset tool requires moving the cursor towards the center of the selection, making it nearly impossible to use the inset tool when the view was aligned with the vertical handle. Use custom settings for VIEW3D_GGT_tool_generic_handle_free to make it draw hollow, as large as the scale tool. Resolves T87991. --- release/scripts/startup/bl_ui/space_toolsystem_toolbar.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index bde710d8dbf..c5191e80aef 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -824,7 +824,11 @@ class _defs_edit_mesh: idname="builtin.inset_faces", label="Inset Faces", icon="ops.mesh.inset", - widget="VIEW3D_GGT_tool_generic_handle_normal", + widget="VIEW3D_GGT_tool_generic_handle_free", + widget_properties=[ + ("radius", 75.0), + ("backdrop_fill_alpha", 0.0), + ], keymap=(), draw_settings=draw_settings, ) -- cgit v1.2.3 From fe7377809596c5a65e185afeefd500f7474c274b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 16:10:05 +1000 Subject: Cleanup: unused function from 082ddc9379b2bdc963635c1109fbd6c6bce91eed --- release/scripts/startup/bl_ui/space_toolsystem_common.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index 74e0f242299..28549098e51 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -942,21 +942,6 @@ class WM_MT_toolsystem_submenu(Menu): ).name = item.idname -def _kmi_props_setattr(kmi_props, attr, value): - if type(value) is list: - kmi_subprop = getattr(kmi_props, attr) - for subattr, subvalue in value: - _kmi_props_setattr(kmi_subprop, subattr, subvalue) - return - - try: - setattr(kmi_props, attr, value) - except AttributeError: - print(f"Warning: property '{attr}' not found in keymap item '{kmi_props.__class__.__name__}'") - except Exception as ex: - print(f"Warning: {ex!r}") - - def _activate_by_item(context, space_type, item, index, *, as_fallback=False): cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type) tool = ToolSelectPanelHelper._tool_active_from_context(context, space_type, create=True) -- cgit v1.2.3 From 1f2bf2fd73b048e866890a8c7bdfab53c9c0b1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Thu, 26 Aug 2021 10:36:04 +0200 Subject: Cleanup, quiet compile warnings --- intern/cycles/blender/blender_object.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 41871582f66..5d98b61b409 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -376,7 +376,7 @@ static bool lookup_property(BL::ID b_id, const string &name, float4 *r_value) if (type == PROP_FLOAT) value = RNA_property_float_get(&ptr, prop); else if (type == PROP_INT) - value = RNA_property_int_get(&ptr, prop); + value = static_cast(RNA_property_int_get(&ptr, prop)); else return false; @@ -504,14 +504,14 @@ void BlenderSync::sync_procedural(BL::Object &b_ob, procedural_map.used(procedural); } - float current_frame = b_scene.frame_current(); + float current_frame = static_cast(b_scene.frame_current()); if (cache_file.override_frame()) { current_frame = cache_file.frame(); } if (!cache_file.override_frame()) { - procedural->set_start_frame(b_scene.frame_start()); - procedural->set_end_frame(b_scene.frame_end()); + procedural->set_start_frame(static_cast(b_scene.frame_start())); + procedural->set_end_frame(static_cast(b_scene.frame_end())); } procedural->set_frame(current_frame); -- cgit v1.2.3 From ec66b3ef9b02f528e7111c1da2ad19aeda9ab659 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Wed, 25 Aug 2021 15:55:27 +0200 Subject: Fix issues with absolute time unit I think there are the following issues with {rB5fa6cdb77a98}: - if we introduce a PROP_UNIT_TIME_ABSOLUTE unit, shouldnt it be visible to RNA as well? - seems like a double entry sneaked into that commit? This is in preparation to use this for render time limit in cycles-x. ref. T90701 Maniphest Tasks: T90701 Differential Revision: https://developer.blender.org/D12315 --- source/blender/makesrna/intern/rna_rna.c | 3 ++- source/blender/python/intern/bpy_props.c | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index f714987fc05..12fb7a40d13 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -123,7 +123,8 @@ const EnumPropertyItem rna_enum_property_unit_items[] = { {PROP_UNIT_AREA, "AREA", 0, "Area", ""}, {PROP_UNIT_VOLUME, "VOLUME", 0, "Volume", ""}, {PROP_UNIT_ROTATION, "ROTATION", 0, "Rotation", ""}, - {PROP_UNIT_TIME, "TIME", 0, "Time", ""}, + {PROP_UNIT_TIME, "TIME", 0, "Time (Scene Relative)", ""}, + {PROP_UNIT_TIME_ABSOLUTE, "TIME_ABSOLUTE", 0, "Time (Absolute)", ""}, {PROP_UNIT_VELOCITY, "VELOCITY", 0, "Velocity", ""}, {PROP_UNIT_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""}, {PROP_UNIT_MASS, "MASS", 0, "Mass", ""}, diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index a84d920d47d..f89a4809587 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -157,7 +157,6 @@ static const EnumPropertyItem property_subtype_number_items[] = { 0, "Time (Absolute)", "Time specified in seconds, independent of the scene"}, - {PROP_TIME_ABSOLUTE, "TIME_ABSOLUTE", 0, "Time Absolute", ""}, {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""}, {PROP_DISTANCE_CAMERA, "DISTANCE_CAMERA", 0, "Camera Distance", ""}, {PROP_POWER, "POWER", 0, "Power", ""}, -- cgit v1.2.3 From c52db4c4cf526402bded49ae192fbb6e3191e687 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 25 Aug 2021 17:59:41 +0200 Subject: Decouple highlighted tiles from RenderPart Should be no visible change on user side. Preparing for render parts removal as part of Cycles X project. Differential Revision: https://developer.blender.org/D12317 --- source/blender/render/intern/engine.c | 83 ++++++++++++++++++++--------- source/blender/render/intern/pipeline.c | 6 +++ source/blender/render/intern/render_types.h | 8 +++ 3 files changed, 72 insertions(+), 25 deletions(-) diff --git a/source/blender/render/intern/engine.c b/source/blender/render/intern/engine.c index 1510587502b..481a6662cc0 100644 --- a/source/blender/render/intern/engine.c +++ b/source/blender/render/intern/engine.c @@ -291,6 +291,15 @@ static RenderPart *get_part_from_result(Render *re, RenderResult *result) return BLI_ghash_lookup(re->parts, &key); } +static HighlightedTile highlighted_tile_from_result_get(Render *re, RenderResult *result) +{ + HighlightedTile tile; + tile.rect = result->tilerect; + BLI_rcti_translate(&tile.rect, re->disprect.xmin, re->disprect.ymin); + + return tile; +} + RenderResult *RE_engine_begin_result( RenderEngine *engine, int x, int y, int w, int h, const char *layername, const char *viewname) { @@ -426,6 +435,30 @@ void RE_engine_end_result( } } + if (re->engine && (re->engine->flag & RE_ENGINE_HIGHLIGHT_TILES)) { + BLI_mutex_lock(&re->highlighted_tiles_mutex); + + if (re->highlighted_tiles == NULL) { + re->highlighted_tiles = BLI_gset_new( + BLI_ghashutil_inthash_v4_p, BLI_ghashutil_inthash_v4_cmp, "highlighted tiles"); + } + + HighlightedTile tile = highlighted_tile_from_result_get(re, result); + if (highlight) { + void **tile_in_set; + if (!BLI_gset_ensure_p_ex(re->highlighted_tiles, &tile, &tile_in_set)) { + *tile_in_set = MEM_mallocN(sizeof(HighlightedTile), __func__); + memcpy(*tile_in_set, &tile, sizeof(tile)); + } + BLI_gset_add(re->highlighted_tiles, &tile); + } + else { + BLI_gset_remove(re->highlighted_tiles, &tile, MEM_freeN); + } + + BLI_mutex_unlock(&re->highlighted_tiles_mutex); + } + if (!cancel || merge_results) { if (re->result->do_exr_tile) { if (!cancel && merge_results) { @@ -597,43 +630,43 @@ rcti *RE_engine_get_current_tiles(Render *re, int *r_total_tiles, bool *r_needs_ rcti *tiles = tiles_static; int allocation_size = BLENDER_MAX_THREADS; - BLI_rw_mutex_lock(&re->partsmutex, THREAD_LOCK_READ); + BLI_mutex_lock(&re->highlighted_tiles_mutex); *r_needs_free = false; - if (!re->parts || (re->engine && (re->engine->flag & RE_ENGINE_HIGHLIGHT_TILES) == 0)) { + if (re->highlighted_tiles == NULL) { *r_total_tiles = 0; - BLI_rw_mutex_unlock(&re->partsmutex); + BLI_mutex_unlock(&re->highlighted_tiles_mutex); return NULL; } - GHashIterator pa_iter; - GHASH_ITER (pa_iter, re->parts) { - RenderPart *pa = BLI_ghashIterator_getValue(&pa_iter); - if (pa->status == PART_STATUS_IN_PROGRESS) { - if (total_tiles >= allocation_size) { - /* Just in case we're using crazy network rendering with more - * workers than BLENDER_MAX_THREADS. + GSET_FOREACH_BEGIN (HighlightedTile *, tile, re->highlighted_tiles) { + if (total_tiles >= allocation_size) { + /* Just in case we're using crazy network rendering with more + * workers than BLENDER_MAX_THREADS. + */ + allocation_size += allocation_step; + if (tiles == tiles_static) { + /* Can not realloc yet, tiles are pointing to a + * stack memory. */ - allocation_size += allocation_step; - if (tiles == tiles_static) { - /* Can not realloc yet, tiles are pointing to a - * stack memory. - */ - tiles = MEM_mallocN(allocation_size * sizeof(rcti), "current engine tiles"); - } - else { - tiles = MEM_reallocN(tiles, allocation_size * sizeof(rcti)); - } - *r_needs_free = true; + tiles = MEM_mallocN(allocation_size * sizeof(rcti), "current engine tiles"); } - tiles[total_tiles] = pa->disprect; - - total_tiles++; + else { + tiles = MEM_reallocN(tiles, allocation_size * sizeof(rcti)); + } + *r_needs_free = true; } + tiles[total_tiles] = tile->rect; + + total_tiles++; } - BLI_rw_mutex_unlock(&re->partsmutex); + GSET_FOREACH_END(); + + BLI_mutex_unlock(&re->highlighted_tiles_mutex); + *r_total_tiles = total_tiles; + return tiles; } diff --git a/source/blender/render/intern/pipeline.c b/source/blender/render/intern/pipeline.c index 9ef52b4bf41..bf42adbab87 100644 --- a/source/blender/render/intern/pipeline.c +++ b/source/blender/render/intern/pipeline.c @@ -569,6 +569,7 @@ Render *RE_NewRender(const char *name) BLI_strncpy(re->name, name, RE_MAXNAME); BLI_rw_mutex_init(&re->resultmutex); BLI_rw_mutex_init(&re->partsmutex); + BLI_mutex_init(&re->highlighted_tiles_mutex); } RE_InitRenderCB(re); @@ -633,12 +634,17 @@ void RE_FreeRender(Render *re) BLI_rw_mutex_end(&re->resultmutex); BLI_rw_mutex_end(&re->partsmutex); + BLI_mutex_end(&re->highlighted_tiles_mutex); BLI_freelistN(&re->view_layers); BLI_freelistN(&re->r.views); BKE_curvemapping_free_data(&re->r.mblur_shutter_curve); + if (re->highlighted_tiles != NULL) { + BLI_gset_free(re->highlighted_tiles, MEM_freeN); + } + /* main dbase can already be invalid now, some database-free code checks it */ re->main = NULL; re->scene = NULL; diff --git a/source/blender/render/intern/render_types.h b/source/blender/render/intern/render_types.h index 50b684beba9..d2d2b499495 100644 --- a/source/blender/render/intern/render_types.h +++ b/source/blender/render/intern/render_types.h @@ -37,6 +37,7 @@ #include "RE_pipeline.h" struct GHash; +struct GSet; struct Main; struct Object; struct RenderEngine; @@ -59,6 +60,10 @@ typedef struct RenderPart { short status; } RenderPart; +typedef struct HighlightedTile { + rcti rect; +} HighlightedTile; + enum { /* PART_STATUS_NONE = 0, */ /* UNUSED */ PART_STATUS_IN_PROGRESS = 1, @@ -118,6 +123,9 @@ struct Render { ThreadRWMutex partsmutex; struct GHash *parts; + ThreadMutex highlighted_tiles_mutex; + struct GSet *highlighted_tiles; + /* render engine */ struct RenderEngine *engine; -- cgit v1.2.3 From 1434ac37674cca0a5fd2802966b53b52dab3ac58 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 20:32:17 +1000 Subject: Cleanup: add ATTR_WARN_UNUSED_RESULT to BLI_string_utf8.h --- source/blender/blenlib/BLI_string_utf8.h | 83 ++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index b97c8748ca4..a9cb13a3277 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -28,77 +28,88 @@ extern "C" { #endif char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy) - ATTR_NONNULL(); -size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy) - ATTR_NONNULL(); -ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL(); -int BLI_str_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL(); + ATTR_NONNULL(1, 2); +size_t BLI_strncpy_utf8_rlen(char *__restrict dst, + const char *__restrict src, + size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); +ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t length) ATTR_NONNULL(1); +int BLI_str_utf8_invalid_strip(char *str, size_t length) ATTR_NONNULL(1); /* warning, can return -1 on bad chars */ -int BLI_str_utf8_size(const char *p) ATTR_NONNULL(); -int BLI_str_utf8_size_safe(const char *p) ATTR_NONNULL(); +int BLI_str_utf8_size(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); +int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /* copied from glib */ -unsigned int BLI_str_utf8_as_unicode(const char *p) ATTR_NONNULL(); +unsigned int BLI_str_utf8_as_unicode(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t p_len, - size_t *__restrict index) ATTR_NONNULL(1, 3); -unsigned int BLI_str_utf8_as_unicode_step_or_error(const char *__restrict p, - size_t p_len, - size_t *__restrict index) ATTR_NONNULL(1, 3); + size_t *__restrict index) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 3); +unsigned int BLI_str_utf8_as_unicode_step_or_error( + const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 3); size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf); size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w, const char *__restrict src_c, - const size_t maxncpy) ATTR_NONNULL(); + const size_t maxncpy) ATTR_NONNULL(1, 2); size_t BLI_str_utf32_as_utf8(char *__restrict dst, const char32_t *__restrict src, - const size_t maxncpy) ATTR_NONNULL(); -size_t BLI_str_utf32_as_utf8_len(const char32_t *src) ATTR_NONNULL(); + const size_t maxncpy) ATTR_NONNULL(1, 2); +size_t BLI_str_utf32_as_utf8_len(const char32_t *src) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); -char *BLI_str_find_prev_char_utf8(const char *str, const char *p) ATTR_NONNULL(); -char *BLI_str_find_next_char_utf8(const char *p, const char *end) ATTR_NONNULL(1); -char *BLI_str_prev_char_utf8(const char *p) ATTR_NONNULL(); +char *BLI_str_find_prev_char_utf8(const char *str, const char *p) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 2); +char *BLI_str_find_next_char_utf8(const char *p, const char *end) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1); +char *BLI_str_prev_char_utf8(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /* wchar_t functions, copied from blenders own font.c originally */ -size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(); -size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) ATTR_NONNULL(); -size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(); +size_t BLI_wstrlen_utf8(const wchar_t *src) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; +size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) + ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; +size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; size_t BLI_strnlen_utf8_ex(const char *strc, const size_t maxlen, size_t *r_len_bytes) - ATTR_NONNULL(); -size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) ATTR_NONNULL(); + ATTR_NONNULL(1, 3); +size_t BLI_strnlen_utf8(const char *strc, const size_t maxlen) + ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, - const size_t maxncpy) ATTR_NONNULL(); + const size_t maxncpy) ATTR_NONNULL(1, 2); size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, - const size_t maxncpy) ATTR_NONNULL(); + const size_t maxncpy) ATTR_NONNULL(1, 2); /* count columns that character/string occupies, based on wcwidth.c */ -int BLI_wcwidth(char32_t ucs); -int BLI_wcswidth(const char32_t *pwcs, size_t n) ATTR_NONNULL(); +int BLI_wcwidth(char32_t ucs) ATTR_WARN_UNUSED_RESULT; +int BLI_wcswidth(const char32_t *pwcs, size_t n) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /* warning, can return -1 on bad chars */ -int BLI_str_utf8_char_width(const char *p) ATTR_NONNULL(); -int BLI_str_utf8_char_width_safe(const char *p) ATTR_NONNULL(); +int BLI_str_utf8_char_width(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); +int BLI_str_utf8_char_width_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); size_t BLI_str_partition_utf8(const char *str, const unsigned int delim[], const char **sep, - const char **suf) ATTR_NONNULL(); + const char **suf) ATTR_NONNULL(1, 2, 3, 4); size_t BLI_str_rpartition_utf8(const char *str, const unsigned int delim[], const char **sep, - const char **suf) ATTR_NONNULL(); + const char **suf) ATTR_NONNULL(1, 2, 3, 4); size_t BLI_str_partition_ex_utf8(const char *str, const char *end, const unsigned int delim[], const char **sep, const char **suf, - const bool from_right) ATTR_NONNULL(1, 3, 4, 5); + const bool from_right) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 3, 4, 5); -int BLI_str_utf8_offset_to_index(const char *str, int offset); -int BLI_str_utf8_offset_from_index(const char *str, int index); -int BLI_str_utf8_offset_to_column(const char *str, int offset); -int BLI_str_utf8_offset_from_column(const char *str, int column); +int BLI_str_utf8_offset_to_index(const char *str, int offset) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1); +int BLI_str_utf8_offset_from_index(const char *str, int index) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1); +int BLI_str_utf8_offset_to_column(const char *str, int offset) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1); +int BLI_str_utf8_offset_from_column(const char *str, int column) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1); #define BLI_UTF8_MAX 6 /* mem */ #define BLI_UTF8_WIDTH_MAX 2 /* columns */ -- cgit v1.2.3 From da17692a3df059bf6810998c4abff74cb741292d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Aug 2021 20:37:51 +1000 Subject: Cleanup: use BLI_UTF8_MAX define --- source/blender/blenlib/intern/string_utf8.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index cc6a192f6ba..e35e2bcca3c 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -297,8 +297,8 @@ size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const size_t maxncpy) { const size_t maxlen = maxncpy - 1; - /* 6 is max utf8 length of an unicode char. */ - const int64_t maxlen_secured = (int64_t)maxlen - 6; + /* #BLI_UTF8_MAX is max utf8 length of an unicode char. */ + const int64_t maxlen_secured = (int64_t)maxlen - BLI_UTF8_MAX; size_t len = 0; BLI_assert(maxncpy != 0); @@ -314,9 +314,9 @@ size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, /* We have to be more careful for the last six bytes, * to avoid buffer overflow in case utf8-encoded char would be too long for our dst buffer. */ while (*src) { - char t[6]; + char t[BLI_UTF8_MAX]; size_t l = BLI_str_utf8_from_unicode((uint)*src++, t); - BLI_assert(l <= 6); + BLI_assert(l <= BLI_UTF8_MAX); if (len + l > maxlen) { break; } @@ -707,8 +707,8 @@ size_t BLI_str_utf32_as_utf8(char *__restrict dst, const size_t maxncpy) { const size_t maxlen = maxncpy - 1; - /* 6 is max utf8 length of an unicode char. */ - const int64_t maxlen_secured = (int64_t)maxlen - 6; + /* #BLI_UTF8_MAX is max utf8 length of an unicode char. */ + const int64_t maxlen_secured = (int64_t)maxlen - BLI_UTF8_MAX; size_t len = 0; BLI_assert(maxncpy != 0); @@ -724,9 +724,9 @@ size_t BLI_str_utf32_as_utf8(char *__restrict dst, /* We have to be more careful for the last six bytes, * to avoid buffer overflow in case utf8-encoded char would be too long for our dst buffer. */ while (*src) { - char t[6]; + char t[BLI_UTF8_MAX]; size_t l = BLI_str_utf8_from_unicode((uint)*src++, t); - BLI_assert(l <= 6); + BLI_assert(l <= BLI_UTF8_MAX); if (len + l > maxlen) { break; } -- cgit v1.2.3 From 2419ffa183702044ff7e8b78fad8862ca313f12d Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 26 Aug 2021 14:35:10 +0200 Subject: Fix T90959: crash when hovering over empty data block socket --- source/blender/editors/space_node/node_draw.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 3b1a55f55ab..b67117f1ad0 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -836,9 +836,8 @@ struct SocketTooltipData { static void create_inspection_string_for_generic_value(const geo_log::GenericValueLog &value_log, std::stringstream &ss) { - auto id_to_inspection_string = [&](ID *id) { - ss << (id ? id->name + 2 : TIP_("None")) << " (" << BKE_idtype_idcode_to_name(GS(id->name)) - << ")"; + auto id_to_inspection_string = [&](ID *id, short idcode) { + ss << (id ? id->name + 2 : TIP_("None")) << " (" << BKE_idtype_idcode_to_name(idcode) << ")"; }; const GPointer value = value_log.value(); @@ -858,16 +857,16 @@ static void create_inspection_string_for_generic_value(const geo_log::GenericVal ss << *value.get() << TIP_(" (String)"); } else if (value.is_type()) { - id_to_inspection_string((ID *)*value.get()); + id_to_inspection_string((ID *)*value.get(), ID_OB); } else if (value.is_type()) { - id_to_inspection_string((ID *)*value.get()); + id_to_inspection_string((ID *)*value.get(), ID_MA); } else if (value.is_type()) { - id_to_inspection_string((ID *)*value.get()); + id_to_inspection_string((ID *)*value.get(), ID_TE); } else if (value.is_type()) { - id_to_inspection_string((ID *)*value.get()); + id_to_inspection_string((ID *)*value.get(), ID_GR); } } -- cgit v1.2.3 From 1bb2077250aed65e9445468161e01aa219a89624 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 25 Aug 2021 11:38:53 +0200 Subject: Add locking fallback atomics implementation Is used for platforms for which we do not have native implementation, such as MIPS, for example. It is possible to test locking implementation on local computer by defining `ATOMIC_FORCE_USE_FALLBACK` in the atomic_ops_unix.h file. Run full regression suit with the locking implementation on amd64 Linux platform and all tests passed. Having non-optimal but working implementation for odd-ball platforms seems to be a better choice than failing the build entirely. Differential Revision: https://developer.blender.org/D12313 --- intern/atomic/intern/atomic_ops_unix.h | 223 +++++++++++++++++++++++++++++--- intern/atomic/intern/atomic_ops_utils.h | 2 + 2 files changed, 205 insertions(+), 20 deletions(-) diff --git a/intern/atomic/intern/atomic_ops_unix.h b/intern/atomic/intern/atomic_ops_unix.h index b08a0e9bc28..dcafbc67949 100644 --- a/intern/atomic/intern/atomic_ops_unix.h +++ b/intern/atomic/intern/atomic_ops_unix.h @@ -60,9 +60,108 @@ # define JE_FORCE_SYNC_COMPARE_AND_SWAP_8 #endif -/******************************************************************************/ -/* 64-bit operations. */ -#if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_8)) +/* Define the `ATOMIC_FORCE_USE_FALLBACK` to force lock-based fallback implementation to be used + * (even on platforms where there is native implementation available via compiler. + * Useful for development purposes. */ +#undef ATOMIC_FORCE_USE_FALLBACK + +/* -------------------------------------------------------------------- */ +/** \name Spin-lock implementation + * + * Used to implement atomics on unsupported platforms. + * The spin implementation is shared for all platforms to make sure it compiles and tested. + * \{ */ + +typedef struct AtomicSpinLock { + volatile int lock; + + /* Pad the structure size to a cache-line, to avoid unwanted sharing with other data. */ + int pad[32 - sizeof(int)]; +} __attribute__((aligned(32))) AtomicSpinLock; + +ATOMIC_INLINE void atomic_spin_lock(volatile AtomicSpinLock *lock) +{ + while (__sync_lock_test_and_set(&lock->lock, 1)) { + while (lock->lock) { + } + } +} + +ATOMIC_INLINE void atomic_spin_unlock(volatile AtomicSpinLock *lock) +{ + __sync_lock_release(&lock->lock); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Common part of locking fallback implementation + * \{ */ + +/* Global lock, shared by all atomic operations implementations. + * + * Could be split into per-size locks, although added complexity and being more error-proone does + * not seem to worth it for a fall-back implementation. */ +static _ATOMIC_MAYBE_UNUSED AtomicSpinLock _atomic_global_lock = {0}; + +#define ATOMIC_LOCKING_OP_AND_FETCH_DEFINE(_type, _op_name, _op) \ + ATOMIC_INLINE _type##_t atomic_##_op_name##_and_fetch_##_type(_type##_t *p, _type##_t x) \ + { \ + atomic_spin_lock(&_atomic_global_lock); \ + const _type##_t original_value = *(p); \ + const _type##_t new_value = original_value _op(x); \ + *(p) = new_value; \ + atomic_spin_unlock(&_atomic_global_lock); \ + return new_value; \ + } + +#define ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, _op_name, _op) \ + ATOMIC_INLINE _type##_t atomic_fetch_and_##_op_name##_##_type(_type##_t *p, _type##_t x) \ + { \ + atomic_spin_lock(&_atomic_global_lock); \ + const _type##_t original_value = *(p); \ + *(p) = original_value _op(x); \ + atomic_spin_unlock(&_atomic_global_lock); \ + return original_value; \ + } + +#define ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE(_type) \ + ATOMIC_LOCKING_OP_AND_FETCH_DEFINE(_type, add, +) + +#define ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE(_type) \ + ATOMIC_LOCKING_OP_AND_FETCH_DEFINE(_type, sub, -) + +#define ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE(_type) \ + ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, add, +) + +#define ATOMIC_LOCKING_FETCH_AND_SUB_DEFINE(_type) \ + ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, sub, -) + +#define ATOMIC_LOCKING_FETCH_AND_OR_DEFINE(_type) ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, or, |) + +#define ATOMIC_LOCKING_FETCH_AND_AND_DEFINE(_type) \ + ATOMIC_LOCKING_FETCH_AND_OP_DEFINE(_type, and, &) + +#define ATOMIC_LOCKING_CAS_DEFINE(_type) \ + ATOMIC_INLINE _type##_t atomic_cas_##_type(_type##_t *v, _type##_t old, _type##_t _new) \ + { \ + atomic_spin_lock(&_atomic_global_lock); \ + const _type##_t original_value = *v; \ + if (*v == old) { \ + *v = _new; \ + } \ + atomic_spin_unlock(&_atomic_global_lock); \ + return original_value; \ + } + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name 64-bit operations + * \{ */ + +#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \ + (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_8)) /* Unsigned */ ATOMIC_INLINE uint64_t atomic_add_and_fetch_uint64(uint64_t *p, uint64_t x) { @@ -115,7 +214,7 @@ ATOMIC_INLINE int64_t atomic_cas_int64(int64_t *v, int64_t old, int64_t _new) return __sync_val_compare_and_swap(v, old, _new); } -#elif (defined(__amd64__) || defined(__x86_64__)) +#elif !defined(ATOMIC_FORCE_USE_FALLBACK) && (defined(__amd64__) || defined(__x86_64__)) /* Unsigned */ ATOMIC_INLINE uint64_t atomic_fetch_and_add_uint64(uint64_t *p, uint64_t x) { @@ -190,12 +289,36 @@ ATOMIC_INLINE int64_t atomic_cas_int64(int64_t *v, int64_t old, int64_t _new) return ret; } #else -# error "Missing implementation for 64-bit atomic operations" + +/* Unsigned */ + +ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE(uint64) +ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE(uint64) + +ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE(uint64) +ATOMIC_LOCKING_FETCH_AND_SUB_DEFINE(uint64) + +ATOMIC_LOCKING_CAS_DEFINE(uint64) + +/* Signed */ +ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE(int64) +ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE(int64) + +ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE(int64) +ATOMIC_LOCKING_FETCH_AND_SUB_DEFINE(int64) + +ATOMIC_LOCKING_CAS_DEFINE(int64) + #endif -/******************************************************************************/ -/* 32-bit operations. */ -#if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_4)) +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name 32-bit operations + * \{ */ + +#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \ + (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_4)) /* Unsigned */ ATOMIC_INLINE uint32_t atomic_add_and_fetch_uint32(uint32_t *p, uint32_t x) { @@ -228,7 +351,8 @@ ATOMIC_INLINE int32_t atomic_cas_int32(int32_t *v, int32_t old, int32_t _new) return __sync_val_compare_and_swap(v, old, _new); } -#elif (defined(__i386__) || defined(__amd64__) || defined(__x86_64__)) +#elif !defined(ATOMIC_FORCE_USE_FALLBACK) && \ + (defined(__i386__) || defined(__amd64__) || defined(__x86_64__)) /* Unsigned */ ATOMIC_INLINE uint32_t atomic_add_and_fetch_uint32(uint32_t *p, uint32_t x) { @@ -286,10 +410,25 @@ ATOMIC_INLINE int32_t atomic_cas_int32(int32_t *v, int32_t old, int32_t _new) } #else -# error "Missing implementation for 32-bit atomic operations" + +/* Unsigned */ + +ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE(uint32) +ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE(uint32) + +ATOMIC_LOCKING_CAS_DEFINE(uint32) + +/* Signed */ + +ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE(int32) +ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE(int32) + +ATOMIC_LOCKING_CAS_DEFINE(int32) + #endif -#if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_4)) +#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \ + (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_4)) /* Unsigned */ ATOMIC_INLINE uint32_t atomic_fetch_and_add_uint32(uint32_t *p, uint32_t x) { @@ -323,12 +462,27 @@ ATOMIC_INLINE int32_t atomic_fetch_and_and_int32(int32_t *p, int32_t x) } #else -# error "Missing implementation for 32-bit atomic operations" + +/* Unsigned */ +ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE(uint32) +ATOMIC_LOCKING_FETCH_AND_OR_DEFINE(uint32) +ATOMIC_LOCKING_FETCH_AND_AND_DEFINE(uint32) + +/* Signed */ +ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE(int32) +ATOMIC_LOCKING_FETCH_AND_OR_DEFINE(int32) +ATOMIC_LOCKING_FETCH_AND_AND_DEFINE(int32) + #endif -/******************************************************************************/ -/* 16-bit operations. */ -#if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_2)) +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name 16-bit operations + * \{ */ + +#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \ + (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_2)) /* Signed */ ATOMIC_INLINE int16_t atomic_fetch_and_and_int16(int16_t *p, int16_t b) @@ -341,12 +495,21 @@ ATOMIC_INLINE int16_t atomic_fetch_and_or_int16(int16_t *p, int16_t b) } #else -# error "Missing implementation for 16-bit atomic operations" + +ATOMIC_LOCKING_FETCH_AND_AND_DEFINE(int16) +ATOMIC_LOCKING_FETCH_AND_OR_DEFINE(int16) + #endif -/******************************************************************************/ -/* 8-bit operations. */ -#if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_1)) +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name 8-bit operations + * \{ */ + +#if !defined(ATOMIC_FORCE_USE_FALLBACK) && \ + (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_1)) + /* Unsigned */ ATOMIC_INLINE uint8_t atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b) { @@ -368,7 +531,27 @@ ATOMIC_INLINE int8_t atomic_fetch_and_or_int8(int8_t *p, int8_t b) } #else -# error "Missing implementation for 8-bit atomic operations" + +/* Unsigned */ +ATOMIC_LOCKING_FETCH_AND_AND_DEFINE(uint8) +ATOMIC_LOCKING_FETCH_AND_OR_DEFINE(uint8) + +/* Signed */ +ATOMIC_LOCKING_FETCH_AND_AND_DEFINE(int8) +ATOMIC_LOCKING_FETCH_AND_OR_DEFINE(int8) + #endif +/** \} */ + +#undef ATOMIC_LOCKING_OP_AND_FETCH_DEFINE +#undef ATOMIC_LOCKING_FETCH_AND_OP_DEFINE +#undef ATOMIC_LOCKING_ADD_AND_FETCH_DEFINE +#undef ATOMIC_LOCKING_SUB_AND_FETCH_DEFINE +#undef ATOMIC_LOCKING_FETCH_AND_ADD_DEFINE +#undef ATOMIC_LOCKING_FETCH_AND_SUB_DEFINE +#undef ATOMIC_LOCKING_FETCH_AND_OR_DEFINE +#undef ATOMIC_LOCKING_FETCH_AND_AND_DEFINE +#undef ATOMIC_LOCKING_CAS_DEFINE + #endif /* __ATOMIC_OPS_UNIX_H__ */ diff --git a/intern/atomic/intern/atomic_ops_utils.h b/intern/atomic/intern/atomic_ops_utils.h index 57e5b74dd72..01f4284284a 100644 --- a/intern/atomic/intern/atomic_ops_utils.h +++ b/intern/atomic/intern/atomic_ops_utils.h @@ -64,9 +64,11 @@ #ifdef __GNUC__ # define _ATOMIC_LIKELY(x) __builtin_expect(!!(x), 1) # define _ATOMIC_UNLIKELY(x) __builtin_expect(!!(x), 0) +# define _ATOMIC_MAYBE_UNUSED __attribute__((unused)) #else # define _ATOMIC_LIKELY(x) (x) # define _ATOMIC_UNLIKELY(x) (x) +# define _ATOMIC_MAYBE_UNUSED #endif #if defined(__SIZEOF_POINTER__) -- cgit v1.2.3 From edb95b3fcbb907fe4b93fecf9e398f41113b3ee4 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 26 Aug 2021 15:01:14 +0200 Subject: Cleanup: Use `ID_IS_LINKED` instead of direct `id.lib` pointer check. --- source/blender/blenkernel/intern/action.c | 2 +- source/blender/blenkernel/intern/constraint.c | 2 +- source/blender/blenkernel/intern/gpencil.c | 2 +- source/blender/blenkernel/intern/gpencil_modifier.c | 2 +- source/blender/blenkernel/intern/lib_id.c | 14 +++++++------- source/blender/blenkernel/intern/lib_id_delete.c | 2 +- source/blender/blenkernel/intern/lib_override.c | 15 +++++++-------- source/blender/blenkernel/intern/lib_query.c | 2 +- source/blender/blenkernel/intern/modifier.c | 2 +- source/blender/blenkernel/intern/nla.c | 2 +- source/blender/blenkernel/intern/object.c | 2 +- source/blender/blenkernel/intern/scene.c | 2 +- source/blender/blenkernel/intern/shader_fx.c | 2 +- source/blender/blenkernel/intern/undo_system.c | 2 +- source/blender/blenloader/intern/blend_validate.c | 6 +++--- source/blender/blenloader/intern/readfile.c | 2 +- source/blender/blenloader/intern/versioning_280.c | 6 +++--- source/blender/blenloader/intern/writefile.c | 2 +- source/blender/editors/interface/interface_templates.c | 4 ++-- source/blender/editors/interface/interface_utils.c | 2 +- source/blender/editors/space_file/filelist.c | 2 +- source/blender/editors/space_image/image_ops.c | 2 +- source/blender/editors/space_view3d/view3d_gizmo_camera.c | 4 ++-- source/blender/editors/undo/memfile_undo.c | 2 +- source/blender/makesrna/intern/rna_access.c | 2 +- 25 files changed, 43 insertions(+), 44 deletions(-) diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 981815f400a..16d269f9e26 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -1991,7 +1991,7 @@ void BKE_pose_blend_read_lib(BlendLibReader *reader, Object *ob, bPose *pose) if (UNLIKELY(pchan->bone == NULL)) { rebuild = true; } - else if ((ob->id.lib == NULL) && arm->id.lib) { + else if (!ID_IS_LINKED(ob) && ID_IS_LINKED(arm)) { /* local pose selection copied to armature, bit hackish */ pchan->bone->flag &= ~BONE_SELECTED; pchan->bone->flag |= pchan->selectflag; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 30aa22387d0..72f14d94833 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -6657,7 +6657,7 @@ void BKE_constraint_blend_read_lib(BlendLibReader *reader, ID *id, ListBase *con BLO_read_id_address(reader, id->lib, &con->ipo); /* XXX deprecated - old animation system */ /* If linking from a library, clear 'local' library override flag. */ - if (id->lib != NULL) { + if (ID_IS_LINKED(id)) { con->flag &= ~CONSTRAINT_OVERRIDE_LIBRARY_LOCAL; } } diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 9062fd2d39c..a143645c2ee 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -208,7 +208,7 @@ void BKE_gpencil_blend_read_data(BlendDataReader *reader, bGPdata *gpd) BKE_animdata_blend_read_data(reader, gpd->adt); /* Ensure full objectmode for linked grease pencil. */ - if (gpd->id.lib != NULL) { + if (ID_IS_LINKED(gpd)) { gpd->flag &= ~GP_DATA_STROKE_PAINTMODE; gpd->flag &= ~GP_DATA_STROKE_EDITMODE; gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE; diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c index 4db527e5b42..eac6a05d33a 100644 --- a/source/blender/blenkernel/intern/gpencil_modifier.c +++ b/source/blender/blenkernel/intern/gpencil_modifier.c @@ -1025,7 +1025,7 @@ void BKE_gpencil_modifier_blend_read_lib(BlendLibReader *reader, Object *ob) BKE_gpencil_modifiers_foreach_ID_link(ob, BKE_object_modifiers_lib_link_common, reader); /* If linking from a library, clear 'local' library override flag. */ - if (ob->id.lib != NULL) { + if (ID_IS_LINKED(ob)) { LISTBASE_FOREACH (GpencilModifierData *, mod, &ob->greasepencil_modifiers) { mod->flag &= ~eGpencilModifierFlag_OverrideLibrary_Local; } diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c index aa458bc1b27..11e9053df43 100644 --- a/source/blender/blenkernel/intern/lib_id.c +++ b/source/blender/blenkernel/intern/lib_id.c @@ -970,7 +970,7 @@ void BKE_main_id_repair_duplicate_names_listbase(ListBase *lb) { int lb_len = 0; LISTBASE_FOREACH (ID *, id, lb) { - if (id->lib == NULL) { + if (!ID_IS_LINKED(id)) { lb_len += 1; } } @@ -983,7 +983,7 @@ void BKE_main_id_repair_duplicate_names_listbase(ListBase *lb) GSet *gset = BLI_gset_str_new_ex(__func__, lb_len); int i = 0; LISTBASE_FOREACH (ID *, id, lb) { - if (id->lib == NULL) { + if (!ID_IS_LINKED(id)) { id_array[i] = id; i++; } @@ -1840,7 +1840,7 @@ static void library_make_local_copying_check(ID *id, from_id = ((Key *)from_id)->from; } - if (from_id->lib == NULL) { + if (!ID_IS_LINKED(from_id)) { /* Local user, early out to avoid some gset querying... */ continue; } @@ -2068,7 +2068,7 @@ void BKE_library_make_local(Main *bmain, ID *id = it->link; BLI_assert(id->newid != NULL); - BLI_assert(id->lib != NULL); + BLI_assert(ID_IS_LINKED(id)); BKE_libblock_remap(bmain, id, id->newid, ID_REMAP_SKIP_INDIRECT_USAGE); if (old_to_new_ids) { @@ -2103,7 +2103,7 @@ void BKE_library_make_local(Main *bmain, bool is_local = false, is_lib = false; /* Proxies only work when the proxified object is linked-in from a library. */ - if (ob->proxy->id.lib == NULL) { + if (!ID_IS_LINKED(ob->proxy)) { CLOG_WARN(&LOG, "proxy object %s will lose its link to %s, because the " "proxified object is local.", @@ -2221,7 +2221,7 @@ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id, char separa { strcpy(name, id->name + 2); - if (id->lib != NULL) { + if (ID_IS_LINKED(id)) { const size_t idname_len = strlen(id->name + 2); const size_t libname_len = strlen(id->lib->id.name + 2); @@ -2274,7 +2274,7 @@ void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], */ char *BKE_id_to_unique_string_key(const struct ID *id) { - if (id->lib == NULL) { + if (!ID_IS_LINKED(id)) { return BLI_strdup(id->name); } diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index 43afac5a376..79717fe5f48 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -219,7 +219,7 @@ void BKE_id_free_us(Main *bmain, void *idv) /* test users */ * Otherwise, there is no real way to get rid of an object anymore - * better handling of this is TODO. */ - if ((GS(id->name) == ID_OB) && (id->us == 1) && (id->lib == NULL)) { + if ((GS(id->name) == ID_OB) && (id->us == 1) && !ID_IS_LINKED(id)) { id_us_clear_real(id); } diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c index 8083585b594..8c1e04838df 100644 --- a/source/blender/blenkernel/intern/lib_override.c +++ b/source/blender/blenkernel/intern/lib_override.c @@ -104,7 +104,7 @@ IDOverrideLibrary *BKE_lib_override_library_init(ID *local_id, ID *reference_id) { /* If reference_id is NULL, we are creating an override template for purely local data. * Else, reference *must* be linked data. */ - BLI_assert(reference_id == NULL || reference_id->lib != NULL); + BLI_assert(reference_id == NULL || ID_IS_LINKED(reference_id)); BLI_assert(local_id->override_library == NULL); ID *ancestor_id; @@ -286,7 +286,7 @@ ID *BKE_lib_override_library_create_from_id(Main *bmain, const bool do_tagged_remap) { BLI_assert(reference_id != NULL); - BLI_assert(reference_id->lib != NULL); + BLI_assert(ID_IS_LINKED(reference_id)); ID *local_id = lib_override_library_create_from(bmain, reference_id, 0); @@ -299,7 +299,7 @@ ID *BKE_lib_override_library_create_from_id(Main *bmain, ID *other_id; FOREACH_MAIN_ID_BEGIN (bmain, other_id) { - if ((other_id->tag & LIB_TAG_DOIT) != 0 && other_id->lib == NULL) { + if ((other_id->tag & LIB_TAG_DOIT) != 0 && !ID_IS_LINKED(other_id)) { /* Note that using ID_REMAP_SKIP_INDIRECT_USAGE below is superfluous, as we only remap * local IDs usages anyway. */ BKE_libblock_relink_ex(bmain, @@ -830,7 +830,7 @@ static void lib_override_library_create_post_process(Main *bmain, Collection *default_instantiating_collection = residual_storage; LISTBASE_FOREACH (Object *, ob, &bmain->objects) { Object *ob_new = (Object *)ob->id.newid; - if (ob_new == NULL || ob_new->id.lib != NULL) { + if (ob_new == NULL || ID_IS_LINKED(ob_new)) { continue; } @@ -1148,7 +1148,7 @@ bool BKE_lib_override_library_resync(Main *bmain, /* We need to 'move back' newly created override into its proper library (since it was * duplicated from the reference ID with 'no main' option, it should currently be the same * as the reference ID one). */ - BLI_assert(/*id_override_new->lib == NULL || */ id_override_new->lib == id->lib); + BLI_assert(/*!ID_IS_LINKED(id_override_new) || */ id_override_new->lib == id->lib); BLI_assert(id_override_old == NULL || id_override_old->lib == id_root->lib); id_override_new->lib = id_root->lib; /* Remap step below will tag directly linked ones properly as needed. */ @@ -1734,8 +1734,7 @@ void BKE_lib_override_library_main_resync(Main *bmain, #define OVERRIDE_RESYNC_RESIDUAL_STORAGE_NAME "OVERRIDE_RESYNC_LEFTOVERS" Collection *override_resync_residual_storage = BLI_findstring( &bmain->collections, OVERRIDE_RESYNC_RESIDUAL_STORAGE_NAME, offsetof(ID, name) + 2); - if (override_resync_residual_storage != NULL && - override_resync_residual_storage->id.lib != NULL) { + if (override_resync_residual_storage != NULL && ID_IS_LINKED(override_resync_residual_storage)) { override_resync_residual_storage = NULL; } if (override_resync_residual_storage == NULL) { @@ -2195,7 +2194,7 @@ void BKE_lib_override_library_validate(Main *UNUSED(bmain), ID *id, ReportList * id->override_library->reference = NULL; return; } - if (id->override_library->reference->lib == NULL) { + if (!ID_IS_LINKED(id->override_library->reference)) { /* Very serious data corruption, cannot do much about it besides removing the reference * (therefore making the id a local override template one only). */ BKE_reportf(reports, diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c index 9400458376d..36cbf35b251 100644 --- a/source/blender/blenkernel/intern/lib_query.c +++ b/source/blender/blenkernel/intern/lib_query.c @@ -845,7 +845,7 @@ void BKE_library_indirectly_used_data_tag_clear(Main *bmain) while (i--) { LISTBASE_FOREACH (ID *, id, lb_array[i]) { - if (id->lib == NULL || id->tag & LIB_TAG_DOIT) { + if (!ID_IS_LINKED(id) || id->tag & LIB_TAG_DOIT) { /* Local or non-indirectly-used ID (so far), no need to check it further. */ continue; } diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 821ca7b98b3..b328a31cda5 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -1573,7 +1573,7 @@ void BKE_modifier_blend_read_lib(BlendLibReader *reader, Object *ob) BKE_modifiers_foreach_ID_link(ob, BKE_object_modifiers_lib_link_common, reader); /* If linking from a library, clear 'local' library override flag. */ - if (ob->id.lib != NULL) { + if (ID_IS_LINKED(ob)) { LISTBASE_FOREACH (ModifierData *, mod, &ob->modifiers) { mod->flag &= ~eModifierFlag_OverrideLibrary_Local; } diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 7ea0d991f4c..4ce2ae3c11f 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -2344,7 +2344,7 @@ void BKE_nla_blend_read_lib(BlendLibReader *reader, ID *id, ListBase *tracks) /* we only care about the NLA strips inside the tracks */ LISTBASE_FOREACH (NlaTrack *, nlt, tracks) { /* If linking from a library, clear 'local' library override flag. */ - if (id->lib != NULL) { + if (ID_IS_LINKED(id)) { nlt->flag &= ~NLATRACK_OVERRIDELIBRARY_LOCAL; } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 6e26ed4925d..c91cf6ed926 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -864,7 +864,7 @@ static void object_blend_read_lib(BlendLibReader *reader, ID *id) BLO_read_id_address(reader, ob->id.lib, &ob->proxy); if (ob->proxy) { /* paranoia check, actually a proxy_from pointer should never be written... */ - if (ob->proxy->id.lib == NULL) { + if (!ID_IS_LINKED(ob->proxy)) { ob->proxy->proxy_from = NULL; ob->proxy = NULL; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index de82f0832d8..6b5c94a2786 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -3356,7 +3356,7 @@ static char *scene_undo_depsgraph_gen_key(Scene *scene, ViewLayer *view_layer, c } size_t key_full_offset = BLI_strncpy_rlen(key_full, scene->id.name, MAX_ID_NAME); - if (scene->id.lib != NULL) { + if (ID_IS_LINKED(scene)) { key_full_offset += BLI_strncpy_rlen( key_full + key_full_offset, scene->id.lib->filepath, FILE_MAX); } diff --git a/source/blender/blenkernel/intern/shader_fx.c b/source/blender/blenkernel/intern/shader_fx.c index 29cbe05f4d1..12017907038 100644 --- a/source/blender/blenkernel/intern/shader_fx.c +++ b/source/blender/blenkernel/intern/shader_fx.c @@ -326,7 +326,7 @@ void BKE_shaderfx_blend_read_lib(BlendLibReader *reader, Object *ob) BKE_shaderfx_foreach_ID_link(ob, BKE_object_modifiers_lib_link_common, reader); /* If linking from a library, clear 'local' library override flag. */ - if (ob->id.lib != NULL) { + if (ID_IS_LINKED(ob)) { LISTBASE_FOREACH (ShaderFxData *, fx, &ob->shader_fx) { fx->flag &= ~eShaderFxFlag_OverrideLibrary_Local; } diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c index e524bd254bb..0ca2b97b4ef 100644 --- a/source/blender/blenkernel/intern/undo_system.c +++ b/source/blender/blenkernel/intern/undo_system.c @@ -145,7 +145,7 @@ static void undosys_id_ref_resolve(void *user_data, UndoRefID *id_ref) Main *bmain = user_data; ListBase *lb = which_libbase(bmain, GS(id_ref->name)); LISTBASE_FOREACH (ID *, id, lb) { - if (STREQ(id_ref->name, id->name) && (id->lib == NULL)) { + if (STREQ(id_ref->name, id->name) && !ID_IS_LINKED(id)) { id_ref->ptr = id; break; } diff --git a/source/blender/blenloader/intern/blend_validate.c b/source/blender/blenloader/intern/blend_validate.c index 5b093223fda..7d641d976e3 100644 --- a/source/blender/blenloader/intern/blend_validate.c +++ b/source/blender/blenloader/intern/blend_validate.c @@ -64,7 +64,7 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports) int i = set_listbasepointers(bmain, lbarray); while (i--) { for (ID *id = lbarray[i]->first; id != NULL; id = id->next) { - if (id->lib != NULL) { + if (ID_IS_LINKED(id)) { is_valid = false; BKE_reportf(reports, RPT_ERROR, @@ -115,7 +115,7 @@ bool BLO_main_validate_libraries(Main *bmain, ReportList *reports) int totnames = 0; LinkNode *names = BLO_blendhandle_get_datablock_names(bh, GS(id->name), false, &totnames); for (; id != NULL; id = id->next) { - if (id->lib == NULL) { + if (!ID_IS_LINKED(id)) { is_valid = false; BKE_reportf(reports, RPT_ERROR, @@ -179,7 +179,7 @@ bool BLO_main_validate_shapekeys(Main *bmain, ReportList *reports) if (!BKE_key_idtype_support(GS(id->name))) { break; } - if (id->lib == NULL) { + if (!ID_IS_LINKED(id)) { /* We assume lib data is valid... */ Key *shapekey = BKE_key_from_id(id); if (shapekey != NULL && shapekey->from != id) { diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 2ee66206878..3e9ea8db758 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1625,7 +1625,7 @@ static void change_link_placeholder_to_real_ID_pointer(ListBase *mainlist, void blo_clear_proxy_pointers_from_lib(Main *oldmain) { LISTBASE_FOREACH (Object *, ob, &oldmain->objects) { - if (ob->id.lib != NULL && ob->proxy_from != NULL && ob->proxy_from->id.lib == NULL) { + if (ID_IS_LINKED(ob) && ob->proxy_from != NULL && !ID_IS_LINKED(ob->proxy_from)) { ob->proxy_from = NULL; } } diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index f77d0361e51..2598c53a5e0 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -444,7 +444,7 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) Collection *collection = BKE_collection_add(bmain, collection_master, name); collection->id.lib = scene->id.lib; - if (collection->id.lib != NULL) { + if (ID_IS_LINKED(collection)) { collection->id.tag |= LIB_TAG_INDIRECT; } collections[layer] = collection; @@ -574,10 +574,10 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene) static void do_version_collection_propagate_lib_to_children(Collection *collection) { - if (collection->id.lib != NULL) { + if (ID_IS_LINKED(collection)) { for (CollectionChild *collection_child = collection->children.first; collection_child != NULL; collection_child = collection_child->next) { - if (collection_child->collection->id.lib == NULL) { + if (!ID_IS_LINKED(collection_child->collection)) { collection_child->collection->id.lib = collection->id.lib; } do_version_collection_propagate_lib_to_children(collection_child->collection); diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 90d58514eb5..56ff7151cb1 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -840,7 +840,7 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) current_screen_compat(mainvar, false, &curscreen, &curscene, &view_layer); LISTBASE_FOREACH (Scene *, sce, &mainvar->scenes) { - if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) { + if (!ID_IS_LINKED(sce) && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) { RenderInfo data; data.sfra = sce->r.sfra; data.efra = sce->r.efra; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 0e5a6a79137..08d78552710 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -397,7 +397,7 @@ static bool id_search_add(const bContext *C, TemplateID *template_ui, uiSearchIt char name_ui[MAX_ID_FULL_NAME_UI]; int iconid = ui_id_icon_get(C, id, template_ui->preview); const bool use_lib_prefix = template_ui->preview || iconid; - const bool has_sep_char = (id->lib != NULL); + const bool has_sep_char = ID_IS_LINKED(id); /* When using previews, the library hint (linked, overridden, missing) is added with a * character prefix, otherwise we can use a icon. */ @@ -1112,7 +1112,7 @@ static void template_ID(const bContext *C, UI_but_flag_enable(but, UI_BUT_REDALERT); } - if (id->lib == NULL && !(ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_OB, ID_WS)) && + if (!ID_IS_LINKED(id) && !(ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_OB, ID_WS)) && (hide_buttons == false)) { uiDefIconButR(block, UI_BTYPE_ICON_TOGGLE, diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 93a790b53d0..1a41dc8e9fb 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -535,7 +535,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C, BLI_STATIC_ASSERT(sizeof(name_buf) >= MAX_ID_FULL_NAME_UI, "Name string buffer should be big enough to hold full UI ID name"); name = name_buf; - has_sep_char = (id->lib != NULL); + has_sep_char = ID_IS_LINKED(id); } } else { diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 1a53d25ad39..c7d23943b6c 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -3055,7 +3055,7 @@ static void filelist_readjob_main_recursive(Main *bmain, FileList *filelist) ok = 1; if (ok) { if (!(filelist->filter_data.flags & FLF_HIDE_DOT) || id->name[2] != '.') { - if (id->lib == NULL) { + if (!ID_IS_LINKED(id)) { files->entry->relpath = BLI_strdup(id->name + 2); } else { diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 4f8feda3911..11efd3e33ef 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -2338,7 +2338,7 @@ int ED_image_save_all_modified_info(const Main *bmain, ReportList *reports) if (image_should_be_saved(ima, &is_format_writable)) { if (BKE_image_has_packedfile(ima) || (ima->source == IMA_SRC_GENERATED)) { - if (ima->id.lib == NULL) { + if (!ID_IS_LINKED(ima)) { num_saveable_images++; } else { diff --git a/source/blender/editors/space_view3d/view3d_gizmo_camera.c b/source/blender/editors/space_view3d/view3d_gizmo_camera.c index e1d439bef15..30b9839935f 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_camera.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_camera.c @@ -75,7 +75,7 @@ static bool WIDGETGROUP_camera_poll(const bContext *C, wmGizmoGroupType *UNUSED( if (ob->type == OB_CAMERA) { Camera *camera = ob->data; /* TODO: support overrides. */ - if (camera->id.lib == NULL) { + if (!ID_IS_LINKED(camera)) { return true; } } @@ -408,7 +408,7 @@ static bool WIDGETGROUP_camera_view_poll(const bContext *C, wmGizmoGroupType *UN if (rv3d->persp == RV3D_CAMOB) { if (scene->r.mode & R_BORDER) { /* TODO: support overrides. */ - if (scene->id.lib == NULL) { + if (!ID_IS_LINKED(scene)) { return true; } } diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c index 7c6ce56eab0..1bdc2b2251e 100644 --- a/source/blender/editors/undo/memfile_undo.c +++ b/source/blender/editors/undo/memfile_undo.c @@ -116,7 +116,7 @@ static int memfile_undosys_step_id_reused_cb(LibraryIDLinkCallbackData *cb_data) BLI_assert((id_self->tag & LIB_TAG_UNDO_OLD_ID_REUSED) != 0); ID *id = *id_pointer; - if (id != NULL && id->lib == NULL && (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) == 0) { + if (id != NULL && !ID_IS_LINKED(id) && (id->tag & LIB_TAG_UNDO_OLD_ID_REUSED) == 0) { bool do_stop_iter = true; if (GS(id_self->name) == ID_OB) { Object *ob_self = (Object *)id_self; diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index c838032f1bb..8fa2d0ed849 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -6151,7 +6151,7 @@ char *RNA_path_full_ID_py(Main *bmain, ID *id) } char lib_filepath_esc[(sizeof(id->lib->filepath) * 2) + 4]; - if (id->lib != NULL) { + if (ID_IS_LINKED(id)) { int ofs = 0; memcpy(lib_filepath_esc, ", \"", 3); ofs += 3; -- cgit v1.2.3 From 06a60fe9f70061cd28af3ffcbf075273225d54b2 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 26 Aug 2021 13:02:52 -0300 Subject: PyAPI: GPU: expose clip distances Now you can get a shader that uses Clip Planes and set the number of Clip Distanes with `gpu.state.clip_distances_set(value)`. --- source/blender/python/gpu/gpu_py_shader.c | 39 +++++++++++++++++++++++++------ source/blender/python/gpu/gpu_py_state.c | 26 +++++++++++++++++++++ 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index 145586d8ab0..c7b59ee0d6e 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -70,6 +70,12 @@ static const struct PyC_StringEnumItems pygpu_shader_builtin_items[] = { {0, NULL}, }; +static const struct PyC_StringEnumItems pygpu_shader_config_items[] = { + {GPU_SHADER_CFG_DEFAULT, "DEFAULT"}, + {GPU_SHADER_CFG_CLIPPED, "CLIPPED"}, + {0, NULL}, +}; + static int pygpu_shader_uniform_location_get(GPUShader *shader, const char *name, const char *error_prefix) @@ -711,29 +717,48 @@ static PyObject *pygpu_shader_unbind(BPyGPUShader *UNUSED(self)) } PyDoc_STRVAR(pygpu_shader_from_builtin_doc, - ".. function:: from_builtin(pygpu_shader_name)\n" + ".. function:: from_builtin(shader_name, config='DEFAULT')\n" "\n" " Shaders that are embedded in the blender internal code.\n" " They all read the uniform ``mat4 ModelViewProjectionMatrix``,\n" " which can be edited by the :mod:`gpu.matrix` module.\n" + " You can also choose a shader configuration that uses clip_planes by setting the " + "``CLIPPED`` value to the config parameter. Note that in this case you also need to " + "manually set the value of ``ModelMatrix``.\n" + "\n" " For more details, you can check the shader code with the\n" " :func:`gpu.shader.code_from_builtin` function.\n" "\n" - " :param pygpu_shader_name: One of these builtin shader names:\n" + " :param shader_name: One of these builtin shader names:\n" "\n" PYDOC_BUILTIN_SHADER_LIST - " :type pygpu_shader_name: str\n" + " :type shader_name: str\n" + " :param config: One of these types of shader configuration:\n" + " - ``DEFAULT``\n" + " - ``CLIPPED``\n" + " :type config: str\n" " :return: Shader object corresponding to the given name.\n" " :rtype: :class:`bpy.types.GPUShader`\n"); -static PyObject *pygpu_shader_from_builtin(PyObject *UNUSED(self), PyObject *arg) +static PyObject *pygpu_shader_from_builtin(PyObject *UNUSED(self), PyObject *args, PyObject *kwds) { BPYGPU_IS_INIT_OR_ERROR_OBJ; struct PyC_StringEnum pygpu_bultinshader = {pygpu_shader_builtin_items}; - if (!PyC_ParseStringEnum(arg, &pygpu_bultinshader)) { + struct PyC_StringEnum pygpu_config = {pygpu_shader_config_items, GPU_SHADER_CFG_DEFAULT}; + + static const char *_keywords[] = {"shader_name", "config", NULL}; + static _PyArg_Parser _parser = {"O&|$O&:from_builtin", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast(args, + kwds, + &_parser, + PyC_ParseStringEnum, + &pygpu_bultinshader, + PyC_ParseStringEnum, + &pygpu_config)) { return NULL; } - GPUShader *shader = GPU_shader_get_builtin_shader(pygpu_bultinshader.value_found); + GPUShader *shader = GPU_shader_get_builtin_shader_with_config(pygpu_bultinshader.value_found, + pygpu_config.value_found); return BPyGPUShader_CreatePyObject(shader, true); } @@ -788,7 +813,7 @@ static struct PyMethodDef pygpu_shader_module__tp_methods[] = { {"unbind", (PyCFunction)pygpu_shader_unbind, METH_NOARGS, pygpu_shader_unbind_doc}, {"from_builtin", (PyCFunction)pygpu_shader_from_builtin, - METH_O, + METH_VARARGS | METH_KEYWORDS, pygpu_shader_from_builtin_doc}, {"code_from_builtin", (PyCFunction)pygpu_shader_code_from_builtin, diff --git a/source/blender/python/gpu/gpu_py_state.c b/source/blender/python/gpu/gpu_py_state.c index 7b7a61cc338..757c787882b 100644 --- a/source/blender/python/gpu/gpu_py_state.c +++ b/source/blender/python/gpu/gpu_py_state.c @@ -123,6 +123,28 @@ static PyObject *pygpu_state_blend_get(PyObject *UNUSED(self)) return PyUnicode_FromString(PyC_StringEnum_FindIDFromValue(pygpu_state_blend_items, blend)); } +PyDoc_STRVAR(pygpu_state_clip_distances_set_doc, + ".. function:: clip_distances_set(distances_enabled)\n" + "\n" + " Sets number of `gl_ClipDistance`s that will be used for clip geometry.\n" + "\n" + " :param distances_enabled: Number of clip distances enabled.\n" + " :type distances_enabled: int\n"); +static PyObject *pygpu_state_clip_distances_set(PyObject *UNUSED(self), PyObject *value) +{ + int distances_enabled = (int)PyLong_AsUnsignedLong(value); + if (distances_enabled == -1) { + return NULL; + } + + if (distances_enabled > 6) { + PyErr_SetString(PyExc_ValueError, "too many distances enabled, max is 6"); + } + + GPU_clip_distances(distances_enabled); + Py_RETURN_NONE; +} + PyDoc_STRVAR(pygpu_state_depth_test_set_doc, ".. function:: depth_test_set(mode)\n" "\n" @@ -356,6 +378,10 @@ static struct PyMethodDef pygpu_state__tp_methods[] = { /* Manage Stack */ {"blend_set", (PyCFunction)pygpu_state_blend_set, METH_O, pygpu_state_blend_set_doc}, {"blend_get", (PyCFunction)pygpu_state_blend_get, METH_NOARGS, pygpu_state_blend_get_doc}, + {"clip_distances_set", + (PyCFunction)pygpu_state_clip_distances_set, + METH_O, + pygpu_state_clip_distances_set_doc}, {"depth_test_set", (PyCFunction)pygpu_state_depth_test_set, METH_O, -- cgit v1.2.3 From d7b0567f7c9f52383eb91d5e6b96aa9fd65ee1a5 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 26 Aug 2021 13:26:31 -0300 Subject: Cleanup: return window in 'WM_window_find_under_cursor' This better matches other functions like `BKE_screen_find_area_xy`. --- .../editors/interface/interface_eyedropper_color.c | 6 ++---- source/blender/windowmanager/WM_api.h | 16 +++++++--------- source/blender/windowmanager/intern/wm_window.c | 16 +++++++--------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/source/blender/editors/interface/interface_eyedropper_color.c b/source/blender/editors/interface/interface_eyedropper_color.c index ba72cecc514..a8542c47fc2 100644 --- a/source/blender/editors/interface/interface_eyedropper_color.c +++ b/source/blender/editors/interface/interface_eyedropper_color.c @@ -342,15 +342,13 @@ void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3]) ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my); if (area == NULL) { int mval[2] = {mx, my}; - if (WM_window_find_under_cursor(wm, NULL, win, mval, &win, mval)) { + win = WM_window_find_under_cursor(wm, NULL, win, mval, mval); + if (win) { mx = mval[0]; my = mval[1]; screen = WM_window_get_active_screen(win); area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my); } - else { - win = NULL; - } } if (area) { diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 3027df41e77..ca1610a8101 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -111,12 +111,11 @@ void WM_reinit_gizmomap_all(struct Main *bmain); void WM_script_tag_reload(void); -bool WM_window_find_under_cursor(const wmWindowManager *wm, - const wmWindow *win_ignore, - const wmWindow *win, - const int mval[2], - wmWindow **r_win, - int r_mval[2]); +wmWindow *WM_window_find_under_cursor(const wmWindowManager *wm, + const wmWindow *win_ignore, + const wmWindow *win, + const int mval[2], + int r_mval[2]); void WM_window_pixel_sample_read(const wmWindowManager *wm, const wmWindow *win, const int pos[2], @@ -263,9 +262,8 @@ struct wmEventHandler_Keymap *WM_event_add_keymap_handler_priority(ListBase *han wmKeyMap *keymap, int priority); -typedef struct wmKeyMap *(wmEventHandler_KeymapDynamicFn)(wmWindowManager *wm, - struct wmEventHandler_Keymap *handler) - ATTR_WARN_UNUSED_RESULT; +typedef struct wmKeyMap *(wmEventHandler_KeymapDynamicFn)( + wmWindowManager *wm, struct wmEventHandler_Keymap *handler)ATTR_WARN_UNUSED_RESULT; struct wmKeyMap *WM_event_get_keymap_from_toolsystem_fallback( struct wmWindowManager *wm, struct wmEventHandler_Keymap *handler); diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 93417213a65..e9d0adf6798 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -1922,12 +1922,11 @@ static void wm_window_screen_pos_get(const wmWindow *win, r_scr_pos[1] = desktop_pos[1] - (int)(U.pixelsize * win->posy); } -bool WM_window_find_under_cursor(const wmWindowManager *wm, - const wmWindow *win_ignore, - const wmWindow *win, - const int mval[2], - wmWindow **r_win, - int r_mval[2]) +wmWindow *WM_window_find_under_cursor(const wmWindowManager *wm, + const wmWindow *win_ignore, + const wmWindow *win, + const int mval[2], + int r_mval[2]) { int desk_pos[2]; wm_window_desktop_pos_get(win, mval, desk_pos); @@ -1949,13 +1948,12 @@ bool WM_window_find_under_cursor(const wmWindowManager *wm, if (scr_pos[0] >= 0 && win_iter->posy >= 0 && scr_pos[0] <= WM_window_pixels_x(win_iter) && scr_pos[1] <= WM_window_pixels_y(win_iter)) { - *r_win = win_iter; copy_v2_v2_int(r_mval, scr_pos); - return true; + return win_iter; } } - return false; + return NULL; } void WM_window_pixel_sample_read(const wmWindowManager *wm, -- cgit v1.2.3 From aadbdb80484c374f054c23502c76511be588fd77 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 26 Aug 2021 14:12:21 -0300 Subject: Cleanup: split eyedropper_color_sample_fl into more specific utilities The window and region find utility can be used in other eyedropper operators. --- .../editors/interface/interface_eyedropper.c | 21 +++++++++++++ .../editors/interface/interface_eyedropper_color.c | 36 ++++++++-------------- .../interface/interface_eyedropper_intern.h | 5 +++ 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index b52bfc81b7a..59629e9f1e6 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -168,4 +168,25 @@ uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *ev return but; } +void datadropper_win_area_find( + const bContext *C, const int mval[2], int r_mval[2], wmWindow **r_win, ScrArea **r_area) +{ + bScreen *screen = CTX_wm_screen(C); + + *r_win = CTX_wm_window(C); + *r_area = BKE_screen_find_area_xy(screen, -1, mval[0], mval[1]); + if (*r_area == NULL) { + wmWindowManager *wm = CTX_wm_manager(C); + *r_win = WM_window_find_under_cursor(wm, NULL, *r_win, mval, r_mval); + if (*r_win) { + screen = WM_window_get_active_screen(*r_win); + *r_area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, r_mval[0], r_mval[1]); + } + } + else if (mval != r_mval) { + r_mval[0] = mval[0]; + r_mval[1] = mval[1]; + } +} + /** \} */ diff --git a/source/blender/editors/interface/interface_eyedropper_color.c b/source/blender/editors/interface/interface_eyedropper_color.c index a8542c47fc2..9d06fb2b27a 100644 --- a/source/blender/editors/interface/interface_eyedropper_color.c +++ b/source/blender/editors/interface/interface_eyedropper_color.c @@ -337,50 +337,41 @@ void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3]) const char *display_device = CTX_data_scene(C)->display_settings.display_device; struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device); - wmWindow *win = CTX_wm_window(C); - bScreen *screen = CTX_wm_screen(C); - ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my); - if (area == NULL) { - int mval[2] = {mx, my}; - win = WM_window_find_under_cursor(wm, NULL, win, mval, mval); - if (win) { - mx = mval[0]; - my = mval[1]; - screen = WM_window_get_active_screen(win); - area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my); - } - } + wmWindow *win; + ScrArea *area; + int mval[2] = {mx, my}; + datadropper_win_area_find(C, mval, mval, &win, &area); if (area) { if (area->spacetype == SPACE_IMAGE) { - ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mx, my); + ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval[0], mval[1]); if (region) { SpaceImage *sima = area->spacedata.first; - int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; + int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin}; - if (ED_space_image_color_sample(sima, region, mval, r_col, NULL)) { + if (ED_space_image_color_sample(sima, region, region_mval, r_col, NULL)) { return; } } } else if (area->spacetype == SPACE_NODE) { - ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mx, my); + ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval[0], mval[1]); if (region) { SpaceNode *snode = area->spacedata.first; - const int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; + int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin}; - if (ED_space_node_color_sample(bmain, snode, region, mval, r_col)) { + if (ED_space_node_color_sample(bmain, snode, region, region_mval, r_col)) { return; } } } else if (area->spacetype == SPACE_CLIP) { - ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mx, my); + ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, mval[0], mval[1]); if (region) { SpaceClip *sc = area->spacedata.first; - int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; + int region_mval[2] = {mval[0] - region->winrct.xmin, mval[1] - region->winrct.ymin}; - if (ED_space_clip_color_sample(sc, region, mval, r_col)) { + if (ED_space_clip_color_sample(sc, region, region_mval, r_col)) { return; } } @@ -389,7 +380,6 @@ void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3]) if (win) { /* Fallback to simple opengl picker. */ - const int mval[2] = {mx, my}; WM_window_pixel_sample_read(wm, win, mval, r_col); IMB_colormanagement_display_to_scene_linear_v3(r_col, display); } diff --git a/source/blender/editors/interface/interface_eyedropper_intern.h b/source/blender/editors/interface/interface_eyedropper_intern.h index 96a2c6ed111..2957ea337e0 100644 --- a/source/blender/editors/interface/interface_eyedropper_intern.h +++ b/source/blender/editors/interface/interface_eyedropper_intern.h @@ -28,6 +28,11 @@ void eyedropper_draw_cursor_text_region(const struct bContext *C, const struct ARegion *region, const char *name); uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event); +void datadropper_win_area_find(const struct bContext *C, + const int mval[2], + int r_mval[2], + struct wmWindow **r_win, + struct ScrArea **r_area); /* interface_eyedropper_color.c (expose for color-band picker) */ void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3]); -- cgit v1.2.3 From 583f6948266ba1195c40549d2c8c90f1a1c02e66 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 26 Aug 2021 14:13:19 -0300 Subject: Fix T90817: Object Picker Doesn't Work on Second window Solution similar to the one seen in {rBb94ab93dfb82}. The idea is to find the window and region under the cursor to use in the operator. Reviewed By: brecht Maniphest Tasks: T90817 Differential Revision: https://developer.blender.org/D12310 --- .../editors/interface/interface_eyedropper.c | 16 +++------ .../interface/interface_eyedropper_datablock.c | 42 +++++++++++++--------- .../editors/interface/interface_eyedropper_depth.c | 5 ++- .../interface/interface_eyedropper_intern.h | 3 +- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index 59629e9f1e6..13566a59910 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -126,23 +126,15 @@ void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const cha } void eyedropper_draw_cursor_text_region(const struct bContext *C, - const ARegion *region, + const int x, + const int y, const char *name) { - wmWindow *win = CTX_wm_window(C); - const int x = win->eventstate->x; - const int y = win->eventstate->y; - - if ((name[0] == '\0') || (BLI_rcti_isect_pt(®ion->winrct, x, y) == false)) { + if (name[0] == '\0') { return; } - const int mval[2] = { - x - region->winrct.xmin, - y - region->winrct.ymin, - }; - - eyedropper_draw_cursor_text_ex(mval[0], mval[1], name); + eyedropper_draw_cursor_text_ex(x, y, name); } /** diff --git a/source/blender/editors/interface/interface_eyedropper_datablock.c b/source/blender/editors/interface/interface_eyedropper_datablock.c index 8c605598cbc..0eeeb0a39e4 100644 --- a/source/blender/editors/interface/interface_eyedropper_datablock.c +++ b/source/blender/editors/interface/interface_eyedropper_datablock.c @@ -71,13 +71,14 @@ typedef struct DataDropper { ScrArea *cursor_area; /* Area under the cursor */ ARegionType *art; void *draw_handle_pixel; + int name_pos[2]; char name[200]; } DataDropper; static void datadropper_draw_cb(const struct bContext *C, ARegion *region, void *arg) { DataDropper *ddr = arg; - eyedropper_draw_cursor_text_region(C, region, ddr->name); + eyedropper_draw_cursor_text_region(C, UNPACK2(ddr->name_pos), ddr->name); } static int datadropper_init(bContext *C, wmOperator *op) @@ -148,12 +149,10 @@ static void datadropper_exit(bContext *C, wmOperator *op) /** * \brief get the ID from the 3D view or outliner. */ -static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int my, ID **r_id) +static void datadropper_id_sample_pt( + bContext *C, wmWindow *win, ScrArea *area, DataDropper *ddr, int mx, int my, ID **r_id) { - /* we could use some clever */ - bScreen *screen = CTX_wm_screen(C); - ScrArea *area = BKE_screen_find_area_xy(screen, -1, mx, my); - + wmWindow *win_prev = CTX_wm_window(C); ScrArea *area_prev = CTX_wm_area(C); ARegion *region_prev = CTX_wm_region(C); @@ -166,6 +165,7 @@ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int const int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; Base *base; + CTX_wm_window_set(C, win); CTX_wm_area_set(C, area); CTX_wm_region_set(C, region); @@ -202,11 +202,15 @@ static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int BLI_snprintf(ddr->name, sizeof(ddr->name), "%s: %s", ddr->idcode_name, id->name + 2); *r_id = id; } + + ddr->name_pos[0] = mval[0]; + ddr->name_pos[1] = mval[1]; } } } } + CTX_wm_window_set(C, win_prev); CTX_wm_area_set(C, area_prev); CTX_wm_region_set(C, region_prev); } @@ -232,7 +236,13 @@ static bool datadropper_id_sample(bContext *C, DataDropper *ddr, int mx, int my) { ID *id = NULL; - datadropper_id_sample_pt(C, ddr, mx, my, &id); + wmWindow *win; + ScrArea *area; + + int mval[] = {mx, my}; + datadropper_win_area_find(C, mval, mval, &win, &area); + + datadropper_id_sample_pt(C, win, area, ddr, mval[0], mval[1], &id); return datadropper_id_set(C, ddr, id); } @@ -244,14 +254,8 @@ static void datadropper_cancel(bContext *C, wmOperator *op) } /* To switch the draw callback when region under mouse event changes */ -static void datadropper_set_draw_callback_region(bContext *C, - DataDropper *ddr, - const int mx, - const int my) +static void datadropper_set_draw_callback_region(bContext *C, ScrArea *area, DataDropper *ddr) { - bScreen *screen = CTX_wm_screen(C); - ScrArea *area = BKE_screen_find_area_xy(screen, -1, mx, my); - if (area) { /* If spacetype changed */ if (area->spacetype != ddr->cursor_area->spacetype) { @@ -300,10 +304,16 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event) else if (event->type == MOUSEMOVE) { ID *id = NULL; + wmWindow *win; + ScrArea *area; + + int mval[] = {event->x, event->y}; + datadropper_win_area_find(C, mval, mval, &win, &area); + /* Set the region for eyedropper cursor text drawing */ - datadropper_set_draw_callback_region(C, ddr, event->x, event->y); + datadropper_set_draw_callback_region(C, area, ddr); - datadropper_id_sample_pt(C, ddr, event->x, event->y, &id); + datadropper_id_sample_pt(C, win, area, ddr, mval[0], mval[1], &id); } return OPERATOR_RUNNING_MODAL; diff --git a/source/blender/editors/interface/interface_eyedropper_depth.c b/source/blender/editors/interface/interface_eyedropper_depth.c index a64fad8c333..6f272201085 100644 --- a/source/blender/editors/interface/interface_eyedropper_depth.c +++ b/source/blender/editors/interface/interface_eyedropper_depth.c @@ -72,13 +72,14 @@ typedef struct DepthDropper { ARegionType *art; void *draw_handle_pixel; + int name_pos[2]; char name[200]; } DepthDropper; static void depthdropper_draw_cb(const struct bContext *C, ARegion *region, void *arg) { DepthDropper *ddr = arg; - eyedropper_draw_cursor_text_region(C, region, ddr->name); + eyedropper_draw_cursor_text_region(C, UNPACK2(ddr->name_pos), ddr->name); } static int depthdropper_init(bContext *C, wmOperator *op) @@ -172,6 +173,8 @@ static void depthdropper_depth_sample_pt( /* weak, we could pass in some reference point */ const float *view_co = v3d->camera ? v3d->camera->obmat[3] : rv3d->viewinv[3]; const int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; + copy_v2_v2_int(ddr->name_pos, mval); + float co[3]; CTX_wm_area_set(C, area); diff --git a/source/blender/editors/interface/interface_eyedropper_intern.h b/source/blender/editors/interface/interface_eyedropper_intern.h index 2957ea337e0..4295a781af8 100644 --- a/source/blender/editors/interface/interface_eyedropper_intern.h +++ b/source/blender/editors/interface/interface_eyedropper_intern.h @@ -25,7 +25,8 @@ /* interface_eyedropper.c */ void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name); void eyedropper_draw_cursor_text_region(const struct bContext *C, - const struct ARegion *region, + const int x, + const int y, const char *name); uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event); void datadropper_win_area_find(const struct bContext *C, -- cgit v1.2.3 From 8e5b7ac6e29ad99201fb70c6b0a02b19918c2e94 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Thu, 26 Aug 2021 13:26:31 -0300 Subject: Fix error in last commmit --- source/blender/windowmanager/intern/wm_event_system.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index b9a3dd0c3fb..1f47b152a2b 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -4357,8 +4357,8 @@ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *wi } } - wmWindow *win_other; - if (WM_window_find_under_cursor(wm, win, win, mval, &win_other, mval)) { + wmWindow *win_other = WM_window_find_under_cursor(wm, win, win, mval, mval); + if (win_other) { event->x = mval[0]; event->y = mval[1]; return win_other; -- cgit v1.2.3 From e5ed9991eaf0734e4b2ea9c3580a578af1827e50 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 26 Aug 2021 10:51:30 -0700 Subject: UI: Consistent Area Move Snapping Locations Change Area Move snapping locations to even 12ths, rather than current eights and thirds, so snap distances are consistent sizes. Also adds snapping at minimum and maximum locations. see D11938 for details and illustrations. Differential Revision: https://developer.blender.org/D11938 Reviewed by Hans Goudey --- source/blender/editors/screen/screen_ops.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index cff3ecfbbd3..daac196a90c 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1738,19 +1738,19 @@ static int area_snap_calc_location(const bScreen *screen, int snap_dist_best = INT_MAX; { const float div_array[] = { - /* Middle. */ - 1.0f / 2.0f, - /* Thirds. */ - 1.0f / 3.0f, - 2.0f / 3.0f, - /* Quarters. */ - 1.0f / 4.0f, - 3.0f / 4.0f, - /* Eighth. */ - 1.0f / 8.0f, - 3.0f / 8.0f, - 5.0f / 8.0f, - 7.0f / 8.0f, + 0.0f, + 1.0f / 12.0f, + 2.0f / 12.0f, + 3.0f / 12.0f, + 4.0f / 12.0f, + 5.0f / 12.0f, + 6.0f / 12.0f, + 7.0f / 12.0f, + 8.0f / 12.0f, + 9.0f / 12.0f, + 10.0f / 12.0f, + 11.0f / 12.0f, + 1.0f, }; /* Test the snap to the best division. */ for (int i = 0; i < ARRAY_SIZE(div_array); i++) { -- cgit v1.2.3 From 2b64b4d90d677dd0055f966814df76486ebbd7dc Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Thu, 26 Aug 2021 21:57:59 +0200 Subject: Fix T90973: GPencil - Add buttons to move up and down vertex groups These buttons were in Meshes but not for Grease Pencil. This patch add them in order to keep consistency. Reviewed By: HooglyBoogly Maniphest Tasks: T90973 Differential Revision: https://developer.blender.org/D12328 --- .../startup/bl_ui/properties_data_gpencil.py | 5 +++ source/blender/editors/object/object_vgroup.c | 40 +++++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/release/scripts/startup/bl_ui/properties_data_gpencil.py b/release/scripts/startup/bl_ui/properties_data_gpencil.py index b273eee4e19..793c4a52350 100644 --- a/release/scripts/startup/bl_ui/properties_data_gpencil.py +++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py @@ -342,6 +342,11 @@ class DATA_PT_gpencil_vertex_groups(ObjectButtonsPanel, Panel): col.operator("object.vertex_group_add", icon='ADD', text="") col.operator("object.vertex_group_remove", icon='REMOVE', text="").all = False + if group: + col.separator() + col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP' + col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN' + if ob.vertex_groups: row = layout.row() diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7a42c9d5d8b..f0ab082cd9c 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -28,6 +28,7 @@ #include "MEM_guardedalloc.h" #include "DNA_curve_types.h" +#include "DNA_gpencil_types.h" #include "DNA_lattice_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" @@ -39,6 +40,7 @@ #include "BLI_alloca.h" #include "BLI_array.h" #include "BLI_blenlib.h" +#include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_utildefines.h" #include "BLI_utildefines_stack.h" @@ -4083,16 +4085,38 @@ static int vgroup_do_remap(Object *ob, const char *name_array, wmOperator *op) } else { int dvert_tot = 0; + /* Grease pencil stores vertex groups separately for each stroke, + * so remap each stroke's weights separately. */ + if (ob->type == OB_GPENCIL) { + bGPdata *gpd = ob->data; + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + dvert = gps->dvert; + dvert_tot = gps->totpoints; + if (dvert) { + while (dvert_tot--) { + if (dvert->totweight) { + BKE_defvert_remap(dvert, sort_map, defbase_tot); + } + dvert++; + } + } + } + } + } + } + else { + BKE_object_defgroup_array_get(ob->data, &dvert, &dvert_tot); - BKE_object_defgroup_array_get(ob->data, &dvert, &dvert_tot); - - /* Create as necessary. */ - if (dvert) { - while (dvert_tot--) { - if (dvert->totweight) { - BKE_defvert_remap(dvert, sort_map, defbase_tot); + /* Create as necessary. */ + if (dvert) { + while (dvert_tot--) { + if (dvert->totweight) { + BKE_defvert_remap(dvert, sort_map, defbase_tot); + } + dvert++; } - dvert++; } } } -- cgit v1.2.3 From 8949eab27ef86a5c506da1c481438999bd5ebb47 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 27 Aug 2021 11:47:34 +1000 Subject: Cleanup: warnings --- source/blender/editors/interface/interface_eyedropper.c | 5 +---- .../blender/editors/interface/interface_eyedropper_datablock.c | 10 ++++++---- source/blender/editors/interface/interface_eyedropper_depth.c | 6 ++++-- source/blender/editors/interface/interface_eyedropper_intern.h | 5 +---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index 13566a59910..2e7b0ce532c 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -125,10 +125,7 @@ void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const cha eyedropper_draw_cursor_text_ex(x, y, name); } -void eyedropper_draw_cursor_text_region(const struct bContext *C, - const int x, - const int y, - const char *name) +void eyedropper_draw_cursor_text_region(const int x, const int y, const char *name) { if (name[0] == '\0') { return; diff --git a/source/blender/editors/interface/interface_eyedropper_datablock.c b/source/blender/editors/interface/interface_eyedropper_datablock.c index 0eeeb0a39e4..4996c803dfe 100644 --- a/source/blender/editors/interface/interface_eyedropper_datablock.c +++ b/source/blender/editors/interface/interface_eyedropper_datablock.c @@ -75,10 +75,12 @@ typedef struct DataDropper { char name[200]; } DataDropper; -static void datadropper_draw_cb(const struct bContext *C, ARegion *region, void *arg) +static void datadropper_draw_cb(const struct bContext *UNUSED(C), + ARegion *UNUSED(region), + void *arg) { DataDropper *ddr = arg; - eyedropper_draw_cursor_text_region(C, UNPACK2(ddr->name_pos), ddr->name); + eyedropper_draw_cursor_text_region(UNPACK2(ddr->name_pos), ddr->name); } static int datadropper_init(bContext *C, wmOperator *op) @@ -254,7 +256,7 @@ static void datadropper_cancel(bContext *C, wmOperator *op) } /* To switch the draw callback when region under mouse event changes */ -static void datadropper_set_draw_callback_region(bContext *C, ScrArea *area, DataDropper *ddr) +static void datadropper_set_draw_callback_region(ScrArea *area, DataDropper *ddr) { if (area) { /* If spacetype changed */ @@ -311,7 +313,7 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event) datadropper_win_area_find(C, mval, mval, &win, &area); /* Set the region for eyedropper cursor text drawing */ - datadropper_set_draw_callback_region(C, area, ddr); + datadropper_set_draw_callback_region(area, ddr); datadropper_id_sample_pt(C, win, area, ddr, mval[0], mval[1], &id); } diff --git a/source/blender/editors/interface/interface_eyedropper_depth.c b/source/blender/editors/interface/interface_eyedropper_depth.c index 6f272201085..311f718d950 100644 --- a/source/blender/editors/interface/interface_eyedropper_depth.c +++ b/source/blender/editors/interface/interface_eyedropper_depth.c @@ -76,10 +76,12 @@ typedef struct DepthDropper { char name[200]; } DepthDropper; -static void depthdropper_draw_cb(const struct bContext *C, ARegion *region, void *arg) +static void depthdropper_draw_cb(const struct bContext *UNUSED(C), + ARegion *UNUSED(region), + void *arg) { DepthDropper *ddr = arg; - eyedropper_draw_cursor_text_region(C, UNPACK2(ddr->name_pos), ddr->name); + eyedropper_draw_cursor_text_region(UNPACK2(ddr->name_pos), ddr->name); } static int depthdropper_init(bContext *C, wmOperator *op) diff --git a/source/blender/editors/interface/interface_eyedropper_intern.h b/source/blender/editors/interface/interface_eyedropper_intern.h index 4295a781af8..f9f3fcfb5d1 100644 --- a/source/blender/editors/interface/interface_eyedropper_intern.h +++ b/source/blender/editors/interface/interface_eyedropper_intern.h @@ -24,10 +24,7 @@ /* interface_eyedropper.c */ void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name); -void eyedropper_draw_cursor_text_region(const struct bContext *C, - const int x, - const int y, - const char *name); +void eyedropper_draw_cursor_text_region(const int x, const int y, const char *name); uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event); void datadropper_win_area_find(const struct bContext *C, const int mval[2], -- cgit v1.2.3 From 20ef77137434efa1854cb1d6de70aa476b2674f9 Mon Sep 17 00:00:00 2001 From: Henrik Dick Date: Fri, 27 Aug 2021 11:32:44 +1000 Subject: Modifier: smooth interpolation support Add an option to the mask modifier to use the vertex weights to generate smooth in between geometry, instead of just deleting non complete faces. This can be used to make all sorts of smooth dissolve animations directly with geometry, which are usually hacked together with shaders. It also allows for implicit function plotting using geometry nodes and boolean like operations on non manifold geometry with the proximity modifier. Reviewed By: campbellbarton Ref D10979 --- source/blender/makesdna/DNA_modifier_types.h | 1 + source/blender/makesrna/intern/rna_modifier.c | 6 + source/blender/modifiers/intern/MOD_mask.cc | 433 +++++++++++++++++++++++++- 3 files changed, 431 insertions(+), 9 deletions(-) diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 1bebbc35747..13213f70fed 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -298,6 +298,7 @@ enum { /* Mask Modifier -> flag */ enum { MOD_MASK_INV = (1 << 0), + MOD_MASK_SMOOTH = (1 << 1), }; typedef struct ArrayModifierData { diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 486d8d13564..f11d845c582 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -4431,6 +4431,12 @@ static void rna_def_modifier_mask(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Invert", "Use vertices that are not part of region defined"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "use_smooth", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_MASK_SMOOTH); + RNA_def_property_ui_text( + prop, "Smooth", "Use vertex group weights to cut faces at the weight contour"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_FACTOR); RNA_def_property_float_sdna(prop, NULL, "threshold"); RNA_def_property_range(prop, 0.0, 1.0); diff --git a/source/blender/modifiers/intern/MOD_mask.cc b/source/blender/modifiers/intern/MOD_mask.cc index 9aa8e3dd7c8..aca90e0533c 100644 --- a/source/blender/modifiers/intern/MOD_mask.cc +++ b/source/blender/modifiers/intern/MOD_mask.cc @@ -27,6 +27,7 @@ #include "BLI_ghash.h" #include "BLI_listbase.h" +#include "BLI_math.h" #include "BLT_translation.h" @@ -214,6 +215,40 @@ static void computed_masked_edges(const Mesh *mesh, *r_num_masked_edges = num_masked_edges; } +static void computed_masked_edges_smooth(const Mesh *mesh, + Span vertex_mask, + MutableSpan r_edge_map, + uint *r_num_masked_edges, + uint *r_num_add_vertices) +{ + BLI_assert(mesh->totedge == r_edge_map.size()); + + uint num_masked_edges = 0; + uint num_add_vertices = 0; + for (int i : IndexRange(mesh->totedge)) { + const MEdge &edge = mesh->medge[i]; + + /* only add if both verts will be in new mesh */ + bool v1 = vertex_mask[edge.v1]; + bool v2 = vertex_mask[edge.v2]; + if (v1 && v2) { + r_edge_map[i] = num_masked_edges; + num_masked_edges++; + } + else if (v1 != v2) { + r_edge_map[i] = -2; + num_add_vertices++; + } + else { + r_edge_map[i] = -1; + } + } + + num_masked_edges += num_add_vertices; + *r_num_masked_edges = num_masked_edges; + *r_num_add_vertices = num_add_vertices; +} + static void computed_masked_polygons(const Mesh *mesh, Span vertex_mask, Vector &r_masked_poly_indices, @@ -224,7 +259,7 @@ static void computed_masked_polygons(const Mesh *mesh, BLI_assert(mesh->totvert == vertex_mask.size()); r_masked_poly_indices.reserve(mesh->totpoly); - r_loop_starts.reserve(mesh->totloop); + r_loop_starts.reserve(mesh->totpoly); uint num_masked_loops = 0; for (int i : IndexRange(mesh->totpoly)) { @@ -250,6 +285,76 @@ static void computed_masked_polygons(const Mesh *mesh, *r_num_masked_loops = num_masked_loops; } +static void compute_interpolated_polygons(const Mesh *mesh, + Span vertex_mask, + uint num_add_vertices, + uint num_masked_loops, + Vector &r_masked_poly_indices, + Vector &r_loop_starts, + uint *r_num_add_edges, + uint *r_num_add_polys, + uint *r_num_add_loops) +{ + BLI_assert(mesh->totvert == vertex_mask.size()); + + /* Can't really know ahead of time how much space to use exactly. Estimate limit instead. */ + /* NOTE: this reserve can only lift the capacity if there are ngons, which get split. */ + r_masked_poly_indices.reserve(r_masked_poly_indices.size() + num_add_vertices); + r_loop_starts.reserve(r_loop_starts.size() + num_add_vertices); + + uint num_add_edges = 0; + uint num_add_polys = 0; + uint num_add_loops = 0; + for (int i : IndexRange(mesh->totpoly)) { + const MPoly &poly_src = mesh->mpoly[i]; + + int in_count = 0; + int start = -1; + int dst_totloop = -1; + Span loops_src(&mesh->mloop[poly_src.loopstart], poly_src.totloop); + for (const int j : loops_src.index_range()) { + const MLoop &loop = loops_src[j]; + if (vertex_mask[loop.v]) { + in_count++; + } + else if (start == -1) { + start = j; + } + } + if (0 < in_count && in_count < poly_src.totloop) { + /* Ring search starting at a vertex which is not included in the mask. */ + const MLoop *last_loop = &loops_src[start]; + bool v_loop_in_mask_last = vertex_mask[last_loop->v]; + for (const int j : loops_src.index_range()) { + const MLoop &loop = loops_src[(start + 1 + j) % poly_src.totloop]; + const bool v_loop_in_mask = vertex_mask[loop.v]; + if (v_loop_in_mask && !v_loop_in_mask_last) { + dst_totloop = 3; + } + else if (!v_loop_in_mask && v_loop_in_mask_last) { + BLI_assert(dst_totloop > 2); + r_masked_poly_indices.append(i); + r_loop_starts.append(num_masked_loops + num_add_loops); + num_add_loops += dst_totloop; + num_add_polys++; + num_add_edges++; + dst_totloop = -1; + } + else if (v_loop_in_mask && v_loop_in_mask_last) { + BLI_assert(dst_totloop > 2); + dst_totloop++; + } + last_loop = &loop; + v_loop_in_mask_last = v_loop_in_mask; + } + } + } + + *r_num_add_edges = num_add_edges; + *r_num_add_polys = num_add_polys; + *r_num_add_loops = num_add_loops; +} + void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh, Mesh &dst_mesh, Span vertex_map) { BLI_assert(src_mesh.totvert == vertex_map.size()); @@ -267,6 +372,89 @@ void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh, Mesh &dst_mesh, Span } } +static float get_interp_factor_from_vgroup( + MDeformVert *dvert, int defgrp_index, float threshold, uint v1, uint v2) +{ + /* NOTE: this calculation is done twice for every vertex, + * instead of storing it the first time and then reusing it. */ + float value1 = BKE_defvert_find_weight(&dvert[v1], defgrp_index); + float value2 = BKE_defvert_find_weight(&dvert[v2], defgrp_index); + return (threshold - value1) / (value2 - value1); +} + +static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh, + Mesh &dst_mesh, + Span vertex_mask, + Span vertex_map, + MDeformVert *dvert, + int defgrp_index, + float threshold, + uint num_masked_edges, + uint num_add_verts, + MutableSpan r_edge_map) +{ + BLI_assert(src_mesh.totvert == vertex_mask.size()); + BLI_assert(src_mesh.totedge == r_edge_map.size()); + + uint vert_index = dst_mesh.totvert - num_add_verts; + uint edge_index = num_masked_edges - num_add_verts; + for (int i_src : IndexRange(src_mesh.totedge)) { + if (r_edge_map[i_src] != -1) { + int i_dst = r_edge_map[i_src]; + if (i_dst == -2) { + i_dst = edge_index; + } + const MEdge &e_src = src_mesh.medge[i_src]; + MEdge &e_dst = dst_mesh.medge[i_dst]; + + CustomData_copy_data(&src_mesh.edata, &dst_mesh.edata, i_src, i_dst, 1); + e_dst = e_src; + e_dst.v1 = vertex_map[e_src.v1]; + e_dst.v2 = vertex_map[e_src.v2]; + } + if (r_edge_map[i_src] == -2) { + const int i_dst = edge_index++; + r_edge_map[i_src] = i_dst; + const MEdge &e_src = src_mesh.medge[i_src]; + /* Cut destination edge and make v1 the new vertex. */ + MEdge &e_dst = dst_mesh.medge[i_dst]; + if (!vertex_mask[e_src.v1]) { + e_dst.v1 = vert_index; + } + else { + BLI_assert(!vertex_mask[e_src.v2]); + e_dst.v2 = e_dst.v1; + e_dst.v1 = vert_index; + } + /* Create the new vertex. */ + float fac = get_interp_factor_from_vgroup( + dvert, defgrp_index, threshold, e_src.v1, e_src.v2); + + float weights[2] = {1.0f - fac, fac}; + CustomData_interp( + &src_mesh.vdata, &dst_mesh.vdata, (int *)&e_src.v1, weights, NULL, 2, vert_index); + MVert &v = dst_mesh.mvert[vert_index]; + MVert &v1 = src_mesh.mvert[e_src.v1]; + MVert &v2 = src_mesh.mvert[e_src.v2]; + + interp_v3_v3v3(v.co, v1.co, v2.co, fac); + + float no1[3]; + float no2[3]; + normal_short_to_float_v3(no1, v1.no); + normal_short_to_float_v3(no2, v2.no); + mul_v3_fl(no1, weights[0]); + madd_v3_v3fl(no1, no2, weights[1]); + normalize_v3(no1); + normal_float_to_short_v3(v.no, no1); + + vert_index++; + } + } + BLI_assert(vert_index == dst_mesh.totvert); + BLI_assert(edge_index == num_masked_edges); +} + void copy_masked_edges_to_new_mesh(const Mesh &src_mesh, Mesh &dst_mesh, Span vertex_map, @@ -276,7 +464,7 @@ void copy_masked_edges_to_new_mesh(const Mesh &src_mesh, BLI_assert(src_mesh.totedge == edge_map.size()); for (const int i_src : IndexRange(src_mesh.totedge)) { const int i_dst = edge_map[i_src]; - if (i_dst == -1) { + if (i_dst == -1 || i_dst == -2) { continue; } @@ -290,6 +478,36 @@ void copy_masked_edges_to_new_mesh(const Mesh &src_mesh, } } +static void copy_masked_polys_to_new_mesh(const Mesh &src_mesh, + Mesh &dst_mesh, + Span vertex_map, + Span edge_map, + Span masked_poly_indices, + Span new_loop_starts, + int num_masked_polys) +{ + for (const int i_dst : IndexRange(num_masked_polys)) { + const int i_src = masked_poly_indices[i_dst]; + + const MPoly &mp_src = src_mesh.mpoly[i_src]; + MPoly &mp_dst = dst_mesh.mpoly[i_dst]; + const int i_ml_src = mp_src.loopstart; + const int i_ml_dst = new_loop_starts[i_dst]; + + CustomData_copy_data(&src_mesh.pdata, &dst_mesh.pdata, i_src, i_dst, 1); + CustomData_copy_data(&src_mesh.ldata, &dst_mesh.ldata, i_ml_src, i_ml_dst, mp_src.totloop); + + const MLoop *ml_src = src_mesh.mloop + i_ml_src; + MLoop *ml_dst = dst_mesh.mloop + i_ml_dst; + + mp_dst = mp_src; + mp_dst.loopstart = i_ml_dst; + for (int i : IndexRange(mp_src.totloop)) { + ml_dst[i].v = vertex_map[ml_src[i].v]; + ml_dst[i].e = edge_map[ml_src[i].e]; + } + } +} void copy_masked_polys_to_new_mesh(const Mesh &src_mesh, Mesh &dst_mesh, Span vertex_map, @@ -320,6 +538,137 @@ void copy_masked_polys_to_new_mesh(const Mesh &src_mesh, } } +static void add_interpolated_polys_to_new_mesh(const Mesh &src_mesh, + Mesh &dst_mesh, + Span vertex_mask, + Span vertex_map, + Span edge_map, + MDeformVert *dvert, + int defgrp_index, + float threshold, + Span masked_poly_indices, + Span new_loop_starts, + int num_masked_polys, + int num_add_edges) +{ + int edge_index = dst_mesh.totedge - num_add_edges; + int sub_poly_index = 0; + int last_i_src = -1; + for (const int i_dst : + IndexRange(num_masked_polys, masked_poly_indices.size() - num_masked_polys)) { + const int i_src = masked_poly_indices[i_dst]; + if (i_src == last_i_src) { + sub_poly_index++; + } + else { + sub_poly_index = 0; + last_i_src = i_src; + } + + const MPoly &mp_src = src_mesh.mpoly[i_src]; + MPoly &mp_dst = dst_mesh.mpoly[i_dst]; + const int i_ml_src = mp_src.loopstart; + int i_ml_dst = new_loop_starts[i_dst]; + const int mp_totloop = (i_dst + 1 < new_loop_starts.size() ? new_loop_starts[i_dst + 1] : + dst_mesh.totloop) - + i_ml_dst; + + CustomData_copy_data(&src_mesh.pdata, &dst_mesh.pdata, i_src, i_dst, 1); + + mp_dst = mp_src; + mp_dst.loopstart = i_ml_dst; + mp_dst.totloop = mp_totloop; + + /* Ring search starting at a vertex which is not included in the mask. */ + int start = -sub_poly_index - 1; + bool skip = false; + Span loops_src(&src_mesh.mloop[i_ml_src], mp_src.totloop); + for (const int j : loops_src.index_range()) { + if (!vertex_mask[loops_src[j].v]) { + if (start == -1) { + start = j; + break; + } + else if (!skip) { + skip = true; + } + } + else if (skip) { + skip = false; + start++; + } + } + + BLI_assert(start >= 0); + BLI_assert(edge_index < dst_mesh.totedge); + + const MLoop *last_loop = &loops_src[start]; + bool v_loop_in_mask_last = vertex_mask[last_loop->v]; + int last_index = start; + for (const int j : loops_src.index_range()) { + const int index = (start + 1 + j) % mp_src.totloop; + const MLoop &loop = loops_src[index]; + const bool v_loop_in_mask = vertex_mask[loop.v]; + if (v_loop_in_mask && !v_loop_in_mask_last) { + /* Start new cut. */ + float fac = get_interp_factor_from_vgroup( + dvert, defgrp_index, threshold, last_loop->v, loop.v); + float weights[2] = {1.0f - fac, fac}; + int indices[2] = {i_ml_src + last_index, i_ml_src + index}; + CustomData_interp(&src_mesh.ldata, &dst_mesh.ldata, indices, weights, NULL, 2, i_ml_dst); + MLoop &cut_dst_loop = dst_mesh.mloop[i_ml_dst]; + cut_dst_loop.e = edge_map[last_loop->e]; + cut_dst_loop.v = dst_mesh.medge[cut_dst_loop.e].v1; + i_ml_dst++; + + CustomData_copy_data(&src_mesh.ldata, &dst_mesh.ldata, i_ml_src + index, i_ml_dst, 1); + MLoop &next_dst_loop = dst_mesh.mloop[i_ml_dst]; + next_dst_loop.v = vertex_map[loop.v]; + next_dst_loop.e = edge_map[loop.e]; + i_ml_dst++; + } + else if (!v_loop_in_mask && v_loop_in_mask_last) { + BLI_assert(i_ml_dst != mp_dst.loopstart); + /* End active cut. */ + float fac = get_interp_factor_from_vgroup( + dvert, defgrp_index, threshold, last_loop->v, loop.v); + float weights[2] = {1.0f - fac, fac}; + int indices[2] = {i_ml_src + last_index, i_ml_src + index}; + CustomData_interp(&src_mesh.ldata, &dst_mesh.ldata, indices, weights, NULL, 2, i_ml_dst); + MLoop &cut_dst_loop = dst_mesh.mloop[i_ml_dst]; + cut_dst_loop.e = edge_index; + cut_dst_loop.v = dst_mesh.medge[edge_map[last_loop->e]].v1; + i_ml_dst++; + + /* Create closing edge. */ + MEdge &cut_edge = dst_mesh.medge[edge_index]; + cut_edge.v1 = dst_mesh.mloop[mp_dst.loopstart].v; + cut_edge.v2 = cut_dst_loop.v; + BLI_assert(cut_edge.v1 != cut_edge.v2); + cut_edge.flag = ME_EDGEDRAW | ME_EDGERENDER; + edge_index++; + + /* Only handle one of the cuts per iteration. */ + break; + } + else if (v_loop_in_mask && v_loop_in_mask_last) { + BLI_assert(i_ml_dst != mp_dst.loopstart); + /* Extend active poly. */ + CustomData_copy_data(&src_mesh.ldata, &dst_mesh.ldata, i_ml_src + index, i_ml_dst, 1); + MLoop &dst_loop = dst_mesh.mloop[i_ml_dst]; + dst_loop.v = vertex_map[loop.v]; + dst_loop.e = edge_map[loop.e]; + i_ml_dst++; + } + last_loop = &loop; + last_index = index; + v_loop_in_mask_last = v_loop_in_mask; + } + BLI_assert(mp_dst.loopstart + mp_dst.totloop == i_ml_dst); + } + BLI_assert(edge_index == dst_mesh.totedge); +} + /* Components of the algorithm: * 1. Figure out which vertices should be present in the output mesh. * 2. Find edges and polygons only using those vertices. @@ -329,6 +678,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) { MaskModifierData *mmd = reinterpret_cast(md); const bool invert_mask = mmd->flag & MOD_MASK_INV; + const bool use_interpolation = mmd->mode == MOD_MASK_MODE_VGROUP && + (mmd->flag & MOD_MASK_SMOOTH); /* Return empty or input mesh when there are no vertex groups. */ MDeformVert *dvert = (MDeformVert *)CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT); @@ -342,6 +693,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) return mesh; } + int defgrp_index = -1; + Array vertex_mask; if (mmd->mode == MOD_MASK_MODE_ARM) { Object *armature_ob = mmd->ob_arm; @@ -355,7 +708,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) compute_vertex_mask__armature_mode(dvert, mesh, armature_ob, mmd->threshold, vertex_mask); } else { - int defgrp_index = BKE_id_defgroup_name_index(&mesh->id, mmd->vgroup); + BLI_assert(mmd->mode == MOD_MASK_MODE_VGROUP); + defgrp_index = BKE_id_defgroup_name_index(&mesh->id, mmd->vgroup); /* Return input mesh if the vertex group does not exist. */ if (defgrp_index == -1) { @@ -376,7 +730,15 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) Array edge_map(mesh->totedge); uint num_masked_edges; - computed_masked_edges(mesh, vertex_mask, edge_map, &num_masked_edges); + uint num_add_vertices; + if (use_interpolation) { + computed_masked_edges_smooth( + mesh, vertex_mask, edge_map, &num_masked_edges, &num_add_vertices); + } + else { + computed_masked_edges(mesh, vertex_mask, edge_map, &num_masked_edges); + num_add_vertices = 0; + } Vector masked_poly_indices; Vector new_loop_starts; @@ -389,13 +751,65 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) &num_masked_polys, &num_masked_loops); - Mesh *result = BKE_mesh_new_nomain_from_template( - mesh, num_masked_vertices, num_masked_edges, 0, num_masked_loops, num_masked_polys); + uint num_add_edges = 0; + uint num_add_polys = 0; + uint num_add_loops = 0; + if (use_interpolation) { + compute_interpolated_polygons(mesh, + vertex_mask, + num_add_vertices, + num_masked_loops, + masked_poly_indices, + new_loop_starts, + &num_add_edges, + &num_add_polys, + &num_add_loops); + } + + Mesh *result = BKE_mesh_new_nomain_from_template(mesh, + num_masked_vertices + num_add_vertices, + num_masked_edges + num_add_edges, + 0, + num_masked_loops + num_add_loops, + num_masked_polys + num_add_polys); copy_masked_vertices_to_new_mesh(*mesh, *result, vertex_map); - copy_masked_edges_to_new_mesh(*mesh, *result, vertex_map, edge_map); - copy_masked_polys_to_new_mesh( - *mesh, *result, vertex_map, edge_map, masked_poly_indices, new_loop_starts); + if (use_interpolation) { + add_interp_verts_copy_edges_to_new_mesh(*mesh, + *result, + vertex_mask, + vertex_map, + dvert, + defgrp_index, + mmd->threshold, + num_masked_edges, + num_add_vertices, + edge_map); + } + else { + copy_masked_edges_to_new_mesh(*mesh, *result, vertex_map, edge_map); + } + copy_masked_polys_to_new_mesh(*mesh, + *result, + vertex_map, + edge_map, + masked_poly_indices, + new_loop_starts, + num_masked_polys); + if (use_interpolation) { + add_interpolated_polys_to_new_mesh(*mesh, + *result, + vertex_mask, + vertex_map, + edge_map, + dvert, + defgrp_index, + mmd->threshold, + masked_poly_indices, + new_loop_starts, + num_masked_polys, + num_add_edges); + } BKE_mesh_calc_edges_loose(result); /* Tag to recalculate normals later. */ @@ -441,6 +855,7 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel) } else if (mode == MOD_MASK_MODE_VGROUP) { modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr); + uiItemR(layout, ptr, "use_smooth", 0, nullptr, ICON_NONE); } uiItemR(layout, ptr, "threshold", 0, nullptr, ICON_NONE); -- cgit v1.2.3 From efc129bc827558e55cf4619b8e2ca502342338f3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 27 Aug 2021 12:59:55 +1000 Subject: Fix sequencer font loading using an unexpected path Reuse the existing font loading function which handles this case. --- source/blender/sequencer/intern/effects.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index d4adad9a34d..203dcccae02 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -3850,9 +3850,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context, if (data->text_blf_id == SEQ_FONT_NOT_LOADED) { data->text_blf_id = -1; - if (data->text_font) { - data->text_blf_id = BLF_load(data->text_font->filepath); - } + SEQ_effect_text_font_load(data, false); } if (data->text_blf_id >= 0) { -- cgit v1.2.3 From 61f9274d07087770e7b4dffc557d66b9bf3c34ec Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 27 Aug 2021 13:02:59 +1000 Subject: Cleanup: use early return --- source/blender/sequencer/intern/effects.c | 45 +++++++++++++++++-------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index 203dcccae02..9235da366f4 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -3755,34 +3755,39 @@ static void init_text_effect(Sequence *seq) void SEQ_effect_text_font_unload(TextVars *data, const bool do_id_user) { - if (data) { - /* Unlink the VFont */ - if (do_id_user && data->text_font != NULL) { - id_us_min(&data->text_font->id); - data->text_font = NULL; - } + if (data == NULL) { + return; + } - /* Unload the BLF font. */ - if (data->text_blf_id >= 0) { - BLF_unload_id(data->text_blf_id); - } + /* Unlink the VFont */ + if (do_id_user && data->text_font != NULL) { + id_us_min(&data->text_font->id); + data->text_font = NULL; + } + + /* Unload the BLF font. */ + if (data->text_blf_id >= 0) { + BLF_unload_id(data->text_blf_id); } } void SEQ_effect_text_font_load(TextVars *data, const bool do_id_user) { - if (data->text_font != NULL) { - if (do_id_user) { - id_us_plus(&data->text_font->id); - } - - char path[FILE_MAX]; - STRNCPY(path, data->text_font->filepath); - BLI_assert(BLI_thread_is_main()); - BLI_path_abs(path, ID_BLEND_PATH_FROM_GLOBAL(&data->text_font->id)); + VFont *vfont = data->text_font; + if (vfont == NULL) { + return; + } - data->text_blf_id = BLF_load(path); + if (do_id_user) { + id_us_plus(&vfont->id); } + + char path[FILE_MAX]; + STRNCPY(path, vfont->filepath); + BLI_assert(BLI_thread_is_main()); + BLI_path_abs(path, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); + + data->text_blf_id = BLF_load(path); } static void free_text_effect(Sequence *seq, const bool do_id_user) -- cgit v1.2.3 From 523bc981cfeecead5050e7af44bbe252c166d718 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 27 Aug 2021 13:09:33 +1000 Subject: Fix loading packed fonts for sequencer strips --- source/blender/sequencer/intern/effects.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/source/blender/sequencer/intern/effects.c b/source/blender/sequencer/intern/effects.c index 9235da366f4..37bac523645 100644 --- a/source/blender/sequencer/intern/effects.c +++ b/source/blender/sequencer/intern/effects.c @@ -39,6 +39,7 @@ #include "BLI_utildefines.h" #include "DNA_anim_types.h" +#include "DNA_packedFile_types.h" #include "DNA_scene_types.h" #include "DNA_sequence_types.h" #include "DNA_space_types.h" @@ -3782,12 +3783,23 @@ void SEQ_effect_text_font_load(TextVars *data, const bool do_id_user) id_us_plus(&vfont->id); } - char path[FILE_MAX]; - STRNCPY(path, vfont->filepath); - BLI_assert(BLI_thread_is_main()); - BLI_path_abs(path, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); + if (vfont->packedfile != NULL) { + PackedFile *pf = vfont->packedfile; + /* Create a name that's unique between library data-blocks to avoid loading + * a font per strip which will load fonts many times. */ + char name[MAX_ID_FULL_NAME]; + BKE_id_full_name_get(name, &vfont->id, 0); - data->text_blf_id = BLF_load(path); + data->text_blf_id = BLF_load_mem(name, pf->data, pf->size); + } + else { + char path[FILE_MAX]; + STRNCPY(path, vfont->filepath); + BLI_assert(BLI_thread_is_main()); + BLI_path_abs(path, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id)); + + data->text_blf_id = BLF_load(path); + } } static void free_text_effect(Sequence *seq, const bool do_id_user) -- cgit v1.2.3