Commit c1295241 authored by Sam Lantinga's avatar Sam Lantinga

Making the API simpler, moved the surface drawing functions to the software renderer.

--HG--
rename : src/video/SDL_blendline.c => src/render/software/SDL_blendline.c
rename : src/video/SDL_blendpoint.c => src/render/software/SDL_blendpoint.c
rename : src/video/SDL_draw.h => src/render/software/SDL_draw.h
rename : src/video/SDL_drawline.c => src/render/software/SDL_drawline.c
rename : src/video/SDL_drawpoint.c => src/render/software/SDL_drawpoint.c
parent 348ea886
......@@ -363,85 +363,6 @@ extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
Uint32 dst_format,
void * dst, int dst_pitch);
/**
* Draws a point with \c color.
*
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_DrawPoint
(SDL_Surface * dst, int x, int y, Uint32 color);
extern DECLSPEC int SDLCALL SDL_DrawPoints
(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
/**
* Blends a point with an RGBA value.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendPoint
(SDL_Surface * dst, int x, int y,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern DECLSPEC int SDLCALL SDL_BlendPoints
(SDL_Surface * dst, const SDL_Point * points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Draws a line with \c color.
*
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_DrawLine
(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
extern DECLSPEC int SDLCALL SDL_DrawLines
(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
/**
* Blends an RGBA value along a line.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendLine
(SDL_Surface * dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern DECLSPEC int SDLCALL SDL_BlendLines
(SDL_Surface * dst, const SDL_Point * points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Draws the given rectangle with \c color.
*
* If \c rect is NULL, the whole surface will be outlined with \c color.
*
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_DrawRect
(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
extern DECLSPEC int SDLCALL SDL_DrawRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color);
/**
* Blends an RGBA value into the outline of the given rectangle.
*
* If \c rect is NULL, the whole surface will have a blended outline.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendRect
(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern DECLSPEC int SDLCALL SDL_BlendRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Performs a fast fill of the given rectangle with \c color.
*
......@@ -457,20 +378,6 @@ extern DECLSPEC int SDLCALL SDL_FillRect
extern DECLSPEC int SDLCALL SDL_FillRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color);
/**
* Blends an RGBA value into the given rectangle.
*
* If \c rect is NULL, the whole surface will be blended with the color.
*
* \return This function returns 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendFillRect
(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern DECLSPEC int SDLCALL SDL_BlendFillRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Performs a fast blit from the source surface to the destination surface.
*
......
......@@ -21,8 +21,9 @@
*/
#include "SDL_config.h"
#include "SDL_video.h"
#include "SDL_draw.h"
#include "SDL_blendfillrect.h"
static int
SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
......
......@@ -19,20 +19,10 @@
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* Functions to pre-multiply the alpha channel into the color channels */
#define DEFINE_PREMULTIPLY_FUNC(fmt) \
void \
SDL_PreMultiplyAlpha##fmt(int w, int h, Uint32 *pixels, int pitch);
/* *INDENT-OFF* */
DEFINE_PREMULTIPLY_FUNC(ARGB8888)
DEFINE_PREMULTIPLY_FUNC(RGBA8888)
DEFINE_PREMULTIPLY_FUNC(ABGR8888)
DEFINE_PREMULTIPLY_FUNC(BGRA8888)
/* *INDENT-ON* */
#undef DEFINE_PREMULTIPLY_FUNC
extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* vi: set ts=4 sw=4 expandtab: */
......@@ -22,6 +22,7 @@
#include "SDL_config.h"
#include "SDL_draw.h"
#include "SDL_blendline.h"
static void
......
......@@ -21,40 +21,8 @@
*/
#include "SDL_config.h"
#include "SDL_blit.h"
#include "SDL_alphamult.h"
/* Functions to pre-multiply the alpha channel into the color channels */
#define DEFINE_PREMULTIPLY_FUNC(fmt) \
void \
SDL_PreMultiplyAlpha##fmt(int w, int h, Uint32 *pixels, int pitch) \
{ \
pitch /= 4; \
while (h--) { \
int n; \
Uint32 *row = pixels; \
Uint32 pixel; \
unsigned r, g, b, a; \
\
for (n = w; n--; ) { \
pixel = *row; \
RGBA_FROM_##fmt(pixel, r, g, b, a); \
r = (r * a) / 255; \
g = (g * a) / 255; \
b = (b * a) / 255; \
fmt##_FROM_RGBA(*row, r, g, b, a); \
++row; \
} \
pixels += pitch; \
} \
}
/* *INDENT-OFF* */
DEFINE_PREMULTIPLY_FUNC(ARGB8888)
DEFINE_PREMULTIPLY_FUNC(RGBA8888)
DEFINE_PREMULTIPLY_FUNC(ABGR8888)
DEFINE_PREMULTIPLY_FUNC(BGRA8888)
/* *INDENT-ON* */
extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* vi: set ts=4 sw=4 expandtab: */
......@@ -22,6 +22,8 @@
#include "SDL_config.h"
#include "SDL_draw.h"
#include "SDL_blendpoint.h"
static int
SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
......
......@@ -21,54 +21,8 @@
*/
#include "SDL_config.h"
#include "SDL_video.h"
int
SDL_DrawRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
{
SDL_Rect full_rect;
SDL_Point points[5];
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
/* If 'rect' == NULL, then outline the whole surface */
if (!rect) {
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = dst->w;
full_rect.h = dst->h;
rect = &full_rect;
}
points[0].x = rect->x;
points[0].y = rect->y;
points[1].x = rect->x+rect->w-1;
points[1].y = rect->y;
points[2].x = rect->x+rect->w-1;
points[2].y = rect->y+rect->h-1;
points[3].x = rect->x;
points[3].y = rect->y+rect->h-1;
points[4].x = rect->x;
points[4].y = rect->y;
return SDL_DrawLines(dst, points, 5, color);
}
int
SDL_DrawRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
Uint32 color)
{
int i;
for (i = 0; i < count; ++i) {
if (SDL_DrawRect(dst, rects[i], color) < 0) {
return -1;
}
}
return 0;
}
extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* vi: set ts=4 sw=4 expandtab: */
......@@ -21,7 +21,7 @@
*/
#include "SDL_config.h"
#include "SDL_blit.h"
#include "../../video/SDL_blit.h"
/* This code assumes that r, g, b, a are the source color,
* and in the blend and add case, the RGB values are premultiplied by a.
......
......@@ -22,6 +22,8 @@
#include "SDL_config.h"
#include "SDL_draw.h"
#include "SDL_drawline.h"
static void
SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
......
......@@ -21,55 +21,8 @@
*/
#include "SDL_config.h"
#include "SDL_video.h"
int
SDL_BlendRect(SDL_Surface * dst, const SDL_Rect * rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_Rect full_rect;
SDL_Point points[5];
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
/* If 'rect' == NULL, then outline the whole surface */
if (!rect) {
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = dst->w;
full_rect.h = dst->h;
rect = &full_rect;
}
points[0].x = rect->x;
points[0].y = rect->y;
points[1].x = rect->x+rect->w-1;
points[1].y = rect->y;
points[2].x = rect->x+rect->w-1;
points[2].y = rect->y+rect->h-1;
points[3].x = rect->x;
points[3].y = rect->y+rect->h-1;
points[4].x = rect->x;
points[4].y = rect->y;
return SDL_BlendLines(dst, points, 5, blendMode, r, g, b, a);
}
int
SDL_BlendRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
int i;
for (i = 0; i < count; ++i) {
if (SDL_BlendRect(dst, rects[i], blendMode, r, g, b, a) < 0) {
return -1;
}
}
return 0;
}
extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
/* vi: set ts=4 sw=4 expandtab: */
......@@ -22,6 +22,7 @@
#include "SDL_config.h"
#include "SDL_draw.h"
#include "SDL_drawpoint.h"
int
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color);
extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
/* vi: set ts=4 sw=4 expandtab: */
......@@ -24,6 +24,13 @@
#include "../SDL_sysrender.h"
#include "../../video/SDL_pixels_c.h"
#include "SDL_draw.h"
#include "SDL_blendfillrect.h"
#include "SDL_blendline.h"
#include "SDL_blendpoint.h"
#include "SDL_drawline.h"
#include "SDL_drawpoint.h"
/* SDL surface based renderer implementation */
......
......@@ -47,7 +47,7 @@
#include "SDL_cpuinfo.h"
#include "SDL_endian.h"
#include "SDL_video.h"
#include "SDL_surface.h"
/* SDL blit copy flags */
#define SDL_COPY_MODULATE_COLOR 0x00000001
......
......@@ -26,8 +26,6 @@
*/
/* Testcases. */
static void surface_testLoad( SDL_Surface *testsur );
static void surface_testPrimitives( SDL_Surface *testsur );
static void surface_testPrimitivesBlend( SDL_Surface *testsur );
static void surface_testBlit( SDL_Surface *testsur );
static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode );
static void surface_testBlitBlend( SDL_Surface *testsur );
......@@ -84,167 +82,6 @@ static void surface_testLoad( SDL_Surface *testsur )
}
/**
* @brief Tests the SDL primitives for rendering.
*/
static void surface_testPrimitives( SDL_Surface *testsur )
{
int ret;
int x, y;
SDL_Rect rect;
SDL_ATbegin( "Primitives Test" );
/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) );
if (SDL_ATassert( "SDL_FillRect", ret == 0))
return;
/* Draw a rectangle. */
rect.x = 40;
rect.y = 0;
rect.w = 40;
rect.h = 80;
ret = SDL_FillRect( testsur, &rect,
SDL_MapRGB( testsur->format, 13, 73, 200 ) );
if (SDL_ATassert( "SDL_FillRect", ret == 0))
return;
/* Draw a rectangle. */
rect.x = 10;
rect.y = 10;
rect.w = 60;
rect.h = 40;
ret = SDL_FillRect( testsur, &rect,
SDL_MapRGB( testsur->format, 200, 0, 100 ) );
if (SDL_ATassert( "SDL_FillRect", ret == 0))
return;
/* Draw some points like so:
* X.X.X.X..
* .X.X.X.X.
* X.X.X.X.. */
for (y=0; y<3; y++) {
x = y % 2;
for (; x<80; x+=2) {
ret = SDL_DrawPoint( testsur, x, y,
SDL_MapRGB( testsur->format, x*y, x*y/2, x*y/3 ) );
if (SDL_ATassert( "SDL_DrawPoint", ret == 0))
return;
}
}
/* Draw some lines. */
ret = SDL_DrawLine( testsur, 0, 30, 80, 30,
SDL_MapRGB( testsur->format, 0, 255, 0 ) );
if (SDL_ATassert( "SDL_DrawLine", ret == 0))
return;
ret = SDL_DrawLine( testsur, 40, 30, 40, 60,
SDL_MapRGB( testsur->format, 55, 55, 5 ) );
if (SDL_ATassert( "SDL_DrawLine", ret == 0))
return;
ret = SDL_DrawLine( testsur, 0, 0, 29, 29,
SDL_MapRGB( testsur->format, 5, 105, 105 ) );
if (SDL_ATassert( "SDL_DrawLine", ret == 0))
return;
ret = SDL_DrawLine( testsur, 29, 30, 0, 59,
SDL_MapRGB( testsur->format, 5, 105, 105 ) );
if (SDL_ATassert( "SDL_DrawLine", ret == 0))
return;
ret = SDL_DrawLine( testsur, 79, 0, 50, 29,
SDL_MapRGB( testsur->format, 5, 105, 105 ) );
if (SDL_ATassert( "SDL_DrawLine", ret == 0))
return;
ret = SDL_DrawLine( testsur, 79, 59, 50, 30,
SDL_MapRGB( testsur->format, 5, 105, 105 ) );
if (SDL_ATassert( "SDL_DrawLine", ret == 0))
return;
/* See if it's the same. */
if (SDL_ATassert( "Primitives output not the same.",
surface_compare( testsur, &img_primitives, 0 )==0 ))
return;
SDL_ATend();
}
/**
* @brief Tests the SDL primitives with alpha for rendering.
*/
static void surface_testPrimitivesBlend( SDL_Surface *testsur )
{
int ret;
int i, j;
SDL_Rect rect;
SDL_ATbegin( "Primitives Blend Test" );
/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) );
if (SDL_ATassert( "SDL_FillRect", ret == 0))
return;
/* Create some rectangles for each blend mode. */
ret = SDL_BlendFillRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 );
if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
return;
rect.x = 10;
rect.y = 25;
rect.w = 40;
rect.h = 25;
ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 );
if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
return;
rect.x = 30;
rect.y = 40;
rect.w = 45;
rect.h = 15;
ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 );
if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
return;
/* Draw blended lines, lines for everyone. */
for (i=0; i<testsur->w; i+=2) {
ret = SDL_BlendLine( testsur, 0, 0, i, 59,
(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE,
60+2*i, 240-2*i, 50, 3*i );
if (SDL_ATassert( "SDL_BlendLine", ret == 0))
return;
}
for (i=0; i<testsur->h; i+=2) {
ret = SDL_BlendLine( testsur, 0, 0, 79, i,
(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE,
60+2*i, 240-2*i, 50, 3*i );
if (SDL_ATassert( "SDL_BlendLine", ret == 0))
return;
}
/* Draw points. */
for (j=0; j<testsur->h; j+=3) {
for (i=0; i<testsur->w; i+=3) {
ret = SDL_BlendPoint( testsur, i, j,
((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE,
j*4, i*3, j*4, i*3 );
if (SDL_ATassert( "SDL_BlendPoint", ret == 0))
return;
}
}
/* See if it's the same. */
if (SDL_ATassert( "Primitives output not the same.",
surface_compare( testsur, &img_blend, 0 )==0 ))
return;
SDL_ATend();
}
/**
* @brief Tests some blitting routines.
*/
......@@ -546,8 +383,6 @@ static void surface_testBlitBlend( SDL_Surface *testsur )
void surface_runTests( SDL_Surface *testsur )
{
/* Software surface blitting. */
surface_testPrimitives( testsur );
surface_testPrimitivesBlend( testsur );
surface_testBlit( testsur );
surface_testBlitBlend( testsur );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment