aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-01-08 21:56:26 +0100
committerSven Gothel <[email protected]>2014-01-08 21:56:26 +0100
commitbd98b927b910d9421e63cf0dbc2b746eec019f80 (patch)
tree0cf29f02720abb656f97bc369b057350a6170226 /src/nativewindow
parentfe28bc125429b38cdcd016746081f4a6d521c6fd (diff)
Bug 935: NEWT PointerIcon: Utilize Toolkit Agnostic PixelFormat and Conversion Utilities (Allowing 'arbitrary' PointerIcon data input)
Commit fe28bc125429b38cdcd016746081f4a6d521c6fd added the notion of toolkit agnostic PixelFormat and conversion utilities, utilized and further tested by this patch. +++ - PointerIcon is a PixelRectangle and hence holds the decoded data. This allows on-the-fly conversion if required as well as recreation w/o PNG re-decoding. - Using array-backed PointerIcon data where possible, allowing better performance when converting PixelFormat etc. - NEWT Display adds 'createPointerIcon(final IOUtil.ClassResources pngResource...' method to support agnostic PointerIcon creation. - NEWT Display adds methods to allow users to avoid PixelFormat and Buffer NIO type forced conversion: - PixelFormat getNativePointerIconPixelFormat() - boolean getNativePointerIconForceDirectNIO() +++ PNGImage -> PNGPixelRect Deleted: com.jogamp.opengl.util.texture.spi.PNGImage Added: com.jogamp.opengl.util.PNGPixelRect (We hope nobody was using PNGImage directly since it was a service-plugin for TextureIO) PNGPixelRect is a PixelRectangle PNGPixelRect actually is implemented OpenGL agnostic, however - since our PNGJ support lives under package 'jogamp.opengl.util.pngj' it cannot be moved up (yet). PNGPixelRect now handles all PixelFormat for the target format and also added support for grayscale+alpha (2 channels). The latter is force-converted to RGB* - similar to paletted. Further more, PNGPixelRect allows simply passing an OutputStream to write the PNG data. Used by: TextureIO and NEWT +++ - OffscreenSurfaceLayer's setCursor(..) uses the agnostic PixelRectangle instead of a PNG resource. - AWTMisc uses the PixelRectangle to produce the AWT Cursor and converts it to the required format. Hence same pixels are used for NEWT and AWT pointer/cursor icon. - TestGearsES2Newt and NewtAWTReparentingKeyAdapter 'tests' iterate over 3 custom PointerIcon when pressed 'c'. - JOGLNewtAppletBase uses the new custom PointerIcon 'newt/data/crosshair-lumina-trans-32x32.png', which is included in NEWT (213 bytes only). -
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java17
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java10
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java48
3 files changed, 46 insertions, 29 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index b947505cb..ddf513180 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -38,7 +38,6 @@
package com.jogamp.nativewindow.awt;
import com.jogamp.common.os.Platform;
-import com.jogamp.common.util.IOUtil;
import com.jogamp.common.util.awt.AWTEDTExecutor;
import com.jogamp.common.util.locks.LockFactory;
import com.jogamp.common.util.locks.RecursiveLock;
@@ -53,7 +52,6 @@ import java.awt.event.ComponentListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.applet.Applet;
-import java.io.IOException;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
@@ -66,6 +64,7 @@ import javax.media.nativewindow.OffscreenLayerSurface;
import javax.media.nativewindow.SurfaceUpdatedListener;
import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.InsetsImmutable;
+import javax.media.nativewindow.util.PixelRectangle;
import javax.media.nativewindow.util.Point;
import javax.media.nativewindow.util.PointImmutable;
import javax.media.nativewindow.util.Rectangle;
@@ -433,19 +432,19 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
}
@Override
- public final boolean setCursor(final IOUtil.ClassResources resources, final PointImmutable hotSpot) throws IOException {
+ public final boolean setCursor(final PixelRectangle pixelrect, final PointImmutable hotSpot) {
AWTEDTExecutor.singleton.invoke(false, new Runnable() {
public void run() {
Cursor c = null;
- if( null == resources || null == hotSpot ) {
+ if( null == pixelrect || null == hotSpot ) {
c = Cursor.getDefaultCursor();
} else {
final java.awt.Point awtHotspot = new java.awt.Point(hotSpot.getX(), hotSpot.getY());
try {
- c = AWTMisc.getCursor(resources, awtHotspot);
- } catch (IOException e) {
- e.printStackTrace();
- }
+ c = AWTMisc.getCursor(pixelrect, awtHotspot);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
if( null != c ) {
component.setCursor(c);
@@ -455,7 +454,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
}
@Override
- public boolean hideCursor() {
+ public final boolean hideCursor() {
AWTEDTExecutor.singleton.invoke(false, new Runnable() {
public void run() {
component.setCursor(AWTMisc.getNullCursor());
diff --git a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
index 81983a7c2..cf8cf89d2 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
@@ -27,11 +27,9 @@
*/
package javax.media.nativewindow;
-import java.io.IOException;
-
+import javax.media.nativewindow.util.PixelRectangle;
import javax.media.nativewindow.util.PointImmutable;
-import com.jogamp.common.util.IOUtil;
import com.jogamp.common.util.locks.RecursiveLock;
/**
@@ -73,12 +71,12 @@ public interface OffscreenLayerSurface {
/**
* Optional method setting cursor in the corresponding on-screen surface/window, if exists.
*
- * @param resources maybe null for default cursor
+ * @param pixelrect cursor pixels, maybe null for default cursor
* @param hotSpot maybe null for default cursor
* @return true if successful, i.e. on-screen surface/window w/ cursor capabilities exists. Otherwise false.
- * @throws IOException
*/
- public boolean setCursor(IOUtil.ClassResources resources, PointImmutable hotSpot) throws IOException;
+ public boolean setCursor(PixelRectangle pixelrect, PointImmutable hotSpot);
+
/**
* Optional method hiding the cursor in the corresponding on-screen surface/window, if exists.
*
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
index b690aff4d..069cffeb8 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
@@ -37,21 +37,19 @@ import java.awt.Component;
import java.awt.Container;
import java.awt.Frame;
import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.net.URLConnection;
import java.util.HashMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.WindowConstants;
-import javax.imageio.ImageIO;
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.WindowClosingProtocol;
+import javax.media.nativewindow.util.PixelRectangle;
+import javax.media.nativewindow.util.PixelFormat;
+import javax.media.nativewindow.util.PixelFormatUtil;
import javax.swing.MenuSelectionManager;
-import com.jogamp.common.util.IOUtil;
-
public class AWTMisc {
public static JFrame getJFrame(Component c) {
@@ -173,7 +171,7 @@ public class AWTMisc {
MenuSelectionManager.defaultManager().clearSelectedPath();
}
- static final HashMap<String, Cursor> cursorMap = new HashMap<String, Cursor>();
+ static final HashMap<Integer, Cursor> cursorMap = new HashMap<Integer, Cursor>();
static final Cursor nulCursor;
static {
final Toolkit toolkit = Toolkit.getDefaultToolkit();
@@ -183,21 +181,43 @@ public class AWTMisc {
public static synchronized Cursor getNullCursor() { return nulCursor; }
- public static synchronized Cursor getCursor(IOUtil.ClassResources resources, Point hotSpot) throws IOException {
- final String key = resources.getClass().getName()+":"+resources.resourcePaths[0];
+ public static synchronized Cursor getCursor(PixelRectangle pixelrect, Point hotSpot) {
+ // 31 * x == (x << 5) - x
+ int hash = 31 + pixelrect.hashCode();
+ hash = ((hash << 5) - hash) + hotSpot.hashCode();
+ final Integer key = Integer.valueOf(hash);
+
Cursor cursor = cursorMap.get(key);
if( null == cursor ) {
- cursor = createAWTCursor(resources, hotSpot);
+ cursor = createCursor(pixelrect, hotSpot);
cursorMap.put(key, cursor);
}
return cursor;
}
- private static synchronized Cursor createAWTCursor(IOUtil.ClassResources resources, Point hotSpot) throws IOException {
- final URLConnection urlConn = resources.resolve(0);
- final BufferedImage img = ImageIO.read(urlConn.getInputStream());
-
+ private static synchronized Cursor createCursor(PixelRectangle pixelrect, Point hotSpot) {
+ final int width = pixelrect.getSize().getWidth();
+ final int height = pixelrect.getSize().getHeight();
+ final BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // PixelFormat.BGRA8888
+ final PixelFormatUtil.PixelSink32 imgSink = new PixelFormatUtil.PixelSink32() {
+ public void store(int x, int y, int pixel) {
+ img.setRGB(x, y, pixel);
+ }
+ @Override
+ public final PixelFormat getPixelformat() {
+ return PixelFormat.BGRA8888;
+ }
+ @Override
+ public int getStride() {
+ return width*4;
+ }
+ @Override
+ public final boolean isGLOriented() {
+ return false;
+ }
+ };
+ PixelFormatUtil.convert32(imgSink, pixelrect);
final Toolkit toolkit = Toolkit.getDefaultToolkit();
- return toolkit.createCustomCursor(img, hotSpot, resources.resourcePaths[0]);
+ return toolkit.createCustomCursor(img, hotSpot, pixelrect.toString());
}
public static WindowClosingProtocol.WindowClosingMode AWT2NWClosingOperation(int awtClosingOperation) {