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 "sun_java2d_d3d_D3DGraphicsDevice.h"
|
|
27 |
#include "D3DGraphicsDevice.h"
|
|
28 |
#include "D3DPipelineManager.h"
|
|
29 |
#include "D3DRenderQueue.h"
|
|
30 |
#include "Trace.h"
|
|
31 |
#include "awt_Toolkit.h"
|
|
32 |
#include "awt_Window.h"
|
|
33 |
|
|
34 |
extern jobject CreateDisplayMode(JNIEnv* env, jint width, jint height,
|
|
35 |
jint bitDepth, jint refreshRate);
|
|
36 |
extern void addDisplayMode(JNIEnv* env, jobject arrayList, jint width,
|
|
37 |
jint height, jint bitDepth, jint refreshRate);
|
|
38 |
|
|
39 |
void InitD3D(void *pReturn)
|
|
40 |
{
|
|
41 |
J2dTraceLn(J2D_TRACE_INFO, "InitD3D");
|
|
42 |
|
|
43 |
jboolean *pRet = (jboolean *)pReturn;
|
|
44 |
|
|
45 |
D3DPipelineManager *pMgr = D3DPipelineManager::CreateInstance();
|
|
46 |
if (pMgr == NULL) {
|
|
47 |
J2dTraceLn(J2D_TRACE_ERROR, "InitD3D: could not create or init d3d");
|
|
48 |
*pRet = JNI_FALSE;
|
|
49 |
} else {
|
|
50 |
J2dTraceLn(J2D_TRACE_INFO, "InitD3D: successfully initialized d3d");
|
|
51 |
*pRet = JNI_TRUE;
|
|
52 |
}
|
|
53 |
}
|
|
54 |
|
|
55 |
extern "C" {
|
|
56 |
/*
|
|
57 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
58 |
* Method: initD3D
|
|
59 |
* Signature: ()Z
|
|
60 |
*/
|
|
61 |
JNIEXPORT jboolean JNICALL Java_sun_java2d_d3d_D3DGraphicsDevice_initD3D
|
|
62 |
(JNIEnv *env, jclass)
|
|
63 |
{
|
|
64 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_initD3D");
|
|
65 |
|
|
66 |
jboolean result = JNI_FALSE;
|
|
67 |
AwtToolkit::GetInstance().InvokeFunction(InitD3D, &result);
|
|
68 |
J2dTraceLn1(J2D_TRACE_INFO, "D3DGD_initD3D: result=%x", result);
|
|
69 |
return result;
|
|
70 |
}
|
|
71 |
|
|
72 |
/*
|
|
73 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
74 |
* Method: getDeviceIdNative
|
|
75 |
* Signature: (I)Ljava/lang/String;
|
|
76 |
*/
|
|
77 |
JNIEXPORT jstring JNICALL Java_sun_java2d_d3d_D3DGraphicsDevice_getDeviceIdNative
|
|
78 |
(JNIEnv *env, jclass d3dsdc, jint gdiScreen)
|
|
79 |
{
|
|
80 |
D3DPipelineManager *pMgr;
|
|
81 |
UINT adapter;
|
|
82 |
D3DADAPTER_IDENTIFIER9 aid;
|
|
83 |
IDirect3D9 *pd3d9;
|
|
84 |
|
|
85 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_getDeviceIdNative");
|
|
86 |
|
|
87 |
pMgr = D3DPipelineManager::GetInstance();
|
|
88 |
RETURN_STATUS_IF_NULL(pMgr, NULL);
|
|
89 |
pd3d9 = pMgr->GetD3DObject();
|
|
90 |
RETURN_STATUS_IF_NULL(pd3d9, NULL);
|
|
91 |
|
|
92 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
93 |
if (FAILED(pd3d9->GetAdapterIdentifier(adapter, 0, &aid))) {
|
|
94 |
return NULL;
|
|
95 |
}
|
|
96 |
|
|
97 |
// ('%d.' will take no more than 6+1 chars since we are printing a WORD)
|
|
98 |
// AAAA&BBBB MAX_DEVICE_IDENTIFIER_STRING (%d.%d.%d.%d)0
|
|
99 |
size_t len = (4+1+4 +1+MAX_DEVICE_IDENTIFIER_STRING+1 +1+(6+1)*4+1 +1);
|
|
100 |
WCHAR *pAdapterId = new WCHAR[len];
|
|
101 |
RETURN_STATUS_IF_NULL(pAdapterId, NULL);
|
|
102 |
|
|
103 |
_snwprintf(pAdapterId, len, L"%x&%x %S (%d.%d.%d.%d)",
|
|
104 |
0xffff & aid.VendorId, 0xffff & aid.DeviceId, aid.Description,
|
|
105 |
HIWORD(aid.DriverVersion.HighPart),
|
|
106 |
LOWORD(aid.DriverVersion.HighPart),
|
|
107 |
HIWORD(aid.DriverVersion.LowPart),
|
|
108 |
LOWORD(aid.DriverVersion.LowPart));
|
|
109 |
// _snwprintf doesn't add 0 at the end if the formatted string didn't fit
|
|
110 |
// in the buffer so we have to make sure it is null terminated
|
|
111 |
pAdapterId[len-1] = (WCHAR)0;
|
|
112 |
|
|
113 |
J2dTraceLn1(J2D_TRACE_VERBOSE, " id=%S", pAdapterId);
|
|
114 |
|
|
115 |
jstring ret = JNU_NewStringPlatform(env, pAdapterId);
|
|
116 |
|
|
117 |
delete pAdapterId;
|
|
118 |
|
|
119 |
return ret;
|
|
120 |
}
|
|
121 |
|
|
122 |
/*
|
|
123 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
124 |
* Method: getDeviceCapsNative
|
|
125 |
* Signature: (I)I
|
|
126 |
*/
|
|
127 |
JNIEXPORT jint JNICALL
|
|
128 |
Java_sun_java2d_d3d_D3DGraphicsDevice_getDeviceCapsNative
|
|
129 |
(JNIEnv *env, jclass d3dsdc, jint gdiScreen)
|
|
130 |
{
|
|
131 |
D3DPipelineManager *pMgr;
|
|
132 |
D3DContext *pCtx;
|
|
133 |
UINT adapter;
|
|
134 |
|
|
135 |
J2dRlsTraceLn(J2D_TRACE_INFO, "D3DGD_getDeviceCapsNative");
|
|
136 |
|
|
137 |
pMgr = D3DPipelineManager::GetInstance();
|
|
138 |
RETURN_STATUS_IF_NULL(pMgr, CAPS_EMPTY);
|
|
139 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
140 |
|
|
141 |
if (FAILED(pMgr->GetD3DContext(adapter, &pCtx))) {
|
|
142 |
J2dRlsTraceLn1(J2D_TRACE_ERROR,
|
|
143 |
"D3DGD_getDeviceCapsNative: device %d disabled", adapter);
|
|
144 |
return CAPS_EMPTY;
|
|
145 |
}
|
|
146 |
return pCtx->GetContextCaps();
|
|
147 |
}
|
|
148 |
|
|
149 |
/*
|
|
150 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
151 |
* Method: enterFullScreenExclusiveNative
|
|
152 |
* Signature: (IJ)V
|
|
153 |
*/
|
|
154 |
JNIEXPORT jboolean JNICALL
|
|
155 |
Java_sun_java2d_d3d_D3DGraphicsDevice_enterFullScreenExclusiveNative
|
|
156 |
(JNIEnv *env, jclass gdc, jint gdiScreen, jlong window)
|
|
157 |
{
|
|
158 |
HRESULT res;
|
|
159 |
D3DPipelineManager *pMgr;
|
|
160 |
D3DContext *pCtx;
|
|
161 |
HWND hWnd;
|
|
162 |
AwtWindow *w;
|
|
163 |
D3DPRESENT_PARAMETERS newParams, *pCurParams;
|
|
164 |
D3DDISPLAYMODE dm;
|
|
165 |
UINT adapter;
|
|
166 |
|
|
167 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_enterFullScreenExclusiveNative");
|
|
168 |
|
|
169 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), JNI_FALSE);
|
|
170 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
171 |
|
|
172 |
if (FAILED(res = pMgr->GetD3DContext(adapter, &pCtx))) {
|
|
173 |
D3DRQ_MarkLostIfNeeded(res, D3DRQ_GetCurrentDestination());
|
|
174 |
return JNI_FALSE;
|
|
175 |
}
|
|
176 |
|
|
177 |
w = (AwtWindow *)AwtComponent::GetComponent((HWND)window);
|
|
178 |
if (w == NULL || !::IsWindow(hWnd = w->GetTopLevelHWnd())) {
|
|
179 |
J2dTraceLn(J2D_TRACE_WARNING,
|
|
180 |
"D3DGD_enterFullScreenExclusiveNative: disposed window");
|
|
181 |
return JNI_FALSE;
|
|
182 |
}
|
|
183 |
|
|
184 |
// REMIND: should we also move the non-topleve window from
|
|
185 |
// being on top here (it's moved to front in GraphicsDevice.setFSW())?
|
|
186 |
|
|
187 |
pCtx->Get3DObject()->GetAdapterDisplayMode(adapter, &dm);
|
|
188 |
pCurParams = pCtx->GetPresentationParams();
|
|
189 |
|
|
190 |
// let the mananger know that we're entering the fs mode, it will
|
|
191 |
// set the proper current focus window for us, which ConfigureContext will
|
|
192 |
// use when creating the device
|
|
193 |
pMgr->SetFSFocusWindow(adapter, hWnd);
|
|
194 |
|
|
195 |
newParams = *pCurParams;
|
|
196 |
newParams.hDeviceWindow = hWnd;
|
|
197 |
newParams.Windowed = FALSE;
|
|
198 |
newParams.BackBufferCount = 1;
|
|
199 |
newParams.BackBufferFormat = dm.Format;
|
|
200 |
newParams.FullScreen_RefreshRateInHz = dm.RefreshRate;
|
|
201 |
newParams.BackBufferWidth = dm.Width;
|
|
202 |
newParams.BackBufferHeight = dm.Height;
|
|
203 |
newParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
|
|
204 |
newParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
205 |
|
|
206 |
res = pCtx->ConfigureContext(&newParams);
|
|
207 |
D3DRQ_MarkLostIfNeeded(res, D3DRQ_GetCurrentDestination());
|
|
208 |
return SUCCEEDED(res);
|
|
209 |
}
|
|
210 |
|
|
211 |
/*
|
|
212 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
213 |
* Method: exitFullScreenExclusiveNative
|
|
214 |
* Signature: (I)V
|
|
215 |
*/
|
|
216 |
JNIEXPORT jboolean JNICALL
|
|
217 |
Java_sun_java2d_d3d_D3DGraphicsDevice_exitFullScreenExclusiveNative
|
|
218 |
(JNIEnv *env, jclass gdc, jint gdiScreen)
|
|
219 |
{
|
|
220 |
HRESULT res;
|
|
221 |
D3DPipelineManager *pMgr;
|
|
222 |
D3DContext *pCtx;
|
|
223 |
D3DPRESENT_PARAMETERS newParams, *pCurParams;
|
|
224 |
UINT adapter;
|
|
225 |
|
|
226 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_exitFullScreenExclusiveNative");
|
|
227 |
|
|
228 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), JNI_FALSE);
|
|
229 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
230 |
|
|
231 |
if (FAILED(res = pMgr->GetD3DContext(adapter, &pCtx))) {
|
|
232 |
D3DRQ_MarkLostIfNeeded(res, D3DRQ_GetCurrentDestination());
|
|
233 |
return JNI_FALSE;
|
|
234 |
}
|
|
235 |
|
|
236 |
pCurParams = pCtx->GetPresentationParams();
|
|
237 |
|
|
238 |
newParams = *pCurParams;
|
|
239 |
// we're exiting fs, the device window can be 0
|
|
240 |
newParams.hDeviceWindow = 0;
|
|
241 |
newParams.Windowed = TRUE;
|
|
242 |
newParams.BackBufferFormat = D3DFMT_UNKNOWN;
|
|
243 |
newParams.BackBufferCount = 1;
|
|
244 |
newParams.FullScreen_RefreshRateInHz = 0;
|
|
245 |
newParams.BackBufferWidth = 0;
|
|
246 |
newParams.BackBufferHeight = 0;
|
|
247 |
newParams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
248 |
newParams.SwapEffect = D3DSWAPEFFECT_COPY;
|
|
249 |
|
|
250 |
res = pCtx->ConfigureContext(&newParams);
|
|
251 |
D3DRQ_MarkLostIfNeeded(res, D3DRQ_GetCurrentDestination());
|
|
252 |
|
|
253 |
// exited fs, update current focus window
|
|
254 |
// note that we call this after this adapter exited fs mode so that
|
|
255 |
// the rest of the adapters can be reset
|
|
256 |
pMgr->SetFSFocusWindow(adapter, 0);
|
|
257 |
|
|
258 |
return SUCCEEDED(res);
|
|
259 |
}
|
|
260 |
|
|
261 |
/*
|
|
262 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
263 |
* Method: configDisplayModeNative
|
|
264 |
* Signature: (IJIIII)V
|
|
265 |
*/
|
|
266 |
JNIEXPORT void JNICALL
|
|
267 |
Java_sun_java2d_d3d_D3DGraphicsDevice_configDisplayModeNative
|
|
268 |
(JNIEnv *env, jclass gdc, jint gdiScreen, jlong window,
|
|
269 |
jint width, jint height, jint bitDepth, jint refreshRate)
|
|
270 |
{
|
|
271 |
HRESULT res;
|
|
272 |
D3DPipelineManager *pMgr;
|
|
273 |
D3DContext *pCtx;
|
|
274 |
D3DPRESENT_PARAMETERS newParams, *pCurParams;
|
|
275 |
UINT adapter;
|
|
276 |
|
|
277 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_configDisplayModeNative");
|
|
278 |
|
|
279 |
RETURN_IF_NULL(pMgr = D3DPipelineManager::GetInstance());
|
|
280 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
281 |
|
|
282 |
if (FAILED(res = pMgr->GetD3DContext(adapter, &pCtx))) {
|
|
283 |
D3DRQ_MarkLostIfNeeded(res, D3DRQ_GetCurrentDestination());
|
|
284 |
return;
|
|
285 |
}
|
|
286 |
|
|
287 |
pCurParams = pCtx->GetPresentationParams();
|
|
288 |
|
|
289 |
newParams = *pCurParams;
|
|
290 |
newParams.BackBufferWidth = width;
|
|
291 |
newParams.BackBufferHeight = height;
|
|
292 |
newParams.FullScreen_RefreshRateInHz = refreshRate;
|
|
293 |
newParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
|
|
294 |
// we leave the swap effect so that it's more likely
|
|
295 |
// to be the one user selected initially
|
|
296 |
// newParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
297 |
|
|
298 |
if (bitDepth == 32) {
|
|
299 |
newParams.BackBufferFormat = D3DFMT_X8R8G8B8;
|
|
300 |
} else if (bitDepth == 16) {
|
|
301 |
UINT modeNum;
|
|
302 |
D3DDISPLAYMODE mode;
|
|
303 |
IDirect3D9 *pd3d9;
|
|
304 |
UINT modesCount;
|
|
305 |
|
|
306 |
RETURN_IF_NULL(pd3d9 = pMgr->GetD3DObject());
|
|
307 |
|
|
308 |
modesCount = pd3d9->GetAdapterModeCount(adapter, D3DFMT_R5G6B5);
|
|
309 |
if (modesCount == 0) {
|
|
310 |
modesCount = pd3d9->GetAdapterModeCount(adapter, D3DFMT_X1R5G5B5);
|
|
311 |
}
|
|
312 |
|
|
313 |
newParams.BackBufferFormat = D3DFMT_UNKNOWN;
|
|
314 |
for (modeNum = 0; modeNum < modesCount; modeNum++) {
|
|
315 |
if (SUCCEEDED(pd3d9->EnumAdapterModes(adapter, D3DFMT_R5G6B5,
|
|
316 |
modeNum, &mode)))
|
|
317 |
{
|
|
318 |
if (mode.Width == width && mode.Height == height &&
|
|
319 |
mode.RefreshRate == refreshRate)
|
|
320 |
{
|
|
321 |
// prefer 565 over 555
|
|
322 |
if (mode.Format == D3DFMT_R5G6B5) {
|
|
323 |
newParams.BackBufferFormat = D3DFMT_R5G6B5;
|
|
324 |
break;
|
|
325 |
} else if (mode.Format == D3DFMT_X1R5G5B5) {
|
|
326 |
newParams.BackBufferFormat = D3DFMT_X1R5G5B5;
|
|
327 |
}
|
|
328 |
}
|
|
329 |
}
|
|
330 |
}
|
|
331 |
if (newParams.BackBufferFormat == D3DFMT_UNKNOWN) {
|
|
332 |
J2dRlsTraceLn(J2D_TRACE_ERROR,
|
|
333 |
"D3DGD_configDisplayModeNative: no 16-bit formats");
|
|
334 |
return;
|
|
335 |
}
|
|
336 |
} else {
|
|
337 |
J2dRlsTraceLn1(J2D_TRACE_ERROR,
|
|
338 |
"D3DGD_configDisplayModeNative: unsupported depth: %d",
|
|
339 |
bitDepth);
|
|
340 |
return;
|
|
341 |
}
|
|
342 |
|
|
343 |
J2dTraceLn4(J2D_TRACE_VERBOSE, " changing to dm: %dx%dx%d@%d",
|
|
344 |
newParams.BackBufferWidth, newParams.BackBufferHeight,
|
|
345 |
bitDepth, refreshRate);
|
|
346 |
J2dTraceLn1(J2D_TRACE_VERBOSE, " selected backbuffer format: %d",
|
|
347 |
newParams.BackBufferFormat);
|
|
348 |
|
|
349 |
res = pCtx->ConfigureContext(&newParams);
|
|
350 |
if (SUCCEEDED(res)) {
|
|
351 |
// the full screen window doesn't receive WM_SIZE event when
|
|
352 |
// the display mode changes (it does get resized though) so we need to
|
|
353 |
// generate the event ourselves
|
|
354 |
::SendMessage(newParams.hDeviceWindow, WM_SIZE, width, height);
|
|
355 |
}
|
|
356 |
D3DRQ_MarkLostIfNeeded(res, D3DRQ_GetCurrentDestination());
|
|
357 |
}
|
|
358 |
|
|
359 |
|
|
360 |
/*
|
|
361 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
362 |
* Method: getCurrentDisplayModeNative
|
|
363 |
* Signature: (I)Ljava/awt/DisplayMode;
|
|
364 |
*/
|
|
365 |
JNIEXPORT jobject JNICALL
|
|
366 |
Java_sun_java2d_d3d_D3DGraphicsDevice_getCurrentDisplayModeNative
|
|
367 |
(JNIEnv *env, jclass gdc, jint gdiScreen)
|
|
368 |
{
|
|
369 |
D3DPipelineManager *pMgr;
|
|
370 |
IDirect3D9 *pd3d9;
|
|
371 |
jobject ret = NULL;
|
|
372 |
D3DDISPLAYMODE mode;
|
|
373 |
UINT adapter;
|
|
374 |
|
|
375 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_getCurrentDisplayModeNative");
|
|
376 |
|
|
377 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), NULL);
|
|
378 |
RETURN_STATUS_IF_NULL(pd3d9 = pMgr->GetD3DObject(), NULL);
|
|
379 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
380 |
|
|
381 |
if (SUCCEEDED(pd3d9->GetAdapterDisplayMode(adapter, &mode))) {
|
|
382 |
int bitDepth = -1;
|
|
383 |
// these are the only three valid screen formats
|
|
384 |
switch (mode.Format) {
|
|
385 |
case D3DFMT_X8R8G8B8: bitDepth = 32; break;
|
|
386 |
case D3DFMT_R5G6B5:
|
|
387 |
case D3DFMT_X1R5G5B5: bitDepth = 16; break;
|
|
388 |
}
|
|
389 |
J2dTraceLn4(J2D_TRACE_VERBOSE,
|
|
390 |
" current dm: %dx%dx%d@%d",
|
|
391 |
mode.Width, mode.Height, bitDepth, mode.RefreshRate);
|
|
392 |
ret = CreateDisplayMode(env, mode.Width, mode.Height, bitDepth,
|
|
393 |
mode.RefreshRate);
|
|
394 |
}
|
|
395 |
return ret;
|
|
396 |
}
|
|
397 |
|
|
398 |
/*
|
|
399 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
400 |
* Method: enumDisplayModesNative
|
|
401 |
* Signature: (ILjava/util/ArrayList;)V
|
|
402 |
*/
|
|
403 |
JNIEXPORT void JNICALL
|
|
404 |
Java_sun_java2d_d3d_D3DGraphicsDevice_enumDisplayModesNative
|
|
405 |
(JNIEnv *env, jclass gdc, jint gdiScreen, jobject arrayList)
|
|
406 |
{
|
|
407 |
D3DPipelineManager *pMgr;
|
|
408 |
IDirect3D9 *pd3d9;
|
|
409 |
jobject ret = NULL;
|
|
410 |
D3DDISPLAYMODE mode;
|
|
411 |
UINT formatNum, modeNum, modesCount;
|
|
412 |
UINT adapter;
|
|
413 |
// EnumAdapterModes treats 555 and 565 formats as equivalents
|
|
414 |
static D3DFORMAT formats[] =
|
|
415 |
{ D3DFMT_X8R8G8B8, D3DFMT_R5G6B5 };
|
|
416 |
|
|
417 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_enumDisplayModesNative");
|
|
418 |
|
|
419 |
RETURN_IF_NULL(pMgr = D3DPipelineManager::GetInstance());
|
|
420 |
RETURN_IF_NULL(pd3d9 = pMgr->GetD3DObject());
|
|
421 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
422 |
|
|
423 |
for (formatNum = 0; formatNum < 3; formatNum++) {
|
|
424 |
modesCount = pd3d9->GetAdapterModeCount(adapter, formats[formatNum]);
|
|
425 |
for (modeNum = 0; modeNum < modesCount; modeNum++) {
|
|
426 |
if (SUCCEEDED(pd3d9->EnumAdapterModes(adapter, formats[formatNum],
|
|
427 |
modeNum, &mode)))
|
|
428 |
{
|
|
429 |
int bitDepth = -1;
|
|
430 |
// these are the only three valid screen formats,
|
|
431 |
// 30-bit is returned as X8R8G8B8
|
|
432 |
switch (mode.Format) {
|
|
433 |
case D3DFMT_X8R8G8B8: bitDepth = 32; break;
|
|
434 |
case D3DFMT_R5G6B5:
|
|
435 |
case D3DFMT_X1R5G5B5: bitDepth = 16; break;
|
|
436 |
}
|
|
437 |
J2dTraceLn4(J2D_TRACE_VERBOSE, " found dm: %dx%dx%d@%d",
|
|
438 |
mode.Width, mode.Height, bitDepth,mode.RefreshRate);
|
|
439 |
addDisplayMode(env, arrayList, mode.Width, mode.Height,
|
|
440 |
bitDepth, mode.RefreshRate);
|
|
441 |
}
|
|
442 |
}
|
|
443 |
}
|
|
444 |
}
|
|
445 |
|
|
446 |
/*
|
|
447 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
448 |
* Method: getAvailableAcceleratedMemoryNative
|
|
449 |
* Signature: (I)J
|
|
450 |
*/
|
|
451 |
JNIEXPORT jlong JNICALL
|
|
452 |
Java_sun_java2d_d3d_D3DGraphicsDevice_getAvailableAcceleratedMemoryNative
|
|
453 |
(JNIEnv *env, jclass gdc, jint gdiScreen)
|
|
454 |
{
|
|
455 |
// REMIND: looks like Direct3D provides information about texture memory
|
|
456 |
// only via IDirect3DDevice9::GetAvailableTextureMem, however, it
|
|
457 |
// seems to report the same amount as direct draw used to.
|
|
458 |
HRESULT res;
|
|
459 |
D3DPipelineManager *pMgr;
|
|
460 |
D3DContext *pCtx;
|
|
461 |
IDirect3DDevice9 *pd3dDevice;
|
|
462 |
UINT adapter;
|
|
463 |
|
|
464 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_getAvailableAcceleratedMemoryNative");
|
|
465 |
|
|
466 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), 0L);
|
|
467 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
468 |
|
|
469 |
if (FAILED(res = pMgr->GetD3DContext(adapter, &pCtx))) {
|
|
470 |
D3DRQ_MarkLostIfNeeded(res, D3DRQ_GetCurrentDestination());
|
|
471 |
return 0L;
|
|
472 |
}
|
|
473 |
RETURN_STATUS_IF_NULL(pd3dDevice = pCtx->Get3DDevice(), 0L);
|
|
474 |
|
|
475 |
UINT mem = pd3dDevice->GetAvailableTextureMem();
|
|
476 |
J2dTraceLn1(J2D_TRACE_VERBOSE, " available memory=%d", mem);
|
|
477 |
return mem;
|
|
478 |
}
|
|
479 |
|
|
480 |
/*
|
|
481 |
* Class: sun_java2d_d3d_D3DGraphicsDevice
|
|
482 |
* Method: isD3DAvailableOnDeviceNative
|
|
483 |
* Signature: (I)Z
|
|
484 |
*/
|
|
485 |
JNIEXPORT jboolean JNICALL
|
|
486 |
Java_sun_java2d_d3d_D3DGraphicsDevice_isD3DAvailableOnDeviceNative
|
|
487 |
(JNIEnv *env, jclass gdc, jint gdiScreen)
|
|
488 |
{
|
|
489 |
HRESULT res;
|
|
490 |
D3DPipelineManager *pMgr;
|
|
491 |
D3DContext *pCtx;
|
|
492 |
UINT adapter;
|
|
493 |
|
|
494 |
J2dTraceLn(J2D_TRACE_INFO, "D3DGD_isD3DAvailableOnDeviceNative");
|
|
495 |
|
|
496 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), JNI_FALSE);
|
|
497 |
adapter = pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
498 |
|
|
499 |
if (FAILED(res = pMgr->GetD3DContext(adapter, &pCtx))) {
|
|
500 |
D3DRQ_MarkLostIfNeeded(res, D3DRQ_GetCurrentDestination());
|
|
501 |
return JNI_FALSE;
|
|
502 |
}
|
|
503 |
|
|
504 |
return JNI_TRUE;
|
|
505 |
}
|
|
506 |
|
|
507 |
} // extern "C"
|