Last active
August 29, 2015 14:03
-
-
Save whyrusleeping/cd7a64362d9c6dada211 to your computer and use it in GitHub Desktop.
SDL BlitCopy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
SDL_BlitCopy(SDL_BlitInfo * info) | |
{ | |
SDL_bool overlap; | |
Uint8 *src, *dst; | |
int w, h; | |
int srcskip, dstskip; | |
w = info->dst_w * info->dst_fmt->BytesPerPixel; | |
h = info->dst_h; | |
src = info->src; | |
dst = info->dst; | |
srcskip = info->src_pitch; | |
dstskip = info->dst_pitch; | |
/* Properly handle overlapping blits */ | |
if (src < dst) { | |
overlap = (dst < (src + h*srcskip)); | |
} else { | |
overlap = (src < (dst + h*dstskip)); | |
} | |
if (overlap) { | |
while (h--) { | |
SDL_memmove(dst, src, w); | |
src += srcskip; | |
dst += dstskip; | |
} | |
return; | |
} | |
#ifdef __SSE__ | |
if (SDL_HasSSE() && | |
!((uintptr_t) src & 15) && !(srcskip & 15) && | |
!((uintptr_t) dst & 15) && !(dstskip & 15)) { | |
while (h--) { | |
SDL_memcpySSE(dst, src, w); | |
src += srcskip; | |
dst += dstskip; | |
} | |
return; | |
} | |
#endif | |
#ifdef __MMX__ | |
if (SDL_HasMMX() && !(srcskip & 7) && !(dstskip & 7)) { | |
while (h--) { | |
SDL_memcpyMMX(dst, src, w); | |
src += srcskip; | |
dst += dstskip; | |
} | |
_mm_empty(); | |
return; | |
} | |
#endif | |
while (h--) { | |
SDL_memcpy(dst, src, w); | |
src += srcskip; | |
dst += dstskip; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment