Refactor: Create File Browser Special Images When Needed
During startup we render 7 large icons used by File Browser in thumbnail view, even though we only ever use 3. This change only renders any the first time it is requested. Saves a tiny amount of startup time and 1 MB of RAM. Pull Request: https://projects.blender.org/blender/blender/pulls/126532
This commit is contained in:
committed by
Harley Acheson
parent
316b5475b9
commit
7045fb6593
@@ -313,22 +313,15 @@ enum FileListTags {
|
||||
FILELIST_TAGS_NO_THREADS = (1 << 2),
|
||||
};
|
||||
|
||||
#define SPECIAL_IMG_SIZE 256
|
||||
#define SPECIAL_IMG_ROWS 1
|
||||
#define SPECIAL_IMG_COLS 7
|
||||
|
||||
enum {
|
||||
SPECIAL_IMG_DOCUMENT = 0,
|
||||
SPECIAL_IMG_DRIVE_DISC = 1,
|
||||
SPECIAL_IMG_FOLDER = 2,
|
||||
SPECIAL_IMG_PARENT = 3,
|
||||
SPECIAL_IMG_DRIVE_FIXED = 4,
|
||||
SPECIAL_IMG_DRIVE_ATTACHED = 5,
|
||||
SPECIAL_IMG_DRIVE_REMOTE = 6,
|
||||
SPECIAL_IMG_MAX,
|
||||
enum class SpecialFileImages {
|
||||
Document,
|
||||
Folder,
|
||||
Parent,
|
||||
/* Keep this last. */
|
||||
_Max,
|
||||
};
|
||||
|
||||
static ImBuf *gSpecialFileImages[SPECIAL_IMG_MAX];
|
||||
static ImBuf *gSpecialFileImages[int(SpecialFileImages::_Max)];
|
||||
|
||||
static void filelist_readjob_main(FileListReadJob *job_params,
|
||||
bool *stop,
|
||||
@@ -1132,30 +1125,11 @@ void filelist_setlibrary(FileList *filelist, const AssetLibraryReference *asset_
|
||||
|
||||
/* ********** Icon/image helpers ********** */
|
||||
|
||||
static ImBuf *fileimage_from_icon(int icon_id)
|
||||
{
|
||||
return UI_svg_icon_bitmap(icon_id, 256.0f, false);
|
||||
}
|
||||
|
||||
void filelist_init_icons()
|
||||
{
|
||||
BLI_assert(G.background == false);
|
||||
#ifndef WITH_HEADLESS
|
||||
gSpecialFileImages[SPECIAL_IMG_DOCUMENT] = fileimage_from_icon(ICON_FILE_LARGE);
|
||||
gSpecialFileImages[SPECIAL_IMG_DRIVE_DISC] = fileimage_from_icon(ICON_DISC_LARGE);
|
||||
gSpecialFileImages[SPECIAL_IMG_FOLDER] = fileimage_from_icon(ICON_FILE_FOLDER_LARGE);
|
||||
gSpecialFileImages[SPECIAL_IMG_PARENT] = fileimage_from_icon(ICON_FILE_PARENT_LARGE);
|
||||
gSpecialFileImages[SPECIAL_IMG_DRIVE_FIXED] = fileimage_from_icon(ICON_DISK_DRIVE_LARGE);
|
||||
gSpecialFileImages[SPECIAL_IMG_DRIVE_ATTACHED] = fileimage_from_icon(ICON_EXTERNAL_DRIVE_LARGE);
|
||||
gSpecialFileImages[SPECIAL_IMG_DRIVE_REMOTE] = fileimage_from_icon(ICON_NETWORK_DRIVE_LARGE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void filelist_free_icons()
|
||||
{
|
||||
BLI_assert(G.background == false);
|
||||
|
||||
for (int i = 0; i < SPECIAL_IMG_MAX; i++) {
|
||||
for (int i = 0; i < int(SpecialFileImages::_Max); i++) {
|
||||
IMB_freeImBuf(gSpecialFileImages[i]);
|
||||
gSpecialFileImages[i] = nullptr;
|
||||
}
|
||||
@@ -1202,20 +1176,29 @@ ImBuf *filelist_file_getimage(const FileDirEntry *file)
|
||||
return file->preview_icon_id ? BKE_icon_imbuf_get_buffer(file->preview_icon_id) : nullptr;
|
||||
}
|
||||
|
||||
static ImBuf *filelist_ensure_special_file_image(SpecialFileImages image, int icon)
|
||||
{
|
||||
ImBuf *ibuf = gSpecialFileImages[int(image)];
|
||||
if (ibuf) {
|
||||
return ibuf;
|
||||
}
|
||||
return gSpecialFileImages[int(image)] = UI_svg_icon_bitmap(icon, 256.0f, false);
|
||||
}
|
||||
|
||||
ImBuf *filelist_geticon_image_ex(const FileDirEntry *file)
|
||||
{
|
||||
ImBuf *ibuf = nullptr;
|
||||
|
||||
if (file->typeflag & FILE_TYPE_DIR) {
|
||||
if (FILENAME_IS_PARENT(file->relpath)) {
|
||||
ibuf = gSpecialFileImages[SPECIAL_IMG_PARENT];
|
||||
ibuf = filelist_ensure_special_file_image(SpecialFileImages::Parent, ICON_FILE_PARENT_LARGE);
|
||||
}
|
||||
else {
|
||||
ibuf = gSpecialFileImages[SPECIAL_IMG_FOLDER];
|
||||
ibuf = filelist_ensure_special_file_image(SpecialFileImages::Folder, ICON_FILE_FOLDER_LARGE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ibuf = gSpecialFileImages[SPECIAL_IMG_DOCUMENT];
|
||||
ibuf = filelist_ensure_special_file_image(SpecialFileImages::Document, ICON_FILE_LARGE);
|
||||
}
|
||||
|
||||
return ibuf;
|
||||
|
||||
@@ -1025,11 +1025,6 @@ void ED_spacetype_file()
|
||||
void ED_file_init()
|
||||
{
|
||||
ED_file_read_bookmarks();
|
||||
|
||||
if (G.background == false) {
|
||||
filelist_init_icons();
|
||||
}
|
||||
|
||||
IMB_thumb_makedirs();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user