From 10fee84d50d1085d977aab413dd446834798e009 Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * If backend is already initialized method returns
+ * If
+ * Due to threading restrictions, arbitrary thread initialization is not supported on:
+ * true
.
+ * offthread
is true
, initialization will kicked off
+ * on a short lived arbitrary thread and method returns immediately.
+ * If platform supports such arbitrary thread initialization method returns
+ * true
, otherwise false
.
+ *
+ *
+ *
+ * If offthread
is false
, initialization be performed
+ * on the current thread and method returns after initialization.
+ * Method returns true
if initialization was successful, otherwise false
.
+ *
+ * @param offthread + */ + public final boolean initializeBackend(boolean offthread) { + if( offthread ) { + if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(true) ) { + return false; + } + new Thread(getThreadName()+"-GLJPanel_Init") { + public void run() { + if( !isInitialized ) { + initializeBackendImpl(); + } + } }.start(); + return true; + } else { + if( !isInitialized ) { + return initializeBackendImpl(); + } else { + return true; + } + } + } + @Override public final void setSharedContext(GLContext sharedContext) throws IllegalStateException { helper.setSharedContext(this.getContext(), sharedContext); @@ -457,8 +503,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing return; } - if (backend == null || !isInitialized) { - createAndInitializeBackend(); + if( !isInitialized ) { + initializeBackendImpl(); } if (!isInitialized || printActive) { @@ -552,8 +598,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private final Runnable setupPrintOnEDT = new Runnable() { @Override public void run() { - if (backend == null || !isInitialized) { - createAndInitializeBackend(); + if( !isInitialized ) { + initializeBackendImpl(); } if (!isInitialized) { if(DEBUG) { @@ -1020,35 +1066,47 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing // Internals only below this point // - private void createAndInitializeBackend() { - if ( 0 >= panelWidth || 0 >= panelHeight ) { - // See whether we have a non-zero size yet and can go ahead with - // initialization - if (0 >= reshapeWidth || 0 >= reshapeHeight ) { - return; - } + private final Object initSync = new Object(); + private boolean initializeBackendImpl() { + if( !isInitialized ) { + synchronized(initSync) { + if( !isInitialized ) { + if ( 0 >= panelWidth || 0 >= panelHeight ) { + // See whether we have a non-zero size yet and can go ahead with + // initialization + if (0 >= reshapeWidth || 0 >= reshapeHeight ) { + return false; + } - if (DEBUG) { - System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend: " +panelWidth+"x"+panelHeight + " -> " + reshapeWidth+"x"+reshapeHeight); - } - // Pull down reshapeWidth and reshapeHeight into panelWidth and - // panelHeight eagerly in order to complete initialization, and - // force a reshape later - panelWidth = reshapeWidth; - panelHeight = reshapeHeight; - } + if (DEBUG) { + System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend: " +panelWidth+"x"+panelHeight + " -> " + reshapeWidth+"x"+reshapeHeight); + } + // Pull down reshapeWidth and reshapeHeight into panelWidth and + // panelHeight eagerly in order to complete initialization, and + // force a reshape later + panelWidth = reshapeWidth; + panelHeight = reshapeHeight; + } - if ( null == backend ) { - if ( oglPipelineUsable() ) { - backend = new J2DOGLBackend(); - } else { - backend = new OffscreenBackend(glProfile, customPixelBufferProvider); - } - isInitialized = false; - } + if ( null == backend ) { + if ( oglPipelineUsable() ) { + backend = new J2DOGLBackend(); + } else { + backend = new OffscreenBackend(glProfile, customPixelBufferProvider); + } + isInitialized = false; + } - if (!isInitialized) { - backend.initialize(); + if (!isInitialized) { + backend.initialize(); + } + return isInitialized; + } else { + return true; + } + } + } else { + return true; } } -- cgit v1.2.3