Blender
V3.3
|
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <mutex>
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "DNA_brush_types.h"
#include "DNA_collection_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_light_types.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_texture_types.h"
#include "DNA_world_types.h"
#include "BLI_fileops.h"
#include "BLI_ghash.h"
#include "BLI_linklist_lockfree.h"
#include "BLI_string.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
#include "BKE_global.h"
#include "BKE_icons.h"
#include "BKE_studiolight.h"
#include "BLI_sys_types.h"
#include "GPU_texture.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_thumbs.h"
#include "BLO_read_write.h"
#include "atomic_ops.h"
Go to the source code of this file.
Classes | |
struct | DeferredIconDeleteNode |
Macros | |
#define | ID_PRV_CASE(id_code, id_struct) |
Enumerations | |
enum | { ICON_FLAG_MANAGED = (1 << 0) } |
Variables | |
static CLG_LogRef | LOG = {"bke.icons"} |
static GHash * | gIcons = nullptr |
static int | gNextIconId = 1 |
static int | gFirstIconId = 1 |
static std::mutex | gIconMutex |
static GHash * | gCachedPreviews = nullptr |
static LockfreeLinkList | g_icon_delete_queue |
#define ID_PRV_CASE | ( | id_code, | |
id_struct | |||
) |
anonymous enum |
void BKE_icon_changed | ( | int | icon_id | ) |
Report changes - icon needs to be recalculated.
Definition at line 637 of file icons.cc.
References BKE_previewimg_id_get_p(), BLI_assert, G, ICON_DATA_ID, icon_ghash_lookup(), Icon_Geom::icon_id, Icon::id_type, NUM_ICON_SIZES, Icon::obj, Icon::obj_type, and PRV_CHANGED.
Referenced by area_move_apply_do(), area_split_apply(), ghost_event_proc(), icon_preview_imbuf_from_brush(), image_changed(), image_init_after_load(), image_replace_exec(), lamp_changed(), material_changed(), screen_area_join_aligned(), screen_area_join_ex(), texture_changed(), and world_changed().
bool BKE_icon_delete | ( | int | icon_id | ) |
Remove icon and free data.
Definition at line 888 of file icons.cc.
References BLI_ghash_popkey(), gIconMutex, gIcons, icon_free(), icon_free_data(), Icon_Geom::icon_id, lock, and POINTER_FROM_INT.
Referenced by BKE_gpencil_layer_delete(), BKE_previewimg_deferred_release(), filelist_cache_previews_clear(), filelist_cache_previews_update(), and filelist_entry_clear().
bool BKE_icon_delete_unmanaged | ( | const int | icon_id | ) |
Definition at line 905 of file icons.cc.
References BLI_ghash_insert(), BLI_ghash_popkey(), Icon::flag, gIconMutex, gIcons, ICON_FLAG_MANAGED, icon_free(), icon_free_data(), Icon_Geom::icon_id, lock, POINTER_FROM_INT, and UNLIKELY.
Referenced by bpy_app_icons_release().
int BKE_icon_ensure_studio_light | ( | struct StudioLight * | sl, |
int | id_type | ||
) |
Definition at line 1005 of file icons.cc.
References get_next_free_id(), icon_create(), ICON_DATA_STUDIOLIGHT, Icon_Geom::icon_id, and Icon::id_type.
Referenced by studiolight_create().
int BKE_icon_geom_ensure | ( | struct Icon_Geom * | geom | ) |
Definition at line 933 of file icons.cc.
References BLI_assert, BLI_thread_is_main(), get_next_free_id(), icon_create(), ICON_DATA_GEOM, and Icon_Geom::icon_id.
Referenced by bpy_app_icons_new_triangles(), and bpy_app_icons_new_triangles_from_file().
struct Icon_Geom* BKE_icon_geom_from_file | ( | const char * | filename | ) |
Definition at line 988 of file icons.cc.
References BKE_icon_geom_from_memory(), BLI_assert, BLI_file_read_binary_as_mem(), BLI_thread_is_main(), and data.
Referenced by bpy_app_icons_new_triangles_from_file().
Definition at line 949 of file icons.cc.
References ARRAY_SIZE, BLI_assert, BLI_thread_is_main(), Icon_Geom::colors, Icon_Geom::coords, Icon_Geom::coords_len, Icon_Geom::coords_range, data, Icon_Geom::icon_id, Icon_Geom::mem, and MEM_mallocN.
Referenced by BKE_icon_geom_from_file().
Icon* BKE_icon_get | ( | int | icon_id | ) |
Retrieve icon for id.
Definition at line 832 of file icons.cc.
References BLI_assert, BLI_thread_is_main(), CLOG_ERROR, icon_ghash_lookup(), Icon_Geom::icon_id, and LOG.
Referenced by icon_draw_size(), ui_icon_ensure_deferred(), UI_icon_get_height(), UI_icon_get_theme_color(), UI_icon_get_width(), UI_icon_to_preview(), and ui_studiolight_kill_icon_preview_job().
int BKE_icon_gplayer_color_ensure | ( | struct bGPDlayer * | gpl | ) |
Return icon id for Grease Pencil layer (color preview) or create new icon if not found.
Definition at line 744 of file icons.cc.
References BLI_assert, BLI_thread_is_main(), CLOG_ERROR, G, get_next_free_id(), icon_gplayer_color_ensure_create_icon(), bGPDlayer_Runtime::icon_id, LOG, and bGPDlayer::runtime.
Remove icon and free data if library object becomes invalid.
Definition at line 870 of file icons.cc.
References BKE_icons_deferred_free(), BLI_ghash_remove(), BLI_thread_is_main(), gIconMutex, gIcons, icon_add_to_deferred_delete_queue(), icon_free(), Icon_Geom::icon_id, lock, and POINTER_FROM_INT.
Referenced by image_free_data(), light_free_data(), material_free_data(), texture_free_data(), and world_free_data().
int BKE_icon_id_ensure | ( | struct ID * | id | ) |
Return icon id for library object or create new icon if not found.
Definition at line 699 of file icons.cc.
References BKE_previewimg_id_get_p(), BLI_assert, BLI_thread_is_main(), CLOG_ERROR, ELEM, G, get_next_free_id(), ID::icon_id, icon_id_ensure_create_icon(), id, and LOG.
Referenced by icon_preview_imbuf_from_brush(), image_changed(), image_init_after_load(), image_replace_exec(), lamp_changed(), material_changed(), texture_changed(), ui_id_brush_get_icon(), ui_id_icon_get(), ui_id_screen_get_icon(), and world_changed().
int BKE_icon_imbuf_create | ( | struct ImBuf * | ibuf | ) |
Create an icon as owner or ibuf. The icon-ID is not stored in ibuf, it needs to be stored separately.
Definition at line 807 of file icons.cc.
References Icon::flag, get_next_free_id(), icon_create(), ICON_DATA_IMBUF, ICON_FLAG_MANAGED, and Icon_Geom::icon_id.
Referenced by filelist_cache_preview_runf(), filelist_cache_previews_push(), and filelist_file_create_entry().
ImBuf* BKE_icon_imbuf_get_buffer | ( | int | icon_id | ) |
Definition at line 817 of file icons.cc.
References CLOG_ERROR, ICON_DATA_IMBUF, icon_ghash_lookup(), Icon_Geom::icon_id, LOG, Icon::obj, and Icon::obj_type.
Referenced by filelist_file_getimage(), and filelist_getimage().
int BKE_icon_preview_ensure | ( | struct ID * | id, |
struct PreviewImage * | preview | ||
) |
Return icon id of given preview, or create new icon if not found.
Definition at line 767 of file icons.cc.
References BKE_previewimg_id_ensure(), BLI_assert, CLOG_ERROR, Icon::flag, G, get_next_free_id(), icon_create(), ICON_DATA_PREVIEW, ICON_FLAG_MANAGED, ID::icon_id, icon_id_ensure_create_icon(), id, LOG, and usdtokens::preview().
Set icon for id if not already defined. Used for inserting the internal icons.
Definition at line 848 of file icons.cc.
References BLI_ghash_ensure_p(), CLOG_ERROR, gIconMutex, gIcons, Icon_Geom::icon_id, lock, LOG, and POINTER_FROM_INT.
Referenced by def_internal_icon(), and def_internal_vicon().
Free all icons marked for deferred deletion.
Definition at line 217 of file icons.cc.
References BLI_ghash_remove(), BLI_linklist_lockfree_begin(), BLI_linklist_lockfree_clear(), g_icon_delete_queue, gIconMutex, gIcons, icon_free(), lock, MEM_freeN, node, and POINTER_FROM_INT.
Referenced by BKE_icon_id_delete().
Free all icons.
Definition at line 200 of file icons.cc.
References BKE_previewimg_freefunc(), BLI_assert, BLI_ghash_free(), BLI_linklist_lockfree_free(), BLI_thread_is_main(), g_icon_delete_queue, gCachedPreviews, gIcons, icon_free(), and MEM_freeN.
Referenced by UI_icons_free().
void BKE_icons_init | ( | int | first_dyn_id | ) |
Definition at line 183 of file icons.cc.
References BLI_assert, BLI_ghash_int_new(), BLI_ghash_str_new(), BLI_linklist_lockfree_init(), BLI_thread_is_main(), g_icon_delete_queue, gCachedPreviews, gFirstIconId, gIcons, and gNextIconId.
Referenced by WM_init().
void BKE_previewimg_blend_read | ( | BlendDataReader * | reader, |
PreviewImage * | prv | ||
) |
Definition at line 615 of file icons.cc.
References BLO_read_data_address, BLO_read_data_is_undo(), PreviewImage::flag, PreviewImage::gputexture, PreviewImage::icon_id, NUM_ICON_SIZES, PRV_RENDERING, PreviewImage::rect, and PreviewImage::tag.
Referenced by action_blend_read_data(), BKE_collection_blend_read_data(), BKE_screen_blend_read_data(), image_blend_read_data(), light_blend_read_data(), material_blend_read_data(), ntreeBlendReadData(), object_blend_read_data(), scene_blend_read_data(), texture_blend_read_data(), and world_blend_read_data().
void BKE_previewimg_blend_write | ( | BlendWriter * | writer, |
const PreviewImage * | prv | ||
) |
Definition at line 595 of file icons.cc.
References BLO_write_struct_at_address, BLO_write_uint32_array(), PreviewImage::h, PreviewImage::rect, and PreviewImage::w.
PreviewImage* BKE_previewimg_cached_ensure | ( | const char * | name | ) |
Generate an empty PreviewImage, if not yet existing.
Definition at line 446 of file icons.cc.
References BKE_previewimg_create(), BLI_assert, BLI_ghash_ensure_p_ex(), BLI_strdup(), BLI_thread_is_main(), and gCachedPreviews.
Referenced by bpy_utils_previews_new().
PreviewImage* BKE_previewimg_cached_get | ( | const char * | name | ) |
Definition at line 440 of file icons.cc.
References BLI_assert, BLI_ghash_lookup(), BLI_thread_is_main(), and gCachedPreviews.
void BKE_previewimg_cached_release | ( | const char * | name | ) |
Definition at line 508 of file icons.cc.
References BKE_previewimg_deferred_release(), BLI_assert, BLI_ghash_popkey(), BLI_thread_is_main(), gCachedPreviews, and MEM_freeN.
PreviewImage* BKE_previewimg_cached_thumbnail_read | ( | const char * | name, |
const char * | filepath, | ||
int | source, | ||
bool | force_update | ||
) |
Generate a PreviewImage from given filepath
, using thumbnails management, if not yet existing. Does not actually generate the preview, BKE_previewimg_ensure() must be called for that.
Definition at line 463 of file icons.cc.
References BKE_previewimg_clear(), BKE_previewimg_free(), BLI_assert, BLI_ghash_insert(), BLI_ghash_lookup_p(), BLI_strdup(), BLI_thread_is_main(), gCachedPreviews, previewimg_deferred_create(), PRV_DEFERRED_DATA, and STREQ.
Referenced by bpy_utils_previews_load().
void BKE_previewimg_clear | ( | struct PreviewImage * | prv | ) |
Clear the preview image or icon, but does not free it.
Definition at line 303 of file icons.cc.
References BKE_previewimg_clear_single(), and NUM_ICON_SIZES.
Referenced by BKE_previewimg_cached_thumbnail_read(), ED_asset_generate_preview(), lib_id_generate_preview_exec(), and previews_clear_exec().
void BKE_previewimg_clear_single | ( | struct PreviewImage * | prv, |
enum eIconSizes | size | ||
) |
Clear the preview image or icon at a specific size.
Definition at line 291 of file icons.cc.
References PreviewImage::changed_timestamp, PreviewImage::flag, GPU_texture_free(), PreviewImage::gputexture, PreviewImage::h, MEM_SAFE_FREE, PRV_CHANGED, PRV_USER_EDITED, PreviewImage::rect, size(), and PreviewImage::w.
Referenced by BKE_previewimg_clear(), and ED_preview_restart_queue_work().
PreviewImage* BKE_previewimg_copy | ( | const PreviewImage * | prv | ) |
Definition at line 310 of file icons.cc.
References PreviewImage::gputexture, MEM_dupallocN, NUM_ICON_SIZES, and PreviewImage::rect.
Referenced by BKE_previewimg_id_copy().
PreviewImage* BKE_previewimg_create | ( | void | ) |
Create a new preview image.
Definition at line 261 of file icons.cc.
References previewimg_create_ex().
Referenced by BKE_previewimg_cached_ensure(), BKE_previewimg_id_ensure(), and UI_icon_to_preview().
void BKE_previewimg_deferred_release | ( | PreviewImage * | prv | ) |
Definition at line 425 of file icons.cc.
References BKE_icon_delete(), BKE_previewimg_freefunc(), PreviewImage::icon_id, PRV_TAG_DEFFERED_DELETE, PRV_TAG_DEFFERED_RENDERING, and PreviewImage::tag.
Referenced by BKE_previewimg_cached_release(), BKE_previewimg_id_custom_set(), and icon_preview_endjob().
void BKE_previewimg_ensure | ( | struct PreviewImage * | prv, |
int | size | ||
) |
Handle deferred (lazy) loading/generation of preview image, if needed. For now, only used with file thumbnails.
Definition at line 517 of file icons.cc.
References PreviewImage::flag, PreviewImage::h, ICON_RENDER_DEFAULT_HEIGHT, ICON_SIZE_ICON, ICON_SIZE_PREVIEW, IMB_freeImBuf(), IMB_premultiply_alpha(), IMB_scaleImBuf(), IMB_thumb_manage(), MEM_dupallocN, PRV_CHANGED, PRV_DEFERRED_DATA, PRV_RENDERING, PRV_TAG_DEFFERED, PRV_USER_EDITED, ImBuf::rect, PreviewImage::rect, size(), PreviewImage::tag, THB_LARGE, PreviewImage::w, ImBuf::x, and ImBuf::y.
Referenced by BKE_previewimg_id_custom_set().
void BKE_previewimg_finish | ( | PreviewImage * | prv, |
const int | size | ||
) |
Definition at line 584 of file icons.cc.
References atomic_fetch_and_and_int16(), PreviewImage::flag, PRV_RENDERING, and size().
Referenced by blo_blendhandle_read_preview_rects(), and icon_preview_endjob().
void BKE_previewimg_free | ( | struct PreviewImage ** | prv | ) |
Free the preview image.
Definition at line 283 of file icons.cc.
References BKE_previewimg_freefunc().
Referenced by action_free_data(), BKE_previewimg_cached_thumbnail_read(), BKE_previewimg_id_free(), brush_free_data(), collection_free_data(), image_free_data(), light_free_data(), material_free_data(), ntree_free_data(), object_free_data(), scene_free_data(), screen_free_data(), texture_free_data(), and world_free_data().
Free the preview image for use in list.
Definition at line 266 of file icons.cc.
References GPU_texture_free(), PreviewImage::gputexture, MEM_freeN, NUM_ICON_SIZES, and PreviewImage::rect.
Referenced by BKE_icons_free(), BKE_previewimg_deferred_release(), BKE_previewimg_free(), and imb_thumb_load_from_blend_id().
Definition at line 326 of file icons.cc.
References BKE_previewimg_copy(), BKE_previewimg_id_get_p(), BLI_assert, ELEM, and ID::icon_id.
Trigger deferred loading of a custom image file into the preview buffer.
Definition at line 399 of file icons.cc.
References BKE_previewimg_deferred_release(), BKE_previewimg_ensure(), BKE_previewimg_id_get_p(), NUM_ICON_SIZES, previewimg_deferred_create(), PRV_USER_EDITED, and THB_SOURCE_IMAGE.
Referenced by lib_id_load_custom_preview_exec().
PreviewImage* BKE_previewimg_id_ensure | ( | struct ID * | id | ) |
Retrieve existing or create new preview image.
Definition at line 385 of file icons.cc.
References BKE_previewimg_create(), and BKE_previewimg_id_get_p().
Referenced by BKE_icon_preview_ensure(), ED_preview_icon_render(), icon_draw_size(), lib_id_generate_preview_from_object_exec(), previews_clear_exec(), ui_icon_ensure_deferred(), UI_icon_render_id(), UI_icon_to_preview(), and ui_id_icon_render().
Free the preview image belonging to the id.
Definition at line 377 of file icons.cc.
References BKE_previewimg_free(), and BKE_previewimg_id_get_p().
Referenced by lib_id_generate_preview_from_object_exec().
PreviewImage* BKE_previewimg_id_get | ( | const ID * | id | ) |
Definition at line 371 of file icons.cc.
References BKE_previewimg_id_get_p().
PreviewImage** BKE_previewimg_id_get_p | ( | const ID * | id | ) |
Definition at line 343 of file icons.cc.
References GS, id, ID_AC, ID_BR, ID_GR, ID_IM, ID_LA, ID_MA, ID_NT, ID_OB, ID_PRV_CASE, ID_SCE, ID_SCR, ID_TE, ID_WO, and ID::name.
Referenced by BKE_icon_changed(), BKE_icon_id_ensure(), BKE_previewimg_id_copy(), BKE_previewimg_id_custom_set(), BKE_previewimg_id_ensure(), BKE_previewimg_id_free(), and BKE_previewimg_id_get().
bool BKE_previewimg_is_finished | ( | const PreviewImage * | prv, |
const int | size | ||
) |
Definition at line 590 of file icons.cc.
References PreviewImage::flag, PRV_RENDERING, and size().
ImBuf* BKE_previewimg_to_imbuf | ( | struct PreviewImage * | prv, |
int | size | ||
) |
Create an ImBuf holding a copy of the preview image buffer in prv.
Definition at line 567 of file icons.cc.
References PreviewImage::h, IB_rect, IMB_allocImBuf(), ImBuf::rect, PreviewImage::rect, size(), w(), and PreviewImage::w.
Referenced by filelist_cache_previews_push(), filelist_file_create_entry(), and imb_thumb_load_from_blend_id().
|
static |
Definition at line 157 of file icons.cc.
References BLI_ghash_lookup(), gFirstIconId, gIconMutex, gIcons, gNextIconId, lock, blender::threading::enumerable_thread_specific_utils::next_id, and POINTER_FROM_INT.
Referenced by BKE_icon_ensure_studio_light(), BKE_icon_geom_ensure(), BKE_icon_gplayer_color_ensure(), BKE_icon_id_ensure(), BKE_icon_imbuf_create(), and BKE_icon_preview_ensure().
|
static |
Definition at line 861 of file icons.cc.
References BLI_linklist_lockfree_insert(), g_icon_delete_queue, Icon_Geom::icon_id, MEM_mallocN, and node.
Referenced by BKE_icon_id_delete().
Definition at line 667 of file icons.cc.
References BLI_ghash_insert(), Icon::drawinfo, Icon::drawinfo_free, Icon::flag, gIconMutex, gIcons, Icon_Geom::icon_id, Icon::id_type, lock, MEM_mallocN, Icon::obj, Icon::obj_type, and POINTER_FROM_INT.
Referenced by BKE_icon_ensure_studio_light(), BKE_icon_geom_ensure(), BKE_icon_imbuf_create(), BKE_icon_preview_ensure(), icon_gplayer_color_ensure_create_icon(), and icon_id_ensure_create_icon().
Definition at line 87 of file icons.cc.
References Icon_Geom::colors, Icon_Geom::coords, Icon::drawinfo, Icon::drawinfo_free, ICON_DATA_GEOM, if(), Icon_Geom::mem, MEM_freeN, Icon::obj, and Icon::obj_type.
Referenced by BKE_icon_delete(), BKE_icon_delete_unmanaged(), BKE_icon_id_delete(), BKE_icons_deferred_free(), and BKE_icons_free().
Definition at line 115 of file icons.cc.
References BKE_studiolight_unset_icon_id(), BLI_assert_unreachable, ICON_DATA_GEOM, ICON_DATA_GPLAYER, ICON_DATA_ID, ICON_DATA_IMBUF, ICON_DATA_PREVIEW, ICON_DATA_STUDIOLIGHT, Icon_Geom::icon_id, if(), IMB_freeImBuf(), Icon::obj, and Icon::obj_type.
Referenced by BKE_icon_delete(), and BKE_icon_delete_unmanaged().
|
static |
Definition at line 149 of file icons.cc.
References BLI_ghash_lookup(), gIconMutex, gIcons, Icon_Geom::icon_id, lock, and POINTER_FROM_INT.
Referenced by BKE_icon_changed(), BKE_icon_get(), and BKE_icon_imbuf_get_buffer().
|
static |
Definition at line 729 of file icons.cc.
References BLI_assert, BLI_thread_is_main(), Icon::flag, icon_create(), ICON_DATA_GPLAYER, ICON_FLAG_MANAGED, bGPDlayer_Runtime::icon_id, and bGPDlayer::runtime.
Referenced by BKE_icon_gplayer_color_ensure().
|
static |
Definition at line 688 of file icons.cc.
References BLI_assert, BLI_thread_is_main(), Icon::flag, GS, icon_create(), ICON_DATA_ID, ICON_FLAG_MANAGED, ID::icon_id, id, Icon::id_type, and ID::name.
Referenced by BKE_icon_id_ensure(), and BKE_icon_preview_ensure().
|
static |
Definition at line 230 of file icons.cc.
References PreviewImage::changed_timestamp, PreviewImage::flag, MEM_mallocN, NUM_ICON_SIZES, PRV_CHANGED, PRV_TAG_DEFFERED, and PreviewImage::tag.
Referenced by BKE_previewimg_create(), and previewimg_deferred_create().
|
static |
Definition at line 247 of file icons.cc.
References previewimg_create_ex(), and PRV_DEFERRED_DATA.
Referenced by BKE_previewimg_cached_thumbnail_read(), and BKE_previewimg_id_custom_set().
|
static |
Definition at line 85 of file icons.cc.
Referenced by BKE_icons_deferred_free(), BKE_icons_free(), BKE_icons_init(), and icon_add_to_deferred_delete_queue().
|
static |
Definition at line 77 of file icons.cc.
Referenced by BKE_icons_free(), BKE_icons_init(), BKE_previewimg_cached_ensure(), BKE_previewimg_cached_get(), BKE_previewimg_cached_release(), and BKE_previewimg_cached_thumbnail_read().
|
static |
Definition at line 72 of file icons.cc.
Referenced by BKE_icons_init(), and get_next_free_id().
|
static |
Definition at line 74 of file icons.cc.
Referenced by BKE_icon_delete(), BKE_icon_delete_unmanaged(), BKE_icon_id_delete(), BKE_icon_set(), BKE_icons_deferred_free(), get_next_free_id(), icon_create(), and icon_ghash_lookup().
|
static |
Definition at line 66 of file icons.cc.
Referenced by BKE_icon_delete(), BKE_icon_delete_unmanaged(), BKE_icon_id_delete(), BKE_icon_set(), BKE_icons_deferred_free(), BKE_icons_free(), BKE_icons_init(), get_next_free_id(), icon_create(), and icon_ghash_lookup().
|
static |
Definition at line 69 of file icons.cc.
Referenced by BKE_icons_init(), and get_next_free_id().
|
static |
Definition at line 63 of file icons.cc.
Referenced by BKE_icon_get(), BKE_icon_gplayer_color_ensure(), BKE_icon_id_ensure(), BKE_icon_imbuf_get_buffer(), BKE_icon_preview_ensure(), and BKE_icon_set().