wintrust: Remove redundant check of pbSignedDataMsg (Coverity).
[wine] / dlls / wined3d / wined3d_main.c
1 /*
2  * Direct3D wine internal interface main
3  *
4  * Copyright 2002-2003 The wine-d3d team
5  * Copyright 2002-2003 Raphael Junqueira
6  * Copyright 2004      Jason Edmeades
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24
25 #include "initguid.h"
26 #include "wined3d_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(wine_d3d);
29
30 int num_lock = 0;
31 void (*wine_tsx11_lock_ptr)(void) = NULL;
32 void (*wine_tsx11_unlock_ptr)(void) = NULL;
33
34
35 /* When updating default value here, make sure to update winecfg as well,
36  * where appropriate. */
37 wined3d_settings_t wined3d_settings = 
38 {
39     VS_HW,          /* Hardware by default */
40     PS_HW,          /* Hardware by default */
41     VBO_HW,         /* Hardware by default */
42     FALSE,          /* Use of GLSL disabled by default */
43     ORM_BACKBUFFER, /* Use the backbuffer to do offscreen rendering */
44     RTL_AUTO,       /* Automatically determine best locking method */
45     64*1024*1024    /* 64MB texture memory by default */
46 };
47
48 WineD3DGlobalStatistics *wineD3DGlobalStatistics = NULL;
49
50 long globalChangeGlRam(long glram){
51     /* FIXME: replace this function with object tracking */
52     int result;
53
54     wineD3DGlobalStatistics->glsurfaceram     += glram;
55     TRACE("Adjusted gl ram by %ld to %d\n", glram, wineD3DGlobalStatistics->glsurfaceram);
56     result = wineD3DGlobalStatistics->glsurfaceram;
57     return result;
58
59 }
60
61 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
62     IWineD3DImpl* object;
63
64     if (!InitAdapters()) {
65         WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
66         if(dxVersion > 7) {
67             ERR("Direct3D%d is not available without opengl\n", dxVersion);
68             return NULL;
69         }
70     }
71
72     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
73     object->lpVtbl = &IWineD3D_Vtbl;
74     object->dxVersion = dxVersion;
75     object->ref = 1;
76     object->parent = parent;
77
78     /*Create a structure for storing global data in*/
79     if(wineD3DGlobalStatistics == NULL){
80         TRACE("Creating global statistics store\n");
81         wineD3DGlobalStatistics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wineD3DGlobalStatistics));
82
83     }
84
85     TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
86
87     return (IWineD3D *)object;
88 }
89
90 static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
91 {
92     if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
93     if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
94     return ERROR_FILE_NOT_FOUND;
95 }
96
97 static void wined3d_do_nothing(void)
98 {
99 }
100
101 /* At process attach */
102 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
103 {
104     TRACE("WineD3D DLLMain Reason=%d\n", fdwReason);
105     if (fdwReason == DLL_PROCESS_ATTACH)
106     {
107        HMODULE mod;
108        char buffer[MAX_PATH+10];
109        DWORD size = sizeof(buffer);
110        HKEY hkey = 0;
111        HKEY appkey = 0;
112        DWORD len;
113        WNDCLASSA wc;
114
115        wined3d_settings.emulated_textureram = 64*1024*1024;
116
117        /* We need our own window class for a fake window which we use to retrieve GL capabilities */
118        /* We might need CS_OWNDC in the future if we notice strange things on Windows.
119         * Various articles/posts about OpenGL problems on Windows recommend this. */
120        wc.style                = CS_HREDRAW | CS_VREDRAW;
121        wc.lpfnWndProc          = DefWindowProcA;
122        wc.cbClsExtra           = 0;
123        wc.cbWndExtra           = 0;
124        wc.hInstance            = hInstDLL;
125        wc.hIcon                = LoadIconA(NULL, (LPCSTR)IDI_WINLOGO);
126        wc.hCursor              = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
127        wc.hbrBackground        = NULL;
128        wc.lpszMenuName         = NULL;
129        wc.lpszClassName        = "WineD3D_OpenGL";
130
131        if (!RegisterClassA(&wc) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
132        {
133            ERR("Failed to register window class 'WineD3D_OpenGL'!\n");
134            return FALSE;
135        }
136
137        DisableThreadLibraryCalls(hInstDLL);
138
139        mod = GetModuleHandleA( "winex11.drv" );
140        if (mod)
141        {
142            wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
143            wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
144        }
145        else /* We are most likely on Windows */
146        {
147            wine_tsx11_lock_ptr   = wined3d_do_nothing;
148            wine_tsx11_unlock_ptr = wined3d_do_nothing;
149        }
150        /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
151        if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
152
153        len = GetModuleFileNameA( 0, buffer, MAX_PATH );
154        if (len && len < MAX_PATH)
155        {
156             HKEY tmpkey;
157             /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
158             if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
159             {
160                 char *p, *appname = buffer;
161                 if ((p = strrchr( appname, '/' ))) appname = p + 1;
162                 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
163                 strcat( appname, "\\Direct3D" );
164                 TRACE("appname = [%s]\n", appname);
165                 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
166                 RegCloseKey( tmpkey );
167             }
168        }
169
170        if ( 0 != hkey || 0 != appkey )
171        {
172             if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
173             {
174                 if (!strcmp(buffer,"none"))
175                 {
176                     TRACE("Disable vertex shaders\n");
177                     wined3d_settings.vs_mode = VS_NONE;
178                 }
179             }
180             if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
181             {
182                 if (!strcmp(buffer,"enabled"))
183                 {
184                     TRACE("Allow pixel shaders\n");
185                     wined3d_settings.ps_mode = PS_HW;
186                 }
187                 if (!strcmp(buffer,"disabled"))
188                 {
189                     TRACE("Disable pixel shaders\n");
190                     wined3d_settings.ps_mode = PS_NONE;
191                 }
192             }
193             if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
194             {
195                 if (!strcmp(buffer,"none"))
196                 {
197                     TRACE("Disable Vertex Buffer Hardware support\n");
198                     wined3d_settings.vbo_mode = VBO_NONE;
199                 }
200                 else if (!strcmp(buffer,"hardware"))
201                 {
202                     TRACE("Allow Vertex Buffer Hardware support\n");
203                     wined3d_settings.vbo_mode = VBO_HW;
204                 }
205             }
206             if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
207             {
208                 if (!strcmp(buffer,"enabled"))
209                 {
210                     TRACE("Use of GL Shading Language enabled for systems that support it\n");
211                     wined3d_settings.glslRequested = TRUE;
212                 }
213                 else
214                 {
215                     TRACE("Use of GL Shading Language disabled\n");
216                 }
217             }
218             if ( !get_config_key( hkey, appkey, "OffscreenRenderingMode", buffer, size) )
219             {
220                 if (!strcmp(buffer,"backbuffer"))
221                 {
222                     TRACE("Using the backbuffer for offscreen rendering\n");
223                     wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
224                 }
225                 else if (!strcmp(buffer,"pbuffer"))
226                 {
227                     TRACE("Using PBuffers for offscreen rendering\n");
228                     wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
229                 }
230                 else if (!strcmp(buffer,"fbo"))
231                 {
232                     TRACE("Using FBOs for offscreen rendering\n");
233                     wined3d_settings.offscreen_rendering_mode = ORM_FBO;
234                 }
235             }
236             if ( !get_config_key( hkey, appkey, "RenderTargetLockMode", buffer, size) )
237             {
238                 if (!strcmp(buffer,"disabled"))
239                 {
240                     TRACE("Disabling render target locking\n");
241                     wined3d_settings.rendertargetlock_mode = RTL_DISABLE;
242                 }
243                 else if (!strcmp(buffer,"readdraw"))
244                 {
245                     TRACE("Using glReadPixels for render target reading and glDrawPixels for writing\n");
246                     wined3d_settings.rendertargetlock_mode = RTL_READDRAW;
247                 }
248                 else if (!strcmp(buffer,"readtex"))
249                 {
250                     TRACE("Using glReadPixels for render target reading and textures for writing\n");
251                     wined3d_settings.rendertargetlock_mode = RTL_READTEX;
252                 }
253                 else if (!strcmp(buffer,"texdraw"))
254                 {
255                     TRACE("Using textures for render target reading and glDrawPixels for writing\n");
256                     wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
257                 }
258                 else if (!strcmp(buffer,"textex"))
259                 {
260                     TRACE("Reading render targets via textures and writing via textures\n");
261                     wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
262                 }
263             }
264             if ( !get_config_key( hkey, appkey, "VideoMemorySize", buffer, size) )
265             {
266                 int TmpVideoMemorySize = atoi(buffer);
267                 if(TmpVideoMemorySize > 0)
268                 {
269                     wined3d_settings.emulated_textureram = TmpVideoMemorySize *1024*1024;
270                     TRACE("Use %iMB = %d byte for emulated_textureram\n",
271                             TmpVideoMemorySize,
272                             wined3d_settings.emulated_textureram);
273                 }
274                 else
275                     ERR("VideoMemorySize is %i but must be >0\n", TmpVideoMemorySize);
276             }
277        }
278        if (wined3d_settings.vs_mode == VS_HW)
279            TRACE("Allow HW vertex shaders\n");
280        if (wined3d_settings.ps_mode == PS_NONE)
281            TRACE("Disable pixel shaders\n");
282        if (wined3d_settings.vbo_mode == VBO_NONE)
283            TRACE("Disable Vertex Buffer Hardware support\n");
284        if (wined3d_settings.glslRequested)
285            TRACE("If supported by your system, GL Shading Language will be used\n");
286
287        if (appkey) RegCloseKey( appkey );
288        if (hkey) RegCloseKey( hkey );
289     }
290     return TRUE;
291 }