SDL: Remove SDL_SetWindowBrightness and SDL_SetWindowGammaRamp.

From 52f4cc843d56456ca4b2bca9b9a97ebbec6394c4 Mon Sep 17 00:00:00 2001
From: slime <[EMAIL REDACTED]>
Date: Thu, 24 Nov 2022 22:42:57 -0400
Subject: [PATCH] Remove SDL_SetWindowBrightness and SDL_SetWindowGammaRamp.

---
 docs/README-migration.md              |   5 +
 include/SDL_pixels.h                  |   2 -
 include/SDL_video.h                   | 110 ----------------
 src/dynapi/SDL_dynapi_overrides.h     |   4 -
 src/dynapi/SDL_dynapi_procs.h         |   4 -
 src/video/SDL_sysvideo.h              |   6 -
 src/video/SDL_video.c                 | 114 -----------------
 src/video/cocoa/SDL_cocoavideo.m      |   2 -
 src/video/cocoa/SDL_cocoawindow.h     |   2 -
 src/video/cocoa/SDL_cocoawindow.m     |  51 --------
 src/video/haiku/SDL_bvideo.cc         |   2 -
 src/video/haiku/SDL_bwindow.cc        |  10 --
 src/video/haiku/SDL_bwindow.h         |   2 -
 src/video/kmsdrm/SDL_kmsdrmsym.h      |   4 -
 src/video/kmsdrm/SDL_kmsdrmvideo.c    |  38 ------
 src/video/kmsdrm/SDL_kmsdrmvideo.h    |   2 -
 src/video/windows/SDL_windowsvideo.c  |   2 -
 src/video/windows/SDL_windowswindow.c |  38 ------
 src/video/windows/SDL_windowswindow.h |   2 -
 src/video/x11/SDL_x11video.c          |   1 -
 src/video/x11/SDL_x11window.c         |  67 ----------
 src/video/x11/SDL_x11window.h         |   1 -
 test/testautomation_video.c           | 176 ++------------------------
 23 files changed, 16 insertions(+), 629 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index 6297dfbcb25e..a045a0b65b8a 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -139,3 +139,8 @@ The structures in this file are versioned separately from the rest of SDL, allow
 
 This function now returns a standard int result instead of SDL_bool, returning 0 if the function succeeds or a negative error code if there was an error. You should also pass `SDL_SYSWM_CURRENT_VERSION` as the new third version parameter. The version member of the info structure will be filled in with the version of data that is returned, the minimum of the version you requested and the version supported by the runtime SDL library.
 
+## SDL_video.h
+
+SDL_SetWindowBrightness and SDL_SetWindowGammaRamp have been removed from the API, because they interact poorly with modern operating systems and aren't able to limit their effects to the SDL window.
+
+Programs which have access to shaders can implement more robust versions of those functions using custom shader code rendered as a post-process effect.
diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h
index 3766e4328c1d..63baf6e833ac 100644
--- a/include/SDL_pixels.h
+++ b/include/SDL_pixels.h
@@ -627,8 +627,6 @@ extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
  * \param ramp an array of 256 values filled in with the gamma ramp
  *
  * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_SetWindowGammaRamp
  */
 extern DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, Uint16 * ramp);
 
diff --git a/include/SDL_video.h b/include/SDL_video.h
index 8b8cafb97834..6f9ca6a0e703 100644
--- a/include/SDL_video.h
+++ b/include/SDL_video.h
@@ -1509,53 +1509,6 @@ extern DECLSPEC int SDLCALL SDL_SetWindowMouseRect(SDL_Window * window, const SD
  */
 extern DECLSPEC const SDL_Rect * SDLCALL SDL_GetWindowMouseRect(SDL_Window * window);
 
-/**
- * Set the brightness (gamma multiplier) for a given window's display.
- *
- * Despite the name and signature, this method sets the brightness of the
- * entire display, not an individual window. A window is considered to be
- * owned by the display that contains the window's center pixel. (The index of
- * this display can be retrieved using SDL_GetWindowDisplayIndex().) The
- * brightness set will not follow the window if it is moved to another
- * display.
- *
- * Many platforms will refuse to set the display brightness in modern times.
- * You are better off using a shader to adjust gamma during rendering, or
- * something similar.
- *
- * \param window the window used to select the display whose brightness will
- *               be changed
- * \param brightness the brightness (gamma multiplier) value to set where 0.0
- *                   is completely dark and 1.0 is normal brightness
- * \returns 0 on success or a negative error code on failure; call
- *          SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetWindowBrightness
- * \sa SDL_SetWindowGammaRamp
- */
-extern DECLSPEC int SDLCALL SDL_SetWindowBrightness(SDL_Window * window, float brightness);
-
-/**
- * Get the brightness (gamma multiplier) for a given window's display.
- *
- * Despite the name and signature, this method retrieves the brightness of the
- * entire display, not an individual window. A window is considered to be
- * owned by the display that contains the window's center pixel. (The index of
- * this display can be retrieved using SDL_GetWindowDisplayIndex().)
- *
- * \param window the window used to select the display whose brightness will
- *               be queried
- * \returns the brightness for the display where 0.0 is completely dark and
- *          1.0 is normal brightness.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_SetWindowBrightness
- */
-extern DECLSPEC float SDLCALL SDL_GetWindowBrightness(SDL_Window * window);
-
 /**
  * Set the opacity for a window.
  *
@@ -1625,69 +1578,6 @@ extern DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window * modal_window, SDL
  */
 extern DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window * window);
 
-/**
- * Set the gamma ramp for the display that owns a given window.
- *
- * Set the gamma translation table for the red, green, and blue channels of
- * the video hardware. Each table is an array of 256 16-bit quantities,
- * representing a mapping between the input and output for that channel. The
- * input is the index into the array, and the output is the 16-bit gamma value
- * at that index, scaled to the output color precision.
- *
- * Despite the name and signature, this method sets the gamma ramp of the
- * entire display, not an individual window. A window is considered to be
- * owned by the display that contains the window's center pixel. (The index of
- * this display can be retrieved using SDL_GetWindowDisplayIndex().) The gamma
- * ramp set will not follow the window if it is moved to another display.
- *
- * \param window the window used to select the display whose gamma ramp will
- *               be changed
- * \param red a 256 element array of 16-bit quantities representing the
- *            translation table for the red channel, or NULL
- * \param green a 256 element array of 16-bit quantities representing the
- *              translation table for the green channel, or NULL
- * \param blue a 256 element array of 16-bit quantities representing the
- *             translation table for the blue channel, or NULL
- * \returns 0 on success or a negative error code on failure; call
- *          SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_GetWindowGammaRamp
- */
-extern DECLSPEC int SDLCALL SDL_SetWindowGammaRamp(SDL_Window * window,
-                                                   const Uint16 * red,
-                                                   const Uint16 * green,
-                                                   const Uint16 * blue);
-
-/**
- * Get the gamma ramp for a given window's display.
- *
- * Despite the name and signature, this method retrieves the gamma ramp of the
- * entire display, not an individual window. A window is considered to be
- * owned by the display that contains the window's center pixel. (The index of
- * this display can be retrieved using SDL_GetWindowDisplayIndex().)
- *
- * \param window the window used to select the display whose gamma ramp will
- *               be queried
- * \param red a 256 element array of 16-bit quantities filled in with the
- *            translation table for the red channel, or NULL
- * \param green a 256 element array of 16-bit quantities filled in with the
- *              translation table for the green channel, or NULL
- * \param blue a 256 element array of 16-bit quantities filled in with the
- *             translation table for the blue channel, or NULL
- * \returns 0 on success or a negative error code on failure; call
- *          SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_SetWindowGammaRamp
- */
-extern DECLSPEC int SDLCALL SDL_GetWindowGammaRamp(SDL_Window * window,
-                                                   Uint16 * red,
-                                                   Uint16 * green,
-                                                   Uint16 * blue);
-
 /**
  * Possible return values from the SDL_HitTest callback.
  *
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 515b854ca99d..5f65cf7db492 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -538,10 +538,6 @@
 #define SDL_UpdateWindowSurfaceRects SDL_UpdateWindowSurfaceRects_REAL
 #define SDL_SetWindowGrab SDL_SetWindowGrab_REAL
 #define SDL_GetWindowGrab SDL_GetWindowGrab_REAL
-#define SDL_SetWindowBrightness SDL_SetWindowBrightness_REAL
-#define SDL_GetWindowBrightness SDL_GetWindowBrightness_REAL
-#define SDL_SetWindowGammaRamp SDL_SetWindowGammaRamp_REAL
-#define SDL_GetWindowGammaRamp SDL_GetWindowGammaRamp_REAL
 #define SDL_DestroyWindow SDL_DestroyWindow_REAL
 #define SDL_IsScreenSaverEnabled SDL_IsScreenSaverEnabled_REAL
 #define SDL_EnableScreenSaver SDL_EnableScreenSaver_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 862878aeb46c..6d0c53e2a120 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -564,10 +564,6 @@ SDL_DYNAPI_PROC(int,SDL_UpdateWindowSurface,(SDL_Window *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_UpdateWindowSurfaceRects,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return)
 SDL_DYNAPI_PROC(void,SDL_SetWindowGrab,(SDL_Window *a, SDL_bool b),(a,b),)
 SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowGrab,(SDL_Window *a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_SetWindowBrightness,(SDL_Window *a, float b),(a,b),return)
-SDL_DYNAPI_PROC(float,SDL_GetWindowBrightness,(SDL_Window *a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_SetWindowGammaRamp,(SDL_Window *a, const Uint16 *b, const Uint16 *c, const Uint16 *d),(a,b,c,d),return)
-SDL_DYNAPI_PROC(int,SDL_GetWindowGammaRamp,(SDL_Window *a, Uint16 *b, Uint16 *c, Uint16 *d),(a,b,c,d),return)
 SDL_DYNAPI_PROC(void,SDL_DestroyWindow,(SDL_Window *a),(a),)
 SDL_DYNAPI_PROC(SDL_bool,SDL_IsScreenSaverEnabled,(void),(),return)
 SDL_DYNAPI_PROC(void,SDL_EnableScreenSaver,(void),(),)
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 54a4d6c9c64c..592f28e351c7 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -92,10 +92,6 @@ struct SDL_Window
 
     float opacity;
 
-    float brightness;
-    Uint16 *gamma;
-    Uint16 *saved_gamma;        /* (just offset into gamma) */
-
     SDL_Surface *surface;
     SDL_bool surface_valid;
 
@@ -241,8 +237,6 @@ struct SDL_VideoDevice
     void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool resizable);
     void (*SetWindowAlwaysOnTop) (_THIS, SDL_Window * window, SDL_bool on_top);
     void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
-    int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
-    int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
     void* (*GetWindowICCProfile) (_THIS, SDL_Window * window, size_t* size);
     int (*GetWindowDisplayIndex)(_THIS, SDL_Window * window);
     void (*SetWindowMouseRect)(_THIS, SDL_Window * window);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 6b8fe67e2c8c..69e0250de3cd 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1739,7 +1739,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
     window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
     window->last_fullscreen_flags = window->flags;
     window->opacity = 1.0f;
-    window->brightness = 1.0f;
     window->next = _this->windows;
     window->is_destroying = SDL_FALSE;
     window->display_index = SDL_GetWindowDisplayIndex(window);
@@ -1838,7 +1837,6 @@ SDL_CreateWindowFrom(const void *data)
     window->last_fullscreen_flags = window->flags;
     window->is_destroying = SDL_FALSE;
     window->opacity = 1.0f;
-    window->brightness = 1.0f;
     window->next = _this->windows;
     if (_this->windows) {
         _this->windows->prev = window;
@@ -2754,30 +2752,6 @@ SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects,
     return _this->UpdateWindowFramebuffer(_this, window, rects, numrects);
 }
 
-int
-SDL_SetWindowBrightness(SDL_Window * window, float brightness)
-{
-    Uint16 ramp[256];
-    int status;
-
-    CHECK_WINDOW_MAGIC(window, -1);
-
-    SDL_CalculateGammaRamp(brightness, ramp);
-    status = SDL_SetWindowGammaRamp(window, ramp, ramp, ramp);
-    if (status == 0) {
-        window->brightness = brightness;
-    }
-    return status;
-}
-
-float
-SDL_GetWindowBrightness(SDL_Window * window)
-{
-    CHECK_WINDOW_MAGIC(window, 1.0f);
-
-    return window->brightness;
-}
-
 int
 SDL_SetWindowOpacity(SDL_Window * window, float opacity)
 {
@@ -2840,85 +2814,6 @@ SDL_SetWindowInputFocus(SDL_Window * window)
 }
 
 
