2
|
1 |
/*
|
|
2 |
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
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
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
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 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
#include "D3DSurfaceData.h"
|
|
27 |
#include "D3DContext.h"
|
|
28 |
#include "jlong.h"
|
|
29 |
#include "jni_util.h"
|
|
30 |
#include "Trace.h"
|
|
31 |
#include "ddrawUtils.h"
|
|
32 |
#include "Devices.h"
|
|
33 |
|
|
34 |
#include "Win32SurfaceData.h"
|
|
35 |
#include "sun_java2d_d3d_D3DBackBufferSurfaceData.h"
|
|
36 |
|
|
37 |
extern LockFunc Win32OSSD_Lock;
|
|
38 |
extern GetRasInfoFunc Win32OSSD_GetRasInfo;
|
|
39 |
extern UnlockFunc Win32OSSD_Unlock;
|
|
40 |
extern DisposeFunc Win32OSSD_Dispose;
|
|
41 |
extern GetDCFunc Win32OSSD_GetDC;
|
|
42 |
extern ReleaseDCFunc Win32OSSD_ReleaseDC;
|
|
43 |
extern InvalidateSDFunc Win32OSSD_InvalidateSD;
|
|
44 |
extern RestoreSurfaceFunc Win32OSSD_RestoreSurface;
|
|
45 |
extern DisposeFunc Win32BBSD_Dispose;
|
|
46 |
|
|
47 |
extern "C" {
|
|
48 |
|
|
49 |
RestoreSurfaceFunc D3DSD_RestoreSurface;
|
|
50 |
|
|
51 |
/*
|
|
52 |
* D3D-surface specific restore function.
|
|
53 |
* We need to make sure the D3DContext is notified if the
|
|
54 |
* surface is lost (only if this surface is the current target,
|
|
55 |
* otherwise it's possible that it'll get restored (along with its
|
|
56 |
* depth buffer), and the context will still think that the clipping
|
|
57 |
* that's set for this surface is valid.
|
|
58 |
* Consider this scenario:
|
|
59 |
* do {
|
|
60 |
* vi.validate(gc); // validated, vi's surface is restored, clipping is lost
|
|
61 |
* // render stuff using d3d, clipping is reset
|
|
62 |
* // -> surface loss event happens
|
|
63 |
* // do a DD blit of the VI to the screen
|
|
64 |
* // at this point the VI surface will be marked lost
|
|
65 |
* // and will be restored in validate() next time around,
|
|
66 |
* // losing the clipping w/o notifying the D3D context
|
|
67 |
* } while (vi.surfaceLost());
|
|
68 |
*/
|
|
69 |
void D3DSD_RestoreSurface(JNIEnv *env, Win32SDOps *wsdo) {
|
|
70 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSD_RestoreSurface");
|
|
71 |
D3DSDOps *d3dsdo = (D3DSDOps *)wsdo;
|
|
72 |
// This is needed only for non-textures, since textures can't
|
|
73 |
// lose their surfaces, as they're managed.
|
|
74 |
if (!(d3dsdo->d3dType & D3D_TEXTURE_SURFACE) && wsdo->lpSurface != NULL)
|
|
75 |
{
|
|
76 |
if (wsdo->ddInstance != NULL && wsdo->ddInstance->ddObject != NULL) {
|
|
77 |
D3DContext *d3dContext =
|
|
78 |
wsdo->ddInstance->ddObject->GetD3dContext();
|
|
79 |
if (d3dContext != NULL) {
|
|
80 |
d3dContext->InvalidateIfTarget(env, wsdo->lpSurface);
|
|
81 |
}
|
|
82 |
}
|
|
83 |
}
|
|
84 |
Win32OSSD_RestoreSurface(env, wsdo);
|
|
85 |
}
|
|
86 |
|
|
87 |
/*
|
|
88 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
89 |
* Method: initOps
|
|
90 |
* Signature: (Ljava/lang/Object;)V
|
|
91 |
*/
|
|
92 |
JNIEXPORT void JNICALL
|
|
93 |
Java_sun_java2d_d3d_D3DSurfaceData_initOps(JNIEnv *env,
|
|
94 |
jobject wsd,
|
|
95 |
jint depth,
|
|
96 |
jint transparency)
|
|
97 |
{
|
|
98 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initOps");
|
|
99 |
Win32SDOps *wsdo = (Win32SDOps *)SurfaceData_InitOps(env, wsd,
|
|
100 |
sizeof(D3DSDOps));
|
|
101 |
wsdo->sdOps.Lock = Win32OSSD_Lock;
|
|
102 |
wsdo->sdOps.GetRasInfo = Win32OSSD_GetRasInfo;
|
|
103 |
wsdo->sdOps.Unlock = Win32OSSD_Unlock;
|
|
104 |
wsdo->sdOps.Dispose = Win32OSSD_Dispose;
|
|
105 |
wsdo->RestoreSurface = D3DSD_RestoreSurface;
|
|
106 |
wsdo->GetDC = Win32OSSD_GetDC;
|
|
107 |
wsdo->ReleaseDC = Win32OSSD_ReleaseDC;
|
|
108 |
wsdo->InvalidateSD = Win32OSSD_InvalidateSD;
|
|
109 |
wsdo->invalid = JNI_FALSE;
|
|
110 |
wsdo->lockType = WIN32SD_LOCK_UNLOCKED;
|
|
111 |
wsdo->window = NULL;
|
|
112 |
wsdo->backBufferCount = 0;
|
|
113 |
wsdo->depth = depth;
|
|
114 |
switch (depth) {
|
|
115 |
case 8:
|
|
116 |
wsdo->pixelStride = 1;
|
|
117 |
break;
|
|
118 |
case 15: //555
|
|
119 |
wsdo->pixelStride = 2;
|
|
120 |
wsdo->pixelMasks[0] = 0x1f << 10;
|
|
121 |
wsdo->pixelMasks[1] = 0x1f << 5;
|
|
122 |
wsdo->pixelMasks[2] = 0x1f;
|
|
123 |
break;
|
|
124 |
case 16: //565
|
|
125 |
wsdo->pixelStride = 2;
|
|
126 |
wsdo->pixelMasks[0] = 0x1f << 11;
|
|
127 |
wsdo->pixelMasks[1] = 0x3f << 5;
|
|
128 |
wsdo->pixelMasks[2] = 0x1f;
|
|
129 |
break;
|
|
130 |
case 24:
|
|
131 |
wsdo->pixelStride = 3;
|
|
132 |
break;
|
|
133 |
case 32: //x888
|
|
134 |
wsdo->pixelStride = 4;
|
|
135 |
wsdo->pixelMasks[0] = 0xff0000;
|
|
136 |
wsdo->pixelMasks[1] = 0x00ff00;
|
|
137 |
wsdo->pixelMasks[2] = 0x0000ff;
|
|
138 |
break;
|
|
139 |
}
|
|
140 |
wsdo->surfaceLock = new CriticalSection();
|
|
141 |
wsdo->surfaceLost = FALSE;
|
|
142 |
wsdo->transparency = transparency;
|
|
143 |
wsdo->surfacePuntData.usingDDSystem = FALSE;
|
|
144 |
wsdo->surfacePuntData.lpSurfaceSystem = NULL;
|
|
145 |
wsdo->surfacePuntData.lpSurfaceVram = NULL;
|
|
146 |
wsdo->surfacePuntData.numBltsSinceRead = 0;
|
|
147 |
wsdo->surfacePuntData.pixelsReadSinceBlt = 0;
|
|
148 |
wsdo->surfacePuntData.numBltsThreshold = 2;
|
|
149 |
wsdo->gdiOpPending = FALSE;
|
|
150 |
}
|
|
151 |
|
|
152 |
jboolean init_D3DSDO(JNIEnv* env, Win32SDOps* wsdo, jint width, jint height,
|
|
153 |
jint d3dSurfaceType, jint screen)
|
|
154 |
{
|
|
155 |
// default in case of an error
|
|
156 |
wsdo->lpSurface = NULL;
|
|
157 |
wsdo->ddInstance = NULL;
|
|
158 |
|
|
159 |
{
|
|
160 |
Devices::InstanceAccess devices;
|
|
161 |
wsdo->device = devices->GetDeviceReference(screen, FALSE);
|
|
162 |
}
|
|
163 |
if (wsdo->device == NULL) {
|
|
164 |
J2dTraceLn1(J2D_TRACE_WARNING,
|
|
165 |
"init_D3DSDO: Incorrect "\
|
|
166 |
"screen number (screen=%d)", screen);
|
|
167 |
wsdo->invalid = TRUE;
|
|
168 |
return JNI_FALSE;
|
|
169 |
}
|
|
170 |
wsdo->w = width;
|
|
171 |
wsdo->h = height;
|
|
172 |
wsdo->surfacePuntData.disablePunts = TRUE;
|
|
173 |
return JNI_TRUE;
|
|
174 |
}
|
|
175 |
|
|
176 |
/*
|
|
177 |
* Class: sun_java2d_d3d_D3DSurfaceData
|
|
178 |
* Method: initOffScreenSurface
|
|
179 |
* Signature: (JJJIIII)I
|
|
180 |
*/
|
|
181 |
JNIEXPORT jint JNICALL
|
|
182 |
Java_sun_java2d_d3d_D3DSurfaceData_initOffScreenSurface
|
|
183 |
(JNIEnv *env, jobject sData,
|
|
184 |
jlong pCtx,
|
|
185 |
jlong pData, jlong parentPdata,
|
|
186 |
jint width, jint height,
|
|
187 |
jint d3dSurfaceType, jint screen)
|
|
188 |
{
|
|
189 |
Win32SDOps *wsdo = (Win32SDOps *)jlong_to_ptr(pData);
|
|
190 |
D3DContext *pd3dc = (D3DContext *)jlong_to_ptr(pCtx);
|
|
191 |
|
|
192 |
J2dTraceLn(J2D_TRACE_INFO, "D3DSurfaceData_initOffScreenSurface");
|
|
193 |
J2dTraceLn4(J2D_TRACE_VERBOSE,
|
|
194 |
" width=%-4d height=%-4d type=%-3d scr=%-3d",
|
|
195 |
width, height, d3dSurfaceType, screen);
|
|
196 |
|
|
197 |
// REMIND: ideally this should be done in initOps
|
|
198 |
if (d3dSurfaceType == D3D_ATTACHED_SURFACE) {
|
|
199 |
wsdo->sdOps.Dispose = Win32BBSD_Dispose;
|
|
200 |
}
|
|
201 |
|
|
202 |
if (init_D3DSDO(env, wsdo, width, height,
|
|
203 |
d3dSurfaceType, screen) == JNI_FALSE)
|
|
204 |
{
|
|
205 |
SurfaceData_ThrowInvalidPipeException(env,
|
|
206 |
"Can't create offscreen surface");
|
|
207 |
return PF_INVALID;
|
|
208 |
}
|
|
209 |
|
|
210 |
HMONITOR hMon = (HMONITOR)wsdo->device->GetMonitor();
|
|
211 |
DDrawObjectStruct *ddInstance = GetDDInstanceForDevice(hMon);
|
|
212 |
if (!ddInstance || !ddInstance->valid || !pd3dc) {
|
|
213 |
return PF_INVALID;
|
|
214 |
}
|
|
215 |
|
|
216 |
if (d3dSurfaceType == D3D_ATTACHED_SURFACE) {
|
|
217 |
// REMIND: still using the old path. ideally the creation of attached
|
|
218 |
// surface shoudld be done in the same way as other types of surfaces,
|
|
219 |
// that is, in D3DContext::CreateSurface, but we really don't use
|
|
220 |
// anything from D3DContext to get an attached surface, so this
|
|
221 |
// was left here.
|
|
222 |
|
|
223 |
Win32SDOps *wsdo_parent = (Win32SDOps *)jlong_to_ptr(parentPdata);
|
|
224 |
// we're being explicit here: requesting backbuffer, and render target
|
|
225 |
DDrawSurface* pNew = wsdo_parent->lpSurface == NULL ?
|
|
226 |
NULL :
|
|
227 |
wsdo_parent->lpSurface->
|
|
228 |
GetDDAttachedSurface(DDSCAPS_BACKBUFFER|DDSCAPS_3DDEVICE);
|
|
229 |
if (pNew == NULL ||
|
|
230 |
FAILED(pd3dc->AttachDepthBuffer(pNew->GetDXSurface())))
|
|
231 |
{
|
|
232 |
J2dRlsTraceLn1(J2D_TRACE_ERROR,
|
|
233 |
"D3DSD_initSurface: GetAttachedSurface for parent"\
|
|
234 |
" wsdo_parent->lpSurface=0x%x failed",
|
|
235 |
wsdo_parent->lpSurface);
|
|
236 |
if (pNew != NULL) {
|
|
237 |
delete pNew;
|
|
238 |
}
|
|
239 |
SurfaceData_ThrowInvalidPipeException(env,
|
|
240 |
"Can't create attached offscreen surface");
|
|
241 |
return PF_INVALID;
|
|
242 |
}
|
|
243 |
|
|
244 |
wsdo->lpSurface = pNew;
|
|
245 |
wsdo->ddInstance = ddInstance;
|
|
246 |
J2dTraceLn2(J2D_TRACE_VERBOSE,
|
|
247 |
"D3DSD_initSurface: created attached surface: "\
|
|
248 |
"wsdo->lpSurface=0x%x for parent "\
|
|
249 |
"wsdo_parent->lpSurface=0x%x",
|
|
250 |
wsdo->lpSurface, wsdo_parent->lpSurface);
|
|
251 |
// we don't care about pixel format for non-texture surfaces
|
|
252 |
return PF_INVALID;
|
|
253 |
}
|
|
254 |
|
|
255 |
DXSurface *dxSurface = NULL;
|
|
256 |
jint pf = PF_INVALID;
|
|
257 |
HRESULT res;
|
|
258 |
if (SUCCEEDED(res = pd3dc->CreateSurface(env, wsdo->w, wsdo->h,
|
|
259 |
wsdo->depth, wsdo->transparency,
|
|
260 |
d3dSurfaceType,
|
|
261 |
&dxSurface, &pf)))
|
|
262 |
{
|
|
263 |
// REMIND: put all the error-handling stuff here from
|
|
264 |
// DDCreateOffScreenSurface
|
|
265 |
wsdo->lpSurface = new DDrawSurface(ddInstance->ddObject, dxSurface);
|
|
266 |
wsdo->surfacePuntData.lpSurfaceVram = wsdo->lpSurface;
|
|
267 |
wsdo->ddInstance = ddInstance;
|
|
268 |
// the dimensions of the surface may be adjusted in case of
|
|
269 |
// textures
|
|
270 |
wsdo->w = dxSurface->GetWidth();
|
|
271 |
wsdo->h = dxSurface->GetHeight();
|
|
272 |
J2dTraceLn1(J2D_TRACE_VERBOSE,
|
|
273 |
"D3DSurfaceData_initSurface: created surface: "\
|
|
274 |
"wsdo->lpSurface=0x%x", wsdo->lpSurface);
|
|
275 |
} else {
|
|
276 |
DebugPrintDirectDrawError(res,
|
|
277 |
"D3DSurfaceData_initSurface: "\
|
|
278 |
"CreateSurface failed");
|
|
279 |
// REMIND: should use some other way to signal that
|
|
280 |
// surface creation was unsuccessful
|
|
281 |
SurfaceData_ThrowInvalidPipeException(env,
|
|
282 |
"Can't create offscreen surf");
|
|
283 |
}
|
|
284 |
return pf;
|
|
285 |
}
|
|
286 |
|
|
287 |
/*
|
|
288 |
* Class: sun_java2d_d3d_D3DBackBufferSurfaceData
|
|
289 |
* Method: restoreDepthBuffer
|
|
290 |
* Signature: ()V
|
|
291 |
*/
|
|
292 |
JNIEXPORT void JNICALL
|
|
293 |
Java_sun_java2d_d3d_D3DBackBufferSurfaceData_restoreDepthBuffer(JNIEnv *env,
|
|
294 |
jobject sData)
|
|
295 |
{
|
|
296 |
Win32SDOps *wsdo = Win32SurfaceData_GetOpsNoSetup(env, sData);
|
|
297 |
J2dTraceLn1(J2D_TRACE_INFO,
|
|
298 |
"D3DBBSD_restoreDepthBuffer: wsdo=0x%x", wsdo);
|
|
299 |
|
|
300 |
if (wsdo != NULL) {
|
|
301 |
if (!DDRestoreSurface(wsdo)) {
|
|
302 |
// Failure - throw exception
|
|
303 |
J2dRlsTraceLn(J2D_TRACE_ERROR,
|
|
304 |
"D3DBBSD_restoreDepthBuffer: failed to "\
|
|
305 |
"restore depth buffer");
|
|
306 |
|
|
307 |
SurfaceData_ThrowInvalidPipeException(env,
|
|
308 |
"RestoreDepthBuffer failure");
|
|
309 |
}
|
|
310 |
}
|
|
311 |
}
|
|
312 |
|
|
313 |
}
|