From 3c7b10d88b40be406bee6b2dc3e6d97d7cf98b35 Mon Sep 17 00:00:00 2001 From: Janrupf Date: Mon, 21 Dec 2020 17:38:54 +0100 Subject: [PATCH 1/2] Use real return type for Javascript called methods --- VERSION | 2 +- .../DatabindJavascriptMethodHandler.java | 10 ++++-- ultralight-java-lwjgl3-opengl/build.gradle | 2 +- .../lwjgl3/opengl/TestApplication.java | 36 ++++++++++++++++--- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index a2268e2..9fc80f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.1 \ No newline at end of file +0.3.2 \ No newline at end of file diff --git a/ultralight-java-databind/src/main/java/com/labymedia/ultralight/DatabindJavascriptMethodHandler.java b/ultralight-java-databind/src/main/java/com/labymedia/ultralight/DatabindJavascriptMethodHandler.java index 15f8516..f67e416 100644 --- a/ultralight-java-databind/src/main/java/com/labymedia/ultralight/DatabindJavascriptMethodHandler.java +++ b/ultralight-java-databind/src/main/java/com/labymedia/ultralight/DatabindJavascriptMethodHandler.java @@ -111,9 +111,15 @@ private JavascriptValue onCallAsFunction( ); try { + Object ret = method.invoke(privateData.instance(), parameters.toArray()); + Class suggestedReturnType = method.getReturnType(); + + if(ret != null) { + suggestedReturnType = ret.getClass(); + } + // Invoke method with constructed arguments - return conversionUtils.toJavascript( - context, method.invoke(privateData.instance(), parameters.toArray()), method.getReturnType()); + return conversionUtils.toJavascript(context, ret, suggestedReturnType); } catch (IllegalAccessException exception) { throw new JavascriptInteropException("Unable to access method: " + method.getName(), exception); } catch (InvocationTargetException exception) { diff --git a/ultralight-java-lwjgl3-opengl/build.gradle b/ultralight-java-lwjgl3-opengl/build.gradle index c21f727..3947db8 100644 --- a/ultralight-java-lwjgl3-opengl/build.gradle +++ b/ultralight-java-lwjgl3-opengl/build.gradle @@ -61,7 +61,7 @@ def ultralightOsIdentifier = { task copyTestResources(type: Copy) { from new File(project(':ultralight-java-native').buildDir, "cmake-gen-${ultralightOsIdentifier()}/3rdparty/ultralight-${ultralightOsIdentifier()}/bin") - include "**/*.dll", "resources/*" + include "**/*.dll", "**/*.so", "**/*.dylib", "resources/*" into runDir } diff --git a/ultralight-java-lwjgl3-opengl/src/test/java/com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java b/ultralight-java-lwjgl3-opengl/src/test/java/com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java index 9d457a6..f03956d 100644 --- a/ultralight-java-lwjgl3-opengl/src/test/java/com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java +++ b/ultralight-java-lwjgl3-opengl/src/test/java/com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java @@ -177,15 +177,40 @@ public void run() { // Update the size updateSize(window, sizeBuffer.get(0), sizeBuffer.get(1)); + /* + * Following snippet disabled due to GLFW bug, glfwGetWindowContentScale returns invalid values! + * + * On a test system + */ // Update scale for the first time - FloatBuffer scaleBuffer = stack.callocFloat(2); + // FloatBuffer scaleBuffer = stack.callocFloat(2); - // Retrieve the size into the float buffer - glfwGetWindowContentScale(window, - (FloatBuffer) scaleBuffer.slice().position(0), (FloatBuffer) scaleBuffer.slice().position(1)); + // Retrieve the scale into the float buffer + // glfwGetWindowContentScale(window, + // (FloatBuffer) scaleBuffer.slice().position(0), (FloatBuffer) scaleBuffer.slice().position(1)); + + // Retrieve framebuffer size for scale calculation + IntBuffer framebufferSizeBuffer = stack.callocInt(2); + + // Retrieve the size into the int buffer + glfwGetFramebufferSize(window, + (IntBuffer) framebufferSizeBuffer.slice().position(0), (IntBuffer) sizeBuffer.slice().position(1)); + + // Calculate scale + float xScale = ((float) (framebufferSizeBuffer.get(0))) / ((float) (sizeBuffer.get(0))); + float yScale = ((float) (framebufferSizeBuffer.get(1))) / ((float) (sizeBuffer.get(1))); + + // Fix up scale in case it gets corrupted... somehow + if(xScale == 0.0f) { + xScale = 1.0f; + } + + if(yScale == 0.0f) { + yScale = 1.0f; + } // Update the scale - inputAdapter.windowContentScaleCallback(window, scaleBuffer.get(0), scaleBuffer.get(1)); + inputAdapter.windowContentScaleCallback(window, xScale, yScale); } glEnable(GL_MULTISAMPLE); @@ -237,6 +262,7 @@ public void run() { * @param height The new height of the viewport */ private void updateSize(long window, int width, int height) { + System.out.println("Resizing to " + width + "x" + height); glViewport(0, 0, width, height); webController.resize(width, height); } From ecfb17602675f7e46c5fac4f34366eb3736a5383 Mon Sep 17 00:00:00 2001 From: Janrupf Date: Mon, 21 Dec 2020 17:44:58 +0100 Subject: [PATCH 2/2] Address PR comments --- .../labymedia/ultralight/DatabindJavascriptMethodHandler.java | 2 +- .../com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ultralight-java-databind/src/main/java/com/labymedia/ultralight/DatabindJavascriptMethodHandler.java b/ultralight-java-databind/src/main/java/com/labymedia/ultralight/DatabindJavascriptMethodHandler.java index f67e416..8095c58 100644 --- a/ultralight-java-databind/src/main/java/com/labymedia/ultralight/DatabindJavascriptMethodHandler.java +++ b/ultralight-java-databind/src/main/java/com/labymedia/ultralight/DatabindJavascriptMethodHandler.java @@ -114,7 +114,7 @@ private JavascriptValue onCallAsFunction( Object ret = method.invoke(privateData.instance(), parameters.toArray()); Class suggestedReturnType = method.getReturnType(); - if(ret != null) { + if (ret != null) { suggestedReturnType = ret.getClass(); } diff --git a/ultralight-java-lwjgl3-opengl/src/test/java/com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java b/ultralight-java-lwjgl3-opengl/src/test/java/com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java index f03956d..bf7de43 100644 --- a/ultralight-java-lwjgl3-opengl/src/test/java/com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java +++ b/ultralight-java-lwjgl3-opengl/src/test/java/com/labymedia/ultralight/lwjgl3/opengl/TestApplication.java @@ -262,7 +262,6 @@ public void run() { * @param height The new height of the viewport */ private void updateSize(long window, int width, int height) { - System.out.println("Resizing to " + width + "x" + height); glViewport(0, 0, width, height); webController.resize(width, height); }