src/SDL_compat.c
branchSDL-1.3
changeset 1678 90bf530ced8e
parent 1675 d33dcfc3fde7
child 1680 9488fca10677
equal deleted inserted replaced
1677:5e4c5e095925 1678:90bf530ced8e
    23 
    23 
    24 /* This file contains functions for backwards compatibility with SDL 1.2 */
    24 /* This file contains functions for backwards compatibility with SDL 1.2 */
    25 
    25 
    26 #include "SDL.h"
    26 #include "SDL.h"
    27 
    27 
    28 #include "video/SDL_sysvideo.h"
    28 #include "video/SDL_pixels_c.h"
    29 
    29 
    30 
    30 
    31 static SDL_WindowID window;
    31 static SDL_WindowID SDL_VideoWindow;
       
    32 static SDL_TextureID SDL_VideoTexture;
       
    33 static SDL_Surface *SDL_VideoSurface;
       
    34 static SDL_Surface *SDL_ShadowSurface;
       
    35 static SDL_Surface *SDL_PublicSurface;
    32 static char *wm_title;
    36 static char *wm_title;
    33 
    37 
    34 char *
    38 char *
    35 SDL_AudioDriverName(char *namebuf, int maxlen)
    39 SDL_AudioDriverName(char *namebuf, int maxlen)
    36 {
    40 {
   211     SDL_DisplayMode mode;
   215     SDL_DisplayMode mode;
   212     int i;
   216     int i;
   213     Uint32 window_flags;
   217     Uint32 window_flags;
   214     Uint32 desktop_format;
   218     Uint32 desktop_format;
   215     Uint32 desired_format;
   219     Uint32 desired_format;
       
   220     Uint32 texture_format;
   216 
   221 
   217     if (!SDL_GetVideoDevice()) {
   222     if (!SDL_GetVideoDevice()) {
   218         if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
   223         if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
   219             return NULL;
   224             return NULL;
   220         }
   225         }
   221     }
   226     }
   222 
   227 
   223     /* Destroy existing window */
   228     /* Destroy existing window */
   224     SDL_DestroyWindow(window);
   229     SDL_PublicSurface = NULL;
       
   230     if (SDL_ShadowSurface) {
       
   231         SDL_FreeSurface(SDL_ShadowSurface);
       
   232         SDL_ShadowSurface = NULL;
       
   233     }
       
   234     if (SDL_VideoSurface) {
       
   235         SDL_FreeSurface(SDL_ShadowSurface);
       
   236         SDL_VideoSurface = NULL;
       
   237     }
       
   238     SDL_DestroyWindow(SDL_VideoWindow);
   225 
   239 
   226     /* Set up the event filter */
   240     /* Set up the event filter */
   227     filter = SDL_GetEventFilter();
   241     filter = SDL_GetEventFilter();
   228     if (filter != SDL_CompatEventFilter) {
   242     if (filter != SDL_CompatEventFilter) {
   229         orig_eventfilter = filter;
   243         orig_eventfilter = filter;
   242         window_flags |= SDL_WINDOW_RESIZABLE;
   256         window_flags |= SDL_WINDOW_RESIZABLE;
   243     }
   257     }
   244     if (flags & SDL_NOFRAME) {
   258     if (flags & SDL_NOFRAME) {
   245         window_flags |= SDL_WINDOW_BORDERLESS;
   259         window_flags |= SDL_WINDOW_BORDERLESS;
   246     }
   260     }
   247     window = SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags);
   261     SDL_VideoWindow =
   248     if (!window) {
   262         SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags);
       
   263     if (!SDL_VideoWindow) {
   249         return NULL;
   264         return NULL;
   250     }
   265     }
   251 
   266 
   252     /* Set up the desired display mode */
   267     /* Set up the desired display mode */
   253     desktop_mode = SDL_GetDesktopDisplayMode();
   268     desktop_mode = SDL_GetDesktopDisplayMode();
   306     }
   321     }
   307     if (SDL_SetDisplayMode(&mode) < 0) {
   322     if (SDL_SetDisplayMode(&mode) < 0) {
   308         return NULL;
   323         return NULL;
   309     }
   324     }
   310 
   325 
   311     /* Create the display surface */
   326     /* Create a renderer for the window */
   312     return SDL_CreateWindowSurface(window, desired_format, flags);
   327     if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
   313 }
       
   314 
       
   315 SDL_Surface *
       
   316 SDL_CreateWindowSurface(SDL_WindowID windowID, Uint32 format, Uint32 flags)
       
   317 {
       
   318     SDL_Window *window = SDL_GetWindowFromID(windowID);
       
   319     Uint32 black;
       
   320     SDL_Surface *surface;
       
   321 
       
   322     if (!window) {
       
   323         return NULL;
   328         return NULL;
   324     }
   329     }
   325 
   330 
   326     if (!_this->CreateWindowSurface) {
   331     /* Create a texture for the screen surface */
       
   332     SDL_VideoTexture =
       
   333         SDL_CreateTexture(desired_format, SDL_TextureAccess_Local, width,
       
   334                           height);
       
   335     if (!SDL_VideoTexture) {
       
   336         SDL_VideoTexture =
       
   337             SDL_CreateTexture(0, SDL_TextureAccess_Local, width, height);
       
   338     }
       
   339     if (!SDL_VideoTexture) {
   327         return NULL;
   340         return NULL;
   328     }
   341     }
   329 
   342 
   330     if (!window->surface) {
   343     /* Create the screen surface */
   331         _this->CreateWindowSurface(_this, window, flags);
   344     SDL_VideoSurface = SDL_CreateRGBSurfaceFromTexture(SDL_VideoTexture);
   332         if (!window->surface) {
   345     if (!SDL_VideoSurface) {
       
   346         return NULL;
       
   347     }
       
   348 
       
   349     /* Set a default screen palette */
       
   350     if (SDL_VideoSurface->format->palette) {
       
   351         SDL_VideoSurface->flags |= SDL_HWPALETTE;
       
   352         SDL_DitherColors(SDL_VideoSurface->format->palette->colors,
       
   353                          SDL_VideoSurface->format->BitsPerPixel);
       
   354         SDL_SetTexturePalette(SDL_VideoTexture,
       
   355                               SDL_VideoSurface->format->palette->colors, 0,
       
   356                               SDL_VideoSurface->format->palette->ncolors);
       
   357     }
       
   358 
       
   359     /* Create a shadow surface if necessary */
       
   360     if (((bpp != SDL_VideoSurface->format->BitsPerPixel)
       
   361          && !(flags & SDL_ANYFORMAT))
       
   362         || ((SDL_VideoSurface->flags & SDL_HWSURFACE)
       
   363             && !(flags & SDL_HWSURFACE))) {
       
   364         if ((bpp == SDL_VideoSurface->format->BitsPerPixel)
       
   365             || (flags & SDL_ANYFORMAT)) {
       
   366             SDL_ShadowSurface =
       
   367                 SDL_CreateRGBSurface(0, width, height,
       
   368                                      SDL_VideoSurface->format->BitsPerPixel,
       
   369                                      SDL_VideoSurface->format->Rmask,
       
   370                                      SDL_VideoSurface->format->Gmask,
       
   371                                      SDL_VideoSurface->format->Bmask,
       
   372                                      SDL_VideoSurface->format->Amask);
       
   373         } else {
       
   374             SDL_ShadowSurface =
       
   375                 SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0);
       
   376         }
       
   377         if (!SDL_ShadowSurface) {
   333             return NULL;
   378             return NULL;
   334         }
   379         }
   335         window->surface->flags |= SDL_SCREEN_SURFACE;
   380 
   336 
   381         /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
   337         /* If we have a palettized surface, create a default palette */
   382         if (SDL_ShadowSurface->format->palette) {
   338         if (window->surface->format->palette) {
   383             SDL_ShadowSurface->flags |= SDL_HWPALETTE;
   339             SDL_Color colors[256];
   384             SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
   340             SDL_PixelFormat *vf = window->surface->format;
   385                              SDL_ShadowSurface->format->BitsPerPixel);
   341             SDL_DitherColors(colors, vf->BitsPerPixel);
   386         }
   342             SDL_SetColors(window->surface, colors, 0, vf->palette->ncolors);
   387     }
   343         }
   388     SDL_PublicSurface =
   344     }
   389         (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface);
   345     surface = window->surface;
       
   346 
       
   347     if (window->shadow) {
       
   348         SDL_FreeSurface(window->shadow);
       
   349         window->shadow = NULL;
       
   350     }
       
   351 
       
   352     /* Create a shadow surface if necessary */
       
   353     if ((!(flags & SDL_ANYFORMAT)
       
   354          && (format != SDL_GetCurrentDisplayMode()->format))
       
   355         || ((flags & SDL_HWPALETTE)
       
   356             && !(window->surface->flags & SDL_HWPALETTE))) {
       
   357         int bpp;
       
   358         Uint32 Rmask, Gmask, Bmask, Amask;
       
   359 
       
   360         SDL_PixelFormatEnumToMasks(format, &bpp, &Amask, &Gmask, &Bmask,
       
   361                                    &Amask);
       
   362         window->shadow =
       
   363             SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, bpp,
       
   364                                  Rmask, Gmask, Bmask, Amask);
       
   365         if (window->shadow == NULL) {
       
   366             return NULL;
       
   367         }
       
   368         window->shadow->flags |= SDL_SHADOW_SURFACE;
       
   369 
       
   370         surface = window->shadow;
       
   371 
       
   372         /* 8-bit shadow surfaces report that they have exclusive palette */
       
   373         if (surface->format->palette) {
       
   374             surface->flags |= SDL_HWPALETTE;
       
   375             if (format == SDL_GetCurrentDisplayMode()->format) {
       
   376                 SDL_memcpy(surface->format->palette->colors,
       
   377                            window->surface->format->palette->colors,
       
   378                            window->surface->format->palette->ncolors *
       
   379                            sizeof(SDL_Color));
       
   380             } else {
       
   381                 SDL_DitherColors(surface->format->palette->colors, bpp);
       
   382             }
       
   383         }
       
   384     }
       
   385 
   390 
   386     /* Clear the surface for display */
   391     /* Clear the surface for display */
   387     {
   392     SDL_FillRect(SDL_PublicSurface, NULL, 0);
   388         Uint32 black = SDL_MapRGB(surface->format, 0, 0, 0);
   393 
   389         SDL_FillRect(surface, NULL, black);
   394     /* We're finally done! */
   390         if (surface->flags & SDL_DOUBLEBUF) {
   395     return SDL_PublicSurface;
   391             SDL_Flip(surface);
       
   392             SDL_FillRect(surface, NULL, black);
       
   393         }
       
   394         SDL_Flip(surface);
       
   395     }
       
   396 
       
   397     return surface;
       
   398 }
   396 }
   399 
   397 
   400 SDL_Surface *
   398 SDL_Surface *
   401 SDL_GetVideoSurface(void)
   399 SDL_GetVideoSurface(void)
   402 {
   400 {
   403     SDL_VideoDevice *_this = SDL_GetVideoDevice();
   401     return SDL_PublicSurface;
   404 
       
   405     return SDL_VideoSurface;
       
   406 }
   402 }
   407 
   403 
   408 SDL_Surface *
   404 SDL_Surface *
   409 SDL_DisplayFormat(SDL_Surface * surface)
   405 SDL_DisplayFormat(SDL_Surface * surface)
   410 {
   406 {
   411     Uint32 flags;
   407     Uint32 flags;
   412 
   408 
   413     if (!SDL_PublicSurface) {
   409     if (!SDL_PublicSurface) {
   414         SDL_SetError("No video mode has been set");
   410         SDL_SetError("No video mode has been set");
   415         return (NULL);
   411         return NULL;
   416     }
   412     }
       
   413 
   417     /* Set the flags appropriate for copying to display surface */
   414     /* Set the flags appropriate for copying to display surface */
   418     if (((SDL_PublicSurface->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
   415     flags = SDL_SWSURFACE;
   419         && _this->info.blit_hw)
       
   420         flags = SDL_HWSURFACE;
       
   421     else
       
   422         flags = SDL_SWSURFACE;
       
   423 #ifdef AUTORLE_DISPLAYFORMAT
   416 #ifdef AUTORLE_DISPLAYFORMAT
   424     flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
   417     flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
   425     flags |= SDL_RLEACCELOK;
   418     flags |= SDL_RLEACCELOK;
   426 #else
   419 #else
   427     flags |=
   420     flags |=
   428         surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
   421         surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
   429 #endif
   422 #endif
   430     return (SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));
   423     return SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags);
   431 }
   424 }
   432 
   425 
   433 SDL_Surface *
   426 SDL_Surface *
   434 SDL_DisplayFormatAlpha(SDL_Surface * surface)
   427 SDL_DisplayFormatAlpha(SDL_Surface * surface)
   435 {
   428 {
   443     Uint32 gmask = 0x0000ff00;
   436     Uint32 gmask = 0x0000ff00;
   444     Uint32 bmask = 0x000000ff;
   437     Uint32 bmask = 0x000000ff;
   445 
   438 
   446     if (!SDL_PublicSurface) {
   439     if (!SDL_PublicSurface) {
   447         SDL_SetError("No video mode has been set");
   440         SDL_SetError("No video mode has been set");
   448         return (NULL);
   441         return NULL;
   449     }
   442     }
   450     vf = SDL_PublicSurface->format;
   443     vf = SDL_PublicSurface->format;
   451 
   444 
   452     switch (vf->BytesPerPixel) {
   445     switch (vf->BytesPerPixel) {
   453     case 2:
   446     case 2:
   479     format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
   472     format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
   480     flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
   473     flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
   481     flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   474     flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   482     converted = SDL_ConvertSurface(surface, format, flags);
   475     converted = SDL_ConvertSurface(surface, format, flags);
   483     SDL_FreeFormat(format);
   476     SDL_FreeFormat(format);
   484     return (converted);
   477     return converted;
       
   478 }
       
   479 
       
   480 int
       
   481 SDL_Flip(SDL_Surface * screen)
       
   482 {
       
   483     SDL_UpdateRect(screen, 0, 0, 0, 0);
       
   484     return 0;
   485 }
   485 }
   486 
   486 
   487 void
   487 void
   488 SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
   488 SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
   489 {
   489 {
   510 }
   510 }
   511 void
   511 void
   512 SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
   512 SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
   513 {
   513 {
   514     int i;
   514     int i;
   515     SDL_Window *window;
   515 
   516 
   516     if (screen == SDL_ShadowSurface) {
   517     /* Find the window corresponding to this surface */
   517         for (i = 0; i < numrects; ++i) {
   518     window = SDL_GetWindowFromSurface(screen);
   518             SDL_LowerBlit(SDL_ShadowSurface, &rects[i], SDL_VideoSurface,
   519     if (!window) {
   519                           &rects[i]);
   520         SDL_SetError("Couldn't find window associated with surface");
       
   521         return;
       
   522     }
       
   523 
       
   524     if (screen->flags & SDL_SHADOW_SURFACE) {
       
   525         if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
       
   526             SDL_LockCursor();
       
   527             SDL_DrawCursor(screen);
       
   528             for (i = 0; i < numrects; ++i) {
       
   529                 SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]);
       
   530             }
       
   531             SDL_EraseCursor(screen);
       
   532             SDL_UnlockCursor();
       
   533         } else {
       
   534             for (i = 0; i < numrects; ++i) {
       
   535                 SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]);
       
   536             }
       
   537         }
   520         }
   538 
   521 
   539         /* Fall through to video surface update */
   522         /* Fall through to video surface update */
   540         screen = window->surface;
   523         screen = SDL_VideoSurface;
   541     }
   524     }
   542     if ((screen->flags & SDL_SCREEN_SURFACE) && _this->UpdateWindowSurface) {
   525     if (screen == SDL_VideoSurface) {
   543         /* Update the video surface */
   526         for (i = 0; i < numrects; ++i) {
   544         if (screen->offset) {
   527             SDL_RenderCopy(SDL_VideoTexture, &rects[i], &rects[i],
   545             int offset_y = screen->offset / screen->pitch;
   528                            SDL_TextureBlendMode_None,
   546             int offset_x = screen->offset % screen->pitch;
   529                            SDL_TextureScaleMode_None);
   547             for (i = 0; i < numrects; ++i) {
   530         }
   548                 rects[i].x += offset_x;
   531         SDL_RenderPresent();
   549                 rects[i].y += offset_y;
   532     }
   550             }
       
   551             _this->UpdateWindowSurface(_this, window, numrects, rects);
       
   552             for (i = 0; i < numrects; ++i) {
       
   553                 rects[i].x -= offset_x;
       
   554                 rects[i].y -= offset_y;
       
   555             }
       
   556         } else {
       
   557             _this->UpdateWindowSurface(_this, window, numrects, rects);
       
   558         }
       
   559     }
       
   560 }
       
   561 
       
   562 int
       
   563 SDL_Flip(SDL_Surface * screen)
       
   564 {
       
   565     SDL_Window *window;
       
   566 
       
   567     /* Find the window corresponding to this surface */
       
   568     window = SDL_GetWindowFromSurface(screen);
       
   569     if (!window) {
       
   570         SDL_SetError("Couldn't find window associated with surface");
       
   571         return;
       
   572     }
       
   573 
       
   574     /* Copy the shadow surface to the video surface */
       
   575     if (screen->flags & SDL_SHADOW_SURFACE) {
       
   576         SDL_Rect rect;
       
   577 
       
   578         rect.x = 0;
       
   579         rect.y = 0;
       
   580         rect.w = screen->w;
       
   581         rect.h = screen->h;
       
   582         if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
       
   583             SDL_LockCursor();
       
   584             SDL_DrawCursor(screen);
       
   585             SDL_LowerBlit(screen, &rect, window->surface, &rect);
       
   586             SDL_EraseCursor(screen);
       
   587             SDL_UnlockCursor();
       
   588         } else {
       
   589             SDL_LowerBlit(screen, &rect, window->surface, &rect);
       
   590         }
       
   591 
       
   592         /* Fall through to video surface update */
       
   593         screen = window->surface;
       
   594     }
       
   595     if (screen->flags & SDL_DOUBLEBUF) {
       
   596         _this->FlipWindowSurface(_this, window);
       
   597     } else {
       
   598         SDL_UpdateRect(screen, 0, 0, 0, 0);
       
   599     }
       
   600     return (0);
       
   601 }
   533 }
   602 
   534 
   603 void
   535 void
   604 SDL_WM_SetCaption(const char *title, const char *icon)
   536 SDL_WM_SetCaption(const char *title, const char *icon)
   605 {
   537 {
   606     if (wm_title) {
   538     if (wm_title) {
   607         SDL_free(wm_title);
   539         SDL_free(wm_title);
   608     } else {
   540     } else {
   609         wm_title = SDL_strdup(title);
   541         wm_title = SDL_strdup(title);
   610     }
   542     }
   611     SDL_SetWindowTitle(window, wm_title);
   543     SDL_SetWindowTitle(SDL_VideoWindow, wm_title);
   612 }
   544 }
   613 
   545 
   614 void
   546 void
   615 SDL_WM_GetCaption(char **title, char **icon)
   547 SDL_WM_GetCaption(char **title, char **icon)
   616 {
   548 {
   629 }
   561 }
   630 
   562 
   631 int
   563 int
   632 SDL_WM_IconifyWindow(void)
   564 SDL_WM_IconifyWindow(void)
   633 {
   565 {
   634     SDL_MinimizeWindow(window);
   566     SDL_MinimizeWindow(SDL_VideoWindow);
   635 }
   567 }
   636 
   568 
   637 int
   569 int
   638 SDL_WM_ToggleFullScreen(SDL_Surface * surface)
   570 SDL_WM_ToggleFullScreen(SDL_Surface * surface)
   639 {
   571 {
   642 
   574 
   643 SDL_GrabMode
   575 SDL_GrabMode
   644 SDL_WM_GrabInput(SDL_GrabMode mode)
   576 SDL_WM_GrabInput(SDL_GrabMode mode)
   645 {
   577 {
   646     if (mode != SDL_GRAB_QUERY) {
   578     if (mode != SDL_GRAB_QUERY) {
   647         SDL_SetWindowGrab(window, mode);
   579         SDL_SetWindowGrab(SDL_VideoWindow, mode);
   648     }
   580     }
   649     return (SDL_GrabMode) SDL_GetWindowGrab(window);
   581     return (SDL_GrabMode) SDL_GetWindowGrab(SDL_VideoWindow);
   650 }
   582 }
   651 
   583 
   652 Uint8
   584 Uint8
   653 SDL_GetAppState(void)
   585 SDL_GetAppState(void)
   654 {
   586 {
   655     Uint8 state = 0;
   587     Uint8 state = 0;
   656     Uint32 flags = 0;
   588     Uint32 flags = 0;
   657 
   589 
   658     flags = SDL_GetWindowFlags(window);
   590     flags = SDL_GetWindowFlags(SDL_VideoWindow);
   659     if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
   591     if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
   660         state |= SDL_APPACTIVE;
   592         state |= SDL_APPACTIVE;
   661     }
   593     }
   662     if (flags & SDL_WINDOW_KEYBOARD_FOCUS) {
   594     if (flags & SDL_WINDOW_KEYBOARD_FOCUS) {
   663         state |= SDL_APPINPUTFOCUS;
   595         state |= SDL_APPINPUTFOCUS;
   685 
   617 
   686 int
   618 int
   687 SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor,
   619 SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor,
   688                     int ncolors)
   620                     int ncolors)
   689 {
   621 {
   690     SDL_Window *window = NULL;
       
   691     SDL_Palette *pal;
   622     SDL_Palette *pal;
   692     int gotall;
   623     int gotall;
   693     int palsize;
   624     int palsize;
   694 
   625 
   695     /* Verify the parameters */
   626     /* Verify the parameters */
   702     if (ncolors > (palsize - firstcolor)) {
   633     if (ncolors > (palsize - firstcolor)) {
   703         ncolors = (palsize - firstcolor);
   634         ncolors = (palsize - firstcolor);
   704         gotall = 0;
   635         gotall = 0;
   705     }
   636     }
   706 
   637 
   707     if (screen->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) {
   638     if (screen == SDL_ShadowSurface) {
   708         window = SDL_GetWindowFromSurface(screen);
       
   709         if (!window) {
       
   710             return 0;
       
   711         }
       
   712     }
       
   713 
       
   714     if (screen->flags & SDL_SHADOW_SURFACE) {
       
   715         SDL_Palette *vidpal;
   639         SDL_Palette *vidpal;
   716 
   640 
   717         vidpal = window->surface->format->palette;
   641         vidpal = SDL_VideoSurface->format->palette;
   718         if (vidpal && vidpal->ncolors == pal->ncolors) {
   642         if (vidpal && vidpal->ncolors == pal->ncolors) {
   719             /* This is a shadow surface, and the physical
   643             /* This is a shadow surface, and the physical
   720              * framebuffer is also indexed. Propagate the
   644              * framebuffer is also indexed. Propagate the
   721              * changes to its logical palette so that
   645              * changes to its logical palette so that
   722              * updates are always identity blits
   646              * updates are always identity blits
   723              */
   647              */
   724             SDL_memcpy(vidpal->colors + firstcolor, colors,
   648             SDL_memcpy(vidpal->colors + firstcolor, colors,
   725                        ncolors * sizeof(*colors));
   649                        ncolors * sizeof(*colors));
   726         }
   650         }
   727         if (window->surface->flags & SDL_HWPALETTE) {
   651         if (SDL_VideoSurface->flags & SDL_HWPALETTE) {
   728             /* Set the physical palette */
   652             /* Set the physical palette */
   729             screen = window->surface;
   653             screen = SDL_VideoSurface;
   730         } else {
   654         } else {
   731             SDL_UpdateRect(screen, 0, 0, 0, 0);
   655             SDL_UpdateRect(screen, 0, 0, 0, 0);
   732         }
   656         }
   733     }
   657     }
   734 
   658 
   735     if (screen->flags & SDL_SCREEN_SURFACE) {
   659     if (screen == SDL_VideoSurface) {
   736         if (_this->SetWindowColors) {
   660         SDL_SetTexturePalette(SDL_VideoTexture,
   737             gotall =
   661                               SDL_VideoSurface->format->palette->colors, 0,
   738                 _this->SetWindowColors(_this, window, firstcolor, ncolors,
   662                               SDL_VideoSurface->format->palette->ncolors);
   739                                        colors);
       
   740             if (!gotall) {
       
   741                 /* The video flags shouldn't have SDL_HWPALETTE, and
       
   742                    the video driver is responsible for copying back the
       
   743                    correct colors into the video surface palette.
       
   744                  */
       
   745                 ;
       
   746             }
       
   747         }
       
   748         SDL_CursorPaletteChanged();
       
   749     }
   663     }
   750 
   664 
   751     return gotall;
   665     return gotall;
   752 }
   666 }
   753 
   667 
   754 int
   668 int
   755 SDL_GetWMInfo(SDL_SysWMinfo * info)
   669 SDL_GetWMInfo(SDL_SysWMinfo * info)
   756 {
   670 {
   757     return SDL_GetWindowWMInfo(window, info);
   671     return SDL_GetWindowWMInfo(SDL_VideoWindow, info);
   758 }
   672 }
   759 
   673 
       
   674 #if 0
   760 void
   675 void
   761 SDL_MoveCursor(int x, int y)
   676 SDL_MoveCursor(int x, int y)
   762 {
   677 {
   763     SDL_VideoDevice *_this = SDL_GetVideoDevice();
   678     SDL_VideoDevice *_this = SDL_GetVideoDevice();
   764 
   679 
  1347             overlay->hwfuncs->FreeHW(_this, overlay);
  1262             overlay->hwfuncs->FreeHW(_this, overlay);
  1348         }
  1263         }
  1349         SDL_free(overlay);
  1264         SDL_free(overlay);
  1350     }
  1265     }
  1351 }
  1266 }
       
  1267 #endif
  1352 
  1268 
  1353 /* vi: set ts=4 sw=4 expandtab: */
  1269 /* vi: set ts=4 sw=4 expandtab: */