Blender  V2.93
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_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)
 
void BKE_icons_deferred_free (void)
 
static PreviewImagepreviewimg_create_ex (size_t deferred_data_size)
 
static PreviewImagepreviewimg_deferred_create (const char *path, int source)
 
PreviewImageBKE_previewimg_create (void)
 
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 *path)
 
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 *path, 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)

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 72 of file icons.cc.

Function Documentation

◆ BKE_icon_changed()

void BKE_icon_changed ( const int  icon_id)

◆ BKE_icon_delete()

bool BKE_icon_delete ( const 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 ( const int  icon_id)

◆ BKE_icon_gplayer_color_ensure()

int BKE_icon_gplayer_color_ensure ( bGPDlayer gpl)

◆ 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 ( 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 856 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(), 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 ( ID id,
PreviewImage preview 
)

Return icon id of given preview, or create new icon if not found.

Definition at line 811 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, PreviewImage::icon_id, icon_id_ensure_create_icon(), id, and LOG.

◆ BKE_icon_set()

void BKE_icon_set ( const int  icon_id,
struct Icon icon 
)

◆ BKE_icons_deferred_free()

void BKE_icons_deferred_free ( void  )

◆ 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 464 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 455 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 *  path,
const int  source,
bool  force_update 
)

Generate a PreviewImage from given file path, using thumbnails management, if not yet existing. Does not actually generate the preview, BKE_previewimg_ensure() must be called for that.

Definition at line 485 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)

◆ 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 322 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  )

◆ BKE_previewimg_deferred_release()

void BKE_previewimg_deferred_release ( PreviewImage prv)

◆ BKE_previewimg_ensure()

void BKE_previewimg_ensure ( PreviewImage prv,
const int  size 
)

◆ BKE_previewimg_finish()

void BKE_previewimg_finish ( PreviewImage prv,
const int  size 
)

◆ BKE_previewimg_free()

void BKE_previewimg_free ( 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 
)

Duplicate preview image from id and clear icon_id, to be used by datablock copy functions.

Definition at line 342 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 ( ID id,
const char *  path 
)

◆ BKE_previewimg_id_ensure()

PreviewImage* BKE_previewimg_id_ensure ( ID id)

◆ BKE_previewimg_id_free()

void BKE_previewimg_id_free ( ID id)

Definition at line 392 of file icons.cc.

References BKE_previewimg_free(), and BKE_previewimg_id_get_p().

◆ BKE_previewimg_id_get()

PreviewImage* BKE_previewimg_id_get ( const ID id)

Definition at line 386 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 435 of file icons.cc.

References ELEM, GS, id, ID_BR, 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 620 of file icons.cc.

References PreviewImage::flag, PRV_UNFINISHED, and size().

◆ BKE_previewimg_to_imbuf()

ImBuf* BKE_previewimg_to_imbuf ( PreviewImage prv,
const 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 597 of file icons.cc.

References PreviewImage::h, IB_rect, IMB_allocImBuf(), ImBuf::rect, PreviewImage::rect, size(), w(), and PreviewImage::w.

Referenced by filelist_cache_preview_runf(), filelist_file_create_entry(), and IMB_thumb_load_blend().

◆ 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 *  path,
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 87 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 84 of file icons.cc.

Referenced by BKE_icons_init(), and get_next_free_id().

◆ LOG

CLG_LogRef LOG = {"bke.icons"}
static