Mercurial > sdl-ios-xcode
comparison src/video/SDL_surface.c @ 2222:926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
- SDL_Surface is a system memory representation of pixel data
- SDL_Texture is a video memory representation of pixel data
The concept of SDL_Surface with SDL_HWSURFACE is no longer used.
Separated SDL_Texture types by usage rather than memory type
- SDL_TEXTUREACCESS_STATIC is for rarely changed pixel data,
can be placed in video memory.
- SDL_TEXTUREACCESS_STREAMING is for frequently changing pixel
data, usually placed in system memory or AGP memory.
Optimized the SDL_compat usage of the OpenGL renderer by only
using one copy of the framebuffer instead of two.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 11 Aug 2007 20:54:31 +0000 |
parents | 8a162bfdc838 |
children | cf8c3b0117b3 |
comparison
equal
deleted
inserted
replaced
2221:1d75c38e1e5c | 2222:926294b2bb4e |
---|---|
168 SDL_SetClipRect(surface, NULL); | 168 SDL_SetClipRect(surface, NULL); |
169 } | 169 } |
170 return surface; | 170 return surface; |
171 } | 171 } |
172 | 172 |
173 SDL_Surface * | |
174 SDL_CreateRGBSurfaceFromTexture(SDL_TextureID textureID) | |
175 { | |
176 SDL_Surface *surface; | |
177 Uint32 format; | |
178 int w, h; | |
179 int bpp; | |
180 Uint32 Rmask, Gmask, Bmask, Amask; | |
181 void *pixels; | |
182 int pitch; | |
183 | |
184 if (SDL_QueryTexture(textureID, &format, NULL, &w, &h) < 0) { | |
185 return NULL; | |
186 } | |
187 | |
188 if (!SDL_PixelFormatEnumToMasks | |
189 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | |
190 SDL_SetError("Unknown texture format"); | |
191 return NULL; | |
192 } | |
193 | |
194 if (SDL_QueryTexturePixels(textureID, &pixels, &pitch) == 0) { | |
195 surface = | |
196 SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, Gmask, | |
197 Bmask, Amask); | |
198 } else { | |
199 surface = | |
200 SDL_CreateRGBSurface(0, 0, 0, bpp, Rmask, Gmask, Bmask, Amask); | |
201 if (surface) { | |
202 surface->flags |= SDL_HWSURFACE; | |
203 surface->w = w; | |
204 surface->h = h; | |
205 surface->pitch = SDL_CalculatePitch(surface); | |
206 SDL_SetClipRect(surface, NULL); | |
207 } | |
208 } | |
209 if (surface) { | |
210 surface->textureID = textureID; | |
211 } | |
212 | |
213 return surface; | |
214 } | |
215 | |
216 static int | 173 static int |
217 SDL_SurfacePaletteChanged(void *userdata, SDL_Palette * palette) | 174 SDL_SurfacePaletteChanged(void *userdata, SDL_Palette * palette) |
218 { | 175 { |
219 SDL_Surface *surface = (SDL_Surface *) userdata; | 176 SDL_Surface *surface = (SDL_Surface *) userdata; |
220 | 177 |
221 if (surface->textureID) { | |
222 if (SDL_SetTexturePalette | |
223 (surface->textureID, palette->colors, 0, palette->ncolors) < 0) { | |
224 SDL_GetTexturePalette(surface->textureID, palette->colors, 0, | |
225 palette->ncolors); | |
226 return -1; | |
227 } | |
228 } | |
229 SDL_FormatChanged(surface); | 178 SDL_FormatChanged(surface); |
230 | 179 |
231 return 0; | 180 return 0; |
232 } | 181 } |
233 | 182 |
625 for (y = dstrect->h; y; --y) { | 574 for (y = dstrect->h; y; --y) { |
626 SDL_memset4(row, 0, n); | 575 SDL_memset4(row, 0, n); |
627 row += dst->pitch; | 576 row += dst->pitch; |
628 } | 577 } |
629 } else { | 578 } else { |
630 #ifdef __powerpc__ | 579 for (y = dstrect->h; y; y--) { |
631 /* | 580 SDL_memset(row, color, x); |
632 * SDL_memset() on PPC (both glibc and codewarrior) uses | 581 row += dst->pitch; |
633 * the dcbz (Data Cache Block Zero) instruction, which | |
634 * causes an alignment exception if the destination is | |
635 * uncachable, so only use it on software surfaces | |
636 */ | |
637 if (dst->flags & SDL_HWSURFACE) { | |
638 if (dstrect->w >= 8) { | |
639 /* | |
640 * 64-bit stores are probably most | |
641 * efficient to uncached video memory | |
642 */ | |
643 double fill; | |
644 SDL_memset(&fill, color, (sizeof fill)); | |
645 for (y = dstrect->h; y; y--) { | |
646 Uint8 *d = row; | |
647 unsigned n = x; | |
648 unsigned nn; | |
649 Uint8 c = color; | |
650 double f = fill; | |
651 while ((unsigned long) d & (sizeof(double) - 1)) { | |
652 *d++ = c; | |
653 n--; | |
654 } | |
655 nn = n / (sizeof(double) * 4); | |
656 while (nn) { | |
657 ((double *) d)[0] = f; | |
658 ((double *) d)[1] = f; | |
659 ((double *) d)[2] = f; | |
660 ((double *) d)[3] = f; | |
661 d += 4 * sizeof(double); | |
662 nn--; | |
663 } | |
664 n &= ~(sizeof(double) * 4 - 1); | |
665 nn = n / sizeof(double); | |
666 while (nn) { | |
667 *(double *) d = f; | |
668 d += sizeof(double); | |
669 nn--; | |
670 } | |
671 n &= ~(sizeof(double) - 1); | |
672 while (n) { | |
673 *d++ = c; | |
674 n--; | |
675 } | |
676 row += dst->pitch; | |
677 } | |
678 } else { | |
679 /* narrow boxes */ | |
680 for (y = dstrect->h; y; y--) { | |
681 Uint8 *d = row; | |
682 Uint8 c = color; | |
683 int n = x; | |
684 while (n) { | |
685 *d++ = c; | |
686 n--; | |
687 } | |
688 row += dst->pitch; | |
689 } | |
690 } | |
691 } else | |
692 #endif /* __powerpc__ */ | |
693 { | |
694 for (y = dstrect->h; y; y--) { | |
695 SDL_memset(row, color, x); | |
696 row += dst->pitch; | |
697 } | |
698 } | 582 } |
699 } | 583 } |
700 } else { | 584 } else { |
701 switch (dst->format->BytesPerPixel) { | 585 switch (dst->format->BytesPerPixel) { |
702 case 2: | 586 case 2: |
751 int | 635 int |
752 SDL_LockSurface(SDL_Surface * surface) | 636 SDL_LockSurface(SDL_Surface * surface) |
753 { | 637 { |
754 if (!surface->locked) { | 638 if (!surface->locked) { |
755 /* Perform the lock */ | 639 /* Perform the lock */ |
756 if (surface->flags & SDL_HWSURFACE) { | |
757 if (SDL_LockTexture | |
758 (surface->textureID, NULL, 1, &surface->pixels, | |
759 &surface->pitch) < 0) { | |
760 return (-1); | |
761 } | |
762 } | |
763 if (surface->flags & SDL_RLEACCEL) { | 640 if (surface->flags & SDL_RLEACCEL) { |
764 SDL_UnRLESurface(surface, 1); | 641 SDL_UnRLESurface(surface, 1); |
765 surface->flags |= SDL_RLEACCEL; /* save accel'd state */ | 642 surface->flags |= SDL_RLEACCEL; /* save accel'd state */ |
766 } | 643 } |
767 } | 644 } |
780 SDL_UnlockSurface(SDL_Surface * surface) | 657 SDL_UnlockSurface(SDL_Surface * surface) |
781 { | 658 { |
782 /* Only perform an unlock if we are locked */ | 659 /* Only perform an unlock if we are locked */ |
783 if (!surface->locked || (--surface->locked > 0)) { | 660 if (!surface->locked || (--surface->locked > 0)) { |
784 return; | 661 return; |
785 } | |
786 | |
787 /* Unlock hardware or accelerated surfaces */ | |
788 if (surface->flags & SDL_HWSURFACE) { | |
789 SDL_UnlockTexture(surface->textureID); | |
790 } | 662 } |
791 | 663 |
792 /* Update RLE encoded surface with new data */ | 664 /* Update RLE encoded surface with new data */ |
793 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { | 665 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { |
794 surface->flags &= ~SDL_RLEACCEL; /* stop lying */ | 666 surface->flags &= ~SDL_RLEACCEL; /* stop lying */ |
926 } | 798 } |
927 if (surface->map != NULL) { | 799 if (surface->map != NULL) { |
928 SDL_FreeBlitMap(surface->map); | 800 SDL_FreeBlitMap(surface->map); |
929 surface->map = NULL; | 801 surface->map = NULL; |
930 } | 802 } |
931 /* Should we destroy the texture too? | |
932 if (surface->textureID) { | |
933 SDL_DestroyTexture(surface->textureID); | |
934 } | |
935 */ | |
936 if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) { | 803 if (surface->pixels && ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC)) { |
937 SDL_free(surface->pixels); | 804 SDL_free(surface->pixels); |
938 } | 805 } |
939 SDL_free(surface); | 806 SDL_free(surface); |
940 #ifdef CHECK_LEAKS | 807 #ifdef CHECK_LEAKS |