author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 7489 | 9136c8c7d74c |
child 18232 | b538b71fb429 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 1999, 2010, 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 |
||
887 | 26 |
#include "sun_java2d_windows_GDIWindowSurfaceData.h" |
2 | 27 |
|
887 | 28 |
#include "GDIWindowSurfaceData.h" |
2 | 29 |
#include "GraphicsPrimitiveMgr.h" |
30 |
#include "Region.h" |
|
31 |
#include "Disposer.h" |
|
32 |
#include "WindowsFlags.h" |
|
33 |
#include "awt_Component.h" |
|
34 |
#include "awt_Palette.h" |
|
35 |
#include "awt_Win32GraphicsDevice.h" |
|
36 |
#include "gdefs.h" |
|
37 |
#include "Trace.h" |
|
38 |
#include "Devices.h" |
|
39 |
||
40 |
#include "jni_util.h" |
|
41 |
||
887 | 42 |
static LockFunc GDIWinSD_Lock; |
43 |
static GetRasInfoFunc GDIWinSD_GetRasInfo; |
|
44 |
static UnlockFunc GDIWinSD_Unlock; |
|
45 |
static DisposeFunc GDIWinSD_Dispose; |
|
46 |
static SetupFunc GDIWinSD_Setup; |
|
47 |
static GetDCFunc GDIWinSD_GetDC; |
|
48 |
static ReleaseDCFunc GDIWinSD_ReleaseDC; |
|
49 |
static InvalidateSDFunc GDIWinSD_InvalidateSD; |
|
2 | 50 |
|
51 |
static HBRUSH nullbrush; |
|
52 |
static HPEN nullpen; |
|
53 |
||
54 |
static jclass xorCompClass; |
|
55 |
||
56 |
static jboolean beingShutdown = JNI_FALSE; |
|
7489
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
57 |
static volatile LONG timeStamp = 0; |
2 | 58 |
extern CriticalSection windowMoveLock; |
59 |
||
60 |
extern "C" |
|
61 |
{ |
|
62 |
GeneralDisposeFunc DisposeThreadGraphicsInfo; |
|
63 |
jobject JNI_GetCurrentThread(JNIEnv *env); |
|
64 |
int threadInfoIndex = TLS_OUT_OF_INDEXES; |
|
65 |
||
66 |
static jclass threadClass = NULL; |
|
67 |
static jmethodID currentThreadMethodID = NULL; |
|
68 |
||
887 | 69 |
void SetupThreadGraphicsInfo(JNIEnv *env, GDIWinSDOps *wsdo) { |
2 | 70 |
J2dTraceLn(J2D_TRACE_INFO, "SetupThreadGraphicsInfo"); |
71 |
||
72 |
// REMIND: handle error when creation fails |
|
73 |
ThreadGraphicsInfo *info = |
|
74 |
(ThreadGraphicsInfo*)TlsGetValue(threadInfoIndex); |
|
75 |
if (info == NULL) { |
|
76 |
info = new ThreadGraphicsInfo; |
|
77 |
ZeroMemory(info, sizeof(ThreadGraphicsInfo)); |
|
78 |
TlsSetValue(threadInfoIndex, (LPVOID)info); |
|
79 |
J2dTraceLn2(J2D_TRACE_VERBOSE, |
|
80 |
" current batch limit for for thread 0x%x is %d", |
|
81 |
GetCurrentThreadId(), ::GdiGetBatchLimit()); |
|
82 |
J2dTraceLn(J2D_TRACE_VERBOSE, " setting to the limit to 1"); |
|
83 |
// Fix for bug 4374079 |
|
84 |
::GdiSetBatchLimit(1); |
|
85 |
||
86 |
Disposer_AddRecord(env, JNI_GetCurrentThread(env), |
|
87 |
DisposeThreadGraphicsInfo, |
|
88 |
ptr_to_jlong(info)); |
|
89 |
} |
|
90 |
||
91 |
HDC oldhDC = info->hDC; |
|
92 |
// the hDC is NULL for offscreen surfaces - we don't store it |
|
93 |
// in TLS as it must be created new every time. |
|
7489
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
94 |
|
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
95 |
if( ((oldhDC == NULL) && wsdo->window != NULL) || |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
96 |
(info->wsdo != wsdo) || |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
97 |
(info->wsdoTimeStamp != wsdo->timeStamp) ) |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
98 |
{ |
2 | 99 |
|
100 |
// Init graphics state, either because this is our first time |
|
101 |
// using it in this thread or because this thread is now |
|
102 |
// dealing with a different window than it was last time. |
|
103 |
||
7489
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
104 |
//check extra condition: |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
105 |
//(info->wsdoTimeStamp != wsdo->timeStamp). |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
106 |
//Checking memory addresses (info->wsdo != wsdo) will not detect |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
107 |
//that wsdo points to a newly allocated structure in case |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
108 |
//that structure just got allocated at a "recycled" memory location |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
109 |
//which previously was pointed by info->wsdo |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
110 |
//see bug# 6859086 |
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
111 |
|
2 | 112 |
// Release cached DC. We use deferred DC releasing mechanism because |
113 |
// the DC is associated with cached wsdo and component peer, |
|
114 |
// which may've been disposed by this time, and we have |
|
115 |
// no means of checking against it. |
|
116 |
if (oldhDC != NULL) { |
|
117 |
MoveDCToPassiveList(oldhDC); |
|
118 |
info->hDC = NULL; |
|
119 |
} |
|
120 |
||
121 |
if (wsdo->window != NULL){ |
|
122 |
HDC hDC; |
|
123 |
// This is a window surface |
|
124 |
// First, init the HDC object |
|
887 | 125 |
AwtComponent *comp = GDIWindowSurfaceData_GetComp(env, wsdo); |
2 | 126 |
if (comp == NULL) { |
127 |
return; |
|
128 |
} |
|
129 |
hDC = comp->GetDCFromComponent(); |
|
130 |
if (hDC != NULL) { |
|
131 |
::SelectObject(hDC, nullbrush); |
|
132 |
::SelectObject(hDC, nullpen); |
|
133 |
::SelectClipRgn(hDC, (HRGN) NULL); |
|
134 |
::SetROP2(hDC, R2_COPYPEN); |
|
135 |
wsdo->device->SelectPalette(hDC); |
|
136 |
// Note that on NT4 we don't need to do a realize here: the |
|
137 |
// palette-sharing takes care of color issues for us. But |
|
138 |
// on win98 if we don't realize a DC's palette, that |
|
139 |
// palette does not appear to have correct access to the |
|
140 |
// logical->system mapping. |
|
141 |
wsdo->device->RealizePalette(hDC); |
|
142 |
||
143 |
// Second, init the rest of the graphics state |
|
144 |
::GetClientRect(wsdo->window, &info->bounds); |
|
145 |
// Make window-relative from client-relative |
|
146 |
::OffsetRect(&info->bounds, wsdo->insets.left, wsdo->insets.top); |
|
147 |
//Likewise, translate GDI calls from client-relative to window-relative |
|
148 |
::OffsetViewportOrgEx(hDC, -wsdo->insets.left, -wsdo->insets.top, NULL); |
|
149 |
} |
|
150 |
||
151 |
// Finally, set these new values in the info for this thread |
|
152 |
info->hDC = hDC; |
|
153 |
} |
|
154 |
||
155 |
// cached brush and pen are not associated with any DC, and can be |
|
156 |
// reused, but have to set type to 0 to indicate that no pen/brush |
|
157 |
// were set to the new hdc |
|
158 |
info->type = 0; |
|
159 |
||
160 |
if (info->clip != NULL) { |
|
161 |
env->DeleteWeakGlobalRef(info->clip); |
|
162 |
} |
|
163 |
info->clip = NULL; |
|
164 |
||
165 |
if (info->comp != NULL) { |
|
166 |
env->DeleteWeakGlobalRef(info->comp); |
|
167 |
} |
|
168 |
info->comp = NULL; |
|
169 |
||
170 |
info->xorcolor = 0; |
|
171 |
info->patrop = PATCOPY; |
|
172 |
||
7489
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
173 |
//store the address and time stamp of newly allocated GDIWinSDOps structure |
2 | 174 |
info->wsdo = wsdo; |
7489
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
175 |
info->wsdoTimeStamp = wsdo->timeStamp; |
2 | 176 |
} |
177 |
} |
|
178 |
||
179 |
/** |
|
180 |
* Releases native data stored in Thread local storage. |
|
181 |
* Called by the Disposer when the associated thread dies. |
|
182 |
*/ |
|
183 |
void DisposeThreadGraphicsInfo(JNIEnv *env, jlong tgi) { |
|
184 |
J2dTraceLn(J2D_TRACE_INFO, "DisposeThreadGraphicsInfo"); |
|
185 |
ThreadGraphicsInfo *info = (ThreadGraphicsInfo*)jlong_to_ptr(tgi); |
|
186 |
if (info != NULL) { |
|
187 |
if (info->hDC != NULL) { |
|
188 |
// move the DC from the active dcs list to |
|
189 |
// the passive dc list to be released later |
|
190 |
MoveDCToPassiveList(info->hDC); |
|
191 |
} |
|
192 |
||
193 |
if (info->clip != NULL) { |
|
194 |
env->DeleteWeakGlobalRef(info->clip); |
|
195 |
} |
|
196 |
if (info->comp != NULL) { |
|
197 |
env->DeleteWeakGlobalRef(info->comp); |
|
198 |
} |
|
199 |
||
200 |
if (info->brush != NULL) { |
|
201 |
info->brush->Release(); |
|
202 |
} |
|
203 |
if (info->pen != NULL) { |
|
204 |
info->pen->Release(); |
|
205 |
} |
|
206 |
||
207 |
delete info; |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
/** |
|
212 |
* Returns current Thread object. |
|
213 |
*/ |
|
214 |
jobject |
|
215 |
JNI_GetCurrentThread(JNIEnv *env) { |
|
216 |
return env->CallStaticObjectMethod(threadClass, currentThreadMethodID); |
|
217 |
} /* JNI_GetCurrentThread() */ |
|
218 |
||
219 |
/** |
|
220 |
* Return the data associated with this thread. |
|
221 |
* NOTE: This function assumes that the SetupThreadGraphicsInfo() |
|
222 |
* function has already been called for this situation (thread, |
|
223 |
* window, etc.), so we can assume that the thread info contains |
|
887 | 224 |
* a valid hDC. This should usually be the case since GDIWinSD_Setup |
2 | 225 |
* is called as part of the GetOps() process. |
226 |
*/ |
|
227 |
ThreadGraphicsInfo *GetThreadGraphicsInfo(JNIEnv *env, |
|
887 | 228 |
GDIWinSDOps *wsdo) { |
2 | 229 |
return (ThreadGraphicsInfo*)TlsGetValue(threadInfoIndex); |
230 |
} |
|
231 |
||
887 | 232 |
__inline HDC GetThreadDC(JNIEnv *env, GDIWinSDOps *wsdo) { |
2 | 233 |
ThreadGraphicsInfo *info = |
234 |
(ThreadGraphicsInfo *)GetThreadGraphicsInfo(env, wsdo); |
|
235 |
if (!info) { |
|
236 |
return (HDC) NULL; |
|
237 |
} |
|
238 |
return info->hDC; |
|
239 |
} |
|
240 |
||
241 |
} // extern "C" |
|
242 |
||
243 |
/** |
|
244 |
* This source file contains support code for loops using the |
|
245 |
* SurfaceData interface to talk to a Win32 drawable from native |
|
246 |
* code. |
|
247 |
*/ |
|
248 |
||
887 | 249 |
static BOOL GDIWinSD_CheckMonitorArea(GDIWinSDOps *wsdo, |
2 | 250 |
SurfaceDataBounds *bounds, |
251 |
HDC hDC) |
|
252 |
{ |
|
253 |
HWND hW = wsdo->window; |
|
254 |
BOOL retCode = TRUE; |
|
255 |
||
887 | 256 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_CheckMonitorArea"); |
2 | 257 |
int numScreens; |
258 |
{ |
|
259 |
Devices::InstanceAccess devices; |
|
260 |
numScreens = devices->GetNumDevices(); |
|
261 |
} |
|
262 |
if( numScreens > 1 ) { |
|
263 |
||
1954 | 264 |
LPMONITORINFO miInfo; |
2 | 265 |
RECT rSect ={0,0,0,0}; |
266 |
RECT rView ={bounds->x1, bounds->y1, bounds->x2, bounds->y2}; |
|
267 |
retCode = FALSE; |
|
268 |
||
269 |
miInfo = wsdo->device->GetMonitorInfo(); |
|
270 |
||
271 |
POINT ptOrig = {0, 0}; |
|
272 |
::ClientToScreen(hW, &ptOrig); |
|
273 |
::OffsetRect(&rView, |
|
274 |
(ptOrig.x), (ptOrig.y)); |
|
275 |
||
1954 | 276 |
::IntersectRect(&rSect,&rView,&(miInfo->rcMonitor)); |
2 | 277 |
|
278 |
if( FALSE == ::IsRectEmpty(&rSect) ) { |
|
279 |
if( TRUE == ::EqualRect(&rSect,&rView) ) { |
|
280 |
retCode = TRUE; |
|
281 |
} |
|
282 |
} |
|
283 |
} |
|
284 |
return retCode; |
|
285 |
} |
|
286 |
||
287 |
extern "C" { |
|
288 |
||
289 |
void |
|
290 |
initThreadInfoIndex() |
|
291 |
{ |
|
292 |
if (threadInfoIndex == TLS_OUT_OF_INDEXES) { |
|
293 |
threadInfoIndex = TlsAlloc(); |
|
294 |
} |
|
295 |
} |
|
296 |
||
887 | 297 |
|
298 |
/** |
|
299 |
* Utility function to make sure that native and java-level |
|
300 |
* surface depths are matched. They can be mismatched when display-depths |
|
301 |
* change, either between the creation of the Java surfaceData structure |
|
302 |
* and the native ddraw surface, or later when a surface is automatically |
|
303 |
* adjusted to be the new display depth (even if it was created in a different |
|
304 |
* depth to begin with) |
|
305 |
*/ |
|
306 |
BOOL SurfaceDepthsCompatible(int javaDepth, int nativeDepth) |
|
307 |
{ |
|
308 |
if (nativeDepth != javaDepth) { |
|
309 |
switch (nativeDepth) { |
|
310 |
case 0: // Error condition: something is wrong with the surface |
|
311 |
case 8: |
|
312 |
case 24: |
|
313 |
// Java and native surface depths should match exactly for |
|
314 |
// these cases |
|
315 |
return FALSE; |
|
316 |
break; |
|
317 |
case 16: |
|
318 |
// Java surfaceData should be 15 or 16 bits |
|
319 |
if (javaDepth < 15 || javaDepth > 16) { |
|
320 |
return FALSE; |
|
321 |
} |
|
322 |
break; |
|
323 |
case 32: |
|
324 |
// Could have this native depth for either 24- or 32-bit |
|
325 |
// Java surfaceData |
|
326 |
if (javaDepth != 24 && javaDepth != 32) { |
|
327 |
return FALSE; |
|
328 |
} |
|
329 |
break; |
|
330 |
default: |
|
331 |
// should not get here, but if we do something is odd, so |
|
332 |
// just register a failure |
|
333 |
return FALSE; |
|
334 |
} |
|
335 |
} |
|
336 |
return TRUE; |
|
337 |
} |
|
338 |
||
339 |
||
2 | 340 |
/* |
887 | 341 |
* Class: sun_java2d_windows_GDIWindowSurfaceData |
2 | 342 |
* Method: initIDs |
343 |
* Signature: ()V |
|
344 |
*/ |
|
345 |
JNIEXPORT void JNICALL |
|
887 | 346 |
Java_sun_java2d_windows_GDIWindowSurfaceData_initIDs(JNIEnv *env, jclass wsd, |
2 | 347 |
jclass XORComp) |
348 |
{ |
|
349 |
jclass tc; |
|
887 | 350 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWindowSurfaceData_initIDs"); |
2 | 351 |
nullbrush = (HBRUSH) ::GetStockObject(NULL_BRUSH); |
352 |
nullpen = (HPEN) ::GetStockObject(NULL_PEN); |
|
353 |
||
354 |
initThreadInfoIndex(); |
|
355 |
||
356 |
xorCompClass = (jclass)env->NewGlobalRef(XORComp); |
|
357 |
||
358 |
tc = env->FindClass("java/lang/Thread"); |
|
359 |
DASSERT(tc != NULL); |
|
360 |
threadClass = (jclass)env->NewGlobalRef(tc); |
|
361 |
DASSERT(threadClass != NULL); |
|
362 |
currentThreadMethodID = |
|
363 |
env->GetStaticMethodID(threadClass, |
|
364 |
"currentThread", "()Ljava/lang/Thread;"); |
|
365 |
DASSERT(currentThreadMethodID != NULL); |
|
366 |
} |
|
367 |
||
368 |
/* |
|
887 | 369 |
* Class: sun_java2d_windows_GDIWindowSurfaceData |
2 | 370 |
* Method: initOps |
371 |
* Signature: (Ljava/lang/Object;IIIIII)V |
|
372 |
*/ |
|
373 |
JNIEXPORT void JNICALL |
|
887 | 374 |
Java_sun_java2d_windows_GDIWindowSurfaceData_initOps(JNIEnv *env, jobject wsd, |
2 | 375 |
jobject peer, jint depth, |
376 |
jint redMask, jint greenMask, |
|
887 | 377 |
jint blueMask, jint screen) |
2 | 378 |
{ |
887 | 379 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWindowSurfaceData_initOps"); |
380 |
GDIWinSDOps *wsdo = (GDIWinSDOps *)SurfaceData_InitOps(env, wsd, sizeof(GDIWinSDOps)); |
|
5938
c93e51904f68
6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents:
5506
diff
changeset
|
381 |
if (wsdo == NULL) { |
c93e51904f68
6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents:
5506
diff
changeset
|
382 |
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed."); |
c93e51904f68
6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents:
5506
diff
changeset
|
383 |
return; |
c93e51904f68
6959998: Return of SurfaceData_InitOps point not checked in all cases (parfait found these)
igor
parents:
5506
diff
changeset
|
384 |
} |
7489
9136c8c7d74c
6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes
miroslawzn
parents:
5938
diff
changeset
|
385 |
wsdo->timeStamp = InterlockedIncrement(&timeStamp); //creation time stamp |
887 | 386 |
wsdo->sdOps.Lock = GDIWinSD_Lock; |
387 |
wsdo->sdOps.GetRasInfo = GDIWinSD_GetRasInfo; |
|
388 |
wsdo->sdOps.Unlock = GDIWinSD_Unlock; |
|
389 |
wsdo->sdOps.Dispose = GDIWinSD_Dispose; |
|
390 |
wsdo->sdOps.Setup = GDIWinSD_Setup; |
|
391 |
wsdo->GetDC = GDIWinSD_GetDC; |
|
392 |
wsdo->ReleaseDC = GDIWinSD_ReleaseDC; |
|
393 |
wsdo->InvalidateSD = GDIWinSD_InvalidateSD; |
|
2 | 394 |
wsdo->invalid = JNI_FALSE; |
395 |
wsdo->lockType = WIN32SD_LOCK_UNLOCKED; |
|
396 |
wsdo->peer = env->NewWeakGlobalRef(peer); |
|
397 |
wsdo->depth = depth; |
|
398 |
wsdo->pixelMasks[0] = redMask; |
|
399 |
wsdo->pixelMasks[1] = greenMask; |
|
400 |
wsdo->pixelMasks[2] = blueMask; |
|
401 |
// Init the DIB pixelStride and pixel masks according to |
|
402 |
// the pixel depth. In the 8-bit case, there are no |
|
403 |
// masks as a palette DIB is used instead. Likewise |
|
404 |
// in the 24-bit case, Windows doesn't expect the masks |
|
405 |
switch (depth) { |
|
406 |
case 8: |
|
407 |
wsdo->pixelStride = 1; |
|
408 |
break; |
|
409 |
case 15: //555 |
|
410 |
wsdo->pixelStride = 2; |
|
411 |
break; |
|
412 |
case 16: //565 |
|
413 |
wsdo->pixelStride = 2; |
|
414 |
break; |
|
415 |
case 24: |
|
416 |
wsdo->pixelStride = 3; |
|
417 |
break; |
|
418 |
case 32: //888 |
|
419 |
wsdo->pixelStride = 4; |
|
420 |
break; |
|
421 |
} |
|
887 | 422 |
// GDIWindowSurfaceData_GetWindow will throw NullPointerException |
2 | 423 |
// if wsdo->window is NULL |
887 | 424 |
wsdo->window = GDIWindowSurfaceData_GetWindow(env, wsdo); |
2 | 425 |
J2dTraceLn2(J2D_TRACE_VERBOSE, " wsdo=0x%x wsdo->window=0x%x", |
426 |
wsdo, wsdo->window); |
|
427 |
||
428 |
{ |
|
429 |
Devices::InstanceAccess devices; |
|
430 |
wsdo->device = devices->GetDeviceReference(screen, FALSE); |
|
431 |
} |
|
432 |
if (wsdo->device == NULL || |
|
887 | 433 |
!SurfaceDepthsCompatible(depth, wsdo->device->GetBitDepth())) |
2 | 434 |
{ |
435 |
if (wsdo->device != NULL) { |
|
436 |
J2dTraceLn2(J2D_TRACE_WARNING, |
|
887 | 437 |
"GDIWindowSurfaceData_initOps: Surface depth mismatch: "\ |
2 | 438 |
"wsdo->depth=%d device depth=%d. Surface invalidated.", |
439 |
wsdo->depth, wsdo->device->GetBitDepth()); |
|
440 |
} else { |
|
441 |
J2dTraceLn1(J2D_TRACE_WARNING, |
|
887 | 442 |
"GDIWindowSurfaceData_initOps: Incorrect "\ |
2 | 443 |
"screen number (screen=%d). Surface invalidated.", |
444 |
screen); |
|
445 |
} |
|
446 |
||
447 |
wsdo->invalid = JNI_TRUE; |
|
448 |
} |
|
449 |
wsdo->surfaceLock = new CriticalSection(); |
|
450 |
wsdo->bitmap = NULL; |
|
451 |
wsdo->bmdc = NULL; |
|
452 |
wsdo->bmCopyToScreen = FALSE; |
|
453 |
} |
|
454 |
||
887 | 455 |
JNIEXPORT GDIWinSDOps * JNICALL |
456 |
GDIWindowSurfaceData_GetOps(JNIEnv *env, jobject sData) |
|
2 | 457 |
{ |
458 |
SurfaceDataOps *ops = SurfaceData_GetOps(env, sData); |
|
459 |
// REMIND: There was originally a condition check here to make sure |
|
887 | 460 |
// that we were really dealing with a GDIWindowSurfaceData object, but |
2 | 461 |
// it did not allow for the existence of other win32-accelerated |
462 |
// surface data objects (e.g., Win32OffScreenSurfaceData). I've |
|
463 |
// removed the check for now, but we should replace it with another, |
|
464 |
// more general check against Win32-related surfaces. |
|
887 | 465 |
return (GDIWinSDOps *) ops; |
2 | 466 |
} |
467 |
||
887 | 468 |
JNIEXPORT GDIWinSDOps * JNICALL |
469 |
GDIWindowSurfaceData_GetOpsNoSetup(JNIEnv *env, jobject sData) |
|
2 | 470 |
{ |
471 |
// use the 'no setup' version of GetOps |
|
472 |
SurfaceDataOps *ops = SurfaceData_GetOpsNoSetup(env, sData); |
|
887 | 473 |
return (GDIWinSDOps *) ops; |
2 | 474 |
} |
475 |
||
476 |
JNIEXPORT AwtComponent * JNICALL |
|
887 | 477 |
GDIWindowSurfaceData_GetComp(JNIEnv *env, GDIWinSDOps *wsdo) |
2 | 478 |
{ |
479 |
PDATA pData; |
|
480 |
jobject localObj = env->NewLocalRef(wsdo->peer); |
|
481 |
||
482 |
if (localObj == NULL || (pData = JNI_GET_PDATA(localObj)) == NULL) { |
|
483 |
J2dTraceLn1(J2D_TRACE_WARNING, |
|
887 | 484 |
"GDIWindowSurfaceData_GetComp: Null pData? pData=0x%x", |
2 | 485 |
pData); |
486 |
if (beingShutdown == JNI_TRUE) { |
|
487 |
wsdo->invalid = JNI_TRUE; |
|
488 |
return (AwtComponent *) NULL; |
|
489 |
} |
|
490 |
try { |
|
491 |
AwtToolkit::GetInstance().VerifyActive(); |
|
492 |
} catch (awt_toolkit_shutdown&) { |
|
493 |
beingShutdown = JNI_TRUE; |
|
494 |
wsdo->invalid = JNI_TRUE; |
|
495 |
return (AwtComponent *) NULL; |
|
496 |
} |
|
497 |
if (wsdo->invalid == JNI_TRUE) { |
|
498 |
SurfaceData_ThrowInvalidPipeException(env, |
|
887 | 499 |
"GDIWindowSurfaceData: bounds changed"); |
2 | 500 |
} else { |
501 |
JNU_ThrowNullPointerException(env, "component argument pData"); |
|
502 |
} |
|
503 |
return (AwtComponent *) NULL; |
|
504 |
} |
|
505 |
return static_cast<AwtComponent*>(pData); |
|
506 |
} |
|
507 |
||
508 |
JNIEXPORT HWND JNICALL |
|
887 | 509 |
GDIWindowSurfaceData_GetWindow(JNIEnv *env, GDIWinSDOps *wsdo) |
2 | 510 |
{ |
511 |
HWND window = wsdo->window; |
|
512 |
||
513 |
if (window == (HWND) NULL) { |
|
887 | 514 |
AwtComponent *comp = GDIWindowSurfaceData_GetComp(env, wsdo); |
2 | 515 |
if (comp == NULL) { |
516 |
J2dTraceLn(J2D_TRACE_WARNING, |
|
887 | 517 |
"GDIWindowSurfaceData_GetWindow: null component"); |
2 | 518 |
return (HWND) NULL; |
519 |
} |
|
520 |
comp->GetInsets(&wsdo->insets); |
|
521 |
window = comp->GetHWnd(); |
|
522 |
if (::IsWindow(window) == FALSE) { |
|
523 |
J2dRlsTraceLn(J2D_TRACE_ERROR, |
|
887 | 524 |
"GDIWindowSurfaceData_GetWindow: disposed component"); |
2 | 525 |
JNU_ThrowNullPointerException(env, "disposed component"); |
526 |
return (HWND) NULL; |
|
527 |
} |
|
528 |
wsdo->window = window; |
|
529 |
} |
|
530 |
||
531 |
return window; |
|
532 |
} |
|
533 |
||
534 |
} /* extern "C" */ |
|
535 |
||
887 | 536 |
static jboolean GDIWinSD_SimpleClip(JNIEnv *env, GDIWinSDOps *wsdo, |
2 | 537 |
SurfaceDataBounds *bounds, |
538 |
HDC hDC) |
|
539 |
{ |
|
540 |
RECT rClip; |
|
541 |
||
887 | 542 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_SimpleClip"); |
2 | 543 |
if (hDC == NULL) { |
544 |
return JNI_FALSE; |
|
545 |
} |
|
546 |
||
547 |
int nComplexity = ::GetClipBox(hDC, &rClip); |
|
548 |
||
549 |
switch (nComplexity) { |
|
550 |
case COMPLEXREGION: |
|
551 |
{ |
|
552 |
J2dTraceLn(J2D_TRACE_VERBOSE, |
|
553 |
" complex clipping region"); |
|
554 |
// if complex user/system clip, more detailed testing required |
|
555 |
// check to see if the view itself has a complex clip. |
|
556 |
// ::GetClipBox is only API which returns overlapped window status |
|
557 |
// so we set the rView as our clip, and then see if resulting |
|
558 |
// clip is complex. |
|
559 |
// Only other way to figure this out would be to walk the |
|
560 |
// overlapping windows (no API to get the actual visible clip |
|
561 |
// list). Then we'd still have to merge that info with the |
|
562 |
// clip region for the dc (if it exists). |
|
563 |
// REMIND: we can cache the CreateRectRgnIndirect result, |
|
564 |
// and only override with ::SetRectRgn |
|
565 |
||
566 |
// First, create a region handle (need existing HRGN for |
|
567 |
// the following call). |
|
568 |
HRGN rgnSave = ::CreateRectRgn(0, 0, 0, 0); |
|
569 |
int clipStatus = ::GetClipRgn(hDC, rgnSave); |
|
570 |
if (-1 == clipStatus) { |
|
571 |
J2dTraceLn(J2D_TRACE_WARNING, |
|
887 | 572 |
"GDIWinSD_SimpleClip: failed due to clip status"); |
2 | 573 |
::DeleteObject(rgnSave); |
574 |
return JNI_FALSE; |
|
575 |
} |
|
576 |
HRGN rgnBounds = ::CreateRectRgn( |
|
577 |
bounds->x1 - wsdo->insets.left, |
|
578 |
bounds->y1 - wsdo->insets.top, |
|
579 |
bounds->x2 - wsdo->insets.left, |
|
580 |
bounds->y2 - wsdo->insets.top); |
|
581 |
::SelectClipRgn(hDC, rgnBounds); |
|
582 |
nComplexity = ::GetClipBox(hDC, &rClip); |
|
583 |
::SelectClipRgn(hDC, clipStatus? rgnSave: NULL); |
|
584 |
::DeleteObject(rgnSave); |
|
585 |
::DeleteObject(rgnBounds); |
|
586 |
||
587 |
// Now, test the new clip box. If it's still not a |
|
588 |
// SIMPLE region, then our bounds must intersect part of |
|
589 |
// the clipping article |
|
590 |
if (SIMPLEREGION != nComplexity) { |
|
591 |
J2dTraceLn(J2D_TRACE_WARNING, |
|
887 | 592 |
"GDIWinSD_SimpleClip: failed due to complexity"); |
2 | 593 |
return JNI_FALSE; |
594 |
} |
|
595 |
} |
|
596 |
// NOTE: No break here - we want to fall through into the |
|
597 |
// SIMPLE case, adjust our bounds by the new rClip rect |
|
598 |
// and make sure that our locking bounds are not empty. |
|
599 |
case SIMPLEREGION: |
|
600 |
J2dTraceLn(J2D_TRACE_VERBOSE, " simple clipping region"); |
|
601 |
// Constrain the bounds to the given clip box |
|
602 |
if (bounds->x1 < rClip.left) { |
|
603 |
bounds->x1 = rClip.left; |
|
604 |
} |
|
605 |
if (bounds->y1 < rClip.top) { |
|
606 |
bounds->y1 = rClip.top; |
|
607 |
} |
|
608 |
if (bounds->x2 > rClip.right) { |
|
609 |
bounds->x2 = rClip.right; |
|
610 |
} |
|
611 |
if (bounds->y2 > rClip.bottom) { |
|
612 |
bounds->y2 = rClip.bottom; |
|
613 |
} |
|
614 |
// If the bounds are 0 or negative, then the bounds have |
|
615 |
// been obscured by the clip box, so return FALSE |
|
616 |
if ((bounds->x2 <= bounds->x1) || |
|
617 |
(bounds->y2 <= bounds->y1)) { |
|
618 |
// REMIND: We should probably do something different here |
|
619 |
// instead of simply returning FALSE. Since the bounds are |
|
620 |
// empty we won't end up drawing anything, so why spend the |
|
621 |
// effort of returning false and having GDI do a LOCK_BY_DIB? |
|
622 |
// Perhaps we need a new lock code that will indicate that we |
|
623 |
// shouldn't bother drawing? |
|
624 |
J2dTraceLn(J2D_TRACE_WARNING, |
|
887 | 625 |
"GDIWinSD_SimpleClip: failed due to empty bounds"); |
2 | 626 |
return JNI_FALSE; |
627 |
} |
|
628 |
break; |
|
629 |
case NULLREGION: |
|
630 |
case ERROR: |
|
631 |
default: |
|
632 |
J2dTraceLn1(J2D_TRACE_ERROR, |
|
887 | 633 |
"GDIWinSD_SimpleClip: failed due to incorrect complexity=%d", |
2 | 634 |
nComplexity); |
635 |
return JNI_FALSE; |
|
636 |
} |
|
637 |
||
638 |
return JNI_TRUE; |
|
639 |
} |
|
640 |
||
887 | 641 |
static jint GDIWinSD_Lock(JNIEnv *env, |
2 | 642 |
SurfaceDataOps *ops, |
643 |
SurfaceDataRasInfo *pRasInfo, |
|
644 |
jint lockflags) |
|
645 |
{ |
|
887 | 646 |
GDIWinSDOps *wsdo = (GDIWinSDOps *) ops; |
2 | 647 |
int ret = SD_SUCCESS; |
648 |
HDC hDC; |
|
887 | 649 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_Lock"); |
2 | 650 |
|
651 |
/* This surfaceLock replaces an earlier implementation which used a |
|
652 |
monitor associated with the peer. That implementation was prone |
|
653 |
to deadlock problems, so it was replaced by a lock that does not |
|
654 |
have dependencies outside of this thread or object. |
|
655 |
However, this lock doesn't necessarily do all that we want. |
|
656 |
For example, a user may issue a call which results in a DIB lock |
|
657 |
and another call which results in a DDraw Blt. We can't guarantee |
|
658 |
what order these operations happen in (they are driver and |
|
659 |
video-card dependent), so locking around the issue of either of |
|
660 |
those calls won't necessarily guarantee a particular result. |
|
661 |
The real solution might be to move away from mixing our |
|
662 |
rendering API's. That is, if we only used DDraw, then we could |
|
663 |
guarantee that all rendering operations would happen in a given |
|
664 |
order. Similarly for GDI. But by mixing them, we leave our |
|
665 |
code at the mercy of driver bugs.*/ |
|
666 |
wsdo->surfaceLock->Enter(); |
|
667 |
if (wsdo->invalid == JNI_TRUE) { |
|
887 | 668 |
J2dTraceLn(J2D_TRACE_WARNING, "GDIWinSD_Lock: surface is invalid"); |
2 | 669 |
wsdo->surfaceLock->Leave(); |
670 |
if (beingShutdown != JNI_TRUE) { |
|
671 |
SurfaceData_ThrowInvalidPipeException(env, |
|
887 | 672 |
"GDIWindowSurfaceData: bounds changed"); |
2 | 673 |
} |
674 |
return SD_FAILURE; |
|
675 |
} |
|
676 |
if (wsdo->lockType != WIN32SD_LOCK_UNLOCKED) { |
|
677 |
wsdo->surfaceLock->Leave(); |
|
678 |
if (!safe_ExceptionOccurred(env)) { |
|
679 |
JNU_ThrowInternalError(env, "Win32 LockRasData cannot nest locks"); |
|
680 |
} |
|
681 |
return SD_FAILURE; |
|
682 |
} |
|
683 |
||
684 |
hDC = wsdo->GetDC(env, wsdo, 0, NULL, NULL, NULL, 0); |
|
685 |
if (hDC == NULL) { |
|
686 |
wsdo->surfaceLock->Leave(); |
|
687 |
if (beingShutdown != JNI_TRUE) { |
|
688 |
JNU_ThrowNullPointerException(env, "HDC for component"); |
|
689 |
} |
|
690 |
return SD_FAILURE; |
|
691 |
} |
|
692 |
||
693 |
if (lockflags & SD_LOCK_RD_WR) { |
|
694 |
// Do an initial clip to the client region of the window |
|
695 |
RECT crect; |
|
696 |
::GetClientRect(wsdo->window, &crect); |
|
697 |
||
698 |
// Translate to window coords |
|
699 |
crect.left += wsdo->insets.left; |
|
700 |
crect.top += wsdo->insets.top; |
|
701 |
crect.right += wsdo->insets.left; |
|
702 |
crect.bottom += wsdo->insets.top; |
|
703 |
||
704 |
SurfaceDataBounds *bounds = &pRasInfo->bounds; |
|
705 |
||
706 |
if (bounds->x1 < crect.left) { |
|
707 |
bounds->x1 = crect.left; |
|
708 |
} |
|
709 |
if (bounds->y1 < crect.top) { |
|
710 |
bounds->y1 = crect.top; |
|
711 |
} |
|
712 |
if (bounds->x2 > crect.right) { |
|
713 |
bounds->x2 = crect.right; |
|
714 |
} |
|
715 |
if (bounds->y2 > crect.bottom) { |
|
716 |
bounds->y2 = crect.bottom; |
|
717 |
} |
|
718 |
||
887 | 719 |
if (bounds->x2 > bounds->x1 && bounds->y2 > bounds->y1) { |
720 |
wsdo->lockType = WIN32SD_LOCK_BY_DIB; |
|
721 |
if (lockflags & SD_LOCK_FASTEST) { |
|
722 |
ret = SD_SLOWLOCK; |
|
2 | 723 |
} |
887 | 724 |
J2dTraceLn(J2D_TRACE_VERBOSE, " locked by DIB"); |
2 | 725 |
} else { |
726 |
wsdo->ReleaseDC(env, wsdo, hDC); |
|
887 | 727 |
wsdo->lockType = WIN32SD_LOCK_UNLOCKED; |
728 |
wsdo->surfaceLock->Leave(); |
|
729 |
ret = SD_FAILURE; |
|
730 |
J2dTraceLn(J2D_TRACE_ERROR, |
|
731 |
"GDIWinSD_Lock: error locking by DIB"); |
|
2 | 732 |
} |
733 |
} else { |
|
887 | 734 |
J2dTraceLn(J2D_TRACE_VERBOSE, "GDIWinSD_Lock: surface wasn't locked"); |
2 | 735 |
/* They didn't lock for anything - we won't give them anything */ |
736 |
wsdo->ReleaseDC(env, wsdo, hDC); |
|
737 |
wsdo->lockType = WIN32SD_LOCK_UNLOCKED; |
|
738 |
wsdo->surfaceLock->Leave(); |
|
739 |
ret = SD_FAILURE; |
|
740 |
} |
|
741 |
||
742 |
wsdo->lockFlags = lockflags; |
|
743 |
return ret; |
|
744 |
} |
|
745 |
||
887 | 746 |
static void GDIWinSD_GetRasInfo(JNIEnv *env, |
2 | 747 |
SurfaceDataOps *ops, |
748 |
SurfaceDataRasInfo *pRasInfo) |
|
749 |
{ |
|
887 | 750 |
GDIWinSDOps *wsdo = (GDIWinSDOps *) ops; |
2 | 751 |
jint lockflags = wsdo->lockFlags; |
887 | 752 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_GetRasInfo"); |
2 | 753 |
HDC hDC = GetThreadDC(env, wsdo); |
754 |
||
755 |
if (wsdo->lockType == WIN32SD_LOCK_UNLOCKED) { |
|
756 |
memset(pRasInfo, 0, sizeof(*pRasInfo)); |
|
757 |
return; |
|
758 |
} |
|
759 |
||
887 | 760 |
if (wsdo->lockType == WIN32SD_LOCK_BY_DIB) { |
2 | 761 |
int x, y, w, h; |
762 |
int pixelStride = wsdo->pixelStride; |
|
763 |
// do not subtract insets from x,y as we take care of it in SD_GetDC |
|
764 |
x = pRasInfo->bounds.x1; |
|
765 |
y = pRasInfo->bounds.y1; |
|
766 |
w = pRasInfo->bounds.x2 - x; |
|
767 |
h = pRasInfo->bounds.y2 - y; |
|
768 |
||
769 |
struct tagBitmapheader { |
|
770 |
BITMAPINFOHEADER bmiHeader; |
|
771 |
union { |
|
772 |
DWORD dwMasks[3]; |
|
773 |
RGBQUAD palette[256]; |
|
774 |
} colors; |
|
775 |
} bmi; |
|
776 |
||
777 |
// Need to create bitmap if we don't have one already or |
|
778 |
// if the existing one is not large enough for this operation |
|
779 |
// or if we are in 8 bpp display mode (because we need to |
|
780 |
// make sure that the latest palette info gets loaded into |
|
781 |
// the bitmap) |
|
782 |
// REMIND: we should find some way to dynamically force bitmap |
|
783 |
// recreation only when the palette changes |
|
784 |
if (pixelStride == 1 || !wsdo->bitmap || (w > wsdo->bmWidth) || |
|
785 |
(h > wsdo->bmHeight)) |
|
786 |
{ |
|
787 |
if (wsdo->bitmap) { |
|
788 |
// delete old objects |
|
789 |
J2dTraceLn(J2D_TRACE_VERBOSE, |
|
887 | 790 |
"GDIWinSD_GetRasInfo: recreating GDI bitmap"); |
2 | 791 |
if (wsdo->bmdc) { // should not be null |
792 |
::SelectObject(wsdo->bmdc, wsdo->oldmap); |
|
793 |
::DeleteDC(wsdo->bmdc); |
|
794 |
wsdo->bmdc = 0; |
|
795 |
} |
|
796 |
::DeleteObject(wsdo->bitmap); |
|
797 |
wsdo->bitmap = 0; |
|
798 |
} |
|
799 |
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); |
|
800 |
bmi.bmiHeader.biWidth = w; |
|
801 |
bmi.bmiHeader.biHeight = -h; |
|
802 |
wsdo->bmWidth = w; |
|
803 |
wsdo->bmHeight = h; |
|
804 |
bmi.bmiHeader.biPlanes = 1; |
|
805 |
bmi.bmiHeader.biBitCount = pixelStride * 8; |
|
806 |
// 1,3 byte use BI_RGB, 2,4 byte use BI_BITFIELD... |
|
807 |
bmi.bmiHeader.biCompression = |
|
808 |
(pixelStride & 1) |
|
809 |
? BI_RGB |
|
810 |
: BI_BITFIELDS; |
|
811 |
bmi.bmiHeader.biSizeImage = 0; |
|
812 |
bmi.bmiHeader.biXPelsPerMeter = 0; |
|
813 |
bmi.bmiHeader.biYPelsPerMeter = 0; |
|
814 |
bmi.bmiHeader.biClrUsed = 0; |
|
815 |
bmi.bmiHeader.biClrImportant = 0; |
|
816 |
if (pixelStride == 1) { |
|
817 |
// we can use systemEntries here because |
|
818 |
// RGBQUAD is xRGB and systemEntries are stored as xRGB |
|
819 |
memcpy(bmi.colors.palette, wsdo->device->GetSystemPaletteEntries(), |
|
820 |
sizeof(bmi.colors.palette)); |
|
821 |
} else { |
|
822 |
// For non-index cases, init the masks for the pixel depth |
|
823 |
for (int i = 0; i < 3; i++) { |
|
824 |
bmi.colors.dwMasks[i] = wsdo->pixelMasks[i]; |
|
825 |
} |
|
826 |
} |
|
827 |
||
828 |
// REMIND: This would be better if moved to the Lock function |
|
829 |
// so that errors could be dealt with. |
|
830 |
wsdo->bitmap = ::CreateDIBSection(hDC, (BITMAPINFO *) &bmi, |
|
831 |
DIB_RGB_COLORS, &wsdo->bmBuffer, NULL, 0); |
|
832 |
if (wsdo->bitmap != 0) { |
|
833 |
// scanStride is cached along with reuseable bitmap |
|
834 |
// Round up to the next DWORD boundary |
|
835 |
wsdo->bmScanStride = (wsdo->bmWidth * pixelStride + 3) & ~3; |
|
836 |
wsdo->bmdc = ::CreateCompatibleDC(hDC); |
|
837 |
if (wsdo->bmdc == 0) { |
|
838 |
::DeleteObject(wsdo->bitmap); |
|
839 |
wsdo->bitmap = 0; |
|
840 |
} else { |
|
841 |
wsdo->oldmap = (HBITMAP) ::SelectObject(wsdo->bmdc, |
|
842 |
wsdo->bitmap); |
|
843 |
} |
|
844 |
} |
|
845 |
} |
|
846 |
if (wsdo->bitmap != 0) { |
|
847 |
if (lockflags & SD_LOCK_NEED_PIXELS) { |
|
848 |
int ret = ::BitBlt(wsdo->bmdc, 0, 0, w, h, |
|
849 |
hDC, x, y, SRCCOPY); |
|
850 |
::GdiFlush(); |
|
851 |
} |
|
852 |
wsdo->x = x; |
|
853 |
wsdo->y = y; |
|
854 |
wsdo->w = w; |
|
855 |
wsdo->h = h; |
|
856 |
pRasInfo->rasBase = (char *)wsdo->bmBuffer - (x*pixelStride + |
|
857 |
y*wsdo->bmScanStride); |
|
858 |
pRasInfo->pixelStride = pixelStride; |
|
859 |
pRasInfo->pixelBitOffset = 0; |
|
860 |
pRasInfo->scanStride = wsdo->bmScanStride; |
|
861 |
if (lockflags & SD_LOCK_WRITE) { |
|
862 |
// If the user writes to the bitmap then we should |
|
863 |
// copy the bitmap to the screen during Unlock |
|
864 |
wsdo->bmCopyToScreen = TRUE; |
|
865 |
} |
|
866 |
} else { |
|
867 |
pRasInfo->rasBase = NULL; |
|
868 |
pRasInfo->pixelStride = 0; |
|
869 |
pRasInfo->pixelBitOffset = 0; |
|
870 |
pRasInfo->scanStride = 0; |
|
871 |
} |
|
872 |
} else { |
|
873 |
/* They didn't lock for anything - we won't give them anything */ |
|
874 |
pRasInfo->rasBase = NULL; |
|
875 |
pRasInfo->pixelStride = 0; |
|
876 |
pRasInfo->pixelBitOffset = 0; |
|
877 |
pRasInfo->scanStride = 0; |
|
878 |
} |
|
879 |
if (wsdo->lockFlags & SD_LOCK_LUT) { |
|
880 |
pRasInfo->lutBase = |
|
881 |
(long *) wsdo->device->GetSystemPaletteEntries(); |
|
882 |
pRasInfo->lutSize = 256; |
|
883 |
} else { |
|
884 |
pRasInfo->lutBase = NULL; |
|
885 |
pRasInfo->lutSize = 0; |
|
886 |
} |
|
887 |
if (wsdo->lockFlags & SD_LOCK_INVCOLOR) { |
|
888 |
pRasInfo->invColorTable = wsdo->device->GetSystemInverseLUT(); |
|
889 |
ColorData *cData = wsdo->device->GetColorData(); |
|
890 |
pRasInfo->redErrTable = cData->img_oda_red; |
|
891 |
pRasInfo->grnErrTable = cData->img_oda_green; |
|
892 |
pRasInfo->bluErrTable = cData->img_oda_blue; |
|
893 |
} else { |
|
894 |
pRasInfo->invColorTable = NULL; |
|
895 |
pRasInfo->redErrTable = NULL; |
|
896 |
pRasInfo->grnErrTable = NULL; |
|
897 |
pRasInfo->bluErrTable = NULL; |
|
898 |
} |
|
899 |
if (wsdo->lockFlags & SD_LOCK_INVGRAY) { |
|
900 |
pRasInfo->invGrayTable = |
|
901 |
wsdo->device->GetColorData()->pGrayInverseLutData; |
|
902 |
} else { |
|
903 |
pRasInfo->invGrayTable = NULL; |
|
904 |
} |
|
905 |
} |
|
906 |
||
887 | 907 |
static void GDIWinSD_Setup(JNIEnv *env, |
2 | 908 |
SurfaceDataOps *ops) |
909 |
{ |
|
910 |
// Call SetupTGI to ensure that this thread already has a DC that is |
|
911 |
// compatible with this window. This means that we won't be calling |
|
912 |
// ::SendMessage(GETDC) in the middle of a lock procedure, which creates |
|
913 |
// a potential deadlock situation. |
|
914 |
// Note that calling SetupTGI here means that anybody needing a DC |
|
915 |
// later in this rendering process need only call GetTGI, which |
|
916 |
// assumes that the TGI structure is valid for this thread/window. |
|
887 | 917 |
SetupThreadGraphicsInfo(env, (GDIWinSDOps*)ops); |
2 | 918 |
} |
919 |
||
920 |
||
887 | 921 |
static void GDIWinSD_Unlock(JNIEnv *env, |
2 | 922 |
SurfaceDataOps *ops, |
923 |
SurfaceDataRasInfo *pRasInfo) |
|
924 |
{ |
|
887 | 925 |
GDIWinSDOps *wsdo = (GDIWinSDOps *) ops; |
926 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_Unlock"); |
|
2 | 927 |
HDC hDC = GetThreadDC(env, wsdo); |
928 |
||
929 |
if (wsdo->lockType == WIN32SD_LOCK_UNLOCKED) { |
|
930 |
if (!safe_ExceptionOccurred(env)) { |
|
931 |
JNU_ThrowInternalError(env, |
|
932 |
"Unmatched unlock on Win32 SurfaceData"); |
|
933 |
} |
|
934 |
return; |
|
935 |
} |
|
936 |
||
887 | 937 |
if (wsdo->lockType == WIN32SD_LOCK_BY_DIB) { |
2 | 938 |
if (wsdo->lockFlags & SD_LOCK_WRITE) { |
939 |
J2dTraceLn(J2D_TRACE_VERBOSE, |
|
887 | 940 |
"GDIWinSD_Unlock: do Blt of the bitmap"); |
2 | 941 |
if (wsdo->bmCopyToScreen && ::IsWindowVisible(wsdo->window)) { |
942 |
// Don't bother copying to screen if our window has gone away |
|
943 |
// or if the bitmap was not actually written to during this |
|
944 |
// Lock/Unlock procedure. |
|
945 |
::BitBlt(hDC, wsdo->x, wsdo->y, wsdo->w, wsdo->h, |
|
946 |
wsdo->bmdc, 0, 0, SRCCOPY); |
|
947 |
::GdiFlush(); |
|
948 |
} |
|
949 |
wsdo->bmCopyToScreen = FALSE; |
|
950 |
} |
|
951 |
wsdo->lockType = WIN32SD_LOCK_UNLOCKED; |
|
952 |
wsdo->ReleaseDC(env, wsdo, hDC); |
|
953 |
} |
|
954 |
wsdo->surfaceLock->Leave(); |
|
955 |
} |
|
956 |
||
957 |
/* |
|
958 |
* REMIND: This mechanism is just a prototype of a way to manage a |
|
959 |
* small cache of DC objects. It is incomplete in the following ways: |
|
960 |
* |
|
961 |
* - It is not thread-safe! It needs appropriate locking and release calls |
|
962 |
* (perhaps the AutoDC mechanisms from Kestrel) |
|
963 |
* - It does hardly any error checking (What if GetDCEx returns NULL?) |
|
964 |
* - It cannot handle printer DCs and their resolution |
|
965 |
* - It should probably "live" in the native SurfaceData object to allow |
|
966 |
* alternate implementations for printing and embedding |
|
967 |
* - It doesn't handle XOR |
|
968 |
* - It caches the client bounds to determine if clipping is really needed |
|
969 |
* (no way to invalidate the cached bounds and there is probably a better |
|
970 |
* way to manage clip validation in any case) |
|
971 |
*/ |
|
972 |
||
973 |
#define COLORFOR(c) (PALETTERGB(((c)>>16)&0xff,((c)>>8)&0xff,((c)&0xff))) |
|
974 |
||
887 | 975 |
COLORREF CheckGrayColor(GDIWinSDOps *wsdo, int c) { |
2 | 976 |
if (wsdo->device->GetGrayness() != GS_NOTGRAY) { |
977 |
int g = (77 *(c & 0xFF) + |
|
978 |
150*((c >> 8) & 0xFF) + |
|
979 |
29 *((c >> 16) & 0xFF) + 128) / 256; |
|
980 |
c = g | (g << 8) | (g << 16); |
|
981 |
} |
|
982 |
return COLORFOR(c); |
|
983 |
} |
|
984 |
||
887 | 985 |
static HDC GDIWinSD_GetDC(JNIEnv *env, GDIWinSDOps *wsdo, |
2 | 986 |
jint type, jint *patrop, |
987 |
jobject clip, jobject comp, jint color) |
|
988 |
{ |
|
887 | 989 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_GetDC"); |
2 | 990 |
|
991 |
if (wsdo->invalid == JNI_TRUE) { |
|
992 |
if (beingShutdown != JNI_TRUE) { |
|
993 |
SurfaceData_ThrowInvalidPipeException(env, "bounds changed"); |
|
994 |
} |
|
995 |
return (HDC) NULL; |
|
996 |
} |
|
997 |
||
998 |
ThreadGraphicsInfo *info = GetThreadGraphicsInfo(env, wsdo); |
|
887 | 999 |
GDIWinSD_InitDC(env, wsdo, info, type, patrop, clip, comp, color); |
2 | 1000 |
return info->hDC; |
1001 |
} |
|
1002 |
||
1003 |
JNIEXPORT void JNICALL |
|
887 | 1004 |
GDIWinSD_InitDC(JNIEnv *env, GDIWinSDOps *wsdo, ThreadGraphicsInfo *info, |
2 | 1005 |
jint type, jint *patrop, |
1006 |
jobject clip, jobject comp, jint color) |
|
1007 |
{ |
|
887 | 1008 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_InitDC"); |
2 | 1009 |
|
1010 |
// init clip |
|
1011 |
if (clip == NULL) { |
|
1012 |
if (info->type & CLIP) { |
|
1013 |
::SelectClipRgn(info->hDC, (HRGN) NULL); |
|
1014 |
info->type ^= CLIP; |
|
1015 |
} |
|
1016 |
if (info->clip != NULL) { |
|
1017 |
env->DeleteWeakGlobalRef(info->clip); |
|
1018 |
info->clip = NULL; |
|
1019 |
} |
|
1020 |
} else if (!env->IsSameObject(clip, info->clip)) { |
|
1021 |
SurfaceDataBounds span; |
|
1022 |
RegionData clipInfo; |
|
1023 |
if (Region_GetInfo(env, clip, &clipInfo)) { |
|
1024 |
// return; // REMIND: What to do here? |
|
1025 |
} |
|
1026 |
||
1027 |
if (Region_IsEmpty(&clipInfo)) { |
|
1028 |
HRGN hrgn = ::CreateRectRgn(0, 0, 0, 0); |
|
1029 |
::SelectClipRgn(info->hDC, hrgn); |
|
1030 |
::DeleteObject(hrgn); |
|
1031 |
info->type |= CLIP; |
|
1032 |
} else if (Region_IsRectangular(&clipInfo)) { |
|
1033 |
if (clipInfo.bounds.x1 <= info->bounds.left && |
|
1034 |
clipInfo.bounds.y1 <= info->bounds.top && |
|
1035 |
clipInfo.bounds.x2 >= info->bounds.right && |
|
1036 |
clipInfo.bounds.y2 >= info->bounds.bottom) |
|
1037 |
{ |
|
1038 |
if (info->type & CLIP) { |
|
1039 |
::SelectClipRgn(info->hDC, (HRGN) NULL); |
|
1040 |
info->type ^= CLIP; |
|
1041 |
} |
|
1042 |
} else { |
|
1043 |
// Make the window-relative rect a client-relative |
|
1044 |
// one for Windows |
|
1045 |
HRGN hrgn = |
|
1046 |
::CreateRectRgn(clipInfo.bounds.x1 - wsdo->insets.left, |
|
1047 |
clipInfo.bounds.y1 - wsdo->insets.top, |
|
1048 |
clipInfo.bounds.x2 - wsdo->insets.left, |
|
1049 |
clipInfo.bounds.y2 - wsdo->insets.top); |
|
1050 |
::SelectClipRgn(info->hDC, hrgn); |
|
1051 |
::DeleteObject(hrgn); |
|
1052 |
info->type |= CLIP; |
|
1053 |
} |
|
1054 |
} else { |
|
1055 |
int leftInset = wsdo->insets.left; |
|
1056 |
int topInset = wsdo->insets.top; |
|
1057 |
Region_StartIteration(env, &clipInfo); |
|
1058 |
jint numrects = Region_CountIterationRects(&clipInfo); |
|
1059 |
DWORD nCount = sizeof(RGNDATAHEADER) + numrects * sizeof(RECT); |
|
1060 |
RGNDATA *lpRgnData = (RGNDATA *) safe_Malloc(nCount); |
|
1061 |
lpRgnData->rdh.dwSize = sizeof(RGNDATAHEADER); |
|
1062 |
lpRgnData->rdh.iType = RDH_RECTANGLES; |
|
1063 |
lpRgnData->rdh.nCount = numrects; |
|
1064 |
lpRgnData->rdh.nRgnSize = 0; |
|
1065 |
lpRgnData->rdh.rcBound.left = clipInfo.bounds.x1 - leftInset; |
|
1066 |
lpRgnData->rdh.rcBound.top = clipInfo.bounds.y1 - topInset; |
|
1067 |
lpRgnData->rdh.rcBound.right = clipInfo.bounds.x2 - leftInset; |
|
1068 |
lpRgnData->rdh.rcBound.bottom = clipInfo.bounds.y2 - topInset; |
|
1069 |
RECT *pRect = (RECT *) &(((RGNDATA *)lpRgnData)->Buffer); |
|
1070 |
while (Region_NextIteration(&clipInfo, &span)) { |
|
1071 |
pRect->left = span.x1 - leftInset; |
|
1072 |
pRect->top = span.y1 - topInset; |
|
1073 |
pRect->right = span.x2 - leftInset; |
|
1074 |
pRect->bottom = span.y2 - topInset; |
|
1075 |
pRect++; |
|
1076 |
} |
|
1077 |
Region_EndIteration(env, &clipInfo); |
|
1078 |
HRGN hrgn = ::ExtCreateRegion(NULL, nCount, lpRgnData); |
|
1079 |
free(lpRgnData); |
|
1080 |
::SelectClipRgn(info->hDC, hrgn); |
|
1081 |
::DeleteObject(hrgn); |
|
1082 |
info->type |= CLIP; |
|
1083 |
} |
|
1084 |
if (info->clip != NULL) { |
|
1085 |
env->DeleteWeakGlobalRef(info->clip); |
|
1086 |
} |
|
1087 |
info->clip = env->NewWeakGlobalRef(clip); |
|
1088 |
} |
|
1089 |
||
1090 |
// init composite |
|
1091 |
if ((comp == NULL) || !env->IsInstanceOf(comp, xorCompClass)) { |
|
1092 |
if (info->comp != NULL) { |
|
1093 |
env->DeleteWeakGlobalRef(info->comp); |
|
1094 |
info->comp = NULL; |
|
1095 |
info->patrop = PATCOPY; |
|
1096 |
::SetROP2(info->hDC, R2_COPYPEN); |
|
1097 |
} |
|
1098 |
} else { |
|
1099 |
if (!env->IsSameObject(comp, info->comp)) { |
|
1100 |
info->xorcolor = GrPrim_CompGetXorColor(env, comp); |
|
1101 |
if (info->comp != NULL) { |
|
1102 |
env->DeleteWeakGlobalRef(info->comp); |
|
1103 |
} |
|
1104 |
info->comp = env->NewWeakGlobalRef(comp); |
|
1105 |
info->patrop = PATINVERT; |
|
1106 |
::SetROP2(info->hDC, R2_XORPEN); |
|
1107 |
} |
|
1108 |
color ^= info->xorcolor; |
|
1109 |
} |
|
1110 |
||
1111 |
if (patrop != NULL) { |
|
1112 |
*patrop = info->patrop; |
|
1113 |
} |
|
1114 |
||
1115 |
// init brush and pen |
|
1116 |
if (type & BRUSH) { |
|
1117 |
if (info->brushclr != color || (info->brush == NULL)) { |
|
1118 |
if (info->type & BRUSH) { |
|
1119 |
::SelectObject(info->hDC, nullbrush); |
|
1120 |
info->type ^= BRUSH; |
|
1121 |
} |
|
1122 |
if (info->brush != NULL) { |
|
1123 |
info->brush->Release(); |
|
1124 |
} |
|
1125 |
info->brush = AwtBrush::Get(CheckGrayColor(wsdo, color)); |
|
1126 |
info->brushclr = color; |
|
1127 |
} |
|
1128 |
if ((info->type & BRUSH) == 0) { |
|
1129 |
::SelectObject(info->hDC, info->brush->GetHandle()); |
|
1130 |
info->type ^= BRUSH; |
|
1131 |
} |
|
1132 |
} else if (type & NOBRUSH) { |
|
1133 |
if (info->type & BRUSH) { |
|
1134 |
::SelectObject(info->hDC, nullbrush); |
|
1135 |
info->type ^= BRUSH; |
|
1136 |
} |
|
1137 |
} |
|
1138 |
if (type & PEN) { |
|
1139 |
if (info->penclr != color || (info->pen == NULL)) { |
|
1140 |
if (info->type & PEN) { |
|
1141 |
::SelectObject(info->hDC, nullpen); |
|
1142 |
info->type ^= PEN; |
|
1143 |
} |
|
1144 |
if (info->pen != NULL) { |
|
1145 |
info->pen->Release(); |
|
1146 |
} |
|
1147 |
info->pen = AwtPen::Get(CheckGrayColor(wsdo, color)); |
|
1148 |
info->penclr = color; |
|
1149 |
} |
|
1150 |
if ((info->type & PEN) == 0) { |
|
1151 |
::SelectObject(info->hDC, info->pen->GetHandle()); |
|
1152 |
info->type ^= PEN; |
|
1153 |
} |
|
1154 |
} else if (type & NOPEN) { |
|
1155 |
if (info->type & PEN) { |
|
1156 |
::SelectObject(info->hDC, nullpen); |
|
1157 |
info->type ^= PEN; |
|
1158 |
} |
|
1159 |
} |
|
1160 |
} |
|
1161 |
||
887 | 1162 |
static void GDIWinSD_ReleaseDC(JNIEnv *env, GDIWinSDOps *wsdo, HDC hDC) |
2 | 1163 |
{ |
887 | 1164 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_ReleaseDC"); |
2 | 1165 |
// Don't actually do anything here: every thread holds its own |
1166 |
// wsdo-specific DC until the thread goes away or the wsdo |
|
1167 |
// is disposed. |
|
1168 |
} |
|
1169 |
||
1170 |
||
887 | 1171 |
static void GDIWinSD_InvalidateSD(JNIEnv *env, GDIWinSDOps *wsdo) |
2 | 1172 |
{ |
887 | 1173 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_InvalidateSD"); |
2 | 1174 |
J2dTraceLn2(J2D_TRACE_VERBOSE, " wsdo=0x%x wsdo->window=0x%x", |
1175 |
wsdo, wsdo->window); |
|
1176 |
||
1177 |
wsdo->invalid = JNI_TRUE; |
|
1178 |
} |
|
1179 |
||
1180 |
||
1181 |
||
1182 |
/* |
|
887 | 1183 |
* Method: GDIWinSD_Dispose |
2 | 1184 |
*/ |
1185 |
static void |
|
887 | 1186 |
GDIWinSD_Dispose(JNIEnv *env, SurfaceDataOps *ops) |
2 | 1187 |
{ |
887 | 1188 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWinSD_Dispose"); |
2 | 1189 |
// ops is assumed non-null as it is checked in SurfaceData_DisposeOps |
887 | 1190 |
GDIWinSDOps *wsdo = (GDIWinSDOps*)ops; |
2 | 1191 |
if (wsdo->bitmap) { |
1192 |
// delete old objects |
|
1193 |
J2dTraceLn(J2D_TRACE_VERBOSE, " disposing the GDI bitmap"); |
|
1194 |
if (wsdo->bmdc) { // should not be null |
|
1195 |
::SelectObject(wsdo->bmdc, wsdo->oldmap); |
|
1196 |
::DeleteDC(wsdo->bmdc); |
|
1197 |
wsdo->bmdc = 0; |
|
1198 |
} |
|
1199 |
::DeleteObject(wsdo->bitmap); |
|
1200 |
wsdo->bitmap = 0; |
|
1201 |
} |
|
1202 |
env->DeleteWeakGlobalRef(wsdo->peer); |
|
1203 |
if (wsdo->device != NULL) { |
|
1204 |
wsdo->device->Release(); |
|
1205 |
wsdo->device = NULL; |
|
1206 |
} |
|
1207 |
delete wsdo->surfaceLock; |
|
1208 |
} |
|
1209 |
||
1210 |
||
1211 |
/* |
|
887 | 1212 |
* Class: sun_java2d_windows_GDIWindowSurfaceData |
2 | 1213 |
* Method: invalidateSD |
1214 |
* Signature: ()V |
|
1215 |
*/ |
|
1216 |
JNIEXPORT void JNICALL |
|
887 | 1217 |
Java_sun_java2d_windows_GDIWindowSurfaceData_invalidateSD(JNIEnv *env, jobject wsd) |
2 | 1218 |
{ |
887 | 1219 |
J2dTraceLn(J2D_TRACE_INFO, "GDIWindowSurfaceData_invalidateSD"); |
1220 |
GDIWinSDOps *wsdo = GDIWindowSurfaceData_GetOpsNoSetup(env, wsd); |
|
2 | 1221 |
if (wsdo != NULL) { |
1222 |
wsdo->InvalidateSD(env, wsdo); |
|
1223 |
} |
|
1224 |
} |