Commit: 1b6fddb9683e9dfb7b65d8ff2f30c302d67817a2
Author: Julian Eisel
Date:   Fri Apr 13 20:29:16 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB1b6fddb9683e9dfb7b65d8ff2f30c302d67817a2

Cleanup: split off area reading/writing functions, from topbar branch.

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

M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 4308fe0fee3..c0d50d341b4 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6516,6 +6516,588 @@ static void direct_link_scene(FileData *fd, Scene *sce, 
Main *bmain)
        direct_link_workspace_link_scene_data(fd, sce, &bmain->workspaces);
 }
 
+/* ****************** READ GREASE PENCIL ***************** */
+
+/* relink's grease pencil data's refs */
+static void lib_link_gpencil(FileData *fd, Main *main)
+{
+       for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
+               if (gpd->id.tag & LIB_TAG_NEED_LINK) {
+                       IDP_LibLinkProperty(gpd->id.properties, fd);
+                       lib_link_animdata(fd, &gpd->id, gpd->adt);
+
+                       gpd->id.tag &= ~LIB_TAG_NEED_LINK;
+               }
+       }
+}
+
+/* relinks grease-pencil data - used for direct_link and old file linkage */
+static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
+{
+       bGPDlayer *gpl;
+       bGPDframe *gpf;
+       bGPDstroke *gps;
+       bGPDpalette *palette;
+
+       /* we must firstly have some grease-pencil data to link! */
+       if (gpd == NULL)
+               return;
+       
+       /* relink animdata */
+       gpd->adt = newdataadr(fd, gpd->adt);
+       direct_link_animdata(fd, gpd->adt);
+
+       /* relink palettes */
+       link_list(fd, &gpd->palettes);
+       for (palette = gpd->palettes.first; palette; palette = palette->next) {
+               link_list(fd, &palette->colors);
+       }
+
+       /* relink layers */
+       link_list(fd, &gpd->layers);
+       
+       for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+               /* parent */
+               gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent);
+               /* relink frames */
+               link_list(fd, &gpl->frames);
+               gpl->actframe = newdataadr(fd, gpl->actframe);
+               
+               for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+                       /* relink strokes (and their points) */
+                       link_list(fd, &gpf->strokes);
+                       
+                       for (gps = gpf->strokes.first; gps; gps = gps->next) {
+                               gps->points = newdataadr(fd, gps->points);
+                               
+                               /* the triangulation is not saved, so need to 
be recalculated */
+                               gps->triangles = NULL;
+                               gps->tot_triangles = 0;
+                               gps->flag |= GP_STROKE_RECALC_CACHES;
+                               /* the color pointer is not saved, so need to 
be recalculated using the color name */
+                               gps->palcolor = NULL;
+                               gps->flag |= GP_STROKE_RECALC_COLOR;
+                       }
+               }
+       }
+}
+
+/* *********** READ AREA **************** */
+
+static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
+{
+       Panel *pa;
+       uiList *ui_list;
+
+       link_list(fd, &ar->panels);
+
+       for (pa = ar->panels.first; pa; pa = pa->next) {
+               pa->paneltab = newdataadr(fd, pa->paneltab);
+               pa->runtime_flag = 0;
+               pa->activedata = NULL;
+               pa->type = NULL;
+       }
+
+       link_list(fd, &ar->panels_category_active);
+
+       link_list(fd, &ar->ui_lists);
+
+       for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) {
+               ui_list->type = NULL;
+               ui_list->dyn_data = NULL;
+               ui_list->properties = newdataadr(fd, ui_list->properties);
+               IDP_DirectLinkGroup_OrFree(&ui_list->properties, (fd->flags & 
FD_FLAGS_SWITCH_ENDIAN), fd);
+       }
+
+       link_list(fd, &ar->ui_previews);
+
+       if (spacetype == SPACE_EMPTY) {
+               /* unkown space type, don't leak regiondata */
+               ar->regiondata = NULL;
+       }
+       else {
+               ar->regiondata = newdataadr(fd, ar->regiondata);
+               if (ar->regiondata) {
+                       if (spacetype == SPACE_VIEW3D) {
+                               RegionView3D *rv3d = ar->regiondata;
+
+                               rv3d->localvd = newdataadr(fd, rv3d->localvd);
+                               rv3d->clipbb = newdataadr(fd, rv3d->clipbb);
+
+                               rv3d->depths = NULL;
+                               rv3d->gpuoffscreen = NULL;
+                               rv3d->render_engine = NULL;
+                               rv3d->sms = NULL;
+                               rv3d->smooth_timer = NULL;
+                               rv3d->compositor = NULL;
+                               rv3d->viewport = NULL;
+                       }
+               }
+       }
+       
+       ar->v2d.tab_offset = NULL;
+       ar->v2d.tab_num = 0;
+       ar->v2d.tab_cur = 0;
+       ar->v2d.sms = NULL;
+       BLI_listbase_clear(&ar->panels_category);
+       BLI_listbase_clear(&ar->handlers);
+       BLI_listbase_clear(&ar->uiblocks);
+       ar->headerstr = NULL;
+       ar->visible = 0;
+       ar->type = NULL;
+       ar->swap = 0;
+       ar->do_draw = 0;
+       ar->manipulator_map = NULL;
+       ar->regiontimer = NULL;
+       memset(&ar->drawrct, 0, sizeof(ar->drawrct));
+}
+
+static void direct_link_area(FileData *fd, ScrArea *area)
+{
+       SpaceLink *sl;
+       ARegion *ar;
+
+       link_list(fd, &(area->spacedata));
+       link_list(fd, &(area->regionbase));
+
+       BLI_listbase_clear(&area->handlers);
+       area->type = NULL;      /* spacetype callbacks */
+       area->region_active_win = -1;
+
+       /* if we do not have the spacetype registered (game player), we cannot
+        * free it, so don't allocate any new memory for such spacetypes. */
+       if (!BKE_spacetype_exists(area->spacetype)) {
+               area->spacetype = SPACE_EMPTY;
+       }
+
+       for (ar = area->regionbase.first; ar; ar = ar->next) {
+               direct_link_region(fd, ar, area->spacetype);
+       }
+
+       /* accident can happen when read/save new file with older version */
+       /* 2.50: we now always add spacedata for info */
+       if (area->spacedata.first == NULL) {
+               SpaceInfo *sinfo= MEM_callocN(sizeof(SpaceInfo), "spaceinfo");
+               area->spacetype= sinfo->spacetype= SPACE_INFO;
+               BLI_addtail(&area->spacedata, sinfo);
+       }
+       /* add local view3d too */
+       else if (area->spacetype == SPACE_VIEW3D) {
+               blo_do_versions_view3d_split_250(area->spacedata.first, 
&area->regionbase);
+       }
+
+       /* incase we set above */
+       area->butspacetype = area->spacetype;
+
+       for (sl = area->spacedata.first; sl; sl = sl->next) {
+               link_list(fd, &(sl->regionbase));
+
+               /* if we do not have the spacetype registered (game player), we 
cannot
+                * free it, so don't allocate any new memory for such 
spacetypes. */
+               if (!BKE_spacetype_exists(sl->spacetype))
+                       sl->spacetype = SPACE_EMPTY;
+
+               for (ar = sl->regionbase.first; ar; ar = ar->next)
+                       direct_link_region(fd, ar, sl->spacetype);
+
+               if (sl->spacetype == SPACE_VIEW3D) {
+                       View3D *v3d= (View3D*) sl;
+
+                       v3d->flag |= V3D_INVALID_BACKBUF;
+
+                       if (v3d->gpd) {
+                               v3d->gpd = newdataadr(fd, v3d->gpd);
+                               direct_link_gpencil(fd, v3d->gpd);
+                       }
+                       v3d->localvd = newdataadr(fd, v3d->localvd);
+                       BLI_listbase_clear(&v3d->afterdraw_transp);
+                       BLI_listbase_clear(&v3d->afterdraw_xray);
+                       BLI_listbase_clear(&v3d->afterdraw_xraytransp);
+                       v3d->properties_storage = NULL;
+                       v3d->defmaterial = NULL;
+
+                       /* render can be quite heavy, set to solid on load */
+                       if (v3d->drawtype == OB_RENDER)
+                               v3d->drawtype = OB_SOLID;
+                       v3d->prev_drawtype = OB_SOLID;
+
+                       if (v3d->fx_settings.dof)
+                               v3d->fx_settings.dof = newdataadr(fd, 
v3d->fx_settings.dof);
+                       if (v3d->fx_settings.ssao)
+                               v3d->fx_settings.ssao = newdataadr(fd, 
v3d->fx_settings.ssao);
+
+                       blo_do_versions_view3d_split_250(v3d, &sl->regionbase);
+               }
+               else if (sl->spacetype == SPACE_IPO) {
+                       SpaceIpo *sipo = (SpaceIpo *)sl;
+
+                       sipo->ads = newdataadr(fd, sipo->ads);
+                       BLI_listbase_clear(&sipo->ghostCurves);
+               }
+               else if (sl->spacetype == SPACE_NLA) {
+                       SpaceNla *snla = (SpaceNla *)sl;
+
+                       snla->ads = newdataadr(fd, snla->ads);
+               }
+               else if (sl->spacetype == SPACE_OUTLINER) {
+                       SpaceOops *soops = (SpaceOops *) sl;
+
+                       /* use newdataadr_no_us and do not free old memory 
avoiding double
+                        * frees and use of freed memory. this could happen 
because of a
+                        * bug fixed in revision 58959 where the treestore 
memory address
+                        * was not unique */
+                       TreeStore *ts = newdataadr_no_us(fd, soops->treestore);
+                       soops->treestore = NULL;
+                       if (ts) {
+                               TreeStoreElem *elems = newdataadr_no_us(fd, 
ts->data);
+
+                               soops->treestore = 
BLI_mempool_create(sizeof(TreeStoreElem), ts->usedelem,
+                                                                     512, 
BLI_MEMPOOL_ALLOW_ITER);
+                               if (ts->usedelem && elems) {
+                                       int i;
+                                       for (i = 0; i < ts->usedelem; i++) {
+                                               TreeStoreElem *new_elem = 
BLI_mempool_alloc(soops->treestore);
+                                               *new_elem = elems[i];
+                                       }
+                               }
+                               /* we only saved what was used */
+                               soops->storeflag |= SO_TREESTORE_CLEANUP;       
// at first draw
+                       }
+                       soops->treehash = NULL;
+                       soops->tree.first = soops->tree.last= NULL;
+               }
+               else if (sl->spacetype == SPACE_IMAGE) {
+                       SpaceImage *sima = (SpaceImage *)sl;
+
+                       sima->iuser.scene = NULL;
+                       sima->iuser.ok = 1;
+                       sima->scopes.waveform_1 = NULL;
+                       sima->scopes.waveform_2 = NULL;
+                       sima->scopes.waveform_3 = NULL;
+                       sima->scopes.vecscope = NULL;
+                       sima->scopes.ok = 0;
+
+                       /* WARNING: gpencil data is no longer stored directly 
in sima after 2.5 
+                        * so sacrifice a few old files for now to avoid 
crashes with new files!
+                        * committed: r28002 */
+#if 0
+                       sima->gpd = newdataadr(fd, sima->gpd);
+                       if (sima->gpd)
+                               direct_link_gpencil(fd, sima->gpd);
+#endif
+               }
+               else if (sl->spacetype == SPACE_NODE) {
+                       SpaceNode *snode = (SpaceNode *)sl;
+                       
+                       if (snode->gpd) {
+                               snode->gpd = newdataadr(fd, snode->gpd);
+                               direct_link_gpencil(fd, snode->gpd);
+                       }
+                       
+                       link_list(fd, &snode->treepath);
+                       snode->edittree = NULL;
+                       snode->iofsd = NULL;
+                       BLI_listbase_clear(&snode->linkdrag);
+               }
+               else if (sl->spacetype == SPACE_TEXT) {
+                       SpaceText *st= (SpaceText *)sl;
+                       
+                       st->drawcache = NULL;
+                       st->scroll_accum[0] = 0.0f;
+                       st->scroll_accum[1] = 0.0f;
+               }
+               else if (sl->spacetype == SPACE_TIME) {
+                       SpaceTime *stime = (SpaceTime *)sl;
+                       BLI_listbase_clear(&stime->caches);
+               }
+               else if (sl->spacetype == SPACE_LOGIC) {
+                       SpaceLogic *slogic = (SpaceLogic *)sl;
+                       
+                       /* XXX: this is new stuff, which shouldn't be directly 
linking to gpd... */
+                       if (slogic->gpd) {
+                               slogic->gpd = newdataadr(fd, slogic->gpd);
+                               direct_link_gpencil(fd, slogic->gpd);
+                       }
+               }
+               else if (sl->spacetype == SPACE_SEQ) {
+                       SpaceSeq *sseq = (SpaceSeq *)sl;
+                       
+                       /* grease pencil data is not a direct data and can't be 
linked from direct_link*
+                        * functions, it should be linked from lib_link* 
functions instead
+                        *
+                        * otherwise it'll lead to lost grease data on open 
because it'll likely be
+                        * read from file after all other users of grease 
pencil and newdataadr would
+                        * simple return NULL here (sergey)
+                        */
+#if 0
+                       if (sseq->gpd) {
+                               sseq->gpd = newdataadr(fd, sseq->gpd);
+                               direct_link_gpencil(fd, sseq->gpd);
+                       }
+#endif
+                       sseq->scopes.reference_ibuf = NULL;
+                       sseq->scopes.zebra_ibuf = NULL;
+                       sseq->scopes.wavefo

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to