[Bf-blender-cvs] [180ad9f77e7] workspaces: Refactor workspace data accessing

Julian Eisel noreply at git.blender.org
Wed May 31 01:26:20 CEST 2017


Commit: 180ad9f77e75159dabecc2f53318d02745cef60d
Author: Julian Eisel
Date:   Tue May 30 23:50:50 2017 +0200
Branches: workspaces
https://developer.blender.org/rB180ad9f77e75159dabecc2f53318d02745cef60d

Refactor workspace data accessing

Following Campbell's and Bastien's suggestion to avoid the
all-or-nothing approach of using private headers.
Instead of using private headers we do some trickery to mark struct
members or whole structs as private.
This way we don't have to go overkill with accessors/mutators but keep
them where it makes sense.

For now this adds a macro based on DNA_DEPRECATED, just to mark certain
struct members as workspace-private (throws 'deprecated' warning if used
outside of workspace.c -- this doesn't work on MSVC though, not sure on
Clang).

Also, this adds a macro to mark struct members as workspace and file
read/write private, not sure if this is really worth it. Just thought it
might be worth considering, since some data is really workspace internal
but needs to be exposed for file read/write.

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

M	source/blender/CMakeLists.txt
M	source/blender/blenkernel/BKE_workspace.h
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/library_query.c
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/screen/workspace_edit.c
M	source/blender/editors/screen/workspace_layout_edit.c
R067	source/blender/makesdna/dna_workspace_types.h	source/blender/makesdna/DNA_workspace_types.h
M	source/blender/makesdna/intern/makesdna.c
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index b06c6fc66d8..1788c889719 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -90,7 +90,7 @@ set(SRC_DNA_INC
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view2d_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view3d_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_windowmanager_types.h
-	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/dna_workspace_types.h
+	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_workspace_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_world_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_movieclip_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_tracking_types.h
diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
index 732ed341af2..224a1f50429 100644
--- a/source/blender/blenkernel/BKE_workspace.h
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -65,28 +65,16 @@ void BKE_workspace_layout_remove(
         struct Main *bmain,
         WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL();
 
+
 /* -------------------------------------------------------------------- */
 /* General Utils */
 
-#define BKE_WORKSPACE_ITER_BEGIN(_workspace, _start_workspace) \
-	for (WorkSpace *_workspace = _start_workspace, *_workspace##_next; _workspace; _workspace = _workspace##_next) { \
-		_workspace##_next = ((ID *)_workspace)->next; /* support removing workspace from list */
-#define BKE_WORKSPACE_ITER_END } ((void)0)
-
 WorkSpaceLayout *BKE_workspace_layout_find(
         const WorkSpace *workspace, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 WorkSpaceLayout *BKE_workspace_layout_find_global(
         const struct Main *bmain, const struct bScreen *screen,
         WorkSpace **r_workspace) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT;
 
-#define BKE_WORKSPACE_LAYOUT_ITER_BEGIN(_layout, _start_layout) \
-	for (WorkSpaceLayout *_layout = _start_layout, *_layout##_next; _layout; _layout = _layout##_next) { \
-		_layout##_next = (WorkSpaceLayout *)((Link *)_layout)->next; /* support removing layout from list */
-#define BKE_WORKSPACE_LAYOUT_ITER_BACKWARD_BEGIN(_layout, _start_layout) \
-	for (WorkSpaceLayout *_layout = _start_layout, *_layout##_prev; _layout; _layout = _layout##_prev) { \
-		_layout##_prev = (WorkSpaceLayout *)((Link *)_layout)->prev; /* support removing layout from list */
-#define BKE_WORKSPACE_LAYOUT_ITER_END } ((void)0)
-
 WorkSpaceLayout *BKE_workspace_layout_iter_circular(
         const WorkSpace *workspace, WorkSpaceLayout *start,
         bool (*callback)(const WorkSpaceLayout *layout, void *arg),
@@ -101,13 +89,8 @@ WorkSpaceLayout *BKE_workspace_layout_iter_circular(
 
 WorkSpace *BKE_workspace_active_get(WorkSpaceInstanceHook *hook) GETTER_ATTRS;
 void       BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) SETTER_ATTRS;
-const char *BKE_workspace_name_get(const WorkSpace *workspace) GETTER_ATTRS;
-WorkSpace *BKE_workspace_temp_store_get(WorkSpaceInstanceHook *hook) GETTER_ATTRS;
-void       BKE_workspace_temp_store_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) SETTER_ATTRS;
 WorkSpaceLayout *BKE_workspace_active_layout_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS;
 void             BKE_workspace_active_layout_set(WorkSpaceInstanceHook *hook, WorkSpaceLayout *layout) SETTER_ATTRS;
-WorkSpaceLayout *BKE_workspace_temp_layout_store_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS;
-void             BKE_workspace_temp_layout_store_set(WorkSpaceInstanceHook *hook, WorkSpaceLayout *layout) SETTER_ATTRS;
 struct bScreen *BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS;
 void            BKE_workspace_active_screen_set(
         WorkSpaceInstanceHook *hook, struct WorkSpace *workspace, struct bScreen *screen) SETTER_ATTRS;
@@ -120,7 +103,8 @@ void               BKE_workspace_render_layer_set(WorkSpace *workspace, struct S
 struct ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) GETTER_ATTRS;
 
 const char *BKE_workspace_layout_name_get(const WorkSpaceLayout *layout) GETTER_ATTRS;
-void        BKE_workspace_layout_name_set(WorkSpace *workspace, WorkSpaceLayout *layout, const char *new_name) ATTR_NONNULL();
+void        BKE_workspace_layout_name_set(
+        WorkSpace *workspace, WorkSpaceLayout *layout, const char *new_name) ATTR_NONNULL();
 struct bScreen *BKE_workspace_layout_screen_get(const WorkSpaceLayout *layout) GETTER_ATTRS;
 void            BKE_workspace_layout_screen_set(WorkSpaceLayout *layout, struct bScreen *screen) SETTER_ATTRS;
 
@@ -128,19 +112,8 @@ WorkSpaceLayout *BKE_workspace_hook_layout_for_workspace_get(
         const WorkSpaceInstanceHook *hook, const WorkSpace *workspace) GETTER_ATTRS;
 void             BKE_workspace_hook_layout_for_workspace_set(
         WorkSpaceInstanceHook *hook, WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL();
-struct ListBase *BKE_workspace_hook_layout_relations_get(WorkSpace *workspace) GETTER_ATTRS;
-
-void BKE_workspace_relation_data_get(
-        const struct WorkSpaceDataRelation *relation,
-        void **parent, void **data) ATTR_NONNULL();
-void BKE_workspace_relation_data_set(struct WorkSpaceDataRelation *relation, void *parent, void *data) ATTR_NONNULL();
 
 #undef GETTER_ATTRS
 #undef SETTER_ATTRS
 
-/* -------------------------------------------------------------------- */
-/* Don't use outside of BKE! */
-
-WorkSpace *BKE_workspace_alloc(void) ATTR_WARN_UNUSED_RESULT;
-
 #endif /* __BKE_WORKSPACE_H__ */
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index fc5991e2bba..9e244246e16 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -32,6 +32,7 @@
 
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_workspace_types.h"
 
 #include "BLI_listbase.h"
 #include "BLI_string.h"
@@ -539,10 +540,9 @@ bool BKE_blendfile_workspace_config_write(Main *bmain, const char *filepath, Rep
 
 	BKE_blendfile_write_partial_begin(bmain);
 
-	BKE_WORKSPACE_ITER_BEGIN (workspace, bmain->workspaces.first) {
-		ID *workspace_id = (ID *)workspace;
-		BKE_blendfile_write_partial_tag_ID(workspace_id, true);
-	} BKE_WORKSPACE_ITER_END;
+	for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+		BKE_blendfile_write_partial_tag_ID(&workspace->id, true);
+	}
 
 	if (BKE_blendfile_write_partial(bmain, filepath, fileflags, reports)) {
 		retval = true;
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 9170605eeb7..b81465a1b1d 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -70,6 +70,7 @@
 #include "DNA_vfont_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_world_types.h"
+#include "DNA_workspace_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
@@ -121,7 +122,6 @@
 #include "BKE_scene.h"
 #include "BKE_text.h"
 #include "BKE_texture.h"
-#include "BKE_workspace.h"
 #include "BKE_world.h"
 
 #include "DEG_depsgraph.h"
@@ -977,7 +977,7 @@ void *BKE_libblock_alloc_notest(short type)
 			id = MEM_callocN(sizeof(CacheFile), "Cache File");
 			break;
 		case ID_WS:
-			id = (ID *)BKE_workspace_alloc();
+			id = MEM_callocN(sizeof(WorkSpace), "Workspace");
 			break;
 	}
 	return id;
diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c
index ba5ecfef678..d2ee11cc397 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -62,6 +62,7 @@
 #include "DNA_text_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
 #include "DNA_world_types.h"
 
 #include "BLI_utildefines.h"
@@ -980,13 +981,13 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
 				WorkSpace *workspace = (WorkSpace *)id;
 				ListBase *layouts = BKE_workspace_layouts_get(workspace);
 
-				BKE_WORKSPACE_LAYOUT_ITER_BEGIN (layout, layouts->first) {
+				for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) {
 					bScreen *screen = BKE_workspace_layout_screen_get(layout);
 
 					CALLBACK_INVOKE(screen, IDWALK_CB_NOP);
 					/* allow callback to set a different screen */
 					BKE_workspace_layout_screen_set(layout, screen);
-				} BKE_WORKSPACE_LAYOUT_ITER_END;
+				}
 
 				break;
 			}
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 526bcba9206..12bfedff6d2 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -22,8 +22,8 @@
  *  \ingroup bke
  */
 
-/* allow including specially guarded dna_workspace_types.h */
-#define DNA_NAMESPACE_WORKSPACE
+/* allow accessing private members of DNA_workspace_types.h */
+#define DNA_PRIVATE_WORKSPACE_ALLOW
 
 #include <stdlib.h>
 
@@ -40,7 +40,7 @@
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
-#include "dna_workspace_types.h"
+#include "DNA_workspace_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -48,14 +48,6 @@
 /* -------------------------------------------------------------------- */
 /* Internal utils */
 
-/**
- * Only to be called by #BKE_libblock_alloc_notest! Always use BKE_workspace_add to add a new workspace.
- */
-WorkSpace *BKE_workspace_alloc(void)
-{
-	return MEM_callocN(sizeof(WorkSpace), __func__);
-}
-
 static void workspace_layout_name_set(
         WorkSpace *workspace, WorkSpaceLayout *layout, const char *new_name)
 {
@@ -162,9 +154,10 @@ void BKE_workspace_free(WorkSpace *workspace)
 
 void BKE_workspace_remove(Main *bmain, WorkSpace *workspace)
 {
-	BKE_WORKSPACE_LAYOUT_ITER_BEGIN (layout, workspace->layouts.first) {
+	for (WorkSpaceLayout *layout = workspace->layouts.first, *layout_next; layout; layout = layout_next) {
+		layout_next = layout->next;
 		BKE_workspace_layout_remove(bmain, workspace, layout);
-	} BKE_WORKSPACE_LAYOUT_ITER_END;
+	}
 
 	BKE_libblock_free(bmain, w

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list