Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 1681:80a5e6a4e1e2 SDL-1.3
Working on paletted display and texture support (two different issues)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 15 Jun 2006 07:07:07 +0000 |
parents | 9488fca10677 |
children | 7ae8018b2e5d |
comparison
equal
deleted
inserted
replaced
1680:9488fca10677 | 1681:80a5e6a4e1e2 |
---|---|
557 (&display_mode, SDL_GetCurrentDisplayMode(), | 557 (&display_mode, SDL_GetCurrentDisplayMode(), |
558 sizeof(display_mode)) == 0) { | 558 sizeof(display_mode)) == 0) { |
559 return 0; | 559 return 0; |
560 } | 560 } |
561 | 561 |
562 if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) { | |
563 display->palette.ncolors = | |
564 (1 << SDL_BITSPERPIXEL(display_mode.format)); | |
565 display->palette.colors = | |
566 (SDL_Color *) SDL_realloc(display->palette.colors, | |
567 display->palette.ncolors * | |
568 sizeof(*display->palette.colors)); | |
569 if (!display->palette.colors) { | |
570 SDL_OutOfMemory(); | |
571 return -1; | |
572 } | |
573 SDL_memset(display->palette.colors, 0xff, | |
574 display->palette.ncolors * | |
575 sizeof(*display->palette.colors)); | |
576 } else { | |
577 if (display->palette.colors) { | |
578 SDL_free(display->palette.colors); | |
579 } | |
580 display->palette.colors = NULL; | |
581 display->palette.ncolors = 0; | |
582 } | |
583 | |
562 return _this->SetDisplayMode(_this, &display_mode); | 584 return _this->SetDisplayMode(_this, &display_mode); |
585 } | |
586 | |
587 int | |
588 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors) | |
589 { | |
590 SDL_Palette *palette; | |
591 | |
592 if (!_this) { | |
593 SDL_SetError("Video subsystem has not been initialized"); | |
594 return -1; | |
595 } | |
596 | |
597 palette = &SDL_CurrentDisplay.palette; | |
598 if (!palette->ncolors) { | |
599 SDL_SetError("Display mode does not have a palette"); | |
600 return -1; | |
601 } | |
602 | |
603 if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) { | |
604 SDL_SetError("Palette indices are out of range"); | |
605 return -1; | |
606 } | |
607 | |
608 SDL_memcpy(&palette->colors[firstcolor], colors, | |
609 ncolors * sizeof(*colors)); | |
610 | |
611 if (_this->SetDisplayPalette) { | |
612 return _this->SetDisplayPalette(_this, palette); | |
613 } else { | |
614 return 0; | |
615 } | |
616 } | |
617 | |
618 int | |
619 SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) | |
620 { | |
621 SDL_Palette *palette; | |
622 | |
623 if (!_this) { | |
624 SDL_SetError("Video subsystem has not been initialized"); | |
625 return -1; | |
626 } | |
627 | |
628 palette = &SDL_CurrentDisplay.palette; | |
629 if (!palette->ncolors) { | |
630 SDL_SetError("Display mode does not have a palette"); | |
631 return -1; | |
632 } | |
633 | |
634 if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) { | |
635 SDL_SetError("Palette indices are out of range"); | |
636 return -1; | |
637 } | |
638 | |
639 SDL_memcpy(colors, &palette->colors[firstcolor], | |
640 ncolors * sizeof(*colors)); | |
641 return 0; | |
563 } | 642 } |
564 | 643 |
565 SDL_WindowID | 644 SDL_WindowID |
566 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) | 645 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) |
567 { | 646 { |
618 | 697 |
619 return window.id; | 698 return window.id; |
620 } | 699 } |
621 | 700 |
622 SDL_WindowID | 701 SDL_WindowID |
623 SDL_CreateWindowFrom(void *data) | 702 SDL_CreateWindowFrom(const void *data) |
624 { | 703 { |
625 SDL_Window window; | 704 SDL_Window window; |
626 int num_windows; | 705 int num_windows; |
627 SDL_Window *windows; | 706 SDL_Window *windows; |
628 | 707 |
1315 } | 1394 } |
1316 return renderer->QueryTexturePixels(renderer, texture, pixels, pitch); | 1395 return renderer->QueryTexturePixels(renderer, texture, pixels, pitch); |
1317 } | 1396 } |
1318 | 1397 |
1319 int | 1398 int |
1320 SDL_SetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, | 1399 SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors, |
1321 int firstcolor, int ncolors) | 1400 int firstcolor, int ncolors) |
1322 { | 1401 { |
1323 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1402 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1324 SDL_Renderer *renderer; | 1403 SDL_Renderer *renderer; |
1325 | 1404 |
1334 return renderer->SetTexturePalette(renderer, texture, colors, firstcolor, | 1413 return renderer->SetTexturePalette(renderer, texture, colors, firstcolor, |
1335 ncolors); | 1414 ncolors); |
1336 } | 1415 } |
1337 | 1416 |
1338 int | 1417 int |
1339 SDL_UpdateTexture(SDL_TextureID textureID, SDL_Rect * rect, | 1418 SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, |
1340 const void *pixels, int pitch) | 1419 int firstcolor, int ncolors) |
1341 { | 1420 { |
1342 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1421 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1343 SDL_Renderer *renderer; | 1422 SDL_Renderer *renderer; |
1344 | 1423 |
1345 if (!texture) { | 1424 if (!texture) { |
1346 return -1; | 1425 return -1; |
1347 } | 1426 } |
1348 | 1427 |
1349 renderer = texture->renderer; | 1428 renderer = texture->renderer; |
1350 if (!renderer->UpdateTexture) { | 1429 if (!renderer->GetTexturePalette) { |
1351 return -1; | 1430 return -1; |
1352 } | 1431 } |
1353 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch); | 1432 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor, |
1354 } | 1433 ncolors); |
1355 | 1434 } |
1356 int | 1435 |
1357 SDL_LockTexture(SDL_TextureID textureID, SDL_Rect * rect, int markDirty, | 1436 int |
1358 void **pixels, int *pitch) | 1437 SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect, |
1438 const void *pixels, int pitch) | |
1359 { | 1439 { |
1360 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1440 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1361 SDL_Renderer *renderer; | 1441 SDL_Renderer *renderer; |
1362 | 1442 |
1363 if (!texture) { | 1443 if (!texture) { |
1364 return -1; | 1444 return -1; |
1365 } | 1445 } |
1366 | 1446 |
1367 renderer = texture->renderer; | 1447 renderer = texture->renderer; |
1448 if (!renderer->UpdateTexture) { | |
1449 return -1; | |
1450 } | |
1451 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch); | |
1452 } | |
1453 | |
1454 int | |
1455 SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty, | |
1456 void **pixels, int *pitch) | |
1457 { | |
1458 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
1459 SDL_Renderer *renderer; | |
1460 | |
1461 if (!texture) { | |
1462 return -1; | |
1463 } | |
1464 | |
1465 renderer = texture->renderer; | |
1368 if (!renderer->LockTexture) { | 1466 if (!renderer->LockTexture) { |
1369 return -1; | 1467 return -1; |
1370 } | 1468 } |
1371 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels, | 1469 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels, |
1372 pitch); | 1470 pitch); |
1388 } | 1486 } |
1389 return renderer->UnlockTexture(renderer, texture); | 1487 return renderer->UnlockTexture(renderer, texture); |
1390 } | 1488 } |
1391 | 1489 |
1392 void | 1490 void |
1393 SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects) | 1491 SDL_DirtyTexture(SDL_TextureID textureID, int numrects, |
1492 const SDL_Rect * rects) | |
1394 { | 1493 { |
1395 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1494 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1396 SDL_Renderer *renderer; | 1495 SDL_Renderer *renderer; |
1397 | 1496 |
1398 if (!texture) { | 1497 if (!texture) { |
1421 } | 1520 } |
1422 renderer->SelectRenderTexture(renderer, texture); | 1521 renderer->SelectRenderTexture(renderer, texture); |
1423 } | 1522 } |
1424 | 1523 |
1425 int | 1524 int |
1426 SDL_RenderFill(SDL_Rect * rect, Uint32 color) | 1525 SDL_RenderFill(const SDL_Rect * rect, Uint32 color) |
1427 { | 1526 { |
1428 SDL_Renderer *renderer; | 1527 SDL_Renderer *renderer; |
1429 | 1528 |
1430 if (!_this) { | 1529 if (!_this) { |
1431 return -1; | 1530 return -1; |
1438 | 1537 |
1439 renderer->RenderFill(renderer, rect, color); | 1538 renderer->RenderFill(renderer, rect, color); |
1440 } | 1539 } |
1441 | 1540 |
1442 int | 1541 int |
1443 SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect * srcrect, | 1542 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, |
1444 SDL_Rect * dstrect, int blendMode, int scaleMode) | 1543 const SDL_Rect * dstrect, int blendMode, int scaleMode) |
1445 { | 1544 { |
1446 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1545 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1447 SDL_Renderer *renderer; | 1546 SDL_Renderer *renderer; |
1448 | 1547 |
1449 if (!texture || texture->renderer != SDL_CurrentDisplay.current_renderer) { | 1548 if (!texture || texture->renderer != SDL_CurrentDisplay.current_renderer) { |
1458 return renderer->RenderCopy(renderer, texture, srcrect, dstrect, | 1557 return renderer->RenderCopy(renderer, texture, srcrect, dstrect, |
1459 blendMode, scaleMode); | 1558 blendMode, scaleMode); |
1460 } | 1559 } |
1461 | 1560 |
1462 int | 1561 int |
1463 SDL_RenderReadPixels(SDL_Rect * rect, void *pixels, int pitch) | 1562 SDL_RenderReadPixels(const SDL_Rect * rect, void *pixels, int pitch) |
1464 { | 1563 { |
1465 SDL_Renderer *renderer; | 1564 SDL_Renderer *renderer; |
1466 | 1565 |
1467 if (!_this) { | 1566 if (!_this) { |
1468 return -1; | 1567 return -1; |
1475 | 1574 |
1476 return renderer->RenderReadPixels(renderer, rect, pixels, pitch); | 1575 return renderer->RenderReadPixels(renderer, rect, pixels, pitch); |
1477 } | 1576 } |
1478 | 1577 |
1479 int | 1578 int |
1480 SDL_RenderWritePixels(SDL_Rect * rect, const void *pixels, int pitch) | 1579 SDL_RenderWritePixels(const SDL_Rect * rect, const void *pixels, int pitch) |
1481 { | 1580 { |
1482 SDL_Renderer *renderer; | 1581 SDL_Renderer *renderer; |
1483 | 1582 |
1484 if (!_this) { | 1583 if (!_this) { |
1485 return -1; | 1584 return -1; |
1614 SDL_DestroyWindow(display->windows[i].id); | 1713 SDL_DestroyWindow(display->windows[i].id); |
1615 } | 1714 } |
1616 if (display->windows) { | 1715 if (display->windows) { |
1617 SDL_free(display->windows); | 1716 SDL_free(display->windows); |
1618 display->windows = NULL; | 1717 display->windows = NULL; |
1718 } | |
1719 if (display->palette.colors) { | |
1720 SDL_free(display->palette.colors); | |
1721 display->palette.colors = NULL; | |
1722 display->palette.ncolors = 0; | |
1619 } | 1723 } |
1620 } | 1724 } |
1621 _this->VideoQuit(_this); | 1725 _this->VideoQuit(_this); |
1622 if (_this->displays) { | 1726 if (_this->displays) { |
1623 SDL_free(_this->displays); | 1727 SDL_free(_this->displays); |