Skip to content

Skia Canvas plugin for hardware-accelerated 2D rendering in SWT#3231

Open
DenisUngemach wants to merge 4 commits intoeclipse-platform:masterfrom
swt-initiative31:skia_canvas
Open

Skia Canvas plugin for hardware-accelerated 2D rendering in SWT#3231
DenisUngemach wants to merge 4 commits intoeclipse-platform:masterfrom
swt-initiative31:skia_canvas

Conversation

@DenisUngemach
Copy link
Copy Markdown
Contributor

Skia Canvas plugin for hardware-accelerated 2D rendering in SWT.
[Experimental Feature]

  • Integrates an SWT’s canvas extension framework, which replaces the
    native backend for canvases with the Skia drawing framework which relies in this implementation on
    OpenGL.

  • adds a new fragment of org.eclipse.swt: bundles/org.eclipse.swt.skia

  • Includes core classes for rendering

  • resource management

  • a factory for SWT integration with the ServiceLoader

  • Implements caching for fonts, images, and text, supports DPI scaling

  • The plugin is modular an minimizes API changes

  • there are some tests in the org.eclipse.swt.skia plugin

  • for more information read the skia.md file in bundles/org.eclipse.swt.skia

  • uses the service loader, if there are bugs at the loading, the skia plugin will be ignored.

  • Since the API was modified the SWT version should be increased (still to do)

  • there seems to be an api tools bug because of sealed classes. This happens only in the github PR checks.

  • The second commit contains only the ignores for the api tools. It can be reverted and then the versioning could be fixed properly.

Integrates an SWT’s canvas extension framework, which replacing the
native backend for canvases with the SWT.SKIA style bit and leveraging
OpenGL.
- Includes core classes for rendering
- resource management
- a factory for SWT integration.
- Implements caching for fonts, images, and text, supports DPI scaling,
and manages Skija resources explicitly.
- The plugin is modular, minimizes API changes, and is OSGi-activatable.
- for more information read the skia.md in bundles/org.eclipse.swt.skia
- for adding the SWT.SKIA field, the version of SWT should be increased
- there seams to be a bug on the api tools for sealed classes. Locally
on my system, there are no api bugs for handle etc. But on github i get
error messages, that handle etc are used. this only happens for sealed
classes.
@DenisUngemach
Copy link
Copy Markdown
Contributor Author

Referring to the issue: #2616

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

Test Results

  186 files  +16    186 suites  +16   26m 25s ⏱️ -58s
4 715 tests +22  4 694 ✅ +22   21 💤 ±0  0 ❌ ±0 
6 764 runs  +88  6 606 ✅ +88  158 💤 ±0  0 ❌ ±0 

Results for commit c44bcc0. ± Comparison against base commit ee1713a.

♻️ This comment has been updated with latest results.

@vogella
Copy link
Copy Markdown
Contributor

vogella commented Apr 14, 2026

I think we need another PR to add the Skia libraries to the buiild. @HeikoKlare can you guide what needs to be done for that?

@DenisUngemach
Copy link
Copy Markdown
Contributor Author

I think we need another PR to add the Skia libraries to the buiild. @HeikoKlare can you guide what needs to be done for that?

In the current change the source jars will also be loaded to the lib folder. On my builds this was only a warning, it seems here it is an error.
I could just remove this handling.

@HeikoKlare
Copy link
Copy Markdown
Contributor

I think we need another PR to add the Skia libraries to the buiild. @HeikoKlare can you guide what needs to be done for that?

From my understanding, we need to add the library to the eclipse-sdk-prereqs target, so they become available in our target platform. Just like we did here for the JSVG library used in the SWT SVG fragment:

I can provide a PR once I find the time to do so. But feel free to just do it inspired by the linked PR even earlier.

Only causes warnings and errors. These are not necessary in the
org.eclipse.swt.skia plugin. Only convenience.
@DenisUngemach
Copy link
Copy Markdown
Contributor Author

DenisUngemach commented Apr 15, 2026

I think we need another PR to add the Skia libraries to the buiild. @HeikoKlare can you guide what needs to be done for that?

From my understanding, we need to add the library to the eclipse-sdk-prereqs target, so they become available in our target platform. Just like we did here for the JSVG library used in the SWT SVG fragment:

I can provide a PR once I find the time to do so. But feel free to just do it inspired by the linked PR even earlier.

Is this right: swt-initiative31/eclipse.platform.releng.aggregator#1

Of course i will open then the PR to the original releng repo, if this should do it.


@Override
public Rectangle getClipping() {
return currentClipBounds;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clip returned by this method should never be null, even if no clipping is set. From the JavaDoc:

If no clipping region is set, the return value will be a rectangle which covers the entire bounds of the object the receiver is drawing on.
Suggested change
return currentClipBounds;
if (currentClipRegion != null) {
return currentClipBounds;
}
return canvas.getBounds();

Here an example that throws an exception with Skia but not with GTK:

public class Test {
	public static void main(String[] args) {
		Shell shell = new Shell();
		shell.setSize(200, 200);
		shell.setLayout(new FillLayout());
		Canvas canvas = new Canvas(shell, SWT.SKIA);
		canvas.addPaintListener(event -> {
			GC gc = event.gc;
			Objects.requireNonNull(gc.getClipping());
		});
		shell.open();
		Display display = shell.getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
}

private boolean xorModeActive;
private int lineWidth = 1;
private int lineCap = SWT.CAP_FLAT;
private int lineStyle;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the line style is never set, 0 is returned, which is an illegal value.

Suggested change
private int lineStyle;
private int lineStyle = SWT.LINE_SOLID;

This will throw an IllegalArgumentException with Skia, but not with GTK.

public class Test {
	public static void main(String[] args) {
		Shell shell = new Shell();
		shell.setSize(200, 200);
		shell.setLayout(new FillLayout());
		Canvas canvas = new Canvas(shell, SWT.SKIA);
		canvas.addPaintListener(event -> {
			GC gc = event.gc;
			gc.setLineStyle(gc.getLineStyle());
		});
		shell.open();
		Display display = shell.getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
}

@ptziegler
Copy link
Copy Markdown
Contributor

I'm currently getting a consistent crash with the Draw2D TreeExample when changing the minor/major spacing. I'm not quite sure yet what exactly is going wrong, but it seems like the Skia surface is being disposed.

Immediately before the crash, the following returns true: surface.isClosed()

Perhaps as a first step, the following check needs to be added to every method, similar to the other GC's?

if (surface.isClosed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);

Here the crash log:
hs_err_pid138498.log

@ptziegler
Copy link
Copy Markdown
Contributor

I also had a quick look at how it looks with the GEF Logic Editor and most figures seem to be drawn as expected. There seems to be an issue when using Paths though, as some of the gates don't show up in the editor.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants