Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Hardware Accelerate SkiaCanvas in JavaFX
package at.bestsolution.skia.example;
import org.jetbrains.skija.Paint;
import org.jetbrains.skija.Path;
import org.jetbrains.skija.Point;
import org.jetbrains.skija.Surface;
import at.bestsolution.skia.SkiaCanvas;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class SkiaSample extends Application {
public void start(Stage primaryStage) throws Exception {
SkiaCanvas c = new SkiaCanvas();
BorderPane p = new BorderPane(c);
Scene s = new Scene(p, 800, 800);
private void paintHandler(Surface surface) {
var canvas = surface.getCanvas();
canvas.drawTriangles(new Point[] { new Point(320, 70), new Point(194, 287), new Point(446, 287) },
new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF }, new Paint());
Path path = new Path().moveTo(253, 216).cubicTo(283, 163.5f, 358, 163.5f, 388, 216)
.cubicTo(358, 268.5f, 283, 268.5f, 253, 216).closePath();
canvas.drawPath(path, new Paint().setColor(0xFFFFFFFF));
canvas.drawCircle(320, 217, 16, new Paint().setColor(0xFF000000));;
public static void main(String[] args) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment