taskmgr: Fix some gcc 4.1 warnings.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 wined3d_settings_t wined3d_settings = 
36 {
37   VS_HW,   /* Hardware by default */
38   PS_NONE, /* Disabled by default */
39   VBO_HW   /* Hardware by default */
40 };
41
42 WineD3DGlobalStatistics *wineD3DGlobalStatistics = NULL;
43 CRITICAL_SECTION resourceStoreCriticalSection;
44
45 long globalChangeGlRam(long glram){
46     /* FIXME: replace this function with object tracking */
47     int result;
48
49     EnterCriticalSection(&resourceStoreCriticalSection); /* this is overkill really, but I suppose it should be thread safe */
50     wineD3DGlobalStatistics->glsurfaceram     += glram;
51     TRACE("Adjusted gl ram by %ld to %d\n", glram, wineD3DGlobalStatistics->glsurfaceram);
52     result = wineD3DGlobalStatistics->glsurfaceram;
53     LeaveCriticalSection(&resourceStoreCriticalSection);
54     return result;
55
56 }
57
58 IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion, IUnknown *parent) {
59     IWineD3DImpl* object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
60     object->lpVtbl = &IWineD3D_Vtbl;
61     object->dxVersion = dxVersion;
62     object->ref = 1;
63     object->parent = parent;
64
65     /* TODO: Move this off to device and possibly x11drv */
66     /* Create a critical section for a dll global data store */
67     InitializeCriticalSectionAndSpinCount(&resourceStoreCriticalSection, 0x80000400);
68
69     /*Create a structure for storing global data in*/
70     if(wineD3DGlobalStatistics == NULL){
71         TRACE("Createing global statistics store\n");
72         wineD3DGlobalStatistics = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wineD3DGlobalStatistics));
73
74     }
75
76
77     TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
78
79     return (IWineD3D *)object;
80 }
81
82 inline static DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
83 {
84     if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
85     if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
86     return ERROR_FILE_NOT_FOUND;
87 }
88
89 /* At process attach */
90 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
91 {
92     TRACE("WineD3D DLLMain Reason=%ld\n", fdwReason);
93     if (fdwReason == DLL_PROCESS_ATTACH)
94     {
95        HMODULE mod;
96        char buffer[MAX_PATH+10];
97        DWORD size = sizeof(buffer);
98        HKEY hkey = 0;
99        HKEY appkey = 0;
100        DWORD len;
101
102        DisableThreadLibraryCalls(hInstDLL);
103
104        mod = GetModuleHandleA( "winex11.drv" );
105        if (mod)
106        {
107            wine_tsx11_lock_ptr   = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
108            wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
109        }
110        /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
111        if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
112
113        len = GetModuleFileNameA( 0, buffer, MAX_PATH );
114        if (len && len < MAX_PATH)
115        {
116             HKEY tmpkey;
117             /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
118             if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
119             {
120                 char *p, *appname = buffer;
121                 if ((p = strrchr( appname, '/' ))) appname = p + 1;
122                 if ((p = strrchr( appname, '\\' ))) appname = p + 1;
123                 strcat( appname, "\\Direct3D" );
124                 TRACE("appname = [%s]\n", appname);
125                 if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
126                 RegCloseKey( tmpkey );
127             }
128        }
129
130        if ( 0 != hkey || 0 != appkey )
131        {
132             if ( !get_config_key( hkey, appkey, "VertexShaderMode", buffer, size) )
133             {
134                 if (!strcmp(buffer,"none"))
135                 {
136                     TRACE("Disable vertex shaders\n");
137                     wined3d_settings.vs_mode = VS_NONE;
138                 }
139                 else if (!strcmp(buffer,"emulation"))
140                 {
141                     TRACE("Force SW vertex shaders\n");
142                     wined3d_settings.vs_mode = VS_SW;
143                 }
144             }
145             if ( !get_config_key( hkey, appkey, "PixelShaderMode", buffer, size) )
146             {
147                 if (!strcmp(buffer,"enabled"))
148                 {
149                     TRACE("Allow pixel shaders\n");
150                     wined3d_settings.ps_mode = PS_HW;
151                 }
152                 if (!strcmp(buffer,"disabled"))
153                 {
154                     TRACE("Disable pixel shaders\n");
155                     wined3d_settings.ps_mode = PS_NONE;
156                 }
157             }
158             if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
159             {
160                 if (!strcmp(buffer,"none"))
161                 {
162                     TRACE("Disable Vertex Buffer Hardware support\n");
163                     wined3d_settings.vbo_mode = VBO_NONE;
164                 }
165                 else if (!strcmp(buffer,"hardware"))
166                 {
167                     TRACE("Allow Vertex Buffer Hardware support\n");
168                     wined3d_settings.vbo_mode = VBO_HW;
169                 }
170             }
171             if ( !get_config_key( hkey, appkey, "Nonpower2Mode", buffer, size) )
172             {
173                 if (!strcmp(buffer,"none"))
174                 {
175                     TRACE("Using default non-power2 textures\n");
176                     wined3d_settings.nonpower2_mode = NP2_NONE;
177
178                 }
179                 else if (!strcmp(buffer,"repack"))
180                 {
181                     TRACE("Repacking non-power2 textre\n");
182                     wined3d_settings.nonpower2_mode = NP2_REPACK;
183                 }
184                 /* There will be a couple of other choices for nonpow2, they are: TextureRecrangle and OpenGL 2 */
185             }
186        }
187        if (wined3d_settings.vs_mode == VS_HW)
188            TRACE("Allow HW vertex shaders\n");
189        if (wined3d_settings.ps_mode == PS_NONE)
190            TRACE("Disable pixel shaders\n");
191        if (wined3d_settings.vbo_mode == VBO_NONE)
192            TRACE("Disable Vertex Buffer Hardware support\n");
193        if (wined3d_settings.nonpower2_mode == NP2_REPACK)
194            TRACE("Repacking non-power2 textures\n");
195
196        if (appkey) RegCloseKey( appkey );
197        if (hkey) RegCloseKey( hkey );
198     }
199     return TRUE;
200 }