SDL  2.0
SDL_render_sw.c File Reference
#include "../../SDL_internal.h"
#include "../SDL_sysrender.h"
#include "SDL_render_sw_c.h"
#include "SDL_hints.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"
#include "SDL_rotate.h"
+ Include dependency graph for SDL_render_sw.c:

Go to the source code of this file.

Data Structures

struct  SW_RenderData
 

Functions

static SDL_RendererSW_CreateRenderer (SDL_Window *window, Uint32 flags)
 
static void SW_WindowEvent (SDL_Renderer *renderer, const SDL_WindowEvent *event)
 
static int SW_GetOutputSize (SDL_Renderer *renderer, int *w, int *h)
 
static int SW_CreateTexture (SDL_Renderer *renderer, SDL_Texture *texture)
 
static int SW_SetTextureColorMod (SDL_Renderer *renderer, SDL_Texture *texture)
 
static int SW_SetTextureAlphaMod (SDL_Renderer *renderer, SDL_Texture *texture)
 
static int SW_SetTextureBlendMode (SDL_Renderer *renderer, SDL_Texture *texture)
 
static int SW_UpdateTexture (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
 
static int SW_LockTexture (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
 
static void SW_UnlockTexture (SDL_Renderer *renderer, SDL_Texture *texture)
 
static int SW_SetRenderTarget (SDL_Renderer *renderer, SDL_Texture *texture)
 
static int SW_UpdateViewport (SDL_Renderer *renderer)
 
static int SW_UpdateClipRect (SDL_Renderer *renderer)
 
static int SW_RenderClear (SDL_Renderer *renderer)
 
static int SW_RenderDrawPoints (SDL_Renderer *renderer, const SDL_FPoint *points, int count)
 
static int SW_RenderDrawLines (SDL_Renderer *renderer, const SDL_FPoint *points, int count)
 
static int SW_RenderFillRects (SDL_Renderer *renderer, const SDL_FRect *rects, int count)
 
static int SW_RenderCopy (SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
 
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_RenderReadPixels (SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
 
static void SW_RenderPresent (SDL_Renderer *renderer)
 
static void SW_DestroyTexture (SDL_Renderer *renderer, SDL_Texture *texture)
 
static void SW_DestroyRenderer (SDL_Renderer *renderer)
 
static SDL_SurfaceSW_ActivateRenderer (SDL_Renderer *renderer)
 
SDL_RendererSW_CreateRendererForSurface (SDL_Surface *surface)
 
static int GetScaleQuality (void)
 

Variables

SDL_RenderDriver SW_RenderDriver
 

Function Documentation

§ GetScaleQuality()

static int GetScaleQuality ( void  )
static

Definition at line 583 of file SDL_render_sw.c.

References SDL_GetHint, SDL_HINT_RENDER_SCALE_QUALITY, and SDL_strcasecmp.

Referenced by SW_RenderCopyEx().

584 {
585  const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
586 
587  if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
588  return 0;
589  } else {
590  return 1;
591  }
592 }
#define SDL_HINT_RENDER_SCALE_QUALITY
A variable controlling the scaling quality.
Definition: SDL_hints.h:131
#define SDL_GetHint
#define SDL_strcasecmp

§ SW_ActivateRenderer()

static SDL_Surface* SW_ActivateRenderer ( SDL_Renderer renderer)
static

Definition at line 106 of file SDL_render_sw.c.

References SDL_Renderer::driverdata, SDL_GetWindowSurface, SW_RenderData::surface, SW_UpdateClipRect(), SW_UpdateViewport(), SW_RenderData::window, and SDL_Renderer::window.

Referenced by SW_CreateRendererForSurface(), SW_GetOutputSize(), SW_RenderClear(), SW_RenderCopy(), SW_RenderCopyEx(), SW_RenderDrawLines(), SW_RenderDrawPoints(), SW_RenderFillRects(), and SW_RenderReadPixels().

107 {
108  SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
109 
110  if (!data->surface) {
111  data->surface = data->window;
112  }
113  if (!data->surface) {
114  SDL_Surface *surface = SDL_GetWindowSurface(renderer->window);
115  if (surface) {
116  data->surface = data->window = surface;
117 
118  SW_UpdateViewport(renderer);
119  SW_UpdateClipRect(renderer);
120  }
121  }
122  return data->surface;
123 }
static int SW_UpdateViewport(SDL_Renderer *renderer)
void * driverdata
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_Window * window
SDL_Surface * surface
#define SDL_GetWindowSurface
SDL_Surface * window
static int SW_UpdateClipRect(SDL_Renderer *renderer)

§ SW_CreateRenderer()

SDL_Renderer * SW_CreateRenderer ( SDL_Window window,
Uint32  flags 
)
static

Definition at line 182 of file SDL_render_sw.c.

References NULL, SDL_GetWindowSurface, and SW_CreateRendererForSurface().

183 {
184  SDL_Surface *surface;
185 
186  surface = SDL_GetWindowSurface(window);
187  if (!surface) {
188  return NULL;
189  }
190  return SW_CreateRendererForSurface(surface);
191 }
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface *surface)
#define SDL_GetWindowSurface
#define NULL
Definition: begin_code.h:143

§ SW_CreateRendererForSurface()

SDL_Renderer* SW_CreateRendererForSurface ( SDL_Surface surface)

Definition at line 126 of file SDL_render_sw.c.

References SDL_Renderer::CreateTexture, SDL_Renderer::DestroyRenderer, SDL_Renderer::DestroyTexture, SDL_Renderer::driverdata, SDL_Renderer::GetOutputSize, SDL_Renderer::info, SDL_RenderDriver::info, SDL_Renderer::LockTexture, NULL, SDL_Renderer::RenderClear, SDL_Renderer::RenderCopy, SDL_Renderer::RenderCopyEx, SDL_Renderer::RenderDrawLines, SDL_Renderer::RenderDrawPoints, renderer, SDL_Renderer::RenderFillRects, SDL_Renderer::RenderPresent, SDL_Renderer::RenderReadPixels, SDL_calloc(), SDL_OutOfMemory, SDL_SetError, SDL_Renderer::SetRenderTarget, SDL_Renderer::SetTextureAlphaMod, SDL_Renderer::SetTextureBlendMode, SDL_Renderer::SetTextureColorMod, SW_RenderData::surface, SW_ActivateRenderer(), SW_CreateTexture(), SW_DestroyRenderer(), SW_DestroyTexture(), SW_GetOutputSize(), SW_LockTexture(), SW_RenderClear(), SW_RenderCopy(), SW_RenderCopyEx(), SW_RenderDrawLines(), SW_RenderDrawPoints(), SW_RenderFillRects(), SW_RenderPresent(), SW_RenderReadPixels(), SW_SetRenderTarget(), SW_SetTextureAlphaMod(), SW_SetTextureBlendMode(), SW_SetTextureColorMod(), SW_UnlockTexture(), SW_UpdateClipRect(), SW_UpdateTexture(), SW_UpdateViewport(), SW_WindowEvent(), SDL_Renderer::UnlockTexture, SDL_Renderer::UpdateClipRect, SDL_Renderer::UpdateTexture, SDL_Renderer::UpdateViewport, SW_RenderData::window, and SDL_Renderer::WindowEvent.

Referenced by SDL_CreateSoftwareRenderer(), and SW_CreateRenderer().

127 {
130 
131  if (!surface) {
132  SDL_SetError("Can't create renderer for NULL surface");
133  return NULL;
134  }
135 
136  renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
137  if (!renderer) {
138  SDL_OutOfMemory();
139  return NULL;
140  }
141 
142  data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
143  if (!data) {
144  SW_DestroyRenderer(renderer);
145  SDL_OutOfMemory();
146  return NULL;
147  }
148  data->surface = surface;
149  data->window = surface;
150 
151  renderer->WindowEvent = SW_WindowEvent;
152  renderer->GetOutputSize = SW_GetOutputSize;
153  renderer->CreateTexture = SW_CreateTexture;
157  renderer->UpdateTexture = SW_UpdateTexture;
158  renderer->LockTexture = SW_LockTexture;
159  renderer->UnlockTexture = SW_UnlockTexture;
161  renderer->UpdateViewport = SW_UpdateViewport;
162  renderer->UpdateClipRect = SW_UpdateClipRect;
163  renderer->RenderClear = SW_RenderClear;
167  renderer->RenderCopy = SW_RenderCopy;
168  renderer->RenderCopyEx = SW_RenderCopyEx;
170  renderer->RenderPresent = SW_RenderPresent;
171  renderer->DestroyTexture = SW_DestroyTexture;
173  renderer->info = SW_RenderDriver.info;
174  renderer->driverdata = data;
175 
176  SW_ActivateRenderer(renderer);
177 
178  return renderer;
179 }
static int SW_SetTextureAlphaMod(SDL_Renderer *renderer, SDL_Texture *texture)
int(* RenderDrawLines)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
int(* RenderDrawPoints)(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
int(* LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch)
Definition: SDL_sysrender.h:97
static int SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
int(* RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect, Uint32 format, void *pixels, int pitch)
static int SW_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
SDL_RendererInfo info
static int SW_UpdateViewport(SDL_Renderer *renderer)
void * driverdata
static int SW_SetTextureColorMod(SDL_Renderer *renderer, SDL_Texture *texture)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
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)
int(* RenderFillRects)(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
static int SW_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
SDL_RendererInfo info
int(* RenderClear)(SDL_Renderer *renderer)
void(* DestroyRenderer)(SDL_Renderer *renderer)
int(* GetOutputSize)(SDL_Renderer *renderer, int *w, int *h)
Definition: SDL_sysrender.h:81
int(* SetTextureBlendMode)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:87
int(* UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
Definition: SDL_sysrender.h:89
static int SW_SetTextureBlendMode(SDL_Renderer *renderer, SDL_Texture *texture)
int(* SetTextureColorMod)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:83
SDL_RenderDriver SW_RenderDriver
Definition: SDL_render_sw.c:78
void * SDL_calloc(size_t nmemb, size_t size)
SDL_Surface * surface
static void SW_RenderPresent(SDL_Renderer *renderer)
static void SW_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
static SDL_Renderer * renderer
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)
void(* UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:99
int(* SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* UpdateViewport)(SDL_Renderer *renderer)
static int SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)
int(* RenderCopy)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
#define NULL
Definition: begin_code.h:143
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
static int SW_RenderClear(SDL_Renderer *renderer)
#define SDL_SetError
SDL_Surface * window
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)
int(* SetTextureAlphaMod)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:85
static void SW_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
static void SW_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
void(* WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event)
Definition: SDL_sysrender.h:80
static int SW_UpdateClipRect(SDL_Renderer *renderer)
void(* DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
int(* CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture)
Definition: SDL_sysrender.h:82
void(* RenderPresent)(SDL_Renderer *renderer)
int(* UpdateClipRect)(SDL_Renderer *renderer)

§ SW_CreateTexture()

static int SW_CreateTexture ( SDL_Renderer renderer,
SDL_Texture texture 
)
static

Definition at line 224 of file SDL_render_sw.c.

References SDL_Texture::a, SDL_Texture::access, SDL_Texture::b, SDL_Texture::blendMode, SDL_Texture::driverdata, SDL_Texture::format, SDL_Texture::g, SDL_Texture::h, SDL_Texture::r, SDL_CreateRGBSurface, SDL_PixelFormatEnumToMasks, SDL_SetError, SDL_SetSurfaceAlphaMod, SDL_SetSurfaceBlendMode, SDL_SetSurfaceColorMod, SDL_SetSurfaceRLE, SDL_TEXTUREACCESS_STATIC, and SDL_Texture::w.

Referenced by SW_CreateRendererForSurface().

225 {
226  int bpp;
227  Uint32 Rmask, Gmask, Bmask, Amask;
228 
230  (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
231  return SDL_SetError("Unknown texture format");
232  }
233 
234  texture->driverdata =
235  SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
236  Bmask, Amask);
237  SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
238  texture->b);
239  SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
240  SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
241 
242  if (texture->access == SDL_TEXTUREACCESS_STATIC) {
243  SDL_SetSurfaceRLE(texture->driverdata, 1);
244  }
245 
246  if (!texture->driverdata) {
247  return -1;
248  }
249  return 0;
250 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:57
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
#define SDL_SetSurfaceColorMod
#define SDL_PixelFormatEnumToMasks
#define SDL_SetSurfaceRLE
#define SDL_SetError
#define SDL_CreateRGBSurface
#define SDL_SetSurfaceBlendMode
Uint32 format
Definition: SDL_sysrender.h:52
void * driverdata
Definition: SDL_sysrender.h:69
#define SDL_SetSurfaceAlphaMod

§ SW_DestroyRenderer()

static void SW_DestroyRenderer ( SDL_Renderer renderer)
static

Definition at line 784 of file SDL_render_sw.c.

References SDL_Renderer::driverdata, and SDL_free().

Referenced by SW_CreateRendererForSurface().

785 {
786  SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
787 
788  SDL_free(data);
789  SDL_free(renderer);
790 }
void * driverdata
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
void SDL_free(void *mem)

§ SW_DestroyTexture()

static void SW_DestroyTexture ( SDL_Renderer renderer,
SDL_Texture texture 
)
static

Definition at line 776 of file SDL_render_sw.c.

References SDL_Texture::driverdata, and SDL_FreeSurface.

Referenced by SW_CreateRendererForSurface().

777 {
778  SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
779 
780  SDL_FreeSurface(surface);
781 }
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
#define SDL_FreeSurface
void * driverdata
Definition: SDL_sysrender.h:69

§ SW_GetOutputSize()

static int SW_GetOutputSize ( SDL_Renderer renderer,
int *  w,
int *  h 
)
static

Definition at line 205 of file SDL_render_sw.c.

References SDL_Surface::h, SDL_SetError, SW_ActivateRenderer(), and SDL_Surface::w.

Referenced by SW_CreateRendererForSurface().

206 {
207  SDL_Surface *surface = SW_ActivateRenderer(renderer);
208 
209  if (surface) {
210  if (w) {
211  *w = surface->w;
212  }
213  if (h) {
214  *h = surface->h;
215  }
216  return 0;
217  } else {
218  SDL_SetError("Software renderer doesn't have an output surface");
219  return -1;
220  }
221 }
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
#define SDL_SetError
GLubyte GLubyte GLubyte GLubyte w
GLfloat GLfloat GLfloat GLfloat h

§ SW_LockTexture()

static int SW_LockTexture ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect rect,
void **  pixels,
int *  pitch 
)
static

Definition at line 319 of file SDL_render_sw.c.

References SDL_PixelFormat::BytesPerPixel, SDL_Texture::driverdata, SDL_Surface::format, SDL_Surface::pitch, SDL_Surface::pixels, SDL_Rect::x, and SDL_Rect::y.

Referenced by SW_CreateRendererForSurface().

321 {
322  SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
323 
324  *pixels =
325  (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch +
326  rect->x * surface->format->BytesPerPixel);
327  *pitch = surface->pitch;
328  return 0;
329 }
Uint8 BytesPerPixel
Definition: SDL_pixels.h:318
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
int x
Definition: SDL_rect.h:66
SDL_PixelFormat * format
Definition: SDL_surface.h:72
void * driverdata
Definition: SDL_sysrender.h:69
int y
Definition: SDL_rect.h:66

§ SW_RenderClear()

static int SW_RenderClear ( SDL_Renderer renderer)
static

Definition at line 380 of file SDL_render_sw.c.

References SDL_Renderer::a, SDL_Renderer::b, SDL_Surface::clip_rect, SDL_Surface::format, SDL_Renderer::g, NULL, SDL_Renderer::r, SDL_FillRect, SDL_MapRGBA, SDL_SetClipRect, and SW_ActivateRenderer().

Referenced by SW_CreateRendererForSurface().

381 {
382  SDL_Surface *surface = SW_ActivateRenderer(renderer);
383  Uint32 color;
384  SDL_Rect clip_rect;
385 
386  if (!surface) {
387  return -1;
388  }
389 
390  color = SDL_MapRGBA(surface->format,
391  renderer->r, renderer->g, renderer->b, renderer->a);
392 
393  /* By definition the clear ignores the clip rect */
394  clip_rect = surface->clip_rect;
395  SDL_SetClipRect(surface, NULL);
396  SDL_FillRect(surface, NULL, color);
397  SDL_SetClipRect(surface, &clip_rect);
398  return 0;
399 }
#define SDL_SetClipRect
#define SDL_MapRGBA
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
SDL_Rect clip_rect
Definition: SDL_surface.h:85
#define NULL
Definition: begin_code.h:143
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_FillRect
GLuint color
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ SW_RenderCopy()

static int SW_RenderCopy ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect srcrect,
const SDL_FRect dstrect 
)
static

