001: /*
002: * $RCSfile: DrawingSurfaceObjectAWT.java,v $
003: *
004: * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.7 $
028: * $Date: 2008/02/28 20:17:21 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.awt.Point;
035:
036: /**
037: * The DrawingSurfaceObject class is used to manage native drawing surface
038: */
039:
040: class DrawingSurfaceObjectAWT extends DrawingSurfaceObject {
041:
042: // drawing surface
043: private long nativeDS = 0;
044: private long dsi = 0;
045:
046: private boolean doLastUnlock = false;
047: private boolean xineramaDisabled = false;
048:
049: private long display = 0;
050: private int screenID = 0;
051:
052: private static long nativeAWT = 0;
053:
054: private native boolean lockAWT(long ds);
055:
056: private native void unlockAWT(long ds);
057:
058: private static native void lockGlobal(long awt);
059:
060: private static native void unlockGlobal(long awt);
061:
062: private native long getDrawingSurfaceAWT(Canvas3D cv, long awt);
063:
064: private native long getDrawingSurfaceInfo(long ds);
065:
066: private static native void freeResource(long awt, long ds, long dsi);
067:
068: // TODO: long window
069: private native int getDrawingSurfaceWindowIdAWT(Canvas3D cv,
070: long ds, long dsi, long display, int screenID,
071: boolean xineramaDisabled);
072:
073: DrawingSurfaceObjectAWT(Canvas3D cv, long awt, long display,
074: int screenID, boolean xineramaDisabled) {
075: super (cv);
076: nativeAWT = awt;
077:
078: this .display = display;
079: this .screenID = screenID;
080: this .xineramaDisabled = xineramaDisabled;
081: }
082:
083: synchronized boolean renderLock() {
084:
085: if (onScreen) {
086: if (nativeDS == 0) {
087: return false;
088: } else {
089: if (lockAWT(nativeDS)) {
090: gotDsiLock = true;
091: return true;
092: } else {
093: return false;
094: }
095: }
096: } else {
097: gotDsiLock = true;
098: lockGlobal(nativeAWT);
099: }
100: return true;
101: }
102:
103: synchronized void unLock() {
104:
105: if (gotDsiLock) {
106: if (onScreen) {
107: if (nativeDS != 0) {
108: unlockAWT(nativeDS);
109: gotDsiLock = false;
110: if (doLastUnlock) {
111: nativeDS = 0;
112: dsi = 0;
113: doLastUnlock = false;
114: }
115: }
116: } else {
117: unlockGlobal(nativeAWT);
118: gotDsiLock = false;
119: }
120: }
121: }
122:
123: synchronized void getDrawingSurfaceObjectInfo() {
124: // Free old DS and DSI
125: if (nativeDS != 0 && dsi != 0) {
126: freeResource(nativeAWT, nativeDS, dsi);
127: nativeDS = 0;
128: dsi = 0;
129: }
130:
131: // get native drawing surface - ds
132: nativeDS = getDrawingSurfaceAWT(canvas, nativeAWT);
133:
134: // get window id
135: if (nativeDS != 0) {
136: dsi = getDrawingSurfaceInfo(nativeDS);
137: if (dsi != 0) {
138: long nativeDrawable = getDrawingSurfaceWindowIdAWT(
139: canvas, nativeDS, dsi, display, screenID,
140: xineramaDisabled);
141: canvas.drawable = new NativeDrawable(nativeDrawable);
142: }
143: }
144: }
145:
146: synchronized void invalidate() {
147: if (gotDsiLock && (nativeDS != 0)) {
148: // Should not call unlock in AWT thread
149: // Otherwise IllegalMonitorException will throw
150: // unlockAWT(nativeDS);
151: // We don't reset nativeDS & dsi to 0 here.
152: // This allow Renderer to continue unLock.
153: doLastUnlock = true;
154: } else {
155: nativeDS = 0;
156: dsi = 0;
157: }
158: }
159:
160: static void freeDrawingSurface(Object obj) {
161: long p[] = (long[]) obj;
162: freeResource(nativeAWT, p[0], p[1]);
163: }
164:
165: long getDSI() {
166: return dsi;
167: }
168:
169: long getDS() {
170: return nativeDS;
171: }
172:
173: }
|