-int
-SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red,
-                                            const Uint16 * green,
-                                            const Uint16 * blue)
-{
-    CHECK_WINDOW_MAGIC(window, -1);
-
-    if (!_this->SetWindowGammaRamp) {
-        return SDL_Unsupported();
-    }
-
-    if (!window->gamma) {
-        if (SDL_GetWindowGammaRamp(window, NULL, NULL, NULL) < 0) {
-            return -1;
-        }
-        SDL_assert(window->gamma != NULL);
-    }
-
-    if (red) {
-        SDL_memcpy(&window->gamma[0*256], red, 256*sizeof(Uint16));
-    }
-    if (green) {
-        SDL_memcpy(&window->gamma[1*256], green, 256*sizeof(Uint16));
-    }
-    if (blue) {
-        SDL_memcpy(&window->gamma[2*256], blue, 256*sizeof(Uint16));
-    }
-    if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
-        return _this->SetWindowGammaRamp(_this, window, window->gamma);
-    } else {
-        return 0;
-    }
-}
-
-int
-SDL_GetWindowGammaRamp(SDL_Window * window, Uint16 * red,
-                                            Uint16 * green,
-                                            Uint16 * blue)
-{
-    CHECK_WINDOW_MAGIC(window, -1);
-
-    if (!window->gamma) {
-        int i;
-
-        window->gamma = (Uint16 *)SDL_malloc(256*6*sizeof(Uint16));
-        if (!window->gamma) {
-            return SDL_OutOfMemory();
-        }
-        window->saved_gamma = window->gamma + 3*256;
-
-        if (_this->GetWindowGammaRamp) {
-            if (_this->GetWindowGammaRamp(_this, window, window->gamma) < 0) {
-                return -1;
-            }
-        } else {
-            /* Create an identity gamma ramp */
-            for (i = 0; i < 256; ++i) {
-                Uint16 value = (Uint16)((i << 8) | i);
-
-                window->gamma[0*256+i] = value;
-                window->gamma[1*256+i] = value;
-                window->gamma[2*256+i] = value;
-            }
-        }
-        SDL_memcpy(window->saved_gamma, window->gamma, 3*256*sizeof(Uint16));
-    }
-
-    if (red) {
-        SDL_memcpy(red, &window->gamma[0*256], 256*sizeof(Uint16));
-    }
-    if (green) {
-        SDL_memcpy(green, &window->gamma[1*256], 256*sizeof(Uint16));
-    }
-    if (blue) {
-        SDL_memcpy(blue, &window->gamma[2*256], 256*sizeof(Uint16));
-    }
-    return 0;
-}
-
 void
 SDL_UpdateWindowGrab(SDL_Window * window)
 {
@@ -3164,10 +3059,6 @@ SDL_OnWindowFocusGained(SDL_Window * window)
 {
     SDL_Mouse *mouse = SDL_GetMouse();
 
-    if (window->gamma && _this->SetWindowGammaRamp) {
-        _this->SetWindowGammaRamp(_this, window, window->gamma);
-    }
-
     if (mouse && mouse->relative_mode) {
         SDL_SetMouseFocus(window);
         if (mouse->relative_mode_warp) {
@@ -3220,10 +3111,6 @@ ShouldMinimizeOnFocusLoss(SDL_Window * window)
 void
 SDL_OnWindowFocusLost(SDL_Window * window)
 {
-    if (window->gamma && _this->SetWindowGammaRamp) {
-        _this->SetWindowGammaRamp(_this, window, window->saved_gamma);
-    }
-
     SDL_UpdateWindowGrab(window);
 
     if (ShouldMinimizeOnFocusLoss(window)) {
@@ -3310,7 +3197,6 @@ SDL_DestroyWindow(SDL_Window * window)
     /* Free memory associated with the window */
     SDL_free(window->title);
     SDL_FreeSurface(window->icon);
-    SDL_free(window->gamma);
     while (window->data) {
         SDL_WindowUserData *data = window->data;
 
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index da43da732ef0..879b6f046d84 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -112,8 +112,6 @@ @implementation SDL_VideoData
     device->SetWindowResizable = Cocoa_SetWindowResizable;
     device->SetWindowAlwaysOnTop = Cocoa_SetWindowAlwaysOnTop;
     device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
-    device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
-    device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
     device->GetWindowICCProfile = Cocoa_GetWindowICCProfile;
     device->GetWindowDisplayIndex = Cocoa_GetWindowDisplayIndex;
     device->SetWindowMouseRect = Cocoa_SetWindowMouseRect;
diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h
index 8a80e765c54b..f11ff4e9c98e 100644
--- a/src/video/cocoa/SDL_cocoawindow.h
+++ b/src/video/cocoa/SDL_cocoawindow.h
@@ -158,10 +158,8 @@ extern void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordere
 extern void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
 extern void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top);
 extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
-extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
 extern void* Cocoa_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size);
 extern int Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window * window);
-extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
 extern void Cocoa_SetWindowMouseRect(_THIS, SDL_Window * window);
 extern void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
 extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index e8e27b54a177..1c0c2336a4a5 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -2211,33 +2211,6 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
     ScheduleContextUpdates(data);
 }}
 
-int
-Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
-{ @autoreleasepool
-{
-    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
-    CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
-    const uint32_t tableSize = 256;
-    CGGammaValue redTable[tableSize];
-    CGGammaValue greenTable[tableSize];
-    CGGammaValue blueTable[tableSize];
-    uint32_t i;
-    float inv65535 = 1.0f / 65535.0f;
-
-    /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
-    for (i = 0; i < 256; i++) {
-        redTable[i] = ramp[0*256+i] * inv65535;
-        greenTable[i] = ramp[1*256+i] * inv65535;
-        blueTable[i] = ramp[2*256+i] * inv65535;
-    }
-
-    if (CGSetDisplayTransferByTable(display_id, tableSize,
-                                    redTable, greenTable, blueTable) != CGDisplayNoErr) {
-        return SDL_SetError("CGSetDisplayTransferByTable()");
-    }
-    return 0;
-}}
-
 void*
 Cocoa_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
 { @autoreleasepool
@@ -2314,30 +2287,6 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
     return SDL_SetError("Couldn't find the display where the window is located.");
 }}
 
-int
-Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
-{
-    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
-    CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
-    const uint32_t tableSize = 256;
-    CGGammaValue redTable[tableSize];
-    CGGammaValue greenTable[tableSize];
-    CGGammaValue blueTable[tableSize];
-    uint32_t i, tableCopied;
-
-    if (CGGetDisplayTransferByTable(display_id, tableSize,
-                                    redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
-        return SDL_SetError("CGGetDisplayTransferByTable()");
-    }
-
-    for (i = 0; i < tableCopied; i++) {
-        ramp[0*256+i] = (Uint16)(redTable[i] * 65535.0f);
-        ramp[1*256+i] = (Uint16)(greenTable[i] * 65535.0f);
-        ramp[2*256+i] = (Uint16)(blueTable[i] * 65535.0f);
-    }
-    return 0;
-}
-
 void
 Cocoa_SetWindowMouseRect(_THIS, SDL_Window * window)
 {
diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc
index e409f3c6fd61..3c7968b90da3 100644
--- a/src/video/haiku/SDL_bvideo.cc
+++ b/src/video/haiku/SDL_bvideo.cc
@@ -91,8 +91,6 @@ HAIKU_CreateDevice(void)
     device->SetWindowBordered = HAIKU_SetWindowBordered;
     device->SetWindowResizable = HAIKU_SetWindowResizable;
     device->SetWindowFullscreen = HAIKU_SetWindowFullscreen;
-    device->SetWindowGammaRamp = HAIKU_SetWindowGammaRamp;
-    device->GetWindowGammaRamp = HAIKU_GetWindowGammaRamp;
     device->SetWindowMouseGrab = HAIKU_SetWindowMouseGrab;
     device->SetWindowMinimumSize = HAIKU_SetWindowMinimumSize;
     device->DestroyWindow = HAIKU_DestroyWindow;
diff --git a/src/video/haiku/SDL_bwindow.cc b/src/video/haiku/SDL_bwindow.cc
index 090259d85999..039d22cb01d8 100644
--- a/src/video/haiku/SDL_bwindow.cc
+++ b/src/video/haiku/SDL_bwindow.cc
@@ -194,16 +194,6 @@ void HAIKU_SetWindowFullscreen(_THIS, SDL_Window * window,
     
 }
 
-int HAIKU_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
-    /* FIXME: Not Haiku supported */
-    return -1;
-}
-
-int HAIKU_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
-    /* FIXME: Not Haiku supported */
-    return -1;
-}
-
 
 void HAIKU_SetWindowMinimumSize(_THIS, SDL_Window * window){
     BMessage msg(BWIN_MINIMUM_SIZE_WINDOW);
diff --git a/src/video/haiku/SDL_bwindow.h b/src/video/haiku/SDL_bwindow.h
index 6cbf1dafd2bb..9cdf8d48ccce 100644
--- a/src/video/haiku/SDL_bwindow.h
+++ b/src/video/haiku/SDL_bwindow.h
@@ -42,8 +42,6 @@ extern void HAIKU_RestoreWindow(_THIS, SDL_Window * window);
 extern void HAIKU_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
 extern void HAIKU_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
 extern void HAIKU_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
-extern int HAIKU_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
-extern int HAIKU_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
 extern void HAIKU_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
 extern void HAIKU_DestroyWindow(_THIS, SDL_Window * window);
 extern int HAIKU_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info);
diff --git a/src/video/kmsdrm/SDL_kmsdrmsym.h b/src/video/kmsdrm/SDL_kmsdrmsym.h
index 4fdce52927c1..6b4ee6936a9c 100644
--- a/src/video/kmsdrm/SDL_kmsdrmsym.h
+++ b/src/video/kmsdrm/SDL_kmsdrmsym.h
@@ -59,10 +59,6 @@ SDL_KMSDRM_SYM(drmModeCrtcPtr,drmModeGetCrtc,(int fd, uint32_t crtcId))
 SDL_KMSDRM_SYM(int,drmModeSetCrtc,(int fd, uint32_t crtcId, uint32_t bufferId,
                                    uint32_t x, uint32_t y, uint32_t *connectors, int count,
                                    drmModeModeInfoPtr mode))
-SDL_KMSDRM_SYM(int,drmModeCrtcGetGamma,(int fd, uint32_t crtc_id, uint32_t size,
-                                        uint16_t *red, uint16_t *green, uint16_t *blue))
-SDL_KMSDRM_SYM(int,drmModeCrtcSetGamma,(int fd, uint32_t crtc_id, uint32_t size,
-                                        uint16_t *red, uint16_t *green, uint16_t *blue))
 SDL_KMSDRM_SYM(int,drmModeSetCursor,(int fd, uint32_t crtcId, uint32_t bo_handle,
                                      uint32_t width, uint32_t height))
 SDL_KMSDRM_SYM(int,drmModeSetCursor2,(int fd, uint32_t crtcId, uint32_t bo_handle,
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 11aced92c974..e7f9aa674cd5 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -274,8 +274,6 @@ KMSDRM_CreateDevice(void)
     device->SetWindowPosition = KMSDRM_SetWindowPosition;
     device->SetWindowSize = KMSDRM_SetWindowSize;
     device->SetWindowFullscreen = KMSDRM_SetWindowFullscreen;
-    device->GetWindowGammaRamp = KMSDRM_GetWindowGammaRamp;
-    device->SetWindowGammaRamp = KMSDRM_SetWindowGammaRamp;
     device->ShowWindow = KMSDRM_ShowWindow;
     device->HideWindow = KMSDRM_HideWindow;
     device->RaiseWindow = KMSDRM_RaiseWindow;
@@ -1541,42 +1539,6 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window)
     return ret;
 }
 
-int
-KMSDRM_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
-{
-    SDL_WindowData *windata = (SDL_WindowData*)window->driverdata;
-    SDL_VideoData *viddata = (SDL_VideoData*)windata->viddata;
-    SDL_VideoDisplay *disp = SDL_GetDisplayForWindow(window);
-    SDL_DisplayData* dispdata = (SDL_DisplayData*)disp->driverdata;
-    if (KMSDRM_drmModeCrtcGetGamma(viddata->drm_fd, dispdata->crtc->crtc_id, 256, &ramp[0*256], &ramp[1*256], &ramp[2*256]) == -1)
-    {
-        return SDL_SetError("Failed to get gamma ramp");
-    }
-    return 0;
-}
-
-int
-KMSDRM_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
-{
-    SDL_WindowData *windata = (SDL_WindowData*)window->driverdata;
-    SDL_VideoData *viddata = (SDL_VideoData*)windata->viddata;
-    SDL_VideoDisplay *disp = SDL_GetDisplayForWindow(window);
-    SDL_DisplayData* dispdata = (SDL_DisplayData*)disp->driverdata;
-    Uint16* tempRamp = SDL_calloc(3 * sizeof(Uint16), 256);
-    if (tempRamp == NULL)
-    {
-        return SDL_OutOfMemory();
-    }
-    SDL_memcpy(tempRamp, ramp, 3 * sizeof(Uint16) * 256);
-    if (KMSDRM_drmModeCrtcSetGamma(viddata->drm_fd, dispdata->crtc->crtc_id, 256, &tempRamp[0*256], &tempRamp[1*256], &tempRamp[2*256]) == -1)
-    {
-        SDL_free(tempRamp);
-        return SDL_SetError("Failed to set gamma ramp");
-    }
-    SDL_free(tempRamp);
-    return 0;
-}
-
 int
 KMSDRM_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
 {
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h
index 48b260584fef..68b5388d3535 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -130,8 +130,6 @@ void KMSDRM_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
 void KMSDRM_SetWindowPosition(_THIS, SDL_Window * window);
 void KMSDRM_SetWindowSize(_THIS, SDL_Window * window);
 void KMSDRM_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen);
-int KMSDRM_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
-int KMSDRM_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
 void KMSDRM_ShowWindow(_THIS, SDL_Window * window);
 void KMSDRM_HideWindow(_THIS, SDL_Window * window);
 void KMSDRM_RaiseWindow(_THIS, SDL_Window * window);
diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c
index 2c30fd230953..efcbbc9f9b3c 100644
--- a/src/video/windows/SDL_windowsvideo.c
+++ b/src/video/windows/SDL_windowsvideo.c
@@ -193,9 +193,7 @@ WIN_CreateDevice(void)
     device->SetWindowAlwaysOnTop = WIN_SetWindowAlwaysOnTop;
     device->SetWindowFullscreen = WIN_SetWindowFullscreen;
 #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
-    device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
     device->GetWindowICCProfile = WIN_GetWindowICCProfile;
-    device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
     device->SetWindowMouseRect = WIN_SetWindowMouseRect;
     device->SetWindowMouseGrab = WIN_SetWindowMouseGrab;
     device->SetWindowKeyboardGrab = WIN_SetWindowKeyboardGrab;
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 93a03c9275a0..331ab83c2879 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -1022,25 +1022,6 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
 }
 
 #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
