windowscodecs: Directly use patterns stored in component info object in IWICBitmapDec...
[wine.git] / dlls / wineandroid.drv / window.c
blobaff687b2c806e7b2c2161ed7bbba4c99190812ed
1 /*
2 * Window related functions
4 * Copyright 1993, 1994, 1995, 1996, 2001, 2013-2017 Alexandre Julliard
5 * Copyright 1993 David Metcalfe
6 * Copyright 1995, 1996 Alex Korobka
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
26 #include "config.h"
27 #include "wine/port.h"
29 #include <assert.h>
30 #include <fcntl.h>
31 #include <poll.h>
32 #include <errno.h>
33 #include <stdarg.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #ifdef HAVE_UNISTD_H
37 # include <unistd.h>
38 #endif
40 #include "windef.h"
41 #include "winbase.h"
42 #include "wingdi.h"
43 #include "winuser.h"
44 #include "wine/unicode.h"
46 #include "android.h"
47 #include "wine/server.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(android);
52 /* private window data */
53 struct android_win_data
55 HWND hwnd; /* hwnd that this private data belongs to */
56 HWND parent; /* parent hwnd for child windows */
57 RECT window_rect; /* USER window rectangle relative to parent */
58 RECT whole_rect; /* X window rectangle for the whole window relative to parent */
59 RECT client_rect; /* client area relative to parent */
60 ANativeWindow *window; /* native window wrapper that forwards calls to the desktop process */
61 struct window_surface *surface;
64 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
66 static CRITICAL_SECTION win_data_section;
67 static CRITICAL_SECTION_DEBUG critsect_debug =
69 0, 0, &win_data_section,
70 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
71 0, 0, { (DWORD_PTR)(__FILE__ ": win_data_section") }
73 static CRITICAL_SECTION win_data_section = { &critsect_debug, -1, 0, 0, 0, 0 };
75 static struct android_win_data *win_data_context[32768];
77 static inline int context_idx( HWND hwnd )
79 return LOWORD( hwnd ) >> 1;
82 static void set_surface_region( struct window_surface *window_surface, HRGN win_region );
84 /* only for use on sanitized BITMAPINFO structures */
85 static inline int get_dib_info_size( const BITMAPINFO *info, UINT coloruse )
87 if (info->bmiHeader.biCompression == BI_BITFIELDS)
88 return sizeof(BITMAPINFOHEADER) + 3 * sizeof(DWORD);
89 if (coloruse == DIB_PAL_COLORS)
90 return sizeof(BITMAPINFOHEADER) + info->bmiHeader.biClrUsed * sizeof(WORD);
91 return FIELD_OFFSET( BITMAPINFO, bmiColors[info->bmiHeader.biClrUsed] );
94 static inline int get_dib_stride( int width, int bpp )
96 return ((width * bpp + 31) >> 3) & ~3;
99 static inline int get_dib_image_size( const BITMAPINFO *info )
101 return get_dib_stride( info->bmiHeader.biWidth, info->bmiHeader.biBitCount )
102 * abs( info->bmiHeader.biHeight );
106 /***********************************************************************
107 * alloc_win_data
109 static struct android_win_data *alloc_win_data( HWND hwnd )
111 struct android_win_data *data;
113 if ((data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data))))
115 data->hwnd = hwnd;
116 data->window = create_ioctl_window( hwnd, FALSE );
117 EnterCriticalSection( &win_data_section );
118 win_data_context[context_idx(hwnd)] = data;
120 return data;
124 /***********************************************************************
125 * free_win_data
127 static void free_win_data( struct android_win_data *data )
129 win_data_context[context_idx( data->hwnd )] = NULL;
130 LeaveCriticalSection( &win_data_section );
131 if (data->window) release_ioctl_window( data->window );
132 HeapFree( GetProcessHeap(), 0, data );
136 /***********************************************************************
137 * get_win_data
139 * Lock and return the data structure associated with a window.
141 static struct android_win_data *get_win_data( HWND hwnd )
143 struct android_win_data *data;
145 if (!hwnd) return NULL;
146 EnterCriticalSection( &win_data_section );
147 if ((data = win_data_context[context_idx(hwnd)]) && data->hwnd == hwnd) return data;
148 LeaveCriticalSection( &win_data_section );
149 return NULL;
153 /***********************************************************************
154 * release_win_data
156 * Release the data returned by get_win_data.
158 static void release_win_data( struct android_win_data *data )
160 if (data) LeaveCriticalSection( &win_data_section );
164 /***********************************************************************
165 * get_ioctl_window
167 static struct ANativeWindow *get_ioctl_window( HWND hwnd )
169 struct ANativeWindow *ret;
170 struct android_win_data *data = get_win_data( hwnd );
172 if (!data || !data->window) return NULL;
173 ret = grab_ioctl_window( data->window );
174 release_win_data( data );
175 return ret;
179 /* Handling of events coming from the Java side */
181 struct java_event
183 struct list entry;
184 union event_data data;
187 static struct list event_queue = LIST_INIT( event_queue );
188 static struct java_event *current_event;
189 static int event_pipe[2];
190 static DWORD desktop_tid;
192 /***********************************************************************
193 * send_event
195 int send_event( const union event_data *data )
197 int res;
199 if ((res = write( event_pipe[1], data, sizeof(*data) )) != sizeof(*data))
201 p__android_log_print( ANDROID_LOG_ERROR, "wine", "failed to send event" );
202 return -1;
204 return 0;
208 /***********************************************************************
209 * desktop_changed
211 * JNI callback, runs in the context of the Java thread.
213 void desktop_changed( JNIEnv *env, jobject obj, jint width, jint height )
215 union event_data data;
217 memset( &data, 0, sizeof(data) );
218 data.type = DESKTOP_CHANGED;
219 data.desktop.width = width;
220 data.desktop.height = height;
221 p__android_log_print( ANDROID_LOG_INFO, "wine", "desktop_changed: %ux%u", width, height );
222 send_event( &data );
226 /***********************************************************************
227 * config_changed
229 * JNI callback, runs in the context of the Java thread.
231 void config_changed( JNIEnv *env, jobject obj, jint dpi )
233 union event_data data;
235 memset( &data, 0, sizeof(data) );
236 data.type = CONFIG_CHANGED;
237 data.cfg.dpi = dpi;
238 p__android_log_print( ANDROID_LOG_INFO, "wine", "config_changed: %u dpi", dpi );
239 send_event( &data );
243 /***********************************************************************
244 * surface_changed
246 * JNI callback, runs in the context of the Java thread.
248 void surface_changed( JNIEnv *env, jobject obj, jint win, jobject surface, jboolean client )
250 union event_data data;
252 memset( &data, 0, sizeof(data) );
253 data.surface.hwnd = LongToHandle( win );
254 data.surface.client = client;
255 if (surface)
257 int width, height;
258 ANativeWindow *win = pANativeWindow_fromSurface( env, surface );
260 if (win->query( win, NATIVE_WINDOW_WIDTH, &width ) < 0) width = 0;
261 if (win->query( win, NATIVE_WINDOW_HEIGHT, &height ) < 0) height = 0;
262 data.surface.window = win;
263 data.surface.width = width;
264 data.surface.height = height;
265 p__android_log_print( ANDROID_LOG_INFO, "wine", "surface_changed: %p %s %ux%u",
266 data.surface.hwnd, client ? "client" : "whole", width, height );
268 data.type = SURFACE_CHANGED;
269 send_event( &data );
273 /***********************************************************************
274 * motion_event
276 * JNI callback, runs in the context of the Java thread.
278 jboolean motion_event( JNIEnv *env, jobject obj, jint win, jint action, jint x, jint y, jint state, jint vscroll )
280 static LONG button_state;
281 union event_data data;
282 int prev_state;
284 int mask = action & AMOTION_EVENT_ACTION_MASK;
286 if (!( mask == AMOTION_EVENT_ACTION_DOWN ||
287 mask == AMOTION_EVENT_ACTION_UP ||
288 mask == AMOTION_EVENT_ACTION_CANCEL ||
289 mask == AMOTION_EVENT_ACTION_SCROLL ||
290 mask == AMOTION_EVENT_ACTION_MOVE ||
291 mask == AMOTION_EVENT_ACTION_HOVER_MOVE ||
292 mask == AMOTION_EVENT_ACTION_BUTTON_PRESS ||
293 mask == AMOTION_EVENT_ACTION_BUTTON_RELEASE ))
294 return JNI_FALSE;
296 /* make sure a subsequent AMOTION_EVENT_ACTION_UP is not treated as a touch event */
297 if (mask == AMOTION_EVENT_ACTION_BUTTON_RELEASE) state |= 0x80000000;
299 prev_state = InterlockedExchange( &button_state, state );
301 data.type = MOTION_EVENT;
302 data.motion.hwnd = LongToHandle( win );
303 data.motion.input.type = INPUT_MOUSE;
304 data.motion.input.u.mi.dx = x;
305 data.motion.input.u.mi.dy = y;
306 data.motion.input.u.mi.mouseData = 0;
307 data.motion.input.u.mi.time = 0;
308 data.motion.input.u.mi.dwExtraInfo = 0;
309 data.motion.input.u.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
310 switch (action & AMOTION_EVENT_ACTION_MASK)
312 case AMOTION_EVENT_ACTION_DOWN:
313 case AMOTION_EVENT_ACTION_BUTTON_PRESS:
314 if ((state & ~prev_state) & AMOTION_EVENT_BUTTON_PRIMARY)
315 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
316 if ((state & ~prev_state) & AMOTION_EVENT_BUTTON_SECONDARY)
317 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_RIGHTDOWN;
318 if ((state & ~prev_state) & AMOTION_EVENT_BUTTON_TERTIARY)
319 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_MIDDLEDOWN;
320 if (!(state & ~prev_state)) /* touch event */
321 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
322 break;
323 case AMOTION_EVENT_ACTION_UP:
324 case AMOTION_EVENT_ACTION_CANCEL:
325 case AMOTION_EVENT_ACTION_BUTTON_RELEASE:
326 if ((prev_state & ~state) & AMOTION_EVENT_BUTTON_PRIMARY)
327 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
328 if ((prev_state & ~state) & AMOTION_EVENT_BUTTON_SECONDARY)
329 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_RIGHTUP;
330 if ((prev_state & ~state) & AMOTION_EVENT_BUTTON_TERTIARY)
331 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_MIDDLEUP;
332 if (!(prev_state & ~state)) /* touch event */
333 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
334 break;
335 case AMOTION_EVENT_ACTION_SCROLL:
336 data.motion.input.u.mi.dwFlags |= MOUSEEVENTF_WHEEL;
337 data.motion.input.u.mi.mouseData = vscroll < 0 ? -WHEEL_DELTA : WHEEL_DELTA;
338 break;
339 case AMOTION_EVENT_ACTION_MOVE:
340 case AMOTION_EVENT_ACTION_HOVER_MOVE:
341 break;
342 default:
343 return JNI_FALSE;
345 send_event( &data );
346 return JNI_TRUE;
350 /***********************************************************************
351 * init_event_queue
353 static void init_event_queue(void)
355 HANDLE handle;
356 int ret;
358 if (pipe2( event_pipe, O_CLOEXEC | O_NONBLOCK ) == -1)
360 ERR( "could not create data\n" );
361 ExitProcess(1);
363 if (wine_server_fd_to_handle( event_pipe[0], GENERIC_READ | SYNCHRONIZE, 0, &handle ))
365 ERR( "Can't allocate handle for event fd\n" );
366 ExitProcess(1);
368 SERVER_START_REQ( set_queue_fd )
370 req->handle = wine_server_obj_handle( handle );
371 ret = wine_server_call( req );
373 SERVER_END_REQ;
374 if (ret)
376 ERR( "Can't store handle for event fd %x\n", ret );
377 ExitProcess(1);
379 CloseHandle( handle );
380 desktop_tid = GetCurrentThreadId();
384 /***********************************************************************
385 * pull_events
387 * Pull events from the event pipe and add them to the queue
389 static void pull_events(void)
391 struct java_event *event;
392 int res;
394 for (;;)
396 if (!(event = HeapAlloc( GetProcessHeap(), 0, sizeof(*event) ))) break;
398 res = read( event_pipe[0], &event->data, sizeof(event->data) );
399 if (res != sizeof(event->data)) break;
400 list_add_tail( &event_queue, &event->entry );
402 HeapFree( GetProcessHeap(), 0, event );
406 /***********************************************************************
407 * process_events
409 static int process_events( DWORD mask )
411 struct java_event *event, *next, *previous;
412 unsigned int count = 0;
414 assert( GetCurrentThreadId() == desktop_tid );
416 pull_events();
418 previous = current_event;
420 LIST_FOR_EACH_ENTRY_SAFE( event, next, &event_queue, struct java_event, entry )
422 switch (event->data.type)
424 case SURFACE_CHANGED:
425 break; /* always process it to unblock other threads */
426 case MOTION_EVENT:
427 if (event->data.motion.input.u.mi.dwFlags & (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_RIGHTDOWN|
428 MOUSEEVENTF_MIDDLEDOWN|MOUSEEVENTF_LEFTUP|
429 MOUSEEVENTF_RIGHTUP|MOUSEEVENTF_MIDDLEUP))
431 if (mask & QS_MOUSEBUTTON) break;
433 else if (mask & QS_MOUSEMOVE) break;
434 continue; /* skip it */
435 case KEYBOARD_EVENT:
436 if (mask & QS_KEY) break;
437 continue; /* skip it */
438 default:
439 if (mask & QS_SENDMESSAGE) break;
440 continue; /* skip it */
443 /* remove it first, in case we process events recursively */
444 list_remove( &event->entry );
445 current_event = event;
447 switch (event->data.type)
449 case DESKTOP_CHANGED:
450 TRACE( "DESKTOP_CHANGED %ux%u\n", event->data.desktop.width, event->data.desktop.height );
451 screen_width = event->data.desktop.width;
452 screen_height = event->data.desktop.height;
453 init_monitors( screen_width, screen_height );
454 SetWindowPos( GetDesktopWindow(), 0, 0, 0, screen_width, screen_height,
455 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW );
456 break;
458 case CONFIG_CHANGED:
459 TRACE( "CONFIG_CHANGED dpi %u\n", event->data.cfg.dpi );
460 set_screen_dpi( event->data.cfg.dpi );
461 break;
463 case SURFACE_CHANGED:
464 TRACE("SURFACE_CHANGED %p %p %s size %ux%u\n", event->data.surface.hwnd,
465 event->data.surface.window, event->data.surface.client ? "client" : "whole",
466 event->data.surface.width, event->data.surface.height );
468 register_native_window( event->data.surface.hwnd, event->data.surface.window, event->data.surface.client );
469 break;
471 case MOTION_EVENT:
473 HWND capture = get_capture_window();
475 if (event->data.motion.input.u.mi.dwFlags & (MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_MIDDLEDOWN))
476 TRACE( "BUTTONDOWN pos %d,%d hwnd %p flags %x\n",
477 event->data.motion.input.u.mi.dx, event->data.motion.input.u.mi.dy,
478 event->data.motion.hwnd, event->data.motion.input.u.mi.dwFlags );
479 else if (event->data.motion.input.u.mi.dwFlags & (MOUSEEVENTF_LEFTUP|MOUSEEVENTF_RIGHTUP|MOUSEEVENTF_MIDDLEUP))
480 TRACE( "BUTTONUP pos %d,%d hwnd %p flags %x\n",
481 event->data.motion.input.u.mi.dx, event->data.motion.input.u.mi.dy,
482 event->data.motion.hwnd, event->data.motion.input.u.mi.dwFlags );
483 else
484 TRACE( "MOUSEMOVE pos %d,%d hwnd %p flags %x\n",
485 event->data.motion.input.u.mi.dx, event->data.motion.input.u.mi.dy,
486 event->data.motion.hwnd, event->data.motion.input.u.mi.dwFlags );
487 if (!capture && (event->data.motion.input.u.mi.dwFlags & MOUSEEVENTF_ABSOLUTE))
489 RECT rect;
490 SetRect( &rect, event->data.motion.input.u.mi.dx, event->data.motion.input.u.mi.dy,
491 event->data.motion.input.u.mi.dx + 1, event->data.motion.input.u.mi.dy + 1 );
492 MapWindowPoints( 0, event->data.motion.hwnd, (POINT *)&rect, 2 );
494 SERVER_START_REQ( update_window_zorder )
496 req->window = wine_server_user_handle( event->data.motion.hwnd );
497 req->rect.left = rect.left;
498 req->rect.top = rect.top;
499 req->rect.right = rect.right;
500 req->rect.bottom = rect.bottom;
501 wine_server_call( req );
503 SERVER_END_REQ;
505 __wine_send_input( capture ? capture : event->data.motion.hwnd, &event->data.motion.input );
507 break;
509 case KEYBOARD_EVENT:
510 if (event->data.kbd.input.u.ki.dwFlags & KEYEVENTF_KEYUP)
511 TRACE("KEYUP hwnd %p vkey %x '%c' scancode %x\n", event->data.kbd.hwnd,
512 event->data.kbd.input.u.ki.wVk, event->data.kbd.input.u.ki.wVk,
513 event->data.kbd.input.u.ki.wScan );
514 else
515 TRACE("KEYDOWN hwnd %p vkey %x '%c' scancode %x\n", event->data.kbd.hwnd,
516 event->data.kbd.input.u.ki.wVk, event->data.kbd.input.u.ki.wVk,
517 event->data.kbd.input.u.ki.wScan );
518 update_keyboard_lock_state( event->data.kbd.input.u.ki.wVk, event->data.kbd.lock_state );
519 __wine_send_input( 0, &event->data.kbd.input );
520 break;
522 default:
523 FIXME( "got event %u\n", event->data.type );
525 HeapFree( GetProcessHeap(), 0, event );
526 count++;
527 /* next may have been removed by a recursive call, so reset it to the beginning of the list */
528 next = LIST_ENTRY( event_queue.next, struct java_event, entry );
530 current_event = previous;
531 return count;
535 /***********************************************************************
536 * wait_events
538 static int wait_events( int timeout )
540 assert( GetCurrentThreadId() == desktop_tid );
542 for (;;)
544 struct pollfd pollfd;
545 int ret;
547 pollfd.fd = event_pipe[0];
548 pollfd.events = POLLIN | POLLHUP;
549 ret = poll( &pollfd, 1, timeout );
550 if (ret == -1 && errno == EINTR) continue;
551 if (ret && (pollfd.revents & (POLLHUP | POLLERR))) ret = -1;
552 return ret;
557 /* Window surface support */
559 struct android_window_surface
561 struct window_surface header;
562 HWND hwnd;
563 ANativeWindow *window;
564 RECT bounds;
565 BOOL byteswap;
566 RGNDATA *region_data;
567 HRGN region;
568 BYTE alpha;
569 COLORREF color_key;
570 void *bits;
571 CRITICAL_SECTION crit;
572 BITMAPINFO info; /* variable size, must be last */
575 static struct android_window_surface *get_android_surface( struct window_surface *surface )
577 return (struct android_window_surface *)surface;
580 static inline void reset_bounds( RECT *bounds )
582 bounds->left = bounds->top = INT_MAX;
583 bounds->right = bounds->bottom = INT_MIN;
586 static inline void add_bounds_rect( RECT *bounds, const RECT *rect )
588 if (rect->left >= rect->right || rect->top >= rect->bottom) return;
589 bounds->left = min( bounds->left, rect->left );
590 bounds->top = min( bounds->top, rect->top );
591 bounds->right = max( bounds->right, rect->right );
592 bounds->bottom = max( bounds->bottom, rect->bottom );
595 /* store the palette or color mask data in the bitmap info structure */
596 static void set_color_info( BITMAPINFO *info, BOOL has_alpha )
598 DWORD *colors = (DWORD *)info->bmiColors;
600 info->bmiHeader.biSize = sizeof(info->bmiHeader);
601 info->bmiHeader.biClrUsed = 0;
602 info->bmiHeader.biBitCount = 32;
603 if (has_alpha)
605 info->bmiHeader.biCompression = BI_RGB;
606 return;
608 info->bmiHeader.biCompression = BI_BITFIELDS;
609 colors[0] = 0xff0000;
610 colors[1] = 0x00ff00;
611 colors[2] = 0x0000ff;
614 /* apply the window region to a single line of the destination image. */
615 static void apply_line_region( DWORD *dst, int width, int x, int y, const RECT *rect, const RECT *end )
617 while (rect < end && rect->top <= y && width > 0)
619 if (rect->left > x)
621 memset( dst, 0, min( rect->left - x, width ) * sizeof(*dst) );
622 dst += rect->left - x;
623 width -= rect->left - x;
624 x = rect->left;
626 if (rect->right > x)
628 dst += rect->right - x;
629 width -= rect->right - x;
630 x = rect->right;
632 rect++;
634 if (width > 0) memset( dst, 0, width * sizeof(*dst) );
637 /***********************************************************************
638 * android_surface_lock
640 static void android_surface_lock( struct window_surface *window_surface )
642 struct android_window_surface *surface = get_android_surface( window_surface );
644 EnterCriticalSection( &surface->crit );
647 /***********************************************************************
648 * android_surface_unlock
650 static void android_surface_unlock( struct window_surface *window_surface )
652 struct android_window_surface *surface = get_android_surface( window_surface );
654 LeaveCriticalSection( &surface->crit );
657 /***********************************************************************
658 * android_surface_get_bitmap_info
660 static void *android_surface_get_bitmap_info( struct window_surface *window_surface, BITMAPINFO *info )
662 struct android_window_surface *surface = get_android_surface( window_surface );
664 memcpy( info, &surface->info, get_dib_info_size( &surface->info, DIB_RGB_COLORS ));
665 return surface->bits;
668 /***********************************************************************
669 * android_surface_get_bounds
671 static RECT *android_surface_get_bounds( struct window_surface *window_surface )
673 struct android_window_surface *surface = get_android_surface( window_surface );
675 return &surface->bounds;
678 /***********************************************************************
679 * android_surface_set_region
681 static void android_surface_set_region( struct window_surface *window_surface, HRGN region )
683 struct android_window_surface *surface = get_android_surface( window_surface );
685 TRACE( "updating surface %p hwnd %p with %p\n", surface, surface->hwnd, region );
687 window_surface->funcs->lock( window_surface );
688 if (!region)
690 if (surface->region) DeleteObject( surface->region );
691 surface->region = 0;
693 else
695 if (!surface->region) surface->region = CreateRectRgn( 0, 0, 0, 0 );
696 CombineRgn( surface->region, region, 0, RGN_COPY );
698 window_surface->funcs->unlock( window_surface );
699 set_surface_region( &surface->header, (HRGN)1 );
702 /***********************************************************************
703 * android_surface_flush
705 static void android_surface_flush( struct window_surface *window_surface )
707 struct android_window_surface *surface = get_android_surface( window_surface );
708 ANativeWindow_Buffer buffer;
709 ARect rc;
710 RECT rect;
711 BOOL needs_flush;
713 window_surface->funcs->lock( window_surface );
714 SetRect( &rect, 0, 0, surface->header.rect.right - surface->header.rect.left,
715 surface->header.rect.bottom - surface->header.rect.top );
716 needs_flush = IntersectRect( &rect, &rect, &surface->bounds );
717 reset_bounds( &surface->bounds );
718 window_surface->funcs->unlock( window_surface );
719 if (!needs_flush) return;
721 TRACE( "flushing %p hwnd %p surface %s rect %s bits %p alpha %02x key %08x region %u rects\n",
722 surface, surface->hwnd, wine_dbgstr_rect( &surface->header.rect ),
723 wine_dbgstr_rect( &rect ), surface->bits, surface->alpha, surface->color_key,
724 surface->region_data ? surface->region_data->rdh.nCount : 0 );
726 rc.left = rect.left;
727 rc.top = rect.top;
728 rc.right = rect.right;
729 rc.bottom = rect.bottom;
731 if (!surface->window->perform( surface->window, NATIVE_WINDOW_LOCK, &buffer, &rc ))
733 const RECT *rgn_rect = NULL, *end = NULL;
734 unsigned int *src, *dst;
735 int x, y, width;
737 rect.left = rc.left;
738 rect.top = rc.top;
739 rect.right = rc.right;
740 rect.bottom = rc.bottom;
741 IntersectRect( &rect, &rect, &surface->header.rect );
743 if (surface->region_data)
745 rgn_rect = (RECT *)surface->region_data->Buffer;
746 end = rgn_rect + surface->region_data->rdh.nCount;
748 src = (unsigned int *)surface->bits
749 + (rect.top - surface->header.rect.top) * surface->info.bmiHeader.biWidth
750 + (rect.left - surface->header.rect.left);
751 dst = (unsigned int *)buffer.bits + rect.top * buffer.stride + rect.left;
752 width = min( rect.right - rect.left, buffer.stride );
754 for (y = rect.top; y < min( buffer.height, rect.bottom); y++)
756 if (surface->info.bmiHeader.biCompression == BI_RGB)
757 memcpy( dst, src, width * sizeof(*dst) );
758 else if (surface->alpha == 255)
759 for (x = 0; x < width; x++) dst[x] = src[x] | 0xff000000;
760 else
761 for (x = 0; x < width; x++)
762 dst[x] = ((surface->alpha << 24) |
763 (((BYTE)(src[x] >> 16) * surface->alpha / 255) << 16) |
764 (((BYTE)(src[x] >> 8) * surface->alpha / 255) << 8) |
765 (((BYTE)src[x] * surface->alpha / 255)));
767 if (surface->color_key != CLR_INVALID)
768 for (x = 0; x < width; x++) if ((src[x] & 0xffffff) == surface->color_key) dst[x] = 0;
770 if (rgn_rect)
772 while (rgn_rect < end && rgn_rect->bottom <= y) rgn_rect++;
773 apply_line_region( dst, width, rect.left, y, rgn_rect, end );
776 src += surface->info.bmiHeader.biWidth;
777 dst += buffer.stride;
779 surface->window->perform( surface->window, NATIVE_WINDOW_UNLOCK_AND_POST );
781 else TRACE( "Unable to lock surface %p window %p buffer %p\n",
782 surface, surface->hwnd, surface->window );
785 /***********************************************************************
786 * android_surface_destroy
788 static void android_surface_destroy( struct window_surface *window_surface )
790 struct android_window_surface *surface = get_android_surface( window_surface );
792 TRACE( "freeing %p bits %p\n", surface, surface->bits );
794 surface->crit.DebugInfo->Spare[0] = 0;
795 DeleteCriticalSection( &surface->crit );
796 HeapFree( GetProcessHeap(), 0, surface->region_data );
797 if (surface->region) DeleteObject( surface->region );
798 release_ioctl_window( surface->window );
799 HeapFree( GetProcessHeap(), 0, surface->bits );
800 HeapFree( GetProcessHeap(), 0, surface );
803 static const struct window_surface_funcs android_surface_funcs =
805 android_surface_lock,
806 android_surface_unlock,
807 android_surface_get_bitmap_info,
808 android_surface_get_bounds,
809 android_surface_set_region,
810 android_surface_flush,
811 android_surface_destroy
814 static BOOL is_argb_surface( struct window_surface *surface )
816 return surface && surface->funcs == &android_surface_funcs &&
817 get_android_surface( surface )->info.bmiHeader.biCompression == BI_RGB;
820 /***********************************************************************
821 * set_color_key
823 static void set_color_key( struct android_window_surface *surface, COLORREF key )
825 if (key == CLR_INVALID)
826 surface->color_key = CLR_INVALID;
827 else if (surface->info.bmiHeader.biBitCount <= 8)
828 surface->color_key = CLR_INVALID;
829 else if (key & (1 << 24)) /* PALETTEINDEX */
830 surface->color_key = 0;
831 else if (key >> 16 == 0x10ff) /* DIBINDEX */
832 surface->color_key = 0;
833 else if (surface->info.bmiHeader.biBitCount == 24)
834 surface->color_key = key;
835 else
836 surface->color_key = (GetRValue(key) << 16) | (GetGValue(key) << 8) | GetBValue(key);
839 /***********************************************************************
840 * set_surface_region
842 static void set_surface_region( struct window_surface *window_surface, HRGN win_region )
844 struct android_window_surface *surface = get_android_surface( window_surface );
845 struct android_win_data *win_data;
846 HRGN region = win_region;
847 RGNDATA *data = NULL;
848 DWORD size;
849 int offset_x, offset_y;
851 if (window_surface->funcs != &android_surface_funcs) return; /* we may get the null surface */
853 if (!(win_data = get_win_data( surface->hwnd ))) return;
854 offset_x = win_data->window_rect.left - win_data->whole_rect.left;
855 offset_y = win_data->window_rect.top - win_data->whole_rect.top;
856 release_win_data( win_data );
858 if (win_region == (HRGN)1) /* hack: win_region == 1 means retrieve region from server */
860 region = CreateRectRgn( 0, 0, win_data->window_rect.right - win_data->window_rect.left,
861 win_data->window_rect.bottom - win_data->window_rect.top );
862 if (GetWindowRgn( surface->hwnd, region ) == ERROR && !surface->region) goto done;
865 OffsetRgn( region, offset_x, offset_y );
866 if (surface->region) CombineRgn( region, region, surface->region, RGN_AND );
868 if (!(size = GetRegionData( region, 0, NULL ))) goto done;
869 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) goto done;
871 if (!GetRegionData( region, size, data ))
873 HeapFree( GetProcessHeap(), 0, data );
874 data = NULL;
877 done:
878 window_surface->funcs->lock( window_surface );
879 HeapFree( GetProcessHeap(), 0, surface->region_data );
880 surface->region_data = data;
881 *window_surface->funcs->get_bounds( window_surface ) = surface->header.rect;
882 window_surface->funcs->unlock( window_surface );
883 if (region != win_region) DeleteObject( region );
886 /***********************************************************************
887 * create_surface
889 static struct window_surface *create_surface( HWND hwnd, const RECT *rect,
890 BYTE alpha, COLORREF color_key, BOOL src_alpha )
892 struct android_window_surface *surface;
893 int width = rect->right - rect->left, height = rect->bottom - rect->top;
895 surface = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
896 FIELD_OFFSET( struct android_window_surface, info.bmiColors[3] ));
897 if (!surface) return NULL;
898 set_color_info( &surface->info, src_alpha );
899 surface->info.bmiHeader.biWidth = width;
900 surface->info.bmiHeader.biHeight = -height; /* top-down */
901 surface->info.bmiHeader.biPlanes = 1;
902 surface->info.bmiHeader.biSizeImage = get_dib_image_size( &surface->info );
904 InitializeCriticalSection( &surface->crit );
905 surface->crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": surface");
907 surface->header.funcs = &android_surface_funcs;
908 surface->header.rect = *rect;
909 surface->header.ref = 1;
910 surface->hwnd = hwnd;
911 surface->window = get_ioctl_window( hwnd );
912 surface->alpha = alpha;
913 set_color_key( surface, color_key );
914 set_surface_region( &surface->header, (HRGN)1 );
915 reset_bounds( &surface->bounds );
917 if (!(surface->bits = HeapAlloc( GetProcessHeap(), 0, surface->info.bmiHeader.biSizeImage )))
918 goto failed;
920 TRACE( "created %p hwnd %p %s bits %p-%p\n", surface, hwnd, wine_dbgstr_rect(rect),
921 surface->bits, (char *)surface->bits + surface->info.bmiHeader.biSizeImage );
923 return &surface->header;
925 failed:
926 android_surface_destroy( &surface->header );
927 return NULL;
930 /***********************************************************************
931 * set_surface_layered
933 static void set_surface_layered( struct window_surface *window_surface, BYTE alpha, COLORREF color_key )
935 struct android_window_surface *surface = get_android_surface( window_surface );
936 COLORREF prev_key;
937 BYTE prev_alpha;
939 if (window_surface->funcs != &android_surface_funcs) return; /* we may get the null surface */
941 window_surface->funcs->lock( window_surface );
942 prev_key = surface->color_key;
943 prev_alpha = surface->alpha;
944 surface->alpha = alpha;
945 set_color_key( surface, color_key );
946 if (alpha != prev_alpha || surface->color_key != prev_key) /* refresh */
947 *window_surface->funcs->get_bounds( window_surface ) = surface->header.rect;
948 window_surface->funcs->unlock( window_surface );
952 static WNDPROC desktop_orig_wndproc;
954 static LRESULT CALLBACK desktop_wndproc_wrapper( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
956 switch (msg)
958 case WM_PARENTNOTIFY:
959 if (LOWORD(wp) == WM_DESTROY) destroy_ioctl_window( (HWND)lp, FALSE );
960 break;
962 return desktop_orig_wndproc( hwnd, msg, wp, lp );
966 /***********************************************************************
967 * ANDROID_MsgWaitForMultipleObjectsEx
969 DWORD CDECL ANDROID_MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
970 DWORD timeout, DWORD mask, DWORD flags )
972 if (GetCurrentThreadId() == desktop_tid)
974 /* don't process nested events */
975 if (current_event) mask = 0;
976 if (process_events( mask )) return count - 1;
978 return WaitForMultipleObjectsEx( count, handles, flags & MWMO_WAITALL,
979 timeout, flags & MWMO_ALERTABLE );
982 /**********************************************************************
983 * ANDROID_CreateWindow
985 BOOL CDECL ANDROID_CreateWindow( HWND hwnd )
987 TRACE( "%p\n", hwnd );
989 if (hwnd == GetDesktopWindow())
991 struct android_win_data *data;
993 init_event_queue();
994 start_android_device();
995 if (!(data = alloc_win_data( hwnd ))) return FALSE;
996 release_win_data( data );
998 return TRUE;
1002 /***********************************************************************
1003 * ANDROID_DestroyWindow
1005 void CDECL ANDROID_DestroyWindow( HWND hwnd )
1007 struct android_win_data *data;
1009 if (!(data = get_win_data( hwnd ))) return;
1011 if (data->surface) window_surface_release( data->surface );
1012 data->surface = NULL;
1013 destroy_gl_drawable( hwnd );
1014 free_win_data( data );
1018 /***********************************************************************
1019 * create_win_data
1021 * Create a data window structure for an existing window.
1023 static struct android_win_data *create_win_data( HWND hwnd, const RECT *window_rect,
1024 const RECT *client_rect )
1026 struct android_win_data *data;
1027 HWND parent;
1029 if (!(parent = GetAncestor( hwnd, GA_PARENT ))) return NULL; /* desktop or HWND_MESSAGE */
1031 if (!(data = alloc_win_data( hwnd ))) return NULL;
1033 data->parent = (parent == GetDesktopWindow()) ? 0 : parent;
1034 data->whole_rect = data->window_rect = *window_rect;
1035 data->client_rect = *client_rect;
1036 return data;
1040 static inline BOOL get_surface_rect( const RECT *visible_rect, RECT *surface_rect )
1042 if (!IntersectRect( surface_rect, visible_rect, &virtual_screen_rect )) return FALSE;
1043 OffsetRect( surface_rect, -visible_rect->left, -visible_rect->top );
1044 surface_rect->left &= ~31;
1045 surface_rect->top &= ~31;
1046 surface_rect->right = max( surface_rect->left + 32, (surface_rect->right + 31) & ~31 );
1047 surface_rect->bottom = max( surface_rect->top + 32, (surface_rect->bottom + 31) & ~31 );
1048 return TRUE;
1052 /***********************************************************************
1053 * ANDROID_WindowPosChanging
1055 void CDECL ANDROID_WindowPosChanging( HWND hwnd, HWND insert_after, UINT swp_flags,
1056 const RECT *window_rect, const RECT *client_rect, RECT *visible_rect,
1057 struct window_surface **surface )
1059 struct android_win_data *data = get_win_data( hwnd );
1060 RECT surface_rect;
1061 DWORD flags;
1062 COLORREF key;
1063 BYTE alpha;
1064 BOOL layered = GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED;
1066 TRACE( "win %p window %s client %s style %08x flags %08x\n",
1067 hwnd, wine_dbgstr_rect(window_rect), wine_dbgstr_rect(client_rect),
1068 GetWindowLongW( hwnd, GWL_STYLE ), swp_flags );
1070 if (!data && !(data = create_win_data( hwnd, window_rect, client_rect ))) return;
1072 *visible_rect = *window_rect;
1074 /* create the window surface if necessary */
1076 if (data->parent) goto done;
1077 if (swp_flags & SWP_HIDEWINDOW) goto done;
1078 if (is_argb_surface( data->surface )) goto done;
1079 if (!get_surface_rect( visible_rect, &surface_rect )) goto done;
1081 if (data->surface)
1083 if (!memcmp( &data->surface->rect, &surface_rect, sizeof(surface_rect) ))
1085 /* existing surface is good enough */
1086 window_surface_add_ref( data->surface );
1087 if (*surface) window_surface_release( *surface );
1088 *surface = data->surface;
1089 goto done;
1092 if (!(swp_flags & SWP_SHOWWINDOW) && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)) goto done;
1094 if (!layered || !GetLayeredWindowAttributes( hwnd, &key, &alpha, &flags )) flags = 0;
1095 if (!(flags & LWA_ALPHA)) alpha = 255;
1096 if (!(flags & LWA_COLORKEY)) key = CLR_INVALID;
1098 if (*surface) window_surface_release( *surface );
1099 *surface = create_surface( data->hwnd, &surface_rect, alpha, key, FALSE );
1101 done:
1102 release_win_data( data );
1106 /***********************************************************************
1107 * ANDROID_WindowPosChanged
1109 void CDECL ANDROID_WindowPosChanged( HWND hwnd, HWND insert_after, UINT swp_flags,
1110 const RECT *window_rect, const RECT *client_rect,
1111 const RECT *visible_rect, const RECT *valid_rects,
1112 struct window_surface *surface )
1114 struct android_win_data *data;
1115 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
1116 HWND owner = 0;
1118 if (!(data = get_win_data( hwnd ))) return;
1120 data->window_rect = *window_rect;
1121 data->whole_rect = *visible_rect;
1122 data->client_rect = *client_rect;
1124 if (!is_argb_surface( data->surface ))
1126 if (surface) window_surface_add_ref( surface );
1127 if (data->surface) window_surface_release( data->surface );
1128 data->surface = surface;
1130 if (!data->parent) owner = GetWindow( hwnd, GW_OWNER );
1131 release_win_data( data );
1133 if (!(swp_flags & SWP_NOZORDER)) insert_after = GetWindow( hwnd, GW_HWNDPREV );
1135 TRACE( "win %p window %s client %s style %08x owner %p after %p flags %08x\n", hwnd,
1136 wine_dbgstr_rect(window_rect), wine_dbgstr_rect(client_rect),
1137 new_style, owner, insert_after, swp_flags );
1139 ioctl_window_pos_changed( hwnd, window_rect, client_rect, visible_rect,
1140 new_style, swp_flags, insert_after, owner );
1144 /***********************************************************************
1145 * ANDROID_ShowWindow
1147 UINT CDECL ANDROID_ShowWindow( HWND hwnd, INT cmd, RECT *rect, UINT swp )
1149 if (IsRectEmpty( rect )) return swp;
1150 if (!IsIconic( hwnd )) return swp;
1151 /* always hide icons off-screen */
1152 if (rect->left != -32000 || rect->top != -32000)
1154 OffsetRect( rect, -32000 - rect->left, -32000 - rect->top );
1155 swp &= ~(SWP_NOMOVE | SWP_NOCLIENTMOVE);
1157 return swp;
1161 /*****************************************************************
1162 * ANDROID_SetParent
1164 void CDECL ANDROID_SetParent( HWND hwnd, HWND parent, HWND old_parent )
1166 struct android_win_data *data;
1168 if (parent == old_parent) return;
1169 if (!(data = get_win_data( hwnd ))) return;
1171 TRACE( "win %p parent %p -> %p\n", hwnd, old_parent, parent );
1173 data->parent = (parent == GetDesktopWindow()) ? 0 : parent;
1174 ioctl_set_window_parent( hwnd, parent );
1175 release_win_data( data );
1179 /***********************************************************************
1180 * ANDROID_SetCapture
1182 void CDECL ANDROID_SetCapture( HWND hwnd, UINT flags )
1184 if (!(flags & (GUI_INMOVESIZE | GUI_INMENUMODE))) return;
1185 ioctl_set_capture( hwnd );
1189 /***********************************************************************
1190 * ANDROID_SetWindowStyle
1192 void CDECL ANDROID_SetWindowStyle( HWND hwnd, INT offset, STYLESTRUCT *style )
1194 struct android_win_data *data;
1195 DWORD changed = style->styleNew ^ style->styleOld;
1197 if (hwnd == GetDesktopWindow()) return;
1198 if (!(data = get_win_data( hwnd ))) return;
1200 if (offset == GWL_EXSTYLE && (changed & WS_EX_LAYERED)) /* changing WS_EX_LAYERED resets attributes */
1202 if (is_argb_surface( data->surface ))
1204 if (data->surface) window_surface_release( data->surface );
1205 data->surface = NULL;
1207 else if (data->surface) set_surface_layered( data->surface, 255, CLR_INVALID );
1209 release_win_data( data );
1213 /***********************************************************************
1214 * ANDROID_SetWindowRgn
1216 void CDECL ANDROID_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1218 struct android_win_data *data;
1220 if ((data = get_win_data( hwnd )))
1222 if (data->surface) set_surface_region( data->surface, hrgn );
1223 release_win_data( data );
1225 else FIXME( "not supported on other process window %p\n", hwnd );
1229 /***********************************************************************
1230 * ANDROID_SetLayeredWindowAttributes
1232 void CDECL ANDROID_SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
1234 struct android_win_data *data;
1236 if (!(flags & LWA_ALPHA)) alpha = 255;
1237 if (!(flags & LWA_COLORKEY)) key = CLR_INVALID;
1239 if ((data = get_win_data( hwnd )))
1241 if (data->surface) set_surface_layered( data->surface, alpha, key );
1242 release_win_data( data );
1247 /*****************************************************************************
1248 * ANDROID_UpdateLayeredWindow
1250 BOOL CDECL ANDROID_UpdateLayeredWindow( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info,
1251 const RECT *window_rect )
1253 struct window_surface *surface;
1254 struct android_win_data *data;
1255 BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, 0 };
1256 COLORREF color_key = (info->dwFlags & ULW_COLORKEY) ? info->crKey : CLR_INVALID;
1257 char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
1258 BITMAPINFO *bmi = (BITMAPINFO *)buffer;
1259 void *src_bits, *dst_bits;
1260 RECT rect, src_rect;
1261 HDC hdc = 0;
1262 HBITMAP dib;
1263 BOOL ret = FALSE;
1265 if (!(data = get_win_data( hwnd ))) return FALSE;
1267 rect = *window_rect;
1268 OffsetRect( &rect, -window_rect->left, -window_rect->top );
1270 surface = data->surface;
1271 if (!is_argb_surface( surface ))
1273 if (surface) window_surface_release( surface );
1274 surface = NULL;
1277 if (!surface || !EqualRect( &surface->rect, &rect ))
1279 data->surface = create_surface( data->hwnd, &rect, 255, color_key, TRUE );
1280 if (surface) window_surface_release( surface );
1281 surface = data->surface;
1283 else set_surface_layered( surface, 255, color_key );
1285 if (surface) window_surface_add_ref( surface );
1286 release_win_data( data );
1288 if (!surface) return FALSE;
1289 if (!info->hdcSrc)
1291 window_surface_release( surface );
1292 return TRUE;
1295 dst_bits = surface->funcs->get_info( surface, bmi );
1297 if (!(dib = CreateDIBSection( info->hdcDst, bmi, DIB_RGB_COLORS, &src_bits, NULL, 0 ))) goto done;
1298 if (!(hdc = CreateCompatibleDC( 0 ))) goto done;
1300 SelectObject( hdc, dib );
1302 surface->funcs->lock( surface );
1304 if (info->prcDirty)
1306 IntersectRect( &rect, &rect, info->prcDirty );
1307 memcpy( src_bits, dst_bits, bmi->bmiHeader.biSizeImage );
1308 PatBlt( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, BLACKNESS );
1310 src_rect = rect;
1311 if (info->pptSrc) OffsetRect( &src_rect, info->pptSrc->x, info->pptSrc->y );
1312 DPtoLP( info->hdcSrc, (POINT *)&src_rect, 2 );
1314 ret = GdiAlphaBlend( hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
1315 info->hdcSrc, src_rect.left, src_rect.top,
1316 src_rect.right - src_rect.left, src_rect.bottom - src_rect.top,
1317 (info->dwFlags & ULW_ALPHA) ? *info->pblend : blend );
1318 if (ret)
1320 memcpy( dst_bits, src_bits, bmi->bmiHeader.biSizeImage );
1321 add_bounds_rect( surface->funcs->get_bounds( surface ), &rect );
1324 surface->funcs->unlock( surface );
1325 surface->funcs->flush( surface );
1327 done:
1328 window_surface_release( surface );
1329 if (hdc) DeleteDC( hdc );
1330 if (dib) DeleteObject( dib );
1331 return ret;
1335 /**********************************************************************
1336 * ANDROID_WindowMessage
1338 LRESULT CDECL ANDROID_WindowMessage( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
1340 struct android_win_data *data;
1342 switch (msg)
1344 case WM_ANDROID_REFRESH:
1345 if (wp) /* opengl client window */
1347 update_gl_drawable( hwnd );
1349 else if ((data = get_win_data( hwnd )))
1351 struct window_surface *surface = data->surface;
1352 if (surface)
1354 surface->funcs->lock( surface );
1355 *surface->funcs->get_bounds( surface ) = surface->rect;
1356 surface->funcs->unlock( surface );
1357 if (is_argb_surface( surface )) surface->funcs->flush( surface );
1359 release_win_data( data );
1361 return 0;
1362 default:
1363 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg, hwnd, wp, lp );
1364 return 0;
1369 /***********************************************************************
1370 * ANDROID_create_desktop
1372 BOOL CDECL ANDROID_create_desktop( UINT width, UINT height )
1374 desktop_orig_wndproc = (WNDPROC)SetWindowLongPtrW( GetDesktopWindow(), GWLP_WNDPROC,
1375 (LONG_PTR)desktop_wndproc_wrapper );
1377 /* wait until we receive the surface changed event */
1378 while (!screen_width)
1380 if (wait_events( 2000 ) != 1)
1382 ERR( "wait timed out\n" );
1383 break;
1385 process_events( QS_ALLINPUT );
1387 return TRUE;