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 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 /******************************************************************************
73 * get the dpi from the registry
75 static DWORD
get_dpi(void)
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)
96 /***********************************************************************
97 * macdrv_get_desktop_rect
99 * Returns the rectangle encompassing all the screens.
101 CGRect
macdrv_get_desktop_rect(void)
104 CGDirectDisplayID displayIDs
[32];
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
||
116 displayIDs
[0] = CGMainDisplayID();
120 for (i
= 0; i
< count
; i
++)
121 desktop_rect
= CGRectUnion(desktop_rect
, CGDisplayBounds(displayIDs
[i
]));
125 LeaveCriticalSection(&device_data_section
);
127 TRACE("%s\n", wine_dbgstr_cgrect(ret
));
133 /**********************************************************************
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();
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
;
160 CFStringRef pixelEncoding
= CGDisplayModeCopyPixelEncoding(mode
);
162 horz_res
= CGDisplayModeGetWidth(mode
);
163 vert_res
= CGDisplayModeGetHeight(mode
);
167 if (CFEqual(pixelEncoding
, CFSTR(IO32BitDirectPixels
)))
169 else if (CFEqual(pixelEncoding
, CFSTR(IO16BitDirectPixels
)))
171 else if (CFEqual(pixelEncoding
, CFSTR(IO8BitIndexedPixels
)))
173 CFRelease(pixelEncoding
);
176 CGDisplayModeRelease(mode
);
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
;
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
),
226 if (!physDev
) return FALSE
;
228 push_dc_driver(pdev
, &physDev
->dev
, &macdrv_funcs
);
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
);
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
);
264 /***********************************************************************
265 * GetDeviceCaps (MACDRV.@)
267 static INT
macdrv_GetDeviceCaps(PHYSDEV dev
, INT cap
)
271 EnterCriticalSection(&device_data_section
);
273 if (!device_data_valid
) device_init();
296 ret
= desktop_horz_res
;
299 ret
= desktop_vert_res
;
302 ret
= bits_per_pixel
;
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
);
326 ret
= sizeof(MACDRV_PDEVICE
);
329 ret
= (CC_CIRCLES
| CC_PIE
| CC_CHORD
| CC_ELLIPSES
| CC_WIDE
|
330 CC_STYLED
| CC_WIDESTYLED
| CC_INTERIORS
| CC_ROUNDRECT
);
333 ret
= (LC_POLYLINE
| LC_MARKER
| LC_POLYMARKER
| LC_WIDE
|
334 LC_STYLED
| LC_WIDESTYLED
| LC_INTERIORS
);
337 ret
= (PC_POLYGON
| PC_RECTANGLE
| PC_WINDPOLYGON
| PC_SCANLINE
|
338 PC_WIDE
| PC_STYLED
| PC_WIDESTYLED
| PC_INTERIORS
);
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
);
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
;
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));
363 ret
= (SB_GRAD_RECT
| SB_GRAD_TRI
| SB_CONST_ALPHA
| SB_PIXEL_ALPHA
);
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
385 ret
= bits_per_pixel
<= 8 ? 1 << bits_per_pixel
: 0;
390 case PHYSICALOFFSETX
:
391 case PHYSICALOFFSETY
:
399 FIXME("(%p): unsupported capability %d, will return 0\n", dev
->hdc
, cap
);
404 TRACE("cap %d -> %d\n", cap
, ret
);
407 LeaveCriticalSection(&device_data_section
);
412 static const struct gdi_dc_funcs macdrv_funcs
=
414 NULL
, /* pAbortDoc */
415 NULL
, /* pAbortPath */
416 NULL
, /* pAlphaBlend */
417 NULL
, /* pAngleArc */
420 NULL
, /* pBeginPath */
421 NULL
, /* pBlendImage */
423 NULL
, /* pCloseFigure */
424 macdrv_CreateCompatibleDC
, /* pCreateCompatibleDC */
425 macdrv_CreateDC
, /* pCreateDC */
426 macdrv_DeleteDC
, /* pDeleteDC */
427 NULL
, /* pDeleteObject */
428 NULL
, /* pDeviceCapabilities */
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 */
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 */
474 NULL
, /* pModifyWorldTransform */
476 NULL
, /* pOffsetClipRgn */
477 NULL
, /* pOffsetViewportOrg */
478 NULL
, /* pOffsetWindowOrg */
479 NULL
, /* pPaintRgn */
482 NULL
, /* pPolyBezier */
483 NULL
, /* pPolyBezierTo */
484 NULL
, /* pPolyDraw */
485 NULL
, /* pPolyPolygon */
486 NULL
, /* pPolyPolyline */
488 NULL
, /* pPolyline */
489 NULL
, /* pPolylineTo */
490 NULL
, /* pPutImage */
491 NULL
, /* pRealizeDefaultPalette */
492 NULL
, /* pRealizePalette */
493 NULL
, /* pRectangle */
495 NULL
, /* pRestoreDC */
496 NULL
, /* pRoundRect */
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 */
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
);
555 return &macdrv_funcs
;