2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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.
|
2
|
24 |
*/
|
|
25 |
|
1954
|
26 |
#include "D3DPipeline.h"
|
887
|
27 |
#include <jlong.h>
|
2
|
28 |
#include "D3DSurfaceData.h"
|
887
|
29 |
#include "D3DPipelineManager.h"
|
2
|
30 |
#include "Trace.h"
|
887
|
31 |
#include "awt_Toolkit.h"
|
|
32 |
#include "awt_Window.h"
|
|
33 |
#include "awt_BitmapUtil.h"
|
|
34 |
#include "D3DRenderQueue.h"
|
|
35 |
|
|
36 |
// REMIND: move to awt_Component.h
|
|
37 |
extern "C" HWND AwtComponent_GetHWnd(JNIEnv *env, jlong pData);
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Initializes nativeWidth/Height fields of the SurfaceData object with
|
|
41 |
* dimensions on the native surface.
|
|
42 |
*/
|
|
43 |
void D3DSD_SetNativeDimensions(JNIEnv *env, D3DSDOps *d3dsdo) {
|
|
44 |
jobject sdObject;
|
|
45 |
jint width, height;
|
|
46 |
|
|
47 |
RETURN_IF_NULL(sdObject = env->NewLocalRef(d3dsdo->sdOps.sdObject));
|
|
48 |
|
|
49 |
if (d3dsdo->pResource != NULL) {
|
|
50 |
width = d3dsdo->pResource->GetDesc()->Width;
|
|
51 |
height = d3dsdo->pResource->GetDesc()->Height;
|
|
52 |
} else {
|
|
53 |
width = d3dsdo->width;
|
|
54 |
height = d3dsdo->height;
|
|
55 |
}
|
|
56 |
|
|
57 |
JNU_SetFieldByName(env, NULL, sdObject, "nativeWidth", "I", width);
|
|
58 |
JNU_SetFieldByName(env, NULL, sdObject, "nativeHeight", "I", height);
|
|
59 |
|
|
60 |
env->DeleteLocalRef(sdObject);
|
|
61 |
}
|
|
62 |
|
|
63 |
void D3DSD_Flush(void *pData)
|
|
64 |
{
|
|
65 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSD_Flush");
|
|
66 |
RETURN_IF_NULL(pData);
|
|
67 |
|
|
68 |
D3DSDOps *d3dsdo = (D3DSDOps*)pData;
|
|
69 |
if (d3dsdo->pResource != NULL) {
|
|
70 |
D3DContext *pCtx;
|
|
71 |
D3DPipelineManager *pMgr;
|
|
72 |
|
|
73 |
d3dsdo->pResource->SetSDOps(NULL);
|
|
74 |
|
|
75 |
if ((pMgr = D3DPipelineManager::GetInstance()) != NULL &&
|
|
76 |
SUCCEEDED(pMgr->GetD3DContext(d3dsdo->adapter, &pCtx)))
|
|
77 |
{
|
|
78 |
if (pCtx->GetResourceManager()) {
|
|
79 |
pCtx->GetResourceManager()->ReleaseResource(d3dsdo->pResource);
|
|
80 |
}
|
|
81 |
}
|
|
82 |
d3dsdo->pResource = NULL;
|
|
83 |
}
|
|
84 |
}
|
2
|
85 |
|
887
|
86 |
void
|
|
87 |
D3DSD_MarkLost(void *pData)
|
|
88 |
{
|
|
89 |
D3DSDOps *d3dsdo;
|
|
90 |
jobject sdObject;
|
|
91 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
|
|
92 |
|
|
93 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSD_MarkLost");
|
|
94 |
|
|
95 |
RETURN_IF_NULL(pData);
|
|
96 |
|
|
97 |
d3dsdo = (D3DSDOps*)pData;
|
|
98 |
RETURN_IF_NULL(sdObject = env->NewLocalRef(d3dsdo->sdOps.sdObject));
|
|
99 |
|
|
100 |
JNU_CallMethodByName(env, NULL, sdObject,
|
|
101 |
"setSurfaceLost", "(Z)V", JNI_TRUE);
|
|
102 |
|
|
103 |
env->DeleteLocalRef(sdObject);
|
|
104 |
}
|
|
105 |
|
|
106 |
// ------------ generic SurfaceData.h functions ----------------
|
|
107 |
|
|
108 |
void
|
|
109 |
D3DSD_Dispose(JNIEnv *env, SurfaceDataOps *ops)
|
|
110 |
{
|
|
111 |
D3DSDOps *d3dsdo = (D3DSDOps *)ops;
|
|
112 |
RETURN_IF_NULL(d3dsdo);
|
|
113 |
|
|
114 |
JNU_CallStaticMethodByName(env, NULL, "sun/java2d/d3d/D3DSurfaceData",
|
|
115 |
"dispose", "(J)V",
|
|
116 |
ptr_to_jlong(ops));
|
|
117 |
}
|
2
|
118 |
|
887
|
119 |
/**
|
|
120 |
* This is the implementation of the general surface LockFunc defined in
|
|
121 |
* SurfaceData.h.
|
|
122 |
*/
|
|
123 |
jint
|
|
124 |
D3DSD_Lock(JNIEnv *env,
|
|
125 |
SurfaceDataOps *ops,
|
|
126 |
SurfaceDataRasInfo *pRasInfo,
|
|
127 |
jint lockflags)
|
|
128 |
{
|
|
129 |
JNU_ThrowInternalError(env, "D3DSD_Lock not implemented!");
|
|
130 |
return SD_FAILURE;
|
|
131 |
}
|
|
132 |
|
|
133 |
/**
|
|
134 |
* This is the implementation of the general GetRasInfoFunc defined in
|
|
135 |
* SurfaceData.h.
|
|
136 |
*/
|
|
137 |
void
|
|
138 |
D3DSD_GetRasInfo(JNIEnv *env,
|
|
139 |
SurfaceDataOps *ops,
|
|
140 |
SurfaceDataRasInfo *pRasInfo)
|
|
141 |
{
|
|
142 |
JNU_ThrowInternalError(env, "D3DSD_GetRasInfo not implemented!");
|
|
143 |
}
|
|
144 |
|
|
145 |
/**
|
|
146 |
* This is the implementation of the general surface UnlockFunc defined in
|
|
147 |
* SurfaceData.h.
|
|
148 |
*/
|
|
149 |
void
|
|
150 |
D3DSD_Unlock(JNIEnv *env,
|
|
151 |
SurfaceDataOps *ops,
|
|
152 |
SurfaceDataRasInfo *pRasInfo)
|
|
153 |
{
|
|
154 |
JNU_ThrowInternalError(env, "D3DSD_Unlock not implemented!");
|
|
155 |
}
|
|
156 |
|
|
157 |
// ------------ D3DSurfaceData's JNI methods ----------------
|
|
158 |
|
2
|
159 |
|
|
160 |
extern "C" {
|
|
161 |
|
|
162 |
/*
|
|
163 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
164 |
* Method: initOps
|
887
|
165 |
* Signature: (III)V
|
2
|
166 |
*/
|
887
|
167 |
JNIEXPORT void
|
|
168 |
JNICALL Java_sun_java2d_d3d_D3DSurfaceData_initOps
|
|
169 |
(JNIEnv *env, jobject d3dsd, jint gdiScreen, jint width, jint height)
|
2
|
170 |
{
|
887
|
171 |
D3DPipelineManager *pMgr;
|
|
172 |
D3DSDOps *d3dsdo = (D3DSDOps *)SurfaceData_InitOps(env, d3dsd,
|
|
173 |
sizeof(D3DSDOps));
|
|
174 |
|
2
|
175 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initOps");
|
887
|
176 |
|
|
177 |
if (d3dsdo == NULL) {
|
|
178 |
JNU_ThrowOutOfMemoryError(env, "creating native d3d ops");
|
|
179 |
return;
|
2
|
180 |
}
|
887
|
181 |
|
|
182 |
d3dsdo->sdOps.Lock = D3DSD_Lock;
|
|
183 |
d3dsdo->sdOps.GetRasInfo = D3DSD_GetRasInfo;
|
|
184 |
d3dsdo->sdOps.Unlock = D3DSD_Unlock;
|
|
185 |
d3dsdo->sdOps.Dispose = D3DSD_Dispose;
|
|
186 |
|
|
187 |
d3dsdo->xoff = 0;
|
|
188 |
d3dsdo->yoff = 0;
|
|
189 |
d3dsdo->width = width;
|
|
190 |
d3dsdo->height = height;
|
|
191 |
|
|
192 |
d3dsdo->pResource = NULL;
|
|
193 |
|
|
194 |
d3dsdo->adapter =
|
|
195 |
(pMgr = D3DPipelineManager::GetInstance()) == NULL ?
|
|
196 |
D3DADAPTER_DEFAULT :
|
|
197 |
pMgr->GetAdapterOrdinalForScreen(gdiScreen);
|
|
198 |
}
|
|
199 |
|
|
200 |
|
|
201 |
/*
|
|
202 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
203 |
* Method: initTexture
|
|
204 |
* Signature: (JZZ)Z
|
|
205 |
*/
|
|
206 |
JNIEXPORT jboolean
|
|
207 |
JNICALL Java_sun_java2d_d3d_D3DSurfaceData_initTexture
|
|
208 |
(JNIEnv *env, jobject d3dsd,
|
|
209 |
jlong pData, jboolean isRTT, jboolean isOpaque)
|
|
210 |
{
|
|
211 |
HRESULT res;
|
|
212 |
D3DSDOps *d3dsdo;
|
|
213 |
D3DContext *pCtx;
|
|
214 |
D3DPipelineManager *pMgr;
|
|
215 |
D3DFORMAT format;
|
|
216 |
|
|
217 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initTexture");
|
|
218 |
|
|
219 |
RETURN_STATUS_IF_NULL(d3dsdo = (D3DSDOps *)jlong_to_ptr(pData), JNI_FALSE);
|
|
220 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), JNI_FALSE);
|
|
221 |
|
|
222 |
if (FAILED(res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx))) {
|
|
223 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
224 |
return JNI_FALSE;
|
|
225 |
}
|
|
226 |
RETURN_STATUS_IF_NULL(pCtx->GetResourceManager(), JNI_FALSE);
|
|
227 |
|
|
228 |
pCtx->GetResourceManager()->ReleaseResource(d3dsdo->pResource);
|
|
229 |
d3dsdo->pResource = NULL;
|
|
230 |
|
|
231 |
if (isRTT && isOpaque) {
|
|
232 |
format = pCtx->GetPresentationParams()->BackBufferFormat;
|
|
233 |
} else {
|
|
234 |
format = D3DFMT_UNKNOWN;
|
|
235 |
}
|
|
236 |
|
|
237 |
res = pCtx->GetResourceManager()->
|
|
238 |
CreateTexture(d3dsdo->width, d3dsdo->height,
|
|
239 |
isRTT, isOpaque,
|
|
240 |
&format, 0/*usage*/, &d3dsdo->pResource);
|
|
241 |
if (SUCCEEDED(res)) {
|
|
242 |
J2dTraceLn1(J2D_TRACE_VERBOSE,
|
|
243 |
" created texture pResource=%x", d3dsdo->pResource);
|
|
244 |
d3dsdo->pResource->SetSDOps(d3dsdo);
|
|
245 |
} else {
|
|
246 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
247 |
}
|
|
248 |
D3DSD_SetNativeDimensions(env, d3dsdo);
|
|
249 |
|
|
250 |
return SUCCEEDED(res);
|
2
|
251 |
}
|
|
252 |
|
887
|
253 |
/*
|
|
254 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
255 |
* Method: initPlain
|
|
256 |
* Signature: (JZ)Z
|
|
257 |
*/
|
|
258 |
JNIEXPORT jboolean JNICALL
|
|
259 |
Java_sun_java2d_d3d_D3DSurfaceData_initRTSurface
|
|
260 |
(JNIEnv *env, jobject d3dsd, jlong pData, jboolean isOpaque)
|
2
|
261 |
{
|
887
|
262 |
HRESULT res;
|
|
263 |
D3DSDOps *d3dsdo;
|
|
264 |
D3DContext *pCtx;
|
|
265 |
D3DPipelineManager *pMgr;
|
|
266 |
D3DFORMAT format = D3DFMT_UNKNOWN;
|
2
|
267 |
|
887
|
268 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initRTSurface");
|
|
269 |
|
|
270 |
RETURN_STATUS_IF_NULL(d3dsdo = (D3DSDOps *)jlong_to_ptr(pData), JNI_FALSE);
|
|
271 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), JNI_FALSE);
|
|
272 |
|
|
273 |
if (FAILED(res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx))) {
|
|
274 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
2
|
275 |
return JNI_FALSE;
|
|
276 |
}
|
887
|
277 |
RETURN_STATUS_IF_NULL(pCtx->GetResourceManager(), JNI_FALSE);
|
|
278 |
|
|
279 |
pCtx->GetResourceManager()->ReleaseResource(d3dsdo->pResource);
|
|
280 |
d3dsdo->pResource = NULL;
|
|
281 |
|
|
282 |
res = pCtx->GetResourceManager()->
|
|
283 |
CreateRTSurface(d3dsdo->width, d3dsdo->height,
|
|
284 |
isOpaque, FALSE /*lockable*/,
|
|
285 |
&format, &d3dsdo->pResource);
|
|
286 |
if (SUCCEEDED(res)) {
|
|
287 |
J2dTraceLn1(J2D_TRACE_VERBOSE, " created RT surface pResource=0x%x",
|
|
288 |
d3dsdo->pResource);
|
|
289 |
d3dsdo->pResource->SetSDOps(d3dsdo);
|
|
290 |
} else {
|
|
291 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
292 |
}
|
|
293 |
D3DSD_SetNativeDimensions(env, d3dsdo);
|
|
294 |
|
|
295 |
return SUCCEEDED(res);
|
|
296 |
}
|
|
297 |
|
|
298 |
/*
|
|
299 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
300 |
* Method: initFlipBackbuffer
|
|
301 |
* Signature: (JJIZ)Z
|
|
302 |
*/
|
|
303 |
JNIEXPORT jboolean
|
|
304 |
JNICALL Java_sun_java2d_d3d_D3DSurfaceData_initFlipBackbuffer
|
|
305 |
(JNIEnv *env, jobject d3dsd, jlong pData, jlong pPeerData,
|
|
306 |
jint numBuffers, jint swapEffect,
|
|
307 |
jint vSyncType)
|
|
308 |
{
|
|
309 |
HRESULT res;
|
|
310 |
D3DSDOps *d3dsdo;
|
|
311 |
D3DContext *pCtx;
|
|
312 |
D3DPipelineManager *pMgr;
|
|
313 |
HWND hWnd;
|
|
314 |
UINT presentationInterval;
|
|
315 |
AwtComponent *pPeer;
|
|
316 |
RECT r = { 0, 0, 0, 0 };
|
|
317 |
|
|
318 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initFlipBackbuffer");
|
|
319 |
|
|
320 |
RETURN_STATUS_IF_NULL(d3dsdo = (D3DSDOps *)jlong_to_ptr(pData), JNI_FALSE);
|
|
321 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), JNI_FALSE);
|
|
322 |
RETURN_STATUS_IF_NULL(pPeer = (AwtComponent *)jlong_to_ptr(pPeerData),
|
|
323 |
JNI_FALSE);
|
|
324 |
|
|
325 |
hWnd = pPeer->GetHWnd();
|
|
326 |
if (!IsWindow(hWnd)) {
|
|
327 |
J2dTraceLn(J2D_TRACE_WARNING,
|
|
328 |
"D3DSurfaceData_initFlipBackbuffer: disposed component");
|
|
329 |
return JNI_FALSE;
|
|
330 |
}
|
|
331 |
|
|
332 |
pPeer->GetInsets(&r);
|
|
333 |
d3dsdo->xoff = -r.left;
|
|
334 |
d3dsdo->yoff = -r.top;
|
|
335 |
|
|
336 |
if (FAILED(res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx))) {
|
|
337 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
338 |
return JNI_FALSE;
|
|
339 |
}
|
|
340 |
RETURN_STATUS_IF_NULL(pCtx->GetResourceManager(), JNI_FALSE);
|
|
341 |
|
|
342 |
pCtx->GetResourceManager()->ReleaseResource(d3dsdo->pResource);
|
|
343 |
d3dsdo->pResource = NULL;
|
|
344 |
|
|
345 |
d3dsdo->swapEffect = (D3DSWAPEFFECT)swapEffect;
|
|
346 |
|
|
347 |
// in full-screen mode we should v-sync
|
|
348 |
if (pCtx->GetPresentationParams()->Windowed) {
|
|
349 |
if (vSyncType == VSYNC_ON) {
|
|
350 |
presentationInterval = D3DPRESENT_INTERVAL_ONE;
|
|
351 |
J2dTraceLn(J2D_TRACE_VERBOSE,
|
|
352 |
" windowed, forced interval: ONE");
|
|
353 |
} else {
|
|
354 |
presentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
355 |
J2dTraceLn(J2D_TRACE_VERBOSE,
|
|
356 |
" windowed, default interval: IMMEDIATE");
|
|
357 |
}
|
|
358 |
|
|
359 |
// REMIND: this is a workaround for the current issue
|
|
360 |
// we have with non-copy flip chains: since we can not specify
|
|
361 |
// the dest rectangle for Present for these modes, the result of
|
|
362 |
// Present(NULL, NULL) is scaled to the client area.
|
|
363 |
if (d3dsdo->xoff != 0 || d3dsdo->yoff != 0) {
|
|
364 |
d3dsdo->swapEffect = D3DSWAPEFFECT_COPY;
|
|
365 |
}
|
|
366 |
} else {
|
|
367 |
if (vSyncType == VSYNC_OFF) {
|
|
368 |
presentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
369 |
J2dTraceLn(J2D_TRACE_VERBOSE,
|
|
370 |
" full-screen, forced interval: IMMEDIATE");
|
|
371 |
} else {
|
|
372 |
presentationInterval = D3DPRESENT_INTERVAL_ONE;
|
|
373 |
J2dTraceLn(J2D_TRACE_VERBOSE,
|
|
374 |
" full-screen, default interval: ONE");
|
|
375 |
}
|
|
376 |
}
|
|
377 |
|
|
378 |
res = pCtx->GetResourceManager()->
|
|
379 |
CreateSwapChain(hWnd, numBuffers,
|
|
380 |
d3dsdo->width, d3dsdo->height,
|
|
381 |
d3dsdo->swapEffect, presentationInterval,
|
|
382 |
&d3dsdo->pResource);
|
|
383 |
if (SUCCEEDED(res)) {
|
|
384 |
J2dTraceLn1(J2D_TRACE_VERBOSE, " created swap chain pResource=0x%x",
|
|
385 |
d3dsdo->pResource);
|
|
386 |
d3dsdo->pResource->SetSDOps(d3dsdo);
|
|
387 |
} else {
|
|
388 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
389 |
}
|
|
390 |
D3DSD_SetNativeDimensions(env, d3dsdo);
|
|
391 |
|
|
392 |
return SUCCEEDED(res);
|
2
|
393 |
}
|
|
394 |
|
|
395 |
/*
|
|
396 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
887
|
397 |
* Method: dbGetPixelNative
|
|
398 |
* Signature: (JII)I
|
2
|
399 |
*/
|
887
|
400 |
JNIEXPORT jint JNICALL Java_sun_java2d_d3d_D3DSurfaceData_dbGetPixelNative
|
|
401 |
(JNIEnv *env, jclass clazz, jlong pData, jint x, jint y)
|
2
|
402 |
{
|
887
|
403 |
HRESULT res;
|
|
404 |
D3DSDOps *d3dsdo;
|
|
405 |
D3DContext *pCtx;
|
|
406 |
D3DPipelineManager *pMgr;
|
|
407 |
D3DResource *pLockableRes;
|
|
408 |
jint pixel = 0;
|
|
409 |
|
|
410 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_dbGetPixelNative");
|
2
|
411 |
|
887
|
412 |
RETURN_STATUS_IF_NULL(d3dsdo = (D3DSDOps *)jlong_to_ptr(pData), pixel);
|
|
413 |
RETURN_STATUS_IF_NULL(d3dsdo->pResource, pixel);
|
|
414 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), pixel);
|
|
415 |
|
|
416 |
if (FAILED(res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx))) {
|
|
417 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
418 |
return pixel;
|
|
419 |
}
|
|
420 |
RETURN_STATUS_IF_NULL(pCtx->GetResourceManager(), 0);
|
2
|
421 |
|
887
|
422 |
IDirect3DDevice9 *pd3dDevice = pCtx->Get3DDevice();
|
|
423 |
IDirect3DSurface9 *pSrc = d3dsdo->pResource->GetSurface();
|
|
424 |
D3DFORMAT srcFmt = d3dsdo->pResource->GetDesc()->Format;
|
|
425 |
|
|
426 |
pCtx->UpdateState(STATE_OTHEROP);
|
2
|
427 |
|
887
|
428 |
res = pCtx->GetResourceManager()->
|
|
429 |
GetLockableRTSurface(1, 1, srcFmt, &pLockableRes);
|
|
430 |
if (SUCCEEDED(res)) {
|
|
431 |
IDirect3DSurface9 *pTmpSurface;
|
|
432 |
RECT srcRect = { x, y, x+1, y+1};
|
|
433 |
RECT dstRect = { 0l, 0l, 1, 1 };
|
2
|
434 |
|
887
|
435 |
pTmpSurface = pLockableRes->GetSurface();
|
|
436 |
res = pd3dDevice->StretchRect(pSrc, &srcRect, pTmpSurface, &dstRect,
|
|
437 |
D3DTEXF_NONE);
|
|
438 |
if (SUCCEEDED(res)) {
|
|
439 |
D3DLOCKED_RECT lRect;
|
2
|
440 |
|
887
|
441 |
res = pTmpSurface->LockRect(&lRect, &dstRect, D3DLOCK_NOSYSLOCK);
|
|
442 |
if (SUCCEEDED(res)) {
|
|
443 |
if (srcFmt == D3DFMT_X8R8G8B8) {
|
|
444 |
pixel = *(jint*)lRect.pBits;
|
|
445 |
} else {
|
|
446 |
pixel = *(unsigned short*)lRect.pBits;
|
|
447 |
}
|
|
448 |
pTmpSurface->UnlockRect();
|
|
449 |
}
|
|
450 |
}
|
|
451 |
}
|
|
452 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
2
|
453 |
|
887
|
454 |
return pixel;
|
|
455 |
}
|
2
|
456 |
|
887
|
457 |
/*
|
|
458 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
459 |
* Method: dbSetPixelNative
|
|
460 |
* Signature: (JIII)V
|
|
461 |
*/
|
|
462 |
JNIEXPORT void JNICALL Java_sun_java2d_d3d_D3DSurfaceData_dbSetPixelNative
|
|
463 |
(JNIEnv *env, jclass clazz, jlong pData, jint x, jint y, jint pixel)
|
|
464 |
{
|
|
465 |
HRESULT res;
|
|
466 |
D3DSDOps *d3dsdo;
|
|
467 |
D3DResource *pLockableRes;
|
|
468 |
D3DContext *pCtx;
|
|
469 |
D3DPipelineManager *pMgr;
|
|
470 |
|
|
471 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_dbSetPixelNative");
|
|
472 |
|
|
473 |
RETURN_IF_NULL(d3dsdo = (D3DSDOps *)jlong_to_ptr(pData));
|
|
474 |
RETURN_IF_NULL(d3dsdo->pResource);
|
|
475 |
RETURN_IF_NULL(pMgr = D3DPipelineManager::GetInstance());
|
|
476 |
|
|
477 |
if (FAILED(res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx))) {
|
|
478 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
479 |
return;
|
2
|
480 |
}
|
887
|
481 |
RETURN_IF_NULL(pCtx->GetResourceManager());
|
2
|
482 |
|
887
|
483 |
IDirect3DDevice9 *pd3dDevice = pCtx->Get3DDevice();
|
|
484 |
IDirect3DSurface9 *pSrc = d3dsdo->pResource->GetSurface();
|
|
485 |
D3DFORMAT srcFmt = d3dsdo->pResource->GetDesc()->Format;
|
|
486 |
|
|
487 |
pCtx->UpdateState(STATE_OTHEROP);
|
|
488 |
|
|
489 |
res = pCtx->GetResourceManager()->
|
|
490 |
GetLockableRTSurface(1, 1, srcFmt, &pLockableRes);
|
|
491 |
if (SUCCEEDED(res)) {
|
|
492 |
IDirect3DSurface9 *pTmpSurface;
|
|
493 |
D3DLOCKED_RECT lRect;
|
|
494 |
RECT srcRect = { 0l, 0l, 1, 1 };
|
|
495 |
RECT dstRect = { x, y, x+1, y+1};
|
|
496 |
|
|
497 |
pTmpSurface = pLockableRes->GetSurface();
|
|
498 |
res = pTmpSurface->LockRect(&lRect, &srcRect, D3DLOCK_NOSYSLOCK);
|
|
499 |
if (SUCCEEDED(res)) {
|
|
500 |
if (srcFmt == D3DFMT_X8R8G8B8) {
|
|
501 |
*(jint*)lRect.pBits = pixel;
|
|
502 |
} else {
|
|
503 |
*(unsigned short*)lRect.pBits = (unsigned short)pixel;
|
|
504 |
}
|
|
505 |
pTmpSurface->UnlockRect();
|
|
506 |
|
|
507 |
res = pd3dDevice->StretchRect(pTmpSurface, &srcRect, pSrc, &dstRect,
|
|
508 |
D3DTEXF_NONE);
|
|
509 |
}
|
2
|
510 |
}
|
887
|
511 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
2
|
512 |
}
|
|
513 |
|
|
514 |
/*
|
887
|
515 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
516 |
* Method: getNativeResourceNative
|
|
517 |
* Signature: (JI)J
|
2
|
518 |
*/
|
887
|
519 |
JNIEXPORT jlong JNICALL
|
|
520 |
Java_sun_java2d_d3d_D3DSurfaceData_getNativeResourceNative
|
|
521 |
(JNIEnv *env, jclass d3sdc, jlong pData, jint resType)
|
2
|
522 |
{
|
887
|
523 |
D3DSDOps *d3dsdo;
|
|
524 |
|
|
525 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_getNativeResourceNative")
|
|
526 |
|
|
527 |
RETURN_STATUS_IF_NULL(d3dsdo = (D3DSDOps *)jlong_to_ptr(pData), 0L);
|
|
528 |
|
|
529 |
if (resType == D3D_DEVICE_RESOURCE) {
|
|
530 |
HRESULT res;
|
|
531 |
D3DPipelineManager *pMgr;
|
|
532 |
D3DContext *pCtx;
|
2
|
533 |
|
887
|
534 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), 0L);
|
|
535 |
if (FAILED(res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx))) {
|
|
536 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
537 |
return 0L;
|
|
538 |
}
|
|
539 |
return ptr_to_jlong(pCtx->Get3DDevice());
|
|
540 |
}
|
|
541 |
|
|
542 |
RETURN_STATUS_IF_NULL(d3dsdo->pResource, 0L);
|
2
|
543 |
|
887
|
544 |
if (resType == RT_PLAIN || resType == RT_TEXTURE) {
|
|
545 |
return ptr_to_jlong(d3dsdo->pResource->GetSurface());
|
|
546 |
}
|
|
547 |
if (resType == TEXTURE) {
|
|
548 |
return ptr_to_jlong(d3dsdo->pResource->GetTexture());
|
2
|
549 |
}
|
887
|
550 |
if (resType == FLIP_BACKBUFFER) {
|
|
551 |
return ptr_to_jlong(d3dsdo->pResource->GetSwapChain());
|
|
552 |
}
|
|
553 |
|
|
554 |
return 0L;
|
2
|
555 |
}
|
|
556 |
|
887
|
557 |
/*
|
|
558 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
559 |
* Method: updateWindowAccelImpl
|
|
560 |
* Signature: (JJII)Z
|
|
561 |
*/
|
|
562 |
JNIEXPORT jboolean
|
|
563 |
JNICALL Java_sun_java2d_d3d_D3DSurfaceData_updateWindowAccelImpl
|
|
564 |
(JNIEnv *env, jclass clazz, jlong pd3dsd, jlong pData, jint w, jint h)
|
|
565 |
{
|
|
566 |
HRESULT res;
|
|
567 |
AwtWindow *window;
|
|
568 |
HBITMAP hBitmap = NULL;
|
|
569 |
D3DSDOps *d3dsdo;
|
|
570 |
D3DResource *pSrcRes;
|
|
571 |
D3DContext *pCtx;
|
|
572 |
D3DPipelineManager *pMgr;
|
|
573 |
D3DResource *pLockableRes = NULL;
|
|
574 |
IDirect3DSurface9 *pTmpSurface = NULL;
|
|
575 |
IDirect3DDevice9 *pd3dDevice = NULL;
|
|
576 |
D3DLOCKED_RECT lockedRect;
|
|
577 |
|
|
578 |
J2dTraceLn(J2D_TRACE_ERROR, "D3DSurfaceData_updateWindowAccelImpl");
|
|
579 |
|
|
580 |
if (w <= 0 || h <= 0) {
|
|
581 |
return JNI_TRUE;
|
|
582 |
}
|
|
583 |
|
|
584 |
RETURN_STATUS_IF_NULL(window = (AwtWindow *)jlong_to_ptr(pData), JNI_FALSE);
|
|
585 |
RETURN_STATUS_IF_NULL(d3dsdo = (D3DSDOps *)jlong_to_ptr(pd3dsd), JNI_FALSE);
|
|
586 |
RETURN_STATUS_IF_NULL(pMgr = D3DPipelineManager::GetInstance(), JNI_FALSE);
|
|
587 |
RETURN_STATUS_IF_NULL(pSrcRes = d3dsdo->pResource, JNI_FALSE);
|
|
588 |
|
|
589 |
if (FAILED(res = pMgr->GetD3DContext(d3dsdo->adapter, &pCtx))) {
|
|
590 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
591 |
return JNI_FALSE;
|
|
592 |
}
|
|
593 |
|
|
594 |
RETURN_STATUS_IF_NULL(pd3dDevice = pCtx->Get3DDevice(), JNI_FALSE);
|
|
595 |
pCtx->UpdateState(STATE_OTHEROP);
|
|
596 |
|
|
597 |
res = pCtx->GetResourceManager()->
|
|
598 |
GetBlitOSPSurface(pSrcRes->GetDesc()->Width,
|
|
599 |
pSrcRes->GetDesc()->Height,
|
|
600 |
pSrcRes->GetDesc()->Format,
|
|
601 |
&pLockableRes);
|
|
602 |
if (FAILED(res)) {
|
|
603 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
604 |
return JNI_FALSE;
|
|
605 |
}
|
|
606 |
pTmpSurface = pLockableRes->GetSurface();
|
|
607 |
|
|
608 |
res = pd3dDevice->GetRenderTargetData(pSrcRes->GetSurface(), pTmpSurface);
|
|
609 |
if (FAILED(res)) {
|
|
610 |
D3DRQ_MarkLostIfNeeded(res, d3dsdo);
|
|
611 |
return JNI_FALSE;
|
|
612 |
}
|
|
613 |
|
|
614 |
res = pTmpSurface->LockRect(&lockedRect, NULL, D3DLOCK_NOSYSLOCK);
|
|
615 |
if (SUCCEEDED(res)) {
|
2451
|
616 |
hBitmap =
|
|
617 |
BitmapUtil::CreateBitmapFromARGBPre(w, h,
|
|
618 |
lockedRect.Pitch,
|
|
619 |
(int*)lockedRect.pBits);
|
887
|
620 |
pTmpSurface->UnlockRect();
|
|
621 |
}
|
|
622 |
RETURN_STATUS_IF_NULL(hBitmap, JNI_FALSE);
|
|
623 |
|
2451
|
624 |
window->UpdateWindow(env, NULL, w, h, hBitmap);
|
887
|
625 |
|
|
626 |
// hBitmap is released in UpdateWindow
|
|
627 |
|
|
628 |
return JNI_TRUE;
|
2
|
629 |
}
|
887
|
630 |
}
|