diff options
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/CMakeLists.txt | 6 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 17 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 6 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_draw.c | 33 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.cc | 128 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 21 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_splash_screen.c | 81 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 175 | ||||
-rw-r--r-- | source/blender/windowmanager/message_bus/wm_message_bus.h | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_window.h | 1 |
14 files changed, 320 insertions, 168 deletions
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 7a36020cea5..9da150e0b7a 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -23,9 +23,9 @@ set(INC ../sequencer ../../../intern/clog ../../../intern/ghost - ../../../intern/glew-mx ../../../intern/guardedalloc ../../../intern/memutil + ../bmesh # for writefile.c: dna_type_offsets.h ${CMAKE_BINARY_DIR}/source/blender/makesdna/intern @@ -164,11 +164,11 @@ if(WIN32 OR APPLE) endif() endif() -if(WITH_COMPOSITOR) +if(WITH_COMPOSITOR_CPU) list(APPEND LIB bf_compositor ) - add_definitions(-DWITH_COMPOSITOR) + add_definitions(-DWITH_COMPOSITOR_CPU) endif() if(WITH_XR_OPENXR) diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 44c5b86857d..0393be93bb5 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -134,7 +134,24 @@ void WM_window_pixel_sample_read(const wmWindowManager *wm, const int pos[2], float r_col[3]); +/** + * Read pixels from the front-buffer (fast). + * + * \note Internally this depends on the front-buffer state, + * for a slower but more reliable method of reading pixels, use #WM_window_pixels_read_offscreen. + * Fast pixel access may be preferred for file-save thumbnails. + * + * \warning Drawing (swap-buffers) immediately before calling this function causes + * the front-buffer state to be invalid under some EGL configurations. + */ uint *WM_window_pixels_read(struct wmWindowManager *wm, struct wmWindow *win, int r_size[2]); +/** + * Draw the window & read pixels from an off-screen buffer (slower than #WM_window_pixels_read). + * + * \note This is needed because the state of the front-buffer may be damaged + * (see in-line code comments for details). + */ +uint *WM_window_pixels_read_offscreen(struct bContext *C, struct wmWindow *win, int r_size[2]); /** * Support for native pixel size diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index e7cbe936607..6526b7bec0e 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -321,6 +321,7 @@ typedef struct wmNotifier { /* category */ #define NOTE_CATEGORY 0xFF000000 +#define NOTE_CATEGORY_TAG_CLEARED NOTE_CATEGORY #define NC_WM (1 << 24) #define NC_WINDOW (2 << 24) #define NC_WORKSPACE (3 << 24) @@ -669,7 +670,6 @@ typedef struct wmTabletData { * * - Mouse-wheel events are excluded even though they generate #KM_PRESS * as clicking and dragging don't make sense for mouse wheel events. - * */ typedef struct wmEvent { struct wmEvent *next, *prev; diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c index 4ecadbc5685..e165cb6b4f8 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c @@ -1053,7 +1053,7 @@ void WM_gizmomaptype_group_unlink(bContext *C, WM_gizmomaptype_group_free(gzgt_ref); } - /* TODO(campbell): Gizmos may share key-maps, for now don't + /* TODO(@campbellbarton): Gizmos may share key-maps, for now don't * remove however we could flag them as temporary/owned by the gizmo. */ #if 0 /* NOTE: we may want to keep this key-map for editing. */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index f5974a2176b..9903b0e50fd 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -259,7 +259,7 @@ bool WM_gizmomap_minmax(const wmGizmoMap *gzmap, * \param poll: Polling function for excluding gizmos. * \param data: Custom data passed to \a poll * - * TODO(campbell): this uses unreliable order, + * TODO(@campbellbarton): this uses unreliable order, * best we use an iterator function instead of a hash. */ static GHash *WM_gizmomap_gizmo_hash_new(const bContext *C, @@ -430,9 +430,9 @@ static void gizmos_draw_list(const wmGizmoMap *gzmap, const bContext *C, ListBas return; } - /* TODO(campbell): This will need it own shader probably? + /* TODO(@campbellbarton): This will need it own shader probably? * Don't think it can be handled from that point though. */ - /* const bool use_lighting = (U.gizmo_flag & V3D_GIZMO_SHADED) != 0; */ + // const bool use_lighting = (U.gizmo_flag & V3D_GIZMO_SHADED) != 0; bool is_depth_prev = false; @@ -501,7 +501,7 @@ static void gizmo_draw_select_3d_loop(const bContext *C, bool *r_use_select_bias) { - /* TODO(campbell): this depends on depth buffer being written to, + /* TODO(@campbellbarton): this depends on depth buffer being written to, * currently broken for the 3D view. */ bool is_depth_prev = false; bool is_depth_skip_prev = false; @@ -674,7 +674,7 @@ static wmGizmo *gizmo_find_intersected_3d(bContext *C, * This way we always use the first hit. */ if (has_3d) { - /* The depth buffer is needed for for gizmos to obscure each other. */ + /* The depth buffer is needed for gizmos to obscure each other. */ GPUViewport *viewport = WM_draw_region_get_viewport(CTX_wm_region(C)); /* When switching between modes and the mouse pointer is over a gizmo, the highlight test is diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 2500d72c850..a0200373ac6 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -15,6 +15,7 @@ #include <stddef.h> #include <string.h> +#include "BLI_ghash.h" #include "BLI_sys_types.h" #include "DNA_windowmanager_types.h" @@ -193,6 +194,7 @@ static void window_manager_blend_read_data(BlendDataReader *reader, ID *id) BLI_listbase_clear(&wm->operators); BLI_listbase_clear(&wm->paintcursors); BLI_listbase_clear(&wm->notifier_queue); + wm->notifier_queue_set = NULL; BKE_reports_init(&wm->reports, RPT_STORE); BLI_listbase_clear(&wm->keyconfigs); @@ -580,6 +582,10 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm) } BLI_freelistN(&wm->notifier_queue); + if (wm->notifier_queue_set) { + BLI_gset_free(wm->notifier_queue_set, NULL); + wm->notifier_queue_set = NULL; + } if (wm->message_bus != NULL) { WM_msgbus_destroy(wm->message_bus); diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 1bb405d1abc..48743c2649f 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -1191,6 +1191,39 @@ static void wm_draw_surface(bContext *C, wmSurface *surface) wm_surface_clear_drawable(); } +uint *WM_window_pixels_read_offscreen(bContext *C, wmWindow *win, int r_size[2]) +{ + /* NOTE(@campbellbarton): There is a problem reading the windows front-buffer after redrawing + * the window in some cases (typically to clear UI elements such as menus or search popup). + * With EGL `eglSurfaceAttrib(..)` may support setting the `EGL_SWAP_BEHAVIOR` attribute to + * `EGL_BUFFER_PRESERVED` however not all implementations support this. + * Requesting the ability with `EGL_SWAP_BEHAVIOR_PRESERVED_BIT` can even cause the EGL context + * not to initialize at all. + * Confusingly there are some cases where this *does* work, depending on the state of the window + * and prior calls to swap-buffers, however ensuring the state exactly as needed to satisfy a + * particular GPU back-end is fragile, see T98462. + * + * So provide an alternative to #WM_window_pixels_read that avoids using the front-buffer. */ + + /* Draw into an off-screen buffer and read it's contents. */ + r_size[0] = WM_window_pixels_x(win); + r_size[1] = WM_window_pixels_y(win); + + GPUOffScreen *offscreen = GPU_offscreen_create(r_size[0], r_size[1], false, GPU_RGBA8, NULL); + if (UNLIKELY(!offscreen)) { + return NULL; + } + + const uint rect_len = r_size[0] * r_size[1]; + uint *rect = MEM_mallocN(sizeof(*rect) * rect_len, __func__); + GPU_offscreen_bind(offscreen, false); + wm_draw_window_onscreen(C, win, -1); + GPU_offscreen_unbind(offscreen, false); + GPU_offscreen_read_pixels(offscreen, GPU_DATA_UBYTE, rect); + GPU_offscreen_free(offscreen); + return rect; +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 895bab8ed89..3054708fbdb 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -27,6 +27,7 @@ #include "BLI_blenlib.h" #include "BLI_dynstr.h" +#include "BLI_ghash.h" #include "BLI_math.h" #include "BLI_timer.h" #include "BLI_utildefines.h" @@ -90,6 +91,7 @@ #define USE_GIZMO_MOUSE_PRIORITY_HACK static void wm_notifier_clear(wmNotifier *note); +static bool wm_notifier_is_clear(const wmNotifier *note); static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, @@ -252,36 +254,67 @@ void wm_event_init_from_window(wmWindow *win, wmEvent *event) /** \name Notifiers & Listeners * \{ */ -static bool wm_test_duplicate_notifier(const wmWindowManager *wm, uint type, void *reference) +/** + * Hash for #wmWindowManager.notifier_queue_set, ignores `window`. + */ +static uint note_hash_for_queue_fn(const void *ptr) { - LISTBASE_FOREACH (wmNotifier *, note, &wm->notifier_queue) { - if ((note->category | note->data | note->subtype | note->action) == type && - note->reference == reference) { - return true; - } - } + const wmNotifier *note = static_cast<const wmNotifier *>(ptr); + return (BLI_ghashutil_ptrhash(note->reference) ^ + (note->category | note->data | note->subtype | note->action)); +} - return false; +/** + * Comparison for #wmWindowManager.notifier_queue_set + * + * \note This is not an exact equality function as the `window` is ignored. + */ +static bool note_cmp_for_queue_fn(const void *a, const void *b) +{ + const wmNotifier *note_a = static_cast<const wmNotifier *>(a); + const wmNotifier *note_b = static_cast<const wmNotifier *>(b); + return !(((note_a->category | note_a->data | note_a->subtype | note_a->action) == + (note_b->category | note_b->data | note_b->subtype | note_b->action)) && + (note_a->reference == note_b->reference)); } void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference) { - if (wm_test_duplicate_notifier(wm, type, reference)) { + if (wm == nullptr) { + /* There may be some cases where e.g. `G_MAIN` is not actually the real current main, but some + * other temporary one (e.g. during liboverride processing over linked data), leading to null + * window manager. + * + * This is fairly bad and weak, but unfortunately RNA does not have any way to operate over + * another main than G_MAIN currently. */ return; } - wmNotifier *note = MEM_cnew<wmNotifier>(__func__); + wmNotifier note_test = {nullptr}; - BLI_addtail(&wm->notifier_queue, note); + note_test.window = win; - note->window = win; + note_test.category = type & NOTE_CATEGORY; + note_test.data = type & NOTE_DATA; + note_test.subtype = type & NOTE_SUBTYPE; + note_test.action = type & NOTE_ACTION; + note_test.reference = reference; - note->category = type & NOTE_CATEGORY; - note->data = type & NOTE_DATA; - note->subtype = type & NOTE_SUBTYPE; - note->action = type & NOTE_ACTION; + BLI_assert(!wm_notifier_is_clear(¬e_test)); - note->reference = reference; + if (wm->notifier_queue_set == nullptr) { + wm->notifier_queue_set = BLI_gset_new_ex( + note_hash_for_queue_fn, note_cmp_for_queue_fn, __func__, 1024); + } + + void **note_p; + if (BLI_gset_ensure_p_ex(wm->notifier_queue_set, ¬e_test, ¬e_p)) { + return; + } + wmNotifier *note = MEM_new<wmNotifier>(__func__); + *note = note_test; + *note_p = note; + BLI_addtail(&wm->notifier_queue, note); } /* XXX: in future, which notifiers to send to other windows? */ @@ -295,20 +328,7 @@ void WM_main_add_notifier(unsigned int type, void *reference) Main *bmain = G_MAIN; wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first); - if (!wm || wm_test_duplicate_notifier(wm, type, reference)) { - return; - } - - wmNotifier *note = MEM_cnew<wmNotifier>(__func__); - - BLI_addtail(&wm->notifier_queue, note); - - note->category = type & NOTE_CATEGORY; - note->data = type & NOTE_DATA; - note->subtype = type & NOTE_SUBTYPE; - note->action = type & NOTE_ACTION; - - note->reference = reference; + WM_event_add_notifier_ex(wm, nullptr, type, reference); } void WM_main_remove_notifier_reference(const void *reference) @@ -319,6 +339,9 @@ void WM_main_remove_notifier_reference(const void *reference) if (wm) { LISTBASE_FOREACH_MUTABLE (wmNotifier *, note, &wm->notifier_queue) { if (note->reference == reference) { + const bool removed = BLI_gset_remove(wm->notifier_queue_set, note, nullptr); + BLI_assert(removed); + UNUSED_VARS_NDEBUG(removed); /* Don't remove because this causes problems for #wm_event_do_notifiers * which may be looping on the data (deleting screens). */ wm_notifier_clear(note); @@ -374,6 +397,12 @@ static void wm_notifier_clear(wmNotifier *note) { /* nullptr the entire notifier, only leaving (`next`, `prev`) members intact. */ memset(((char *)note) + sizeof(Link), 0, sizeof(*note) - sizeof(Link)); + note->category = NOTE_CATEGORY_TAG_CLEARED; +} + +static bool wm_notifier_is_clear(const wmNotifier *note) +{ + return note->category == NOTE_CATEGORY_TAG_CLEARED; } void wm_event_do_depsgraph(bContext *C, bool is_after_open_file) @@ -473,7 +502,7 @@ void wm_event_do_notifiers(bContext *C) CTX_wm_window_set(C, win); - LISTBASE_FOREACH_MUTABLE (wmNotifier *, note, &wm->notifier_queue) { + LISTBASE_FOREACH_MUTABLE (const wmNotifier *, note, &wm->notifier_queue) { if (note->category == NC_WM) { if (ELEM(note->data, ND_FILEREAD, ND_FILESAVE)) { wm->file_saved = 1; @@ -565,8 +594,15 @@ void wm_event_do_notifiers(bContext *C) } /* The notifiers are sent without context, to keep it clean. */ - wmNotifier *note; - while ((note = static_cast<wmNotifier *>(BLI_pophead(&wm->notifier_queue)))) { + const wmNotifier *note; + while ((note = static_cast<const wmNotifier *>(BLI_pophead(&wm->notifier_queue)))) { + if (wm_notifier_is_clear(note)) { + MEM_freeN((void *)note); + continue; + } + const bool removed = BLI_gset_remove(wm->notifier_queue_set, note, nullptr); + BLI_assert(removed); + UNUSED_VARS_NDEBUG(removed); LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { Scene *scene = WM_window_get_active_scene(win); bScreen *screen = WM_window_get_active_screen(win); @@ -630,7 +666,7 @@ void wm_event_do_notifiers(bContext *C) } } - MEM_freeN(note); + MEM_freeN((void *)note); } #endif /* If 1 (postpone disabling for in favor of message-bus), eventually. */ @@ -657,7 +693,7 @@ void wm_event_do_notifiers(bContext *C) wm_test_autorun_warning(C); } -static int wm_event_always_pass(const wmEvent *event) +static bool wm_event_always_pass(const wmEvent *event) { /* Some events we always pass on, to ensure proper communication. */ return ISTIMER(event->type) || (event->type == WINDEACTIVATE); @@ -1555,6 +1591,7 @@ static int wm_operator_call_internal(bContext *C, case WM_OP_EXEC_AREA: case WM_OP_EXEC_SCREEN: event = nullptr; + break; default: break; } @@ -2740,7 +2777,7 @@ static int wm_handler_fileselect_call(bContext *C, return wm_handler_fileselect_do(C, handlers, handler, event->val); } -static int wm_action_not_handled(int action) +static bool wm_action_not_handled(int action) { return action == WM_HANDLER_CONTINUE || action == (WM_HANDLER_BREAK | WM_HANDLER_MODAL); } @@ -5181,7 +5218,7 @@ static bool wm_event_is_ignorable_key_press(const wmWindow *win, const wmEvent & return false; } - const wmEvent &last_event = *reinterpret_cast<const wmEvent *>(win->event_queue.last); + const wmEvent &last_event = *static_cast<const wmEvent *>(win->event_queue.last); return wm_event_is_same_key_press(last_event, event); } @@ -5221,6 +5258,13 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void event.prev_type = event.type; event.prev_val = event.val; + /* Always use modifiers from the active window since + changes to modifiers aren't sent to inactive windows, see: T66088. */ + if ((wm->winactive != win) && (wm->winactive && wm->winactive->eventstate)) { + event.modifier = wm->winactive->eventstate->modifier; + event.keymodifier = wm->winactive->eventstate->keymodifier; + } + /* Ensure the event state is correct, any deviation from this may cause bugs. * * NOTE: #EVENT_NONE is set when unknown keys are pressed, @@ -5263,6 +5307,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void if (win_other) { wmEvent event_other = *win_other->eventstate; + /* Use the modifier state of this window. */ + event_other.modifier = event.modifier; + event_other.keymodifier = event.keymodifier; + /* See comment for this operation on `event` for details. */ event_other.prev_type = event_other.type; event_other.prev_val = event_other.val; @@ -5352,6 +5400,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void if (win_other) { wmEvent event_other = *win_other->eventstate; + /* Use the modifier state of this window. */ + event_other.modifier = event.modifier; + event_other.keymodifier = event.keymodifier; + /* See comment for this operation on `event` for details. */ event_other.prev_type = event_other.type; event_other.prev_val = event_other.val; diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 25782cb4fe7..fb3da9dc7ec 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -705,6 +705,14 @@ static void wm_file_read_post(bContext *C, const struct wmFileReadPost_Params *p } } + if (is_factory_startup && BLT_translate_new_dataname()) { + /* Translate workspace names */ + LISTBASE_FOREACH_MUTABLE (WorkSpace *, workspace, &bmain->workspaces) { + BKE_libblock_rename( + bmain, &workspace->id, CTX_DATA_(BLT_I18NCONTEXT_ID_WORKSPACE, workspace->id.name + 2)); + } + } + if (use_data) { /* important to do before NULL'ing the context */ BKE_callback_exec_null(bmain, BKE_CB_EVT_VERSION_UPDATE); @@ -1774,9 +1782,11 @@ static bool wm_file_write(bContext *C, /* Enforce full override check/generation on file save. */ BKE_lib_override_library_main_operations_create(bmain, true); - /* NOTE: Ideally we would call `WM_redraw_windows` here to remove any open menus. But we - * can crash if saving from a script, see T92704 & T97627. Just checking `!G.background - * && BLI_thread_is_main()` is not sufficient to fix this. */ + /* NOTE: Ideally we would call `WM_redraw_windows` here to remove any open menus. + * But we can crash if saving from a script, see T92704 & T97627. + * Just checking `!G.background && BLI_thread_is_main()` is not sufficient to fix this. + * Additionally some some EGL configurations don't support reading the front-buffer + * immediately after drawing, see: T98462. In that case off-screen drawing is necessary. */ /* don't forget not to return without! */ WM_cursor_wait(true); @@ -1893,9 +1903,6 @@ static void wm_autosave_location(char *filepath) { const int pid = abs(getpid()); char path[1024]; -#ifdef WIN32 - const char *savedir; -#endif /* Normally there is no need to check for this to be NULL, * however this runs on exit when it may be cleared. */ @@ -1921,7 +1928,7 @@ static void wm_autosave_location(char *filepath) * through BLI_windows_get_default_root_dir(). * If there is no C:\tmp autosave fails. */ if (!BLI_exists(BKE_tempdir_base())) { - savedir = BKE_appdir_folder_id_create(BLENDER_USER_AUTOSAVE, NULL); + const char *savedir = BKE_appdir_folder_id_create(BLENDER_USER_AUTOSAVE, NULL); BLI_make_file_string("/", filepath, savedir, path); return; } diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 7f5ec77e16d..8163b39b3dd 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -166,7 +166,7 @@ void WM_init_opengl(void) if (G.background) { /* Ghost is still not initialized elsewhere in background mode. */ - wm_ghost_init(NULL); + wm_ghost_init_background(); } if (!GPU_backend_supported()) { @@ -540,7 +540,7 @@ void WM_exit_ex(bContext *C, const bool do_python) BKE_vfont_clipboard_free(); BKE_node_clipboard_free(); -#ifdef WITH_COMPOSITOR +#ifdef WITH_COMPOSITOR_CPU COM_deinitialize(); #endif diff --git a/source/blender/windowmanager/intern/wm_splash_screen.c b/source/blender/windowmanager/intern/wm_splash_screen.c index 2e04a629308..8fca3deef92 100644 --- a/source/blender/windowmanager/intern/wm_splash_screen.c +++ b/source/blender/windowmanager/intern/wm_splash_screen.c @@ -78,50 +78,51 @@ static void wm_block_splash_add_label(uiBlock *block, const char *label, int x, static void wm_block_splash_image_roundcorners_add(ImBuf *ibuf) { uchar *rct = (uchar *)ibuf->rect; + if (!rct) { + return; + } - if (rct) { - bTheme *btheme = UI_GetTheme(); - const float roundness = btheme->tui.wcol_menu_back.roundness * U.dpi_fac; - const int size = roundness * 20; - - if (size < ibuf->x && size < ibuf->y) { - /* Y-axis initial offset. */ - rct += 4 * (ibuf->y - size) * ibuf->x; - - for (int y = 0; y < size; y++) { - for (int x = 0; x < size; x++, rct += 4) { - const float pixel = 1.0 / size; - const float u = pixel * x; - const float v = pixel * y; - const float distance = sqrt(u * u + v * v); - - /* Pointer offset to the alpha value of pixel. */ - /* NOTE: the left corner is flipped in the X-axis. */ - const int offset_l = 4 * (size - x - x - 1) + 3; - const int offset_r = 4 * (ibuf->x - size) + 3; - - if (distance > 1.0) { - rct[offset_l] = 0; - rct[offset_r] = 0; - } - else { - /* Create a single pixel wide transition for anti-aliasing. - * Invert the distance and map its range [0, 1] to [0, pixel]. */ - const float fac = (1.0 - distance) * size; - - if (fac > 1.0) { - continue; - } - - const uchar alpha = unit_float_to_uchar_clamp(fac); - rct[offset_l] = alpha; - rct[offset_r] = alpha; - } + bTheme *btheme = UI_GetTheme(); + const float roundness = btheme->tui.wcol_menu_back.roundness * U.dpi_fac; + const int size = roundness * 20; + + if (size < ibuf->x && size < ibuf->y) { + /* Y-axis initial offset. */ + rct += 4 * (ibuf->y - size) * ibuf->x; + + for (int y = 0; y < size; y++) { + for (int x = 0; x < size; x++, rct += 4) { + const float pixel = 1.0 / size; + const float u = pixel * x; + const float v = pixel * y; + const float distance = sqrt(u * u + v * v); + + /* Pointer offset to the alpha value of pixel. */ + /* NOTE: the left corner is flipped in the X-axis. */ + const int offset_l = 4 * (size - x - x - 1) + 3; + const int offset_r = 4 * (ibuf->x - size) + 3; + + if (distance > 1.0) { + rct[offset_l] = 0; + rct[offset_r] = 0; } + else { + /* Create a single pixel wide transition for anti-aliasing. + * Invert the distance and map its range [0, 1] to [0, pixel]. */ + const float fac = (1.0 - distance) * size; - /* X-axis offset to the next row. */ - rct += 4 * (ibuf->x - size); + if (fac > 1.0) { + continue; + } + + const uchar alpha = unit_float_to_uchar_clamp(fac); + rct[offset_l] = alpha; + rct[offset_r] = alpha; + } } + + /* X-axis offset to the next row. */ + rct += 4 * (ibuf->x - size); } } } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index a1ebe1fc76f..661db1b62e7 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -155,28 +155,30 @@ static void wm_window_check_size(rcti *rect) static void wm_ghostwindow_destroy(wmWindowManager *wm, wmWindow *win) { - if (win->ghostwin) { - /* Prevents non-drawable state of main windows (bugs T22967, - * T25071 and possibly T22477 too). Always clear it even if - * this window was not the drawable one, because we mess with - * drawing context to discard the GW context. */ - wm_window_clear_drawable(wm); + if (UNLIKELY(!win->ghostwin)) { + return; + } - if (win == wm->winactive) { - wm->winactive = NULL; - } + /* Prevents non-drawable state of main windows (bugs T22967, + * T25071 and possibly T22477 too). Always clear it even if + * this window was not the drawable one, because we mess with + * drawing context to discard the GW context. */ + wm_window_clear_drawable(wm); - /* We need this window's opengl context active to discard it. */ - GHOST_ActivateWindowDrawingContext(win->ghostwin); - GPU_context_active_set(win->gpuctx); + if (win == wm->winactive) { + wm->winactive = NULL; + } + + /* We need this window's opengl context active to discard it. */ + GHOST_ActivateWindowDrawingContext(win->ghostwin); + GPU_context_active_set(win->gpuctx); - /* Delete local GPU context. */ - GPU_context_discard(win->gpuctx); + /* Delete local GPU context. */ + GPU_context_discard(win->gpuctx); - GHOST_DisposeWindow(g_system, win->ghostwin); - win->ghostwin = NULL; - win->gpuctx = NULL; - } + GHOST_DisposeWindow(g_system, win->ghostwin); + win->ghostwin = NULL; + win->gpuctx = NULL; } void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win) @@ -968,8 +970,8 @@ typedef enum { OS = 'C', } modifierKeyType; -/* check if specified modifier key type is pressed */ -static int query_qual(modifierKeyType qual) +/** Check if specified modifier key type is pressed. */ +static bool query_qual(modifierKeyType qual) { GHOST_TModifierKey left, right; switch (qual) { @@ -1113,14 +1115,22 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt } wmWindow *win = GHOST_GetWindowUserData(ghostwin); + /* Win23/GHOST modifier bug, see T40317 */ +#ifndef WIN32 +//# define USE_WIN_ACTIVATE +#endif + switch (type) { case GHOST_kEventWindowDeactivate: wm_event_add_ghostevent(wm, win, type, data); win->active = 0; /* XXX */ - /* clear modifiers for inactive windows */ + /* When window activation is enabled, these modifiers are set with window activation. + * Otherwise leave them set so re-activation doesn't loose keys which are held. */ +#ifdef USE_WIN_ACTIVATE win->eventstate->modifier = 0; win->eventstate->keymodifier = 0; +#endif break; case GHOST_kEventWindowActivate: { @@ -1128,11 +1138,6 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt (query_qual(CONTROL) ? KM_CTRL : 0) | (query_qual(ALT) ? KM_ALT : 0) | (query_qual(OS) ? KM_OSKEY : 0)); - /* Win23/GHOST modifier bug, see T40317 */ -#ifndef WIN32 -//# define USE_WIN_ACTIVATE -#endif - /* No context change! C->wm->windrawable is drawable, or for area queues. */ wm->winactive = win; @@ -1367,6 +1372,10 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt event.xy[0] = ddd->x; event.xy[1] = ddd->y; + /* The values from #wm_window_update_eventstate may not match (under WAYLAND they don't) + * Write this into the event state. */ + copy_v2_v2_int(win->eventstate->xy, event.xy); + event.flag = 0; /* No context change! C->wm->windrawable is drawable, or for area queues. */ @@ -1551,36 +1560,55 @@ void wm_window_process_events(const bContext *C) void wm_ghost_init(bContext *C) { - if (!g_system) { - GHOST_EventConsumerHandle consumer; + if (g_system) { + return; + } - if (C != NULL) { - consumer = GHOST_CreateEventConsumer(ghost_event_proc, C); - } + BLI_assert(C != NULL); + BLI_assert_msg(!G.background, "Use wm_ghost_init_background instead"); - GHOST_SetBacktraceHandler((GHOST_TBacktraceFn)BLI_system_backtrace); + GHOST_EventConsumerHandle consumer; - g_system = GHOST_CreateSystem(); + consumer = GHOST_CreateEventConsumer(ghost_event_proc, C); - GHOST_Debug debug = {0}; - if (G.debug & G_DEBUG_GHOST) { - debug.flags |= GHOST_kDebugDefault; - } - if (G.debug & G_DEBUG_WINTAB) { - debug.flags |= GHOST_kDebugWintab; - } - GHOST_SystemInitDebug(g_system, debug); + GHOST_SetBacktraceHandler((GHOST_TBacktraceFn)BLI_system_backtrace); - if (C != NULL) { - GHOST_AddEventConsumer(g_system, consumer); - } + g_system = GHOST_CreateSystem(); - if (wm_init_state.native_pixels) { - GHOST_UseNativePixels(); - } + GHOST_Debug debug = {0}; + if (G.debug & G_DEBUG_GHOST) { + debug.flags |= GHOST_kDebugDefault; + } + if (G.debug & G_DEBUG_WINTAB) { + debug.flags |= GHOST_kDebugWintab; + } + GHOST_SystemInitDebug(g_system, debug); + + GHOST_AddEventConsumer(g_system, consumer); + + if (wm_init_state.native_pixels) { + GHOST_UseNativePixels(); + } + + GHOST_UseWindowFocus(wm_init_state.window_focus); +} + +/* TODO move this to wm_init_exit.c. */ +void wm_ghost_init_background(void) +{ + if (g_system) { + return; + } + + GHOST_SetBacktraceHandler((GHOST_TBacktraceFn)BLI_system_backtrace); - GHOST_UseWindowFocus(wm_init_state.window_focus); + g_system = GHOST_CreateSystemBackground(); + + GHOST_Debug debug = {0}; + if (G.debug & G_DEBUG_GHOST) { + debug.flags |= GHOST_kDebugDefault; } + GHOST_SystemInitDebug(g_system, debug); } void wm_ghost_exit(void) @@ -1925,6 +1953,9 @@ void WM_window_pixel_sample_read(const wmWindowManager *wm, uint *WM_window_pixels_read(wmWindowManager *wm, wmWindow *win, int r_size[2]) { + /* WARNING: Reading from the front-buffer immediately after drawing may fail, + * for a slower but more reliable version of this function #WM_window_pixels_read_offscreen + * should be preferred. See it's comments for details on why it's needed, see also T98462. */ bool setup_context = wm->windrawable != win; if (setup_context) { @@ -2006,36 +2037,40 @@ void WM_init_native_pixels(bool do_it) void WM_init_tablet_api(void) { - if (g_system) { - switch (U.tablet_api) { - case USER_TABLET_NATIVE: - GHOST_SetTabletAPI(g_system, GHOST_kTabletWinPointer); - break; - case USER_TABLET_WINTAB: - GHOST_SetTabletAPI(g_system, GHOST_kTabletWintab); - break; - case USER_TABLET_AUTOMATIC: - default: - GHOST_SetTabletAPI(g_system, GHOST_kTabletAutomatic); - break; - } + if (UNLIKELY(!g_system)) { + return; + } + + switch (U.tablet_api) { + case USER_TABLET_NATIVE: + GHOST_SetTabletAPI(g_system, GHOST_kTabletWinPointer); + break; + case USER_TABLET_WINTAB: + GHOST_SetTabletAPI(g_system, GHOST_kTabletWintab); + break; + case USER_TABLET_AUTOMATIC: + default: + GHOST_SetTabletAPI(g_system, GHOST_kTabletAutomatic); + break; } } void WM_cursor_warp(wmWindow *win, int x, int y) { - if (win && win->ghostwin) { - int oldx = x, oldy = y; + if (!(win && win->ghostwin)) { + return; + } - wm_cursor_position_to_ghost_client_coords(win, &x, &y); - GHOST_SetCursorPosition(g_system, win->ghostwin, x, y); + int oldx = x, oldy = y; - win->eventstate->prev_xy[0] = oldx; - win->eventstate->prev_xy[1] = oldy; + wm_cursor_position_to_ghost_client_coords(win, &x, &y); + GHOST_SetCursorPosition(g_system, win->ghostwin, x, y); - win->eventstate->xy[0] = oldx; - win->eventstate->xy[1] = oldy; - } + win->eventstate->prev_xy[0] = oldx; + win->eventstate->prev_xy[1] = oldy; + + win->eventstate->xy[0] = oldx; + win->eventstate->xy[1] = oldy; } /** \} */ diff --git a/source/blender/windowmanager/message_bus/wm_message_bus.h b/source/blender/windowmanager/message_bus/wm_message_bus.h index 1bc983f20ad..1558fe4004e 100644 --- a/source/blender/windowmanager/message_bus/wm_message_bus.h +++ b/source/blender/windowmanager/message_bus/wm_message_bus.h @@ -66,7 +66,7 @@ typedef struct wmMsg { } wmMsg; typedef struct wmMsgSubscribeKey { - /** Linked list for predicable ordering, otherwise we would depend on #GHash bucketing. */ + /** Linked list for predictable ordering, otherwise we would depend on #GHash bucketing. */ struct wmMsgSubscribeKey *next, *prev; ListBase values; /* over-alloc, eg: wmMsgSubscribeKey_RNA */ diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h index 3644aa085f7..036a34a5140 100644 --- a/source/blender/windowmanager/wm_window.h +++ b/source/blender/windowmanager/wm_window.h @@ -20,6 +20,7 @@ extern "C" { * need to event handling. */ void wm_ghost_init(bContext *C); +void wm_ghost_init_background(void); void wm_ghost_exit(void); /** |