Render *Controller::RenderStrokes(Render *re, bool render) { int totmesh = 0; _Chrono.start(); BlenderStrokeRenderer *blenderRenderer = new BlenderStrokeRenderer(re, ++_render_count); if (render) { _Canvas->Render(blenderRenderer); totmesh = blenderRenderer->GenerateScene(); } real d = _Chrono.stop(); if (G.debug & G_DEBUG_FREESTYLE) { cout << "Temporary scene generation: " << d << endl; } _Chrono.start(); Render *freestyle_render = blenderRenderer->RenderScene(re, render); d = _Chrono.stop(); if (G.debug & G_DEBUG_FREESTYLE) { cout << "Stroke rendering : " << d << endl; uintptr_t mem_in_use = MEM_get_memory_in_use(); uintptr_t mmap_in_use = MEM_get_mapped_memory_in_use(); uintptr_t peak_memory = MEM_get_peak_memory(); float megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0); float mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0); float megs_peak_memory = (peak_memory) / (1024.0 * 1024.0); printf("%d objs, %d verts, %d faces, mem %.2fM (%.2fM, peak %.2fM)\n", totmesh, freestyle_render->i.totvert, freestyle_render->i.totface, megs_used_memory, mmap_used_memory, megs_peak_memory); } delete blenderRenderer; return freestyle_render; }
/* str is IMA_MAX_RENDER_TEXT in size */ static void make_renderinfo_string(RenderStats *rs, Scene *scene, char *str) { char info_time_str[32]; // used to be extern to header_info.c uintptr_t mem_in_use, mmap_in_use, peak_memory; float megs_used_memory, mmap_used_memory, megs_peak_memory; char *spos = str; mem_in_use = MEM_get_memory_in_use(); mmap_in_use = MEM_get_mapped_memory_in_use(); peak_memory = MEM_get_peak_memory(); megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0); mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0); megs_peak_memory = (peak_memory) / (1024.0 * 1024.0); if (scene->lay & 0xFF000000) spos += sprintf(spos, IFACE_("Localview | ")); else if (scene->r.scemode & R_SINGLE_LAYER) spos += sprintf(spos, IFACE_("Single Layer | ")); spos += sprintf(spos, IFACE_("Frame:%d "), (scene->r.cfra)); if (rs->statstr) { spos += sprintf(spos, "| %s ", rs->statstr); } else { if (rs->totvert) spos += sprintf(spos, IFACE_("Ve:%d "), rs->totvert); if (rs->totface) spos += sprintf(spos, IFACE_("Fa:%d "), rs->totface); if (rs->tothalo) spos += sprintf(spos, IFACE_("Ha:%d "), rs->tothalo); if (rs->totstrand) spos += sprintf(spos, IFACE_("St:%d "), rs->totstrand); if (rs->totlamp) spos += sprintf(spos, IFACE_("La:%d "), rs->totlamp); if (rs->mem_peak == 0.0f) spos += sprintf(spos, IFACE_("Mem:%.2fM (%.2fM, Peak %.2fM) "), megs_used_memory, mmap_used_memory, megs_peak_memory); else spos += sprintf(spos, IFACE_("Mem:%.2fM, Peak: %.2fM "), rs->mem_used, rs->mem_peak); if (rs->curfield) spos += sprintf(spos, IFACE_("Field %d "), rs->curfield); if (rs->curblur) spos += sprintf(spos, IFACE_("Blur %d "), rs->curblur); } BLI_timestr(rs->lastframetime, info_time_str, sizeof(info_time_str)); spos += sprintf(spos, IFACE_("Time:%s "), info_time_str); if (rs->curfsa) spos += sprintf(spos, IFACE_("| Full Sample %d "), rs->curfsa); if (rs->infostr && rs->infostr[0]) spos += sprintf(spos, "| %s ", rs->infostr); /* very weak... but 512 characters is quite safe */ if (spos >= str + IMA_MAX_RENDER_TEXT) if (G.debug & G_DEBUG) printf("WARNING! renderwin text beyond limit\n"); }
/* str is IMA_MAX_RENDER_TEXT in size */ static void make_renderinfo_string(RenderStats *rs, Scene *scene, char *str) { char info_time_str[32]; // used to be extern to header_info.c uintptr_t mem_in_use, mmap_in_use, peak_memory; float megs_used_memory, mmap_used_memory, megs_peak_memory; char *spos = str; mem_in_use = MEM_get_memory_in_use(); mmap_in_use = MEM_get_mapped_memory_in_use(); peak_memory = MEM_get_peak_memory(); megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0); mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0); megs_peak_memory = (peak_memory) / (1024.0 * 1024.0); /* local view */ if (rs->localview) spos += sprintf(spos, "%s | ", IFACE_("Local View")); /* frame number */ spos += sprintf(spos, IFACE_("Frame:%d "), (scene->r.cfra)); /* previous and elapsed time */ BLI_timestr(rs->lastframetime, info_time_str, sizeof(info_time_str)); if (rs->infostr && rs->infostr[0]) { if (rs->lastframetime != 0.0) spos += sprintf(spos, IFACE_("| Last:%s "), info_time_str); else spos += sprintf(spos, "| "); BLI_timestr(PIL_check_seconds_timer() - rs->starttime, info_time_str, sizeof(info_time_str)); } else spos += sprintf(spos, "| "); spos += sprintf(spos, IFACE_("Time:%s "), info_time_str); /* statistics */ if (rs->statstr) { if (rs->statstr[0]) { spos += sprintf(spos, "| %s ", rs->statstr); } } else { if (rs->totvert || rs->totface || rs->tothalo || rs->totstrand || rs->totlamp) spos += sprintf(spos, "| "); if (rs->totvert) spos += sprintf(spos, IFACE_("Ve:%d "), rs->totvert); if (rs->totface) spos += sprintf(spos, IFACE_("Fa:%d "), rs->totface); if (rs->tothalo) spos += sprintf(spos, IFACE_("Ha:%d "), rs->tothalo); if (rs->totstrand) spos += sprintf(spos, IFACE_("St:%d "), rs->totstrand); if (rs->totlamp) spos += sprintf(spos, IFACE_("La:%d "), rs->totlamp); if (rs->mem_peak == 0.0f) spos += sprintf(spos, IFACE_("| Mem:%.2fM (%.2fM, Peak %.2fM) "), megs_used_memory, mmap_used_memory, megs_peak_memory); else spos += sprintf(spos, IFACE_("| Mem:%.2fM, Peak: %.2fM "), rs->mem_used, rs->mem_peak); if (rs->curfield) spos += sprintf(spos, IFACE_("Field %d "), rs->curfield); if (rs->curblur) spos += sprintf(spos, IFACE_("Blur %d "), rs->curblur); } /* full sample */ if (rs->curfsa) spos += sprintf(spos, IFACE_("| Full Sample %d "), rs->curfsa); /* extra info */ if (rs->infostr && rs->infostr[0]) spos += sprintf(spos, "| %s ", rs->infostr); /* very weak... but 512 characters is quite safe */ if (spos >= str + IMA_MAX_RENDER_TEXT) if (G.debug & G_DEBUG) printf("WARNING! renderwin text beyond limit\n"); }
/** * \note doesn't run exit() call #WM_exit() for that. */ void WM_exit_ext(bContext *C, const bool do_python) { wmWindowManager *wm = C ? CTX_wm_manager(C) : NULL; /* first wrap up running stuff, we assume only the active WM is running */ /* modal handlers are on window level freed, others too? */ /* note; same code copied in wm_files.c */ if (C && wm) { wmWindow *win; if (!G.background) { struct MemFile *undo_memfile = wm->undo_stack ? ED_undosys_stack_memfile_get_active(wm->undo_stack) : NULL; if ((U.uiflag2 & USER_KEEP_SESSION) || (undo_memfile != NULL)) { /* save the undo state as quit.blend */ char filename[FILE_MAX]; bool has_edited; int fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_HISTORY); BLI_make_file_string("/", filename, BKE_tempdir_base(), BLENDER_QUIT_FILE); has_edited = ED_editors_flush_edits(C, false); if ((has_edited && BLO_write_file(CTX_data_main(C), filename, fileflags, NULL, NULL)) || (undo_memfile && BLO_memfile_write_file(undo_memfile, filename))) { printf("Saved session recovery to '%s'\n", filename); } } } WM_jobs_kill_all(wm); for (win = wm->windows.first; win; win = win->next) { CTX_wm_window_set(C, win); /* needed by operator close callbacks */ WM_event_remove_handlers(C, &win->handlers); WM_event_remove_handlers(C, &win->modalhandlers); ED_screen_exit(C, win, win->screen); } } BKE_addon_pref_type_free(); wm_operatortype_free(); wm_dropbox_free(); WM_menutype_free(); WM_uilisttype_free(); /* all non-screen and non-space stuff editors did, like editmode */ if (C) ED_editors_exit(C); ED_undosys_type_free(); // XXX // BIF_GlobalReebFree(); // BIF_freeRetarget(); BIF_freeTemplates(C); free_openrecent(); BKE_mball_cubeTable_free(); /* render code might still access databases */ RE_FreeAllRender(); RE_engines_exit(); ED_preview_free_dbase(); /* frees a Main dbase, before BKE_blender_free! */ if (C && wm) wm_free_reports(C); /* before BKE_blender_free! - since the ListBases get freed there */ BKE_sequencer_free_clipboard(); /* sequencer.c */ BKE_tracking_clipboard_free(); BKE_mask_clipboard_free(); BKE_vfont_clipboard_free(); #ifdef WITH_COMPOSITOR COM_deinitialize(); #endif BKE_blender_free(); /* blender.c, does entire library and spacetypes */ // free_matcopybuf(); ANIM_fcurves_copybuf_free(); ANIM_drivers_copybuf_free(); ANIM_driver_vars_copybuf_free(); ANIM_fmodifiers_copybuf_free(); ED_gpencil_anim_copybuf_free(); ED_gpencil_strokes_copybuf_free(); BKE_node_clipboard_clear(); BLF_exit(); #ifdef WITH_INTERNATIONAL BLF_free_unifont(); BLF_free_unifont_mono(); BLT_lang_free(); #endif ANIM_keyingset_infos_exit(); // free_txt_data(); #ifdef WITH_PYTHON /* option not to close python so we can use 'atexit' */ if (do_python && ((C == NULL) || CTX_py_init_get(C))) { /* XXX - old note */ /* before BKE_blender_free so py's gc happens while library still exists */ /* needed at least for a rare sigsegv that can happen in pydrivers */ /* Update for blender 2.5, move after BKE_blender_free because blender now holds references to PyObject's * so decref'ing them after python ends causes bad problems every time * the pyDriver bug can be fixed if it happens again we can deal with it then */ BPY_python_end(); } #else (void)do_python; #endif if (!G.background) { #ifdef WITH_OPENSUBDIV BKE_subsurf_osd_cleanup(); #endif GPU_global_buffer_pool_free(); GPU_free_unused_buffers(G_MAIN); GPU_exit(); } ED_file_exit(); /* for fsmenu */ UI_exit(); BKE_blender_userdef_data_free(&U, false); RNA_exit(); /* should be after BPY_python_end so struct python slots are cleared */ wm_ghost_exit(); CTX_free(C); #ifdef WITH_GAMEENGINE SYS_DeleteSystem(SYS_GetSystem()); #endif GHOST_DisposeSystemPaths(); DNA_sdna_current_free(); BLI_threadapi_exit(); /* No need to call this early, rather do it late so that other pieces of Blender using sound may exit cleanly, * see also T50676. */ BKE_sound_exit(); CLG_exit(); BKE_blender_atexit(); if (MEM_get_memory_blocks_in_use() != 0) { size_t mem_in_use = MEM_get_memory_in_use() + MEM_get_memory_in_use(); printf("Error: Not freed memory blocks: %u, total unfreed memory %f MB\n", MEM_get_memory_blocks_in_use(), (double)mem_in_use / 1024 / 1024); MEM_printmemlist(); } wm_autosave_delete(); BKE_tempdir_session_purge(); }
/* name can be a dynamic string */ void BKE_write_undo(bContext *C, const char *name) { uintptr_t maxmem, totmem, memused; int nr /*, success */ /* UNUSED */; UndoElem *uel; if ((U.uiflag & USER_GLOBALUNDO) == 0) { return; } if (U.undosteps == 0) { return; } /* remove all undos after (also when curundo == NULL) */ while (undobase.last != curundo) { uel = undobase.last; BLI_remlink(&undobase, uel); BLO_free_memfile(&uel->memfile); MEM_freeN(uel); } /* make new */ curundo = uel = MEM_callocN(sizeof(UndoElem), "undo file"); BLI_strncpy(uel->name, name, sizeof(uel->name)); BLI_addtail(&undobase, uel); /* and limit amount to the maximum */ nr = 0; uel = undobase.last; while (uel) { nr++; if (nr == U.undosteps) break; uel = uel->prev; } if (uel) { while (undobase.first != uel) { UndoElem *first = undobase.first; BLI_remlink(&undobase, first); /* the merge is because of compression */ BLO_merge_memfile(&first->memfile, &first->next->memfile); MEM_freeN(first); } } /* disk save version */ if (UNDO_DISK) { static int counter = 0; char filepath[FILE_MAX]; char numstr[32]; int fileflags = G.fileflags & ~(G_FILE_HISTORY); /* don't do file history on undo */ /* calculate current filepath */ counter++; counter = counter % U.undosteps; BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter); BLI_make_file_string("/", filepath, BKE_tempdir_session(), numstr); /* success = */ /* UNUSED */ BLO_write_file(CTX_data_main(C), filepath, fileflags, NULL, NULL); BLI_strncpy(curundo->str, filepath, sizeof(curundo->str)); } else { MemFile *prevfile = NULL; if (curundo->prev) prevfile = &(curundo->prev->memfile); memused = MEM_get_memory_in_use(); /* success = */ /* UNUSED */ BLO_write_file_mem(CTX_data_main(C), prevfile, &curundo->memfile, G.fileflags); curundo->undosize = MEM_get_memory_in_use() - memused; } if (U.undomemory != 0) { /* limit to maximum memory (afterwards, we can't know in advance) */ totmem = 0; maxmem = ((uintptr_t)U.undomemory) * 1024 * 1024; /* keep at least two (original + other) */ uel = undobase.last; while (uel && uel->prev) { totmem += uel->undosize; if (totmem > maxmem) break; uel = uel->prev; } if (uel) { if (uel->prev && uel->prev->prev) uel = uel->prev; while (undobase.first != uel) { UndoElem *first = undobase.first; BLI_remlink(&undobase, first); /* the merge is because of compression */ BLO_merge_memfile(&first->memfile, &first->next->memfile); MEM_freeN(first); } } } }
/* name can be a dynamic string */ void undo_editmode_push(bContext *C, const char *name, void * (*getdata)(bContext *C), void (*freedata)(void *), void (*to_editmode)(void *, void *), void *(*from_editmode)(void *), int (*validate_undo)(void *, void *)) { UndoElem *uel; Object *obedit= CTX_data_edit_object(C); void *editdata; int nr; uintptr_t memused, totmem, maxmem; /* at first here was code to prevent an "original" key to be insterted twice this was giving conflicts for example when mesh changed due to keys or apply */ /* remove all undos after (also when curundo==NULL) */ while(undobase.last != curundo) { uel= undobase.last; uel->freedata(uel->undodata); BLI_freelinkN(&undobase, uel); } /* make new */ curundo= uel= MEM_callocN(sizeof(UndoElem), "undo editmode"); strncpy(uel->name, name, MAXUNDONAME-1); BLI_addtail(&undobase, uel); uel->getdata= getdata; uel->freedata= freedata; uel->to_editmode= to_editmode; uel->from_editmode= from_editmode; uel->validate_undo= validate_undo; /* limit amount to the maximum amount*/ nr= 0; uel= undobase.last; while(uel) { nr++; if(nr==U.undosteps) break; uel= uel->prev; } if(uel) { while(undobase.first!=uel) { UndoElem *first= undobase.first; first->freedata(first->undodata); BLI_freelinkN(&undobase, first); } } /* copy */ memused= MEM_get_memory_in_use(); editdata= getdata(C); curundo->undodata= curundo->from_editmode(editdata); curundo->undosize= MEM_get_memory_in_use() - memused; curundo->ob= obedit; curundo->id= obedit->id; curundo->type= obedit->type; if(U.undomemory != 0) { /* limit to maximum memory (afterwards, we can't know in advance) */ totmem= 0; maxmem= ((uintptr_t)U.undomemory)*1024*1024; uel= undobase.last; while(uel && uel->prev) { totmem+= uel->undosize; if(totmem>maxmem) break; uel= uel->prev; } if(uel) { if(uel->prev && uel->prev->prev) uel= uel->prev; while(undobase.first!=uel) { UndoElem *first= undobase.first; first->freedata(first->undodata); BLI_freelinkN(&undobase, first); } } } }