forked from eclipse-efx/efxclipse-drift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prism.java
130 lines (102 loc) · 4.19 KB
/
Prism.java
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package org.eclipse.fx.drift.internal.prism;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Optional;
import org.eclipse.fx.drift.internal.Log;
import org.eclipse.fx.drift.internal.Versioning;
import org.eclipse.fx.drift.internal.jni.win32.Win32;
import org.eclipse.fx.drift.internal.jni.win32.Win32.IDirect3DDevice9Ex;
import org.eclipse.fx.drift.util.NativeUtil;
import com.sun.prism.Texture;
@SuppressWarnings("restriction")
public class Prism {
static {
//NativeLoader.loadLibrary(Prism.class, "DriftGL");
NativeUtil.loadLibrary(Prism.class, "driftfx");
}
private static Class<?> cGraphicsPipeline;
private static Method mGraphicsPipelineGetDefaultResourceFactory;
private static Class<?> cResourceFactory;
private static Object iDefaultResourceFactory;
private static Optional<Class<?>> getClass(String className) {
try {
return Optional.of(Class.forName(className));
} catch (Exception e) {
return Optional.empty();
}
}
private static boolean isD3D;
private static boolean isSW;
private static boolean isES2;
private static Object iD3DContext;
private static long contextHandleD3D;
private static Win32.IDirect3DDevice9Ex d3dDevice;
private static Object iES2Context;
private static Object iGLContext;
private static long contextHandleES2;
public static void initialize() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
IllegalAccessException, IllegalArgumentException, NoSuchFieldException {
Log.info("DriftFX " + Versioning.getVersion() + "(git sha: " + Versioning.getSha()+") initializing");
cGraphicsPipeline = Class.forName("com.sun.prism.GraphicsPipeline");
mGraphicsPipelineGetDefaultResourceFactory = cGraphicsPipeline.getMethod("getDefaultResourceFactory");
cResourceFactory = Class.forName("com.sun.prism.ResourceFactory");
iDefaultResourceFactory = mGraphicsPipelineGetDefaultResourceFactory.invoke(null);
String name = iDefaultResourceFactory.getClass().getName();
isD3D = "com.sun.prism.d3d.D3DResourceFactory".equals(name);
isES2 = "com.sun.prism.es2.ES2ResourceFactory".equals(name);
isSW = "com.sun.prism.sw.SWResourceFactory".equals(name);
if (isD3D) {
PrismD3D.initialize();
iD3DContext = PrismD3D.getD3DContext(iDefaultResourceFactory);
contextHandleD3D = PrismD3D.getContextHandle(iD3DContext);
Log.debug(" * D3D Context handle = " + contextHandleD3D);
d3dDevice = org.eclipse.fx.drift.internal.jni.win32.Prism.getPrismIDirect3DDevice9Ex(contextHandleD3D);
Log.debug(" * D3D Context direct3D device = " + d3dDevice);
//NativeAPI.initializeD3DPipeline(contextHandleD3D);
} else if (isES2) {
PrismES2.initialize();
iES2Context = PrismES2.getES2Context(iDefaultResourceFactory);
iGLContext = PrismES2.getGLContext(iES2Context);
contextHandleES2 = PrismES2.getNativeHandle(iGLContext);
// QuantumRendererHelper.initialize(contextHandleES2);
//NativeAPI.initializeES2Pipeline(contextHandleES2);
} else if (isSW) {
throw new UnsupportedOperationException("SW Support not yet implemented!");
} else {
throw new UnsupportedOperationException("Unknown JavaFX pipeline!");
}
}
public static boolean isD3D() {
return isD3D;
}
public static boolean isSW() {
return isSW;
}
public static boolean isES2() {
return isES2;
}
public static long getES2ContextHandle() {
return contextHandleES2;
}
public static long getTextureHandle(Texture texture) {
if (isD3D()) {
try {
// TODO move class and method to members
Class<?> d3dTexture = Class.forName("com.sun.prism.d3d.D3DTexture");
Method mD3DTextureGetNativeSourceHandle = d3dTexture.getMethod("getNativeSourceHandle");
mD3DTextureGetNativeSourceHandle.setAccessible(true);
return (long) mD3DTextureGetNativeSourceHandle.invoke(texture);
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
if (isES2()) {
return PrismES2.getTextureName(texture);
}
throw new UnsupportedOperationException("Not implemented");
}
public static IDirect3DDevice9Ex getD3DDevice() {
return d3dDevice;
}
}