include: Add event trace flags and guid to evntrace.h.
[wine.git] / dlls / winemac.drv / gdi.c
blob951b569c0c059855c91f0ffa231fbad7ef4a5d94
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 log_pixels_x; /* pixels per logical inch in x direction */
44 static int log_pixels_y; /* pixels per logical inch in y direction */
45 static int horz_size; /* horz. size of screen in millimeters */
46 static int vert_size; /* vert. size of screen in millimeters */
47 static int horz_res; /* width in pixels of screen */
48 static int vert_res; /* height in pixels of screen */
49 static int desktop_horz_res; /* width in pixels of virtual desktop */
50 static int desktop_vert_res; /* height in pixels of virtual desktop */
51 static int bits_per_pixel; /* pixel depth of screen */
52 static int device_data_valid; /* do the above variables have up-to-date values? */
54 static CRITICAL_SECTION device_data_section;
55 static CRITICAL_SECTION_DEBUG critsect_debug =
57 0, 0, &device_data_section,
58 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
59 0, 0, { (DWORD_PTR)(__FILE__ ": device_data_section") }
61 static CRITICAL_SECTION device_data_section = { &critsect_debug, -1, 0, 0, 0, 0 };
64 static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
65 static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'};
67 static const struct gdi_dc_funcs macdrv_funcs;
70 /******************************************************************************
71 * get_dpi
73 * get the dpi from the registry
75 static DWORD get_dpi(void)
77 DWORD dpi = 0;
78 HKEY hkey;
80 if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
82 DWORD type, size, new_dpi;
84 size = sizeof(new_dpi);
85 if (RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (void *)&new_dpi, &size) == ERROR_SUCCESS)
87 if (type == REG_DWORD && new_dpi != 0)
88 dpi = new_dpi;
90 RegCloseKey(hkey);
92 return dpi;
96 /***********************************************************************
97 * macdrv_get_desktop_rect
99 * Returns the rectangle encompassing all the screens.
101 CGRect macdrv_get_desktop_rect(void)
103 CGRect ret;
104 CGDirectDisplayID displayIDs[32];
105 uint32_t count, i;
107 EnterCriticalSection(&device_data_section);
109 if (!device_data_valid)
111 desktop_rect = CGRectNull;
112 if (CGGetActiveDisplayList(sizeof(displayIDs)/sizeof(displayIDs[0]),
113 displayIDs, &count) != kCGErrorSuccess ||
114 !count)
116 displayIDs[0] = CGMainDisplayID();
117 count = 1;
120 for (i = 0; i < count; i++)
121 desktop_rect = CGRectUnion(desktop_rect, CGDisplayBounds(displayIDs[i]));
124 ret = desktop_rect;
125 LeaveCriticalSection(&device_data_section);
127 TRACE("%s\n", wine_dbgstr_cgrect(ret));
129 return ret;
133 /**********************************************************************
134 * device_init
136 * Perform initializations needed upon creation of the first device.
138 static void device_init(void)
140 CGDirectDisplayID mainDisplay = CGMainDisplayID();
141 CGSize size_mm = CGDisplayScreenSize(mainDisplay);
142 CGDisplayModeRef mode = CGDisplayCopyDisplayMode(mainDisplay);
144 /* Initialize device caps */
145 log_pixels_x = log_pixels_y = get_dpi();
146 if (!log_pixels_x)
148 size_t width = CGDisplayPixelsWide(mainDisplay);
149 size_t height = CGDisplayPixelsHigh(mainDisplay);
150 log_pixels_x = MulDiv(width, 254, size_mm.width * 10);
151 log_pixels_y = MulDiv(height, 254, size_mm.height * 10);
154 horz_size = size_mm.width;
155 vert_size = size_mm.height;
157 bits_per_pixel = 32;
158 if (mode)
160 CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(mode);
162 horz_res = CGDisplayModeGetWidth(mode);
163 vert_res = CGDisplayModeGetHeight(mode);
165 if (pixelEncoding)
167 if (CFEqual(pixelEncoding, CFSTR(IO32BitDirectPixels)))
168 bits_per_pixel = 32;
169 else if (CFEqual(pixelEncoding, CFSTR(IO16BitDirectPixels)))
170 bits_per_pixel = 16;
171 else if (CFEqual(pixelEncoding, CFSTR(IO8BitIndexedPixels)))
172 bits_per_pixel = 8;
173 CFRelease(pixelEncoding);
176 CGDisplayModeRelease(mode);
178 else
180 horz_res = CGDisplayPixelsWide(mainDisplay);
181 vert_res = CGDisplayPixelsHigh(mainDisplay);
184 macdrv_get_desktop_rect();
185 desktop_horz_res = desktop_rect.size.width;
186 desktop_vert_res = desktop_rect.size.height;
188 device_data_valid = TRUE;
192 void macdrv_reset_device_metrics(void)
194 EnterCriticalSection(&device_data_section);
195 device_data_valid = FALSE;
196 LeaveCriticalSection(&device_data_section);
200 static MACDRV_PDEVICE *create_mac_physdev(void)
202 MACDRV_PDEVICE *physDev;
204 EnterCriticalSection(&device_data_section);
205 if (!device_data_valid) device_init();
206 LeaveCriticalSection(&device_data_section);
208 if (!(physDev = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev)))) return NULL;
210 return physDev;
214 /**********************************************************************
215 * CreateDC (MACDRV.@)
217 static BOOL macdrv_CreateDC(PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device,
218 LPCWSTR output, const DEVMODEW* initData)
220 MACDRV_PDEVICE *physDev = create_mac_physdev();
222 TRACE("pdev %p hdc %p driver %s device %s output %s initData %p\n", pdev,
223 (*pdev)->hdc, debugstr_w(driver),debugstr_w(device), debugstr_w(output),
224 initData);
226 if (!physDev) return FALSE;
228 push_dc_driver(pdev, &physDev->dev, &macdrv_funcs);
229 return TRUE;
233 /**********************************************************************
234 * CreateCompatibleDC (MACDRV.@)
236 static BOOL macdrv_CreateCompatibleDC(PHYSDEV orig, PHYSDEV *pdev)
238 MACDRV_PDEVICE *physDev = create_mac_physdev();
240 TRACE("orig %p orig->hdc %p pdev %p pdev->hdc %p\n", orig, (orig ? orig->hdc : NULL), pdev,
241 ((pdev && *pdev) ? (*pdev)->hdc : NULL));
243 if (!physDev) return FALSE;
245 push_dc_driver(pdev, &physDev->dev, &macdrv_funcs);
246 return TRUE;
250 /**********************************************************************
251 * DeleteDC (MACDRV.@)
253 static BOOL macdrv_DeleteDC(PHYSDEV dev)
255 MACDRV_PDEVICE *physDev = get_macdrv_dev(dev);
257 TRACE("hdc %p\n", dev->hdc);
259 HeapFree(GetProcessHeap(), 0, physDev);
260 return TRUE;
264 /***********************************************************************
265 * GetDeviceCaps (MACDRV.@)
267 static INT macdrv_GetDeviceCaps(PHYSDEV dev, INT cap)
269 INT ret;
271 EnterCriticalSection(&device_data_section);
273 if (!device_data_valid) device_init();
275 switch(cap)
277 case DRIVERVERSION:
278 ret = 0x300;
279 break;
280 case TECHNOLOGY:
281 ret = DT_RASDISPLAY;
282 break;
283 case HORZSIZE:
284 ret = horz_size;
285 break;
286 case VERTSIZE:
287 ret = vert_size;
288 break;
289 case HORZRES:
290 ret = horz_res;
291 break;
292 case VERTRES:
293 ret = vert_res;
294 break;
295 case DESKTOPHORZRES:
296 ret = desktop_horz_res;
297 break;
298 case DESKTOPVERTRES:
299 ret = desktop_vert_res;
300 break;
301 case BITSPIXEL:
302 ret = bits_per_pixel;
303 break;
304 case PLANES:
305 ret = 1;
306 break;
307 case NUMBRUSHES:
308 ret = -1;
309 break;
310 case NUMPENS:
311 ret = -1;
312 break;
313 case NUMMARKERS:
314 ret = 0;
315 break;
316 case NUMFONTS:
317 ret = 0;
318 break;
319 case NUMCOLORS:
320 /* MSDN: Number of entries in the device's color table, if the device has
321 * a color depth of no more than 8 bits per pixel.For devices with greater
322 * color depths, -1 is returned. */
323 ret = (bits_per_pixel > 8) ? -1 : (1 << bits_per_pixel);
324 break;
325 case PDEVICESIZE:
326 ret = sizeof(MACDRV_PDEVICE);
327 break;
328 case CURVECAPS:
329 ret = (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
330 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
331 break;
332 case LINECAPS:
333 ret = (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
334 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
335 break;
336 case POLYGONALCAPS:
337 ret = (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
338 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
339 break;
340 case TEXTCAPS:
341 ret = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
342 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
343 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
344 break;
345 case CLIPCAPS:
346 ret = CP_REGION;
347 break;
348 case COLORRES:
349 /* The observed correspondence between BITSPIXEL and COLORRES is:
350 * BITSPIXEL: 8 -> COLORRES: 18
351 * BITSPIXEL: 16 -> COLORRES: 16
352 * BITSPIXEL: 24 -> COLORRES: 24
353 * (note that bits_per_pixel is never 24)
354 * BITSPIXEL: 32 -> COLORRES: 24 */
355 ret = (bits_per_pixel <= 8) ? 18 : (bits_per_pixel == 32) ? 24 : bits_per_pixel;
356 break;
357 case RASTERCAPS:
358 ret = (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
359 RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS |
360 (bits_per_pixel <= 8 ? RC_PALETTE : 0));
361 break;
362 case SHADEBLENDCAPS:
363 ret = (SB_GRAD_RECT | SB_GRAD_TRI | SB_CONST_ALPHA | SB_PIXEL_ALPHA);
364 break;
365 case ASPECTX:
366 case ASPECTY:
367 ret = 36;
368 break;
369 case ASPECTXY:
370 ret = 51;
371 break;
372 case LOGPIXELSX:
373 ret = log_pixels_x;
374 break;
375 case LOGPIXELSY:
376 ret = log_pixels_y;
377 break;
378 case CAPS1:
379 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", dev->hdc);
380 /* please see wingdi.h for the possible bit-flag values that need
381 to be returned. */
382 ret = 0;
383 break;
384 case SIZEPALETTE:
385 ret = bits_per_pixel <= 8 ? 1 << bits_per_pixel : 0;
386 break;
387 case NUMRESERVED:
388 case PHYSICALWIDTH:
389 case PHYSICALHEIGHT:
390 case PHYSICALOFFSETX:
391 case PHYSICALOFFSETY:
392 case SCALINGFACTORX:
393 case SCALINGFACTORY:
394 case VREFRESH:
395 case BLTALIGNMENT:
396 ret = 0;
397 break;
398 default:
399 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap);
400 ret = 0;
401 goto done;
404 TRACE("cap %d -> %d\n", cap, ret);
406 done:
407 LeaveCriticalSection(&device_data_section);
408 return ret;
412 static const struct gdi_dc_funcs macdrv_funcs =
414 NULL, /* pAbortDoc */
415 NULL, /* pAbortPath */
416 NULL, /* pAlphaBlend */
417 NULL, /* pAngleArc */
418 NULL, /* pArc */
419 NULL, /* pArcTo */
420 NULL, /* pBeginPath */
421 NULL, /* pBlendImage */
422 NULL, /* pChord */
423 NULL, /* pCloseFigure */
424 macdrv_CreateCompatibleDC, /* pCreateCompatibleDC */
425 macdrv_CreateDC, /* pCreateDC */
426 macdrv_DeleteDC, /* pDeleteDC */
427 NULL, /* pDeleteObject */
428 NULL, /* pDeviceCapabilities */
429 NULL, /* pEllipse */
430 NULL, /* pEndDoc */
431 NULL, /* pEndPage */
432 NULL, /* pEndPath */
433 NULL, /* pEnumFonts */
434 NULL, /* pEnumICMProfiles */
435 NULL, /* pExcludeClipRect */
436 NULL, /* pExtDeviceMode */
437 NULL, /* pExtEscape */
438 NULL, /* pExtFloodFill */
439 NULL, /* pExtSelectClipRgn */
440 NULL, /* pExtTextOut */
441 NULL, /* pFillPath */
442 NULL, /* pFillRgn */
443 NULL, /* pFlattenPath */
444 NULL, /* pFontIsLinked */
445 NULL, /* pFrameRgn */
446 NULL, /* pGdiComment */
447 NULL, /* pGdiRealizationInfo */
448 NULL, /* pGetBoundsRect */
449 NULL, /* pGetCharABCWidths */
450 NULL, /* pGetCharABCWidthsI */
451 NULL, /* pGetCharWidth */
452 macdrv_GetDeviceCaps, /* pGetDeviceCaps */
453 macdrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
454 NULL, /* pGetFontData */
455 NULL, /* pGetFontUnicodeRanges */
456 NULL, /* pGetGlyphIndices */
457 NULL, /* pGetGlyphOutline */
458 NULL, /* pGetICMProfile */
459 NULL, /* pGetImage */
460 NULL, /* pGetKerningPairs */
461 NULL, /* pGetNearestColor */
462 NULL, /* pGetOutlineTextMetrics */
463 NULL, /* pGetPixel */
464 NULL, /* pGetSystemPaletteEntries */
465 NULL, /* pGetTextCharsetInfo */
466 NULL, /* pGetTextExtentExPoint */
467 NULL, /* pGetTextExtentExPointI */
468 NULL, /* pGetTextFace */
469 NULL, /* pGetTextMetrics */
470 NULL, /* pGradientFill */
471 NULL, /* pIntersectClipRect */
472 NULL, /* pInvertRgn */
473 NULL, /* pLineTo */
474 NULL, /* pModifyWorldTransform */
475 NULL, /* pMoveTo */
476 NULL, /* pOffsetClipRgn */
477 NULL, /* pOffsetViewportOrg */
478 NULL, /* pOffsetWindowOrg */
479 NULL, /* pPaintRgn */
480 NULL, /* pPatBlt */
481 NULL, /* pPie */
482 NULL, /* pPolyBezier */
483 NULL, /* pPolyBezierTo */
484 NULL, /* pPolyDraw */
485 NULL, /* pPolyPolygon */
486 NULL, /* pPolyPolyline */
487 NULL, /* pPolygon */
488 NULL, /* pPolyline */
489 NULL, /* pPolylineTo */
490 NULL, /* pPutImage */
491 NULL, /* pRealizeDefaultPalette */
492 NULL, /* pRealizePalette */
493 NULL, /* pRectangle */
494 NULL, /* pResetDC */
495 NULL, /* pRestoreDC */
496 NULL, /* pRoundRect */
497 NULL, /* pSaveDC */
498 NULL, /* pScaleViewportExt */
499 NULL, /* pScaleWindowExt */
500 NULL, /* pSelectBitmap */
501 NULL, /* pSelectBrush */
502 NULL, /* pSelectClipPath */
503 NULL, /* pSelectFont */
504 NULL, /* pSelectPalette */
505 NULL, /* pSelectPen */
506 NULL, /* pSetArcDirection */
507 NULL, /* pSetBkColor */
508 NULL, /* pSetBkMode */
509 NULL, /* pSetBoundsRect */
510 NULL, /* pSetDCBrushColor */
511 NULL, /* pSetDCPenColor */
512 NULL, /* pSetDIBitsToDevice */
513 NULL, /* pSetDeviceClipping */
514 macdrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
515 NULL, /* pSetLayout */
516 NULL, /* pSetMapMode */
517 NULL, /* pSetMapperFlags */
518 NULL, /* pSetPixel */
519 NULL, /* pSetPolyFillMode */
520 NULL, /* pSetROP2 */
521 NULL, /* pSetRelAbs */
522 NULL, /* pSetStretchBltMode */
523 NULL, /* pSetTextAlign */
524 NULL, /* pSetTextCharacterExtra */
525 NULL, /* pSetTextColor */
526 NULL, /* pSetTextJustification */
527 NULL, /* pSetViewportExt */
528 NULL, /* pSetViewportOrg */
529 NULL, /* pSetWindowExt */
530 NULL, /* pSetWindowOrg */
531 NULL, /* pSetWorldTransform */
532 NULL, /* pStartDoc */
533 NULL, /* pStartPage */
534 NULL, /* pStretchBlt */
535 NULL, /* pStretchDIBits */
536 NULL, /* pStrokeAndFillPath */
537 NULL, /* pStrokePath */
538 NULL, /* pUnrealizePalette */
539 NULL, /* pWidenPath */
540 macdrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
541 GDI_PRIORITY_GRAPHICS_DRV /* priority */
545 /******************************************************************************
546 * macdrv_get_gdi_driver
548 const struct gdi_dc_funcs * CDECL macdrv_get_gdi_driver(unsigned int version)
550 if (version != WINE_GDI_DRIVER_VERSION)
552 ERR("version mismatch, gdi32 wants %u but winemac has %u\n", version, WINE_GDI_DRIVER_VERSION);
553 return NULL;
555 return &macdrv_funcs;