-int
-WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
-{
-    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
-    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
-    HDC hdc;
-    BOOL succeeded = FALSE;
-
-    hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL);
-    if (hdc) {
-        succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
-        if (!succeeded) {
-            WIN_SetError("SetDeviceGammaRamp()");
-        }
-        DeleteDC(hdc);
-    }
-    return succeeded ? 0 : -1;
-}
-
 void
 WIN_UpdateWindowICCProfile(SDL_Window * window, SDL_bool send_event)
 {
@@ -1091,25 +1072,6 @@ WIN_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size)
     return iccProfileData;
 }
 
-int
-WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
-{
-    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
-    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
-    HDC hdc;
-    BOOL succeeded = FALSE;
-
-    hdc = CreateDCW(data->DeviceName, NULL, NULL, NULL);
-    if (hdc) {
-        succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
-        if (!succeeded) {
-            WIN_SetError("GetDeviceGammaRamp()");
-        }
-        DeleteDC(hdc);
-    }
-    return succeeded ? 0 : -1;
-}
-
 static void WIN_GrabKeyboard(SDL_Window *window)
 {
     SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h
index c03b7660f098..eb7246a7030d 100644
--- a/src/video/windows/SDL_windowswindow.h
+++ b/src/video/windows/SDL_windowswindow.h
@@ -93,10 +93,8 @@ extern void WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
 extern void WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
 extern void WIN_SetWindowAlwaysOnTop(_THIS, SDL_Window * window, SDL_bool on_top);
 extern void WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
-extern int WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
 extern void WIN_UpdateWindowICCProfile(SDL_Window * window, SDL_bool send_event);
 extern void* WIN_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size);
-extern int WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
 extern void WIN_SetWindowMouseRect(_THIS, SDL_Window * window);
 extern void WIN_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
 extern void WIN_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed);

(Patch may be truncated, please check the link at the top of this post.)