23 #if !SDL_RENDER_DISABLED
25 #include "../SDL_sysrender.h"
110 if (!data->surface) {
111 data->surface = data->window;
113 if (!data->surface) {
116 data->surface = data->window =
surface;
122 return data->surface;
142 data = (SW_RenderData *)
SDL_calloc(1,
sizeof(*data));
172 renderer->
info = SW_RenderDriver.
info;
198 data->surface =
NULL;
217 SDL_SetError(
"Software renderer doesn't have an output surface");
226 Uint32 Rmask, Gmask, Bmask, Amask;
229 (texture->
format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
284 src = (
Uint8 *) pixels;
286 rect->
y * surface->
pitch +
308 *pitch = surface->
pitch;
325 data->surface = data->window;
374 renderer->
r, renderer->
g, renderer->
b, renderer->
a);
404 for (i = 0; i <
count; ++
i) {
405 final_points[
i].
x = (
int)(x + points[i].x);
406 final_points[
i].
y = (
int)(y + points[i].y);
409 for (i = 0; i <
count; ++
i) {
410 final_points[
i].
x = (
int)points[i].
x;
411 final_points[
i].
y = (
int)points[i].
y;
418 renderer->
r, renderer->
g, renderer->
b,
425 renderer->
r, renderer->
g, renderer->
b,
453 for (i = 0; i <
count; ++
i) {
454 final_points[
i].
x = (
int)(x + points[i].x);
455 final_points[
i].
y = (
int)(y + points[i].y);
458 for (i = 0; i <
count; ++
i) {
459 final_points[
i].
x = (
int)points[i].
x;
460 final_points[
i].
y = (
int)points[i].
y;
467 renderer->
r, renderer->
g, renderer->
b,
474 renderer->
r, renderer->
g, renderer->
b,
501 for (i = 0; i <
count; ++
i) {
502 final_rects[
i].
x = (
int)(x + rects[i].x);
503 final_rects[
i].
y = (
int)(y + rects[i].y);
504 final_rects[
i].
w =
SDL_max((
int)rects[i].
w, 1);
505 final_rects[
i].
h =
SDL_max((
int)rects[i].
h, 1);
508 for (i = 0; i <
count; ++
i) {
509 final_rects[
i].
x = (
int)rects[i].
x;
510 final_rects[
i].
y = (
int)rects[i].
y;
511 final_rects[
i].
w =
SDL_max((
int)rects[i].
w, 1);
512 final_rects[
i].
h =
SDL_max((
int)rects[i].
h, 1);
518 renderer->
r, renderer->
g, renderer->
b,
524 renderer->
r, renderer->
g, renderer->
b,
548 final_rect.x = (
int)dstrect->
x;
549 final_rect.y = (
int)dstrect->
y;
551 final_rect.w = (
int)dstrect->
w;
552 final_rect.h = (
int)dstrect->
h;
554 if ( srcrect->
w == final_rect.w && srcrect->
h == final_rect.h ) {
566 if (!hint || *hint ==
'0' ||
SDL_strcasecmp(hint,
"nearest") == 0) {
583 int retval, dstwidth, dstheight, abscenterx, abscentery;
584 double cangle, sangle, px, py, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y;
594 final_rect.
x = (
int)dstrect->
x;
595 final_rect.
y = (
int)dstrect->
y;
597 final_rect.
w = (
int)dstrect->
w;
598 final_rect.
h = (
int)dstrect->
h;
603 if (surface_scaled) {
606 tmp_rect = final_rect;
613 surface_rotated =
_rotateSurface(surface_scaled, -angle, dstwidth/2, dstheight/2,
GetScaleQuality(), flip &
SDL_FLIP_HORIZONTAL, flip &
SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle);
614 if(surface_rotated) {
616 abscenterx = final_rect.
x + (
int)center->
x;
617 abscentery = final_rect.
y + (
int)center->
y;
622 px = final_rect.
x - abscenterx;
623 py = final_rect.
y - abscentery;
624 p1x = px * cangle - py * sangle + abscenterx;
625 p1y = px * sangle + py * cangle + abscentery;
628 px = final_rect.
x + final_rect.
w - abscenterx;
629 py = final_rect.
y - abscentery;
630 p2x = px * cangle - py * sangle + abscenterx;
631 p2y = px * sangle + py * cangle + abscentery;
634 px = final_rect.
x - abscenterx;
635 py = final_rect.
y + final_rect.
h - abscentery;
636 p3x = px * cangle - py * sangle + abscenterx;
637 p3y = px * sangle + py * cangle + abscentery;
640 px = final_rect.
x + final_rect.
w - abscenterx;
641 py = final_rect.
y + final_rect.
h - abscentery;
642 p4x = px * cangle - py * sangle + abscenterx;
643 p4y = px * sangle + py * cangle + abscentery;
647 tmp_rect.w = dstwidth;
648 tmp_rect.h = dstheight;
678 final_rect.
w = rect->
w;
679 final_rect.
h = rect->
h;
683 if (rect->
x < 0 || rect->
x+rect->
w > surface->
w ||
684 rect->
y < 0 || rect->
y+rect->
h > surface->
h) {
685 return SDL_SetError(
"Tried to read outside of surface bounds");
690 rect->
y * surface->
pitch +
694 src_format, src_pixels, surface->
pitch,
695 format, pixels, pitch);
static int SW_SetTextureAlphaMod(SDL_Renderer *renderer, SDL_Texture *texture)
int(* UpdateClipRect)(SDL_Renderer *renderer)
DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface)
int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color)
DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b)
Set an additional color value used in blit operations.
static int SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
Set an additional alpha value used in blit operations.
GLfloat GLfloat GLfloat GLfloat h
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
static int SW_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
Copy a block of pixels of one format to another format.
static int SW_UpdateViewport(SDL_Renderer *renderer)
int(* RenderClear)(SDL_Renderer *renderer)
#define SDL_stack_free(data)
int(* RenderDrawPoints)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
Set the blend mode used for blit operations.
#define SDL_HINT_RENDER_SCALE_QUALITY
A variable controlling the scaling quality.
The structure that defines a point.
A collection of pixels used in software blitting.
static int SW_SetTextureColorMod(SDL_Renderer *renderer, SDL_Texture *texture)
DECLSPEC void SDLCALL SDL_free(void *mem)
DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface *surface, const SDL_Rect *rect)
static int SW_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
static int SW_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface *surface, Uint32 *key)
Gets the color key (transparent pixel) in a blittable surface.
static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
static int SW_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
DECLSPEC int SDLCALL SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Maps an RGBA quadruple to a pixel value for a given pixel format.
DECLSPEC SDL_Surface *SDLCALL SDL_GetWindowSurface(SDL_Window *window)
Get the SDL surface associated with the window.
SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface *surface)
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface *surface)
int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
static int SW_SetTextureBlendMode(SDL_Renderer *renderer, SDL_Texture *texture)
GLenum GLenum GLvoid * row
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
static void SW_RenderPresent(SDL_Renderer *renderer)
SDL_RenderDriver SW_RenderDriver
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
static void SW_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
static int GetScaleQuality(void)
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
static void SW_DestroyRenderer(SDL_Renderer *renderer)
SDL_Surface * _rotateSurface(SDL_Surface *src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
int(* SetTextureColorMod)(SDL_Renderer *renderer, SDL_Texture *texture)
int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
DECLSPEC const char *SDLCALL SDL_GetHint(const char *name)
Get a hint.
static int SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* RenderCopy)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
void _rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle)
static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
SDL_RendererFlip
Flip constants for SDL_RenderCopyEx.
Window state change event data (event.window.*)
int(* SetTextureBlendMode)(SDL_Renderer *renderer, SDL_Texture *texture)
DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key)
Sets the color key (transparent pixel) in a blittable surface.
EGLSurface EGLint EGLint y
#define SDL_OutOfMemory()
static int SW_RenderClear(SDL_Renderer *renderer)
GLenum GLenum GLuint texture
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color)
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window *window)
Copy the window surface to the screen.
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
uint8_t Uint8
An unsigned 8-bit integer type.
static void SW_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
Convert one of the enumerated pixel formats to a bpp and RGBA masks.
static void SW_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
GLint GLint GLint GLint GLint w
#define SDL_stack_alloc(type, count)
static SDL_Renderer * SW_CreateRenderer(SDL_Window *window, Uint32 flags)
static int SW_UpdateClipRect(SDL_Renderer *renderer)
int(* UpdateViewport)(SDL_Renderer *renderer)
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
int(* RenderCopyEx)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
void(* RenderPresent)(SDL_Renderer *renderer)
void(* DestroyRenderer)(SDL_Renderer *renderer)
int(* SetTextureAlphaMod)(SDL_Renderer *renderer, SDL_Texture *texture)
DECLSPEC int SDLCALL SDL_FillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface)
Sets up a surface for directly accessing the pixels.
DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2)
A rectangle, with the origin at the upper left.
DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, int flag)
Sets the RLE acceleration hint for a surface.