comparison src/video/SDL_video.c @ 1706:1577404809f0 SDL-1.3

Added a multi-window version of testsprite using the new API.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 24 Jun 2006 16:51:01 +0000
parents c4aa1a2f48f1
children 57ce47f033a5
comparison
equal deleted inserted replaced
1705:fc731a7d83ed 1706:1577404809f0
505 if (match->refresh_rate) { 505 if (match->refresh_rate) {
506 closest->refresh_rate = match->refresh_rate; 506 closest->refresh_rate = match->refresh_rate;
507 } else { 507 } else {
508 closest->refresh_rate = mode->refresh_rate; 508 closest->refresh_rate = mode->refresh_rate;
509 } 509 }
510 /* Pick some reasonable defaults if the app and driver don't care */
511 if (!closest->format) {
512 closest->format = SDL_PixelFormat_RGB888;
513 }
514 if (!closest->w) {
515 closest->w = 640;
516 }
517 if (!closest->h) {
518 closest->h = 480;
519 }
510 return closest; 520 return closest;
511 } 521 }
512 return NULL; 522 return NULL;
513 } 523 }
514 524
575 if (ncolors) { 585 if (ncolors) {
576 display->palette = SDL_AllocPalette(ncolors); 586 display->palette = SDL_AllocPalette(ncolors);
577 if (!display->palette) { 587 if (!display->palette) {
578 return -1; 588 return -1;
579 } 589 }
590 SDL_DitherColors(display->palette->colors,
591 SDL_BITSPERPIXEL(display_mode.format));
580 } 592 }
581 } 593 }
582 594
583 return _this->SetDisplayMode(_this, &display_mode); 595 return _this->SetDisplayMode(_this, &display_mode);
584 } 596 }
662 window.x = x; 674 window.x = x;
663 window.y = y; 675 window.y = y;
664 window.w = w; 676 window.w = w;
665 window.h = h; 677 window.h = h;
666 window.flags = (flags & allowed_flags); 678 window.flags = (flags & allowed_flags);
667 window.display = &SDL_CurrentDisplay; 679 window.display = _this->current_display;
668 680
669 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { 681 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
670 if (window.title) { 682 if (window.title) {
671 SDL_free(window.title); 683 SDL_free(window.title);
672 } 684 }
705 return (0); 717 return (0);
706 } 718 }
707 719
708 SDL_zero(window); 720 SDL_zero(window);
709 window.id = _this->next_object_id++; 721 window.id = _this->next_object_id++;
710 window.display = &SDL_CurrentDisplay; 722 window.display = _this->current_display;
711 723
712 if (!_this->CreateWindowFrom || 724 if (!_this->CreateWindowFrom ||
713 _this->CreateWindowFrom(_this, &window, data) < 0) { 725 _this->CreateWindowFrom(_this, &window, data) < 0) {
714 return 0; 726 return 0;
715 } 727 }
732 SDL_CurrentDisplay.num_windows++; 744 SDL_CurrentDisplay.num_windows++;
733 745
734 return window.id; 746 return window.id;
735 } 747 }
736 748
737 static __inline__ SDL_Window * 749 SDL_Window *
738 SDL_GetWindowFromID(SDL_WindowID windowID) 750 SDL_GetWindowFromID(SDL_WindowID windowID)
739 { 751 {
740 int i, j; 752 int i, j;
741 753
742 if (!_this) { 754 if (!_this) {
751 return window; 763 return window;
752 } 764 }
753 } 765 }
754 } 766 }
755 return NULL; 767 return NULL;
768 }
769
770 SDL_VideoDisplay *
771 SDL_GetDisplayFromWindow(SDL_Window * window)
772 {
773 if (!_this) {
774 return NULL;
775 }
776 return &_this->displays[window->display];
756 } 777 }
757 778
758 Uint32 779 Uint32
759 SDL_GetWindowFlags(SDL_WindowID windowID) 780 SDL_GetWindowFlags(SDL_WindowID windowID)
760 { 781 {
1219 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { 1240 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
1220 SDL_SetError("Unknown pixel format"); 1241 SDL_SetError("Unknown pixel format");
1221 return 0; 1242 return 0;
1222 } 1243 }
1223 } else { 1244 } else {
1224 bpp = fmt->BitsPerPixel; 1245 if (fmt->Amask || !(surface_flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA))) {
1225 Rmask = fmt->Rmask; 1246 bpp = fmt->BitsPerPixel;
1226 Gmask = fmt->Gmask; 1247 Rmask = fmt->Rmask;
1227 Bmask = fmt->Bmask; 1248 Gmask = fmt->Gmask;
1228 Amask = fmt->Amask; 1249 Bmask = fmt->Bmask;
1250 Amask = fmt->Amask;
1251 } else {
1252 /* Need a format with alpha */
1253 bpp = 32;
1254 Rmask = 0x00FF0000;
1255 Gmask = 0x0000FF00;
1256 Bmask = 0x000000FF;
1257 Amask = 0xFF000000;
1258 }
1229 format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); 1259 format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
1230 if (!format) { 1260 if (!format) {
1231 SDL_SetError("Unknown pixel format"); 1261 SDL_SetError("Unknown pixel format");
1232 return 0; 1262 return 0;
1233 } 1263 }
1259 return 0; 1289 return 0;
1260 } 1290 }
1261 } 1291 }
1262 1292
1263 /* Copy the palette if any */ 1293 /* Copy the palette if any */
1264 if (fmt->palette && dst.format->palette) { 1294 if (fmt->palette) {
1265 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, 1295 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
1266 fmt->palette->ncolors); 1296 fmt->palette->ncolors);
1267 1297 SDL_SetSurfacePalette(&dst, fmt->palette);
1268 SDL_memcpy(dst.format->palette->colors,
1269 fmt->palette->colors,
1270 fmt->palette->ncolors * sizeof(SDL_Color));
1271 dst.format->palette->ncolors = fmt->palette->ncolors;
1272 } 1298 }
1273 1299
1274 /* Make the texture transparent if the surface has colorkey */ 1300 /* Make the texture transparent if the surface has colorkey */
1275 if (surface_flags & SDL_SRCCOLORKEY) { 1301 if (surface_flags & SDL_SRCCOLORKEY) {
1276 int row; 1302 int row;
1550 if (!renderer || !renderer->RenderFill) { 1576 if (!renderer || !renderer->RenderFill) {
1551 return -1; 1577 return -1;
1552 } 1578 }
1553 1579
1554 if (!rect) { 1580 if (!rect) {
1581 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1555 full_rect.x = 0; 1582 full_rect.x = 0;
1556 full_rect.y = 0; 1583 full_rect.y = 0;
1557 full_rect.w = renderer->window->w; 1584 full_rect.w = window->w;
1558 full_rect.h = renderer->window->h; 1585 full_rect.h = window->h;
1559 rect = &full_rect; 1586 rect = &full_rect;
1560 } 1587 }
1561 1588
1562 renderer->RenderFill(renderer, rect, color); 1589 renderer->RenderFill(renderer, rect, color);
1563 } 1590 }
1586 full_srcrect.w = texture->w; 1613 full_srcrect.w = texture->w;
1587 full_srcrect.h = texture->h; 1614 full_srcrect.h = texture->h;
1588 srcrect = &full_srcrect; 1615 srcrect = &full_srcrect;
1589 } 1616 }
1590 if (!dstrect) { 1617 if (!dstrect) {
1618 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1591 full_dstrect.x = 0; 1619 full_dstrect.x = 0;
1592 full_dstrect.y = 0; 1620 full_dstrect.y = 0;
1593 full_dstrect.w = renderer->window->w; 1621 full_dstrect.w = window->w;
1594 full_dstrect.h = renderer->window->h; 1622 full_dstrect.h = window->h;
1595 dstrect = &full_dstrect; 1623 dstrect = &full_dstrect;
1596 } 1624 }
1597 1625
1598 return renderer->RenderCopy(renderer, texture, srcrect, dstrect, 1626 return renderer->RenderCopy(renderer, texture, srcrect, dstrect,
1599 blendMode, scaleMode); 1627 blendMode, scaleMode);
1613 if (!renderer || !renderer->RenderReadPixels) { 1641 if (!renderer || !renderer->RenderReadPixels) {
1614 return -1; 1642 return -1;
1615 } 1643 }
1616 1644
1617 if (!rect) { 1645 if (!rect) {
1646 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1618 full_rect.x = 0; 1647 full_rect.x = 0;
1619 full_rect.y = 0; 1648 full_rect.y = 0;
1620 full_rect.w = renderer->window->w; 1649 full_rect.w = window->w;
1621 full_rect.h = renderer->window->h; 1650 full_rect.h = window->h;
1622 rect = &full_rect; 1651 rect = &full_rect;
1623 } 1652 }
1624 1653
1625 return renderer->RenderReadPixels(renderer, rect, pixels, pitch); 1654 return renderer->RenderReadPixels(renderer, rect, pixels, pitch);
1626 } 1655 }
1639 if (!renderer || !renderer->RenderWritePixels) { 1668 if (!renderer || !renderer->RenderWritePixels) {
1640 return -1; 1669 return -1;
1641 } 1670 }
1642 1671
1643 if (!rect) { 1672 if (!rect) {
1673 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
1644 full_rect.x = 0; 1674 full_rect.x = 0;
1645 full_rect.y = 0; 1675 full_rect.y = 0;
1646 full_rect.w = renderer->window->w; 1676 full_rect.w = window->w;
1647 full_rect.h = renderer->window->h; 1677 full_rect.h = window->h;
1648 rect = &full_rect; 1678 rect = &full_rect;
1649 } 1679 }
1650 1680
1651 return renderer->RenderWritePixels(renderer, rect, pixels, pitch); 1681 return renderer->RenderWritePixels(renderer, rect, pixels, pitch);
1652 } 1682 }