Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2019-11-01 21:05:09 +0300
committerJacques Lucke <mail@jlucke.com>2019-11-01 21:05:09 +0300
commit324537287f62cd6876faf32e83f7e9795f8110c6 (patch)
tree80488bc1d925b892c128cfdb6d6d34acf90c1f74 /source/blender
parent6379f1d0353f90711acae5636e6ce1bba8d87791 (diff)
initial functions2 folder
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/CMakeLists.txt1
-rw-r--r--source/blender/functions/FN_all-c.h4
-rw-r--r--source/blender/functions/initialize.cpp4
-rw-r--r--source/blender/functions2/CMakeLists.txt39
-rw-r--r--source/blender/functions2/FN_cpp_type.h160
-rw-r--r--source/blender/functions2/FN_initialize.h10
-rw-r--r--source/blender/functions2/intern/cpp_type.cc9
-rw-r--r--source/blender/functions2/intern/cpp_types.cc120
-rw-r--r--source/blender/functions2/intern/cpp_types.h11
-rw-r--r--source/blender/functions2/intern/initialize.cc12
-rw-r--r--source/blender/modifiers/CMakeLists.txt1
-rw-r--r--source/blender/windowmanager/CMakeLists.txt1
-rw-r--r--source/blender/windowmanager/intern/wm_init_exit.c2
13 files changed, 370 insertions, 4 deletions
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 98a93af93c7..4cbc31d3f1b 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -112,6 +112,7 @@ add_subdirectory(modifiers)
add_subdirectory(gpencil_modifiers)
add_subdirectory(shader_fx)
add_subdirectory(functions)
+add_subdirectory(functions2)
add_subdirectory(simulations)
add_subdirectory(makesdna)
add_subdirectory(makesrna)
diff --git a/source/blender/functions/FN_all-c.h b/source/blender/functions/FN_all-c.h
index b970d8be2d5..71f8e2ed387 100644
--- a/source/blender/functions/FN_all-c.h
+++ b/source/blender/functions/FN_all-c.h
@@ -11,8 +11,8 @@
extern "C" {
#endif
-void FN_initialize(void);
-void FN_exit(void);
+void FN_old_initialize(void);
+void FN_old_exit(void);
#ifdef __cplusplus
}
diff --git a/source/blender/functions/initialize.cpp b/source/blender/functions/initialize.cpp
index a7a17469c89..b2f7171c666 100644
--- a/source/blender/functions/initialize.cpp
+++ b/source/blender/functions/initialize.cpp
@@ -1,12 +1,12 @@
#include "FN_all.hpp"
-void FN_initialize()
+void FN_old_initialize()
{
FN::initialize_llvm();
FN::Types::initialize_types();
}
-void FN_exit()
+void FN_old_exit()
{
FN::Types::uninitialize_types();
}
diff --git a/source/blender/functions2/CMakeLists.txt b/source/blender/functions2/CMakeLists.txt
new file mode 100644
index 00000000000..2f07f0a9930
--- /dev/null
+++ b/source/blender/functions2/CMakeLists.txt
@@ -0,0 +1,39 @@
+set(INC
+ .
+ ../blenlib
+ ../makesdna
+ ../makesrna
+ ../blenkernel
+ ../depsgraph
+ ../windowmanager
+ ../../../intern/guardedalloc
+)
+
+set(INC_SYS
+ ${LLVM_INCLUDE_DIRS}
+ ${PYTHON_INCLUDE_DIRS}
+)
+
+if(WITH_PYTHON)
+ add_definitions(-DWITH_PYTHON)
+ list(APPEND INC
+ ../python
+ )
+endif()
+
+set(SRC
+ intern/cpp_type.cc
+ intern/cpp_types.cc
+ intern/initialize.cc
+
+ FN_cpp_type.h
+ FN_initialize.h
+
+ intern/cpp_types.h
+)
+
+set(LIB
+ bf_blenlib
+)
+
+blender_add_lib(bf_functions2 "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/functions2/FN_cpp_type.h b/source/blender/functions2/FN_cpp_type.h
new file mode 100644
index 00000000000..8ab1e9f5ce4
--- /dev/null
+++ b/source/blender/functions2/FN_cpp_type.h
@@ -0,0 +1,160 @@
+#ifndef __FN_CPP_TYPE_H__
+#define __FN_CPP_TYPE_H__
+
+#include "BLI_string_ref.h"
+#include "BLI_utility_mixins.h"
+#include "BLI_vector.h"
+
+namespace FN {
+
+using BLI::StringRef;
+using BLI::StringRefNull;
+
+class CPPType {
+ public:
+ using ConstructDefaultF = void (*)(const CPPType *self, void *ptr);
+ using DestructF = void (*)(void *ptr);
+ using CopyToInitializedF = void (*)(const void *src, void *dst);
+ using CopyToUninitializedF = void (*)(const void *src, void *dst);
+ using RelocateToInitializedF = void (*)(void *src, void *dst);
+ using RelocateToUninitializedF = void (*)(void *src, void *dst);
+
+ CPPType(std::string name,
+ uint size,
+ uint alignment,
+ bool trivially_destructible,
+ ConstructDefaultF construct_default,
+ DestructF destruct,
+ CopyToInitializedF copy_to_initialized,
+ CopyToUninitializedF copy_to_uninitialized,
+ RelocateToInitializedF relocate_to_initialized,
+ RelocateToUninitializedF relocate_to_uninitialized,
+ const CPPType *generalization)
+ : m_size(size),
+ m_alignment(alignment),
+ m_trivially_destructible(trivially_destructible),
+ m_construct_default(construct_default),
+ m_destruct(destruct),
+ m_copy_to_initialized(copy_to_initialized),
+ m_copy_to_uninitialized(copy_to_uninitialized),
+ m_relocate_to_initialized(relocate_to_initialized),
+ m_relocate_to_uninitialized(relocate_to_uninitialized),
+ m_generalization(generalization),
+ m_name(name)
+ {
+ BLI_assert(is_power_of_2_i(m_alignment));
+ BLI_assert(generalization == nullptr ||
+ (generalization->size() == size && generalization->alignment() <= alignment));
+
+ m_alignment_mask = m_alignment - 1;
+ }
+
+ virtual ~CPPType();
+
+ StringRefNull name() const
+ {
+ return m_name;
+ }
+
+ uint size() const
+ {
+ return m_size;
+ }
+
+ uint alignment() const
+ {
+ return m_alignment;
+ }
+
+ const CPPType *generalization() const
+ {
+ return m_generalization;
+ }
+
+ bool trivially_destructible() const
+ {
+ return m_trivially_destructible;
+ }
+
+ bool pointer_has_valid_alignment(const void *ptr) const
+ {
+ return (POINTER_AS_UINT(ptr) & m_alignment_mask) == 0;
+ }
+
+ void construct_default(void *ptr) const
+ {
+ BLI_assert(this->pointer_has_valid_alignment(ptr));
+
+ m_construct_default(this, ptr);
+ }
+
+ void destruct(void *ptr) const
+ {
+ BLI_assert(this->pointer_has_valid_alignment(ptr));
+
+ m_destruct(ptr);
+ }
+
+ void copy_to_initialized(const void *src, void *dst) const
+ {
+ BLI_assert(this->pointer_has_valid_alignment(src));
+ BLI_assert(this->pointer_has_valid_alignment(dst));
+
+ m_copy_to_initialized(src, dst);
+ }
+
+ void copy_to_uninitialized(const void *src, void *dst) const
+ {
+ BLI_assert(this->pointer_has_valid_alignment(src));
+ BLI_assert(this->pointer_has_valid_alignment(dst));
+
+ m_copy_to_uninitialized(src, dst);
+ }
+
+ void relocate_to_initialized(void *src, void *dst) const
+ {
+ BLI_assert(this->pointer_has_valid_alignment(src));
+ BLI_assert(this->pointer_has_valid_alignment(dst));
+
+ m_relocate_to_initialized(src, dst);
+ }
+
+ void relocate_to_uninitialized(void *src, void *dst) const
+ {
+ BLI_assert(this->pointer_has_valid_alignment(src));
+ BLI_assert(this->pointer_has_valid_alignment(dst));
+
+ m_relocate_to_uninitialized(src, dst);
+ }
+
+ bool is_same_or_generalization(const CPPType &other) const
+ {
+ if (&other == this) {
+ return true;
+ }
+ if (m_generalization == nullptr) {
+ return false;
+ }
+ return m_generalization->is_same_or_generalization(other);
+ }
+
+ private:
+ uint m_size;
+ uint m_alignment;
+ uint m_alignment_mask;
+ bool m_trivially_destructible;
+ ConstructDefaultF m_construct_default;
+ DestructF m_destruct;
+ CopyToInitializedF m_copy_to_initialized;
+ CopyToUninitializedF m_copy_to_uninitialized;
+ RelocateToInitializedF m_relocate_to_initialized;
+ RelocateToUninitializedF m_relocate_to_uninitialized;
+ const CPPType *m_generalization;
+ std::string m_name;
+};
+
+template<typename T> const CPPType &GET_TYPE();
+
+} // namespace FN
+
+#endif /* __FN_CPP_TYPE_H__ */
diff --git a/source/blender/functions2/FN_initialize.h b/source/blender/functions2/FN_initialize.h
new file mode 100644
index 00000000000..10e8a68f02d
--- /dev/null
+++ b/source/blender/functions2/FN_initialize.h
@@ -0,0 +1,10 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void FN_initialize(void);
+void FN_exit(void);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/functions2/intern/cpp_type.cc b/source/blender/functions2/intern/cpp_type.cc
new file mode 100644
index 00000000000..2e04b405a22
--- /dev/null
+++ b/source/blender/functions2/intern/cpp_type.cc
@@ -0,0 +1,9 @@
+#include "FN_cpp_type.h"
+
+namespace FN {
+
+CPPType::~CPPType()
+{
+}
+
+} // namespace FN
diff --git a/source/blender/functions2/intern/cpp_types.cc b/source/blender/functions2/intern/cpp_types.cc
new file mode 100644
index 00000000000..54d78882991
--- /dev/null
+++ b/source/blender/functions2/intern/cpp_types.cc
@@ -0,0 +1,120 @@
+#include "FN_cpp_type.h"
+#include "cpp_types.h"
+
+#include "DNA_object_types.h"
+
+#include "BLI_math_cxx.h"
+#include "BLI_vector.h"
+
+namespace FN {
+
+using BLI::Vector;
+
+static Vector<CPPType *, 4, BLI::RawAllocator> allocated_types;
+
+void free_cpp_types()
+{
+ for (CPPType *type : allocated_types) {
+ delete type;
+ }
+}
+
+template<typename T> void ConstructDefault_CB(const CPPType *UNUSED(self), void *ptr)
+{
+ BLI::construct_default((T *)ptr);
+}
+
+template<typename T, bool IsDefaultConstructible> struct DefaultConstructor;
+template<typename T> struct DefaultConstructor<T, true> {
+ static CPPType::ConstructDefaultF get_callback()
+ {
+ return ConstructDefault_CB<T>;
+ }
+};
+template<typename T> struct DefaultConstructor<T, false> {
+ static CPPType::ConstructDefaultF get_callback()
+ {
+ return nullptr;
+ }
+};
+
+template<typename T> void Destruct_CB(void *ptr)
+{
+ BLI::destruct((T *)ptr);
+}
+template<typename T> void CopyToInitialized_CB(const void *src, void *dst)
+{
+ *(T *)dst = *(T *)src;
+}
+template<typename T> void CopyToUninitialized_CB(const void *src, void *dst)
+{
+ BLI::uninitialized_copy_n((T *)src, 1, (T *)dst);
+}
+template<typename T> void RelocateToInitialized_CB(void *src, void *dst)
+{
+ BLI::relocate((T *)src, (T *)dst);
+}
+template<typename T> void RelocateToUninitialized_CB(void *src, void *dst)
+{
+ BLI::uninitialized_relocate((T *)src, (T *)dst);
+}
+
+#define CPP_TYPE_DECLARE(IDENTIFIER) static CPPType *TYPE_##IDENTIFIER = nullptr
+
+CPP_TYPE_DECLARE(float);
+CPP_TYPE_DECLARE(bool);
+CPP_TYPE_DECLARE(ObjectPtr);
+CPP_TYPE_DECLARE(int32);
+CPP_TYPE_DECLARE(rgba_f);
+CPP_TYPE_DECLARE(float3);
+CPP_TYPE_DECLARE(string);
+
+#undef CPP_TYPE_DECLARE
+
+void init_cpp_types()
+{
+
+#define CPP_TYPE_CONSTRUCTION(IDENTIFIER, TYPE_NAME) \
+ TYPE_##IDENTIFIER = new CPPType( \
+ STRINGIFY(IDENTIFIER), \
+ sizeof(TYPE_NAME), \
+ alignof(TYPE_NAME), \
+ std::is_trivially_destructible<TYPE_NAME>::value, \
+ DefaultConstructor<TYPE_NAME, \
+ std::is_default_constructible<TYPE_NAME>::value>::get_callback(), \
+ Destruct_CB<TYPE_NAME>, \
+ CopyToInitialized_CB<TYPE_NAME>, \
+ CopyToUninitialized_CB<TYPE_NAME>, \
+ RelocateToInitialized_CB<TYPE_NAME>, \
+ RelocateToUninitialized_CB<TYPE_NAME>, \
+ nullptr); \
+ allocated_types.append(TYPE_##IDENTIFIER)
+
+ CPP_TYPE_CONSTRUCTION(float, float);
+ CPP_TYPE_CONSTRUCTION(bool, bool);
+ CPP_TYPE_CONSTRUCTION(ObjectPtr, Object *);
+ CPP_TYPE_CONSTRUCTION(int32, int32_t);
+ CPP_TYPE_CONSTRUCTION(rgba_f, BLI::rgba_f);
+ CPP_TYPE_CONSTRUCTION(float3, BLI::float3);
+ CPP_TYPE_CONSTRUCTION(string, std::string);
+
+#undef CPP_TYPE_CONSTRUCTION
+}
+
+#define CPP_TYPE_GETTER(IDENTIFIER, TYPE_NAME) \
+ template<> const CPPType &GET_TYPE<TYPE_NAME>() \
+ { \
+ return *TYPE_##IDENTIFIER; \
+ }
+
+CPP_TYPE_GETTER(float, float)
+CPP_TYPE_GETTER(bool, bool)
+CPP_TYPE_GETTER(ObjectPtr, Object *)
+CPP_TYPE_GETTER(int32, int32_t)
+CPP_TYPE_GETTER(rgba_f, BLI::rgba_f)
+CPP_TYPE_GETTER(float3, BLI::float3)
+CPP_TYPE_GETTER(string, std::string)
+
+#undef CPP_TYPE_GETTER
+
+} // namespace FN
diff --git a/source/blender/functions2/intern/cpp_types.h b/source/blender/functions2/intern/cpp_types.h
new file mode 100644
index 00000000000..34299f20beb
--- /dev/null
+++ b/source/blender/functions2/intern/cpp_types.h
@@ -0,0 +1,11 @@
+#ifndef __FN_CPP_TYPES_H__
+#define __FN_CPP_TYPES_H__
+
+namespace FN {
+
+void init_cpp_types();
+void free_cpp_types();
+
+} // namespace FN
+
+#endif /* __FN_CPP_TYPES_H__ */
diff --git a/source/blender/functions2/intern/initialize.cc b/source/blender/functions2/intern/initialize.cc
new file mode 100644
index 00000000000..61f3214c4b2
--- /dev/null
+++ b/source/blender/functions2/intern/initialize.cc
@@ -0,0 +1,12 @@
+#include "FN_initialize.h"
+#include "cpp_types.h"
+
+void FN_initialize(void)
+{
+ FN::init_cpp_types();
+}
+
+void FN_exit(void)
+{
+ FN::free_cpp_types();
+}
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index f062d99f4fe..3cfbac5ad9f 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -119,6 +119,7 @@ set(LIB
bf_blenkernel
bf_blenlib
bf_functions
+ bf_functions2
bf_simulations
)
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 8e3f0cba7fe..73b0b09dd5c 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -37,6 +37,7 @@ set(INC
../makesrna
../nodes
../functions
+ ../functions2
../render/extern/include
../../../intern/clog
../../../intern/ghost
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 6b83a053e71..7627196fb48 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -133,6 +133,7 @@
#include "DRW_engine.h"
#include "FN_all-c.h"
+#include "FN_initialize.h"
#ifdef WITH_OPENSUBDIV
# include "BKE_subsurf.h"
@@ -661,6 +662,7 @@ void WM_exit_ex(bContext *C, const bool do_python)
BKE_blender_atexit();
FN_exit();
+ FN_old_exit();
if (MEM_get_memory_blocks_in_use() != 0) {
size_t mem_in_use = MEM_get_memory_in_use() + MEM_get_memory_in_use();