summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-11-21 07:33:19 +0100
committerSven Gothel <[email protected]>2019-11-21 07:33:19 +0100
commit9b52db212f8749b61e4cf775fe3244b94c5ae41c (patch)
tree74f1d9d9921c6a2acb668ea679a365a9e892400d
parent10d3ba66b725fb44dc2c646c9ddc9816a4d72777 (diff)
Bug 1156: EGL-GBM: Cleanup Code & Replace Newt GBM implementation
GBM driver is now under egl/gbm subpackage and has been replaced by bcm_vc_iv boilerplate. Native code is reentrant capable and cleaned up. TODO: EGLDisplayUtil work with SharedResourceRunner
-rw-r--r--make/build-common.xml8
-rw-r--r--make/build-newt.xml41
-rw-r--r--make/scripts/tests.sh8
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java29
-rw-r--r--src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java113
-rw-r--r--src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java121
-rw-r--r--src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java233
-rw-r--r--src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java62
-rw-r--r--src/newt/classes/jogamp/newt/driver/gbm/ScreenDriver.java88
-rw-r--r--src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java120
-rw-r--r--src/newt/native/bcm_vc_iv.c4
-rw-r--r--src/newt/native/egl_gbm.c237
-rw-r--r--src/newt/native/gbm.c147
13 files changed, 751 insertions, 460 deletions
diff --git a/make/build-common.xml b/make/build-common.xml
index 0967b6b0f..1d8928cf2 100644
--- a/make/build-common.xml
+++ b/make/build-common.xml
@@ -414,7 +414,7 @@
<property name="newt-driver-intelgdl.jar" value="${build.newt}/newt-driver-intelgdl.jar" /> <!-- excluded from all -->
<property name="newt-driver-bcm-old.jar" value="${build.newt}/newt-driver-bcm-old.jar" /> <!-- excluded from all -->
<property name="newt-driver-bcm-vc.jar" value="${build.newt}/newt-driver-bcm-vc.jar" />
- <property name="newt-driver-gbm.jar" value="${build.newt}/newt-driver-gbm.jar" />
+ <property name="newt-driver-egl-gbm.jar" value="${build.newt}/newt-driver-egl-gbm.jar" />
<path id="newt_all_atoms.classpath">
<pathelement location="${newt.jar}" />
@@ -428,7 +428,7 @@
<pathelement location="${newt-driver-osx.jar}" />
<pathelement location="${newt-driver-ios.jar}" />
<pathelement location="${newt-driver-bcm-vc.jar}" />
- <pathelement location="${newt-driver-gbm.jar}" />
+ <pathelement location="${newt-driver-egl-gbm.jar}" />
</path>
<path id="newt_all-noawt_atoms.classpath">
<pathelement location="${newt.jar}" />
@@ -439,7 +439,7 @@
<pathelement location="${newt-driver-osx.jar}" />
<pathelement location="${newt-driver-ios.jar}" />
<pathelement location="${newt-driver-bcm-vc.jar}" />
- <pathelement location="${newt-driver-gbm.jar}" />
+ <pathelement location="${newt-driver-egl-gbm.jar}" />
</path>
<path id="newt_all-mobile_atoms.classpath">
<pathelement location="${newt.jar}" />
@@ -449,7 +449,7 @@
<pathelement location="${newt-driver-win.jar}" />
<pathelement location="${newt-driver-ios.jar}" />
<pathelement location="${newt-driver-bcm-vc.jar}" />
- <pathelement location="${newt-driver-gbm.jar}" />
+ <pathelement location="${newt-driver-egl-gbm.jar}" />
</path>
<path id="newt_all-android_atoms.classpath">
<pathelement location="${newt.jar}" />
diff --git a/make/build-newt.xml b/make/build-newt.xml
index 447a41189..c3fc22afd 100644
--- a/make/build-newt.xml
+++ b/make/build-newt.xml
@@ -49,7 +49,7 @@
setup.addNativeKD
setup.addNativeIntelGDL
setup.addNativeBroadcom ( always true if 'isLinux' )
- setup.addNativeGBM ( always true if 'isLinux' )
+ setup.addNativeEGLGBM ( always true if 'isLinux' )
- Internal settings, may not be necessary to set them manually,
since all JAR archives are orthogonal.
@@ -76,7 +76,7 @@
<isset property="isLinux"/>
</condition>
- <condition property="setup.addNativeGBM">
+ <condition property="setup.addNativeEGLGBM">
<isset property="isLinux"/>
</condition>
@@ -90,7 +90,7 @@
<isfalse value="${setup.addNativeKD}" />
<isfalse value="${setup.addNativeIntelGDL}" />
<isfalse value="${setup.addNativeBroadcom}" />
- <isfalse value="${setup.addNativeGBM}" />
+ <isfalse value="${setup.addNativeEGLGBM}" />
</and>
</condition>
@@ -103,7 +103,7 @@
<echo message="setup.addNativeKD: ${setup.addNativeKD}" />
<echo message="setup.addNativeIntelGDL: ${setup.addNativeIntelGDL}" />
<echo message="setup.addNativeBroadcom: ${setup.addNativeBroadcom}" />
- <echo message="setup.addNativeGBM: ${setup.addNativeGBM}" />
+ <echo message="setup.addNativeEGLGBM: ${setup.addNativeEGLGBM}" />
<echo message="setup.nonatives: ${setup.nonatives}" />
<!-- partitioning -->
@@ -156,8 +156,8 @@
<property name="java.part.driver.bcm.vc"
value="jogamp/newt/driver/bcm/vc/**"/>
- <property name="java.part.driver.gbm"
- value="jogamp/newt/driver/gbm/**"/>
+ <property name="java.part.driver.egl.gbm"
+ value="jogamp/newt/driver/egl/gbm/**"/>
<property name="java.part.driver.android"
value="jogamp/newt/driver/android/**"/>
@@ -245,7 +245,7 @@
<mkdir dir="${src.generated.c}/IntelGDL" />
<mkdir dir="${src.generated.c}/bcm/egl" />
<mkdir dir="${src.generated.c}/bcm/vc/iv" />
- <mkdir dir="${src.generated.c}/gbm" />
+ <mkdir dir="${src.generated.c}/egl/gbm" />
<mkdir dir="${classes}" />
<mkdir dir="${obj.newt}" />
</target>
@@ -332,7 +332,7 @@
<javac srcdir="${src.java}"
destdir="${classes}"
excludes="${java.excludes.all} ${java.part.driver.android}"
- nativeheaderdir="${src.generated.c}/gbm"
+ nativeheaderdir="${src.generated.c}/egl/gbm"
fork="yes"
includeAntRuntime="false"
memoryMaximumSize="${javac.memorymax}"
@@ -342,9 +342,9 @@
bootclasspath="${target.rt.jar}"
debug="${javacdebug}" debuglevel="${javacdebuglevel}">
<classpath refid="jogl_nativewindow_gluegen.classpath"/>
- <include name="jogamp/newt/driver/gbm/DisplayDriver.java" />
- <include name="jogamp/newt/driver/gbm/ScreenDriver.java" />
- <include name="jogamp/newt/driver/gbm/WindowDriver.java" />
+ <include name="jogamp/newt/driver/egl/gbm/DisplayDriver.java" />
+ <include name="jogamp/newt/driver/egl/gbm/ScreenDriver.java" />
+ <include name="jogamp/newt/driver/egl/gbm/WindowDriver.java" />
</javac>
<!-- create Windows native headers -->
@@ -525,11 +525,11 @@
<!-- syslibset libs="EGL"/ -->
</linker>
- <linker id="linker.cfg.linux.newt.bcm_vc" extends="linker.cfg.linux">
- <syslibset libs="EGL"/>
- <syslibset libs="gbm"/>
- <syslibset libs="drm"/>
- </linker>
+ <linker id="linker.cfg.linux.newt.egl_gbm" extends="linker.cfg.linux">
+ <syslibset libs="EGL"/>
+ <syslibset libs="gbm"/>
+ <syslibset libs="drm"/>
+ </linker>
<linker id="linker.cfg.linux.newt.bcm_egl" extends="linker.cfg.linux">
<syslibset libs="EGL"/>
@@ -899,7 +899,7 @@
<include name="${rootrel.src.c}/IntelGDL.c" if="setup.addNativeIntelGDL"/>
<include name="${rootrel.src.c}/bcm_egl.c" if="setup.addNativeBroadcom"/>
<include name="${rootrel.src.c}/bcm_vc_iv.c" if="setup.addNativeBroadcom"/>
- <include name="${rootrel.src.c}/gbm.c" if="setup.addNativeGBM"/>
+ <include name="${rootrel.src.c}/egl_gbm.c" if="setup.addNativeEGLGBM"/>
</patternset>
<echo message="Compiling @{output.lib.name}" />
@@ -948,7 +948,8 @@
<includepath path="stub_includes/embedded/IntelGDL" if="setup.addNativeIntelGDL" />
<includepath path="${src.generated.c}/bcm/egl" if="setup.addNativeBroadcom" />
<includepath path="${src.generated.c}/bcm/vc/iv" if="setup.addNativeBroadcom" />
- <includepath path="${src.generated.c}/gbm" if="setup.addNativeGBM" />
+ <includepath path="${src.generated.c}/egl/gbm" if="setup.addNativeEGLGBM" />
+ <includepath path="/usr/include/libdrm" if="setup.addNativeEGLGBM" />
<!-- This must come last to not override real include paths -->
<!-- includepath path="stub_includes/macosx" if="isOSX" / -->
</compiler>
@@ -1094,9 +1095,9 @@
<fileset dir="${classes}"
includes="${java.part.driver.bcm.vc}"/>
</jar>
- <jar manifest="${build.newt}/manifest.mf" destfile="${newt-driver-gbm.jar}" filesonly="true">
+ <jar manifest="${build.newt}/manifest.mf" destfile="${newt-driver-egl-gbm.jar}" filesonly="true">
<fileset dir="${classes}"
- includes="${java.part.driver.gbm}"/>
+ includes="${java.part.driver.egl.gbm}"/>
</jar>
<jar manifest="${build.newt}/manifest.mf" destfile="${newt-driver-intelgdl.jar}" filesonly="true">
<fileset dir="${classes}"
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index e0f0c0673..0355ceae8 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -114,7 +114,7 @@ function jrun() {
#D_ARGS="-Dnativewindow.debug=all"
#D_ARGS="-Djogl.debug=all"
#D_ARGS="-Djogl.debug=all -Dnewt.debug=all -Djogl.debug.DebugGL"
- #D_ARGS="-Dnewt.debug=all"
+ D_ARGS="-Dnewt.debug=all"
#D_ARGS="-Djogl.debug=all -Dnewt.debug=all"
#D_ARGS="-Djogl.debug=all -Dnativewindow.debug=all"
#D_ARGS="-Djogamp.debug=all -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all"
@@ -123,7 +123,7 @@ function jrun() {
#D_ARGS="-Dnativewindow.debug.OSXUtil -Dnativewindow.debug.JAWT -Djogl.debug.GLContext"
#D_ARGS="-Dnewt.debug.Window"
#D_ARGS="-Dnewt.debug.Window -Djogamp.common.utils.locks.Lock.timeout=600000 -Dnewt.debug.EDT"
- D_ARGS="-Dnewt.debug.Window -Dnewt.debug.EDT -Djogamp.common.utils.locks.Lock.timeout=600000 -Dnativewindow.debug.OSXUtil.MainThreadChecker"
+ #D_ARGS="-Dnewt.debug.Window -Dnewt.debug.EDT -Djogamp.common.utils.locks.Lock.timeout=600000 -Dnativewindow.debug.OSXUtil.MainThreadChecker"
#X_ARGS="--illegal-access=warn"
#D_ARGS="-Djogamp.debug.NativeLibrary=true -Djogamp.debug.JNILibLoader=true"
@@ -448,7 +448,7 @@ function testawtswt() {
#testnoawt com.jogamp.newt.opengl.GLWindow $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLVersionParsing00NEWT $*
-#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLWindowNEWT $*
+testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLWindowNEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLCanvasAWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLProfile00NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLProfile01NEWT $*
@@ -952,7 +952,7 @@ function testawtswt() {
# 2.4.0 Regressions
#
# OSX
-testnoawt com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext01VSyncAnimNEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext01VSyncAnimNEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestDisplayLifecycle02NEWT $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestParentingFocus02SwingAWTRobot $*
#testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT $*
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
index 5adba1703..580a881d1 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
@@ -199,19 +199,26 @@ public class EGLDisplayUtil {
}
final String nativeWindowType = NativeWindowFactory.getNativeWindowType(false);
- int platform = 0;
+ final int platform;
final long eglDisplay;
- if(nativeWindowType == NativeWindowFactory.TYPE_X11) {
- platform = EGLExt.EGL_PLATFORM_X11_KHR;
- }else if(nativeWindowType == NativeWindowFactory.TYPE_ANDROID) {
- platform = EGLExt.EGL_PLATFORM_ANDROID_KHR;
- }else if(nativeWindowType == NativeWindowFactory.TYPE_GBM){
- platform = EGLExt.EGL_PLATFORM_GBM_MESA;
- } else if(nativeWindowType == NativeWindowFactory.TYPE_WAYLAND){
- // TODO
- platform = EGLExt.EGL_PLATFORM_WAYLAND_KHR;
+ switch( nativeWindowType ) {
+ case NativeWindowFactory.TYPE_X11:
+ platform = EGLExt.EGL_PLATFORM_X11_KHR;
+ break;
+ case NativeWindowFactory.TYPE_ANDROID:
+ platform = EGLExt.EGL_PLATFORM_ANDROID_KHR;
+ break;
+ case NativeWindowFactory.TYPE_GBM:
+ platform = EGLExt.EGL_PLATFORM_GBM_MESA;
+ break;
+ case NativeWindowFactory.TYPE_WAYLAND:
+ // TODO
+ platform = EGLExt.EGL_PLATFORM_WAYLAND_KHR;
+ break;
+ default:
+ platform = 0;
}
- if( platform != 0){
+ if( 0 != platform && false ) {
eglDisplay = EGL.eglGetPlatformDisplay(platform, nativeDisplay_id, null);
}
else{
diff --git a/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java
new file mode 100644
index 000000000..e83e8e2a7
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java
@@ -0,0 +1,113 @@
+/**
+ * Copyright 2019 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package jogamp.newt.driver.egl.gbm;
+
+import com.jogamp.nativewindow.AbstractGraphicsDevice;
+import com.jogamp.nativewindow.NativeWindowException;
+import com.jogamp.nativewindow.egl.EGLGraphicsDevice;
+import com.jogamp.opengl.GLProfile;
+
+import jogamp.newt.DisplayImpl;
+import jogamp.newt.NEWTJNILibLoader;
+import jogamp.opengl.egl.EGLDisplayUtil;
+
+public class DisplayDriver extends DisplayImpl {
+
+ static {
+ NEWTJNILibLoader.loadNEWT();
+ GLProfile.initSingleton();
+
+ if (!DisplayDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize egl.gbm Display jmethodIDs");
+ }
+ if (!ScreenDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize egl.gbm Screen jmethodIDs");
+ }
+ if (!WindowDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize egl.gbm Window jmethodIDs");
+ }
+ drmHandle = initDrm();
+ }
+
+ static void validateDrm() {
+ if( 0 == drmHandle ) {
+ throw new NativeWindowException("Failed to initialize egl.gbm DRM handle");
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ validateDrm();
+ }
+
+ private static void shutdownHook() {
+ freeDrm(drmHandle);
+ }
+
+ public DisplayDriver() {
+ gbmHandle = 0;
+ }
+
+ @Override
+ protected void createNativeImpl() {
+ validateDrm();
+ gbmHandle = OpenGBMDisplay0(drmHandle);
+ aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(gbmHandle, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
+ aDevice.open();
+ }
+
+ @Override
+ protected void closeNativeImpl(final AbstractGraphicsDevice aDevice) {
+ aDevice.close();
+ CloseGBMDisplay0(gbmHandle);
+ gbmHandle = 0;
+ }
+
+ /* pp */ static final long getDrmHandle() { validateDrm(); return drmHandle; }
+ /* pp */ final long getGBMHandle() { return gbmHandle; }
+
+ @Override
+ protected void dispatchMessagesNative() {
+ DispatchMessages0();
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+ private static native boolean initIDs();
+ private static native long initDrm();
+ private static native void freeDrm(long drmHandle);
+
+ private static native long OpenGBMDisplay0(long drmHandle);
+ private static native void CloseGBMDisplay0(long gbmHandle);
+
+ private static native void DispatchMessages0();
+
+ private static final long drmHandle;
+ private long gbmHandle;
+}
diff --git a/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java
new file mode 100644
index 000000000..2ff7ab299
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java
@@ -0,0 +1,121 @@
+/**
+ * Copyright 2019 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package jogamp.newt.driver.egl.gbm;
+
+import com.jogamp.nativewindow.DefaultGraphicsScreen;
+import com.jogamp.nativewindow.util.Rectangle;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
+import jogamp.newt.MonitorModeProps;
+import jogamp.newt.ScreenImpl;
+
+public class ScreenDriver extends ScreenImpl {
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public ScreenDriver() {
+ }
+
+ @Override
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
+ initNative( DisplayDriver.getDrmHandle() );
+ }
+
+ @Override
+ protected void closeNativeImpl() { }
+
+ @Override
+ protected int validateScreenIndex(final int idx) {
+ return 0; // only one screen available
+ }
+
+ @Override
+ protected void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Cache cache) {
+ int[] props = new int[ MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL ];
+ int i = 0;
+ props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL;
+ props[i++] = cachedWidth; // width
+ props[i++] = cachedHeight; // height
+ props[i++] = ScreenImpl.default_sm_bpp; // FIXME
+ props[i++] = cachedVRrefresh * 100;
+ props[i++] = 0; // flags
+ props[i++] = 0; // mode_idx
+ props[i++] = 0; // rotation
+ final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0);
+
+ props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES];
+ i = 0;
+ props[i++] = props.length;
+ props[i++] = 0; // crt_idx
+ props[i++] = 0; // is-clone
+ props[i++] = 1; // is-primary
+ props[i++] = ScreenImpl.default_sm_widthmm; // FIXME
+ props[i++] = ScreenImpl.default_sm_heightmm; // FIXME
+ props[i++] = 0; // rotated viewport x pixel-units
+ props[i++] = 0; // rotated viewport y pixel-units
+ props[i++] = cachedWidth; // rotated viewport width pixel-units
+ props[i++] = cachedHeight; // rotated viewport height pixel-units
+ props[i++] = 0; // rotated viewport x window-units
+ props[i++] = 0; // rotated viewport y window-units
+ props[i++] = cachedWidth; // rotated viewport width window-units
+ props[i++] = cachedHeight; // rotated viewport height window-units
+ MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null);
+ }
+
+ @Override
+ protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) {
+ return monitor.getSupportedModes().get(0);
+ }
+
+ @Override
+ protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, final MonitorMode mode) {
+ return false;
+ }
+
+ @Override
+ protected void calcVirtualScreenOriginAndSize(final Rectangle viewport, final Rectangle viewportInWindowUnits) {
+ viewport.set(0, 0, cachedWidth, cachedHeight);
+ viewportInWindowUnits.set(viewport);
+ }
+
+ /** Called from {@link #initNative(long)}. */
+ protected void notifyScreenMode(final int width, final int height, final int vrefresh) {
+ cachedWidth = width; // write to static field intended
+ cachedHeight = height; // write to static field intended
+ cachedVRrefresh = vrefresh;
+ }
+
+ private static int cachedWidth = 0;
+ private static int cachedHeight = 0;
+ private static int cachedVRrefresh = 0;
+
+ protected static native boolean initIDs();
+ protected native void initNative(long drmHandle);
+}
diff --git a/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java
new file mode 100644
index 000000000..41f1bc359
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java
@@ -0,0 +1,233 @@
+/**
+ * Copyright 2019 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package jogamp.newt.driver.egl.gbm;
+
+import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
+import com.jogamp.nativewindow.AbstractGraphicsScreen;
+import com.jogamp.nativewindow.Capabilities;
+import com.jogamp.nativewindow.GraphicsConfigurationFactory;
+import com.jogamp.nativewindow.NativeWindowException;
+import com.jogamp.nativewindow.VisualIDHolder;
+import com.jogamp.nativewindow.egl.EGLGraphicsDevice;
+import com.jogamp.nativewindow.util.Point;
+import com.jogamp.nativewindow.util.Rectangle;
+import com.jogamp.nativewindow.util.RectangleImmutable;
+
+import jogamp.newt.WindowImpl;
+import jogamp.newt.driver.linux.LinuxEventDeviceTracker;
+import jogamp.newt.driver.linux.LinuxMouseTracker;
+
+public class WindowDriver extends WindowImpl {
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public WindowDriver() {
+ linuxMouseTracker = LinuxMouseTracker.getSingleton();
+ linuxEventDeviceTracker = LinuxEventDeviceTracker.getSingleton();
+
+ windowHandleClose = 0;
+ }
+
+ /**
+ * Clamp given rectangle to given screen bounds.
+ *
+ * @param screen
+ * @param rect the {@link RectangleImmutable} in pixel units
+ * @param definePosSize if {@code true} issue {@link #definePosition(int, int)} and {@link #defineSize(int, int)}
+ * if either has changed.
+ * @return If position or size has been clamped a new {@link RectangleImmutable} instance w/ clamped values
+ * will be returned, otherwise the given {@code rect} is returned.
+ */
+ private RectangleImmutable clampRect(final ScreenDriver screen, final RectangleImmutable rect, final boolean definePosSize) {
+ int x = rect.getX();
+ int y = rect.getY();
+ int w = rect.getWidth();
+ int h = rect.getHeight();
+ final int s_w = screen.getWidth();
+ final int s_h = screen.getHeight();
+ boolean modPos = false;
+ boolean modSize = false;
+ if( 0 > x ) {
+ x = 0;
+ modPos = true;
+ }
+ if( 0 > y ) {
+ y = 0;
+ modPos = true;
+ }
+ if( s_w < x + w ) {
+ if( 0 < x ) {
+ x = 0;
+ modPos = true;
+ }
+ if( s_w < w ) {
+ w = s_w;
+ modSize = true;
+ }
+ }
+ if( s_h < y + h ) {
+ if( 0 < y ) {
+ y = 0;
+ modPos = true;
+ }
+ if( s_h < h ) {
+ h = s_h;
+ modSize = true;
+ }
+ }
+ if( modPos || modSize ) {
+ if( definePosSize ) {
+ if( modPos ) {
+ definePosition(x, y);
+ }
+ if( modSize ) {
+ defineSize(w, h);
+ }
+ }
+ return new Rectangle(x, y, w, h);
+ } else {
+ return rect;
+ }
+ }
+
+ @Override
+ protected boolean canCreateNativeImpl() {
+ // clamp if required incl. redefinition of position and size
+ clampRect((ScreenDriver) getScreen(), new Rectangle(getX(), getY(), getWidth(), getHeight()), true);
+ return true; // default: always able to be created
+ }
+
+ @Override
+ protected void createNativeImpl() {
+ if (0 != getParentWindowHandle()) {
+ throw new RuntimeException("Window parenting not supported (yet)");
+ }
+
+ final ScreenDriver screen = (ScreenDriver) getScreen();
+ final DisplayDriver display = (DisplayDriver) screen.getDisplay();
+
+ // Create own screen/device resource instance allowing independent ownership,
+ // while still utilizing shared EGL resources.
+ final AbstractGraphicsScreen aScreen = screen.getGraphicsScreen();
+ // final AbstractGraphicsDevice aDevice = display.getGraphicsDevice();
+ // final EGLGraphicsDevice aDevice = (EGLGraphicsDevice) aScreen.getDevice();
+
+ final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
+ capsRequested, capsRequested, capabilitiesChooser, aScreen, VisualIDHolder.VID_UNDEFINED);
+ if (null == cfg) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
+ final Capabilities chosenCaps = (Capabilities) cfg.getChosenCapabilities();
+ // FIXME: Pass along opaque flag, since EGL doesn't determine it
+ if(capsRequested.isBackgroundOpaque() != chosenCaps.isBackgroundOpaque()) {
+ chosenCaps.setBackgroundOpaque(capsRequested.isBackgroundOpaque());
+ }
+ setGraphicsConfiguration(cfg);
+ final long nativeWindowHandle = CreateWindow0(DisplayDriver.getDrmHandle(), display.getGBMHandle(),
+ getX(), getY(), getWidth(), getHeight(),
+ chosenCaps.isBackgroundOpaque(), chosenCaps.getAlphaBits());
+ if (nativeWindowHandle == 0) {
+ throw new NativeWindowException("Error creating egl window: "+cfg);
+ }
+ setWindowHandle(nativeWindowHandle);
+ if (0 == getWindowHandle()) {
+ throw new NativeWindowException("Error native Window Handle is null");
+ }
+ windowHandleClose = nativeWindowHandle;
+
+ addWindowListener(linuxEventDeviceTracker);
+ addWindowListener(linuxMouseTracker);
+ focusChanged(false, true);
+ }
+
+ @Override
+ protected void closeNativeImpl() {
+ final DisplayDriver display = (DisplayDriver) getScreen().getDisplay();
+ final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) getGraphicsConfiguration().getScreen().getDevice();
+
+ removeWindowListener(linuxMouseTracker);
+ removeWindowListener(linuxEventDeviceTracker);
+
+ if( 0 != windowHandleClose ) {
+ CloseWindow0(display.getGBMHandle(), windowHandleClose);
+ windowHandleClose = 0;
+ }
+
+ eglDevice.close();
+ }
+
+
+ @Override
+ protected void requestFocusImpl(final boolean reparented) {
+ focusChanged(false, true);
+ }
+
+ @Override
+ protected final int getSupportedReconfigMaskImpl() {
+ return minimumReconfigStateMask
+ // | STATE_MASK_UNDECORATED
+ // | STATE_MASK_ALWAYSONTOP
+ // | STATE_MASK_ALWAYSONBOTTOM
+ // | STATE_MASK_STICKY
+ // | STATE_MASK_RESIZABLE
+ // | STATE_MASK_MAXIMIZED_VERT
+ // | STATE_MASK_MAXIMIZED_HORZ
+ // | STATE_MASK_POINTERVISIBLE
+ // | STATE_MASK_POINTERCONFINED
+ ;
+ }
+
+ @Override
+ protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final int flags) {
+ final RectangleImmutable rect = clampRect((ScreenDriver) getScreen(), new Rectangle(x, y, width, height), false);
+ // reconfigure0 will issue position/size changed events if required
+ reconfigure0(getWindowHandle(), rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), flags);
+
+ return true;
+ }
+
+ @Override
+ protected Point getLocationOnScreenImpl(final int x, final int y) {
+ return new Point(x,y);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+ private final LinuxMouseTracker linuxMouseTracker;
+ private final LinuxEventDeviceTracker linuxEventDeviceTracker;
+ private long windowHandleClose;
+
+ protected static native boolean initIDs();
+ private native long CreateWindow0(long drmHandle, long gbmHandle, int x, int y, int width, int height, boolean opaque, int alphaBits);
+ private native void CloseWindow0(long gbmDisplay, long eglWindowHandle);
+ private native void reconfigure0(long eglWindowHandle, int x, int y, int width, int height, int flags);
+
+}
diff --git a/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java
deleted file mode 100644
index 00a1ca384..000000000
--- a/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java
+++ /dev/null
@@ -1,62 +0,0 @@
-//Copyright 2015 Erik De Rijcke
-//
-//Licensed under the Apache License,Version2.0(the"License");
-//you may not use this file except in compliance with the License.
-//You may obtain a copy of the License at
-//
-//http://www.apache.org/licenses/LICENSE-2.0
-//
-//Unless required by applicable law or agreed to in writing,software
-//distributed under the License is distributed on an"AS IS"BASIS,
-//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
-//See the License for the specific language governing permissions and
-//limitations under the License.
-package jogamp.newt.driver.gbm;
-
-import com.jogamp.nativewindow.AbstractGraphicsDevice;
-import com.jogamp.nativewindow.egl.EGLGraphicsDevice;
-import jogamp.newt.DisplayImpl;
-import jogamp.newt.NEWTJNILibLoader;
-import jogamp.opengl.egl.EGLDisplayUtil;
-
-public class DisplayDriver extends DisplayImpl {
-
- static {
- NEWTJNILibLoader.loadNEWT();
- }
-
-
- public static void initSingleton() {
- // just exist to ensure static init has been run
- }
-
- @Override
- protected void createNativeImpl() {
- final EGLGraphicsDevice eglGraphicsDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(initGbm(), AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
- eglGraphicsDevice.open();
-
- this.aDevice = eglGraphicsDevice;
- }
-
- private native long initGbm();
-// {
-//
-//
-// }
-
- @Override
- protected void closeNativeImpl(final AbstractGraphicsDevice aDevice) {
- //DrmLibrary.INSTANCE.drmModeFreeConnector(this.connector);
- aDevice.close();
- destroyDisplay();
- //GbmLibrary.INSTANCE.gbm_device_destroy(dev);
- //CLibrary.INSTANCE.close(this.fd);
- }
-
- private native void destroyDisplay();
-
- @Override
- protected void dispatchMessagesNative() {
- //NA
- }
-}
diff --git a/src/newt/classes/jogamp/newt/driver/gbm/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/gbm/ScreenDriver.java
deleted file mode 100644
index 0066d42e4..000000000
--- a/src/newt/classes/jogamp/newt/driver/gbm/ScreenDriver.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package jogamp.newt.driver.gbm;
-
-import com.jogamp.nativewindow.DefaultGraphicsScreen;
-import com.jogamp.newt.MonitorDevice;
-import com.jogamp.newt.MonitorMode;
-import jogamp.newt.MonitorModeProps;
-import jogamp.newt.ScreenImpl;
-
-public class ScreenDriver extends ScreenImpl {
-
-
- @Override
- protected void createNativeImpl() {
- this.aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(),
- this.screen_idx);
- }
-
- @Override
- protected void closeNativeImpl() {
- }
-
- @Override
- protected int validateScreenIndex(final int idx) {
- return 0;
- }
-
- @Override
- protected void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Cache cache) {
-// DisplayDriver display = (DisplayDriver) getDisplay();
-// final drmModeConnector connector = display.getConnector();
-// final drmModeEncoder encoder = display.getEncoder();
-// //TODO collect info from init method
-// int[] props = new int[MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL];
-// int i = 0;
-// props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL;
-// props[i++] = connector.modes.hdisplay; // width
-// props[i++] = connector.modes.vdisplay; // height
-// props[i++] = ScreenImpl.default_sm_bpp; // FIXME
-// props[i++] = ScreenImpl.default_sm_rate * 100; // FIXME
-// props[i++] = connector.modes.flags; // flags
-// props[i++] = 0; // mode_idx
-// props[i++] = 0; // rotation
-// final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null,
-// cache,
-// props,
-// 0);
-//
-// props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES];
-// i = 0;
-// props[i++] = props.length;
-// props[i++] = encoder.crtc_id; // crt_idx
-// props[i++] = 0; // is-clone
-// props[i++] = 1; // is-primary
-// props[i++] = ScreenImpl.default_sm_widthmm; // FIXME
-// props[i++] = ScreenImpl.default_sm_heightmm; // FIXME
-// props[i++] = 0; // rotated viewport x pixel-units
-// props[i++] = 0; // rotated viewport y pixel-units
-// props[i++] = connector.modes.hdisplay; // rotated viewport width pixel-units
-// props[i++] = connector.modes.vdisplay; // rotated viewport height pixel-units
-// props[i++] = 0; // rotated viewport x window-units
-// props[i++] = 0; // rotated viewport y window-units
-// props[i++] = connector.modes.hdisplay; // rotated viewport width window-units
-// props[i++] = connector.modes.vdisplay; // rotated viewport height window-units
-// MonitorModeProps.streamInMonitorDevice(cache,
-// this,
-// currentMode,
-// null,
-// cache.monitorModes,
-// props,
-// 0,
-// null);
- }
-
- @Override
- protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) {
- //TODO collect info from init method
-
- return null;
- }
-
- @Override
- protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor,
- final MonitorMode mode) {
- //TODO collect info from init method
-
- return false;
- }
-}
diff --git a/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java
deleted file mode 100644
index f4e86ed00..000000000
--- a/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java
+++ /dev/null
@@ -1,120 +0,0 @@
-//Copyright 2015 Erik De Rijcke
-//
-//Licensed under the Apache License,Version2.0(the"License");
-//you may not use this file except in compliance with the License.
-//You may obtain a copy of the License at
-//
-//http://www.apache.org/licenses/LICENSE-2.0
-//
-//Unless required by applicable law or agreed to in writing,software
-//distributed under the License is distributed on an"AS IS"BASIS,
-//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
-//See the License for the specific language governing permissions and
-//limitations under the License.
-package jogamp.newt.driver.gbm;
-
-import com.jogamp.nativewindow.*;
-import com.jogamp.nativewindow.util.Insets;
-import com.jogamp.nativewindow.util.Point;
-import jogamp.newt.WindowImpl;
-import jogamp.newt.driver.linux.LinuxEventDeviceTracker;
-import jogamp.newt.driver.linux.LinuxMouseTracker;
-
-public class WindowDriver extends WindowImpl {
-
- private final LinuxMouseTracker linuxMouseTracker;
- private final LinuxEventDeviceTracker linuxEventDeviceTracker;
-
- public WindowDriver() {
- this.linuxMouseTracker = LinuxMouseTracker.getSingleton();
- this.linuxEventDeviceTracker = LinuxEventDeviceTracker.getSingleton();
- }
-
-
- @Override
- protected final int getSupportedReconfigMaskImpl() {
- return minimumReconfigStateMask;
- }
-
- @Override
- protected void createNativeImpl() {
- if (0 != getParentWindowHandle()) {
- throw new RuntimeException("Window parenting not supported (yet)");
- }
-
- final ScreenDriver screen = (ScreenDriver) getScreen();
- final DisplayDriver display = (DisplayDriver) screen.getDisplay();
-
- // Create own screen/device resource instance allowing independent ownership,
- // while still utilizing shared EGL resources.
- final AbstractGraphicsScreen aScreen = screen.getGraphicsScreen();
- final AbstractGraphicsDevice aDevice = display.getGraphicsDevice();
- final DefaultGraphicsScreen eglScreen = new DefaultGraphicsScreen(aDevice, aScreen.getIndex());
-
- final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
- capsRequested, capsRequested, capabilitiesChooser, eglScreen, VisualIDHolder.VID_UNDEFINED);
- if (null == cfg) {
- throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
- }
- final Capabilities chosenCaps = (Capabilities) cfg.getChosenCapabilities();
- // FIXME: Pass along opaque flag, since EGL doesn't determine it
- if(capsRequested.isBackgroundOpaque() != chosenCaps.isBackgroundOpaque()) {
- chosenCaps.setBackgroundOpaque(capsRequested.isBackgroundOpaque());
- }
- setGraphicsConfiguration(cfg);
- long nativeWindowHandle = createSurface();
- if (nativeWindowHandle == 0) {
- throw new NativeWindowException("Error creating egl window: "+cfg);
- }
- setWindowHandle(nativeWindowHandle);
- if (0 == getWindowHandle()) {
- throw new NativeWindowException("Error native Window Handle is null");
- }
-
- addWindowListener(linuxEventDeviceTracker);
- addWindowListener(linuxMouseTracker);
- focusChanged(false, true);
- }
-
- private native long createSurface();
- //{
- // surface = GbmLibrary.INSTANCE.gbm_surface_create(dev,
-// mode.hdisplay, mode.vdisplay,
-// GbmLibrary.Constants.GBM_FORMAT_XRGB8888,
-// GBM_BO.GBM_BO_USE_SCANOUT | GBM_BO.GBM_BO_USE_RENDERING);
-// if (surface == null) {
-// throw new NativeWindowException("failed to create gbm surface");
-// }
-//
-// return 0;
- //}
-
- @Override
- protected void closeNativeImpl() {
- removeWindowListener(this.linuxMouseTracker);
- removeWindowListener(this.linuxEventDeviceTracker);
- }
-
- @Override
- protected void requestFocusImpl(final boolean force) {
- focusChanged(false,
- true);
- }
-
- @Override
- protected boolean reconfigureWindowImpl(final int x,
- final int y,
- final int width,
- final int height,
- final int flags) {
- return false;
- }
-
- @Override
- protected Point getLocationOnScreenImpl(final int x,
- final int y) {
- return new Point(x,
- y);
- }
-
-}
diff --git a/src/newt/native/bcm_vc_iv.c b/src/newt/native/bcm_vc_iv.c
index dc753157e..9e6a41a1d 100644
--- a/src/newt/native/bcm_vc_iv.c
+++ b/src/newt/native/bcm_vc_iv.c
@@ -299,10 +299,6 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_vc_iv_DisplayDriver_MovePoint
JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_bcm_vc_iv_ScreenDriver_initIDs
(JNIEnv *env, jclass clazz)
{
- uint32_t screen_width;
- uint32_t screen_height;
- int32_t success = 0;
-
setScreenSizeID = (*env)->GetMethodID(env, clazz, "setScreenSize", "(II)V");
if (setScreenSizeID == NULL) {
DBG_PRINT( "BCM.Screen initIDs FALSE\n" );
diff --git a/src/newt/native/egl_gbm.c b/src/newt/native/egl_gbm.c
new file mode 100644
index 000000000..87a402eed
--- /dev/null
+++ b/src/newt/native/egl_gbm.c
@@ -0,0 +1,237 @@
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include "jogamp_newt_driver_egl_gbm_DisplayDriver.h"
+#include "jogamp_newt_driver_egl_gbm_ScreenDriver.h"
+#include "jogamp_newt_driver_egl_gbm_WindowDriver.h"
+
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include <gbm.h>
+
+// #define VERBOSE_ON 1
+
+#ifdef VERBOSE_ON
+ #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
+#else
+ #define DBG_PRINT(...)
+#endif
+
+typedef struct {
+ int fd; // drmClose
+ drmModeRes *resources; // drmModeFreeResources
+ drmModeConnector *connector; // drmModeFreeConnector
+ drmModeEncoder *encoder; // drmModeFreeEncoder
+ drmModeModeInfo *current_mode;
+} DRM_HANDLE;
+
+typedef struct {
+ struct gbm_bo *bo;
+ uint32_t fb_id;
+} DRM_GBM_FB;
+
+static jmethodID notifyScreenModeID = NULL;
+
+/**
+ * Display
+ */
+
+static void freeDrm(DRM_HANDLE *drm) {
+ if( NULL != drm ) {
+ if( NULL != drm->encoder ) {
+ drmModeFreeEncoder(drm->encoder);
+ drm->encoder = NULL;
+ }
+ if( NULL != drm->connector ) {
+ drmModeFreeConnector(drm->connector);
+ drm->connector = NULL;
+ }
+ if( NULL != drm->resources ) {
+ drmModeFreeResources(drm->resources);
+ drm->resources = NULL;
+ }
+ if( 0 != drm->fd ) {
+ drmClose(drm->fd);
+ drm->fd = 0;
+ }
+ free(drm);
+ }
+}
+
+JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_initIDs
+ (JNIEnv *env, jclass clazz)
+{
+ DBG_PRINT( "EGL_GBM.Display initIDs ok\n" );
+ return JNI_TRUE;
+}
+
+JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_initDrm
+ (JNIEnv *env, jclass clazz)
+{
+ static const char *modules[] = {
+ "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "msm"
+ };
+ int i, area;
+ DRM_HANDLE *drm = calloc(1, sizeof(DRM_HANDLE));
+
+ for (i = 0; i < 6 /* ARRAY_SIZE(modules) */; i++) {
+ printf("trying to load module %s...", modules[i]);
+ drm->fd = drmOpen(modules[i], NULL);
+ if (drm->fd < 0) {
+ printf("failed.\n");
+ } else {
+ printf("success.\n");
+ break;
+ }
+ }
+
+ if (drm->fd < 0) {
+ printf("could not open drm device\n");
+ goto error;
+ }
+
+ drm->resources = drmModeGetResources(drm->fd);
+ if ( NULL == drm->resources ) {
+ printf("drmModeGetResources failed: %s\n", strerror(errno));
+ goto error;
+ }
+
+ /* find a connected connector: */
+ for (i = 0; i < drm->resources->count_connectors; i++) {
+ drm->connector = drmModeGetConnector(drm->fd, drm->resources->connectors[i]);
+ if (drm->connector->connection == DRM_MODE_CONNECTED) {
+ /* it's connected, let's use this! */
+ break;
+ }
+ /* we could be fancy and listen for hotplug events and wait for
+ * a connector..
+ */
+ printf("no connected connector!\n");
+ goto error;
+ }
+
+ /* find highest resolution mode: */
+ for (i = 0, area = 0; i < drm->connector->count_modes; i++) {
+ drmModeModeInfo *current_mode = &drm->connector->modes[i];
+ int current_area = current_mode->hdisplay * current_mode->vdisplay;
+ if (current_area > area) {
+ drm->current_mode = current_mode;
+ area = current_area;
+ }
+ }
+
+ if ( NULL == drm->current_mode ) {
+ printf("could not find mode!\n");
+ goto error;
+ }
+
+ /* find encoder: */
+ for (i = 0; i < drm->resources->count_encoders; i++) {
+ drm->encoder = drmModeGetEncoder(drm->fd, drm->resources->encoders[i]);
+ if (drm->encoder->encoder_id == drm->connector->encoder_id) {
+ break;
+ }
+ printf("no encoder!\n");
+ goto error;
+ }
+
+ // drm->crtc_id = encoder->crtc_id;
+ // drm->connector_id = connector->connector_id;
+ return (jlong) (intptr_t) drm;
+
+error:
+ freeDrm(drm);
+ return 0;
+}
+
+JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_freeDrm
+ (JNIEnv *env, jclass clazz, jlong jdrm) {
+ freeDrm( (DRM_HANDLE*) (intptr_t) jdrm );
+}
+
+JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_OpenGBMDisplay0
+ (JNIEnv *env, jclass clazz, jlong jdrm)
+{
+ DRM_HANDLE *drm = (DRM_HANDLE*) (intptr_t) jdrm;
+ struct gbm_device * dev = gbm_create_device(drm->fd);
+ return (jlong) (intptr_t) dev;
+}
+
+JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_CloseGBMDisplay0
+ (JNIEnv *env, jclass clazz, jlong jgbm)
+{
+ struct gbm_device * dev = (struct gbm_device *) (intptr_t) jgbm;
+ gbm_device_destroy(dev);
+}
+
+/**
+ * Screen
+ */
+JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_egl_gbm_ScreenDriver_initIDs
+ (JNIEnv *env, jclass clazz)
+{
+ notifyScreenModeID = (*env)->GetMethodID(env, clazz, "notifyScreenMode", "(III)V");
+ if (notifyScreenModeID == NULL) {
+ DBG_PRINT( "EGL_GBM.Screen initIDs FALSE\n" );
+ return JNI_FALSE;
+ }
+ DBG_PRINT( "EGL_GBM.Screen initIDs ok\n" );
+ return JNI_TRUE;
+}
+
+JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_ScreenDriver_initNative
+ (JNIEnv *env, jobject obj, jlong jdrm)
+{
+ DRM_HANDLE *drm = (DRM_HANDLE*) (intptr_t) jdrm;
+ uint32_t screen_width = 0;
+ uint32_t screen_height = 0;
+ uint32_t screen_vrefresh = 0;
+ int32_t success = 0;
+
+ if( NULL != drm ) {
+ /**
+ connector.modes.hdisplay; // width
+ connector.modes.vdisplay; // height
+ connector.modes.flags; // flags
+ encoder.crtc_id; // crt_idx
+ */
+ screen_width = drm->current_mode->hdisplay;
+ screen_height = drm->current_mode->vdisplay;
+ screen_vrefresh = drm->current_mode->vrefresh;
+
+ DBG_PRINT( "EGL_GBM.Screen initNative ok %dx%d @ %d\n", screen_width, screen_height, screen_vrefresh );
+ (*env)->CallVoidMethod(env, obj, notifyScreenModeID, (jint) screen_width, (jint) screen_height, (jint) screen_vrefresh);
+ } else {
+ DBG_PRINT( "BCM.Screen initNative failed\n" );
+ }
+}
+
+/**
+ * Window
+ */
+
+JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_CreateWindow0
+ (JNIEnv *env, jobject obj, jlong jdrm, jlong jgbm, jint x, jint y, jint width, jint height, jboolean opaque, jint alphaBits)
+{
+ DRM_HANDLE *drm = (DRM_HANDLE*) (intptr_t) jdrm;
+ struct gbm_device *dev = (struct gbm_device *) (intptr_t) jgbm;
+
+ struct gbm_surface *surface = gbm_surface_create(dev,
+ drm->current_mode->hdisplay, drm->current_mode->vdisplay,
+ opaque ? GBM_FORMAT_XRGB8888 : GBM_BO_FORMAT_ARGB8888,
+ GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+ if ( NULL == surface ) {
+ printf("failed to create gbm surface\n");
+ return -1;
+ }
+ return (jlong) (intptr_t) surface;
+}
+
+JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_CloseWindow0
+ (JNIEnv *env, jobject obj, jlong display, jlong window)
+{
+ struct gbm_surface *surface = (struct gbm_surface *) (intptr_t) window;
+ gbm_surface_destroy(surface);
+}
+
diff --git a/src/newt/native/gbm.c b/src/newt/native/gbm.c
deleted file mode 100644
index 927faa47e..000000000
--- a/src/newt/native/gbm.c
+++ /dev/null
@@ -1,147 +0,0 @@
-#include <errno.h>
-#include <string.h>
-
-#include "jogamp_newt_driver_gbm_DisplayDriver.h"
-#include "jogamp_newt_driver_gbm_ScreenDriver.h"
-#include "jogamp_newt_driver_gbm_WindowDriver.h"
-
-#include <xf86drm.h>
-#include <xf86drmMode.h>
-#include <gbm.h>
-
-static struct {
- struct gbm_device *dev;
- struct gbm_surface *surface;
-} gbm;
-
-static struct {
- int fd;
- drmModeModeInfo *mode;
- uint32_t crtc_id;
- uint32_t connector_id;
-} drm;
-
-struct drm_fb {
- struct gbm_bo *bo;
- uint32_t fb_id;
-};
-
-/*
- * Class: jogamp_newt_driver_gbm_DisplayDriver
- * Method: initGbm
- * Signature: (J)V
- */
-JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_initGbm
- (JNIEnv *env, jobject this){
- static const char *modules[] = {
- "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "msm"
- };
- drmModeRes *resources;
- drmModeConnector *connector = NULL;
- drmModeEncoder *encoder = NULL;
- int i, area;
-
- for (i = 0; i < 6 /* ARRAY_SIZE(modules) */; i++) {
- printf("trying to load module %s...", modules[i]);
- drm.fd = drmOpen(modules[i], NULL);
- if (drm.fd < 0) {
- printf("failed.\n");
- } else {
- printf("success.\n");
- break;
- }
- }
-
- if (drm.fd < 0) {
- printf("could not open drm device\n");
- return -1;
- }
-
- resources = drmModeGetResources(drm.fd);
- if (!resources) {
- printf("drmModeGetResources failed: %s\n", strerror(errno));
- return -1;
- }
-
- /* find a connected connector: */
- for (i = 0; i < resources->count_connectors; i++) {
- connector = drmModeGetConnector(drm.fd, resources->connectors[i]);
- if (connector->connection == DRM_MODE_CONNECTED) {
- /* it's connected, let's use this! */
- break;
- }
- drmModeFreeConnector(connector);
- connector = NULL;
- }
-
- if (!connector) {
- /* we could be fancy and listen for hotplug events and wait for
- * a connector..
- */
- printf("no connected connector!\n");
- return -1;
- }
-
- /* find highest resolution mode: */
- for (i = 0, area = 0; i < connector->count_modes; i++) {
- drmModeModeInfo *current_mode = &connector->modes[i];
- int current_area = current_mode->hdisplay * current_mode->vdisplay;
- if (current_area > area) {
- drm.mode = current_mode;
- area = current_area;
- }
- }
-
- if (!drm.mode) {
- printf("could not find mode!\n");
- return -1;
- }
-
- /* find encoder: */
- for (i = 0; i < resources->count_encoders; i++) {
- encoder = drmModeGetEncoder(drm.fd, resources->encoders[i]);
- if (encoder->encoder_id == connector->encoder_id)
- break;
- drmModeFreeEncoder(encoder);
- encoder = NULL;
- }
-
- if (!encoder) {
- printf("no encoder!\n");
- return -1;
- }
-
- drm.crtc_id = encoder->crtc_id;
- drm.connector_id = connector->connector_id;
-
- gbm.dev = gbm_create_device(drm.fd);
-
- return gbm.dev;
- }
-
-/*
- * Class: jogamp_newt_driver_gbm_DisplayDriver
- * Method: destroyDisplay
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_destroyDisplay
- (JNIEnv *env, jobject this){
- }
-
-/*
- * Class: jogamp_newt_driver_gbm_WindowDriver
- * Method: createSurface
- * Signature: (J)J
- */
-JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_gbm_WindowDriver_createSurface
- (JNIEnv *env, jobject this){
- gbm.surface = gbm_surface_create(gbm.dev,
- drm.mode->hdisplay, drm.mode->vdisplay,
- GBM_FORMAT_XRGB8888,
- GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
- if (!gbm.surface) {
- printf("failed to create gbm surface\n");
- return -1;
- }
- return gbm.surface;
- }