diff options
Diffstat (limited to 'src')
20 files changed, 1360 insertions, 731 deletions
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java index d5ab61e20..4dd09ebbd 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java @@ -213,7 +213,7 @@ public class EGLDisplayUtil { case NativeWindowFactory.TYPE_ANDROID: eglPlatform = EGLExt.EGL_PLATFORM_ANDROID_KHR; break; - case NativeWindowFactory.TYPE_EGL_GBM: + case NativeWindowFactory.TYPE_DRM_GBM: eglPlatform = EGLExt.EGL_PLATFORM_GBM_KHR; // same EGLExt.EGL_PLATFORM_GBM_MESA; break; case NativeWindowFactory.TYPE_WAYLAND: diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java index 8c9656354..eda2610a4 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java @@ -49,10 +49,13 @@ import com.jogamp.nativewindow.AbstractGraphicsScreen; import com.jogamp.nativewindow.DefaultGraphicsScreen; import com.jogamp.nativewindow.MutableSurface; import com.jogamp.nativewindow.NativeSurface; +import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.NativeWindowFactory; import com.jogamp.nativewindow.ProxySurface; import com.jogamp.nativewindow.UpstreamSurfaceHook; +import com.jogamp.nativewindow.UpstreamSurfaceHookMutableSize; import com.jogamp.nativewindow.VisualIDHolder; +import com.jogamp.nativewindow.VisualIDHolder.VIDType; import com.jogamp.opengl.GL; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLCapabilitiesChooser; @@ -64,6 +67,9 @@ import com.jogamp.opengl.GLException; import com.jogamp.opengl.GLProfile; import jogamp.common.os.PlatformPropsImpl; +import jogamp.nativewindow.drm.DRMLib; +import jogamp.nativewindow.drm.DRMUtil; +import jogamp.nativewindow.drm.GBMDummyUpstreamSurfaceHook; import jogamp.opengl.Debug; import jogamp.opengl.GLContextImpl; import jogamp.opengl.GLContextImpl.MappedGLVersion; @@ -100,6 +106,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { private static GLDynamicLookupHelper eglGLnDynamicLookupHelper = null; private static boolean isANGLE = false; private static boolean hasX11 = false; + private static boolean isDRM_GBM = false; private static String defaultConnection = null; private static EGLGraphicsDevice defaultDevice = null; private static EGLFeatures defaultDeviceEGLFeatures = null; @@ -205,6 +212,12 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } else { hasX11 = false; } + if(NativeWindowFactory.TYPE_DRM_GBM == nwt) { + isDRM_GBM = true; + } else { + isDRM_GBM = false; + } + defaultConnection = NativeWindowFactory.getDefaultDisplayConnection(nwt); /** @@ -346,7 +359,13 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { // Note: defaultDevice.open() triggers eglInitialize(..) which crashed on Windows w/ Chrome/ANGLE, FF/ANGLE! // Hence opening will happen later, eventually - defaultDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, defaultConnection, AbstractGraphicsDevice.DEFAULT_UNIT); + final long nativeDisplayID; + if( isDRM_GBM ) { // Bug 1402 related and in case surfaceless is n/a + nativeDisplayID = DRMLib.gbm_create_device(DRMUtil.getDrmFd()); + } else { + nativeDisplayID = EGL.EGL_DEFAULT_DISPLAY; + } + defaultDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(nativeDisplayID, defaultConnection, AbstractGraphicsDevice.DEFAULT_UNIT); // Init shared resources off thread // Will be released via ShutdownHook @@ -379,6 +398,9 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } if(null != defaultDevice) { + if( isDRM_GBM ) { // Bug 1402 related and in case surfaceless is n/a + DRMLib.gbm_device_destroy(defaultDevice.getNativeDisplayID()); + } defaultDevice.close(); defaultDevice = null; } @@ -690,7 +712,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { System.err.println("EGLDrawableFactory.MapGLVersions: "+profileString+" ( "+majorVersion+" ), "+ "mapsADeviceToDefaultDevice "+mapsADeviceToDefaultDevice[0]+ " (useDefaultDevice "+useDefaultDevice+", defaultDeviceHasPBuffer "+defaultDeviceHasPBuffer+", hasDesktopFactory "+(null != desktopFactory)+ - ", isEGLGraphicsDevice "+(adevice instanceof EGLGraphicsDevice)+")"); + ", isEGLGraphicsDevice "+(adevice instanceof EGLGraphicsDevice)+"), isDRM_GBM "+isDRM_GBM); } if( mapsADeviceToDefaultDevice[0] ) { @@ -700,13 +722,16 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { final boolean defaultNoSurfacelessCtx = GLRendererQuirks.existStickyDeviceQuirk(defaultDevice, GLRendererQuirks.NoSurfacelessCtx); boolean success = false; final boolean hasKHRSurfacelessTried; - if( defaultDeviceEGLFeatures.hasKHRSurfaceless && !defaultNoSurfacelessCtx ) { + if( defaultDeviceEGLFeatures.hasKHRSurfaceless && !defaultNoSurfacelessCtx + && ( !isDRM_GBM || isDRM_GBM && useDefaultDevice ) ) + { + // Includes mapping DRM_GBM EGL device to EGL default shared resources (default behavior), surfaceless. hasKHRSurfacelessTried = true; final AbstractGraphicsDevice zdevice = useDefaultDevice ? defaultDevice : adevice; // reuse final EGLSurface zeroSurface = createSurfacelessImpl(zdevice, false, reqCapsAny, reqCapsAny, null, 64, 64); resEGLDevice[0] = (EGLGraphicsDevice) zeroSurface.getGraphicsConfiguration().getScreen().getDevice(); if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.0: "+resEGLDevice[0]); + System.err.println("EGLDrawableFactory.MapGLVersions.0: "+resEGLDevice[0]); } EGLDrawable zeroDrawable = null; EGLContext context = null; @@ -730,12 +755,12 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { setNoSurfacelessCtxQuirk(context); } } else if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.0: NOT_CURRENT: "+resEGLDevice[0]+", "+context); + System.err.println("EGLDrawableFactory.MapGLVersions.0: NOT_CURRENT: "+resEGLDevice[0]+", "+context); } } catch (final Throwable t) { hasException = true; if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.0: INFO: context create/makeCurrent failed"); + System.err.println("EGLDrawableFactory.MapGLVersions.0: INFO: context create/makeCurrent failed"); t.printStackTrace(); } } finally { @@ -744,7 +769,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { context.destroy(); } catch (final GLException gle) { if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.0: INFO: destroy caught exception:"); + System.err.println("EGLDrawableFactory.MapGLVersions.0: INFO: destroy caught exception:"); gle.printStackTrace(); } } @@ -777,13 +802,26 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { ProxySurface upstreamSurface = null; // X11, GLX, .. ProxySurface downstreamSurface = null; // EGL try { - if( useDefaultDevice && defaultDeviceHasPBuffer ) { + if( useDefaultDevice && isDRM_GBM ) { + // Map DRM_GBM EGL device to EGL default shared resources (default behavior), using a GBM dummy surface + resEGLDevice[0] = defaultDevice; // reuse + eglFeatures = defaultDeviceEGLFeatures; + if ( DEBUG_SHAREDCTX ) { + System.err.println("EGLDrawableFactory.MapGLVersions.1: "+resEGLDevice[0]); + System.err.println("EGLDrawableFactory.MapGLVersions.1: "+eglFeatures); + } + downstreamSurface = createDummySurfaceImpl(resEGLDevice[0], false, reqCapsAny, reqCapsAny, null, 64, 64); + if( null != downstreamSurface ) { + downstreamSurface.createNotify(); + surface = downstreamSurface; + } + } else if( useDefaultDevice && defaultDeviceHasPBuffer ) { // Map any non EGL device to EGL default shared resources (default behavior), using a pbuffer surface resEGLDevice[0] = defaultDevice; // reuse eglFeatures = defaultDeviceEGLFeatures; if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.1: "+resEGLDevice[0]); - System.err.println("EGLDrawableFactory-MapGLVersions.1: "+eglFeatures); + System.err.println("EGLDrawableFactory.MapGLVersions.2: "+resEGLDevice[0]); + System.err.println("EGLDrawableFactory.MapGLVersions.2: "+eglFeatures); } downstreamSurface = createDummySurfaceImpl(resEGLDevice[0], false, reqCapsPBuffer, reqCapsPBuffer, null, 64, 64); @@ -791,9 +829,8 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { downstreamSurface.createNotify(); surface = downstreamSurface; } - } else if( adevice != defaultDevice ) { + } else if( !useDefaultDevice && !isDRM_GBM ) { // Create a true mapping of given device to EGL - // FIXME !!!! EGL-GBM upstreamSurface = desktopFactory.createDummySurface(adevice, reqCapsAny, null, 64, 64); // X11, WGL, .. dummy window if(null != upstreamSurface) { upstreamSurface.createNotify(); @@ -801,8 +838,8 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { resEGLDevice[0].open(); eglFeatures = new EGLFeatures(resEGLDevice[0]); if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.2: "+resEGLDevice[0]); - System.err.println("EGLDrawableFactory-MapGLVersions.2: "+eglFeatures); + System.err.println("EGLDrawableFactory.MapGLVersions.3: "+resEGLDevice[0]); + System.err.println("EGLDrawableFactory.MapGLVersions.3: "+eglFeatures); } surface = upstreamSurface; } @@ -835,15 +872,15 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { setNoSurfacelessCtxQuirk(context); } } else if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.12: NULL VERSION: "+resEGLDevice[0]+", "+context.getGLVersion()); + System.err.println("EGLDrawableFactory.MapGLVersions.123: NULL VERSION: "+resEGLDevice[0]+", "+context.getGLVersion()); } } else if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.12: NOT_CURRENT: "+resEGLDevice[0]+", "+context); + System.err.println("EGLDrawableFactory.MapGLVersions.123: NOT_CURRENT: "+resEGLDevice[0]+", "+context); } } } catch (final Throwable t) { if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.12: INFO: context create/makeCurrent failed"); + System.err.println("EGLDrawableFactory.MapGLVersions.123: INFO: context create/makeCurrent failed"); t.printStackTrace(); } success = false; @@ -853,7 +890,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { context.destroy(); } catch (final GLException gle) { if ( DEBUG_SHAREDCTX ) { - System.err.println("EGLDrawableFactory-MapGLVersions.12: INFO: destroy caught exception:"); + System.err.println("EGLDrawableFactory.MapGLVersions.123: INFO: destroy caught exception:"); gle.printStackTrace(); } } @@ -915,11 +952,25 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { * switching the API via 'eglBindAPI(EGL_OpenGL_API)' the latter 'eglCreateContext(..)' fails w/ EGL_BAD_ACCESS. * Hence we require both: OpenGL API support _and_ 'EGL_KHR_create_context'. * - * Using EGL_GBM, i.e. EGLExt.EGL_PLATFORM_GBM_KHR, we get an unsatisfied linkage error using desktop GL !! + * TODO Bug 1401: Mesa 18.3.6 issues using EGL_PLATFORM_GBM_KHR and OpenGL Desktop Profile + * Using EGL_GBM with OpenGL results in an unsatisfied linkage error using desktop GL, see: + * + * java.lang.UnsatisfiedLinkError: 'int jogamp.opengl.gl4.GL4bcImpl.dispatch_glGetError1(long)' + * at jogamp.opengl.gl4.GL4bcImpl.dispatch_glGetError1(Native Method) + * at jogamp.opengl.gl4.GL4bcImpl.glGetError(GL4bcImpl.java:648) + * at jogamp.opengl.GLContextImpl.setGLFunctionAvailability(GLContextImpl.java:2186) + * at jogamp.opengl.GLContextImpl.createContextARBVersions(GLContextImpl.java:1427) + * at jogamp.opengl.GLContextImpl.createContextARBMapVersionsAvailable(GLContextImpl.java:1366) + * at jogamp.opengl.GLContextImpl.mapGLVersions(GLContextImpl.java:1223) + * at jogamp.opengl.GLContextImpl.createContextARB(GLContextImpl.java:968) + * at jogamp.opengl.egl.EGLContext.createImpl(EGLContext.java:318) + * at jogamp.opengl.GLContextImpl.makeCurrentWithinLock(GLContextImpl.java:769) + * at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:652) + * at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:590) + * at jogamp.opengl.egl.EGLDrawableFactory$SharedResourceImplementation.mapAvailableEGLESConfig(EGLDrawableFactory.java:858) */ return null != eglGLnDynamicLookupHelper && - defaultDeviceEGLFeatures.hasGLAPI && defaultDeviceEGLFeatures.hasKHRCreateContext && - false; // hack + defaultDeviceEGLFeatures.hasGLAPI && defaultDeviceEGLFeatures.hasKHRCreateContext && !isDRM_GBM; } /** @@ -1051,7 +1102,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { private final EGLGraphicsConfiguration evalConfig(final boolean[] ownDevice, final AbstractGraphicsDevice deviceReq, final boolean createNewDevice, final GLCapabilitiesImmutable capsChosen, final GLCapabilitiesImmutable capsRequested, - final GLCapabilitiesChooser chooser) { + final GLCapabilitiesChooser chooser, final int nativeVisualID) { final EGLGraphicsDevice device; if( createNewDevice || ! (deviceReq instanceof EGLGraphicsDevice) ) { device = EGLDisplayUtil.eglCreateEGLGraphicsDevice(deviceReq); @@ -1062,7 +1113,8 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { ownDevice[0] = false; } final DefaultGraphicsScreen screen = new DefaultGraphicsScreen(device, 0); - final EGLGraphicsConfiguration config = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, VisualIDHolder.VID_UNDEFINED, false); + final EGLGraphicsConfiguration config = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( + capsChosen, capsRequested, chooser, screen, nativeVisualID, false); if(null == config) { throw new GLException("Choosing GraphicsConfiguration failed w/ "+capsChosen+" on "+screen); } @@ -1071,26 +1123,42 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { @Override protected final EGLSurface createMutableSurfaceImpl(final AbstractGraphicsDevice deviceReq, final boolean createNewDevice, - final GLCapabilitiesImmutable capsChosen, final GLCapabilitiesImmutable capsRequested, - final GLCapabilitiesChooser chooser, final UpstreamSurfaceHook upstreamHook) { + final GLCapabilitiesImmutable capsChosen, final GLCapabilitiesImmutable capsRequested, + final GLCapabilitiesChooser chooser, + final UpstreamSurfaceHook upstreamHook) { + return createMutableSurfaceImpl2(deviceReq, createNewDevice, capsChosen, capsRequested, chooser, VisualIDHolder.VID_UNDEFINED, upstreamHook); + } + private final EGLSurface createMutableSurfaceImpl2(final AbstractGraphicsDevice deviceReq, final boolean createNewDevice, + final GLCapabilitiesImmutable capsChosen, final GLCapabilitiesImmutable capsRequested, + final GLCapabilitiesChooser chooser, final int nativeVisualID, + final UpstreamSurfaceHook upstreamHook) { final boolean[] ownDevice = { false }; - final EGLGraphicsConfiguration config = evalConfig(ownDevice, deviceReq, createNewDevice, capsChosen, capsRequested, chooser); + final EGLGraphicsConfiguration config = evalConfig(ownDevice, deviceReq, createNewDevice, capsChosen, capsRequested, chooser, nativeVisualID); return EGLSurface.createWrapped(config, 0, upstreamHook, ownDevice[0]); } @Override public final EGLSurface createDummySurfaceImpl(final AbstractGraphicsDevice deviceReq, final boolean createNewDevice, - GLCapabilitiesImmutable chosenCaps, final GLCapabilitiesImmutable requestedCaps, final GLCapabilitiesChooser chooser, final int width, final int height) { - chosenCaps = GLGraphicsConfigurationUtil.fixGLPBufferGLCapabilities(chosenCaps); // complete validation in EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(..) above - return createMutableSurfaceImpl(deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser, new EGLDummyUpstreamSurfaceHook(width, height)); + GLCapabilitiesImmutable chosenCaps, final GLCapabilitiesImmutable requestedCaps, final GLCapabilitiesChooser chooser, final int width, final int height) { + final UpstreamSurfaceHook ush; + final int nativeVisualID; + if( isDRM_GBM ) { + ush = new GBMDummyUpstreamSurfaceHook(width, height); + nativeVisualID = DRMUtil.GBM_FORMAT_XRGB8888; + } else { + ush = new EGLDummyUpstreamSurfaceHook(width, height); + chosenCaps = GLGraphicsConfigurationUtil.fixGLPBufferGLCapabilities(chosenCaps); // complete validation in EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(..) above + nativeVisualID = VisualIDHolder.VID_UNDEFINED; + } + return createMutableSurfaceImpl2(deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser, nativeVisualID, ush); } @Override public final EGLSurface createSurfacelessImpl(final AbstractGraphicsDevice deviceReq, final boolean createNewDevice, - GLCapabilitiesImmutable chosenCaps, final GLCapabilitiesImmutable requestedCaps, final GLCapabilitiesChooser chooser, final int width, final int height) { + GLCapabilitiesImmutable chosenCaps, final GLCapabilitiesImmutable requestedCaps, final GLCapabilitiesChooser chooser, final int width, final int height) { chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(chosenCaps); final boolean[] ownDevice = { false }; - final EGLGraphicsConfiguration config = evalConfig(ownDevice, deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser); + final EGLGraphicsConfiguration config = evalConfig(ownDevice, deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser, VisualIDHolder.VID_UNDEFINED); return EGLSurface.createSurfaceless(config, new GenericUpstreamSurfacelessHook(width, height), ownDevice[0]); } diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java index 7e54152bf..5fd0535ad 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java @@ -113,15 +113,22 @@ public class EGLGraphicsConfiguration extends MutableGraphicsConfiguration imple void updateGraphicsConfiguration() { final CapabilitiesImmutable capsChosen = getChosenCapabilities(); - final EGLGraphicsConfiguration newConfig = (EGLGraphicsConfiguration) - GraphicsConfigurationFactory.getFactory(getScreen().getDevice(), capsChosen).chooseGraphicsConfiguration( - capsChosen, getRequestedCapabilities(), chooser, getScreen(), VisualIDHolder.VID_UNDEFINED); - if(null!=newConfig) { - // FIXME: setScreen( ... ); - setChosenCapabilities(newConfig.getChosenCapabilities()); - if(DEBUG) { - System.err.println("updateGraphicsConfiguration(1): "+this); + if( VisualIDHolder.VID_UNDEFINED == capsChosen.getVisualID(VIDType.NATIVE) ) { + final EGLGraphicsConfiguration newConfig = (EGLGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(getScreen().getDevice(), capsChosen).chooseGraphicsConfiguration( + capsChosen, getRequestedCapabilities(), chooser, getScreen(), VisualIDHolder.VID_UNDEFINED); + if(null!=newConfig) { + // FIXME: setScreen( ... ); + setChosenCapabilities(newConfig.getChosenCapabilities()); + if(DEBUG) { + System.err.println("EGLGraphicsConfiguration.updateGraphicsConfiguration updated: "+this); + } + } else { + throw new GLException("No native VisualID pre-chosen and update failed: "+this); } + } else if (DEBUG) { + System.err.println("EGLGraphicsConfiguration.updateGraphicsConfiguration kept:"+this); + } } diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java index 929be16e3..1d9a9732d 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java @@ -219,6 +219,18 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact return availableCaps; } + /** + * Called mainly by {@link #chooseGraphicsConfigurationImpl(CapabilitiesImmutable, CapabilitiesImmutable, CapabilitiesChooser, AbstractGraphicsScreen, int)} + * @param capsChosen the intermediate chosen capabilities to be refined by this implementation, may be equal to capsRequested + * @param capsReq the original requested capabilities + * @param chooser the choosing implementation + * @param absScreen the referring Screen + * @param nativeVisualID if not {@link VisualIDHolder#VID_UNDEFINED} it reflects a pre-chosen visualID of the native platform's windowing system. + * @param forceTransparentFlag + * @return the complete GraphicsConfiguration + * @see #chooseGraphicsConfigurationImpl(CapabilitiesImmutable, CapabilitiesImmutable, CapabilitiesChooser, AbstractGraphicsScreen, int) + * @see GraphicsConfigurationFactory#chooseGraphicsConfiguration(CapabilitiesImmutable, CapabilitiesImmutable, CapabilitiesChooser, AbstractGraphicsScreen, int) + */ public static EGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilitiesImmutable capsChosen, final GLCapabilitiesImmutable capsReq, final GLCapabilitiesChooser chooser, diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/GraphicsConfigurationFactory.java index 929af054e..5214dbf3d 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/GraphicsConfigurationFactory.java @@ -427,6 +427,24 @@ public abstract class GraphicsConfigurationFactory { } } + /** + * Called by {@link #chooseGraphicsConfiguration(CapabilitiesImmutable, CapabilitiesImmutable, CapabilitiesChooser, AbstractGraphicsScreen, int)} + * post argument validation within {@link AbstractGraphicsDevice#lock()}ed segment. + * + * @param capsChosen the intermediate chosen capabilities to be refined by this implementation, may be equal to capsRequested + * @param capsRequested the original requested capabilities + * @param chooser the choosing implementation + * @param screen the referring Screen + * @param nativeVisualID if not {@link VisualIDHolder#VID_UNDEFINED} it reflects a pre-chosen visualID of the native platform's windowing system. + * @return the complete GraphicsConfiguration + * + * @throws IllegalArgumentException if the data type of the passed + * AbstractGraphicsDevice is not supported by this + * NativeWindowFactory. + * @throws NativeWindowException if any window system-specific errors caused + * the selection of the graphics configuration to fail. + * @see #chooseGraphicsConfiguration(CapabilitiesImmutable, CapabilitiesImmutable, CapabilitiesChooser, AbstractGraphicsScreen, int) + */ protected abstract AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl(CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, CapabilitiesChooser chooser, AbstractGraphicsScreen screen, int nativeVisualID) diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java index a41e9c349..d4249d404 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java @@ -86,8 +86,8 @@ public abstract class NativeWindowFactory { /** Wayland/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}.*/ public static final String TYPE_WAYLAND = ".wayland"; - /** GBM/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}.*/ - public static final String TYPE_EGL_GBM = ".egl.gbm"; + /** DRM/GBM type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}.*/ + public static final String TYPE_DRM_GBM = ".egl.gbm"; // We leave the sub-package name as .egl.gbm for NEWT as it uses EGL /** OpenKODE/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}.*/ public static final String TYPE_EGL = ".egl"; @@ -128,6 +128,8 @@ public abstract class NativeWindowFactory { private static final String JAWTUtilClassName = "jogamp.nativewindow.jawt.JAWTUtil" ; /** {@link jogamp.nativewindow.x11.X11Util} implements {@link ToolkitProperties}. */ private static final String X11UtilClassName = "jogamp.nativewindow.x11.X11Util"; + /** {@link jogamp.nativewindow.drm.DRMUtil} implements {@link ToolkitProperties}. */ + private static final String DRMUtilClassName = "jogamp.nativewindow.drm.DRMUtil"; /** {@link jogamp.nativewindow.macosx.OSXUtil} implements {@link ToolkitProperties}. */ private static final String OSXUtilClassName = "jogamp.nativewindow.macosx.OSXUtil"; /** {@link jogamp.nativewindow.ios.IOSUtil} implements {@link ToolkitProperties}. */ @@ -181,7 +183,7 @@ public abstract class NativeWindowFactory { return TYPE_WAYLAND; } if( guessGBM(false) ) { - return TYPE_EGL_GBM; + return TYPE_DRM_GBM; } if( BcmVCArtifacts.guessVCIVUsed(false) ) { return TYPE_BCM_VC_IV; @@ -259,6 +261,9 @@ public abstract class NativeWindowFactory { case TYPE_X11: clazzName = X11UtilClassName; break; + case TYPE_DRM_GBM: + clazzName = DRMUtilClassName; + break; case TYPE_WINDOWS: clazzName = GDIClassName; break; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/VisualIDHolder.java b/src/nativewindow/classes/com/jogamp/nativewindow/VisualIDHolder.java index 69bfe50f8..62b73d230 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/VisualIDHolder.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/VisualIDHolder.java @@ -40,13 +40,13 @@ import java.util.Comparator; public interface VisualIDHolder { public enum VIDType { - // Generic Values + /** Generic Values */ INTRINSIC(0), NATIVE(1), - // EGL Values + /** EGL Values */ EGL_CONFIG(10), - // X11 Values + /** X11 Values */ X11_XVISUAL(20), X11_FBCONFIG(21), - // Windows Values + /** Windows Values */ WIN32_PFD(30); public final int id; diff --git a/src/nativewindow/classes/jogamp/nativewindow/drm/DRMUtil.java b/src/nativewindow/classes/jogamp/nativewindow/drm/DRMUtil.java new file mode 100644 index 000000000..176ebccb0 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/drm/DRMUtil.java @@ -0,0 +1,154 @@ +/** + * 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.nativewindow.drm; + +import com.jogamp.nativewindow.NativeWindowException; +import com.jogamp.nativewindow.NativeWindowFactory; + +import jogamp.nativewindow.Debug; +import jogamp.nativewindow.NWJNILibLoader; +import jogamp.nativewindow.ToolkitProperties; + +import com.jogamp.common.ExceptionUtils; + +/** + * DRM and GBM utility + */ +public class DRMUtil implements ToolkitProperties { + /* pp */ static final boolean DEBUG = Debug.debug("DRMUtil"); + + /** FIXME: Add support for other OS implementing DRM/GBM, e.g. FreeBSD, OpenBSD, ..? */ + private static final String dri0Linux = "/dev/dri/card0"; + + private static volatile boolean isInit = false; + /** DRM file descriptor, valid if >= 0 */ + private static int drmFd = -1; + + /** + * Called by {@link NativeWindowFactory#initSingleton()} + * @see ToolkitProperties + */ + public static void initSingleton() { + if(!isInit) { + synchronized(DRMUtil.class) { + if(!isInit) { + isInit = true; + if(DEBUG) { + System.out.println("DRMUtil.initSingleton()"); + } + if(!NWJNILibLoader.loadNativeWindow("drm")) { + throw new NativeWindowException("NativeWindow DRM native library load error."); + } + if( initialize0(DEBUG) ) { + drmFd = DRMLib.drmOpenFile(dri0Linux); + } + if(DEBUG) { + System.err.println("DRMUtil.initSingleton(): OK "+(0 <= drmFd)+", drmFd "+drmFd+"]"); + if( 0 <= drmFd ) { + final DrmMode d = DrmMode.create(drmFd, true); + d.print(System.err); + d.destroy(); + } + // Thread.dumpStack(); + } + } + } + } + } + + /** Return the global DRM file descriptor */ + public static int getDrmFd() { return drmFd; } + + /** + * Cleanup resources. + * <p> + * Called by {@link NativeWindowFactory#shutdown()} + * </p> + * @see ToolkitProperties + */ + public static void shutdown() { + if(isInit) { + synchronized(DRMUtil.class) { + if(isInit) { + final boolean isJVMShuttingDown = NativeWindowFactory.isJVMShuttingDown() ; + if( DEBUG ) { + System.err.println("DRMUtil.Display: Shutdown (JVM shutdown: "+isJVMShuttingDown+")"); + if(DEBUG) { + ExceptionUtils.dumpStack(System.err); + } + } + + // Only at JVM shutdown time, since AWT impl. seems to + // dislike closing of X11 Display's (w/ ATI driver). + if( isJVMShuttingDown ) { + if( 0 <= drmFd ) { + DRMLib.drmClose(drmFd); + drmFd = -1; + } + isInit = false; + shutdown0(); + } + } + } + } + } + + /** + * Called by {@link NativeWindowFactory#initSingleton()} + * @see ToolkitProperties + */ + public static final boolean requiresToolkitLock() { + return true; + } + + /** + * Called by {@link NativeWindowFactory#initSingleton()} + * @see ToolkitProperties + */ + public static final boolean hasThreadingIssues() { + return false; + } + + static int fourcc_code(final char a, final char b, final char c, final char d) { + // return ( (int)(a) | ((int)(b) << 8) | ((int)(c) << 16) | ((int)(d) << 24) ); + return ( (a) | ((b) << 8) | ((c) << 16) | ((d) << 24) ); + } + /** [31:0] x:R:G:B 8:8:8:8 little endian */ + public static final int GBM_FORMAT_XRGB8888 = fourcc_code('X', 'R', '2', '4'); + /** [31:0] A:R:G:B 8:8:8:8 little endian */ + public static final int GBM_FORMAT_ARGB8888 = fourcc_code('A', 'R', '2', '4'); + + private DRMUtil() {} + + private static final String getCurrentThreadName() { return Thread.currentThread().getName(); } // Callback for JNI + private static final void dumpStack() { ExceptionUtils.dumpStack(System.err); } // Callback for JNI + + private static native boolean initialize0(boolean debug); + private static native void shutdown0(); +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/drm/DrmMode.java b/src/nativewindow/classes/jogamp/nativewindow/drm/DrmMode.java new file mode 100644 index 000000000..44b2a1327 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/drm/DrmMode.java @@ -0,0 +1,304 @@ +/** + * 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.nativewindow.drm; + +import java.io.PrintStream; +import java.nio.IntBuffer; +import java.util.ArrayList; +import java.util.List; + +import com.jogamp.nativewindow.NativeWindowException; + +import jogamp.nativewindow.drm.DRMLib; +import jogamp.nativewindow.drm.drmModeConnector; +import jogamp.nativewindow.drm.drmModeEncoder; +import jogamp.nativewindow.drm.drmModeModeInfo; +import jogamp.nativewindow.drm.drmModeRes; + +/** + * Describing a DRM adapter's connected {@link drmModeConnector} + * and it's {@link drmModeModeInfo}, {@link drmModeEncoder} and CRT index. + */ +public class DrmMode { + /** DRM file descriptor, valid if >= 0 */ + public final int drmFd; + /** Number of connected {@link drmModeConnector}s and hence length of all arrays within this instance. */ + public final int count; + /** Connected {@link drmModeConnector}, multiple outputs supported. Array can be of length zero if none is connected. */ + private final drmModeConnector[] connectors; + /** Selected current mode {@link drmModeModeInfo}. Array index matches the {@link #connectors}. */ + private final drmModeModeInfo[] modes; + /** Selected {@link drmModeEncoder}. Array index matches the {@link #connectors}. */ + private final drmModeEncoder[] encoder; + /** Selected CRT IDs. Array index matches the {@link #connectors}. */ + private final int[] crtc_ids; + /** Selected CRT indices. Array index matches the {@link #connectors}. */ + private final int[] crtc_indices; + /** boolean indicating that instance data is valid reflecting native DRM data and has not been {@link #destroy()}ed. */ + private volatile boolean valid; + + private DrmMode(final int drmFd, final int count) { + this.drmFd = drmFd; + this.count = count; + this.connectors = new drmModeConnector[count]; + this.modes = new drmModeModeInfo[count]; + this.encoder = new drmModeEncoder[count]; + this.crtc_ids = new int[count]; + this.crtc_indices = new int[count]; + this.valid = false; + } + + public void print(final PrintStream out) { + for(int i=0; i<count; i++) { + print(out, i); + } + } + public void print(final PrintStream out, final int connectorIdx) { + final drmModeConnector c = connectors[connectorIdx]; + out.printf("Connector[%d]: id[con 0x%x, enc 0x%x], type %d[id 0x%x], connection %d, dim %dx%x mm, modes %d, encoders %d\n", + connectorIdx, c.getConnector_id(), c.getEncoder_id(), + c.getConnector_type(), c.getConnector_type_id(), c.getConnection(), c.getMmWidth(), c.getMmHeight(), + c.getCount_modes(), c.getCount_encoders()); + final drmModeModeInfo m = modes[connectorIdx]; + System.err.printf( "Connector[%d].Mode: clock %d, %dx%d @ %d Hz, type %d, name <%s>\n", + connectorIdx, m.getClock(), m.getHdisplay(), m.getVdisplay(), m.getVrefresh(), + m.getType(), m.getNameAsString()); + final drmModeEncoder e = encoder[connectorIdx]; + System.err.printf( "Connector[%d].Encoder: id 0x%x, type %d, crtc_id 0x%x, possible[crtcs %d, clones %d]\n", + connectorIdx, e.getEncoder_id(), e.getEncoder_type(), e.getCrtc_id(), + e.getPossible_crtcs(), e.getPossible_clones()); + } + + /** + * Collecting all connected {@link drmModeConnector} + * and it's {@link drmModeModeInfo}, {@link drmModeEncoder} and CRT index. + * + * @param drmFd the DRM file descriptor + * @param preferNativeMode chose {@link DRMLib#DRM_MODE_TYPE_PREFERRED} + */ + public static DrmMode create(final int drmFd, final boolean preferNativeMode) { + final drmModeRes resources = DRMLib.drmModeGetResources(drmFd); + if( null == resources ) { + throw new NativeWindowException("drmModeGetResources failed"); + } + DrmMode res = null; + try { + { + final List<drmModeConnector> _connectors = new ArrayList<drmModeConnector>(); + final IntBuffer _connectorIDs = resources.getConnectors(); + if(DRMUtil.DEBUG) { + for(int i=0; i<_connectorIDs.limit(); i++) { + final drmModeConnector c = DRMLib.drmModeGetConnector(drmFd, _connectorIDs.get(i)); + final boolean chosen = DRMLib.DRM_MODE_CONNECTED == c.getConnection(); + System.err.printf("Connector %d/%d chosen %b,: id[con 0x%x, enc 0x%x], type %d[id 0x%x], connection %d, dim %dx%x mm, modes %d, encoders %d\n", + i, _connectorIDs.limit(), chosen, c.getConnector_id(), c.getEncoder_id(), + c.getConnector_type(), c.getConnector_type_id(), c.getConnection(), c.getMmWidth(), c.getMmHeight(), + c.getCount_modes(), c.getCount_encoders()); + DRMLib.drmModeFreeConnector(c); + } + } + drmModeConnector con = null; + for(int i=0; i<_connectorIDs.limit(); i++) { + con = DRMLib.drmModeGetConnector(drmFd, _connectorIDs.get(i)); + if( DRMLib.DRM_MODE_CONNECTED == con.getConnection() ) { + _connectors.add(con); + } else { + DRMLib.drmModeFreeConnector(con); + con = null; + } + } + res = new DrmMode(drmFd, _connectors.size()); + _connectors.toArray(res.connectors); + } + for(int k=0; k<res.count; k++) { + final drmModeModeInfo _modes[] = res.connectors[k].getModes(0, new drmModeModeInfo[res.connectors[k].getCount_modes()]); + drmModeModeInfo _mode = null; + { + int maxArea = 0; + int j=0; + for(int i=0; i<_modes.length; i++) { + final drmModeModeInfo m = _modes[i]; + final int area = m.getHdisplay() * m.getVdisplay(); + if( preferNativeMode && m.getType() == DRMLib.DRM_MODE_TYPE_PREFERRED ) { + _mode = m; + maxArea = Integer.MAX_VALUE; + j = i; + // only continue loop for DEBUG verbosity + } else if( area > maxArea ) { + _mode = m; + maxArea = area; + j = i; + } + if( DRMUtil.DEBUG ) { + System.err.printf( "Connector[%d].Mode %d/%d (max-chosen %d): clock %d, %dx%d @ %d Hz, type %d, name <%s>\n", + k, i, _modes.length, j, + m.getClock(), m.getHdisplay(), m.getVdisplay(), m.getVrefresh(), + m.getType(), m.getNameAsString()); + } + } + } + if( null == _mode ) { + throw new NativeWindowException("could not find mode"); + } + res.modes[k] = _mode; + } + { + final IntBuffer encoderIDs = resources.getEncoders(); + for(int k=0; k<res.count; k++) { + if( DRMUtil.DEBUG ) { + for (int i = 0; i < encoderIDs.limit(); i++) { + final drmModeEncoder e = DRMLib.drmModeGetEncoder(drmFd, encoderIDs.get(i)); + final boolean chosen = e.getEncoder_id() == res.connectors[k].getEncoder_id(); + System.err.printf( "Connector[%d].Encoder %d/%d chosen %b: id 0x%x, type %d, crtc_id 0x%x, possible[crtcs %d, clones %d]\n", + k, i, encoderIDs.limit(), chosen, + e.getEncoder_id(), e.getEncoder_type(), e.getCrtc_id(), + e.getPossible_crtcs(), e.getPossible_clones()); + DRMLib.drmModeFreeEncoder(e); + } + } + drmModeEncoder e = null; + for (int i = 0; i < encoderIDs.limit(); i++) { + e = DRMLib.drmModeGetEncoder(drmFd, encoderIDs.get(i)); + if( e.getEncoder_id() == res.connectors[k].getEncoder_id() ) { + break; + } else { + DRMLib.drmModeFreeEncoder(e); + e = null; + } + } + if( null == e ) { + throw new NativeWindowException("could not find encoder"); + } + res.encoder[k] = e; + } + } + { + final IntBuffer crtcs = resources.getCrtcs(); + for(int k=0; k<res.count; k++) { + int idx = -1; + for(int i=0; i<crtcs.limit(); i++) { + if( crtcs.get(i) == res.encoder[k].getCrtc_id() ) { + idx = i; + break; + } + } + if( 0 > idx ) { + throw new NativeWindowException("could not find crtc index"); + } + res.crtc_ids[k] = crtcs.get(idx); + res.crtc_indices[k] = idx; + } + } + } catch (final Throwable t) { + if( null != res ) { + res.destroy(); + res = null; + } + throw t; + } finally { + DRMLib.drmModeFreeResources(resources); + } + res.valid = true; + return res; + } + + /** + * Returns whether instance data is valid reflecting native DRM data and has not been {@link #destroy()}ed. + */ + public final boolean isValid() { + return valid; + } + private final void checkValid() { + if( !valid ) { + throw new IllegalStateException("Instance is invalid"); + } + } + + + /** + * Frees all native DRM resources collected by one of the static methods like {@link #create(int, boolean)}. + * <p> + * Method should be issued before shutting down or releasing the {@link #drmFd} via {@link DRMLib#drmClose(int)}. + * </p> + */ + public final void destroy() { + if( valid ) { + synchronized( this ) { + if( valid ) { + valid = false; + for(int i=0; i<count; i++) { + if( null != encoder[i] ) { + DRMLib.drmModeFreeEncoder(encoder[i]); + } + if( null != connectors[i]) { + DRMLib.drmModeFreeConnector(connectors[i]); + } + } + } + } + } + } + + /** + * Returns an array for each connected {@link drmModeConnector}s. + * <p> + * Returned array length is zero if no {@link drmModeConnector} is connected. + * </p> + * @throws IllegalStateException if instance is not {@link #isValid()}. + */ + public final drmModeConnector[] getConnectors() throws IllegalStateException + { checkValid(); return connectors; } + + /** + * Returns an array of {@link drmModeModeInfo} for each connected {@link #getConnectors()}'s current mode. + * @throws IllegalStateException if instance is not {@link #isValid()}. + */ + public final drmModeModeInfo[] getModes() throws IllegalStateException + { checkValid(); return modes; } + + /** + * Returns an array of {@link drmModeEncoder} for each connected {@link #getConnectors()}. + * @throws IllegalStateException if instance is not {@link #isValid()}. + */ + public final drmModeEncoder[] getEncoder() throws IllegalStateException + { checkValid(); return encoder; } + + /** + * Returns an array of selected CRT IDs for each connected {@link #getConnectors()}. + * @throws IllegalStateException if instance is not {@link #isValid()}. + */ + public final int[] getCrtcIDs() throws IllegalStateException + { checkValid(); return crtc_ids; } + + /** + * Returns an array of selected CRT indices for each connected {@link #getConnectors()}. + * @throws IllegalStateException if instance is not {@link #isValid()}. + */ + public final int[] getCrtcIndices() throws IllegalStateException + { checkValid(); return crtc_indices; } +}
\ No newline at end of file diff --git a/src/nativewindow/classes/jogamp/nativewindow/drm/GBMDummyUpstreamSurfaceHook.java b/src/nativewindow/classes/jogamp/nativewindow/drm/GBMDummyUpstreamSurfaceHook.java new file mode 100644 index 000000000..c237e6802 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/drm/GBMDummyUpstreamSurfaceHook.java @@ -0,0 +1,105 @@ +/** + * 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.nativewindow.drm; + +import com.jogamp.nativewindow.AbstractGraphicsDevice; +import com.jogamp.nativewindow.NativeSurface; +import com.jogamp.nativewindow.NativeWindowException; +import com.jogamp.nativewindow.ProxySurface; +import com.jogamp.nativewindow.UpstreamSurfaceHook; + +import com.jogamp.nativewindow.UpstreamSurfaceHookMutableSize; + +public class GBMDummyUpstreamSurfaceHook extends UpstreamSurfaceHookMutableSize { + private long gbmDevice = 0; + + /** + * @param width the initial width as returned by {@link NativeSurface#getSurfaceWidth()} via {@link UpstreamSurfaceHook#getSurfaceWidth(ProxySurface)}, + * not the actual dummy surface width. + * The latter is platform specific and small + * @param height the initial height as returned by {@link NativeSurface#getSurfaceHeight()} via {@link UpstreamSurfaceHook#getSurfaceHeight(ProxySurface)}, + * not the actual dummy surface height, + * The latter is platform specific and small + */ + public GBMDummyUpstreamSurfaceHook(final int width, final int height) { + super(width, height); + } + + @Override + public final void create(final ProxySurface s) { + final AbstractGraphicsDevice gd = s.getGraphicsConfiguration().getScreen().getDevice(); + final int visualID = DRMUtil.GBM_FORMAT_XRGB8888; + gd.lock(); + try { + if( 0 == s.getSurfaceHandle() ) { + gbmDevice = DRMLib.gbm_create_device(DRMUtil.getDrmFd()); + if(0 == gbmDevice) { + throw new NativeWindowException("Creating dummy GBM device failed"); + } + + final long gbmSurface = DRMLib.gbm_surface_create(gbmDevice, 64, 64, visualID, + DRMLib.GBM_BO_USE_SCANOUT | DRMLib.GBM_BO_USE_RENDERING); + if(0 == gbmSurface) { + throw new NativeWindowException("Creating dummy GBM surface failed"); + } + s.setSurfaceHandle(gbmSurface); + + s.addUpstreamOptionBits( ProxySurface.OPT_PROXY_OWNS_UPSTREAM_SURFACE ); + } + s.addUpstreamOptionBits( ProxySurface.OPT_UPSTREAM_WINDOW_INVISIBLE ); + } finally { + gd.unlock(); + } + } + + @Override + public final void destroy(final ProxySurface s) { + if( s.containsUpstreamOptionBits( ProxySurface.OPT_PROXY_OWNS_UPSTREAM_SURFACE ) ) { + final AbstractGraphicsDevice gd = s.getGraphicsConfiguration().getScreen().getDevice(); + final long gbmSurface = s.getSurfaceHandle(); + if( 0 == gbmDevice ) { + throw new InternalError("GBM device handle is null"); + } + if( 0 == gbmSurface ) { + throw new InternalError("Owns upstream surface, but has no GBM surface: "+s); + } + gd.lock(); + try { + DRMLib.gbm_surface_destroy(gbmSurface); + s.setSurfaceHandle(0); + + DRMLib.gbm_device_destroy(gbmDevice); + gbmDevice = 0; + + s.clearUpstreamOptionBits( ProxySurface.OPT_PROXY_OWNS_UPSTREAM_SURFACE ); + } finally { + gd.unlock(); + } + } + } +} diff --git a/src/nativewindow/native/JVM_JNI8.c b/src/nativewindow/native/JVM_JNI8.c index a7b4e5d90..4cdeaeb43 100644 --- a/src/nativewindow/native/JVM_JNI8.c +++ b/src/nativewindow/native/JVM_JNI8.c @@ -36,12 +36,14 @@ JNIEXPORT jint JNICALL JNI_OnLoad_nativewindow_x11(JavaVM *vm, void *reserved) { JNIEXPORT jint JNICALL JNI_OnLoad_nativewindow_win32(JavaVM *vm, void *reserved) { return JNI_VERSION_1_8; } JNIEXPORT jint JNICALL JNI_OnLoad_nativewindow_macosx(JavaVM *vm, void *reserved) { return JNI_VERSION_1_8; } JNIEXPORT jint JNICALL JNI_OnLoad_nativewindow_ios(JavaVM *vm, void *reserved) { return JNI_VERSION_1_8; } +JNIEXPORT jint JNICALL JNI_OnLoad_nativewindow_drm(JavaVM *vm, void *reserved) { return JNI_VERSION_1_8; } JNIEXPORT void JNICALL JNI_OnUnload_nativewindow_awt(JavaVM *vm, void *reserved) { } JNIEXPORT void JNICALL JNI_OnUnload_nativewindow_x11(JavaVM *vm, void *reserved) { } JNIEXPORT void JNICALL JNI_OnUnload_nativewindow_win32(JavaVM *vm, void *reserved) { } JNIEXPORT void JNICALL JNI_OnUnload_nativewindow_macosx(JavaVM *vm, void *reserved) { } JNIEXPORT void JNICALL JNI_OnUnload_nativewindow_ios(JavaVM *vm, void *reserved) { } +JNIEXPORT void JNICALL JNI_OnUnload_nativewindow_drm(JavaVM *vm, void *reserved) { } #endif /* defined (JNI_VERSION_1_8) */ diff --git a/src/nativewindow/native/drm/DRMmisc.c b/src/nativewindow/native/drm/DRMmisc.c new file mode 100644 index 000000000..1bd8e1eaf --- /dev/null +++ b/src/nativewindow/native/drm/DRMmisc.c @@ -0,0 +1,89 @@ +/** + * 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. + */ + +#include "NativewindowCommon.h" + +#include "jogamp_nativewindow_drm_DRMLib.h" +#include "jogamp_nativewindow_drm_DRMUtil.h" + +#include <fcntl.h> + +/** Remove memcpy GLIBC > 2.4 dependencies */ +#include <glibc-compat-symbols.h> + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(args...) fprintf(stderr, args); +#else + #define DBG_PRINT(args...) +#endif + +static int _initialized = 0; + +JNIEXPORT jboolean JNICALL +Java_jogamp_nativewindow_drm_DRMUtil_initialize0(JNIEnv *env, jclass clazz, jboolean debug) { + if( 0 == _initialized ) { + _initialized=1; + if(JNI_TRUE == debug) { + fprintf(stderr, "Info: NativeWindow native init passed\n"); + } + } + return JNI_TRUE; +} + +JNIEXPORT void JNICALL +Java_jogamp_nativewindow_drm_DRMUtil_shutdown0(JNIEnv *env, jclass _unused) { + // NOP +} + +/* Java->C glue code: + * Java package: jogamp.nativewindow.drm.DRMLib + * Java method: int drmOpenFile(java.lang.String filename) + * C function: int drmOpenFile(const char *filename) + */ +JNIEXPORT jint JNICALL +Java_jogamp_nativewindow_drm_DRMLib_drmOpenFile(JNIEnv *env, jclass _unused, jstring filename) { + const char* _strchars_filename = NULL; + int _res; + if ( NULL != filename ) { + _strchars_filename = (*env)->GetStringUTFChars(env, filename, (jboolean*)NULL); + if ( NULL == _strchars_filename ) { + (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"), + "Failed to get UTF-8 chars for argument \"filename\" in native dispatcher for \"drmOpenFile\""); + return 0; + } + } + _res = (int) open((const char * ) _strchars_filename, O_RDWR); + if ( NULL != filename ) { + (*env)->ReleaseStringUTFChars(env, filename, _strchars_filename); + } + return _res; +} + + diff --git a/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java index 4d9835826..847532bb4 100644 --- a/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java +++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/DisplayDriver.java @@ -31,6 +31,8 @@ import com.jogamp.nativewindow.AbstractGraphicsDevice; import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.opengl.GLProfile; +import jogamp.nativewindow.drm.DRMLib; +import jogamp.nativewindow.drm.DRMUtil; import jogamp.newt.DisplayImpl; import jogamp.newt.NEWTJNILibLoader; import jogamp.opengl.egl.EGLDisplayUtil; @@ -50,31 +52,23 @@ public class DisplayDriver extends DisplayImpl { if (!WindowDriver.initIDs()) { throw new NativeWindowException("Failed to initialize egl.gbm Window jmethodIDs"); } - drmHandle = initDrm(DEBUG); - } - - 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 } - private static void shutdownHook() { - freeDrm(drmHandle); - } - public DisplayDriver() { gbmHandle = 0; } @Override protected void createNativeImpl() { - validateDrm(); - gbmHandle = OpenGBMDisplay0(drmHandle); + final int drmFd = DRMUtil.getDrmFd(); + if( 0 > drmFd ) { + throw new NativeWindowException("Failed to initialize DRM"); + } + gbmHandle = DRMLib.gbm_create_device(drmFd); aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(gbmHandle, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); aDevice.open(); } @@ -82,11 +76,10 @@ public class DisplayDriver extends DisplayImpl { @Override protected void closeNativeImpl(final AbstractGraphicsDevice aDevice) { aDevice.close(); - CloseGBMDisplay0(gbmHandle); + DRMLib.gbm_device_destroy(gbmHandle); gbmHandle = 0; } - /* pp */ static final long getDrmHandle() { validateDrm(); return drmHandle; } /* pp */ final long getGBMHandle() { return gbmHandle; } @Override @@ -98,14 +91,8 @@ public class DisplayDriver extends DisplayImpl { // Internals only // private static native boolean initIDs(); - private static native long initDrm(boolean verbose); - 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 index 2ff7ab299..7d6c2b41c 100644 --- a/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java @@ -31,6 +31,9 @@ import com.jogamp.nativewindow.DefaultGraphicsScreen; import com.jogamp.nativewindow.util.Rectangle; import com.jogamp.newt.MonitorDevice; import com.jogamp.newt.MonitorMode; + +import jogamp.nativewindow.drm.DRMUtil; +import jogamp.nativewindow.drm.DrmMode; import jogamp.newt.MonitorModeProps; import jogamp.newt.ScreenImpl; @@ -45,26 +48,40 @@ public class ScreenDriver extends ScreenImpl { @Override protected void createNativeImpl() { aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx); - initNative( DisplayDriver.getDrmHandle() ); + drmMode = DrmMode.create(DRMUtil.getDrmFd(), true /* preferNativeMode */); + if( DEBUG ) { + drmMode.print(System.err); + } } @Override - protected void closeNativeImpl() { } + protected void closeNativeImpl() { + drmMode.destroy(); + drmMode = null; + } @Override protected int validateScreenIndex(final int idx) { - return 0; // only one screen available + // FIXME add multi-monitor support + /** + if( 0 <= idx && idx < drmMode.count ) { + return idx; + } */ + return 0; } @Override protected void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Cache cache) { + // FIXME add multi-monitor multi-mode support + final int scridx = 0; // getIndex(); + 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++] = drmMode.getModes()[scridx].getHdisplay(); + props[i++] = drmMode.getModes()[scridx].getVdisplay(); props[i++] = ScreenImpl.default_sm_bpp; // FIXME - props[i++] = cachedVRrefresh * 100; + props[i++] = drmMode.getModes()[scridx].getVrefresh() * 100; props[i++] = 0; // flags props[i++] = 0; // mode_idx props[i++] = 0; // rotation @@ -76,45 +93,40 @@ public class ScreenDriver extends ScreenImpl { 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++] = drmMode.getConnectors()[scridx].getMmWidth(); + props[i++] = drmMode.getConnectors()[scridx].getMmHeight(); 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++] = drmMode.getModes()[scridx].getHdisplay(); // rotated viewport width pixel-units + props[i++] = drmMode.getModes()[scridx].getVdisplay(); // 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 + props[i++] = drmMode.getModes()[scridx].getHdisplay(); // rotated viewport width window-units + props[i++] = drmMode.getModes()[scridx].getVdisplay(); // rotated viewport height window-units MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null); } @Override protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) { + // FIXME add multi-monitor multi-mode support return monitor.getSupportedModes().get(0); } @Override protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, final MonitorMode mode) { + // FIXME add multi-monitor multi-mode support return false; } @Override protected void calcVirtualScreenOriginAndSize(final Rectangle viewport, final Rectangle viewportInWindowUnits) { - viewport.set(0, 0, cachedWidth, cachedHeight); + // FIXME add multi-monitor support + final int scridx = 0; // getIndex(); + viewport.set(0, 0, drmMode.getModes()[scridx].getHdisplay(), drmMode.getModes()[scridx].getVdisplay()); 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; + /* pp */ DrmMode drmMode; 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 index 8517a132f..7253fac52 100644 --- a/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java @@ -27,17 +27,27 @@ */ package jogamp.newt.driver.egl.gbm; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.nativewindow.AbstractGraphicsDevice; import com.jogamp.nativewindow.AbstractGraphicsScreen; import com.jogamp.nativewindow.NativeWindowException; 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 com.jogamp.newt.Display; import com.jogamp.opengl.GLCapabilitiesChooser; import com.jogamp.opengl.GLCapabilitiesImmutable; import com.jogamp.opengl.GLException; import com.jogamp.opengl.egl.EGL; +import jogamp.nativewindow.drm.DRMLib; +import jogamp.nativewindow.drm.DRMUtil; +import jogamp.nativewindow.drm.DrmMode; +import jogamp.nativewindow.drm.drmModeModeInfo; import jogamp.newt.WindowImpl; import jogamp.newt.driver.linux.LinuxEventDeviceTracker; import jogamp.newt.driver.linux.LinuxMouseTracker; @@ -120,21 +130,66 @@ public class WindowDriver extends WindowImpl { } } + /** + * Align 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 aligned a new {@link RectangleImmutable} instance w/ clamped values + * will be returned, otherwise the given {@code rect} is returned. + */ + private RectangleImmutable alignRect2Screen(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 != w ) { + w = s_w; + modSize = 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 - } + // clampRect((ScreenDriver) getScreen(), new Rectangle(getX(), getY(), getWidth(), getHeight()), true); - static int fourcc_code(final char a, final char b, final char c, final char d) { - // return ( (int)(a) | ((int)(b) << 8) | ((int)(c) << 16) | ((int)(d) << 24) ); - return ( (a) | ((b) << 8) | ((c) << 16) | ((d) << 24) ); + // Turns out DRM / GBM can only handle full screen size FB and crtc-modesetting (?) + alignRect2Screen((ScreenDriver) getScreen(), new Rectangle(getX(), getY(), getWidth(), getHeight()), true); + + return true; // default: always able to be created } - /** [31:0] x:R:G:B 8:8:8:8 little endian */ - static final int GBM_FORMAT_XRGB8888 = fourcc_code('X', 'R', '2', '4'); - /** [31:0] A:R:G:B 8:8:8:8 little endian */ - static final int GBM_FORMAT_ARGB8888 = fourcc_code('A', 'R', '2', '4'); @Override protected void createNativeImpl() { @@ -148,7 +203,12 @@ public class WindowDriver extends WindowImpl { // Create own screen/device resource instance allowing independent ownership, // while still utilizing shared EGL resources. final AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); - final int nativeVisualID = capsRequested.isBackgroundOpaque() ? GBM_FORMAT_XRGB8888 : GBM_FORMAT_ARGB8888; + final int nativeVisualID = capsRequested.isBackgroundOpaque() ? DRMUtil.GBM_FORMAT_XRGB8888 : DRMUtil.GBM_FORMAT_ARGB8888; + + final boolean ctDesktopGL = false; + if( !EGL.eglBindAPI( ctDesktopGL ? EGL.EGL_OPENGL_API : EGL.EGL_OPENGL_ES_API) ) { + throw new GLException("Caught: eglBindAPI to "+(ctDesktopGL ? "ES" : "GL")+" failed , error "+toHexString(EGL.eglGetError())); + } final EGLGraphicsConfiguration eglConfig = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( (GLCapabilitiesImmutable)capsRequested, (GLCapabilitiesImmutable)capsRequested, (GLCapabilitiesChooser)capabilitiesChooser, @@ -157,8 +217,8 @@ public class WindowDriver extends WindowImpl { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } setGraphicsConfiguration(eglConfig); - final long nativeWindowHandle = CreateWindow0(DisplayDriver.getDrmHandle(), display.getGBMHandle(), - getX(), getY(), getWidth(), getHeight(), nativeVisualID); + final long nativeWindowHandle = DRMLib.gbm_surface_create(display.getGBMHandle(), getWidth(), getHeight(), nativeVisualID, + DRMLib.GBM_BO_USE_SCANOUT | DRMLib.GBM_BO_USE_RENDERING); if (nativeWindowHandle == 0) { throw new NativeWindowException("Error creating egl window: "+eglConfig); } @@ -174,15 +234,7 @@ public class WindowDriver extends WindowImpl { throw new NativeWindowException("Creation of eglSurface failed: "+eglConfig+", windowHandle 0x"+Long.toHexString(nativeWindowHandle)+", error "+toHexString(EGL.eglGetError())); } - if(false) { - /** - if(!EGL.eglSwapBuffers(display.getHandle(), eglSurface)) { - throw new GLException("Error swapping buffers, eglError "+toHexString(EGL.eglGetError())+", "+this); - } */ - lastBO = FirstSwapSurface0(DisplayDriver.getDrmHandle(), nativeWindowHandle, display.getHandle(), eglSurface); - } else { - lastBO = 0; - } + lastBO = 0; if( null != linuxEventDeviceTracker ) { addWindowListener(linuxEventDeviceTracker); @@ -196,8 +248,7 @@ public class WindowDriver extends WindowImpl { @Override protected void closeNativeImpl() { - final DisplayDriver display = (DisplayDriver) getScreen().getDisplay(); - final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) getGraphicsConfiguration().getScreen().getDevice(); + final Display display = getScreen().getDisplay(); if( null != linuxMouseTracker ) { removeWindowListener(linuxMouseTracker); @@ -209,7 +260,7 @@ public class WindowDriver extends WindowImpl { lastBO = 0; if(0 != eglSurface) { try { - if (!EGL.eglDestroySurface(eglDevice.getHandle(), eglSurface)) { + if (!EGL.eglDestroySurface(display.getHandle(), eglSurface)) { throw new GLException("Error destroying window surface (eglDestroySurface)"); } } catch (final Throwable t) { @@ -219,11 +270,9 @@ public class WindowDriver extends WindowImpl { } } if( 0 != windowHandleClose ) { - CloseWindow0(display.getGBMHandle(), windowHandleClose); + DRMLib.gbm_surface_destroy(windowHandleClose); windowHandleClose = 0; } - - eglDevice.close(); } @Override @@ -233,21 +282,21 @@ public class WindowDriver extends WindowImpl { @Override public boolean surfaceSwap() { - final DisplayDriver display = (DisplayDriver) getScreen().getDisplay(); + final ScreenDriver screen = (ScreenDriver) getScreen(); + final DisplayDriver display = (DisplayDriver) screen.getDisplay(); final long nativeWindowHandle = getWindowHandle(); + final DrmMode d = screen.drmMode; + if(!EGL.eglSwapBuffers(display.getHandle(), eglSurface)) { + throw new GLException("Error swapping buffers, eglError "+toHexString(EGL.eglGetError())+", "+this); + } if( 0 == lastBO ) { - /** if(!EGL.eglSwapBuffers(display.getHandle(), eglSurface)) { - throw new GLException("Error swapping buffers, eglError "+toHexString(EGL.eglGetError())+", "+this); - } */ - lastBO = FirstSwapSurface0(DisplayDriver.getDrmHandle(), nativeWindowHandle, display.getHandle(), eglSurface); + lastBO = FirstSwapSurface(d.drmFd, d.getCrtcIDs()[0], getX(), getY(), d.getConnectors()[0].getConnector_id(), + d.getModes()[0], nativeWindowHandle); + } else { + lastBO = NextSwapSurface(d.drmFd, d.getCrtcIDs()[0], getX(), getY(), d.getConnectors()[0].getConnector_id(), + d.getModes()[0], nativeWindowHandle, lastBO); } - - /**if(!EGL.eglSwapBuffers(display.getHandle(), eglSurface)) { - throw new GLException("Error swapping buffers, eglError "+toHexString(EGL.eglGetError())+", "+this); - } */ - lastBO = NextSwapSurface0(DisplayDriver.getDrmHandle(), nativeWindowHandle, lastBO, display.getHandle(), eglSurface); - System.exit(1); return true; // eglSwapBuffers done! } @@ -273,11 +322,11 @@ public class WindowDriver extends WindowImpl { @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); + // 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); + // reconfigure0(getWindowHandle(), rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), flags); - return true; + return false; } @Override @@ -295,9 +344,29 @@ public class WindowDriver extends WindowImpl { private long lastBO; protected static native boolean initIDs(); - private native long CreateWindow0(long drmHandle, long gbmHandle, int x, int y, int width, int height, int nativeVisualID); - private native void CloseWindow0(long gbmDisplay, long eglWindowHandle); - private native void reconfigure0(long eglWindowHandle, int x, int y, int width, int height, int flags); - private native long FirstSwapSurface0(long drmHandle, long gbmSurface, long eglDisplay, long eglSurface); - private native long NextSwapSurface0(long drmHandle, long gbmSurface, long lastBO, long eglDisplay, long eglSurface); + // private native void reconfigure0(long eglWindowHandle, int x, int y, int width, int height, int flags); + + private long FirstSwapSurface(final int drmFd, final int crtc_id, final int x, final int y, final int connector_id, final drmModeModeInfo drmMode, final long gbmSurface) { + final ByteBuffer bb = drmMode.getBuffer(); + if(!Buffers.isDirect(bb)) { + throw new IllegalArgumentException("drmMode's buffer is not direct (NIO)"); + } + return FirstSwapSurface0(drmFd, crtc_id, x, y, connector_id, + bb, Buffers.getDirectBufferByteOffset(bb), + gbmSurface); + } + private native long FirstSwapSurface0(int drmFd, int crtc_id, int x, int y, int connector_id, Object mode, int mode_byte_offset, + long gbmSurface); + + private long NextSwapSurface(final int drmFd, final int crtc_id, final int x, final int y, final int connector_id, final drmModeModeInfo drmMode, final long gbmSurface, final long lastBO) { + final ByteBuffer bb = drmMode.getBuffer(); + if(!Buffers.isDirect(bb)) { + throw new IllegalArgumentException("drmMode's buffer is not direct (NIO)"); + } + return NextSwapSurface0(drmFd, crtc_id, x, y, connector_id, + bb, Buffers.getDirectBufferByteOffset(bb), + gbmSurface, lastBO); + } + private native long NextSwapSurface0(int drmFd, int crtc_id, int x, int y, int connector_id, Object mode, int mode_byte_offset, + long gbmSurface, long lastBO); } diff --git a/src/newt/native/drm_gbm.c b/src/newt/native/drm_gbm.c new file mode 100644 index 000000000..93b02dbe7 --- /dev/null +++ b/src/newt/native/drm_gbm.c @@ -0,0 +1,83 @@ +/** + * 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. + */ + +#include "drm_gbm.h" + +static jmethodID sizeChangedID = NULL; +static jmethodID positionChangedID = NULL; +static jmethodID visibleChangedID = NULL; +static jmethodID windowDestroyNotifyID = NULL; + +/** + * Display + */ + +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 void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_DispatchMessages0 + (JNIEnv *env, jclass clazz) +{ +} + +/** + * Screen + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_egl_gbm_ScreenDriver_initIDs + (JNIEnv *env, jclass clazz) +{ + DBG_PRINT( "EGL_GBM.Screen initIDs ok\n" ); + return JNI_TRUE; +} + +/** + * Window + */ + +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_initIDs + (JNIEnv *env, jclass clazz) +{ + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V"); + positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(ZII)V"); + visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V"); + windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "(Z)Z"); + if (sizeChangedID == NULL || + positionChangedID == NULL || + visibleChangedID == NULL || + windowDestroyNotifyID == NULL) { + DBG_PRINT( "initIDs failed\n" ); + return JNI_FALSE; + } + DBG_PRINT( "EGL_GBM.Window initIDs ok\n" ); + return JNI_TRUE; +} + diff --git a/src/newt/native/egl_gbm.h b/src/newt/native/drm_gbm.h index ae7c9121f..3fac0f59b 100644 --- a/src/newt/native/egl_gbm.h +++ b/src/newt/native/drm_gbm.h @@ -42,7 +42,7 @@ #define WEAK __attribute__((weak)) -#define VERBOSE_ON 1 +// #define VERBOSE_ON 1 #ifdef VERBOSE_ON #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr) @@ -51,12 +51,3 @@ #endif #define ERR_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr) -typedef struct { - int fd; // drmClose - drmModeConnector *connector; // drmModeFreeConnector - drmModeEncoder *encoder; // drmModeFreeEncoder - int crtc_index; - - drmModeModeInfo *current_mode; -} DRM_HANDLE; - diff --git a/src/newt/native/drm_gbm_legacy.c b/src/newt/native/drm_gbm_legacy.c new file mode 100644 index 000000000..8cc1c3c15 --- /dev/null +++ b/src/newt/native/drm_gbm_legacy.c @@ -0,0 +1,306 @@ +/** + * 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. + */ + +#include "drm_gbm.h" + +WEAK uint64_t +gbm_bo_get_modifier(struct gbm_bo *bo); + +WEAK int +gbm_bo_get_plane_count(struct gbm_bo *bo); + +WEAK uint32_t +gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane); + +WEAK uint32_t +gbm_bo_get_offset(struct gbm_bo *bo, int plane); + +typedef struct { + struct gbm_bo *bo; + uint32_t fb_id; + uint32_t x, y; +} DRM_FB; + +static void page_flip_handler(int fd, unsigned int frame, + unsigned int sec, unsigned int usec, void *data) +{ + /* suppress 'unused parameter' warnings */ + (void)fd, (void)frame, (void)sec, (void)usec; + + int *waiting_for_flip = data; + *waiting_for_flip = 0; +} + +static drmEventContext drm_event_ctx = { + .version = DRM_EVENT_CONTEXT_VERSION, + .page_flip_handler = page_flip_handler, + }; + +static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) +{ + struct gbm_device * gbmDev = gbm_bo_get_device(bo); + int drm_fd = gbm_device_get_fd(gbmDev); + DRM_FB *fb = data; + + if (fb->fb_id) { + drmModeRmFB(drm_fd, fb->fb_id); + fb->fb_id = 0; + fb->bo = NULL; + } + + free(fb); +} + +static DRM_FB * drm_fb_get_from_bo2(int drmFd, struct gbm_bo *bo) +{ + DRM_FB *fb = gbm_bo_get_user_data(bo); + uint32_t width, height, format, + strides[4] = {0}, handles[4] = {0}, + offsets[4] = {0}, flags = 0; + int ret = -1; + + if (fb) { + return fb; + } + + fb = calloc(1, sizeof *fb); + fb->bo = bo; + + width = gbm_bo_get_width(bo); + height = gbm_bo_get_height(bo); + format = gbm_bo_get_format(bo); + + if (gbm_bo_get_modifier && gbm_bo_get_plane_count && + gbm_bo_get_stride_for_plane && gbm_bo_get_offset) { + + uint64_t modifiers[4] = {0}; + modifiers[0] = gbm_bo_get_modifier(bo); + const int num_planes = gbm_bo_get_plane_count(bo); + for (int i = 0; i < num_planes; i++) { + strides[i] = gbm_bo_get_stride_for_plane(bo, i); + handles[i] = gbm_bo_get_handle(bo).u32; + offsets[i] = gbm_bo_get_offset(bo, i); + modifiers[i] = modifiers[0]; + } + + if (modifiers[0]) { + flags = DRM_MODE_FB_MODIFIERS; + DBG_PRINT("Using modifier %" PRIx64 "\n", modifiers[0]); + } + + ret = drmModeAddFB2WithModifiers(drmFd, width, height, + format, handles, strides, offsets, + modifiers, &fb->fb_id, flags); + if(ret) { + ERR_PRINT("drmModeAddFB2WithModifiers failed!\n"); + } else { + DBG_PRINT("drmModeAddFB2WithModifiers OK!\n"); + } + } + + if (ret) { + memcpy(handles, (uint32_t [4]){gbm_bo_get_handle(bo).u32,0,0,0}, 16); + memcpy(strides, (uint32_t [4]){gbm_bo_get_stride(bo),0,0,0}, 16); + memset(offsets, 0, 16); + ret = drmModeAddFB2(drmFd, width, height, format, + handles, strides, offsets, &fb->fb_id, 0); + if(ret) { + ERR_PRINT("drmModeAddFB2 failed!\n"); + } else { + DBG_PRINT("drmModeAddFB2 OK!\n"); + } + } + + if (ret) { + ERR_PRINT("failed to create fb: %s\n", strerror(errno)); + free(fb); + return NULL; + } + + gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback); + + return fb; +} + +static DRM_FB * drm_fb_get_from_bo(int drmFd, struct gbm_bo *bo) +{ + DRM_FB *fb = gbm_bo_get_user_data(bo); + uint32_t width, height, stride, handle; + int ret; + + if (fb) { + return fb; + } + + fb = calloc(1, sizeof *fb); + fb->bo = bo; + + width = gbm_bo_get_width(bo); + height = gbm_bo_get_height(bo); + stride = gbm_bo_get_stride(bo); + handle = gbm_bo_get_handle(bo).u32; + + ret = drmModeAddFB(drmFd, width, height, 24, 32, stride, handle, &fb->fb_id); + if (ret) { + ERR_PRINT("failed to create fb: %s\n", strerror(errno)); + free(fb); + return NULL; + } else { + DBG_PRINT("drmModeAddFB OK!\n"); + } + + gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback); + + return fb; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_FirstSwapSurface0 + (JNIEnv *env, jobject obj, jint drmFd, jint jcrtc_id, jint jx, jint jy, + jint jconnector_id, jobject jmode, jint jmode_byte_offset, jlong jgbmSurface) +{ + uint32_t crtc_id = (uint32_t)jcrtc_id; + uint32_t connector_id = (uint32_t)jconnector_id; + drmModeModeInfo *drmMode = NULL; + struct gbm_surface *gbmSurface = (struct gbm_surface *) (intptr_t) jgbmSurface; + struct gbm_bo *nextBO = NULL; + DRM_FB *fb = NULL; + int ret; + + if ( NULL != jmode ) { + const char * c1 = (const char *) (*env)->GetDirectBufferAddress(env, jmode); + drmMode = (drmModeModeInfo *) (intptr_t) ( c1 + jmode_byte_offset ); + } + nextBO = gbm_surface_lock_front_buffer(gbmSurface); + fb = drm_fb_get_from_bo(drmFd, nextBO); + if (!fb) { + ERR_PRINT("Failed to get a new framebuffer BO (0)\n"); + return 0; + } + fb->x = (uint32_t)jx; + fb->y = (uint32_t)jy; + /** + * Set Mode + * + * Fails with x/y != 0: -28 No space left on device + * drmModeSetCrtc.0 failed to set mode: fd 26, crtc_id 0x27, fb_id 0x54, pos 10/10, conn_id 0x4d, curMode 1920x1080: -28 No space left on device + */ + ret = drmModeSetCrtc(drmFd, crtc_id, fb->fb_id, fb->x, fb->y, + &connector_id, 1, drmMode); + if (ret) { + ERR_PRINT("drmModeSetCrtc.0 failed to set mode: fd %d, crtc_id 0x%x, fb_id 0x%x, pos %d/%d, conn_id 0x%x, curMode %s: %d %s\n", + drmFd, crtc_id, fb->fb_id, jx, jy, connector_id, drmMode->name, ret, strerror(errno)); + return 0; + } + DBG_PRINT( "EGL_GBM.Window FirstSwapSurface0 nextBO %p, fd %d, crtc_id 0x%x, fb_id 0x%x, pos %d/%d, conn_id 0x%x, curMode %s\n", + nextBO, drmFd, crtc_id, fb->fb_id, jx, jy, connector_id, drmMode->name); + return (jlong) (intptr_t) nextBO; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_NextSwapSurface0 + (JNIEnv *env, jobject obj, jint drmFd, jint jcrtc_id, jint jx, jint jy, + jint jconnector_id, jobject jmode, jint jmode_byte_offset, jlong jgbmSurface, jlong jlastBO) +{ + uint32_t crtc_id = (uint32_t)jcrtc_id; + uint32_t x = (uint32_t)jx; + uint32_t y = (uint32_t)jy; + uint32_t connector_id = (uint32_t)jconnector_id; + drmModeModeInfo *drmMode = NULL; + struct gbm_surface *gbmSurface = (struct gbm_surface *) (intptr_t) jgbmSurface; + struct gbm_bo *lastBO = (struct gbm_bo*) (intptr_t) jlastBO, *nextBO = NULL; + DRM_FB *fbNext = NULL; + int ret, waiting_for_flip = 1; + fd_set fds; + + if ( NULL != jmode ) { + const char * c1 = (const char *) (*env)->GetDirectBufferAddress(env, jmode); + drmMode = (drmModeModeInfo *) (intptr_t) ( c1 + jmode_byte_offset ); + } + nextBO = gbm_surface_lock_front_buffer(gbmSurface); + fbNext = drm_fb_get_from_bo(drmFd, nextBO); + if (!fbNext) { + ERR_PRINT("Failed to get a new framebuffer BO (1)\n"); + return 0; + } + if( fbNext->x != x || fbNext->y != y ) { + // position changed, hard drmModeSetCrtc(..) w/o vsync + fbNext->x = x; + fbNext->y = y; + + /** + * Set Mode + * + * Fails with x/y != 0: -28 No space left on device + * drmModeSetCrtc.0 failed to set mode: fd 26, crtc_id 0x27, fb_id 0x54, pos 10/10, conn_id 0x4d, curMode 1920x1080: -28 No space left on device + */ + ret = drmModeSetCrtc(drmFd, crtc_id, fbNext->fb_id, fbNext->x, fbNext->y, + &connector_id, 1, drmMode); + + if (ret) { + ERR_PRINT("drmModeSetCrtc.1 failed to set mode: fd %d, crtc_id 0x%x, fb_id 0x%x, pos %d/%d, conn_id 0x%x, curMode %s: %d %s\n", + drmFd, crtc_id, fbNext->fb_id, jx, jy, connector_id, drmMode->name, ret, strerror(errno)); + return 0; + } + } else { + // same position, use vsync + ret = drmModePageFlip(drmFd, crtc_id, fbNext->fb_id, + DRM_MODE_PAGE_FLIP_EVENT, &waiting_for_flip); + if (ret) { + ERR_PRINT("drmModePageFlip.1 failed to queue page flip: fd %d, crtc_id 0x%x, fb_id 0x%x, conn_id 0x%x, curMode %s: %p -> %p: %d %s\n", + drmFd, crtc_id, fbNext->fb_id, connector_id, drmMode->name, lastBO, nextBO, ret, strerror(errno)); + return 0; + } + + while (waiting_for_flip) { + FD_ZERO(&fds); + FD_SET(0, &fds); + FD_SET(drmFd, &fds); + + ret = select(drmFd + 1, &fds, NULL, NULL, NULL); + if (ret < 0) { + ERR_PRINT("drm.select: select err: %s\n", strerror(errno)); + return ret; + } else if (ret == 0) { + ERR_PRINT("drm.select: select timeout!\n"); + return -1; + } else if (FD_ISSET(0, &fds)) { + ERR_PRINT("drm.select: user interrupted!\n"); + return 0; + } + drmHandleEvent(drmFd, &drm_event_ctx); + } + } + + /* release last buffer to render on again: */ + if( NULL != lastBO ) { + gbm_surface_release_buffer(gbmSurface, lastBO); + } + + DBG_PRINT( "EGL_GBM.Window NextSwapSurface0 %p -> %p\n", lastBO, nextBO); + return (jlong) (intptr_t) nextBO; +} + diff --git a/src/newt/native/egl_gbm.c b/src/newt/native/egl_gbm.c deleted file mode 100644 index afbab9ef2..000000000 --- a/src/newt/native/egl_gbm.c +++ /dev/null @@ -1,353 +0,0 @@ -#include "egl_gbm.h" - -static jmethodID notifyScreenModeID = NULL; - -static jmethodID sizeChangedID = NULL; -static jmethodID positionChangedID = NULL; -static jmethodID visibleChangedID = NULL; -static jmethodID windowDestroyNotifyID = 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( 0 <= drm->fd ) { - drmClose(drm->fd); - drm->fd = -1; - } - 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, jboolean verbose) -{ - static const char *linux_dri_card0 = "/dev/dri/card0"; - static const char *modules[] = { - "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "msm" - }; - int module_count = sizeof(modules) / sizeof(const char*); - const char * module_used = NULL; - int ret, i, j, area; - DRM_HANDLE *drm = calloc(1, sizeof(DRM_HANDLE)); - drmModeRes *resources = NULL; - -#ifdef VERBOSE_ON - verbose = JNI_TRUE; -#endif - - if( verbose ) { - ERR_PRINT( "EGL_GBM.Display initDrm start\n"); - } - - drm->fd = -1; - -#if 1 - // try linux_dri_card0 first - drm->fd = open(linux_dri_card0, O_RDWR); - ERR_PRINT("EGL_GBM.Display trying to open '%s': success %d\n", - linux_dri_card0, 0<=drm->fd); -#endif - - // try drm modules - for (i = 0; 0>drm->fd && i < module_count; i++) { - if( verbose ) { - ERR_PRINT("EGL_GBM.Display trying to load module[%d/%d] %s...", - i, module_count, modules[i]); - } - drm->fd = drmOpen(modules[i], NULL); - if (drm->fd < 0) { - if( verbose ) { - ERR_PRINT("failed.\n"); - } - } else { - if( verbose ) { - ERR_PRINT("success.\n"); - } - module_used = modules[i]; - } - } - if (drm->fd < 0) { - ERR_PRINT("EGL_GBM.Display could not open drm device\n"); - goto error; - } - -#if 1 - ret = drmSetMaster(drm->fd); - if(ret) { - //drmDropMaster(int fd); - DBG_PRINT( "EGL_GBM.Display drmSetMaster fd %d: FAILED: %d %s\n", - drm->fd, ret, strerror(errno)); - } else { - DBG_PRINT( "EGL_GBM.Display drmSetMaster fd %d: OK\n", drm->fd); - } -#endif - - resources = drmModeGetResources(drm->fd); - if ( NULL == resources ) { - ERR_PRINT("EGL_GBM.Display drmModeGetResources failed on module %s: %s\n", - module_used, strerror(errno)); - goto error; - } - - if( verbose ) { - for (i = 0; i < resources->count_connectors; i++) { - drmModeConnector * c = drmModeGetConnector(drm->fd, resources->connectors[i]); - int chosen = DRM_MODE_CONNECTED == c->connection; - ERR_PRINT( "EGL_GBM.Display Connector %d/%d chosen %d: id[con 0x%x, enc 0x%x], type %d[id 0x%x], connection %d, dim %dx%x mm, modes %d, encoders %d\n", - i, resources->count_connectors, chosen, - c->connector_id, c->encoder_id, c->connector_type, c->connector_type_id, - c->connection, c->mmWidth, c->mmHeight, c->count_modes, c->count_encoders); - drmModeFreeConnector(c); - } - } - /* find a connected connector: */ - for (i = 0; i < resources->count_connectors; i++) { - drm->connector = drmModeGetConnector(drm->fd, resources->connectors[i]); - if( DRM_MODE_CONNECTED == drm->connector->connection ) { - break; - } else { - drmModeFreeConnector(drm->connector); - drm->connector = NULL; - } - } - if( i >= resources->count_connectors ) { - /* we could be fancy and listen for hotplug events and wait for - * a connector.. - */ - ERR_PRINT("EGL_GBM.Display no connected connector (connector count %d, module %s)!\n", - resources->count_connectors, module_used); - goto error; - } - - /* find highest resolution mode: */ - for (i = 0, j = -1, 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; - j = i; - } - if( verbose ) { - ERR_PRINT( "EGL_GBM.Display Mode %d/%d (max-chosen %d): clock %d, %dx%d @ %d Hz, type %d, name <%s>\n", - i, drm->connector->count_modes, j, - current_mode->clock, current_mode->hdisplay, current_mode->vdisplay, current_mode->vrefresh, - current_mode->type, current_mode->name); - } - } - if ( NULL == drm->current_mode ) { - ERR_PRINT("EGL_GBM.Display could not find mode (module %s)!\n", module_used); - goto error; - } - - if( verbose ) { - for (i = 0; i < resources->count_encoders; i++) { - drmModeEncoder * e = drmModeGetEncoder(drm->fd, resources->encoders[i]); - int chosen = e->encoder_id == drm->connector->encoder_id; - ERR_PRINT( "EGL_GBM.Display Encoder %d/%d chosen %d: id 0x%x, type %d, crtc_id 0x%x, possible[crtcs %d, clones %d]\n", - i, resources->count_encoders, chosen, - e->encoder_id, e->encoder_type, e->crtc_id, - e->possible_crtcs, e->possible_clones); - drmModeFreeEncoder(e); - } - } - /* find encoder: */ - for (i = 0; i < resources->count_encoders; i++) { - drm->encoder = drmModeGetEncoder(drm->fd, resources->encoders[i]); - if( drm->encoder->encoder_id == drm->connector->encoder_id ) { - break; - } else { - drmModeFreeEncoder(drm->encoder); - drm->encoder = NULL; - } - } - if ( i >= resources->count_encoders ) { - ERR_PRINT("EGL_GBM.Display no encoder (module %s)!\n", module_used); - goto error; - } - for (i = 0; i < resources->count_crtcs; i++) { - if (resources->crtcs[i] == drm->encoder->crtc_id) { - drm->crtc_index = i; - break; - } - } - - drmModeFreeResources(resources); - resources = NULL; - - if( verbose ) { - DBG_PRINT( "EGL_GBM.Display initDrm end.X0 OK: fd %d, enc_id 0x%x, crtc_id 0x%x, conn_id 0x%x, curMode %s\n", - drm->fd, drm->encoder->encoder_id, drm->encoder->crtc_id, drm->connector->connector_id, drm->current_mode->name); - } - - // drm->crtc_id = encoder->crtc_id; - // drm->connector_id = connector->connector_id; - return (jlong) (intptr_t) drm; - -error: - if( verbose ) { - DBG_PRINT( "EGL_GBM.Display initDrm end.X2 ERROR\n"); - } - drmModeFreeResources(resources); - resources = NULL; - 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); - DBG_PRINT( "EGL_GBM.Display OpenGBMDisplay0 handle %p\n", dev); - 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; - DBG_PRINT( "EGL_GBM.Display CloseGBMDisplay0 handle %p\n", dev); - gbm_device_destroy(dev); -} - -JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_DispatchMessages0 - (JNIEnv *env, jclass clazz) -{ -} - -/** - * 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 jboolean JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_initIDs - (JNIEnv *env, jclass clazz) -{ - sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V"); - positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(ZII)V"); - visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V"); - windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "(Z)Z"); - if (sizeChangedID == NULL || - positionChangedID == NULL || - visibleChangedID == NULL || - windowDestroyNotifyID == NULL) { - DBG_PRINT( "initIDs failed\n" ); - return JNI_FALSE; - } - DBG_PRINT( "EGL_GBM.Window initIDs ok\n" ); - return JNI_TRUE; -} - -#ifndef DRM_FORMAT_MOD_LINEAR - #define DRM_FORMAT_MOD_LINEAR 0 -#endif - -WEAK struct gbm_surface * -gbm_surface_create_with_modifiers(struct gbm_device *gbm, - uint32_t width, uint32_t height, - uint32_t format, - const uint64_t *modifiers, - const unsigned int count); - -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, jint visual_id) -{ - DRM_HANDLE *drm = (DRM_HANDLE*) (intptr_t) jdrm; - struct gbm_device *dev = (struct gbm_device *) (intptr_t) jgbm; - uint64_t modifier = DRM_FORMAT_MOD_LINEAR; - struct gbm_surface *surface = NULL; - - if( gbm_surface_create_with_modifiers ) { - surface = gbm_surface_create_with_modifiers(dev, width, height, visual_id, &modifier, 1); - } - if( NULL == surface ) { - if( gbm_surface_create_with_modifiers ) { - DBG_PRINT( "EGL_GBM.Window CreateWindow0 gbm_surface_create_with_modifiers failed\n"); - } - surface = gbm_surface_create(dev, width, height, visual_id, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); - } - if ( NULL == surface ) { - DBG_PRINT( "EGL_GBM.Window CreateWindow0 gbm_surface_create failed\n"); - return 0; - } - - // Done in Java code .. - // (*env)->CallVoidMethod(env, obj, visibleChangedID, JNI_TRUE); - - DBG_PRINT( "EGL_GBM.Window CreateWindow0 handle %p\n", surface); - 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; - DBG_PRINT( "EGL_GBM.Window CloseWindow0 handle %p\n", surface); - gbm_surface_destroy(surface); -} - diff --git a/src/newt/native/egl_gbm_drmflip.c b/src/newt/native/egl_gbm_drmflip.c deleted file mode 100644 index 4dda026a0..000000000 --- a/src/newt/native/egl_gbm_drmflip.c +++ /dev/null @@ -1,230 +0,0 @@ -#include "egl_gbm.h" - -#include <EGL/egl.h> - -WEAK uint64_t -gbm_bo_get_modifier(struct gbm_bo *bo); - -WEAK int -gbm_bo_get_plane_count(struct gbm_bo *bo); - -WEAK uint32_t -gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane); - -WEAK uint32_t -gbm_bo_get_offset(struct gbm_bo *bo, int plane); - -typedef struct { - struct gbm_bo *bo; - uint32_t fb_id; -} DRM_FB; - -static void page_flip_handler(int fd, unsigned int frame, - unsigned int sec, unsigned int usec, void *data) -{ - /* suppress 'unused parameter' warnings */ - (void)fd, (void)frame, (void)sec, (void)usec; - - int *waiting_for_flip = data; - *waiting_for_flip = 0; -} - -static drmEventContext drm_event_ctx = { - .version = 2, - .page_flip_handler = page_flip_handler, - }; - -static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) -{ - struct gbm_device * gbmDev = gbm_bo_get_device(bo); - int drm_fd = gbm_device_get_fd(gbmDev); - DRM_FB *fb = data; - - if (fb->fb_id) - drmModeRmFB(drm_fd, fb->fb_id); - - free(fb); -} - -static DRM_FB * drm_fb_get_from_bo(struct gbm_bo *bo) -{ - struct gbm_device * gbmDev = gbm_bo_get_device(bo); - int drm_fd = gbm_device_get_fd(gbmDev); - DRM_FB *fb = gbm_bo_get_user_data(bo); - uint32_t width, height, format, - strides[4] = {0}, handles[4] = {0}, - offsets[4] = {0}, flags = 0; - int ret = -1; - - if (fb) - return fb; - - fb = calloc(1, sizeof *fb); - fb->bo = bo; - - width = gbm_bo_get_width(bo); - height = gbm_bo_get_height(bo); - format = gbm_bo_get_format(bo); - - if (gbm_bo_get_modifier && gbm_bo_get_plane_count && - gbm_bo_get_stride_for_plane && gbm_bo_get_offset) { - - uint64_t modifiers[4] = {0}; - modifiers[0] = gbm_bo_get_modifier(bo); - const int num_planes = gbm_bo_get_plane_count(bo); - for (int i = 0; i < num_planes; i++) { - strides[i] = gbm_bo_get_stride_for_plane(bo, i); - handles[i] = gbm_bo_get_handle(bo).u32; - offsets[i] = gbm_bo_get_offset(bo, i); - modifiers[i] = modifiers[0]; - } - - if (modifiers[0]) { - flags = DRM_MODE_FB_MODIFIERS; - DBG_PRINT("Using modifier %" PRIx64 "\n", modifiers[0]); - } - - ret = drmModeAddFB2WithModifiers(drm_fd, width, height, - format, handles, strides, offsets, - modifiers, &fb->fb_id, flags); - if(ret) { - ERR_PRINT("drmModeAddFB2WithModifiers failed!\n"); - } else { - ERR_PRINT("drmModeAddFB2WithModifiers OK!\n"); - } - } - - if (ret) { - memcpy(handles, (uint32_t [4]){gbm_bo_get_handle(bo).u32,0,0,0}, 16); - memcpy(strides, (uint32_t [4]){gbm_bo_get_stride(bo),0,0,0}, 16); - memset(offsets, 0, 16); - ret = drmModeAddFB2(drm_fd, width, height, format, - handles, strides, offsets, &fb->fb_id, 0); - if(ret) { - ERR_PRINT("drmModeAddFB2 failed!\n"); - } else { - ERR_PRINT("drmModeAddFB2 OK!\n"); - } - } - - if (ret) { - ERR_PRINT("failed to create fb: %s\n", strerror(errno)); - free(fb); - return NULL; - } - - gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback); - - return fb; -} - -JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_FirstSwapSurface0 - (JNIEnv *env, jobject obj, jlong jdrm, jlong jgbmSurface, jlong jeglDisplay, jlong jeglSurface) -{ - DRM_HANDLE *drm = (DRM_HANDLE*) (intptr_t) jdrm; - struct gbm_surface *gbmSurface = (struct gbm_surface *) (intptr_t) jgbmSurface; - EGLDisplay eglDisplay = (EGLDisplay) (intptr_t) jeglDisplay; - EGLSurface eglSurface = (EGLSurface) (intptr_t) jeglSurface; - struct gbm_bo *nextBO = NULL; - DRM_FB *fb = NULL; - int ret; - - if ( EGL_TRUE != eglSwapBuffers(eglDisplay, eglSurface) ) { - EGLint err = eglGetError(); - ERR_PRINT("Failed eglSwapBuffers, err 0x%x\n", err); - return 0; - } - nextBO = gbm_surface_lock_front_buffer(gbmSurface); - fb = drm_fb_get_from_bo(nextBO); - if (!fb) { - ERR_PRINT("Failed to get a new framebuffer BO\n"); - return 0; - } - /* set mode: */ - ret = drmModeSetCrtc(drm->fd, drm->encoder->crtc_id, fb->fb_id, 0, 0, - &drm->connector->connector_id, 1, drm->current_mode); - /** - int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId, - uint32_t x, uint32_t y, uint32_t *connectors, int count, - drmModeModeInfoPtr mode); - */ - - if (ret) { - ERR_PRINT("drmModeSetCrtc failed to set mode: fd %d, enc_id 0x%x, crtc_id 0x%x, fb_id 0x%x, conn_id 0x%x, curMode %s: %d %s\n", - drm->fd, drm->encoder->encoder_id, drm->encoder->crtc_id, fb->fb_id, - drm->connector->connector_id, drm->current_mode->name, ret, strerror(errno)); - return 0; - } - DBG_PRINT( "EGL_GBM.Window FirstSwapSurface0 nextBO %p, fd %d, enc_id 0x%x, crtc_id 0x%x, fb_id 0x%x, conn_id 0x%x, curMode %s\n", - nextBO, - drm->fd, drm->encoder->encoder_id, drm->encoder->crtc_id, fb->fb_id, - drm->connector->connector_id, drm->current_mode->name); - return (jlong) (intptr_t) nextBO; -} - -JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_WindowDriver_NextSwapSurface0 - (JNIEnv *env, jobject obj, jlong jdrm, jlong jgbmSurface, jlong jlastBO, jlong jeglDisplay, jlong jeglSurface) -{ - DRM_HANDLE *drm = (DRM_HANDLE*) (intptr_t) jdrm; - struct gbm_surface *gbmSurface = (struct gbm_surface *) (intptr_t) jgbmSurface; - struct gbm_bo *lastBO = (struct gbm_bo*) (intptr_t) jlastBO, *nextBO = NULL; - EGLDisplay eglDisplay = (EGLDisplay) (intptr_t) jeglDisplay; - EGLSurface eglSurface = (EGLSurface) (intptr_t) jeglSurface; - DRM_FB *fb = NULL; - int ret, waiting_for_flip = 1; - fd_set fds; - - if ( EGL_TRUE != eglSwapBuffers(eglDisplay, eglSurface) ) { - EGLint err = eglGetError(); - ERR_PRINT("Failed eglSwapBuffers, err 0x%x\n", err); - return 0; - } - nextBO = gbm_surface_lock_front_buffer(gbmSurface); - fb = drm_fb_get_from_bo(nextBO); - if (!fb) { - ERR_PRINT("Failed to get a new framebuffer BO\n"); - return 0; - } - - /** - * Here you could also update drm plane layers if you want - * hw composition - */ - ret = drmModePageFlip(drm->fd, drm->encoder->crtc_id, fb->fb_id, - DRM_MODE_PAGE_FLIP_EVENT, &waiting_for_flip); - if (ret) { - ERR_PRINT("drmModePageFlip failed to queue page flip: fd %d, enc_id 0x%x, crtc_id 0x%x, fb_id 0x%x, conn_id 0x%x, curMode %s: %p -> %p: %d %s\n", - drm->fd, drm->encoder->encoder_id, drm->encoder->crtc_id, fb->fb_id, - drm->connector->connector_id, drm->current_mode->name, - lastBO, nextBO, ret, strerror(errno)); - return 0; - } - - while (waiting_for_flip) { - FD_ZERO(&fds); - FD_SET(0, &fds); - FD_SET(drm->fd, &fds); - - ret = select(drm->fd + 1, &fds, NULL, NULL, NULL); - if (ret < 0) { - ERR_PRINT("select err: %s\n", strerror(errno)); - return ret; - } else if (ret == 0) { - ERR_PRINT("select timeout!\n"); - return -1; - } else if (FD_ISSET(0, &fds)) { - ERR_PRINT("user interrupted!\n"); - return 0; - } - drmHandleEvent(drm->fd, &drm_event_ctx); - } - - /* release last buffer to render on again: */ - if( NULL != lastBO ) { - gbm_surface_release_buffer(gbmSurface, lastBO); - } - - DBG_PRINT( "EGL_GBM.Window NextSwapSurface0 %p -> %p\n", lastBO, nextBO); - return (jlong) (intptr_t) nextBO; -} - |