Skip to content

Commit

Permalink
fixed some java issues
Browse files Browse the repository at this point in the history
  • Loading branch information
redrezo committed Aug 5, 2020
1 parent 7061670 commit f82b431
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,13 @@ public void setSwapChain(FrontSwapChain swapChain) {
}




// Internal Type access

@SuppressWarnings("restriction")
private static void drift_addShutdownHook(Runnable hook) {
com.sun.javafx.tk.Toolkit.getToolkit().addShutdownHook(hook);
}

// JDK-Version specific methods

@SuppressWarnings("restriction")
protected com.sun.javafx.geom.BaseBounds drift_computeGeomBounds(com.sun.javafx.geom.BaseBounds bounds, com.sun.javafx.geom.transform.BaseTransform tx) {
com.sun.javafx.geom.BaseBounds rv = new com.sun.javafx.geom.RectBounds(0f, 0f, (float) getWidth(), (float) getHeight());
rv = tx.transform(rv, rv);
Expand All @@ -271,7 +266,6 @@ protected boolean drift_computeContains(double localX, double localY) {
return (w > 0 && h > 0 && localX >= 0 && localY >= 0 && localX < w && localY < h);
}

@SuppressWarnings("restriction")
protected com.sun.javafx.sg.prism.NGNode drift_createPeer() {
NGDriftFXSurface peer = new NGDriftFXSurface(this);
return peer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.eclipse.fx.drift;

import org.eclipse.fx.drift.internal.prism.Prism;

import com.sun.javafx.geom.BaseBounds;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.jmx.MXNodeAlgorithm;
import com.sun.javafx.jmx.MXNodeAlgorithmContext;
import com.sun.javafx.sg.prism.NGNode;

@SuppressWarnings("restriction")
public class DriftFXSurface extends BaseDriftFXSurface {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Optional;

import org.eclipse.fx.drift.BaseDriftFXSurface;
import org.eclipse.fx.drift.internal.FPSCounter2;
import org.eclipse.fx.drift.internal.FPSCounter;
import org.eclipse.fx.drift.internal.Log;
import org.eclipse.fx.drift.internal.Placement;
import org.eclipse.fx.drift.internal.SurfaceData;
Expand Down Expand Up @@ -49,7 +49,7 @@ public class NGDriftFXSurface extends NGNode {
/** image currently in use by javafx renderer - we may not dispose it */
private FxImage<?> curImage;

private FPSCounter2 fxFpsCounter = new FPSCounter2(100);
private FPSCounter fxFpsCounter = new FPSCounter(100);

public void setSwapChain(FrontSwapChain swapChain) {
this.nextSwapChain = swapChain;
Expand Down Expand Up @@ -193,7 +193,7 @@ private void drawStats(Graphics g) {
}
NGRenderUtil.drawFPSGraph(g, 0, 0, 150, 40, "JavaFX", fxFpsCounter);
if (swapChain != null) {
FPSCounter2 c = ((SimpleFrontSwapChain)swapChain).fpsCounter;
FPSCounter c = ((SimpleFrontSwapChain)swapChain).fpsCounter;
NGRenderUtil.drawFPSGraph(g, 0, 45, 150, 40, "Renderer", c);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.eclipse.fx.drift.impl;

import org.eclipse.fx.drift.internal.DriftUtil;
import org.eclipse.fx.drift.internal.FPSCounter2;
import org.eclipse.fx.drift.internal.FPSCounter;

import com.sun.javafx.font.FontStrike;
import com.sun.javafx.font.PGFont;
Expand All @@ -19,7 +19,7 @@

@SuppressWarnings("restriction")
public class NGRenderUtil {
public static void drawFPSGraph(Graphics g, float x, float y, float width, float height, String label, FPSCounter2 c) {
public static void drawFPSGraph(Graphics g, float x, float y, float width, float height, String label, FPSCounter c) {
int count = 30;
Color bg = new Color(0, 0, 0, 0.5f);
Color fg = new Color(1, 1, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.eclipse.fx.drift.internal;

public class FPSCounter2 {
public class FPSCounter {

long thisFrameTime;
long frameTime;
Expand All @@ -17,7 +17,7 @@ public class FPSCounter2 {
public double[] fpsHistory;
public long[] durationHistory;

public FPSCounter2(int historySize) {
public FPSCounter(int historySize) {
this.fpsHistory = new double[historySize];
this.durationHistory = new long[historySize];
}
Expand All @@ -34,7 +34,7 @@ public void tick() {
time = getTime();
thisFrameTime = time - lastLoop;
frameTime += (thisFrameTime - frameTime) / smoothing;
fps = 1000 / frameTime;
fps = frameTime == 0 ? 0 : (1000 / frameTime);
duration = frameStart < lastLoop ? frameTime : time - frameStart;
lastLoop = time;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import org.eclipse.fx.drift.TransferType;
import org.eclipse.fx.drift.Vec2i;
import org.eclipse.fx.drift.util.NativeUtil;

public class IOSurfaceImageData extends ImageData {

public static final TransferType TYPE = new TransferType("IOSurface", () -> true);
public static final TransferType TYPE = new TransferType("IOSurface", () -> NativeUtil.isMacOs());

public final long ioSurfaceID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import org.eclipse.fx.drift.PresentationMode;
import org.eclipse.fx.drift.TransferType;
import org.eclipse.fx.drift.Vec2i;
import org.eclipse.fx.drift.internal.FPSCounter2;
import org.eclipse.fx.drift.internal.FPSCounter;
import org.eclipse.fx.drift.internal.common.ImageData;

import com.sun.prism.ResourceFactory;
Expand All @@ -32,7 +31,7 @@ public class SimpleFrontSwapChain implements FrontSwapChain {
private int imageCount;
private PresentationMode presentationMode;

public FPSCounter2 fpsCounter = new FPSCounter2(100);
public FPSCounter fpsCounter = new FPSCounter(100);
private boolean disposeScheduled;

public SimpleFrontSwapChain(UUID id, List<ImageData> images, PresentationMode presentationMode, BiConsumer<UUID, ImageData> onRelease) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ private NativeUtil() {}

private static final boolean USE_JAVA_LIBRARY_PATH = Boolean.getBoolean("driftfx.use.java.library.path");

private static String OS = null;
private static String OS = System.getProperty("os.name");
private static boolean isWindows = getOsName().toLowerCase().contains("windows");
private static boolean isLinux = getOsName().toLowerCase().contains("linux");
private static boolean isMacOs = getOsName().toLowerCase().contains("mac") || getOsName().toLowerCase().contains("darwin");


static boolean osgi = false;

Expand All @@ -25,53 +29,47 @@ public static void useOsgiEnvironment() {
}

public static String getOsName() {
if (OS == null) {
OS = System.getProperty("os.name");
}
return OS;
}

public static boolean isWindows() {
return getOsName().toLowerCase().contains("windows");
return isWindows;
}

public static boolean isLinux() {
return getOsName().toLowerCase().contains("linux");
return isLinux;
}

public static boolean isMacOs() {
return getOsName().toLowerCase().contains("mac");
return isMacOs;
}

public static void loadLibrary(Class<?> context, String libname, Consumer<String> loadLibrary, Consumer<String> load) {
if (USE_JAVA_LIBRARY_PATH || osgi) {
// osgi will take care of it
Log.info("loading " + libname + " via system call");
// System.loadLibrary(libname);
loadLibrary.accept(libname);
}
else {

// we need to make it happen

String filename = getFilename(libname);
Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir"));
Path extractPath = tmpDir.resolve("driftfx").resolve(ManifestUtil.getManifestEntry(context, "Bundle-Version")).resolve(filename);

String resourceName = "/native/" + filename;
URL url = context.getResource(resourceName);
Log.debug("Resource Lookup: name: " + resourceName + ", context: " + context + " => " + url);


try (InputStream in = context.getResourceAsStream("/native/" + filename)) {
extract(in, extractPath);
try {
String filename = getFilename(libname);
Path tmpDir = Files.createTempDirectory("driftfx");
Path extractPath = tmpDir.resolve(filename);

String resourceName = "/native/" + filename;
URL url = context.getResource(resourceName);
Log.debug("Resource Lookup: name: " + resourceName + ", context: " + context + " => " + url);

try (InputStream in = context.getResourceAsStream("/native/" + filename)) {
extract(in, extractPath);
}

Log.info("loading " + libname + " from extracted location (" + extractPath + ")");
load.accept(extractPath.toString());
} catch (IOException e) {
e.printStackTrace();
}

Log.info("loading " + libname + " from extracted location (" + extractPath + ")");
// System.load(extractPath.toString());
load.accept(extractPath.toString());
}
}

Expand Down

0 comments on commit f82b431

Please sign in to comment.