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

Latest commit

 

History

History
195 lines (168 loc) · 5.75 KB

SDL_nullrender.c

File metadata and controls

195 lines (168 loc) · 5.75 KB
 
Jun 13, 2006
Jun 13, 2006
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
26
27
28
29
30
31
32
33
34
/*
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"
/* SDL surface based renderer implementation */
static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
Uint32 flags);
static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
Jun 16, 2006
Jun 16, 2006
35
const SDL_Rect * rect, void *pixels,
Jun 13, 2006
Jun 13, 2006
36
37
int pitch);
static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
Jun 16, 2006
Jun 16, 2006
38
39
const SDL_Rect * rect,
const void *pixels, int pitch);
Jun 13, 2006
Jun 13, 2006
40
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,
{
"minimal",
Jun 14, 2006
Jun 14, 2006
48
49
(SDL_Renderer_Minimal | SDL_Renderer_PresentDiscard |
SDL_Renderer_PresentCopy),
Jun 13, 2006
Jun 13, 2006
50
51
52
53
54
55
56
57
58
59
SDL_TextureBlendMode_None,
SDL_TextureScaleMode_None,
0,
{},
0,
0}
};
typedef struct
{
Jun 16, 2006
Jun 16, 2006
60
SDL_Surface *surface;
Jun 13, 2006
Jun 13, 2006
61
62
63
64
65
} SDL_DUMMY_RenderData;
SDL_Renderer *
SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags)
{
Jun 24, 2006
Jun 24, 2006
66
67
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_DisplayMode *displayMode = &display->current_mode;
Jun 13, 2006
Jun 13, 2006
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
SDL_Renderer *renderer;
SDL_DUMMY_RenderData *data;
int i, n;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (!SDL_PixelFormatEnumToMasks
(displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown display format");
return NULL;
}
renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
SDL_zerop(renderer);
data = (SDL_DUMMY_RenderData *) SDL_malloc(sizeof(*data));
if (!data) {
SDL_DUMMY_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
}
SDL_zerop(data);
renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels;
renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels;
renderer->RenderPresent = SDL_DUMMY_RenderPresent;
renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer;
renderer->info = SDL_DUMMY_RenderDriver.info;
Jun 24, 2006
Jun 24, 2006
100
renderer->window = window->id;
Jun 13, 2006
Jun 13, 2006
101
102
renderer->driverdata = data;
Jun 16, 2006
Jun 16, 2006
103
data->surface =
Jun 13, 2006
Jun 13, 2006
104
105
SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
Bmask, Amask);
Jun 16, 2006
Jun 16, 2006
106
if (!data->surface) {
Jun 13, 2006
Jun 13, 2006
107
108
109
SDL_DUMMY_DestroyRenderer(renderer);
return NULL;
}
Jun 24, 2006
Jun 24, 2006
110
SDL_SetSurfacePalette(data->surface, display->palette);
Jun 16, 2006
Jun 16, 2006
111
Jun 13, 2006
Jun 13, 2006
112
113
114
115
return renderer;
}
int
Jun 16, 2006
Jun 16, 2006
116
SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Jun 13, 2006
Jun 13, 2006
117
118
119
120
void *pixels, int pitch)
{
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
Jun 16, 2006
Jun 16, 2006
121
SDL_Surface *surface = data->surface;
Jun 13, 2006
Jun 13, 2006
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Uint8 *src, *dst;
int row;
size_t length;
src =
(Uint8 *) surface->pixels + rect->y * surface->pitch +
rect->x * surface->format->BytesPerPixel;
dst = (Uint8 *) pixels;
length = rect->w * surface->format->BytesPerPixel;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += surface->pitch;
dst += pitch;
}
return 0;
}
int
Jun 16, 2006
Jun 16, 2006
140
SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Jun 13, 2006
Jun 13, 2006
141
142
143
144
const void *pixels, int pitch)
{
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
Jun 16, 2006
Jun 16, 2006
145
SDL_Surface *surface = data->surface;
Jun 13, 2006
Jun 13, 2006
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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;
}
return 0;
}
void
SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
{
static int frame_number;
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
Jun 16, 2006
Jun 16, 2006
169
SDL_Surface *surface = data->surface;
Jun 13, 2006
Jun 13, 2006
170
171
172
if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
char file[128];
Jun 17, 2006
Jun 17, 2006
173
SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
Jun 24, 2006
Jun 24, 2006
174
renderer->window, ++frame_number);
Jun 13, 2006
Jun 13, 2006
175
176
177
178
179
180
181
182
183
184
185
SDL_SaveBMP(surface, file);
}
}
void
SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer)
{
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
if (data) {
Jun 16, 2006
Jun 16, 2006
186
187
188
if (data->surface) {
data->surface->format->palette = NULL;
SDL_FreeSurface(data->surface);
Jun 13, 2006
Jun 13, 2006
189
190
191
192
193
194
195
}
SDL_free(data);
}
SDL_free(renderer);
}
/* vi: set ts=4 sw=4 expandtab: */