diff options
Diffstat (limited to 'src/newt/classes/com')
3 files changed, 29 insertions, 43 deletions
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java index 372859208..0556fe792 100644 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 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 @@ -33,73 +34,61 @@ package com.jogamp.newt.impl.windows; -import javax.media.nativewindow.*; -import javax.media.nativewindow.windows.*; -import com.jogamp.newt.*; -import com.jogamp.newt.impl.*; +import com.jogamp.newt.impl.DisplayImpl; +import com.jogamp.newt.impl.NEWTJNILibLoader; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.windows.RegisteredClassFactory; +import javax.media.nativewindow.windows.RegisteredClass; +import javax.media.nativewindow.windows.WindowsGraphicsDevice; public class WindowsDisplay extends DisplayImpl { - protected static final String WINDOW_CLASS_NAME = "NewtWindowClass"; - private static int windowClassAtom; - private static long hInstance; + private static final String newtClassBaseName = "_newt_clazz" ; + private static RegisteredClassFactory sharedClassFactory; static { NEWTJNILibLoader.loadNEWT(); if (!WindowsWindow.initIDs0()) { throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); - } + } + sharedClassFactory = new RegisteredClassFactory(newtClassBaseName, WindowsWindow.getNewtWndProc0()); } public static void initSingleton() { // just exist to ensure static init has been run } + private RegisteredClass sharedClass; public WindowsDisplay() { } protected void createNativeImpl() { + sharedClass = sharedClassFactory.getSharedClass(); aDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); } protected void closeNativeImpl() { - // Can't do .. only at application shutdown - // UnregisterWindowClass0(getWindowClassAtom(), getHInstance()); + sharedClassFactory.releaseSharedClass(); } protected void dispatchMessagesNative() { DispatchMessages0(); } - protected static synchronized int getWindowClassAtom() { - if(0 == windowClassAtom) { - windowClassAtom = RegisterWindowClass0(WINDOW_CLASS_NAME, getHInstance()); - if (0 == windowClassAtom) { - throw new NativeWindowException("Error while registering window class"); - } - } - return windowClassAtom; + protected long getHInstance() { + return sharedClass.getHandle(); } - protected static synchronized long getHInstance() { - if(0 == hInstance) { - hInstance = LoadLibraryW0("newt"); - if (0 == hInstance) { - throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); - } - } - return hInstance; + protected String getWindowClassName() { + return sharedClass.getName(); } //---------------------------------------------------------------------- // Internals only // - private static native long LoadLibraryW0(String libraryName); - private static native int RegisterWindowClass0(String windowClassName, long hInstance); - private static native void UnregisterWindowClass0(int wndClassAtom, long hInstance); - private static native void DispatchMessages0(); } diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java index d26f4dc82..eb6539c06 100644 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java @@ -97,9 +97,8 @@ public class WindowsWindow extends WindowImpl { if (config == null) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } - setWindowHandle(CreateWindow0(getParentWindowHandle(), - display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(), - 0, undecorated, x, y, width, height)); + setWindowHandle(CreateWindow0(display.getHInstance(), display.getWindowClassName(), display.getWindowClassName(), + getParentWindowHandle(), 0, undecorated, x, y, width, height)); if (getWindowHandle() == 0) { throw new NativeWindowException("Error creating window"); } @@ -128,7 +127,7 @@ public class WindowsWindow extends WindowImpl { } if(windowHandleClose != 0) { try { - DestroyWindow0(windowHandleClose); + GDI.DestroyWindow(windowHandleClose); } catch (Throwable t) { if(DEBUG_IMPLEMENTATION) { Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t); @@ -177,12 +176,11 @@ public class WindowsWindow extends WindowImpl { // Internals only // protected static native boolean initIDs0(); - private native long CreateWindow0(long parentWindowHandle, - int wndClassAtom, String wndName, - long hInstance, long visualID, - boolean isUndecorated, - int x, int y, int width, int height); - private native void DestroyWindow0(long windowHandle); + protected static native long getNewtWndProc0(); + + private native long CreateWindow0(long hInstance, String wndClassName, String wndName, + long parentWindowHandle, long visualID, boolean isUndecorated, + int x, int y, int width, int height); private native long MonitorFromWindow0(long windowHandle); private native void setVisible0(long windowHandle, boolean visible, boolean top, int x, int y, int width, int height); private native void reconfigureWindow0(long parentWindowHandle, long windowHandle, diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java index 1aaffacb5..af05c0356 100644 --- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java @@ -76,9 +76,8 @@ public class X11Display extends DisplayImpl { throw e; } aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.getNullToolkitLock()); - // aDevice = new X11GraphicsDevice(handle, NativeWindowFactory.createDefaultToolkitLockNoAWT(NativeWindowFactory.TYPE_X11, handle)); - // aDevice = new X11GraphicsDevice(handle); - + // aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.createDefaultToolkitLockNoAWT(NativeWindowFactory.TYPE_X11, handle)); + // aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT); } protected void closeNativeImpl() { |