[Bf-blender-cvs] [2f5e040f9ad] usd-importer-T81257-merge: USD Import: cachefile handle cleanup.

makowalski noreply at git.blender.org
Tue Apr 13 16:45:46 CEST 2021


Commit: 2f5e040f9ad59f52a19b3fa3cbc1a21bf9572486
Author: makowalski
Date:   Mon Apr 12 12:47:52 2021 -0400
Branches: usd-importer-T81257-merge
https://developer.blender.org/rB2f5e040f9ad59f52a19b3fa3cbc1a21bf9572486

USD Import: cachefile handle cleanup.

Removed CacheArchiveHandle opaque struct declaration from
DNA_cachefile_types.h.  Moved CacheArchiveHandle and
CacheReader declarations to a shared common/IO_types.h header.
Removed unneeded casts.  Removed unneeded USDStageHandle struct.

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

M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/io/alembic/ABC_alembic.h
M	source/blender/io/alembic/intern/abc_util.h
M	source/blender/io/alembic/intern/alembic_capi.cc
M	source/blender/io/common/CMakeLists.txt
A	source/blender/io/common/IO_types.h
M	source/blender/io/usd/intern/usd_capi.cc
M	source/blender/io/usd/usd.h
M	source/blender/makesdna/DNA_cachefile_types.h

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

diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index b666f76eb2b..3cf56ebda9d 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -180,8 +180,7 @@ void BKE_cachefile_reader_open(CacheFile *cache_file,
       }
 
       /* Open Alembic cache reader. */
-      *reader = CacheReader_open_alembic_object(
-          (CacheArchiveHandle *)cache_file->handle, *reader, object, object_path);
+      *reader = CacheReader_open_alembic_object(cache_file->handle, *reader, object, object_path);
 
       /* Multiple modifiers and constraints can call this function concurrently. */
       BLI_spin_lock(&spin);
@@ -207,8 +206,7 @@ void BKE_cachefile_reader_open(CacheFile *cache_file,
       }
 
       /* Open USD cache reader. */
