From 7e99e575a439fd8be10183af4f78923e0e89f0aa Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 4 Mar 2025 17:45:37 +0100 Subject: [PATCH 1/2] Fix: Fix most cases of asset browser preview flickering on undo/redo Mitigates #93726. With this asset previews will no longer flicker in the asset browser on actions like undo, redo or when using "Adjust Last Operation" if the asset library doesn't contain assets from the current file. Previews of assets from the current file would have to be cleared on undo & redo, because their memory location can change then. However the file browser's data model didn't allow clearing just these previews, so previews from external assets would have to be reloaded from disk too, causing the flickering. Noticed we can trivially skip clearing of previews if there are no assets from the current file anyway. This mitigates the issue quite a bit until preview handling is rewritten, see #122439. --- source/blender/editors/space_file/filelist.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc index 48ce40367df..701c06f7c05 100644 --- a/source/blender/editors/space_file/filelist.cc +++ b/source/blender/editors/space_file/filelist.cc @@ -1498,7 +1498,9 @@ static int filelist_intern_free_main_files(FileList *filelist) removed_counter++; } - MEM_SAFE_FREE(filelist_intern->filtered); + if (removed_counter > 0) { + MEM_SAFE_FREE(filelist_intern->filtered); + } return removed_counter; } @@ -1914,6 +1916,11 @@ static void filelist_clear_main_files(FileList *filelist, if (filelist->filelist.entries_num == FILEDIR_NBR_ENTRIES_UNSET) { return; } + const int removed_files = filelist_intern_free_main_files(filelist); + /* File list contains no main files to clear. */ + if (removed_files == 0) { + return; + } filelist_tag_needs_filtering(filelist); @@ -1921,8 +1928,6 @@ static void filelist_clear_main_files(FileList *filelist, filelist_cache_clear(&filelist->filelist_cache, filelist->filelist_cache.size); } - const int removed_files = filelist_intern_free_main_files(filelist); - filelist->filelist.entries_num -= removed_files; filelist->filelist.entries_filtered_num = FILEDIR_NBR_ENTRIES_UNSET; BLI_assert(filelist->filelist.entries_num > FILEDIR_NBR_ENTRIES_UNSET); From 84123446e3236edfc7a44679ba2db4b587d62bec Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 4 Mar 2025 18:11:00 +0100 Subject: [PATCH 2/2] Fix #135324: Data-block selector icon drawn too big DPI scaling was applied twice. Added an API comment to make this more clear for the caller of the function. This is exactly the changes to main committed in 47bbf3fcaefb2c63661a8ab9098f840925c67a9f, which is a correction to 1f88645728. Pull Request: https://projects.blender.org/blender/blender/pulls/135411 --- source/blender/editors/interface/interface_widgets.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc index 7b698d59f25..7e2eff18fb7 100644 --- a/source/blender/editors/interface/interface_widgets.cc +++ b/source/blender/editors/interface/interface_widgets.cc @@ -1253,6 +1253,8 @@ static void widget_draw_icon_centered(const BIFIconID icon, } /** + * \param aspect: The inverse zoom factor (typically #uiBlock.aspect), with DPI applied (i.e. not + * multiplied by #UI_INV_SCALE_FAC). * \param mono_color: Only for drawing monochrome icons. */ static void widget_draw_preview_icon( @@ -1295,11 +1297,9 @@ static int ui_but_draw_menu_icon(const uiBut *but) static void widget_draw_icon( const uiBut *but, BIFIconID icon, float alpha, const rcti *rect, const uchar mono_color[4]) { - const float aspect = but->block->aspect * UI_INV_SCALE_FAC; - if (but->flag & UI_BUT_ICON_PREVIEW) { GPU_blend(GPU_BLEND_ALPHA); - widget_draw_preview_icon(icon, alpha, aspect, rect, mono_color); + widget_draw_preview_icon(icon, alpha, but->block->aspect, rect, mono_color); GPU_blend(GPU_BLEND_NONE); return; } @@ -1309,6 +1309,7 @@ static void widget_draw_icon( return; } + const float aspect = but->block->aspect * UI_INV_SCALE_FAC; const float height = ICON_DEFAULT_HEIGHT / aspect; /* calculate blend color */ @@ -2274,7 +2275,6 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle, /* Big previews with optional text label below */ if (but->flag & UI_BUT_ICON_PREVIEW && ui_block_is_menu(but->block)) { - const float aspect = but->block->aspect * UI_INV_SCALE_FAC; const BIFIconID icon = ui_but_icon(but); int icon_size = BLI_rcti_size_y(rect); int text_size = 0; @@ -2289,7 +2289,7 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle, /* draw icon in rect above the space reserved for the label */ rect->ymin += text_size; GPU_blend(GPU_BLEND_ALPHA); - widget_draw_preview_icon(icon, alpha, aspect, rect, icon_color); + widget_draw_preview_icon(icon, alpha, but->block->aspect, rect, icon_color); GPU_blend(GPU_BLEND_NONE); /* offset rect to draw label in */