[Bf-blender-cvs] [f82a34e0b3b] asset-browser: Merge branch 'master' into asset-browser
Julian Eisel
noreply at git.blender.org
Wed May 19 18:19:59 CEST 2021
Commit: f82a34e0b3bfaa0d483ca02bf883ce53bc343366
Author: Julian Eisel
Date: Wed May 19 18:19:39 2021 +0200
Branches: asset-browser
https://developer.blender.org/rBf82a34e0b3bfaa0d483ca02bf883ce53bc343366
Merge branch 'master' into asset-browser
===================================================================
===================================================================
diff --cc source/blender/blenkernel/CMakeLists.txt
index 3df018cf138,021d7e15814..bdb4feef7db
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@@ -270,10 -292,11 +292,12 @@@ set(SR
BKE_animsys.h
BKE_appdir.h
BKE_armature.h
+ BKE_asset.h
BKE_attribute.h
BKE_attribute_access.hh
+ BKE_attribute_math.hh
BKE_autoexec.h
+ BKE_asset.h
BKE_blender.h
BKE_blender_copybuffer.h
BKE_blender_undo.h
diff --cc source/blender/blenkernel/intern/icons.cc
index b92b2259eeb,7e9f81f9c83..5427288b11c
--- a/source/blender/blenkernel/intern/icons.cc
+++ b/source/blender/blenkernel/intern/icons.cc
@@@ -379,15 -380,15 +380,21 @@@ PreviewImage **BKE_previewimg_id_get_p(
break;
}
- return NULL;
+ return nullptr;
+ }
+
+ PreviewImage *BKE_previewimg_id_get(const ID *id)
+ {
+ PreviewImage **prv_p = BKE_previewimg_id_get_p(id);
+ return prv_p ? *prv_p : nullptr;
}
+PreviewImage *BKE_previewimg_id_get(const ID *id)
+{
+ PreviewImage **prv_p = BKE_previewimg_id_get_p(id);
+ return prv_p ? *prv_p : NULL;
+}
+
void BKE_previewimg_id_free(ID *id)
{
PreviewImage **prv_p = BKE_previewimg_id_get_p(id);
@@@ -407,31 -408,31 +414,72 @@@ PreviewImage *BKE_previewimg_id_ensure(
return *prv_p;
}
- return NULL;
+ return nullptr;
+ }
+
+ void BKE_previewimg_id_custom_set(ID *id, const char *path)
+ {
+ PreviewImage **prv = BKE_previewimg_id_get_p(id);
+
+ /* Thumbnail previews must use the deferred pipeline. But we force them to be immediately
+ * generated here still. */
+
+ if (*prv) {
+ BKE_previewimg_deferred_release(*prv);
+ }
+ *prv = previewimg_deferred_create(path, THB_SOURCE_IMAGE);
+
+ /* Can't lazy-render the preview on access. ID previews are saved to files and we want them to be
+ * there in time. Not only if something happened to have accessed it meanwhile. */
+ for (int i = 0; i < NUM_ICON_SIZES; i++) {
+ BKE_previewimg_ensure(*prv, i);
+ /* Prevent auto-updates. */
+ (*prv)->flag[i] |= PRV_USER_EDITED;
+ }
+ }
+
+ bool BKE_previewimg_id_supports_jobs(const ID *id)
++{
++ return ELEM(GS(id->name), ID_OB, ID_MA, ID_TE, ID_LA, ID_WO, ID_IM, ID_BR);
++}
++
++void BKE_previewimg_deferred_release(PreviewImage *prv)
++{
++ if (prv) {
++ if (prv->tag & PRV_TAG_DEFFERED_RENDERING) {
++ /* We cannot delete the preview while it is being loaded in another thread... */
++ prv->tag |= PRV_TAG_DEFFERED_DELETE;
++ return;
++ }
++ if (prv->icon_id) {
++ BKE_icon_delete(prv->icon_id);
++ }
++ BKE_previewimg_freefunc(prv);
++ }
+}
+
+void BKE_previewimg_id_custom_set(ID *id, const char *path)
+{
+ PreviewImage **prv = BKE_previewimg_id_get_p(id);
+
+ /* Thumbnail previews must use the deferred pipeline. But we force them to be immediately
+ * generated here still. */
+
+ if (*prv) {
+ BKE_previewimg_deferred_release(*prv);
+ }
+ *prv = previewimg_deferred_create(path, THB_SOURCE_IMAGE);
+
+ /* Can't lazy-render the preview on access. ID previews are saved to files and we want them to be
+ * there in time. Not only if something happened to have accessed it meanwhile. */
+ for (int i = 0; i < NUM_ICON_SIZES; i++) {
+ BKE_previewimg_ensure(*prv, i);
+ /* Prevent auto-updates. */
+ (*prv)->flag[i] |= PRV_USER_EDITED;
+ }
+}
+
+bool BKE_previewimg_id_supports_jobs(const ID *id)
{
return ELEM(GS(id->name), ID_OB, ID_MA, ID_TE, ID_LA, ID_WO, ID_IM, ID_BR);
}
diff --cc source/blender/blenloader/intern/readfile.c
index f43cb690a67,fe7d50bfa15..f8f8d8e2f8c
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@@ -960,18 -987,18 +987,27 @@@ static BHead *blo_bhead_read_full(FileD
/* Warning! Caller's responsibility to ensure given bhead **is** an ID one! */
const char *blo_bhead_id_name(const FileData *fd, const BHead *bhead)
{
- return (const char *)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_name_offs);
+ return (const char *)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_name_offset);
+ }
+
+ /* Warning! Caller's responsibility to ensure given bhead **is** an ID one! */
+ AssetMetaData *blo_bhead_id_asset_data_address(const FileData *fd, const BHead *bhead)
+ {
+ BLI_assert(blo_bhead_is_id_valid_type(bhead));
+ return (fd->id_asset_data_offset >= 0) ?
+ *(AssetMetaData **)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_asset_data_offset) :
+ NULL;
}
+/* Warning! Caller's responsibility to ensure given bhead **is** an ID one! */
+AssetMetaData *blo_bhead_id_asset_data_address(const FileData *fd, const BHead *bhead)
+{
+ BLI_assert(BKE_idtype_idcode_is_valid(bhead->code));
+ return (fd->id_asset_data_offs >= 0) ?
+ *(AssetMetaData **)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_asset_data_offs) :
+ NULL;
+}
+
static void decode_blender_header(FileData *fd)
{
char header[SIZEOFBLENDERHEADER], num[4];
diff --cc source/blender/editors/include/ED_fileselect.h
index ff754c80685,8118e3c6c69..63896606ade
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@@ -28,8 -28,9 +28,10 @@@ extern "C"
#endif
struct ARegion;
+ struct FileAssetSelectParams;
+ struct FileDirEntry;
struct FileSelectParams;
+struct FileAssetSelectParams;
struct Scene;
struct ScrArea;
struct SpaceFile;
diff --cc source/blender/editors/space_file/filelist.c
index 7be567e57e9,37a32164cfc..1e92fe7db90
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@@ -275,21 -276,23 +276,40 @@@ typedef struct FileListInternEntry
char *redirection_path;
/** not strictly needed, but used during sorting, avoids to have to recompute it there... */
char *name;
+ bool free_name;
+
+ /**
+ * This is data from the current main, represented by this file. It's crucial that this is
+ * updated correctly on undo, redo and file reading (without UI). The space is responsible to
+ * take care of that.
+ */
+ struct {
+ /** When showing local IDs (FILE_MAIN, FILE_MAIN_ASSET), the ID this file entry represents. */
+ ID *id;
+
+ /* For the few file types that have the preview already in memory. For others, there's delayed
+ * preview reading from disk. Non-owning pointer. */
+ PreviewImage *preview_image;
+ } local_data;
+
+ /** When the file represents an asset read from another file, it is stored here.
++ * Owning pointer. */
++ AssetMetaData *imported_asset_data;
+
+ /**
+ * This is data from the current main, represented by this file. It's crucial that this is
+ * updated correctly on undo, redo and file reading (without UI). That's job of the space to do.
+ */
+ struct {
+ /** When showing local IDs (FILE_MAIN, FILE_MAIN_ASSET), the ID this file entry represents. */
+ ID *id;
+
+ /* For the few file types that have the preview already in memory. For others, there's delayed
+ * preview reading from disk. Non-owning pointer. */
+ PreviewImage *preview_image;
+ } local_data;
+
+ /** When the file represents an asset read from another file, it is stored here.
* Owning pointer. */
AssetMetaData *imported_asset_data;
diff --cc source/blender/editors/space_file/filelist.h
index 59bd5bb50d7,9eb70dd8437..4b8c3de48c1
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@@ -29,8 -29,8 +29,9 @@@ extern "C"
struct BlendHandle;
struct FileList;
+ struct FileSelectAssetLibraryUID;
struct FileSelection;
+struct FileSelectAssetLibraryUID;
struct wmWindowManager;
struct FileDirEntry;
diff --cc source/blender/editors/space_file/space_file.c
index d1c0da1a99a,12bc0a68ca6..5e7da945bfb
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@@ -752,74 -829,94 +829,159 @@@ static void file_dropboxes(void
{
ListBase *lb = WM_dropboxmap_find("Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
- WM_dropbox_add(lb, "FILE_OT_filepath_drop", filepath_drop_poll, filepath_drop_copy);
+ WM_dropbox_add(lb, "FILE_OT_filepath_drop", filepath_drop_poll, filepath_drop_copy, NULL);
+ }
+
+ static int file_space_subtype_get(ScrArea *area)
+ {
+ SpaceFile *sfile = area->spacedata.first;
+ return sfile->browse_mode;
+ }
+
+ static void file_space_subtype_set(ScrArea *area, int value)
+ {
+ SpaceFile *sfile = area->spacedata.first;
+ sfile->browse_mode = value;
+ }
+
+ static void file_space_subtype_item_extend(bContext *UNUSED(C),
+ EnumPropertyItem **item,
+ int *totitem)
+ {
+ if (U.experimental.use_asset_browser) {
+ RNA_enum_items_add(item, totitem, rna_enum_space_file_browse_mode_items);
+ }
+ else {
+ RNA_enum_items_add_value(
+ item, totitem, rna_enum_space_file_browse_mode_items, FILE_BROWSE_MODE_FILES);
+ }
+ }
+
+ static const char *file_context_dir[] = {"active_file", "id", NULL};
+
+ static int /*eContextResult*/ file_context(const bContext *C,
+ const char *member,
+ bContextDataResult *result)
+ {
+ bScreen *screen = CTX_wm_screen(C);
+ SpaceFile *sfile = CTX_wm_space_file(C);
+ FileSelectParams *params = ED_fileselect_get_active_params(sfile);
+
+ BLI_assert(!ED_area_is_global(CTX_wm_area(C)));
+
+ if (CTX_data_dir(member)) {
+ CTX_data_dir_set(result, file_context_dir);
+ return CTX_RESULT_OK;
+ }
+
+ /* The following member checks return file-list data, check if that needs refreshing first. */
+ if (file_main_region_needs_refresh_before_draw(sfile)) {
+ return CTX_RESULT_NO_DATA;
+ }
+
+ if (CTX_data_equals(member, "active_file")) {
+ FileDirEntry *file = filelist_file(sfile->files, params->active_file);
+ if (file == NULL) {
+ return CTX_RESULT_NO_DATA;
+ }
+
+ CTX_data_pointer_set(result, &screen->id, &RNA_FileSelectEntry, file);
+ return CTX_RESULT_OK;
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list