Mercurial > sdl-ios-xcode
comparison src/video/SDL_fillrect.c @ 3536:0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
SDL_DrawPoints()
SDL_BlendPoints()
SDL_BlendLines()
SDL_DrawLines()
SDL_FillRects()
SDL_BlendRects()
SDL_RenderPoints()
SDL_RenderLines()
SDL_RenderRects()
Renamed SDL_RenderFill() to SDL_RenderRect()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 09 Dec 2009 15:56:56 +0000 |
parents | 7e30c2dc7783 |
children | f7b03b6838cb |
comparison
equal
deleted
inserted
replaced
3535:b403f790df65 | 3536:0267b8b1595c |
---|---|
308 | 308 |
309 /* | 309 /* |
310 * This function performs a fast fill of the given rectangle with 'color' | 310 * This function performs a fast fill of the given rectangle with 'color' |
311 */ | 311 */ |
312 int | 312 int |
313 SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) | 313 SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color) |
314 { | 314 { |
315 SDL_Rect clipped; | |
315 Uint8 *pixels; | 316 Uint8 *pixels; |
317 | |
318 if (!dst) { | |
319 SDL_SetError("Passed NULL destination surface"); | |
320 return -1; | |
321 } | |
316 | 322 |
317 /* This function doesn't work on surfaces < 8 bpp */ | 323 /* This function doesn't work on surfaces < 8 bpp */ |
318 if (dst->format->BitsPerPixel < 8) { | 324 if (dst->format->BitsPerPixel < 8) { |
319 SDL_SetError("SDL_FillRect(): Unsupported surface format"); | 325 SDL_SetError("SDL_FillRect(): Unsupported surface format"); |
320 return (-1); | 326 return -1; |
321 } | 327 } |
322 | 328 |
323 /* If 'dstrect' == NULL, then fill the whole surface */ | 329 /* If 'rect' == NULL, then fill the whole surface */ |
324 if (dstrect) { | 330 if (rect) { |
325 /* Perform clipping */ | 331 /* Perform clipping */ |
326 if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) { | 332 if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { |
327 return (0); | 333 return 0; |
328 } | 334 } |
335 rect = &clipped; | |
329 } else { | 336 } else { |
330 dstrect = &dst->clip_rect; | 337 rect = &dst->clip_rect; |
331 } | 338 } |
332 | 339 |
333 /* Perform software fill */ | 340 /* Perform software fill */ |
334 if (!dst->pixels) { | 341 if (!dst->pixels) { |
335 SDL_SetError("SDL_FillRect(): You must lock the surface"); | 342 SDL_SetError("SDL_FillRect(): You must lock the surface"); |
336 return (-1); | 343 return (-1); |
337 } | 344 } |
338 | 345 |
339 pixels = | 346 pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch + |
340 (Uint8 *) dst->pixels + dstrect->y * dst->pitch + | 347 rect->x * dst->format->BytesPerPixel; |
341 dstrect->x * dst->format->BytesPerPixel; | |
342 | 348 |
343 switch (dst->format->BytesPerPixel) { | 349 switch (dst->format->BytesPerPixel) { |
344 case 1: | 350 case 1: |
345 { | 351 { |
346 color |= (color << 8); | 352 color |= (color << 8); |
347 color |= (color << 16); | 353 color |= (color << 16); |
348 #ifdef __SSE__ | 354 #ifdef __SSE__ |
349 if (SDL_HasSSE()) { | 355 if (SDL_HasSSE()) { |
350 SDL_FillRect1SSE(pixels, dst->pitch, color, dstrect->w, | 356 SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h); |
351 dstrect->h); | |
352 break; | 357 break; |
353 } | 358 } |
354 #endif | 359 #endif |
355 #ifdef __MMX__ | 360 #ifdef __MMX__ |
356 if (SDL_HasMMX()) { | 361 if (SDL_HasMMX()) { |
357 SDL_FillRect1MMX(pixels, dst->pitch, color, dstrect->w, | 362 SDL_FillRect1MMX(pixels, dst->pitch, color, rect->w, rect->h); |
358 dstrect->h); | 363 break; |
359 break; | 364 } |
360 } | 365 #endif |
361 #endif | 366 SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h); |
362 SDL_FillRect1(pixels, dst->pitch, color, dstrect->w, dstrect->h); | |
363 break; | 367 break; |
364 } | 368 } |
365 | 369 |
366 case 2: | 370 case 2: |
367 { | 371 { |
368 color |= (color << 16); | 372 color |= (color << 16); |
369 #ifdef __SSE__ | 373 #ifdef __SSE__ |
370 if (SDL_HasSSE()) { | 374 if (SDL_HasSSE()) { |
371 SDL_FillRect2SSE(pixels, dst->pitch, color, dstrect->w, | 375 SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h); |
372 dstrect->h); | |
373 break; | 376 break; |
374 } | 377 } |
375 #endif | 378 #endif |
376 #ifdef __MMX__ | 379 #ifdef __MMX__ |
377 if (SDL_HasMMX()) { | 380 if (SDL_HasMMX()) { |
378 SDL_FillRect2MMX(pixels, dst->pitch, color, dstrect->w, | 381 SDL_FillRect2MMX(pixels, dst->pitch, color, rect->w, rect->h); |
379 dstrect->h); | 382 break; |
380 break; | 383 } |
381 } | 384 #endif |
382 #endif | 385 SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h); |
383 SDL_FillRect2(pixels, dst->pitch, color, dstrect->w, dstrect->h); | |
384 break; | 386 break; |
385 } | 387 } |
386 | 388 |
387 case 3: | 389 case 3: |
388 /* 24-bit RGB is a slow path, at least for now. */ | 390 /* 24-bit RGB is a slow path, at least for now. */ |
389 { | 391 { |
390 SDL_FillRect3(pixels, dst->pitch, color, dstrect->w, dstrect->h); | 392 SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h); |
391 break; | 393 break; |
392 } | 394 } |
393 | 395 |
394 case 4: | 396 case 4: |
395 { | 397 { |
396 #ifdef __SSE__ | 398 #ifdef __SSE__ |
397 if (SDL_HasSSE()) { | 399 if (SDL_HasSSE()) { |
398 SDL_FillRect4SSE(pixels, dst->pitch, color, dstrect->w, | 400 SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h); |
399 dstrect->h); | |
400 break; | 401 break; |
401 } | 402 } |
402 #endif | 403 #endif |
403 #ifdef __MMX__ | 404 #ifdef __MMX__ |
404 if (SDL_HasMMX()) { | 405 if (SDL_HasMMX()) { |
405 SDL_FillRect4MMX(pixels, dst->pitch, color, dstrect->w, | 406 SDL_FillRect4MMX(pixels, dst->pitch, color, rect->w, rect->h); |
406 dstrect->h); | 407 break; |
407 break; | 408 } |
408 } | 409 #endif |
409 #endif | 410 SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h); |
410 SDL_FillRect4(pixels, dst->pitch, color, dstrect->w, dstrect->h); | |
411 break; | 411 break; |
412 } | 412 } |
413 } | 413 } |
414 | 414 |
415 /* We're done! */ | 415 /* We're done! */ |
416 return (0); | 416 return 0; |
417 } | |
418 | |
419 int | |
420 SDL_FillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, | |
421 Uint32 color) | |
422 { | |
423 int i; | |
424 int status = 0; | |
425 | |
426 for (i = 0; i < count; ++i) { | |
427 status = SDL_FillRect(dst, rects[i], color); | |
428 } | |
429 return status; | |
417 } | 430 } |
418 | 431 |
419 /* vi: set ts=4 sw=4 expandtab: */ | 432 /* vi: set ts=4 sw=4 expandtab: */ |