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 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 palette_size
; /* number of color entries in palette */
53 static int device_data_valid
; /* do the above variables have up-to-date values? */
55 static CRITICAL_SECTION device_data_section
;
56 static CRITICAL_SECTION_DEBUG critsect_debug
=
58 0, 0, &device_data_section
,
59 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
60 0, 0, { (DWORD_PTR
)(__FILE__
": device_data_section") }
62 static CRITICAL_SECTION device_data_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
65 static const WCHAR dpi_key_name
[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
66 static const WCHAR dpi_value_name
[] = {'L','o','g','P','i','x','e','l','s','\0'};
68 static const struct gdi_dc_funcs macdrv_funcs
;
71 /******************************************************************************
74 * get the dpi from the registry
76 static DWORD
get_dpi(void)
81 if (RegOpenKeyW(HKEY_CURRENT_CONFIG
, dpi_key_name
, &hkey
) == ERROR_SUCCESS
)
83 DWORD type
, size
, new_dpi
;
85 size
= sizeof(new_dpi
);
86 if (RegQueryValueExW(hkey
, dpi_value_name
, NULL
, &type
, (void *)&new_dpi
, &size
) == ERROR_SUCCESS
)
88 if (type
== REG_DWORD
&& new_dpi
!= 0)
97 /***********************************************************************
98 * macdrv_get_desktop_rect
100 * Returns the rectangle encompassing all the screens.
102 CGRect
macdrv_get_desktop_rect(void)
105 CGDirectDisplayID displayIDs
[32];
108 EnterCriticalSection(&device_data_section
);
110 if (!device_data_valid
)
112 desktop_rect
= CGRectNull
;
113 if (CGGetActiveDisplayList(sizeof(displayIDs
)/sizeof(displayIDs
[0]),
114 displayIDs
, &count
) != kCGErrorSuccess
||
117 displayIDs
[0] = CGMainDisplayID();
121 for (i
= 0; i
< count
; i
++)
122 desktop_rect
= CGRectUnion(desktop_rect
, CGDisplayBounds(displayIDs
[i
]));
126 LeaveCriticalSection(&device_data_section
);
128 TRACE("%s\n", wine_dbgstr_cgrect(ret
));
134 /**********************************************************************
137 * Perform initializations needed upon creation of the first device.
139 static void device_init(void)
141 CGDirectDisplayID mainDisplay
= CGMainDisplayID();
142 CGSize size_mm
= CGDisplayScreenSize(mainDisplay
);
143 CGDisplayModeRef mode
= CGDisplayCopyDisplayMode(mainDisplay
);
144 CGDirectPaletteRef palette
;
146 /* Initialize device caps */
147 log_pixels_x
= log_pixels_y
= get_dpi();
150 size_t width
= CGDisplayPixelsWide(mainDisplay
);
151 size_t height
= CGDisplayPixelsHigh(mainDisplay
);
152 log_pixels_x
= MulDiv(width
, 254, size_mm
.width
* 10);
153 log_pixels_y
= MulDiv(height
, 254, size_mm
.height
* 10);
156 horz_size
= size_mm
.width
;
157 vert_size
= size_mm
.height
;
162 CFStringRef pixelEncoding
= CGDisplayModeCopyPixelEncoding(mode
);
164 horz_res
= CGDisplayModeGetWidth(mode
);
165 vert_res
= CGDisplayModeGetHeight(mode
);
169 if (CFEqual(pixelEncoding
, CFSTR(IO32BitDirectPixels
)))
171 else if (CFEqual(pixelEncoding
, CFSTR(IO16BitDirectPixels
)))
173 else if (CFEqual(pixelEncoding
, CFSTR(IO8BitIndexedPixels
)))
175 CFRelease(pixelEncoding
);
178 CGDisplayModeRelease(mode
);
182 horz_res
= CGDisplayPixelsWide(mainDisplay
);
183 vert_res
= CGDisplayPixelsHigh(mainDisplay
);
186 macdrv_get_desktop_rect();
187 desktop_horz_res
= desktop_rect
.size
.width
;
188 desktop_vert_res
= desktop_rect
.size
.height
;
190 palette
= CGPaletteCreateWithDisplay(mainDisplay
);
193 palette_size
= CGPaletteGetNumberOfSamples(palette
);
194 CGPaletteRelease(palette
);
199 device_data_valid
= TRUE
;
203 void macdrv_reset_device_metrics(void)
205 EnterCriticalSection(&device_data_section
);
206 device_data_valid
= FALSE
;
207 LeaveCriticalSection(&device_data_section
);
211 static MACDRV_PDEVICE
*create_mac_physdev(void)
213 MACDRV_PDEVICE
*physDev
;
215 EnterCriticalSection(&device_data_section
);
216 if (!device_data_valid
) device_init();
217 LeaveCriticalSection(&device_data_section
);
219 if (!(physDev
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*physDev
)))) return NULL
;
225 /**********************************************************************
226 * CreateDC (MACDRV.@)
228 static BOOL
macdrv_CreateDC(PHYSDEV
*pdev
, LPCWSTR driver
, LPCWSTR device
,
229 LPCWSTR output
, const DEVMODEW
* initData
)
231 MACDRV_PDEVICE
*physDev
= create_mac_physdev();
233 TRACE("pdev %p hdc %p driver %s device %s output %s initData %p\n", pdev
,
234 (*pdev
)->hdc
, debugstr_w(driver
),debugstr_w(device
), debugstr_w(output
),
237 if (!physDev
) return FALSE
;
239 push_dc_driver(pdev
, &physDev
->dev
, &macdrv_funcs
);
244 /**********************************************************************
245 * CreateCompatibleDC (MACDRV.@)
247 static BOOL
macdrv_CreateCompatibleDC(PHYSDEV orig
, PHYSDEV
*pdev
)
249 MACDRV_PDEVICE
*physDev
= create_mac_physdev();
251 TRACE("orig %p orig->hdc %p pdev %p pdev->hdc %p\n", orig
, (orig
? orig
->hdc
: NULL
), pdev
,
252 ((pdev
&& *pdev
) ? (*pdev
)->hdc
: NULL
));
254 if (!physDev
) return FALSE
;
256 push_dc_driver(pdev
, &physDev
->dev
, &macdrv_funcs
);
261 /**********************************************************************
262 * DeleteDC (MACDRV.@)
264 static BOOL
macdrv_DeleteDC(PHYSDEV dev
)
266 MACDRV_PDEVICE
*physDev
= get_macdrv_dev(dev
);
268 TRACE("hdc %p\n", dev
->hdc
);
270 HeapFree(GetProcessHeap(), 0, physDev
);
275 /***********************************************************************
276 * GetDeviceCaps (MACDRV.@)
278 static INT
macdrv_GetDeviceCaps(PHYSDEV dev
, INT cap
)
282 EnterCriticalSection(&device_data_section
);
284 if (!device_data_valid
) device_init();
307 ret
= desktop_horz_res
;
310 ret
= desktop_vert_res
;
313 ret
= bits_per_pixel
;
331 /* MSDN: Number of entries in the device's color table, if the device has
332 * a color depth of no more than 8 bits per pixel.For devices with greater
333 * color depths, -1 is returned. */
334 ret
= (bits_per_pixel
> 8) ? -1 : (1 << bits_per_pixel
);
337 ret
= sizeof(MACDRV_PDEVICE
);
340 ret
= (CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
| CC_WIDE
|
341 CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
| CC_ROUNDRECT
);
344 ret
= (LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
345 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
);
348 ret
= (PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
| PC_SCANLINE
|
349 PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
| PC_INTERIORS
);
352 ret
= (TC_OP_CHARACTER
| TC_OP_STROKE
| TC_CP_STROKE
|
353 TC_CR_ANY
| TC_SF_X_YINDEP
| TC_SA_DOUBLE
| TC_SA_INTEGER
|
354 TC_SA_CONTIN
| TC_UA_ABLE
| TC_SO_ABLE
| TC_RA_ABLE
| TC_VA_ABLE
);
360 /* The observed correspondence between BITSPIXEL and COLORRES is:
361 * BITSPIXEL: 8 -> COLORRES: 18
362 * BITSPIXEL: 16 -> COLORRES: 16
363 * BITSPIXEL: 24 -> COLORRES: 24
364 * (note that bits_per_pixel is never 24)
365 * BITSPIXEL: 32 -> COLORRES: 24 */
366 ret
= (bits_per_pixel
<= 8) ? 18 : (bits_per_pixel
== 32) ? 24 : bits_per_pixel
;
369 ret
= (RC_BITBLT
| RC_BANDING
| RC_SCALING
| RC_BITMAP64
| RC_DI_BITMAP
|
370 RC_DIBTODEV
| RC_BIGFONT
| RC_STRETCHBLT
| RC_STRETCHDIB
| RC_DEVBITS
|
371 (palette_size
? RC_PALETTE
: 0));
374 ret
= (SB_GRAD_RECT
| SB_GRAD_TRI
| SB_CONST_ALPHA
| SB_PIXEL_ALPHA
);
390 FIXME("(%p): CAPS1 is unimplemented, will return 0\n", dev
->hdc
);
391 /* please see wingdi.h for the possible bit-flag values that need
401 case PHYSICALOFFSETX
:
402 case PHYSICALOFFSETY
:
410 FIXME("(%p): unsupported capability %d, will return 0\n", dev
->hdc
, cap
);
415 TRACE("cap %d -> %d\n", cap
, ret
);
418 LeaveCriticalSection(&device_data_section
);
423 static const struct gdi_dc_funcs macdrv_funcs
=
425 NULL
, /* pAbortDoc */
426 NULL
, /* pAbortPath */
427 NULL
, /* pAlphaBlend */
428 NULL
, /* pAngleArc */
431 NULL
, /* pBeginPath */
432 NULL
, /* pBlendImage */
434 NULL
, /* pCloseFigure */
435 macdrv_CreateCompatibleDC
, /* pCreateCompatibleDC */
436 macdrv_CreateDC
, /* pCreateDC */
437 macdrv_DeleteDC
, /* pDeleteDC */
438 NULL
, /* pDeleteObject */
439 NULL
, /* pDeviceCapabilities */
444 NULL
, /* pEnumFonts */
445 NULL
, /* pEnumICMProfiles */
446 NULL
, /* pExcludeClipRect */
447 NULL
, /* pExtDeviceMode */
448 NULL
, /* pExtEscape */
449 NULL
, /* pExtFloodFill */
450 NULL
, /* pExtSelectClipRgn */
451 NULL
, /* pExtTextOut */
452 NULL
, /* pFillPath */
454 NULL
, /* pFlattenPath */
455 NULL
, /* pFontIsLinked */
456 NULL
, /* pFrameRgn */
457 NULL
, /* pGdiComment */
458 NULL
, /* pGdiRealizationInfo */
459 NULL
, /* pGetBoundsRect */
460 NULL
, /* pGetCharABCWidths */
461 NULL
, /* pGetCharABCWidthsI */
462 NULL
, /* pGetCharWidth */
463 macdrv_GetDeviceCaps
, /* pGetDeviceCaps */
464 macdrv_GetDeviceGammaRamp
, /* pGetDeviceGammaRamp */
465 NULL
, /* pGetFontData */
466 NULL
, /* pGetFontUnicodeRanges */
467 NULL
, /* pGetGlyphIndices */
468 NULL
, /* pGetGlyphOutline */
469 NULL
, /* pGetICMProfile */
470 NULL
, /* pGetImage */
471 NULL
, /* pGetKerningPairs */
472 NULL
, /* pGetNearestColor */
473 NULL
, /* pGetOutlineTextMetrics */
474 NULL
, /* pGetPixel */
475 NULL
, /* pGetSystemPaletteEntries */
476 NULL
, /* pGetTextCharsetInfo */
477 NULL
, /* pGetTextExtentExPoint */
478 NULL
, /* pGetTextExtentExPointI */
479 NULL
, /* pGetTextFace */
480 NULL
, /* pGetTextMetrics */
481 NULL
, /* pGradientFill */
482 NULL
, /* pIntersectClipRect */
483 NULL
, /* pInvertRgn */
485 NULL
, /* pModifyWorldTransform */
487 NULL
, /* pOffsetClipRgn */
488 NULL
, /* pOffsetViewportOrg */
489 NULL
, /* pOffsetWindowOrg */
490 NULL
, /* pPaintRgn */
493 NULL
, /* pPolyBezier */
494 NULL
, /* pPolyBezierTo */
495 NULL
, /* pPolyDraw */
496 NULL
, /* pPolyPolygon */
497 NULL
, /* pPolyPolyline */
499 NULL
, /* pPolyline */
500 NULL
, /* pPolylineTo */
501 NULL
, /* pPutImage */
502 NULL
, /* pRealizeDefaultPalette */
503 NULL
, /* pRealizePalette */
504 NULL
, /* pRectangle */
506 NULL
, /* pRestoreDC */
507 NULL
, /* pRoundRect */
509 NULL
, /* pScaleViewportExt */
510 NULL
, /* pScaleWindowExt */
511 NULL
, /* pSelectBitmap */
512 NULL
, /* pSelectBrush */
513 NULL
, /* pSelectClipPath */
514 NULL
, /* pSelectFont */
515 NULL
, /* pSelectPalette */
516 NULL
, /* pSelectPen */
517 NULL
, /* pSetArcDirection */
518 NULL
, /* pSetBkColor */
519 NULL
, /* pSetBkMode */
520 NULL
, /* pSetBoundsRect */
521 NULL
, /* pSetDCBrushColor */
522 NULL
, /* pSetDCPenColor */
523 NULL
, /* pSetDIBitsToDevice */
524 NULL
, /* pSetDeviceClipping */
525 macdrv_SetDeviceGammaRamp
, /* pSetDeviceGammaRamp */
526 NULL
, /* pSetLayout */
527 NULL
, /* pSetMapMode */
528 NULL
, /* pSetMapperFlags */
529 NULL
, /* pSetPixel */
530 NULL
, /* pSetPolyFillMode */
532 NULL
, /* pSetRelAbs */
533 NULL
, /* pSetStretchBltMode */
534 NULL
, /* pSetTextAlign */
535 NULL
, /* pSetTextCharacterExtra */
536 NULL
, /* pSetTextColor */
537 NULL
, /* pSetTextJustification */
538 NULL
, /* pSetViewportExt */
539 NULL
, /* pSetViewportOrg */
540 NULL
, /* pSetWindowExt */
541 NULL
, /* pSetWindowOrg */
542 NULL
, /* pSetWorldTransform */
543 NULL
, /* pStartDoc */
544 NULL
, /* pStartPage */
545 NULL
, /* pStretchBlt */
546 NULL
, /* pStretchDIBits */
547 NULL
, /* pStrokeAndFillPath */
548 NULL
, /* pStrokePath */
549 NULL
, /* pUnrealizePalette */
550 NULL
, /* pWidenPath */
551 macdrv_wine_get_wgl_driver
, /* wine_get_wgl_driver */
552 GDI_PRIORITY_GRAPHICS_DRV
/* priority */
556 /******************************************************************************
557 * macdrv_get_gdi_driver
559 const struct gdi_dc_funcs
* CDECL
macdrv_get_gdi_driver(unsigned int version
)
561 if (version
!= WINE_GDI_DRIVER_VERSION
)
563 ERR("version mismatch, gdi32 wants %u but winemac has %u\n", version
, WINE_GDI_DRIVER_VERSION
);
566 return &macdrv_funcs
;