Changeset View
Standalone View
source/blender/windowmanager/intern/wm_window.c
| Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
| /* for assert */ | /* for assert */ | ||||
| #ifndef NDEBUG | #ifndef NDEBUG | ||||
| # include "BLI_threads.h" | # include "BLI_threads.h" | ||||
| #endif | #endif | ||||
| /* the global to talk to ghost */ | /* the global to talk to ghost */ | ||||
| static GHOST_SystemHandle g_system = NULL; | static GHOST_SystemHandle g_system = NULL; | ||||
| typedef enum WinOverrideFlag { | typedef enum WinOverrideFlag { | ||||
brecht: Any reason we can't use `wm->winactive` here?
If it's to avoid passing context, you can use… | |||||
Not Done Inline ActionsI used it because winactive was not set. But in fact I should have used windrawable. Is it ok to use wm.first? can there be multiple window manager? can there be none? fclem: I used it because winactive was not set. But in fact I should have used windrawable. Is it ok… | |||||
Not Done Inline ActionsIt's safe to use wm.first, there is always exactly one window manager, and the same code is used in other places. brecht: It's safe to use wm.first, there is always exactly one window manager, and the same code is… | |||||
| WIN_OVERRIDE_GEOM = (1 << 0), | WIN_OVERRIDE_GEOM = (1 << 0), | ||||
| WIN_OVERRIDE_WINSTATE = (1 << 1) | WIN_OVERRIDE_WINSTATE = (1 << 1) | ||||
| } WinOverrideFlag; | } WinOverrideFlag; | ||||
| /* set by commandline */ | /* set by commandline */ | ||||
| static struct WMInitStruct { | static struct WMInitStruct { | ||||
| /* window geometry */ | /* window geometry */ | ||||
| int size_x, size_y; | int size_x, size_y; | ||||
| ▲ Show 20 Lines • Show All 375 Lines • ▼ Show 20 Lines | |||||
| #ifdef __APPLE__ | #ifdef __APPLE__ | ||||
| /* we agreed to not set any fullscreen or iconized state on startup */ | /* we agreed to not set any fullscreen or iconized state on startup */ | ||||
| GHOST_kWindowStateNormal, | GHOST_kWindowStateNormal, | ||||
| #else | #else | ||||
| (GHOST_TWindowState)win->windowstate, | (GHOST_TWindowState)win->windowstate, | ||||
| #endif | #endif | ||||
| GHOST_kDrawingContextTypeOpenGL, | GHOST_kDrawingContextTypeOpenGL, | ||||
| glSettings); | glSettings); | ||||
| if (ghostwin) { | if (ghostwin) { | ||||
| GHOST_RectangleHandle bounds; | GHOST_RectangleHandle bounds; | ||||
| win->gwnctx = GWN_context_create(); | win->gwnctx = GWN_context_create(); | ||||
| /* the new window has already been made drawable upon creation */ | /* the new window has already been made drawable upon creation */ | ||||
| wm->windrawable = win; | wm->windrawable = win; | ||||
| ▲ Show 20 Lines • Show All 520 Lines • ▼ Show 20 Lines | // win->lmbut = 0; /* keeps hanging when mousepressed while other window opened */ | ||||
| GWN_context_active_set(win->gwnctx); | GWN_context_active_set(win->gwnctx); | ||||
| immActivate(); | immActivate(); | ||||
| /* this can change per window */ | /* this can change per window */ | ||||
| WM_window_set_dpi(win); | WM_window_set_dpi(win); | ||||
| } | } | ||||
| } | } | ||||
| /* Reset active the current window opengl drawing context. */ | |||||
| void wm_window_reset_drawable(void) | |||||
| { | |||||
| wmWindowManager *wm = G.main->wm.first; | |||||
| wmWindow *win = wm->windrawable; | |||||
| if (BLI_thread_is_main() && win && win->ghostwin) { | |||||
| immDeactivate(); | |||||
| GHOST_ActivateWindowDrawingContext(win->ghostwin); | |||||
| GWN_context_active_set(win->gwnctx); | |||||
| immActivate(); | |||||
| } | |||||
| else { | |||||
| GWN_context_active_set(NULL); | |||||
| /* TODO unbind the context (set context to NULL) */ | |||||
| } | |||||
Not Done Inline ActionsIt seems more clear to me if the immediate mode and gawain calls that are here go to the DRW_opengl_context functions, Now it's kind of spread out. Also not sure if this TODO is important to fix still. brecht: It seems more clear to me if the immediate mode and gawain calls that are here go to the… | |||||
Not Done Inline ActionsActually, wm_window_make_drawable does the same stuff so I guess it's ok. Just didn't expect that stuff in the WM. brecht: Actually, `wm_window_make_drawable` does the same stuff so I guess it's ok. Just didn't expect… | |||||
| } | |||||
| /* called by ghost, here we handle events for windows themselves or send to event system */ | /* called by ghost, here we handle events for windows themselves or send to event system */ | ||||
| /* mouse coordinate converversion happens here */ | /* mouse coordinate converversion happens here */ | ||||
| static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr) | static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr) | ||||
| { | { | ||||
| bContext *C = C_void_ptr; | bContext *C = C_void_ptr; | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| GHOST_TEventType type = GHOST_GetEventType(evt); | GHOST_TEventType type = GHOST_GetEventType(evt); | ||||
| int time = GHOST_GetEventTime(evt); | int time = GHOST_GetEventTime(evt); | ||||
| ▲ Show 20 Lines • Show All 990 Lines • ▼ Show 20 Lines | |||||
| void wm_window_IME_end(wmWindow *win) | void wm_window_IME_end(wmWindow *win) | ||||
| { | { | ||||
| BLI_assert(win && win->ime_data); | BLI_assert(win && win->ime_data); | ||||
| GHOST_EndIME(win->ghostwin); | GHOST_EndIME(win->ghostwin); | ||||
| win->ime_data = NULL; | win->ime_data = NULL; | ||||
| } | } | ||||
| #endif /* WITH_INPUT_IME */ | #endif /* WITH_INPUT_IME */ | ||||
| /* ****** direct opengl context management ****** */ | |||||
| void *WM_opengl_context_create(void) | |||||
Not Done Inline ActionsMaybe use WM_opengl_context_create(), it's not so obvious otherwise. brecht: Maybe use `WM_opengl_context_create()`, it's not so obvious otherwise. | |||||
| { | |||||
| return GHOST_CreateOpenGLContext(g_system); | |||||
Not Done Inline ActionsAnd this one could also be GHOST_CreateOpenGLContext, so it's a consistent name throughout. brecht: And this one could also be `GHOST_CreateOpenGLContext`, so it's a consistent name throughout. | |||||
Not Done Inline ActionsI find the naming of GHOST_CreateOpenGLContext pretty redundant for GHOST and the context could be tied to the window (not in the api for now). This is to differentiate them. The offscreen context has no surface attached to it. And maybe we will have a background context creation in the future GHOST_CreateBackgroundContext. Since it's GHOST the context is obviously OGL, right?. fclem: I find the naming of GHOST_CreateOpenGLContext pretty redundant for GHOST and the context could… | |||||
Not Done Inline ActionsI don't mind it being called GHOST_CreateOffscreenContext. I just found it a bit confusing that the same thing was called three slightly different names in three different modules. Maybe it can be "offscreen context" everywhere then. It's just a small nitpick though. brecht: I don't mind it being called `GHOST_CreateOffscreenContext`. I just found it a bit confusing… | |||||
| } | |||||
| void WM_opengl_context_dispose(void *context) | |||||
| { | |||||
| GHOST_DisposeOpenGLContext(g_system, (GHOST_ContextHandle)context); | |||||
| } | |||||
| void WM_opengl_context_activate(void *context) | |||||
| { | |||||
| GHOST_ActivateOpenGLContext((GHOST_ContextHandle)context); | |||||
| } | |||||
Any reason we can't use wm->winactive here?
If it's to avoid passing context, you can use wmWindowManager *wm = G.main->wm.first;. If it has a different meaning, that seems confusing and the name/comment should be more clear on what the difference is.