Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_photon_render.c @ 3092:cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
From: "Mike Gorchak"
Subject: New QNX patches
In photon.tar.gz there are new files to be placed into ./src/video/photon/
directory.
qnx3.diff - new patches for QNX support. Since I've found a lot of bugs in
the new GF QNX Graphics Framework and I'm suspended development for GF
driver until already found bugs will be fixed and switched to Photon driver
implementation.
sdl.diff - I've found that renderer creation result has not been checked and
SDL shows error like: "there is no current renderer", now SDL will show
correct error which was set be renderer.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 17 Mar 2009 03:24:22 +0000 |
parents | |
children | aa1897bee1e9 |
comparison
equal
deleted
inserted
replaced
3091:32efcc94b3da | 3092:cad1aefa2ed9 |
---|---|
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 QNX Photon GUI SDL driver | |
23 Copyright (C) 2009 Mike Gorchak | |
24 (mike@malva.ua, lestat@i.com.ua) | |
25 */ | |
26 | |
27 #include "SDL_config.h" | |
28 | |
29 #include "../SDL_pixels_c.h" | |
30 #include "../SDL_yuv_sw_c.h" | |
31 | |
32 #include "SDL_video.h" | |
33 | |
34 #include "SDL_photon_render.h" | |
35 #include "SDL_photon.h" | |
36 | |
37 static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags); | |
38 static int photon_displaymodechanged(SDL_Renderer* renderer); | |
39 static int photon_activaterenderer(SDL_Renderer* renderer); | |
40 static int photon_createtexture(SDL_Renderer* renderer, SDL_Texture* texture); | |
41 static int photon_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch); | |
42 static int photon_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors); | |
43 static int photon_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors); | |
44 static int photon_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture); | |
45 static int photon_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture); | |
46 static int photon_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture); | |
47 static int photon_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture); | |
48 static int photon_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch); | |
49 static int photon_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch); | |
50 static void photon_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture); | |
51 static void photon_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects); | |
52 static int photon_renderpoint(SDL_Renderer* renderer, int x, int y); | |
53 static int photon_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2); | |
54 static int photon_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect); | |
55 static int photon_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect); | |
56 static void photon_renderpresent(SDL_Renderer* renderer); | |
57 static void photon_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture); | |
58 static void photon_destroyrenderer(SDL_Renderer* renderer); | |
59 | |
60 SDL_RenderDriver photon_renderdriver= | |
61 { | |
62 photon_createrenderer, | |
63 { | |
64 "photon", | |
65 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | | |
66 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | | |
67 SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_PRESENTDISCARD | | |
68 SDL_RENDERER_ACCELERATED), | |
69 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | | |
70 SDL_TEXTUREMODULATE_ALPHA), | |
71 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | | |
72 SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), | |
73 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW), | |
74 13, | |
75 { | |
76 SDL_PIXELFORMAT_INDEX8, | |
77 SDL_PIXELFORMAT_RGB555, | |
78 SDL_PIXELFORMAT_RGB565, | |
79 SDL_PIXELFORMAT_RGB888, | |
80 SDL_PIXELFORMAT_BGR888, | |
81 SDL_PIXELFORMAT_ARGB8888, | |
82 SDL_PIXELFORMAT_RGBA8888, | |
83 SDL_PIXELFORMAT_ABGR8888, | |
84 SDL_PIXELFORMAT_BGRA8888, | |
85 SDL_PIXELFORMAT_YV12, | |
86 SDL_PIXELFORMAT_YUY2, | |
87 SDL_PIXELFORMAT_UYVY, | |
88 SDL_PIXELFORMAT_YVYU | |
89 }, | |
90 0, | |
91 0 | |
92 } | |
93 }; | |
94 | |
95 static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags) | |
96 { | |
97 SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(window); | |
98 SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata; | |
99 SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata; | |
100 SDL_Renderer* renderer = NULL; | |
101 SDL_RenderData* rdata = NULL; | |
102 | |
103 /* Allocate new renderer structure */ | |
104 renderer=(SDL_Renderer*)SDL_calloc(1, sizeof(SDL_Renderer)); | |
105 if (renderer==NULL) | |
106 { | |
107 SDL_OutOfMemory(); | |
108 return NULL; | |
109 } | |
110 | |
111 /* Allocate renderer data */ | |
112 rdata=(SDL_RenderData*)SDL_calloc(1, sizeof(SDL_RenderData)); | |
113 if (rdata==NULL) | |
114 { | |
115 SDL_free(renderer); | |
116 SDL_OutOfMemory(); | |
117 return NULL; | |
118 } | |
119 | |
120 renderer->DisplayModeChanged=photon_displaymodechanged; | |
121 renderer->ActivateRenderer=photon_activaterenderer; | |
122 renderer->CreateTexture=photon_createtexture; | |
123 renderer->QueryTexturePixels=photon_querytexturepixels; | |
124 renderer->SetTexturePalette=photon_settexturepalette; | |
125 renderer->GetTexturePalette=photon_gettexturepalette; | |
126 renderer->SetTextureAlphaMod=photon_settexturealphamod; | |
127 renderer->SetTextureColorMod=photon_settexturecolormod; | |
128 renderer->SetTextureBlendMode=photon_settextureblendmode; | |
129 renderer->SetTextureScaleMode=photon_settexturescalemode; | |
130 renderer->UpdateTexture=photon_updatetexture; | |
131 renderer->LockTexture=photon_locktexture; | |
132 renderer->UnlockTexture=photon_unlocktexture; | |
133 renderer->DirtyTexture=photon_dirtytexture; | |
134 renderer->RenderPoint=photon_renderpoint; | |
135 renderer->RenderLine=photon_renderline; | |
136 renderer->RenderFill=photon_renderfill; | |
137 renderer->RenderCopy=photon_rendercopy; | |
138 renderer->RenderPresent = photon_renderpresent; | |
139 renderer->DestroyTexture = photon_destroytexture; | |
140 renderer->DestroyRenderer = photon_destroyrenderer; | |
141 renderer->info = photon_renderdriver.info; | |
142 renderer->window = window->id; | |
143 renderer->driverdata = rdata; | |
144 | |
145 /* Set render acceleration flag in case it is accelerated */ | |
146 if ((didata->caps & SDL_PHOTON_ACCELERATED)==SDL_PHOTON_ACCELERATED) | |
147 { | |
148 renderer->info.flags=SDL_RENDERER_ACCELERATED; | |
149 } | |
150 else | |
151 { | |
152 renderer->info.flags&=~(SDL_RENDERER_ACCELERATED); | |
153 } | |
154 | |
155 rdata->window=window; | |
156 | |
157 /* Check if upper level requested synchronization on vsync signal */ | |
158 if ((flags & SDL_RENDERER_PRESENTVSYNC)==SDL_RENDERER_PRESENTVSYNC) | |
159 { | |
160 rdata->enable_vsync=SDL_TRUE; | |
161 } | |
162 else | |
163 { | |
164 rdata->enable_vsync=SDL_FALSE; | |
165 } | |
166 | |
167 /* Check what buffer copy/flip scheme is requested */ | |
168 rdata->surfaces_count=0; | |
169 if ((flags & SDL_RENDERER_SINGLEBUFFER)==SDL_RENDERER_SINGLEBUFFER) | |
170 { | |
171 if ((flags & SDL_RENDERER_PRESENTDISCARD)==SDL_RENDERER_PRESENTDISCARD) | |
172 { | |
173 renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD; | |
174 } | |
175 else | |
176 { | |
177 renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY; | |
178 } | |
179 rdata->surfaces_count=1; | |
180 rdata->surface_visible_idx=0; | |
181 rdata->surface_render_idx=0; | |
182 } | |
183 else | |
184 { | |
185 if ((flags & SDL_RENDERER_PRESENTFLIP2)==SDL_RENDERER_PRESENTFLIP2) | |
186 { | |
187 renderer->info.flags|=SDL_RENDERER_PRESENTFLIP2; | |
188 rdata->surfaces_count=2; | |
189 rdata->surface_visible_idx=0; | |
190 rdata->surface_render_idx=1; | |
191 } | |
192 else | |
193 { | |
194 if ((flags & SDL_RENDERER_PRESENTFLIP3)==SDL_RENDERER_PRESENTFLIP3) | |
195 { | |
196 renderer->info.flags|=SDL_RENDERER_PRESENTFLIP3; | |
197 rdata->surfaces_count=3; | |
198 rdata->surface_visible_idx=0; | |
199 rdata->surface_render_idx=1; | |
200 } | |
201 else | |
202 { | |
203 renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY; | |
204 rdata->surfaces_count=1; | |
205 rdata->surface_visible_idx=0; | |
206 rdata->surface_render_idx=0; | |
207 } | |
208 } | |
209 } | |
210 | |
211 return renderer; | |
212 } | |
213 | |
214 void photon_addrenderdriver(_THIS) | |
215 { | |
216 uint32_t it; | |
217 | |
218 for (it=0; it<_this->num_displays; it++) | |
219 { | |
220 SDL_AddRenderDriver(it, &photon_renderdriver); | |
221 } | |
222 } | |
223 | |
224 /****************************************************************************/ | |
225 /* SDL render interface */ | |
226 /****************************************************************************/ | |
227 static int photon_displaymodechanged(SDL_Renderer* renderer) | |
228 { | |
229 SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; | |
230 | |
231 /* Remove all allocated surfaces, they are no more valid */ | |
232 | |
233 /* TODO: Add video mode change detection and new parameters detection */ | |
234 | |
235 return 0; | |
236 } | |
237 | |
238 static int photon_activaterenderer(SDL_Renderer* renderer) | |
239 { | |
240 SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; | |
241 SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(rdata->window); | |
242 SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata; | |
243 | |
244 return 0; | |
245 } | |
246 | |
247 static int photon_createtexture(SDL_Renderer* renderer, SDL_Texture* texture) | |
248 { | |
249 SDL_RenderData* renderdata=(SDL_RenderData*)renderer->driverdata; | |
250 SDL_Window* window=SDL_GetWindowFromID(renderer->window); | |
251 SDL_VideoDisplay* display=SDL_GetDisplayFromWindow(window); | |
252 SDL_TextureData* tdata=NULL; | |
253 | |
254 /* Allocate texture driver data */ | |
255 tdata=(SDL_TextureData*)SDL_calloc(1, sizeof(SDL_TextureData)); | |
256 if (tdata==NULL) | |
257 { | |
258 SDL_OutOfMemory(); | |
259 return -1; | |
260 } | |
261 | |
262 /* Set texture driver data */ | |
263 texture->driverdata=tdata; | |
264 | |
265 } | |
266 | |
267 static int photon_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch) | |
268 { | |
269 } | |
270 | |
271 static int photon_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors) | |
272 { | |
273 } | |
274 | |
275 static int photon_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors) | |
276 { | |
277 } | |
278 | |
279 static int photon_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture) | |
280 { | |
281 } | |
282 | |
283 static int photon_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture) | |
284 { | |
285 } | |
286 | |
287 static int photon_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture) | |
288 { | |
289 } | |
290 | |
291 static int photon_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture) | |
292 { | |
293 } | |
294 | |
295 static int photon_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch) | |
296 { | |
297 } | |
298 | |
299 static int photon_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch) | |
300 { | |
301 } | |
302 | |
303 static void photon_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture) | |
304 { | |
305 } | |
306 | |
307 static void photon_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects) | |
308 { | |
309 } | |
310 | |
311 static int photon_renderpoint(SDL_Renderer* renderer, int x, int y) | |
312 { | |
313 } | |
314 | |
315 static int photon_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2) | |
316 { | |
317 } | |
318 | |
319 static int photon_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect) | |
320 { | |
321 } | |
322 | |
323 static int photon_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect) | |
324 { | |
325 } | |
326 | |
327 static void photon_renderpresent(SDL_Renderer* renderer) | |
328 { | |
329 } | |
330 | |
331 static void photon_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture) | |
332 { | |
333 } | |
334 | |
335 static void photon_destroyrenderer(SDL_Renderer* renderer) | |
336 { | |
337 SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; | |
338 uint32_t it; | |
339 | |
340 } | |
341 | |
342 /* vi: set ts=4 sw=4 expandtab: */ |