diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/bcm/egl/Display.java (renamed from src/newt/classes/jogamp/newt/driver/broadcom/egl/Display.java) | 2 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/bcm/egl/Screen.java (renamed from src/newt/classes/jogamp/newt/driver/broadcom/egl/Screen.java) | 2 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/bcm/egl/Window.java (renamed from src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java) | 2 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Display.java | 78 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Screen.java | 73 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Window.java | 149 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java | 221 | ||||
-rw-r--r-- | src/newt/native/bcm_egl.c (renamed from src/newt/native/BroadcomEGL.c) | 16 | ||||
-rw-r--r-- | src/newt/native/bcm_vc_iv.c | 204 | ||||
-rw-r--r-- | src/newt/native/bcm_vc_iv.h | 189 |
10 files changed, 925 insertions, 11 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Display.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/Display.java index e3f50b7e0..f08890da6 100644 --- a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Display.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/Display.java @@ -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; diff --git a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Screen.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/Screen.java index 0544bc06c..909444d24 100644 --- a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Screen.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/Screen.java @@ -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; diff --git a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/Window.java index 223ad6484..87170e4ab 100644 --- a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/Window.java @@ -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; diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Display.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Display.java new file mode 100644 index 000000000..62af02abb --- /dev/null +++ b/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(); +} + diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Screen.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Screen.java new file mode 100644 index 000000000..484d4bf81 --- /dev/null +++ b/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(); +} diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Window.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Window.java new file mode 100644 index 000000000..3d00949de --- /dev/null +++ b/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; +} diff --git a/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java b/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java new file mode 100644 index 000000000..885649d17 --- /dev/null +++ b/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java @@ -0,0 +1,221 @@ +/** + * 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.linux; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import jogamp.newt.WindowImpl; + +import com.jogamp.newt.Window; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.event.WindowListener; +import com.jogamp.newt.event.WindowUpdateEvent; + +/** + * Experimental native mouse tracker thread for GNU/Linux + * just reading <code>/dev/input/mice</code> + * within it's own polling thread. + */ +public class LinuxMouseTracker implements WindowListener { + + private static final LinuxMouseTracker lmt; + + static { + lmt = new LinuxMouseTracker(); + final Thread t = new Thread(lmt.mouseDevicePoller, "NEWT-LinuxMouseTracker"); + t.setDaemon(true); + t.start(); + } + + public static LinuxMouseTracker getSingleton() { + return lmt; + } + + private volatile boolean stop = false; + private int x = 0; + private int y = 0; + private int buttonDown = 0; + private int old_x = 0; + private int old_y = 0; + private int old_buttonDown = 0; + private WindowImpl focusedWindow = null; + private MouseDevicePoller mouseDevicePoller = new MouseDevicePoller(); + + @Override + public void windowResized(WindowEvent e) { } + + @Override + public void windowMoved(WindowEvent e) { } + + @Override + public void windowDestroyNotify(WindowEvent e) { + Object s = e.getSource(); + if(focusedWindow == s) { + focusedWindow = null; + } + } + + @Override + public void windowDestroyed(WindowEvent e) { } + + @Override + public void windowGainedFocus(WindowEvent e) { + Object s = e.getSource(); + if(s instanceof WindowImpl) { + focusedWindow = (WindowImpl) s; + } + } + + @Override + public void windowLostFocus(WindowEvent e) { + Object s = e.getSource(); + if(focusedWindow == s) { + focusedWindow = null; + } + } + + @Override + public void windowRepaint(WindowUpdateEvent e) { } + + class MouseDevicePoller implements Runnable { + @Override + public void run() { + final byte[] b = new byte[3]; + final File f = new File("/dev/input/mice"); + f.setReadOnly(); + InputStream fis; + try { + fis = new FileInputStream(f); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } + int xd=0,yd=0; //x/y movement delta + boolean xo=false,yo=false; // x/y overflow (out of range -255 to +255) + boolean lb=false,mb=false,rb=false,hs=false,vs=false; //left/middle/right mousebutton + while(!stop) { + int remaining=3; + while(remaining>0) { + int read = 0; + try { + read = fis.read(b, 0, remaining); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(read<0) { + stop = true; // EOF of mouse !? + } else { + remaining -= read; + } + } + lb=(b[0]&1)>0; + rb=(b[0]&2)>0; + mb=(b[0]&4)>0; + hs=(b[0]&16)>0; + vs=(b[0]&32)>0; + xo=(b[0]&64)>0; + yo=(b[0]&128)>0; + xd=b[1]; + yd=b[2]; + + x+=xd; + y+=yd; + + if(x<0) { + x=0; + } + if(y<0) { + y=0; + } + + if(lb) { + buttonDown = MouseEvent.BUTTON1; + } + if(mb) { + buttonDown = MouseEvent.BUTTON2; + } + if(rb) { + buttonDown = MouseEvent.BUTTON3; + } + + if(null != focusedWindow) { + if( x >= focusedWindow.getScreen().getWidth() ) { + x = focusedWindow.getScreen().getWidth() - 1; + } + if( y >= focusedWindow.getScreen().getHeight() ) { + y = focusedWindow.getScreen().getHeight() - 1; + } + int wx = x - focusedWindow.getX(), wy = y - focusedWindow.getY(); + + if(old_x != x || old_y != y) { + // mouse moved + focusedWindow.sendMouseEvent(MouseEvent.EVENT_MOUSE_MOVED, 0, wx, wy, 0, 0 ); + } + + if(old_buttonDown != buttonDown) { + // press/release + if( 0 != buttonDown ) { + focusedWindow.sendMouseEvent( + MouseEvent.EVENT_MOUSE_PRESSED, + 0, wx, wy, buttonDown, 0 ); + } else { + focusedWindow.sendMouseEvent( + MouseEvent.EVENT_MOUSE_RELEASED, + 0, wx, wy, old_buttonDown, 0 ); + } + } + } else { + if(Window.DEBUG_MOUSE_EVENT) { + System.out.println(x+"/"+y+", hs="+hs+",vs="+vs+",lb="+lb+",rb="+rb+",mb="+mb+",xo="+xo+",yo="+yo+"xd="+xd+",yd="+yd); + } + } + + old_x = x; + old_y = y; + old_buttonDown = buttonDown; + + } + if(null != fis) { + try { + fis.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } +} diff --git a/src/newt/native/BroadcomEGL.c b/src/newt/native/bcm_egl.c index df6aca611..79ebd20e0 100644 --- a/src/newt/native/BroadcomEGL.c +++ b/src/newt/native/bcm_egl.c @@ -37,7 +37,7 @@ #include <stdio.h> #include <string.h> -#include "jogamp_newt_driver_broadcom_egl_Window.h" +#include "jogamp_newt_driver_bcm_egl_Window.h" #include "MouseEvent.h" #include "KeyEvent.h" @@ -67,7 +67,7 @@ static jmethodID windowCreatedID = NULL; * Display */ -JNIEXPORT void JNICALL Java_jogamp_newt_driver_broadcom_egl_Display_DispatchMessages +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_egl_Display_DispatchMessages (JNIEnv *env, jobject obj) { // FIXME: n/a @@ -75,7 +75,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_broadcom_egl_Display_DispatchMess (void) obj; } -JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_broadcom_egl_Display_CreateDisplay +JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_bcm_egl_Display_CreateDisplay (JNIEnv *env, jobject obj, jint width, jint height) { (void) env; @@ -89,7 +89,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_broadcom_egl_Display_CreateDispl return (jlong) (intptr_t) dpy; } -JNIEXPORT void JNICALL Java_jogamp_newt_driver_broadcom_egl_Display_DestroyDisplay +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_egl_Display_DestroyDisplay (JNIEnv *env, jobject obj, jlong display) { EGLDisplay dpy = (EGLDisplay)(intptr_t)display; @@ -106,7 +106,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_broadcom_egl_Display_DestroyDispl * Window */ -JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_broadcom_egl_Window_initIDs +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_bcm_egl_Window_initIDs (JNIEnv *env, jclass clazz) { windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(III)V"); @@ -118,7 +118,7 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_broadcom_egl_Window_initIDs return JNI_TRUE; } -JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_broadcom_egl_Window_CreateWindow +JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_bcm_egl_Window_CreateWindow (JNIEnv *env, jobject obj, jlong display, jboolean chromaKey, jint width, jint height) { EGLDisplay dpy = (EGLDisplay)(intptr_t)display; @@ -162,7 +162,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_broadcom_egl_Window_CreateWindow return (jlong) (intptr_t) window; } -JNIEXPORT void JNICALL Java_jogamp_newt_driver_broadcom_egl_Window_CloseWindow +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_egl_Window_CloseWindow (JNIEnv *env, jobject obj, jlong display, jlong window) { EGLDisplay dpy = (EGLDisplay) (intptr_t) display; @@ -175,7 +175,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_broadcom_egl_Window_CloseWindow DBG_PRINT( "[CloseWindow] X\n"); } -JNIEXPORT void JNICALL Java_jogamp_newt_driver_broadcom_egl_Window_SwapWindow +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_egl_Window_SwapWindow (JNIEnv *env, jobject obj, jlong display, jlong window) { EGLDisplay dpy = (EGLDisplay) (intptr_t) display; diff --git a/src/newt/native/bcm_vc_iv.c b/src/newt/native/bcm_vc_iv.c new file mode 100644 index 000000000..09ab8a634 --- /dev/null +++ b/src/newt/native/bcm_vc_iv.c @@ -0,0 +1,204 @@ +/** + * 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. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "bcm_vc_iv.h" + +#include "jogamp_newt_driver_bcm_vc_iv_Display.h" +#include "jogamp_newt_driver_bcm_vc_iv_Screen.h" +#include "jogamp_newt_driver_bcm_vc_iv_Window.h" + +#define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(...) fprintf(stdout, __VA_ARGS__) +#else + #define DBG_PRINT(...) +#endif + +static jmethodID setScreenSizeID = NULL; + +static jmethodID windowCreatedID = NULL; +static jmethodID sizeChangedID = NULL; +static jmethodID visibleChangedID = NULL; +static jmethodID windowDestroyNotifyID = NULL; +static jmethodID sendMouseEventID = NULL; +static jmethodID sendKeyEventID = NULL; + +/** + * Display + */ + +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Display_initIDs + (JNIEnv *env, jclass clazz) +{ + bcm_host_init(); + // TODO: bcm_host_deinit(); + DBG_PRINT( "BCM.Display initIDs ok\n" ); + return JNI_TRUE; +} + +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Display_DispatchMessages + (JNIEnv *env, jobject obj) +{ +} + +/** + * Screen + */ + +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Screen_initIDs + (JNIEnv *env, jclass clazz) +{ + uint32_t screen_width; + uint32_t screen_height; + int32_t success = 0; + + setScreenSizeID = (*env)->GetMethodID(env, clazz, "setScreenSize", "(II)V"); + if (setScreenSizeID == NULL) { + DBG_PRINT( "BCM.Screen initIDs FALSE\n" ); + return JNI_FALSE; + } + DBG_PRINT( "BCM.Screen initIDs ok\n" ); + return JNI_TRUE; +} + +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Screen_initNative + (JNIEnv *env, jobject obj) +{ + uint32_t screen_width; + uint32_t screen_height; + int32_t success = 0; + + if( graphics_get_display_size(0 /* LCD */, &screen_width, &screen_height) >= 0 ) { + DBG_PRINT( "BCM.Screen initNative ok %dx%d\n", screen_width, screen_height ); + (*env)->CallVoidMethod(env, obj, setScreenSizeID, (jint) screen_width, (jint) screen_height); + } + DBG_PRINT( "BCM.Screen initNative failed\n" ); +} + +/** + * Window + */ + +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Window_initIDs + (JNIEnv *env, jclass clazz) +{ + windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(J)V"); + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V"); + visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(ZZ)V"); + windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "(Z)Z"); + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + if (windowCreatedID == NULL || + sizeChangedID == NULL || + visibleChangedID == NULL || + windowDestroyNotifyID == NULL || + sendMouseEventID == NULL || + sendKeyEventID == NULL) { + DBG_PRINT( "initIDs failed\n" ); + return JNI_FALSE; + } + DBG_PRINT( "BCM.Window initIDs ok\n" ); + return JNI_TRUE; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Window_CreateWindow + (JNIEnv *env, jobject obj, jint width, jint height) +{ + int32_t success = 0; + VC_RECT_T dst_rect; + VC_RECT_T src_rect; + + dst_rect.x = 0; + dst_rect.y = 0; + dst_rect.width = width; + dst_rect.height = height; + + src_rect.x = 0; + src_rect.y = 0; + src_rect.width = width << 16; + src_rect.height = height << 16; + + DISPMANX_DISPLAY_HANDLE_T dispman_display = vc_dispmanx_display_open( 0 /* LCD */); + DISPMANX_UPDATE_HANDLE_T dispman_update = vc_dispmanx_update_start( 0 ); + DISPMANX_ELEMENT_HANDLE_T dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display, + 0/*layer*/, &dst_rect, 0/*src*/, + &src_rect, DISPMANX_PROTECTION_NONE, + 0 /*alpha TODO*/, 0/*clamp*/, 0/*transform*/); + EGL_DISPMANX_WINDOW_T * nativeWindowPtr = calloc(1, sizeof(EGL_DISPMANX_WINDOW_T)); + nativeWindowPtr->element = dispman_element; + nativeWindowPtr->width = width; + nativeWindowPtr->height = height; + + vc_dispmanx_update_submit_sync( dispman_update ); + + (*env)->CallVoidMethod(env, obj, visibleChangedID, JNI_FALSE, JNI_TRUE); // FIXME: or defer=true ? + + return (jlong) (intptr_t) nativeWindowPtr; +} + +JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Window_RealizeWindow + (JNIEnv *env, jobject obj, jlong window) +{ + return (jlong) (intptr_t) 0; +} + +JNIEXPORT jint JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Window_CloseWindow + (JNIEnv *env, jobject obj, jlong window, jlong juserData) +{ + EGL_DISPMANX_WINDOW_T * nativeWindowPtr = (EGL_DISPMANX_WINDOW_T *) (intptr_t) window ; + free( nativeWindowPtr ); + return 0; +} + +/* + * Class: jogamp_newt_driver_bcm_vc_iv_Window + * Method: setVisible0 + * Signature: (JJZ)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Window_setVisible0 + (JNIEnv *env, jobject obj, jlong window, jboolean visible) +{ +} + +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Window_setFullScreen0 + (JNIEnv *env, jobject obj, jlong window, jboolean fullscreen) +{ +} + +JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_vc_iv_Window_setSize0 + (JNIEnv *env, jobject obj, jlong window, jint width, jint height) +{ + // FIXME RESIZE (*env)->CallVoidMethod(env, obj, sizeChangedID, JNI_FALSE, (jint) width, (jint) height, JNI_FALSE); +} + + diff --git a/src/newt/native/bcm_vc_iv.h b/src/newt/native/bcm_vc_iv.h new file mode 100644 index 000000000..cfcc44b16 --- /dev/null +++ b/src/newt/native/bcm_vc_iv.h @@ -0,0 +1,189 @@ +/** + * 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. + */ + +#ifndef BCM_VC_IV_H +#define BCM_VC_IV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +typedef uint32_t DISPMANX_PROTECTION_T; +typedef uint32_t DISPMANX_RESOURCE_HANDLE_T; +typedef uint32_t DISPMANX_DISPLAY_HANDLE_T; +typedef uint32_t DISPMANX_UPDATE_HANDLE_T; +typedef uint32_t DISPMANX_ELEMENT_HANDLE_T; + +#define DISPMANX_NO_HANDLE 0 + +#define DISPMANX_PROTECTION_MAX 0x0f +#define DISPMANX_PROTECTION_NONE 0 +#define DISPMANX_PROTECTION_HDCP 11 // Derived from the WM DRM levels, 101-300 + + + +/* Default display IDs. + Note: if you overwrite with you own dispmanx_platfrom_init function, you + should use IDs you provided during dispmanx_display_attach. +*/ +#define DISPMANX_ID_MAIN_LCD 0 +#define DISPMANX_ID_AUX_LCD 1 +#define DISPMANX_ID_HDMI 2 +#define DISPMANX_ID_SDTV 3 + +/* Return codes. Nonzero ones indicate failure. */ +typedef enum { + DISPMANX_SUCCESS = 0, + DISPMANX_INVALID = -1 + /* XXX others TBA */ +} DISPMANX_STATUS_T; + +typedef enum { + /* Bottom 2 bits sets the orientation */ + DISPMANX_NO_ROTATE = 0, + DISPMANX_ROTATE_90 = 1, + DISPMANX_ROTATE_180 = 2, + DISPMANX_ROTATE_270 = 3, + + DISPMANX_FLIP_HRIZ = 1 << 16, + DISPMANX_FLIP_VERT = 1 << 17 +} DISPMANX_TRANSFORM_T; + +typedef enum { + /* Bottom 2 bits sets the alpha mode */ + DISPMANX_FLAGS_ALPHA_FROM_SOURCE = 0, + DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS = 1, + DISPMANX_FLAGS_ALPHA_FIXED_NON_ZERO = 2, + DISPMANX_FLAGS_ALPHA_FIXED_EXCEED_0X07 = 3, + + DISPMANX_FLAGS_ALPHA_PREMULT = 1 << 16, + DISPMANX_FLAGS_ALPHA_MIX = 1 << 17 +} DISPMANX_FLAGS_ALPHA_T; + +struct VC_IMAGE_T; +typedef struct VC_IMAGE_T VC_IMAGE_T; + +typedef struct { + DISPMANX_FLAGS_ALPHA_T flags; + uint32_t opacity; + VC_IMAGE_T *mask; +} DISPMANX_ALPHA_T; + +typedef struct { + DISPMANX_FLAGS_ALPHA_T flags; + uint32_t opacity; + DISPMANX_RESOURCE_HANDLE_T mask; +} VC_DISPMANX_ALPHA_T; /* for use with vmcs_host */ + + +typedef enum { + DISPMANX_FLAGS_CLAMP_NONE = 0, + DISPMANX_FLAGS_CLAMP_LUMA_TRANSPARENT = 1, +#if __VCCOREVER__ >= 0x04000000 + DISPMANX_FLAGS_CLAMP_TRANSPARENT = 2, + DISPMANX_FLAGS_CLAMP_REPLACE = 3 +#else + DISPMANX_FLAGS_CLAMP_CHROMA_TRANSPARENT = 2, + DISPMANX_FLAGS_CLAMP_TRANSPARENT = 3 +#endif +} DISPMANX_FLAGS_CLAMP_T; + +typedef enum { + DISPMANX_FLAGS_KEYMASK_OVERRIDE = 1, + DISPMANX_FLAGS_KEYMASK_SMOOTH = 1 << 1, + DISPMANX_FLAGS_KEYMASK_CR_INV = 1 << 2, + DISPMANX_FLAGS_KEYMASK_CB_INV = 1 << 3, + DISPMANX_FLAGS_KEYMASK_YY_INV = 1 << 4 +} DISPMANX_FLAGS_KEYMASK_T; + +typedef union { + struct { + uint8_t yy_upper; + uint8_t yy_lower; + uint8_t cr_upper; + uint8_t cr_lower; + uint8_t cb_upper; + uint8_t cb_lower; + } yuv; + struct { + uint8_t red_upper; + uint8_t red_lower; + uint8_t blue_upper; + uint8_t blue_lower; + uint8_t green_upper; + uint8_t green_lower; + } rgb; +} DISPMANX_CLAMP_KEYS_T; + +typedef struct { + DISPMANX_FLAGS_CLAMP_T mode; + DISPMANX_FLAGS_KEYMASK_T key_mask; + DISPMANX_CLAMP_KEYS_T key_value; + uint32_t replace_value; +} DISPMANX_CLAMP_T; + + +typedef uint32_t DISPMANX_ELEMENT_HANDLE_T; + +typedef struct { + DISPMANX_ELEMENT_HANDLE_T element; + int width; /* This is necessary because dispmanx elements are not queriable. */ + int height; +} EGL_DISPMANX_WINDOW_T; + +typedef struct tag_VC_RECT_T { + int32_t x; + int32_t y; + int32_t width; + int32_t height; +} VC_RECT_T; + +extern void bcm_host_init(void); +extern void bcm_host_deinit(void); + +extern int32_t graphics_get_display_size( const uint16_t display_number, + uint32_t *width, + uint32_t *height); + +extern DISPMANX_DISPLAY_HANDLE_T vc_dispmanx_display_open( uint32_t device ); +extern DISPMANX_UPDATE_HANDLE_T vc_dispmanx_update_start( int32_t priority ); +extern DISPMANX_ELEMENT_HANDLE_T vc_dispmanx_element_add ( DISPMANX_UPDATE_HANDLE_T update, DISPMANX_DISPLAY_HANDLE_T display, + int32_t layer, const VC_RECT_T *dest_rect, DISPMANX_RESOURCE_HANDLE_T src, + const VC_RECT_T *src_rect, DISPMANX_PROTECTION_T protection, + VC_DISPMANX_ALPHA_T *alpha, + DISPMANX_CLAMP_T *clamp, DISPMANX_TRANSFORM_T transform ); + +extern int vc_dispmanx_update_submit_sync( DISPMANX_UPDATE_HANDLE_T update ); + +#ifdef __cplusplus +} +#endif + +#endif |