diff options
Diffstat (limited to 'source/blender/windowmanager')
32 files changed, 339 insertions, 182 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 3d4c84805f9..332f53c9ee7 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -16,8 +16,7 @@ * The Original Code is Copyright (C) 2007 Blender Foundation. * All rights reserved. */ -#ifndef __WM_API_H__ -#define __WM_API_H__ +#pragma once /** \file * \ingroup wm @@ -904,5 +903,3 @@ bool WM_xr_session_state_viewer_pose_matrix_info_get(const wmXrData *xr, #ifdef __cplusplus } #endif - -#endif /* __WM_API_H__ */ diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h index 53a3fd5ebda..15be21bdbc4 100644 --- a/source/blender/windowmanager/WM_keymap.h +++ b/source/blender/windowmanager/WM_keymap.h @@ -17,8 +17,7 @@ * All rights reserved. */ -#ifndef __WM_KEYMAP_H__ -#define __WM_KEYMAP_H__ +#pragma once /** \file * \ingroup wm @@ -194,5 +193,3 @@ const char *WM_bool_as_string(bool test); #ifdef __cplusplus } #endif - -#endif /* __WM_KEYMAP_H__ */ diff --git a/source/blender/windowmanager/WM_message.h b/source/blender/windowmanager/WM_message.h index 1527d514e9b..25d5bae392b 100644 --- a/source/blender/windowmanager/WM_message.h +++ b/source/blender/windowmanager/WM_message.h @@ -18,9 +18,6 @@ * \ingroup wm */ -#ifndef __WM_MESSAGE_H__ -#define __WM_MESSAGE_H__ +#pragma once #include "message_bus/wm_message_bus.h" - -#endif /* __WM_MESSAGE_H__ */ diff --git a/source/blender/windowmanager/WM_toolsystem.h b/source/blender/windowmanager/WM_toolsystem.h index 163f37be974..13d1666dc95 100644 --- a/source/blender/windowmanager/WM_toolsystem.h +++ b/source/blender/windowmanager/WM_toolsystem.h @@ -13,8 +13,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __WM_TOOLSYSTEM_H__ -#define __WM_TOOLSYSTEM_H__ +#pragma once /** \file * \ingroup wm @@ -140,5 +139,3 @@ void WM_toolsystem_refresh_screen_all(struct Main *bmain); #ifdef __cplusplus } #endif - -#endif /* __WM_TOOLSYSTEM_API_H__ */ diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index b4b3d0957af..efe600a846a 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -106,8 +106,7 @@ * \endcode */ -#ifndef __WM_TYPES_H__ -#define __WM_TYPES_H__ +#pragma once struct ID; struct ImBuf; @@ -928,5 +927,3 @@ extern struct CLG_LogRef *WM_LOG_MSGBUS_SUB; #ifdef __cplusplus } #endif - -#endif /* __WM_TYPES_H__ */ diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_api.h b/source/blender/windowmanager/gizmo/WM_gizmo_api.h index 07a3f0445bb..a4412ecce5c 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_api.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_api.h @@ -26,8 +26,7 @@ * Only included in WM_api.h */ -#ifndef __WM_GIZMO_API_H__ -#define __WM_GIZMO_API_H__ +#pragma once struct ARegion; struct GHashIterator; @@ -52,6 +51,10 @@ struct wmWindowManager; #include "wm_gizmo_fn.h" +#ifdef __cplusplus +extern "C" { +#endif + /* -------------------------------------------------------------------- */ /* wmGizmo */ @@ -396,4 +399,6 @@ void WM_gizmo_group_tag_remove(struct wmGizmoGroup *gzgroup); bool WM_gizmo_group_type_poll(const struct bContext *C, const struct wmGizmoGroupType *gzgt); void WM_gizmo_group_refresh(const struct bContext *C, struct wmGizmoGroup *gzgroup); -#endif /* __WM_GIZMO_API_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_types.h b/source/blender/windowmanager/gizmo/WM_gizmo_types.h index 3863e3bd797..bddf54b846f 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_types.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_types.h @@ -26,8 +26,7 @@ * Only included in WM_types.h and lower level files. */ -#ifndef __WM_GIZMO_TYPES_H__ -#define __WM_GIZMO_TYPES_H__ +#pragma once #include "BLI_compiler_attrs.h" @@ -40,6 +39,10 @@ struct wmKeyConfig; #include "DNA_listBase.h" +#ifdef __cplusplus +extern "C" { +#endif + /* -------------------------------------------------------------------- */ /* Enum Typedef's */ @@ -506,4 +509,6 @@ typedef enum eWM_GizmoFlagMapDrawStep { } eWM_GizmoFlagMapDrawStep; #define WM_GIZMOMAP_DRAWSTEP_MAX 2 -#endif /* __WM_GIZMO_TYPES_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h index 00df6edef22..953722f28e9 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_GIZMO_INTERN_H__ -#define __WM_GIZMO_INTERN_H__ +#pragma once struct BLI_Buffer; struct wmGizmoMap; @@ -142,5 +141,3 @@ bool wm_gizmomap_deselect_all(struct wmGizmoMap *gzmap); void wm_gizmomap_select_array_shrink(struct wmGizmoMap *gzmap, int len_subtract); void wm_gizmomap_select_array_push_back(struct wmGizmoMap *gzmap, wmGizmo *gz); void wm_gizmomap_select_array_remove(struct wmGizmoMap *gzmap, wmGizmo *gz); - -#endif diff --git a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h index 58b58fa01d0..418e848e35b 100644 --- a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h +++ b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h @@ -20,13 +20,16 @@ * Callback function definitions, needed for both Types & API headers. */ -#ifndef __WM_GIZMO_FN_H__ -#define __WM_GIZMO_FN_H__ +#pragma once #include "BLI_compiler_attrs.h" struct wmMsgBus; +#ifdef __cplusplus +extern "C" { +#endif + /* wmGizmoGroup */ typedef bool (*wmGizmoGroupFnPoll)(const struct bContext *, struct wmGizmoGroupType *) ATTR_WARN_UNUSED_RESULT; @@ -85,4 +88,6 @@ typedef struct wmGizmoPropertyFnParams { void *user_data; } wmGizmoPropertyFnParams; -#endif /* __WM_GIZMO_FN_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h b/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h index cc9ccc5f4bb..18b3f40aba6 100644 --- a/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h +++ b/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h @@ -28,14 +28,17 @@ * Only included in wm.h and lower level files. */ -#ifndef __WM_GIZMO_WMAPI_H__ -#define __WM_GIZMO_WMAPI_H__ +#pragma once struct wmEventHandler_Gizmo; struct wmEventHandler_Op; struct wmGizmoMap; struct wmOperatorType; +#ifdef __cplusplus +extern "C" { +#endif + /* -------------------------------------------------------------------- */ /* wmGizmo */ @@ -92,4 +95,6 @@ struct ListBase *wm_gizmomap_groups_get(wmGizmoMap *gzmap); void wm_gizmomaptypes_free(void); -#endif /* __WM_GIZMO_WMAPI_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 16454e473cc..fdbc7a7d136 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -51,6 +51,7 @@ #include "ED_screen.h" #include "ED_view3d.h" +#include "GPU_context.h" #include "GPU_draw.h" #include "GPU_framebuffer.h" #include "GPU_immediate.h" @@ -999,6 +1000,7 @@ void wm_draw_update(bContext *C) wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win; + GPU_context_main_lock(); GPU_free_unused_buffers(); for (win = wm->windows.first; win; win = win->next) { @@ -1036,6 +1038,8 @@ void wm_draw_update(bContext *C) /* Draw non-windows (surfaces) */ wm_surfaces_iter(C, wm_draw_surface); + + GPU_context_main_unlock(); } void wm_draw_region_clear(wmWindow *win, ARegion *UNUSED(region)) diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 05ef4bfac30..8dbb608cd30 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -387,6 +387,18 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C) CTX_wm_window_set(C, NULL); } +static void wm_event_execute_timers(bContext *C) +{ + wmWindowManager *wm = CTX_wm_manager(C); + + /* Set the first window as context, so that there is some minimal context. This avoids crashes + * when calling code that assumes that there is always a window in the context (which many + * operators do). */ + CTX_wm_window_set(C, wm->windows.first); + BLI_timer_execute(); + CTX_wm_window_set(C, NULL); +} + /* called in mainloop */ void wm_event_do_notifiers(bContext *C) { @@ -398,7 +410,7 @@ void wm_event_do_notifiers(bContext *C) return; } - BLI_timer_execute(); + wm_event_execute_timers(C); /* disable? - keep for now since its used for window level notifiers. */ #if 1 diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index c8574a5a7fb..31d36603505 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -34,6 +34,7 @@ #include "MEM_guardedalloc.h" #include "DNA_ID.h" +#include "DNA_key_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_windowmanager_types.h" @@ -50,8 +51,10 @@ #include "BKE_context.h" #include "BKE_global.h" +#include "BKE_key.h" #include "BKE_layer.h" #include "BKE_lib_id.h" +#include "BKE_lib_override.h" #include "BKE_lib_remap.h" #include "BKE_main.h" #include "BKE_report.h" @@ -694,6 +697,92 @@ static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UN return OPERATOR_CANCELLED; } +static void lib_relocate_do_remap(Main *bmain, + ID *old_id, + ID *new_id, + ReportList *reports, + const bool do_reload, + const short remap_flags) +{ + BLI_assert(old_id); + if (do_reload) { + /* Since we asked for placeholders in case of missing IDs, + * we expect to always get a valid one. */ + BLI_assert(new_id); + } + if (new_id) { +#ifdef PRINT_DEBUG + printf("before remap of %s, old_id users: %d, new_id users: %d\n", + old_id->name, + old_id->us, + new_id->us); +#endif + BKE_libblock_remap_locked(bmain, old_id, new_id, remap_flags); + + if (old_id->flag & LIB_FAKEUSER) { + id_fake_user_clear(old_id); + id_fake_user_set(new_id); + } + +#ifdef PRINT_DEBUG + printf("after remap of %s, old_id users: %d, new_id users: %d\n", + old_id->name, + old_id->us, + new_id->us); +#endif + + /* In some cases, new_id might become direct link, remove parent of library in this case. */ + if (new_id->lib->parent && (new_id->tag & LIB_TAG_INDIRECT) == 0) { + if (do_reload) { + BLI_assert(0); /* Should not happen in 'pure' reload case... */ + } + new_id->lib->parent = NULL; + } + } + + if (old_id->us > 0 && new_id && old_id->lib == new_id->lib) { + /* Note that this *should* not happen - but better be safe than sorry in this area, + * at least until we are 100% sure this cannot ever happen. + * Also, we can safely assume names were unique so far, + * so just replacing '.' by '~' should work, + * but this does not totally rules out the possibility of name collision. */ + size_t len = strlen(old_id->name); + size_t dot_pos; + bool has_num = false; + + for (dot_pos = len; dot_pos--;) { + char c = old_id->name[dot_pos]; + if (c == '.') { + break; + } + else if (c < '0' || c > '9') { + has_num = false; + break; + } + has_num = true; + } + + if (has_num) { + old_id->name[dot_pos] = '~'; + } + else { + len = MIN2(len, MAX_ID_NAME - 7); + BLI_strncpy(&old_id->name[len], "~000", 7); + } + + id_sort_by_name(which_libbase(bmain, GS(old_id->name)), old_id, NULL); + + BKE_reportf( + reports, + RPT_WARNING, + "Lib Reload: Replacing all references to old data-block '%s' by reloaded one failed, " + "old one (%d remaining users) had to be kept and was renamed to '%s'", + new_id->name, + old_id->us, + old_id->name); + } +} + static void lib_relocate_do(Main *bmain, Library *library, WMLinkAppendData *lapp_data, @@ -725,6 +814,12 @@ static void lib_relocate_do(Main *bmain, /* We remove it from current Main, and add it to items to link... */ /* Note that non-linkable IDs (like e.g. shapekeys) are also explicitly linked here... */ BLI_remlink(lbarray[lba_idx], id); + /* Usual special code for ShapeKeys snowflakes... */ + Key *old_key = BKE_key_from_id(id); + if (old_key != NULL) { + BLI_remlink(which_libbase(bmain, GS(old_key->id.name)), &old_key->id); + } + item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id); BLI_bitmap_set_all(item->libraries, true, lapp_data->num_libraries); @@ -757,6 +852,12 @@ static void lib_relocate_do(Main *bmain, BLI_assert(old_id); BLI_addtail(which_libbase(bmain, GS(old_id->name)), old_id); + + /* Usual special code for ShapeKeys snowflakes... */ + Key *old_key = BKE_key_from_id(old_id); + if (old_key != NULL) { + BLI_addtail(which_libbase(bmain, GS(old_key->id.name)), &old_key->id); + } } /* Since our (old) reloaded IDs were removed from main, the user count done for them in linking @@ -773,82 +874,20 @@ static void lib_relocate_do(Main *bmain, ID *old_id = item->customdata; ID *new_id = item->new_id; - BLI_assert(old_id); - if (do_reload) { - /* Since we asked for placeholders in case of missing IDs, - * we expect to always get a valid one. */ - BLI_assert(new_id); - } - if (new_id) { -#ifdef PRINT_DEBUG - printf("before remap of %s, old_id users: %d, new_id users: %d\n", - old_id->name, - old_id->us, - new_id->us); -#endif - BKE_libblock_remap_locked(bmain, old_id, new_id, remap_flags); - - if (old_id->flag & LIB_FAKEUSER) { - id_fake_user_clear(old_id); - id_fake_user_set(new_id); - } - -#ifdef PRINT_DEBUG - printf("after remap of %s, old_id users: %d, new_id users: %d\n", - old_id->name, - old_id->us, - new_id->us); -#endif - - /* In some cases, new_id might become direct link, remove parent of library in this case. */ - if (new_id->lib->parent && (new_id->tag & LIB_TAG_INDIRECT) == 0) { - if (do_reload) { - BLI_assert(0); /* Should not happen in 'pure' reload case... */ - } - new_id->lib->parent = NULL; - } + lib_relocate_do_remap(bmain, old_id, new_id, reports, do_reload, remap_flags); + /* Usual special code for ShapeKeys snowflakes... */ + Key **old_key_p = BKE_key_from_id_p(old_id); + if (old_key_p == NULL) { + continue; } - - if (old_id->us > 0 && new_id && old_id->lib == new_id->lib) { - /* Note that this *should* not happen - but better be safe than sorry in this area, - * at least until we are 100% sure this cannot ever happen. - * Also, we can safely assume names were unique so far, - * so just replacing '.' by '~' should work, - * but this does not totally rules out the possibility of name collision. */ - size_t len = strlen(old_id->name); - size_t dot_pos; - bool has_num = false; - - for (dot_pos = len; dot_pos--;) { - char c = old_id->name[dot_pos]; - if (c == '.') { - break; - } - else if (c < '0' || c > '9') { - has_num = false; - break; - } - has_num = true; - } - - if (has_num) { - old_id->name[dot_pos] = '~'; - } - else { - len = MIN2(len, MAX_ID_NAME - 7); - BLI_strncpy(&old_id->name[len], "~000", 7); - } - - id_sort_by_name(which_libbase(bmain, GS(old_id->name)), old_id, NULL); - - BKE_reportf( - reports, - RPT_WARNING, - "Lib Reload: Replacing all references to old data-block '%s' by reloaded one failed, " - "old one (%d remaining users) had to be kept and was renamed to '%s'", - new_id->name, - old_id->us, - old_id->name); + Key *old_key = *old_key_p; + Key *new_key = BKE_key_from_id(new_id); + if (old_key != NULL) { + *old_key_p = NULL; + id_us_min(&old_key->id); + lib_relocate_do_remap(bmain, &old_key->id, &new_key->id, reports, do_reload, remap_flags); + *old_key_p = old_key; + id_us_plus_no_lib(&old_key->id); } } @@ -900,6 +939,23 @@ static void lib_relocate_do(Main *bmain, } } + /* Update overrides of reloaded linked data-blocks. + * Note that this will not necessarily fully update the override, it might need to be manually + * 're-generated' depending on changes in linked data. */ + ID *id; + FOREACH_MAIN_ID_BEGIN (bmain, id) { + if (ID_IS_LINKED(id) || !ID_IS_OVERRIDE_LIBRARY_REAL(id) || + (id->tag & LIB_TAG_PRE_EXISTING) == 0) { + continue; + } + if (id->override_library->reference->lib == library) { + BKE_lib_override_library_update(bmain, id); + } + } + FOREACH_MAIN_ID_END; + + BKE_main_collection_sync(bmain); + BKE_main_lib_objects_recalc_all(bmain); IMB_colormanagement_check_file_config(bmain); diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index aa3f11c2515..945d5fd42e4 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -656,13 +656,6 @@ void WM_exit_ex(bContext *C, const bool do_python) 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(); diff --git a/source/blender/windowmanager/intern/wm_keymap_utils.c b/source/blender/windowmanager/intern/wm_keymap_utils.c index 5ab36b15666..460b19ac8d1 100644 --- a/source/blender/windowmanager/intern/wm_keymap_utils.c +++ b/source/blender/windowmanager/intern/wm_keymap_utils.c @@ -217,7 +217,6 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname) * FLUID_OT * TEXTURE_OT * UI_OT - * VIEW2D_OT * WORLD_OT */ @@ -344,6 +343,10 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname) break; } } + /* General 2D View, not bound to a specific spacetype. */ + else if (STRPREFIX(opname, "VIEW2D_OT")) { + km = WM_keymap_find_all(wm, "View2D", 0, 0); + } /* Image Editor */ else if (STRPREFIX(opname, "IMAGE_OT")) { km = WM_keymap_find_all(wm, "Image", sl->spacetype, 0); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index d1f65b6271b..e14b59d77b2 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -3722,6 +3722,7 @@ static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win = CTX_wm_window(C); View3D *v3d = CTX_wm_view3d(C); /* Lazy-create xr context - tries to dynlink to the runtime, reading active_runtime.json. */ @@ -3730,7 +3731,7 @@ static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op)) } v3d->runtime.flag |= V3D_RUNTIME_XR_SESSION_ROOT; - wm_xr_session_toggle(wm, wm_xr_session_update_screen_on_exit_cb); + wm_xr_session_toggle(wm, win, wm_xr_session_update_screen_on_exit_cb); wm_xr_session_update_screen(bmain, &wm->xr); WM_event_add_notifier(C, NC_WM | ND_XR_DATA_CHANGED, NULL); diff --git a/source/blender/windowmanager/intern/wm_platform_support.h b/source/blender/windowmanager/intern/wm_platform_support.h index a8e20f6bcdf..6346f517343 100644 --- a/source/blender/windowmanager/intern/wm_platform_support.h +++ b/source/blender/windowmanager/intern/wm_platform_support.h @@ -20,11 +20,8 @@ /** \file * \ingroup wm */ -#ifndef __WM_PLATFORM_SUPPORT_H__ -#define __WM_PLATFORM_SUPPORT_H__ +#pragma once #include "BLI_sys_types.h" bool WM_platform_support_perform_checks(void); - -#endif diff --git a/source/blender/windowmanager/intern/wm_window_private.h b/source/blender/windowmanager/intern/wm_window_private.h index 115539861d7..c208d07ee37 100644 --- a/source/blender/windowmanager/intern/wm_window_private.h +++ b/source/blender/windowmanager/intern/wm_window_private.h @@ -20,8 +20,7 @@ /** \file * \ingroup wm */ -#ifndef __WM_WINDOW_PRIVATE_H__ -#define __WM_WINDOW_PRIVATE_H__ +#pragma once #include "BLI_sys_types.h" #include "GHOST_Types.h" @@ -38,5 +37,3 @@ void WM_ghost_show_message_box(const char *title, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options); - -#endif diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h b/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h index ccf7034e3e0..24c0192fe14 100644 --- a/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h +++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_MESSAGE_BUS_INTERN_H__ -#define __WM_MESSAGE_BUS_INTERN_H__ +#pragma once #include "../wm_message_bus.h" @@ -47,5 +46,3 @@ BLI_INLINE wmMsg *wm_msg_subscribe_value_msg_cast_mut(wmMsgSubscribeKey *key) { return &((wmMsgSubscribeKey_Generic *)key)->msg; } - -#endif /* __WM_MESSAGE_BUS_INTERN_H__ */ diff --git a/source/blender/windowmanager/message_bus/wm_message_bus.h b/source/blender/windowmanager/message_bus/wm_message_bus.h index 8020be3017a..23a53eace52 100644 --- a/source/blender/windowmanager/message_bus/wm_message_bus.h +++ b/source/blender/windowmanager/message_bus/wm_message_bus.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_MESSAGE_BUS_H__ -#define __WM_MESSAGE_BUS_H__ +#pragma once #include "RNA_types.h" #include <stdio.h> @@ -34,6 +33,10 @@ struct wmMsgSubscribeKey; struct wmMsgSubscribeValue; struct wmMsgSubscribeValueLink; +#ifdef __cplusplus +extern "C" { +#endif + typedef void (*wmMsgNotifyFn)(struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val); @@ -287,4 +290,6 @@ void WM_msg_publish_ID(struct wmMsgBus *mbus, struct ID *id); } \ ((void)0) -#endif /* __WM_MESSAGE_BUS_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h index 16aa5cb44db..baa47098bd3 100644 --- a/source/blender/windowmanager/wm.h +++ b/source/blender/windowmanager/wm.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_H__ -#define __WM_H__ +#pragma once struct ARegion; struct ReportList; @@ -30,6 +29,10 @@ struct wmWindow; #include "gizmo/wm_gizmo_wmapi.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct wmPaintCursor { struct wmPaintCursor *next, *prev; @@ -97,4 +100,6 @@ void wm_stereo3d_set_cancel(bContext *C, wmOperator *op); void wm_open_init_load_ui(wmOperator *op, bool use_prefs); void wm_open_init_use_scripts(wmOperator *op, bool use_prefs); +#ifdef __cplusplus +} #endif diff --git a/source/blender/windowmanager/wm_cursors.h b/source/blender/windowmanager/wm_cursors.h index 7a28aeb3c70..b85616deda5 100644 --- a/source/blender/windowmanager/wm_cursors.h +++ b/source/blender/windowmanager/wm_cursors.h @@ -21,12 +21,15 @@ * \ingroup wm */ -#ifndef __WM_CURSORS_H__ -#define __WM_CURSORS_H__ +#pragma once struct wmEvent; struct wmWindow; +#ifdef __cplusplus +extern "C" { +#endif + typedef enum WMCursorType { WM_CURSOR_DEFAULT = 1, WM_CURSOR_TEXT_EDIT, @@ -77,4 +80,6 @@ typedef enum WMCursorType { void wm_init_cursor_data(void); bool wm_cursor_arrow_move(struct wmWindow *win, const struct wmEvent *event); -#endif /* __WM_CURSORS_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/wm_draw.h b/source/blender/windowmanager/wm_draw.h index ff2fc25333a..a26c02317d0 100644 --- a/source/blender/windowmanager/wm_draw.h +++ b/source/blender/windowmanager/wm_draw.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_DRAW_H__ -#define __WM_DRAW_H__ +#pragma once #include "GPU_glew.h" @@ -30,6 +29,10 @@ struct GPUOffScreen; struct GPUTexture; struct GPUViewport; +#ifdef __cplusplus +extern "C" { +#endif + typedef struct wmDrawBuffer { struct GPUOffScreen *offscreen; struct GPUViewport *viewport; @@ -50,4 +53,6 @@ void wm_draw_region_test(struct bContext *C, struct ScrArea *area, struct ARegio struct GPUTexture *wm_draw_region_texture(struct ARegion *region, int view); -#endif /* __WM_DRAW_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/wm_event_system.h b/source/blender/windowmanager/wm_event_system.h index efcf40d03eb..787c840de8a 100644 --- a/source/blender/windowmanager/wm_event_system.h +++ b/source/blender/windowmanager/wm_event_system.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_EVENT_SYSTEM_H__ -#define __WM_EVENT_SYSTEM_H__ +#pragma once /* return value of handler-operator call */ #define WM_HANDLER_CONTINUE 0 @@ -34,6 +33,10 @@ struct ARegion; struct GHOST_TabletData; struct ScrArea; +#ifdef __cplusplus +extern "C" { +#endif + /* wmKeyMap is in DNA_windowmanager.h, it's saveable */ /** Custom types for handlers, for signaling, freeing */ @@ -165,4 +168,6 @@ void wm_dropbox_free(void); void wm_drags_check_ops(bContext *C, const wmEvent *event); void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect); -#endif /* __WM_EVENT_SYSTEM_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index ffed86abfe7..ed8f39fea48 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -23,8 +23,11 @@ * Blender copied the conventions quite some, and expanded it with internal new defines (ton) */ -#ifndef __WM_EVENT_TYPES_H__ -#define __WM_EVENT_TYPES_H__ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif /* customdata type */ enum { @@ -489,4 +492,6 @@ enum { GESTURE_MODAL_CIRCLE_SIZE = 11, }; -#endif /* __WM_EVENT_TYPES_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h index 42eab35cdb9..d54090a6025 100644 --- a/source/blender/windowmanager/wm_files.h +++ b/source/blender/windowmanager/wm_files.h @@ -21,13 +21,16 @@ * \ingroup wm */ -#ifndef __WM_FILES_H__ -#define __WM_FILES_H__ +#pragma once struct Main; struct wmGenericCallback; struct wmOperatorType; +#ifdef __cplusplus +extern "C" { +#endif + /* wm_files.c */ void wm_history_file_read(void); void wm_homefile_read(struct bContext *C, @@ -68,4 +71,6 @@ void WM_OT_append(struct wmOperatorType *ot); void WM_OT_lib_relocate(struct wmOperatorType *ot); void WM_OT_lib_reload(struct wmOperatorType *ot); -#endif /* __WM_FILES_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/wm_surface.h b/source/blender/windowmanager/wm_surface.h index bc1cc825e4b..06c29231361 100644 --- a/source/blender/windowmanager/wm_surface.h +++ b/source/blender/windowmanager/wm_surface.h @@ -22,11 +22,14 @@ * Container to manage painting in an offscreen context. */ -#ifndef __WM_SURFACE_H__ -#define __WM_SURFACE_H__ +#pragma once struct bContext; +#ifdef __cplusplus +extern "C" { +#endif + typedef struct wmSurface { struct wmSurface *next, *prev; @@ -59,4 +62,6 @@ void wm_surface_clear_drawable(void); void wm_surface_set_drawable(wmSurface *surface, bool activate); void wm_surface_reset_drawable(void); -#endif /* __WM_SURFACE_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h index 5ca5711b4f2..336db7edb50 100644 --- a/source/blender/windowmanager/wm_window.h +++ b/source/blender/windowmanager/wm_window.h @@ -21,11 +21,14 @@ * \ingroup wm */ -#ifndef __WM_WINDOW_H__ -#define __WM_WINDOW_H__ +#pragma once struct wmOperator; +#ifdef __cplusplus +extern "C" { +#endif + /* *************** internal api ************** */ void wm_ghost_init(bContext *C); void wm_ghost_exit(void); @@ -85,4 +88,6 @@ int wm_window_new_main_exec(bContext *C, struct wmOperator *op); void wm_test_autorun_warning(bContext *C); -#endif /* __WM_WINDOW_H__ */ +#ifdef __cplusplus +} +#endif diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c index 684e59eb8b2..6f96d2ea6a0 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c @@ -55,7 +55,7 @@ static void wm_xr_draw_matrices_create(const wmXrDrawData *draw_data, copy_qt_qt(eye_pose.orientation_quat, draw_view->eye_pose.orientation_quat); copy_v3_v3(eye_pose.position, draw_view->eye_pose.position); - add_v3_v3(eye_pose.position, draw_data->eye_position_ofs); + sub_v3_v3(eye_pose.position, draw_data->eye_position_ofs); if ((session_settings->flag & XR_SESSION_USE_POSITION_TRACKING) == 0) { sub_v3_v3(eye_pose.position, draw_view->local_pose.position); } diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h index 9b7e9a15948..25e3da3ffb4 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h +++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_XR_INTERN_H__ -#define __WM_XR_INTERN_H__ +#pragma once #include "CLG_log.h" @@ -50,7 +49,11 @@ typedef struct wmXrSessionState { typedef struct wmXrRuntimeData { GHOST_XrContextHandle context; - /* Although this struct is internal, RNA gets a handle to this for state information queries. */ + /** The window the session was started in. Stored to be able to follow its view-layer. This may + * be an invalid reference, i.e. the window may have been closed. */ + wmWindow *session_root_win; + + /** Although this struct is internal, RNA gets a handle to this for state information queries. */ wmXrSessionState session_state; wmXrSessionExitFn exit_fn; } wmXrRuntimeData; @@ -71,6 +74,8 @@ typedef struct wmXrDrawData { * space). With positional tracking enabled, it should be the same as the base pose, when * disabled it also contains a location delta from the moment the option was toggled. */ GHOST_XrPose base_pose; + /** Offset to _substract_ from the OpenXR eye and viewer pose to get the wanted effective pose + * (e.g. a pose exactly at the landmark position). */ float eye_position_ofs[3]; /* Local/view space. */ } wmXrDrawData; @@ -92,5 +97,3 @@ void wm_xr_session_gpu_binding_context_destroy(GHOST_ContextHandle context); void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4]); void wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view, void *customdata); - -#endif diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index 5d85045e8fa..9c6b8e8fbda 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -19,7 +19,10 @@ */ #include "BKE_context.h" +#include "BKE_main.h" +#include "BKE_scene.h" +#include "BLI_listbase.h" #include "BLI_math.h" #include "DEG_depsgraph.h" @@ -41,8 +44,8 @@ #include "wm_window.h" #include "wm_xr_intern.h" -wmSurface *g_xr_surface = NULL; -CLG_LogRef LOG = {"wm.xr"}; +static wmSurface *g_xr_surface = NULL; +static CLG_LogRef LOG = {"wm.xr"}; /* -------------------------------------------------------------------- */ @@ -68,7 +71,9 @@ static void wm_xr_session_begin_info_create(wmXrData *xr_data, r_begin_info->exit_customdata = xr_data; } -void wm_xr_session_toggle(wmWindowManager *wm, wmXrSessionExitFn session_exit_fn) +void wm_xr_session_toggle(wmWindowManager *wm, + wmWindow *session_root_win, + wmXrSessionExitFn session_exit_fn) { wmXrData *xr_data = &wm->xr; @@ -78,6 +83,7 @@ void wm_xr_session_toggle(wmWindowManager *wm, wmXrSessionExitFn session_exit_fn else { GHOST_XrSessionBeginInfo begin_info; + xr_data->runtime->session_root_win = session_root_win; xr_data->runtime->session_state.is_started = true; xr_data->runtime->exit_fn = session_exit_fn; @@ -159,6 +165,43 @@ static void wm_xr_session_draw_data_populate(wmXrData *xr_data, wm_xr_session_base_pose_calc(r_draw_data->scene, settings, &r_draw_data->base_pose); } +static wmWindow *wm_xr_session_root_window_or_fallback_get(const wmWindowManager *wm, + const wmXrRuntimeData *runtime_data) +{ + if (runtime_data->session_root_win && + BLI_findindex(&wm->windows, runtime_data->session_root_win) != -1) { + /* Root window is still valid, use it. */ + return runtime_data->session_root_win; + } + /* Otherwise, fallback. */ + return wm->windows.first; +} + +/** + * Get the scene and depsgraph shown in the VR session's root window (the window the session was + * started from) if still available. If it's not available, use some fallback window. + * + * It's important that the VR session follows some existing window, otherwise it would need to have + * an own depsgraph, which is an expense we should avoid. + */ +static void wm_xr_session_scene_and_evaluated_depsgraph_get(Main *bmain, + const wmWindowManager *wm, + Scene **r_scene, + Depsgraph **r_depsgraph) +{ + const wmWindow *root_win = wm_xr_session_root_window_or_fallback_get(wm, wm->xr.runtime); + + /* Follow the scene & view layer shown in the root 3D View. */ + Scene *scene = WM_window_get_active_scene(root_win); + ViewLayer *view_layer = WM_window_get_active_view_layer(root_win); + + Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer, false); + BLI_assert(scene && view_layer && depsgraph); + BKE_scene_graph_evaluated_ensure(depsgraph, bmain); + *r_scene = scene; + *r_depsgraph = depsgraph; +} + typedef enum wmXrSessionStateEvent { SESSION_STATE_EVENT_NONE = 0, SESSION_STATE_EVENT_START, @@ -177,8 +220,8 @@ static bool wm_xr_session_draw_data_needs_reset_to_base_pose(const wmXrSessionSt (state->prev_base_pose_object != settings->base_pose_object)); } -wmXrSessionStateEvent wm_xr_session_state_to_event(const wmXrSessionState *state, - const XrSessionSettings *settings) +static wmXrSessionStateEvent wm_xr_session_state_to_event(const wmXrSessionState *state, + const XrSessionSettings *settings) { if (!state->is_view_data_set) { return SESSION_STATE_EVENT_START; @@ -208,8 +251,9 @@ void wm_xr_session_draw_data_update(const wmXrSessionState *state, switch (event) { case SESSION_STATE_EVENT_START: - /* Always use the exact base pose with no offset when starting the session. */ - copy_v3_fl(draw_data->eye_position_ofs, 0.0f); + /* We want to start the session exactly at landmark position. Runtimes may have a non-[0,0,0] + * starting position that we have to substract for that. */ + copy_v3_v3(draw_data->eye_position_ofs, draw_view->local_pose.position); break; /* This should be triggered by the VR add-on if a landmark changes. */ case SESSION_STATE_EVENT_RESET_TO_BASE_POSE: @@ -256,9 +300,9 @@ void wm_xr_session_state_update(const XrSessionSettings *settings, copy_v3_v3(viewer_pose.position, draw_data->base_pose.position); /* The local pose and the eye pose (which is copied from an earlier local pose) both are view * space, so Y-up. In this case we need them in regular Z-up. */ - viewer_pose.position[0] += draw_data->eye_position_ofs[0]; - viewer_pose.position[1] -= draw_data->eye_position_ofs[2]; - viewer_pose.position[2] += draw_data->eye_position_ofs[1]; + viewer_pose.position[0] -= draw_data->eye_position_ofs[0]; + viewer_pose.position[1] += draw_data->eye_position_ofs[2]; + viewer_pose.position[2] -= draw_data->eye_position_ofs[1]; if (use_position_tracking) { viewer_pose.position[0] += draw_view->local_pose.position[0]; viewer_pose.position[1] -= draw_view->local_pose.position[2]; @@ -278,6 +322,8 @@ void wm_xr_session_state_update(const XrSessionSettings *settings, state->prev_base_pose_type = settings->base_pose_type; state->prev_base_pose_object = settings->base_pose_object; state->is_view_data_set = true; + /* Assume this was already done through wm_xr_session_draw_data_update(). */ + state->force_reset_to_base_pose = false; } wmXrSessionState *WM_xr_session_state_handle_get(const wmXrData *xr) @@ -342,13 +388,17 @@ static void wm_xr_session_surface_draw(bContext *C) { wmXrSurfaceData *surface_data = g_xr_surface->customdata; wmWindowManager *wm = CTX_wm_manager(C); + Main *bmain = CTX_data_main(C); wmXrDrawData draw_data; if (!GHOST_XrSessionIsRunning(wm->xr.runtime->context)) { return; } - wm_xr_session_draw_data_populate( - &wm->xr, CTX_data_scene(C), CTX_data_ensure_evaluated_depsgraph(C), &draw_data); + + Scene *scene; + Depsgraph *depsgraph; + wm_xr_session_scene_and_evaluated_depsgraph_get(bmain, wm, &scene, &depsgraph); + wm_xr_session_draw_data_populate(&wm->xr, scene, depsgraph, &draw_data); GHOST_XrSessionDrawViews(wm->xr.runtime->context, &draw_data); diff --git a/source/blender/windowmanager/xr/wm_xr.h b/source/blender/windowmanager/xr/wm_xr.h index 33f79bc75b2..0f0fbe8bc00 100644 --- a/source/blender/windowmanager/xr/wm_xr.h +++ b/source/blender/windowmanager/xr/wm_xr.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_XR_H__ -#define __WM_XR_H__ +#pragma once struct wmWindowManager; struct wmXrData; @@ -29,7 +28,5 @@ typedef void (*wmXrSessionExitFn)(const wmXrData *xr_data); /* wm_xr.c */ bool wm_xr_init(wmWindowManager *wm); void wm_xr_exit(wmWindowManager *wm); -void wm_xr_session_toggle(wmWindowManager *wm, wmXrSessionExitFn session_exit_fn); +void wm_xr_session_toggle(wmWindowManager *wm, wmWindow *win, wmXrSessionExitFn session_exit_fn); bool wm_xr_events_handle(wmWindowManager *wm); - -#endif |