/project/jni/sdl-1.3/src/video/SDL_blit_copy.c

https://github.com/aichunyu/FFPlayer · C · 152 lines · 112 code · 17 blank · 23 comment · 17 complexity · 7b227e2f1be1a0f5ada449af9c74608a MD5 · raw file

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_config.h"
  19. #include "SDL_video.h"
  20. #include "SDL_blit.h"
  21. #include "SDL_blit_copy.h"
  22. #ifdef __SSE__
  23. /* This assumes 16-byte aligned src and dst */
  24. static __inline__ void
  25. SDL_memcpySSE(Uint8 * dst, const Uint8 * src, int len)
  26. {
  27. int i;
  28. __m128 values[4];
  29. for (i = len / 64; i--;) {
  30. _mm_prefetch(src, _MM_HINT_NTA);
  31. values[0] = *(__m128 *) (src + 0);
  32. values[1] = *(__m128 *) (src + 16);
  33. values[2] = *(__m128 *) (src + 32);
  34. values[3] = *(__m128 *) (src + 48);
  35. _mm_stream_ps((float *) (dst + 0), values[0]);
  36. _mm_stream_ps((float *) (dst + 16), values[1]);
  37. _mm_stream_ps((float *) (dst + 32), values[2]);
  38. _mm_stream_ps((float *) (dst + 48), values[3]);
  39. src += 64;
  40. dst += 64;
  41. }
  42. if (len & 63)
  43. SDL_memcpy(dst, src, len & 63);
  44. }
  45. #endif /* __SSE__ */
  46. #ifdef __MMX__
  47. #ifdef _MSC_VER
  48. #pragma warning(disable:4799)
  49. #endif
  50. static __inline__ void
  51. SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len)
  52. {
  53. const int remain = (len & 63);
  54. int i;
  55. __m64* d64 = (__m64*)dst;
  56. __m64* s64 = (__m64*)src;
  57. for(i= len / 64; i--;) {
  58. d64[0] = s64[0];
  59. d64[1] = s64[1];
  60. d64[2] = s64[2];
  61. d64[3] = s64[3];
  62. d64[4] = s64[4];
  63. d64[5] = s64[5];
  64. d64[6] = s64[6];
  65. d64[7] = s64[7];
  66. d64 += 8;
  67. s64 += 8;
  68. }
  69. if (remain)
  70. {
  71. const int skip = len - remain;
  72. SDL_memcpy(dst + skip, src + skip, remain);
  73. }
  74. }
  75. #endif /* __MMX__ */
  76. void
  77. SDL_BlitCopy(SDL_BlitInfo * info)
  78. {
  79. SDL_bool overlap;
  80. Uint8 *src, *dst;
  81. int w, h;
  82. int srcskip, dstskip;
  83. w = info->dst_w * info->dst_fmt->BytesPerPixel;
  84. h = info->dst_h;
  85. src = info->src;
  86. dst = info->dst;
  87. srcskip = info->src_pitch;
  88. dstskip = info->dst_pitch;
  89. /* Properly handle overlapping blits */
  90. if (src < dst) {
  91. overlap = (dst < (src + h*srcskip));
  92. } else {
  93. overlap = (src < (dst + h*dstskip));
  94. }
  95. if (overlap) {
  96. while (h--) {
  97. SDL_memmove(dst, src, w);
  98. src += srcskip;
  99. dst += dstskip;
  100. }
  101. return;
  102. }
  103. #ifdef __SSE__
  104. if (SDL_HasSSE() &&
  105. !((uintptr_t) src & 15) && !(srcskip & 15) &&
  106. !((uintptr_t) dst & 15) && !(dstskip & 15)) {
  107. while (h--) {
  108. SDL_memcpySSE(dst, src, w);
  109. src += srcskip;
  110. dst += dstskip;
  111. }
  112. return;
  113. }
  114. #endif
  115. #ifdef __MMX__
  116. if (SDL_HasMMX() && !(srcskip & 7) && !(dstskip & 7)) {
  117. while (h--) {
  118. SDL_memcpyMMX(dst, src, w);
  119. src += srcskip;
  120. dst += dstskip;
  121. }
  122. _mm_empty();
  123. return;
  124. }
  125. #endif
  126. while (h--) {
  127. SDL_memcpy(dst, src, w);
  128. src += srcskip;
  129. dst += dstskip;
  130. }
  131. }
  132. /* vi: set ts=4 sw=4 expandtab: */