diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-06-01 09:46:01 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-06-01 09:46:01 +0200 |
commit | 7c4863fee3bdc57fa700fd21e8605fb63dd72909 (patch) | |
tree | 4092a250000498865b079e2a2a1d5e8445321a63 /src/lib/fake-w32-gdi.c | |
parent | m + memleak fix + doc (diff) | |
download | libgamma-7c4863fee3bdc57fa700fd21e8605fb63dd72909.tar.gz libgamma-7c4863fee3bdc57fa700fd21e8605fb63dd72909.tar.bz2 libgamma-7c4863fee3bdc57fa700fd21e8605fb63dd72909.tar.xz |
doc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/lib/fake-w32-gdi.c')
-rw-r--r-- | src/lib/fake-w32-gdi.c | 62 |
1 files changed, 54 insertions, 8 deletions
diff --git a/src/lib/fake-w32-gdi.c b/src/lib/fake-w32-gdi.c index 541b3c8..ba72dce 100644 --- a/src/lib/fake-w32-gdi.c +++ b/src/lib/fake-w32-gdi.c @@ -34,10 +34,13 @@ #ifndef HAVE_LIBGAMMA_METHOD_X_RANDR +/* Use dummy translation. */ + /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd144871(v=vs.85).aspx */ HDC GetDC(HWND hWnd) { + /* Just a non-NULL value. */ (void) hWnd; return (HDC*)16; } @@ -45,6 +48,7 @@ HDC GetDC(HWND hWnd) /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd162920(v=vs.85).aspx */ int ReleaseDC(HWND hWnd, HDC hDC) { + /* Always successful. */ (void) hWnd; (void) hDC; return 1; @@ -54,6 +58,7 @@ int ReleaseDC(HWND hWnd, HDC hDC) /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx */ int GetDeviceCaps(HDC hDC, int nIndex) { + /* We have gamma ramps if the user asks for colour management capabilities. */ (void) hDC; return CM_GAMMA_RAMP + nIndex - COLORMGMTCAPS; } @@ -61,6 +66,7 @@ int GetDeviceCaps(HDC hDC, int nIndex) /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd372194(v=vs.85).aspx */ BOOL SetDeviceGammaRamp(HDC hDC, LPVOID restrict lpRamp) { + /* Always successful. */ (void) hDC; (void) lpRamp; return TRUE; @@ -69,6 +75,7 @@ BOOL SetDeviceGammaRamp(HDC hDC, LPVOID restrict lpRamp) /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd316946(v=vs.85).aspx */ BOOL GetDeviceGammaRamp(HDC hDC, LPVOID restrict lpRamp) { + /* Always successful. */ (void) hDC; (void) lpRamp; return TRUE; @@ -79,12 +86,11 @@ BOOL GetDeviceGammaRamp(HDC hDC, LPVOID restrict lpRamp) HDC CreateDC(LPCTSTR restrict lpszDriver, LPCTSTR restrict lpszDevice, void* restrict lpszOutput, void* restrict lpInitData) { + /* `NULL` if not asking for a CRTC, otherwise a non-NULL value. */ (void) lpszOutput; (void) lpInitData; (void) lpszDevice; - if (strcmp(lpszDriver, "DISPLAY")) - return NULL; - return (HDC*)16; + return strcmp(lpszDriver, "DISPLAY") ? NULL : (HDC*)16; } @@ -93,46 +99,78 @@ BOOL EnumDisplayDevices(LPCTSTR lpDevice, restrict DWORD iDevNum, PDISPLAY_DEVICE restrict lpDisplayDevice, DWORD dwFlags) { (void) dwFlags; + /* Check correctness of `lpDevice`. */ if (lpDevice != NULL) { fprintf(stderr, "lpDevice (argument 1) for EnumDisplayDevices should be NULL\n"); abort(); return FALSE; } + /* Pretend that we have two CRTC:s. */ if (iDevNum >= 2) return FALSE; + /* Check correctness of `lpDisplayDevice`. */ if (lpDisplayDevice->cb != sizeof(DISPLAY_DEVICE)) { - fprintf(stderr, - "lpDisplayDevice->cb for EnumDisplayDevices is not sizeof(DISPLAY_DEVICE)\n"); + fprintf(stderr, "lpDisplayDevice->cb for EnumDisplayDevices is not sizeof(DISPLAY_DEVICE)\n"); abort(); return FALSE; } + /* Store an arbitrary name for the monitor. */ strcmp(lpDisplayDevice->DeviceName, "some monitor"); + /* The connector is always enabled. */ lpDisplayDevice->StateFlags = DISPLAY_DEVICE_ACTIVE; return TRUE; } + #else +/* Use translation to X RandR. */ #include <xcb/xcb.h> #include <xcb/randr.h> +/** + * The gamma ramp size that devices will + * always have in Windows GDI. + */ #define GAMMA_RAMP_SIZE 256 +/** + * Connection to the X RandR display. + */ static xcb_connection_t* restrict connection = NULL; -static size_t dc_count = 0; + +/** + * Resouces for the screen. + * We only have one screen, again this is a very sloppy compatibility layer. + */ +static xcb_randr_get_screen_resources_current_reply_t* restrict res_reply = NULL; + +/** + * The number of available CRTC:s, -1 if not known yet. + */ static ssize_t crtc_count = -1; + +/** + * List of X RandR CRTC:s. + */ static xcb_randr_crtc_t* restrict crtcs = NULL; -static xcb_randr_get_screen_resources_current_reply_t* restrict res_reply = NULL; + +/** + * The number of opened CRTC:s. + */ +static size_t dc_count = 0; + /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd144871(v=vs.85).aspx */ HDC GetDC(HWND hWnd) { + /* Return the primary CRTC. */ (void) hWnd; return CreateDC(TEXT("DISPLAY"), "0", NULL, NULL); } @@ -141,6 +179,7 @@ HDC GetDC(HWND hWnd) /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd162920(v=vs.85).aspx */ int ReleaseDC(HWND hWnd, HDC hDC) { + /* Disconnect from the RandR display when all monitors have been closed. */ (void) hWnd; (void) hDC; dc_count--; @@ -159,17 +198,22 @@ int ReleaseDC(HWND hWnd, HDC hDC) /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd144877(v=vs.85).aspx */ int GetDeviceCaps(HDC hDC, int nIndex) { + /* We have gamma ramps if the user asks for colour management capabilities. */ (void) hDC; return CM_GAMMA_RAMP + nIndex - COLORMGMTCAPS; } +/* xcb violates the rule to never return struct:s. */ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Waggregate-return" + /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd372194(v=vs.85).aspx */ BOOL SetDeviceGammaRamp(HDC hDC, LPVOID restrict lpRamp) { + /* We assume that our gamma ramps are of the same size + as used by Windows GDI (we are so sloppy.) */ xcb_void_cookie_t gamma_cookie = xcb_randr_set_crtc_gamma_checked(connection, *(xcb_randr_crtc_t*)hDC, GAMMA_RAMP_SIZE, ((uint16_t*)lpRamp) + 0 * GAMMA_RAMP_SIZE, @@ -187,15 +231,16 @@ BOOL GetDeviceGammaRamp(HDC hDC, LPVOID restrict lpRamp) xcb_randr_get_crtc_gamma_reply_t* restrict gamma_reply; xcb_generic_error_t* error; + /* Read current gamma ramps. */ gamma_cookie = xcb_randr_get_crtc_gamma(connection, *(xcb_randr_crtc_t*)hDC); gamma_reply = xcb_randr_get_crtc_gamma_reply(connection, gamma_cookie, &error); - if (error) return FALSE; #define DEST_RAMP(I) (((uint16_t*)lpRamp) + (I) * GAMMA_RAMP_SIZE) #define SRC_RAMP(C) (xcb_randr_get_crtc_gamma_##C(gamma_reply)) + /* Copy the ramps into the output parameter. (coalesced) */ memcpy(DEST_RAMP(0), SRC_RAMP(red), GAMMA_RAMP_SIZE * sizeof(uint16_t)); memcpy(DEST_RAMP(1), SRC_RAMP(green), GAMMA_RAMP_SIZE * sizeof(uint16_t)); memcpy(DEST_RAMP(2), SRC_RAMP(blue), GAMMA_RAMP_SIZE * sizeof(uint16_t)); @@ -256,6 +301,7 @@ HDC CreateDC(LPCTSTR restrict lpszDriver, LPCTSTR restrict lpszDevice, return crtcs + crtc_index; } + # pragma GCC diagnostic pop |