comparison src/video/SDL_blit.c @ 2257:340942cfda48

Moved the colorkey and per-surface alpha into the blit info, in preparation for support for general color channel modulation. Removed and consolidated some data in the blit info.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 17 Aug 2007 00:54:53 +0000
parents 17b2369756be
children 202ddfd1cfb1
comparison
equal deleted inserted replaced
2256:e893d24ad8db 2257:340942cfda48
75 (Uint16) dstrect->y * dst->pitch + 75 (Uint16) dstrect->y * dst->pitch +
76 (Uint16) dstrect->x * dst->format->BytesPerPixel; 76 (Uint16) dstrect->x * dst->format->BytesPerPixel;
77 info.d_width = dstrect->w; 77 info.d_width = dstrect->w;
78 info.d_height = dstrect->h; 78 info.d_height = dstrect->h;
79 info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel; 79 info.d_skip = dst->pitch - info.d_width * dst->format->BytesPerPixel;
80 info.aux_data = src->map->sw_data->aux_data;
81 info.src = src->format; 80 info.src = src->format;
82 info.table = src->map->table; 81 info.table = src->map->table;
83 info.dst = dst->format; 82 info.dst = dst->format;
84 RunBlit = src->map->sw_data->blit; 83 info.ckey = src->map->ckey;
84 info.cmod = src->map->cmod;
85 RunBlit = (SDL_loblit)src->map->data;
85 86
86 /* Run the actual software blit */ 87 /* Run the actual software blit */
87 RunBlit(&info); 88 RunBlit(&info);
88 } 89 }
89 90
164 165
165 /* Figure out which of many blit routines to set up on a surface */ 166 /* Figure out which of many blit routines to set up on a surface */
166 int 167 int
167 SDL_CalculateBlit(SDL_Surface * surface) 168 SDL_CalculateBlit(SDL_Surface * surface)
168 { 169 {
170 SDL_loblit blit = NULL;
169 int blit_index; 171 int blit_index;
170 172
171 /* Clean everything out to start */ 173 /* Clean everything out to start */
172 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { 174 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
173 SDL_UnRLESurface(surface, 1); 175 SDL_UnRLESurface(surface, 1);
174 } 176 }
175 surface->map->sw_blit = NULL; 177 surface->map->blit = NULL;
176 178
177 /* Get the blit function index, based on surface mode */ 179 /* Get the blit function index, based on surface mode */
178 /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ 180 /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */
179 blit_index = 0; 181 blit_index = 0;
180 blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0; 182 blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0;
181 if (surface->flags & SDL_SRCALPHA 183 if (surface->flags & SDL_SRCALPHA
182 && (surface->format->alpha != SDL_ALPHA_OPAQUE 184 && ((surface->map->cmod >> 24) != SDL_ALPHA_OPAQUE
183 || surface->format->Amask)) { 185 || surface->format->Amask)) {
184 blit_index |= 2; 186 blit_index |= 2;
185 } 187 }
186 188
187 /* Check for special "identity" case -- copy blit */ 189 /* Check for special "identity" case -- copy blit */
188 if (surface->map->identity && blit_index == 0) { 190 if (surface->map->identity && blit_index == 0) {
189 /* Handle overlapping blits on the same surface */ 191 /* Handle overlapping blits on the same surface */
190 if (surface == surface->map->dst) { 192 if (surface == surface->map->dst) {
191 surface->map->sw_data->blit = SDL_BlitCopyOverlap; 193 blit = SDL_BlitCopyOverlap;
192 } else { 194 } else {
193 surface->map->sw_data->blit = SDL_BlitCopy; 195 blit = SDL_BlitCopy;
194 } 196 }
195 } else { 197 } else {
196 if (surface->format->BitsPerPixel < 8) { 198 if (surface->format->BitsPerPixel < 8) {
197 surface->map->sw_data->blit = 199 blit = SDL_CalculateBlit0(surface, blit_index);
198 SDL_CalculateBlit0(surface, blit_index);
199 } else { 200 } else {
200 switch (surface->format->BytesPerPixel) { 201 switch (surface->format->BytesPerPixel) {
201 case 1: 202 case 1:
202 surface->map->sw_data->blit = 203 blit = SDL_CalculateBlit1(surface, blit_index);
203 SDL_CalculateBlit1(surface, blit_index);
204 break; 204 break;
205 case 2: 205 case 2:
206 case 3: 206 case 3:
207 case 4: 207 case 4:
208 surface->map->sw_data->blit = 208 blit = SDL_CalculateBlitN(surface, blit_index);
209 SDL_CalculateBlitN(surface, blit_index);
210 break; 209 break;
211 default:
212 surface->map->sw_data->blit = NULL;
213 break;
214 } 210 }
215 } 211 }
216 } 212 }
217 /* Make sure we have a blit function */ 213 /* Make sure we have a blit function */
218 if (surface->map->sw_data->blit == NULL) { 214 if (blit == NULL) {
219 SDL_InvalidateMap(surface->map); 215 SDL_InvalidateMap(surface->map);
220 SDL_SetError("Blit combination not supported"); 216 SDL_SetError("Blit combination not supported");
221 return (-1); 217 return (-1);
222 } 218 }
223 219
225 if (surface->flags & SDL_RLEACCELOK) { 221 if (surface->flags & SDL_RLEACCELOK) {
226 if (surface->map->identity 222 if (surface->map->identity
227 && (blit_index == 1 223 && (blit_index == 1
228 || (blit_index == 3 && !surface->format->Amask))) { 224 || (blit_index == 3 && !surface->format->Amask))) {
229 if (SDL_RLESurface(surface) == 0) 225 if (SDL_RLESurface(surface) == 0)
230 surface->map->sw_blit = SDL_RLEBlit; 226 surface->map->blit = SDL_RLEBlit;
231 } else if (blit_index == 2 && surface->format->Amask) { 227 } else if (blit_index == 2 && surface->format->Amask) {
232 if (SDL_RLESurface(surface) == 0) 228 if (SDL_RLESurface(surface) == 0)
233 surface->map->sw_blit = SDL_RLEAlphaBlit; 229 surface->map->blit = SDL_RLEAlphaBlit;
234 } 230 }
235 } 231 }
236 232
237 if (surface->map->sw_blit == NULL) { 233 if (surface->map->blit == NULL) {
238 surface->map->sw_blit = SDL_SoftBlit; 234 surface->map->blit = SDL_SoftBlit;
235 surface->map->data = blit;
239 } 236 }
240 return (0); 237 return (0);
241 } 238 }
242 239
243 /* vi: set ts=4 sw=4 expandtab: */ 240 /* vi: set ts=4 sw=4 expandtab: */