Mercurial > sdl-ios-xcode
annotate src/video/windows/SDL_ceddrawrender.c @ 5088:c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 24 Jan 2011 15:46:11 -0800 |
parents | e8916fe9cfc8 |
children | da10636e5eca |
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 | |
5062 | 29 #include "SDL_windowsvideo.h" |
3168 | 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), | |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4569
diff
changeset
|
88 (SDL_SCALEMODE_NONE), |
3168 | 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 | |
4569 | 462 videodata->render = RENDER_DDRAW; |
463 | |
3168 | 464 renderer->DisplayModeChanged = DDRAW_DisplayModeChanged; |
465 renderer->CreateTexture = DDRAW_CreateTexture; | |
466 renderer->QueryTexturePixels = DDRAW_QueryTexturePixels; | |
467 | |
468 renderer->SetTextureColorMod = DDRAW_SetTextureColorMod; | |
469 renderer->SetTextureAlphaMod = DDRAW_SetTextureAlphaMod; | |
470 renderer->SetTextureBlendMode = DDRAW_SetTextureBlendMode; | |
471 renderer->SetTextureScaleMode = DDRAW_SetTextureScaleMode; | |
472 renderer->UpdateTexture = DDRAW_UpdateTexture; | |
473 renderer->LockTexture = DDRAW_LockTexture; | |
474 renderer->UnlockTexture = DDRAW_UnlockTexture; | |
475 renderer->DirtyTexture = DDRAW_DirtyTexture; | |
476 renderer->RenderPoint = DDRAW_RenderPoint; | |
477 renderer->RenderLine = DDRAW_RenderLine; | |
478 renderer->RenderFill = DDRAW_RenderFill; | |
479 renderer->RenderCopy = DDRAW_RenderCopy; | |
480 renderer->RenderPresent = DDRAW_RenderPresent; | |
481 renderer->DestroyTexture = DDRAW_DestroyTexture; | |
482 renderer->DestroyRenderer = DDRAW_DestroyRenderer; | |
483 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
|
484 renderer->window = window; |
3168 | 485 renderer->driverdata = data; |
486 | |
487 renderer->info.flags = SDL_RENDERER_ACCELERATED; | |
488 | |
489 SDL_zero(ddsd); | |
490 ddsd.dwSize = sizeof(ddsd); | |
491 ddsd.dwFlags = DDSD_CAPS; | |
492 | |
493 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
494 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; | |
495 } else { | |
496 //TODO handle non fullscreen | |
497 SDL_SetError("DirectDraw renderer has only fullscreen implemented"); | |
498 DDRAW_DestroyRenderer(renderer); | |
499 return NULL; | |
500 } | |
501 | |
502 if (flags & SDL_RENDERER_PRESENTFLIP2) { | |
503 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; | |
504 ddsd.dwBackBufferCount = 2; | |
505 } else if (flags & SDL_RENDERER_PRESENTFLIP3) { | |
506 ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; | |
507 ddsd.dwBackBufferCount = 3; | |
508 } else if (flags & SDL_RENDERER_PRESENTCOPY) { | |
509 //TODO what is the best approximation to this mode | |
510 } else { | |
511 | |
512 } | |
513 | |
514 if (flags & SDL_RENDERER_PRESENTVSYNC) { | |
515 SDL_SetError("DirectDraw renderer with v-sync is not implemented"); | |
516 DDRAW_DestroyRenderer(renderer); | |
517 return NULL; | |
518 } | |
519 | |
520 result = | |
521 data->ddraw->lpVtbl->SetCooperativeLevel(data->ddraw, | |
522 windowdata->hwnd, | |
523 DDSCL_NORMAL); | |
524 if (result != DD_OK) { | |
525 DDRAW_SetError("CreateDevice()", result); | |
526 DDRAW_DestroyRenderer(renderer); | |
527 return NULL; | |
528 } | |
529 | |
530 result = | |
531 data->ddraw->lpVtbl->CreateSurface(data->ddraw, &ddsd, &data->primary, | |
532 NULL); | |
533 if (result != DD_OK) { | |
534 DDRAW_SetError("CreateDevice()", result); | |
535 DDRAW_DestroyRenderer(renderer); | |
536 return NULL; | |
537 } | |
538 | |
539 return renderer; | |
540 } | |
541 | |
542 static int | |
543 DDRAW_Reset(SDL_Renderer * renderer) | |
544 { | |
545 //TODO implement | |
546 /*D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; | |
547 HRESULT result; | |
548 | |
549 result = IDirect3DDevice9_Reset(data->device, &data->pparams); | |
550 if (FAILED(result)) { | |
551 if (result == D3DERR_DEVICELOST) { | |
552 /* Don't worry about it, we'll reset later... * | |
553 return 0; | |
554 } else { | |
555 D3D_SetError("Reset()", result); | |
556 return -1; | |
557 } | |
558 } | |
559 IDirect3DDevice9_SetVertexShader(data->device, NULL); | |
560 IDirect3DDevice9_SetFVF(data->device, | |
561 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); | |
562 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, | |
563 D3DCULL_NONE); | |
564 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); */ | |
565 return 0; | |
566 } | |
567 | |
568 static int | |
569 DDRAW_DisplayModeChanged(SDL_Renderer * renderer) | |
570 { | |
571 //TODO implement | |
572 /*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
|
573 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
|
574 SDL_VideoDisplay *display = window->display; |
3168 | 575 |
576 data->pparams.BackBufferWidth = window->w; | |
577 data->pparams.BackBufferHeight = window->h; | |
578 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
579 data->pparams.BackBufferFormat = | |
580 PixelFormatToD3DFMT(display->fullscreen_mode.format); | |
581 } else { | |
582 data->pparams.BackBufferFormat = D3DFMT_UNKNOWN; | |
583 } | |
584 return D3D_Reset(renderer); */ | |
585 return 0; | |
586 } | |
587 | |
588 static int | |
589 DDRAW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
590 { | |
591 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
|
592 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
|
593 SDL_VideoDisplay *display = window->display; |
3168 | 594 Uint32 display_format = display->current_mode.format; |
595 DDRAW_TextureData *data; | |
596 DDSURFACEDESC ddsd; | |
597 HRESULT result; | |
598 | |
599 data = (DDRAW_TextureData *) SDL_calloc(1, sizeof(*data)); | |
600 if (!data) { | |
601 SDL_OutOfMemory(); | |
602 return -1; | |
603 } | |
604 | |
605 SDL_zero(ddsd); | |
606 ddsd.dwSize = sizeof(ddsd); | |
607 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_HEIGHT | DDSD_WIDTH; | |
608 ddsd.dwWidth = texture->w; | |
609 ddsd.dwHeight = texture->h; | |
610 | |
611 | |
612 if (!PixelFormatToDDPIXELFORMAT(texture->format, &ddsd.ddpfPixelFormat)) { | |
613 SDL_free(data); | |
614 return -1; | |
615 } | |
616 | |
617 texture->driverdata = data; | |
618 | |
619 result = | |
620 renderdata->ddraw->lpVtbl->CreateSurface(renderdata->ddraw, &ddsd, | |
621 &data->surface, NULL); | |
622 if (result != DD_OK) { | |
623 SDL_free(data); | |
624 DDRAW_SetError("CreateTexture", result); | |
625 return -1; | |
626 } | |
627 | |
628 return 0; | |
629 } | |
630 | |
631 static int | |
632 DDRAW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, | |
633 void **pixels, int *pitch) | |
634 { | |
635 //TODO implement | |
636 SDL_SetError("QueryTexturePixels is not implemented"); | |
637 return -1; | |
638 } | |
639 | |
640 static int | |
641 DDRAW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
642 { | |
643 return 0; | |
644 } | |
645 | |
646 static int | |
647 DDRAW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
648 { | |
649 return 0; | |
650 } | |
651 | |
652 static int | |
653 DDRAW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
654 { | |
655 switch (texture->blendMode) { | |
656 case SDL_BLENDMODE_NONE: | |
657 return 0; | |
658 default: | |
659 SDL_Unsupported(); | |
660 texture->blendMode = SDL_BLENDMODE_NONE; | |
661 return -1; | |
662 } | |
663 } | |
664 | |
665 static int | |
666 DDRAW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
667 { | |
668 switch (texture->scaleMode) { | |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4569
diff
changeset
|
669 case SDL_SCALEMODE_NONE: |
3168 | 670 default: |
671 SDL_Unsupported(); | |
4929
aa8888658021
Use the enumerated type for blend and scale mode instead of int
Sam Lantinga <slouken@libsdl.org>
parents:
4569
diff
changeset
|
672 texture->scaleMode = SDL_SCALEMODE_NONE; |
3168 | 673 return -1; |
674 } | |
675 return 0; | |
676 } | |
677 | |
678 static int | |
679 DDRAW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
680 const SDL_Rect * rect, const void *pixels, int pitch) | |
681 { | |
682 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata; | |
683 | |
684 //TODO implement | |
685 SDL_SetError("UpdateTexture is not implemented"); | |
686 return 0; | |
687 } | |
688 | |
689 static int | |
690 DDRAW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
691 const SDL_Rect * rect, int markDirty, void **pixels, | |
692 int *pitch) | |
693 { | |
694 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata; | |
695 HRESULT result; | |
696 DDSURFACEDESC ddsd; | |
697 | |
698 SDL_zero(ddsd); | |
699 ddsd.dwSize = sizeof(ddsd); | |
700 | |
701 /** | |
702 * On a Axim x51v locking a subrect returns the startaddress of the whole surface, | |
703 * wheras on my ASUS MyPal 696 the startaddress of the locked area is returned, | |
704 * thats why I always lock the whole surface and calculate the pixels pointer by hand. | |
705 * This shouldn't be a speed problem, as multiple locks aren't available on DDraw Mobile | |
706 * see http://msdn.microsoft.com/en-us/library/ms858221.aspx | |
707 */ | |
708 | |
709 result = data->surface->lpVtbl->Lock(data->surface, NULL, &ddsd, 0, NULL); | |
710 if (result != DD_OK) { | |
711 DDRAW_SetError("LockRect()", result); | |
712 return -1; | |
713 } | |
714 | |
715 *pixels = ddsd.lpSurface + rect->y * ddsd.lPitch + rect->x * ddsd.lXPitch; | |
716 *pitch = ddsd.lPitch; | |
717 return 0; | |
718 } | |
719 | |
720 static void | |
721 DDRAW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
722 { | |
723 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata; | |
724 | |
725 data->surface->lpVtbl->Unlock(data->surface, NULL); | |
726 } | |
727 | |
728 static void | |
729 DDRAW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | |
730 int numrects, const SDL_Rect * rects) | |
731 { | |
732 } | |
733 | |
734 static void | |
735 DDRAW_SetBlendMode(DDRAW_RenderData * data, int blendMode) | |
736 { | |
737 switch (blendMode) { | |
738 | |
739 } | |
740 } | |
741 | |
742 static int | |
743 DDRAW_RenderPoint(SDL_Renderer * renderer, int x, int y) | |
744 { | |
745 return -1; | |
746 } | |
747 | |
748 static int | |
749 DDRAW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | |
750 { | |
751 return -1; | |
752 } | |
753 | |
754 static int | |
755 DDRAW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) | |
756 { | |
757 return -1; | |
758 } | |
759 | |
760 static int | |
761 DDRAW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | |
762 const SDL_Rect * srcrect, const SDL_Rect * dstrect) | |
763 { | |
764 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata; | |
765 DDRAW_TextureData *texturedata = | |
766 (DDRAW_TextureData *) texture->driverdata; | |
767 HRESULT result; | |
768 RECT srcr; | |
769 RECT dstr; | |
770 DDBLTFX bltfx; | |
771 | |
772 srcr.left = srcrect->x; | |
773 srcr.top = srcrect->y; | |
774 srcr.right = srcrect->x + srcrect->w; | |
775 srcr.bottom = srcrect->y + srcrect->h; | |
776 | |
777 dstr.left = dstrect->x; | |
778 dstr.top = dstrect->y; | |
779 dstr.right = dstrect->x + dstrect->w; | |
780 dstr.bottom = dstrect->y + dstrect->h; | |
781 | |
782 SDL_zero(bltfx); | |
783 bltfx.dwSize = sizeof(bltfx); | |
784 bltfx.dwROP = SRCCOPY; | |
785 | |
786 data->primary->lpVtbl->Blt(data->primary, &dstr, texturedata->surface, | |
787 &srcr, DDBLT_ROP, &bltfx); | |
788 | |
789 return 0; | |
790 } | |
791 | |
792 static void | |
793 DDRAW_RenderPresent(SDL_Renderer * renderer) | |
794 { | |
795 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata; | |
796 HRESULT result; | |
797 | |
798 return; | |
799 | |
800 result = | |
801 data->primary->lpVtbl->Flip(data->primary, NULL, DDFLIP_INTERVAL1); | |
802 if (result != DD_OK) { | |
803 DDRAW_SetError("Present()", result); | |
804 } | |
805 } | |
806 | |
807 static void | |
808 DDRAW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) | |
809 { | |
810 DDRAW_TextureData *data = (DDRAW_TextureData *) texture->driverdata; | |
811 | |
812 if (!data) { | |
813 return; | |
814 } | |
815 | |
816 data->surface->lpVtbl->Release(data->surface); | |
817 SDL_free(data); | |
818 texture->driverdata = NULL; | |
819 } | |
820 | |
821 static void | |
822 DDRAW_DestroyRenderer(SDL_Renderer * renderer) | |
823 { | |
824 DDRAW_RenderData *data = (DDRAW_RenderData *) renderer->driverdata; | |
825 | |
826 if (data) { | |
827 data->primary->lpVtbl->Release(data->primary); | |
828 SDL_free(data); | |
829 } | |
830 SDL_free(renderer); | |
831 } | |
832 | |
833 #endif /* SDL_VIDEO_RENDER_DDRAW */ | |
834 | |
835 /* vi: set ts=4 sw=4 expandtab: */ |