diff options
Diffstat (limited to 'source/blender/editors/space_info/info_stats.c')
-rw-r--r-- | source/blender/editors/space_info/info_stats.c | 82 |
1 files changed, 64 insertions, 18 deletions
diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index ebdf32a1cdb..20d901a05bc 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -31,6 +31,7 @@ #include "DNA_mesh_types.h" #include "DNA_meta_types.h" #include "DNA_scene_types.h" +#include "DNA_space_types.h" #include "DNA_windowmanager_types.h" #include "BLF_api.h" @@ -63,6 +64,8 @@ #include "ED_info.h" +#include "WM_api.h" + #include "UI_resources.h" #include "GPU_capabilities.h" @@ -123,12 +126,19 @@ static bool stats_mesheval(Mesh *me_eval, bool is_selected, SceneStats *stats) return true; } -static void stats_object(Object *ob, SceneStats *stats, GSet *objects_gset) +static void stats_object(Object *ob, + const View3D *v3d_local, + SceneStats *stats, + GSet *objects_gset) { if ((ob->base_flag & BASE_VISIBLE_VIEWLAYER) == 0) { return; } + if (v3d_local && !BKE_object_is_visible_in_viewport(v3d_local, ob)) { + return; + } + const bool is_selected = (ob->base_flag & BASE_SELECTED) != 0; stats->totobj++; @@ -386,7 +396,7 @@ static void stats_object_sculpt(Object *ob, SceneStats *stats) } /* Statistics displayed in info header. Called regularly on scene changes. */ -static void stats_update(Depsgraph *depsgraph, ViewLayer *view_layer) +static void stats_update(Depsgraph *depsgraph, ViewLayer *view_layer, View3D *v3d_local) { SceneStats stats = {0}; Object *ob = OBACT(view_layer); @@ -400,6 +410,13 @@ static void stats_update(Depsgraph *depsgraph, ViewLayer *view_layer) stats_object_edit(ob_iter, &stats); stats.totobjsel++; } + else { + /* Skip hidden objects in local view that are not in edit-mode, + * an exception for edit-mode, in other modes these would be considered hidden. */ + if ((v3d_local && !BKE_object_is_visible_in_viewport(v3d_local, ob_iter))) { + continue; + } + } stats.totobj++; } } @@ -417,7 +434,7 @@ static void stats_update(Depsgraph *depsgraph, ViewLayer *view_layer) /* Objects */ GSet *objects_gset = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN (depsgraph, ob_iter) { - stats_object(ob_iter, &stats, objects_gset); + stats_object(ob_iter, v3d_local, &stats, objects_gset); } DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; BLI_gset_free(objects_gset, NULL); @@ -429,38 +446,61 @@ static void stats_update(Depsgraph *depsgraph, ViewLayer *view_layer) stats_object_sculpt(ob, &stats); } - if (!view_layer->stats) { - view_layer->stats = MEM_callocN(sizeof(SceneStats), "SceneStats"); + if (v3d_local) { + BLI_assert(v3d_local->localvd != NULL); + if (v3d_local->runtime.local_stats == NULL) { + v3d_local->runtime.local_stats = MEM_mallocN(sizeof(SceneStats), "LocalStats"); + } + *v3d_local->runtime.local_stats = stats; + } + else { + if (!view_layer->stats) { + view_layer->stats = MEM_callocN(sizeof(SceneStats), "SceneStats"); + } + *view_layer->stats = stats; } - - *(view_layer->stats) = stats; } -void ED_info_stats_clear(ViewLayer *view_layer) +void ED_info_stats_clear(wmWindowManager *wm, ViewLayer *view_layer) { if (view_layer->stats) { MEM_freeN(view_layer->stats); view_layer->stats = NULL; } + + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { + ViewLayer *view_layer_test = WM_window_get_active_view_layer(win); + if (view_layer != view_layer_test) { + continue; + } + const bScreen *screen = WM_window_get_active_screen(win); + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + if (area->spacetype == SPACE_VIEW3D) { + View3D *v3d = area->spacedata.first; + if (v3d->localvd) { + MEM_SAFE_FREE(v3d->runtime.local_stats); + } + } + } + } } -static bool format_stats(Main *bmain, - Scene *scene, - ViewLayer *view_layer, - SceneStatsFmt *stats_fmt) +static bool format_stats( + Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d_local, SceneStatsFmt *stats_fmt) { /* Create stats if they don't already exist. */ - if (!view_layer->stats) { + SceneStats **stats_p = (v3d_local) ? &v3d_local->runtime.local_stats : &view_layer->stats; + if (*stats_p == NULL) { /* Do not not access dependency graph if interface is marked as locked. */ wmWindowManager *wm = bmain->wm.first; if (wm->is_interface_locked) { return false; } Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer); - stats_update(depsgraph, view_layer); + stats_update(depsgraph, view_layer, v3d_local); } - SceneStats *stats = view_layer->stats; + SceneStats *stats = *stats_p; /* Generate formatted numbers. */ #define SCENE_STATS_FMT_INT(_id) BLI_str_format_uint64_grouped(stats_fmt->_id, stats->_id) @@ -605,7 +645,7 @@ static const char *info_statusbar_string(Main *bmain, /* Scene statistics. */ if (statusbar_flag & STATUSBAR_SHOW_STATS) { SceneStatsFmt stats_fmt; - if (format_stats(bmain, scene, view_layer, &stats_fmt)) { + if (format_stats(bmain, scene, view_layer, NULL, &stats_fmt)) { get_stats_string(info + ofs, len, &ofs, view_layer, &stats_fmt); } } @@ -682,11 +722,17 @@ static void stats_row(int col1, BLF_draw_default(col2, *y, 0.0f, values, sizeof(values)); } +/** + * \param v3d_local: Pass this argument to calculate view-port local statistics. + * Note that this must only be used for local-view, otherwise report specific statistics + * will be written into the global scene statistics giving incorrect results. + */ void ED_info_draw_stats( - Main *bmain, Scene *scene, ViewLayer *view_layer, int x, int *y, int height) + Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d_local, int x, int *y, int height) { + BLI_assert(v3d_local == NULL || v3d_local->localvd != NULL); SceneStatsFmt stats_fmt; - if (!format_stats(bmain, scene, view_layer, &stats_fmt)) { + if (!format_stats(bmain, scene, view_layer, v3d_local, &stats_fmt)) { return; } |