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

Latest commit

 

History

History
256 lines (224 loc) · 8.78 KB

SDL_nullrender.c

File metadata and controls

256 lines (224 loc) · 8.78 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 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"
#include "SDL_video.h"
#include "../SDL_sysvideo.h"
Jul 15, 2006
Jul 15, 2006
26
#include "../SDL_yuv_sw_c.h"
Aug 12, 2007
Aug 12, 2007
27
#include "../SDL_renderer_sw.h"
Aug 28, 2006
Aug 28, 2006
28
#include "../SDL_rendercopy.h"
29
30
31
32
/* SDL surface based renderer implementation */
Jul 16, 2006
Jul 16, 2006
33
34
static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
Uint32 flags);
Aug 28, 2006
Aug 28, 2006
35
36
static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g,
Uint8 b, Uint8 a, const SDL_Rect * rect);
Jul 16, 2006
Jul 16, 2006
37
38
39
static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Rect * srcrect,
Aug 28, 2006
Aug 28, 2006
40
const SDL_Rect * dstrect);
41
42
43
44
45
46
47
static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
SDL_RenderDriver SDL_DUMMY_RenderDriver = {
SDL_DUMMY_CreateRenderer,
{
Jul 14, 2006
Jul 14, 2006
48
"dummy",
Aug 5, 2006
Aug 5, 2006
49
50
51
(SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
SDL_RENDERER_PRESENTDISCARD),
Aug 11, 2007
Aug 11, 2007
52
}
53
54
55
56
};
typedef struct
{
Jul 15, 2006
Jul 15, 2006
57
58
int current_screen;
SDL_Surface *screens[3];
59
60
61
62
63
64
65
66
67
} SDL_DUMMY_RenderData;
SDL_Renderer *
SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_DisplayMode *displayMode = &display->current_mode;
SDL_Renderer *renderer;
SDL_DUMMY_RenderData *data;
Jul 15, 2006
Jul 15, 2006
68
int i, n;
69
70
71
72
73
74
75
76
77
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (!SDL_PixelFormatEnumToMasks
(displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown display format");
return NULL;
}
Jul 15, 2006
Jul 15, 2006
78
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
79
80
81
82
83
84
85
86
87
88
89
90
91
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
data = (SDL_DUMMY_RenderData *) SDL_malloc(sizeof(*data));
if (!data) {
SDL_DUMMY_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
}
SDL_zerop(data);
Jul 15, 2006
Jul 15, 2006
92
93
renderer->RenderFill = SDL_DUMMY_RenderFill;
renderer->RenderCopy = SDL_DUMMY_RenderCopy;
94
95
renderer->RenderPresent = SDL_DUMMY_RenderPresent;
renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer;
Aug 11, 2007
Aug 11, 2007
96
97
renderer->info.name = SDL_DUMMY_RenderDriver.info.name;
renderer->info.flags = 0;
98
99
renderer->window = window->id;
renderer->driverdata = data;
Aug 11, 2007
Aug 11, 2007
100
Setup_SoftwareRenderer(renderer);
Jul 15, 2006
Jul 15, 2006
101
Aug 5, 2006
Aug 5, 2006
102
103
if (flags & SDL_RENDERER_PRESENTFLIP2) {
renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
Jul 15, 2006
Jul 15, 2006
104
n = 2;
Aug 5, 2006
Aug 5, 2006
105
106
} else if (flags & SDL_RENDERER_PRESENTFLIP3) {
renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
Jul 15, 2006
Jul 15, 2006
107
108
n = 3;
} else {
Aug 5, 2006
Aug 5, 2006
109
renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
Jul 15, 2006
Jul 15, 2006
110
n = 1;
Jul 15, 2006
Jul 15, 2006
112
113
114
115
116
117
118
119
120
121
122
for (i = 0; i < n; ++i) {
data->screens[i] =
SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
Bmask, Amask);
if (!data->screens[i]) {
SDL_DUMMY_DestroyRenderer(renderer);
return NULL;
}
SDL_SetSurfacePalette(data->screens[i], display->palette);
}
data->current_screen = 0;
123
124
125
126
return renderer;
}
Jul 15, 2006
Jul 15, 2006
127
static int
Aug 28, 2006
Aug 28, 2006
128
129
SDL_DUMMY_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
Uint8 a, const SDL_Rect * rect)
Jul 15, 2006
Jul 15, 2006
130
{
Jul 16, 2006
Jul 16, 2006
131
132
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
Jul 15, 2006
Jul 15, 2006
133
SDL_Surface *target = data->screens[data->current_screen];
Aug 28, 2006
Aug 28, 2006
134
Uint32 color;
Jul 15, 2006
Jul 15, 2006
135
136
137
138
139
140
141
142
143
SDL_Rect real_rect = *rect;
color = SDL_MapRGBA(target->format, r, g, b, a);
return SDL_FillRect(target, &real_rect, color);
}
static int
SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
Aug 28, 2006
Aug 28, 2006
144
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
Jul 15, 2006
Jul 15, 2006
145
{
Jul 16, 2006
Jul 16, 2006
146
147
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
Jul 15, 2006
Jul 15, 2006
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
SDL_Surface *target = data->screens[data->current_screen];
void *pixels =
(Uint8 *) target->pixels + dstrect->y * target->pitch +
dstrect->x * target->format->BytesPerPixel;
return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
srcrect, display->current_mode.format,
dstrect->w, dstrect->h, pixels,
target->pitch);
} else {
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
SDL_Surface *target = data->screens[data->current_screen];
Aug 28, 2006
Aug 28, 2006
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
SDL_RenderCopyFunc copyfunc = (SDL_RenderCopyFunc) surface->userdata;
if (copyfunc) {
SDL_RenderCopyData copydata;
copydata.src =
(Uint8 *) surface->pixels + srcrect->y * surface->pitch +
srcrect->x * surface->format->BytesPerPixel;
copydata.src_w = srcrect->w;
copydata.src_h = srcrect->h;
copydata.src_pitch = surface->pitch;
copydata.dst =
(Uint8 *) target->pixels + dstrect->y * target->pitch +
dstrect->x * target->format->BytesPerPixel;
copydata.dst_w = dstrect->w;
copydata.dst_h = dstrect->h;
copydata.dst_pitch = target->pitch;
copydata.flags = 0;
if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
copydata.flags |= SDL_RENDERCOPY_MODULATE_COLOR;
copydata.r = texture->r;
copydata.g = texture->g;
copydata.b = texture->b;
}
if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
copydata.flags |= SDL_RENDERCOPY_MODULATE_ALPHA;
copydata.a = texture->a;
}
Aug 28, 2006
Aug 28, 2006
191
192
193
if (texture->blendMode & SDL_TEXTUREBLENDMODE_MASK) {
copydata.flags |= SDL_RENDERCOPY_MASK;
} else if (texture->blendMode & SDL_TEXTUREBLENDMODE_BLEND) {
Aug 28, 2006
Aug 28, 2006
194
195
196
197
198
199
200
201
202
copydata.flags |= SDL_RENDERCOPY_BLEND;
} else if (texture->blendMode & SDL_TEXTUREBLENDMODE_ADD) {
copydata.flags |= SDL_RENDERCOPY_ADD;
} else if (texture->blendMode & SDL_TEXTUREBLENDMODE_MOD) {
copydata.flags |= SDL_RENDERCOPY_MOD;
}
if (texture->scaleMode) {
copydata.flags |= SDL_RENDERCOPY_NEAREST;
}
Aug 17, 2007
Aug 17, 2007
203
204
copyfunc(&copydata);
return 0;
Jul 15, 2006
Jul 15, 2006
205
} else {
Aug 28, 2006
Aug 28, 2006
206
207
208
SDL_Rect real_srcrect = *srcrect;
SDL_Rect real_dstrect = *dstrect;
Jul 16, 2006
Jul 16, 2006
209
210
return SDL_LowerBlit(surface, &real_srcrect, target,
&real_dstrect);
Jul 15, 2006
Jul 15, 2006
211
212
213
214
215
}
}
}
static void
216
217
218
SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
{
static int frame_number;
Jul 16, 2006
Jul 16, 2006
219
220
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
Jul 15, 2006
Jul 15, 2006
222
/* Send the data to the display */
223
224
225
226
if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
char file[128];
SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
renderer->window, ++frame_number);
Jul 15, 2006
Jul 15, 2006
227
228
229
230
SDL_SaveBMP(data->screens[data->current_screen], file);
}
/* Update the flipping chain, if any */
Aug 5, 2006
Aug 5, 2006
231
if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
Jul 15, 2006
Jul 15, 2006
232
data->current_screen = (data->current_screen + 1) % 2;
Aug 5, 2006
Aug 5, 2006
233
} else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
Jul 15, 2006
Jul 15, 2006
234
235
236
237
238
data->current_screen = (data->current_screen + 1) % 3;
}
}
static void
239
240
SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer)
{
Jul 16, 2006
Jul 16, 2006
241
242
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
Jul 15, 2006
Jul 15, 2006
243
int i;
Jul 15, 2006
Jul 15, 2006
246
247
248
249
for (i = 0; i < SDL_arraysize(data->screens); ++i) {
if (data->screens[i]) {
SDL_FreeSurface(data->screens[i]);
}
250
251
252
253
254
255
256
}
SDL_free(data);
}
SDL_free(renderer);
}
/* vi: set ts=4 sw=4 expandtab: */