Make SDL_SetError and friends unconditionally return -1.
This lets us change things like this...
if (Failed) {
SDL_SetError("We failed");
return -1;
}
...into this...
if (Failed) {
return SDL_SetError("We failed");
}
Fixes Bugzilla #1778.
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 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 #if !SDL_RENDER_DISABLED
26 #include "SDL_drawline.h"
27 #include "SDL_drawpoint.h"
31 SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
35 //HLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
37 int pitch = (dst->pitch / dst->format->BytesPerPixel);
40 pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
41 length = draw_end ? (x2-x1+1) : (x2-x1);
43 pixel = (Uint8 *)dst->pixels + y1 * pitch + x2;
47 length = draw_end ? (x1-x2+1) : (x1-x2);
49 SDL_memset(pixel, color, length);
50 } else if (x1 == x2) {
51 VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
52 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
53 DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
55 BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end);
60 SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
64 HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
65 } else if (x1 == x2) {
66 VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
67 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
68 DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
71 const SDL_PixelFormat * fmt = dst->format;
72 SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
73 if (fmt->Rmask == 0x7C00) {
74 AALINE(x1, y1, x2, y2,
75 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
77 } else if (fmt->Rmask == 0xF800) {
78 AALINE(x1, y1, x2, y2,
79 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565,
82 AALINE(x1, y1, x2, y2,
83 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB,
90 SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
94 HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
95 } else if (x1 == x2) {
96 VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
97 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
98 DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
100 Uint8 _r, _g, _b, _a;
101 const SDL_PixelFormat * fmt = dst->format;
102 SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
103 if (fmt->Rmask == 0x00FF0000) {
105 AALINE(x1, y1, x2, y2,
106 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888,
109 AALINE(x1, y1, x2, y2,
110 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888,
114 AALINE(x1, y1, x2, y2,
115 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB,
121 typedef void (*DrawLineFunc) (SDL_Surface * dst,
122 int x1, int y1, int x2, int y2,
123 Uint32 color, SDL_bool draw_end);
126 SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
128 switch (fmt->BytesPerPixel) {
130 if (fmt->BitsPerPixel < 8) {
133 return SDL_DrawLine1;
135 return SDL_DrawLine2;
137 return SDL_DrawLine4;
143 SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
148 return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
151 func = SDL_CalculateDrawLineFunc(dst->format);
153 return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
156 /* Perform clipping */
157 /* FIXME: We don't actually want to clip, as it may change line slope */
158 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
162 func(dst, x1, y1, x2, y2, color, SDL_TRUE);
167 SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
177 return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
180 func = SDL_CalculateDrawLineFunc(dst->format);
182 return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
185 for (i = 1; i < count; ++i) {
191 /* Perform clipping */
192 /* FIXME: We don't actually want to clip, as it may change line slope */
193 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
197 /* Draw the end if it was clipped */
198 draw_end = (x2 != points[i].x || y2 != points[i].y);
200 func(dst, x1, y1, x2, y2, color, draw_end);
202 if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
203 SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
208 #endif /* !SDL_RENDER_DISABLED */
210 /* vi: set ts=4 sw=4 expandtab: */