[Bf-blender-cvs] [acb8aa88343] temp-asset-representation: Use asset representation in file browser entries, not asset metadata

Julian Eisel noreply at git.blender.org
Wed Nov 2 19:02:49 CET 2022


Commit: acb8aa88343b119d146ad362e28c393b776022e2
Author: Julian Eisel
Date:   Wed Nov 2 18:42:09 2022 +0100
Branches: temp-asset-representation
https://developer.blender.org/rBacb8aa88343b119d146ad362e28c393b776022e2

Use asset representation in file browser entries, not asset metadata

Rather than having the file entries store the asset metadata (and own it
unless it's a local ID asset), reference the asset representation (owned
by the asset library) and request the metadata through that.

===================================================================

M	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenkernel/BKE_asset_representation.hh
M	source/blender/blenkernel/intern/asset_representation.cc
M	source/blender/blenkernel/intern/context.c
M	source/blender/editors/asset/intern/asset_handle.cc
M	source/blender/editors/asset/intern/asset_temp_id_consumer.cc
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_drag.cc
M	source/blender/editors/interface/interface_template_asset_view.cc
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/filelist.cc
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_dragdrop.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index 81b520a1db0..379a16432cb 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -23,6 +23,9 @@ struct ID;
 struct IDProperty;
 struct PreviewImage;
 
+/** C handle for #bke::AssetRepresentation. */
+typedef struct AssetRepresentation AssetRepresentation;
+
 typedef void (*PreSaveFn)(void *asset_ptr, struct AssetMetaData *asset_data);
 
 typedef struct AssetTypeInfo {
@@ -68,6 +71,11 @@ struct PreviewImage *BKE_asset_metadata_preview_get_from_id(const struct AssetMe
 void BKE_asset_metadata_write(struct BlendWriter *writer, struct AssetMetaData *asset_data);
 void BKE_asset_metadata_read(struct BlendDataReader *reader, struct AssetMetaData *asset_data);
 
+AssetMetaData *BKE_asset_representation_metadata_get(const AssetRepresentation *asset)
+    ATTR_WARN_UNUSED_RESULT;
+bool BKE_asset_representation_is_local_id(const AssetRepresentation *asset)
+    ATTR_WARN_UNUSED_RESULT;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/BKE_asset_representation.hh b/source/blender/blenkernel/BKE_asset_representation.hh
index 74593e20b40..32f5dd44f43 100644
--- a/source/blender/blenkernel/BKE_asset_representation.hh
+++ b/source/blender/blenkernel/BKE_asset_representation.hh
@@ -36,9 +36,9 @@ class AssetRepresentation {
   /* TODO this doesn't make sense. Remove this. */
   explicit AssetRepresentation(AssetMetaData &&metadata);
 
-  AssetMetaData &get_metadata();
+  AssetMetaData &get_metadata() const;
   /** Returns if this asset is stored inside this current file, and as such fully editable. */
-  bool is_local();
+  bool is_local_id() const;
 };
 
 }  // namespace blender::bke
diff --git a/source/blender/blenkernel/intern/asset_representation.cc b/source/blender/blenkernel/intern/asset_representation.cc
index 562a166a7b0..df10ab35d24 100644
--- a/source/blender/blenkernel/intern/asset_representation.cc
+++ b/source/blender/blenkernel/intern/asset_representation.cc
@@ -7,6 +7,7 @@
 #include "DNA_ID.h"
 #include "DNA_asset_types.h"
 
+#include "BKE_asset.h"
 #include "BKE_asset_representation.hh"
 
 namespace blender::bke {
@@ -25,14 +26,36 @@ AssetRepresentation::AssetRepresentation(AssetMetaData &&metadata)
 {
 }
 
-AssetMetaData &AssetRepresentation::get_metadata()
+AssetMetaData &AssetRepresentation::get_metadata() const
 {
   return local_id_metadata_ ? *local_id_metadata_ : *metadata_;
 }
 
-bool AssetRepresentation::is_local()
+bool AssetRepresentation::is_local_id() const
 {
   return local_id_metadata_ != nullptr;
 }
 
 }  // namespace blender::bke
+
+/* ---------------------------------------------------------------------- */
+/** \name C-API
+ * \{ */
+
+using namespace blender;
+
+AssetMetaData *BKE_asset_representation_metadata_get(const AssetRepresentation *asset_handle)
+{
+  const bke::AssetRepresentation *asset = reinterpret_cast<const bke::AssetRepresentation *>(
+      asset_handle);
+  return &asset->get_metadata();
+}
+
+bool BKE_asset_representation_is_local_id(const AssetRepresentation *asset_handle)
+{
+  const bke::AssetRepresentation *asset = reinterpret_cast<const bke::AssetRepresentation *>(
+      asset_handle);
+  return asset->is_local_id();
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 1d6092849cc..0ddd53ccb99 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -1495,7 +1495,7 @@ AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid)
    * require returning a non-owning pointer, which we don't have in the Asset Browser (yet). */
   FileDirEntry *file =
       (FileDirEntry *)CTX_data_pointer_get_type(C, "active_file", &RNA_FileSelectEntry).data;
-  if (file && file->asset_data) {
+  if (file && file->asset) {
     *r_is_valid = true;
     return (AssetHandle){.file_data = file};
   }
diff --git a/source/blender/editors/asset/intern/asset_handle.cc b/source/blender/editors/asset/intern/asset_handle.cc
index 00fffd595c0..47e3ac770ff 100644
--- a/source/blender/editors/asset/intern/asset_handle.cc
+++ b/source/blender/editors/asset/intern/asset_handle.cc
@@ -8,6 +8,9 @@
 
 #include "DNA_space_types.h"
 
+#include "BKE_asset.h"
+#include "BKE_asset_representation.hh"
+
 #include "BLO_readfile.h"
 
 #include "ED_asset_handle.h"
@@ -20,9 +23,9 @@ const char *ED_asset_handle_get_name(const AssetHandle *asset)
   return asset->file_data->name;
 }
 
-AssetMetaData *ED_asset_handle_get_metadata(const AssetHandle *asset)
+AssetMetaData *ED_asset_handle_get_metadata(const AssetHandle *asset_handle)
 {
-  return asset->file_data->asset_data;
+  return BKE_asset_representation_metadata_get(asset_handle->file_data->asset);
 }
 
 ID *ED_asset_handle_get_local_id(const AssetHandle *asset)
diff --git a/source/blender/editors/asset/intern/asset_temp_id_consumer.cc b/source/blender/editors/asset/intern/asset_temp_id_consumer.cc
index 376454d62b6..d1fd48d966c 100644
--- a/source/blender/editors/asset/intern/asset_temp_id_consumer.cc
+++ b/source/blender/editors/asset/intern/asset_temp_id_consumer.cc
@@ -72,7 +72,7 @@ AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const AssetHandle *handle)
   if (!handle) {
     return nullptr;
   }
