This repository was archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathultralight_java_gpu.cpp
More file actions
98 lines (79 loc) · 3.86 KB
/
ultralight_java_gpu.cpp
File metadata and controls
98 lines (79 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Ultralight Java - Java wrapper for the Ultralight web engine
* Copyright (C) 2021 LabyMedia and contributors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "ultralight_java/gpudriver/com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil.h"
#include "ultralight_java/gpudriver/gl/GPUContextGL.h"
#include "ultralight_java/gpudriver/gl/GPUDriverGL.h"
#include "ultralight_java/gpudriver/gl/glad.h"
JNIEnv *env;
void *JniLoaderFunc(const char *name) {
jclass glfw = env->FindClass("org/lwjgl/glfw/GLFW");
jmethodID nglfwGetProcAddress = env->GetStaticMethodID(glfw, "nglfwGetProcAddress", "(J)J");
jlong res = env->CallStaticLongMethod(glfw, nglfwGetProcAddress, (jlong) name);
return (void *) res;
}
extern "C" jint JNI_OnLoad(JavaVM *jvm, void *) {
jvm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_8);
return JNI_VERSION_1_8;
}
JNIEXPORT jlong JNICALL Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_createOpenGLContext(
JNIEnv *e, jobject, jlong window, jboolean msaa) {
env = e;
gladLoadGLLoader((GLADloadproc) JniLoaderFunc);
auto *context = new ultralight::GPUContextGL((void *) window, msaa);
return (jlong) context;
}
JNIEXPORT jlong JNICALL Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_getDriverFromContext(
JNIEnv *, jobject, jlong contextHandle) {
auto *context = (ultralight::GPUContextGL *) contextHandle;
return (jlong) context->driver();
}
JNIEXPORT void JNICALL
Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_beginSynchronize(JNIEnv *, jobject, jlong handle) {
auto *driver = (ultralight::GPUDriverGL *) handle;
driver->BeginSynchronize();
}
JNIEXPORT void JNICALL
Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_endSynchronize(JNIEnv *, jobject, jlong handle) {
auto *driver = (ultralight::GPUDriverGL *) handle;
driver->EndSynchronize();
}
JNIEXPORT jboolean JNICALL
Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_hasCommandsPending(JNIEnv *, jobject, jlong handle) {
auto *driver = (ultralight::GPUDriverGL *) handle;
return (jboolean) driver->HasCommandsPending();
}
JNIEXPORT void JNICALL
Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_drawCommandList(JNIEnv *, jobject, jlong handle) {
auto *driver = (ultralight::GPUDriverGL *) handle;
driver->DrawCommandList();
}
JNIEXPORT void JNICALL Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_setActiveWindow(
JNIEnv *, jobject, jlong handle, jlong window) {
auto *driver = (ultralight::GPUDriverGL *) handle;
driver->GetContext()->set_active_window(reinterpret_cast<void *>(window));
}
JNIEXPORT void JNICALL Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_bindTexture(
JNIEnv *, jobject, jlong handle, jlong textureId, jlong texture) {
auto *driver = (ultralight::GPUDriverGL *) handle;
driver->BindTexture(textureId, texture);
}
JNIEXPORT jint JNICALL Java_com_labymedia_ultralight_gpu_UltralightGPUDriverNativeUtil_getGlTextureId (JNIEnv *, jobject, jlong handle, jlong texture) {
auto *driver = (ultralight::GPUDriverGL *) handle;
return (jint) driver->GetGlTextureId(texture);
}