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

Latest commit

 

History

History
833 lines (738 loc) · 23.5 KB

SDL_ceddrawrender.c

File metadata and controls

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