-  BLI_assert(handle->file_data->asset_data != nullptr);
+  BLI_assert(handle->file_data->asset != nullptr);
   return reinterpret_cast<AssetTempIDConsumer *>(
       MEM_new<AssetTemporaryIDConsumer>(__func__, *handle));
 }
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 1098266331f..df4daa58b9e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1787,7 +1787,6 @@ void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, float scale);
 void UI_but_drag_set_asset(uiBut *but,
                            const struct AssetHandle *asset,
                            const char *path,
-                           struct AssetMetaData *metadata,
                            int import_type, /* eFileAssetImportType */
                            int icon,
                            struct ImBuf *imb,
diff --git a/source/blender/editors/interface/interface_drag.cc b/source/blender/editors/interface/interface_drag.cc
index 4bf2dac4151..e959986d19e 100644
--- a/source/blender/editors/interface/interface_drag.cc
+++ b/source/blender/editors/interface/interface_drag.cc
@@ -27,15 +27,14 @@ void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, const float scale)
 }
 
 void UI_but_drag_set_asset(uiBut *but,
-                           const AssetHandle *asset,
+                           const AssetHandle *asset_handle,
                            const char *path,
-                           struct AssetMetaData *metadata,
                            int import_type,
                            int icon,
                            struct ImBuf *imb,
                            float scale)
 {
-  wmDragAsset *asset_drag = WM_drag_create_asset_data(asset, metadata, path, import_type);
+  wmDragAsset *asset_drag = WM_drag_create_asset_data(asset_handle, path, import_type);
 
   /* FIXME: This is temporary evil solution to get scene/view-layer/etc in the copy callback of the
    * #wmDropBox.
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
index 11fe653724c..9a3f7800c64 100644
--- a/source/blender/editors/interface/interface_template_asset_view.cc
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -57,7 +57,6 @@ static void asset_view_item_but_drag_set(uiBut *but,
     UI_but_drag_set_asset(but,
                           asset_handle,
                           BLI_strdup(blend_path),
-                          ED_asset_handle_get_metadata(asset_handle),
                           FILE_ASSET_IMPORT_APPEND,
                           ED_asset_handle_get_preview_icon_id(asset_handle),
                           imbuf,
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 240901318b5..ed0132c6990 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -171,7 +171,6 @@ static void file_draw_icon(const SpaceFile *sfile,
         UI_but_drag_set_asset(but,
                               &(AssetHandle){.file_data = file},
                               BLI_strdup(blend_path),
-                              file->asset_data,
                               asset_params->import_type,
                               icon,
                               preview_image,
@@ -565,7 +564,6 @@ static void file_draw_preview(const SpaceFile *sfile,
         UI_but_drag_set_asset(but,
                               &(AssetHandle){.file_data = file},
                               BLI_strdup(blend_path),
-                              file->asset_data,
                               asset_params->import_type,
                               icon,
                               imb,
diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc
index f2d407e0455..9d806be61f5 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -115,9 +115,6 @@ struct FileListInternEntry {
     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;
   /* References an asset in the asset library storage. */
   bke::AssetRepresentation *asset; /* Non-owning. */
 
@@ -781,8 +778,10 @@ static bool is_filtered_id_file_type(const FileListInternEntry *file,
  */
 static AssetMetaData *filelist_file_internal_get_asset_data(const FileListInternEntry *file)
 {
-  const ID *local_id = file->local_data.id;
-  return local_id ? local_id->asset_data : file->imported_asset_data;
+  if (!file->asset) {
+    return nullptr;
+  }
+  return &file->asset->get_metadata();
 }

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list