comparison src/video/SDL_blit_N.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 93994f65c74c
children bee005ace1bf
comparison
equal deleted inserted replaced
2256:e893d24ad8db 2257:340942cfda48
320 assert(dstfmt->BytesPerPixel == 4); 320 assert(dstfmt->BytesPerPixel == 4);
321 321
322 vf800 = (vector unsigned short) vec_splat_u8(-7); 322 vf800 = (vector unsigned short) vec_splat_u8(-7);
323 vf800 = vec_sl(vf800, vec_splat_u16(8)); 323 vf800 = vec_sl(vf800, vec_splat_u16(8));
324 324
325 if (dstfmt->Amask && srcfmt->alpha) { 325 if (dstfmt->Amask && (info->cmod >> 24)) {
326 ((unsigned char *) &valpha)[0] = alpha = srcfmt->alpha; 326 ((unsigned char *) &valpha)[0] = alpha = (info->cmod >> 24);
327 valpha = vec_splat(valpha, 0); 327 valpha = vec_splat(valpha, 0);
328 } else { 328 } else {
329 alpha = 0; 329 alpha = 0;
330 valpha = vec_splat_u8(0); 330 valpha = vec_splat_u8(0);
331 } 331 }
468 assert(dstfmt->BytesPerPixel == 4); 468 assert(dstfmt->BytesPerPixel == 4);
469 469
470 vf800 = (vector unsigned short) vec_splat_u8(-7); 470 vf800 = (vector unsigned short) vec_splat_u8(-7);
471 vf800 = vec_sl(vf800, vec_splat_u16(8)); 471 vf800 = vec_sl(vf800, vec_splat_u16(8));
472 472
473 if (dstfmt->Amask && srcfmt->alpha) { 473 if (dstfmt->Amask && (info->cmod >> 24)) {
474 ((unsigned char *) &valpha)[0] = alpha = srcfmt->alpha; 474 ((unsigned char *) &valpha)[0] = alpha = (info->cmod >> 24);
475 valpha = vec_splat(valpha, 0); 475 valpha = vec_splat(valpha, 0);
476 } else { 476 } else {
477 alpha = 0; 477 alpha = 0;
478 valpha = vec_splat_u8(0); 478 valpha = vec_splat_u8(0);
479 } 479 }
567 SDL_PixelFormat *srcfmt = info->src; 567 SDL_PixelFormat *srcfmt = info->src;
568 int srcbpp = srcfmt->BytesPerPixel; 568 int srcbpp = srcfmt->BytesPerPixel;
569 SDL_PixelFormat *dstfmt = info->dst; 569 SDL_PixelFormat *dstfmt = info->dst;
570 int dstbpp = dstfmt->BytesPerPixel; 570 int dstbpp = dstfmt->BytesPerPixel;
571 int copy_alpha = (srcfmt->Amask && dstfmt->Amask); 571 int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
572 unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; 572 unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
573 Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask; 573 Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
574 Uint32 ckey = info->src->colorkey; 574 Uint32 ckey = info->ckey;
575 vector unsigned int valpha; 575 vector unsigned int valpha;
576 vector unsigned char vpermute; 576 vector unsigned char vpermute;
577 vector unsigned char vzero; 577 vector unsigned char vzero;
578 vector unsigned int vckey; 578 vector unsigned int vckey;
579 vector unsigned int vrgbmask; 579 vector unsigned int vrgbmask;
685 SDL_PixelFormat *srcfmt = info->src; 685 SDL_PixelFormat *srcfmt = info->src;
686 SDL_PixelFormat *dstfmt = info->dst; 686 SDL_PixelFormat *dstfmt = info->dst;
687 vector unsigned int vzero = vec_splat_u32(0); 687 vector unsigned int vzero = vec_splat_u32(0);
688 vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); 688 vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
689 if (dstfmt->Amask && !srcfmt->Amask) { 689 if (dstfmt->Amask && !srcfmt->Amask) {
690 if (srcfmt->alpha) { 690 if ((info->cmod >> 24)) {
691 vector unsigned char valpha; 691 vector unsigned char valpha;
692 ((unsigned char *) &valpha)[0] = srcfmt->alpha; 692 ((unsigned char *) &valpha)[0] = (info->cmod >> 24);
693 vzero = (vector unsigned int) vec_splat(valpha, 0); 693 vzero = (vector unsigned int) vec_splat(valpha, 0);
694 } 694 }
695 } 695 }
696 696
697 assert(srcfmt->BytesPerPixel == 4); 697 assert(srcfmt->BytesPerPixel == 4);
764 SDL_PixelFormat *srcfmt = info->src; 764 SDL_PixelFormat *srcfmt = info->src;
765 SDL_PixelFormat *dstfmt = info->dst; 765 SDL_PixelFormat *dstfmt = info->dst;
766 vector unsigned int vzero = vec_splat_u32(0); 766 vector unsigned int vzero = vec_splat_u32(0);
767 vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt); 767 vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
768 if (dstfmt->Amask && !srcfmt->Amask) { 768 if (dstfmt->Amask && !srcfmt->Amask) {
769 if (srcfmt->alpha) { 769 if ((info->cmod >> 24)) {
770 vector unsigned char valpha; 770 vector unsigned char valpha;
771 ((unsigned char *) &valpha)[0] = srcfmt->alpha; 771 ((unsigned char *) &valpha)[0] = (info->cmod >> 24);
772 vzero = (vector unsigned int) vec_splat(valpha, 0); 772 vzero = (vector unsigned int) vec_splat(valpha, 0);
773 } 773 }
774 } 774 }
775 775
776 assert(srcfmt->BytesPerPixel == 4); 776 assert(srcfmt->BytesPerPixel == 4);
2037 SDL_PixelFormat *srcfmt = info->src; 2037 SDL_PixelFormat *srcfmt = info->src;
2038 SDL_PixelFormat *dstfmt = info->dst; 2038 SDL_PixelFormat *dstfmt = info->dst;
2039 2039
2040 if (dstfmt->Amask) { 2040 if (dstfmt->Amask) {
2041 /* RGB->RGBA, SET_ALPHA */ 2041 /* RGB->RGBA, SET_ALPHA */
2042 Uint32 mask = (srcfmt->alpha >> dstfmt->Aloss) << dstfmt->Ashift; 2042 Uint32 mask = ((info->cmod >> 24) >> dstfmt->Aloss) << dstfmt->Ashift;
2043 2043
2044 while (height--) { 2044 while (height--) {
2045 /* *INDENT-OFF* */ 2045 /* *INDENT-OFF* */
2046 DUFFS_LOOP( 2046 DUFFS_LOOP(
2047 { 2047 {
2085 int dstskip = info->d_skip; 2085 int dstskip = info->d_skip;
2086 SDL_PixelFormat *srcfmt = info->src; 2086 SDL_PixelFormat *srcfmt = info->src;
2087 int srcbpp = srcfmt->BytesPerPixel; 2087 int srcbpp = srcfmt->BytesPerPixel;
2088 SDL_PixelFormat *dstfmt = info->dst; 2088 SDL_PixelFormat *dstfmt = info->dst;
2089 int dstbpp = dstfmt->BytesPerPixel; 2089 int dstbpp = dstfmt->BytesPerPixel;
2090 unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; 2090 unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
2091 2091
2092 while (height--) { 2092 while (height--) {
2093 /* *INDENT-OFF* */ 2093 /* *INDENT-OFF* */
2094 DUFFS_LOOP( 2094 DUFFS_LOOP(
2095 { 2095 {
2148 int srcskip = info->s_skip; 2148 int srcskip = info->s_skip;
2149 Uint8 *dst = info->d_pixels; 2149 Uint8 *dst = info->d_pixels;
2150 int dstskip = info->d_skip; 2150 int dstskip = info->d_skip;
2151 SDL_PixelFormat *srcfmt = info->src; 2151 SDL_PixelFormat *srcfmt = info->src;
2152 const Uint8 *palmap = info->table; 2152 const Uint8 *palmap = info->table;
2153 Uint32 ckey = srcfmt->colorkey; 2153 Uint32 ckey = info->ckey;
2154 Uint32 rgbmask = ~srcfmt->Amask; 2154 Uint32 rgbmask = ~srcfmt->Amask;
2155 int srcbpp; 2155 int srcbpp;
2156 Uint32 Pixel; 2156 Uint32 Pixel;
2157 unsigned sR, sG, sB; 2157 unsigned sR, sG, sB;
2158 2158
2212 int height = info->d_height; 2212 int height = info->d_height;
2213 Uint16 *srcp = (Uint16 *) info->s_pixels; 2213 Uint16 *srcp = (Uint16 *) info->s_pixels;
2214 int srcskip = info->s_skip; 2214 int srcskip = info->s_skip;
2215 Uint16 *dstp = (Uint16 *) info->d_pixels; 2215 Uint16 *dstp = (Uint16 *) info->d_pixels;
2216 int dstskip = info->d_skip; 2216 int dstskip = info->d_skip;
2217 Uint32 ckey = info->src->colorkey; 2217 Uint32 ckey = info->ckey;
2218 Uint32 rgbmask = ~info->src->Amask; 2218 Uint32 rgbmask = ~info->src->Amask;
2219 2219
2220 /* Set up some basic variables */ 2220 /* Set up some basic variables */
2221 srcskip /= 2; 2221 srcskip /= 2;
2222 dstskip /= 2; 2222 dstskip /= 2;
2246 int height = info->d_height; 2246 int height = info->d_height;
2247 Uint8 *src = info->s_pixels; 2247 Uint8 *src = info->s_pixels;
2248 int srcskip = info->s_skip; 2248 int srcskip = info->s_skip;
2249 Uint8 *dst = info->d_pixels; 2249 Uint8 *dst = info->d_pixels;
2250 int dstskip = info->d_skip; 2250 int dstskip = info->d_skip;
2251 Uint32 ckey = info->src->colorkey; 2251 Uint32 ckey = info->ckey;
2252 SDL_PixelFormat *srcfmt = info->src; 2252 SDL_PixelFormat *srcfmt = info->src;
2253 SDL_PixelFormat *dstfmt = info->dst; 2253 SDL_PixelFormat *dstfmt = info->dst;
2254 int srcbpp = srcfmt->BytesPerPixel; 2254 int srcbpp = srcfmt->BytesPerPixel;
2255 int dstbpp = dstfmt->BytesPerPixel; 2255 int dstbpp = dstfmt->BytesPerPixel;
2256 unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0; 2256 unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
2257 Uint32 rgbmask = ~srcfmt->Amask; 2257 Uint32 rgbmask = ~srcfmt->Amask;
2258 2258
2259 /* Set up some basic variables */ 2259 /* Set up some basic variables */
2260 ckey &= rgbmask; 2260 ckey &= rgbmask;
2261 2261
2289 int height = info->d_height; 2289 int height = info->d_height;
2290 Uint8 *src = info->s_pixels; 2290 Uint8 *src = info->s_pixels;
2291 int srcskip = info->s_skip; 2291 int srcskip = info->s_skip;
2292 Uint8 *dst = info->d_pixels; 2292 Uint8 *dst = info->d_pixels;
2293 int dstskip = info->d_skip; 2293 int dstskip = info->d_skip;
2294 Uint32 ckey = info->src->colorkey; 2294 Uint32 ckey = info->ckey;
2295 SDL_PixelFormat *srcfmt = info->src; 2295 SDL_PixelFormat *srcfmt = info->src;
2296 SDL_PixelFormat *dstfmt = info->dst; 2296 SDL_PixelFormat *dstfmt = info->dst;
2297 Uint32 rgbmask = ~srcfmt->Amask; 2297 Uint32 rgbmask = ~srcfmt->Amask;
2298 2298
2299 Uint8 srcbpp; 2299 Uint8 srcbpp;
2330 { 2330 {
2331 Uint32 srcR, srcG, srcB; 2331 Uint32 srcR, srcG, srcB;
2332 int dstbpp; 2332 int dstbpp;
2333 Uint32 dstR, dstG, dstB; 2333 Uint32 dstR, dstG, dstB;
2334 Uint32 blit_features; 2334 Uint32 blit_features;
2335 void *aux_data;
2336 SDL_loblit blitfunc; 2335 SDL_loblit blitfunc;
2337 enum 2336 enum
2338 { NO_ALPHA = 1, SET_ALPHA = 2, COPY_ALPHA = 4 } alpha; 2337 { NO_ALPHA = 1, SET_ALPHA = 2, COPY_ALPHA = 4 } alpha;
2339 }; 2338 };
2340 static const struct blit_table normal_blit_1[] = { 2339 static const struct blit_table normal_blit_1[] = {
2341 /* Default for 8-bit RGB source, an invalid combination */ 2340 /* Default for 8-bit RGB source, an invalid combination */
2342 {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL}, 2341 {0, 0, 0, 0, 0, 0, 0, 0, NULL},
2343 }; 2342 };
2344 static const struct blit_table normal_blit_2[] = { 2343 static const struct blit_table normal_blit_2[] = {
2345 #if SDL_ALTIVEC_BLITTERS 2344 #if SDL_ALTIVEC_BLITTERS
2346 /* has-altivec */ 2345 /* has-altivec */
2347 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000, 2346 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000,
2348 0x00000000, 2347 0x00000000,
2349 2, NULL, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, 2348 2, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
2350 {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000, 2349 {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000,
2351 0x00000000, 2350 0x00000000,
2352 2, NULL, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA}, 2351 2, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
2353 #endif 2352 #endif
2354 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00, 2353 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00,
2355 0x000000FF, 2354 0x000000FF,
2356 0, NULL, Blit_RGB565_ARGB8888, SET_ALPHA}, 2355 0, Blit_RGB565_ARGB8888, SET_ALPHA},
2357 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00, 2356 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00,
2358 0x00FF0000, 2357 0x00FF0000,
2359 0, NULL, Blit_RGB565_ABGR8888, SET_ALPHA}, 2358 0, Blit_RGB565_ABGR8888, SET_ALPHA},
2360 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000, 2359 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000,
2361 0x0000FF00, 2360 0x0000FF00,
2362 0, NULL, Blit_RGB565_RGBA8888, SET_ALPHA}, 2361 0, Blit_RGB565_RGBA8888, SET_ALPHA},
2363 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000, 2362 {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000,
2364 0xFF000000, 2363 0xFF000000,
2365 0, NULL, Blit_RGB565_BGRA8888, SET_ALPHA}, 2364 0, Blit_RGB565_BGRA8888, SET_ALPHA},
2366 2365
2367 /* Default for 16-bit RGB source, used if no other blitter matches */ 2366 /* Default for 16-bit RGB source, used if no other blitter matches */
2368 {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0} 2367 {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
2369 }; 2368 };
2370 static const struct blit_table normal_blit_3[] = { 2369 static const struct blit_table normal_blit_3[] = {
2371 /* Default for 24-bit RGB source, never optimized */ 2370 /* Default for 24-bit RGB source, never optimized */
2372 {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0} 2371 {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
2373 }; 2372 };
2374 static const struct blit_table normal_blit_4[] = { 2373 static const struct blit_table normal_blit_4[] = {
2375 #if SDL_ALTIVEC_BLITTERS 2374 #if SDL_ALTIVEC_BLITTERS
2376 /* has-altivec | dont-use-prefetch */ 2375 /* has-altivec | dont-use-prefetch */
2377 {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 2376 {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000,
2378 0x00000000, 2377 0x00000000,
2379 6, NULL, ConvertAltivec32to32_noprefetch, 2378 6, ConvertAltivec32to32_noprefetch,
2380 NO_ALPHA | COPY_ALPHA | SET_ALPHA}, 2379 NO_ALPHA | COPY_ALPHA | SET_ALPHA},
2381 /* has-altivec */ 2380 /* has-altivec */
2382 {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 2381 {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000,
2383 0x00000000, 2382 0x00000000,
2384 2, NULL, ConvertAltivec32to32_prefetch, 2383 2, ConvertAltivec32to32_prefetch,
2385 NO_ALPHA | COPY_ALPHA | SET_ALPHA}, 2384 NO_ALPHA | COPY_ALPHA | SET_ALPHA},
2386 /* has-altivec */ 2385 /* has-altivec */
2387 {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 2386 {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0,
2388 0x0000001F, 2387 0x0000001F,
2389 2, NULL, Blit_RGB888_RGB565Altivec, NO_ALPHA}, 2388 2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
2390 #endif 2389 #endif
2391 {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 2390 {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0,
2392 0x0000001F, 2391 0x0000001F,
2393 0, NULL, Blit_RGB888_RGB565, NO_ALPHA}, 2392 0, Blit_RGB888_RGB565, NO_ALPHA},
2394 {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 2393 {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0,
2395 0x0000001F, 2394 0x0000001F,
2396 0, NULL, Blit_RGB888_RGB555, NO_ALPHA}, 2395 0, Blit_RGB888_RGB555, NO_ALPHA},
2397 /* Default for 32-bit RGB source, used if no other blitter matches */ 2396 /* Default for 32-bit RGB source, used if no other blitter matches */
2398 {0, 0, 0, 0, 0, 0, 0, 0, NULL, BlitNtoN, 0} 2397 {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
2399 }; 2398 };
2400 static const struct blit_table *normal_blit[] = { 2399 static const struct blit_table *normal_blit[] = {
2401 normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4 2400 normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
2402 }; 2401 };
2403 2402
2405 #define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000)) 2404 #define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000))
2406 2405
2407 SDL_loblit 2406 SDL_loblit
2408 SDL_CalculateBlitN(SDL_Surface * surface, int blit_index) 2407 SDL_CalculateBlitN(SDL_Surface * surface, int blit_index)
2409 { 2408 {
2410 struct private_swaccel *sdata;
2411 SDL_PixelFormat *srcfmt; 2409 SDL_PixelFormat *srcfmt;
2412 SDL_PixelFormat *dstfmt; 2410 SDL_PixelFormat *dstfmt;
2413 const struct blit_table *table; 2411 const struct blit_table *table;
2414 int which; 2412 int which;
2415 SDL_loblit blitfun; 2413 SDL_loblit blitfun;
2416 2414
2417 /* Set up data for choosing the blit */ 2415 /* Set up data for choosing the blit */
2418 sdata = surface->map->sw_data;
2419 srcfmt = surface->format; 2416 srcfmt = surface->format;
2420 dstfmt = surface->map->dst->format; 2417 dstfmt = surface->map->dst->format;
2421 2418
2422 if (blit_index & 2) { 2419 if (blit_index & 2) {
2423 /* alpha or alpha+colorkey */ 2420 /* alpha or alpha+colorkey */
2484 (a_need & table[which].alpha) == a_need && 2481 (a_need & table[which].alpha) == a_need &&
2485 ((table[which].blit_features & GetBlitFeatures()) == 2482 ((table[which].blit_features & GetBlitFeatures()) ==
2486 table[which].blit_features)) 2483 table[which].blit_features))
2487 break; 2484 break;
2488 } 2485 }
2489 sdata->aux_data = table[which].aux_data;
2490 blitfun = table[which].blitfunc; 2486 blitfun = table[which].blitfunc;
2491 2487
2492 if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */ 2488 if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */
2493 /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */ 2489 /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
2494 if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 && 2490 if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 &&