Blender  V3.3
Classes | Macros | Enumerations | Functions | Variables
icons.cc File Reference
#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) }
 

Functions

static void icon_free (void *val)
 
static void icon_free_data (int icon_id, Icon *icon)
 
static Iconicon_ghash_lookup (int icon_id)
 
static int get_next_free_id ()
 
void BKE_icons_init (int first_dyn_id)
 
void BKE_icons_free ()
 
void BKE_icons_deferred_free ()
 
static PreviewImagepreviewimg_create_ex (size_t deferred_data_size)
 
static PreviewImagepreviewimg_deferred_create (const char *filepath, int source)
 
PreviewImageBKE_previewimg_create ()
 
void BKE_previewimg_freefunc (void *link)
 
void BKE_previewimg_free (PreviewImage **prv)
 
void BKE_previewimg_clear_single (struct PreviewImage *prv, enum eIconSizes size)
 
void BKE_previewimg_clear (struct PreviewImage *prv)
 
PreviewImageBKE_previewimg_copy (const PreviewImage *prv)
 
void BKE_previewimg_id_copy (ID *new_id, const ID *old_id)
 
PreviewImage ** BKE_previewimg_id_get_p (const ID *id)
 
PreviewImageBKE_previewimg_id_get (const ID *id)
 
void BKE_previewimg_id_free (ID *id)
 
PreviewImageBKE_previewimg_id_ensure (ID *id)
 
void BKE_previewimg_id_custom_set (ID *id, const char *filepath)
 
bool BKE_previewimg_id_supports_jobs (const ID *id)
 
void BKE_previewimg_deferred_release (PreviewImage *prv)
 
PreviewImageBKE_previewimg_cached_get (const char *name)
 
PreviewImageBKE_previewimg_cached_ensure (const char *name)
 
PreviewImageBKE_previewimg_cached_thumbnail_read (const char *name, const char *filepath, const int source, bool force_update)
 
void BKE_previewimg_cached_release (const char *name)
 
void BKE_previewimg_ensure (PreviewImage *prv, const int size)
 
ImBufBKE_previewimg_to_imbuf (PreviewImage *prv, const int size)
 
void BKE_previewimg_finish (PreviewImage *prv, const int size)
 
bool BKE_previewimg_is_finished (const PreviewImage *prv, const int size)
 
void BKE_previewimg_blend_write (BlendWriter *writer, const PreviewImage *prv)
 
void BKE_previewimg_blend_read (BlendDataReader *reader, PreviewImage *prv)
 
void BKE_icon_changed (const int icon_id)
 
static Iconicon_create (int icon_id, int obj_type, void *obj)
 
static int icon_id_ensure_create_icon (struct ID *id)
 
int BKE_icon_id_ensure (struct ID *id)
 
static int icon_gplayer_color_ensure_create_icon (bGPDlayer *gpl)
 
int BKE_icon_gplayer_color_ensure (bGPDlayer *gpl)
 
int BKE_icon_preview_ensure (ID *id, PreviewImage *preview)
 
int BKE_icon_imbuf_create (ImBuf *ibuf)
 
ImBufBKE_icon_imbuf_get_buffer (int icon_id)
 
IconBKE_icon_get (const int icon_id)
 
void BKE_icon_set (const int icon_id, struct Icon *icon)
 
static void icon_add_to_deferred_delete_queue (int icon_id)
 
void BKE_icon_id_delete (struct ID *id)
 
bool BKE_icon_delete (const int icon_id)
 
bool BKE_icon_delete_unmanaged (const int icon_id)
 
Geometry Icon
int BKE_icon_geom_ensure (struct Icon_Geom *geom)
 
struct Icon_GeomBKE_icon_geom_from_memory (uchar *data, size_t data_len)
 
struct Icon_GeomBKE_icon_geom_from_file (const char *filename)
 
Studio Light Icon
int BKE_icon_ensure_studio_light (struct StudioLight *sl, int id_type)
 

Variables

static CLG_LogRef LOG = {"bke.icons"}
 
static GHashgIcons = nullptr
 
static int gNextIconId = 1
 
static int gFirstIconId = 1
 
static std::mutex gIconMutex
 
static GHashgCachedPreviews = nullptr
 
static LockfreeLinkList g_icon_delete_queue
 

Macro Definition Documentation

◆ ID_PRV_CASE

#define ID_PRV_CASE (   id_code,
  id_struct 
)
Value:
case id_code: { \
return &((id_struct *)id)->preview; \
} \
((void)0)
SyclQueue void void size_t num_bytes void

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Only allow non-managed icons to be removed (by Python for eg). Previews & ID's have their own functions to remove icons.

Enumerator
ICON_FLAG_MANAGED 

Definition at line 57 of file icons.cc.

Function Documentation

◆ BKE_icon_changed()

void BKE_icon_changed ( int  icon_id)

◆ BKE_icon_delete()

bool BKE_icon_delete ( int  icon_id)

◆ BKE_icon_delete_unmanaged()

bool BKE_icon_delete_unmanaged ( const int  icon_id)

◆ BKE_icon_ensure_studio_light()

int BKE_icon_ensure_studio_light ( struct StudioLight sl,
int  id_type 
)

◆ BKE_icon_geom_ensure()

int BKE_icon_geom_ensure ( struct Icon_Geom geom)

◆ BKE_icon_geom_from_file()

struct Icon_Geom* BKE_icon_geom_from_file ( const char *  filename)

◆ BKE_icon_geom_from_memory()

struct Icon_Geom* BKE_icon_geom_from_memory ( uchar data,
size_t  data_len 
)

◆ BKE_icon_get()

Icon* BKE_icon_get ( int  icon_id)

