├── .github └── workflows │ └── ci.yml ├── .gitignore ├── 3rdparty └── cmake │ └── Ultralight.cmake ├── LICENSE ├── LICENSE_HEADER ├── README.md ├── VERSION ├── artwork └── public │ └── discord.svg ├── build.gradle ├── buildSrc ├── build.gradle.kts └── src │ └── main │ ├── java │ └── com │ │ └── labymedia │ │ └── gradle │ │ └── cmake │ │ ├── GradleCMakePlugin.java │ │ ├── GradleLogOutputStream.java │ │ ├── extension │ │ ├── GradleCMakeExtensionGlobal.java │ │ └── GradleCMakeExtensionTask.java │ │ └── tasks │ │ └── CMakeBuildTask.java │ └── kotlin │ └── ultralight-java.example-conventions.gradle.kts ├── example └── lwjgl3-opengl │ ├── build.gradle │ └── src │ └── main │ ├── java │ └── com │ │ └── labymedia │ │ └── ultralight │ │ └── lwjgl3 │ │ └── opengl │ │ ├── ExampleApplication.java │ │ ├── ExampleMain.java │ │ ├── drawing │ │ └── OpenGLDrawer.java │ │ ├── input │ │ ├── ClipboardAdapter.java │ │ ├── CursorAdapter.java │ │ └── InputAdapter.java │ │ ├── js │ │ └── JSInteraction.java │ │ ├── listener │ │ ├── ExampleLoadListener.java │ │ └── ExampleViewListener.java │ │ └── support │ │ ├── ExampleFileSystem.java │ │ ├── ExampleLogger.java │ │ ├── ViewContextProvider.java │ │ └── WebController.java │ └── resources │ ├── example.html │ ├── example.js │ ├── shader_fill_frag.fs │ ├── shader_fill_path_frag.fs │ ├── shader_v2f_c4f_t2f.vs │ ├── shader_v2f_c4f_t2f_t2f_d28f.vs │ └── style.css ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── ultralight-java-base ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── labymedia │ └── ultralight │ ├── UltralightJava.java │ ├── UltralightLoadException.java │ ├── UltralightPlatform.java │ ├── UltralightRenderer.java │ ├── UltralightSession.java │ ├── UltralightSurface.java │ ├── UltralightView.java │ ├── annotation │ ├── AntiFree.java │ ├── NativeCall.java │ ├── NativeType.java │ ├── Unsigned.java │ └── Unstable.java │ ├── bitmap │ ├── UltralightBitmap.java │ ├── UltralightBitmapFormat.java │ └── UltralightBitmapSurface.java │ ├── config │ ├── FaceWinding.java │ ├── FontHinting.java │ ├── UltralightConfig.java │ └── UltralightViewConfig.java │ ├── ffi │ ├── ObjectWithHandle.java │ ├── RefPtr.java │ └── gc │ │ ├── BoundDeleter.java │ │ ├── DeletableObject.java │ │ ├── FFIGarbageCollector.java │ │ ├── FFIGarbageCollectorController.java │ │ ├── ObjectDeleter.java │ │ └── impl │ │ └── DefaultFFIGarbageCollectorImpl.java │ ├── input │ ├── UltralightCursor.java │ ├── UltralightInputModifier.java │ ├── UltralightKey.java │ ├── UltralightKeyEvent.java │ ├── UltralightKeyEventType.java │ ├── UltralightMouseEvent.java │ ├── UltralightMouseEventButton.java │ ├── UltralightMouseEventType.java │ ├── UltralightScrollEvent.java │ └── UltralightScrollEventType.java │ ├── javascript │ ├── JavascriptClass.java │ ├── JavascriptClassAttributes.java │ ├── JavascriptClassDefinition.java │ ├── JavascriptContext.java │ ├── JavascriptContextLock.java │ ├── JavascriptEvaluationException.java │ ├── JavascriptException.java │ ├── JavascriptGlobalContext.java │ ├── JavascriptLockedObject.java │ ├── JavascriptObject.java │ ├── JavascriptPropertyAttributes.java │ ├── JavascriptProtectedValue.java │ ├── JavascriptType.java │ ├── JavascriptTypedArrayType.java │ ├── JavascriptValue.java │ └── interop │ │ ├── JavascriptInteropException.java │ │ ├── JavascriptObjectConstructor.java │ │ ├── JavascriptObjectFinalizer.java │ │ ├── JavascriptObjectFunction.java │ │ ├── JavascriptObjectHasInstanceTester.java │ │ ├── JavascriptObjectHasPropertyTester.java │ │ ├── JavascriptObjectInitializer.java │ │ ├── JavascriptObjectPropertyDeleter.java │ │ ├── JavascriptObjectPropertyGetter.java │ │ ├── JavascriptObjectPropertyNamesCollector.java │ │ ├── JavascriptObjectPropertySetter.java │ │ └── JavascriptObjectToTypeConverter.java │ ├── math │ ├── IntRect.java │ ├── UltralightMatrix.java │ ├── UltralightMatrix4x4.java │ └── Vec4.java │ ├── os │ ├── Architecture.java │ └── OperatingSystem.java │ ├── plugin │ ├── clipboard │ │ └── UltralightClipboard.java │ ├── filesystem │ │ └── UltralightFileSystem.java │ ├── loading │ │ └── UltralightLoadListener.java │ ├── logging │ │ ├── UltralightLogLevel.java │ │ └── UltralightLogger.java │ ├── render │ │ ├── UltralightCommand.java │ │ ├── UltralightCommandType.java │ │ ├── UltralightGPUDriver.java │ │ ├── UltralightGPUDriverNative.java │ │ ├── UltralightGPUState.java │ │ ├── UltralightIndexBuffer.java │ │ ├── UltralightRenderBuffer.java │ │ ├── UltralightRenderTarget.java │ │ ├── UltralightShaderType.java │ │ ├── UltralightVertexBuffer.java │ │ └── UltralightVertexBufferFormat.java │ └── view │ │ ├── MessageLevel.java │ │ ├── MessageSource.java │ │ └── UltralightViewListener.java │ └── util │ └── Util.java ├── ultralight-java-databind-codegen ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── labymedia │ └── ultralight │ └── databind │ └── codegen │ └── call │ └── property │ ├── CallerGenerationException.java │ ├── GeneratedPropertyCaller.java │ ├── PropertyCallerGenerator.java │ └── SingleGeneratedPropertyCaller.java ├── ultralight-java-databind ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── labymedia │ └── ultralight │ └── databind │ ├── Databind.java │ ├── DatabindConfiguration.java │ ├── DatabindJavascriptClass.java │ ├── DatabindJavascriptExplicitAPI.java │ ├── DatabindJavascriptMethodHandler.java │ ├── api │ ├── InjectJavascriptContext.java │ └── JavaAPI.java │ ├── cache │ ├── JavascriptClassCache.java │ └── NaiveJavascriptClassCache.java │ ├── call │ ├── CallData.java │ ├── HeuristicMethodChooser.java │ ├── MethodChooser.java │ └── property │ │ ├── PropertyCaller.java │ │ └── ReflectivePropertyCaller.java │ ├── context │ ├── ContextProvider.java │ └── ContextProviderFactory.java │ └── utils │ ├── FunctionalInterfaceBinder.java │ ├── FunctionalInvocationHandler.java │ └── JavascriptConversionUtils.java ├── ultralight-java-glfw-opengl-util ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── labymedia │ └── ultralight │ └── util │ ├── UltralightGlfwOpenGLContext.java │ ├── UltralightGlfwOpenGLGPUDriver.java │ ├── UltralightGlfwOpenGLWindow.java │ ├── UltralightOpenGLGPUDriver.java │ └── UltralightRendererInstanceHolder.java ├── ultralight-java-gpu-native ├── .clang-format ├── CMakeLists.txt ├── build.gradle ├── include │ ├── KHR │ │ └── khrplatform.h │ └── ultralight_java │ │ └── gpudriver │ │ ├── com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil.h │ │ ├── common │ │ └── GPUDriverImpl.h │ │ └── gl │ │ ├── GPUContextGL.h │ │ ├── GPUDriverGL.h │ │ ├── glad.h │ │ ├── shader_fill_frag.h │ │ ├── shader_fill_path_frag.h │ │ ├── shader_v2f_c4f_t2f_t2f_d28f_vert.h │ │ └── shader_v2f_c4f_t2f_vert.h └── src │ └── gpudriver │ ├── common │ └── GPUDriverImpl.cpp │ ├── gl │ ├── GPUContextGL.cpp │ ├── GPUDriverGL.cpp │ └── glad.c │ └── ultralight_java_gpu.cpp ├── ultralight-java-gpu ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── labymedia │ └── ultralight │ └── gpu │ ├── UltralightGPUDriverNativeUtil.java │ └── UltralightOpenGLGPUDriverNative.java ├── ultralight-java-native ├── .clang-format ├── CMakeLists.txt ├── build.gradle ├── include │ └── ultralight_java │ │ ├── java_bridges │ │ ├── bridegd_clipboard.hpp │ │ ├── bridged_file_system.hpp │ │ ├── bridged_gpu_driver.hpp │ │ ├── bridged_load_listener.hpp │ │ ├── bridged_logger.hpp │ │ ├── bridged_view_listener.hpp │ │ ├── javascript_class_definition_jni.hpp │ │ ├── javascript_class_jni.hpp │ │ ├── javascript_context_jni.hpp │ │ ├── javascript_context_lock_jni.hpp │ │ ├── javascript_global_context_jni.hpp │ │ ├── javascript_object_jni.hpp │ │ ├── javascript_value_jni.hpp │ │ ├── proxied_java_exception.hpp │ │ ├── ultralight_bitmap_jni.hpp │ │ ├── ultralight_bitmap_surface_jni.hpp │ │ ├── ultralight_key_event_jni.hpp │ │ ├── ultralight_matrix4x4_jni.hpp │ │ ├── ultralight_matrix_jni.hpp │ │ ├── ultralight_platform_jni.hpp │ │ ├── ultralight_ref_ptr_jni.hpp │ │ ├── ultralight_renderer_jni.hpp │ │ ├── ultralight_surface_jni.hpp │ │ └── ultralight_view_jni.hpp │ │ ├── platform │ │ └── managed_javascript_class.hpp │ │ ├── ultralight_initializer.hpp │ │ ├── ultralight_java_instance.hpp │ │ └── util │ │ ├── java_enum.hpp │ │ ├── jni_reference_wrapper.hpp │ │ ├── local_jni_reference_wrapper.hpp │ │ ├── temporary_jni.hpp │ │ └── util.hpp └── src │ ├── java_bridges │ ├── bridged_clipboard.cpp │ ├── bridged_file_system.cpp │ ├── bridged_gpu_driver.cpp │ ├── bridged_load_listener.cpp │ ├── bridged_logger.cpp │ ├── bridged_view_listener.cpp │ ├── javascript_class_definition_jni.cpp │ ├── javascript_class_jni.cpp │ ├── javascript_context_jni.cpp │ ├── javascript_context_lock_jni.cpp │ ├── javascript_global_context_jni.cpp │ ├── javascript_object_jni.cpp │ ├── javascript_value_jni.cpp │ ├── proxied_java_exception.cpp │ ├── ultralight_bitmap_jni.cpp │ ├── ultralight_bitmap_surface_jni.cpp │ ├── ultralight_key_event_jni.cpp │ ├── ultralight_matrix4x4_jni.cpp │ ├── ultralight_matrix_jni.cpp │ ├── ultralight_platform_jni.cpp │ ├── ultralight_ref_ptr_jni.cpp │ ├── ultralight_renderer_jni.cpp │ ├── ultralight_surface_jni.cpp │ └── ultralight_view_jni.cpp │ ├── platform │ └── managed_javascript_class.cpp │ ├── ultralight_initializer.cpp │ ├── ultralight_java_instance.cpp │ └── util │ ├── jni_reference_wrapper.cpp │ ├── temporary_jni.cpp │ └── util.cpp └── version.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | out/ 3 | .gradle/ 4 | .idea/ 5 | cmake-build-*/ 6 | **/run/ 7 | bin/ 8 | .vscode/ 9 | .settings/ 10 | .project 11 | .classpath -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | Ultralight Java - Java wrapper for the Ultralight web engine 2 | Copyright (C) ${year} ${author} and contributors 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 3 of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program; if not, write to the Free Software Foundation, 16 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.4.13 2 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-gradle-plugin") 3 | `kotlin-dsl` 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | gradlePlugin { 11 | plugins { 12 | create("CMakeGradle") { 13 | id = "com.labymedia.cmake-gradle" 14 | implementationClass = "com.labymedia.gradle.cmake.GradleCMakePlugin" 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /buildSrc/src/main/java/com/labymedia/gradle/cmake/GradleCMakePlugin.java: -------------------------------------------------------------------------------- 1 | package com.labymedia.gradle.cmake; 2 | 3 | import com.labymedia.gradle.cmake.extension.GradleCMakeExtensionGlobal; 4 | import org.gradle.api.Plugin; 5 | import org.gradle.api.Project; 6 | import org.gradle.api.tasks.Delete; 7 | 8 | import javax.annotation.Nonnull; 9 | 10 | public class GradleCMakePlugin implements Plugin { 11 | private static GradleCMakePlugin instance; 12 | private GradleCMakeExtensionGlobal cmakeExtension; 13 | 14 | @Nonnull 15 | public static GradleCMakePlugin getInstance() { 16 | return instance; 17 | } 18 | 19 | public GradleCMakePlugin() { 20 | instance = this; 21 | } 22 | 23 | public void apply(@Nonnull Project target) { 24 | this.cmakeExtension = target.getExtensions().create("cmake", GradleCMakeExtensionGlobal.class, target); 25 | target.getTasks().register("clean", Delete.class, delete -> delete.delete(target.getBuildDir())); 26 | } 27 | 28 | public GradleCMakeExtensionGlobal getCMakeExtension() { 29 | return this.cmakeExtension; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/com/labymedia/gradle/cmake/GradleLogOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.labymedia.gradle.cmake; 2 | 3 | 4 | import org.gradle.api.logging.LogLevel; 5 | import org.gradle.api.logging.Logger; 6 | 7 | import java.io.OutputStream; 8 | 9 | public class GradleLogOutputStream extends OutputStream { 10 | private String prefix; 11 | private Logger logger; 12 | private LogLevel level; 13 | private StringBuilder buffer; 14 | 15 | public GradleLogOutputStream(String prefix, Logger logger, LogLevel level) { 16 | this.prefix = prefix; 17 | this.logger = logger; 18 | this.level = level; 19 | this.buffer = new StringBuilder(1024); 20 | this.buffer.append("[").append(prefix).append("] "); 21 | } 22 | 23 | public void write(int b) { 24 | char c = (char) b; 25 | if (c == '\n') { 26 | this.logger.log(this.level, this.buffer.toString()); 27 | this.buffer.setLength(0); 28 | this.buffer.append("[").append(this.prefix).append("] "); 29 | } else { 30 | this.buffer.append(c); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/com/labymedia/gradle/cmake/extension/GradleCMakeExtensionTask.java: -------------------------------------------------------------------------------- 1 | package com.labymedia.gradle.cmake.extension; 2 | 3 | 4 | import org.gradle.api.Task; 5 | 6 | public class GradleCMakeExtensionTask extends GradleCMakeExtensionGlobal { 7 | private String generator; 8 | private String target; 9 | 10 | public GradleCMakeExtensionTask(Task task) { 11 | super(task); 12 | } 13 | 14 | public void setGenerator(String generator) { 15 | this.generator = generator; 16 | } 17 | 18 | public void setTarget(String target) { 19 | this.target = target; 20 | } 21 | 22 | public String getGenerator() { 23 | return this.generator; 24 | } 25 | 26 | public String getTarget() { 27 | return this.target; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/drawing/OpenGLDrawer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.lwjgl3.opengl.drawing; 21 | 22 | import static org.lwjgl.opengl.GL21.*; 23 | 24 | /** 25 | * This class just draws a simple, colored rotating triangle in the background for demonstration. 26 | */ 27 | public class OpenGLDrawer { 28 | private float rotation; 29 | 30 | /** 31 | * Draw a rotating triangle. 32 | */ 33 | public void draw() { 34 | glDisable(GL_DEPTH_TEST); 35 | glEnable(GL_ALPHA_TEST); 36 | glUseProgram(0); 37 | glPushMatrix(); 38 | rotation += 0.01; 39 | glRotatef(rotation, 0, 0, 1); 40 | glBegin(GL_TRIANGLES); 41 | 42 | 43 | glColor3f(1.0f, 0.0f, 0.0f); 44 | glVertex2f(-1.0f, -1.0f); 45 | 46 | glColor3f(0.0f, 1.0f, 0.0f); 47 | glVertex2f(1.0f, -1.0f); 48 | 49 | glColor3f(0.0f, 0.0f, 1.0f); 50 | glVertex2f(0.0f, 1.0f); 51 | 52 | glEnd(); 53 | glPopMatrix(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/input/ClipboardAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.lwjgl3.opengl.input; 21 | 22 | import com.labymedia.ultralight.plugin.clipboard.UltralightClipboard; 23 | 24 | import static org.lwjgl.glfw.GLFW.glfwGetClipboardString; 25 | import static org.lwjgl.glfw.GLFW.glfwSetClipboardString; 26 | 27 | /** 28 | * Example clipboard using GLFW as backend. 29 | */ 30 | public class ClipboardAdapter implements UltralightClipboard { 31 | /** 32 | * This is called by Ultralight when the clipboard should be cleared. 33 | */ 34 | @Override 35 | public void clear() { 36 | glfwSetClipboardString(0, ""); 37 | } 38 | 39 | /** 40 | * This is called by Ultralight when the clipboard is requested as a string. 41 | * 42 | * @return The clipboard content as a string 43 | */ 44 | @Override 45 | public String readPlainText() { 46 | return glfwGetClipboardString(0); 47 | } 48 | 49 | /** 50 | * This is called by Ultralight when the clipboard content should be overwritten. 51 | * 52 | * @param text The plain text to write to the clipboard 53 | */ 54 | @Override 55 | public void writePlainText(String text) { 56 | glfwSetClipboardString(0, text); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/js/JSInteraction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.lwjgl3.opengl.js; 21 | 22 | import java.util.Arrays; 23 | import java.util.List; 24 | import java.util.function.Consumer; 25 | 26 | /** 27 | * Example class containing methods which Javascript can interact with. 28 | */ 29 | public class JSInteraction { 30 | private final String[] messages; 31 | 32 | /** 33 | * Javascript can call varargs method as if they would be native. 34 | * 35 | * @param messages The message to store 36 | */ 37 | public JSInteraction(String... messages) { 38 | this.messages = messages; 39 | } 40 | 41 | /** 42 | * Javascript can work on interface types without any issues. 43 | * 44 | * @return The stored messages as a list 45 | */ 46 | public List getMessageList() { 47 | return Arrays.asList(messages); 48 | } 49 | 50 | /** 51 | * Java arrays are translated to Javascript arrays automatically. 52 | * 53 | * @return The stored messages 54 | */ 55 | public String[] getMessageArray() { 56 | return messages; 57 | } 58 | 59 | /** 60 | * Javascript methods can be automatically convert to Java functional interfaces as long as they are annotated with 61 | * {@link FunctionalInterface}. 62 | * 63 | * @param consumer The consumer to pass the messages to 64 | */ 65 | public void useConsumer(Consumer consumer) { 66 | consumer.accept(messages); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/support/ExampleLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.lwjgl3.opengl.support; 21 | 22 | import com.labymedia.ultralight.lwjgl3.opengl.listener.ExampleViewListener; 23 | import com.labymedia.ultralight.plugin.logging.UltralightLogLevel; 24 | import com.labymedia.ultralight.plugin.logging.UltralightLogger; 25 | import com.labymedia.ultralight.plugin.view.MessageLevel; 26 | import com.labymedia.ultralight.plugin.view.MessageSource; 27 | 28 | /** 29 | * Example implementation of a logger 30 | */ 31 | public class ExampleLogger implements UltralightLogger { 32 | /** 33 | * This is called by Ultralight every time a message needs to be logged. Note that Ultralight messages may include 34 | * new lines, so if you want really pretty log output reformat the string accordingly. 35 | *

