summaryrefslogtreecommitdiffstats
path: root/make/config/nativewindow/jawt-CustomJavaCode.java
blob: 090dcb31f6c3c91269f733c14f9da4b661af5ea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/** Available and recommended on Mac OS X >= 10.6 Update 4 */
public static final int JAWT_MACOSX_USE_CALAYER = 0x80000000;
public static final VersionNumber JAWT_MacOSXCALayerMinVersion = new VersionNumber(10,6,4);

private static volatile JAWT jawt = null;
private static int jawt_version_flags = 0;

private int jawt_version_cached = 0;

public final int getVersionCached() {
    return jawt_version_cached;
}

public static void setJAWTVersionFlags(int versionFlags) {
    synchronized (JAWT.class) {
      if (jawt != null) {
        throw new RuntimeException("JAWT already instantiated");
      }
      jawt_version_flags = versionFlags;
    }
}

public static boolean isJAWTInstantiated() {
    synchronized (JAWT.class) {
      return jawt != null;
    }      
}

/** Helper routine for all users to call to access the JAWT. */
public static JAWT getJAWT() {
  if (jawt == null) {
    synchronized (JAWT.class) {
      if (jawt == null) {
        JAWTUtil.initSingleton();
        // Workaround for 4845371.
        // Make sure the first reference to the JNI GetDirectBufferAddress is done
        // from a privileged context so the VM's internal class lookups will succeed.
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
              JAWT j = JAWT.create();
              if( 0 != ( jawt_version_flags & JAWT_MACOSX_USE_CALAYER ) ) {
                  j.setVersion(jawt_version_flags);
                  if (JAWTFactory.JAWT_GetAWT(j)) {
                      jawt = j;
                      jawt.jawt_version_cached = jawt.getVersion();
                      return null;
                  }
                  jawt_version_flags &= ~JAWT_MACOSX_USE_CALAYER;
                  System.err.println("MacOSX "+Platform.OS_VERSION_NUMBER+" >= "+JAWT_MacOSXCALayerMinVersion+": Failed to use JAWT_MACOSX_USE_CALAYER");
              }
              j.setVersion(jawt_version_flags);
              if (!JAWTFactory.JAWT_GetAWT(j)) {
                throw new RuntimeException("Unable to initialize JAWT: 0x"+Integer.toHexString(jawt_version_flags));
              }
              jawt = j;
              jawt.jawt_version_cached = jawt.getVersion();
              return null;
            }
          });
      }
    }
  }
  return jawt;
}