-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wine-1.7.31-d3d9-d6d23a8.patch
3827 lines (3767 loc) · 130 KB
/
wine-1.7.31-d3d9-d6d23a8.patch
1
2
3
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
394
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
431
432
433
434
435
436
437
438
439
440
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
482
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
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
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/configure b/configure
index de03151..5b8e3ce 100755
--- a/configure
+++ b/configure
@@ -677,6 +677,8 @@ XSLT_CFLAGS
XML2_LIBS
XML2_CFLAGS
LIBPCAP
+D3D_LIBS
+D3D_CFLAGS
X_EXTRA_LIBS
X_LIBS
X_PRE_LIBS
@@ -821,6 +823,7 @@ with_netapi
with_openal
with_opencl
with_opengl
+with_d3dadapter
with_osmesa
with_oss
with_pcap
@@ -831,6 +834,7 @@ with_tiff
with_v4l
with_xcomposite
with_xcursor
+with_xfixes
with_xinerama
with_xinput
with_xinput2
@@ -2099,6 +2103,7 @@ Optional Packages:
--without-openal do not use OpenAL
--without-opencl do not use OpenCL
--without-opengl do not use OpenGL
+ --without-d3dadapter do not use native Direct3D
--without-osmesa do not use the OSMesa library
--without-oss do not use the OSS sound support
--without-pcap do not use the Packet Capture library
@@ -2109,6 +2114,7 @@ Optional Packages:
--without-v4l do not use v4l1 (v4l support)
--without-xcomposite do not use the Xcomposite extension
--without-xcursor do not use the Xcursor extension
+ --without-xfixes do not use the Xfixes extension
--without-xinerama do not use Xinerama (multi-monitor support)
--without-xinput do not use the Xinput extension
--without-xinput2 do not use the Xinput 2 extension
@@ -3321,6 +3327,12 @@ if test "${with_opengl+set}" = set; then :
fi
+# Check whether --with-d3dadapter was given.
+if test "${with_d3dadapter+set}" = set; then :
+ withval=$with_d3dadapter;
+fi
+
+
# Check whether --with-osmesa was given.
if test "${with_osmesa+set}" = set; then :
withval=$with_osmesa;
@@ -3381,6 +3393,12 @@ if test "${with_xcursor+set}" = set; then :
fi
+# Check whether --with-xfixes was given.
+if test "${with_xfixes+set}" = set; then :
+ withval=$with_xfixes; if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_Xfixes_h=no; fi
+fi
+
+
# Check whether --with-xinerama was given.
if test "${with_xinerama+set}" = set; then :
withval=$with_xinerama; if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_Xinerama_h=no; fi
@@ -9433,6 +9451,7 @@ fi
X11/extensions/XInput2.h \
X11/extensions/XShm.h \
X11/extensions/Xcomposite.h \
+ X11/extensions/Xfixes.h \
X11/extensions/Xinerama.h \
X11/extensions/Xrandr.h \
X11/extensions/Xrender.h \
@@ -10209,6 +10228,71 @@ This is an error since --with-xcomposite was requested." "$LINENO" 5 ;;
esac
fi
+ if test "$ac_cv_header_X11_extensions_Xfixes_h" = "yes"
+ then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -lXfixes" >&5
+$as_echo_n "checking for -lXfixes... " >&6; }
+if ${ac_cv_lib_soname_Xfixes+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_soname_save_LIBS=$LIBS
+LIBS="-lXfixes $X_LIBS $XLIB $X_EXTRA_LIBS $LIBS"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char XFixesCreateRegion ();
+int
+main ()
+{
+return XFixesCreateRegion ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ case "$LIBEXT" in
+ dll) ac_cv_lib_soname_Xfixes=`$ac_cv_path_LDD conftest.exe | grep "Xfixes" | sed -e "s/dll.*/dll/"';2,$d'` ;;
+ dylib) ac_cv_lib_soname_Xfixes=`otool -L conftest$ac_exeext | grep "libXfixes\\.[0-9A-Za-z.]*dylib" | sed -e "s/^.*\/\(libXfixes\.[0-9A-Za-z.]*dylib\).*$/\1/"';2,$d'` ;;
+ *) ac_cv_lib_soname_Xfixes=`$READELF -d conftest$ac_exeext | grep "NEEDED.*libXfixes\\.$LIBEXT" | sed -e "s/^.*\\[\\(libXfixes\\.$LIBEXT[^ ]*\\)\\].*$/\1/"';2,$d'`
+ if ${ac_cv_lib_soname_Xfixes:+false} :; then :
+ ac_cv_lib_soname_Xfixes=`$LDD conftest$ac_exeext | grep "libXfixes\\.$LIBEXT" | sed -e "s/^.*\(libXfixes\.$LIBEXT[^ ]*\).*$/\1/"';2,$d'`
+fi ;;
+ esac
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ LIBS=$ac_check_soname_save_LIBS
+fi
+if ${ac_cv_lib_soname_Xfixes:+false} :; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
+$as_echo "not found" >&6; }
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_soname_Xfixes" >&5
+$as_echo "$ac_cv_lib_soname_Xfixes" >&6; }
+
+cat >>confdefs.h <<_ACEOF
+#define SONAME_LIBXFIXES "$ac_cv_lib_soname_Xfixes"
+_ACEOF
+
+
+fi
+ fi
+ if test "x$ac_cv_lib_soname_Xfixes" = "x"; then :
+ case "x$with_xfixes" in
+ x) as_fn_append wine_notices "|libxfixes ${notice_platform}development files not found, Xfixes won't be supported." ;;
+ xno) ;;
+ *) as_fn_error $? "libxfixes ${notice_platform}development files not found, Xfixes won't be supported.
+This is an error since --with-xfixes was requested." "$LINENO" 5 ;;
+esac
+fi
+
ac_fn_c_check_member "$LINENO" "XICCallback" "callback" "ac_cv_member_XICCallback_callback" "#ifdef HAVE_X11_XLIB_H
#include <X11/Xlib.h>
#endif
@@ -10478,6 +10562,22 @@ This is an error since --with-opengl was requested." "$LINENO" 5 ;;
esac
fi
+ if test "x$with_d3dadapter" != "xno"
+ then
+ D3D_CFLAGS=`pkg-config --cflags d3d`
+ D3D_LIBS=`pkg-config --libs d3d`
+
+
+
+$as_echo "#define SONAME_D3DADAPTER9 \"d3dadapter9.so.1\"" >>confdefs.h
+
+
+cat >>confdefs.h <<_ACEOF
+#define D3D_MODULE_DIR "`pkg-config --variable=moduledir d3d`"
+_ACEOF
+
+ fi
+
CPPFLAGS="$ac_save_CPPFLAGS"
else
X_CFLAGS=""
@@ -16668,6 +16768,8 @@ X_CFLAGS = $X_CFLAGS
X_PRE_LIBS = $X_PRE_LIBS
X_LIBS = $X_LIBS
X_EXTRA_LIBS = $X_EXTRA_LIBS
+D3D_CFLAGS = $D3D_CFLAGS
+D3D_LIBS = $D3D_LIBS
XML2_CFLAGS = $XML2_CFLAGS
XML2_LIBS = $XML2_LIBS
XSLT_CFLAGS = $XSLT_CFLAGS
diff --git a/configure.ac b/configure.ac
index 4ee8133..af56482 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,7 @@ AC_ARG_WITH(openal, AS_HELP_STRING([--without-openal],[do not use OpenAL]),
AC_ARG_WITH(opencl, AS_HELP_STRING([--without-opencl],[do not use OpenCL]),
[if test "x$withval" = "xno"; then ac_cv_header_CL_cl_h=no; ac_cv_header_OpenCL_opencl_h=no; fi])
AC_ARG_WITH(opengl, AS_HELP_STRING([--without-opengl],[do not use OpenGL]))
+AC_ARG_WITH(d3dadapter,AS_HELP_STRING([--without-d3dadapter],[do not use native Direct3D]))
AC_ARG_WITH(osmesa, AS_HELP_STRING([--without-osmesa],[do not use the OSMesa library]))
AC_ARG_WITH(oss, AS_HELP_STRING([--without-oss],[do not use the OSS sound support]))
AC_ARG_WITH(pcap, AS_HELP_STRING([--without-pcap],[do not use the Packet Capture library]),
@@ -79,6 +80,8 @@ AC_ARG_WITH(xcomposite,AS_HELP_STRING([--without-xcomposite],[do not use the Xco
[if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_Xcomposite_h=no; fi])
AC_ARG_WITH(xcursor, AS_HELP_STRING([--without-xcursor],[do not use the Xcursor extension]),
[if test "x$withval" = "xno"; then ac_cv_header_X11_Xcursor_Xcursor_h=no; fi])
+AC_ARG_WITH(xfixes, AS_HELP_STRING([--without-xfixes],[do not use the Xfixes extension]),
+ [if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_Xfixes_h=no; fi])
AC_ARG_WITH(xinerama, AS_HELP_STRING([--without-xinerama],[do not use Xinerama (multi-monitor support)]),
[if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_Xinerama_h=no; fi])
AC_ARG_WITH(xinput, AS_HELP_STRING([--without-xinput],[do not use the Xinput extension]),
@@ -1092,6 +1095,7 @@ then
X11/extensions/XInput2.h \
X11/extensions/XShm.h \
X11/extensions/Xcomposite.h \
+ X11/extensions/Xfixes.h \
X11/extensions/Xinerama.h \
X11/extensions/Xrandr.h \
X11/extensions/Xrender.h \
@@ -1207,6 +1211,14 @@ then
WINE_NOTICE_WITH(xcomposite,[test "x$ac_cv_lib_soname_Xcomposite" = "x"],
[libxcomposite ${notice_platform}development files not found, Xcomposite won't be supported.])
+ dnl *** Check for X Fixes extension
+ if test "$ac_cv_header_X11_extensions_Xfixes_h" = "yes"
+ then
+ WINE_CHECK_SONAME(Xfixes,XFixesCreateRegion,,,[$X_LIBS $XLIB $X_EXTRA_LIBS])
+ fi
+ WINE_NOTICE_WITH(xfixes,[test "x$ac_cv_lib_soname_Xfixes" = "x"],
+ [libxfixes ${notice_platform}development files not found, Xfixes won't be supported.])
+
dnl *** Check for XICCallback struct
AC_CHECK_MEMBERS([XICCallback.callback, XEvent.xcookie],,,
[#ifdef HAVE_X11_XLIB_H
@@ -1249,6 +1261,17 @@ This probably prevents linking to OpenGL. Try deleting the file and restarting c
WINE_WARNING_WITH(opengl,[test -n "$opengl_msg"],[$opengl_msg
OpenGL and Direct3D won't be supported.])
+ dnl Check for d3dadapter
+ if test "x$with_d3dadapter" != "xno"
+ then
+ D3D_CFLAGS=`pkg-config --cflags d3d`
+ D3D_LIBS=`pkg-config --libs d3d`
+ AC_SUBST(D3D_CFLAGS)
+ AC_SUBST(D3D_LIBS)
+ AC_DEFINE(SONAME_D3DADAPTER9, ["d3dadapter9.so.1"], ["temporary hack"])
+ AC_DEFINE_UNQUOTED(D3D_MODULE_DIR, ["`pkg-config --variable=moduledir d3d`"], ["module dir"])
+ fi
+
CPPFLAGS="$ac_save_CPPFLAGS"
else
X_CFLAGS=""
diff --git a/dlls/d3d9/Makefile.in b/dlls/d3d9/Makefile.in
index 1c05f5a..92b458d 100644
--- a/dlls/d3d9/Makefile.in
+++ b/dlls/d3d9/Makefile.in
@@ -1,10 +1,11 @@
MODULE = d3d9.dll
IMPORTLIB = d3d9
-IMPORTS = dxguid uuid wined3d
+IMPORTS = dxguid uuid advapi32 gdi32 user32 wined3d
C_SRCS = \
buffer.c \
d3d9_main.c \
+ d3dadapter9.c \
device.c \
directx.c \
query.c \
diff --git a/dlls/d3d9/d3d9_main.c b/dlls/d3d9/d3d9_main.c
index 0afdc04..6f58a13 100644
--- a/dlls/d3d9/d3d9_main.c
+++ b/dlls/d3d9/d3d9_main.c
@@ -33,12 +33,63 @@ void WINAPI DebugSetMute(void) {
/* nothing to do */
}
+static BOOL try_native(void)
+{
+ HKEY defkey, appkey;
+ DWORD type, data = 0;
+ DWORD size = sizeof(DWORD);
+ DWORD len;
+ char buffer[MAX_PATH];
+
+ /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
+ if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &defkey ) ) defkey = 0;
+
+ len = GetModuleFileNameA( 0, buffer, MAX_PATH );
+ if (len && len < MAX_PATH)
+ {
+ HKEY tmpkey;
+ /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
+ if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
+ {
+ char *p, *appname = buffer;
+ if ((p = strrchr( appname, '/' ))) appname = p + 1;
+ if ((p = strrchr( appname, '\\' ))) appname = p + 1;
+ strcat( appname, "\\Direct3D" );
+ TRACE("appname = [%s]\n", appname);
+ if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
+ RegCloseKey( tmpkey );
+ }
+ }
+
+ if (!(appkey && !RegQueryValueExA(appkey, "UseNative", 0, &type, (BYTE *)&data, &size) && (type == REG_DWORD))) {
+ if (!(defkey && !RegQueryValueExA(defkey, "UseNative", 0, &type, (BYTE *)&data, &size) && (type == REG_DWORD))) {
+ data = 0;
+ }
+ }
+
+ if (appkey) RegCloseKey( appkey );
+ if (defkey) RegCloseKey( defkey );
+
+ if (!data)
+ FIXME("\033[1;33m\nNative Direct3D 9 is disabled."
+ "\nFor more information visit https://wiki.ixit.cz/d3d9\n\033[0m");
+
+ return data ? TRUE : FALSE;
+}
+
IDirect3D9 * WINAPI DECLSPEC_HOTPATCH Direct3DCreate9(UINT sdk_version)
{
struct d3d9 *object;
TRACE("sdk_version %#x.\n", sdk_version);
+ if (try_native()) {
+ IDirect3D9 *native;
+ if (SUCCEEDED(d3dadapter9_new(FALSE, (IDirect3D9Ex **)&native))) {
+ return native;
+ }
+ }
+
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
return NULL;
@@ -60,6 +111,10 @@ HRESULT WINAPI DECLSPEC_HOTPATCH Direct3DCreate9Ex(UINT sdk_version, IDirect3D9E
TRACE("sdk_version %#x, d3d9ex %p.\n", sdk_version, d3d9ex);
+ if (try_native()) {
+ if (SUCCEEDED(d3dadapter9_new(TRUE, d3d9ex))) { return D3D_OK; }
+ }
+
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
return E_OUTOFMEMORY;
@@ -90,6 +145,25 @@ void* WINAPI Direct3DShaderValidatorCreate9(void)
return NULL;
}
+/*******************************************************************
+ * DllMain
+ */
+BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
+{
+ switch (reason)
+ {
+ case DLL_PROCESS_ATTACH:
+ d3dadapter9_init(inst);
+ break;
+
+ case DLL_PROCESS_DETACH:
+ d3dadapter9_destroy(inst);
+ break;
+ }
+
+ return TRUE;
+}
+
/***********************************************************************
* D3DPERF_BeginEvent (D3D9.@)
*/
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index d12805f..cdc1f07 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -39,6 +39,9 @@
#include "d3d9.h"
#include "wine/wined3d.h"
+extern void d3dadapter9_init(HINSTANCE hinst);
+extern void d3dadapter9_destroy(HINSTANCE hinst);
+
extern HRESULT vdecl_convert_fvf(DWORD FVF, D3DVERTEXELEMENT9 **ppVertexElements) DECLSPEC_HIDDEN;
D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN;
enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
@@ -132,6 +135,7 @@ struct d3d9
BOOL d3d9_init(struct d3d9 *d3d9, BOOL extended) DECLSPEC_HIDDEN;
void filter_caps(D3DCAPS9* pCaps) DECLSPEC_HIDDEN;
+HRESULT d3dadapter9_new(boolean ex, IDirect3D9Ex **ppOut);
struct fvf_declaration
{
diff --git a/dlls/d3d9/d3dadapter9.c b/dlls/d3d9/d3dadapter9.c
new file mode 100644
index 0000000..33e8e7f
--- /dev/null
+++ b/dlls/d3d9/d3dadapter9.c
@@ -0,0 +1,937 @@
+/*
+ * X11DRV IDirect3D9 interface using ID3DAdapter9
+ *
+ * Copyright 2013 Joakim Sindholt
+ * Christoph Bumiller
+ *
+ * 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
+ */
+
+#include "config.h"
+#include "wine/debug.h"
+
+#include <d3d9.h>
+
+#ifdef SONAME_D3DADAPTER9
+
+#include "wine/d3dadapter.h"
+#include "wine/gdi_driver.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
+
+/* this represents a snapshot taken at the moment of creation */
+struct output
+{
+ D3DDISPLAYROTATION rotation; /* current rotation */
+ D3DDISPLAYMODEEX *modes;
+ unsigned nmodes;
+ unsigned nmodesalloc;
+ unsigned current; /* current mode num */
+
+ HMONITOR monitor;
+};
+
+struct adapter_group
+{
+ struct output *outputs;
+ unsigned noutputs;
+ unsigned noutputsalloc;
+
+ /* override driver provided DeviceName with this to homogenize device names
+ * with wine */
+ WCHAR devname[32];
+
+ /* driver stuff */
+ ID3DAdapter9 *adapter;
+};
+
+struct adapter_map
+{
+ unsigned group;
+ unsigned master;
+};
+
+struct d3dadapter9
+{
+ /* COM vtable */
+ void *vtable;
+ /* IUnknown reference count */
+ LONG refs;
+
+ /* adapter groups and mappings */
+ struct adapter_group *groups;
+ struct adapter_map *map;
+ unsigned nadapters;
+ unsigned ngroups;
+ unsigned ngroupsalloc;
+
+ struct d3dadapter_funcs *funcs;
+ /* fake window for getting driver funcs */
+ HWND hwnd;
+ HDC hdc;
+
+ /* true if it implements IDirect3D9Ex */
+ boolean ex;
+};
+
+/* convenience wrapper for calls into ID3D9Adapter */
+#define ADAPTER_GROUP \
+ This->groups[This->map[Adapter].group]
+
+#define ADAPTER_PROC(name, ...) \
+ ID3DAdapter9_##name(ADAPTER_GROUP.adapter, ## __VA_ARGS__)
+
+#define ADAPTER_OUTPUT \
+ ADAPTER_GROUP.outputs[Adapter-This->map[Adapter].master]
+
+static HRESULT WINAPI
+d3dadapter9_CheckDeviceFormat( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ D3DFORMAT AdapterFormat,
+ DWORD Usage,
+ D3DRESOURCETYPE RType,
+ D3DFORMAT CheckFormat );
+
+static ULONG WINAPI
+d3dadapter9_AddRef( struct d3dadapter9 *This )
+{
+ ULONG refs = InterlockedIncrement(&This->refs);
+ TRACE("%p increasing refcount to %u.\n", This, refs);
+ return refs;
+}
+
+static ULONG WINAPI
+d3dadapter9_Release( struct d3dadapter9 *This )
+{
+ ULONG refs = InterlockedDecrement(&This->refs);
+ TRACE("%p decreasing refcount to %u.\n", This, refs);
+ if (refs == 0) {
+ /* dtor */
+ if (This->map) {
+ HeapFree(GetProcessHeap(), 0, This->map);
+ }
+
+ if (This->groups) {
+ int i, j;
+ for (i = 0; i < This->ngroups; ++i) {
+ if (This->groups[i].outputs) {
+ for (j = 0; j < This->groups[i].noutputs; ++j) {
+ if (This->groups[i].outputs[j].modes) {
+ HeapFree(GetProcessHeap(), 0,
+ This->groups[i].outputs[j].modes);
+ }
+ }
+ HeapFree(GetProcessHeap(), 0, This->groups[i].outputs);
+ }
+
+ if (This->groups[i].adapter) {
+ ID3DAdapter9_Release(This->groups[i].adapter);
+ }
+ }
+ HeapFree(GetProcessHeap(), 0, This->groups);
+ }
+
+ if (This->hdc) { ReleaseDC(This->hwnd, This->hdc); }
+ if (This->hwnd) { DestroyWindow(This->hwnd); }
+
+ HeapFree(GetProcessHeap(), 0, This);
+ }
+ return refs;
+}
+
+static HRESULT WINAPI
+d3dadapter9_QueryInterface( struct d3dadapter9 *This,
+ REFIID riid,
+ void **ppvObject )
+{
+ if (!ppvObject) { return E_POINTER; }
+ if ((IsEqualGUID(&IID_IDirect3D9Ex, riid) && This->ex) ||
+ IsEqualGUID(&IID_IDirect3D9, riid) ||
+ IsEqualGUID(&IID_IUnknown, riid)) {
+ *ppvObject = This;
+ d3dadapter9_AddRef(This);
+ return S_OK;
+ }
+
+ WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+ *ppvObject = NULL;
+
+ return E_NOINTERFACE;
+}
+
+static HRESULT WINAPI
+d3dadapter9_RegisterSoftwareDevice( struct d3dadapter9 *This,
+ void *pInitializeFunction )
+{
+ FIXME("(%p, %p), stub!\n", This, pInitializeFunction);
+ return D3DERR_INVALIDCALL;
+}
+
+static UINT WINAPI
+d3dadapter9_GetAdapterCount( struct d3dadapter9 *This )
+{
+ return This->nadapters;
+}
+
+static HRESULT WINAPI
+d3dadapter9_GetAdapterIdentifier( struct d3dadapter9 *This,
+ UINT Adapter,
+ DWORD Flags,
+ D3DADAPTER_IDENTIFIER9 *pIdentifier )
+{
+ HRESULT hr;
+ HKEY regkey;
+
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return D3DERR_INVALIDCALL; }
+
+ hr = ADAPTER_PROC(GetAdapterIdentifier, Flags, pIdentifier);
+ if (SUCCEEDED(hr)) {
+ /* Override the driver provided DeviceName with what Wine provided */
+ ZeroMemory(pIdentifier->DeviceName, sizeof(pIdentifier->DeviceName));
+ if (!WideCharToMultiByte(CP_ACP, 0, ADAPTER_GROUP.devname, -1,
+ pIdentifier->DeviceName,
+ sizeof(pIdentifier->DeviceName),
+ NULL, NULL)) {
+ /* Wine does it */
+ return D3DERR_INVALIDCALL;
+ }
+ TRACE("DeviceName overriden: %s\n", pIdentifier->DeviceName);
+
+ /* Override PCI IDs when wined3d registry keys are set */
+ if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", ®key)) {
+ DWORD type, data;
+ DWORD size = sizeof(DWORD);
+
+ if (!RegQueryValueExA(regkey, "VideoPciDeviceID", 0, &type, (BYTE *)&data, &size) && (type == REG_DWORD))
+ pIdentifier->DeviceId = data;
+ if (!RegQueryValueExA(regkey, "VideoPciVendorID", 0, &type, (BYTE *)&data, &size) && (type == REG_DWORD))
+ pIdentifier->VendorId = data;
+ RegCloseKey(regkey);
+
+ TRACE("DeviceId:VendorId overridden: %04X:%04X\n", pIdentifier->DeviceId, pIdentifier->VendorId);
+ }
+ }
+ return hr;
+}
+
+static UINT WINAPI
+d3dadapter9_GetAdapterModeCount( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DFORMAT Format )
+{
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) {
+ WARN("Adapter %u does not exist.\n", Adapter);
+ return 0;
+ }
+ if (FAILED(d3dadapter9_CheckDeviceFormat(This, Adapter, D3DDEVTYPE_HAL,
+ Format, D3DUSAGE_RENDERTARGET,
+ D3DRTYPE_SURFACE, Format))) {
+ WARN("DeviceFormat not available.\n");
+ return 0;
+ }
+
+ TRACE("%u modes.\n", ADAPTER_OUTPUT.nmodes);
+ return ADAPTER_OUTPUT.nmodes;
+}
+
+static HRESULT WINAPI
+d3dadapter9_EnumAdapterModes( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DFORMAT Format,
+ UINT Mode,
+ D3DDISPLAYMODE *pMode )
+{
+ HRESULT hr;
+
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) {
+ WARN("Adapter %u does not exist.\n", Adapter);
+ return D3DERR_INVALIDCALL;
+ }
+
+ hr = d3dadapter9_CheckDeviceFormat(This, Adapter, D3DDEVTYPE_HAL,
+ Format, D3DUSAGE_RENDERTARGET,
+ D3DRTYPE_SURFACE, Format);
+ if (FAILED(hr)) {
+ TRACE("DeviceFormat not available.\n");
+ return hr;
+ }
+
+ if (Mode >= ADAPTER_OUTPUT.nmodes) {
+ WARN("Mode %u does not exist.\n", Mode);
+ return D3DERR_INVALIDCALL;
+ }
+
+ pMode->Width = ADAPTER_OUTPUT.modes[Mode].Width;
+ pMode->Height = ADAPTER_OUTPUT.modes[Mode].Height;
+ pMode->RefreshRate = ADAPTER_OUTPUT.modes[Mode].RefreshRate;
+ pMode->Format = Format;
+
+ return D3D_OK;
+}
+
+static HRESULT WINAPI
+d3dadapter9_GetAdapterDisplayMode( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDISPLAYMODE *pMode )
+{
+ UINT Mode;
+
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) {
+ WARN("Adapter %u does not exist.\n", Adapter);
+ return D3DERR_INVALIDCALL;
+ }
+
+ Mode = ADAPTER_OUTPUT.current;
+ pMode->Width = ADAPTER_OUTPUT.modes[Mode].Width;
+ pMode->Height = ADAPTER_OUTPUT.modes[Mode].Height;
+ pMode->RefreshRate = ADAPTER_OUTPUT.modes[Mode].RefreshRate;
+ pMode->Format = ADAPTER_OUTPUT.modes[Mode].Format;
+
+ return D3D_OK;
+}
+
+static HRESULT WINAPI
+d3dadapter9_CheckDeviceType( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DevType,
+ D3DFORMAT AdapterFormat,
+ D3DFORMAT BackBufferFormat,
+ BOOL bWindowed )
+{
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return D3DERR_INVALIDCALL; }
+ return ADAPTER_PROC(CheckDeviceType,
+ DevType, AdapterFormat, BackBufferFormat, bWindowed);
+}
+
+static HRESULT WINAPI
+d3dadapter9_CheckDeviceFormat( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ D3DFORMAT AdapterFormat,
+ DWORD Usage,
+ D3DRESOURCETYPE RType,
+ D3DFORMAT CheckFormat )
+{
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return D3DERR_INVALIDCALL; }
+ return ADAPTER_PROC(CheckDeviceFormat,
+ DeviceType, AdapterFormat, Usage, RType, CheckFormat);
+}
+
+static HRESULT WINAPI
+d3dadapter9_CheckDeviceMultiSampleType( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ D3DFORMAT SurfaceFormat,
+ BOOL Windowed,
+ D3DMULTISAMPLE_TYPE MultiSampleType,
+ DWORD *pQualityLevels )
+{
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return D3DERR_INVALIDCALL; }
+ return ADAPTER_PROC(CheckDeviceMultiSampleType, DeviceType, SurfaceFormat,
+ Windowed, MultiSampleType, pQualityLevels);
+}
+
+static HRESULT WINAPI
+d3dadapter9_CheckDepthStencilMatch( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ D3DFORMAT AdapterFormat,
+ D3DFORMAT RenderTargetFormat,
+ D3DFORMAT DepthStencilFormat )
+{
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return D3DERR_INVALIDCALL; }
+ return ADAPTER_PROC(CheckDepthStencilMatch, DeviceType, AdapterFormat,
+ RenderTargetFormat, DepthStencilFormat);
+}
+
+static HRESULT WINAPI
+d3dadapter9_CheckDeviceFormatConversion( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ D3DFORMAT SourceFormat,
+ D3DFORMAT TargetFormat )
+{
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return D3DERR_INVALIDCALL; }
+ return ADAPTER_PROC(CheckDeviceFormatConversion,
+ DeviceType, SourceFormat, TargetFormat);
+}
+
+static HRESULT WINAPI
+d3dadapter9_GetDeviceCaps( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ D3DCAPS9 *pCaps )
+{
+ HRESULT hr;
+
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return D3DERR_INVALIDCALL; }
+
+ hr = ADAPTER_PROC(GetDeviceCaps, DeviceType, pCaps);
+ if (FAILED(hr)) { return hr; }
+
+ pCaps->MasterAdapterOrdinal = This->map[Adapter].master;
+ pCaps->AdapterOrdinalInGroup = Adapter-This->map[Adapter].master;
+ pCaps->NumberOfAdaptersInGroup = ADAPTER_GROUP.noutputs;
+
+ return hr;
+}
+
+static HMONITOR WINAPI
+d3dadapter9_GetAdapterMonitor( struct d3dadapter9 *This,
+ UINT Adapter )
+{
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return (HMONITOR)0; }
+ return (HMONITOR)ADAPTER_OUTPUT.monitor;
+}
+
+static HRESULT WINAPI
+d3dadapter9_CreateDeviceEx( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ HWND hFocusWindow,
+ DWORD BehaviorFlags,
+ D3DPRESENT_PARAMETERS *pPresentationParameters,
+ D3DDISPLAYMODEEX *pFullscreenDisplayMode,
+ IDirect3DDevice9Ex **ppReturnedDeviceInterface );
+
+static HRESULT WINAPI
+d3dadapter9_CreateDevice( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ HWND hFocusWindow,
+ DWORD BehaviorFlags,
+ D3DPRESENT_PARAMETERS *pPresentationParameters,
+ IDirect3DDevice9 **ppReturnedDeviceInterface )
+{
+ HRESULT hr;
+ hr = d3dadapter9_CreateDeviceEx(This, Adapter, DeviceType, hFocusWindow,
+ BehaviorFlags, pPresentationParameters,
+ NULL,
+ (IDirect3DDevice9Ex **)ppReturnedDeviceInterface);
+ if (FAILED(hr))
+ return hr;
+ return D3D_OK;
+}
+
+static UINT WINAPI
+d3dadapter9_GetAdapterModeCountEx( struct d3dadapter9 *This,
+ UINT Adapter,
+ const D3DDISPLAYMODEFILTER *pFilter )
+{
+ return 1;
+}
+
+static HRESULT WINAPI
+d3dadapter9_EnumAdapterModesEx( struct d3dadapter9 *This,
+ UINT Adapter,
+ const D3DDISPLAYMODEFILTER *pFilter,
+ UINT Mode,
+ D3DDISPLAYMODEEX *pMode )
+{
+ FIXME("(%p, %u, %p, %u, %p), stub!\n", This, Adapter, pFilter, Mode, pMode);
+ return D3DERR_INVALIDCALL;
+}
+
+static HRESULT WINAPI
+d3dadapter9_GetAdapterDisplayModeEx( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDISPLAYMODEEX *pMode,
+ D3DDISPLAYROTATION *pRotation )
+{
+ FIXME("(%p, %u, %p, %p), stub!\n", This, Adapter, pMode, pRotation);
+ return D3DERR_INVALIDCALL;
+}
+
+static HRESULT WINAPI
+d3dadapter9_CreateDeviceEx( struct d3dadapter9 *This,
+ UINT Adapter,
+ D3DDEVTYPE DeviceType,
+ HWND hFocusWindow,
+ DWORD BehaviorFlags,
+ D3DPRESENT_PARAMETERS *pPresentationParameters,
+ D3DDISPLAYMODEEX *pFullscreenDisplayMode,
+ IDirect3DDevice9Ex **ppReturnedDeviceInterface )
+{
+ ID3DPresentGroup *present;
+ HRESULT hr;
+
+ if (Adapter >= d3dadapter9_GetAdapterCount(This)) {
+ WARN("Adapter %u does not exist.\n", Adapter);
+ return D3DERR_INVALIDCALL;
+ }
+
+ {
+ struct adapter_group *group = &ADAPTER_GROUP;
+ unsigned nparams, ordinal;
+
+ if (BehaviorFlags & D3DCREATE_ADAPTERGROUP_DEVICE) {
+ nparams = group->noutputs;
+ ordinal = 0;
+ } else {
+ nparams = 1;
+ ordinal = Adapter - This->map[Adapter].master;
+ }
+ hr = This->funcs->create_present_group(group->devname, ordinal,
+ hFocusWindow,
+ pPresentationParameters,
+ nparams, &present);
+ }
+
+ if (FAILED(hr)) {
+ WARN("Failed to create PresentGroup.\n");
+ return hr;
+ }
+
+ if (This->ex) {
+ hr = ADAPTER_PROC(CreateDeviceEx, Adapter, DeviceType, hFocusWindow,
+ BehaviorFlags, pPresentationParameters,
+ pFullscreenDisplayMode,
+ (IDirect3D9Ex *)This, present,
+ ppReturnedDeviceInterface);
+ } else { /* CreateDevice on non-ex */
+ hr = ADAPTER_PROC(CreateDevice, Adapter, DeviceType, hFocusWindow,
+ BehaviorFlags, pPresentationParameters,
+ (IDirect3D9 *)This, present,
+ (IDirect3DDevice9 **)ppReturnedDeviceInterface);
+ }
+ if (FAILED(hr)) {
+ WARN("ADAPTER_PROC failed.\n");
+ ID3DPresentGroup_Release(present);
+ }
+
+ return hr;
+}
+
+static HRESULT WINAPI
+d3dadapter9_GetAdapterLUID( struct d3dadapter9 *This,
+ UINT Adapter,
+ LUID *pLUID )
+{
+ FIXME("(%p, %u, %p), stub!\n", This, Adapter, pLUID);
+ return D3DERR_INVALIDCALL;
+}
+
+static struct adapter_group *
+add_group( struct d3dadapter9 *This )
+{
+ if (This->ngroups >= This->ngroupsalloc) {
+ void *r;
+
+ if (This->ngroupsalloc == 0) {
+ This->ngroupsalloc = 2;
+ r = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+ This->ngroupsalloc*sizeof(struct adapter_group));
+ } else {
+ This->ngroupsalloc <<= 1;
+ r = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->groups,
+ This->ngroupsalloc*sizeof(struct adapter_group));
+ }
+
+ if (!r) { return NULL; }
+ This->groups = r;
+ }
+
+ return &This->groups[This->ngroups++];
+}
+
+static void
+remove_group( struct d3dadapter9 *This )
+{
+ struct adapter_group *group = &This->groups[This->ngroups-1];
+ int i;
+
+ for (i = 0; i < group->noutputs; ++i) {
+ HeapFree(GetProcessHeap(), 0, group->outputs[i].modes);
+ }
+ HeapFree(GetProcessHeap(), 0, group->outputs);
+
+ ZeroMemory(group, sizeof(struct adapter_group));
+ This->ngroups--;
+}
+
+static struct output *
+add_output( struct d3dadapter9 *This )
+{
+ struct adapter_group *group = &This->groups[This->ngroups-1];
+
+ if (group->noutputs >= group->noutputsalloc) {
+ void *r;
+
+ if (group->noutputsalloc == 0) {
+ group->noutputsalloc = 2;
+ r = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+ group->noutputsalloc*sizeof(struct output));
+ } else {
+ group->noutputsalloc <<= 1;
+ r = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, group->outputs,
+ group->noutputsalloc*sizeof(struct output));
+ }
+
+ if (!r) { return NULL; }
+ group->outputs = r;
+ }
+
+ return &group->outputs[group->noutputs++];
+}
+
+static void
+remove_output( struct d3dadapter9 *This )
+{
+ struct adapter_group *group = &This->groups[This->ngroups-1];
+ struct output *out = &group->outputs[group->noutputs-1];
+
+ HeapFree(GetProcessHeap(), 0, out->modes);
+
+ ZeroMemory(out, sizeof(struct output));
+ group->noutputs--;
+}
+
+static D3DDISPLAYMODEEX *
+add_mode( struct d3dadapter9 *This )
+{
+ struct adapter_group *group = &This->groups[This->ngroups-1];