From 962f764d58847614d083dc382285d997652d6992 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 9 Jun 2015 01:25:34 +1000 Subject: WM: refactor window code for stereo3d Window copy code made it hard to test fixes. --- source/blender/windowmanager/intern/wm_stereo.c | 34 ++++++------ source/blender/windowmanager/intern/wm_window.c | 69 +++++++++++++++---------- source/blender/windowmanager/wm_window.h | 4 +- 3 files changed, 62 insertions(+), 45 deletions(-) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_stereo.c b/source/blender/windowmanager/intern/wm_stereo.c index 60863515dd1..3f80570dd7b 100644 --- a/source/blender/windowmanager/intern/wm_stereo.c +++ b/source/blender/windowmanager/intern/wm_stereo.c @@ -448,9 +448,10 @@ static void wm_stereo3d_set_init(bContext *C, wmOperator *op) int wm_stereo3d_set_exec(bContext *C, wmOperator *op) { wmWindowManager *wm = CTX_wm_manager(C); - wmWindow *win = CTX_wm_window(C); - const bool is_fullscreen = WM_window_is_fullscreen(win); - char prev_display_mode = win->stereo3d_format->display_mode; + wmWindow *win_src = CTX_wm_window(C); + wmWindow *win_dst = NULL; + const bool is_fullscreen = WM_window_is_fullscreen(win_src); + char prev_display_mode = win_src->stereo3d_format->display_mode; Stereo3dData *s3dd; bool ok = true; @@ -464,14 +465,14 @@ int wm_stereo3d_set_exec(bContext *C, wmOperator *op) } s3dd = op->customdata; - *win->stereo3d_format = s3dd->stereo3d_format; + *win_src->stereo3d_format = s3dd->stereo3d_format; if (prev_display_mode == S3D_DISPLAY_PAGEFLIP && - prev_display_mode != win->stereo3d_format->display_mode) + prev_display_mode != win_src->stereo3d_format->display_mode) { /* in case the hardward supports pageflip but not the display */ - if (wm_window_duplicate_exec(C, op) == OPERATOR_FINISHED) { - wm_window_close(C, wm, win); + if ((win_dst = wm_window_copy_test(C, win_src))) { + /* pass */ } else { BKE_report(op->reports, RPT_ERROR, @@ -479,23 +480,22 @@ int wm_stereo3d_set_exec(bContext *C, wmOperator *op) ok = false; } } - else if (win->stereo3d_format->display_mode == S3D_DISPLAY_PAGEFLIP) { + else if (win_src->stereo3d_format->display_mode == S3D_DISPLAY_PAGEFLIP) { /* pageflip requires a new window to be created with the proper OS flags */ - if (wm_window_duplicate_exec(C, op) == OPERATOR_FINISHED) { + if ((win_dst = wm_window_copy_test(C, win_src))) { if (wm_stereo3d_quadbuffer_supported()) { - wm_window_close(C, wm, win); BKE_report(op->reports, RPT_INFO, "Quad-buffer window successfully created"); } else { - wmWindow *win_new = wm->windows.last; - wm_window_close(C, wm, win_new); - win->stereo3d_format->display_mode = prev_display_mode; + wm_window_close(C, wm, win_dst); + win_dst = NULL; + win_src->stereo3d_format->display_mode = prev_display_mode; BKE_report(op->reports, RPT_ERROR, "Quad-buffer not supported by the system"); ok = false; } } else { - win->stereo3d_format->display_mode = prev_display_mode; + win_src->stereo3d_format->display_mode = prev_display_mode; BKE_report(op->reports, RPT_ERROR, "Failed to create a window compatible with the time sequential display method"); ok = false; @@ -511,12 +511,16 @@ int wm_stereo3d_set_exec(bContext *C, wmOperator *op) MEM_freeN(op->customdata); if (ok) { + if (win_dst) { + wm_window_close(C, wm, win_src); + } + WM_event_add_notifier(C, NC_WINDOW, NULL); return OPERATOR_FINISHED; } else { /* without this, the popup won't be freed freed properly T44688 */ - CTX_wm_window_set(C, win); + CTX_wm_window_set(C, win_src); return OPERATOR_CANCELLED; } } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index d0db55d64db..d11d88db147 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -244,30 +244,53 @@ wmWindow *wm_window_new(bContext *C) /* part of wm_window.c api */ -wmWindow *wm_window_copy(bContext *C, wmWindow *winorig) +wmWindow *wm_window_copy(bContext *C, wmWindow *win_src) { - wmWindow *win = wm_window_new(C); + wmWindow *win_dst = wm_window_new(C); - win->posx = winorig->posx + 10; - win->posy = winorig->posy; - win->sizex = winorig->sizex; - win->sizey = winorig->sizey; + win_dst->posx = win_src->posx + 10; + win_dst->posy = win_src->posy; + win_dst->sizex = win_src->sizex; + win_dst->sizey = win_src->sizey; /* duplicate assigns to window */ - win->screen = ED_screen_duplicate(win, winorig->screen); - BLI_strncpy(win->screenname, win->screen->id.name + 2, sizeof(win->screenname)); - win->screen->winid = win->winid; + win_dst->screen = ED_screen_duplicate(win_dst, win_src->screen); + BLI_strncpy(win_dst->screenname, win_dst->screen->id.name + 2, sizeof(win_dst->screenname)); + win_dst->screen->winid = win_dst->winid; - win->screen->do_refresh = true; - win->screen->do_draw = true; + win_dst->screen->do_refresh = true; + win_dst->screen->do_draw = true; - win->drawmethod = U.wmdrawmethod; + win_dst->drawmethod = U.wmdrawmethod; - BLI_listbase_clear(&win->drawdata); + BLI_listbase_clear(&win_dst->drawdata); - *win->stereo3d_format = *winorig->stereo3d_format; + *win_dst->stereo3d_format = *win_src->stereo3d_format; - return win; + return win_dst; +} + +/** + * A higher level version of copy that tests the new window can be added. + * (called from the operator directly) + */ +wmWindow *wm_window_copy_test(bContext *C, wmWindow *win_src) +{ + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win_dst; + + win_dst = wm_window_copy(C, win_src); + + WM_check(C); + + if (win_dst->ghostwin) { + WM_event_add_notifier(C, NC_WINDOW | NA_ADDED, NULL); + return win_dst; + } + else { + wm_window_close(C, wm, win_dst); + return NULL; + } } /* this is event from ghost, or exit-blender op */ @@ -615,22 +638,12 @@ void WM_window_open_temp(bContext *C, rcti *position, int type) /* operator callback */ int wm_window_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) { - wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win_src = CTX_wm_window(C); - wmWindow *win_dst; + bool ok; - win_dst = wm_window_copy(C, win_src); + ok = (wm_window_copy_test(C, win_src) != NULL); - WM_check(C); - - if (win_dst->ghostwin) { - WM_event_add_notifier(C, NC_WINDOW | NA_ADDED, NULL); - return OPERATOR_FINISHED; - } - else { - wm_window_close(C, wm, win_dst); - return OPERATOR_CANCELLED; - } + return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h index 95dc8762ae7..a104f6aba39 100644 --- a/source/blender/windowmanager/wm_window.h +++ b/source/blender/windowmanager/wm_window.h @@ -42,6 +42,8 @@ void wm_get_screensize(int *r_width, int *r_height); void wm_get_desktopsize(int *r_width, int *r_height); wmWindow *wm_window_new (bContext *C); +wmWindow *wm_window_copy (bContext *C, wmWindow *win_src); +wmWindow *wm_window_copy_test (bContext *C, wmWindow *win_src); void wm_window_free (bContext *C, wmWindowManager *wm, wmWindow *win); void wm_window_close (bContext *C, wmWindowManager *wm, wmWindow *win); @@ -64,8 +66,6 @@ float wm_window_pixelsize(wmWindow *win); void wm_get_cursor_position (wmWindow *win, int *x, int *y); -wmWindow *wm_window_copy (bContext *C, wmWindow *winorig); - void wm_window_testbreak (void); #ifdef WITH_INPUT_IME -- cgit v1.2.3