annotate src/video/SDL_drawrect.c @ 3593:b931bcfd94a0

In the process of adding rectangle drawing
author Sam Lantinga <slouken@libsdl.org>
date Fri, 18 Dec 2009 07:03:09 +0000
parents
children c8bed77b0386
rev   line source
3593
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_video.h"
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "SDL_blit.h"
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #ifdef __SSE__
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 /* *INDENT-OFF* */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #ifdef _MSC_VER
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #define SSE_BEGIN \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 __m128 c128; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 c128.m128_u32[0] = color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 c128.m128_u32[1] = color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 c128.m128_u32[2] = color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 c128.m128_u32[3] = color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #else
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #define SSE_BEGIN \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 DECLARE_ALIGNED(Uint32, cccc[4], 16); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 cccc[0] = color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 cccc[1] = color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 cccc[2] = color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 cccc[3] = color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 __m128 c128 = *(__m128 *)cccc;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #endif
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #define SSE_WORK \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 for (i = n / 64; i--;) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 _mm_stream_ps((float *)(p+0), c128); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 _mm_stream_ps((float *)(p+16), c128); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 _mm_stream_ps((float *)(p+32), c128); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 _mm_stream_ps((float *)(p+48), c128); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 p += 64; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 #define SSE_END
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 #define DEFINE_SSE_FILLRECT(bpp, type) \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 static void \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 SDL_DrawRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 SSE_BEGIN; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 while (h--) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 int i, n = w * bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 Uint8 *p = pixels; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 if (n > 63) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 int adjust = 16 - ((uintptr_t)p & 15); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 if (adjust < 16) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 n -= adjust; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 adjust /= bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 while (adjust--) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 *((type *)p) = (type)color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 p += bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 SSE_WORK; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 if (n & 63) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 int remainder = (n & 63); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 remainder /= bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 while (remainder--) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 *((type *)p) = (type)color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 p += bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 pixels += pitch; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 SSE_END; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 static void
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 SDL_DrawRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 SSE_BEGIN;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 while (h--) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 int i, n = w;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 Uint8 *p = pixels;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 if (n > 63) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 int adjust = 16 - ((uintptr_t)p & 15);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 if (adjust) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 n -= adjust;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 SDL_memset(p, color, adjust);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 p += adjust;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 SSE_WORK;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 if (n & 63) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 int remainder = (n & 63);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 SDL_memset(p, color, remainder);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 p += remainder;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 pixels += pitch;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 SSE_END;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 /*DEFINE_SSE_FILLRECT(1, Uint8)*/
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 DEFINE_SSE_FILLRECT(2, Uint16)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 DEFINE_SSE_FILLRECT(4, Uint32)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 /* *INDENT-ON* */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 #endif /* __SSE__ */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 #ifdef __MMX__
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 /* *INDENT-OFF* */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 #define MMX_BEGIN \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 __m64 c64 = _mm_set_pi32(color, color)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 #define MMX_WORK \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 for (i = n / 64; i--;) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 _mm_stream_pi((__m64 *)(p+0), c64); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 _mm_stream_pi((__m64 *)(p+8), c64); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 _mm_stream_pi((__m64 *)(p+16), c64); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 _mm_stream_pi((__m64 *)(p+24), c64); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 _mm_stream_pi((__m64 *)(p+32), c64); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 _mm_stream_pi((__m64 *)(p+40), c64); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 _mm_stream_pi((__m64 *)(p+48), c64); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 _mm_stream_pi((__m64 *)(p+56), c64); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 p += 64; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 #define MMX_END \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 _mm_empty()
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 #define DEFINE_MMX_FILLRECT(bpp, type) \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 static void \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 SDL_DrawRect##bpp##MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 MMX_BEGIN; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 while (h--) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 int i, n = w * bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 Uint8 *p = pixels; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 if (n > 63) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 int adjust = 8 - ((uintptr_t)p & 7); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 if (adjust < 8) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 n -= adjust; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 adjust /= bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 while (adjust--) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 *((type *)p) = (type)color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 p += bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 MMX_WORK; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 if (n & 63) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 int remainder = (n & 63); \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 remainder /= bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 while (remainder--) { \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 *((type *)p) = (type)color; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 p += bpp; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 pixels += pitch; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 } \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 MMX_END; \
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 static void
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 SDL_DrawRect1MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 MMX_BEGIN;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 while (h--) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 int i, n = w;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 Uint8 *p = pixels;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 if (n > 63) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 int adjust = 8 - ((uintptr_t)p & 7);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 if (adjust) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 n -= adjust;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 SDL_memset(p, color, adjust);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 p += adjust;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 MMX_WORK;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 if (n & 63) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 int remainder = (n & 63);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 SDL_memset(p, color, remainder);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 p += remainder;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 pixels += pitch;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 MMX_END;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 /*DEFINE_MMX_FILLRECT(1, Uint8)*/
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 DEFINE_MMX_FILLRECT(2, Uint16)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 DEFINE_MMX_FILLRECT(4, Uint32)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 /* *INDENT-ON* */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 #endif /* __MMX__ */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 static void
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 SDL_DrawRect1(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 while (h--) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 int n = w;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 Uint8 *p = pixels;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 if (n > 3) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 switch ((uintptr_t) p & 3) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 case 1:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 *p++ = (Uint8) color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 --n;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 case 2:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 *p++ = (Uint8) color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 --n;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 case 3:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 *p++ = (Uint8) color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 --n;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 SDL_memset4(p, color, (n >> 2));
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 if (n & 3) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 p += (n & ~3);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 switch (n & 3) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 case 3:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 *p++ = (Uint8) color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 case 2:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 *p++ = (Uint8) color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 case 1:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 *p++ = (Uint8) color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 pixels += pitch;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 static void
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 SDL_DrawRect2(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 while (h--) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 int n = w;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 Uint16 *p = (Uint16 *) pixels;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 if (n > 1) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 if ((uintptr_t) p & 2) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 *p++ = (Uint16) color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 --n;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 SDL_memset4(p, color, (n >> 1));
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 if (n & 1) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 p[n - 1] = (Uint16) color;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 pixels += pitch;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 static void
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 SDL_DrawRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 Uint8 r = (Uint8) ((color >> 16) & 0xFF);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 Uint8 g = (Uint8) ((color >> 8) & 0xFF);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 Uint8 b = (Uint8) (color & 0xFF);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 while (h--) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 int n = w;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 Uint8 *p = pixels;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 while (n--) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 *p++ = r;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 *p++ = g;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 *p++ = b;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 pixels += pitch;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 static void
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 SDL_DrawRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 while (h--) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 SDL_memset4(pixels, color, w);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 pixels += pitch;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 /*
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 * This function performs a fast fill of the given rectangle with 'color'
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 int
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 SDL_DrawRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 SDL_Rect clipped;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 Uint8 *pixels;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 if (!dst) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 SDL_SetError("Passed NULL destination surface");
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 return -1;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 /* This function doesn't work on surfaces < 8 bpp */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 if (dst->format->BitsPerPixel < 8) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 SDL_SetError("SDL_DrawRect(): Unsupported surface format");
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 return -1;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 /* If 'rect' == NULL, then fill the whole surface */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 if (rect) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 /* Perform clipping */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 return 0;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 rect = &clipped;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 } else {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 rect = &dst->clip_rect;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 /* Perform software fill */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 if (!dst->pixels) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 SDL_SetError("SDL_DrawRect(): You must lock the surface");
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 return (-1);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 rect->x * dst->format->BytesPerPixel;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 switch (dst->format->BytesPerPixel) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 case 1:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 color |= (color << 8);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 color |= (color << 16);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 #ifdef __SSE__
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 if (SDL_HasSSE()) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 SDL_DrawRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 #endif
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 #ifdef __MMX__
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 if (SDL_HasMMX()) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 SDL_DrawRect1MMX(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 #endif
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 SDL_DrawRect1(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 case 2:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 color |= (color << 16);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 #ifdef __SSE__
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 if (SDL_HasSSE()) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 SDL_DrawRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 #endif
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 #ifdef __MMX__
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 if (SDL_HasMMX()) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 SDL_DrawRect2MMX(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 #endif
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 SDL_DrawRect2(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 case 3:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 /* 24-bit RGB is a slow path, at least for now. */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 SDL_DrawRect3(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 case 4:
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 #ifdef __SSE__
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 if (SDL_HasSSE()) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 SDL_DrawRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 #endif
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 #ifdef __MMX__
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 if (SDL_HasMMX()) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 SDL_DrawRect4MMX(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 #endif
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 SDL_DrawRect4(pixels, dst->pitch, color, rect->w, rect->h);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 break;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 /* We're done! */
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 return 0;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 int
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 SDL_DrawRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 Uint32 color)
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 int i;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 int status = 0;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 for (i = 0; i < count; ++i) {
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 status = SDL_DrawRect(dst, rects[i], color);
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 return status;
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 }
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431
b931bcfd94a0 In the process of adding rectangle drawing
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 /* vi: set ts=4 sw=4 expandtab: */