[Bf-blender-cvs] [8adb1e80b9] temp-workspace-multi-window: Moving forward, various of changes

Julian Eisel noreply at git.blender.org
Fri Mar 3 23:55:59 CET 2017


Commit: 8adb1e80b940b1751bc5f18bf46c6c4542c3c238
Author: Julian Eisel
Date:   Fri Mar 3 23:53:56 2017 +0100
Branches: temp-workspace-multi-window
https://developer.blender.org/rB8adb1e80b940b1751bc5f18bf46c6c4542c3c238

Moving forward, various of changes

Mainly:
- Store/use information in layout-type for creating screens with the layout instance
- Properly create layout instances when creating workspaces/layouts
- Fix double-free
- Fix memory leaks

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

M	source/blender/blenkernel/BKE_library_remap.h
M	source/blender/blenkernel/BKE_workspace.h
M	source/blender/blenkernel/intern/library_remap.c
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/workspace/screen_edit.c
M	source/blender/editors/workspace/screen_intern.h
M	source/blender/editors/workspace/screen_ops.c
M	source/blender/editors/workspace/workspace_edit.c
M	source/blender/editors/workspace/workspace_layout_edit.c
M	source/blender/makesdna/dna_workspace_types.h
M	source/blender/windowmanager/intern/wm.c
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/blender/windowmanager/intern/wm_window.c
M	source/blender/windowmanager/wm.h
M	source/blender/windowmanager/wm_window.h

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

diff --git a/source/blender/blenkernel/BKE_library_remap.h b/source/blender/blenkernel/BKE_library_remap.h
index 53d438a0fd..2de78ea994 100644
--- a/source/blender/blenkernel/BKE_library_remap.h
+++ b/source/blender/blenkernel/BKE_library_remap.h
@@ -66,7 +66,7 @@ void BKE_libblock_relink_ex(
 
 void  BKE_libblock_relink_to_newid(struct ID *id) ATTR_NONNULL();
 
-typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *);
+typedef void (*BKE_library_free_window_manager_cb)(struct Main *, struct bContext *, struct wmWindowManager *);
 typedef void (*BKE_library_free_notifier_reference_cb)(const void *);
 typedef void (*BKE_library_remap_editor_id_reference_cb)(struct ID *, struct ID *);
 
diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
index 6334b32ea9..1ff1549c34 100644
--- a/source/blender/blenkernel/BKE_workspace.h
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -57,12 +57,13 @@ WorkSpace *BKE_workspace_add(struct Main *bmain, const char *name);
 void BKE_workspace_free(WorkSpace *ws);
 void BKE_workspace_remove(WorkSpace *workspace, struct Main *bmain);
 
-WorkSpaceLayout *BKE_workspace_layout_add_from_type(WorkSpace *workspace, WorkSpaceLayoutType *type, struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
-WorkSpaceLayoutType *BKE_workspace_layout_type_add(WorkSpace *workspace, const char *name) ATTR_NONNULL();
-WorkSpaceLayout *BKE_workspace_layout_add(WorkSpace *workspace, struct bScreen *screen) ATTR_NONNULL();
+WorkSpaceLayout *BKE_workspace_layout_add_from_type(WorkSpace *workspace, WorkSpaceLayoutType *type,
+                                                    struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+WorkSpaceLayoutType *BKE_workspace_layout_type_add(WorkSpace *workspace, const char *name,
+                                                   struct ListBase *vertbase, struct ListBase *areabase) ATTR_NONNULL();
 void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout, struct Main *bmain) ATTR_NONNULL();
 WorkSpaceHook *BKE_workspace_hook_new(void) ATTR_WARN_UNUSED_RESULT;
-void BKE_workspace_hook_delete(WorkSpaceHook *hook) ATTR_NONNULL();
+void BKE_workspace_hook_delete(struct Main *bmain, WorkSpaceHook *hook) ATTR_NONNULL();
 
 
 /* -------------------------------------------------------------------- */
@@ -73,6 +74,8 @@ void BKE_workspace_hook_delete(WorkSpaceHook *hook) ATTR_NONNULL();
 		_workspace##_next = BKE_workspace_next_get(_workspace); /* support removing workspace from list */
 #define BKE_workspace_iter_end } (void)0
 
+void BKE_workspace_change_prepare(struct Main *bmain, WorkSpaceHook *workspace_hook) ATTR_NONNULL();
+
 void BKE_workspaces_transform_orientation_remove(const struct ListBase *workspaces,
                                                  const struct TransformOrientation *orientation) ATTR_NONNULL();
 
@@ -119,9 +122,12 @@ void            BKE_workspace_object_mode_set(WorkSpace *workspace, const enum O
 struct SceneLayer *BKE_workspace_render_layer_get(const WorkSpace *workspace) GETTER_ATTRS;
 void               BKE_workspace_render_layer_set(WorkSpace *workspace, struct SceneLayer *layer) SETTER_ATTRS;
 struct ListBase *BKE_workspace_layouts_get(WorkSpace *workspace) GETTER_ATTRS;
-WorkSpaceLayoutType *BKE_workspace_active_layout_type_get(WorkSpace *workspace) GETTER_ATTRS;
+WorkSpaceLayoutType *BKE_workspace_active_layout_type_get(const WorkSpace *workspace) GETTER_ATTRS;
+void                 BKE_workspace_active_layout_type_set(WorkSpace *workspace, WorkSpaceLayoutType *layout_type) SETTER_ATTRS;
 struct ListBase *BKE_workspace_layout_types_get(WorkSpace *workspace) GETTER_ATTRS;
-const char      *BKE_workspace_layout_type_name_get(WorkSpaceLayoutType *layout_type) GETTER_ATTRS;
+const char      *BKE_workspace_layout_type_name_get(const WorkSpaceLayoutType *layout_type) GETTER_ATTRS;
+struct ListBase *BKE_workspace_layout_type_vertbase_get(const WorkSpaceLayoutType *type) GETTER_ATTRS;
+struct ListBase *BKE_workspace_layout_type_areabase_get(const WorkSpaceLayoutType *type) GETTER_ATTRS;
 WorkSpaceLayoutType *BKE_workspace_layout_type_next_get(WorkSpaceLayoutType *layout_type) GETTER_ATTRS;
 WorkSpaceLayout *BKE_workspace_new_layout_get(const WorkSpace *workspace) GETTER_ATTRS;
 void             BKE_workspace_new_layout_set(WorkSpace *workspace, WorkSpaceLayout *layout) SETTER_ATTRS;
diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c
index b5f795545c..7b507809a7 100644
--- a/source/blender/blenkernel/intern/library_remap.c
+++ b/source/blender/blenkernel/intern/library_remap.c
@@ -859,7 +859,7 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, const bool do_id_user, const b
 			break;
 		case ID_WM:
 			if (free_windowmanager_cb)
-				free_windowmanager_cb(NULL, (wmWindowManager *)id);
+				free_windowmanager_cb(bmain, NULL, (wmWindowManager *)id);
 			break;
 		case ID_GD:
 			BKE_gpencil_free((bGPdata *)id, true);
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 55c9761430..c3c1f39ade 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -82,7 +82,6 @@ WorkSpace *BKE_workspace_add(Main *bmain, const char *name)
 void BKE_workspace_free(WorkSpace *ws)
 {
 	BLI_freelistN(&ws->layout_types);
-	BLI_freelistN(&ws->layouts);
 }
 
 void BKE_workspace_remove(WorkSpace *workspace, Main *bmain)
@@ -106,7 +105,7 @@ WorkSpaceLayout *BKE_workspace_layout_add_from_type(WorkSpace *workspace, WorkSp
 {
 	WorkSpaceLayout *layout = MEM_mallocN(sizeof(*layout), __func__);
 
-//	BLI_assert(!workspaces_is_screen_used(G.main, screen));
+	BLI_assert(!workspaces_is_screen_used(G.main, screen));
 
 	layout->type = type;
 	layout->screen = screen;
@@ -115,25 +114,19 @@ WorkSpaceLayout *BKE_workspace_layout_add_from_type(WorkSpace *workspace, WorkSp
 	return layout;
 }
 
-WorkSpaceLayoutType *BKE_workspace_layout_type_add(WorkSpace *workspace, const char *name)
+WorkSpaceLayoutType *BKE_workspace_layout_type_add(WorkSpace *workspace, const char *name,
+                                                   ListBase *vertbase, ListBase *areabase)
 {
 	WorkSpaceLayoutType *layout_type = MEM_mallocN(sizeof(*layout_type), __func__);
 
-	layout_type->name = name;
+	layout_type->name = name; /* XXX should probably copy name */
+	layout_type->vertbase = vertbase;
+	layout_type->areabase = areabase;
 	BLI_addhead(&workspace->layout_types, layout_type);
 
 	return layout_type;
 }
 
-/**
- * Add a new layout to \a workspace for \a screen.
- */
-WorkSpaceLayout *BKE_workspace_layout_add(WorkSpace *workspace, bScreen *screen)
-{
-	WorkSpaceLayoutType *layout_type = BKE_workspace_layout_type_add(workspace, screen->id.name + 2);
-	return BKE_workspace_layout_add_from_type(workspace, layout_type, screen);
-}
-
 void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout, Main *bmain)
 {
 	WorkSpaceLayoutType *layout_type = layout->type;
@@ -146,8 +139,14 @@ WorkSpaceHook *BKE_workspace_hook_new(void)
 	return MEM_callocN(sizeof(WorkSpaceHook), __func__);
 }
 
-void BKE_workspace_hook_delete(WorkSpaceHook *hook)
+void BKE_workspace_hook_delete(Main *bmain, WorkSpaceHook *hook)
 {
+	for (WorkSpaceLayout *layout = hook->layouts.first, *layout_next; layout; layout = layout_next) {
+		layout_next = layout->next;
+
+		BKE_libblock_free(bmain, layout->screen);
+		BLI_freelinkN(&hook->layouts, layout);
+	}
 	MEM_freeN(hook);
 }
 
@@ -155,6 +154,30 @@ void BKE_workspace_hook_delete(WorkSpaceHook *hook)
 /* -------------------------------------------------------------------- */
 /* General Utils */
 
+void BKE_workspace_change_prepare(Main *bmain, WorkSpaceHook *workspace_hook)
+{
+	WorkSpace *workspace = workspace_hook->act_workspace;
+	BLI_freelistN(&workspace_hook->layouts);
+
+	for (WorkSpaceLayoutType *type = workspace->layout_types.first; type; type = type->next) {
+		bScreen *screen = BKE_libblock_alloc(bmain, ID_SCR, type->name);
+		WorkSpaceLayout *layout;
+
+		for (ScrVert *sv = type->vertbase->first; sv; sv = sv->next) {
+			ScrVert *sv_new = MEM_callocN(sizeof(ScrVert), "workspace_change_add_screenvert");
+			*sv_new = *sv;
+			BLI_addtail(&screen->vertbase, sv_new);
+		}
+		for (ScrArea *sa = type->areabase->first; sa; sa = sa->next) {
+			ScrArea *sa_new = MEM_callocN(sizeof(ScrArea), "workspace_change_add_screenarea");
+			*sa_new = *sa;
+			BLI_addtail(&screen->areabase, sa_new);
+		}
+		layout = BKE_workspace_layout_add_from_type(workspace, type, screen);
+		BLI_addtail(&workspace_hook->layouts, layout);
+	}
+}
+
 void BKE_workspaces_transform_orientation_remove(const ListBase *workspaces, const TransformOrientation *orientation)
 {
 	BKE_workspace_iter_begin(workspace, workspaces->first)
@@ -309,21 +332,34 @@ ListBase *BKE_workspace_layouts_get(WorkSpace *workspace)
 	return &workspace->layouts;
 }
 
-WorkSpaceLayoutType *BKE_workspace_active_layout_type_get(WorkSpace *workspace)
+WorkSpaceLayoutType *BKE_workspace_active_layout_type_get(const WorkSpace *workspace)
 {
 	return workspace->act_layout_type;
 }
+void BKE_workspace_active_layout_type_set(WorkSpace *workspace, WorkSpaceLayoutType *layout_type)
+{
+	workspace->act_layout_type = layout_type;
+}
 
 ListBase *BKE_workspace_layout_types_get(WorkSpace *workspace)
 {
 	return &workspace->layout_types;
 }
 
-const char *BKE_workspace_layout_type_name_get(WorkSpaceLayoutType *layout_type)
+const char *BKE_workspace_layout_type_name_get(const WorkSpaceLayoutType *layout_type)
 {
 	return layout_type->name;
 }
 
+ListBase *BKE_workspace_layout_type_vertbase_get(const WorkSpaceLayoutType *type)
+{
+	return type->areabase;
+}
+ListBase *BKE_workspace_layout_type_areabase_get(const WorkSpaceLayoutType *type)
+{
+	return type->areabase;
+}
+
 WorkSpaceLayoutType *BKE_workspace_layout_type_next_get(WorkSpaceLayoutType *layout_type)
 {
 	return layout_type->next;
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index a6b20467c9..fe4d6eeee0 100644
--- a/source/blender/blenloader/inte

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list