Skip to content

Commit

Permalink
Fixes #3318. Needs to be tested more seriously on Linux and Windows
Browse files Browse the repository at this point in the history
- Removal of use_old_animator & use_old_sync_strategy
- Better synchronization of displays
- Also better synchronization of views and overlays
- Removal of several "automated focus" of Java2D displays
  • Loading branch information
AlexisDrogoul committed Mar 12, 2022
1 parent bb20f75 commit c267590
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 498 deletions.
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* IDisplaySynchronizer.java, in msi.gama.core, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* IDisplaySynchronizer.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.common.interfaces;

Expand All @@ -20,7 +20,7 @@
public interface IDisplaySynchronizer {
/**
* Allows any object calling this method to release the thread waiting for the scene to be rendered (called by the
* rendering processes or when this surface is disposed)
* rendering processes or when this surface is disposed). Nothing to do by default
*/
void signalRenderingIsFinished();

Expand Down Expand Up @@ -49,4 +49,12 @@ public interface IDisplaySynchronizer {
*/
void signalSurfaceIsRealized();

/**
* Sets the surface.
*
* @param displaySurface
* the new surface
*/
void setSurface(IDisplaySurface displaySurface);

}
28 changes: 13 additions & 15 deletions ummisco.gama.annotations/src/ummisco/gama/dev/utils/FLAGS.java
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* FLAGS.java, in ummisco.gama.annotations, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* FLAGS.java, in ummisco.gama.annotations, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.dev.utils;

Expand Down Expand Up @@ -63,16 +63,15 @@ private static boolean get(final String name, final boolean def) {

/**
* For debugging purposes, see #3164. True by default until bugs on Linux regarding the use of multiple threads in
* UI processes are solved.
* UI processes are solved. Update 12/03/22: now false by default, tested on Ubuntu
*/
public static final boolean USE_OLD_ANIMATOR =
get("use_old_animator", true /* System.getProperty("os.name").contains("Linux") */);
// public static final boolean USE_OLD_ANIMATOR = get("use_old_animator", false);

/**
* Used in LayeredDisplayView. True to use a combination of wait(), notify() and Thread.sleep() for synchronizing
* displays with the simulation or false to use semaphores (reduces the time spent between frames). False by default
*/
public static final boolean USE_OLD_SYNC_STRATEGY = get("use_old_sync_strategy", false);
// public static final boolean USE_OLD_SYNC_STRATEGY = get("use_old_sync_strategy", false);

/**
* Used in GamaPreferences, true to save the preferences in the global (managed by the JRE) preference store or
Expand Down Expand Up @@ -105,18 +104,17 @@ private static boolean get(final String name, final boolean def) {
public static final boolean USE_LEGACY_DRAWERS = get("use_legacy_drawers", false);

/**
* Used in msi.gama.application.workbench.ApplicationWorkbenchWindowAdvisor to work around issue #3195. If true,
* makes the workbench window resize its views asynchronously. True by default on macOS. Could prove useful also in
* other environments, for instance in the presence of slow graphic cards/computers.
* Originally used in msi.gama.application.workbench.ApplicationWorkbenchWindowAdvisor to work around issue #3195.
* If true, makes the workbench window resize its views asynchronously. Could prove useful in all environments, for
* instance in the presence of slow graphic cards/computers. False by default
*/
public static final boolean USE_DELAYED_RESIZE =
get("use_delayed_resize", System.getProperty("os.name").contains("Mac"));
public static final boolean USE_DELAYED_RESIZE = get("use_delayed_resize", false);

/**
* Used in JOGL displays, esp. ummisco.gama.opengl.view.SWTOpenGLDisplaySurface to create a NEWT window instead of a
* GLCanvas. Advantages are multiple (smaller memory footprint, immediate opening and resizing, etc.) but so are
* incompatibilities.
* GLCanvas. Advantages are multiple (smaller memory footprint, immediate opening and resizing, etc.), and only a
* few glitches remain (esp. on macOS). True by defautl
*/
public static final boolean USE_NATIVE_OPENGL_WINDOW = get("use_native_opengl_window", false);
public static final boolean USE_NATIVE_OPENGL_WINDOW = get("use_native_opengl_window", true);

}
11 changes: 8 additions & 3 deletions ummisco.gama.java2d/src/ummisco/gama/java2d/AWTDisplayView.java
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* AWTDisplayView.java, in ummisco.gama.java2d, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* AWTDisplayView.java, in ummisco.gama.java2d, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.java2d;

Expand Down Expand Up @@ -47,4 +47,9 @@ public void focusCanvas() {
WorkbenchHelper.asyncRun(() -> centralPanel.forceFocus());
}

@Override
protected boolean canBeSynchronized() {
return true;
}

}
@@ -1,17 +1,20 @@
/*******************************************************************************************************
*
* SwingControl.java, in ummisco.gama.java2d, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* SwingControl.java, in ummisco.gama.java2d, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.java2d.swing;

import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JApplet;
import javax.swing.LayoutFocusTraversalPolicy;
Expand Down Expand Up @@ -89,14 +92,35 @@ protected void populate() {
// WorkbenchHelper.runInUI("Opening Java2D display", 400, m -> {
WorkbenchHelper.asyncRun(() -> {
frame = SWT_AWT.new_Frame(SwingControl.this);
// EventQueue.invokeLater(() -> {

frame.setAlwaysOnTop(false);
frame.setAutoRequestFocus(false);
// frame.setFocusable(false);
// frame.setFocusableWindowState(false);
applet = new JApplet();
// applet.setFocusable(false);
if (PlatformHelper.isWindows()) { applet.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); }
final Java2DDisplaySurface surface = createSwingComponent();
applet.getRootPane().getContentPane().add(surface);
WorkaroundForIssue2476.installOn(applet, surface);
frame.add(applet);
// });
if (PlatformHelper.isMac()) {
MouseListener ml = new MouseAdapter() {

@Override
public void mouseExited(final MouseEvent e) {
if (surface.isFocusOwner() && !surface.contains(e.getPoint())) {
frame.setVisible(false);
frame.setVisible(true);
WorkbenchHelper.asyncRun(() -> getShell().forceActive());
}

}

};
applet.addMouseListener(ml);
surface.addMouseListener(ml);
}
});
// SwingControl.this.getParent().layout(true, true);

Expand Down
Expand Up @@ -114,8 +114,8 @@ public void controlResized(final ControlEvent e) {
* @return the GL animator control
*/
private GLAnimatorControl defineAnimator() {
GLAnimatorControl animator =
FLAGS.USE_OLD_ANIMATOR ? new SingleThreadGLAnimator(drawable) : new MultithreadGLAnimator(drawable);
GLAnimatorControl animator = new MultithreadGLAnimator(drawable);
// FLAGS.USE_OLD_ANIMATOR ? new SingleThreadGLAnimator(drawable) : new MultithreadGLAnimator(drawable);
animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, null);
return animator;
}
Expand Down

0 comments on commit c267590

Please sign in to comment.