Mercurial > sdl-ios-xcode
annotate src/video/win32/SDL_ceddrawrender.c @ 4425:a3e71b957215
Fixed bug #961
Kalle Olavi Niemitalo 2010-02-28 09:15:50 PST
It seems the SDLK_LMETA and SDLK_RMETA constants have been removed from SDL
1.3. I grepped for them in the SDL source tree and these were the only hits:
./include/SDL_compat.h:230:#define SDLK_LSUPER SDLK_LMETA
./include/SDL_compat.h:231:#define SDLK_RSUPER SDLK_RMETA
./src/video/bwindow/SDL_BWin.h:194: keymap[0x66] = SDLK_LMETA;
./src/video/bwindow/SDL_BWin.h:195: keymap[0x67] = SDLK_RMETA;
I don't know how compatible SDL 1.3 is supposed to be with applications
designed for SDL 1.2. However, as you can see, SDL itself is still trying to
use the removed constants, and that is clearly a bug.
Because SDL_compat.h defines KMOD_LMETA as KMOD_LGUI, I suppose it should also
define SDLK_LMETA as SDLK_LGUI, and SDLK_RMETA likewise.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 09 Mar 2010 06:07:48 +0000 |
parents | f7b03b6838cb |
children | e1664f94f026 |
rev | line source |
---|---|
3168 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
3168 | 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 Stefan Klug | |
23 klug.stefan@gmx.de | |
24 */ | |
25 #include "SDL_config.h" | |
26 | |
27 #if SDL_VIDEO_RENDER_DDRAW | |
28 | |
29 #include "SDL_win32video.h" | |
30 #include "../SDL_yuv_sw_c.h" | |
31 | |
32 #if 0 | |
33 #define DDRAW_LOG(...) printf(__VA_ARGS__) | |
34 #else | |
35 #define DDRAW_LOG(...) | |
36 #endif | |
37 | |
38 | |
39 /* DirectDraw renderer implementation */ | |
40 | |
41 static SDL_Renderer *DDRAW_CreateRenderer(SDL_Window * window, Uint32 flags); | |
42 static int DDRAW_DisplayModeChanged(SDL_Renderer * renderer); | |
43 static int DDRAW_CreateTexture(SDL_Renderer * renderer, | |
44 SDL_Texture * texture); | |
45 static int DDRAW_QueryTexturePixels(SDL_Renderer * renderer, | |
46 SDL_Texture * texture, void **pixels, | |
47 int *pitch); | |
48 static int DDRAW_SetTextureColorMod(SDL_Renderer * renderer, | |
49 SDL_Texture * texture); | |
50 static int DDRAW_SetTextureAlphaMod(SDL_Renderer * renderer, | |
51 SDL_Texture * texture); | |
52 static int DDRAW_SetTextureBlendMode(SDL_Renderer * renderer, | |
53 SDL_Texture * texture); | |
54 static int DDRAW_SetTextureScaleMode(SDL_Renderer * renderer, | |
55 SDL_Texture * texture); | |
56 static int DDRAW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
57 const SDL_Rect * rect, const void *pixels, | |
58 int pitch); | |
59 static int DDRAW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
60 const SDL_Rect * rect, int markDirty, | |
61 void **pixels, int *pitch); | |
62 static void DDRAW_UnlockTexture(SDL_Renderer * renderer, | |
63 SDL_Texture * texture); | |
64 static void DDRAW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
65 int numrects, const SDL_Rect * rects); | |
66 static int DDRAW_RenderPoint(SDL_Renderer * renderer, int x, int y); | |
67 static int DDRAW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, | |
68 int y2); | |
69 static int DDRAW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); | |
70 static int DDRAW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | |
71 const SDL_Rect * srcrect, | |
72 const SDL_Rect * dstrect); | |
73 static void DDRAW_RenderPresent(SDL_Renderer * renderer); | |
74 static void DDRAW_DestroyTexture(SDL_Renderer * renderer, | |
75 SDL_Texture * texture); | |
76 static void DDRAW_DestroyRenderer(SDL_Renderer * renderer); | |
77 | |
78 | |
79 SDL_RenderDriver DDRAW_RenderDriver = { | |
80 DDRAW_CreateRenderer, | |
81 { | |
82 "ddraw", | |
83 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | | |
84 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | | |
85 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED), | |
86 (SDL_TEXTUREMODULATE_NONE), | |
87 (SDL_BLENDMODE_NONE), | |
88 (SDL_TEXTURESCALEMODE_NONE), | |
89 0, | |
90 {0}, | |
91 0, | |
92 0} | |
93 }; | |
94 | |
95 typedef struct | |
96 { | |
97 IDirectDraw *ddraw; | |
98 IDirectDrawSurface *primary; | |
99 } DDRAW_RenderData; | |
100 | |
101 typedef struct | |
102 { | |
103 RECT lock; | |
104 IDirectDrawSurface *surface; | |
105 } DDRAW_TextureData; | |
106 | |
107 | |
108 static void | |
109 DDRAW_SetError(const char *prefix, HRESULT result) | |
110 { | |
111 const char *error; | |
112 | |
113 switch (result) { | |
114 case DDERR_CANTCREATEDC: | |
115 error = "CANTCREATEDC"; | |
116 break; | |
117 case DDERR_CANTLOCKSURFACE: | |
118 error = "CANTLOCKSURFACE"; | |
119 break; | |
120 case DDERR_CLIPPERISUSINGHWND: | |
121 error = "CLIPPERISUSINGHWND"; | |
122 break; | |
123 case DDERR_COLORKEYNOTSET: | |
124 error = "COLORKEYNOTSET"; | |
125 break; | |
126 case DDERR_CURRENTLYNOTAVAIL: | |
127 error = "CURRENTLYNOTAVAIL"; | |
128 break; | |
129 case DDERR_DCALREADYCREATED: | |
130 error = "DCALREADYCREATED"; | |
131 break; | |
132 case DDERR_DEVICEDOESNTOWNSURFACE: | |
133 error = "DEVICEDOESNTOWNSURFACE"; | |
134 break; | |
135 case DDERR_DIRECTDRAWALREADYCREATED: | |
136 error = "DIRECTDRAWALREADYCREATED"; | |
137 break; | |
138 case DDERR_EXCLUSIVEMODEALREADYSET: | |
139 error = "EXCLUSIVEMODEALREADYSET"; | |
140 break; | |
141 case DDERR_GENERIC: | |
142 error = "GENERIC"; | |
143 break; | |
144 case DDERR_HEIGHTALIGN: | |
145 error = "HEIGHTALIGN"; | |
146 break; | |
147 case DDERR_IMPLICITLYCREATED: | |
148 error = "IMPLICITLYCREATED"; | |
149 break; | |
150 case DDERR_INCOMPATIBLEPRIMARY: | |
151 error = "INCOMPATIBLEPRIMARY"; | |
152 break; | |
153 case DDERR_INVALIDCAPS: | |
154 error = "INVALIDCAPS"; | |
155 break; | |
156 case DDERR_INVALIDCLIPLIST: | |
157 error = "INVALIDCLIPLIST"; | |
158 break; | |
159 case DDERR_INVALIDMODE: | |
160 error = "INVALIDMODE"; | |
161 break; | |
162 case DDERR_INVALIDOBJECT: | |
163 error = "INVALIDOBJECT"; | |
164 break; | |
165 case DDERR_INVALIDPARAMS: | |
166 error = "INVALIDPARAMS"; | |
167 break; | |
168 case DDERR_INVALIDPIXELFORMAT: | |
169 error = "INVALIDPIXELFORMAT"; | |
170 break; | |
171 case DDERR_INVALIDPOSITION: | |
172 error = "INVALIDPOSITION"; | |
173 break; | |
174 case DDERR_INVALIDRECT: | |
175 error = "INVALIDRECT"; | |
176 break; | |
177 case DDERR_LOCKEDSURFACES: | |
178 error = "LOCKEDSURFACES"; | |
179 break; | |
180 case DDERR_MOREDATA: | |
181 error = "MOREDATA"; | |
182 break; | |
183 case DDERR_NOALPHAHW: | |
184 error = "NOALPHAHW"; | |
185 break; | |
186 case DDERR_NOBLTHW: | |
187 error = "NOBLTHW"; | |
188 break; | |
189 case DDERR_NOCLIPLIST: | |
190 error = "NOCLIPLIST"; | |
191 break; | |
192 case DDERR_NOCLIPPERATTACHED: | |
193 error = "NOCLIPPERATTACHED"; | |
194 break; | |
195 case DDERR_NOCOLORCONVHW: | |
196 error = "NOCOLORCONVHW"; | |
197 break; | |
198 case DDERR_NOCOLORKEYHW: | |
199 error = "NOCOLORKEYHW"; | |
200 break; | |
201 case DDERR_NOCOOPERATIVELEVELSET: | |
202 error = "NOCOOPERATIVELEVELSET"; | |
203 break; | |
204 case DDERR_NODC: | |
205 error = "NODC"; | |
206 break; | |
207 case DDERR_NOFLIPHW: | |
208 error = "NOFLIPHW"; | |
209 break; | |
210 case DDERR_NOOVERLAYDEST: | |
211 error = "NOOVERLAYDEST"; | |
212 break; | |
213 case DDERR_NOOVERLAYHW: | |
214 error = "NOOVERLAYHW"; | |
215 break; | |
216 case DDERR_NOPALETTEATTACHED: | |
217 error = "NOPALETTEATTACHED"; | |
218 break; | |
219 case DDERR_NOPALETTEHW: | |
220 error = "NOPALETTEHW"; | |
221 break; | |
222 case DDERR_NORASTEROPHW: | |
223 error = "NORASTEROPHW"; | |
224 break; | |
225 case DDERR_NOSTRETCHHW: | |
226 error = "NOSTRETCHHW"; | |
227 break; | |
228 case DDERR_NOTAOVERLAYSURFACE: | |
229 error = "NOTAOVERLAYSURFACE"; | |
230 break; | |
231 case DDERR_NOTFLIPPABLE: | |
232 error = "NOTFLIPPABLE"; | |
233 break; | |
234 case DDERR_NOTFOUND: | |
235 error = "NOTFOUND"; | |
236 break; | |
237 case DDERR_NOTLOCKED: | |
238 error = "NOTLOCKED"; | |
239 break; | |
240 case DDERR_NOTPALETTIZED: | |
241 error = "NOTPALETTIZED"; | |
242 break; | |
243 case DDERR_NOVSYNCHW: | |
244 error = "NOVSYNCHW"; | |
245 break; | |
246 case DDERR_NOZOVERLAYHW: | |
247 error = "NOZOVERLAYHW"; | |
248 break; | |
249 case DDERR_OUTOFCAPS: | |
250 error = "OUTOFCAPS"; | |
251 break; | |
252 case DDERR_OUTOFMEMORY: | |
253 error = "OUTOFMEMORY"; | |
254 break; | |
255 case DDERR_OUTOFVIDEOMEMORY: | |
256 error = "OUTOFVIDEOMEMORY"; | |
257 break; | |
258 case DDERR_OVERLAPPINGRECTS: | |
259 error = "OVERLAPPINGRECTS"; | |
260 break; | |
261 case DDERR_OVERLAYNOTVISIBLE: | |
262 error = "OVERLAYNOTVISIBLE"; | |
263 break; | |
264 case DDERR_PALETTEBUSY: | |
265 error = "PALETTEBUSY"; | |
266 break; | |
267 case DDERR_PRIMARYSURFACEALREADYEXISTS: | |
268 error = "PRIMARYSURFACEALREADYEXISTS"; | |
269 break; | |
270 case DDERR_REGIONTOOSMALL: | |
271 error = "REGIONTOOSMALL"; | |
272 break; | |
273 case DDERR_SURFACEBUSY: | |
274 error = "SURFACEBUSY"; | |
275 break; | |
276 case DDERR_SURFACELOST: | |
277 error = "SURFACELOST"; | |
278 break; | |
279 case DDERR_TOOBIGHEIGHT: | |
280 error = "TOOBIGHEIGHT"; | |
281 break; | |
282 case DDERR_TOOBIGSIZE: | |
283 error = "TOOBIGSIZE"; | |
284 break; | |
285 case DDERR_TOOBIGWIDTH: | |
286 error = "TOOBIGWIDTH"; | |
287 break; | |
288 case DDERR_UNSUPPORTED: | |
289 error = "UNSUPPORTED"; | |
290 break; | |
291 case DDERR_UNSUPPORTEDFORMAT: | |
292 error = "UNSUPPORTEDFORMAT"; | |
293 break; | |
294 case DDERR_VERTICALBLANKINPROGRESS: | |
295 error = "VERTICALBLANKINPROGRESS"; | |
296 break; | |
297 case DDERR_VIDEONOTACTIVE: | |
298 error = "VIDEONOTACTIVE"; | |
299 break; | |
300 case DDERR_WASSTILLDRAWING: | |
301 error = "WASSTILLDRAWING"; | |
302 break; | |
303 case DDERR_WRONGMODE: | |
304 error = "WRONGMODE"; | |
305 break; | |
306 default: | |
307 error = "UNKNOWN"; | |
308 break; | |
309 } | |
310 SDL_SetError("%s: %s", prefix, error); | |
311 } | |
312 | |
313 static SDL_bool | |
314 PixelFormatToDDPIXELFORMAT(Uint32 format, LPDDPIXELFORMAT dst) | |
315 { | |
316 SDL_zerop(dst); | |
317 dst->dwSize = sizeof(*dst); | |
318 | |
319 if (SDL_ISPIXELFORMAT_FOURCC(format)) { | |
320 dst->dwFlags = DDPF_FOURCC; | |
321 dst->dwFourCC = format; | |
322 } else if (SDL_ISPIXELFORMAT_INDEXED(format)) { | |
323 SDL_SetError("Indexed pixelformats are not supported."); | |
324 return SDL_FALSE; | |
325 } else { | |
326 int bpp; | |
327 Uint32 Rmask, Gmask, Bmask, Amask; | |
328 if (!SDL_PixelFormatEnumToMasks | |
329 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | |
330 SDL_SetError("pixelformat not supported"); | |
331 return SDL_FALSE; | |
332 } | |
333 | |
334 if (!Rmask && !Gmask && !Bmask) { | |
335 dst->dwFlags = DDPF_ALPHA; | |
336 dst->dwAlphaBitDepth = bpp; | |
337 } else { | |
338 dst->dwFlags = DDPF_RGB; | |
339 dst->dwRGBBitCount = bpp; | |
340 dst->dwRBitMask = Rmask; | |
341 dst->dwGBitMask = Gmask; | |
342 dst->dwBBitMask = Bmask; | |
343 | |
344 if (Amask) { | |
345 dst->dwFlags |= DDPF_ALPHAPIXELS; | |
346 dst->dwRGBAlphaBitMask = Amask; | |
347 } | |
348 } | |
349 } | |
350 | |
351 return SDL_TRUE; | |
352 } | |
353 | |
354 static SDL_bool | |
355 DDRAW_IsTextureFormatAvailable(IDirectDraw * ddraw, Uint32 display_format, | |
356 Uint32 texture_format) | |
357 { | |
358 int bpp; | |
359 Uint32 Rmask, Gmask, Bmask, Amask; | |
360 | |
361 if (SDL_ISPIXELFORMAT_FOURCC(texture_format)) { | |
362 //TODO I don't expect DDRAW to support all 4CC formats, but I don't know which ones | |
363 return SDL_TRUE; | |
364 } | |
365 //These are only basic checks | |
366 if (SDL_ISPIXELFORMAT_INDEXED(texture_format)) { | |
367 return SDL_FALSE; | |
368 } | |
369 | |
370 if (!SDL_PixelFormatEnumToMasks | |
371 (texture_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | |
372 return SDL_FALSE; | |
373 } | |
374 | |
375 switch (bpp) { | |
376 case 4: | |
377 case 8: | |
378 case 16: | |
379 case 24: | |
380 case 32: | |
381 break; | |
382 default: | |
383 return SDL_FALSE; | |
384 } | |
385 | |
386 return SDL_TRUE; | |
387 } | |
388 | |
389 void | |
390 DDRAW_AddRenderDriver(_THIS) | |
391 { | |
392 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | |
393 SDL_RendererInfo *info = &DDRAW_RenderDriver.info; | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3520
diff
changeset
|
394 SDL_DisplayMode *mode = &SDL_CurrentDisplay->desktop_mode; |
3168 | 395 |
396 if (data->ddraw) { | |
397 int i; | |
398 int formats[] = { | |
399 SDL_PIXELFORMAT_INDEX8, | |
400 SDL_PIXELFORMAT_RGB332, | |
401 SDL_PIXELFORMAT_RGB444, | |
402 SDL_PIXELFORMAT_RGB555, | |
403 SDL_PIXELFORMAT_ARGB4444, | |
404 SDL_PIXELFORMAT_ARGB1555, | |
405 SDL_PIXELFORMAT_RGB565, | |
406 SDL_PIXELFORMAT_RGB888, | |
407 SDL_PIXELFORMAT_ARGB8888, | |
408 SDL_PIXELFORMAT_ARGB2101010, | |
409 }; | |
410 | |
411 for (i = 0; i < SDL_arraysize(formats); ++i) { | |
412 if (DDRAW_IsTextureFormatAvailable | |
413 (data->ddraw, mode->format, formats[i])) { | |
414 info->texture_formats[info->num_texture_formats++] = | |
415 formats[i]; | |
416 } | |
417 } | |
418 | |
419 //TODO the fourcc formats should get fetched from IDirectDraw::GetFourCCCodes | |
420 info->texture_formats[info->num_texture_formats++] = | |
421 SDL_PIXELFORMAT_YV12; | |
422 info->texture_formats[info->num_texture_formats++] = | |
423 SDL_PIXELFORMAT_IYUV; | |
424 info->texture_formats[info->num_texture_formats++] = | |
425 SDL_PIXELFORMAT_YUY2; | |
426 info->texture_formats[info->num_texture_formats++] = | |
427 SDL_PIXELFORMAT_UYVY; | |
428 info->texture_formats[info->num_texture_formats++] = | |
429 SDL_PIXELFORMAT_YVYU; | |
430 | |
3520
83518f8fcd61
Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents:
3168
diff
changeset
|
431 for (i = 0; i < _this->num_displays; ++i) |
83518f8fcd61
Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents:
3168
diff
changeset
|
432 SDL_AddRenderDriver(&_this->displays[i], &DDRAW_RenderDriver); |
83518f8fcd61
Fixed calls to SDL_AddRenderDriver()
Sam Lantinga <slouken@libsdl.org>
parents:
3168
diff
changeset
|
433 } |
3168 | 434 } |
435 } | |
436 | |
437 SDL_Renderer * | |
438 DDRAW_CreateRenderer(SDL_Window * window, Uint32 flags) | |
439 { | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3520
diff
changeset
|
440 SDL_VideoDisplay *display = window->display; |
3168 | 441 SDL_VideoData *videodata = (SDL_VideoData *) display->device->driverdata; |
442 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; | |
443 SDL_Renderer *renderer; | |
444 DDRAW_RenderData *data; | |
445 HRESULT result; | |
446 DDSURFACEDESC ddsd; | |
447 | |
448 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); | |
449 if (!renderer) { | |
450 SDL_OutOfMemory(); | |
451 return NULL; | |
452 } | |
453 | |
454 data = (DDRAW_RenderData *) SDL_calloc(1, sizeof(*data)); | |
455 if (!data) { | |
456 DDRAW_DestroyRenderer(renderer); | |
457 SDL_OutOfMemory(); | |
458 return NULL; | |
459 } | |
460 data->ddraw = videodata->ddraw; | |
461 | |
462 renderer->DisplayModeChanged = DDRAW_DisplayModeChanged; | |
463 renderer->CreateTexture = DDRAW_CreateTexture; | |
464 renderer->QueryTexturePixels = DDRAW_QueryTexturePixels; | |
465 | |
466 renderer->SetTextureColorMod = DDRAW_SetTextureColorMod; | |
467 renderer->SetTextureAlphaMod = DDRAW_SetTextureAlphaMod; | |
468 renderer->SetTextureBlendMode = DDRAW_SetTextureBlendMode; | |
469 renderer->SetTextureScaleMode = DDRAW_SetTextureScaleMode; | |
470 renderer->UpdateTexture = DDRAW_UpdateTexture; | |
471 renderer->LockTexture = DDRAW_LockTexture; | |
472 renderer->UnlockTexture = DDRAW_UnlockTexture; | |
473 renderer->DirtyTexture = DDRAW_DirtyTexture; | |
474 renderer->RenderPoint = DDRAW_RenderPoint; | |
475 renderer->RenderLine = DDRAW_RenderLine; | |
476 renderer->RenderFill = DDRAW_RenderFill; | |
477 renderer->RenderCopy = DDRAW_RenderCopy; | |
478 renderer->RenderPresent = DDRAW_RenderPresent; | |
479 renderer->DestroyTexture = DDRAW_DestroyTexture; | |
480 renderer->DestroyRenderer = DDRAW_DestroyRenderer; | |
481 renderer->info = DDRAW_RenderDriver.info; | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3520
diff
changeset
|
482 renderer->window = window; |
3168 | 483 renderer->driverdata = data; |
484 | |
485 renderer->info.flags = SDL_RENDERER_ACCELERATED; | |
486 | |
487 SDL_zero(ddsd); | |
488 ddsd.dwSize = sizeof(ddsd); | |
489 ddsd.dwFlags = DDSD_CAPS; | |
490 | |
491 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
492 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; | |
493 } else { | |
494 //TODO handle non fullscreen | |
495 SDL_SetError("DirectDraw renderer has only fullscreen implemented"); | |
496 DDRAW_DestroyRenderer(renderer); | |
497 return NULL; | |
498 } | |
499 | |
500 if (flags & SDL_RENDERER_PRESENTFLIP2) { | |
501 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; | |
502 ddsd.dwBackBufferCount = 2; | |
503 } else if (flags & SDL_RENDERER_PRESENTFLIP3) { | |
504 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; | |
505 ddsd.dwBackBufferCount = 3; | |
506 } else if (flags & SDL_RENDERER_PRESENTCOPY) { | |
507 //TODO what is the best approximation to this mode | |
508 } else { | |
509 | |
510 } | |
511 | |
512 if (flags & SDL_RENDERER_PRESENTVSYNC) { | |
513 SDL_SetError("DirectDraw renderer with v-sync is not implemented"); | |
514 DDRAW_DestroyRenderer(renderer); | |
515 return NULL; | |
516 } | |
517 | |
518 result = | |
519 data->ddraw->lpVtbl->SetCooperativeLevel(data->ddraw, | |
520 windowdata->hwnd, | |
521 DDSCL_NORMAL); | |
522 if (result != DD_OK) { | |
523 DDRAW_SetError("CreateDevice()", result); | |
524 DDRAW_DestroyRenderer(renderer); | |
525 return NULL; | |
526 } | |
527 | |
528 result = | |
529 data->ddraw->lpVtbl->CreateSurface(data->ddraw, &ddsd, &data->primary, | |
530 NULL); | |
531 if (result != DD_OK) { | |
532 DDRAW_SetError("CreateDevice()", result); | |
533 DDRAW_DestroyRenderer(renderer); | |
534 return NULL; | |
535 } | |
536 | |
537 return renderer; | |
538 } | |
539 | |
540 static int | |
541 DDRAW_Reset(SDL_Renderer * renderer) | |
542 { | |
543 //TODO implement | |
544 /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; | |
545 HRESULT result; | |
546 | |
547 result = IDirect3DDevice9_Reset(data->device, &data->pparams); | |
548 if (FAILED(result)) { | |
549 if (result == D3DERR_DEVICELOST) { | |
550 /* Don't worry about it, we'll reset later... * | |
551 return 0; | |
552 } else { | |
553 D3D_SetError("Reset()", result); | |
554 return -1; | |
555 } | |
556 } | |
557 IDirect3DDevice9_SetVertexShader(data->device, NULL); | |
558 IDirect3DDevice9_SetFVF(data->device, | |
559 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); | |
560 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, | |
561 D3DCULL_NONE); | |
562 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); */ | |
563 return 0; | |
564 } | |
565 | |
566 static int | |
567 DDRAW_DisplayModeChanged(SDL_Renderer * renderer) | |
568 { | |
569 //TODO implement | |
570 /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3520
diff
changeset
|
571 SDL_Window *window = renderer->window; |
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3520
diff
changeset
|
572 SDL_VideoDisplay *display = window->display; |
3168 | 573 |
574 data->pparams.BackBufferWidth = window->w; | |
575 data->pparams.BackBufferHeight = window->h; | |
576 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
577 data->pparams.BackBufferFormat = | |
578 PixelFormatToD3DFMT(display->fullscreen_mode.format); | |
579 } else { | |
580 data->pparams.BackBufferFormat = D3DFMT_UNKNOWN; | |
581 } | |
582 return D3D_Reset(renderer); */ | |
583 return 0; | |
584 } | |
585 | |
586 static int | |
587 DDRAW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
588 { | |
589 DDRAW_RenderData *renderdata = (DDRAW_RenderData *) renderer->driverdata; | |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3520
diff
changeset
|
590 SDL_Window *window = renderer->window; |
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
3520
diff
changeset
|
591 SDL_VideoDisplay *display = window->display; |
3168 | 592 Uint32 display_format = display->current_mode.format; |
593 DDRAW_TextureData *data; | |
594 DDSURFACEDESC ddsd; | |
595 HRESULT result; | |
596 | |
597 data = (DDRAW_TextureData *) SDL_calloc(1, sizeof(*data)); | |
598 if (!data) { | |
599 SDL_OutOfMemory(); | |
600 return -1; | |
601 } | |
602 | |
603 SDL_zero(ddsd); | |
604 ddsd.dwSize = sizeof(ddsd); | |
605 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_HEIGHT | DDSD_WIDTH; | |
606 ddsd.dwWidth = texture->w; | |
607 ddsd.dwHeight = texture->h; | |
608 | |
609 | |
610 if (!PixelFormatToDDPIXELFORMAT(texture->format, &ddsd.ddpfPixelFormat)) { | |
611 SDL_free(data); | |
612 return -1; | |
613 } | |
614 | |
615 texture->driverdata = data; | |
616 | |
617 result = | |
618 renderdata->ddraw->lpVtbl->CreateSurface(renderdata->ddraw, &ddsd, | |
619 &data->surface, NULL); | |
620 if (result != DD_OK) { | |
621 SDL_free(data); | |
622 DDRAW_SetError("CreateTexture", result); | |
623 return -1; | |
624 } | |
625 | |
626 return 0; | |
627 } | |
628 | |
629 static int | |
630 DDRAW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, | |
631 void **pixels, int *pitch) | |
632 { | |
633 //TODO implement | |
634 SDL_SetError("QueryTexturePixels is not implemented"); | |
635 return -1; | |
636 } | |
637 | |
638 static int | |
639 DDRAW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
640 { | |
641 return 0; | |
642 } | |
643 | |
644 static int | |
645 DDRAW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
646 { | |
647 return 0; | |
648 } | |
649 | |
650 static int | |
651 DDRAW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
652 { | |
653 switch (texture->blendMode) { | |
654 case SDL_BLENDMODE_NONE: | |
655 return 0; | |
656 default: | |
657 SDL_Unsupported(); | |
658 texture->blendMode = SDL_BLENDMODE_NONE; | |
659 return -1; | |
660 } | |
661 } | |
662 | |
663 static int | |
664 DDRAW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
665 { | |
666 switch (texture->scaleMode) { | |
667 case SDL_TEXTURESCALEMODE_NONE: | |
668 default: | |
669 SDL_Unsupported(); | |
670 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; | |
671 return -1; | |
672 } | |
673 return 0; | |
674 } | |
675 | |
676 static int | |
677 DDRAW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
678 const SDL_Rect * rect, const void *pixels, int pitch) | |
679 { | |
680 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata; | |
681 | |
682 //TODO implement | |
683 SDL_SetError("UpdateTexture is not implemented"); | |
684 return 0; | |
685 } | |
686 | |
687 static int | |
688 DDRAW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
689 const SDL_Rect * rect, int markDirty, void **pixels, | |
690 int *pitch) | |
691 { | |
692 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata; | |
693 HRESULT result; | |
694 DDSURFACEDESC ddsd; | |
695 | |
696 SDL_zero(ddsd); | |
697 ddsd.dwSize = sizeof(ddsd); | |
698 | |
699 /** | |
700 * On a Axim x51v locking a subrect returns the startaddress of the whole surface, | |
701 * wheras on my ASUS MyPal 696 the startaddress of the locked area is returned, | |
702 * thats why I always lock the whole surface and calculate the pixels pointer by hand. | |
703 * This shouldn't be a speed problem, as multiple locks aren't available on DDraw Mobile | |
704 * see http://msdn.microsoft.com/en-us/library/ms858221.aspx | |
705 */ | |
706 | |
707 result = data->surface->lpVtbl->Lock(data->surface, NULL, &ddsd, 0, NULL); | |
708 if (result != DD_OK) { | |
709 DDRAW_SetError("LockRect()", result); | |
710 return -1; | |
711 } | |
712 | |
713 *pixels = ddsd.lpSurface + rect->y * ddsd.lPitch + rect->x * ddsd.lXPitch; | |
714 *pitch = ddsd.lPitch; | |
715 return 0; | |
716 } | |
717 | |
718 static void | |
719 DDRAW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
720 { | |
721 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata; | |
722 | |
723 data->surface->lpVtbl->Unlock(data->surface, NULL); | |
724 } | |
725 | |
726 static void | |
727 DDRAW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
728 int numrects, const SDL_Rect * rects) | |
729 { | |
730 } | |
731 | |
732 static void | |
733 DDRAW_SetBlendMode(DDRAW_RenderData * data, int blendMode) | |
734 { | |
735 switch (blendMode) { | |
736 | |
737 } | |
738 } | |
739 | |
740 static int | |
741 DDRAW_RenderPoint(SDL_Renderer * renderer, int x, int y) | |
742 { | |
743 return -1; | |
744 } | |
745 | |
746 static int | |
747 DDRAW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | |
748 { | |
749 return -1; | |
750 } | |
751 | |
752 static int | |
753 DDRAW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) | |
754 { | |
755 return -1; | |
756 } | |
757 | |
758 static int | |
759 DDRAW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | |
760 const SDL_Rect * srcrect, const SDL_Rect * dstrect) | |
761 { | |
762 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata; | |
763 DDRAW_TextureData *texturedata = | |
764 (DDRAW_TextureData *) texture->driverdata; | |
765 HRESULT result; | |
766 RECT srcr; | |
767 RECT dstr; | |
768 DDBLTFX bltfx; | |
769 | |
770 srcr.left = srcrect->x; | |
771 srcr.top = srcrect->y; | |
772 srcr.right = srcrect->x + srcrect->w; | |
773 srcr.bottom = srcrect->y + srcrect->h; | |
774 | |
775 dstr.left = dstrect->x; | |
776 dstr.top = dstrect->y; | |
777 dstr.right = dstrect->x + dstrect->w; | |
778 dstr.bottom = dstrect->y + dstrect->h; | |
779 | |
780 SDL_zero(bltfx); | |
781 bltfx.dwSize = sizeof(bltfx); | |
782 bltfx.dwROP = SRCCOPY; | |
783 | |
784 data->primary->lpVtbl->Blt(data->primary, &dstr, texturedata->surface, | |
785 &srcr, DDBLT_ROP, &bltfx); | |
786 | |
787 return 0; | |
788 } | |
789 | |
790 static void | |
791 DDRAW_RenderPresent(SDL_Renderer * renderer) | |
792 { | |
793 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata; | |
794 HRESULT result; | |
795 | |
796 return; | |
797 | |
798 result = | |
799 data->primary->lpVtbl->Flip(data->primary, NULL, DDFLIP_INTERVAL1); | |
800 if (result != DD_OK) { | |
801 DDRAW_SetError("Present()", result); | |
802 } | |
803 } | |
804 | |
805 static void | |
806 DDRAW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
807 { | |
808 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata; | |
809 | |
810 if (!data) { | |
811 return; | |
812 } | |
813 | |
814 data->surface->lpVtbl->Release(data->surface); | |
815 SDL_free(data); | |
816 texture->driverdata = NULL; | |
817 } | |
818 | |
819 static void | |
820 DDRAW_DestroyRenderer(SDL_Renderer * renderer) | |
821 { | |
822 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata; | |
823 | |
824 if (data) { | |
825 data->primary->lpVtbl->Release(data->primary); | |
826 SDL_free(data); | |
827 } | |
828 SDL_free(renderer); | |
829 } | |
830 | |
831 #endif /* SDL_VIDEO_RENDER_DDRAW */ | |
832 | |
833 /* vi: set ts=4 sw=4 expandtab: */ |