-      *reader = CacheReader_open_usd_object(
-          (USDStageHandle *)cache_file->handle, *reader, object, object_path);
+      *reader = CacheReader_open_usd_object(cache_file->handle, *reader, object, object_path);
       /* Multiple modifiers and constraints can call this function concurrently. */
       BLI_spin_lock(&spin);
       if (*reader) {
@@ -302,7 +300,7 @@ static void cachefile_handle_free(CacheFile *cache_file)
 
       /* Free handle. */
       if (cache_file->handle) {
-        ABC_free_handle((CacheArchiveHandle *)cache_file->handle);
+        ABC_free_handle(cache_file->handle);
         cache_file->handle = NULL;
       }
 
@@ -331,7 +329,7 @@ static void cachefile_handle_free(CacheFile *cache_file)
 
       /* Free handle. */
       if (cache_file->handle) {
-        USD_free_handle((USDStageHandle *)cache_file->handle);
+        USD_free_handle(cache_file->handle);
         cache_file->handle = NULL;
       }
 
@@ -383,16 +381,14 @@ void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file
 #ifdef WITH_ALEMBIC
   if (BLI_path_extension_check_glob(filepath, "*abc")) {
     cache_file->type = CACHEFILE_TYPE_ALEMBIC;
-    cache_file->handle = (CacheArchiveHandle *)ABC_create_handle(
-        bmain, filepath, &cache_file->object_paths);
+    cache_file->handle = ABC_create_handle(bmain, filepath, &cache_file->object_paths);
     BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
   }
 #endif
 #ifdef WITH_USD
   if (BLI_path_extension_check_glob(filepath, "*.usd;*.usda;*.usdc;*.usdz")) {
     cache_file->type = CACHEFILE_TYPE_USD;
-    cache_file->handle = (CacheArchiveHandle *)USD_create_handle(
-        bmain, filepath, &cache_file->object_paths);
+    cache_file->handle = USD_create_handle(bmain, filepath, &cache_file->object_paths);
     BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
   }
 #endif
@@ -439,4 +435,4 @@ float BKE_cachefile_time_offset(const CacheFile *cache_file, const float time, c
   const float time_offset = cache_file->frame_offset / fps;
   const float frame = (cache_file->override_frame ? cache_file->frame : time);
   return cache_file->is_sequence ? frame : frame / fps - time_offset;
-}
\ No newline at end of file
+}
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h
index 6faf763f8a5..ea0e42da729 100644
--- a/source/blender/io/alembic/ABC_alembic.h
+++ b/source/blender/io/alembic/ABC_alembic.h
@@ -23,6 +23,7 @@
 extern "C" {
 #endif
 
+struct CacheArchiveHandle;
 struct CacheReader;
 struct ListBase;
 struct Main;
@@ -31,8 +32,6 @@ struct Object;
 struct Scene;
 struct bContext;
 
-typedef struct CacheArchiveHandle CacheArchiveHandle;
-
 int ABC_get_version(void);
 
 struct AlembicExportParams {
@@ -97,11 +96,11 @@ bool ABC_import(struct bContext *C,
                 bool validate_meshes,
                 bool as_background_job);
 
-CacheArchiveHandle *ABC_create_handle(struct Main *bmain,
-                                      const char *filename,
-                                      struct ListBase *object_paths);
+struct CacheArchiveHandle *ABC_create_handle(struct Main *bmain,
+                                             const char *filename,
+                                             struct ListBase *object_paths);
 
-void ABC_free_handle(CacheArchiveHandle *handle);
+void ABC_free_handle(struct CacheArchiveHandle *handle);
 
 void ABC_get_transform(struct CacheReader *reader,
                        float r_mat_world[4][4],
diff --git a/source/blender/io/alembic/intern/abc_util.h b/source/blender/io/alembic/intern/abc_util.h
index 98f4b0376a7..ced9fde0f85 100644
--- a/source/blender/io/alembic/intern/abc_util.h
+++ b/source/blender/io/alembic/intern/abc_util.h
@@ -22,15 +22,6 @@
 #include <Alembic/Abc/All.h>
 #include <Alembic/AbcGeom/All.h>
 
-/**
- * \brief The CacheReader struct is only used for anonymous pointers,
- * to interface between C and C++ code. This library only creates
- * pointers to AbcObjectReader (or subclasses thereof).
- */
-struct CacheReader {
-  int unused;
-};
-
 using Alembic::Abc::chrono_t;
 
 struct ID;
diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc
index 45ea4d2ed60..d962d9d00f8 100644
--- a/source/blender/io/alembic/intern/alembic_capi.cc
+++ b/source/blender/io/alembic/intern/alembic_capi.cc
@@ -19,6 +19,7 @@
  */
 
 #include "../ABC_alembic.h"
+#include "IO_types.h"
 
 #include <Alembic/AbcMaterial/IMaterial.h>
 
diff --git a/source/blender/io/common/CMakeLists.txt b/source/blender/io/common/CMakeLists.txt
index 7e39af32f11..2aaf5d57fd6 100644
--- a/source/blender/io/common/CMakeLists.txt
+++ b/source/blender/io/common/CMakeLists.txt
@@ -37,6 +37,7 @@ set(SRC
 
   IO_abstract_hierarchy_iterator.h
   IO_dupli_persistent_id.hh
+  IO_types.h
   intern/dupli_parent_finder.hh
 )
 
diff --git a/source/blender/io/common/IO_types.h b/source/blender/io/common/IO_types.h
new file mode 100644
index 00000000000..18774f6f327
--- /dev/null
+++ b/source/blender/io/common/IO_types.h
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 Blender Foundation.
+ * All rights reserved.
+ */
+#pragma once
+
+/* The CacheArchiveHandle struct is only used for anonymous pointers,
+ * to interface between C and C++ code. This is currently used
+ * to hide pointers to alembic ArchiveReader and USDStageReader. */
+struct CacheArchiveHandle {
+  int unused;
+};
+
+/* The CacheReader struct is only used for anonymous pointers,
+ * to interface between C and C++ code. This is currently used
+ * to hide pointers to AbcObjectReader and USDPrimReader
+ * (or subclasses thereof). */
+struct CacheReader {
+  int unused;
+};
+
diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc
index fc2779e1a4c..b4d3fae72ed 100644
--- a/source/blender/io/usd/intern/usd_capi.cc
+++ b/source/blender/io/usd/intern/usd_capi.cc
@@ -17,6 +17,7 @@
  * All rights reserved.
  */
 
+#include "IO_types.h"
 #include "usd.h"
 #include "usd_hierarchy_iterator.h"
 #include "usd_reader_instance.h"
@@ -77,27 +78,18 @@
 
 #include <iostream>
 
-struct USDStageHandle {
-  CacheArchiveHandle base;
-};
-
 namespace blender::io::usd {
 
-USDStageReader *archive_from_handle(USDStageHandle *handle)
+CacheArchiveHandle *handle_from_stage_reader(USDStageReader *reader)
 {
-  return reinterpret_cast<USDStageReader *>(handle);
+  return reinterpret_cast<CacheArchiveHandle *>(reader);
 }
 
-USDStageReader *archive_from_handle(CacheArchiveHandle *handle)
+USDStageReader *stage_reader_from_handle(CacheArchiveHandle *handle)
 {
   return reinterpret_cast<USDStageReader *>(handle);
 }
 
-USDStageHandle *handle_from_archive(USDStageReader *archive)
-{
-  return reinterpret_cast<USDStageHandle *>(archive);
-}
-
 static bool gather_objects_paths(const pxr::UsdPrim &object, ListBase *object_paths)
 {
   if (!object.IsValid()) {
@@ -866,7 +858,7 @@ void USDCacheReader_incref(CacheReader *reader)
   usd_reader->incref();
 }
 
-CacheReader *CacheReader_open_usd_object(USDStageHandle *handle,
+CacheReader *CacheReader_open_usd_object(CacheArchiveHandle *handle,
                                          CacheReader *reader,
                                          Object *object,
                                          const char *object_path)
@@ -875,7 +867,7 @@ CacheReader *CacheReader_open_usd_object(USDStageHandle *handle,
     return reader;
   }
 
-  USDStageReader *archive = archive_from_handle(handle);
+  USDStageReader *archive = stage_reader_from_handle(handle);
 
   if (!archive || !archive->valid()) {
     return reader;
@@ -910,26 +902,28 @@ void USDCacheReader_free(CacheReader *reader)
   }
 }
 
-USDStageHandle *USD_create_handle(struct Main *bmain, const char *filename, ListBase *object_paths)
+CacheArchiveHandle *USD_create_handle(struct Main *bmain,
+                                      const char *filename,
+                                      ListBase *object_paths)
 {
-  USDStageReader *archive = new USDStageReader(bmain, filename);
+  USDStageReader *stage_reader = new USDStageReader(bmain, filename);
 
-  if (!archive->valid()) {
-    delete archive;
+  if (!stage_reader->valid()) {
+    delete stage_reader;
     return NULL;
   }
 
   if (object_paths) {
-    gather_objects_paths(archive->stage()->GetPseudoRoot(), object_paths);
+    gather_objects_paths(stage_reader->stage()->GetPseudoRoot(), object_paths);
   }
 
-  return handle_from_archive(archive);
+  return handle_from_stage_reader(stage_reader);
 }
 
-void USD_free_handle(USDStageHandle *handle)
+void USD_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list