comparison src/SDL_compat.c @ 1683:396a35389351 SDL-1.3

Finished palettized display handling. Added support for surface palette sharing.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 17 Jun 2006 06:45:14 +0000
parents 7ae8018b2e5d
children c4aa1a2f48f1
comparison
equal deleted inserted replaced
1682:7ae8018b2e5d 1683:396a35389351
202 fake.active.state = SDL_APPINPUTFOCUS; 202 fake.active.state = SDL_APPINPUTFOCUS;
203 SDL_PushEvent(&fake); 203 SDL_PushEvent(&fake);
204 break; 204 break;
205 } 205 }
206 } 206 }
207 return orig_eventfilter(event); 207 if (orig_eventfilter) {
208 return orig_eventfilter(event);
209 } else {
210 return 1;
211 }
212 }
213
214 static int
215 SDL_VideoPaletteChanged(void *userdata, SDL_Palette * palette)
216 {
217 if (userdata == SDL_ShadowSurface) {
218 /* If the shadow palette changed, make the changes visible */
219 if (!SDL_VideoSurface->format->palette) {
220 SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
221 }
222 }
223 if (userdata == SDL_VideoSurface) {
224 return SDL_SetDisplayPalette(palette->colors, 0, palette->ncolors);
225 }
208 } 226 }
209 227
210 SDL_Surface * 228 SDL_Surface *
211 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) 229 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
212 { 230 {
231 if (SDL_ShadowSurface) { 249 if (SDL_ShadowSurface) {
232 SDL_FreeSurface(SDL_ShadowSurface); 250 SDL_FreeSurface(SDL_ShadowSurface);
233 SDL_ShadowSurface = NULL; 251 SDL_ShadowSurface = NULL;
234 } 252 }
235 if (SDL_VideoSurface) { 253 if (SDL_VideoSurface) {
236 SDL_FreeSurface(SDL_ShadowSurface); 254 SDL_DelPaletteWatch(SDL_VideoSurface->format->palette,
255 SDL_VideoPaletteChanged, NULL);
256 SDL_FreeSurface(SDL_VideoSurface);
237 SDL_VideoSurface = NULL; 257 SDL_VideoSurface = NULL;
238 } 258 }
239 SDL_DestroyWindow(SDL_VideoWindow); 259 SDL_DestroyWindow(SDL_VideoWindow);
240 260
241 /* Set up the event filter */ 261 /* Set up the event filter */
378 /* Set a default screen palette */ 398 /* Set a default screen palette */
379 if (SDL_VideoSurface->format->palette) { 399 if (SDL_VideoSurface->format->palette) {
380 SDL_VideoSurface->flags |= SDL_HWPALETTE; 400 SDL_VideoSurface->flags |= SDL_HWPALETTE;
381 SDL_DitherColors(SDL_VideoSurface->format->palette->colors, 401 SDL_DitherColors(SDL_VideoSurface->format->palette->colors,
382 SDL_VideoSurface->format->BitsPerPixel); 402 SDL_VideoSurface->format->BitsPerPixel);
383 SDL_SetTexturePalette(SDL_VideoTexture, 403 SDL_AddPaletteWatch(SDL_VideoSurface->format->palette,
384 SDL_VideoSurface->format->palette->colors, 0, 404 SDL_VideoPaletteChanged, NULL);
385 SDL_VideoSurface->format->palette->ncolors); 405 SDL_SetPaletteColors(SDL_VideoSurface->format->palette,
386 SDL_SetDisplayPalette(SDL_VideoSurface->format->palette->colors, 0, 406 SDL_VideoSurface->format->palette->colors, 0,
387 SDL_VideoSurface->format->palette->ncolors); 407 SDL_VideoSurface->format->palette->ncolors);
388 } 408 }
389 409
390 /* Create a shadow surface if necessary */ 410 /* Create a shadow surface if necessary */
391 if (((bpp != SDL_VideoSurface->format->BitsPerPixel) 411 if (((bpp != SDL_VideoSurface->format->BitsPerPixel)
392 && !(flags & SDL_ANYFORMAT)) 412 && !(flags & SDL_ANYFORMAT))
413 SDL_ShadowSurface->flags |= surface_flags; 433 SDL_ShadowSurface->flags |= surface_flags;
414 434
415 /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */ 435 /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
416 if (SDL_ShadowSurface->format->palette) { 436 if (SDL_ShadowSurface->format->palette) {
417 SDL_ShadowSurface->flags |= SDL_HWPALETTE; 437 SDL_ShadowSurface->flags |= SDL_HWPALETTE;
418 SDL_DitherColors(SDL_ShadowSurface->format->palette->colors, 438 if (SDL_VideoSurface->format->palette) {
419 SDL_ShadowSurface->format->BitsPerPixel); 439 SDL_SetSurfacePalette(SDL_ShadowSurface,
440 SDL_VideoSurface->format->palette);
441 } else {
442 SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
443 SDL_ShadowSurface->format->BitsPerPixel);
444 }
420 } 445 }
421 } 446 }
422 SDL_PublicSurface = 447 SDL_PublicSurface =
423 (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface); 448 (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface);
424 449
654 { 679 {
655 SDL_SetColors(surface, colors, firstcolor, ncolors); 680 SDL_SetColors(surface, colors, firstcolor, ncolors);
656 } 681 }
657 682
658 int 683 int
659 SDL_SetScreenColors(SDL_Surface * screen, const SDL_Color * colors, 684 SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
660 int firstcolor, int ncolors) 685 int ncolors)
661 { 686 {
662 SDL_Palette *pal; 687 if (SDL_SetPaletteColors
663 int gotall; 688 (surface->format->palette, colors, firstcolor, ncolors) == 0) {
664 int palsize; 689 return 1;
665 690 } else {
666 /* Verify the parameters */ 691 return 0;
667 pal = screen->format->palette; 692 }
668 if (!pal) {
669 return 0; /* not a palettized surface */
670 }
671 gotall = 1;
672 palsize = 1 << screen->format->BitsPerPixel;
673 if (ncolors > (palsize - firstcolor)) {
674 ncolors = (palsize - firstcolor);
675 gotall = 0;
676 }
677
678 if (screen == SDL_ShadowSurface) {
679 SDL_Palette *vidpal;
680
681 vidpal = SDL_VideoSurface->format->palette;
682 if (vidpal && vidpal->ncolors == pal->ncolors) {
683 /* This is a shadow surface, and the physical
684 * framebuffer is also indexed. Propagate the
685 * changes to its logical palette so that
686 * updates are always identity blits
687 */
688 SDL_memcpy(vidpal->colors + firstcolor, colors,
689 ncolors * sizeof(*colors));
690 }
691 if (SDL_VideoSurface->flags & SDL_HWPALETTE) {
692 /* Set the physical palette */
693 screen = SDL_VideoSurface;
694 } else {
695 SDL_UpdateRect(screen, 0, 0, 0, 0);
696 }
697 }
698
699 if (screen == SDL_VideoSurface) {
700 SDL_SetTexturePalette(SDL_VideoTexture,
701 SDL_VideoSurface->format->palette->colors, 0,
702 SDL_VideoSurface->format->palette->ncolors);
703 SDL_SetDisplayPalette(SDL_VideoSurface->format->palette->colors, 0,
704 SDL_VideoSurface->format->palette->ncolors);
705 }
706
707 return gotall;
708 } 693 }
709 694
710 int 695 int
711 SDL_GetWMInfo(SDL_SysWMinfo * info) 696 SDL_GetWMInfo(SDL_SysWMinfo * info)
712 { 697 {