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
27 WINE_DEFAULT_DEBUG_CHANNEL(macdrv
);
32 struct gdi_physdev dev
;
35 static inline MACDRV_PDEVICE
*get_macdrv_dev(PHYSDEV dev
)
37 return (MACDRV_PDEVICE
*)dev
;
41 /* a few dynamic device caps */
42 static CGRect desktop_rect
; /* virtual desktop rectangle */
43 static int horz_size
; /* horz. size of screen in millimeters */
44 static int vert_size
; /* vert. size of screen in millimeters */
45 static int bits_per_pixel
; /* pixel depth of screen */
46 static int device_data_valid
; /* do the above variables have up-to-date values? */
48 int retina_on
= FALSE
;
50 static CRITICAL_SECTION device_data_section
;
51 static CRITICAL_SECTION_DEBUG critsect_debug
=
53 0, 0, &device_data_section
,
54 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
55 0, 0, { (DWORD_PTR
)(__FILE__
": device_data_section") }
57 static CRITICAL_SECTION device_data_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
60 static const struct user_driver_funcs macdrv_funcs
;
62 /***********************************************************************
63 * compute_desktop_rect
65 static void compute_desktop_rect(void)
67 CGDirectDisplayID displayIDs
[32];
70 desktop_rect
= CGRectNull
;
71 if (CGGetOnlineDisplayList(ARRAY_SIZE(displayIDs
), displayIDs
, &count
) != kCGErrorSuccess
||
74 displayIDs
[0] = CGMainDisplayID();
78 for (i
= 0; i
< count
; i
++)
79 desktop_rect
= CGRectUnion(desktop_rect
, CGDisplayBounds(displayIDs
[i
]));
80 desktop_rect
= cgrect_win_from_mac(desktop_rect
);
84 /***********************************************************************
85 * macdrv_get_desktop_rect
87 * Returns the rectangle encompassing all the screens.
89 CGRect
macdrv_get_desktop_rect(void)
93 EnterCriticalSection(&device_data_section
);
95 if (!device_data_valid
)
97 check_retina_status();
98 compute_desktop_rect();
102 LeaveCriticalSection(&device_data_section
);
104 TRACE("%s\n", wine_dbgstr_cgrect(ret
));
110 /**********************************************************************
113 * Perform initializations needed upon creation of the first device.
115 static void device_init(void)
117 CGDirectDisplayID mainDisplay
= CGMainDisplayID();
118 CGSize size_mm
= CGDisplayScreenSize(mainDisplay
);
119 CGDisplayModeRef mode
= CGDisplayCopyDisplayMode(mainDisplay
);
121 check_retina_status();
123 /* Initialize device caps */
124 horz_size
= size_mm
.width
;
125 vert_size
= size_mm
.height
;
130 CFStringRef pixelEncoding
= CGDisplayModeCopyPixelEncoding(mode
);
134 if (CFEqual(pixelEncoding
, CFSTR(IO32BitDirectPixels
)))
136 else if (CFEqual(pixelEncoding
, CFSTR(IO16BitDirectPixels
)))
138 else if (CFEqual(pixelEncoding
, CFSTR(IO8BitIndexedPixels
)))
140 CFRelease(pixelEncoding
);
143 CGDisplayModeRelease(mode
);
146 compute_desktop_rect();
148 device_data_valid
= TRUE
;
152 void macdrv_reset_device_metrics(void)
154 EnterCriticalSection(&device_data_section
);
155 device_data_valid
= FALSE
;
156 LeaveCriticalSection(&device_data_section
);
160 static MACDRV_PDEVICE
*create_mac_physdev(void)
162 MACDRV_PDEVICE
*physDev
;
164 EnterCriticalSection(&device_data_section
);
165 if (!device_data_valid
) device_init();
166 LeaveCriticalSection(&device_data_section
);
168 if (!(physDev
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*physDev
)))) return NULL
;
174 /**********************************************************************
175 * CreateDC (MACDRV.@)
177 static BOOL CDECL
macdrv_CreateDC(PHYSDEV
*pdev
, LPCWSTR device
, LPCWSTR output
,
178 const DEVMODEW
* initData
)
180 MACDRV_PDEVICE
*physDev
= create_mac_physdev();
182 TRACE("pdev %p hdc %p device %s output %s initData %p\n", pdev
,
183 (*pdev
)->hdc
, debugstr_w(device
), debugstr_w(output
), initData
);
185 if (!physDev
) return FALSE
;
187 push_dc_driver(pdev
, &physDev
->dev
, &macdrv_funcs
.dc_funcs
);
192 /**********************************************************************
193 * CreateCompatibleDC (MACDRV.@)
195 static BOOL CDECL
macdrv_CreateCompatibleDC(PHYSDEV orig
, PHYSDEV
*pdev
)
197 MACDRV_PDEVICE
*physDev
= create_mac_physdev();
199 TRACE("orig %p orig->hdc %p pdev %p pdev->hdc %p\n", orig
, (orig
? orig
->hdc
: NULL
), pdev
,
200 ((pdev
&& *pdev
) ? (*pdev
)->hdc
: NULL
));
202 if (!physDev
) return FALSE
;
204 push_dc_driver(pdev
, &physDev
->dev
, &macdrv_funcs
.dc_funcs
);
209 /**********************************************************************
210 * DeleteDC (MACDRV.@)
212 static BOOL CDECL
macdrv_DeleteDC(PHYSDEV dev
)
214 MACDRV_PDEVICE
*physDev
= get_macdrv_dev(dev
);
216 TRACE("hdc %p\n", dev
->hdc
);
218 HeapFree(GetProcessHeap(), 0, physDev
);
223 /***********************************************************************
224 * GetDeviceCaps (MACDRV.@)
226 static INT CDECL
macdrv_GetDeviceCaps(PHYSDEV dev
, INT cap
)
230 EnterCriticalSection(&device_data_section
);
232 if (!device_data_valid
) device_init();
243 ret
= bits_per_pixel
;
248 LeaveCriticalSection(&device_data_section
);
249 dev
= GET_NEXT_PHYSDEV( dev
, pGetDeviceCaps
);
250 ret
= dev
->funcs
->pGetDeviceCaps( dev
, cap
);
251 if ((cap
== HORZRES
|| cap
== VERTRES
) && retina_on
)
256 TRACE("cap %d -> %d\n", cap
, ret
);
258 LeaveCriticalSection(&device_data_section
);
263 static const struct user_driver_funcs macdrv_funcs
=
265 .dc_funcs
.pCreateCompatibleDC
= macdrv_CreateCompatibleDC
,
266 .dc_funcs
.pCreateDC
= macdrv_CreateDC
,
267 .dc_funcs
.pDeleteDC
= macdrv_DeleteDC
,
268 .dc_funcs
.pGetDeviceCaps
= macdrv_GetDeviceCaps
,
269 .dc_funcs
.pGetDeviceGammaRamp
= macdrv_GetDeviceGammaRamp
,
270 .dc_funcs
.pSetDeviceGammaRamp
= macdrv_SetDeviceGammaRamp
,
271 .dc_funcs
.priority
= GDI_PRIORITY_GRAPHICS_DRV
,
273 .pActivateKeyboardLayout
= macdrv_ActivateKeyboardLayout
,
274 .pBeep
= macdrv_Beep
,
275 .pChangeDisplaySettingsEx
= macdrv_ChangeDisplaySettingsEx
,
276 .pClipCursor
= macdrv_ClipCursor
,
277 .pCreateDesktopWindow
= macdrv_CreateDesktopWindow
,
278 .pCreateWindow
= macdrv_CreateWindow
,
279 .pDestroyCursorIcon
= macdrv_DestroyCursorIcon
,
280 .pDestroyWindow
= macdrv_DestroyWindow
,
281 .pEnumDisplaySettingsEx
= macdrv_EnumDisplaySettingsEx
,
282 .pUpdateDisplayDevices
= macdrv_UpdateDisplayDevices
,
283 .pGetCursorPos
= macdrv_GetCursorPos
,
284 .pGetKeyboardLayoutList
= macdrv_GetKeyboardLayoutList
,
285 .pGetKeyNameText
= macdrv_GetKeyNameText
,
286 .pMapVirtualKeyEx
= macdrv_MapVirtualKeyEx
,
287 .pMsgWaitForMultipleObjectsEx
= macdrv_MsgWaitForMultipleObjectsEx
,
288 .pRegisterHotKey
= macdrv_RegisterHotKey
,
289 .pSetCapture
= macdrv_SetCapture
,
290 .pSetCursor
= macdrv_SetCursor
,
291 .pSetCursorPos
= macdrv_SetCursorPos
,
292 .pSetFocus
= macdrv_SetFocus
,
293 .pSetLayeredWindowAttributes
= macdrv_SetLayeredWindowAttributes
,
294 .pSetParent
= macdrv_SetParent
,
295 .pSetWindowRgn
= macdrv_SetWindowRgn
,
296 .pSetWindowStyle
= macdrv_SetWindowStyle
,
297 .pSetWindowText
= macdrv_SetWindowText
,
298 .pShowWindow
= macdrv_ShowWindow
,
299 .pSysCommand
=macdrv_SysCommand
,
300 .pSystemParametersInfo
= macdrv_SystemParametersInfo
,
301 .pThreadDetach
= macdrv_ThreadDetach
,
302 .pToUnicodeEx
= macdrv_ToUnicodeEx
,
303 .pUnregisterHotKey
= macdrv_UnregisterHotKey
,
304 .pUpdateClipboard
= macdrv_UpdateClipboard
,
305 .pUpdateLayeredWindow
= macdrv_UpdateLayeredWindow
,
306 .pVkKeyScanEx
= macdrv_VkKeyScanEx
,
307 .pWindowMessage
= macdrv_WindowMessage
,
308 .pWindowPosChanged
= macdrv_WindowPosChanged
,
309 .pWindowPosChanging
= macdrv_WindowPosChanging
,
310 .pwine_get_vulkan_driver
= macdrv_wine_get_vulkan_driver
,
311 .pwine_get_wgl_driver
= macdrv_wine_get_wgl_driver
,
315 void init_user_driver(void)
317 __wine_set_user_driver( &macdrv_funcs
, WINE_GDI_DRIVER_VERSION
);