src/video/SDL_video.c
branchSDL-1.3
changeset 1706 1577404809f0
parent 1684 c4aa1a2f48f1
child 1707 57ce47f033a5
     1.1 --- a/src/video/SDL_video.c	Sat Jun 24 04:31:42 2006 +0000
     1.2 +++ b/src/video/SDL_video.c	Sat Jun 24 16:51:01 2006 +0000
     1.3 @@ -507,6 +507,16 @@
     1.4          } else {
     1.5              closest->refresh_rate = mode->refresh_rate;
     1.6          }
     1.7 +        /* Pick some reasonable defaults if the app and driver don't care */
     1.8 +        if (!closest->format) {
     1.9 +            closest->format = SDL_PixelFormat_RGB888;
    1.10 +        }
    1.11 +        if (!closest->w) {
    1.12 +            closest->w = 640;
    1.13 +        }
    1.14 +        if (!closest->h) {
    1.15 +            closest->h = 480;
    1.16 +        }
    1.17          return closest;
    1.18      }
    1.19      return NULL;
    1.20 @@ -577,6 +587,8 @@
    1.21              if (!display->palette) {
    1.22                  return -1;
    1.23              }
    1.24 +            SDL_DitherColors(display->palette->colors,
    1.25 +                             SDL_BITSPERPIXEL(display_mode.format));
    1.26          }
    1.27      }
    1.28  
    1.29 @@ -664,7 +676,7 @@
    1.30      window.w = w;
    1.31      window.h = h;
    1.32      window.flags = (flags & allowed_flags);
    1.33 -    window.display = &SDL_CurrentDisplay;
    1.34 +    window.display = _this->current_display;
    1.35  
    1.36      if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
    1.37          if (window.title) {
    1.38 @@ -707,7 +719,7 @@
    1.39  
    1.40      SDL_zero(window);
    1.41      window.id = _this->next_object_id++;
    1.42 -    window.display = &SDL_CurrentDisplay;
    1.43 +    window.display = _this->current_display;
    1.44  
    1.45      if (!_this->CreateWindowFrom ||
    1.46          _this->CreateWindowFrom(_this, &window, data) < 0) {
    1.47 @@ -734,7 +746,7 @@
    1.48      return window.id;
    1.49  }
    1.50  
    1.51 -static __inline__ SDL_Window *
    1.52 +SDL_Window *
    1.53  SDL_GetWindowFromID(SDL_WindowID windowID)
    1.54  {
    1.55      int i, j;
    1.56 @@ -755,6 +767,15 @@
    1.57      return NULL;
    1.58  }
    1.59  
    1.60 +SDL_VideoDisplay *
    1.61 +SDL_GetDisplayFromWindow(SDL_Window * window)
    1.62 +{
    1.63 +    if (!_this) {
    1.64 +        return NULL;
    1.65 +    }
    1.66 +    return &_this->displays[window->display];
    1.67 +}
    1.68 +
    1.69  Uint32
    1.70  SDL_GetWindowFlags(SDL_WindowID windowID)
    1.71  {
    1.72 @@ -1221,11 +1242,20 @@
    1.73              return 0;
    1.74          }
    1.75      } else {
    1.76 -        bpp = fmt->BitsPerPixel;
    1.77 -        Rmask = fmt->Rmask;
    1.78 -        Gmask = fmt->Gmask;
    1.79 -        Bmask = fmt->Bmask;
    1.80 -        Amask = fmt->Amask;
    1.81 +        if (fmt->Amask || !(surface_flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA))) {
    1.82 +            bpp = fmt->BitsPerPixel;
    1.83 +            Rmask = fmt->Rmask;
    1.84 +            Gmask = fmt->Gmask;
    1.85 +            Bmask = fmt->Bmask;
    1.86 +            Amask = fmt->Amask;
    1.87 +        } else {
    1.88 +            /* Need a format with alpha */
    1.89 +            bpp = 32;
    1.90 +            Rmask = 0x00FF0000;
    1.91 +            Gmask = 0x0000FF00;
    1.92 +            Bmask = 0x000000FF;
    1.93 +            Amask = 0xFF000000;
    1.94 +        }
    1.95          format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
    1.96          if (!format) {
    1.97              SDL_SetError("Unknown pixel format");
    1.98 @@ -1261,14 +1291,10 @@
    1.99      }
   1.100  
   1.101      /* Copy the palette if any */
   1.102 -    if (fmt->palette && dst.format->palette) {
   1.103 +    if (fmt->palette) {
   1.104          SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
   1.105                                fmt->palette->ncolors);
   1.106 -
   1.107 -        SDL_memcpy(dst.format->palette->colors,
   1.108 -                   fmt->palette->colors,
   1.109 -                   fmt->palette->ncolors * sizeof(SDL_Color));
   1.110 -        dst.format->palette->ncolors = fmt->palette->ncolors;
   1.111 +        SDL_SetSurfacePalette(&dst, fmt->palette);
   1.112      }
   1.113  
   1.114      /* Make the texture transparent if the surface has colorkey */
   1.115 @@ -1552,10 +1578,11 @@
   1.116      }
   1.117  
   1.118      if (!rect) {
   1.119 +        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.120          full_rect.x = 0;
   1.121          full_rect.y = 0;
   1.122 -        full_rect.w = renderer->window->w;
   1.123 -        full_rect.h = renderer->window->h;
   1.124 +        full_rect.w = window->w;
   1.125 +        full_rect.h = window->h;
   1.126          rect = &full_rect;
   1.127      }
   1.128  
   1.129 @@ -1588,10 +1615,11 @@
   1.130          srcrect = &full_srcrect;
   1.131      }
   1.132      if (!dstrect) {
   1.133 +        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.134          full_dstrect.x = 0;
   1.135          full_dstrect.y = 0;
   1.136 -        full_dstrect.w = renderer->window->w;
   1.137 -        full_dstrect.h = renderer->window->h;
   1.138 +        full_dstrect.w = window->w;
   1.139 +        full_dstrect.h = window->h;
   1.140          dstrect = &full_dstrect;
   1.141      }
   1.142  
   1.143 @@ -1615,10 +1643,11 @@
   1.144      }
   1.145  
   1.146      if (!rect) {
   1.147 +        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.148          full_rect.x = 0;
   1.149          full_rect.y = 0;
   1.150 -        full_rect.w = renderer->window->w;
   1.151 -        full_rect.h = renderer->window->h;
   1.152 +        full_rect.w = window->w;
   1.153 +        full_rect.h = window->h;
   1.154          rect = &full_rect;
   1.155      }
   1.156  
   1.157 @@ -1641,10 +1670,11 @@
   1.158      }
   1.159  
   1.160      if (!rect) {
   1.161 +        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.162          full_rect.x = 0;
   1.163          full_rect.y = 0;
   1.164 -        full_rect.w = renderer->window->w;
   1.165 -        full_rect.h = renderer->window->h;
   1.166 +        full_rect.w = window->w;
   1.167 +        full_rect.h = window->h;
   1.168          rect = &full_rect;
   1.169      }
   1.170