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
44 #include "wine/server.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(android
);
49 /* private window data */
50 struct android_win_data
52 HWND hwnd
; /* hwnd that this private data belongs to */
53 HWND parent
; /* parent hwnd for child windows */
54 RECT window_rect
; /* USER window rectangle relative to parent */
55 RECT whole_rect
; /* X window rectangle for the whole window relative to parent */
56 RECT client_rect
; /* client area relative to parent */
57 ANativeWindow
*window
; /* native window wrapper that forwards calls to the desktop process */
58 struct window_surface
*surface
;
61 #define SWP_AGG_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
63 static CRITICAL_SECTION win_data_section
;
64 static CRITICAL_SECTION_DEBUG critsect_debug
=
66 0, 0, &win_data_section
,
67 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
68 0, 0, { (DWORD_PTR
)(__FILE__
": win_data_section") }
70 static CRITICAL_SECTION win_data_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
72 static struct android_win_data
*win_data_context
[32768];
74 static inline int context_idx( HWND hwnd
)
76 return LOWORD( hwnd
) >> 1;
79 static void set_surface_region( struct window_surface
*window_surface
, HRGN win_region
);
81 /* only for use on sanitized BITMAPINFO structures */
82 static inline int get_dib_info_size( const BITMAPINFO
*info
, UINT coloruse
)
84 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
)
85 return sizeof(BITMAPINFOHEADER
) + 3 * sizeof(DWORD
);
86 if (coloruse
== DIB_PAL_COLORS
)
87 return sizeof(BITMAPINFOHEADER
) + info
->bmiHeader
.biClrUsed
* sizeof(WORD
);
88 return FIELD_OFFSET( BITMAPINFO
, bmiColors
[info
->bmiHeader
.biClrUsed
] );
91 static inline int get_dib_stride( int width
, int bpp
)
93 return ((width
* bpp
+ 31) >> 3) & ~3;
96 static inline int get_dib_image_size( const BITMAPINFO
*info
)
98 return get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
)
99 * abs( info
->bmiHeader
.biHeight
);
102 static BOOL
intersect_rect( RECT
*dst
, const RECT
*src1
, const RECT
*src2
)
104 dst
->left
= max(src1
->left
, src2
->left
);
105 dst
->top
= max(src1
->top
, src2
->top
);
106 dst
->right
= min(src1
->right
, src2
->right
);
107 dst
->bottom
= min(src1
->bottom
, src2
->bottom
);
108 return !IsRectEmpty( dst
);
112 /**********************************************************************
113 * get_win_monitor_dpi
115 static UINT
get_win_monitor_dpi( HWND hwnd
)
117 return NtUserGetSystemDpiForProcess( NULL
); /* FIXME: get monitor dpi */
121 /***********************************************************************
124 static struct android_win_data
*alloc_win_data( HWND hwnd
)
126 struct android_win_data
*data
;
128 if ((data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
))))
131 data
->window
= create_ioctl_window( hwnd
, FALSE
,
132 (float)get_win_monitor_dpi( hwnd
) / NtUserGetDpiForWindow( hwnd
));
133 EnterCriticalSection( &win_data_section
);
134 win_data_context
[context_idx(hwnd
)] = data
;
140 /***********************************************************************
143 static void free_win_data( struct android_win_data
*data
)
145 win_data_context
[context_idx( data
->hwnd
)] = NULL
;
146 LeaveCriticalSection( &win_data_section
);
147 if (data
->window
) release_ioctl_window( data
->window
);
148 HeapFree( GetProcessHeap(), 0, data
);
152 /***********************************************************************
155 * Lock and return the data structure associated with a window.
157 static struct android_win_data
*get_win_data( HWND hwnd
)
159 struct android_win_data
*data
;
161 if (!hwnd
) return NULL
;
162 EnterCriticalSection( &win_data_section
);
163 if ((data
= win_data_context
[context_idx(hwnd
)]) && data
->hwnd
== hwnd
) return data
;
164 LeaveCriticalSection( &win_data_section
);
169 /***********************************************************************
172 * Release the data returned by get_win_data.
174 static void release_win_data( struct android_win_data
*data
)
176 if (data
) LeaveCriticalSection( &win_data_section
);
180 /***********************************************************************
183 static struct ANativeWindow
*get_ioctl_window( HWND hwnd
)
185 struct ANativeWindow
*ret
;
186 struct android_win_data
*data
= get_win_data( hwnd
);
188 if (!data
|| !data
->window
) return NULL
;
189 ret
= grab_ioctl_window( data
->window
);
190 release_win_data( data
);
195 /* Handling of events coming from the Java side */
200 union event_data data
;
203 static struct list event_queue
= LIST_INIT( event_queue
);
204 static struct java_event
*current_event
;
205 static int event_pipe
[2];
206 static DWORD desktop_tid
;
208 /***********************************************************************
211 int send_event( const union event_data
*data
)
215 if ((res
= write( event_pipe
[1], data
, sizeof(*data
) )) != sizeof(*data
))
217 p__android_log_print( ANDROID_LOG_ERROR
, "wine", "failed to send event" );
224 /***********************************************************************
227 * JNI callback, runs in the context of the Java thread.
229 void desktop_changed( JNIEnv
*env
, jobject obj
, jint width
, jint height
)
231 union event_data data
;
233 memset( &data
, 0, sizeof(data
) );
234 data
.type
= DESKTOP_CHANGED
;
235 data
.desktop
.width
= width
;
236 data
.desktop
.height
= height
;
237 p__android_log_print( ANDROID_LOG_INFO
, "wine", "desktop_changed: %ux%u", width
, height
);
242 /***********************************************************************
245 * JNI callback, runs in the context of the Java thread.
247 void config_changed( JNIEnv
*env
, jobject obj
, jint dpi
)
249 union event_data data
;
251 memset( &data
, 0, sizeof(data
) );
252 data
.type
= CONFIG_CHANGED
;
254 p__android_log_print( ANDROID_LOG_INFO
, "wine", "config_changed: %u dpi", dpi
);
259 /***********************************************************************
262 * JNI callback, runs in the context of the Java thread.
264 void surface_changed( JNIEnv
*env
, jobject obj
, jint win
, jobject surface
, jboolean client
)
266 union event_data data
;
268 memset( &data
, 0, sizeof(data
) );
269 data
.surface
.hwnd
= LongToHandle( win
);
270 data
.surface
.client
= client
;
274 ANativeWindow
*win
= pANativeWindow_fromSurface( env
, surface
);
276 if (win
->query( win
, NATIVE_WINDOW_WIDTH
, &width
) < 0) width
= 0;
277 if (win
->query( win
, NATIVE_WINDOW_HEIGHT
, &height
) < 0) height
= 0;
278 data
.surface
.window
= win
;
279 data
.surface
.width
= width
;
280 data
.surface
.height
= height
;
281 p__android_log_print( ANDROID_LOG_INFO
, "wine", "surface_changed: %p %s %ux%u",
282 data
.surface
.hwnd
, client
? "client" : "whole", width
, height
);
284 data
.type
= SURFACE_CHANGED
;
289 /***********************************************************************
292 * JNI callback, runs in the context of the Java thread.
294 jboolean
motion_event( JNIEnv
*env
, jobject obj
, jint win
, jint action
, jint x
, jint y
, jint state
, jint vscroll
)
296 static LONG button_state
;
297 union event_data data
;
300 int mask
= action
& AMOTION_EVENT_ACTION_MASK
;
302 if (!( mask
== AMOTION_EVENT_ACTION_DOWN
||
303 mask
== AMOTION_EVENT_ACTION_UP
||
304 mask
== AMOTION_EVENT_ACTION_CANCEL
||
305 mask
== AMOTION_EVENT_ACTION_SCROLL
||
306 mask
== AMOTION_EVENT_ACTION_MOVE
||
307 mask
== AMOTION_EVENT_ACTION_HOVER_MOVE
||
308 mask
== AMOTION_EVENT_ACTION_BUTTON_PRESS
||
309 mask
== AMOTION_EVENT_ACTION_BUTTON_RELEASE
))
312 /* make sure a subsequent AMOTION_EVENT_ACTION_UP is not treated as a touch event */
313 if (mask
== AMOTION_EVENT_ACTION_BUTTON_RELEASE
) state
|= 0x80000000;
315 prev_state
= InterlockedExchange( &button_state
, state
);
317 data
.type
= MOTION_EVENT
;
318 data
.motion
.hwnd
= LongToHandle( win
);
319 data
.motion
.input
.type
= INPUT_MOUSE
;
320 data
.motion
.input
.u
.mi
.dx
= x
;
321 data
.motion
.input
.u
.mi
.dy
= y
;
322 data
.motion
.input
.u
.mi
.mouseData
= 0;
323 data
.motion
.input
.u
.mi
.time
= 0;
324 data
.motion
.input
.u
.mi
.dwExtraInfo
= 0;
325 data
.motion
.input
.u
.mi
.dwFlags
= MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
;
326 switch (action
& AMOTION_EVENT_ACTION_MASK
)
328 case AMOTION_EVENT_ACTION_DOWN
:
329 case AMOTION_EVENT_ACTION_BUTTON_PRESS
:
330 if ((state
& ~prev_state
) & AMOTION_EVENT_BUTTON_PRIMARY
)
331 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTDOWN
;
332 if ((state
& ~prev_state
) & AMOTION_EVENT_BUTTON_SECONDARY
)
333 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_RIGHTDOWN
;
334 if ((state
& ~prev_state
) & AMOTION_EVENT_BUTTON_TERTIARY
)
335 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_MIDDLEDOWN
;
336 if (!(state
& ~prev_state
)) /* touch event */
337 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTDOWN
;
339 case AMOTION_EVENT_ACTION_UP
:
340 case AMOTION_EVENT_ACTION_CANCEL
:
341 case AMOTION_EVENT_ACTION_BUTTON_RELEASE
:
342 if ((prev_state
& ~state
) & AMOTION_EVENT_BUTTON_PRIMARY
)
343 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTUP
;
344 if ((prev_state
& ~state
) & AMOTION_EVENT_BUTTON_SECONDARY
)
345 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_RIGHTUP
;
346 if ((prev_state
& ~state
) & AMOTION_EVENT_BUTTON_TERTIARY
)
347 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_MIDDLEUP
;
348 if (!(prev_state
& ~state
)) /* touch event */
349 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_LEFTUP
;
351 case AMOTION_EVENT_ACTION_SCROLL
:
352 data
.motion
.input
.u
.mi
.dwFlags
|= MOUSEEVENTF_WHEEL
;
353 data
.motion
.input
.u
.mi
.mouseData
= vscroll
< 0 ? -WHEEL_DELTA
: WHEEL_DELTA
;
355 case AMOTION_EVENT_ACTION_MOVE
:
356 case AMOTION_EVENT_ACTION_HOVER_MOVE
:
366 /***********************************************************************
369 static void init_event_queue(void)
374 if (pipe2( event_pipe
, O_CLOEXEC
| O_NONBLOCK
) == -1)
376 ERR( "could not create data\n" );
379 if (wine_server_fd_to_handle( event_pipe
[0], GENERIC_READ
| SYNCHRONIZE
, 0, &handle
))
381 ERR( "Can't allocate handle for event fd\n" );
384 SERVER_START_REQ( set_queue_fd
)
386 req
->handle
= wine_server_obj_handle( handle
);
387 ret
= wine_server_call( req
);
392 ERR( "Can't store handle for event fd %x\n", ret
);
395 CloseHandle( handle
);
396 desktop_tid
= GetCurrentThreadId();
400 /***********************************************************************
403 * Pull events from the event pipe and add them to the queue
405 static void pull_events(void)
407 struct java_event
*event
;
412 if (!(event
= HeapAlloc( GetProcessHeap(), 0, sizeof(*event
) ))) break;
414 res
= read( event_pipe
[0], &event
->data
, sizeof(event
->data
) );
415 if (res
!= sizeof(event
->data
)) break;
416 list_add_tail( &event_queue
, &event
->entry
);
418 HeapFree( GetProcessHeap(), 0, event
);
422 /***********************************************************************
425 static int process_events( DWORD mask
)
427 DPI_AWARENESS_CONTEXT context
;
428 struct java_event
*event
, *next
, *previous
;
429 unsigned int count
= 0;
431 assert( GetCurrentThreadId() == desktop_tid
);
435 previous
= current_event
;
437 LIST_FOR_EACH_ENTRY_SAFE( event
, next
, &event_queue
, struct java_event
, entry
)
439 switch (event
->data
.type
)
441 case SURFACE_CHANGED
:
442 break; /* always process it to unblock other threads */
444 if (event
->data
.motion
.input
.u
.mi
.dwFlags
& (MOUSEEVENTF_LEFTDOWN
|MOUSEEVENTF_RIGHTDOWN
|
445 MOUSEEVENTF_MIDDLEDOWN
|MOUSEEVENTF_LEFTUP
|
446 MOUSEEVENTF_RIGHTUP
|MOUSEEVENTF_MIDDLEUP
))
448 if (mask
& QS_MOUSEBUTTON
) break;
450 else if (mask
& QS_MOUSEMOVE
) break;
451 continue; /* skip it */
453 if (mask
& QS_KEY
) break;
454 continue; /* skip it */
456 if (mask
& QS_SENDMESSAGE
) break;
457 continue; /* skip it */
460 /* remove it first, in case we process events recursively */
461 list_remove( &event
->entry
);
462 current_event
= event
;
464 switch (event
->data
.type
)
466 case DESKTOP_CHANGED
:
467 TRACE( "DESKTOP_CHANGED %ux%u\n", event
->data
.desktop
.width
, event
->data
.desktop
.height
);
468 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
469 screen_width
= event
->data
.desktop
.width
;
470 screen_height
= event
->data
.desktop
.height
;
471 init_monitors( screen_width
, screen_height
);
472 NtUserSetWindowPos( NtUserGetDesktopWindow(), 0, 0, 0, screen_width
, screen_height
,
473 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
474 SetThreadDpiAwarenessContext( context
);
478 TRACE( "CONFIG_CHANGED dpi %u\n", event
->data
.cfg
.dpi
);
479 set_screen_dpi( event
->data
.cfg
.dpi
);
482 case SURFACE_CHANGED
:
483 TRACE("SURFACE_CHANGED %p %p %s size %ux%u\n", event
->data
.surface
.hwnd
,
484 event
->data
.surface
.window
, event
->data
.surface
.client
? "client" : "whole",
485 event
->data
.surface
.width
, event
->data
.surface
.height
);
487 register_native_window( event
->data
.surface
.hwnd
, event
->data
.surface
.window
, event
->data
.surface
.client
);
492 HWND capture
= get_capture_window();
494 if (event
->data
.motion
.input
.u
.mi
.dwFlags
& (MOUSEEVENTF_LEFTDOWN
|MOUSEEVENTF_RIGHTDOWN
|MOUSEEVENTF_MIDDLEDOWN
))
495 TRACE( "BUTTONDOWN pos %d,%d hwnd %p flags %x\n",
496 event
->data
.motion
.input
.u
.mi
.dx
, event
->data
.motion
.input
.u
.mi
.dy
,
497 event
->data
.motion
.hwnd
, event
->data
.motion
.input
.u
.mi
.dwFlags
);
498 else if (event
->data
.motion
.input
.u
.mi
.dwFlags
& (MOUSEEVENTF_LEFTUP
|MOUSEEVENTF_RIGHTUP
|MOUSEEVENTF_MIDDLEUP
))
499 TRACE( "BUTTONUP pos %d,%d hwnd %p flags %x\n",
500 event
->data
.motion
.input
.u
.mi
.dx
, event
->data
.motion
.input
.u
.mi
.dy
,
501 event
->data
.motion
.hwnd
, event
->data
.motion
.input
.u
.mi
.dwFlags
);
503 TRACE( "MOUSEMOVE pos %d,%d hwnd %p flags %x\n",
504 event
->data
.motion
.input
.u
.mi
.dx
, event
->data
.motion
.input
.u
.mi
.dy
,
505 event
->data
.motion
.hwnd
, event
->data
.motion
.input
.u
.mi
.dwFlags
);
506 if (!capture
&& (event
->data
.motion
.input
.u
.mi
.dwFlags
& MOUSEEVENTF_ABSOLUTE
))
509 SetRect( &rect
, event
->data
.motion
.input
.u
.mi
.dx
, event
->data
.motion
.input
.u
.mi
.dy
,
510 event
->data
.motion
.input
.u
.mi
.dx
+ 1, event
->data
.motion
.input
.u
.mi
.dy
+ 1 );
512 SERVER_START_REQ( update_window_zorder
)
514 req
->window
= wine_server_user_handle( event
->data
.motion
.hwnd
);
515 req
->rect
.left
= rect
.left
;
516 req
->rect
.top
= rect
.top
;
517 req
->rect
.right
= rect
.right
;
518 req
->rect
.bottom
= rect
.bottom
;
519 wine_server_call( req
);
523 __wine_send_input( capture
? capture
: event
->data
.motion
.hwnd
, &event
->data
.motion
.input
, NULL
);
528 if (event
->data
.kbd
.input
.u
.ki
.dwFlags
& KEYEVENTF_KEYUP
)
529 TRACE("KEYUP hwnd %p vkey %x '%c' scancode %x\n", event
->data
.kbd
.hwnd
,
530 event
->data
.kbd
.input
.u
.ki
.wVk
, event
->data
.kbd
.input
.u
.ki
.wVk
,
531 event
->data
.kbd
.input
.u
.ki
.wScan
);
533 TRACE("KEYDOWN hwnd %p vkey %x '%c' scancode %x\n", event
->data
.kbd
.hwnd
,
534 event
->data
.kbd
.input
.u
.ki
.wVk
, event
->data
.kbd
.input
.u
.ki
.wVk
,
535 event
->data
.kbd
.input
.u
.ki
.wScan
);
536 update_keyboard_lock_state( event
->data
.kbd
.input
.u
.ki
.wVk
, event
->data
.kbd
.lock_state
);
537 __wine_send_input( 0, &event
->data
.kbd
.input
, NULL
);
541 FIXME( "got event %u\n", event
->data
.type
);
543 HeapFree( GetProcessHeap(), 0, event
);
545 /* next may have been removed by a recursive call, so reset it to the beginning of the list */
546 next
= LIST_ENTRY( event_queue
.next
, struct java_event
, entry
);
548 current_event
= previous
;
553 /***********************************************************************
556 static int wait_events( int timeout
)
558 assert( GetCurrentThreadId() == desktop_tid
);
562 struct pollfd pollfd
;
565 pollfd
.fd
= event_pipe
[0];
566 pollfd
.events
= POLLIN
| POLLHUP
;
567 ret
= poll( &pollfd
, 1, timeout
);
568 if (ret
== -1 && errno
== EINTR
) continue;
569 if (ret
&& (pollfd
.revents
& (POLLHUP
| POLLERR
))) ret
= -1;
575 /* Window surface support */
577 struct android_window_surface
579 struct window_surface header
;
581 ANativeWindow
*window
;
584 RGNDATA
*region_data
;
589 CRITICAL_SECTION crit
;
590 BITMAPINFO info
; /* variable size, must be last */
593 static struct android_window_surface
*get_android_surface( struct window_surface
*surface
)
595 return (struct android_window_surface
*)surface
;
598 static inline void reset_bounds( RECT
*bounds
)
600 bounds
->left
= bounds
->top
= INT_MAX
;
601 bounds
->right
= bounds
->bottom
= INT_MIN
;
604 static inline void add_bounds_rect( RECT
*bounds
, const RECT
*rect
)
606 if (rect
->left
>= rect
->right
|| rect
->top
>= rect
->bottom
) return;
607 bounds
->left
= min( bounds
->left
, rect
->left
);
608 bounds
->top
= min( bounds
->top
, rect
->top
);
609 bounds
->right
= max( bounds
->right
, rect
->right
);
610 bounds
->bottom
= max( bounds
->bottom
, rect
->bottom
);
613 /* store the palette or color mask data in the bitmap info structure */
614 static void set_color_info( BITMAPINFO
*info
, BOOL has_alpha
)
616 DWORD
*colors
= (DWORD
*)info
->bmiColors
;
618 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
619 info
->bmiHeader
.biClrUsed
= 0;
620 info
->bmiHeader
.biBitCount
= 32;
623 info
->bmiHeader
.biCompression
= BI_RGB
;
626 info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
627 colors
[0] = 0xff0000;
628 colors
[1] = 0x00ff00;
629 colors
[2] = 0x0000ff;
632 /* apply the window region to a single line of the destination image. */
633 static void apply_line_region( DWORD
*dst
, int width
, int x
, int y
, const RECT
*rect
, const RECT
*end
)
635 while (rect
< end
&& rect
->top
<= y
&& width
> 0)
639 memset( dst
, 0, min( rect
->left
- x
, width
) * sizeof(*dst
) );
640 dst
+= rect
->left
- x
;
641 width
-= rect
->left
- x
;
646 dst
+= rect
->right
- x
;
647 width
-= rect
->right
- x
;
652 if (width
> 0) memset( dst
, 0, width
* sizeof(*dst
) );
655 /***********************************************************************
656 * android_surface_lock
658 static void android_surface_lock( struct window_surface
*window_surface
)
660 struct android_window_surface
*surface
= get_android_surface( window_surface
);
662 EnterCriticalSection( &surface
->crit
);
665 /***********************************************************************
666 * android_surface_unlock
668 static void android_surface_unlock( struct window_surface
*window_surface
)
670 struct android_window_surface
*surface
= get_android_surface( window_surface
);
672 LeaveCriticalSection( &surface
->crit
);
675 /***********************************************************************
676 * android_surface_get_bitmap_info
678 static void *android_surface_get_bitmap_info( struct window_surface
*window_surface
, BITMAPINFO
*info
)
680 struct android_window_surface
*surface
= get_android_surface( window_surface
);
682 memcpy( info
, &surface
->info
, get_dib_info_size( &surface
->info
, DIB_RGB_COLORS
));
683 return surface
->bits
;
686 /***********************************************************************
687 * android_surface_get_bounds
689 static RECT
*android_surface_get_bounds( struct window_surface
*window_surface
)
691 struct android_window_surface
*surface
= get_android_surface( window_surface
);
693 return &surface
->bounds
;
696 /***********************************************************************
697 * android_surface_set_region
699 static void android_surface_set_region( struct window_surface
*window_surface
, HRGN region
)
701 struct android_window_surface
*surface
= get_android_surface( window_surface
);
703 TRACE( "updating surface %p hwnd %p with %p\n", surface
, surface
->hwnd
, region
);
705 window_surface
->funcs
->lock( window_surface
);
708 if (surface
->region
) NtGdiDeleteObjectApp( surface
->region
);
713 if (!surface
->region
) surface
->region
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
714 NtGdiCombineRgn( surface
->region
, region
, 0, RGN_COPY
);
716 window_surface
->funcs
->unlock( window_surface
);
717 set_surface_region( &surface
->header
, (HRGN
)1 );
720 /***********************************************************************
721 * android_surface_flush
723 static void android_surface_flush( struct window_surface
*window_surface
)
725 struct android_window_surface
*surface
= get_android_surface( window_surface
);
726 ANativeWindow_Buffer buffer
;
731 window_surface
->funcs
->lock( window_surface
);
732 SetRect( &rect
, 0, 0, surface
->header
.rect
.right
- surface
->header
.rect
.left
,
733 surface
->header
.rect
.bottom
- surface
->header
.rect
.top
);
734 needs_flush
= intersect_rect( &rect
, &rect
, &surface
->bounds
);
735 reset_bounds( &surface
->bounds
);
736 window_surface
->funcs
->unlock( window_surface
);
737 if (!needs_flush
) return;
739 TRACE( "flushing %p hwnd %p surface %s rect %s bits %p alpha %02x key %08x region %u rects\n",
740 surface
, surface
->hwnd
, wine_dbgstr_rect( &surface
->header
.rect
),
741 wine_dbgstr_rect( &rect
), surface
->bits
, surface
->alpha
, surface
->color_key
,
742 surface
->region_data
? surface
->region_data
->rdh
.nCount
: 0 );
746 rc
.right
= rect
.right
;
747 rc
.bottom
= rect
.bottom
;
749 if (!surface
->window
->perform( surface
->window
, NATIVE_WINDOW_LOCK
, &buffer
, &rc
))
751 const RECT
*rgn_rect
= NULL
, *end
= NULL
;
752 unsigned int *src
, *dst
;
757 rect
.right
= rc
.right
;
758 rect
.bottom
= rc
.bottom
;
759 intersect_rect( &rect
, &rect
, &surface
->header
.rect
);
761 if (surface
->region_data
)
763 rgn_rect
= (RECT
*)surface
->region_data
->Buffer
;
764 end
= rgn_rect
+ surface
->region_data
->rdh
.nCount
;
766 src
= (unsigned int *)surface
->bits
767 + (rect
.top
- surface
->header
.rect
.top
) * surface
->info
.bmiHeader
.biWidth
768 + (rect
.left
- surface
->header
.rect
.left
);
769 dst
= (unsigned int *)buffer
.bits
+ rect
.top
* buffer
.stride
+ rect
.left
;
770 width
= min( rect
.right
- rect
.left
, buffer
.stride
);
772 for (y
= rect
.top
; y
< min( buffer
.height
, rect
.bottom
); y
++)
774 if (surface
->info
.bmiHeader
.biCompression
== BI_RGB
)
775 memcpy( dst
, src
, width
* sizeof(*dst
) );
776 else if (surface
->alpha
== 255)
777 for (x
= 0; x
< width
; x
++) dst
[x
] = src
[x
] | 0xff000000;
779 for (x
= 0; x
< width
; x
++)
780 dst
[x
] = ((surface
->alpha
<< 24) |
781 (((BYTE
)(src
[x
] >> 16) * surface
->alpha
/ 255) << 16) |
782 (((BYTE
)(src
[x
] >> 8) * surface
->alpha
/ 255) << 8) |
783 (((BYTE
)src
[x
] * surface
->alpha
/ 255)));
785 if (surface
->color_key
!= CLR_INVALID
)
786 for (x
= 0; x
< width
; x
++) if ((src
[x
] & 0xffffff) == surface
->color_key
) dst
[x
] = 0;
790 while (rgn_rect
< end
&& rgn_rect
->bottom
<= y
) rgn_rect
++;
791 apply_line_region( dst
, width
, rect
.left
, y
, rgn_rect
, end
);
794 src
+= surface
->info
.bmiHeader
.biWidth
;
795 dst
+= buffer
.stride
;
797 surface
->window
->perform( surface
->window
, NATIVE_WINDOW_UNLOCK_AND_POST
);
799 else TRACE( "Unable to lock surface %p window %p buffer %p\n",
800 surface
, surface
->hwnd
, surface
->window
);
803 /***********************************************************************
804 * android_surface_destroy
806 static void android_surface_destroy( struct window_surface
*window_surface
)
808 struct android_window_surface
*surface
= get_android_surface( window_surface
);
810 TRACE( "freeing %p bits %p\n", surface
, surface
->bits
);
812 surface
->crit
.DebugInfo
->Spare
[0] = 0;
813 DeleteCriticalSection( &surface
->crit
);
814 HeapFree( GetProcessHeap(), 0, surface
->region_data
);
815 if (surface
->region
) NtGdiDeleteObjectApp( surface
->region
);
816 release_ioctl_window( surface
->window
);
817 HeapFree( GetProcessHeap(), 0, surface
->bits
);
818 HeapFree( GetProcessHeap(), 0, surface
);
821 static const struct window_surface_funcs android_surface_funcs
=
823 android_surface_lock
,
824 android_surface_unlock
,
825 android_surface_get_bitmap_info
,
826 android_surface_get_bounds
,
827 android_surface_set_region
,
828 android_surface_flush
,
829 android_surface_destroy
832 static BOOL
is_argb_surface( struct window_surface
*surface
)
834 return surface
&& surface
->funcs
== &android_surface_funcs
&&
835 get_android_surface( surface
)->info
.bmiHeader
.biCompression
== BI_RGB
;
838 /***********************************************************************
841 static void set_color_key( struct android_window_surface
*surface
, COLORREF key
)
843 if (key
== CLR_INVALID
)
844 surface
->color_key
= CLR_INVALID
;
845 else if (surface
->info
.bmiHeader
.biBitCount
<= 8)
846 surface
->color_key
= CLR_INVALID
;
847 else if (key
& (1 << 24)) /* PALETTEINDEX */
848 surface
->color_key
= 0;
849 else if (key
>> 16 == 0x10ff) /* DIBINDEX */
850 surface
->color_key
= 0;
851 else if (surface
->info
.bmiHeader
.biBitCount
== 24)
852 surface
->color_key
= key
;
854 surface
->color_key
= (GetRValue(key
) << 16) | (GetGValue(key
) << 8) | GetBValue(key
);
857 /***********************************************************************
860 static void set_surface_region( struct window_surface
*window_surface
, HRGN win_region
)
862 struct android_window_surface
*surface
= get_android_surface( window_surface
);
863 struct android_win_data
*win_data
;
864 HRGN region
= win_region
;
865 RGNDATA
*data
= NULL
;
867 int offset_x
, offset_y
;
869 if (window_surface
->funcs
!= &android_surface_funcs
) return; /* we may get the null surface */
871 if (!(win_data
= get_win_data( surface
->hwnd
))) return;
872 offset_x
= win_data
->window_rect
.left
- win_data
->whole_rect
.left
;
873 offset_y
= win_data
->window_rect
.top
- win_data
->whole_rect
.top
;
874 release_win_data( win_data
);
876 if (win_region
== (HRGN
)1) /* hack: win_region == 1 means retrieve region from server */
878 region
= NtGdiCreateRectRgn( 0, 0, win_data
->window_rect
.right
- win_data
->window_rect
.left
,
879 win_data
->window_rect
.bottom
- win_data
->window_rect
.top
);
880 if (NtUserGetWindowRgnEx( surface
->hwnd
, region
, 0 ) == ERROR
&& !surface
->region
) goto done
;
883 NtGdiOffsetRgn( region
, offset_x
, offset_y
);
884 if (surface
->region
) NtGdiCombineRgn( region
, region
, surface
->region
, RGN_AND
);
886 if (!(size
= NtGdiGetRegionData( region
, 0, NULL
))) goto done
;
887 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) goto done
;
889 if (!NtGdiGetRegionData( region
, size
, data
))
891 HeapFree( GetProcessHeap(), 0, data
);
896 window_surface
->funcs
->lock( window_surface
);
897 HeapFree( GetProcessHeap(), 0, surface
->region_data
);
898 surface
->region_data
= data
;
899 *window_surface
->funcs
->get_bounds( window_surface
) = surface
->header
.rect
;
900 window_surface
->funcs
->unlock( window_surface
);
901 if (region
!= win_region
) NtGdiDeleteObjectApp( region
);
904 /***********************************************************************
907 static struct window_surface
*create_surface( HWND hwnd
, const RECT
*rect
,
908 BYTE alpha
, COLORREF color_key
, BOOL src_alpha
)
910 struct android_window_surface
*surface
;
911 int width
= rect
->right
- rect
->left
, height
= rect
->bottom
- rect
->top
;
913 surface
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
914 FIELD_OFFSET( struct android_window_surface
, info
.bmiColors
[3] ));
915 if (!surface
) return NULL
;
916 set_color_info( &surface
->info
, src_alpha
);
917 surface
->info
.bmiHeader
.biWidth
= width
;
918 surface
->info
.bmiHeader
.biHeight
= -height
; /* top-down */
919 surface
->info
.bmiHeader
.biPlanes
= 1;
920 surface
->info
.bmiHeader
.biSizeImage
= get_dib_image_size( &surface
->info
);
922 InitializeCriticalSection( &surface
->crit
);
923 surface
->crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": surface");
925 surface
->header
.funcs
= &android_surface_funcs
;
926 surface
->header
.rect
= *rect
;
927 surface
->header
.ref
= 1;
928 surface
->hwnd
= hwnd
;
929 surface
->window
= get_ioctl_window( hwnd
);
930 surface
->alpha
= alpha
;
931 set_color_key( surface
, color_key
);
932 set_surface_region( &surface
->header
, (HRGN
)1 );
933 reset_bounds( &surface
->bounds
);
935 if (!(surface
->bits
= HeapAlloc( GetProcessHeap(), 0, surface
->info
.bmiHeader
.biSizeImage
)))
938 TRACE( "created %p hwnd %p %s bits %p-%p\n", surface
, hwnd
, wine_dbgstr_rect(rect
),
939 surface
->bits
, (char *)surface
->bits
+ surface
->info
.bmiHeader
.biSizeImage
);
941 return &surface
->header
;
944 android_surface_destroy( &surface
->header
);
948 /***********************************************************************
949 * set_surface_layered
951 static void set_surface_layered( struct window_surface
*window_surface
, BYTE alpha
, COLORREF color_key
)
953 struct android_window_surface
*surface
= get_android_surface( window_surface
);
957 if (window_surface
->funcs
!= &android_surface_funcs
) return; /* we may get the null surface */
959 window_surface
->funcs
->lock( window_surface
);
960 prev_key
= surface
->color_key
;
961 prev_alpha
= surface
->alpha
;
962 surface
->alpha
= alpha
;
963 set_color_key( surface
, color_key
);
964 if (alpha
!= prev_alpha
|| surface
->color_key
!= prev_key
) /* refresh */
965 *window_surface
->funcs
->get_bounds( window_surface
) = surface
->header
.rect
;
966 window_surface
->funcs
->unlock( window_surface
);
969 /***********************************************************************
972 * Return a monochrome icon/cursor bitmap bits in ARGB format.
974 static unsigned int *get_mono_icon_argb( HDC hdc
, HBITMAP bmp
, unsigned int *width
, unsigned int *height
)
978 unsigned int i
, j
, stride
, mask_size
, bits_size
, *bits
= NULL
, *ptr
;
980 if (!NtGdiExtGetObjectW( bmp
, sizeof(bm
), &bm
)) return NULL
;
981 stride
= ((bm
.bmWidth
+ 15) >> 3) & ~1;
982 mask_size
= stride
* bm
.bmHeight
;
983 if (!(mask
= HeapAlloc( GetProcessHeap(), 0, mask_size
))) return NULL
;
984 if (!NtGdiGetBitmapBits( bmp
, mask_size
, mask
)) goto done
;
987 bits_size
= bm
.bmWidth
* bm
.bmHeight
* sizeof(*bits
);
988 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, bits_size
))) goto done
;
991 for (i
= 0; i
< bm
.bmHeight
; i
++)
992 for (j
= 0; j
< bm
.bmWidth
; j
++, ptr
++)
994 int and = ((mask
[i
* stride
+ j
/ 8] << (j
% 8)) & 0x80);
995 int xor = ((mask
[(i
+ bm
.bmHeight
) * stride
+ j
/ 8] << (j
% 8)) & 0x80);
998 else if (xor && !and)
1001 /* we can't draw "invert" pixels, so render them as black instead */
1005 *width
= bm
.bmWidth
;
1006 *height
= bm
.bmHeight
;
1009 HeapFree( GetProcessHeap(), 0, mask
);
1013 /***********************************************************************
1016 * Return the bitmap bits in ARGB format. Helper for setting icons and cursors.
1018 static unsigned int *get_bitmap_argb( HDC hdc
, HBITMAP color
, HBITMAP mask
, unsigned int *width
,
1019 unsigned int *height
)
1021 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
1022 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
1024 unsigned int *ptr
, *bits
= NULL
;
1025 unsigned char *mask_bits
= NULL
;
1027 BOOL has_alpha
= FALSE
;
1029 if (!color
) return get_mono_icon_argb( hdc
, mask
, width
, height
);
1031 if (!NtGdiExtGetObjectW( color
, sizeof(bm
), &bm
)) return NULL
;
1032 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1033 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
1034 info
->bmiHeader
.biHeight
= -bm
.bmHeight
;
1035 info
->bmiHeader
.biPlanes
= 1;
1036 info
->bmiHeader
.biBitCount
= 32;
1037 info
->bmiHeader
.biCompression
= BI_RGB
;
1038 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
1039 info
->bmiHeader
.biXPelsPerMeter
= 0;
1040 info
->bmiHeader
.biYPelsPerMeter
= 0;
1041 info
->bmiHeader
.biClrUsed
= 0;
1042 info
->bmiHeader
.biClrImportant
= 0;
1043 if (!(bits
= HeapAlloc( GetProcessHeap(), 0, bm
.bmWidth
* bm
.bmHeight
* sizeof(unsigned int) )))
1045 if (!NtGdiGetDIBitsInternal( hdc
, color
, 0, bm
.bmHeight
, bits
, info
, DIB_RGB_COLORS
, 0, 0 ))
1048 *width
= bm
.bmWidth
;
1049 *height
= bm
.bmHeight
;
1051 for (i
= 0; i
< bm
.bmWidth
* bm
.bmHeight
; i
++)
1052 if ((has_alpha
= (bits
[i
] & 0xff000000) != 0)) break;
1056 unsigned int width_bytes
= (bm
.bmWidth
+ 31) / 32 * 4;
1057 /* generate alpha channel from the mask */
1058 info
->bmiHeader
.biBitCount
= 1;
1059 info
->bmiHeader
.biSizeImage
= width_bytes
* bm
.bmHeight
;
1060 if (!(mask_bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
))) goto failed
;
1061 if (!NtGdiGetDIBitsInternal( hdc
, mask
, 0, bm
.bmHeight
, mask_bits
, info
, DIB_RGB_COLORS
, 0, 0 ))
1064 for (i
= 0; i
< bm
.bmHeight
; i
++)
1065 for (j
= 0; j
< bm
.bmWidth
; j
++, ptr
++)
1066 if (!((mask_bits
[i
* width_bytes
+ j
/ 8] << (j
% 8)) & 0x80)) *ptr
|= 0xff000000;
1067 HeapFree( GetProcessHeap(), 0, mask_bits
);
1073 HeapFree( GetProcessHeap(), 0, bits
);
1074 HeapFree( GetProcessHeap(), 0, mask_bits
);
1075 *width
= *height
= 0;
1080 enum android_system_cursors
1083 TYPE_CONTEXT_MENU
= 1001,
1088 TYPE_CROSSHAIR
= 1007,
1090 TYPE_VERTICAL_TEXT
= 1009,
1093 TYPE_NO_DROP
= 1012,
1094 TYPE_ALL_SCROLL
= 1013,
1095 TYPE_HORIZONTAL_DOUBLE_ARROW
= 1014,
1096 TYPE_VERTICAL_DOUBLE_ARROW
= 1015,
1097 TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW
= 1016,
1098 TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW
= 1017,
1099 TYPE_ZOOM_IN
= 1018,
1100 TYPE_ZOOM_OUT
= 1019,
1102 TYPE_GRABBING
= 1021,
1105 struct system_cursors
1108 enum android_system_cursors android_id
;
1111 static const struct system_cursors user32_cursors
[] =
1113 { OCR_NORMAL
, TYPE_ARROW
},
1114 { OCR_IBEAM
, TYPE_TEXT
},
1115 { OCR_WAIT
, TYPE_WAIT
},
1116 { OCR_CROSS
, TYPE_CROSSHAIR
},
1117 { OCR_SIZE
, TYPE_ALL_SCROLL
},
1118 { OCR_SIZEALL
, TYPE_ALL_SCROLL
},
1119 { OCR_SIZENWSE
, TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW
},
1120 { OCR_SIZENESW
, TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW
},
1121 { OCR_SIZEWE
, TYPE_HORIZONTAL_DOUBLE_ARROW
},
1122 { OCR_SIZENS
, TYPE_VERTICAL_DOUBLE_ARROW
},
1123 { OCR_NO
, TYPE_NO_DROP
},
1124 { OCR_HAND
, TYPE_HAND
},
1125 { OCR_HELP
, TYPE_HELP
},
1129 static const struct system_cursors comctl32_cursors
[] =
1131 /* 102 TYPE_MOVE doesn't exist */
1133 { 105, TYPE_ARROW
},
1134 { 106, TYPE_HORIZONTAL_DOUBLE_ARROW
},
1135 { 107, TYPE_HORIZONTAL_DOUBLE_ARROW
},
1136 { 108, TYPE_GRABBING
},
1137 { 135, TYPE_VERTICAL_DOUBLE_ARROW
},
1141 static const struct system_cursors ole32_cursors
[] =
1143 { 1, TYPE_NO_DROP
},
1144 /* 2 TYPE_MOVE doesn't exist */
1150 static const struct system_cursors riched20_cursors
[] =
1152 { 105, TYPE_GRABBING
},
1154 /* 110 TYPE_MOVE doesn't exist */
1155 { 111, TYPE_NO_DROP
},
1161 const struct system_cursors
*cursors
;
1163 } module_cursors
[] =
1165 { user32_cursors
, {'u','s','e','r','3','2','.','d','l','l',0} },
1166 { comctl32_cursors
, {'c','o','m','c','t','l','3','2','.','d','l','l',0} },
1167 { ole32_cursors
, {'o','l','e','3','2','.','d','l','l',0} },
1168 { riched20_cursors
, {'r','i','c','h','e','d','2','0','.','d','l','l',0} }
1171 static int get_cursor_system_id( const ICONINFOEXW
*info
)
1173 const struct system_cursors
*cursors
;
1177 if (info
->szResName
[0]) return 0; /* only integer resources are supported here */
1178 if (!(module
= GetModuleHandleW( info
->szModName
))) return 0;
1180 for (i
= 0; i
< ARRAY_SIZE( module_cursors
); i
++)
1181 if (GetModuleHandleW( module_cursors
[i
].name
) == module
) break;
1182 if (i
== ARRAY_SIZE( module_cursors
)) return 0;
1184 cursors
= module_cursors
[i
].cursors
;
1185 for (i
= 0; cursors
[i
].id
; i
++)
1186 if (cursors
[i
].id
== info
->wResID
) return cursors
[i
].android_id
;
1192 LRESULT
ANDROID_DesktopWindowProc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1196 case WM_PARENTNOTIFY
:
1197 if (LOWORD(wp
) == WM_DESTROY
) destroy_ioctl_window( (HWND
)lp
, FALSE
);
1200 return NtUserMessageCall( hwnd
, msg
, wp
, lp
, 0, NtUserDefWindowProc
, FALSE
);
1204 /***********************************************************************
1205 * ANDROID_MsgWaitForMultipleObjectsEx
1207 NTSTATUS
ANDROID_MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
1208 const LARGE_INTEGER
*timeout
,
1209 DWORD mask
, DWORD flags
)
1211 if (GetCurrentThreadId() == desktop_tid
)
1213 /* don't process nested events */
1214 if (current_event
) mask
= 0;
1215 if (process_events( mask
)) return count
- 1;
1217 return NtWaitForMultipleObjects( count
, handles
, !(flags
& MWMO_WAITALL
),
1218 !!(flags
& MWMO_ALERTABLE
), timeout
);
1221 /**********************************************************************
1222 * ANDROID_CreateWindow
1224 BOOL
ANDROID_CreateWindow( HWND hwnd
)
1226 TRACE( "%p\n", hwnd
);
1228 if (hwnd
== NtUserGetDesktopWindow())
1230 struct android_win_data
*data
;
1233 start_android_device();
1234 if (!(data
= alloc_win_data( hwnd
))) return FALSE
;
1235 release_win_data( data
);
1241 /***********************************************************************
1242 * ANDROID_DestroyWindow
1244 void ANDROID_DestroyWindow( HWND hwnd
)
1246 struct android_win_data
*data
;
1248 if (!(data
= get_win_data( hwnd
))) return;
1250 if (data
->surface
) window_surface_release( data
->surface
);
1251 data
->surface
= NULL
;
1252 destroy_gl_drawable( hwnd
);
1253 free_win_data( data
);
1257 /***********************************************************************
1260 * Create a data window structure for an existing window.
1262 static struct android_win_data
*create_win_data( HWND hwnd
, const RECT
*window_rect
,
1263 const RECT
*client_rect
)
1265 struct android_win_data
*data
;
1268 if (!(parent
= NtUserGetAncestor( hwnd
, GA_PARENT
))) return NULL
; /* desktop or HWND_MESSAGE */
1270 if (!(data
= alloc_win_data( hwnd
))) return NULL
;
1272 data
->parent
= (parent
== NtUserGetDesktopWindow()) ? 0 : parent
;
1273 data
->whole_rect
= data
->window_rect
= *window_rect
;
1274 data
->client_rect
= *client_rect
;
1279 static inline BOOL
get_surface_rect( const RECT
*visible_rect
, RECT
*surface_rect
)
1281 if (!intersect_rect( surface_rect
, visible_rect
, &virtual_screen_rect
)) return FALSE
;
1282 OffsetRect( surface_rect
, -visible_rect
->left
, -visible_rect
->top
);
1283 surface_rect
->left
&= ~31;
1284 surface_rect
->top
&= ~31;
1285 surface_rect
->right
= max( surface_rect
->left
+ 32, (surface_rect
->right
+ 31) & ~31 );
1286 surface_rect
->bottom
= max( surface_rect
->top
+ 32, (surface_rect
->bottom
+ 31) & ~31 );
1291 /***********************************************************************
1292 * ANDROID_WindowPosChanging
1294 BOOL
ANDROID_WindowPosChanging( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1295 const RECT
*window_rect
, const RECT
*client_rect
, RECT
*visible_rect
,
1296 struct window_surface
**surface
)
1298 struct android_win_data
*data
= get_win_data( hwnd
);
1303 BOOL layered
= NtUserGetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
;
1305 TRACE( "win %p window %s client %s style %08x flags %08x\n",
1306 hwnd
, wine_dbgstr_rect(window_rect
), wine_dbgstr_rect(client_rect
),
1307 NtUserGetWindowLongW( hwnd
, GWL_STYLE
), swp_flags
);
1309 if (!data
&& !(data
= create_win_data( hwnd
, window_rect
, client_rect
))) return TRUE
;
1311 *visible_rect
= *window_rect
;
1313 /* create the window surface if necessary */
1315 if (data
->parent
) goto done
;
1316 if (swp_flags
& SWP_HIDEWINDOW
) goto done
;
1317 if (is_argb_surface( data
->surface
)) goto done
;
1318 if (!get_surface_rect( visible_rect
, &surface_rect
)) goto done
;
1322 if (!memcmp( &data
->surface
->rect
, &surface_rect
, sizeof(surface_rect
) ))
1324 /* existing surface is good enough */
1325 window_surface_add_ref( data
->surface
);
1326 if (*surface
) window_surface_release( *surface
);
1327 *surface
= data
->surface
;
1331 if (!(swp_flags
& SWP_SHOWWINDOW
) && !(NtUserGetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1334 if (!layered
|| !NtUserGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
)) flags
= 0;
1335 if (!(flags
& LWA_ALPHA
)) alpha
= 255;
1336 if (!(flags
& LWA_COLORKEY
)) key
= CLR_INVALID
;
1338 if (*surface
) window_surface_release( *surface
);
1339 *surface
= create_surface( data
->hwnd
, &surface_rect
, alpha
, key
, FALSE
);
1342 release_win_data( data
);
1347 /***********************************************************************
1348 * ANDROID_WindowPosChanged
1350 void ANDROID_WindowPosChanged( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1351 const RECT
*window_rect
, const RECT
*client_rect
,
1352 const RECT
*visible_rect
, const RECT
*valid_rects
,
1353 struct window_surface
*surface
)
1355 struct android_win_data
*data
;
1356 DWORD new_style
= NtUserGetWindowLongW( hwnd
, GWL_STYLE
);
1359 if (!(data
= get_win_data( hwnd
))) return;
1361 data
->window_rect
= *window_rect
;
1362 data
->whole_rect
= *visible_rect
;
1363 data
->client_rect
= *client_rect
;
1365 if (!is_argb_surface( data
->surface
))
1367 if (surface
) window_surface_add_ref( surface
);
1368 if (data
->surface
) window_surface_release( data
->surface
);
1369 data
->surface
= surface
;
1371 if (!data
->parent
) owner
= NtUserGetWindowRelative( hwnd
, GW_OWNER
);
1372 release_win_data( data
);
1374 if (!(swp_flags
& SWP_NOZORDER
)) insert_after
= NtUserGetWindowRelative( hwnd
, GW_HWNDPREV
);
1376 TRACE( "win %p window %s client %s style %08x owner %p after %p flags %08x\n", hwnd
,
1377 wine_dbgstr_rect(window_rect
), wine_dbgstr_rect(client_rect
),
1378 new_style
, owner
, insert_after
, swp_flags
);
1380 ioctl_window_pos_changed( hwnd
, window_rect
, client_rect
, visible_rect
,
1381 new_style
, swp_flags
, insert_after
, owner
);
1385 /***********************************************************************
1386 * ANDROID_ShowWindow
1388 UINT
ANDROID_ShowWindow( HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
)
1390 if (!(NtUserGetWindowLongW( hwnd
, GWL_STYLE
) & WS_MINIMIZE
)) return swp
;
1391 /* always hide icons off-screen */
1392 if (rect
->left
!= -32000 || rect
->top
!= -32000)
1394 OffsetRect( rect
, -32000 - rect
->left
, -32000 - rect
->top
);
1395 swp
&= ~(SWP_NOMOVE
| SWP_NOCLIENTMOVE
);
1401 /*****************************************************************
1404 void ANDROID_SetParent( HWND hwnd
, HWND parent
, HWND old_parent
)
1406 struct android_win_data
*data
;
1408 if (parent
== old_parent
) return;
1409 if (!(data
= get_win_data( hwnd
))) return;
1411 TRACE( "win %p parent %p -> %p\n", hwnd
, old_parent
, parent
);
1413 data
->parent
= (parent
== NtUserGetDesktopWindow()) ? 0 : parent
;
1414 ioctl_set_window_parent( hwnd
, parent
, (float)get_win_monitor_dpi( hwnd
) / NtUserGetDpiForWindow( hwnd
));
1415 release_win_data( data
);
1419 /***********************************************************************
1420 * ANDROID_SetCapture
1422 void ANDROID_SetCapture( HWND hwnd
, UINT flags
)
1424 if (!(flags
& (GUI_INMOVESIZE
| GUI_INMENUMODE
))) return;
1425 ioctl_set_capture( hwnd
);
1429 static BOOL
get_icon_info( HICON handle
, ICONINFOEXW
*ret
)
1431 UNICODE_STRING module
, res_name
;
1434 module
.Buffer
= ret
->szModName
;
1435 module
.MaximumLength
= sizeof(ret
->szModName
) - sizeof(WCHAR
);
1436 res_name
.Buffer
= ret
->szResName
;
1437 res_name
.MaximumLength
= sizeof(ret
->szResName
) - sizeof(WCHAR
);
1438 if (!NtUserGetIconInfo( handle
, &info
, &module
, &res_name
, NULL
, 0 )) return FALSE
;
1439 ret
->fIcon
= info
.fIcon
;
1440 ret
->xHotspot
= info
.xHotspot
;
1441 ret
->yHotspot
= info
.yHotspot
;
1442 ret
->hbmColor
= info
.hbmColor
;
1443 ret
->hbmMask
= info
.hbmMask
;
1444 ret
->wResID
= res_name
.Length
? 0 : LOWORD(res_name
.Buffer
);
1445 ret
->szModName
[module
.Length
] = 0;
1446 ret
->szResName
[res_name
.Length
] = 0;
1451 /***********************************************************************
1454 void ANDROID_SetCursor( HCURSOR handle
)
1456 static HCURSOR last_cursor
;
1457 static DWORD last_cursor_change
;
1459 if (InterlockedExchangePointer( (void **)&last_cursor
, handle
) != handle
||
1460 GetTickCount() - last_cursor_change
> 100)
1462 last_cursor_change
= GetTickCount();
1466 unsigned int width
= 0, height
= 0, *bits
= NULL
;
1470 if (!get_icon_info( handle
, &info
)) return;
1472 if (!(id
= get_cursor_system_id( &info
)))
1474 HDC hdc
= NtGdiCreateCompatibleDC( 0 );
1475 bits
= get_bitmap_argb( hdc
, info
.hbmColor
, info
.hbmMask
, &width
, &height
);
1476 NtGdiDeleteObjectApp( hdc
);
1478 /* make sure hotspot is valid */
1479 if (info
.xHotspot
>= width
|| info
.yHotspot
>= height
)
1481 info
.xHotspot
= width
/ 2;
1482 info
.yHotspot
= height
/ 2;
1485 ioctl_set_cursor( id
, width
, height
, info
.xHotspot
, info
.yHotspot
, bits
);
1486 HeapFree( GetProcessHeap(), 0, bits
);
1487 NtGdiDeleteObjectApp( info
.hbmColor
);
1488 NtGdiDeleteObjectApp( info
.hbmMask
);
1490 else ioctl_set_cursor( 0, 0, 0, 0, 0, NULL
);
1495 /***********************************************************************
1496 * ANDROID_SetWindowStyle
1498 void ANDROID_SetWindowStyle( HWND hwnd
, INT offset
, STYLESTRUCT
*style
)
1500 struct android_win_data
*data
;
1501 DWORD changed
= style
->styleNew
^ style
->styleOld
;
1503 if (hwnd
== NtUserGetDesktopWindow()) return;
1504 if (!(data
= get_win_data( hwnd
))) return;
1506 if (offset
== GWL_EXSTYLE
&& (changed
& WS_EX_LAYERED
)) /* changing WS_EX_LAYERED resets attributes */
1508 if (is_argb_surface( data
->surface
))
1510 if (data
->surface
) window_surface_release( data
->surface
);
1511 data
->surface
= NULL
;
1513 else if (data
->surface
) set_surface_layered( data
->surface
, 255, CLR_INVALID
);
1515 release_win_data( data
);
1519 /***********************************************************************
1520 * ANDROID_SetWindowRgn
1522 void ANDROID_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1524 struct android_win_data
*data
;
1526 if ((data
= get_win_data( hwnd
)))
1528 if (data
->surface
) set_surface_region( data
->surface
, hrgn
);
1529 release_win_data( data
);
1531 else FIXME( "not supported on other process window %p\n", hwnd
);
1535 /***********************************************************************
1536 * ANDROID_SetLayeredWindowAttributes
1538 void ANDROID_SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
1540 struct android_win_data
*data
;
1542 if (!(flags
& LWA_ALPHA
)) alpha
= 255;
1543 if (!(flags
& LWA_COLORKEY
)) key
= CLR_INVALID
;
1545 if ((data
= get_win_data( hwnd
)))
1547 if (data
->surface
) set_surface_layered( data
->surface
, alpha
, key
);
1548 release_win_data( data
);
1553 /*****************************************************************************
1554 * ANDROID_UpdateLayeredWindow
1556 BOOL
ANDROID_UpdateLayeredWindow( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
,
1557 const RECT
*window_rect
)
1559 struct window_surface
*surface
;
1560 struct android_win_data
*data
;
1561 BLENDFUNCTION blend
= { AC_SRC_OVER
, 0, 255, 0 };
1562 COLORREF color_key
= (info
->dwFlags
& ULW_COLORKEY
) ? info
->crKey
: CLR_INVALID
;
1563 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
1564 BITMAPINFO
*bmi
= (BITMAPINFO
*)buffer
;
1565 void *src_bits
, *dst_bits
;
1566 RECT rect
, src_rect
;
1571 if (!(data
= get_win_data( hwnd
))) return FALSE
;
1573 rect
= *window_rect
;
1574 OffsetRect( &rect
, -window_rect
->left
, -window_rect
->top
);
1576 surface
= data
->surface
;
1577 if (!is_argb_surface( surface
))
1579 if (surface
) window_surface_release( surface
);
1583 if (!surface
|| !EqualRect( &surface
->rect
, &rect
))
1585 data
->surface
= create_surface( data
->hwnd
, &rect
, 255, color_key
, TRUE
);
1586 if (surface
) window_surface_release( surface
);
1587 surface
= data
->surface
;
1589 else set_surface_layered( surface
, 255, color_key
);
1591 if (surface
) window_surface_add_ref( surface
);
1592 release_win_data( data
);
1594 if (!surface
) return FALSE
;
1597 window_surface_release( surface
);
1601 dst_bits
= surface
->funcs
->get_info( surface
, bmi
);
1603 if (!(dib
= NtGdiCreateDIBSection( info
->hdcDst
, NULL
, 0, bmi
, DIB_RGB_COLORS
, 0, 0, 0, &src_bits
)))
1605 if (!(hdc
= NtGdiCreateCompatibleDC( 0 ))) goto done
;
1607 NtGdiSelectBitmap( hdc
, dib
);
1609 surface
->funcs
->lock( surface
);
1613 intersect_rect( &rect
, &rect
, info
->prcDirty
);
1614 memcpy( src_bits
, dst_bits
, bmi
->bmiHeader
.biSizeImage
);
1615 NtGdiPatBlt( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, BLACKNESS
);
1618 if (info
->pptSrc
) OffsetRect( &src_rect
, info
->pptSrc
->x
, info
->pptSrc
->y
);
1619 NtGdiTransformPoints( info
->hdcSrc
, (POINT
*)&src_rect
, (POINT
*)&src_rect
, 2, NtGdiDPtoLP
);
1621 ret
= NtGdiAlphaBlend( hdc
, rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1622 info
->hdcSrc
, src_rect
.left
, src_rect
.top
,
1623 src_rect
.right
- src_rect
.left
, src_rect
.bottom
- src_rect
.top
,
1624 (info
->dwFlags
& ULW_ALPHA
) ? *info
->pblend
: blend
, 0 );
1627 memcpy( dst_bits
, src_bits
, bmi
->bmiHeader
.biSizeImage
);
1628 add_bounds_rect( surface
->funcs
->get_bounds( surface
), &rect
);
1631 surface
->funcs
->unlock( surface
);
1632 surface
->funcs
->flush( surface
);
1635 window_surface_release( surface
);
1636 if (hdc
) NtGdiDeleteObjectApp( hdc
);
1637 if (dib
) NtGdiDeleteObjectApp( dib
);
1642 /**********************************************************************
1643 * ANDROID_WindowMessage
1645 LRESULT
ANDROID_WindowMessage( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1647 struct android_win_data
*data
;
1651 case WM_ANDROID_REFRESH
:
1652 if (wp
) /* opengl client window */
1654 update_gl_drawable( hwnd
);
1656 else if ((data
= get_win_data( hwnd
)))
1658 struct window_surface
*surface
= data
->surface
;
1661 surface
->funcs
->lock( surface
);
1662 *surface
->funcs
->get_bounds( surface
) = surface
->rect
;
1663 surface
->funcs
->unlock( surface
);
1664 if (is_argb_surface( surface
)) surface
->funcs
->flush( surface
);
1666 release_win_data( data
);
1670 FIXME( "got window msg %x hwnd %p wp %lx lp %lx\n", msg
, hwnd
, wp
, lp
);
1676 /***********************************************************************
1677 * ANDROID_create_desktop
1679 BOOL CDECL
ANDROID_create_desktop( UINT width
, UINT height
)
1681 /* wait until we receive the surface changed event */
1682 while (!screen_width
)
1684 if (wait_events( 2000 ) != 1)
1686 ERR( "wait timed out\n" );
1689 process_events( QS_ALLINPUT
);