36 | * This logger is NOT called for {@code console.log} messages, see {@link 37 | * ExampleViewListener#onAddConsoleMessage(MessageSource, MessageLevel, String, long, long, String)} for that 38 | * instead. 39 | * 40 | * @param level The level of the message 41 | * @param message The message to log 42 | */ 43 | @Override 44 | public void logMessage(UltralightLogLevel level, String message) { 45 | switch (level) { 46 | case ERROR: 47 | System.err.println("[Ultralight/ERR] " + message); 48 | break; 49 | 50 | case WARNING: 51 | System.err.println("[Ultralight/WARN] " + message); 52 | break; 53 | 54 | case INFO: 55 | System.out.println("[Ultralight/INFO] " + message); 56 | break; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /example/lwjgl3-opengl/src/main/resources/example.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | Example application 24 | 25 | 26 | 27 |

28 | Hello, World! 29 |
30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/lwjgl3-opengl/src/main/resources/shader_v2f_c4f_t2f.vs: -------------------------------------------------------------------------------- 1 | #version 150 2 | // Program Uniforms 3 | uniform vec4 State; 4 | uniform mat4 Transform; 5 | uniform vec4 Scalar4[2]; 6 | uniform vec4 Vector[8]; 7 | uniform uint ClipSize; 8 | uniform mat4 Clip[8]; 9 | // Uniform Accessor Functions 10 | float Time() { return State[0]; } 11 | float ScreenWidth() { return State[1]; } 12 | float ScreenHeight() { return State[2]; } 13 | float ScreenScale() { return State[3]; } 14 | float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; } 15 | vec4 sRGBToLinear(vec4 val) { 16 | return val; 17 | // return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w); 18 | } 19 | // Vertex Attributes 20 | in vec2 in_Position; 21 | in vec4 in_Color; 22 | in vec2 in_TexCoord; 23 | // Out Params 24 | out vec4 ex_Color; 25 | out vec2 ex_ObjectCoord; 26 | out vec2 ex_ScreenCoord; 27 | void main(void) 28 | { 29 | ex_ObjectCoord = in_TexCoord; 30 | gl_Position = Transform * vec4(in_Position, 0.0, 1.0); 31 | ex_Color = sRGBToLinear(in_Color); 32 | } 33 | -------------------------------------------------------------------------------- /example/lwjgl3-opengl/src/main/resources/shader_v2f_c4f_t2f_t2f_d28f.vs: -------------------------------------------------------------------------------- 1 | #version 150 2 | // Program Uniforms 3 | uniform vec4 State; 4 | uniform mat4 Transform; 5 | uniform vec4 Scalar4[2]; 6 | uniform vec4 Vector[8]; 7 | uniform uint ClipSize; 8 | uniform mat4 Clip[8]; 9 | // Uniform Accessor Functions 10 | float Time() { return State[0]; } 11 | float ScreenWidth() { return State[1]; } 12 | float ScreenHeight() { return State[2]; } 13 | float ScreenScale() { return State[3]; } 14 | float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; } 15 | vec4 sRGBToLinear(vec4 val) { 16 | return val; 17 | // return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w); 18 | } 19 | // Vertex Attributes 20 | in vec2 in_Position; 21 | in vec4 in_Color; 22 | in vec2 in_TexCoord; 23 | in vec2 in_ObjCoord; 24 | in vec4 in_Data0; 25 | in vec4 in_Data1; 26 | in vec4 in_Data2; 27 | in vec4 in_Data3; 28 | in vec4 in_Data4; 29 | in vec4 in_Data5; 30 | in vec4 in_Data6; 31 | // Out Params 32 | out vec4 ex_Color; 33 | out vec2 ex_TexCoord; 34 | out vec4 ex_Data0; 35 | out vec4 ex_Data1; 36 | out vec4 ex_Data2; 37 | out vec4 ex_Data3; 38 | out vec4 ex_Data4; 39 | out vec4 ex_Data5; 40 | out vec4 ex_Data6; 41 | out vec2 ex_ObjectCoord; 42 | out vec2 ex_ScreenCoord; 43 | void main(void) 44 | { 45 | ex_ObjectCoord = in_ObjCoord; 46 | gl_Position = Transform * vec4(in_Position, 0.0, 1.0); 47 | ex_Color = in_Color; 48 | ex_TexCoord = in_TexCoord; 49 | ex_Data0 = in_Data0; 50 | ex_Data1 = in_Data1; 51 | ex_Data2 = in_Data2; 52 | ex_Data3 = in_Data3; 53 | ex_Data4 = in_Data4; 54 | ex_Data5 = in_Data5; 55 | ex_Data6 = in_Data6; 56 | } 57 | -------------------------------------------------------------------------------- /example/lwjgl3-opengl/src/main/resources/style.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | html, body { 21 | background: transparent; 22 | } 23 | 24 | #center { 25 | position: absolute; 26 | width: 400px; 27 | height: 100px; 28 | 29 | margin: auto; 30 | 31 | background: rgba(0, 0, 0, 0.2); 32 | 33 | top: 0; 34 | left: 0; 35 | bottom: 0; 36 | right: 0; 37 | 38 | border-radius: 10px; 39 | } 40 | 41 | #center > span { 42 | text-align: center; 43 | vertical-align: middle; 44 | line-height: 100px; 45 | 46 | color: white; 47 | font-size: 40px; 48 | 49 | width: 400px; 50 | } 51 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LabyMod/ultralight-java/6cb1c5bb814ced299502ccc6c4ffe1696a0ea7fb/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'ultralight-java' 2 | 3 | include 'ultralight-java-base' 4 | include 'ultralight-java-native' 5 | include 'ultralight-java-glfw-opengl-util' 6 | include 'ultralight-java-databind' 7 | include 'ultralight-java-databind-codegen' 8 | 9 | include 'ultralight-java-gpu' 10 | include 'ultralight-java-gpu-native' 11 | 12 | include 'example:lwjgl3-opengl' 13 | 14 | -------------------------------------------------------------------------------- /ultralight-java-base/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'maven-publish' 4 | } 5 | 6 | group 'com.labymedia' 7 | 8 | jar { 9 | manifest { 10 | attributes( 11 | 'Automatic-Module-Name': 'com.labymedia.ultralight' 12 | ) 13 | } 14 | } 15 | 16 | processResources { 17 | if (project.getProperties().get("ultralight-java.base.native-binaries-folder") == null) { 18 | dependsOn(':ultralight-java-native:build') 19 | } 20 | from(rootProject.file(project.getProperties().getOrDefault("ultralight-java.base.native-binaries-folder", project(":ultralight-java-native").buildDir.toPath().toString() + "/nativeBinaries").toString())) { 21 | into "native-binaries" 22 | include("*.dll", "*.so", "*.dylib") 23 | } 24 | } 25 | 26 | commonPublish(project) { 27 | pom { 28 | name = "UltralightJava" 29 | description = "Ultralight bindings for Java" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/UltralightLoadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight; 21 | 22 | /** 23 | * Exception that can occur while trying to load the native library. 24 | */ 25 | public class UltralightLoadException extends Exception { 26 | private static final long serialVersionUID = 5174097344028286712L; 27 | 28 | /** 29 | * Constructs a new {@link UltralightLoadException} with just a message. 30 | * 31 | * @param message The message to display to the user 32 | */ 33 | public UltralightLoadException(String message) { 34 | super(message); 35 | } 36 | 37 | /** 38 | * Constructs a new {@link UltralightLoadException} with a message and a cause. 39 | * 40 | * @param message The message to display to the user 41 | * @param cause The exception causing this exception 42 | */ 43 | public UltralightLoadException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/UltralightSession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | /** 25 | * TODO 26 | */ 27 | @NativeType("ultralight::RefPtr") 28 | public class UltralightSession { 29 | } 30 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/annotation/AntiFree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.annotation; 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Marker annotation to mark fields as a reference holder to prevent unwanted frees. 28 | */ 29 | @Documented 30 | @Target({ElementType.FIELD, ElementType.PARAMETER}) 31 | public @interface AntiFree { 32 | } 33 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/annotation/NativeCall.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.annotation; 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Marks a method or constructor as called by native code. 28 | */ 29 | @Documented 30 | @Target({ElementType.CONSTRUCTOR, ElementType.METHOD}) 31 | public @interface NativeCall { 32 | } 33 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/annotation/NativeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.annotation; 21 | 22 | import java.lang.annotation.Documented; 23 | 24 | /** 25 | * Annotation for a java type to note which native type it represents. 26 | */ 27 | @Documented 28 | public @interface NativeType { 29 | /** 30 | * Returns the fully qualified name of the native type. 31 | * 32 | * @return The fully qualified name of the native type 33 | */ 34 | String value(); 35 | } 36 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/annotation/Unsigned.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.annotation; 21 | 22 | import java.lang.annotation.Documented; 23 | 24 | /** 25 | * Marks a field, type parameter as unsigned, should be used in conjunction with 26 | * {@link NativeType}. 27 | */ 28 | @Documented 29 | public @interface Unsigned { 30 | } 31 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/annotation/Unstable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.annotation; 21 | 22 | import java.lang.annotation.Documented; 23 | 24 | /** 25 | * Marks an element as subject to change. This might be used when it is not yet clear if an implementation will be kept 26 | * or changed. 27 | */ 28 | @Documented 29 | public @interface Unstable { 30 | /** 31 | * Specifies the reason this element has been marked as unstable. 32 | * 33 | * @return The reason this element is unstable 34 | */ 35 | String value(); 36 | } 37 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/bitmap/UltralightBitmapFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.bitmap; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | import java.lang.annotation.Native; 25 | 26 | /** 27 | * The various Bitmap formats. 28 | */ 29 | @NativeType("ultralight::BitmapFormat") 30 | public enum UltralightBitmapFormat { 31 | /** 32 | * Alpha channel only, 8-bits per pixel. 33 | *

34 | * Encoding: 8-bits per channel, unsigned normalized. 35 | *

36 | * Color-space: Linear (no gamma), alpha-coverage only. 37 | */ 38 | @Native 39 | A8_UNORM(1), 40 | 41 | /** 42 | * Blue Green Red Alpha channels, 32-bits per pixel. 43 | *

44 | * Encoding: 8-bits per channel, unsigned normalized. 45 | *

46 | * Color-space: sRGB gamma with premultiplied linear alpha channel. 47 | *

48 | * Alpha is premultiplied with BGR channels before sRGB gamma is 49 | * applied so we can use sRGB conversion hardware and perform all 50 | * blending in linear space on GPU. 51 | */ 52 | @Native 53 | BGRA8_UNORM_SRGB(4); 54 | 55 | private final int bytesPerPixel; 56 | 57 | UltralightBitmapFormat(int bytesPerPixel) { 58 | this.bytesPerPixel = bytesPerPixel; 59 | } 60 | 61 | /** 62 | * Retrieves the amount of bytes per pixel. 63 | * 64 | * @return The amount of bytes per pixel 65 | */ 66 | public int getBytesPerPixel() { 67 | return bytesPerPixel; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/bitmap/UltralightBitmapSurface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.bitmap; 21 | 22 | import com.labymedia.ultralight.UltralightSurface; 23 | import com.labymedia.ultralight.UltralightView; 24 | 25 | /** 26 | * The default Surface implementation, backed by a Bitmap. 27 | */ 28 | public class UltralightBitmapSurface extends UltralightSurface { 29 | /** 30 | * Constructs a new {@link UltralightBitmapSurface} from an underlying handle. 31 | * 32 | * @param view The view this surface belongs to, used to prevent the view from 33 | * being freed to early 34 | * @param handle The underlying handle 35 | */ 36 | protected UltralightBitmapSurface(UltralightView view, long handle) { 37 | super(view, handle); 38 | } 39 | 40 | /** 41 | * Get the underlying Bitmap. 42 | * 43 | * @return Retrieves the underlying Bitmap 44 | */ 45 | public native UltralightBitmap bitmap(); 46 | } 47 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/config/FaceWinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.config; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | import java.lang.annotation.Native; 25 | 26 | /** 27 | * The winding order for front-facing triangles. 28 | *

29 | * In most 3D engines, there is the concept that triangles have a 30 | * a "front" and a "back". All the front-facing triangles (eg, those 31 | * that are facing the camera) are rendered, and all back-facing 32 | * triangles are culled (ignored). The winding-order of the triangle's 33 | * vertices is used to determine which side is front and back. You 34 | * should tell Ultralight which winding-order your 3D engine uses. 35 | */ 36 | @NativeType("ultralight::FaceWinding") 37 | public enum FaceWinding { 38 | /** 39 | * Clockwise Winding (Direct3D, etc.) 40 | */ 41 | @Native 42 | CLOCKWISE, 43 | 44 | /** 45 | * Counter-Clockwise Winding (OpenGL, etc.) 46 | */ 47 | @Native 48 | COUNTER_CLOCKWISE 49 | } 50 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/config/FontHinting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.config; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | import java.lang.annotation.Native; 25 | 26 | /** 27 | * Representation of the native enum `ultralight::FontHinting` 28 | */ 29 | @NativeType("ultralight::FontHinting") 30 | public enum FontHinting { 31 | /** 32 | * Lighter hinting algorithm-- glyphs are slightly fuzzier but better 33 | * resemble their original shape. This is achieved by snapping glyphs to the 34 | * pixel grid only vertically which better preserves inter-glyph spacing. 35 | */ 36 | @Native 37 | SMOOTH, 38 | 39 | /** 40 | * Default hinting algorithm-- offers a good balance between sharpness and 41 | * shape at smaller font sizes. 42 | */ 43 | @Native 44 | NORMAL, 45 | 46 | /** 47 | * Strongest hinting algorithm-- outputs only black/white glyphs. The result 48 | * is usually unpleasant if the underlying TTF does not contain hints for 49 | * this type of rendering. 50 | */ 51 | @Native 52 | MONOCHROME 53 | } 54 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/ffi/ObjectWithHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.ffi; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.annotation.Unsigned; 25 | 26 | /** 27 | * Interface used by native code to retrieve underlying pointers 28 | * from java instances, 29 | */ 30 | public interface ObjectWithHandle { 31 | /** 32 | * Retrieves the underlying native pointer from this instance. 33 | * 34 | * @return The underlying native pointer 35 | */ 36 | @NativeCall 37 | @NativeType("void *") 38 | @Unsigned 39 | long getHandle(); 40 | } 41 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/ffi/RefPtr.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.ffi; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.annotation.Unsigned; 25 | import com.labymedia.ultralight.ffi.gc.DeletableObject; 26 | 27 | /** 28 | * Wrapper for Ultralight smart pointers. Under the hood this RefPtr will only ever have one reference 29 | * on the java side, regardless of how many times it is copied. The underlying FFI garbage collector is 30 | * used to count these objects internally. 31 | * 32 | * @param The type this pointer contains 33 | */ 34 | @NativeType("ultralight::RefPtr") 35 | public class RefPtr implements ObjectWithHandle { 36 | private final DeletableObject handle; 37 | 38 | /** 39 | * Constructs a new {@link RefPtr} and begins tracking the underlying handle. 40 | * 41 | * @param handle A pointer to a native `ultralight::RefPtr`, the java object will take 42 | * ownership of the native pointer 43 | */ 44 | @NativeCall 45 | private RefPtr(@NativeType("ultralight::RefPtr *") @Unsigned long handle) { 46 | this.handle = new DeletableObject<>(handle, RefPtr::delete); 47 | } 48 | 49 | @Override 50 | public @NativeType("ultralight::RefPtr *") 51 | @Unsigned 52 | long getHandle() { 53 | return handle.get(); 54 | } 55 | 56 | /** 57 | * Executes the deletion of the native `ultralight::RefPtr` instance. 58 | * This method is static to not keep a reference to the java object, which 59 | * else would prevent deletion. 60 | * 61 | * @param handle A pointer to the instance to delete 62 | */ 63 | private static native void delete(long handle); 64 | } 65 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/ffi/gc/BoundDeleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.ffi.gc; 21 | 22 | /** 23 | * Bound version of a {@link ObjectDeleter}. 24 | */ 25 | public class BoundDeleter { 26 | private final T value; 27 | private final ObjectDeleter deleter; 28 | 29 | private boolean deleted; 30 | 31 | /** 32 | * Crates a new {@link BoundDeleter} binding an object and its deleter. 33 | * 34 | * @param value The object to bind to the deleter 35 | * @param deleter The deleter to bind the object to 36 | */ 37 | BoundDeleter(T value, ObjectDeleter deleter) { 38 | this.value = value; 39 | this.deleter = deleter; 40 | this.deleted = false; 41 | } 42 | 43 | /** 44 | * Runs the deleter with the stored object. 45 | * 46 | * @return {@code true} if the object has been deleted, {@code false} otherwise 47 | */ 48 | public boolean delete() { 49 | if (deleted) { 50 | return false; 51 | } 52 | 53 | deleter.delete(value); 54 | deleted = true; 55 | return true; 56 | } 57 | 58 | /** 59 | * Determines if this deleter has been executed already. 60 | * 61 | * @return {@code true} if the deleter has been executed already, {@code false} otherwise 62 | */ 63 | public boolean isDeleted() { 64 | return deleted; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return "BoundDeleter{" + 70 | "value=" + value + 71 | ", deleter=" + deleter + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/ffi/gc/FFIGarbageCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.ffi.gc; 21 | 22 | /** 23 | * Interface for abstracting away the FFI garbage collector to allow 24 | * users to implement their own. 25 | */ 26 | public interface FFIGarbageCollector { 27 | /** 28 | * Submits a new object the garbage collector should listen for deletion to. 29 | * No reference to the value may be kept inside the instance after this method returned. 30 | * 31 | * @param value The object to listen for deletion to 32 | * @param deleter The deleter to invoke when the object gets deleted 33 | * @param The type of the object to be deleted 34 | */ 35 | void submit(DeletableObject value, BoundDeleter deleter); 36 | } 37 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/ffi/gc/ObjectDeleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.ffi.gc; 21 | 22 | /** 23 | * Callback when an {@link DeletableObject} has been garbage collected. 24 | * 25 | * @param The type of the collected object. 26 | */ 27 | public interface ObjectDeleter { 28 | /** 29 | * Executes the deletion routine for the object. 30 | * 31 | * @param value The object to delete 32 | */ 33 | void delete(T value); 34 | } 35 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/input/UltralightCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.input; 21 | 22 | /** 23 | * Cursor types 24 | */ 25 | public enum UltralightCursor { 26 | POINTER, 27 | CROSS, 28 | HAND, 29 | I_BEAM, 30 | WAIT, 31 | HELP, 32 | EAST_RESIZE, 33 | NORTH_RESIZE, 34 | NORTH_EAST_RESIZE, 35 | NORTH_WEST_RESIZE, 36 | SOUTH_RESIZE, 37 | SOUTH_EAST_RESIZE, 38 | SOUTH_WEST_RESIZE, 39 | WEST_RESIZE, 40 | NORTH_SOUTH_RESIZE, 41 | EAST_WEST_RESIZE, 42 | NORTH_EAST_SOUTH_WEST_RESIZE, 43 | NORTH_WEST_SOUTH_EAST_RESIZE, 44 | COLUMN_RESIZE, 45 | ROW_RESIZE, 46 | MIDDLE_PANNING, 47 | EAST_PANNING, 48 | NORTH_PANNING, 49 | NORTH_EAST_PANNING, 50 | NORTH_WEST_PANNING, 51 | SOUTH_PANNING, 52 | SOUTH_EAST_PANNING, 53 | SOUTH_WEST_PANNING, 54 | WEST_PANNING, 55 | MOVE, 56 | VERTICAL_TEXT, 57 | CELL, 58 | CONTEXT_MENU, 59 | ALIAS, 60 | PROGRESS, 61 | NO_DROP, 62 | COPY, 63 | NONE, 64 | NOT_ALLOWED, 65 | ZOOM_IN, 66 | ZOOM_OUT, 67 | GRAB, 68 | GRABBING, 69 | CUSTOM 70 | } 71 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/input/UltralightInputModifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.input; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | import com.labymedia.ultralight.annotation.Unsigned; 24 | 25 | /** 26 | * An enumeration of the different keyboard modifiers. 27 | */ 28 | public final class UltralightInputModifier { 29 | /** 30 | * Whether or not an ALT key is down 31 | */ 32 | @NativeType("unsigned") 33 | @Unsigned 34 | public static final int ALT_KEY = 1; 35 | 36 | /** 37 | * Whether or not a Control key is down 38 | */ 39 | @NativeType("unsigned") 40 | @Unsigned 41 | public static final int CTRL_KEY = 1 << 1; 42 | 43 | /** 44 | * Whether or not a meta key (Command-key on Mac, Windows-key on Win) is down 45 | */ 46 | @NativeType("unsigned") 47 | @Unsigned 48 | public static final int META_KEY = 1 << 2; 49 | 50 | /** 51 | * Whether or not a Shift key is down 52 | */ 53 | @NativeType("unsigned") 54 | @Unsigned 55 | public static final int SHIFT_KEY = 1 << 3; 56 | } 57 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/input/UltralightKeyEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.input; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | import java.lang.annotation.Native; 25 | 26 | /** 27 | * The various KeyEvent types. 28 | */ 29 | @NativeType("ultralight::KeyEvent::Type") 30 | public enum UltralightKeyEventType { 31 | /** 32 | * Key-Down type 33 | */ 34 | @Native 35 | DOWN, 36 | 37 | /** 38 | * Key-Up type 39 | */ 40 | @Native 41 | UP, 42 | 43 | /** 44 | * Raw Key-Down type 45 | */ 46 | @Native 47 | RAW_DOWN, 48 | 49 | /** 50 | * Character input type (this event generates text in input fields) 51 | */ 52 | @Native 53 | CHAR 54 | } 55 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/input/UltralightMouseEventButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.input; 21 | 22 | import java.lang.annotation.Native; 23 | 24 | /** 25 | * The various mouse button types. 26 | */ 27 | public enum UltralightMouseEventButton { 28 | /** 29 | * The left mouse button 30 | */ 31 | @Native 32 | LEFT, 33 | 34 | /** 35 | * The middle mouse button 36 | */ 37 | @Native 38 | MIDDLE, 39 | 40 | /** 41 | * The right mouse button 42 | */ 43 | @Native 44 | RIGHT 45 | } 46 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/input/UltralightMouseEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.input; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | import java.lang.annotation.Native; 25 | 26 | /** 27 | * The various MouseEvent types. 28 | */ 29 | @NativeType("ultralight::MouseEvent::Type") 30 | public enum UltralightMouseEventType { 31 | /** 32 | * Mouse moved type 33 | */ 34 | @Native 35 | MOVED, 36 | 37 | /** 38 | * Mouse button pressed type 39 | */ 40 | @Native 41 | DOWN, 42 | 43 | /** 44 | * Mouse button released type 45 | */ 46 | @Native 47 | UP 48 | } 49 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/input/UltralightScrollEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.input; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | import java.lang.annotation.Native; 25 | 26 | /** 27 | * A generic scroll event. 28 | */ 29 | @NativeType("ultralight::ScrollEvent") 30 | public class UltralightScrollEvent { 31 | /** 32 | * Scroll granularity type 33 | */ 34 | @Native 35 | private UltralightScrollEventType type; 36 | 37 | /** 38 | * Horizontal scroll amount 39 | */ 40 | @Native 41 | private int deltaX; 42 | 43 | /** 44 | * Vertical scroll amount 45 | */ 46 | @Native 47 | private int deltaY; 48 | 49 | /** 50 | * Sets the type field of this instance. 51 | * 52 | * @param type The new value of the field 53 | * @return this 54 | * @see #type 55 | */ 56 | public UltralightScrollEvent type(UltralightScrollEventType type) { 57 | this.type = type; 58 | return this; 59 | } 60 | 61 | /** 62 | * Sets the deltaX field of this instance. 63 | * 64 | * @param deltaX The new value of the field 65 | * @return this 66 | * @see #deltaX 67 | */ 68 | public UltralightScrollEvent deltaX(int deltaX) { 69 | this.deltaX = deltaX; 70 | return this; 71 | } 72 | 73 | /** 74 | * Sets the deltaY field of this instance. 75 | * 76 | * @param deltaY The new value of the field 77 | * @return this 78 | * @see #deltaY 79 | */ 80 | public UltralightScrollEvent deltaY(int deltaY) { 81 | this.deltaY = deltaY; 82 | return this; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/input/UltralightScrollEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.input; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | import java.lang.annotation.Native; 25 | 26 | /** 27 | * The scroll event granularity type 28 | */ 29 | @NativeType("ultralight::ScrollEvent::Type") 30 | public enum UltralightScrollEventType { 31 | /** 32 | * The delta value is interpreted as number of pixels 33 | */ 34 | @Native 35 | BY_PIXEL, 36 | 37 | /** 38 | * The delta value is interpreted as number of pages 39 | */ 40 | @Native 41 | BY_PAGE 42 | } 43 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | import com.labymedia.ultralight.ffi.ObjectWithHandle; 24 | import com.labymedia.ultralight.ffi.gc.DeletableObject; 25 | 26 | /** 27 | * A JavaScript class. Used with {@link JavascriptContext#makeObject(JavascriptClass, Object)} 28 | * to construct objects with custom behavior. 29 | */ 30 | @NativeType("JSClassRef") 31 | public class JavascriptClass implements ObjectWithHandle { 32 | private final DeletableObject handle; 33 | 34 | /** 35 | * Constructs a new {@link JavascriptClass} wrapping an existing native handle. 36 | * 37 | * @param handle The native handle to wrap 38 | */ 39 | private JavascriptClass(long handle) { 40 | this.handle = new DeletableObject<>(handle, JavascriptClass::release); 41 | } 42 | 43 | /** 44 | * Releases the class by decrementing its reference count. 45 | * 46 | * @param handle The native handle to decrement the reference count of 47 | */ 48 | private static native void release(long handle); 49 | 50 | @Override 51 | public long getHandle() { 52 | return handle.get(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptClassAttributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | /** 25 | * Attributes of a Javascript class. Defines how the Javascript class is created. 26 | */ 27 | public final class JavascriptClassAttributes { 28 | /** 29 | * Specifies that a class has no special attributes. 30 | */ 31 | @NativeType("") 32 | public static final int NONE = 0; 33 | 34 | /** 35 | * Specifies that a class should not automatically generate a shared prototype for its instance objects. Use 36 | * this in combination with {@link JavascriptObject#setPrototype(JavascriptValue)} to manage prototypes manually. 37 | */ 38 | @NativeType("") 39 | public static final int NO_AUTOMATIC_PROTOTYPE = 1 << 1; 40 | } 41 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptEvaluationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | 24 | /** 25 | * Exceptions which can be thrown during the evaluation of javascript. 26 | */ 27 | public class JavascriptEvaluationException extends Exception { 28 | private static final long serialVersionUID = 250417540756557840L; 29 | 30 | /** 31 | * Constructs a new {@link JavascriptEvaluationException} with just a message. 32 | * 33 | * @param message The message to display to the user 34 | */ 35 | @NativeCall 36 | public JavascriptEvaluationException(String message) { 37 | super(message); 38 | } 39 | 40 | /** 41 | * Constructs a new {@link JavascriptEvaluationException} with a message and a cause. 42 | * 43 | * @param message The message to display to the user 44 | * @param cause The exception causing this exception 45 | */ 46 | public JavascriptEvaluationException(String message, Throwable cause) { 47 | super(message, cause); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | 24 | /** 25 | * Exception bridged from Javascript. Handling these is difficult and should be done as soon as possible, 26 | * as the contained exception value gets lost as soon as the context unlocks. 27 | *

28 | * As Javascript exceptions, this exception is unchecked since it is not known when it can occur. 29 | */ 30 | public class JavascriptException extends RuntimeException { 31 | private final JavascriptValue value; 32 | 33 | /** 34 | * Constructs a new {@link JavascriptException} 35 | * 36 | * @param message The message describing when the exception occurred 37 | * @param value The value that has been thrown by Javascript 38 | */ 39 | @NativeCall 40 | public JavascriptException(String message, JavascriptValue value) { 41 | super(message); 42 | this.value = value; 43 | } 44 | 45 | /** 46 | * Retrieves the Javascript native value of this exception. 47 | * 48 | * @return The Javascript native value of this exception 49 | */ 50 | public JavascriptValue getValue() { 51 | return value; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptGlobalContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | /** 25 | * A global JavaScript execution context. A {@link JavascriptGlobalContext} is a {@link JavascriptContext}. 26 | */ 27 | @NativeType("JSGlobalContextRef") 28 | public class JavascriptGlobalContext extends JavascriptContext { 29 | /** 30 | * Constructs a new {@link JavascriptGlobalContext} wrapping the given native handle. 31 | * 32 | * @param handle The native handle to wrap 33 | */ 34 | private JavascriptGlobalContext(@NativeType("JSGlobalContextRef") long handle, JavascriptContextLock lock) { 35 | super(handle, lock); 36 | lock.addDependency(this); 37 | } 38 | 39 | /** 40 | * Retrieves the name of the context. A {@link JavascriptGlobalContext}s name is exposed for remote debugging to 41 | * make it easier to identify the context you would like to attach to. 42 | * 43 | * @return The name of the context 44 | */ 45 | public native String getName(); 46 | 47 | /** 48 | * Sets the remote debugging name for this context. 49 | * 50 | * @param name The remote debugging name to set on this context 51 | */ 52 | public native void setName(String name); 53 | 54 | /** 55 | * Releases the reference to this context. 56 | */ 57 | @Override 58 | public native void contextUnlocking(); 59 | } 60 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptLockedObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.annotation.Unsigned; 25 | 26 | /** 27 | * Interface for objects depending on the context lock. Useful for invalidation when the context is unlocked. 28 | */ 29 | public interface JavascriptLockedObject { 30 | /** 31 | * Called when the lock is about to be released. This can be used to release the internal references. After this 32 | * call returned the object must not use the context anymore. 33 | */ 34 | void contextUnlocking(); 35 | 36 | /** 37 | * Retrieves the lock the object is currently locked with. 38 | * 39 | * @return The lock the object is currently locked with 40 | */ 41 | JavascriptContextLock getLock(); 42 | 43 | /** 44 | * Retrieves the handle of the context this object is currently locked with. If the object is not locked anymore, 45 | * this method throws an {@link IllegalStateException}. 46 | * 47 | * @return The handle of the context this object is currently locked with 48 | * @throws IllegalStateException If the context object is not locked anymore 49 | */ 50 | @NativeCall 51 | @Unsigned 52 | @NativeType("JSContextRef") 53 | long getContextHandle(); 54 | 55 | /** 56 | * Retrieves the handle of the lock this object is locked with. If the object is not locked anymore, this method 57 | * throws an {@link IllegalStateException}. 58 | * 59 | * @return The handle of the lock this object is currently locked with 60 | * @throws IllegalStateException If the context object is not locked anymore 61 | */ 62 | @NativeCall 63 | @Unsigned 64 | @NativeType("ultralight_java::HoldContextLock *") 65 | long getLockHandle(); 66 | } 67 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptPropertyAttributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | /** 23 | * Attributes of properties on Javascript classes. Defines how those properties can be altered. 24 | */ 25 | public final class JavascriptPropertyAttributes { 26 | /** 27 | * Specifies that a property has no special attributes. 28 | */ 29 | public static int NONE = 0; 30 | 31 | /** 32 | * Specifies that a property is read-only. 33 | */ 34 | public static int READ_ONLY = 1 << 1; 35 | 36 | /** 37 | *

38 | * Specifies that a property should not be enumerated by {@link JavascriptObject#copyPropertyNames()} 39 | * and JavaScript for...in loops. 40 | */ 41 | public static int DONT_ENUM = 1 << 2; 42 | 43 | /** 44 | * Specifies that the delete operation should fail on a property. 45 | */ 46 | public static int DONT_DELETE = 1 << 3; 47 | } 48 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptProtectedValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | /** 23 | * A Javascript value that is currently not within any locked context. Those values keep references to their underlying 24 | * objects and prevent them from freeing. Don't keep these objects around forever, as this will create a memory leak 25 | * else. 26 | */ 27 | public class JavascriptProtectedValue { 28 | private long handle; 29 | 30 | /** 31 | * Constructs a new {@link JavascriptProtectedValue} wrapping the given native value reference. The native value 32 | * needs to be protected already! 33 | * 34 | * @param handle The native, already protected handle 35 | */ 36 | JavascriptProtectedValue(long handle) { 37 | this.handle = handle; 38 | } 39 | 40 | /** 41 | * "revives" the value by attaching it to a lock again. This invalidates this value. 42 | * 43 | * @param lock The lock to attach the value to 44 | * @return The reattached value 45 | * @throws IllegalArgumentException If the given lock is null 46 | * @throws IllegalStateException If the value has been revived already 47 | */ 48 | public JavascriptValue revive(JavascriptContextLock lock) { 49 | if (lock == null) { 50 | throw new IllegalArgumentException(new NullPointerException("lock")); 51 | } else if (handle == 0) { 52 | throw new IllegalStateException("The value has been revived already"); 53 | } 54 | 55 | long tHandle = handle; 56 | handle = 0; 57 | 58 | return new JavascriptValue(tHandle, lock); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/JavascriptType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | import java.lang.annotation.Native; 25 | 26 | /** 27 | * A constant identifying the type of a {@link JavascriptValue}. 28 | */ 29 | @NativeType("JSType") 30 | public enum JavascriptType { 31 | /** 32 | * The unique undefined value. 33 | */ 34 | @Native 35 | UNDEFINED, 36 | 37 | /** 38 | * The unique null value. 39 | */ 40 | @Native 41 | NULL, 42 | 43 | /** 44 | * A primitive boolean value, one of {@code true} or false {@code false}. 45 | */ 46 | @Native 47 | BOOLEAN, 48 | 49 | /** 50 | * A primitive number value. 51 | */ 52 | @Native 53 | NUMBER, 54 | 55 | /** 56 | * A primitive string value. 57 | */ 58 | @Native 59 | STRING, 60 | 61 | /** 62 | * An object value (meaning that the {@link JavascriptValue} is a {@link JavascriptObject}). 63 | */ 64 | @Native 65 | OBJECT, 66 | 67 | /** 68 | * A primitive symbol value. 69 | */ 70 | @Native 71 | SYMBOL 72 | } 73 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptInteropException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | /** 23 | * Exception which might by thrown by user code when interop'ing Java and Javascript. 24 | */ 25 | public class JavascriptInteropException extends Exception { 26 | /** 27 | * Constructs a new {@link JavascriptInteropException} with the given message. 28 | * 29 | * @param message The message to pass on to Javascript 30 | */ 31 | public JavascriptInteropException(String message) { 32 | super(message); 33 | } 34 | 35 | /** 36 | * Constructs a new {@link JavascriptInteropException} with the given message caused by another exception. 37 | * 38 | * @param message The message to pass on to Javascript 39 | * @param cause The exception causing this exception 40 | */ 41 | public JavascriptInteropException(String message, Throwable cause) { 42 | super(message, cause); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | import com.labymedia.ultralight.javascript.JavascriptValue; 27 | 28 | /** 29 | * Callback for calling a Javascript object with the new operator. 30 | */ 31 | @NativeType("JSObjectCallAsConstructorCallback") 32 | public interface JavascriptObjectConstructor { 33 | /** 34 | * The callback invoked when an object is used as a constructor in a 'new' expression. 35 | * 36 | * @param context The execution context to use 37 | * @param constructor An object that is the constructor being called 38 | * @param arguments An array of the arguments passed to the function 39 | * @return An object that is the constructor's return value 40 | * @throws JavascriptInteropException If an error occurs while invoking the constructor 41 | */ 42 | @NativeCall 43 | JavascriptObject callAsJavascriptConstructor( 44 | JavascriptContext context, JavascriptObject constructor, JavascriptValue[] arguments) 45 | throws JavascriptInteropException; 46 | } 47 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectFinalizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptObject; 25 | 26 | /** 27 | * Callback for the finalization of Javascript objects. 28 | */ 29 | @NativeType("JSObjectFinalizeCallback") 30 | public interface JavascriptObjectFinalizer { 31 | /** 32 | * The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on 33 | * any thread. 34 | *

35 | * The finalize callback is called on the most derived class first, and the least derived class (the parent class) 36 | * last. 37 | *

38 | * Functions which may cause garbage collection or allocation of new objects must not be called from inside this 39 | * callback! 40 | * 41 | * @param object The object being finalized 42 | */ 43 | @NativeCall 44 | void finalizeJavascriptObject(JavascriptObject object); 45 | } 46 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | import com.labymedia.ultralight.javascript.JavascriptValue; 27 | 28 | /** 29 | * Callback for invoking a Javascript object as a function. 30 | */ 31 | @NativeType("JSObjectCallAsFunctionCallback") 32 | public interface JavascriptObjectFunction { 33 | /** 34 | * The callback invoked when an object is called as a function. 35 | * 36 | * @param context The execution context to use 37 | * @param function An object that is the function being called 38 | * @param thisObject An object that is the 'this' variable in the function's scope 39 | * @param arguments An array of the arguments passed to the function 40 | * @return The return value of the function, must not be null 41 | * @throws JavascriptInteropException If an error occurs while invoking the function 42 | */ 43 | @NativeCall 44 | JavascriptValue callAsJavascriptFunction( 45 | JavascriptContext context, 46 | JavascriptObject function, 47 | JavascriptObject thisObject, 48 | JavascriptValue[] arguments 49 | ) throws JavascriptInteropException; 50 | } 51 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectHasInstanceTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | import com.labymedia.ultralight.javascript.JavascriptValue; 27 | 28 | /** 29 | * Callback when an object is used with an instanceof test. 30 | */ 31 | @NativeType("JSObjectHasInstanceCallback") 32 | public interface JavascriptObjectHasInstanceTester { 33 | /** 34 | * The callback invoked when an object is used as the target of an 'instanceof' expression. 35 | * 36 | * @param context The execution context to use 37 | * @param constructor The object that is the target of the 'instanceof' expression 38 | * @param possibleInstance The value being tested to determine if it is an instance of constructor 39 | * @return {@code true} if possibleInstance is an instance of constructor, otherwise {@code false} 40 | * @throws JavascriptInteropException If an error occurs while testing if the object is an instance of the value 41 | */ 42 | @NativeCall 43 | boolean hasJavascriptInstance( 44 | JavascriptContext context, JavascriptObject constructor, JavascriptValue possibleInstance) 45 | throws JavascriptInteropException; 46 | } 47 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectHasPropertyTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | 27 | /** 28 | * Callback for testing if a Javascript object has a certain property. 29 | */ 30 | @NativeType("JSObjectHasPropertyCallback") 31 | public interface JavascriptObjectHasPropertyTester { 32 | /** 33 | * If this function returns false, the hasProperty request forwards to object's statically declared properties, then 34 | * its parent class chain (which includes the default object class), then its prototype chain. 35 | *

36 | * This callback enables optimization in cases where only a property's existence needs to be known, not its value, 37 | * and computing its value would be expensive. 38 | * 39 | * @param context The execution context to use 40 | * @param object The object to search for the property 41 | * @param propertyName A string containing the name of the property look up 42 | * @return {@code true} if object has the property, otherwise {@code false} 43 | */ 44 | @NativeCall 45 | boolean hasJavascriptProperty(JavascriptContext context, JavascriptObject object, String propertyName); 46 | } 47 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | 27 | /** 28 | * Callback for the initialization of Javascript objects. 29 | */ 30 | @NativeType("JSObjectInitializeCallback") 31 | public interface JavascriptObjectInitializer { 32 | /** 33 | * The callback invoked when an object is first created. 34 | *

35 | * Unlike the other object callbacks, the initialize callback is called on the least 36 | * derived class (the parent class) first, and the most derived class last. 37 | *

38 | * The parameters are only valid for the duration of execution of this method! 39 | * 40 | * @param context The execution context to use 41 | * @param object The JSObject being created 42 | */ 43 | @NativeCall 44 | void initializeJavascriptObject(JavascriptContext context, JavascriptObject object); 45 | } 46 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectPropertyDeleter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | 27 | /** 28 | * Callback for deleting properties of Javascript objects. 29 | */ 30 | @NativeType("JSObjectDeletePropertyCallback") 31 | public interface JavascriptObjectPropertyDeleter { 32 | /** 33 | * The callback invoked when deleting a property. 34 | *

35 | * If this function returns false, the delete request forwards to object's statically declared properties, then its 36 | * parent class chain (which includes the default object class). 37 | * 38 | * @param context The execution context to use 39 | * @param object The object in which to delete the property 40 | * @param propertyName A string containing the name of the property to delete 41 | * @return {@code true} if propertyName was successfully deleted, otherwise {@code false} 42 | * @throws JavascriptInteropException If an error occurs while deleting the property 43 | */ 44 | @NativeCall 45 | boolean deleteJavascriptProperty(JavascriptContext context, JavascriptObject object, String propertyName) 46 | throws JavascriptInteropException; 47 | } 48 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectPropertyGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | import com.labymedia.ultralight.javascript.JavascriptType; 27 | import com.labymedia.ultralight.javascript.JavascriptValue; 28 | 29 | /** 30 | * Callback for retrieving properties from a Javascript object. 31 | */ 32 | @NativeType("JSObjectGetPropertyCallback") 33 | public interface JavascriptObjectPropertyGetter { 34 | /** 35 | * The callback invoked when getting a property's value. 36 | *

37 | * If this function returns {@code null}, the get request forwards to object's statically declared properties, then 38 | * its parent class chain (which includes the default object class), then its prototype chain. 39 | * 40 | * @param context The execution context to use 41 | * @param object The object to search for the property 42 | * @param propertyName A string containing the name of the property to get 43 | * @return The property's value if object has the property, otherwise {@code null}, to return the literal null 44 | * value, construct a {@link JavascriptValue} with the {@link JavascriptType#NULL} 45 | * type 46 | * @throws JavascriptInteropException If an error occurs while retrieving the property 47 | */ 48 | @NativeCall 49 | JavascriptValue getJavascriptProperty(JavascriptContext context, JavascriptObject object, String propertyName) 50 | throws JavascriptInteropException; 51 | } 52 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectPropertyNamesCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | 27 | /** 28 | * Callback for retrieving names of a Javascript object. 29 | */ 30 | @NativeType("JSObjectGetPropertyNamesCallback") 31 | public interface JavascriptObjectPropertyNamesCollector { 32 | /** 33 | * The callback invoked when collecting the names of an object's properties. 34 | *

35 | * {@link JavascriptObject#copyPropertyNames()} and JavaScript for...in loops. 36 | *

37 | * A class's {@link JavascriptObjectPropertyNamesCollector} callback only needs to provide the names of properties 38 | * that the class vends through a custom {@link JavascriptObjectPropertyGetter} or {@link 39 | * JavascriptObjectPropertySetter}. Other properties, including statically declared properties, properties vended by 40 | * other classes, and properties belonging to object's prototype, are added independently. 41 | * 42 | * @param context The execution context to use 43 | * @param object The object whose property names are being collected 44 | * @return An array of all property names on the given object 45 | */ 46 | @NativeCall 47 | String[] collectJavascriptPropertyNames(JavascriptContext context, JavascriptObject object); 48 | } 49 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectPropertySetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | import com.labymedia.ultralight.javascript.JavascriptValue; 27 | 28 | /** 29 | * Callback for setting properties on Javascript objects. 30 | */ 31 | @NativeType("JSObjectSetPropertyCallback") 32 | public interface JavascriptObjectPropertySetter { 33 | /** 34 | * The callback invoked when setting a property's value. 35 | *

36 | * If this function returns false, the set request forwards to object's statically declared properties, then its 37 | * parent class chain (which includes the default object class). 38 | * 39 | * @param context The execution context to use 40 | * @param object The object on which to set the property's value 41 | * @param propertyName A string containing the name of the property to set 42 | * @param value A value to use as the property's value 43 | * @return {@code true} if the property was set, otherwise {@code false} 44 | * @throws JavascriptInteropException If an error occurs while setting the property 45 | */ 46 | @NativeCall 47 | boolean setJavascriptProperty( 48 | JavascriptContext context, JavascriptObject object, String propertyName, JavascriptValue value) 49 | throws JavascriptInteropException; 50 | } 51 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/javascript/interop/JavascriptObjectToTypeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.javascript.interop; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | import com.labymedia.ultralight.javascript.JavascriptContext; 25 | import com.labymedia.ultralight.javascript.JavascriptObject; 26 | import com.labymedia.ultralight.javascript.JavascriptType; 27 | import com.labymedia.ultralight.javascript.JavascriptValue; 28 | 29 | /** 30 | * Callback for converting a Javascript object to another type. 31 | */ 32 | @NativeType("JSObjectConvertToTypeCallback") 33 | public interface JavascriptObjectToTypeConverter { 34 | /** 35 | * The callback invoked when converting an object to a particular JavaScript type. 36 | * 37 | * @param context The execution context to use 38 | * @param object The object to convert 39 | * @param type A {@link JavascriptType} specifying the JavaScript type to convert to 40 | * @return The object's converted value, must not be null 41 | * @throws JavascriptInteropException If an error occurs while converting the object 42 | */ 43 | @NativeCall 44 | JavascriptValue convertToJavascriptType(JavascriptContext context, JavascriptObject object, JavascriptType type) 45 | throws JavascriptInteropException; 46 | } 47 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/os/Architecture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.os; 21 | 22 | /** 23 | * Enum representing known computer architectures. 24 | */ 25 | public enum Architecture { 26 | /** 27 | * amd64/x86_64 architecture, most common one for home PC's 28 | */ 29 | AMD64(64), 30 | 31 | /** 32 | * i386/x86 architecture, most common one for older home PC's 33 | */ 34 | I386(32), 35 | 36 | /** 37 | * Unknown architecture 38 | */ 39 | UNKNOWN(-1); 40 | 41 | private final int bits; 42 | 43 | /** 44 | * Constructs a new {@link Architecture} with the given amount of bits per pointer. 45 | * 46 | * @param bits The amount of bits of a pointer on this architecture 47 | */ 48 | Architecture(int bits) { 49 | this.bits = bits; 50 | } 51 | 52 | /** 53 | * Retrieves the amount of bits a pointer has on this platform. 54 | * 55 | * @return The amount of bits of a pointer, or {@code -1} if unknown 56 | */ 57 | public int getBits() { 58 | return bits; 59 | } 60 | 61 | /** 62 | * Guesses the architecture this application is running on. 63 | * 64 | * @return A best guess of the architecture 65 | */ 66 | public static Architecture get() { 67 | String arch = System.getProperty("os.arch", "unknown").toLowerCase(); 68 | String dataModel = System.getProperty("sun.arch.data.model", "unknown").toLowerCase(); 69 | 70 | if (arch.equals("unknown") && dataModel.equals("unknown")) { 71 | return UNKNOWN; 72 | } else if (arch.contains("64") || dataModel.contains("64")) { 73 | // TODO: Technically incorrect, for now we just assume its some kind of amd64 PC 74 | return AMD64; 75 | } else { 76 | // TODO: Technically incorrect, for now just assume its some kind of i386 PC 77 | return I386; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/clipboard/UltralightClipboard.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.clipboard; 21 | 22 | /** 23 | * Clipboard interface. 24 | *

25 | * This is used for reading and writing data to the platform Clipboard. 26 | *

27 | * This is intended to be implemented by users and defined before creating the Renderer. @see Platform::set_clipboard. 28 | */ 29 | public interface UltralightClipboard { 30 | /** 31 | * Clear the clipboard. 32 | */ 33 | void clear(); 34 | 35 | /** 36 | * Read plain text from the clipboard 37 | * 38 | * @return The content of the clipboard as plain text 39 | */ 40 | String readPlainText(); 41 | 42 | /** 43 | * Write plain text to the clipboard. 44 | * 45 | * @param text The plain text to write to the clipboard 46 | */ 47 | void writePlainText(String text); 48 | } 49 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/logging/UltralightLogLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.logging; 21 | 22 | /** 23 | * Log levels, used with {@link UltralightLogger#logMessage(UltralightLogLevel, String)} 24 | */ 25 | public enum UltralightLogLevel { 26 | /** 27 | * An error occurred and a message has been generated. 28 | */ 29 | ERROR, 30 | 31 | /** 32 | * Some warning has been triggered and a message has been generated. 33 | */ 34 | WARNING, 35 | 36 | /** 37 | * An event occurred and a message has been generated 38 | */ 39 | INFO 40 | } 41 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/logging/UltralightLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.logging; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | /** 25 | * Logger interface. 26 | *

27 | * This can be used to log debug messages to the console or to a log file. 28 | *

29 | * This is intended to be implemented by users and defined before creating the 30 | * Renderer. 31 | */ 32 | @NativeType("ultralight::Logger") 33 | public interface UltralightLogger { 34 | /** 35 | * Called when the library wants to print a message to the log. 36 | * 37 | * @param level The level of the message 38 | * @param message The message to log 39 | */ 40 | void logMessage(UltralightLogLevel level, String message); 41 | } 42 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/render/UltralightCommandType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.render; 21 | 22 | /** 23 | * Command types, used by {@link UltralightCommand#getCommandType()}. 24 | */ 25 | public enum UltralightCommandType { 26 | /** 27 | * The command should clear the render buffer. 28 | */ 29 | CLEAR_RENDER_BUFFER, 30 | 31 | /** 32 | * The command should draw some geometry into the render buffer. 33 | */ 34 | DRAW_GEOMETRY 35 | } 36 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/render/UltralightGPUDriverNative.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.render; 21 | 22 | public interface UltralightGPUDriverNative { 23 | 24 | long getDriverHandle(); 25 | 26 | void beginSynchronize(); 27 | 28 | void endSynchronize(); 29 | 30 | boolean hasCommandsPending(); 31 | 32 | void drawCommandList(); 33 | 34 | void bindTexture(long textureId, long texture); 35 | 36 | int getGlTextureId(long texture); 37 | 38 | void setActiveWindow(long window); 39 | } 40 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/render/UltralightIndexBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.render; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | 25 | import java.nio.ByteBuffer; 26 | 27 | /** 28 | * Vertex index buffer. 29 | * 30 | * @see UltralightGPUDriver#createGeometry(long, UltralightVertexBuffer, UltralightIndexBuffer) 31 | */ 32 | @NativeType("ultralight::IndexBuffer") 33 | public class UltralightIndexBuffer { 34 | private final @NativeType("uint8_t[]") 35 | ByteBuffer data; 36 | 37 | /** 38 | * Constructs a new index buffer wrapping an existing byte buffer. 39 | * 40 | * @param data The data of the index buffer 41 | */ 42 | @NativeCall 43 | public UltralightIndexBuffer(ByteBuffer data) { 44 | this.data = data; 45 | } 46 | 47 | /** 48 | * Retrieves the data of the index buffer. 49 | * 50 | * @return The data of the index buffer 51 | */ 52 | public ByteBuffer getData() { 53 | return data; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/render/UltralightShaderType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.render; 21 | 22 | public enum UltralightShaderType { 23 | FILL, 24 | FILL_PATH 25 | } 26 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/render/UltralightVertexBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.render; 21 | 22 | import com.labymedia.ultralight.annotation.NativeCall; 23 | import com.labymedia.ultralight.annotation.NativeType; 24 | 25 | import java.nio.ByteBuffer; 26 | 27 | /** 28 | * Vertex buffer. 29 | * 30 | * @see UltralightGPUDriver#createGeometry(long, UltralightVertexBuffer, UltralightIndexBuffer) 31 | */ 32 | @NativeType("ultralight::VertexBuffer") 33 | public class UltralightVertexBuffer { 34 | private final UltralightVertexBufferFormat format; 35 | private final @NativeType("uint8_t[]") 36 | ByteBuffer data; 37 | 38 | /** 39 | * Constructs a new {@link UltralightVertexBuffer} wrapping an existing native buffer. 40 | * 41 | * @param format The format of the buffer 42 | * @param data The data to wrap of the buffer 43 | */ 44 | @NativeCall 45 | public UltralightVertexBuffer(UltralightVertexBufferFormat format, @NativeType("uint8_t[]") ByteBuffer data) { 46 | this.format = format; 47 | this.data = data; 48 | } 49 | 50 | /** 51 | * Retrieves the format of the the buffer. 52 | * 53 | * @return The format of the buffer 54 | */ 55 | public UltralightVertexBufferFormat getFormat() { 56 | return format; 57 | } 58 | 59 | /** 60 | * Retrieves the data of the buffer. 61 | * 62 | * @return The data of the buffer 63 | */ 64 | public ByteBuffer getData() { 65 | return data; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/render/UltralightVertexBufferFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.render; 21 | 22 | import com.labymedia.ultralight.annotation.NativeType; 23 | 24 | /** 25 | * Vertex formats. 26 | */ 27 | @NativeType("ultralight::VertexBufferFormat") 28 | public enum UltralightVertexBufferFormat { 29 | FORMAT_2F_4UB_2F, 30 | FORMAT_2F_4UB_2F_2F_28F 31 | } 32 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/view/MessageLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.view; 21 | 22 | /** 23 | * MessageLevel types 24 | */ 25 | public enum MessageLevel { 26 | LOG, 27 | WARNING, 28 | ERROR, 29 | DEBUG, 30 | INFO 31 | } 32 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/view/MessageSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.plugin.view; 21 | 22 | /** 23 | * MessageSource types 24 | */ 25 | public enum MessageSource { 26 | XML, 27 | JS, 28 | NETWORK, 29 | CONSOLE_API, 30 | STORAGE, 31 | APP_CACHE, 32 | RENDERING, 33 | CSS, 34 | SECURITY, 35 | CONTENT_BLOCKER, 36 | OTHER 37 | } 38 | -------------------------------------------------------------------------------- /ultralight-java-base/src/main/java/com/labymedia/ultralight/util/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.util; 21 | 22 | /** 23 | * General purpose utility class containing methods which don't fit anywhere else. 24 | */ 25 | public class Util { 26 | // Static class 27 | private Util() { 28 | } 29 | 30 | /** 31 | * Method to simply force cast any type to any type. Use with caution, 32 | * absolutely no checks are done. This is often useful when generic signatures 33 | * begin to clash and you can ensure that it is safe to erase them. 34 | * 35 | * @param o The object to cast 36 | * @param The target type 37 | * @return The casted object 38 | */ 39 | @SuppressWarnings("unchecked") 40 | public static T forceCast(Object o) { 41 | return (T) o; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ultralight-java-databind-codegen/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'maven-publish' 4 | } 5 | 6 | group 'com.labymedia' 7 | 8 | jar { 9 | manifest { 10 | attributes( 11 | 'Automatic-Module-Name': 'com.labymedia.ultralight.databind.codegen' 12 | ) 13 | } 14 | } 15 | 16 | repositories { 17 | mavenCentral() 18 | } 19 | 20 | dependencies { 21 | implementation project(':ultralight-java-base') 22 | implementation project(':ultralight-java-databind') 23 | implementation group: 'org.javassist', name: 'javassist', version: '3.27.0-GA' 24 | } 25 | 26 | commonPublish(project) { 27 | pom { 28 | name = "UltralightJava Databind Codegen" 29 | description = "Optional Codegen for UltralightJava Databind" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ultralight-java-databind-codegen/src/main/java/com/labymedia/ultralight/databind/codegen/call/property/CallerGenerationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.databind.codegen.call.property; 21 | 22 | /** 23 | * Exception thrown when there was a problem generating a new {@link SingleGeneratedPropertyCaller}. 24 | */ 25 | public class CallerGenerationException extends RuntimeException { 26 | 27 | /** 28 | * {@inheritDoc} 29 | */ 30 | public CallerGenerationException(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ultralight-java-databind-codegen/src/main/java/com/labymedia/ultralight/databind/codegen/call/property/SingleGeneratedPropertyCaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.databind.codegen.call.property; 21 | 22 | /** 23 | * Represents a bytecode-generated caller which directly calls a certain property on a java object or class without reflection. 24 | */ 25 | public interface SingleGeneratedPropertyCaller { 26 | 27 | /** 28 | * Calls the property of the object or class directly. 29 | * 30 | * @param instance The instance the property belongs to or {@code null} if the property belongs to a class. 31 | * @param parameters The parameters the property should be called with or {@code null} if the property does not support arguments. 32 | * @return The result of the call or {@code null} if the property has no result 33 | */ 34 | Object callProperty(Object instance, Object[] parameters); 35 | } 36 | -------------------------------------------------------------------------------- /ultralight-java-databind/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'maven-publish' 4 | } 5 | 6 | group 'com.labymedia' 7 | 8 | jar { 9 | manifest { 10 | attributes( 11 | 'Automatic-Module-Name': 'com.labymedia.ultralight.databind' 12 | ) 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation project(':ultralight-java-base') 18 | } 19 | 20 | commonPublish(project) { 21 | pom { 22 | name = "UltralightJava Databind" 23 | description = "Automatic bindings from Java to Javascript for UltralightJava" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ultralight-java-databind/src/main/java/com/labymedia/ultralight/databind/api/InjectJavascriptContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.databind.api; 21 | 22 | import com.labymedia.ultralight.databind.Databind; 23 | import com.labymedia.ultralight.javascript.JavascriptContext; 24 | 25 | import java.lang.annotation.ElementType; 26 | import java.lang.annotation.Retention; 27 | import java.lang.annotation.RetentionPolicy; 28 | import java.lang.annotation.Target; 29 | 30 | /** 31 | * Marks the method as accepting a {@link JavascriptContext} as the first 32 | * parameter. 33 | *

34 | * The {@link Databind} instance will then a call the method with the current context. 35 | */ 36 | @Target(ElementType.METHOD) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | public @interface InjectJavascriptContext { 39 | } 40 | -------------------------------------------------------------------------------- /ultralight-java-databind/src/main/java/com/labymedia/ultralight/databind/cache/JavascriptClassCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.databind.cache; 21 | 22 | import com.labymedia.ultralight.javascript.JavascriptClass; 23 | 24 | /** 25 | * Map like cache structure for caching Javascript classes. 26 | */ 27 | public interface JavascriptClassCache { 28 | /** 29 | * Retrieves a class from the cache. 30 | * 31 | * @param name The name of the class to retrieve 32 | * @return The cached class, or {@code null}, if the class is not cached 33 | */ 34 | JavascriptClass get(String name); 35 | 36 | /** 37 | * Puts a class into the cache. 38 | * 39 | * @param name The name of the class to cache 40 | * @param javascriptClass The class instance to cache 41 | * @return javascriptClass 42 | */ 43 | JavascriptClass put(String name, JavascriptClass javascriptClass); 44 | 45 | /** 46 | * Removes a class from the cache. 47 | * 48 | * @param name The name of the class to remove 49 | * @return The previously cached class, or {@code null}, if the class was not cached 50 | */ 51 | JavascriptClass delete(String name); 52 | 53 | /** 54 | * Determines whether the cache contains a class. 55 | * 56 | * @param name The name of the class to test for 57 | * @return {@code true} if the class is cached, {@code false} otherwise 58 | */ 59 | boolean contains(String name); 60 | } 61 | -------------------------------------------------------------------------------- /ultralight-java-databind/src/main/java/com/labymedia/ultralight/databind/cache/NaiveJavascriptClassCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.databind.cache; 21 | 22 | import com.labymedia.ultralight.javascript.JavascriptClass; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | /** 28 | * Simple, {@link HashMap} based implementation of a {@link JavascriptClassCache}. 29 | */ 30 | public final class NaiveJavascriptClassCache implements JavascriptClassCache { 31 | private final Map cache; 32 | 33 | /** 34 | * Constructs a new empty {@link NaiveJavascriptClassCache}. 35 | */ 36 | public NaiveJavascriptClassCache() { 37 | this.cache = new HashMap<>(); 38 | } 39 | 40 | @Override 41 | public JavascriptClass get(String name) { 42 | return cache.get(name); 43 | } 44 | 45 | @Override 46 | public JavascriptClass put(String name, JavascriptClass javascriptClass) { 47 | cache.put(name, javascriptClass); 48 | return javascriptClass; 49 | } 50 | 51 | @Override 52 | public JavascriptClass delete(String name) { 53 | return cache.remove(name); 54 | } 55 | 56 | @Override 57 | public boolean contains(String name) { 58 | return cache.containsKey(name); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ultralight-java-databind/src/main/java/com/labymedia/ultralight/databind/call/MethodChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.databind.call; 21 | 22 | import com.labymedia.ultralight.javascript.JavascriptValue; 23 | 24 | import java.lang.reflect.Executable; 25 | import java.util.Collection; 26 | 27 | /** 28 | * Describes an abstraction layer around the system determining which method to invoke on an incoming 29 | * call from Javascript. 30 | */ 31 | public interface MethodChooser { 32 | /** 33 | * Chooses the best matching method based on the arguments incoming from Javascript. 34 | * 35 | * @param possibilities All executables which could possibly be targeted by this call 36 | * @param javascriptValues The arguments being passed from Javascript 37 | * @param The target executable type 38 | * @return Information on how to call the chosen executable 39 | * @throws IllegalStateException If the target executable can not be determined 40 | */ 41 | CallData choose(Collection possibilities, JavascriptValue[] javascriptValues); 42 | 43 | /** 44 | * Chooses the best matching method based on the arguments incoming from Javascript. 45 | * 46 | * @param possibilities All executables which could possibly be targeted by this call 47 | * @param sourceParameterTypes The desired types for the parameters 48 | * @param javascriptValues The arguments being passed from Javascript 49 | * @param The target executable type 50 | * @return Information on how to call the chosen executable 51 | * @throws IllegalStateException If the target executable can not be determined 52 | */ 53 | CallData choose( 54 | Collection possibilities, Class[] sourceParameterTypes, JavascriptValue[] javascriptValues); 55 | } 56 | -------------------------------------------------------------------------------- /ultralight-java-databind/src/main/java/com/labymedia/ultralight/databind/context/ContextProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.databind.context; 21 | 22 | import com.labymedia.ultralight.javascript.JavascriptContextLock; 23 | 24 | import java.util.function.Consumer; 25 | 26 | /** 27 | * Interface to be implemented by the user. 28 | */ 29 | public interface ContextProvider { 30 | /** 31 | * Executes the callback later on a thread which is synchronized with the Javascript engine. 32 | * 33 | * @param callback The callback to execute 34 | */ 35 | void syncWithJavascript(Consumer callback); 36 | } 37 | -------------------------------------------------------------------------------- /ultralight-java-databind/src/main/java/com/labymedia/ultralight/databind/context/ContextProviderFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.databind.context; 21 | 22 | import com.labymedia.ultralight.databind.DatabindConfiguration; 23 | import com.labymedia.ultralight.javascript.JavascriptValue; 24 | 25 | /** 26 | * Interface to be implemented by the user for binding values in callbacks to contexts. 27 | *

28 | * This is required for translating Javascript methods to functional interfaces and invoking them, as the context 29 | * gets lost in the process of binding the interface. The library will then invoke the context provider factory 30 | * to re-acquire the context. 31 | * 32 | * @see DatabindConfiguration.Builder#contextProviderFactory(ContextProviderFactory) 33 | */ 34 | public interface ContextProviderFactory { 35 | /** 36 | * Binds a provider for the specified Javascript value. 37 | * 38 | * @param value The value to bind a provider for 39 | * @return The bound provider 40 | */ 41 | ContextProvider bindProvider(JavascriptValue value); 42 | } 43 | -------------------------------------------------------------------------------- /ultralight-java-glfw-opengl-util/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-library") 3 | id("maven-publish") 4 | } 5 | 6 | group = "com.labymedia" 7 | 8 | jar { 9 | manifest { 10 | attributes( 11 | 'Automatic-Module-Name': 'com.labymedia.ultralight.util' 12 | ) 13 | } 14 | } 15 | 16 | repositories { 17 | mavenCentral() 18 | } 19 | 20 | dependencies { 21 | implementation(project(":ultralight-java-base")) 22 | implementation(project(":ultralight-java-gpu")) 23 | 24 | implementation(group: "org.lwjgl", name: "lwjgl-glfw", version: "3.2.2") 25 | implementation(group: "org.lwjgl", name: "lwjgl-opengl", version: "3.2.2") 26 | } 27 | 28 | commonPublish(project) { 29 | pom { 30 | name = "UltralightJavaGlfwOpenGLUtil" 31 | description = "Ultralight Java Glfw OpenGL Util" 32 | } 33 | } -------------------------------------------------------------------------------- /ultralight-java-glfw-opengl-util/src/main/java/com/labymedia/ultralight/util/UltralightOpenGLGPUDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.util; 21 | 22 | /** 23 | * Defines the minimal logic to generate an OpenGL texture from the current 24 | */ 25 | public interface UltralightOpenGLGPUDriver { 26 | 27 | /** 28 | * Set driver specific Ultralight Settings to a given context 29 | * 30 | * @param context the context to initialize 31 | */ 32 | void initialize(UltralightGlfwOpenGLContext context); 33 | 34 | /** 35 | * Update web content and render it to an OpenGL texture. 36 | * 37 | * @param window the window to reload and render 38 | */ 39 | void renderTexture(UltralightGlfwOpenGLWindow window); 40 | 41 | /** 42 | * Bind the latest rendered texture of a given window to the current OpenGL context. 43 | * 44 | * @param window the window to retrieve texture from 45 | */ 46 | void bindTexture(UltralightGlfwOpenGLWindow window); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ultralight-java-glfw-opengl-util/src/main/java/com/labymedia/ultralight/util/UltralightRendererInstanceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2020 - 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | package com.labymedia.ultralight.util; 21 | 22 | import com.labymedia.ultralight.UltralightRenderer; 23 | 24 | // This class is only required because UltralightRenderer#create does not cache the singleton instance and will crash on multiple calls. :) 25 | public class UltralightRendererInstanceHolder { 26 | 27 | private static UltralightRenderer renderer; 28 | 29 | private UltralightRendererInstanceHolder() { 30 | } 31 | 32 | public static UltralightRenderer getRenderer() { 33 | if (renderer == null) { 34 | renderer = UltralightRenderer.create(); 35 | } 36 | return renderer; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ultralight-java-gpu-native/include/ultralight_java/gpudriver/common/GPUDriverImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace ultralight { 27 | 28 | class GPUDriverImpl : public GPUDriver { 29 | public: 30 | GPUDriverImpl(); 31 | virtual ~GPUDriverImpl(); 32 | 33 | virtual const char *name() = 0; 34 | 35 | virtual void BeginDrawing() = 0; 36 | 37 | virtual void EndDrawing() = 0; 38 | 39 | virtual void BindTexture(uint8_t texture_unit, uint32_t texture_id) = 0; 40 | 41 | virtual void BindRenderBuffer(uint32_t render_buffer_id) = 0; 42 | 43 | virtual void ClearRenderBuffer(uint32_t render_buffer_id) = 0; 44 | 45 | virtual void DrawGeometry( 46 | uint32_t geometry_id, uint32_t indices_count, uint32_t indices_offset, const GPUState &state) = 0; 47 | 48 | virtual bool HasCommandsPending(); 49 | 50 | virtual void DrawCommandList(); 51 | 52 | virtual int batch_count() const; 53 | 54 | // Inherited from GPUDriver 55 | 56 | virtual void BeginSynchronize() override; 57 | 58 | virtual void EndSynchronize() override; 59 | 60 | virtual uint32_t NextTextureId() override; 61 | 62 | virtual uint32_t NextRenderBufferId() override; 63 | 64 | virtual uint32_t NextGeometryId() override; 65 | 66 | virtual void UpdateCommandList(const CommandList &list) override; 67 | 68 | protected: 69 | uint32_t next_texture_id_ = 1; 70 | uint32_t next_render_buffer_id_ = 1; // render buffer id 0 is reserved for default render target view. 71 | uint32_t next_geometry_id_ = 1; 72 | std::vector command_list_; 73 | int batch_count_; 74 | }; 75 | 76 | } // namespace ultralight -------------------------------------------------------------------------------- /ultralight-java-gpu-native/include/ultralight_java/gpudriver/gl/GPUContextGL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | #include 22 | #include 23 | #include 24 | 25 | #include "ultralight_java/gpudriver/common/GPUDriverImpl.h" 26 | 27 | typedef struct GLFWwindow GLFWwindow; 28 | 29 | #define ENABLE_OFFSCREEN_GL 0 30 | 31 | namespace ultralight { 32 | 33 | class GPUContextGL { 34 | protected: 35 | std::unique_ptr driver_; 36 | void *window_; 37 | void *active_window_ = nullptr; 38 | bool msaa_enabled_; 39 | 40 | public: 41 | GPUContextGL(void *window, bool enable_msaa); 42 | 43 | virtual ~GPUContextGL() { 44 | } 45 | 46 | virtual ultralight::GPUDriverImpl *driver() const { 47 | return driver_.get(); 48 | } 49 | 50 | virtual ultralight::FaceWinding face_winding() const { 51 | return ultralight::kFaceWinding_CounterClockwise; 52 | } 53 | 54 | virtual void BeginDrawing() { 55 | } 56 | 57 | virtual void EndDrawing() { 58 | } 59 | 60 | virtual bool msaa_enabled() const { 61 | return msaa_enabled_; 62 | } 63 | 64 | // An offscreen window dedicated to maintaining the OpenGL context. 65 | // All other windows created during lifetime of the app share this context. 66 | virtual void *window() { 67 | return window_; 68 | } 69 | 70 | // FBOs are not shared across contexts in OpenGL 3.2 (AFAIK), we luckily 71 | // don't need to share them across multiple windows anyways so we temporarily 72 | // set the active GL context to the "active window" when creating FBOs. 73 | virtual void set_active_window(void *win) { 74 | active_window_ = win; 75 | } 76 | 77 | virtual void *active_window() { 78 | return active_window_; 79 | } 80 | }; 81 | 82 | } // namespace ultralight -------------------------------------------------------------------------------- /ultralight-java-gpu-native/include/ultralight_java/gpudriver/gl/shader_v2f_c4f_t2f_t2f_d28f_vert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | static std::string shader_v2f_c4f_t2f_t2f_d28f_vert() { 23 | return R"(#version 150 24 | 25 | // Program Uniforms 26 | uniform vec4 State; 27 | uniform mat4 Transform; 28 | uniform vec4 Scalar4[2]; 29 | uniform vec4 Vector[8]; 30 | uniform uint ClipSize; 31 | uniform mat4 Clip[8]; 32 | 33 | // Uniform Accessor Functions 34 | float Time() { return State[0]; } 35 | float ScreenWidth() { return State[1]; } 36 | float ScreenHeight() { return State[2]; } 37 | float ScreenScale() { return State[3]; } 38 | float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; } 39 | vec4 sRGBToLinear(vec4 val) { 40 | return val; 41 | // return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w); 42 | } 43 | // Vertex Attributes 44 | in vec2 in_Position; 45 | in vec4 in_Color; 46 | in vec2 in_TexCoord; 47 | in vec2 in_ObjCoord; 48 | in vec4 in_Data0; 49 | in vec4 in_Data1; 50 | in vec4 in_Data2; 51 | in vec4 in_Data3; 52 | in vec4 in_Data4; 53 | in vec4 in_Data5; 54 | in vec4 in_Data6; 55 | 56 | // Out Params 57 | out vec4 ex_Color; 58 | out vec2 ex_TexCoord; 59 | out vec4 ex_Data0; 60 | out vec4 ex_Data1; 61 | out vec4 ex_Data2; 62 | out vec4 ex_Data3; 63 | out vec4 ex_Data4; 64 | out vec4 ex_Data5; 65 | out vec4 ex_Data6; 66 | out vec2 ex_ObjectCoord; 67 | out vec2 ex_ScreenCoord; 68 | 69 | void main(void) 70 | { 71 | ex_ObjectCoord = in_ObjCoord; 72 | gl_Position = Transform * vec4(in_Position, 0.0, 1.0); 73 | ex_Color = in_Color; 74 | ex_TexCoord = in_TexCoord; 75 | ex_Data0 = in_Data0; 76 | ex_Data1 = in_Data1; 77 | ex_Data2 = in_Data2; 78 | ex_Data3 = in_Data3; 79 | ex_Data4 = in_Data4; 80 | ex_Data5 = in_Data5; 81 | ex_Data6 = in_Data6; 82 | } 83 | 84 | )"; 85 | } -------------------------------------------------------------------------------- /ultralight-java-gpu-native/include/ultralight_java/gpudriver/gl/shader_v2f_c4f_t2f_vert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | 22 | static std::string shader_v2f_c4f_t2f_vert() { 23 | return R"(#version 150 24 | 25 | // Program Uniforms 26 | uniform vec4 State; 27 | uniform mat4 Transform; 28 | uniform vec4 Scalar4[2]; 29 | uniform vec4 Vector[8]; 30 | uniform uint ClipSize; 31 | uniform mat4 Clip[8]; 32 | 33 | // Uniform Accessor Functions 34 | float Time() { return State[0]; } 35 | float ScreenWidth() { return State[1]; } 36 | float ScreenHeight() { return State[2]; } 37 | float ScreenScale() { return State[3]; } 38 | float Scalar(uint i) { if (i < 4u) return Scalar4[0][i]; else return Scalar4[1][i - 4u]; } 39 | vec4 sRGBToLinear(vec4 val) { return vec4(val.xyz * (val.xyz * (val.xyz * 0.305306011 + 0.682171111) + 0.012522878), val.w); } 40 | 41 | // Vertex Attributes 42 | in vec2 in_Position; 43 | in vec4 in_Color; 44 | in vec2 in_TexCoord; 45 | 46 | // Out Params 47 | out vec4 ex_Color; 48 | out vec2 ex_ObjectCoord; 49 | out vec2 ex_ScreenCoord; 50 | 51 | void main(void) 52 | { 53 | ex_ObjectCoord = in_TexCoord; 54 | gl_Position = Transform * vec4(in_Position, 0.0, 1.0); 55 | ex_Color = in_Color; 56 | } 57 | 58 | )"; 59 | } -------------------------------------------------------------------------------- /ultralight-java-gpu-native/src/gpudriver/common/GPUDriverImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/gpudriver/common/GPUDriverImpl.h" 21 | 22 | namespace ultralight { 23 | 24 | GPUDriverImpl::GPUDriverImpl() : batch_count_(0) { 25 | } 26 | 27 | GPUDriverImpl::~GPUDriverImpl() { 28 | } 29 | 30 | bool GPUDriverImpl::HasCommandsPending() { 31 | return !command_list_.empty(); 32 | } 33 | 34 | void GPUDriverImpl::DrawCommandList() { 35 | if(command_list_.empty()) 36 | return; 37 | 38 | batch_count_ = 0; 39 | 40 | for(auto &cmd : command_list_) { 41 | if(cmd.command_type == kCommandType_DrawGeometry) 42 | DrawGeometry(cmd.geometry_id, cmd.indices_count, cmd.indices_offset, cmd.gpu_state); 43 | else if(cmd.command_type == kCommandType_ClearRenderBuffer) 44 | ClearRenderBuffer(cmd.gpu_state.render_buffer_id); 45 | batch_count_++; 46 | } 47 | 48 | command_list_.clear(); 49 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 50 | } 51 | 52 | int GPUDriverImpl::batch_count() const { 53 | return batch_count_; 54 | } 55 | 56 | void GPUDriverImpl::BeginSynchronize() { 57 | } 58 | 59 | void GPUDriverImpl::EndSynchronize() { 60 | } 61 | 62 | uint32_t GPUDriverImpl::NextTextureId() { 63 | return next_texture_id_++; 64 | } 65 | 66 | uint32_t GPUDriverImpl::NextRenderBufferId() { 67 | return next_render_buffer_id_++; 68 | } 69 | 70 | uint32_t GPUDriverImpl::NextGeometryId() { 71 | return next_geometry_id_++; 72 | } 73 | 74 | void GPUDriverImpl::UpdateCommandList(const CommandList &list) { 75 | if(list.size) { 76 | command_list_.resize(list.size); 77 | memcpy(&command_list_[0], list.commands, sizeof(Command) * list.size); 78 | } 79 | } 80 | 81 | } // namespace ultralight -------------------------------------------------------------------------------- /ultralight-java-gpu-native/src/gpudriver/gl/GPUContextGL.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/gpudriver/gl/GPUContextGL.h" 21 | 22 | #include 23 | 24 | #include "ultralight_java/gpudriver/gl/GPUDriverGL.h" 25 | 26 | namespace ultralight { 27 | 28 | GPUContextGL::GPUContextGL(void *window, bool enable_msaa) : msaa_enabled_(enable_msaa) { 29 | 30 | window_ = window; 31 | active_window_ = window_; 32 | // TODO: enable msaa, GLFW currently has num_samples == 0 in glfwWindowHint 33 | int samples = 4; 34 | if(!samples) { 35 | msaa_enabled_ = false; 36 | } 37 | 38 | driver_.reset(new ultralight::GPUDriverGL(this)); 39 | } 40 | 41 | } // namespace ultralight -------------------------------------------------------------------------------- /ultralight-java-gpu/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-library") 3 | id 'maven-publish' 4 | } 5 | 6 | group 'com.labymedia' 7 | 8 | jar { 9 | manifest { 10 | attributes( 11 | 'Automatic-Module-Name': 'com.labymedia.ultralight.gpu' 12 | ) 13 | } 14 | } 15 | 16 | processResources { 17 | if (project.getProperties().get("ultralight-java.gpu.native-binaries-folder") == null) { 18 | dependsOn(':ultralight-java-gpu-native:build') 19 | } 20 | from(rootProject.file(project.getProperties().getOrDefault("ultralight-java.gpu.native-binaries-folder", project(":ultralight-java-gpu-native").buildDir.toPath().toString() + "/nativeBinaries").toString())) { 21 | into "native-binaries" 22 | include("*.dll", "*.so", "*.dylib") 23 | } 24 | } 25 | 26 | commonPublish(project) { 27 | pom { 28 | name = "UltralightGPUJava" 29 | description = "Ultralight native GPU driver for Java" 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation(project(":ultralight-java-base")) 35 | } -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/java_bridges/bridegd_clipboard.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include "ultralight_java/util/jni_reference_wrapper.hpp" 25 | 26 | namespace ultralight_java { 27 | /** 28 | * Bridge for com/labymedia/ultralight/plugin/clipboard/UltralightClipboard to ultralight::Clipboard 29 | */ 30 | class BridgedClipboard : public ultralight::Clipboard, public JNIReferenceWrapper { 31 | public: 32 | /** 33 | * Constructs a new BridgedClipboard wrapping an existing java clipboard. 34 | * 35 | * @param env The JNI environment to use for wrapping the file system 36 | * @param clipboard The clipboard which should be wrapped 37 | */ 38 | explicit BridgedClipboard(JNIEnv *env, jobject clipboard); 39 | 40 | /** 41 | * Clears the clipboard 42 | */ 43 | void Clear() final; 44 | 45 | /** 46 | * Reads the clipboard content as UTF-16. 47 | * 48 | * @return The clipboard content 49 | */ 50 | ultralight::String16 ReadPlainText() final; 51 | 52 | /** 53 | * Writes the specified UTF-16 text into the clipboard. 54 | * 55 | * @param text The text to write into the clipboard 56 | */ 57 | void WritePlainText(const ultralight::String16 &text) final; 58 | }; 59 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/java_bridges/bridged_gpu_driver.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include "ultralight_java/util/jni_reference_wrapper.hpp" 25 | 26 | namespace ultralight_java { 27 | 28 | class BridgedGPUDriver : public ultralight::GPUDriver, JNIReferenceWrapper { 29 | public: 30 | explicit BridgedGPUDriver(JNIEnv *env, jobject gpu_driver); 31 | 32 | void BeginSynchronize() final; 33 | 34 | void EndSynchronize() final; 35 | 36 | uint32_t NextTextureId() final; 37 | 38 | void CreateTexture(uint32_t texture_id, 39 | ultralight::Ref bitmap) final; 40 | 41 | void UpdateTexture(uint32_t texture_id, 42 | ultralight::Ref bitmap) final; 43 | 44 | void DestroyTexture(uint32_t texture_id) final; 45 | 46 | uint32_t NextRenderBufferId() final; 47 | 48 | void CreateRenderBuffer(uint32_t render_buffer_id, 49 | const ultralight::RenderBuffer& buffer) final; 50 | 51 | void DestroyRenderBuffer(uint32_t render_buffer_id) final; 52 | 53 | uint32_t NextGeometryId() final; 54 | 55 | void CreateGeometry(uint32_t geometry_id, 56 | const ultralight::VertexBuffer& vertices, 57 | const ultralight::IndexBuffer& indices) final; 58 | 59 | void UpdateGeometry(uint32_t geometry_id, 60 | const ultralight::VertexBuffer& vertices, 61 | const ultralight::IndexBuffer& indices) final; 62 | 63 | void DestroyGeometry(uint32_t geometry_id) final; 64 | 65 | void UpdateCommandList(const ultralight::CommandList& list) final; 66 | 67 | }; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/java_bridges/bridged_logger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include "ultralight_java/util/jni_reference_wrapper.hpp" 25 | 26 | namespace ultralight_java { 27 | /** 28 | * Bridge for com/labymedia/ultralight/plugin/logging/Logger to ultralight::Logger 29 | */ 30 | class BridgedLogger : public ultralight::Logger, public JNIReferenceWrapper { 31 | public: 32 | /** 33 | * Creates a new BridgedLogger using a JNI environment and a java instance. 34 | * 35 | * @param env The environment to use for referencing the logger 36 | * @param logger The java instance of the logger 37 | */ 38 | explicit BridgedLogger(JNIEnv *env, jobject logger); 39 | 40 | /** 41 | * Called when the library wants to print a message to the log. 42 | * 43 | * @param log_level The level of the message that should be printed 44 | * @param message The message that should be printed 45 | */ 46 | void LogMessage(ultralight::LogLevel log_level, const ultralight::String16 &message) final; 47 | }; 48 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/java_bridges/javascript_class_jni.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include "ultralight_java/platform/managed_javascript_class.hpp" 24 | 25 | namespace ultralight_java { 26 | /** 27 | * Class for interfacing with JSClassRef from java 28 | */ 29 | class JavascriptClassJNI { 30 | public: 31 | /** 32 | * Releases the data. 33 | * NOTE: This function is currently a NO-OP, because JavascriptCore does not properly track references, 34 | * and us freeing them would cause crashes! 35 | * 36 | * @param env The JNI environment to use for accessing java 37 | * @param caller_class The java class calling the method, should always be JavascriptClass 38 | * @param handle The handle of the JSClassRef to release 39 | */ 40 | static void release(JNIEnv *env, jclass caller_class, jlong handle); 41 | }; 42 | } -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/java_bridges/javascript_global_context_jni.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace ultralight_java { 25 | /** 26 | * Class for interfacing with JSGlobalContextRef from java. 27 | */ 28 | class JavascriptGlobalContextJNI { 29 | public: 30 | /** 31 | * Releases the underlying JSContextRef instance. 32 | * 33 | * @param env The JNI environment to use for accessing java 34 | * @param java_instance The java instance of this global context 35 | */ 36 | static void context_unlocking(JNIEnv *env, jobject java_instance); 37 | 38 | /** 39 | * Retrieves the name of this context. 40 | * 41 | * @param env The JNI environment to use for accessing java 42 | * @param java_instance The java instance of this global context 43 | * @return The name of this global context as a java string 44 | */ 45 | static jstring get_name(JNIEnv *env, jobject java_instance); 46 | 47 | /** 48 | * Sets the name of this context. 49 | * 50 | * @param env The JNI environment to use for accessing java 51 | * @param java_instance The java instance of this global context 52 | * @param java_name The new name of this context 53 | */ 54 | static void set_name(JNIEnv *env, jobject java_instance, jstring java_name); 55 | }; 56 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/java_bridges/proxied_java_exception.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #include "ultralight_java/util/jni_reference_wrapper.hpp" 26 | 27 | namespace ultralight_java { 28 | /** 29 | * C++ exception for a caught java exception. 30 | */ 31 | class ProxiedJavaException : public std::exception { 32 | private: 33 | // The thrown object 34 | JNIReferenceWrapper thrown; 35 | 36 | /** 37 | * Constructs a new ProxiedJavaException with the given underlying throwable. 38 | * 39 | * @param thrown The thrown throwable 40 | */ 41 | explicit ProxiedJavaException(JNIReferenceWrapper thrown); 42 | 43 | public: 44 | /** 45 | * Constructs a JavaProxiedException from the exception in the current JNI environment. 46 | * This method removes the exception from the environment. If there is no active exception, 47 | * then this is a no-op. 48 | * 49 | * @param env The environment to obtain the exception from 50 | * @throws ProxiedJavaException The currently active java exception 51 | */ 52 | static void throw_if_any(JNIEnv *env); 53 | 54 | ProxiedJavaException(const ProxiedJavaException &other) = delete; 55 | 56 | /** 57 | * Throws this exception back to Java and clears the throwable. 58 | * 59 | * @param env The environment to throw the exception in 60 | */ 61 | void throw_to_java(JNIEnv *env); 62 | }; 63 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/java_bridges/ultralight_bitmap_surface_jni.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace ultralight_java { 25 | /** 26 | * Class for interfacing with ultralight::BitmapSurface from java. 27 | */ 28 | class UltralightBitmapSurfaceJNI { 29 | public: 30 | /** 31 | * Retrieves the underlying Bitmap from this Bitmap surface. 32 | * 33 | * @param env The JNI environment to use for accessing java 34 | * @param instance The java instance of the Bitmap surface 35 | * @return The underlying Bitmap from this surface 36 | */ 37 | static jobject bitmap(JNIEnv *env, jobject instance); 38 | }; 39 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/java_bridges/ultralight_key_event_jni.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include 25 | 26 | namespace ultralight_java { 27 | /** 28 | * Class for interfacing with ultralight::KeyEvent from java. 29 | */ 30 | class UltralightKeyEventJNI { 31 | public: 32 | /** 33 | * Retrieves a key identifier from a virtual key code. 34 | * 35 | * @param env The JNI environment to use for accessing java 36 | * @param caller_class The class calling this method, should always be UltralightKeyEvent 37 | * @param virtual_key_code The virtual key code to convert 38 | * @return The identifier as a jstring 39 | */ 40 | static jstring get_key_identifier_from_virtual_key_code(JNIEnv *env, jclass caller_class, jobject virtual_key_code); 41 | }; 42 | } -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/ultralight_initializer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace ultralight_java { 23 | /** 24 | * Initialize the global runtime struct 25 | */ 26 | void init_runtime_struct(); 27 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/util/jni_reference_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace ultralight_java { 25 | /** 26 | * Wrapper for JNI references with auto deletion 27 | */ 28 | class JNIReferenceWrapper { 29 | protected: 30 | jobject reference; 31 | 32 | public: 33 | // Delete copy constructor and copy assignment operator 34 | JNIReferenceWrapper(const JNIReferenceWrapper &other) = delete; 35 | 36 | JNIReferenceWrapper &operator=(const JNIReferenceWrapper &other) = delete; 37 | 38 | // Implement move constructor, but delete move assignment operator 39 | JNIReferenceWrapper(JNIReferenceWrapper &&other) noexcept; 40 | 41 | JNIReferenceWrapper &operator=(JNIReferenceWrapper &&other) = delete; 42 | 43 | /** 44 | * Constructs a new JNIReferenceWrapper wrapping a jobject. 45 | * 46 | * @param env The environment to use for wrapping the reference 47 | * @param reference The reference to wrap, a global ref will be created for it 48 | */ 49 | explicit JNIReferenceWrapper(JNIEnv *env, jobject reference); 50 | 51 | /** 52 | * Destructs the JNIReferenceWrapper and deletes the underlying reference. 53 | */ 54 | virtual ~JNIReferenceWrapper(); 55 | 56 | /** 57 | * Retrieves the wrapped reference. 58 | * 59 | * @return The wrapped reference 60 | */ 61 | operator jobject(); 62 | 63 | /** 64 | * Retrieves the wrapped reference. 65 | * 66 | * @return The wrapped reference 67 | */ 68 | jobject operator*(); 69 | 70 | /** 71 | * Retrieves the wrapped reference. 72 | * 73 | * @return The wrapped reference 74 | */ 75 | jobject get(); 76 | }; 77 | } -------------------------------------------------------------------------------- /ultralight-java-native/include/ultralight_java/util/temporary_jni.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace ultralight_java { 25 | /** 26 | * Helper for obtaining a JNI environment for a limited amount of time. 27 | */ 28 | class TemporaryJNI { 29 | private: 30 | // The stored environment 31 | JNIEnv *env; 32 | bool detach_on_destruct; 33 | 34 | public: 35 | /** 36 | * Constructs a new TemporaryJNI environment and attaches it to the JVM 37 | * if required. 38 | */ 39 | explicit TemporaryJNI(); 40 | 41 | /** 42 | * Destructs the temporary JNI environment, detaches it from the JVM 43 | * if it has been attached by the constructor. 44 | */ 45 | ~TemporaryJNI(); 46 | 47 | /** 48 | * Retrieves the JNI environment contained by this temporary environment. 49 | * 50 | * @return The contained JNI environment 51 | */ 52 | operator JNIEnv *(); 53 | 54 | /** 55 | * Retrieves the JNI environment contained by this temporary environment. 56 | * 57 | * @return The contained JNI environment 58 | */ 59 | JNIEnv *operator*(); 60 | 61 | /** 62 | * Retrieves the JNI environment contained by this temporary environment. 63 | * 64 | * @return The contained JNI environment 65 | */ 66 | JNIEnv *operator->(); 67 | }; 68 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/java_bridges/bridged_clipboard.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/java_bridges/bridegd_clipboard.hpp" 21 | #include "ultralight_java/java_bridges/proxied_java_exception.hpp" 22 | #include "ultralight_java/ultralight_java_instance.hpp" 23 | #include "ultralight_java/util/temporary_jni.hpp" 24 | #include "ultralight_java/util/util.hpp" 25 | 26 | namespace ultralight_java { 27 | BridgedClipboard::BridgedClipboard(JNIEnv *env, jobject clipboard) : JNIReferenceWrapper(env, clipboard) { 28 | } 29 | 30 | void BridgedClipboard::Clear() { 31 | TemporaryJNI env; 32 | 33 | env->CallVoidMethod(reference, runtime.ultralight_clipboard.clear_method); 34 | ProxiedJavaException::throw_if_any(env); 35 | } 36 | 37 | ultralight::String16 BridgedClipboard::ReadPlainText() { 38 | TemporaryJNI env; 39 | 40 | auto java_clipboard_content = reinterpret_cast( 41 | env->CallObjectMethod(reference, runtime.ultralight_clipboard.read_plain_text_method)); 42 | ProxiedJavaException::throw_if_any(env); 43 | 44 | if(!java_clipboard_content) { 45 | return ultralight::String16(); 46 | } 47 | 48 | auto clipboard_content = Util::create_utf16_from_jstring(env, java_clipboard_content); 49 | ProxiedJavaException::throw_if_any(env); 50 | 51 | return clipboard_content; 52 | } 53 | 54 | void BridgedClipboard::WritePlainText(const ultralight::String16 &text) { 55 | TemporaryJNI env; 56 | 57 | auto java_text = Util::create_jstring_from_utf16(env, text); 58 | ProxiedJavaException::throw_if_any(env); 59 | 60 | env->CallVoidMethod(reference, runtime.ultralight_clipboard.write_plain_text_method, java_text); 61 | ProxiedJavaException::throw_if_any(env); 62 | } 63 | 64 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/java_bridges/bridged_logger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/java_bridges/bridged_logger.hpp" 21 | 22 | #include "ultralight_java/java_bridges/proxied_java_exception.hpp" 23 | #include "ultralight_java/ultralight_java_instance.hpp" 24 | #include "ultralight_java/util/temporary_jni.hpp" 25 | #include "ultralight_java/util/util.hpp" 26 | 27 | namespace ultralight_java { 28 | BridgedLogger::BridgedLogger(JNIEnv *env, jobject logger) : JNIReferenceWrapper(env, logger) { 29 | } 30 | 31 | void BridgedLogger::LogMessage(ultralight::LogLevel log_level, const ultralight::String16 &message) { 32 | TemporaryJNI env; 33 | 34 | // Convert the level 35 | jobject java_log_level = runtime.log_level.constants.to_java(env, log_level); 36 | 37 | // Convert the message 38 | jstring java_message = Util::create_jstring_from_utf16(env, message); 39 | 40 | // Invoke the logMessage method 41 | env->CallVoidMethod(reference, runtime.logger.log_message_method, java_log_level, java_message); 42 | 43 | // Clean up the references 44 | env->DeleteLocalRef(java_message); 45 | env->DeleteLocalRef(java_log_level); 46 | 47 | // Possibly throw exception if one occurred 48 | ProxiedJavaException::throw_if_any(env); 49 | } 50 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/java_bridges/javascript_class_jni.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/java_bridges/javascript_class_jni.hpp" 21 | 22 | #include "JavaScriptCore/JavaScript.h" 23 | 24 | namespace ultralight_java { 25 | void JavascriptClassJNI::release(JNIEnv *, jclass, jlong handle) { 26 | // TODO: Actually release when callback is implemented in Javascript engine 27 | } 28 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/java_bridges/proxied_java_exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/java_bridges/proxied_java_exception.hpp" 21 | 22 | namespace ultralight_java { 23 | ProxiedJavaException::ProxiedJavaException(JNIReferenceWrapper thrown) : thrown(std::move(thrown)) { 24 | } 25 | 26 | void ProxiedJavaException::throw_if_any(JNIEnv *env) { 27 | if(!env->ExceptionCheck()) { 28 | // Can't throw anything 29 | return; 30 | } else { 31 | // Retrieve the current exception and remove it from the environment 32 | jthrowable thrown = env->ExceptionOccurred(); 33 | env->ExceptionClear(); 34 | 35 | // Create a proxied exception and throw it 36 | throw ProxiedJavaException(JNIReferenceWrapper(env, thrown)); 37 | } 38 | } 39 | 40 | void ProxiedJavaException::throw_to_java(JNIEnv *env) { 41 | env->Throw(reinterpret_cast(*thrown)); 42 | } 43 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/java_bridges/ultralight_bitmap_surface_jni.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/java_bridges/ultralight_bitmap_surface_jni.hpp" 21 | 22 | #include "ultralight_java/java_bridges/ultralight_ref_ptr_jni.hpp" 23 | #include "ultralight_java/ultralight_java_instance.hpp" 24 | 25 | namespace ultralight_java { 26 | jobject UltralightBitmapSurfaceJNI::bitmap(JNIEnv *env, jobject instance) { 27 | auto *surface = reinterpret_cast( 28 | env->CallLongMethod(instance, runtime.object_with_handle.get_handle_method)); 29 | if(env->ExceptionCheck()) { 30 | return nullptr; 31 | } 32 | 33 | auto bitmap = surface->bitmap(); 34 | return env->NewObject( 35 | runtime.ultralight_bitmap.clazz, 36 | runtime.ultralight_bitmap.constructor, 37 | UltralightRefPtrJNI::create< 38 | ultralight::Bitmap>(env, std::move(ultralight::RefPtr(std::move(bitmap))))); 39 | } 40 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/java_bridges/ultralight_key_event_jni.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/java_bridges/ultralight_key_event_jni.hpp" 21 | 22 | #include "ultralight_java/ultralight_java_instance.hpp" 23 | #include "ultralight_java/util/util.hpp" 24 | 25 | namespace ultralight_java { 26 | jstring UltralightKeyEventJNI::get_key_identifier_from_virtual_key_code( 27 | JNIEnv *env, jclass caller_class, jobject virtual_key_code) { 28 | ultralight::String identifier; 29 | 30 | if(!virtual_key_code) { 31 | ultralight::GetKeyIdentifierFromVirtualKeyCode(0, identifier); 32 | } else { 33 | ultralight::GetKeyIdentifierFromVirtualKeyCode( 34 | env->GetIntField(virtual_key_code, runtime.ultralight_key.id_field), identifier); 35 | } 36 | 37 | return Util::create_jstring_from_utf16(env, identifier.utf16()); 38 | } 39 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/java_bridges/ultralight_matrix4x4_jni.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/java_bridges/ultralight_matrix4x4_jni.hpp" 21 | 22 | #include "ultralight_java/java_bridges/ultralight_ref_ptr_jni.hpp" 23 | #include "ultralight_java/util/util.hpp" 24 | 25 | namespace ultralight_java { 26 | jobject UltralightMatrix4x4JNI::create(JNIEnv *env, ultralight::Matrix4x4 matrix) { 27 | return env->NewObject( 28 | runtime.ultralight_matrix4x4.clazz, 29 | runtime.ultralight_matrix4x4.constructor, 30 | new ultralight::Matrix4x4(matrix)); 31 | } 32 | 33 | jlong UltralightMatrix4x4JNI::construct(JNIEnv *, jclass) { 34 | return reinterpret_cast(new ultralight::Matrix4x4()); 35 | } 36 | 37 | jfloatArray UltralightMatrix4x4JNI::get_data(JNIEnv *env, jobject instance) { 38 | auto *matrix4x4 = reinterpret_cast( 39 | env->CallLongMethod(instance, runtime.object_with_handle.get_handle_method)); 40 | return Util::create_float_array(env, 16, matrix4x4->data); 41 | } 42 | 43 | void UltralightMatrix4x4JNI::set_identity(JNIEnv *env, jobject instance) { 44 | auto *matrix4x4 = reinterpret_cast( 45 | env->CallLongMethod(instance, runtime.object_with_handle.get_handle_method)); 46 | matrix4x4->SetIdentity(); 47 | } 48 | 49 | void UltralightMatrix4x4JNI::_delete(JNIEnv *, jclass, jlong handle) { 50 | delete reinterpret_cast(handle); 51 | } 52 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/java_bridges/ultralight_ref_ptr_jni.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/java_bridges/ultralight_ref_ptr_jni.hpp" 21 | 22 | namespace ultralight_java { 23 | void UltralightRefPtrJNI::_delete(JNIEnv *, jclass, jlong handle) { 24 | // Get back the wrapper 25 | auto *ptr = reinterpret_cast(handle); 26 | 27 | // Invoke the deleter to delete the wrapped pointer and 28 | // then delete the wrapper itself 29 | ptr->deleter(ptr->ptr_value); 30 | delete ptr; 31 | } 32 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/util/jni_reference_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/util/jni_reference_wrapper.hpp" 21 | 22 | #include "ultralight_java/util/temporary_jni.hpp" 23 | 24 | namespace ultralight_java { 25 | JNIReferenceWrapper::JNIReferenceWrapper(JNIReferenceWrapper &&other) noexcept : reference(other.reference) { 26 | other.reference = nullptr; 27 | } 28 | 29 | JNIReferenceWrapper::JNIReferenceWrapper(JNIEnv *env, jobject reference) : reference(env->NewGlobalRef(reference)) { 30 | } 31 | 32 | JNIReferenceWrapper::~JNIReferenceWrapper() { 33 | if(reference) { 34 | TemporaryJNI jni; 35 | jni->DeleteGlobalRef(reference); 36 | } 37 | } 38 | 39 | JNIReferenceWrapper::operator jobject() { 40 | return reference; 41 | } 42 | 43 | jobject JNIReferenceWrapper::operator*() { 44 | return reference; 45 | } 46 | 47 | jobject JNIReferenceWrapper::get() { 48 | return reference; 49 | } 50 | } // namespace ultralight_java -------------------------------------------------------------------------------- /ultralight-java-native/src/util/temporary_jni.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultralight Java - Java wrapper for the Ultralight web engine 3 | * Copyright (C) 2021 LabyMedia and contributors 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 3 of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ultralight_java/util/temporary_jni.hpp" 21 | 22 | #include "ultralight_java/ultralight_java_instance.hpp" 23 | 24 | namespace ultralight_java { 25 | TemporaryJNI::TemporaryJNI() { 26 | // Try to get a JNI environment 27 | int error = runtime.vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_8); 28 | if(error == JNI_EDETACHED) { 29 | // The current thread is detached, attach it and obtain the JNI environment 30 | // using the attach function 31 | runtime.vm->AttachCurrentThread(reinterpret_cast(&env), nullptr); 32 | detach_on_destruct = true; 33 | } else { 34 | detach_on_destruct = false; 35 | } 36 | } 37 | 38 | TemporaryJNI::~TemporaryJNI() { 39 | if(detach_on_destruct) { 40 | // The detach flag is set, detach the thread now 41 | runtime.vm->DetachCurrentThread(); 42 | } 43 | } 44 | 45 | TemporaryJNI::operator JNIEnv *() { 46 | return env; 47 | } 48 | 49 | JNIEnv *TemporaryJNI::operator*() { 50 | return env; 51 | } 52 | 53 | JNIEnv *TemporaryJNI::operator->() { 54 | return env; 55 | } 56 | } // namespace ultralight_java -------------------------------------------------------------------------------- /version.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.taskdefs.condition.Os 2 | 3 | def versionFromFile = file("VERSION").text.trim() 4 | 5 | static String getGithubVar(String name) { 6 | return System.getenv("GITHUB_${name}") 7 | } 8 | 9 | static boolean isWindows() { 10 | return Os.isFamily(Os.FAMILY_WINDOWS) 11 | } 12 | 13 | File getGitExecutable() { 14 | String gitExe = isWindows() ? "git.exe" : "git" 15 | return System.getenv("PATH")?.split(File.pathSeparator)?.collect { file("${it}/${gitExe}") }?.find { it.canExecute() } 16 | } 17 | 18 | String getBranchName() { 19 | File gitExe = getGitExecutable() 20 | 21 | if (gitExe == null) { 22 | logger.warn("Git not found on path") 23 | return "unknown" 24 | } 25 | 26 | return new ByteArrayOutputStream().withStream { out -> 27 | String githubActionsRef = getGithubVar("REF") 28 | if (githubActionsRef != null) { 29 | return githubActionsRef.trim().substring(11).replace('/', '_') 30 | } 31 | 32 | exec { 33 | executable gitExe 34 | workingDir rootDir 35 | args "rev-parse", "--abbrev-ref", "HEAD" 36 | standardOutput out 37 | } 38 | 39 | return out.toString("UTF-8").trim() 40 | } 41 | } 42 | 43 | String getCommit() { 44 | File gitExe = getGitExecutable() 45 | 46 | if (gitExe == null) { 47 | logger.warn("Git not found on path") 48 | return "unknown" 49 | } 50 | 51 | return new ByteArrayOutputStream().withStream { out -> 52 | exec { 53 | executable gitExe 54 | workingDir rootDir 55 | args "rev-parse", "--short", "HEAD" 56 | standardOutput out 57 | } 58 | 59 | return out.toString("UTF-8").trim() 60 | } 61 | } 62 | 63 | 64 | String branchName = getBranchName() 65 | switch (branchName) { 66 | case "master": 67 | version = versionFromFile 68 | break 69 | 70 | case "develop": 71 | version = "${versionFromFile}-SNAPSHOT" 72 | break 73 | 74 | default: 75 | version = "${versionFromFile}-${getCommit()}-UNSTABLE" 76 | break 77 | } 78 | --------------------------------------------------------------------------------