diff options
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java | 192 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/gbm/ScreenDriver.java | 88 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java | 118 | ||||
-rw-r--r-- | src/newt/native/gbm.c | 49 |
4 files changed, 447 insertions, 0 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java new file mode 100644 index 000000000..0e43536c6 --- /dev/null +++ b/src/newt/classes/jogamp/newt/driver/gbm/DisplayDriver.java @@ -0,0 +1,192 @@ +//Copyright 2015 Erik De Rijcke +// +//Licensed under the Apache License,Version2.0(the"License"); +//you may not use this file except in compliance with the License. +//You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing,software +//distributed under the License is distributed on an"AS IS"BASIS, +//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. +//See the License for the specific language governing permissions and +//limitations under the License. +package jogamp.newt.driver.gbm; + +import com.jogamp.nativewindow.AbstractGraphicsDevice; +import com.jogamp.nativewindow.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; + +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 + } + + @Override + protected void createNativeImpl() { + final EGLGraphicsDevice eglGraphicsDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(dev, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); + eglGraphicsDevice.open(); + + this.aDevice = eglGraphicsDevice; + } + + private native void 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(); + + @Override + protected void dispatchMessagesNative() { + //NA + } + + public long getGbmDevice() { + return dev; + } +} diff --git a/src/newt/classes/jogamp/newt/driver/gbm/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/gbm/ScreenDriver.java new file mode 100644 index 000000000..0066d42e4 --- /dev/null +++ b/src/newt/classes/jogamp/newt/driver/gbm/ScreenDriver.java @@ -0,0 +1,88 @@ +package jogamp.newt.driver.gbm; + +import com.jogamp.nativewindow.DefaultGraphicsScreen; +import com.jogamp.newt.MonitorDevice; +import com.jogamp.newt.MonitorMode; +import jogamp.newt.MonitorModeProps; +import jogamp.newt.ScreenImpl; + +public class ScreenDriver extends ScreenImpl { + + + @Override + protected void createNativeImpl() { + this.aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), + this.screen_idx); + } + + @Override + protected void closeNativeImpl() { + } + + @Override + protected int validateScreenIndex(final int idx) { + return 0; + } + + @Override + protected void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Cache cache) { +// DisplayDriver display = (DisplayDriver) getDisplay(); +// final drmModeConnector connector = display.getConnector(); +// final drmModeEncoder encoder = display.getEncoder(); +// //TODO collect info from init method +// int[] props = new int[MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL]; +// int i = 0; +// props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL; +// props[i++] = connector.modes.hdisplay; // width +// props[i++] = connector.modes.vdisplay; // height +// props[i++] = ScreenImpl.default_sm_bpp; // FIXME +// props[i++] = ScreenImpl.default_sm_rate * 100; // FIXME +// props[i++] = connector.modes.flags; // flags +// props[i++] = 0; // mode_idx +// props[i++] = 0; // rotation +// final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, +// cache, +// props, +// 0); +// +// props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES]; +// i = 0; +// props[i++] = props.length; +// props[i++] = encoder.crtc_id; // crt_idx +// props[i++] = 0; // is-clone +// props[i++] = 1; // is-primary +// props[i++] = ScreenImpl.default_sm_widthmm; // FIXME +// props[i++] = ScreenImpl.default_sm_heightmm; // FIXME +// props[i++] = 0; // rotated viewport x pixel-units +// props[i++] = 0; // rotated viewport y pixel-units +// props[i++] = connector.modes.hdisplay; // rotated viewport width pixel-units +// props[i++] = connector.modes.vdisplay; // rotated viewport height pixel-units +// props[i++] = 0; // rotated viewport x window-units +// props[i++] = 0; // rotated viewport y window-units +// props[i++] = connector.modes.hdisplay; // rotated viewport width window-units +// props[i++] = connector.modes.vdisplay; // rotated viewport height window-units +// MonitorModeProps.streamInMonitorDevice(cache, +// this, +// currentMode, +// null, +// cache.monitorModes, +// props, +// 0, +// null); + } + + @Override + protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) { + //TODO collect info from init method + + return null; + } + + @Override + protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, + final MonitorMode mode) { + //TODO collect info from init method + + return false; + } +} diff --git a/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java new file mode 100644 index 000000000..9c5803e1a --- /dev/null +++ b/src/newt/classes/jogamp/newt/driver/gbm/WindowDriver.java @@ -0,0 +1,118 @@ +//Copyright 2015 Erik De Rijcke +// +//Licensed under the Apache License,Version2.0(the"License"); +//you may not use this file except in compliance with the License. +//You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing,software +//distributed under the License is distributed on an"AS IS"BASIS, +//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. +//See the License for the specific language governing permissions and +//limitations under the License. +package jogamp.newt.driver.gbm; + +import com.jogamp.nativewindow.*; +import com.jogamp.nativewindow.util.Insets; +import com.jogamp.nativewindow.util.Point; +import jogamp.newt.WindowImpl; +import jogamp.newt.driver.linux.LinuxEventDeviceTracker; +import jogamp.newt.driver.linux.LinuxMouseTracker; + +public class WindowDriver extends WindowImpl { + + private final LinuxMouseTracker linuxMouseTracker; + private final LinuxEventDeviceTracker linuxEventDeviceTracker; + + public WindowDriver() { + this.linuxMouseTracker = LinuxMouseTracker.getSingleton(); + this.linuxEventDeviceTracker = LinuxEventDeviceTracker.getSingleton(); + } + + @Override + protected void createNativeImpl() { + if (0 != getParentWindowHandle()) { + throw new RuntimeException("Window parenting not supported (yet)"); + } + + final ScreenDriver screen = (ScreenDriver) getScreen(); + final DisplayDriver display = (DisplayDriver) screen.getDisplay(); + + // Create own screen/device resource instance allowing independent ownership, + // while still utilizing shared EGL resources. + final AbstractGraphicsScreen aScreen = screen.getGraphicsScreen(); + final AbstractGraphicsDevice aDevice = display.getGraphicsDevice(); + final DefaultGraphicsScreen eglScreen = new DefaultGraphicsScreen(aDevice, aScreen.getIndex()); + + final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, eglScreen, VisualIDHolder.VID_UNDEFINED); + if (null == cfg) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + final Capabilities chosenCaps = (Capabilities) cfg.getChosenCapabilities(); + // FIXME: Pass along opaque flag, since EGL doesn't determine it + if(capsRequested.isBackgroundOpaque() != chosenCaps.isBackgroundOpaque()) { + chosenCaps.setBackgroundOpaque(capsRequested.isBackgroundOpaque()); + } + setGraphicsConfiguration(cfg); + long nativeWindowHandle = createSurface(display.getGbmDevice()); + if (nativeWindowHandle == 0) { + throw new NativeWindowException("Error creating egl window: "+cfg); + } + setWindowHandle(nativeWindowHandle); + if (0 == getWindowHandle()) { + throw new NativeWindowException("Error native Window Handle is null"); + } + + addWindowListener(linuxEventDeviceTracker); + addWindowListener(linuxMouseTracker); + focusChanged(false, true); + } + + private native long createSurface(final long gbmDevice); + //{ + // surface = GbmLibrary.INSTANCE.gbm_surface_create(dev, +// mode.hdisplay, mode.vdisplay, +// GbmLibrary.Constants.GBM_FORMAT_XRGB8888, +// GBM_BO.GBM_BO_USE_SCANOUT | GBM_BO.GBM_BO_USE_RENDERING); +// if (surface == null) { +// throw new NativeWindowException("failed to create gbm surface"); +// } +// +// return 0; + //} + + @Override + protected void closeNativeImpl() { + removeWindowListener(this.linuxMouseTracker); + removeWindowListener(this.linuxEventDeviceTracker); + } + + @Override + protected void requestFocusImpl(final boolean force) { + focusChanged(false, + true); + } + + @Override + protected boolean reconfigureWindowImpl(final int x, + final int y, + final int width, + final int height, + final int flags) { + return false; + } + + @Override + protected Point getLocationOnScreenImpl(final int x, + final int y) { + return new Point(x, + y); + } + + @Override + protected void updateInsetsImpl(final Insets insets) { + + } +} diff --git a/src/newt/native/gbm.c b/src/newt/native/gbm.c new file mode 100644 index 000000000..8b0baedc5 --- /dev/null +++ b/src/newt/native/gbm.c @@ -0,0 +1,49 @@ +#include "jogamp_newt_driver_gbm_DisplayDriver.h" +#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){ + } + +/* + * Class: jogamp_newt_driver_gbm_DisplayDriver + * Method: initGbm + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_initGbm + (JNIEnv *env, jobject this){ + + } + +/* + * Class: jogamp_newt_driver_gbm_DisplayDriver + * Method: init + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_init + (JNIEnv *env, jobject this){ + } + +/* + * Class: jogamp_newt_driver_gbm_DisplayDriver + * Method: destroyDisplay + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_driver_gbm_DisplayDriver_destroyDisplay + (JNIEnv *env, jobject this){ + } + +/* + * Class: jogamp_newt_driver_gbm_WindowDriver + * Method: createSurface + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_gbm_WindowDriver_createSurface + (JNIEnv *env, jobject this, jlong gbmDevice){ + }
\ No newline at end of file |