comparison src/video/SDL_blit.c @ 2266:e61ad15a205f

More work in progress integrating SDL_Surface and the new SDL_Texture API
author Sam Lantinga <slouken@libsdl.org>
date Sat, 18 Aug 2007 01:44:21 +0000
parents 265bb136af92
children c785543d1843
comparison
equal deleted inserted replaced
2265:265bb136af92 2266:e61ad15a205f
204 /* Figure out which of many blit routines to set up on a surface */ 204 /* Figure out which of many blit routines to set up on a surface */
205 int 205 int
206 SDL_CalculateBlit(SDL_Surface * surface) 206 SDL_CalculateBlit(SDL_Surface * surface)
207 { 207 {
208 SDL_BlitFunc blit = NULL; 208 SDL_BlitFunc blit = NULL;
209 SDL_Surface *dst = surface->map->dst; 209 SDL_BlitMap *map = surface->map;
210 SDL_Surface *dst = map->dst;
210 Uint32 src_format; 211 Uint32 src_format;
211 Uint32 dst_format; 212 Uint32 dst_format;
212 213
213 /* Clean everything out to start */ 214 /* Clean everything out to start */
214 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { 215 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
215 SDL_UnRLESurface(surface, 1); 216 SDL_UnRLESurface(surface, 1);
216 } 217 }
217 surface->map->blit = NULL; 218 map->blit = SDL_SoftBlit;
218 surface->map->info.src_fmt = surface->format; 219 map->info.src_fmt = surface->format;
219 surface->map->info.src_pitch = surface->pitch; 220 map->info.src_pitch = surface->pitch;
220 surface->map->info.dst_fmt = dst->format; 221 map->info.dst_fmt = dst->format;
221 surface->map->info.dst_pitch = dst->pitch; 222 map->info.dst_pitch = dst->pitch;
222 223
224 /* See if we can do RLE acceleration */
225 if (surface->flags & SDL_RLEACCELOK) {
226 if (SDL_RLESurface(surface) == 0) {
227 return 0;
228 }
229 }
230
231 /* Choose a standard blit function */
223 src_format = SDL_MasksToPixelFormatEnum(surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask); 232 src_format = SDL_MasksToPixelFormatEnum(surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);
224 dst_format = SDL_MasksToPixelFormatEnum(dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask); 233 dst_format = SDL_MasksToPixelFormatEnum(dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask);
225 234
226 /* Check for special "identity" case -- copy blit */ 235 if (map->identity && !map->info.flags) {
227 if (surface->map->identity && !surface->map->info.flags) {
228 /* Handle overlapping blits on the same surface */ 236 /* Handle overlapping blits on the same surface */
229 if (surface == dst) { 237 if (surface == dst) {
230 blit = SDL_BlitCopyOverlap; 238 blit = SDL_BlitCopyOverlap;
231 } else { 239 } else {
232 blit = SDL_BlitCopy; 240 blit = SDL_BlitCopy;
233 } 241 }
242 } else if (surface->format->BitsPerPixel < 8) {
243 blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTable0);
244 } else if (surface->format->BytesPerPixel == 1) {
245 blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTable1);
234 } else { 246 } else {
235 if (surface->format->BitsPerPixel < 8) { 247 blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_BlitFuncTableN);
236 blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTable0);
237 } else {
238 switch (surface->format->BytesPerPixel) {
239 case 1:
240 blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTable1);
241 break;
242 case 2:
243 case 3:
244 case 4:
245 blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTableN);
246 break;
247 }
248 }
249 } 248 }
250 if (blit == NULL) { 249 if (blit == NULL) {
251 blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_GeneratedBlitFuncTable); 250 blit = SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_GeneratedBlitFuncTable);
252 } 251 }
253 252
254 /* Make sure we have a blit function */ 253 /* Make sure we have a blit function */
255 if (blit == NULL) { 254 if (blit == NULL) {
256 SDL_InvalidateMap(surface->map); 255 SDL_InvalidateMap(map);
257 SDL_SetError("Blit combination not supported"); 256 SDL_SetError("Blit combination not supported");
258 return (-1); 257 return (-1);
259 } 258 }
260 259
261 /* Choose software blitting function */
262 if ((surface->flags & SDL_RLEACCELOK) && !(surface->map->flags & () {
263 if (surface->map->identity && (surface->map->flags & SDL_COPY_COLORKEY)
264 && (blit_index == 1
265 || (blit_index == 3 && !surface->format->Amask))) {
266 if (SDL_RLESurface(surface) == 0)
267 surface->map->blit = SDL_RLEBlit;
268 } else if (blit_index == 2 && surface->format->Amask) {
269 if (SDL_RLESurface(surface) == 0)
270 surface->map->blit = SDL_RLEAlphaBlit;
271 }
272 }
273
274 if (surface->map->blit == NULL) {
275 surface->map->blit = SDL_SoftBlit;
276 surface->map->data = blit;
277 }
278 return (0); 260 return (0);
279 } 261 }
280 262
281 /* vi: set ts=4 sw=4 expandtab: */ 263 /* vi: set ts=4 sw=4 expandtab: */