diff options
author | Erik De Rijcke <[email protected]> | 2015-05-10 22:06:27 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-11-21 03:44:24 +0100 |
commit | df599b1c9b08da7335b2c6036c1c9f308ec56387 (patch) | |
tree | 5e2044bfda07efbc1b2edf3d1b422286fc35aa2d | |
parent | e1d767a4063d2503f9099d24a570664f6acd1a34 (diff) |
add native gbm implementation for drm and gbm initialization.
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java | 134 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java | 4 | ||||
-rw-r--r-- | src/newt/native/gbm.c | 131 |
3 files changed, 117 insertions, 152 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java index 0e43536c6..00a1ca384 100644 --- a/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java +++ b/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java @@ -14,9 +14,7 @@ package jogamp.newt.driver.gbm; import com.jogamp.nativewindow.AbstractGraphicsDevice; -import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.egl.EGLGraphicsDevice; -import com.jogamp.opengl.GLDrawableFactory; import jogamp.newt.DisplayImpl; import jogamp.newt.NEWTJNILibLoader; import jogamp.opengl.egl.EGLDisplayUtil; @@ -25,42 +23,8 @@ public class DisplayDriver extends DisplayImpl { static { NEWTJNILibLoader.loadNEWT(); - - if (!DisplayDriver.initIDs()) { - throw new NativeWindowException("Failed to initialize gbm Display jmethodIDs"); - } -// if (!ScreenDriver.initIDs()) { -// throw new NativeWindowException("Failed to initialize gbm Screen jmethodIDs"); -// } -// if (!WindowDriver.initIDs()) { -// throw new NativeWindowException("Failed to initialize gbm Window jmethodIDs"); -// } - } - - protected static native boolean initIDs(); - - private long dev; - private long surface; - - private int fd; - private long mode; - - static { - NEWTJNILibLoader.loadNEWT(); - GLDrawableFactory.initSingleton(); } - //private final EGLGraphicsDevice.EGLDisplayLifecycleCallback eglDisplayLifecycleCallback; - private long connector; - private long encoder; - - public long getConnector() { - return connector; - } - - public long getEncoder() { - return encoder; - } public static void initSingleton() { // just exist to ensure static init has been run @@ -68,115 +32,25 @@ public class DisplayDriver extends DisplayImpl { @Override protected void createNativeImpl() { - final EGLGraphicsDevice eglGraphicsDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(dev, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); + final EGLGraphicsDevice eglGraphicsDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(initGbm(), AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); eglGraphicsDevice.open(); this.aDevice = eglGraphicsDevice; } - private native void initGbm(); + private native long initGbm(); // { // // // } - public long getSurface() { - return surface; - } - - private native void init(); -// { -// -// String[] modules = { -// "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "msm" -// }; -// drmModeRes resources; -// connector = null; -// encoder = null; -// -// for (int i = 0; i < modules.length; i++) { -// if(DEBUG){ -// System.out.println(String.format("trying to load module %s...", modules[i])); -// } -// fd = DrmLibrary.INSTANCE.drmOpen(modules[i], null); -// if (fd < 0) { -// throw new NativeWindowException("Can not open drm device."); -// } else { -// break; -// } -// } -// -// if (fd < 0) { -// throw new NativeWindowException("could not open drm device"); -// } -// -// resources = DrmLibrary.INSTANCE.drmModeGetResources(fd); -// if (resources == null) { -// throw new NativeWindowException("drmModeGetResources failed"); -// } -// -// /* find a connected connector: */ -// for (int i = 0; i < resources.count_connectors; i++) { -// connector = DrmLibrary.INSTANCE.drmModeGetConnector(fd, resources.connectors.getInt(i)); -// if (connector.connection == drmModeConnection.DRM_MODE_CONNECTED) { -// /* it's connected, let's use this! */ -// break; -// } -// DrmLibrary.INSTANCE.drmModeFreeConnector(connector); -// connector = null; -// } -// -// if (connector == null) { -// /* we could be fancy and listen for hotplug events and wait for -// * a connector.. -// */ -// throw new NativeWindowException("no connected connector!"); -// } -// -// /* find highest resolution mode: */ -// drmModeModeInfo[] drmModeModeInfos = (drmModeModeInfo[]) connector.modes.toArray(connector.count_modes); -// for (int i = 0, area = 0; i < drmModeModeInfos.length; i++) { -// drmModeModeInfo current_mode = drmModeModeInfos[i]; -// int current_area = current_mode.hdisplay * current_mode.vdisplay; -// if (current_area > area) { -// mode = current_mode; -// area = current_area; -// } -// } -// -// if (mode == null) { -// throw new NativeWindowException("could not find mode!"); -// } -// -// /* find encoder: */ -// for (int i = 0; i < resources.count_encoders; i++) { -// encoder = DrmLibrary.INSTANCE.drmModeGetEncoder(fd, resources.encoders.getInt(i)); -// if (encoder.encoder_id == connector.encoder_id) { -// break; -// } -// DrmLibrary.INSTANCE.drmModeFreeEncoder(encoder); -// encoder = null; -// } -// -// if (encoder == null) { -// throw new NativeWindowException("no encoder!"); -// } -// -// final int crtc_id = encoder.crtc_id; -// final int connector_id = connector.connector_id; -// -// dev = GbmLibrary.INSTANCE.gbm_create_device(fd); -// } - @Override protected void closeNativeImpl(final AbstractGraphicsDevice aDevice) { //DrmLibrary.INSTANCE.drmModeFreeConnector(this.connector); aDevice.close(); destroyDisplay(); //GbmLibrary.INSTANCE.gbm_device_destroy(dev); - this.dev = 0; //CLibrary.INSTANCE.close(this.fd); - this.fd = 0; } private native void destroyDisplay(); @@ -185,8 +59,4 @@ public class DisplayDriver extends DisplayImpl { protected void dispatchMessagesNative() { //NA } - - public long getGbmDevice() { - return dev; - } } diff --git a/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java index 9c5803e1a..cbada076c 100644 --- a/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java @@ -56,7 +56,7 @@ public class WindowDriver extends WindowImpl { chosenCaps.setBackgroundOpaque(capsRequested.isBackgroundOpaque()); } setGraphicsConfiguration(cfg); - long nativeWindowHandle = createSurface(display.getGbmDevice()); + long nativeWindowHandle = createSurface(); if (nativeWindowHandle == 0) { throw new NativeWindowException("Error creating egl window: "+cfg); } @@ -70,7 +70,7 @@ public class WindowDriver extends WindowImpl { focusChanged(false, true); } - private native long createSurface(final long gbmDevice); + private native long createSurface(); //{ // surface = GbmLibrary.INSTANCE.gbm_surface_create(dev, // mode.hdisplay, mode.vdisplay, diff --git a/src/newt/native/gbm.c b/src/newt/native/gbm.c index 8b0baedc5..19efb8d7a 100644 --- a/src/newt/native/gbm.c +++ b/src/newt/native/gbm.c @@ -2,32 +2,118 @@ #include "jogamp_newt_driver_gbm_ScreenDriver.h" #include "jogamp_newt_driver_gbm_WindowDriver.h" -/* - * Class: jogamp_newt_driver_gbm_DisplayDriver - * Method: initIDs - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_initIDs - (JNIEnv *env, jclass cls){ - } +#include <xf86drm.h> +#include <xf86drmMode.h> +#include <gbm.h> + +static struct { + struct gbm_device *dev; + struct gbm_surface *surface; +} gbm; + +static struct { + int fd; + drmModeModeInfo *mode; + uint32_t crtc_id; + uint32_t connector_id; +} drm; + +struct drm_fb { + struct gbm_bo *bo; + uint32_t fb_id; +}; /* * Class: jogamp_newt_driver_gbm_DisplayDriver * Method: initGbm - * Signature: ()V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_initGbm (JNIEnv *env, jobject this){ + static const char *modules[] = { + "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "msm" + }; + drmModeRes *resources; + drmModeConnector *connector = NULL; + drmModeEncoder *encoder = NULL; + int i, area; - } + for (i = 0; i < ARRAY_SIZE(modules); i++) { + printf("trying to load module %s...", modules[i]); + drm.fd = drmOpen(modules[i], NULL); + if (drm.fd < 0) { + printf("failed.\n"); + } else { + printf("success.\n"); + break; + } + } -/* - * Class: jogamp_newt_driver_gbm_DisplayDriver - * Method: init - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_init - (JNIEnv *env, jobject this){ + if (drm.fd < 0) { + printf("could not open drm device\n"); + return -1; + } + + resources = drmModeGetResources(drm.fd); + if (!resources) { + printf("drmModeGetResources failed: %s\n", strerror(errno)); + return -1; + } + + /* find a connected connector: */ + for (i = 0; i < resources->count_connectors; i++) { + connector = drmModeGetConnector(drm.fd, resources->connectors[i]); + if (connector->connection == DRM_MODE_CONNECTED) { + /* it's connected, let's use this! */ + break; + } + drmModeFreeConnector(connector); + connector = NULL; + } + + if (!connector) { + /* we could be fancy and listen for hotplug events and wait for + * a connector.. + */ + printf("no connected connector!\n"); + return -1; + } + + /* find highest resolution mode: */ + for (i = 0, area = 0; i < connector->count_modes; i++) { + drmModeModeInfo *current_mode = &connector->modes[i]; + int current_area = current_mode->hdisplay * current_mode->vdisplay; + if (current_area > area) { + drm.mode = current_mode; + area = current_area; + } + } + + if (!drm.mode) { + printf("could not find mode!\n"); + return -1; + } + + /* find encoder: */ + for (i = 0; i < resources->count_encoders; i++) { + encoder = drmModeGetEncoder(drm.fd, resources->encoders[i]); + if (encoder->encoder_id == connector->encoder_id) + break; + drmModeFreeEncoder(encoder); + encoder = NULL; + } + + if (!encoder) { + printf("no encoder!\n"); + return -1; + } + + drm.crtc_id = encoder->crtc_id; + drm.connector_id = connector->connector_id; + + gbm.dev = gbm_create_device(drm.fd); + + return gbm.dev; } /* @@ -45,5 +131,14 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_destroyDisplay * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_gbm_WindowDriver_createSurface - (JNIEnv *env, jobject this, jlong gbmDevice){ + (JNIEnv *env, jobject this){ + gbm.surface = gbm_surface_create(gbm.dev, + drm.mode->hdisplay, drm.mode->vdisplay, + GBM_FORMAT_XRGB8888, + GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + if (!gbm.surface) { + printf("failed to create gbm surface\n"); + return -1; + } + return gbm.surface; }
\ No newline at end of file |