Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 3e0fcc1

Browse files
committed
Clean up native code
1 parent 535c481 commit 3e0fcc1

File tree

10 files changed

+174
-85
lines changed

10 files changed

+174
-85
lines changed

example/lwjgl3-opengl/src/main/java/com/labymedia/ultralight/lwjgl3/opengl/GPUDriverGL.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
3737
*/
3838

39-
import com.labymedia.ultralight.UltralightMatrix;
40-
import com.labymedia.ultralight.UltralightMatrix4x4;
39+
import com.labymedia.ultralight.math.UltralightMatrix;
40+
import com.labymedia.ultralight.math.UltralightMatrix4x4;
4141
import com.labymedia.ultralight.bitmap.UltralightBitmap;
4242
import com.labymedia.ultralight.bitmap.UltralightBitmapFormat;
4343
import com.labymedia.ultralight.math.IntRect;
@@ -63,7 +63,6 @@
6363
import static org.lwjgl.opengl.GL30.*;
6464
import static org.lwjgl.opengl.GL32.GL_TEXTURE_2D_MULTISAMPLE;
6565
import static org.lwjgl.opengl.GL32.glTexImage2DMultisample;
66-
import static org.lwjgl.opengl.GL43.GL_DEBUG_OUTPUT_SYNCHRONOUS;
6766
import static org.lwjgl.opengl.GLUtil.setupDebugMessageCallback;
6867

6968
public class GPUDriverGL implements UltralightGPUDriver {

ultralight-java-base/src/main/java/com/labymedia/ultralight/UltralightMatrix.java renamed to ultralight-java-base/src/main/java/com/labymedia/ultralight/math/UltralightMatrix.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight;
20+
package com.labymedia.ultralight.math;
2121

2222
import com.labymedia.ultralight.annotation.NativeCall;
2323
import com.labymedia.ultralight.annotation.NativeType;
24-
import com.labymedia.ultralight.bitmap.UltralightBitmap;
2524
import com.labymedia.ultralight.ffi.ObjectWithHandle;
2625
import com.labymedia.ultralight.ffi.gc.DeletableObject;
2726

28-
import java.lang.annotation.Native;
29-
import java.nio.ByteBuffer;
30-
3127
@NativeType("ultralight::Matrix")
3228
public class UltralightMatrix implements ObjectWithHandle {
3329
private final DeletableObject<Long> handle;
@@ -42,10 +38,14 @@ public UltralightMatrix() {
4238
}
4339

4440
public native void set(
45-
@NativeType("double") double m11, @NativeType("double") double m12, @NativeType("double") double m13, @NativeType("double") double m14,
46-
@NativeType("double") double m21, @NativeType("double") double m22, @NativeType("double") double m23, @NativeType("double") double m24,
47-
@NativeType("double") double m31, @NativeType("double") double m32, @NativeType("double") double m33, @NativeType("double") double m34,
48-
@NativeType("double") double m41, @NativeType("double") double m42, @NativeType("double") double m43, @NativeType("double") double m44
41+
@NativeType("double") double m11, @NativeType("double") double m12, @NativeType(
42+
"double") double m13, @NativeType("double") double m14,
43+
@NativeType("double") double m21, @NativeType("double") double m22, @NativeType(
44+
"double") double m23, @NativeType("double") double m24,
45+
@NativeType("double") double m31, @NativeType("double") double m32, @NativeType(
46+
"double") double m33, @NativeType("double") double m34,
47+
@NativeType("double") double m41, @NativeType("double") double m42, @NativeType(
48+
"double") double m43, @NativeType("double") double m44
4949
);
5050

5151
public native void set(UltralightMatrix4x4 ultralightMatrix4x4);
@@ -60,7 +60,8 @@ public long getHandle() {
6060
return handle.get();
6161
}
6262

63-
public native void setOrthographicProjection(@NativeType("double") double screenWidth, @NativeType("double") double screenHeight, @NativeType("bool") boolean flipY);
63+
public native void setOrthographicProjection(@NativeType("double") double screenWidth, @NativeType(
64+
"double") double screenHeight, @NativeType("bool") boolean flipY);
6465

6566
public native void transform(UltralightMatrix transformMat);
6667

ultralight-java-base/src/main/java/com/labymedia/ultralight/UltralightMatrix4x4.java renamed to ultralight-java-base/src/main/java/com/labymedia/ultralight/math/UltralightMatrix4x4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

20-
package com.labymedia.ultralight;
20+
package com.labymedia.ultralight.math;
2121

2222
import com.labymedia.ultralight.annotation.NativeCall;
2323
import com.labymedia.ultralight.annotation.NativeType;

ultralight-java-base/src/main/java/com/labymedia/ultralight/plugin/render/UltralightGPUState.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@
1919

2020
package com.labymedia.ultralight.plugin.render;
2121

22-
import com.labymedia.ultralight.UltralightMatrix;
23-
import com.labymedia.ultralight.UltralightMatrix4x4;
22+
import com.labymedia.ultralight.math.UltralightMatrix4x4;
2423
import com.labymedia.ultralight.annotation.NativeType;
2524
import com.labymedia.ultralight.math.IntRect;
2625
import com.labymedia.ultralight.math.Vec4;
2726

28-
import java.nio.ByteBuffer;
29-
3027
@NativeType("ultralight::GPUState")
3128
public class UltralightGPUState {
3229
public final @NativeType("uint32_t")

ultralight-java-native/src/main/c/include/ultralight_java/java_bridges/ultralight_matrix4x4_jni.hpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,48 @@
2525
namespace ultralight_java {
2626
class UltralightMatrix4x4JNI {
2727
public:
28-
///
29-
/// Raw 4x4 matrix as an array
30-
///
31-
static jfloatArray get_data(JNIEnv *env, jobject instance);
32-
///
33-
/// Set to identity matrix.
34-
///
35-
static void set_identity(JNIEnv *env, jobject instance);
28+
/**
29+
* Creates a new java object wrapping an existing Ultralight 4x4 matrix.
30+
*
31+
* @param env The JNI environment to use for accessing java
32+
* @param matrix The matrix to wrap
33+
* @return The created java object
34+
*/
3635
static jobject create(JNIEnv *env, ultralight::Matrix4x4 matrix);
36+
37+
/**
38+
* Constructs a new Ultralight matrix pointer from java.
39+
*
40+
* @param env The JNI environment to use for accessing java
41+
* @param caller_class The class that called the method
42+
* @return The constructed matrix as a pointer
43+
*/
3744
static jlong construct(JNIEnv *env, jclass caller_class);
45+
46+
/**
47+
* Retrieves the data of the matrix as a float array.
48+
*
49+
* @param env The JNI environment to use for accessing java
50+
* @param instance The java instance of the Matrix
51+
* @return The data of this matrix as a java float array
52+
*/
53+
static jfloatArray get_data(JNIEnv *env, jobject instance);
54+
55+
/**
56+
* Sets this matrix as an identity matrix.
57+
*
58+
* @param env The JNI environment to use for accessing java
59+
* @param instance The java instance of the Matrix
60+
*/
61+
static void set_identity(JNIEnv *env, jobject instance);
62+
63+
/**
64+
* Deletes the underlying pointer of the wrapper Matrix object.
65+
*
66+
* @param env The JNI environment to use for accessing java
67+
* @param instance The java instance of the Matrix
68+
* @param handle A pointer to the Matrix object to delete
69+
*/
3870
static void _delete(JNIEnv *env, jclass caller_class, jlong handle);
3971
};
4072
} // namespace ultralight_java

ultralight-java-native/src/main/c/include/ultralight_java/java_bridges/ultralight_matrix_jni.hpp

Lines changed: 81 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,55 @@
2525
namespace ultralight_java {
2626
class UltralightMatrixJNI {
2727
public:
28-
///
29-
/// Set to another matrix.
30-
///
28+
/**
29+
* Creates a new java object wrapping an existing Ultralight matrix.
30+
*
31+
* @param env The JNI environment to use for accessing java
32+
* @param matrix The matrix to wrap
33+
* @return The created java object
34+
*/
35+
static jobject create(JNIEnv *env, ultralight::Matrix matrix);
36+
37+
/**
38+
* Constructs a new Ultralight matrix pointer from java.
39+
*
40+
* @param env The JNI environment to use for accessing java
41+
* @param caller_class The class that called the method
42+
* @return The constructed matrix as a pointer
43+
*/
44+
static jlong construct(JNIEnv *env, jclass caller_class);
45+
46+
/**
47+
* Mutates the matrix by copying from a 4x4 matrix.
48+
*
49+
* @param env The JNI environment to use for accessing java
50+
* @param instance The java instance of the Matrix
51+
* @param matrix4x4 The java 4x4 matrix to copy from
52+
*/
3153
static void set1(JNIEnv *env, jobject instance, jobject matrix4x4);
3254

33-
///
34-
/// Set from raw 4x4 components.
35-
///
55+
/**
56+
* Mutates the matrix by setting its values.
57+
*
58+
* @param env The JNI environment to use for accessing java
59+
* @param instance The java instance of the Matrix
60+
* @param m11 The value at row 1, column 1
61+
* @param m12 The value at row 1, column 2
62+
* @param m13 The value at row 1, column 3
63+
* @param m14 The value at row 1, column 4
64+
* @param m21 The value at row 2, column 1
65+
* @param m22 The value at row 2, column 2
66+
* @param m23 The value at row 2, column 3
67+
* @param m24 The value at row 2, column 4
68+
* @param m31 The value at row 3, column 1
69+
* @param m32 The value at row 3, column 2
70+
* @param m33 The value at row 3, column 3
71+
* @param m34 The value at row 3, column 4
72+
* @param m41 The value at row 4, column 1
73+
* @param m42 The value at row 4, column 2
74+
* @param m43 The value at row 4, column 3
75+
* @param m44 The value at row 4, column 4
76+
*/
3677
static void set(
3778
JNIEnv *env,
3879
jobject instance,
@@ -53,28 +94,43 @@ namespace ultralight_java {
5394
jdouble m43,
5495
jdouble m44);
5596

56-
///
57-
/// Get this matrix as unaligned 4x4 float components (for use passing to
58-
/// GPU driver APIs).
59-
///
60-
static jobject getMatrix4x4(JNIEnv *env, jobject instance);
97+
/**
98+
* Retrieves this matrix as a 4x4 matrix.
99+
*
100+
* @param env The JNI environment to use for accessing java
101+
* @param instance The java instance of the Matrix
102+
* @return The java instance of the created 4x4 matrix
103+
*/
104+
static jobject get_matrix_4x4(JNIEnv *env, jobject instance);
61105

62-
///
63-
/// Set to an orthographic projection matrix suitable for use with our
64-
/// vertex shaders. Optionally flip the y-coordinate space (eg, for OpenGL).
65-
///
66-
static void setOrthographicProjection(
67-
JNIEnv *env, jobject instance, jdouble width, jdouble height, jboolean flipY);
106+
/**
107+
* Mutates this matrix for orthographic projection.
108+
*
109+
* @param env The JNI environment to use for accessing java
110+
* @param instance The java instance of the Matrix
111+
* @param width The width of the projection
112+
* @param height The height of the projection
113+
* @param flip_y Whether the Y axis should be flipped
114+
*/
115+
static void set_orthographic_projection(
116+
JNIEnv *env, jobject instance, jdouble width, jdouble height, jboolean flip_y);
68117

69-
///
70-
/// Transform (multiply) by another Matrix
71-
///
72-
static void transform(JNIEnv *env, jobject instance, jobject transformMatrix);
73-
74-
static jobject create(JNIEnv *env, ultralight::Matrix matrix);
75-
76-
static jlong construct(JNIEnv *env, jclass caller_class);
118+
/**
119+
* Transforms this matrix with another matrix.
120+
*
121+
* @param env The JNI environment to use for accessing java
122+
* @param instance The java instance of the Matrix
123+
* @param transform_matrix The matrix to transform with
124+
*/
125+
static void transform(JNIEnv *env, jobject instance, jobject transform_matrix);
77126

127+
/**
128+
* Deletes the underlying pointer of the wrapper Matrix object.
129+
*
130+
* @param env The JNI environment to use for accessing java
131+
* @param instance The java instance of the Matrix
132+
* @param handle A pointer to the Matrix object to delete
133+
*/
78134
static void _delete(JNIEnv *env, jclass caller_class, jlong handle);
79135
};
80136
} // namespace ultralight_java

ultralight-java-native/src/main/c/src/java_bridges/ultralight_matrix4x4_jni.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
#include "ultralight_java/util/util.hpp"
2424

2525
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<jlong>(new ultralight::Matrix4x4());
35+
}
36+
2637
jfloatArray UltralightMatrix4x4JNI::get_data(JNIEnv *env, jobject instance) {
2738
auto *matrix4x4 = reinterpret_cast<ultralight::Matrix4x4 *>(
2839
env->CallLongMethod(instance, runtime.object_with_handle.get_handle_method));
@@ -35,18 +46,7 @@ namespace ultralight_java {
3546
matrix4x4->SetIdentity();
3647
}
3748

38-
jobject UltralightMatrix4x4JNI::create(JNIEnv *env, ultralight::Matrix4x4 matrix) {
39-
return env->NewObject(
40-
runtime.ultralight_matrix4x4.clazz,
41-
runtime.ultralight_matrix4x4.constructor,
42-
new ultralight::Matrix4x4(matrix));
43-
}
44-
45-
jlong UltralightMatrix4x4JNI::construct(JNIEnv *env, jclass caller_class) {
46-
return reinterpret_cast<jlong>(new ultralight::Matrix4x4());
47-
}
48-
void UltralightMatrix4x4JNI::_delete(JNIEnv *env, jclass caller_class, jlong handle) {
49+
void UltralightMatrix4x4JNI::_delete(JNIEnv *, jclass, jlong handle) {
4950
delete reinterpret_cast<ultralight::Matrix4x4 *>(handle);
5051
}
51-
5252
} // namespace ultralight_java

ultralight-java-native/src/main/c/src/java_bridges/ultralight_matrix_jni.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
#include "ultralight_java/ultralight_java_instance.hpp"
2424

2525
namespace ultralight_java {
26+
jobject UltralightMatrixJNI::create(JNIEnv *env, ultralight::Matrix matrix) {
27+
return env->NewObject(
28+
runtime.ultralight_matrix.clazz, runtime.ultralight_matrix.constructor, new ultralight::Matrix(matrix));
29+
}
30+
31+
jlong UltralightMatrixJNI::construct(JNIEnv *, jclass) {
32+
return reinterpret_cast<jlong>(new ultralight::Matrix());
33+
}
34+
2635
void UltralightMatrixJNI::set1(JNIEnv *env, jobject instance, jobject target) {
2736
auto *matrix = reinterpret_cast<ultralight::Matrix *>(
2837
env->CallLongMethod(instance, runtime.object_with_handle.get_handle_method));
@@ -58,35 +67,30 @@ namespace ultralight_java {
5867
matrix->Set(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44);
5968
}
6069

61-
void UltralightMatrixJNI::setOrthographicProjection(
62-
JNIEnv *env, jobject instance, jdouble width, jdouble height, jboolean flipY) {
70+
void UltralightMatrixJNI::set_orthographic_projection(
71+
JNIEnv *env, jobject instance, jdouble width, jdouble height, jboolean flip_y) {
6372
auto *matrix = reinterpret_cast<ultralight::Matrix *>(
6473
env->CallLongMethod(instance, runtime.object_with_handle.get_handle_method));
6574

66-
matrix->SetOrthographicProjection(width, height, flipY);
75+
matrix->SetOrthographicProjection(width, height, flip_y);
6776
}
6877

69-
jobject UltralightMatrixJNI::getMatrix4x4(JNIEnv *env, jobject instance) {
78+
jobject UltralightMatrixJNI::get_matrix_4x4(JNIEnv *env, jobject instance) {
7079
auto *matrix = reinterpret_cast<ultralight::Matrix *>(
7180
env->CallLongMethod(instance, runtime.object_with_handle.get_handle_method));
7281
return UltralightMatrix4x4JNI::create(env, matrix->GetMatrix4x4());
7382
}
74-
void UltralightMatrixJNI::transform(JNIEnv *env, jobject instance, jobject transformMatrix) {
83+
84+
void UltralightMatrixJNI::transform(JNIEnv *env, jobject instance, jobject transform_matrix) {
7585
auto *matrix = reinterpret_cast<ultralight::Matrix *>(
7686
env->CallLongMethod(instance, runtime.object_with_handle.get_handle_method));
7787
auto *targetMatrix = reinterpret_cast<ultralight::Matrix *>(
78-
env->CallLongMethod(transformMatrix, runtime.object_with_handle.get_handle_method));
88+
env->CallLongMethod(transform_matrix, runtime.object_with_handle.get_handle_method));
7989

8090
matrix->Transform(*targetMatrix);
8191
}
82-
jobject UltralightMatrixJNI::create(JNIEnv *env, ultralight::Matrix matrix) {
83-
return env->NewObject(
84-
runtime.ultralight_matrix.clazz, runtime.ultralight_matrix.constructor, new ultralight::Matrix(matrix));
85-
}
86-
jlong UltralightMatrixJNI::construct(JNIEnv *env, jclass caller_class) {
87-
return reinterpret_cast<jlong>(new ultralight::Matrix());
88-
}
89-
void UltralightMatrixJNI::_delete(JNIEnv *env, jclass caller_class, jlong handle) {
92+
93+
void UltralightMatrixJNI::_delete(JNIEnv *, jclass, jlong handle) {
9094
delete reinterpret_cast<ultralight::Matrix *>(handle);
9195
}
9296
} // namespace ultralight_java

ultralight-java-native/src/main/c/src/ultralight_initializer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ namespace ultralight_java {
185185
runtime.ultralight_matrix.native_methods =
186186
{NATIVE_METHOD(
187187
"getMatrix4x4",
188-
"()Lcom/labymedia/ultralight/UltralightMatrix4x4;",
189-
UltralightMatrixJNI::getMatrix4x4),
188+
"()Lcom/labymedia/ultralight/math/UltralightMatrix4x4;",
189+
UltralightMatrixJNI::get_matrix_4x4),
190190
NATIVE_METHOD("delete", "(J)V", UltralightMatrixJNI::_delete),
191191
NATIVE_METHOD("construct", "()J", UltralightMatrixJNI::construct),
192192
NATIVE_METHOD("set", "(DDDDDDDDDDDDDDDD)V", UltralightMatrixJNI::set),
193-
NATIVE_METHOD("set", "(Lcom/labymedia/ultralight/UltralightMatrix4x4;)V", UltralightMatrixJNI::set1),
194-
NATIVE_METHOD("setOrthographicProjection", "(DDZ)V", UltralightMatrixJNI::setOrthographicProjection),
193+
NATIVE_METHOD("set", "(Lcom/labymedia/ultralight/math/UltralightMatrix4x4;)V", UltralightMatrixJNI::set1),
194+
NATIVE_METHOD("setOrthographicProjection", "(DDZ)V", UltralightMatrixJNI::set_orthographic_projection),
195195
NATIVE_METHOD(
196-
"transform", "(Lcom/labymedia/ultralight/UltralightMatrix;)V", UltralightMatrixJNI::transform)};
196+
"transform", "(Lcom/labymedia/ultralight/math/UltralightMatrix;)V", UltralightMatrixJNI::transform)};
197197

198198
runtime.ultralight_bitmap_surface.native_methods = {NATIVE_METHOD(
199199
"bitmap", "()Lcom/labymedia/ultralight/bitmap/UltralightBitmap;", UltralightBitmapSurfaceJNI::bitmap)};

0 commit comments

Comments
 (0)