Skip to content

Commit

Permalink
NEWT: Adding support for BCM VC IV (Broadcom VideoCodec 4) and Linux …
Browse files Browse the repository at this point in the history
…console mouse tracker

Rasperry PI uses the 'BCM VC IV' GPU via console as it's default configuration.
This driver enables direct support for JOGL/NEWT.

Due to the lack of detection (TODO) users have to specify the Java property:
  -Dnativewindow.ws.name=jogamp.newt.driver.bcm.vc.iv

- Autodetection should be included in 'NativeWindowFactory._getNativeWindowingType()'
  while adding a new TYPE: 'TYPE_BCM_VC_IV'.

- Autodetection may need to detect whether an X11 Display runs and the installed
  EGL library uses it (instead of the default console one)

This work is authored in coop w/ Xerxes Rånby <xerxes@zafena.se>!
  • Loading branch information
sgothel committed Aug 16, 2012
1 parent 3732d01 commit 0ca4813
Show file tree
Hide file tree
Showing 11 changed files with 934 additions and 12 deletions.
10 changes: 9 additions & 1 deletion make/build-common.xml
Expand Up @@ -364,34 +364,42 @@
<property name="newt-awt.jar" value="${build.newt}/newt-awt.jar" />
<property name="newt-swt.jar" value="${build.newt}/newt-swt.jar" />
<property name="newt-event.jar" value="${build.newt}/newt-event.jar" /> <!-- using NEWT events w/o NEWT -->
<property name="newt-driver-linux.jar" value="${build.newt}/newt-driver-linux.jar" />
<property name="newt-driver-x11.jar" value="${build.newt}/newt-driver-x11.jar" />
<property name="newt-driver-win.jar" value="${build.newt}/newt-driver-win.jar" />
<property name="newt-driver-osx.jar" value="${build.newt}/newt-driver-osx.jar" />
<property name="newt-driver-android.jar" value="${build.newt}/newt-driver-android.jar" /> <!-- excluded from all -->
<property name="newt-driver-kd.jar" value="${build.newt}/newt-driver-kd.jar" /> <!-- excluded from all -->
<property name="newt-driver-intelgdl.jar" value="${build.newt}/newt-driver-intelgdl.jar" /> <!-- excluded from all -->
<property name="newt-driver-bcm.jar" value="${build.newt}/newt-driver-bcm.jar" /> <!-- excluded from all -->
<property name="newt-driver-bcm-old.jar" value="${build.newt}/newt-driver-bcm-old.jar" /> <!-- excluded from all -->
<property name="newt-driver-bcm-vc.jar" value="${build.newt}/newt-driver-bcm-vc.jar" />
<path id="newt_all_atoms.classpath">
<pathelement location="${newt-core.jar}" />
<pathelement location="${newt-ogl.jar}" />
<pathelement location="${newt-awt.jar}" />
<pathelement location="${newt-swt.jar}" />
<pathelement location="${newt-driver-linux.jar}" />
<pathelement location="${newt-driver-x11.jar}" />
<pathelement location="${newt-driver-win.jar}" />
<pathelement location="${newt-driver-osx.jar}" />
<pathelement location="${newt-driver-bcm-vc.jar}" />
</path>
<path id="newt_all-noawt_atoms.classpath">
<pathelement location="${newt-core.jar}" />
<pathelement location="${newt-ogl.jar}" />
<pathelement location="${newt-driver-linux.jar}" />
<pathelement location="${newt-driver-x11.jar}" />
<pathelement location="${newt-driver-win.jar}" />
<pathelement location="${newt-driver-osx.jar}" />
<pathelement location="${newt-driver-bcm-vc.jar}" />
</path>
<path id="newt_all-mobile_atoms.classpath">
<pathelement location="${newt-core.jar}" />
<pathelement location="${newt-ogl.jar}" />
<pathelement location="${newt-driver-linux.jar}" />
<pathelement location="${newt-driver-x11.jar}" />
<pathelement location="${newt-driver-win.jar}" />
<pathelement location="${newt-driver-bcm-vc.jar}" />
</path>
<path id="newt_all-android_atoms.classpath">
<pathelement location="${newt-core.jar}" />
Expand Down
Expand Up @@ -32,7 +32,7 @@
*
*/

package jogamp.newt.driver.broadcom.egl;
package jogamp.newt.driver.bcm.egl;

import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeWindowException;
Expand Down
Expand Up @@ -32,7 +32,7 @@
*
*/

package jogamp.newt.driver.broadcom.egl;
package jogamp.newt.driver.bcm.egl;

import javax.media.nativewindow.DefaultGraphicsScreen;
import javax.media.nativewindow.util.Dimension;
Expand Down
Expand Up @@ -32,7 +32,7 @@
*
*/

package jogamp.newt.driver.broadcom.egl;
package jogamp.newt.driver.bcm.egl;

