wpcap: Handle different layout of the native packet header structure on 32-bit.
[wine.git] / dlls / winemac.drv / gdi.c
blob0b12c65303d6d468d2149095f585c3577336f237
1 /*
2 * Mac graphics driver initialisation functions
4 * Copyright 1996 Alexandre Julliard
5 * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #if 0
23 #pragma makedep unix
24 #endif
26 #include "config.h"
28 #include "macdrv.h"
29 #include "winreg.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(macdrv);
34 typedef struct
36 struct gdi_physdev dev;
37 } MACDRV_PDEVICE;
39 static inline MACDRV_PDEVICE *get_macdrv_dev(PHYSDEV dev)
41 return (MACDRV_PDEVICE*)dev;
45 /* a few dynamic device caps */
46 static CGRect desktop_rect; /* virtual desktop rectangle */
47 static int horz_size; /* horz. size of screen in millimeters */
48 static int vert_size; /* vert. size of screen in millimeters */
49 static int bits_per_pixel; /* pixel depth of screen */
50 static int device_data_valid; /* do the above variables have up-to-date values? */
52 int retina_on = FALSE;
54 static pthread_mutex_t device_data_mutex = PTHREAD_MUTEX_INITIALIZER;
56 static const struct user_driver_funcs macdrv_funcs;
58 /***********************************************************************
59 * compute_desktop_rect
61 static void compute_desktop_rect(void)
63 CGDirectDisplayID displayIDs[32];
64 uint32_t count, i;
66 desktop_rect = CGRectNull;
67 if (CGGetOnlineDisplayList(ARRAY_SIZE(displayIDs), displayIDs, &count) != kCGErrorSuccess ||
68 !count)
70 displayIDs[0] = CGMainDisplayID();
71 count = 1;
74 for (i = 0; i < count; i++)
75 desktop_rect = CGRectUnion(desktop_rect, CGDisplayBounds(displayIDs[i]));
76 desktop_rect = cgrect_win_from_mac(desktop_rect);
80 /***********************************************************************
81 * macdrv_get_desktop_rect
83 * Returns the rectangle encompassing all the screens.
85 CGRect macdrv_get_desktop_rect(void)
87 CGRect ret;
89 pthread_mutex_lock(&device_data_mutex);
91 if (!device_data_valid)
93 check_retina_status();
94 compute_desktop_rect();
96 ret = desktop_rect;
98 pthread_mutex_unlock(&device_data_mutex);
100 TRACE("%s\n", wine_dbgstr_cgrect(ret));
102 return ret;
106 /**********************************************************************
107 * device_init
109 * Perform initializations needed upon creation of the first device.
111 static void device_init(void)
113 CGDirectDisplayID mainDisplay = CGMainDisplayID();
114 CGSize size_mm = CGDisplayScreenSize(mainDisplay);
115 CGDisplayModeRef mode = CGDisplayCopyDisplayMode(mainDisplay);
117 check_retina_status();
119 /* Initialize device caps */
120 horz_size = size_mm.width;
121 vert_size = size_mm.height;
123 bits_per_pixel = 32;
124 if (mode)
126 CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
128 if (pixelEncoding)
130 if (CFEqual(pixelEncoding, CFSTR(IO32BitDirectPixels)))
131 bits_per_pixel = 32;
132 else if (CFEqual(pixelEncoding, CFSTR(IO16BitDirectPixels)))
133 bits_per_pixel = 16;
134 else if (CFEqual(pixelEncoding, CFSTR(IO8BitIndexedPixels)))
135 bits_per_pixel = 8;
136 CFRelease(pixelEncoding);
139 CGDisplayModeRelease(mode);
142 compute_desktop_rect();
144 device_data_valid = TRUE;
148 void macdrv_reset_device_metrics(void)
150 pthread_mutex_lock(&device_data_mutex);
151 device_data_valid = FALSE;
152 pthread_mutex_unlock(&device_data_mutex);
156 static MACDRV_PDEVICE *create_mac_physdev(void)
158 MACDRV_PDEVICE *physDev;
160 pthread_mutex_lock(&device_data_mutex);
161 if (!device_data_valid) device_init();
162 pthread_mutex_unlock(&device_data_mutex);
164 if (!(physDev = calloc(1, sizeof(*physDev)))) return NULL;
166 return physDev;
170 /**********************************************************************
171 * CreateDC (MACDRV.@)
173 static BOOL macdrv_CreateDC(PHYSDEV *pdev, LPCWSTR device, LPCWSTR output, const DEVMODEW* initData)
175 MACDRV_PDEVICE *physDev = create_mac_physdev();
177 TRACE("pdev %p hdc %p device %s output %s initData %p\n", pdev,
178 (*pdev)->hdc, debugstr_w(device), debugstr_w(output), initData);
180 if (!physDev) return FALSE;
182 push_dc_driver(pdev, &physDev->dev, &macdrv_funcs.dc_funcs);
183 return TRUE;
187 /**********************************************************************
188 * CreateCompatibleDC (MACDRV.@)
190 static BOOL macdrv_CreateCompatibleDC(PHYSDEV orig, PHYSDEV *pdev)
192 MACDRV_PDEVICE *physDev = create_mac_physdev();
194 TRACE("orig %p orig->hdc %p pdev %p pdev->hdc %p\n", orig, (orig ? orig->hdc : NULL), pdev,
195 ((pdev && *pdev) ? (*pdev)->hdc : NULL));
197 if (!physDev) return FALSE;
199 push_dc_driver(pdev, &physDev->dev, &macdrv_funcs.dc_funcs);
200 return TRUE;
204 /**********************************************************************
205 * DeleteDC (MACDRV.@)
207 static BOOL macdrv_DeleteDC(PHYSDEV dev)
209 MACDRV_PDEVICE *physDev = get_macdrv_dev(dev);
211 TRACE("hdc %p\n", dev->hdc);
213 free(physDev);
214 return TRUE;
218 /***********************************************************************
219 * GetDeviceCaps (MACDRV.@)
221 static INT macdrv_GetDeviceCaps(PHYSDEV dev, INT cap)
223 INT ret;
225 pthread_mutex_lock(&device_data_mutex);
227 if (!device_data_valid) device_init();
229 switch(cap)
231 case HORZSIZE:
232 ret = horz_size;
233 break;
234 case VERTSIZE:
235 ret = vert_size;
236 break;
237 case BITSPIXEL:
238 ret = bits_per_pixel;
239 break;
240 case HORZRES:
241 case VERTRES:
242 default:
243 pthread_mutex_unlock(&device_data_mutex);
244 dev = GET_NEXT_PHYSDEV( dev, pGetDeviceCaps );
245 ret = dev->funcs->pGetDeviceCaps( dev, cap );
246 if ((cap == HORZRES || cap == VERTRES) && retina_on)
247 ret *= 2;
248 return ret;
251 TRACE("cap %d -> %d\n", cap, ret);
253 pthread_mutex_unlock(&device_data_mutex);
254 return ret;
258 static const struct user_driver_funcs macdrv_funcs =
260 .dc_funcs.pCreateCompatibleDC = macdrv_CreateCompatibleDC,
261 .dc_funcs.pCreateDC = macdrv_CreateDC,
262 .dc_funcs.pDeleteDC = macdrv_DeleteDC,
263 .dc_funcs.pGetDeviceCaps = macdrv_GetDeviceCaps,
264 .dc_funcs.pGetDeviceGammaRamp = macdrv_GetDeviceGammaRamp,
265 .dc_funcs.pSetDeviceGammaRamp = macdrv_SetDeviceGammaRamp,
266 .dc_funcs.priority = GDI_PRIORITY_GRAPHICS_DRV,
268 .pActivateKeyboardLayout = macdrv_ActivateKeyboardLayout,
269 .pBeep = macdrv_Beep,
270 .pChangeDisplaySettings = macdrv_ChangeDisplaySettings,
271 .pClipCursor = macdrv_ClipCursor,
272 .pNotifyIcon = macdrv_NotifyIcon,
273 .pCleanupIcons = macdrv_CleanupIcons,
274 .pClipboardWindowProc = macdrv_ClipboardWindowProc,
275 .pDesktopWindowProc = macdrv_DesktopWindowProc,
276 .pDestroyCursorIcon = macdrv_DestroyCursorIcon,
277 .pDestroyWindow = macdrv_DestroyWindow,
278 .pGetCurrentDisplaySettings = macdrv_GetCurrentDisplaySettings,
279 .pGetDisplayDepth = macdrv_GetDisplayDepth,
280 .pUpdateDisplayDevices = macdrv_UpdateDisplayDevices,
281 .pGetCursorPos = macdrv_GetCursorPos,
282 .pGetKeyboardLayoutList = macdrv_GetKeyboardLayoutList,
283 .pGetKeyNameText = macdrv_GetKeyNameText,
284 .pMapVirtualKeyEx = macdrv_MapVirtualKeyEx,
285 .pProcessEvents = macdrv_ProcessEvents,
286 .pRegisterHotKey = macdrv_RegisterHotKey,
287 .pSetCapture = macdrv_SetCapture,
288 .pSetCursor = macdrv_SetCursor,
289 .pSetCursorPos = macdrv_SetCursorPos,
290 .pSetDesktopWindow = macdrv_SetDesktopWindow,
291 .pSetFocus = macdrv_SetFocus,
292 .pSetLayeredWindowAttributes = macdrv_SetLayeredWindowAttributes,
293 .pSetParent = macdrv_SetParent,
294 .pSetWindowRgn = macdrv_SetWindowRgn,
295 .pSetWindowStyle = macdrv_SetWindowStyle,
296 .pSetWindowText = macdrv_SetWindowText,
297 .pShowWindow = macdrv_ShowWindow,
298 .pSysCommand =macdrv_SysCommand,
299 .pSystemParametersInfo = macdrv_SystemParametersInfo,
300 .pThreadDetach = macdrv_ThreadDetach,
301 .pToUnicodeEx = macdrv_ToUnicodeEx,
302 .pUnregisterHotKey = macdrv_UnregisterHotKey,
303 .pUpdateClipboard = macdrv_UpdateClipboard,
304 .pCreateLayeredWindow = macdrv_CreateLayeredWindow,
305 .pUpdateLayeredWindow = macdrv_UpdateLayeredWindow,
306 .pVkKeyScanEx = macdrv_VkKeyScanEx,
307 .pImeProcessKey = macdrv_ImeProcessKey,
308 .pNotifyIMEStatus = macdrv_NotifyIMEStatus,
309 .pWindowMessage = macdrv_WindowMessage,
310 .pWindowPosChanged = macdrv_WindowPosChanged,
311 .pWindowPosChanging = macdrv_WindowPosChanging,
312 .pCreateWindowSurface = macdrv_CreateWindowSurface,
313 .pVulkanInit = macdrv_VulkanInit,
314 .pwine_get_wgl_driver = macdrv_wine_get_wgl_driver,
318 void init_user_driver(void)
320 __wine_set_user_driver( &macdrv_funcs, WINE_GDI_DRIVER_VERSION );