◆ BKE_icon_gplayer_color_ensure()

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.

◆ BKE_icon_id_delete()

void BKE_icon_id_delete ( struct ID id)

◆ BKE_icon_id_ensure()

int BKE_icon_id_ensure ( struct ID id)

◆ BKE_icon_imbuf_create()

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.

Note
Transforms ownership of ibuf to the newly created icon.

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().

◆ BKE_icon_imbuf_get_buffer()

ImBuf* BKE_icon_imbuf_get_buffer ( int  icon_id)

◆ BKE_icon_preview_ensure()

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().

◆ BKE_icon_set()

void BKE_icon_set ( int  icon_id,
struct Icon icon 
)

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().

◆ BKE_icons_deferred_free()

void BKE_icons_deferred_free ( void  )

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().

◆ BKE_icons_free()

void BKE_icons_free ( void  )

◆ BKE_icons_init()

void BKE_icons_init ( int  first_dyn_id)

◆ BKE_previewimg_blend_read()

void BKE_previewimg_blend_read ( BlendDataReader reader,
PreviewImage prv 
)

◆ BKE_previewimg_blend_write()

void BKE_previewimg_blend_write ( BlendWriter writer,
const PreviewImage prv 
)

◆ BKE_previewimg_cached_ensure()

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().

◆ BKE_previewimg_cached_get()

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.

◆ BKE_previewimg_cached_release()

void BKE_previewimg_cached_release ( const char *  name)

◆ BKE_previewimg_cached_thumbnail_read()

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().

◆ BKE_previewimg_clear()

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().

◆ BKE_previewimg_clear_single()

void BKE_previewimg_clear_single ( struct PreviewImage prv,
enum eIconSizes  size 
)

◆ BKE_previewimg_copy()

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().

◆ BKE_previewimg_create()

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().

◆ BKE_previewimg_deferred_release()

void BKE_previewimg_deferred_release ( PreviewImage prv)

◆ BKE_previewimg_ensure()

void BKE_previewimg_ensure ( struct PreviewImage prv,
int  size 
)

◆ BKE_previewimg_finish()

void BKE_previewimg_finish ( PreviewImage prv,
const int  size 
)

◆ BKE_previewimg_free()

void BKE_previewimg_free ( struct PreviewImage **  prv)

◆ BKE_previewimg_freefunc()

void BKE_previewimg_freefunc ( void link)

◆ BKE_previewimg_id_copy()

void BKE_previewimg_id_copy ( ID new_id,
const ID old_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.

◆ BKE_previewimg_id_custom_set()

void BKE_previewimg_id_custom_set ( struct ID id,
const char *  filepath 
)

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().

◆ BKE_previewimg_id_ensure()

PreviewImage* BKE_previewimg_id_ensure ( struct ID id)

◆ BKE_previewimg_id_free()

void BKE_previewimg_id_free ( struct ID id)

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().

◆ BKE_previewimg_id_get()

PreviewImage* BKE_previewimg_id_get ( const ID id)

Definition at line 371 of file icons.cc.

References BKE_previewimg_id_get_p().

◆ BKE_previewimg_id_get_p()

PreviewImage** BKE_previewimg_id_get_p ( const ID id)

◆ BKE_previewimg_id_supports_jobs()

bool BKE_previewimg_id_supports_jobs ( const ID id)

Definition at line 420 of file icons.cc.

References ELEM, GS, id, ID_BR, ID_GR, ID_IM, ID_LA, ID_MA, ID_OB, ID_TE, ID_WO, and ID::name.

◆ BKE_previewimg_is_finished()

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().

◆ BKE_previewimg_to_imbuf()

ImBuf* BKE_previewimg_to_imbuf ( struct PreviewImage prv,
int  size 
)

Create an ImBuf holding a copy of the preview image buffer in prv.

Note
The returned image buffer has to be free'd (IMB_freeImBuf()).

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().

◆ get_next_free_id()

static int get_next_free_id ( )
static

◆ icon_add_to_deferred_delete_queue()

static void icon_add_to_deferred_delete_queue ( int  icon_id)
static

◆ icon_create()

static Icon* icon_create ( int  icon_id,
int  obj_type,
void obj 
)
static

◆ icon_free()

static void icon_free ( void val)
static

◆ icon_free_data()

static void icon_free_data ( int  icon_id,
Icon icon 
)
static

◆ icon_ghash_lookup()

static Icon* icon_ghash_lookup ( int  icon_id)
static

◆ icon_gplayer_color_ensure_create_icon()

static int icon_gplayer_color_ensure_create_icon ( bGPDlayer gpl)
static

◆ icon_id_ensure_create_icon()

static int icon_id_ensure_create_icon ( struct ID id)
static

◆ previewimg_create_ex()

static PreviewImage* previewimg_create_ex ( size_t  deferred_data_size)
static

◆ previewimg_deferred_create()

static PreviewImage* previewimg_deferred_create ( const char *  filepath,
int  source 
)
static

Variable Documentation

◆ g_icon_delete_queue

LockfreeLinkList g_icon_delete_queue
static

◆ gCachedPreviews

GHash* gCachedPreviews = nullptr
static

◆ gFirstIconId

int gFirstIconId = 1
static

Definition at line 72 of file icons.cc.

Referenced by BKE_icons_init(), and get_next_free_id().

◆ gIconMutex

std::mutex gIconMutex
static

◆ gIcons

GHash* gIcons = nullptr
static

◆ gNextIconId

int gNextIconId = 1
static

Definition at line 69 of file icons.cc.

Referenced by BKE_icons_init(), and get_next_free_id().

◆ LOG

CLG_LogRef LOG = {"bke.icons"}
static