Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to enable double-buffering when doing paint operations #434

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# GEF Classic 3.20.0
# GEF Classic 3.20.0 (Eclipse 2024-03)

## Draw2d
- _Experimental:_ Clients can set the `org.eclipse.draw2d.LightweightSystem.useDoubleBuffering` system property to enable double buffering while performing paint operations.

## GEF
- Clients can now configure the accessible steps of tools through methods `accGetStep()`, `accStepIncrement` and `accStepReset` from `org.eclipse.gef.tools.AbstractTool`.
Expand Down
8 changes: 8 additions & 0 deletions org.eclipse.draw2d/.settings/.api_filters
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/draw2d/LightweightSystem.java" type="org.eclipse.draw2d.LightweightSystem">
<filter id="336658481">
<message_arguments>
<message_argument value="org.eclipse.draw2d.LightweightSystem"/>
<message_argument value="KEY_USE_DOUBLE_BUFFERING"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/draw2d/Orientable.java" type="org.eclipse.draw2d.Orientable">
<filter id="576720909">
<message_arguments>
Expand Down
39 changes: 38 additions & 1 deletion org.eclipse.draw2d/src/org/eclipse/draw2d/LightweightSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.swt.accessibility.AccessibleListener;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusEvent;
Expand All @@ -34,6 +35,7 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
Expand All @@ -54,13 +56,23 @@
* </ol>
*/
public class LightweightSystem {
/**
* Indicates whether double-buffering should be used when painting the figures.
* This is an experimental feature that might be removed in a future release.
*
* @since 3.16
* @noreference This field is not intended to be referenced by clients.
*/
public static final String KEY_USE_DOUBLE_BUFFERING = "org.eclipse.draw2d.LightweightSystem.useDoubleBuffering"; //$NON-NLS-1$
private static final boolean USE_DOUBLE_BUFFERING = Boolean.valueOf(System.getProperty(KEY_USE_DOUBLE_BUFFERING));

private Canvas canvas;
IFigure contents;
private IFigure root;
private EventDispatcher dispatcher;
private UpdateManager manager = new DeferredUpdateManager();
private int ignoreResize;
private Image bufferedImage;

/**
* Constructs a LightweightSystem on Canvas <i>c</i>.
Expand Down Expand Up @@ -100,6 +112,17 @@ protected void addListeners() {
canvas.addFocusListener(handler);
canvas.addDisposeListener(handler);
canvas.addListener(SWT.MouseWheel, handler);
canvas.addDisposeListener(event -> {
if (bufferedImage != null) {
bufferedImage.dispose();
}
});
canvas.addControlListener(ControlListener.controlResizedAdapter(event -> {
if (bufferedImage != null) {
bufferedImage.dispose();
}
bufferedImage = null;
}));

canvas.addControlListener(new ControlAdapter() {
@Override
Expand Down Expand Up @@ -199,7 +222,21 @@ EventHandler internalCreateEventHandler() {
* @since 2.0
*/
public void paint(GC gc) {
getUpdateManager().paint(gc);
if (USE_DOUBLE_BUFFERING) {
if (bufferedImage == null) {
Rectangle bounds = getRootFigure().getBounds();
bufferedImage = new Image(null, bounds.width, bounds.height);
}
GC bufferedGC = new GC(bufferedImage);
try {
getUpdateManager().paint(bufferedGC);
gc.drawImage(bufferedImage, 0, 0);
} finally {
bufferedGC.dispose();
}
} else {
getUpdateManager().paint(gc);
}
}

/**
Expand Down
Loading