Mercurial > sdl-ios-xcode
comparison src/video/fbcon-1.3/SDL_fbrender.c @ 3158:30f3b987fec3 gsoc2009_ps3
created env (fbcon-1.3) and added basic files
author | Martin Lowinski <martin@goldtopf.org> |
---|---|
date | Sat, 07 Nov 2009 11:35:19 +0000 |
parents | |
children | 2632b7453516 |
comparison
equal
deleted
inserted
replaced
3157:cce01ba54174 | 3158:30f3b987fec3 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2009 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this library; if not, write to the Free Software | |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 #include "SDL_config.h" | |
23 | |
24 #include "SDL_video.h" | |
25 #include "../SDL_sysvideo.h" | |
26 #include "../SDL_yuv_sw_c.h" | |
27 #include "../SDL_renderer_sw.h" | |
28 | |
29 | |
30 /* SDL surface based renderer implementation */ | |
31 | |
32 static SDL_Renderer *SDL_FB_CreateRenderer(SDL_Window * window, | |
33 Uint32 flags); | |
34 static int SDL_FB_RenderPoint(SDL_Renderer * renderer, int x, int y); | |
35 static int SDL_FB_RenderLine(SDL_Renderer * renderer, int x1, int y1, | |
36 int x2, int y2); | |
37 static int SDL_FB_RenderFill(SDL_Renderer * renderer, | |
38 const SDL_Rect * rect); | |
39 static int SDL_FB_RenderCopy(SDL_Renderer * renderer, | |
40 SDL_Texture * texture, | |
41 const SDL_Rect * srcrect, | |
42 const SDL_Rect * dstrect); | |
43 static void SDL_FB_RenderPresent(SDL_Renderer * renderer); | |
44 static void SDL_FB_DestroyRenderer(SDL_Renderer * renderer); | |
45 | |
46 | |
47 SDL_RenderDriver SDL_FB_RenderDriver = { | |
48 SDL_FB_CreateRenderer, | |
49 { | |
50 "fbcon", | |
51 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | | |
52 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | | |
53 SDL_RENDERER_PRESENTDISCARD), | |
54 } | |
55 }; | |
56 | |
57 typedef struct | |
58 { | |
59 int current_screen; | |
60 SDL_Surface *screens[3]; | |
61 } SDL_FB_RenderData; | |
62 | |
63 SDL_Renderer * | |
64 SDL_FB_CreateRenderer(SDL_Window * window, Uint32 flags) | |
65 { | |
66 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | |
67 SDL_DisplayMode *displayMode = &display->current_mode; | |
68 SDL_Renderer *renderer; | |
69 SDL_FB_RenderData *data; | |
70 int i, n; | |
71 int bpp; | |
72 Uint32 Rmask, Gmask, Bmask, Amask; | |
73 | |
74 if (!SDL_PixelFormatEnumToMasks | |
75 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | |
76 SDL_SetError("Unknown display format"); | |
77 return NULL; | |
78 } | |
79 | |
80 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); | |
81 if (!renderer) { | |
82 SDL_OutOfMemory(); | |
83 return NULL; | |
84 } | |
85 | |
86 data = (SDL_FB_RenderData *) SDL_malloc(sizeof(*data)); | |
87 if (!data) { | |
88 SDL_FB_DestroyRenderer(renderer); | |
89 SDL_OutOfMemory(); | |
90 return NULL; | |
91 } | |
92 SDL_zerop(data); | |
93 | |
94 renderer->RenderPoint = SDL_FB_RenderPoint; | |
95 renderer->RenderLine = SDL_FB_RenderLine; | |
96 renderer->RenderFill = SDL_FB_RenderFill; | |
97 renderer->RenderCopy = SDL_FB_RenderCopy; | |
98 renderer->RenderPresent = SDL_FB_RenderPresent; | |
99 renderer->DestroyRenderer = SDL_FB_DestroyRenderer; | |
100 renderer->info.name = SDL_FB_RenderDriver.info.name; | |
101 renderer->info.flags = 0; | |
102 renderer->window = window->id; | |
103 renderer->driverdata = data; | |
104 Setup_SoftwareRenderer(renderer); | |
105 | |
106 if (flags & SDL_RENDERER_PRESENTFLIP2) { | |
107 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; | |
108 n = 2; | |
109 } else if (flags & SDL_RENDERER_PRESENTFLIP3) { | |
110 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3; | |
111 n = 3; | |
112 } else { | |
113 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY; | |
114 n = 1; | |
115 } | |
116 for (i = 0; i < n; ++i) { | |
117 data->screens[i] = | |
118 SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask, | |
119 Bmask, Amask); | |
120 if (!data->screens[i]) { | |
121 SDL_FB_DestroyRenderer(renderer); | |
122 return NULL; | |
123 } | |
124 SDL_SetSurfacePalette(data->screens[i], display->palette); | |
125 } | |
126 data->current_screen = 0; | |
127 | |
128 return renderer; | |
129 } | |
130 | |
131 static int | |
132 SDL_FB_RenderPoint(SDL_Renderer * renderer, int x, int y) | |
133 { | |
134 SDL_FB_RenderData *data = | |
135 (SDL_FB_RenderData *) renderer->driverdata; | |
136 SDL_Surface *target = data->screens[data->current_screen]; | |
137 int status; | |
138 | |
139 if (renderer->blendMode == SDL_BLENDMODE_NONE || | |
140 renderer->blendMode == SDL_BLENDMODE_MASK) { | |
141 Uint32 color = | |
142 SDL_MapRGBA(target->format, renderer->r, renderer->g, renderer->b, | |
143 renderer->a); | |
144 | |
145 status = SDL_DrawPoint(target, x, y, color); | |
146 } else { | |
147 status = | |
148 SDL_BlendPoint(target, x, y, renderer->blendMode, renderer->r, | |
149 renderer->g, renderer->b, renderer->a); | |
150 } | |
151 return status; | |
152 } | |
153 | |
154 static int | |
155 SDL_FB_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | |
156 { | |
157 SDL_FB_RenderData *data = | |
158 (SDL_FB_RenderData *) renderer->driverdata; | |
159 SDL_Surface *target = data->screens[data->current_screen]; | |
160 int status; | |
161 | |
162 if (renderer->blendMode == SDL_BLENDMODE_NONE || | |
163 renderer->blendMode == SDL_BLENDMODE_MASK) { | |
164 Uint32 color = | |
165 SDL_MapRGBA(target->format, renderer->r, renderer->g, renderer->b, | |
166 renderer->a); | |
167 | |
168 status = SDL_DrawLine(target, x1, y1, x2, y2, color); | |
169 } else { | |
170 status = | |
171 SDL_BlendLine(target, x1, y1, x2, y2, renderer->blendMode, | |
172 renderer->r, renderer->g, renderer->b, renderer->a); | |
173 } | |
174 return status; | |
175 } | |
176 | |
177 static int | |
178 SDL_FB_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) | |
179 { | |
180 SDL_FB_RenderData *data = | |
181 (SDL_FB_RenderData *) renderer->driverdata; | |
182 SDL_Surface *target = data->screens[data->current_screen]; | |
183 SDL_Rect real_rect = *rect; | |
184 int status; | |
185 | |
186 if (renderer->blendMode == SDL_BLENDMODE_NONE) { | |
187 Uint32 color = | |
188 SDL_MapRGBA(target->format, renderer->r, renderer->g, renderer->b, | |
189 renderer->a); | |
190 | |
191 status = SDL_FillRect(target, &real_rect, color); | |
192 } else { | |
193 status = | |
194 SDL_BlendRect(target, &real_rect, renderer->blendMode, | |
195 renderer->r, renderer->g, renderer->b, renderer->a); | |
196 } | |
197 return status; | |
198 } | |
199 | |
200 static int | |
201 SDL_FB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | |
202 const SDL_Rect * srcrect, const SDL_Rect * dstrect) | |
203 { | |
204 SDL_FB_RenderData *data = | |
205 (SDL_FB_RenderData *) renderer->driverdata; | |
206 SDL_Window *window = SDL_GetWindowFromID(renderer->window); | |
207 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | |
208 | |
209 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { | |
210 SDL_Surface *target = data->screens[data->current_screen]; | |
211 void *pixels = | |
212 (Uint8 *) target->pixels + dstrect->y * target->pitch + | |
213 dstrect->x * target->format->BytesPerPixel; | |
214 return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata, | |
215 srcrect, display->current_mode.format, | |
216 dstrect->w, dstrect->h, pixels, | |
217 target->pitch); | |
218 } else { | |
219 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; | |
220 SDL_Surface *target = data->screens[data->current_screen]; | |
221 SDL_Rect real_srcrect = *srcrect; | |
222 SDL_Rect real_dstrect = *dstrect; | |
223 | |
224 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); | |
225 } | |
226 } | |
227 | |
228 static void | |
229 SDL_FB_RenderPresent(SDL_Renderer * renderer) | |
230 { | |
231 static int frame_number; | |
232 SDL_FB_RenderData *data = | |
233 (SDL_FB_RenderData *) renderer->driverdata; | |
234 | |
235 /* Send the data to the display */ | |
236 if (SDL_getenv("SDL_VIDEO_FB_SAVE_FRAMES")) { | |
237 char file[128]; | |
238 SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp", | |
239 renderer->window, ++frame_number); | |
240 SDL_SaveBMP(data->screens[data->current_screen], file); | |
241 } | |
242 | |
243 /* Update the flipping chain, if any */ | |
244 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) { | |
245 data->current_screen = (data->current_screen + 1) % 2; | |
246 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) { | |
247 data->current_screen = (data->current_screen + 1) % 3; | |
248 } | |
249 } | |
250 | |
251 static void | |
252 SDL_FB_DestroyRenderer(SDL_Renderer * renderer) | |
253 { | |
254 SDL_FB_RenderData *data = | |
255 (SDL_FB_RenderData *) renderer->driverdata; | |
256 int i; | |
257 | |
258 if (data) { | |
259 for (i = 0; i < SDL_arraysize(data->screens); ++i) { | |
260 if (data->screens[i]) { | |
261 SDL_FreeSurface(data->screens[i]); | |
262 } | |
263 } | |
264 SDL_free(data); | |
265 } | |
266 SDL_free(renderer); | |
267 } | |
268 | |
269 /* vi: set ts=4 sw=4 expandtab: */ |