remove egl wrapper&fix crash

This commit is contained in:
ShirosakiMio 2023-03-03 16:34:30 +08:00
parent 3b8d071cd6
commit 7c78f047e1
7 changed files with 30 additions and 240 deletions

View File

@ -7,7 +7,7 @@ import java.io.Serializable;
public class FCLConfig implements Serializable { public class FCLConfig implements Serializable {
public enum Renderer implements Serializable { public enum Renderer implements Serializable {
RENDERER_GL4ES("libgl4es.so:libgl4es_egl.so"), RENDERER_GL4ES("libgl4es.so:libEGL.so"),
RENDERER_ZINK("libGL.so:libEGL.so"), RENDERER_ZINK("libGL.so:libEGL.so"),
RENDERER_ANGLE("libtinywrapper.so:libEGL_angle.so"); RENDERER_ANGLE("libtinywrapper.so:libEGL_angle.so");

View File

@ -148,168 +148,6 @@ GLFWbool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig)
return GLFW_TRUE; return GLFW_TRUE;
} }
// Chooses the framebuffer config that best matches the desired one
//
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
const _GLFWfbconfig* alternatives,
unsigned int count)
{
unsigned int i;
unsigned int missing, leastMissing = UINT_MAX;
unsigned int colorDiff, leastColorDiff = UINT_MAX;
unsigned int extraDiff, leastExtraDiff = UINT_MAX;
const _GLFWfbconfig* current;
const _GLFWfbconfig* closest = NULL;
for (i = 0; i < count; i++)
{
current = alternatives + i;
if (desired->stereo > 0 && current->stereo == 0)
{
// Stereo is a hard constraint
continue;
}
// Count number of missing buffers
{
missing = 0;
if (desired->alphaBits > 0 && current->alphaBits == 0)
missing++;
if (desired->depthBits > 0 && current->depthBits == 0)
missing++;
if (desired->stencilBits > 0 && current->stencilBits == 0)
missing++;
if (desired->auxBuffers > 0 &&
current->auxBuffers < desired->auxBuffers)
{
missing += desired->auxBuffers - current->auxBuffers;
}
if (desired->samples > 0 && current->samples == 0)
{
// Technically, several multisampling buffers could be
// involved, but that's a lower level implementation detail and
// not important to us here, so we count them as one
missing++;
}
if (desired->transparent != current->transparent)
missing++;
}
// These polynomials make many small channel size differences matter
// less than one large channel size difference
// Calculate color channel size difference value
{
colorDiff = 0;
if (desired->redBits != GLFW_DONT_CARE)
{
colorDiff += (desired->redBits - current->redBits) *
(desired->redBits - current->redBits);
}
if (desired->greenBits != GLFW_DONT_CARE)
{
colorDiff += (desired->greenBits - current->greenBits) *
(desired->greenBits - current->greenBits);
}
if (desired->blueBits != GLFW_DONT_CARE)
{
colorDiff += (desired->blueBits - current->blueBits) *
(desired->blueBits - current->blueBits);
}
}
// Calculate non-color channel size difference value
{
extraDiff = 0;
if (desired->alphaBits != GLFW_DONT_CARE)
{
extraDiff += (desired->alphaBits - current->alphaBits) *
(desired->alphaBits - current->alphaBits);
}
if (desired->depthBits != GLFW_DONT_CARE)
{
extraDiff += (desired->depthBits - current->depthBits) *
(desired->depthBits - current->depthBits);
}
if (desired->stencilBits != GLFW_DONT_CARE)
{
extraDiff += (desired->stencilBits - current->stencilBits) *
(desired->stencilBits - current->stencilBits);
}
if (desired->accumRedBits != GLFW_DONT_CARE)
{
extraDiff += (desired->accumRedBits - current->accumRedBits) *
(desired->accumRedBits - current->accumRedBits);
}
if (desired->accumGreenBits != GLFW_DONT_CARE)
{
extraDiff += (desired->accumGreenBits - current->accumGreenBits) *
(desired->accumGreenBits - current->accumGreenBits);
}
if (desired->accumBlueBits != GLFW_DONT_CARE)
{
extraDiff += (desired->accumBlueBits - current->accumBlueBits) *
(desired->accumBlueBits - current->accumBlueBits);
}
if (desired->accumAlphaBits != GLFW_DONT_CARE)
{
extraDiff += (desired->accumAlphaBits - current->accumAlphaBits) *
(desired->accumAlphaBits - current->accumAlphaBits);
}
if (desired->samples != GLFW_DONT_CARE)
{
extraDiff += (desired->samples - current->samples) *
(desired->samples - current->samples);
}
if (desired->sRGB && !current->sRGB)
extraDiff++;
}
// Figure out if the current one is better than the best one found so far
// Least number of missing buffers is the most important heuristic,
// then color buffer size match and lastly size match for other buffers
if (missing < leastMissing)
closest = current;
else if (missing == leastMissing)
{
if ((colorDiff < leastColorDiff) ||
(colorDiff == leastColorDiff && extraDiff < leastExtraDiff))
{
closest = current;
}
}
if (current == closest)
{
leastMissing = missing;
leastColorDiff = colorDiff;
leastExtraDiff = extraDiff;
}
}
return closest;
}
// Retrieves the attributes of the current context // Retrieves the attributes of the current context
// //
GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window,
@ -393,36 +231,6 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window,
return GLFW_FALSE; return GLFW_FALSE;
} }
// if (window->context.major < ctxconfig->major ||
// (window->context.major == ctxconfig->major &&
// window->context.minor < ctxconfig->minor))
// {
// // The desired OpenGL version is greater than the actual version
// // This only happens if the machine lacks {GLX|WGL}_ARB_create_context
// // /and/ the user has requested an OpenGL version greater than 1.0
//
// // For API consistency, we emulate the behavior of the
// // {GLX|WGL}_ARB_create_context extension and fail here
//
// if (window->context.client == GLFW_OPENGL_API)
// {
// _glfwInputError(GLFW_VERSION_UNAVAILABLE,
// "Requested OpenGL version %i.%i, got version %i.%i",
// ctxconfig->major, ctxconfig->minor,
// window->context.major, window->context.minor);
// }
// else
// {
// _glfwInputError(GLFW_VERSION_UNAVAILABLE,
// "Requested OpenGL ES version %i.%i, got version %i.%i",
// ctxconfig->major, ctxconfig->minor,
// window->context.major, window->context.minor);
// }
//
// glfwMakeContextCurrent((GLFWwindow*) previous);
// return GLFW_FALSE;
// }
if (window->context.major >= 3) if (window->context.major >= 3)
{ {
// OpenGL 3.0+ uses a different function for extension string retrieval // OpenGL 3.0+ uses a different function for extension string retrieval

View File

@ -341,8 +341,15 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
eglChooseConfig(_glfw.egl.display, egl_attributes, &config, 1, &num_configs); eglChooseConfig(_glfw.egl.display, egl_attributes, &config, 1, &num_configs);
// eglGetConfigAttrib(_glfw.egl.display, config, EGL_NATIVE_VISUAL_ID, 0); // eglGetConfigAttrib(_glfw.egl.display, config, EGL_NATIVE_VISUAL_ID, 0);
int client=0;
const char* render= getenv("LIBGL_NAME");
if (strcmp(render,"libgl4es.so")==0){
client=0;
} else if (strcmp(render,"libtinywrapper.so")==0){
client=1;
}
if (ctxconfig->client == GLFW_OPENGL_ES_API) if (client==0)
{ {
if (!eglBindAPI(EGL_OPENGL_ES_API)) if (!eglBindAPI(EGL_OPENGL_ES_API))
{ {

View File

@ -109,32 +109,6 @@ static int convertToBPE(int bpp) {
return bpe; return bpe;
} }
static EGLConfig *chooseVisualEGLFromBPP(JNIEnv *env, EGLDisplay disp, jobject pixel_format, int bpp, int drawable_type) {
EGLint egl_attributes[] = {
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT|0x0001,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};
EGLint num_configs = 0;
if (lwjgl_eglChooseConfig(disp, egl_attributes, NULL, 0, &num_configs)!=EGL_TRUE) {
throwException(env, "eglChooseConfig() failed");
return false;
}
if (num_configs == 0) {
throwException(env, "eglChooseConfig() found no matching config");
return false;
}
EGLConfig *configs = calloc(num_configs, sizeof(EGLConfig));
lwjgl_eglChooseConfig(disp, egl_attributes, configs, 1, &num_configs);
return configs;
}
EGLConfig *chooseVisualEGL(JNIEnv *env, EGLDisplay disp, jobject pixel_format, bool use_display_bpp, int drawable_type) { EGLConfig *chooseVisualEGL(JNIEnv *env, EGLDisplay disp, jobject pixel_format, bool use_display_bpp, int drawable_type) {
EGLint egl_attributes[] = { EGLint egl_attributes[] = {
EGL_BLUE_SIZE, 8, EGL_BLUE_SIZE, 8,
@ -158,6 +132,7 @@ EGLConfig *chooseVisualEGL(JNIEnv *env, EGLDisplay disp, jobject pixel_format, b
} }
EGLConfig *configs = calloc(num_configs, sizeof(EGLConfig)); EGLConfig *configs = calloc(num_configs, sizeof(EGLConfig));
lwjgl_eglChooseConfig(disp, egl_attributes, configs, 1, &num_configs); lwjgl_eglChooseConfig(disp, egl_attributes, configs, 1, &num_configs);
return configs; return configs;
} }
@ -208,22 +183,22 @@ bool initPeerInfo(JNIEnv *env, jobject peer_info_handle, EGLDisplay display, job
return false; return false;
} }
EGLConfig *configs = chooseVisualEGL(env, display, pixel_format, use_display_bpp, drawable_type); // EGLConfig *configs = chooseVisualEGL(env, display, pixel_format, use_display_bpp, drawable_type);
if (configs == NULL) { // if (configs == NULL) {
throwException(env, "Could not choose EGL config"); // throwException(env, "Could not choose EGL config");
return false; // return false;
} // }
if (isDebugEnabled()) { // if (isDebugEnabled()) {
dumpVisualInfo(env, display, configs[0]); // dumpVisualInfo(env, display, configs[0]);
} // }
EGLint config_id; // EGLint config_id;
int result = lwjgl_eglGetConfigAttrib(display, configs[0], EGL_CONFIG_ID, &config_id); // int result = lwjgl_eglGetConfigAttrib(display, configs[0], EGL_CONFIG_ID, &config_id);
free(configs); // free(configs);
if (result != EGL_TRUE) { // if (result != EGL_TRUE) {
throwException(env, "Could not get EGL_CONFIG_ID from EGLConfig"); // throwException(env, "Could not get EGL_CONFIG_ID from EGLConfig");
return false; // return false;
} // }
peer_info->config_id = config_id; // peer_info->config_id = config_id;
peer_info->display = display; peer_info->display = display;
peer_info->drawable = EGL_NO_SURFACE; peer_info->drawable = EGL_NO_SURFACE;
return true; return true;

View File

@ -59,10 +59,10 @@ static void createContextEGL(JNIEnv *env, FCLPeerInfo *peer_info, FCLContext *co
EGLConfig *config = getFBConfigFromPeerInfo(env, peer_info); EGLConfig *config = getFBConfigFromPeerInfo(env, peer_info);
if (config == NULL) if (config == NULL)
return; return;
if (!lwjgl_eglBindAPI(EGL_OPENGL_API)) { // if (!lwjgl_eglBindAPI(EGL_OPENGL_API)) {
throwException(env, "Could not bind OpenGL API"); // throwException(env, "Could not bind OpenGL API");
return; // return;
} // }
EGLContext context; EGLContext context;
const EGLint egl_context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; const EGLint egl_context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
if (attribs) { if (attribs) {