src/video/SDL_video.c
changeset 5466 006883d5fa51
parent 5428 cff5d3cd5777
child 5478 6b65ff3cee62
     1.1 --- a/src/video/SDL_video.c	Thu Mar 10 01:03:43 2011 -0800
     1.2 +++ b/src/video/SDL_video.c	Fri Mar 11 08:49:20 2011 -0800
     1.3 @@ -1161,6 +1161,7 @@
     1.4          }
     1.5      }
     1.6      window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
     1.7 +    window->brightness = 1.0f;
     1.8      window->next = _this->windows;
     1.9      if (_this->windows) {
    1.10          _this->windows->prev = window;
    1.11 @@ -1193,6 +1194,7 @@
    1.12      window->magic = &_this->window_magic;
    1.13      window->id = _this->next_object_id++;
    1.14      window->flags = SDL_WINDOW_FOREIGN;
    1.15 +    window->brightness = 1.0f;
    1.16      window->next = _this->windows;
    1.17      if (_this->windows) {
    1.18          _this->windows->prev = window;
    1.19 @@ -1675,6 +1677,110 @@
    1.20      return _this->UpdateWindowFramebuffer(_this, window, rects, numrects);
    1.21  }
    1.22  
    1.23 +int
    1.24 +SDL_SetWindowBrightness(SDL_Window * window, float brightness)
    1.25 +{
    1.26 +    Uint16 ramp[256];
    1.27 +    int status;
    1.28 +
    1.29 +    CHECK_WINDOW_MAGIC(window, -1);
    1.30 +
    1.31 +    SDL_CalculateGammaRamp(brightness, ramp);
    1.32 +    status = SDL_SetWindowGammaRamp(window, ramp, ramp, ramp);
    1.33 +    if (status == 0) {
    1.34 +        window->brightness = brightness;
    1.35 +    }
    1.36 +    return status;
    1.37 +}
    1.38 +
    1.39 +float
    1.40 +SDL_GetWindowBrightness(SDL_Window * window)
    1.41 +{
    1.42 +    CHECK_WINDOW_MAGIC(window, 1.0f);
    1.43 +
    1.44 +    return window->brightness;
    1.45 +}
    1.46 +
    1.47 +int
    1.48 +SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red,
    1.49 +                                            const Uint16 * green,
    1.50 +                                            const Uint16 * blue)
    1.51 +{
    1.52 +    CHECK_WINDOW_MAGIC(window, -1);
    1.53 +
    1.54 +    if (!_this->SetWindowGammaRamp) {
    1.55 +        SDL_Unsupported();
    1.56 +        return -1;
    1.57 +    }
    1.58 +
    1.59 +    if (!window->gamma) {
    1.60 +        if (SDL_GetWindowGammaRamp(window, NULL, NULL, NULL) < 0) {
    1.61 +            return -1;
    1.62 +        }
    1.63 +    }
    1.64 +
    1.65 +    if (red) {
    1.66 +        SDL_memcpy(&window->gamma[0*256], red, 256*sizeof(Uint16));
    1.67 +    }
    1.68 +    if (green) {
    1.69 +        SDL_memcpy(&window->gamma[1*256], green, 256*sizeof(Uint16));
    1.70 +    }
    1.71 +    if (blue) {
    1.72 +        SDL_memcpy(&window->gamma[2*256], blue, 256*sizeof(Uint16));
    1.73 +    }
    1.74 +    if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
    1.75 +        return _this->SetWindowGammaRamp(_this, window, window->gamma);
    1.76 +    } else {
    1.77 +        return 0;
    1.78 +    }
    1.79 +}
    1.80 +
    1.81 +int
    1.82 +SDL_GetWindowGammaRamp(SDL_Window * window, Uint16 * red,
    1.83 +                                            Uint16 * green,
    1.84 +                                            Uint16 * blue)
    1.85 +{
    1.86 +    CHECK_WINDOW_MAGIC(window, -1);
    1.87 +
    1.88 +    if (!window->gamma) {
    1.89 +        int i;
    1.90 +
    1.91 +        window->gamma = (Uint16 *)SDL_malloc(256*6*sizeof(Uint16));
    1.92 +        if (!window->gamma) {
    1.93 +            SDL_OutOfMemory();
    1.94 +            return -1;
    1.95 +        }
    1.96 +        window->saved_gamma = window->gamma + 3*256;
    1.97 +
    1.98 +        if (_this->GetWindowGammaRamp) {
    1.99 +            if (_this->GetWindowGammaRamp(_this, window, window->gamma) < 0) {
   1.100 +                return -1;
   1.101 +            }
   1.102 +        } else {
   1.103 +            /* Create an identity gamma ramp */
   1.104 +            for (i = 0; i < 256; ++i) {
   1.105 +                Uint16 value = (Uint16)((i << 8) | i);
   1.106 +
   1.107 +                window->gamma[0*256+i] = value;
   1.108 +                window->gamma[1*256+i] = value;
   1.109 +                window->gamma[2*256+i] = value;
   1.110 +            }
   1.111 +        }
   1.112 +        SDL_memcpy(window->saved_gamma, window->gamma, 3*256*sizeof(Uint16));
   1.113 +    }
   1.114 +
   1.115 +    if (red) {
   1.116 +        SDL_memcpy(red, &window->gamma[0*256], 256*sizeof(Uint16));
   1.117 +    }
   1.118 +    if (green) {
   1.119 +        SDL_memcpy(green, &window->gamma[1*256], 256*sizeof(Uint16));
   1.120 +    }
   1.121 +    if (blue) {
   1.122 +        SDL_memcpy(blue, &window->gamma[2*256], 256*sizeof(Uint16));
   1.123 +    }
   1.124 +    return 0;
   1.125 +}
   1.126 +
   1.127  static void
   1.128  SDL_UpdateWindowGrab(SDL_Window * window)
   1.129  {
   1.130 @@ -1702,7 +1808,7 @@
   1.131  SDL_bool
   1.132  SDL_GetWindowGrab(SDL_Window * window)
   1.133  {
   1.134 -    CHECK_WINDOW_MAGIC(window, 0);
   1.135 +    CHECK_WINDOW_MAGIC(window, SDL_FALSE);
   1.136  
   1.137      return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
   1.138  }
   1.139 @@ -1745,8 +1851,12 @@
   1.140  void
   1.141  SDL_OnWindowFocusGained(SDL_Window * window)
   1.142  {
   1.143 -    if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
   1.144 -        && _this->SetWindowGrab) {
   1.145 +    if (window->gamma && _this->SetWindowGammaRamp) {
   1.146 +        _this->SetWindowGammaRamp(_this, window, window->gamma);
   1.147 +    }
   1.148 +
   1.149 +    if ((window->flags & SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN) &&
   1.150 +        _this->SetWindowGrab) {
   1.151          _this->SetWindowGrab(_this, window);
   1.152      }
   1.153  }
   1.154 @@ -1754,16 +1864,19 @@
   1.155  void
   1.156  SDL_OnWindowFocusLost(SDL_Window * window)
   1.157  {
   1.158 -    /* If we're fullscreen on a single-head system and lose focus, minimize */
   1.159 -    if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
   1.160 -        _this->num_displays == 1) {
   1.161 -        SDL_MinimizeWindow(window);
   1.162 +    if (window->gamma && _this->SetWindowGammaRamp) {
   1.163 +        _this->SetWindowGammaRamp(_this, window, window->saved_gamma);
   1.164      }
   1.165  
   1.166 -    if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN))
   1.167 -        && _this->SetWindowGrab) {
   1.168 +    if ((window->flags & SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN) &&
   1.169 +        _this->SetWindowGrab) {
   1.170          _this->SetWindowGrab(_this, window);
   1.171      }
   1.172 +
   1.173 +    /* If we're fullscreen on a single-head system and lose focus, minimize */
   1.174 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) && _this->num_displays == 1) {
   1.175 +        SDL_MinimizeWindow(window);
   1.176 +    }
   1.177  }
   1.178  
   1.179  SDL_Window *
   1.180 @@ -1818,6 +1931,9 @@
   1.181      if (window->title) {
   1.182          SDL_free(window->title);
   1.183      }
   1.184 +    if (window->gamma) {
   1.185 +        SDL_free(window->gamma);
   1.186 +    }
   1.187      while (window->data) {
   1.188          SDL_WindowUserData *data = window->data;
   1.189