comparison src/video/SDL_blit.c @ 2262:bee005ace1bf

Work in progress: merging new texture features into SDL blit system
author Sam Lantinga <slouken@libsdl.org>
date Fri, 17 Aug 2007 06:21:58 +0000
parents 202ddfd1cfb1
children 900c35d8e8fd
comparison
equal deleted inserted replaced
2261:c20476d7d7b3 2262:bee005ace1bf
59 } 59 }
60 } 60 }
61 61
62 /* Set up source and destination buffer pointers, and BLIT! */ 62 /* Set up source and destination buffer pointers, and BLIT! */
63 if (okay && srcrect->w && srcrect->h) { 63 if (okay && srcrect->w && srcrect->h) {
64 SDL_BlitInfo info; 64 SDL_BlitInfo *info = &src->map->info;
65 SDL_loblit RunBlit;
66 65
67 /* Set up the blit information */ 66 /* Set up the blit information */
68 info.s_pixels = (Uint8 *) src->pixels + 67 info->src = (Uint8 *) src->pixels +
69 (Uint16) srcrect->y * src->pitch + 68 (Uint16) srcrect->y * src->pitch +
70 (Uint16) srcrect->x * src->format->BytesPerPixel; 69 (Uint16) srcrect->x * info->src_fmt->BytesPerPixel;
71 info.s_width = srcrect->w; 70 info.src_w = srcrect->w;
72 info.s_height = srcrect->h; 71 info.src_h = srcrect->h;
73 info.s_skip = src->pitch - info.s_width * src->format->BytesPerPixel; 72 info.dst = (Uint8 *) dst->pixels +
74 info.d_pixels = (Uint8 *) dst->pixels +
75 (Uint16) dstrect->y * dst->pitch + 73 (Uint16) dstrect->y * dst->pitch +
76 (Uint16) dstrect->x * dst->format->BytesPerPixel; 74 (Uint16) dstrect->x * info->dst_fmt->BytesPerPixel;
77 info.d_width = dstrect->w; 75 info.dst_w = dstrect->w;
78 info.d_height = dstrect->h; 76 info.dst_h = dstrect->h;
79 info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel; 77 RunBlit = (SDL_BlitFunc) src->map->data;
80 info.src = src->format;
81 info.table = src->map->table;
82 info.dst = dst->format;
83 info.ckey = src->map->ckey;
84 info.cmod = src->map->cmod;
85 RunBlit = (SDL_loblit) src->map->data;
86 78
87 /* Run the actual software blit */ 79 /* Run the actual software blit */
88 RunBlit(&info); 80 RunBlit(info);
89 } 81 }
90 82
91 /* We need to unlock the surfaces if they're locked */ 83 /* We need to unlock the surfaces if they're locked */
92 if (dst_locked) { 84 if (dst_locked) {
93 SDL_UnlockSurface(dst); 85 SDL_UnlockSurface(dst);
122 /* Just guess G4 */ 114 /* Just guess G4 */
123 return SDL_TRUE; 115 return SDL_TRUE;
124 } 116 }
125 #endif /* __MACOSX__ */ 117 #endif /* __MACOSX__ */
126 118
127 static SDL_loblit 119 static SDL_BlitFunc
128 SDL_ChooseBlitFunc(SDL_BlitEntry * entries, int count) 120 SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, SDL_BlitEntry * entries)
129 { 121 {
130 int i; 122 int i;
131 static Uint32 features = 0xffffffff; 123 static Uint32 features = 0xffffffff;
132 124
125 /* Get the available CPU features */
133 if (features == 0xffffffff) { 126 if (features == 0xffffffff) {
134 const char *override = SDL_getenv("SDL_BLIT_FEATURES"); 127 const char *override = SDL_getenv("SDL_BLIT_CPU_FEATURES");
135 128
136 features = SDL_BLIT_ANY; 129 features = SDL_CPU_ANY;
137 130
138 /* Allow an override for testing .. */ 131 /* Allow an override for testing .. */
139 if (override) { 132 if (override) {
140 SDL_sscanf(override, "%u", &features); 133 SDL_sscanf(override, "%u", &features);
141 } else { 134 } else {
142 if (SDL_HasMMX()) { 135 if (SDL_HasMMX()) {
143 features |= SDL_BLIT_MMX; 136 features |= SDL_CPU_MMX;
137 }
138 if (SDL_Has3DNow()) {
139 features |= SDL_CPU_3DNOW;
144 } 140 }
145 if (SDL_HasSSE()) { 141 if (SDL_HasSSE()) {
146 features |= SDL_BLIT_SSE; 142 features |= SDL_CPU_SSE;
143 }
144 if (SDL_HasSSE2()) {
145 features |= SDL_CPU_SSE2;
147 } 146 }
148 if (SDL_HasAltiVec()) { 147 if (SDL_HasAltiVec()) {
149 if (SDL_UseAltivecPrefetch()) { 148 if (SDL_UseAltivecPrefetch()) {
150 features |= SDL_BLIT_ALTIVEC_PREFETCH; 149 features |= SDL_CPU_ALTIVEC_PREFETCH;
151 } else { 150 } else {
152 features |= SDL_BLIT_ALTIVEC_NOPREFETCH; 151 features |= SDL_CPU_ALTIVEC_NOPREFETCH;
153 } 152 }
154 } 153 }
155 } 154 }
156 } 155 }
157 156
158 for (i = count; i > 0; --i) { 157 for (i = 0; entries[i].blit; ++i) {
159 if (features & entries[i].features) { 158 if (src_format != entries[i].src_format) {
160 return entries[i].blit; 159 continue;
161 } 160 }
162 } 161 if (dst_format != entries[i].dst_format) {
163 return entries[0].blit; 162 continue;
163 }
164 if ((flags & entries[i].flags) != flags) {
165 continue;
166 }
167 if (!(features & entries[i].cpu)) {
168 continue;
169 }
170 return entries[i].func;
171 }
172 return NULL;
164 } 173 }
165 174
166 /* Figure out which of many blit routines to set up on a surface */ 175 /* Figure out which of many blit routines to set up on a surface */
167 int 176 int
168 SDL_CalculateBlit(SDL_Surface * surface) 177 SDL_CalculateBlit(SDL_Surface * surface)
169 { 178 {
170 SDL_loblit blit = NULL; 179 SDL_BlitFunc blit = NULL;
171 int blit_index; 180 int blit_index;
172 181
173 /* Clean everything out to start */ 182 /* Clean everything out to start */
174 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { 183 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
175 SDL_UnRLESurface(surface, 1); 184 SDL_UnRLESurface(surface, 1);
208 blit = SDL_CalculateBlitN(surface, blit_index); 217 blit = SDL_CalculateBlitN(surface, blit_index);
209 break; 218 break;
210 } 219 }
211 } 220 }
212 } 221 }
222 if (blit == NULL) {
223 blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_GeneratedBlitFuncTable);
224 }
225
213 /* Make sure we have a blit function */ 226 /* Make sure we have a blit function */
214 if (blit == NULL) { 227 if (blit == NULL) {
215 SDL_InvalidateMap(surface->map); 228 SDL_InvalidateMap(surface->map);
216 SDL_SetError("Blit combination not supported"); 229 SDL_SetError("Blit combination not supported");
217 return (-1); 230 return (-1);