author | amenkov |
Thu, 25 Nov 2010 15:58:11 +0300 | |
changeset 7256 | adb296cc2eae |
parent 7004 | 3f92ea1ffcac |
child 7491 | ba3dc59cd2fd |
permissions | -rw-r--r-- |
887 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. |
887 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
887 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
887 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
887 | 24 |
*/ |
25 |
||
26 |
#include "D3DBadHardware.h" |
|
27 |
#include "D3DPipelineManager.h" |
|
28 |
#include "D3DRenderQueue.h" |
|
29 |
#include "WindowsFlags.h" |
|
30 |
#include "awt_Win32GraphicsDevice.h" |
|
31 |
||
32 |
// state of the adapter prior to initialization |
|
33 |
#define CONTEXT_NOT_INITED 0 |
|
34 |
// this state is set if adapter initialization had failed |
|
35 |
#define CONTEXT_INIT_FAILED (-1) |
|
36 |
// this state is set if adapter was successfully created |
|
37 |
#define CONTEXT_CREATED 1 |
|
38 |
||
39 |
static BOOL bNoHwCheck = (getenv("J2D_D3D_NO_HWCHECK") != NULL); |
|
40 |
||
41 |
D3DPipelineManager *D3DPipelineManager::pMgr = NULL; |
|
42 |
||
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
43 |
|
887 | 44 |
D3DPipelineManager * D3DPipelineManager::CreateInstance(void) |
45 |
{ |
|
46 |
if (!IsD3DEnabled() || |
|
47 |
FAILED((D3DPipelineManager::CheckOSVersion())) || |
|
48 |
FAILED((D3DPipelineManager::GDICheckForBadHardware()))) |
|
49 |
{ |
|
50 |
return NULL; |
|
51 |
} |
|
52 |
||
53 |
if (pMgr == NULL) { |
|
54 |
pMgr = new D3DPipelineManager(); |
|
55 |
if (FAILED(pMgr->InitD3D())) { |
|
56 |
SAFE_DELETE(pMgr); |
|
57 |
} |
|
58 |
} else { |
|
59 |
// this should never happen so to be on the safe side do not |
|
60 |
// use this unexpected pointer, do not try to release it, just null |
|
61 |
// it out and fail safely |
|
62 |
J2dRlsTraceLn1(J2D_TRACE_ERROR, |
|
63 |
"D3DPPLM::CreateInstance: unexpected instance: 0x%x,"\ |
|
64 |
" abort.", pMgr); |
|
65 |
pMgr = NULL; |
|
66 |
} |
|
67 |
return pMgr; |
|
68 |
} |
|
69 |
||
70 |
void D3DPipelineManager::DeleteInstance() |
|
71 |
{ |
|
72 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::DeleteInstance()"); |
|
73 |
SAFE_DELETE(pMgr); |
|
74 |
} |
|
75 |
||
76 |
D3DPipelineManager * D3DPipelineManager::GetInstance(void) |
|
77 |
{ |
|
78 |
return pMgr; |
|
79 |
} |
|
80 |
||
81 |
D3DPipelineManager::D3DPipelineManager(void) |
|
82 |
{ |
|
83 |
pd3d9 = NULL; |
|
84 |
hLibD3D9 = NULL; |
|
85 |
pAdapters = NULL; |
|
86 |
adapterCount = 0; |
|
87 |
currentFSFocusAdapter = -1; |
|
88 |
defaultFocusWindow = 0; |
|
89 |
devType = SelectDeviceType(); |
|
90 |
} |
|
91 |
||
92 |
D3DPipelineManager::~D3DPipelineManager(void) |
|
93 |
{ |
|
94 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::~D3DPipelineManager()"); |
|
95 |
ReleaseD3D(); |
|
96 |
} |
|
97 |
||
98 |
HRESULT D3DPipelineManager::ReleaseD3D(void) |
|
99 |
{ |
|
100 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::ReleaseD3D()"); |
|
101 |
||
102 |
ReleaseAdapters(); |
|
103 |
||
104 |
SAFE_RELEASE(pd3d9); |
|
105 |
||
106 |
if (hLibD3D9 != NULL) { |
|
107 |
::FreeLibrary(hLibD3D9); |
|
108 |
hLibD3D9 = NULL; |
|
109 |
} |
|
110 |
||
111 |
return S_OK; |
|
112 |
} |
|
113 |
||
114 |
// Creates a Direct3D9 object and initializes adapters. |
|
115 |
// If succeeded, returns S_OK, otherwise returns the error code. |
|
116 |
HRESULT D3DPipelineManager::InitD3D(void) |
|
117 |
{ |
|
118 |
typedef IDirect3D9 * WINAPI FnDirect3DCreate9(UINT SDKVersion); |
|
119 |
||
120 |
hLibD3D9 = ::LoadLibrary(TEXT("d3d9.dll")); |
|
121 |
if (hLibD3D9 == NULL) { |
|
122 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "InitD3D: no d3d9.dll"); |
|
123 |
return E_FAIL; |
|
124 |
} |
|
125 |
||
126 |
FnDirect3DCreate9 *d3dcreate9 = NULL; |
|
127 |
d3dcreate9 = (FnDirect3DCreate9*) |
|
128 |
::GetProcAddress(hLibD3D9, "Direct3DCreate9"); |
|
129 |
if (d3dcreate9 == NULL) { |
|
130 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "InitD3D: no Direct3DCreate9"); |
|
131 |
::FreeLibrary(hLibD3D9); |
|
132 |
return E_FAIL; |
|
133 |
} |
|
134 |
||
135 |
pd3d9 = d3dcreate9(D3D_SDK_VERSION); |
|
136 |
if (pd3d9 == NULL) { |
|
137 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
138 |
"InitD3D: unable to create IDirect3D9 object"); |
|
139 |
::FreeLibrary(hLibD3D9); |
|
140 |
return E_FAIL; |
|
141 |
} |
|
142 |
||
143 |
HRESULT res; |
|
144 |
if (FAILED(res = InitAdapters())) { |
|
145 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "InitD3D: failed to init adapters"); |
|
146 |
ReleaseD3D(); |
|
147 |
return res; |
|
148 |
} |
|
149 |
||
150 |
return S_OK; |
|
151 |
} |
|
152 |
||
153 |
HRESULT D3DPipelineManager::ReleaseAdapters() |
|
154 |
{ |
|
155 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::ReleaseAdapters()"); |
|
156 |
||
157 |
D3DRQ_ResetCurrentContextAndDestination(); |
|
158 |
if (pAdapters != NULL) { |
|
159 |
for (UINT i = 0; i < adapterCount; i++) { |
|
160 |
if (pAdapters[i].pd3dContext != NULL) { |
|
161 |
delete pAdapters[i].pd3dContext; |
|
162 |
} |
|
163 |
} |
|
164 |
delete[] pAdapters; |
|
165 |
pAdapters = NULL; |
|
166 |
} |
|
167 |
if (defaultFocusWindow != 0) { |
|
168 |
DestroyWindow(defaultFocusWindow); |
|
169 |
UnregisterClass(L"D3DFocusWindow", GetModuleHandle(NULL)); |
|
170 |
defaultFocusWindow = 0; |
|
171 |
} |
|
172 |
currentFSFocusAdapter = -1; |
|
173 |
return S_OK; |
|
174 |
} |
|
175 |
||
176 |
// static |
|
177 |
void D3DPipelineManager::NotifyAdapterEventListeners(UINT adapter, |
|
178 |
jint eventType) |
|
179 |
{ |
|
180 |
HMONITOR hMon; |
|
181 |
int gdiScreen; |
|
182 |
D3DPipelineManager *pMgr; |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
183 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
184 |
// fix for 6946559: if d3d preloading fails jmv may be NULL |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
185 |
if (jvm == NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
186 |
return; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
187 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
188 |
|
887 | 189 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
190 |
||
191 |
pMgr = D3DPipelineManager::GetInstance(); |
|
192 |
RETURN_IF_NULL(pMgr); |
|
193 |
hMon = pMgr->pd3d9->GetAdapterMonitor(adapter); |
|
1954 | 194 |
gdiScreen = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(hMon); |
887 | 195 |
|
196 |
JNU_CallStaticMethodByName(env, NULL, |
|
197 |
"sun/java2d/pipe/hw/AccelDeviceEventNotifier", |
|
198 |
"eventOccured", "(II)V", |
|
199 |
gdiScreen, eventType); |
|
200 |
} |
|
201 |
||
202 |
UINT D3DPipelineManager::GetAdapterOrdinalForScreen(jint gdiScreen) |
|
203 |
{ |
|
1954 | 204 |
HMONITOR mHnd = AwtWin32GraphicsDevice::GetMonitor(gdiScreen); |
205 |
if (mHnd == (HMONITOR)0) { |
|
887 | 206 |
return D3DADAPTER_DEFAULT; |
207 |
} |
|
208 |
return GetAdapterOrdinalByHmon((HMONITOR)mHnd); |
|
209 |
} |
|
210 |
||
211 |
// static |
|
1954 | 212 |
HRESULT D3DPipelineManager::HandleAdaptersChange(HMONITOR *pHMONITORs, UINT monNum) |
887 | 213 |
{ |
214 |
HRESULT res = S_OK; |
|
215 |
BOOL bResetD3D = FALSE, bFound; |
|
216 |
||
217 |
D3DPipelineManager *pMgr = D3DPipelineManager::GetInstance(); |
|
1954 | 218 |
RETURN_STATUS_IF_NULL(pHMONITORs, E_FAIL); |
887 | 219 |
if (pMgr == NULL) { |
220 |
// NULL pMgr is valid when the pipeline is not enabled or if it hasn't |
|
221 |
// been created yet |
|
222 |
return S_OK; |
|
223 |
} |
|
224 |
RETURN_STATUS_IF_NULL(pMgr->pAdapters, E_FAIL); |
|
225 |
RETURN_STATUS_IF_NULL(pMgr->pd3d9, E_FAIL); |
|
226 |
||
227 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::HandleAdaptersChange"); |
|
228 |
||
229 |
if (monNum != pMgr->adapterCount) { |
|
230 |
J2dTraceLn2(J2D_TRACE_VERBOSE, |
|
231 |
" number of adapters changed (old=%d, new=%d)", |
|
232 |
pMgr->adapterCount, monNum); |
|
233 |
bResetD3D = TRUE; |
|
234 |
} else { |
|
235 |
for (UINT i = 0; i < pMgr->adapterCount; i++) { |
|
236 |
HMONITOR hMon = pMgr->pd3d9->GetAdapterMonitor(i); |
|
237 |
if (hMon == (HMONITOR)0x0) { |
|
238 |
J2dTraceLn1(J2D_TRACE_VERBOSE, " adapter %d: removed", i); |
|
239 |
bResetD3D = TRUE; |
|
240 |
break; |
|
241 |
} |
|
242 |
bFound = FALSE; |
|
243 |
for (UINT mon = 0; mon < monNum; mon++) { |
|
1954 | 244 |
if (pHMONITORs[mon] == hMon) { |
887 | 245 |
J2dTraceLn3(J2D_TRACE_VERBOSE, |
246 |
" adapter %d: found hmnd[%d]=0x%x", i, mon, hMon); |
|
247 |
bFound = TRUE; |
|
248 |
break; |
|
249 |
} |
|
250 |
} |
|
251 |
if (!bFound) { |
|
252 |
J2dTraceLn2(J2D_TRACE_VERBOSE, |
|
253 |
" adapter %d: could not find hmnd=0x%x "\ |
|
254 |
"in the list of new hmnds", i, hMon); |
|
255 |
bResetD3D = TRUE; |
|
256 |
break; |
|
257 |
} |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
if (bResetD3D) { |
|
262 |
J2dTraceLn(J2D_TRACE_VERBOSE, " adapters changed: resetting d3d"); |
|
263 |
pMgr->ReleaseD3D(); |
|
264 |
res = pMgr->InitD3D(); |
|
265 |
} |
|
266 |
return res; |
|
267 |
} |
|
268 |
||
269 |
HRESULT D3DPipelineManager::HandleLostDevices() |
|
270 |
{ |
|
271 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::HandleLostDevices()"); |
|
272 |
BOOL bAllClear = TRUE; |
|
273 |
||
274 |
HWND hwnd = GetCurrentFocusWindow(); |
|
275 |
if (hwnd != defaultFocusWindow) { |
|
276 |
// we're in full-screen mode |
|
277 |
WINDOWPLACEMENT wp; |
|
278 |
::ZeroMemory(&wp, sizeof(WINDOWPLACEMENT)); |
|
279 |
wp.length = sizeof(WINDOWPLACEMENT); |
|
280 |
::GetWindowPlacement(hwnd, &wp); |
|
281 |
||
282 |
// Only attempt to restore the devices if we're in full-screen mode |
|
283 |
// and the fs window is active; sleep otherwise. |
|
284 |
// Restoring a window while minimized causes problems on Vista: |
|
285 |
// sometimes we restore the window too quickly and it pops up back from |
|
286 |
// minimized state when the device is restored. |
|
287 |
// |
|
288 |
// WARNING: this is a sleep on the Toolkit thread! We may reconsider |
|
289 |
// this if we find any issues later. |
|
290 |
if ((wp.showCmd & SW_SHOWMINNOACTIVE) && !(wp.showCmd & SW_SHOWNORMAL)){ |
|
291 |
static DWORD prevCallTime = 0; |
|
292 |
J2dTraceLn(J2D_TRACE_VERBOSE, " fs focus window is minimized"); |
|
293 |
DWORD currentTime = ::GetTickCount(); |
|
294 |
if ((currentTime - prevCallTime) < 100) { |
|
295 |
J2dTraceLn(J2D_TRACE_VERBOSE, " tight loop detected, sleep"); |
|
296 |
::Sleep(100); |
|
297 |
} |
|
298 |
prevCallTime = currentTime; |
|
299 |
return D3DERR_DEVICELOST; |
|
300 |
} |
|
301 |
} |
|
302 |
if (pAdapters != NULL) { |
|
303 |
for (UINT i = 0; i < adapterCount; i++) { |
|
304 |
if (pAdapters[i].pd3dContext != NULL) { |
|
305 |
J2dTraceLn1(J2D_TRACE_VERBOSE, |
|
306 |
" HandleLostDevices: checking adapter %d", i); |
|
307 |
D3DContext *d3dc = pAdapters[i].pd3dContext; |
|
308 |
if (FAILED(d3dc->CheckAndResetDevice())) { |
|
309 |
bAllClear = FALSE; |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
return bAllClear ? S_OK : D3DERR_DEVICELOST; |
|
315 |
} |
|
316 |
||
317 |
HRESULT D3DPipelineManager::InitAdapters() |
|
318 |
{ |
|
319 |
HRESULT res = E_FAIL; |
|
320 |
||
321 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::InitAdapters()"); |
|
322 |
if (pAdapters != NULL) { |
|
323 |
ReleaseAdapters(); |
|
324 |
} |
|
325 |
||
326 |
adapterCount = pd3d9->GetAdapterCount(); |
|
327 |
pAdapters = new D3DAdapter[adapterCount]; |
|
328 |
if (pAdapters == NULL) { |
|
329 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "InitAdapters: out of memory"); |
|
330 |
adapterCount = 0; |
|
331 |
return E_FAIL; |
|
332 |
} |
|
333 |
ZeroMemory(pAdapters, adapterCount * sizeof(D3DAdapter)); |
|
334 |
||
335 |
res = CheckAdaptersInfo(); |
|
336 |
RETURN_STATUS_IF_FAILED(res); |
|
337 |
||
338 |
currentFSFocusAdapter = -1; |
|
339 |
if (CreateDefaultFocusWindow() == 0) { |
|
340 |
return E_FAIL; |
|
341 |
} |
|
342 |
||
343 |
return S_OK; |
|
344 |
} |
|
345 |
||
346 |
// static |
|
347 |
HRESULT |
|
348 |
D3DPipelineManager::CheckOSVersion() |
|
349 |
{ |
|
350 |
// require Windows XP or newer client-class OS |
|
351 |
if (IS_WINVER_ATLEAST(5, 1) && |
|
352 |
!D3DPPLM_OsVersionMatches(OS_WINSERV_2008|OS_WINSERV_2003)) |
|
353 |
{ |
|
354 |
J2dTraceLn(J2D_TRACE_INFO, |
|
355 |
"D3DPPLM::CheckOSVersion: Windows XP or newer client-classs"\ |
|
356 |
" OS detected, passed"); |
|
357 |
return S_OK; |
|
358 |
} |
|
359 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
360 |
"D3DPPLM::CheckOSVersion: Windows 2000 or earlier (or a "\ |
|
361 |
"server) OS detected, failed"); |
|
362 |
if (bNoHwCheck) { |
|
363 |
J2dRlsTraceLn(J2D_TRACE_WARNING, |
|
364 |
" OS check overridden via J2D_D3D_NO_HWCHECK"); |
|
365 |
return S_OK; |
|
366 |
} |
|
367 |
return E_FAIL; |
|
368 |
} |
|
369 |
||
370 |
// static |
|
371 |
HRESULT |
|
372 |
D3DPipelineManager::GDICheckForBadHardware() |
|
373 |
{ |
|
1954 | 374 |
DISPLAY_DEVICE dd; |
375 |
dd.cb = sizeof(DISPLAY_DEVICE); |
|
887 | 376 |
|
377 |
int failedDevices = 0; |
|
378 |
int attachedDevices = 0; |
|
379 |
int i = 0; |
|
380 |
WCHAR *id; |
|
381 |
WCHAR vendorId[5]; |
|
382 |
WCHAR deviceId[5]; |
|
383 |
DWORD dwDId, dwVId; |
|
384 |
||
385 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::GDICheckForBadHardware"); |
|
386 |
||
387 |
// i<20 is to guard against buggy drivers |
|
388 |
while (EnumDisplayDevices(NULL, i, &dd, 0) && i < 20) { |
|
1954 | 389 |
if (dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) { |
887 | 390 |
attachedDevices++; |
1954 | 391 |
id = dd.DeviceID; |
887 | 392 |
if (wcslen(id) > 21) { |
393 |
// get vendor ID |
|
394 |
wcsncpy(vendorId, id+8, 4); |
|
395 |
int args1 = swscanf(vendorId, L"%X", &dwVId); |
|
396 |
||
397 |
// get device ID |
|
398 |
wcsncpy(deviceId, id+17, 4); |
|
399 |
int args2 = swscanf(deviceId, L"%X", &dwDId); |
|
400 |
||
401 |
if (args1 == 1 && args2 == 1) { |
|
402 |
J2dTraceLn2(J2D_TRACE_VERBOSE, |
|
403 |
" device: vendorID=0x%04x, deviceId=0x%04x", |
|
404 |
dwVId, dwDId); |
|
405 |
// since we don't have a driver version here we will |
|
406 |
// just ask to ignore the version for now; bad hw |
|
407 |
// entries with specific drivers information will be |
|
408 |
// processed later when d3d is initialized and we can |
|
409 |
// obtain a driver version |
|
410 |
if (FAILED(CheckForBadHardware(dwVId, dwDId, MAX_VERSION))){ |
|
411 |
failedDevices++; |
|
412 |
} |
|
413 |
} |
|
414 |
} |
|
415 |
} |
|
416 |
||
417 |
i++; |
|
418 |
} |
|
419 |
||
420 |
if (failedDevices == attachedDevices) { |
|
421 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
422 |
"D3DPPLM::GDICheckForBadHardware: no suitable devices found"); |
|
423 |
return E_FAIL; |
|
424 |
} |
|
425 |
||
426 |
return S_OK; |
|
427 |
} |
|
428 |
||
429 |
BOOL D3DPPLM_OsVersionMatches(USHORT osInfo) { |
|
430 |
static USHORT currentOS = OS_UNDEFINED; |
|
431 |
||
432 |
if (currentOS == OS_UNDEFINED) { |
|
433 |
BOOL bVersOk; |
|
434 |
OSVERSIONINFOEX osvi; |
|
435 |
||
436 |
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); |
|
437 |
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
|
438 |
||
439 |
bVersOk = GetVersionEx((OSVERSIONINFO *) &osvi); |
|
440 |
||
441 |
J2dRlsTrace(J2D_TRACE_INFO, "[I] OS Version = "); |
|
442 |
if (bVersOk && osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && |
|
443 |
osvi.dwMajorVersion > 4) |
|
444 |
{ |
|
445 |
if (osvi.dwMajorVersion >= 6 && osvi.dwMinorVersion >= 0) { |
|
446 |
if (osvi.wProductType == VER_NT_WORKSTATION) { |
|
447 |
J2dRlsTrace(J2D_TRACE_INFO, "OS_VISTA or newer\n"); |
|
448 |
currentOS = OS_VISTA; |
|
449 |
} else { |
|
450 |
J2dRlsTrace(J2D_TRACE_INFO, "OS_WINSERV_2008 or newer\n"); |
|
451 |
currentOS = OS_WINSERV_2008; |
|
452 |
} |
|
453 |
} else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) { |
|
454 |
if (osvi.wProductType == VER_NT_WORKSTATION) { |
|
455 |
J2dRlsTrace(J2D_TRACE_INFO, "OS_WINXP_64\n"); |
|
456 |
currentOS = OS_WINXP_64; |
|
457 |
} else { |
|
458 |
J2dRlsTrace(J2D_TRACE_INFO, "OS_WINSERV_2003\n"); |
|
459 |
currentOS = OS_WINSERV_2003; |
|
460 |
} |
|
461 |
} else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) { |
|
462 |
J2dRlsTrace(J2D_TRACE_INFO, "OS_WINXP "); |
|
463 |
currentOS = OS_WINXP; |
|
464 |
if (osvi.wSuiteMask & VER_SUITE_PERSONAL) { |
|
465 |
J2dRlsTrace(J2D_TRACE_INFO, "Home\n"); |
|
466 |
} else { |
|
467 |
J2dRlsTrace(J2D_TRACE_INFO, "Pro\n"); |
|
468 |
} |
|
469 |
} else { |
|
470 |
J2dRlsTrace2(J2D_TRACE_INFO, |
|
471 |
"OS_UNKNOWN: dwMajorVersion=%d dwMinorVersion=%d\n", |
|
472 |
osvi.dwMajorVersion, osvi.dwMinorVersion); |
|
473 |
currentOS = OS_UNKNOWN; |
|
474 |
} |
|
475 |
} else { |
|
476 |
if (bVersOk) { |
|
477 |
J2dRlsTrace2(J2D_TRACE_INFO, |
|
478 |
"OS_UNKNOWN: dwPlatformId=%d dwMajorVersion=%d\n", |
|
479 |
osvi.dwPlatformId, osvi.dwMajorVersion); |
|
480 |
} else { |
|
481 |
J2dRlsTrace(J2D_TRACE_INFO,"OS_UNKNOWN: GetVersionEx failed\n"); |
|
482 |
} |
|
483 |
currentOS = OS_UNKNOWN; |
|
484 |
} |
|
485 |
} |
|
486 |
return (currentOS & osInfo); |
|
487 |
} |
|
488 |
||
489 |
// static |
|
490 |
HRESULT |
|
491 |
D3DPipelineManager::CheckForBadHardware(DWORD vId, DWORD dId, LONGLONG version) |
|
492 |
{ |
|
493 |
DWORD vendorId, deviceId; |
|
494 |
UINT adapterInfo = 0; |
|
495 |
||
496 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::CheckForBadHardware"); |
|
497 |
||
498 |
while ((vendorId = badHardware[adapterInfo].VendorId) != 0x0000 && |
|
499 |
(deviceId = badHardware[adapterInfo].DeviceId) != 0x0000) |
|
500 |
{ |
|
501 |
if (vendorId == vId && (deviceId == dId || deviceId == ALL_DEVICEIDS)) { |
|
502 |
LONGLONG goodVersion = badHardware[adapterInfo].DriverVersion; |
|
503 |
USHORT osInfo = badHardware[adapterInfo].OsInfo; |
|
504 |
// the hardware check fails if: |
|
505 |
// - we have an entry for this OS and |
|
506 |
// - hardware is bad for all driver versions (NO_VERSION), or |
|
507 |
// we have a driver version which is older than the |
|
508 |
// minimum required for this OS |
|
509 |
if (D3DPPLM_OsVersionMatches(osInfo) && |
|
510 |
(goodVersion == NO_VERSION || version < goodVersion)) |
|
511 |
{ |
|
512 |
J2dRlsTraceLn2(J2D_TRACE_ERROR, |
|
513 |
"D3DPPLM::CheckForBadHardware: found matching "\ |
|
514 |
"hardware: VendorId=0x%04x DeviceId=0x%04x", |
|
515 |
vendorId, deviceId); |
|
516 |
if (goodVersion != NO_VERSION) { |
|
517 |
// this was a match by the driver version |
|
518 |
LARGE_INTEGER li; |
|
519 |
li.QuadPart = goodVersion; |
|
520 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
521 |
" bad driver found, device disabled"); |
|
522 |
J2dRlsTraceLn4(J2D_TRACE_ERROR, |
|
523 |
" update your driver to at "\ |
|
524 |
"least version %d.%d.%d.%d", |
|
525 |
HIWORD(li.HighPart), LOWORD(li.HighPart), |
|
526 |
HIWORD(li.LowPart), LOWORD(li.LowPart)); |
|
527 |
} else { |
|
528 |
// this was a match by the device (no good driver for this |
|
529 |
// device) |
|
530 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
531 |
"D3DPPLM::CheckForBadHardware: bad hardware "\ |
|
532 |
"found, device disabled"); |
|
533 |
} |
|
534 |
if (!bNoHwCheck) { |
|
535 |
return D3DERR_INVALIDDEVICE; |
|
536 |
} |
|
537 |
J2dRlsTraceLn(J2D_TRACE_WARNING, " Warning: hw/driver match "\ |
|
538 |
"overridden (via J2D_D3D_NO_HWCHECK)"); |
|
539 |
} |
|
540 |
} |
|
541 |
adapterInfo++; |
|
542 |
} |
|
543 |
||
544 |
return S_OK; |
|
545 |
} |
|
546 |
||
547 |
HRESULT D3DPipelineManager::CheckAdaptersInfo() |
|
548 |
{ |
|
549 |
D3DADAPTER_IDENTIFIER9 aid; |
|
550 |
UINT failedAdaptersCount = 0; |
|
551 |
||
552 |
J2dRlsTraceLn(J2D_TRACE_INFO, "CheckAdaptersInfo"); |
|
553 |
J2dRlsTraceLn(J2D_TRACE_INFO, "------------------"); |
|
554 |
for (UINT Adapter = 0; Adapter < adapterCount; Adapter++) { |
|
555 |
||
556 |
if (FAILED(pd3d9->GetAdapterIdentifier(Adapter, 0, &aid))) { |
|
557 |
pAdapters[Adapter].state = CONTEXT_INIT_FAILED; |
|
558 |
failedAdaptersCount++; |
|
559 |
continue; |
|
560 |
} |
|
561 |
||
562 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "Adapter Ordinal : %d", Adapter); |
|
563 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "Adapter Handle : 0x%x", |
|
564 |
pd3d9->GetAdapterMonitor(Adapter)); |
|
565 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "Description : %s", |
|
566 |
aid.Description); |
|
567 |
J2dRlsTraceLn2(J2D_TRACE_INFO, "GDI Name, Driver : %s, %s", |
|
568 |
aid.DeviceName, aid.Driver); |
|
569 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "Vendor Id : 0x%04x", |
|
570 |
aid.VendorId); |
|
571 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "Device Id : 0x%04x", |
|
572 |
aid.DeviceId); |
|
573 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "SubSys Id : 0x%x", |
|
574 |
aid.SubSysId); |
|
575 |
J2dRlsTraceLn4(J2D_TRACE_INFO, "Driver Version : %d.%d.%d.%d", |
|
576 |
HIWORD(aid.DriverVersion.HighPart), |
|
577 |
LOWORD(aid.DriverVersion.HighPart), |
|
578 |
HIWORD(aid.DriverVersion.LowPart), |
|
579 |
LOWORD(aid.DriverVersion.LowPart)); |
|
580 |
J2dRlsTrace3(J2D_TRACE_INFO, |
|
581 |
"[I] GUID : {%08X-%04X-%04X-", |
|
582 |
aid.DeviceIdentifier.Data1, |
|
583 |
aid.DeviceIdentifier.Data2, |
|
584 |
aid.DeviceIdentifier.Data3); |
|
585 |
J2dRlsTrace4(J2D_TRACE_INFO, "%02X%02X-%02X%02X", |
|
586 |
aid.DeviceIdentifier.Data4[0], |
|
587 |
aid.DeviceIdentifier.Data4[1], |
|
588 |
aid.DeviceIdentifier.Data4[2], |
|
589 |
aid.DeviceIdentifier.Data4[3]); |
|
590 |
J2dRlsTrace4(J2D_TRACE_INFO, "%02X%02X%02X%02X}\n", |
|
591 |
aid.DeviceIdentifier.Data4[4], |
|
592 |
aid.DeviceIdentifier.Data4[5], |
|
593 |
aid.DeviceIdentifier.Data4[6], |
|
594 |
aid.DeviceIdentifier.Data4[7]); |
|
595 |
||
596 |
if (FAILED(CheckForBadHardware(aid.VendorId, aid.DeviceId, |
|
597 |
aid.DriverVersion.QuadPart)) || |
|
598 |
FAILED(CheckDeviceCaps(Adapter)) || |
|
599 |
FAILED(D3DEnabledOnAdapter(Adapter))) |
|
600 |
{ |
|
601 |
pAdapters[Adapter].state = CONTEXT_INIT_FAILED; |
|
602 |
failedAdaptersCount++; |
|
603 |
} |
|
604 |
J2dRlsTraceLn(J2D_TRACE_INFO, "------------------"); |
|
605 |
} |
|
606 |
||
607 |
if (failedAdaptersCount == adapterCount) { |
|
608 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
609 |
"D3DPPLM::CheckAdaptersInfo: no suitable adapters found"); |
|
610 |
return E_FAIL; |
|
611 |
} |
|
612 |
||
613 |
return S_OK; |
|
614 |
} |
|
615 |
||
616 |
D3DDEVTYPE D3DPipelineManager::SelectDeviceType() |
|
617 |
{ |
|
618 |
char *pRas = getenv("J2D_D3D_RASTERIZER"); |
|
619 |
D3DDEVTYPE dtype = D3DDEVTYPE_HAL; |
|
620 |
if (pRas != NULL) { |
|
621 |
J2dRlsTrace(J2D_TRACE_WARNING, "[W] D3DPPLM::SelectDeviceType: "); |
|
622 |
if (strncmp(pRas, "ref", 3) == 0 || strncmp(pRas, "rgb", 3) == 0) { |
|
623 |
J2dRlsTrace(J2D_TRACE_WARNING, "ref rasterizer selected"); |
|
624 |
dtype = D3DDEVTYPE_REF; |
|
625 |
} else if (strncmp(pRas, "hal",3) == 0 || strncmp(pRas, "tnl",3) == 0) { |
|
626 |
J2dRlsTrace(J2D_TRACE_WARNING, "hal rasterizer selected"); |
|
627 |
dtype = D3DDEVTYPE_HAL; |
|
628 |
} else if (strncmp(pRas, "nul", 3) == 0) { |
|
629 |
J2dRlsTrace(J2D_TRACE_WARNING, "nullref rasterizer selected"); |
|
630 |
dtype = D3DDEVTYPE_NULLREF; |
|
631 |
} else { |
|
632 |
J2dRlsTrace1(J2D_TRACE_WARNING, |
|
633 |
"unknown rasterizer: %s, only (ref|hal|nul) "\ |
|
634 |
"supported, hal selected instead", pRas); |
|
635 |
} |
|
636 |
J2dRlsTrace(J2D_TRACE_WARNING, "\n"); |
|
637 |
} |
|
638 |
return dtype; |
|
639 |
} |
|
640 |
||
641 |
#define CHECK_CAP(FLAG, CAP) \ |
|
642 |
do { \ |
|
643 |
if (!((FLAG)&CAP)) { \ |
|
644 |
J2dRlsTraceLn2(J2D_TRACE_ERROR, \ |
|
645 |
"D3DPPLM::CheckDeviceCaps: adapter %d: Failed "\ |
|
646 |
"(cap %s not supported)", \ |
|
647 |
adapter, #CAP); \ |
|
648 |
return E_FAIL; \ |
|
649 |
} \ |
|
650 |
} while (0) |
|
651 |
||
652 |
HRESULT D3DPipelineManager::CheckDeviceCaps(UINT adapter) |
|
653 |
{ |
|
654 |
HRESULT res; |
|
655 |
D3DCAPS9 d3dCaps; |
|
656 |
||
657 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::CheckDeviceCaps"); |
|
658 |
||
659 |
res = pd3d9->GetDeviceCaps(adapter, devType, &d3dCaps); |
|
660 |
RETURN_STATUS_IF_FAILED(res); |
|
661 |
||
662 |
CHECK_CAP(d3dCaps.DevCaps, D3DDEVCAPS_DRAWPRIMTLVERTEX); |
|
663 |
||
664 |
// by requiring hardware tnl we are hoping for better drivers quality |
|
665 |
if (!IsD3DForced()) { |
|
666 |
// fail if not hw tnl unless d3d was forced |
|
667 |
CHECK_CAP(d3dCaps.DevCaps, D3DDEVCAPS_HWTRANSFORMANDLIGHT); |
|
668 |
} |
|
669 |
if (d3dCaps.DeviceType == D3DDEVTYPE_HAL) { |
|
670 |
CHECK_CAP(d3dCaps.DevCaps, D3DDEVCAPS_HWRASTERIZATION); |
|
671 |
} |
|
672 |
||
673 |
CHECK_CAP(d3dCaps.RasterCaps, D3DPRASTERCAPS_SCISSORTEST); |
|
674 |
||
675 |
CHECK_CAP(d3dCaps.Caps3, D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD); |
|
676 |
||
677 |
CHECK_CAP(d3dCaps.PrimitiveMiscCaps, D3DPMISCCAPS_CULLNONE); |
|
678 |
CHECK_CAP(d3dCaps.PrimitiveMiscCaps, D3DPMISCCAPS_BLENDOP); |
|
679 |
CHECK_CAP(d3dCaps.PrimitiveMiscCaps, D3DPMISCCAPS_MASKZ); |
|
680 |
||
681 |
CHECK_CAP(d3dCaps.ZCmpCaps, D3DPCMPCAPS_ALWAYS); |
|
682 |
CHECK_CAP(d3dCaps.ZCmpCaps, D3DPCMPCAPS_LESS); |
|
683 |
||
684 |
CHECK_CAP(d3dCaps.SrcBlendCaps, D3DPBLENDCAPS_ZERO); |
|
685 |
CHECK_CAP(d3dCaps.SrcBlendCaps, D3DPBLENDCAPS_ONE); |
|
686 |
CHECK_CAP(d3dCaps.SrcBlendCaps, D3DPBLENDCAPS_SRCALPHA); |
|
687 |
CHECK_CAP(d3dCaps.SrcBlendCaps, D3DPBLENDCAPS_DESTALPHA); |
|
688 |
CHECK_CAP(d3dCaps.SrcBlendCaps, D3DPBLENDCAPS_INVSRCALPHA); |
|
689 |
CHECK_CAP(d3dCaps.SrcBlendCaps, D3DPBLENDCAPS_INVDESTALPHA); |
|
690 |
||
691 |
CHECK_CAP(d3dCaps.DestBlendCaps, D3DPBLENDCAPS_ZERO); |
|
692 |
CHECK_CAP(d3dCaps.DestBlendCaps, D3DPBLENDCAPS_ONE); |
|
693 |
CHECK_CAP(d3dCaps.DestBlendCaps, D3DPBLENDCAPS_SRCALPHA); |
|
694 |
CHECK_CAP(d3dCaps.DestBlendCaps, D3DPBLENDCAPS_DESTALPHA); |
|
695 |
CHECK_CAP(d3dCaps.DestBlendCaps, D3DPBLENDCAPS_INVSRCALPHA); |
|
696 |
CHECK_CAP(d3dCaps.DestBlendCaps, D3DPBLENDCAPS_INVDESTALPHA); |
|
697 |
||
698 |
CHECK_CAP(d3dCaps.TextureAddressCaps, D3DPTADDRESSCAPS_CLAMP); |
|
699 |
CHECK_CAP(d3dCaps.TextureAddressCaps, D3DPTADDRESSCAPS_WRAP); |
|
700 |
||
701 |
CHECK_CAP(d3dCaps.TextureOpCaps, D3DTEXOPCAPS_MODULATE); |
|
702 |
||
703 |
if (d3dCaps.PixelShaderVersion < D3DPS_VERSION(2,0) && !IsD3DForced()) { |
|
704 |
J2dRlsTraceLn1(J2D_TRACE_ERROR, |
|
705 |
"D3DPPLM::CheckDeviceCaps: adapter %d: Failed "\ |
|
706 |
"(pixel shaders 2.0 required)", adapter); |
|
707 |
return E_FAIL; |
|
708 |
} |
|
709 |
||
710 |
J2dRlsTraceLn1(J2D_TRACE_INFO, |
|
711 |
"D3DPPLM::CheckDeviceCaps: adapter %d: Passed", adapter); |
|
712 |
return S_OK; |
|
713 |
} |
|
714 |
||
715 |
||
716 |
HRESULT D3DPipelineManager::D3DEnabledOnAdapter(UINT adapter) |
|
717 |
{ |
|
718 |
HRESULT res; |
|
719 |
D3DDISPLAYMODE dm; |
|
720 |
||
721 |
res = pd3d9->GetAdapterDisplayMode(adapter, &dm); |
|
722 |
RETURN_STATUS_IF_FAILED(res); |
|
723 |
||
724 |
res = pd3d9->CheckDeviceType(adapter, devType, dm.Format, dm.Format, TRUE); |
|
725 |
if (FAILED(res)) { |
|
726 |
J2dRlsTraceLn1(J2D_TRACE_ERROR, |
|
727 |
"D3DPPLM::D3DEnabledOnAdapter: no " \ |
|
728 |
"suitable d3d device on adapter %d", adapter); |
|
729 |
} |
|
730 |
||
731 |
return res; |
|
732 |
} |
|
733 |
||
734 |
UINT D3DPipelineManager::GetAdapterOrdinalByHmon(HMONITOR hMon) |
|
735 |
{ |
|
736 |
UINT ret = D3DADAPTER_DEFAULT; |
|
737 |
||
738 |
if (pd3d9 != NULL) { |
|
739 |
UINT adapterCount = pd3d9->GetAdapterCount(); |
|
740 |
for (UINT adapter = 0; adapter < adapterCount; adapter++) { |
|
741 |
HMONITOR hm = pd3d9->GetAdapterMonitor(adapter); |
|
742 |
if (hm == hMon) { |
|
743 |
ret = adapter; |
|
744 |
break; |
|
745 |
} |
|
746 |
} |
|
747 |
} |
|
748 |
return ret; |
|
749 |
} |
|
750 |
||
751 |
D3DFORMAT |
|
752 |
D3DPipelineManager::GetMatchingDepthStencilFormat(UINT adapterOrdinal, |
|
753 |
D3DFORMAT adapterFormat, |
|
754 |
D3DFORMAT renderTargetFormat) |
|
755 |
{ |
|
756 |
static D3DFORMAT formats[] = |
|
757 |
{ D3DFMT_D16, D3DFMT_D32, D3DFMT_D24S8, D3DFMT_D24X8 }; |
|
758 |
D3DFORMAT newFormat = D3DFMT_UNKNOWN; |
|
759 |
HRESULT res; |
|
760 |
for (int i = 0; i < 4; i++) { |
|
761 |
res = pd3d9->CheckDeviceFormat(adapterOrdinal, |
|
762 |
devType, adapterFormat, D3DUSAGE_DEPTHSTENCIL, |
|
763 |
D3DRTYPE_SURFACE, formats[i]); |
|
764 |
if (FAILED(res)) continue; |
|
765 |
||
766 |
res = pd3d9->CheckDepthStencilMatch(adapterOrdinal, |
|
767 |
devType, adapterFormat, renderTargetFormat, formats[i]); |
|
768 |
if (FAILED(res)) continue; |
|
769 |
newFormat = formats[i]; |
|
770 |
break; |
|
771 |
} |
|
772 |
return newFormat; |
|
773 |
} |
|
774 |
||
775 |
HWND D3DPipelineManager::CreateDefaultFocusWindow() |
|
776 |
{ |
|
777 |
UINT adapterOrdinal = D3DADAPTER_DEFAULT; |
|
778 |
||
779 |
J2dTraceLn1(J2D_TRACE_INFO, |
|
780 |
"D3DPPLM::CreateDefaultFocusWindow: adapter=%d", |
|
781 |
adapterOrdinal); |
|
782 |
||
783 |
if (defaultFocusWindow != 0) { |
|
784 |
J2dRlsTraceLn(J2D_TRACE_WARNING, |
|
785 |
"D3DPPLM::CreateDefaultFocusWindow: "\ |
|
786 |
"existing default focus window!"); |
|
787 |
return defaultFocusWindow; |
|
788 |
} |
|
789 |
||
790 |
WNDCLASS wc; |
|
791 |
ZeroMemory(&wc, sizeof(WNDCLASS)); |
|
792 |
wc.hInstance = GetModuleHandle(NULL); |
|
793 |
wc.lpfnWndProc = DefWindowProc; |
|
794 |
wc.lpszClassName = L"D3DFocusWindow"; |
|
795 |
if (RegisterClass(&wc) == 0) { |
|
796 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
797 |
"D3DPPLM::CreateDefaultFocusWindow: "\ |
|
798 |
"error registering window class"); |
|
799 |
return 0; |
|
800 |
} |
|
801 |
||
802 |
MONITORINFO mi; |
|
803 |
ZeroMemory(&mi, sizeof(MONITORINFO)); |
|
804 |
mi.cbSize = sizeof(MONITORINFO); |
|
805 |
HMONITOR hMon = pd3d9->GetAdapterMonitor(adapterOrdinal); |
|
1954 | 806 |
if (hMon == 0 || !GetMonitorInfo(hMon, (LPMONITORINFO)&mi)) { |
887 | 807 |
J2dRlsTraceLn1(J2D_TRACE_ERROR, |
808 |
"D3DPPLM::CreateDefaultFocusWindow: "\ |
|
809 |
"error getting monitor info for adapter=%d", adapterOrdinal); |
|
810 |
return 0; |
|
811 |
} |
|
812 |
||
813 |
HWND hWnd = CreateWindow(L"D3DFocusWindow", L"D3DFocusWindow", 0, |
|
814 |
mi.rcMonitor.left, mi.rcMonitor.top, 1, 1, |
|
815 |
NULL, NULL, GetModuleHandle(NULL), NULL); |
|
816 |
if (hWnd == 0) { |
|
817 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
818 |
"D3DPPLM::CreateDefaultFocusWindow: CreateWindow failed"); |
|
819 |
} else { |
|
820 |
J2dTraceLn2(J2D_TRACE_INFO, |
|
821 |
" Created default focus window %x for adapter %d", |
|
822 |
hWnd, adapterOrdinal); |
|
823 |
defaultFocusWindow = hWnd; |
|
824 |
} |
|
825 |
return hWnd; |
|
826 |
} |
|
827 |
||
828 |
HWND D3DPipelineManager::GetCurrentFocusWindow() |
|
829 |
{ |
|
830 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::GetCurrentFocusWindow"); |
|
831 |
if (currentFSFocusAdapter < 0) { |
|
832 |
J2dTraceLn1(J2D_TRACE_VERBOSE, |
|
833 |
" no fs windows, using default focus window=0x%x", |
|
834 |
defaultFocusWindow); |
|
835 |
return defaultFocusWindow; |
|
836 |
} |
|
837 |
J2dTraceLn1(J2D_TRACE_VERBOSE, " using fs window=0x%x", |
|
838 |
pAdapters[currentFSFocusAdapter].fsFocusWindow); |
|
839 |
return pAdapters[currentFSFocusAdapter].fsFocusWindow; |
|
840 |
} |
|
841 |
||
842 |
HWND D3DPipelineManager::SetFSFocusWindow(UINT adapterOrdinal, HWND hWnd) |
|
843 |
{ |
|
844 |
J2dTraceLn2(J2D_TRACE_INFO,"D3DPPLM::SetFSFocusWindow hwnd=0x%x adapter=%d", |
|
845 |
hWnd, adapterOrdinal); |
|
846 |
||
847 |
HWND prev = pAdapters[adapterOrdinal].fsFocusWindow; |
|
848 |
pAdapters[adapterOrdinal].fsFocusWindow = hWnd; |
|
849 |
if (currentFSFocusAdapter < 0) { |
|
850 |
J2dTraceLn(J2D_TRACE_VERBOSE, " first full-screen window"); |
|
851 |
// first fs window |
|
852 |
currentFSFocusAdapter = adapterOrdinal; |
|
853 |
// REMIND: we might want to reset the rest of the context here as well |
|
854 |
// like we do when the an adapter exits fs mode; currently they will |
|
855 |
// be reset sometime later |
|
856 |
} else { |
|
857 |
// there's already a fs window |
|
858 |
if (currentFSFocusAdapter == adapterOrdinal) { |
|
859 |
// it's current fs window => we're exiting fs mode on this adapter; |
|
860 |
// look for a new fs focus window |
|
861 |
if (hWnd == 0) { |
|
862 |
UINT i; |
|
863 |
currentFSFocusAdapter = -1; |
|
864 |
for (i = 0; i < adapterCount; i++) { |
|
865 |
if (pAdapters[i].fsFocusWindow != 0) { |
|
866 |
J2dTraceLn1(J2D_TRACE_VERBOSE, |
|
867 |
" adapter %d is still in fs mode", i); |
|
868 |
currentFSFocusAdapter = i; |
|
869 |
break; |
|
870 |
} |
|
871 |
} |
|
872 |
// we have to reset all devices any time current focus device |
|
873 |
// exits fs mode, and also to prevent some of them being left in |
|
874 |
// a lost state when the last device exits fs - when non-last |
|
875 |
// adapters exit fs mode they would not be able to create the |
|
876 |
// device and will be put in a lost state forever |
|
877 |
HRESULT res; |
|
878 |
J2dTraceLn(J2D_TRACE_VERBOSE, |
|
879 |
" adapter exited full-screen, reset all adapters"); |
|
880 |
for (i = 0; i < adapterCount; i++) { |
|
881 |
if (pAdapters[i].pd3dContext != NULL) { |
|
882 |
res = pAdapters[i].pd3dContext->ResetContext(); |
|
883 |
D3DRQ_MarkLostIfNeeded(res, |
|
884 |
D3DRQ_GetCurrentDestination()); |
|
885 |
} |
|
886 |
} |
|
887 |
} else { |
|
888 |
J2dTraceLn1(J2D_TRACE_WARNING, |
|
889 |
"D3DPM::SetFSFocusWindow: setting the fs "\ |
|
890 |
"window again for adapter %d", adapterOrdinal); |
|
891 |
} |
|
892 |
} |
|
893 |
} |
|
894 |
return prev; |
|
895 |
} |
|
896 |
||
897 |
HRESULT D3DPipelineManager::GetD3DContext(UINT adapterOrdinal, |
|
898 |
D3DContext **ppd3dContext) |
|
899 |
{ |
|
900 |
J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::GetD3DContext"); |
|
901 |
||
902 |
HRESULT res = S_OK; |
|
903 |
if (adapterOrdinal < 0 || adapterOrdinal >= adapterCount || |
|
904 |
pAdapters == NULL || |
|
905 |
pAdapters[adapterOrdinal].state == CONTEXT_INIT_FAILED) |
|
906 |
{ |
|
907 |
J2dRlsTraceLn1(J2D_TRACE_ERROR, |
|
908 |
"D3DPPLM::GetD3DContext: invalid parameters or "\ |
|
909 |
"failed init for adapter %d", adapterOrdinal); |
|
910 |
*ppd3dContext = NULL; |
|
911 |
return E_FAIL; |
|
912 |
} |
|
913 |
||
914 |
if (pAdapters[adapterOrdinal].state == CONTEXT_NOT_INITED) { |
|
915 |
D3DContext *pCtx = NULL; |
|
916 |
||
917 |
if (pAdapters[adapterOrdinal].pd3dContext != NULL) { |
|
918 |
J2dTraceLn1(J2D_TRACE_ERROR, " non-null context in "\ |
|
919 |
"uninitialized adapter %d", adapterOrdinal); |
|
920 |
res = E_FAIL; |
|
921 |
} else { |
|
922 |
J2dTraceLn1(J2D_TRACE_VERBOSE, |
|
923 |
" initializing context for adapter %d",adapterOrdinal); |
|
924 |
||
925 |
if (SUCCEEDED(res = D3DEnabledOnAdapter(adapterOrdinal))) { |
|
926 |
res = D3DContext::CreateInstance(pd3d9, adapterOrdinal, &pCtx); |
|
927 |
if (FAILED(res)) { |
|
928 |
J2dRlsTraceLn1(J2D_TRACE_ERROR, |
|
929 |
"D3DPPLM::GetD3DContext: failed to create context "\ |
|
930 |
"for adapter=%d", adapterOrdinal); |
|
931 |
} |
|
932 |
} else { |
|
933 |
J2dRlsTraceLn1(J2D_TRACE_ERROR, |
|
934 |
"D3DPPLM::GetContext: no d3d on adapter %d",adapterOrdinal); |
|
935 |
} |
|
936 |
} |
|
937 |
pAdapters[adapterOrdinal].state = |
|
938 |
SUCCEEDED(res) ? CONTEXT_CREATED : CONTEXT_INIT_FAILED; |
|
939 |
pAdapters[adapterOrdinal].pd3dContext = pCtx; |
|
940 |
} |
|
941 |
*ppd3dContext = pAdapters[adapterOrdinal].pd3dContext; |
|
942 |
return res; |
|
943 |
} |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
944 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
945 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
946 |
//============================================================== |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
947 |
// D3DInitializer |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
948 |
//============================================================== |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
949 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
950 |
D3DInitializer D3DInitializer::theInstance; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
951 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
952 |
D3DInitializer::D3DInitializer() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
953 |
: bComInitialized(false), pAdapterIniters(NULL) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
954 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
955 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
956 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
957 |
D3DInitializer::~D3DInitializer() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
958 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
959 |
if (pAdapterIniters) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
960 |
delete[] pAdapterIniters; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
961 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
962 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
963 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
964 |
void D3DInitializer::InitImpl() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
965 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
966 |
J2dRlsTraceLn(J2D_TRACE_INFO, "D3DInitializer::InitImpl"); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
967 |
if (SUCCEEDED(::CoInitialize(NULL))) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
968 |
bComInitialized = true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
969 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
970 |
D3DPipelineManager *pMgr = D3DPipelineManager::CreateInstance(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
971 |
if (pMgr != NULL) { |
7256
adb296cc2eae
6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents:
7004
diff
changeset
|
972 |
// init adapters if we are preloading |
adb296cc2eae
6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents:
7004
diff
changeset
|
973 |
if (AwtToolkit::GetInstance().GetPreloadThread().OnPreloadThread()) { |
adb296cc2eae
6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents:
7004
diff
changeset
|
974 |
UINT adapterCount = pMgr->adapterCount; |
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
975 |
|
7256
adb296cc2eae
6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents:
7004
diff
changeset
|
976 |
pAdapterIniters = new D3DAdapterInitializer[adapterCount]; |
adb296cc2eae
6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents:
7004
diff
changeset
|
977 |
for (UINT i=0; i<adapterCount; i++) { |
adb296cc2eae
6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents:
7004
diff
changeset
|
978 |
pAdapterIniters[i].setAdapter(i); |
adb296cc2eae
6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents:
7004
diff
changeset
|
979 |
AwtToolkit::GetInstance().GetPreloadThread().AddAction(&pAdapterIniters[i]); |
adb296cc2eae
6999872: java.awt.Window instantiation leads to JVM CRASH on Windows, JDK7b118+ fastdebug
amenkov
parents:
7004
diff
changeset
|
980 |
} |
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
981 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
982 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
983 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
984 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
985 |
void D3DInitializer::CleanImpl(bool reInit) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
986 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
987 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "D3DInitializer::CleanImpl (%s)", |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
988 |
reInit ? "RELAUNCH" : "normal"); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
989 |
D3DPipelineManager::DeleteInstance(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
990 |
if (bComInitialized) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
991 |
CoUninitialize(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
992 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
993 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
994 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
995 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
996 |
void D3DInitializer::D3DAdapterInitializer::InitImpl() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
997 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
998 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "D3DAdapterInitializer::InitImpl(%d) started", adapter); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
999 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1000 |
D3DPipelineManager *pMgr = D3DPipelineManager::GetInstance(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1001 |
if (pMgr == NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1002 |
return; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1003 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1004 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1005 |
D3DContext *pd3dContext; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1006 |
pMgr->GetD3DContext(adapter, &pd3dContext); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1007 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1008 |
J2dRlsTraceLn1(J2D_TRACE_INFO, "D3DAdapterInitializer::InitImpl(%d) finished", adapter); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1009 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1010 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1011 |
void D3DInitializer::D3DAdapterInitializer::CleanImpl(bool reInit) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1012 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1013 |
// nothing to do - D3DPipelineManager cleans adapters |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1014 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1015 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1016 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1017 |
extern "C" { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1018 |
/* |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1019 |
* Export function to start D3D preloading |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1020 |
* (called from java/javaw - see src/windows/bin/java-md.c) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1021 |
*/ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1022 |
__declspec(dllexport) int preloadD3D() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1023 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1024 |
J2dRlsTraceLn(J2D_TRACE_INFO, "AWT warmup: preloadD3D"); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1025 |
AwtToolkit::GetInstance().GetPreloadThread().AddAction(&D3DInitializer::GetInstance()); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1026 |
return 1; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1027 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1028 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1029 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
1030 |