SDL  2.0
SDL_fillrect.c File Reference
#include "../SDL_internal.h"
#include "SDL_video.h"
#include "SDL_blit.h"
#include "SDL_cpuinfo.h"
+ Include dependency graph for SDL_fillrect.c:

Go to the source code of this file.

Functions

static void SDL_FillRect1 (Uint8 *pixels, int pitch, Uint32 color, int w, int h)
 
static void SDL_FillRect2 (Uint8 *pixels, int pitch, Uint32 color, int w, int h)
 
static void SDL_FillRect3 (Uint8 *pixels, int pitch, Uint32 color, int w, int h)
 
static void SDL_FillRect4 (Uint8 *pixels, int pitch, Uint32 color, int w, int h)
 
int SDL_FillRect (SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
 
int SDL_FillRects (SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
 

Function Documentation

◆ SDL_FillRect()

int SDL_FillRect ( SDL_Surface dst,
const SDL_Rect rect,
Uint32  color 
)

Performs a fast fill of the given rectangle with color.

If rect is NULL, the whole surface will be filled with color.

The color should be a pixel of the format used by the surface, and can be generated by the SDL_MapRGB() function.

Returns
0 on success, or -1 on error.

Definition at line 238 of file SDL_fillrect.c.

References SDL_PixelFormat::BitsPerPixel, SDL_PixelFormat::BytesPerPixel, SDL_Surface::clip_rect, SDL_Surface::format, SDL_Rect::h, if, SDL_Surface::pitch, SDL_Surface::pixels, SDL_FillRect1(), SDL_FillRect2(), SDL_FillRect3(), SDL_FillRect4(), SDL_HasARMSIMD(), SDL_HasNEON, SDL_HasSSE, SDL_IntersectRect, SDL_RectEmpty(), SDL_SetError, SDL_UnlockSurface, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SDL_FillRects().

239 {
240  SDL_Rect clipped;
241  Uint8 *pixels;
242 
243  if (!dst) {
244  return SDL_SetError("Passed NULL destination surface");
245  }
246 
247  /* This function doesn't work on surfaces < 8 bpp */
248  if (dst->format->BitsPerPixel < 8) {
249  return SDL_SetError("SDL_FillRect(): Unsupported surface format");
250  }
251 
252  /* If 'rect' == NULL, then fill the whole surface */
253  if (rect) {
254  /* Perform clipping */
255  if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
256  return 0;
257  }
258  rect = &clipped;
259  } else {
260  rect = &dst->clip_rect;
261  /* Don't attempt to fill if the surface's clip_rect is empty */
262  if (SDL_RectEmpty(rect)) {
263  return 0;
264  }
265  }
266 
267  /* Perform software fill */
268  if (!dst->pixels) {
269  return SDL_SetError("SDL_FillRect(): You must lock the surface");
270  }
271 
272  pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
273  rect->x * dst->format->BytesPerPixel;
274 
275 #if SDL_ARM_NEON_BLITTERS
276  if (SDL_HasNEON() && dst->format->BytesPerPixel != 3) {
277  void FillRect8ARMNEONAsm(int32_t w, int32_t h, uint8_t *dst, int32_t dst_stride, uint8_t src);
278  void FillRect16ARMNEONAsm(int32_t w, int32_t h, uint16_t *dst, int32_t dst_stride, uint16_t src);
279  void FillRect32ARMNEONAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t src);
280  switch (dst->format->BytesPerPixel) {
281  case 1:
282  FillRect8ARMNEONAsm(rect->w, rect->h, (uint8_t *) pixels, dst->pitch >> 0, color);
283  break;
284  case 2:
285  FillRect16ARMNEONAsm(rect->w, rect->h, (uint16_t *) pixels, dst->pitch >> 1, color);
286  break;
287  case 4:
288  FillRect32ARMNEONAsm(rect->w, rect->h, (uint32_t *) pixels, dst->pitch >> 2, color);
289  break;
290  }
291 
292  SDL_UnlockSurface(dst);
293  return(0);
294  }
295 #endif
296 #if SDL_ARM_SIMD_BLITTERS
297  if (SDL_HasARMSIMD() && dst->format->BytesPerPixel != 3) {
298  void FillRect8ARMSIMDAsm(int32_t w, int32_t h, uint8_t *dst, int32_t dst_stride, uint8_t src);
299  void FillRect16ARMSIMDAsm(int32_t w, int32_t h, uint16_t *dst, int32_t dst_stride, uint16_t src);
300  void FillRect32ARMSIMDAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t src);
301  switch (dst->format->BytesPerPixel) {
302  case 1:
303  FillRect8ARMSIMDAsm(rect->w, rect->h, (uint8_t *) pixels, dst->pitch >> 0, color);
304  break;
305  case 2:
306  FillRect16ARMSIMDAsm(rect->w, rect->h, (uint16_t *) pixels, dst->pitch >> 1, color);
307  break;
308  case 4:
309  FillRect32ARMSIMDAsm(rect->w, rect->h, (uint32_t *) pixels, dst->pitch >> 2, color);
310  break;
311  }
312 
313  SDL_UnlockSurface(dst);
314  return(0);
315  }
316 #endif
317 
318  switch (dst->format->BytesPerPixel) {
319  case 1:
320  {
321  color |= (color << 8);
322  color |= (color << 16);
323 #ifdef __SSE__
324  if (SDL_HasSSE()) {
325  SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
326  break;
327  }
328 #endif
329  SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h);
330  break;
331  }
332 
333  case 2:
334  {
335  color |= (color << 16);
336 #ifdef __SSE__
337  if (SDL_HasSSE()) {
338  SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
339  break;
340  }
341 #endif
342  SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h);
343  break;
344  }
345 
346  case 3:
347  /* 24-bit RGB is a slow path, at least for now. */
348  {
349  SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h);
350  break;
351  }
352 
353  case 4:
354  {
355 #ifdef __SSE__
356  if (SDL_HasSSE()) {
357  SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
358  break;
359  }
360 #endif
361  SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h);
362  break;
363  }
364  }
365 
366  /* We're done! */
367  return 0;
368 }
#define SDL_UnlockSurface
signed int int32_t
unsigned short uint16_t
Uint8 BytesPerPixel
Definition: SDL_pixels.h:320
GLfloat GLfloat GLfloat GLfloat h
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
GLenum src
#define SDL_IntersectRect
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
Definition: SDL_rect.h:82
static void SDL_FillRect3(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:198
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:179
Uint8 BitsPerPixel
Definition: SDL_pixels.h:319
#define SDL_HasNEON
GLubyte GLubyte GLubyte GLubyte w
int x
Definition: SDL_rect.h:66
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
int w
Definition: SDL_rect.h:67
SDL_Rect clip_rect
Definition: SDL_surface.h:85
unsigned char uint8_t
unsigned int uint32_t
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_SetError
static void SDL_FillRect2(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:174
SDL_bool SDL_HasARMSIMD(void)
Definition: SDL_cpuinfo.c:777
int h
Definition: SDL_rect.h:67
GLuint color
static void SDL_FillRect4(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:226
static void SDL_FillRect1(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
Definition: SDL_fillrect.c:135
#define SDL_HasSSE
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ SDL_FillRect1()

static void SDL_FillRect1 ( Uint8 pixels,
int  pitch,
Uint32  color,
int  w,
int  h 
)
static

Definition at line 135 of file SDL_fillrect.c.

References NULL, and SDL_memset4().

Referenced by SDL_FillRect().

136 {
137  int n;
138  Uint8 *p = NULL;
139 
140  while (h--) {
141  n = w;
142  p = pixels;
143 
144  if (n > 3) {
145  switch ((uintptr_t) p & 3) {
146  case 1:
147  *p++ = (Uint8) color;
148  --n; /* fallthrough */
149  case 2:
150  *p++ = (Uint8) color;
151  --n; /* fallthrough */
152  case 3:
153  *p++ = (Uint8) color;
154  --n; /* fallthrough */
155  }
156  SDL_memset4(p, color, (n >> 2));
157  }
158  if (n & 3) {
159  p += (n & ~3);
160  switch (n & 3) {
161  case 3:
162  *p++ = (Uint8) color; /* fallthrough */
163  case 2:
164  *p++ = (Uint8) color; /* fallthrough */
165  case 1:
166  *p++ = (Uint8) color; /* fallthrough */
167  }
168  }
169  pixels += pitch;
170  }
171 }
GLfloat GLfloat GLfloat GLfloat h
GLfloat GLfloat p
SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
Definition: SDL_stdinc.h:420
uint8_t Uint8
Definition: SDL_stdinc.h:179
GLubyte GLubyte GLubyte GLubyte w
unsigned int uintptr_t
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
#define NULL
Definition: begin_code.h:164
GLuint color
GLdouble n

◆ SDL_FillRect2()

static void SDL_FillRect2 ( Uint8 pixels,
int  pitch,
Uint32  color,
int  w,
int  h 
)
static

Definition at line 174 of file SDL_fillrect.c.

References NULL, and SDL_memset4().

Referenced by SDL_FillRect().

175 {
176  int n;
177  Uint16 *p = NULL;
178 
179  while (h--) {
180  n = w;
181  p = (Uint16 *) pixels;
182 
183  if (n > 1) {
184  if ((uintptr_t) p & 2) {
185  *p++ = (Uint16) color;
186  --n;
187  }
188  SDL_memset4(p, color, (n >> 1));
189  }
190  if (n & 1) {
191  p[n - 1] = (Uint16) color;
192  }
193  pixels += pitch;
194  }
195 }
GLfloat GLfloat GLfloat GLfloat h
GLfloat GLfloat p
uint16_t Uint16
Definition: SDL_stdinc.h:191
SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
Definition: SDL_stdinc.h:420
GLubyte GLubyte GLubyte GLubyte w
unsigned int uintptr_t
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
#define NULL
Definition: begin_code.h:164
GLuint color
GLdouble n

◆ SDL_FillRect3()

static void SDL_FillRect3 ( Uint8 pixels,
int  pitch,
Uint32  color,
int  w,
int  h 
)
static

Definition at line 198 of file SDL_fillrect.c.

References NULL.

Referenced by SDL_FillRect().

199 {
200 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
201  Uint8 b1 = (Uint8) (color & 0xFF);
202  Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
203  Uint8 b3 = (Uint8) ((color >> 16) & 0xFF);
204 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
205  Uint8 b1 = (Uint8) ((color >> 16) & 0xFF);
206  Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
207  Uint8 b3 = (Uint8) (color & 0xFF);
208 #endif
209  int n;
210  Uint8 *p = NULL;
211 
212  while (h--) {
213  n = w;
214  p = pixels;
215 
216  while (n--) {
217  *p++ = b1;
218  *p++ = b2;
219  *p++ = b3;
220  }
221  pixels += pitch;
222  }
223 }
GLfloat GLfloat GLfloat GLfloat h
GLfloat GLfloat p
uint8_t Uint8
Definition: SDL_stdinc.h:179
GLubyte GLubyte GLubyte GLubyte w
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
#define NULL
Definition: begin_code.h:164
GLuint color
GLdouble n

◆ SDL_FillRect4()

static void SDL_FillRect4 ( Uint8 pixels,
int  pitch,
Uint32  color,
int  w,
int  h 
)
static

Definition at line 226 of file SDL_fillrect.c.

References SDL_memset4().

Referenced by SDL_FillRect().

227 {
228  while (h--) {
230  pixels += pitch;
231  }
232 }
GLfloat GLfloat GLfloat GLfloat h
SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
Definition: SDL_stdinc.h:420
GLubyte GLubyte GLubyte GLubyte w
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
GLuint color

◆ SDL_FillRects()

int SDL_FillRects ( SDL_Surface dst,
const SDL_Rect rects,
int  count,
Uint32  color 
)

Definition at line 371 of file SDL_fillrect.c.

References i, SDL_FillRect(), and SDL_SetError.

373 {
374  int i;
375  int status = 0;
376 
377  if (!rects) {
378  return SDL_SetError("SDL_FillRects() passed NULL rects");
379  }
380 
381  for (i = 0; i < count; ++i) {
382  status += SDL_FillRect(dst, &rects[i], color);
383  }
384  return status;
385 }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
int SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
Definition: SDL_fillrect.c:238
#define SDL_SetError
GLuint color