import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.GraphicsConfigurationFactory;
Expand Down
78 changes: 78 additions & 0 deletions src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Display.java
@@ -0,0 +1,78 @@
/**
* Copyright 2012 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/

package jogamp.newt.driver.bcm.vc.iv;

import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeWindowException;

import jogamp.newt.DisplayImpl;
import jogamp.newt.NEWTJNILibLoader;
import jogamp.opengl.egl.EGL;
import jogamp.opengl.egl.EGLDisplayUtil;

public class Display extends DisplayImpl {
static {
NEWTJNILibLoader.loadNEWT();

if (!Display.initIDs()) {
throw new NativeWindowException("Failed to initialize bcm.vc.iv Display jmethodIDs");
}
if (!Screen.initIDs()) {
throw new NativeWindowException("Failed to initialize bcm.vc.iv Screen jmethodIDs");
}
if (!Window.initIDs()) {
throw new NativeWindowException("Failed to initialize bcm.vc.iv Window jmethodIDs");
}
}

public static void initSingleton() {
// just exist to ensure static init has been run
}


public Display() {
}

protected void createNativeImpl() {
// FIXME: map name to EGL_*_DISPLAY
aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
}

protected void closeNativeImpl() {
aDevice.close();
}

protected void dispatchMessagesNative() {
DispatchMessages();
}

protected static native boolean initIDs();
private native void DispatchMessages();
}

73 changes: 73 additions & 0 deletions src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Screen.java
@@ -0,0 +1,73 @@
/**
* Copyright 2012 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/

package jogamp.newt.driver.bcm.vc.iv;

import javax.media.nativewindow.DefaultGraphicsScreen;
import javax.media.nativewindow.util.Dimension;
import javax.media.nativewindow.util.Point;

import jogamp.newt.ScreenImpl;

public class Screen extends ScreenImpl {
static {
Display.initSingleton();
}

public Screen() {
}

protected void createNativeImpl() {
aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
initNative();
}

protected void closeNativeImpl() { }

protected int validateScreenIndex(int idx) {
return 0; // only one screen available
}

protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
virtualOrigin.setX(0);
virtualOrigin.setY(0);
virtualSize.setWidth(cachedWidth);
virtualSize.setHeight(cachedHeight);
}

protected void setScreenSize(int width, int height) {
cachedWidth = width;
cachedHeight = height;
}

private static int cachedWidth = 0;
private static int cachedHeight = 0;

protected static native boolean initIDs();
protected native void initNative();
}
149 changes: 149 additions & 0 deletions src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Window.java
@@ -0,0 +1,149 @@
/**
* Copyright 2012 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/

package jogamp.newt.driver.bcm.vc.iv;

import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.GraphicsConfigurationFactory;
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.VisualIDHolder;
import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.Point;

import jogamp.newt.WindowImpl;
import jogamp.newt.driver.linux.LinuxMouseTracker;

public class Window extends WindowImpl {
private static final String WINDOW_CLASS_NAME = "NewtWindow";

static {
Display.initSingleton();
}

public Window() {
}

protected void createNativeImpl() {
if(0!=getParentWindowHandle()) {
throw new RuntimeException("Window parenting not supported (yet)");
}
final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
if (null == cfg) {
throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
}
setGraphicsConfiguration(cfg);

nativeWindowHandle = CreateWindow(getWidth(), getHeight());
if (nativeWindowHandle == 0) {
throw new NativeWindowException("Error creating egl window: "+cfg);
}
setVisible0(nativeWindowHandle, false);
setWindowHandle(nativeWindowHandle);
if (0 == getWindowHandle()) {
throw new NativeWindowException("Error native Window Handle is null");
}
windowHandleClose = nativeWindowHandle;
addWindowListener(LinuxMouseTracker.getSingleton());
focusChanged(false, true);
}

protected void closeNativeImpl() {
removeWindowListener(LinuxMouseTracker.getSingleton());

if(0!=windowHandleClose) {
CloseWindow(windowHandleClose, windowUserData);
windowUserData=0;
}
}

protected void requestFocusImpl(boolean reparented) {
focusChanged(false, true);
}

protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
setVisible0(nativeWindowHandle, 0 != ( FLAG_IS_VISIBLE & flags));
visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
}

if(0!=nativeWindowHandle) {
if(0 != ( FLAG_CHANGE_FULLSCREEN & flags)) {
final boolean fs = 0 != ( FLAG_IS_FULLSCREEN & flags) ;
setFullScreen0(nativeWindowHandle, fs);
if(fs) {
return true;
}
}
// int _x=(x>=0)?x:this.x;
// int _y=(x>=0)?y:this.y;
width=(width>0)?width:getWidth();
height=(height>0)?height:getHeight();
if(width>0 || height>0) {
setSize0(nativeWindowHandle, width, height);
}
if(x>=0 || y>=0) {
System.err.println("setPosition n/a in KD");
}
}

if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
}

return true;
}

protected Point getLocationOnScreenImpl(int x, int y) {
return new Point(x,y);
}

protected void updateInsetsImpl(Insets insets) {
// nop ..
}

//----------------------------------------------------------------------
// Internals only
//

protected static native boolean initIDs();
private native long CreateWindow(int width, int height);
private native long RealizeWindow(long eglWindowHandle);
private native int CloseWindow(long eglWindowHandle, long userData);
private native void setVisible0(long eglWindowHandle, boolean visible);
private native void setSize0(long eglWindowHandle, int width, int height);
private native void setFullScreen0(long eglWindowHandle, boolean fullscreen);

private void windowCreated(long userData) {
windowUserData=userData;
}

private long nativeWindowHandle;
private long windowHandleClose;
private long windowUserData;
}

0 comments on commit 0ca4813

Please sign in to comment.