d3dx10: Check device in d3dx10_sprite_GetDevice().
[wine.git] / dlls / winemac.drv / gdi.c
blob42c9998b3fafc486325a04c81a192fcfda555349
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 #include "config.h"
24 #include "macdrv.h"
25 #include "winreg.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(macdrv);
30 typedef struct
32 struct gdi_physdev dev;
33 } MACDRV_PDEVICE;
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 gdi_dc_funcs macdrv_funcs;
62 /***********************************************************************
63 * compute_desktop_rect
65 static void compute_desktop_rect(void)
67 CGDirectDisplayID displayIDs[32];
68 uint32_t count, i;
70 desktop_rect = CGRectNull;
71 if (CGGetOnlineDisplayList(ARRAY_SIZE(displayIDs), displayIDs, &count) != kCGErrorSuccess ||
72 !count)
74 displayIDs[0] = CGMainDisplayID();
75 count = 1;
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)
91 CGRect ret;
93 EnterCriticalSection(&device_data_section);
95 if (!device_data_valid)
97 check_retina_status();
98 compute_desktop_rect();
100 ret = desktop_rect;
102 LeaveCriticalSection(&device_data_section);
104 TRACE("%s\n", wine_dbgstr_cgrect(ret));
106 return ret;
110 /**********************************************************************
111 * device_init
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;
127 bits_per_pixel = 32;
128 if (mode)
130 CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
132 if (pixelEncoding)
134 if (CFEqual(pixelEncoding, CFSTR(IO32BitDirectPixels)))
135 bits_per_pixel = 32;
136 else if (CFEqual(pixelEncoding, CFSTR(IO16BitDirectPixels)))
137 bits_per_pixel = 16;
138 else if (CFEqual(pixelEncoding, CFSTR(IO8BitIndexedPixels)))
139 bits_per_pixel = 8;
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;
170 return physDev;
174 /**********************************************************************
175 * CreateDC (MACDRV.@)
177 static BOOL CDECL macdrv_CreateDC(PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
178 LPCWSTR output, const DEVMODEW* initData)
180 MACDRV_PDEVICE *physDev = create_mac_physdev();
182 TRACE("pdev %p hdc %p driver %s device %s output %s initData %p\n", pdev,
183 (*pdev)->hdc, debugstr_w(driver),debugstr_w(device), debugstr_w(output),
184 initData);
186 if (!physDev) return FALSE;
188 push_dc_driver(pdev, &physDev->dev, &macdrv_funcs);
189 return TRUE;
193 /**********************************************************************
194 * CreateCompatibleDC (MACDRV.@)
196 static BOOL CDECL macdrv_CreateCompatibleDC(PHYSDEV orig, PHYSDEV *pdev)
198 MACDRV_PDEVICE *physDev = create_mac_physdev();
200 TRACE("orig %p orig->hdc %p pdev %p pdev->hdc %p\n", orig, (orig ? orig->hdc : NULL), pdev,
201 ((pdev && *pdev) ? (*pdev)->hdc : NULL));
203 if (!physDev) return FALSE;
205 push_dc_driver(pdev, &physDev->dev, &macdrv_funcs);
206 return TRUE;
210 /**********************************************************************
211 * DeleteDC (MACDRV.@)
213 static BOOL CDECL macdrv_DeleteDC(PHYSDEV dev)
215 MACDRV_PDEVICE *physDev = get_macdrv_dev(dev);
217 TRACE("hdc %p\n", dev->hdc);
219 HeapFree(GetProcessHeap(), 0, physDev);
220 return TRUE;
224 /***********************************************************************
225 * GetDeviceCaps (MACDRV.@)
227 static INT CDECL macdrv_GetDeviceCaps(PHYSDEV dev, INT cap)
229 INT ret;
231 EnterCriticalSection(&device_data_section);
233 if (!device_data_valid) device_init();
235 switch(cap)
237 case HORZSIZE:
238 ret = horz_size;
239 break;
240 case VERTSIZE:
241 ret = vert_size;
242 break;
243 case BITSPIXEL:
244 ret = bits_per_pixel;
245 break;
246 case HORZRES:
247 case VERTRES:
248 default:
249 LeaveCriticalSection(&device_data_section);
250 dev = GET_NEXT_PHYSDEV( dev, pGetDeviceCaps );
251 ret = dev->funcs->pGetDeviceCaps( dev, cap );
252 if ((cap == HORZRES || cap == VERTRES) && retina_on)
253 ret *= 2;
254 return ret;
257 TRACE("cap %d -> %d\n", cap, ret);
259 LeaveCriticalSection(&device_data_section);
260 return ret;
264 static const struct gdi_dc_funcs macdrv_funcs =
266 NULL, /* pAbortDoc */
267 NULL, /* pAbortPath */
268 NULL, /* pAlphaBlend */
269 NULL, /* pAngleArc */
270 NULL, /* pArc */
271 NULL, /* pArcTo */
272 NULL, /* pBeginPath */
273 NULL, /* pBlendImage */
274 NULL, /* pChord */
275 NULL, /* pCloseFigure */
276 macdrv_CreateCompatibleDC, /* pCreateCompatibleDC */
277 macdrv_CreateDC, /* pCreateDC */
278 macdrv_DeleteDC, /* pDeleteDC */
279 NULL, /* pDeleteObject */
280 NULL, /* pDeviceCapabilities */
281 NULL, /* pEllipse */
282 NULL, /* pEndDoc */
283 NULL, /* pEndPage */
284 NULL, /* pEndPath */
285 NULL, /* pEnumFonts */
286 NULL, /* pEnumICMProfiles */
287 NULL, /* pExtDeviceMode */
288 NULL, /* pExtEscape */
289 NULL, /* pExtFloodFill */
290 NULL, /* pExtTextOut */
291 NULL, /* pFillPath */
292 NULL, /* pFillRgn */
293 NULL, /* pFontIsLinked */
294 NULL, /* pFrameRgn */
295 NULL, /* pGetBoundsRect */
296 NULL, /* pGetCharABCWidths */
297 NULL, /* pGetCharABCWidthsI */
298 NULL, /* pGetCharWidth */
299 NULL, /* pGetCharWidthInfo */
300 macdrv_GetDeviceCaps, /* pGetDeviceCaps */
301 macdrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
302 NULL, /* pGetFontData */
303 NULL, /* pGetFontRealizationInfo */
304 NULL, /* pGetFontUnicodeRanges */
305 NULL, /* pGetGlyphIndices */
306 NULL, /* pGetGlyphOutline */
307 NULL, /* pGetICMProfile */
308 NULL, /* pGetImage */
309 NULL, /* pGetKerningPairs */
310 NULL, /* pGetNearestColor */
311 NULL, /* pGetOutlineTextMetrics */
312 NULL, /* pGetPixel */
313 NULL, /* pGetSystemPaletteEntries */
314 NULL, /* pGetTextCharsetInfo */
315 NULL, /* pGetTextExtentExPoint */
316 NULL, /* pGetTextExtentExPointI */
317 NULL, /* pGetTextFace */
318 NULL, /* pGetTextMetrics */
319 NULL, /* pGradientFill */
320 NULL, /* pInvertRgn */
321 NULL, /* pLineTo */
322 NULL, /* pMoveTo */
323 NULL, /* pPaintRgn */
324 NULL, /* pPatBlt */
325 NULL, /* pPie */
326 NULL, /* pPolyBezier */
327 NULL, /* pPolyBezierTo */
328 NULL, /* pPolyDraw */
329 NULL, /* pPolyPolygon */
330 NULL, /* pPolyPolyline */
331 NULL, /* pPolylineTo */
332 NULL, /* pPutImage */
333 NULL, /* pRealizeDefaultPalette */
334 NULL, /* pRealizePalette */
335 NULL, /* pRectangle */
336 NULL, /* pResetDC */
337 NULL, /* pRoundRect */
338 NULL, /* pSelectBitmap */
339 NULL, /* pSelectBrush */
340 NULL, /* pSelectFont */
341 NULL, /* pSelectPen */
342 NULL, /* pSetBkColor */
343 NULL, /* pSetBoundsRect */
344 NULL, /* pSetDCBrushColor */
345 NULL, /* pSetDCPenColor */
346 NULL, /* pSetDIBitsToDevice */
347 NULL, /* pSetDeviceClipping */
348 macdrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
349 NULL, /* pSetPixel */
350 NULL, /* pSetTextColor */
351 NULL, /* pStartDoc */
352 NULL, /* pStartPage */
353 NULL, /* pStretchBlt */
354 NULL, /* pStretchDIBits */
355 NULL, /* pStrokeAndFillPath */
356 NULL, /* pStrokePath */
357 NULL, /* pUnrealizePalette */
358 NULL, /* pD3DKMTCheckVidPnExclusiveOwnership */
359 NULL, /* pD3DKMTSetVidPnSourceOwner */
360 macdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
361 macdrv_wine_get_vulkan_driver, /* wine_get_vulkan_driver */
362 GDI_PRIORITY_GRAPHICS_DRV /* priority */
366 /******************************************************************************
367 * macdrv_get_gdi_driver
369 const struct gdi_dc_funcs * CDECL macdrv_get_gdi_driver(unsigned int version)
371 if (version != WINE_GDI_DRIVER_VERSION)
373 ERR("version mismatch, gdi32 wants %u but winemac has %u\n", version, WINE_GDI_DRIVER_VERSION);
374 return NULL;
376 return &macdrv_funcs;