wineps: Copy GetTextExtentExPoint implementation to unixlib.
[wine.git] / dlls / winemac.drv / gdi.c
blobd22532fd3b741d73ed2d37a40b9791de69e610ae
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 CDECL macdrv_CreateDC(PHYSDEV *pdev, LPCWSTR device, LPCWSTR output,
174 const DEVMODEW* initData)
176 MACDRV_PDEVICE *physDev = create_mac_physdev();
178 TRACE("pdev %p hdc %p device %s output %s initData %p\n", pdev,
179 (*pdev)->hdc, debugstr_w(device), debugstr_w(output), initData);
181 if (!physDev) return FALSE;
183 push_dc_driver(pdev, &physDev->dev, &macdrv_funcs.dc_funcs);
184 return TRUE;
188 /**********************************************************************
189 * CreateCompatibleDC (MACDRV.@)
191 static BOOL CDECL macdrv_CreateCompatibleDC(PHYSDEV orig, PHYSDEV *pdev)
193 MACDRV_PDEVICE *physDev = create_mac_physdev();
195 TRACE("orig %p orig->hdc %p pdev %p pdev->hdc %p\n", orig, (orig ? orig->hdc : NULL), pdev,
196 ((pdev && *pdev) ? (*pdev)->hdc : NULL));
198 if (!physDev) return FALSE;
200 push_dc_driver(pdev, &physDev->dev, &macdrv_funcs.dc_funcs);
201 return TRUE;
205 /**********************************************************************
206 * DeleteDC (MACDRV.@)
208 static BOOL CDECL macdrv_DeleteDC(PHYSDEV dev)
210 MACDRV_PDEVICE *physDev = get_macdrv_dev(dev);
212 TRACE("hdc %p\n", dev->hdc);
214 free(physDev);
215 return TRUE;
219 /***********************************************************************
220 * GetDeviceCaps (MACDRV.@)
222 static INT CDECL macdrv_GetDeviceCaps(PHYSDEV dev, INT cap)
224 INT ret;
226 pthread_mutex_lock(&device_data_mutex);
228 if (!device_data_valid) device_init();
230 switch(cap)
232 case HORZSIZE:
233 ret = horz_size;
234 break;
235 case VERTSIZE:
236 ret = vert_size;
237 break;
238 case BITSPIXEL:
239 ret = bits_per_pixel;
240 break;
241 case HORZRES:
242 case VERTRES:
243 default:
244 pthread_mutex_unlock(&device_data_mutex);
245 dev = GET_NEXT_PHYSDEV( dev, pGetDeviceCaps );
246 ret = dev->funcs->pGetDeviceCaps( dev, cap );
247 if ((cap == HORZRES || cap == VERTRES) && retina_on)
248 ret *= 2;
249 return ret;
252 TRACE("cap %d -> %d\n", cap, ret);
254 pthread_mutex_unlock(&device_data_mutex);
255 return ret;
259 static const struct user_driver_funcs macdrv_funcs =
261 .dc_funcs.pCreateCompatibleDC = macdrv_CreateCompatibleDC,
262 .dc_funcs.pCreateDC = macdrv_CreateDC,
263 .dc_funcs.pDeleteDC = macdrv_DeleteDC,
264 .dc_funcs.pGetDeviceCaps = macdrv_GetDeviceCaps,
265 .dc_funcs.pGetDeviceGammaRamp = macdrv_GetDeviceGammaRamp,
266 .dc_funcs.pSetDeviceGammaRamp = macdrv_SetDeviceGammaRamp,
267 .dc_funcs.priority = GDI_PRIORITY_GRAPHICS_DRV,
269 .pActivateKeyboardLayout = macdrv_ActivateKeyboardLayout,
270 .pBeep = macdrv_Beep,
271 .pChangeDisplaySettings = macdrv_ChangeDisplaySettings,
272 .pClipCursor = macdrv_ClipCursor,
273 .pClipboardWindowProc = macdrv_ClipboardWindowProc,
274 .pCreateDesktopWindow = macdrv_CreateDesktopWindow,
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 .pSetFocus = macdrv_SetFocus,
291 .pSetLayeredWindowAttributes = macdrv_SetLayeredWindowAttributes,
292 .pSetParent = macdrv_SetParent,
293 .pSetWindowRgn = macdrv_SetWindowRgn,
294 .pSetWindowStyle = macdrv_SetWindowStyle,
295 .pSetWindowText = macdrv_SetWindowText,
296 .pShowWindow = macdrv_ShowWindow,
297 .pSysCommand =macdrv_SysCommand,
298 .pSystemParametersInfo = macdrv_SystemParametersInfo,
299 .pThreadDetach = macdrv_ThreadDetach,
300 .pToUnicodeEx = macdrv_ToUnicodeEx,
301 .pUnregisterHotKey = macdrv_UnregisterHotKey,
302 .pUpdateClipboard = macdrv_UpdateClipboard,
303 .pUpdateLayeredWindow = macdrv_UpdateLayeredWindow,
304 .pVkKeyScanEx = macdrv_VkKeyScanEx,
305 .pWindowMessage = macdrv_WindowMessage,
306 .pWindowPosChanged = macdrv_WindowPosChanged,
307 .pWindowPosChanging = macdrv_WindowPosChanging,
308 .pwine_get_vulkan_driver = macdrv_wine_get_vulkan_driver,
309 .pwine_get_wgl_driver = macdrv_wine_get_wgl_driver,
313 void init_user_driver(void)
315 __wine_set_user_driver( &macdrv_funcs, WINE_GDI_DRIVER_VERSION );