Module: wine Branch: master Commit: e633f79f610516e78f7958b2946cb96bac327fe5 URL: http://source.winehq.org/git/wine.git/?a=commit;h=e633f79f610516e78f7958b294...
Author: Ken Thomases ken@codeweavers.com Date: Sun Mar 17 22:41:07 2013 -0500
winemac: Implement GetDeviceGammaRamp() and SetDeviceGammaRamp().
---
dlls/winemac.drv/display.c | 131 ++++++++++++++++++++++++++++++++++++++++++++ dlls/winemac.drv/gdi.c | 4 +- dlls/winemac.drv/macdrv.h | 2 + 3 files changed, 135 insertions(+), 2 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index f152cc8..85c903d 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -24,6 +24,7 @@ #include "macdrv.h" #include "winuser.h" #include "winreg.h" +#include "ddrawi.h"
WINE_DEFAULT_DEBUG_CHANNEL(display);
@@ -599,6 +600,91 @@ failed:
/*********************************************************************** + * GetDeviceGammaRamp (MACDRV.@) + */ +BOOL macdrv_GetDeviceGammaRamp(PHYSDEV dev, LPVOID ramp) +{ + BOOL ret = FALSE; + DDGAMMARAMP *r = ramp; + struct macdrv_display *displays; + int num_displays; + uint32_t mac_entries; + int win_entries = sizeof(r->red) / sizeof(r->red[0]); + CGGammaValue *red, *green, *blue; + CGError err; + int win_entry; + + TRACE("dev %p ramp %p\n", dev, ramp); + + if (macdrv_get_displays(&displays, &num_displays)) + { + WARN("failed to get Mac displays\n"); + return FALSE; + } + + mac_entries = CGDisplayGammaTableCapacity(displays[0].displayID); + red = HeapAlloc(GetProcessHeap(), 0, mac_entries * sizeof(red[0]) * 3); + if (!red) + goto done; + green = red + mac_entries; + blue = green + mac_entries; + + err = CGGetDisplayTransferByTable(displays[0].displayID, mac_entries, red, green, + blue, &mac_entries); + if (err != kCGErrorSuccess) + { + WARN("failed to get Mac gamma table: %d\n", err); + goto done; + } + + if (mac_entries == win_entries) + { + for (win_entry = 0; win_entry < win_entries; win_entry++) + { + r->red[win_entry] = red[win_entry] * 65535 + 0.5; + r->green[win_entry] = green[win_entry] * 65535 + 0.5; + r->blue[win_entry] = blue[win_entry] * 65535 + 0.5; + } + } + else + { + for (win_entry = 0; win_entry < win_entries; win_entry++) + { + double mac_pos = win_entry * (mac_entries - 1) / (double)(win_entries - 1); + int mac_entry = mac_pos; + double red_value, green_value, blue_value; + + if (mac_entry == mac_entries - 1) + { + red_value = red[mac_entry]; + green_value = green[mac_entry]; + blue_value = blue[mac_entry]; + } + else + { + double distance = mac_pos - mac_entry; + + red_value = red[mac_entry] * (1 - distance) + red[mac_entry + 1] * distance; + green_value = green[mac_entry] * (1 - distance) + green[mac_entry + 1] * distance; + blue_value = blue[mac_entry] * (1 - distance) + blue[mac_entry + 1] * distance; + } + + r->red[win_entry] = red_value * 65535 + 0.5; + r->green[win_entry] = green_value * 65535 + 0.5; + r->blue[win_entry] = blue_value * 65535 + 0.5; + } + } + + ret = TRUE; + +done: + HeapFree(GetProcessHeap(), 0, red); + macdrv_free_displays(displays); + return ret; +} + + +/*********************************************************************** * GetMonitorInfo (MACDRV.@) */ BOOL CDECL macdrv_GetMonitorInfo(HMONITOR monitor, LPMONITORINFO info) @@ -650,6 +736,51 @@ BOOL CDECL macdrv_GetMonitorInfo(HMONITOR monitor, LPMONITORINFO info)
/*********************************************************************** + * SetDeviceGammaRamp (MACDRV.@) + */ +BOOL macdrv_SetDeviceGammaRamp(PHYSDEV dev, LPVOID ramp) +{ + DDGAMMARAMP *r = ramp; + struct macdrv_display *displays; + int num_displays; + int win_entries = sizeof(r->red) / sizeof(r->red[0]); + CGGammaValue *red, *green, *blue; + int i; + CGError err = kCGErrorFailure; + + TRACE("dev %p ramp %p\n", dev, ramp); + + if (macdrv_get_displays(&displays, &num_displays)) + { + WARN("failed to get Mac displays\n"); + return FALSE; + } + + red = HeapAlloc(GetProcessHeap(), 0, win_entries * sizeof(red[0]) * 3); + if (!red) + goto done; + green = red + win_entries; + blue = green + win_entries; + + for (i = 0; i < win_entries; i++) + { + red[i] = r->red[i] / 65535.0; + green[i] = r->green[i] / 65535.0; + blue[i] = r->blue[i] / 65535.0; + } + + err = CGSetDisplayTransferByTable(displays[0].displayID, win_entries, red, green, blue); + if (err != kCGErrorSuccess) + WARN("failed to set display gamma table: %d\n", err); + +done: + HeapFree(GetProcessHeap(), 0, red); + macdrv_free_displays(displays); + return (err == kCGErrorSuccess); +} + + +/*********************************************************************** * macdrv_displays_changed * * Handler for DISPLAYS_CHANGED events. diff --git a/dlls/winemac.drv/gdi.c b/dlls/winemac.drv/gdi.c index 2a9a019..e05f9ab 100644 --- a/dlls/winemac.drv/gdi.c +++ b/dlls/winemac.drv/gdi.c @@ -461,7 +461,7 @@ static const struct gdi_dc_funcs macdrv_funcs = NULL, /* pGetCharABCWidthsI */ NULL, /* pGetCharWidth */ macdrv_GetDeviceCaps, /* pGetDeviceCaps */ - NULL, /* pGetDeviceGammaRamp */ + macdrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */ NULL, /* pGetFontData */ NULL, /* pGetFontUnicodeRanges */ NULL, /* pGetGlyphIndices */ @@ -522,7 +522,7 @@ static const struct gdi_dc_funcs macdrv_funcs = NULL, /* pSetDCPenColor */ NULL, /* pSetDIBitsToDevice */ NULL, /* pSetDeviceClipping */ - NULL, /* pSetDeviceGammaRamp */ + macdrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */ NULL, /* pSetLayout */ NULL, /* pSetMapMode */ NULL, /* pSetMapperFlags */ diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index d4cbe1d..aeeee2d 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -71,6 +71,8 @@ static inline const char *wine_dbgstr_cgrect(CGRect cgrect)
extern CGRect macdrv_get_desktop_rect(void) DECLSPEC_HIDDEN; extern void macdrv_reset_device_metrics(void) DECLSPEC_HIDDEN; +extern BOOL macdrv_GetDeviceGammaRamp(PHYSDEV dev, LPVOID ramp) DECLSPEC_HIDDEN; +extern BOOL macdrv_SetDeviceGammaRamp(PHYSDEV dev, LPVOID ramp) DECLSPEC_HIDDEN;
/**************************************************************************