Definition at line 550 of file SDL_render_sw.c.

References SDL_Texture::driverdata, SDL_FRect::h, SDL_Rect::h, SDL_BlitScaled, SDL_BlitSurface, SDL_SetSurfaceRLE, SW_ActivateRenderer(), SDL_Renderer::viewport, SDL_FRect::w, SDL_Rect::w, SDL_FRect::x, SDL_Rect::x, SDL_FRect::y, and SDL_Rect::y.

Referenced by SW_CreateRendererForSurface().

552 {
553  SDL_Surface *surface = SW_ActivateRenderer(renderer);
554  SDL_Surface *src = (SDL_Surface *) texture->driverdata;
555  SDL_Rect final_rect;
556 
557  if (!surface) {
558  return -1;
559  }
560 
561  if (renderer->viewport.x || renderer->viewport.y) {
562  final_rect.x = (int)(renderer->viewport.x + dstrect->x);
563  final_rect.y = (int)(renderer->viewport.y + dstrect->y);
564  } else {
565  final_rect.x = (int)dstrect->x;
566  final_rect.y = (int)dstrect->y;
567  }
568  final_rect.w = (int)dstrect->w;
569  final_rect.h = (int)dstrect->h;
570 
571  if ( srcrect->w == final_rect.w && srcrect->h == final_rect.h ) {
572  return SDL_BlitSurface(src, srcrect, surface, &final_rect);
573  } else {
574  /* If scaling is ever done, permanently disable RLE (which doesn't support scaling)
575  * to avoid potentially frequent RLE encoding/decoding.
576  */
577  SDL_SetSurfaceRLE(surface, 0);
578  return SDL_BlitScaled(src, srcrect, surface, &final_rect);
579  }
580 }
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
#define SDL_BlitSurface
Definition: SDL_surface.h:457
#define SDL_BlitScaled
Definition: SDL_surface.h:486
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define SDL_SetSurfaceRLE
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
void * driverdata
Definition: SDL_sysrender.h:69
GLenum src
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ SW_RenderCopyEx()

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

