winex11: Create contexts at initialization time to avoid the need for locks.

This commit is contained in:
Alexandre Julliard 2012-08-15 15:51:06 +02:00
parent b2a7111a3d
commit c970621d90
4 changed files with 14 additions and 12 deletions

View File

@ -121,10 +121,11 @@ static const UINT button_up_data[NB_BUTTONS] =
XBUTTON2 XBUTTON2
}; };
XContext cursor_context = 0;
static HWND cursor_window; static HWND cursor_window;
static HCURSOR last_cursor; static HCURSOR last_cursor;
static DWORD last_cursor_change; static DWORD last_cursor_change;
static XContext cursor_context;
static RECT clip_rect; static RECT clip_rect;
static Cursor create_cursor( HANDLE handle ); static Cursor create_cursor( HANDLE handle );
@ -200,16 +201,13 @@ void set_window_cursor( Window window, HCURSOR handle )
{ {
Cursor cursor, prev; Cursor cursor, prev;
wine_tsx11_lock();
if (!handle) cursor = get_empty_cursor(); if (!handle) cursor = get_empty_cursor();
else if (!cursor_context || XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&cursor )) else if (XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&cursor ))
{ {
/* try to create it */ /* try to create it */
wine_tsx11_unlock();
if (!(cursor = create_cursor( handle ))) return; if (!(cursor = create_cursor( handle ))) return;
wine_tsx11_lock(); wine_tsx11_lock();
if (!cursor_context) cursor_context = XUniqueContext();
if (!XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&prev )) if (!XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&prev ))
{ {
/* someone else was here first */ /* someone else was here first */
@ -221,12 +219,12 @@ void set_window_cursor( Window window, HCURSOR handle )
XSaveContext( gdi_display, (XID)handle, cursor_context, (char *)cursor ); XSaveContext( gdi_display, (XID)handle, cursor_context, (char *)cursor );
TRACE( "cursor %p created %lx\n", handle, cursor ); TRACE( "cursor %p created %lx\n", handle, cursor );
} }
wine_tsx11_unlock();
} }
XDefineCursor( gdi_display, window, cursor ); XDefineCursor( gdi_display, window, cursor );
/* make the change take effect immediately */ /* make the change take effect immediately */
XFlush( gdi_display ); XFlush( gdi_display );
wine_tsx11_unlock();
} }
/*********************************************************************** /***********************************************************************
@ -1205,7 +1203,7 @@ void CDECL X11DRV_DestroyCursorIcon( HCURSOR handle )
Cursor cursor; Cursor cursor;
wine_tsx11_lock(); wine_tsx11_lock();
if (cursor_context && !XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&cursor )) if (!XFindContext( gdi_display, (XID)handle, cursor_context, (char **)&cursor ))
{ {
TRACE( "%p xid %lx\n", handle, cursor ); TRACE( "%p xid %lx\n", handle, cursor );
XFreeCursor( gdi_display, cursor ); XFreeCursor( gdi_display, cursor );

View File

@ -75,7 +75,7 @@ int clipping_cursor = 0;
XContext winContext = 0; XContext winContext = 0;
/* X context to associate a struct x11drv_win_data to an hwnd */ /* X context to associate a struct x11drv_win_data to an hwnd */
static XContext win_data_context; XContext win_data_context = 0;
/* time of last user event and window where it's stored */ /* time of last user event and window where it's stored */
static Time last_user_time; static Time last_user_time;
@ -1914,11 +1914,7 @@ static struct x11drv_win_data *alloc_win_data( Display *display, HWND hwnd )
if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data)))) if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
{ {
data->hwnd = hwnd; data->hwnd = hwnd;
wine_tsx11_lock();
if (!winContext) winContext = XUniqueContext();
if (!win_data_context) win_data_context = XUniqueContext();
XSaveContext( display, (XID)hwnd, win_data_context, (char *)data ); XSaveContext( display, (XID)hwnd, win_data_context, (char *)data );
wine_tsx11_unlock();
} }
return data; return data;
} }

View File

@ -615,6 +615,10 @@ static inline BOOL is_window_rect_fullscreen( const RECT *rect )
/* X context to associate a hwnd to an X window */ /* X context to associate a hwnd to an X window */
extern XContext winContext DECLSPEC_HIDDEN; extern XContext winContext DECLSPEC_HIDDEN;
/* X context to associate a struct x11drv_win_data to an hwnd */
extern XContext win_data_context DECLSPEC_HIDDEN;
/* X context to associate an X cursor to a Win32 cursor handle */
extern XContext cursor_context DECLSPEC_HIDDEN;
extern void X11DRV_InitClipboard(void) DECLSPEC_HIDDEN; extern void X11DRV_InitClipboard(void) DECLSPEC_HIDDEN;
extern int CDECL X11DRV_AcquireClipboard(HWND hWndClipWindow) DECLSPEC_HIDDEN; extern int CDECL X11DRV_AcquireClipboard(HWND hWndClipWindow) DECLSPEC_HIDDEN;

View File

@ -570,6 +570,10 @@ static BOOL process_attach(void)
XInternAtoms( display, (char **)atom_names, NB_XATOMS - FIRST_XATOM, False, X11DRV_Atoms ); XInternAtoms( display, (char **)atom_names, NB_XATOMS - FIRST_XATOM, False, X11DRV_Atoms );
winContext = XUniqueContext();
win_data_context = XUniqueContext();
cursor_context = XUniqueContext();
if (TRACE_ON(synchronous)) XSynchronize( display, True ); if (TRACE_ON(synchronous)) XSynchronize( display, True );
xinerama_init( WidthOfScreen(screen), HeightOfScreen(screen) ); xinerama_init( WidthOfScreen(screen), HeightOfScreen(screen) );