author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 7491 | ba3dc59cd2fd |
permissions | -rw-r--r-- |
887 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2007, 2010, 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 |
#pragma once |
|
26 |
||
27 |
#include "D3DPipeline.h" |
|
28 |
#include "D3DContext.h" |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
29 |
#include "awt_Toolkit.h" |
887 | 30 |
|
31 |
typedef class D3DPipelineManager *LPD3DPIPELINEMANAGER; |
|
32 |
||
33 |
typedef struct D3DAdapter |
|
34 |
{ |
|
35 |
D3DContext *pd3dContext; |
|
36 |
DWORD state; |
|
37 |
HWND fsFocusWindow; |
|
38 |
} D3DAdapter; |
|
39 |
||
40 |
class D3DPIPELINE_API D3DPipelineManager |
|
41 |
{ |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
42 |
friend class D3DInitializer; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
43 |
private: |
887 | 44 |
// creates and initializes instance of D3DPipelineManager, may return NULL |
45 |
static D3DPipelineManager* CreateInstance(void); |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
46 |
|
887 | 47 |
// deletes the single instance of the manager |
48 |
static void DeleteInstance(); |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
49 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
50 |
public: |
887 | 51 |
// returns the single instance of the manager, may return NULL |
52 |
static D3DPipelineManager* GetInstance(void); |
|
53 |
||
54 |
HRESULT GetD3DContext(UINT adapterOrdinal, D3DContext **ppd3dContext); |
|
55 |
||
56 |
HRESULT HandleLostDevices(); |
|
57 |
// Checks if adapters were added or removed, or if the order had changed |
|
58 |
// (which may happen with primary display is changed). If that's the case |
|
59 |
// releases current adapters and d3d9 instance, reinitializes the pipeline. |
|
60 |
// @param *monHds list of monitor handles retrieved from GDI |
|
61 |
// @param monNum number of gdi monitors |
|
62 |
static |
|
63 |
HRESULT HandleAdaptersChange(HMONITOR *monHds, UINT monNum); |
|
64 |
// returns depth stencil buffer format matching adapterFormat and render target |
|
65 |
// format for the device specified by adapterOrdinal/devType |
|
66 |
D3DFORMAT GetMatchingDepthStencilFormat(UINT adapterOrdinal, |
|
67 |
D3DFORMAT adapterFormat, |
|
68 |
D3DFORMAT renderTargetFormat); |
|
69 |
||
70 |
HWND GetCurrentFocusWindow(); |
|
71 |
// returns previous fs window |
|
72 |
HWND SetFSFocusWindow(UINT, HWND); |
|
73 |
||
74 |
LPDIRECT3D9 GetD3DObject() { return pd3d9; } |
|
75 |
D3DDEVTYPE GetDeviceType() { return devType; } |
|
76 |
||
77 |
// returns the d3d adapter ordinal given GDI screen number: |
|
78 |
// these may differ depending on which display is primary |
|
79 |
UINT GetAdapterOrdinalForScreen(jint gdiScreen); |
|
80 |
||
81 |
// notifies adapter event listeners by calling |
|
82 |
// AccelDeviceEventNotifier.eventOccured() |
|
83 |
static |
|
84 |
void NotifyAdapterEventListeners(UINT adapter, jint eventType); |
|
85 |
||
86 |
private: |
|
87 |
D3DPipelineManager(void); |
|
88 |
~D3DPipelineManager(void); |
|
89 |
||
90 |
// Creates a Direct3D9 object and initializes adapters. |
|
91 |
HRESULT InitD3D(void); |
|
92 |
// Releases adapters, Direct3D9 object and the d3d9 library. |
|
93 |
HRESULT ReleaseD3D(); |
|
94 |
||
95 |
// selects the device type based on user input and available |
|
96 |
// device types |
|
97 |
D3DDEVTYPE SelectDeviceType(); |
|
98 |
||
99 |
// creates array of adapters (releases the old one first) |
|
100 |
HRESULT InitAdapters(); |
|
101 |
// releases each adapter's context, and then releases the array |
|
102 |
HRESULT ReleaseAdapters(); |
|
103 |
||
104 |
HWND CreateDefaultFocusWindow(); |
|
105 |
// returns S_OK if the adapter is capable of running the Direct3D |
|
106 |
// pipeline |
|
107 |
HRESULT D3DEnabledOnAdapter(UINT Adapter); |
|
108 |
// returns adapterOrdinal given a HMONITOR handle |
|
109 |
UINT GetAdapterOrdinalByHmon(HMONITOR hMon); |
|
110 |
HRESULT CheckAdaptersInfo(); |
|
111 |
HRESULT CheckDeviceCaps(UINT Adapter); |
|
112 |
// Check the OS, succeeds if the OS is XP or newer client-class OS |
|
113 |
static HRESULT CheckOSVersion(); |
|
114 |
// used to check attached adapters using GDI against known bad hw database |
|
115 |
// prior to the instantiation of the pipeline manager |
|
116 |
static HRESULT GDICheckForBadHardware(); |
|
117 |
// given VendorId, DeviceId and driver version, checks against a database |
|
118 |
// of known bad hardware/driver combinations. |
|
119 |
// If the driver version is not known MAX_VERSION can be used |
|
120 |
// which is guaranteed to satisfy the check |
|
121 |
static HRESULT CheckForBadHardware(DWORD vId, DWORD dId, LONGLONG version); |
|
122 |
||
123 |
private: |
|
124 |
||
125 |
// current adapter count |
|
126 |
UINT adapterCount; |
|
127 |
// Pointer to Direct3D9 Object mainained by the pipeline manager |
|
128 |
LPDIRECT3D9 pd3d9; |
|
129 |
// d3d9.dll lib |
|
130 |
HINSTANCE hLibD3D9; |
|
131 |
||
132 |
int currentFSFocusAdapter; |
|
133 |
HWND defaultFocusWindow; |
|
134 |
||
135 |
D3DDEVTYPE devType; |
|
136 |
||
137 |
D3DAdapter *pAdapters; |
|
138 |
// instance of this object |
|
139 |
static LPD3DPIPELINEMANAGER pMgr; |
|
140 |
}; |
|
141 |
||
142 |
#define OS_UNDEFINED (0 << 0) |
|
143 |
#define OS_VISTA (1 << 0) |
|
144 |
#define OS_WINSERV_2008 (1 << 1) |
|
145 |
#define OS_WINXP (1 << 2) |
|
146 |
#define OS_WINXP_64 (1 << 3) |
|
147 |
#define OS_WINSERV_2003 (1 << 4) |
|
7491
ba3dc59cd2fd
7005896: Java2D D3D pipeline doesn't recognise latest Windows OSes
prr
parents:
7004
diff
changeset
|
148 |
#define OS_WINDOWS7 (1 << 5) |
ba3dc59cd2fd
7005896: Java2D D3D pipeline doesn't recognise latest Windows OSes
prr
parents:
7004
diff
changeset
|
149 |
#define OS_WINSERV_2008R2 (1 << 6) |
ba3dc59cd2fd
7005896: Java2D D3D pipeline doesn't recognise latest Windows OSes
prr
parents:
7004
diff
changeset
|
150 |
#define OS_ALL (OS_VISTA|OS_WINSERV_2008|OS_WINXP|OS_WINXP_64|OS_WINSERV_2003|\ |
ba3dc59cd2fd
7005896: Java2D D3D pipeline doesn't recognise latest Windows OSes
prr
parents:
7004
diff
changeset
|
151 |
OS_WINDOWS7|OS_WINSERV_2008R2) |
887 | 152 |
#define OS_UNKNOWN (~OS_ALL) |
153 |
BOOL D3DPPLM_OsVersionMatches(USHORT osInfo); |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
154 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
155 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
156 |
class D3DInitializer : public AwtToolkit::PreloadAction { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
157 |
private: |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
158 |
D3DInitializer(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
159 |
~D3DInitializer(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
160 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
161 |
protected: |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
162 |
// PreloadAction overrides |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
163 |
virtual void InitImpl(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
164 |
virtual void CleanImpl(bool reInit); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
165 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
166 |
public: |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
167 |
static D3DInitializer& GetInstance() { return theInstance; } |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
168 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
169 |
private: |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
170 |
// single instance |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
171 |
static D3DInitializer theInstance; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
172 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
173 |
// adapter initializer class |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
174 |
class D3DAdapterInitializer : public AwtToolkit::PreloadAction { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
175 |
public: |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
176 |
void setAdapter(UINT adapter) { this->adapter = adapter; } |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
177 |
protected: |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
178 |
// PreloadAction overrides |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
179 |
virtual void InitImpl(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
180 |
virtual void CleanImpl(bool reInit); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
181 |
private: |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
182 |
UINT adapter; |
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 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
185 |
// the flag indicates success of COM initialization |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
186 |
bool bComInitialized; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
187 |
D3DAdapterInitializer *pAdapterIniters; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
188 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
189 |
}; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
5506
diff
changeset
|
190 |