Definition at line 595 of file SDL_render_sw.c.

References SDL_PixelFormat::Amask, SDL_PixelFormat::BitsPerPixel, blendMode, SDL_PixelFormat::Bmask, SDL_Texture::driverdata, SDL_Surface::flags, SDL_Surface::format, GetScaleQuality(), SDL_PixelFormat::Gmask, SDL_FRect::h, SDL_Rect::h, MIN, NULL, retval, SDL_PixelFormat::Rmask, SDL_BLENDMODE_NONE, SDL_BlitScaled, SDL_BlitSurface, SDL_ConvertSurface, SDL_CreateRGBSurface, SDL_FALSE, SDL_FLIP_HORIZONTAL, SDL_FLIP_VERTICAL, SDL_FreeSurface, SDL_GetColorKey, SDL_GetSurfaceAlphaMod, SDL_GetSurfaceBlendMode, SDL_GetSurfaceColorMod, SDL_SetColorKey, SDL_SetSurfaceAlphaMod, SDL_SetSurfaceBlendMode, SDL_SetSurfaceColorMod, SDL_SetSurfaceRLE, SDL_SWSURFACE, SDL_TRUE, SDLgfx_rotateSurface(), SDLgfx_rotozoomSurfaceSizeTrig(), SW_ActivateRenderer(), SDL_Renderer::viewport, SDL_FRect::w, SDL_Rect::w, SDL_FPoint::x, SDL_FRect::x, SDL_Rect::x, SDL_FPoint::y, SDL_FRect::y, and SDL_Rect::y.

Referenced by SW_CreateRendererForSurface().

598 {
599  SDL_Surface *surface = SW_ActivateRenderer(renderer);
600  SDL_Surface *src = (SDL_Surface *) texture->driverdata;
601  SDL_Rect final_rect, tmp_rect;
602  SDL_Surface *surface_rotated, *surface_scaled;
603  int retval, dstwidth, dstheight, abscenterx, abscentery;
604  double cangle, sangle, px, py, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y;
605 
606  if (!surface) {
607  return -1;
608  }
609 
610  if (renderer->viewport.x || renderer->viewport.y) {
611  final_rect.x = (int)(renderer->viewport.x + dstrect->x);
612  final_rect.y = (int)(renderer->viewport.y + dstrect->y);
613  } else {
614  final_rect.x = (int)dstrect->x;
615  final_rect.y = (int)dstrect->y;
616  }
617  final_rect.w = (int)dstrect->w;
618  final_rect.h = (int)dstrect->h;
619 
620  /* SDLgfx_rotateSurface doesn't accept a source rectangle, so crop and scale if we need to */
621  tmp_rect = final_rect;
622  tmp_rect.x = 0;
623  tmp_rect.y = 0;
624  if (srcrect->w == final_rect.w && srcrect->h == final_rect.h && srcrect->x == 0 && srcrect->y == 0) {
625  surface_scaled = src; /* but if we don't need to, just use the original */
626  retval = 0;
627  } else {
628  SDL_Surface *blit_src = src;
629  Uint32 colorkey;
631  Uint8 alphaMod, r, g, b;
632  SDL_bool cloneSource = SDL_FALSE;
633 
634  surface_scaled = SDL_CreateRGBSurface(SDL_SWSURFACE, final_rect.w, final_rect.h, src->format->BitsPerPixel,
635  src->format->Rmask, src->format->Gmask,
636  src->format->Bmask, src->format->Amask );
637  if (!surface_scaled) {
638  return -1;
639  }
640 
641  /* copy the color key, alpha mod, blend mode, and color mod so the scaled surface behaves like the source */
642  if (SDL_GetColorKey(src, &colorkey) == 0) {
643  SDL_SetColorKey(surface_scaled, SDL_TRUE, colorkey);
644  cloneSource = SDL_TRUE;
645  }
646  SDL_GetSurfaceAlphaMod(src, &alphaMod); /* these will be copied to surface_scaled below if necessary */
647  SDL_GetSurfaceBlendMode(src, &blendMode);
648  SDL_GetSurfaceColorMod(src, &r, &g, &b);
649 
650  /* now we need to blit the src into surface_scaled. since we want to copy the colors from the source to
651  * surface_scaled rather than blend them, etc. we'll need to disable the blend mode, alpha mod, etc.
652  * but we don't want to modify src (in case it's being used on other threads), so we'll need to clone it
653  * before changing the blend options
654  */
655  cloneSource |= blendMode != SDL_BLENDMODE_NONE || (alphaMod & r & g & b) != 255;
656  if (cloneSource) {
657  blit_src = SDL_ConvertSurface(src, src->format, src->flags); /* clone src */
658  if (!blit_src) {
659  SDL_FreeSurface(surface_scaled);
660  return -1;
661  }
662  SDL_SetSurfaceAlphaMod(blit_src, 255); /* disable all blending options in blit_src */
664  SDL_SetColorKey(blit_src, 0, 0);
665  SDL_SetSurfaceColorMod(blit_src, 255, 255, 255);
666  SDL_SetSurfaceRLE(blit_src, 0); /* don't RLE encode a surface we'll only use once */
667 
668  SDL_SetSurfaceAlphaMod(surface_scaled, alphaMod); /* copy blending options to surface_scaled */
669  SDL_SetSurfaceBlendMode(surface_scaled, blendMode);
670  SDL_SetSurfaceColorMod(surface_scaled, r, g, b);
671  }
672 
673  retval = SDL_BlitScaled(blit_src, srcrect, surface_scaled, &tmp_rect);
674  if (blit_src != src) {
675  SDL_FreeSurface(blit_src);
676  }
677  }
678 
679  if (!retval) {
680  SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, &dstwidth, &dstheight, &cangle, &sangle);
681  surface_rotated = SDLgfx_rotateSurface(surface_scaled, angle, dstwidth/2, dstheight/2, GetScaleQuality(), flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle);
682  if(surface_rotated) {
683  /* Find out where the new origin is by rotating the four final_rect points around the center and then taking the extremes */
684  abscenterx = final_rect.x + (int)center->x;
685  abscentery = final_rect.y + (int)center->y;
686  /* Compensate the angle inversion to match the behaviour of the other backends */
687  sangle = -sangle;
688 
689  /* Top Left */
690  px = final_rect.x - abscenterx;
691  py = final_rect.y - abscentery;
692  p1x = px * cangle - py * sangle + abscenterx;
693  p1y = px * sangle + py * cangle + abscentery;
694 
695  /* Top Right */
696  px = final_rect.x + final_rect.w - abscenterx;
697  py = final_rect.y - abscentery;
698  p2x = px * cangle - py * sangle + abscenterx;
699  p2y = px * sangle + py * cangle + abscentery;
700 
701  /* Bottom Left */
702  px = final_rect.x - abscenterx;
703  py = final_rect.y + final_rect.h - abscentery;
704  p3x = px * cangle - py * sangle + abscenterx;
705  p3y = px * sangle + py * cangle + abscentery;
706 
707  /* Bottom Right */
708  px = final_rect.x + final_rect.w - abscenterx;
709  py = final_rect.y + final_rect.h - abscentery;
710  p4x = px * cangle - py * sangle + abscenterx;
711  p4y = px * sangle + py * cangle + abscentery;
712 
713  tmp_rect.x = (int)MIN(MIN(p1x, p2x), MIN(p3x, p4x));
714  tmp_rect.y = (int)MIN(MIN(p1y, p2y), MIN(p3y, p4y));
715  tmp_rect.w = dstwidth;
716  tmp_rect.h = dstheight;
717 
718  retval = SDL_BlitSurface(surface_rotated, NULL, surface, &tmp_rect);
719  SDL_FreeSurface(surface_rotated);
720  }
721  }
722 
723  if (surface_scaled != src) {
724  SDL_FreeSurface(surface_scaled);
725  }
726  return retval;
727 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
#define SDL_SWSURFACE
Definition: SDL_surface.h:52
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
#define SDL_ConvertSurface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
#define SDL_BlitSurface
Definition: SDL_surface.h:457
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
Uint32 flags
Definition: SDL_surface.h:71
#define SDL_BlitScaled
Definition: SDL_surface.h:486
#define SDL_GetSurfaceBlendMode
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
GLboolean GLboolean g
SDL_bool retval
#define SDL_GetColorKey
static int GetScaleQuality(void)
#define SDL_FreeSurface
#define SDL_SetSurfaceColorMod
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
Uint8 BitsPerPixel
Definition: SDL_pixels.h:317
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
#define SDL_SetColorKey
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define SDL_GetSurfaceAlphaMod
#define SDL_SetSurfaceRLE
#define NULL
Definition: begin_code.h:143
SDL_bool
Definition: SDL_stdinc.h:130
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_CreateRGBSurface
#define SDL_GetSurfaceColorMod
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
#define SDL_SetSurfaceBlendMode
GLfloat angle
void * driverdata
Definition: SDL_sysrender.h:69
SDL_Surface * SDLgfx_rotateSurface(SDL_Surface *src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle)
Definition: SDL_rotate.c:414
GLenum src
GLboolean GLboolean GLboolean b
void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle)
Definition: SDL_rotate.c:109
int y
Definition: SDL_rect.h:66
#define SDL_SetSurfaceAlphaMod
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
#define MIN(a, b)
Definition: SDL_rotate.h:23

§ SW_RenderDrawLines()

static int SW_RenderDrawLines ( SDL_Renderer renderer,
const SDL_FPoint points,
int  count 
)
static

Definition at line 451 of file SDL_render_sw.c.

References SDL_Renderer::a, SDL_Renderer::b, SDL_Renderer::blendMode, SDL_Surface::format, SDL_Renderer::g, i, SDL_Renderer::r, SDL_BlendLines(), SDL_BLENDMODE_NONE, SDL_DrawLines(), SDL_MapRGBA, SDL_OutOfMemory, SDL_stack_alloc, SDL_stack_free, SW_ActivateRenderer(), SDL_Renderer::viewport, SDL_Point::x, SDL_Rect::x, SDL_Point::y, and SDL_Rect::y.

Referenced by SW_CreateRendererForSurface().

453 {
454  SDL_Surface *surface = SW_ActivateRenderer(renderer);
455  SDL_Point *final_points;
456  int i, status;
457 
458  if (!surface) {
459  return -1;
460  }
461 
462  final_points = SDL_stack_alloc(SDL_Point, count);
463  if (!final_points) {
464  return SDL_OutOfMemory();
465  }
466  if (renderer->viewport.x || renderer->viewport.y) {
467  int x = renderer->viewport.x;
468  int y = renderer->viewport.y;
469 
470  for (i = 0; i < count; ++i) {
471  final_points[i].x = (int)(x + points[i].x);
472  final_points[i].y = (int)(y + points[i].y);
473  }
474  } else {
475  for (i = 0; i < count; ++i) {
476  final_points[i].x = (int)points[i].x;
477  final_points[i].y = (int)points[i].y;
478  }
479  }
480 
481  /* Draw the lines! */
482  if (renderer->blendMode == SDL_BLENDMODE_NONE) {
483  Uint32 color = SDL_MapRGBA(surface->format,
484  renderer->r, renderer->g, renderer->b,
485  renderer->a);
486 
487  status = SDL_DrawLines(surface, final_points, count, color);
488  } else {
489  status = SDL_BlendLines(surface, final_points, count,
490  renderer->blendMode,
491  renderer->r, renderer->g, renderer->b,
492  renderer->a);
493  }
494  SDL_stack_free(final_points);
495 
496  return status;
497 }
int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color)
Definition: SDL_drawline.c:166
#define SDL_MapRGBA
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
The structure that defines a point.
Definition: SDL_rect.h:48
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
int x
Definition: SDL_rect.h:50
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
int y
Definition: SDL_rect.h:51
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:328
SDL_BlendMode blendMode
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int x
Definition: SDL_rect.h:66
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
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_PixelFormat * format
Definition: SDL_surface.h:72
SDL_Rect viewport
GLuint color
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:329
int y
Definition: SDL_rect.h:66

§ SW_RenderDrawPoints()

static int SW_RenderDrawPoints ( SDL_Renderer renderer,
const SDL_FPoint points,
int  count 
)
static

Definition at line 402 of file SDL_render_sw.c.

References SDL_Renderer::a, SDL_Renderer::b, SDL_Renderer::blendMode, SDL_Surface::format, SDL_Renderer::g, i, SDL_Renderer::r, SDL_BLENDMODE_NONE, SDL_BlendPoints(), SDL_DrawPoints(), SDL_MapRGBA, SDL_OutOfMemory, SDL_stack_alloc, SDL_stack_free, SW_ActivateRenderer(), SDL_Renderer::viewport, SDL_Point::x, SDL_Rect::x, SDL_Point::y, and SDL_Rect::y.

Referenced by SW_CreateRendererForSurface().

404 {
405  SDL_Surface *surface = SW_ActivateRenderer(renderer);
406  SDL_Point *final_points;
407  int i, status;
408 
409  if (!surface) {
410  return -1;
411  }
412 
413  final_points = SDL_stack_alloc(SDL_Point, count);
414  if (!final_points) {
415  return SDL_OutOfMemory();
416  }
417  if (renderer->viewport.x || renderer->viewport.y) {
418  int x = renderer->viewport.x;
419  int y = renderer->viewport.y;
420 
421  for (i = 0; i < count; ++i) {
422  final_points[i].x = (int)(x + points[i].x);
423  final_points[i].y = (int)(y + points[i].y);
424  }
425  } else {
426  for (i = 0; i < count; ++i) {
427  final_points[i].x = (int)points[i].x;
428  final_points[i].y = (int)points[i].y;
429  }
430  }
431 
432  /* Draw the points! */
433  if (renderer->blendMode == SDL_BLENDMODE_NONE) {
434  Uint32 color = SDL_MapRGBA(surface->format,
435  renderer->r, renderer->g, renderer->b,
436  renderer->a);
437 
438  status = SDL_DrawPoints(surface, final_points, count, color);
439  } else {
440  status = SDL_BlendPoints(surface, final_points, count,
441  renderer->blendMode,
442  renderer->r, renderer->g, renderer->b,
443  renderer->a);
444  }
445  SDL_stack_free(final_points);
446 
447  return status;
448 }
#define SDL_MapRGBA
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
The structure that defines a point.
Definition: SDL_rect.h:48
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
int x
Definition: SDL_rect.h:50
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
int y
Definition: SDL_rect.h:51
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:328
SDL_BlendMode blendMode
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
int x
Definition: SDL_rect.h:66
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
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_PixelFormat * format
Definition: SDL_surface.h:72
int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color)
Definition: SDL_drawpoint.c:65
SDL_Rect viewport
GLuint color
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:329
int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
int y
Definition: SDL_rect.h:66

§ SW_RenderFillRects()

static int SW_RenderFillRects ( SDL_Renderer renderer,
const SDL_FRect rects,
int  count 
)
static

Definition at line 500 of file SDL_render_sw.c.

References SDL_Renderer::a, SDL_Renderer::b, SDL_Renderer::blendMode, SDL_Surface::format, SDL_Renderer::g, SDL_Rect::h, i, SDL_Renderer::r, SDL_BlendFillRects(), SDL_BLENDMODE_NONE, SDL_FillRects, SDL_MapRGBA, SDL_max, SDL_OutOfMemory, SDL_stack_alloc, SDL_stack_free, SW_ActivateRenderer(), SDL_Renderer::viewport, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SW_CreateRendererForSurface().

501 {
502  SDL_Surface *surface = SW_ActivateRenderer(renderer);
503  SDL_Rect *final_rects;
504  int i, status;
505 
506  if (!surface) {
507  return -1;
508  }
509 
510  final_rects = SDL_stack_alloc(SDL_Rect, count);
511  if (!final_rects) {
512  return SDL_OutOfMemory();
513  }
514  if (renderer->viewport.x || renderer->viewport.y) {
515  int x = renderer->viewport.x;
516  int y = renderer->viewport.y;
517 
518  for (i = 0; i < count; ++i) {
519  final_rects[i].x = (int)(x + rects[i].x);
520  final_rects[i].y = (int)(y + rects[i].y);
521  final_rects[i].w = SDL_max((int)rects[i].w, 1);
522  final_rects[i].h = SDL_max((int)rects[i].h, 1);
523  }
524  } else {
525  for (i = 0; i < count; ++i) {
526  final_rects[i].x = (int)rects[i].x;
527  final_rects[i].y = (int)rects[i].y;
528  final_rects[i].w = SDL_max((int)rects[i].w, 1);
529  final_rects[i].h = SDL_max((int)rects[i].h, 1);
530  }
531  }
532 
533  if (renderer->blendMode == SDL_BLENDMODE_NONE) {
534  Uint32 color = SDL_MapRGBA(surface->format,
535  renderer->r, renderer->g, renderer->b,
536  renderer->a);
537  status = SDL_FillRects(surface, final_rects, count, color);
538  } else {
539  status = SDL_BlendFillRects(surface, final_rects, count,
540  renderer->blendMode,
541  renderer->r, renderer->g, renderer->b,
542  renderer->a);
543  }
544  SDL_stack_free(final_rects);
545 
546  return status;
547 }
#define SDL_MapRGBA
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1564
#define SDL_FillRects
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
#define SDL_max(x, y)
Definition: SDL_stdinc.h:350
int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:328
SDL_BlendMode blendMode
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
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
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_PixelFormat * format
Definition: SDL_surface.h:72
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
GLuint color
GLubyte GLubyte GLubyte GLubyte w
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:329
int y
Definition: SDL_rect.h:66
GLfloat GLfloat GLfloat GLfloat h
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ SW_RenderPresent()

static void SW_RenderPresent ( SDL_Renderer renderer)
static

Definition at line 766 of file SDL_render_sw.c.

References SDL_UpdateWindowSurface, window, and SDL_Renderer::window.

Referenced by SW_CreateRendererForSurface().

767 {
768  SDL_Window *window = renderer->window;
769 
770  if (window) {
771  SDL_UpdateWindowSurface(window);
772  }
773 }
static SDL_Window * window
SDL_Window * window
#define SDL_UpdateWindowSurface
The type used to identify a window.
Definition: SDL_sysvideo.h:71

§ SW_RenderReadPixels()

static int SW_RenderReadPixels ( SDL_Renderer renderer,
const SDL_Rect rect,
Uint32  format,
void pixels,
int  pitch 
)
static

Definition at line 730 of file SDL_render_sw.c.

References SDL_PixelFormat::BytesPerPixel, SDL_Surface::format, SDL_PixelFormat::format, SDL_Rect::h, SDL_Surface::h, SDL_Surface::pitch, SDL_Surface::pixels, SDL_ConvertPixels, SDL_SetError, SW_ActivateRenderer(), SDL_Renderer::viewport, SDL_Rect::w, SDL_Surface::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SW_CreateRendererForSurface().

732 {
733  SDL_Surface *surface = SW_ActivateRenderer(renderer);
734  Uint32 src_format;
735  void *src_pixels;
736  SDL_Rect final_rect;
737 
738  if (!surface) {
739  return -1;
740  }
741 
742  if (renderer->viewport.x || renderer->viewport.y) {
743  final_rect.x = renderer->viewport.x + rect->x;
744  final_rect.y = renderer->viewport.y + rect->y;
745  final_rect.w = rect->w;
746  final_rect.h = rect->h;
747  rect = &final_rect;
748  }
749 
750  if (rect->x < 0 || rect->x+rect->w > surface->w ||
751  rect->y < 0 || rect->y+rect->h > surface->h) {
752  return SDL_SetError("Tried to read outside of surface bounds");
753  }
754 
755  src_format = surface->format->format;
756  src_pixels = (void*)((Uint8 *) surface->pixels +
757  rect->y * surface->pitch +
758  rect->x * surface->format->BytesPerPixel);
759 
760  return SDL_ConvertPixels(rect->w, rect->h,
761  src_format, src_pixels, surface->pitch,
762  format, pixels, pitch);
763 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
Uint8 BytesPerPixel
Definition: SDL_pixels.h:318
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
static SDL_Surface * SW_ActivateRenderer(SDL_Renderer *renderer)
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_SetError
SDL_Rect viewport
int h
Definition: SDL_rect.h:67
#define SDL_ConvertPixels
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

§ SW_SetRenderTarget()

static int SW_SetRenderTarget ( SDL_Renderer renderer,
SDL_Texture texture 
)
static

Definition at line 337 of file SDL_render_sw.c.

References SDL_Texture::driverdata, SDL_Renderer::driverdata, SW_RenderData::surface, and SW_RenderData::window.

Referenced by SW_CreateRendererForSurface().

338 {
339  SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
340 
341  if (texture ) {
342  data->surface = (SDL_Surface *) texture->driverdata;
343  } else {
344  data->surface = data->window;
345  }
346  return 0;
347 }
void * driverdata
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_Surface * surface
SDL_Surface * window
void * driverdata
Definition: SDL_sysrender.h:69

§ SW_SetTextureAlphaMod()

static int SW_SetTextureAlphaMod ( SDL_Renderer renderer,
SDL_Texture texture 
)
static

Definition at line 267 of file SDL_render_sw.c.

References SDL_Texture::a, SDL_PixelFormat::Amask, SDL_Texture::driverdata, SDL_Surface::format, SDL_SetSurfaceAlphaMod, and SDL_SetSurfaceRLE.

Referenced by SW_CreateRendererForSurface().

268 {
269  SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
270  /* If the texture ever has multiple alpha values (surface alpha plus alpha channel), permanently
271  * disable RLE (which doesn't support this) to avoid potentially frequent RLE encoding/decoding.
272  */
273  if (texture->a != 255 && surface->format->Amask) {
274  SDL_SetSurfaceRLE(surface, 0);
275  }
276  return SDL_SetSurfaceAlphaMod(surface, texture->a);
277 }
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
#define SDL_SetSurfaceRLE
SDL_PixelFormat * format
Definition: SDL_surface.h:72
void * driverdata
Definition: SDL_sysrender.h:69
#define SDL_SetSurfaceAlphaMod

§ SW_SetTextureBlendMode()

static int SW_SetTextureBlendMode ( SDL_Renderer renderer,
SDL_Texture texture 
)
static

Definition at line 280 of file SDL_render_sw.c.

References SDL_Texture::blendMode, SDL_Texture::driverdata, SDL_BLENDMODE_ADD, SDL_BLENDMODE_MOD, SDL_SetSurfaceBlendMode, and SDL_SetSurfaceRLE.

Referenced by SW_CreateRendererForSurface().

281 {
282  SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
283  /* If add or mod blending are ever enabled, permanently disable RLE (which doesn't support
284  * them) to avoid potentially frequent RLE encoding/decoding.
285  */
286  if ((texture->blendMode == SDL_BLENDMODE_ADD || texture->blendMode == SDL_BLENDMODE_MOD)) {
287  SDL_SetSurfaceRLE(surface, 0);
288  }
289  return SDL_SetSurfaceBlendMode(surface, texture->blendMode);
290 }
SDL_BlendMode blendMode
Definition: SDL_sysrender.h:57
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
#define SDL_SetSurfaceRLE
#define SDL_SetSurfaceBlendMode
void * driverdata
Definition: SDL_sysrender.h:69

§ SW_SetTextureColorMod()

static int SW_SetTextureColorMod ( SDL_Renderer renderer,
SDL_Texture texture 
)
static

Definition at line 253 of file SDL_render_sw.c.

References SDL_Texture::b, SDL_Texture::driverdata, SDL_Texture::g, SDL_Texture::r, SDL_SetSurfaceColorMod, and SDL_SetSurfaceRLE.

Referenced by SW_CreateRendererForSurface().

254 {
255  SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
256  /* If the color mod is ever enabled (non-white), permanently disable RLE (which doesn't support
257  * color mod) to avoid potentially frequent RLE encoding/decoding.
258  */
259  if ((texture->r & texture->g & texture->b) != 255) {
260  SDL_SetSurfaceRLE(surface, 0);
261  }
262  return SDL_SetSurfaceColorMod(surface, texture->r, texture->g,
263  texture->b);
264 }
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
#define SDL_SetSurfaceColorMod
#define SDL_SetSurfaceRLE
void * driverdata
Definition: SDL_sysrender.h:69

§ SW_UnlockTexture()

static void SW_UnlockTexture ( SDL_Renderer renderer,
SDL_Texture texture 
)
static

Definition at line 332 of file SDL_render_sw.c.

Referenced by SW_CreateRendererForSurface().

333 {
334 }

§ SW_UpdateClipRect()

static int SW_UpdateClipRect ( SDL_Renderer renderer)
static

Definition at line 365 of file SDL_render_sw.c.

References SDL_Renderer::clip_rect, SDL_Renderer::clipping_enabled, SDL_Renderer::driverdata, NULL, SDL_SetClipRect, and SW_RenderData::surface.

Referenced by SW_ActivateRenderer(), and SW_CreateRendererForSurface().

366 {
367  SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
368  SDL_Surface *surface = data->surface;
369  if (surface) {
370  if (renderer->clipping_enabled) {
371  SDL_SetClipRect(surface, &renderer->clip_rect);
372  } else {
373  SDL_SetClipRect(surface, NULL);
374  }
375  }
376  return 0;
377 }
#define SDL_SetClipRect
void * driverdata
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_Rect clip_rect
SDL_Surface * surface
#define NULL
Definition: begin_code.h:143
SDL_bool clipping_enabled

§ SW_UpdateTexture()

static int SW_UpdateTexture ( SDL_Renderer renderer,
SDL_Texture texture,
const SDL_Rect rect,
const void pixels,
int  pitch 
)
static

Definition at line 293 of file SDL_render_sw.c.

References SDL_PixelFormat::BytesPerPixel, SDL_Texture::driverdata, SDL_Surface::format, SDL_Rect::h, SDL_Surface::pitch, SDL_Surface::pixels, SDL_LockSurface, SDL_memcpy, SDL_MUSTLOCK, SDL_UnlockSurface, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by SW_CreateRendererForSurface().

295 {
296  SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
297  Uint8 *src, *dst;
298  int row;
299  size_t length;
300 
301  if(SDL_MUSTLOCK(surface))
302  SDL_LockSurface(surface);
303  src = (Uint8 *) pixels;
304  dst = (Uint8 *) surface->pixels +
305  rect->y * surface->pitch +
306  rect->x * surface->format->BytesPerPixel;
307  length = rect->w * surface->format->BytesPerPixel;
308  for (row = 0; row < rect->h; ++row) {
309  SDL_memcpy(dst, src, length);
310  src += pitch;
311  dst += surface->pitch;
312  }
313  if(SDL_MUSTLOCK(surface))
314  SDL_UnlockSurface(surface);
315  return 0;
316 }
GLenum GLenum dst
#define SDL_UnlockSurface
Uint8 BytesPerPixel
Definition: SDL_pixels.h:318
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
#define SDL_memcpy
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_LockSurface
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
int h
Definition: SDL_rect.h:67
void * driverdata
Definition: SDL_sysrender.h:69
GLuint GLsizei GLsizei * length
GLenum src
GLenum GLenum void * row
int y
Definition: SDL_rect.h:66

§ SW_UpdateViewport()

static int SW_UpdateViewport ( SDL_Renderer renderer)
static

Definition at line 350 of file SDL_render_sw.c.

References SDL_Renderer::driverdata, SDL_SetClipRect, SW_RenderData::surface, and SDL_Renderer::viewport.

Referenced by SW_ActivateRenderer(), and SW_CreateRendererForSurface().

351 {
352  SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
353  SDL_Surface *surface = data->surface;
354 
355  if (!surface) {
356  /* We'll update the viewport after we recreate the surface */
357  return 0;
358  }
359 
360  SDL_SetClipRect(data->surface, &renderer->viewport);
361  return 0;
362 }
#define SDL_SetClipRect
void * driverdata
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_Surface * surface
SDL_Rect viewport

§ SW_WindowEvent()

static void SW_WindowEvent ( SDL_Renderer renderer,
const SDL_WindowEvent event 
)
static

Definition at line 194 of file SDL_render_sw.c.

References SDL_Renderer::driverdata, SDL_WindowEvent::event, NULL, SDL_WINDOWEVENT_SIZE_CHANGED, SW_RenderData::surface, and SW_RenderData::window.

Referenced by SW_CreateRendererForSurface().

195 {
196  SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
197 
198  if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
199  data->surface = NULL;
200  data->window = NULL;
201  }
202 }
void * driverdata
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_Surface * surface
#define NULL
Definition: begin_code.h:143
SDL_Surface * window

Variable Documentation

§ SW_RenderDriver