Skip to content

Commit

Permalink
SWTAccessor: OS_gtk_widget_unrealize optional (SWT 4.3) ; decorate Pr…
Browse files Browse the repository at this point in the history
…ivilegedAction for static initSingleton block (SWTAccessor, NewtFactory, NativeWindowFactory)
  • Loading branch information
sgothel committed Nov 26, 2012
1 parent 541bcc1 commit 8cf694c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.jogamp.common.os.Platform;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;

import org.eclipse.swt.graphics.GCData;
import org.eclipse.swt.widgets.Control;
Expand Down Expand Up @@ -70,7 +72,7 @@ public class SWTAccessor {
static final String str_OS_gtk_class = "org.eclipse.swt.internal.gtk.OS";
static final Class<?> OS_gtk_class;
static final Method OS_gtk_widget_realize;
static final Method OS_gtk_widget_unrealize;
static final Method OS_gtk_widget_unrealize; // optional (removed in SWT 4.3)
static final Method OS_GTK_WIDGET_WINDOW;
static final Method OS_gdk_x11_drawable_get_xdisplay;
static final Method OS_gdk_x11_drawable_get_xid;
Expand All @@ -83,6 +85,12 @@ public class SWTAccessor {
static {
Field f = null;

AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
NativeWindowFactory.initSingleton(); // last resort ..
return null;
} } );

final String nwt = NativeWindowFactory.getNativeWindowType(false);

if(NativeWindowFactory.TYPE_MACOSX != nwt ) {
Expand Down Expand Up @@ -127,14 +135,18 @@ public class SWTAccessor {
Method m1=null, m2=null, m3=null, m4=null, m5=null;
Class<?> handleType = swt_uses_long_handles ? long.class : int.class ;
if( NativeWindowFactory.TYPE_X11 == nwt ) {
// mandatory
try {
c = ReflectionUtil.getClass(str_OS_gtk_class, false, SWTAccessor.class.getClassLoader());
m1 = c.getDeclaredMethod(str_gtk_widget_realize, handleType);
m2 = c.getDeclaredMethod(str_gtk_widget_unrealize, handleType);
m3 = c.getDeclaredMethod(str_GTK_WIDGET_WINDOW, handleType);
m4 = c.getDeclaredMethod(str_gdk_x11_drawable_get_xdisplay, handleType);
m5 = c.getDeclaredMethod(str_gdk_x11_drawable_get_xid, handleType);
} catch (Exception ex) { throw new NativeWindowException(ex); }
// optional
try {
m2 = c.getDeclaredMethod(str_gtk_widget_unrealize, handleType);
} catch (Exception ex) { }
}
OS_gtk_class = c;
OS_gtk_widget_realize = m1;
Expand Down Expand Up @@ -197,7 +209,7 @@ public static void setRealized(final Control swtControl, final boolean realize)
public void run() {
if(realize) {
callStaticMethodL2V(OS_gtk_widget_realize, handle);
} else {
} else if(null != OS_gtk_widget_unrealize) {
callStaticMethodL2V(OS_gtk_widget_unrealize, handle);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,29 @@ private static String _getNativeWindowingType() {
}

static {
Platform.initSingleton();
DEBUG = Debug.debug("NativeWindow");
final boolean[] _DEBUG = new boolean[] { false };
final String[] _tmp = new String[] { null };

AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
Platform.initSingleton(); // last resort ..
_DEBUG[0] = Debug.debug("NativeWindow");
_tmp[0] = Debug.getProperty("nativewindow.ws.name", true);
return null;
} } ) ;

DEBUG = _DEBUG[0];
if(DEBUG) {
System.err.println(Thread.currentThread().getName()+" - Info: NativeWindowFactory.<init>");
// Thread.dumpStack();
}

// Gather the windowing TK first
nativeWindowingTypePure = _getNativeWindowingType();
final String tmp = Debug.getProperty("nativewindow.ws.name", true);
if(null==tmp || tmp.length()==0) {
if(null==_tmp[0] || _tmp[0].length()==0) {
nativeWindowingTypeCustom = nativeWindowingTypePure;
} else {
nativeWindowingTypeCustom = tmp.intern(); // canonical representation
nativeWindowingTypeCustom = _tmp[0].intern(); // canonical representation
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/newt/classes/com/jogamp/newt/NewtFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@

package com.jogamp.newt;

import java.security.AccessController;
import java.security.PrivilegedAction;

import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.AbstractGraphicsScreen;
import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowFactory;

import com.jogamp.common.os.Platform;

import jogamp.newt.Debug;
import jogamp.newt.DisplayImpl;
import jogamp.newt.ScreenImpl;
Expand All @@ -54,8 +59,12 @@ public class NewtFactory {
// Work-around for initialization order problems on Mac OS X
// between native Newt and (apparently) Fmod
static {
NativeWindowFactory.initSingleton(); // last resort ..
WindowImpl.init(NativeWindowFactory.getNativeWindowType(true));
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
NativeWindowFactory.initSingleton(); // last resort ..
WindowImpl.init(NativeWindowFactory.getNativeWindowType(true));
return null;
} } );
}

public static Class<?> getCustomClass(String packageName, String classBaseName) {
Expand Down

0 comments on commit 8cf694c

Please sign in to comment.