Added a way to get a framebuffer interface for a window, and also a way to create a software renderer for an arbitrary surface.
The software renderer has been re-routed to use the framebuffer interface, which makes it possible to have software rendering available even on simple ports.
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2010 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
25 #include "SDL_drawline.h"
26 #include "SDL_drawpoint.h"
30 SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
34 //HLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
36 int pitch = (dst->pitch / dst->format->BytesPerPixel);
39 pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
40 length = draw_end ? (x2-x1+1) : (x2-x1);
42 pixel = (Uint8 *)dst->pixels + y1 * pitch + x2;
46 length = draw_end ? (x1-x2+1) : (x1-x2);
48 SDL_memset(pixel, color, length);
49 } else if (x1 == x2) {
50 VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
51 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
52 DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
54 BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end);
59 SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
63 HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
64 } else if (x1 == x2) {
65 VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
66 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
67 DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
70 const SDL_PixelFormat * fmt = dst->format;
71 SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
72 if (fmt->Rmask == 0x7C00) {
73 AALINE(x1, y1, x2, y2,
74 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
76 } else if (fmt->Rmask == 0xF800) {
77 AALINE(x1, y1, x2, y2,
78 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565,
81 AALINE(x1, y1, x2, y2,
82 DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB,
89 SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
93 HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
94 } else if (x1 == x2) {
95 VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
96 } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
97 DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
100 const SDL_PixelFormat * fmt = dst->format;
101 SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
102 if (fmt->Rmask == 0x00FF0000) {
104 AALINE(x1, y1, x2, y2,
105 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888,
108 AALINE(x1, y1, x2, y2,
109 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888,
113 AALINE(x1, y1, x2, y2,
114 DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB,
120 typedef void (*DrawLineFunc) (SDL_Surface * dst,
121 int x1, int y1, int x2, int y2,
122 Uint32 color, SDL_bool draw_end);
125 SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
127 switch (fmt->BytesPerPixel) {
129 if (fmt->BitsPerPixel < 8) {
132 return SDL_DrawLine1;
134 return SDL_DrawLine2;
136 return SDL_DrawLine4;
142 SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
147 SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
151 func = SDL_CalculateDrawLineFunc(dst->format);
153 SDL_SetError("SDL_DrawLine(): Unsupported surface format");
157 /* Perform clipping */
158 /* FIXME: We don't actually want to clip, as it may change line slope */
159 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
163 func(dst, x1, y1, x2, y2, color, SDL_TRUE);
168 SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
178 SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
182 func = SDL_CalculateDrawLineFunc(dst->format);
184 SDL_SetError("SDL_DrawLines(): Unsupported surface format");
188 for (i = 1; i < count; ++i) {
194 /* Perform clipping */
195 /* FIXME: We don't actually want to clip, as it may change line slope */
196 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
200 /* Draw the end if it was clipped */
201 draw_end = (x2 != points[i].x || y2 != points[i].y);
203 func(dst, x1, y1, x2, y2, color, draw_end);
205 if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
206 SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
211 /* vi: set ts=4 sw=4 expandtab: */