Fixed error message when destroying a software renderer, thanks to wahono for the patch.
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
21 #include "SDL_config.h"
23 #include "SDL_video.h"
33 c128.m128_u32[0] = color; \
34 c128.m128_u32[1] = color; \
35 c128.m128_u32[2] = color; \
36 c128.m128_u32[3] = color;
39 DECLARE_ALIGNED(Uint32, cccc[4], 16); \
44 __m128 c128 = *(__m128 *)cccc;
48 for (i = n / 64; i--;) { \
49 _mm_stream_ps((float *)(p+0), c128); \
50 _mm_stream_ps((float *)(p+16), c128); \
51 _mm_stream_ps((float *)(p+32), c128); \
52 _mm_stream_ps((float *)(p+48), c128); \
58 #define DEFINE_SSE_FILLRECT(bpp, type) \
60 SDL_FillRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
69 int adjust = 16 - ((uintptr_t)p & 15); \
74 *((type *)p) = (type)color; \
81 int remainder = (n & 63); \
83 while (remainder--) { \
84 *((type *)p) = (type)color; \
95 SDL_FillRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
104 int adjust = 16 - ((uintptr_t)p & 15);
107 SDL_memset(p, color, adjust);
113 int remainder = (n & 63);
114 SDL_memset(p, color, remainder);
122 /*DEFINE_SSE_FILLRECT(1, Uint8)*/
123 DEFINE_SSE_FILLRECT(2, Uint16)
124 DEFINE_SSE_FILLRECT(4, Uint32)
133 __m64 c64 = _mm_set_pi32(color, color)
136 for (i = n / 64; i--;) { \
137 _mm_stream_pi((__m64 *)(p+0), c64); \
138 _mm_stream_pi((__m64 *)(p+8), c64); \
139 _mm_stream_pi((__m64 *)(p+16), c64); \
140 _mm_stream_pi((__m64 *)(p+24), c64); \
141 _mm_stream_pi((__m64 *)(p+32), c64); \
142 _mm_stream_pi((__m64 *)(p+40), c64); \
143 _mm_stream_pi((__m64 *)(p+48), c64); \
144 _mm_stream_pi((__m64 *)(p+56), c64); \
151 #define DEFINE_MMX_FILLRECT(bpp, type) \
153 SDL_FillRect##bpp##MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
158 int i, n = w * bpp; \
162 int adjust = 8 - ((uintptr_t)p & 7); \
167 *((type *)p) = (type)color; \
174 int remainder = (n & 63); \
176 while (remainder--) { \
177 *((type *)p) = (type)color; \
188 SDL_FillRect1MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
197 int adjust = 8 - ((uintptr_t)p & 7);
200 SDL_memset(p, color, adjust);
206 int remainder = (n & 63);
207 SDL_memset(p, color, remainder);
215 /*DEFINE_MMX_FILLRECT(1, Uint8)*/
216 DEFINE_MMX_FILLRECT(2, Uint16)
217 DEFINE_MMX_FILLRECT(4, Uint32)
223 SDL_FillRect1(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
230 switch ((uintptr_t) p & 3) {
232 *p++ = (Uint8) color;
235 *p++ = (Uint8) color;
238 *p++ = (Uint8) color;
241 SDL_memset4(p, color, (n >> 2));
247 *p++ = (Uint8) color;
249 *p++ = (Uint8) color;
251 *p++ = (Uint8) color;
259 SDL_FillRect2(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
263 Uint16 *p = (Uint16 *) pixels;
266 if ((uintptr_t) p & 2) {
267 *p++ = (Uint16) color;
270 SDL_memset4(p, color, (n >> 1));
273 p[n - 1] = (Uint16) color;
280 SDL_FillRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
282 Uint8 r = (Uint8) ((color >> 16) & 0xFF);
283 Uint8 g = (Uint8) ((color >> 8) & 0xFF);
284 Uint8 b = (Uint8) (color & 0xFF);
300 SDL_FillRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
303 SDL_memset4(pixels, color, w);
309 * This function performs a fast fill of the given rectangle with 'color'
312 SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
318 SDL_SetError("Passed NULL destination surface");
322 /* This function doesn't work on surfaces < 8 bpp */
323 if (dst->format->BitsPerPixel < 8) {
324 SDL_SetError("SDL_FillRect(): Unsupported surface format");
328 /* If 'rect' == NULL, then fill the whole surface */
330 /* Perform clipping */
331 if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
336 rect = &dst->clip_rect;
339 /* Perform software fill */
341 SDL_SetError("SDL_FillRect(): You must lock the surface");
345 pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
346 rect->x * dst->format->BytesPerPixel;
348 switch (dst->format->BytesPerPixel) {
351 color |= (color << 8);
352 color |= (color << 16);
355 SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
361 SDL_FillRect1MMX(pixels, dst->pitch, color, rect->w, rect->h);
365 SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h);
371 color |= (color << 16);
374 SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
380 SDL_FillRect2MMX(pixels, dst->pitch, color, rect->w, rect->h);
384 SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h);
389 /* 24-bit RGB is a slow path, at least for now. */
391 SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h);
399 SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
405 SDL_FillRect4MMX(pixels, dst->pitch, color, rect->w, rect->h);
409 SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h);
419 SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
426 SDL_SetError("SDL_FillRects() passed NULL rects");
430 for (i = 0; i < count; ++i) {
431 status += SDL_FillRect(dst, &rects[i], color);
436 /* vi: set ts=4 sw=4 expandtab: */