Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
542 lines (457 loc) · 15.8 KB

SDL_render_sw.c

File metadata and controls

542 lines (457 loc) · 15.8 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Feb 12, 2011
Feb 12, 2011
3
Copyright (C) 1997-2011 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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"
Feb 8, 2011
Feb 8, 2011
24
25
#if !SDL_RENDER_DISABLED
Feb 2, 2011
Feb 2, 2011
26
#include "../SDL_sysrender.h"
Feb 3, 2011
Feb 3, 2011
28
29
30
31
32
33
34
#include "SDL_draw.h"
#include "SDL_blendfillrect.h"
#include "SDL_blendline.h"
#include "SDL_blendpoint.h"
#include "SDL_drawline.h"
#include "SDL_drawpoint.h"
35
36
37
/* SDL surface based renderer implementation */
Jul 19, 2006
Jul 19, 2006
38
static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags);
Feb 2, 2011
Feb 2, 2011
39
40
static void SW_WindowEvent(SDL_Renderer * renderer,
const SDL_WindowEvent *event);
Jul 19, 2006
Jul 19, 2006
41
static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
Aug 28, 2006
Aug 28, 2006
42
43
44
45
static int SW_SetTextureColorMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int SW_SetTextureAlphaMod(SDL_Renderer * renderer,
SDL_Texture * texture);
Feb 1, 2011
Feb 1, 2011
46
47
static int SW_SetTextureBlendMode(SDL_Renderer * renderer,
SDL_Texture * texture);
Aug 28, 2006
Aug 28, 2006
48
49
50
static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
Jul 19, 2006
Jul 19, 2006
51
static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Feb 3, 2011
Feb 3, 2011
52
const SDL_Rect * rect, void **pixels, int *pitch);
Jul 19, 2006
Jul 19, 2006
53
static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
Feb 15, 2011
Feb 15, 2011
54
55
static int SW_UpdateViewport(SDL_Renderer * renderer);
static int SW_RenderClear(SDL_Renderer * renderer);
Dec 23, 2009
Dec 23, 2009
56
57
58
59
60
static int SW_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_Point * points, int count);
static int SW_RenderDrawLines(SDL_Renderer * renderer,
const SDL_Point * points, int count);
static int SW_RenderFillRects(SDL_Renderer * renderer,
Feb 15, 2011
Feb 15, 2011
61
const SDL_Rect * rects, int count);
Jul 19, 2006
Jul 19, 2006
62
static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Aug 28, 2006
Aug 28, 2006
63
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
Nov 9, 2009
Nov 9, 2009
64
static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Nov 16, 2009
Nov 16, 2009
65
Uint32 format, void * pixels, int pitch);
Jul 19, 2006
Jul 19, 2006
66
67
68
69
70
71
72
static void SW_RenderPresent(SDL_Renderer * renderer);
static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void SW_DestroyRenderer(SDL_Renderer * renderer);
SDL_RenderDriver SW_RenderDriver = {
SW_CreateRenderer,
Feb 17, 2011
Feb 17, 2011
75
SDL_RENDERER_SOFTWARE,
Feb 3, 2011
Feb 3, 2011
76
8,
Aug 5, 2006
Aug 5, 2006
78
79
80
81
82
83
84
SDL_PIXELFORMAT_RGB555,
SDL_PIXELFORMAT_RGB565,
SDL_PIXELFORMAT_RGB888,
SDL_PIXELFORMAT_BGR888,
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ABGR8888,
Feb 3, 2011
Feb 3, 2011
85
86
SDL_PIXELFORMAT_BGRA8888
},
87
88
89
90
91
92
0,
0}
};
typedef struct
{
Feb 3, 2011
Feb 3, 2011
93
SDL_Surface *surface;
Jul 19, 2006
Jul 19, 2006
94
} SW_RenderData;
Jul 15, 2006
Jul 15, 2006
96
Feb 15, 2011
Feb 15, 2011
97
98
99
100
101
102
103
104
105
106
107
108
109
static SDL_Surface *
SW_ActivateRenderer(SDL_Renderer * renderer)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
if (!data->surface) {
data->surface = SDL_GetWindowSurface(renderer->window);
SW_UpdateViewport(renderer);
}
return data->surface;
}
Feb 3, 2011
Feb 3, 2011
111
SW_CreateRendererForSurface(SDL_Surface * surface)
112
113
{
SDL_Renderer *renderer;
Jul 19, 2006
Jul 19, 2006
114
SW_RenderData *data;
Feb 3, 2011
Feb 3, 2011
116
117
if (!surface) {
SDL_SetError("Can't create renderer for NULL surface");
118
119
120
121
122
123
124
125
126
return NULL;
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
Jul 22, 2006
Jul 22, 2006
127
data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
Jul 19, 2006
Jul 19, 2006
129
SW_DestroyRenderer(renderer);
130
131
132
SDL_OutOfMemory();
return NULL;
}
Feb 3, 2011
Feb 3, 2011
133
134
data->surface = surface;
Feb 2, 2011
Feb 2, 2011
135
renderer->WindowEvent = SW_WindowEvent;
Feb 2, 2011
Feb 2, 2011
136
137
138
139
140
141
142
renderer->CreateTexture = SW_CreateTexture;
renderer->SetTextureColorMod = SW_SetTextureColorMod;
renderer->SetTextureAlphaMod = SW_SetTextureAlphaMod;
renderer->SetTextureBlendMode = SW_SetTextureBlendMode;
renderer->UpdateTexture = SW_UpdateTexture;
renderer->LockTexture = SW_LockTexture;
renderer->UnlockTexture = SW_UnlockTexture;
Feb 15, 2011
Feb 15, 2011
143
renderer->UpdateViewport = SW_UpdateViewport;
Feb 2, 2011
Feb 2, 2011
144
renderer->DestroyTexture = SW_DestroyTexture;
Feb 15, 2011
Feb 15, 2011
145
renderer->RenderClear = SW_RenderClear;
Dec 23, 2009
Dec 23, 2009
146
147
148
renderer->RenderDrawPoints = SW_RenderDrawPoints;
renderer->RenderDrawLines = SW_RenderDrawLines;
renderer->RenderFillRects = SW_RenderFillRects;
Jul 19, 2006
Jul 19, 2006
149
renderer->RenderCopy = SW_RenderCopy;
Nov 9, 2009
Nov 9, 2009
150
renderer->RenderReadPixels = SW_RenderReadPixels;
Jul 19, 2006
Jul 19, 2006
151
152
renderer->RenderPresent = SW_RenderPresent;
renderer->DestroyRenderer = SW_DestroyRenderer;
Feb 2, 2011
Feb 2, 2011
153
renderer->info = SW_RenderDriver.info;
154
155
renderer->driverdata = data;
Feb 15, 2011
Feb 15, 2011
156
157
SW_ActivateRenderer(renderer);
Feb 3, 2011
Feb 3, 2011
158
159
return renderer;
}
Jul 15, 2006
Jul 15, 2006
160
Feb 3, 2011
Feb 3, 2011
161
162
163
164
SDL_Renderer *
SW_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_Surface *surface;
Jul 15, 2006
Jul 15, 2006
165
Feb 3, 2011
Feb 3, 2011
166
167
surface = SDL_GetWindowSurface(window);
if (!surface) {
Jul 15, 2006
Jul 15, 2006
168
169
return NULL;
}
Feb 3, 2011
Feb 3, 2011
170
return SW_CreateRendererForSurface(surface);
Feb 2, 2011
Feb 2, 2011
173
174
static void
SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
Aug 6, 2006
Aug 6, 2006
175
176
177
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
Feb 13, 2011
Feb 13, 2011
178
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
Feb 15, 2011
Feb 15, 2011
179
data->surface = NULL;
Aug 6, 2006
Aug 6, 2006
180
181
182
}
}
Jul 19, 2006
Jul 19, 2006
184
SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Feb 3, 2011
Feb 3, 2011
186
187
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
Feb 3, 2011
Feb 3, 2011
189
190
191
192
193
if (!SDL_PixelFormatEnumToMasks
(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown texture format");
return -1;
}
Feb 3, 2011
Feb 3, 2011
195
196
197
198
199
200
201
texture->driverdata =
SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
Bmask, Amask);
SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
texture->b);
SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
Jan 30, 2009
Jan 30, 2009
202
Feb 3, 2011
Feb 3, 2011
203
204
if (texture->access == SDL_TEXTUREACCESS_STATIC) {
SDL_SetSurfaceRLE(texture->driverdata, 1);
205
206
207
208
209
210
211
212
}
if (!texture->driverdata) {
return -1;
}
return 0;
}
Aug 28, 2006
Aug 28, 2006
213
214
215
static int
SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 18, 2007
Aug 18, 2007
216
217
218
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
return SDL_SetSurfaceColorMod(surface, texture->r, texture->g,
texture->b);
Aug 28, 2006
Aug 28, 2006
219
220
221
222
223
}
static int
SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 18, 2007
Aug 18, 2007
224
225
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
return SDL_SetSurfaceAlphaMod(surface, texture->a);
Aug 28, 2006
Aug 28, 2006
226
227
228
229
230
}
static int
SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
Aug 18, 2007
Aug 18, 2007
231
232
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
return SDL_SetSurfaceBlendMode(surface, texture->blendMode);
Aug 28, 2006
Aug 28, 2006
233
234
}
Jul 19, 2006
Jul 19, 2006
236
237
SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
Feb 3, 2011
Feb 3, 2011
239
240
241
242
243
244
245
246
247
248
249
250
251
252
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
Uint8 *src, *dst;
int row;
size_t length;
src = (Uint8 *) pixels;
dst = (Uint8 *) surface->pixels +
rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel;
length = rect->w * surface->format->BytesPerPixel;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += surface->pitch;
Feb 3, 2011
Feb 3, 2011
254
return 0;
255
256
257
}
static int
Jul 19, 2006
Jul 19, 2006
258
SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
Feb 3, 2011
Feb 3, 2011
259
const SDL_Rect * rect, void **pixels, int *pitch)
Feb 3, 2011
Feb 3, 2011
261
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
Feb 3, 2011
Feb 3, 2011
263
264
265
266
267
*pixels =
(void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel);
*pitch = surface->pitch;
return 0;
268
269
270
}
static void
Jul 19, 2006
Jul 19, 2006
271
SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Feb 15, 2011
Feb 15, 2011
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
static int
SW_UpdateViewport(SDL_Renderer * renderer)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SDL_Surface *surface = data->surface;
if (!surface) {
/* We'll update the viewport after we recreate the surface */
return 0;
}
if (!renderer->viewport.w && !renderer->viewport.h) {
/* There may be no window, so update the viewport directly */
renderer->viewport.w = surface->w;
renderer->viewport.h = surface->h;
}
Feb 15, 2011
Feb 15, 2011
291
SDL_SetClipRect(data->surface, &renderer->viewport);
Feb 15, 2011
Feb 15, 2011
292
293
294
295
296
return 0;
}
static int
SW_RenderClear(SDL_Renderer * renderer)
Feb 8, 2011
Feb 8, 2011
297
298
{
SDL_Surface *surface = SW_ActivateRenderer(renderer);
Feb 15, 2011
Feb 15, 2011
299
300
Uint32 color;
SDL_Rect clip_rect;
Feb 8, 2011
Feb 8, 2011
301
302
if (!surface) {
Feb 15, 2011
Feb 15, 2011
303
return -1;
Feb 8, 2011
Feb 8, 2011
304
}
Feb 15, 2011
Feb 15, 2011
305
306
307
308
309
310
311
312
313
314
color = SDL_MapRGBA(surface->format,
renderer->r, renderer->g, renderer->b, renderer->a);
/* By definition the clear ignores the clip rect */
clip_rect = surface->clip_rect;
SDL_SetClipRect(surface, NULL);
SDL_FillRect(surface, NULL, color);
SDL_SetClipRect(surface, &clip_rect);
return 0;
Feb 8, 2011
Feb 8, 2011
315
316
}
Dec 21, 2008
Dec 21, 2008
317
static int
Dec 23, 2009
Dec 23, 2009
318
319
SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count)
Dec 21, 2008
Dec 21, 2008
320
{
Feb 3, 2011
Feb 3, 2011
321
SDL_Surface *surface = SW_ActivateRenderer(renderer);
Feb 15, 2011
Feb 15, 2011
322
323
SDL_Point *temp = NULL;
int status;
Dec 9, 2009
Dec 9, 2009
324
Feb 3, 2011
Feb 3, 2011
325
if (!surface) {
Feb 2, 2011
Feb 2, 2011
326
327
328
return -1;
}
Feb 15, 2011
Feb 15, 2011
329
330
331
332
333
334
335
336
337
338
339
340
341
if (renderer->viewport.x || renderer->viewport.y) {
int i;
int x = renderer->viewport.x;
int y = renderer->viewport.y;
temp = SDL_stack_alloc(SDL_Point, count);
for (i = 0; i < count; ++i) {
temp[i].x = x + points[i].x;
temp[i].y = y + points[i].x;
}
points = temp;
}
Dec 9, 2009
Dec 9, 2009
342
/* Draw the points! */
Feb 1, 2011
Feb 1, 2011
343
if (renderer->blendMode == SDL_BLENDMODE_NONE) {
Feb 3, 2011
Feb 3, 2011
344
Uint32 color = SDL_MapRGBA(surface->format,
Dec 9, 2009
Dec 9, 2009
345
346
347
renderer->r, renderer->g, renderer->b,
renderer->a);
Feb 15, 2011
Feb 15, 2011
348
status = SDL_DrawPoints(surface, points, count, color);
Dec 21, 2008
Dec 21, 2008
349
} else {
Feb 15, 2011
Feb 15, 2011
350
351
352
353
354
355
356
357
status = SDL_BlendPoints(surface, points, count,
renderer->blendMode,
renderer->r, renderer->g, renderer->b,
renderer->a);
}
if (temp) {
SDL_stack_free(temp);
Dec 21, 2008
Dec 21, 2008
358
}
Feb 15, 2011
Feb 15, 2011
359
return status;
Dec 21, 2008
Dec 21, 2008
360
361
}
Dec 20, 2008
Dec 20, 2008
362
static int
Dec 23, 2009
Dec 23, 2009
363
364
SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
Dec 20, 2008
Dec 20, 2008
365
{
Feb 3, 2011
Feb 3, 2011
366
SDL_Surface *surface = SW_ActivateRenderer(renderer);
Feb 15, 2011
Feb 15, 2011
367
368
SDL_Point *temp = NULL;
int status;
Dec 9, 2009
Dec 9, 2009
369
Feb 3, 2011
Feb 3, 2011
370
if (!surface) {
Feb 2, 2011
Feb 2, 2011
371
372
373
return -1;
}
Feb 15, 2011
Feb 15, 2011
374
375
376
377
378
379
380
381
382
383
384
385
386
if (renderer->viewport.x || renderer->viewport.y) {
int i;
int x = renderer->viewport.x;
int y = renderer->viewport.y;
temp = SDL_stack_alloc(SDL_Point, count);
for (i = 0; i < count; ++i) {
temp[i].x = x + points[i].x;
temp[i].y = y + points[i].y;
}
points = temp;
}
Feb 3, 2011
Feb 3, 2011
387
/* Draw the lines! */
Feb 1, 2011
Feb 1, 2011
388
if (renderer->blendMode == SDL_BLENDMODE_NONE) {
Feb 3, 2011
Feb 3, 2011
389
Uint32 color = SDL_MapRGBA(surface->format,
Dec 9, 2009
Dec 9, 2009
390
391
392
renderer->r, renderer->g, renderer->b,
renderer->a);
Feb 15, 2011
Feb 15, 2011
393
status = SDL_DrawLines(surface, points, count, color);
Dec 20, 2008
Dec 20, 2008
394
} else {
Feb 15, 2011
Feb 15, 2011
395
396
397
398
399
400
401
402
status = SDL_BlendLines(surface, points, count,
renderer->blendMode,
renderer->r, renderer->g, renderer->b,
renderer->a);
}
if (temp) {
SDL_stack_free(temp);
Dec 20, 2008
Dec 20, 2008
403
}
Feb 15, 2011
Feb 15, 2011
404
return status;
Dec 20, 2008
Dec 20, 2008
405
406
}
Dec 23, 2009
Dec 23, 2009
407
static int
Feb 15, 2011
Feb 15, 2011
408
SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int count)
Dec 23, 2009
Dec 23, 2009
409
{
Feb 3, 2011
Feb 3, 2011
410
SDL_Surface *surface = SW_ActivateRenderer(renderer);
Feb 15, 2011
Feb 15, 2011
411
412
SDL_Rect *temp = NULL;
int status;
Dec 23, 2009
Dec 23, 2009
413
Feb 3, 2011
Feb 3, 2011
414
if (!surface) {
Feb 2, 2011
Feb 2, 2011
415
416
417
return -1;
}
Feb 15, 2011
Feb 15, 2011
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
if (renderer->viewport.x || renderer->viewport.y) {
int i;
int x = renderer->viewport.x;
int y = renderer->viewport.y;
temp = SDL_stack_alloc(SDL_Rect, count);
for (i = 0; i < count; ++i) {
temp[i].x = x + rects[i].x;
temp[i].y = y + rects[i].y;
temp[i].w = rects[i].w;
temp[i].h = rects[i].h;
}
rects = temp;
}
Feb 1, 2011
Feb 1, 2011
433
if (renderer->blendMode == SDL_BLENDMODE_NONE) {
Feb 3, 2011
Feb 3, 2011
434
435
436
Uint32 color = SDL_MapRGBA(surface->format,
renderer->r, renderer->g, renderer->b,
renderer->a);
Feb 15, 2011
Feb 15, 2011
437
status = SDL_FillRects(surface, rects, count, color);
Feb 3, 2011
Feb 3, 2011
438
} else {
Feb 15, 2011
Feb 15, 2011
439
440
441
442
status = SDL_BlendFillRects(surface, rects, count,
renderer->blendMode,
renderer->r, renderer->g, renderer->b,
renderer->a);
Dec 23, 2009
Dec 23, 2009
443
}
Feb 15, 2011
Feb 15, 2011
444
445
446
447
448
if (temp) {
SDL_stack_free(temp);
}
return status;
Dec 23, 2009
Dec 23, 2009
449
450
}
Jul 19, 2006
Jul 19, 2006
452
SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Aug 28, 2006
Aug 28, 2006
453
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
Feb 3, 2011
Feb 3, 2011
455
456
457
SDL_Surface *surface = SW_ActivateRenderer(renderer);
SDL_Surface *src = (SDL_Surface *) texture->driverdata;
SDL_Rect final_rect = *dstrect;
Feb 3, 2011
Feb 3, 2011
459
if (!surface) {
Feb 2, 2011
Feb 2, 2011
460
461
return -1;
}
Feb 14, 2011
Feb 14, 2011
462
Feb 15, 2011
Feb 15, 2011
463
464
465
466
if (renderer->viewport.x || renderer->viewport.y) {
final_rect.x += renderer->viewport.x;
final_rect.y += renderer->viewport.y;
}
Feb 14, 2011
Feb 14, 2011
467
468
469
470
471
if ( srcrect->w == final_rect.w && srcrect->h == final_rect.h ) {
return SDL_BlitSurface(src, srcrect, surface, &final_rect);
} else {
return SDL_BlitScaled(src, srcrect, surface, &final_rect);
}
Nov 9, 2009
Nov 9, 2009
474
475
static int
SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Nov 16, 2009
Nov 16, 2009
476
Uint32 format, void * pixels, int pitch)
Nov 9, 2009
Nov 9, 2009
477
{
Feb 3, 2011
Feb 3, 2011
478
479
480
SDL_Surface *surface = SW_ActivateRenderer(renderer);
Uint32 src_format;
void *src_pixels;
Feb 15, 2011
Feb 15, 2011
481
SDL_Rect final_rect;
Nov 9, 2009
Nov 9, 2009
482
Feb 3, 2011
Feb 3, 2011
483
if (!surface) {
Feb 2, 2011
Feb 2, 2011
484
485
486
return -1;
}
Feb 15, 2011
Feb 15, 2011
487
488
489
490
491
492
493
494
if (renderer->viewport.x || renderer->viewport.y) {
final_rect.x = renderer->viewport.x + rect->x;
final_rect.y = renderer->viewport.y + rect->y;
final_rect.w = rect->w;
final_rect.h = rect->h;
rect = &final_rect;
}
Feb 3, 2011
Feb 3, 2011
495
496
497
if (rect->x < 0 || rect->x+rect->w > surface->w ||
rect->y < 0 || rect->y+rect->h > surface->h) {
SDL_SetError("Tried to read outside of surface bounds");
Nov 9, 2009
Nov 9, 2009
498
499
500
return -1;
}
Feb 15, 2011
Feb 15, 2011
501
src_format = surface->format->format;
Feb 3, 2011
Feb 3, 2011
502
503
504
505
506
507
508
src_pixels = (void*)((Uint8 *) surface->pixels +
rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel);
return SDL_ConvertPixels(rect->w, rect->h,
src_format, src_pixels, surface->pitch,
format, pixels, pitch);
Nov 9, 2009
Nov 9, 2009
509
510
}
Jul 19, 2006
Jul 19, 2006
512
SW_RenderPresent(SDL_Renderer * renderer)
Feb 3, 2011
Feb 3, 2011
514
SDL_Window *window = renderer->window;
Feb 3, 2011
Feb 3, 2011
516
517
if (window) {
SDL_UpdateWindowSurface(window);
Feb 2, 2011
Feb 2, 2011
518
}
519
520
521
}
static void
Jul 19, 2006
Jul 19, 2006
522
SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
Feb 3, 2011
Feb 3, 2011
524
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
Feb 3, 2011
Feb 3, 2011
526
SDL_FreeSurface(surface);
527
528
529
}
static void
Jul 19, 2006
Jul 19, 2006
530
SW_DestroyRenderer(SDL_Renderer * renderer)
Jul 19, 2006
Jul 19, 2006
532
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
533
534
535
536
537
538
539
if (data) {
SDL_free(data);
}
SDL_free(renderer);
}
Feb 8, 2011
Feb 8, 2011
540
541
#endif /* !SDL_RENDER_DISABLED */
542
/* vi: set ts=4 sw=4 expandtab: */