Created
November 26, 2020 10:40
-
-
Save tomsontom/24ca57c223607b752cc454baf07ec0b8 to your computer and use it in GitHub Desktop.
Hardware Accelerate SkiaCanvas in JavaFX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
SkiaCanvas c = new SkiaCanvas(); | |
c.setPaintHandler(this::paintHandler); | |
BorderPane p = new BorderPane(c); | |
Scene s = new Scene(p, 800, 800); | |
primaryStage.setScene(s); | |
primaryStage.show(); | |
} | |
private void paintHandler(Surface surface) { | |
var canvas = surface.getCanvas(); | |
canvas.clear(0xFFFFFFFF); | |
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)); | |
canvas.save(); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment