2018-09-22 06:26:10 +00:00
|
|
|
/*
|
|
|
|
Looking Glass - KVM FrameRelay (KVMFR) Client
|
2019-02-22 11:16:14 +00:00
|
|
|
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
2018-09-22 06:26:10 +00:00
|
|
|
https://looking-glass.hostfission.com
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2019-03-28 00:02:36 +00:00
|
|
|
#include "interface/renderer.h"
|
2018-11-19 22:50:09 +00:00
|
|
|
|
2019-04-11 01:12:59 +00:00
|
|
|
#include "common/debug.h"
|
2019-05-21 05:03:59 +00:00
|
|
|
#include "common/option.h"
|
2019-05-23 06:56:13 +00:00
|
|
|
#include "common/sysinfo.h"
|
2018-09-24 09:48:11 +00:00
|
|
|
#include "utils.h"
|
2019-03-28 08:56:14 +00:00
|
|
|
#include "dynamic/fonts.h"
|
2018-09-22 06:26:10 +00:00
|
|
|
|
|
|
|
#include <SDL2/SDL_syswm.h>
|
|
|
|
#include <SDL2/SDL_egl.h>
|
2019-03-26 06:29:49 +00:00
|
|
|
|
|
|
|
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
|
2019-01-01 13:04:40 +00:00
|
|
|
#include <wayland-egl.h>
|
2019-03-26 06:29:49 +00:00
|
|
|
#endif
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2019-03-28 00:02:36 +00:00
|
|
|
#include "model.h"
|
|
|
|
#include "shader.h"
|
|
|
|
#include "desktop.h"
|
|
|
|
#include "cursor.h"
|
|
|
|
#include "fps.h"
|
|
|
|
#include "splash.h"
|
|
|
|
#include "alert.h"
|
2018-12-15 13:54:37 +00:00
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
#define SPLASH_FADE_TIME 1000000
|
|
|
|
#define ALERT_TIMEOUT 2000000
|
2018-09-22 06:26:10 +00:00
|
|
|
|
|
|
|
struct Options
|
|
|
|
{
|
2018-09-22 08:00:52 +00:00
|
|
|
bool vsync;
|
2018-09-22 06:26:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Inst
|
|
|
|
{
|
|
|
|
LG_RendererParams params;
|
|
|
|
struct Options opt;
|
|
|
|
|
2019-01-01 13:04:40 +00:00
|
|
|
EGLNativeDisplayType nativeDisp;
|
|
|
|
EGLNativeWindowType nativeWind;
|
|
|
|
EGLDisplay display;
|
|
|
|
EGLConfig configs;
|
|
|
|
EGLSurface surface;
|
|
|
|
EGLContext context;
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2018-12-12 10:41:51 +00:00
|
|
|
EGL_Desktop * desktop; // the desktop
|
|
|
|
EGL_Cursor * cursor; // the mouse cursor
|
|
|
|
EGL_FPS * fps; // the fps display
|
2018-12-15 13:54:37 +00:00
|
|
|
EGL_Splash * splash; // the splash screen
|
2018-12-15 23:57:01 +00:00
|
|
|
EGL_Alert * alert; // the alert display
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2018-09-23 10:45:20 +00:00
|
|
|
LG_RendererFormat format;
|
|
|
|
bool sourceChanged;
|
2018-12-15 13:54:37 +00:00
|
|
|
uint64_t waitFadeTime;
|
|
|
|
bool waitDone;
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
bool showAlert;
|
|
|
|
uint64_t alertTimeout;
|
|
|
|
bool useCloseFlag;
|
|
|
|
bool closeFlag;
|
|
|
|
|
2018-11-19 22:50:09 +00:00
|
|
|
int width, height;
|
|
|
|
LG_RendererRect destRect;
|
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
float translateX , translateY;
|
|
|
|
float scaleX , scaleY;
|
|
|
|
float splashRatio;
|
|
|
|
float screenScaleX, screenScaleY;
|
2019-04-19 01:23:51 +00:00
|
|
|
bool useNearest;
|
2018-10-03 16:31:37 +00:00
|
|
|
|
2019-05-28 04:06:15 +00:00
|
|
|
bool cursorVisible;
|
|
|
|
int cursorX , cursorY;
|
2018-12-12 07:53:55 +00:00
|
|
|
float mouseWidth , mouseHeight;
|
2018-09-24 09:48:11 +00:00
|
|
|
float mouseScaleX, mouseScaleY;
|
2018-11-19 22:50:09 +00:00
|
|
|
|
|
|
|
const LG_Font * font;
|
|
|
|
LG_FontObj fontObj;
|
2018-09-22 06:26:10 +00:00
|
|
|
};
|
|
|
|
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2019-05-21 05:03:59 +00:00
|
|
|
static struct Option egl_options[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "vsync",
|
|
|
|
.description = "Enable vsync",
|
|
|
|
.type = OPTION_TYPE_BOOL,
|
|
|
|
.value.x_bool = false
|
|
|
|
},
|
2019-05-27 08:39:21 +00:00
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "doubleBuffer",
|
|
|
|
.description = "Enable double buffering",
|
|
|
|
.type = OPTION_TYPE_BOOL,
|
|
|
|
.value.x_bool = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "multisample",
|
|
|
|
.description = "Enable Multisampling",
|
|
|
|
.type = OPTION_TYPE_BOOL,
|
|
|
|
.value.x_bool = true
|
|
|
|
},
|
2019-05-23 06:32:18 +00:00
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "nvGainMax",
|
|
|
|
.description = "The maximum night vision gain",
|
|
|
|
.type = OPTION_TYPE_INT,
|
|
|
|
.value.x_int = 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "nvGain",
|
|
|
|
.description = "The initial night vision gain at startup",
|
|
|
|
.type = OPTION_TYPE_INT,
|
|
|
|
.value.x_int = 0
|
|
|
|
},
|
2019-05-21 05:03:59 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2018-09-24 09:48:11 +00:00
|
|
|
void update_mouse_shape(struct Inst * this);
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
const char * egl_get_name()
|
|
|
|
{
|
|
|
|
return "EGL";
|
|
|
|
}
|
|
|
|
|
2019-05-21 05:03:59 +00:00
|
|
|
void egl_setup()
|
|
|
|
{
|
|
|
|
option_register(egl_options);
|
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
bool egl_create(void ** opaque, const LG_RendererParams params)
|
|
|
|
{
|
|
|
|
// create our local storage
|
|
|
|
*opaque = malloc(sizeof(struct Inst));
|
|
|
|
if (!*opaque)
|
|
|
|
{
|
|
|
|
DEBUG_INFO("Failed to allocate %lu bytes", sizeof(struct Inst));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
memset(*opaque, 0, sizeof(struct Inst));
|
|
|
|
|
|
|
|
// safe off parameteres and init our default option values
|
|
|
|
struct Inst * this = (struct Inst *)*opaque;
|
2019-05-21 05:03:59 +00:00
|
|
|
memcpy(&this->params, ¶ms, sizeof(LG_RendererParams));
|
|
|
|
|
|
|
|
this->opt.vsync = option_get_bool("egl", "vsync");
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
this->translateX = 0;
|
|
|
|
this->translateY = 0;
|
|
|
|
this->scaleX = 1.0f;
|
|
|
|
this->scaleY = 1.0f;
|
|
|
|
this->screenScaleX = 1.0f;
|
|
|
|
this->screenScaleY = 1.0f;
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2018-11-19 22:50:09 +00:00
|
|
|
this->font = LG_Fonts[0];
|
2019-05-23 09:58:12 +00:00
|
|
|
if (!this->font->create(&this->fontObj, NULL, 16))
|
2018-11-19 22:50:09 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to create a font instance");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool egl_initialize(void * opaque, Uint32 * sdlFlags)
|
|
|
|
{
|
2019-05-27 08:39:21 +00:00
|
|
|
const bool doubleBuffer = option_get_bool("egl", "doubleBuffer");
|
|
|
|
DEBUG_INFO("Double buffering is %s", doubleBuffer ? "on" : "off");
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
*sdlFlags = SDL_WINDOW_OPENGL;
|
2019-05-27 08:39:21 +00:00
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER , doubleBuffer ? 1 : 0);
|
2018-09-22 06:26:10 +00:00
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
2018-12-12 07:53:55 +00:00
|
|
|
|
2019-05-27 08:39:21 +00:00
|
|
|
if (option_get_bool("egl", "multisample"))
|
2019-05-23 06:56:13 +00:00
|
|
|
{
|
2019-05-27 08:39:21 +00:00
|
|
|
int maxSamples = sysinfo_gfx_max_multisample();
|
|
|
|
if (maxSamples > 1)
|
|
|
|
{
|
|
|
|
if (maxSamples > 4)
|
|
|
|
maxSamples = 4;
|
2019-05-23 06:56:13 +00:00
|
|
|
|
2019-05-27 08:39:21 +00:00
|
|
|
DEBUG_INFO("Multsampling enabled, max samples: %d", maxSamples);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, maxSamples);
|
|
|
|
}
|
2019-05-23 06:56:13 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_deinitialize(void * opaque)
|
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
2018-11-19 22:50:09 +00:00
|
|
|
if (this->font && this->fontObj)
|
|
|
|
this->font->destroy(this->fontObj);
|
|
|
|
|
2018-12-12 10:41:51 +00:00
|
|
|
egl_desktop_free(&this->desktop);
|
|
|
|
egl_cursor_free (&this->cursor);
|
|
|
|
egl_fps_free (&this->fps );
|
2018-12-15 13:54:37 +00:00
|
|
|
egl_splash_free (&this->splash);
|
2018-12-15 23:57:01 +00:00
|
|
|
egl_alert_free (&this->alert );
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_on_resize(void * opaque, const int width, const int height, const LG_RendererRect destRect)
|
|
|
|
{
|
2018-09-24 09:48:11 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
2018-11-19 22:50:09 +00:00
|
|
|
this->width = width;
|
|
|
|
this->height = height;
|
|
|
|
memcpy(&this->destRect, &destRect, sizeof(LG_RendererRect));
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
glViewport(0, 0, width, height);
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2018-10-03 16:31:37 +00:00
|
|
|
if (destRect.valid)
|
|
|
|
{
|
|
|
|
this->translateX = 1.0f - (((destRect.w / 2) + destRect.x) * 2) / (float)width;
|
|
|
|
this->translateY = 1.0f - (((destRect.h / 2) + destRect.y) * 2) / (float)height;
|
|
|
|
this->scaleX = (float)destRect.w / (float)width;
|
|
|
|
this->scaleY = (float)destRect.h / (float)height;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->mouseScaleX = 2.0f / this->format.width ;
|
2018-09-24 10:11:42 +00:00
|
|
|
this->mouseScaleY = 2.0f / this->format.height;
|
2018-12-12 07:53:55 +00:00
|
|
|
egl_cursor_set_size(this->cursor,
|
|
|
|
(this->mouseWidth * (1.0f / this->format.width )) * this->scaleX,
|
|
|
|
(this->mouseHeight * (1.0f / this->format.height)) * this->scaleY
|
|
|
|
);
|
2018-12-15 13:54:37 +00:00
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
this->splashRatio = (float)width / (float)height;
|
|
|
|
this->screenScaleX = 1.0f / width;
|
|
|
|
this->screenScaleY = 1.0f / height;
|
2019-05-28 04:06:15 +00:00
|
|
|
|
|
|
|
egl_cursor_set_state(
|
|
|
|
this->cursor,
|
|
|
|
this->cursorVisible,
|
|
|
|
(((float)this->cursorX * this->mouseScaleX) - 1.0f) * this->scaleX,
|
|
|
|
(((float)this->cursorY * this->mouseScaleY) - 1.0f) * this->scaleY
|
|
|
|
);
|
2018-09-22 06:26:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool egl_on_mouse_shape(void * opaque, const LG_RendererCursor cursor, const int width, const int height, const int pitch, const uint8_t * data)
|
|
|
|
{
|
2018-09-24 09:48:11 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
2018-12-12 07:53:55 +00:00
|
|
|
if (!egl_cursor_set_shape(this->cursor, cursor, width, height, pitch, data))
|
2018-09-24 09:48:11 +00:00
|
|
|
{
|
2018-12-12 07:53:55 +00:00
|
|
|
DEBUG_ERROR("Failed to update the cursor shape");
|
|
|
|
return false;
|
2018-09-24 09:48:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-12 07:53:55 +00:00
|
|
|
this->mouseWidth = width;
|
|
|
|
this->mouseHeight = height;
|
|
|
|
egl_cursor_set_size(this->cursor,
|
|
|
|
(this->mouseWidth * (1.0f / this->format.width )) * this->scaleX,
|
|
|
|
(this->mouseHeight * (1.0f / this->format.height)) * this->scaleY
|
|
|
|
);
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-28 04:06:15 +00:00
|
|
|
bool egl_on_mouse_event(void * opaque, const bool visible, const int x, const int y)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
2018-09-24 09:48:11 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
2019-05-28 04:06:15 +00:00
|
|
|
this->cursorVisible = visible;
|
|
|
|
this->cursorX = x;
|
|
|
|
this->cursorY = y;
|
2018-12-12 07:53:55 +00:00
|
|
|
|
|
|
|
egl_cursor_set_state(
|
|
|
|
this->cursor,
|
2019-05-28 04:06:15 +00:00
|
|
|
this->cursorVisible,
|
|
|
|
(((float)this->cursorX * this->mouseScaleX) - 1.0f) * this->scaleX,
|
|
|
|
(((float)this->cursorY * this->mouseScaleY) - 1.0f) * this->scaleY
|
2018-12-12 07:53:55 +00:00
|
|
|
);
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-01 13:17:20 +00:00
|
|
|
bool egl_on_frame_event(void * opaque, const LG_RendererFormat format, const FrameBuffer frame)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
2018-09-23 05:48:44 +00:00
|
|
|
this->sourceChanged = (
|
|
|
|
this->sourceChanged ||
|
|
|
|
this->format.type != format.type ||
|
|
|
|
this->format.width != format.width ||
|
|
|
|
this->format.height != format.height ||
|
|
|
|
this->format.pitch != format.pitch
|
|
|
|
);
|
|
|
|
|
|
|
|
if (this->sourceChanged)
|
|
|
|
memcpy(&this->format, &format, sizeof(LG_RendererFormat));
|
2018-09-23 10:45:20 +00:00
|
|
|
|
2019-04-19 01:23:51 +00:00
|
|
|
this->useNearest = this->width < format.width || this->height < format.height;
|
|
|
|
|
2019-10-01 13:17:20 +00:00
|
|
|
if (!egl_desktop_prepare_update(this->desktop, this->sourceChanged, format, frame))
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
|
|
|
DEBUG_INFO("Failed to prepare to update the desktop");
|
|
|
|
return false;
|
2018-09-23 05:48:44 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-30 01:26:06 +00:00
|
|
|
void egl_on_alert(void * opaque, const LG_MsgAlert alert, const char * message, bool ** closeFlag)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
2018-12-15 23:57:01 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
|
|
|
static const uint32_t colors[] =
|
|
|
|
{
|
|
|
|
0x0000CCCC, // LG_ALERT_INFO
|
|
|
|
0x00CC00CC, // LG_ALERT_SUCCESS
|
|
|
|
0xCC7F00CC, // LG_ALERT_WARNING
|
|
|
|
0xFF0000CC // LG_ALERT_ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
if (alert > LG_ALERT_ERROR || alert < 0)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Invalid alert value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
egl_alert_set_color(this->alert, colors[alert]);
|
|
|
|
egl_alert_set_text (this->alert, message );
|
|
|
|
|
|
|
|
if (closeFlag)
|
|
|
|
{
|
|
|
|
this->useCloseFlag = true;
|
|
|
|
*closeFlag = &this->closeFlag;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->useCloseFlag = false;
|
|
|
|
this->alertTimeout = microtime() + ALERT_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->showAlert = true;
|
2018-09-22 06:26:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool egl_render_startup(void * opaque, SDL_Window * window)
|
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
|
|
|
SDL_SysWMinfo wminfo;
|
|
|
|
SDL_VERSION(&wminfo.version);
|
|
|
|
if (!SDL_GetWindowWMInfo(window, &wminfo))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("SDL_GetWindowWMInfo failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-01 13:04:40 +00:00
|
|
|
switch(wminfo.subsystem)
|
|
|
|
{
|
|
|
|
case SDL_SYSWM_X11:
|
|
|
|
{
|
|
|
|
this->nativeDisp = (EGLNativeDisplayType)wminfo.info.x11.display;
|
|
|
|
this->nativeWind = (EGLNativeWindowType)wminfo.info.x11.window;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-26 06:29:49 +00:00
|
|
|
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
|
2019-01-01 13:04:40 +00:00
|
|
|
case SDL_SYSWM_WAYLAND:
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
SDL_GetWindowSize(window, &width, &height);
|
|
|
|
this->nativeDisp = (EGLNativeDisplayType)wminfo.info.wl.display;
|
|
|
|
this->nativeWind = (EGLNativeWindowType)wl_egl_window_create(wminfo.info.wl.surface, width, height);
|
|
|
|
break;
|
|
|
|
}
|
2019-03-26 06:29:49 +00:00
|
|
|
#endif
|
2019-01-01 13:04:40 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_ERROR("Unsupported subsystem");
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2019-01-01 13:04:40 +00:00
|
|
|
this->display = eglGetDisplay(this->nativeDisp);
|
2018-09-22 06:26:10 +00:00
|
|
|
if (this->display == EGL_NO_DISPLAY)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("eglGetDisplay failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglInitialize(this->display, NULL, NULL))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Unable to initialize EGL");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint attr[] =
|
|
|
|
{
|
2019-05-27 08:39:21 +00:00
|
|
|
EGL_BUFFER_SIZE , 32,
|
2018-09-25 13:04:29 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
2018-12-15 13:54:37 +00:00
|
|
|
EGL_SAMPLE_BUFFERS , 1,
|
2019-05-27 08:39:21 +00:00
|
|
|
EGL_SAMPLES , 4,
|
2018-09-22 06:26:10 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
EGLint num_config;
|
|
|
|
if (!eglChooseConfig(this->display, attr, &this->configs, 1, &num_config))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to choose config (eglError: 0x%x)", eglGetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-01 13:04:40 +00:00
|
|
|
this->surface = eglCreateWindowSurface(this->display, this->configs, this->nativeWind, NULL);
|
2018-09-22 06:26:10 +00:00
|
|
|
if (this->surface == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to create EGL surface (eglError: 0x%x)", eglGetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint ctxattr[] =
|
|
|
|
{
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
this->context = eglCreateContext(this->display, this->configs, EGL_NO_CONTEXT, ctxattr);
|
|
|
|
if (this->context == EGL_NO_CONTEXT)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to create EGL context (eglError: 0x%x)", eglGetError());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
eglMakeCurrent(this->display, this->surface, this->surface, this->context);
|
|
|
|
|
|
|
|
DEBUG_INFO("Vendor : %s", glGetString(GL_VENDOR ));
|
|
|
|
DEBUG_INFO("Renderer: %s", glGetString(GL_RENDERER));
|
|
|
|
DEBUG_INFO("Version : %s", glGetString(GL_VERSION ));
|
|
|
|
|
2018-12-12 10:41:51 +00:00
|
|
|
eglSwapInterval(this->display, this->opt.vsync ? 1 : 0);
|
2018-09-23 05:48:44 +00:00
|
|
|
|
2018-12-12 10:41:51 +00:00
|
|
|
if (!egl_desktop_init(&this->desktop))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the desktop");
|
2018-09-22 08:00:52 +00:00
|
|
|
return false;
|
2018-12-12 10:41:51 +00:00
|
|
|
}
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2018-12-12 07:53:55 +00:00
|
|
|
if (!egl_cursor_init(&this->cursor))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the cursor");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-12 09:04:43 +00:00
|
|
|
if (!egl_fps_init(&this->fps, this->font, this->fontObj))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the FPS display");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-15 13:54:37 +00:00
|
|
|
if (!egl_splash_init(&this->splash))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the splash screen");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
if (!egl_alert_init(&this->alert, this->font, this->fontObj))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the alert display");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool egl_render(void * opaque, SDL_Window * window)
|
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
2019-06-12 12:36:00 +00:00
|
|
|
if (egl_desktop_render(this->desktop, this->translateX, this->translateY, this->scaleX, this->scaleY, this->useNearest))
|
|
|
|
{
|
|
|
|
if (!this->waitFadeTime)
|
|
|
|
this->waitFadeTime = microtime() + SPLASH_FADE_TIME;
|
|
|
|
egl_cursor_render(this->cursor);
|
|
|
|
}
|
2018-11-19 22:50:09 +00:00
|
|
|
|
2018-12-15 13:54:37 +00:00
|
|
|
if (!this->waitDone)
|
|
|
|
{
|
2018-12-16 01:17:12 +00:00
|
|
|
float a = 1.0f;
|
2018-12-15 13:54:37 +00:00
|
|
|
if (!this->waitFadeTime)
|
|
|
|
a = 1.0f;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint64_t t = microtime();
|
|
|
|
if (t > this->waitFadeTime)
|
|
|
|
this->waitDone = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint64_t delta = this->waitFadeTime - t;
|
2018-12-15 23:57:01 +00:00
|
|
|
a = 1.0f / SPLASH_FADE_TIME * delta;
|
2018-12-15 13:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-01 23:36:17 +00:00
|
|
|
|
|
|
|
if (!this->waitDone)
|
|
|
|
egl_splash_render(this->splash, a, this->splashRatio);
|
2018-12-15 23:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->showAlert)
|
|
|
|
{
|
|
|
|
bool close = false;
|
|
|
|
if (this->useCloseFlag)
|
|
|
|
close = this->closeFlag;
|
|
|
|
else if (this->alertTimeout < microtime())
|
|
|
|
close = true;
|
|
|
|
|
|
|
|
if (close)
|
|
|
|
this->showAlert = false;
|
|
|
|
else
|
|
|
|
egl_alert_render(this->alert, this->screenScaleX, this->screenScaleY);
|
2018-12-15 13:54:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
egl_fps_render(this->fps, this->screenScaleX, this->screenScaleY);
|
2018-09-22 06:26:10 +00:00
|
|
|
eglSwapBuffers(this->display, this->surface);
|
2018-10-03 14:09:10 +00:00
|
|
|
|
|
|
|
// defer texture uploads until after the flip to avoid stalling
|
2019-06-12 12:36:00 +00:00
|
|
|
egl_desktop_perform_update(this->desktop, this->sourceChanged);
|
2018-10-03 14:09:10 +00:00
|
|
|
|
2019-06-12 12:36:00 +00:00
|
|
|
this->sourceChanged = false;
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-12 12:59:22 +00:00
|
|
|
void egl_update_fps(void * opaque, const float avgUPS, const float avgFPS)
|
2018-11-19 18:26:51 +00:00
|
|
|
{
|
2018-11-19 22:50:09 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
if (!this->params.showFPS)
|
|
|
|
return;
|
|
|
|
|
2018-12-12 12:59:22 +00:00
|
|
|
egl_fps_update(this->fps, avgUPS, avgFPS);
|
2018-11-19 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
struct LG_Renderer LGR_EGL =
|
|
|
|
{
|
|
|
|
.get_name = egl_get_name,
|
2019-05-21 05:03:59 +00:00
|
|
|
.setup = egl_setup,
|
|
|
|
.create = egl_create,
|
2018-09-22 06:26:10 +00:00
|
|
|
.initialize = egl_initialize,
|
|
|
|
.deinitialize = egl_deinitialize,
|
|
|
|
.on_resize = egl_on_resize,
|
|
|
|
.on_mouse_shape = egl_on_mouse_shape,
|
|
|
|
.on_mouse_event = egl_on_mouse_event,
|
|
|
|
.on_frame_event = egl_on_frame_event,
|
|
|
|
.on_alert = egl_on_alert,
|
|
|
|
.render_startup = egl_render_startup,
|
2018-11-19 18:26:51 +00:00
|
|
|
.render = egl_render,
|
|
|
|
.update_fps = egl_update_fps
|
2018-09-22 06:26:10 +00:00
|
|
|
};
|