2021-06-06 01:26:18 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
|
|
|
* Copyright (C) 2017-2021 The Looking Glass Authors
|
|
|
|
* https://looking-glass.io
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2018-09-22 06:26:10 +00:00
|
|
|
|
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"
|
2021-07-11 01:20:08 +00:00
|
|
|
#include "common/KVMFR.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"
|
2020-01-17 03:35:08 +00:00
|
|
|
#include "common/time.h"
|
2020-05-21 01:44:56 +00:00
|
|
|
#include "common/locking.h"
|
2021-07-08 01:45:54 +00:00
|
|
|
#include "app.h"
|
2021-01-25 08:58:36 +00:00
|
|
|
#include "util.h"
|
2019-03-28 08:56:14 +00:00
|
|
|
#include "dynamic/fonts.h"
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2021-07-08 01:45:54 +00:00
|
|
|
#include <GL/glew.h>
|
2021-01-26 10:46:30 +00:00
|
|
|
#include <EGL/egl.h>
|
2019-03-26 06:29:49 +00:00
|
|
|
|
2021-07-08 01:45:54 +00:00
|
|
|
#include "cimgui.h"
|
|
|
|
#include "generator/output/cimgui_impl.h"
|
|
|
|
|
2021-01-19 15:06:49 +00:00
|
|
|
#include <assert.h>
|
2021-02-21 06:25:54 +00:00
|
|
|
#include <math.h>
|
2021-01-26 10:46:30 +00:00
|
|
|
#include <string.h>
|
2021-01-19 15:06:49 +00:00
|
|
|
|
2021-01-15 09:30:03 +00:00
|
|
|
#include "app.h"
|
2021-01-26 10:46:30 +00:00
|
|
|
#include "egl_dynprocs.h"
|
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"
|
2021-01-30 22:06:57 +00:00
|
|
|
#include "help.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;
|
2020-12-31 04:31:24 +00:00
|
|
|
bool doubleBuffer;
|
2018-09-22 06:26:10 +00:00
|
|
|
};
|
|
|
|
|
2021-07-11 01:20:08 +00:00
|
|
|
struct DesktopDamage
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
FrameDamageRect rects[KVMFR_MAX_DAMAGE_RECTS];
|
|
|
|
};
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
struct Inst
|
|
|
|
{
|
2020-10-29 15:32:25 +00:00
|
|
|
bool dmaSupport;
|
2018-09-22 06:26:10 +00:00
|
|
|
LG_RendererParams params;
|
|
|
|
struct Options opt;
|
|
|
|
|
2019-01-01 13:04:40 +00:00
|
|
|
EGLNativeWindowType nativeWind;
|
|
|
|
EGLDisplay display;
|
|
|
|
EGLConfig configs;
|
|
|
|
EGLSurface surface;
|
2020-05-21 01:44:56 +00:00
|
|
|
EGLContext context, frameContext;
|
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
|
2021-01-30 22:06:57 +00:00
|
|
|
EGL_Help * help; // the help display
|
2021-07-08 01:45:54 +00:00
|
|
|
bool imgui; // if imgui was initialized
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2018-09-23 10:45:20 +00:00
|
|
|
LG_RendererFormat format;
|
2021-01-19 09:36:43 +00:00
|
|
|
bool formatValid;
|
2020-08-11 04:45:08 +00:00
|
|
|
bool start;
|
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;
|
|
|
|
|
2021-01-18 15:44:56 +00:00
|
|
|
int width, height;
|
2021-02-21 06:25:54 +00:00
|
|
|
float uiScale;
|
2021-01-18 15:44:56 +00:00
|
|
|
LG_RendererRect destRect;
|
|
|
|
LG_RendererRotate rotate; //client side rotation
|
2018-11-19 22:50:09 +00:00
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
float translateX , translateY;
|
|
|
|
float scaleX , scaleY;
|
|
|
|
float splashRatio;
|
|
|
|
float screenScaleX, screenScaleY;
|
2021-02-21 00:50:59 +00:00
|
|
|
|
|
|
|
int viewportWidth, viewportHeight;
|
|
|
|
enum EGL_DesktopScaleType scaleType;
|
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;
|
2021-02-21 06:25:54 +00:00
|
|
|
unsigned fontSize;
|
2021-01-31 11:13:34 +00:00
|
|
|
LG_FontObj helpFontObj;
|
2021-02-21 06:25:54 +00:00
|
|
|
unsigned helpFontSize;
|
2021-05-11 20:49:39 +00:00
|
|
|
|
|
|
|
bool cursorLastValid;
|
|
|
|
struct CursorState cursorLast;
|
2021-07-11 01:20:08 +00:00
|
|
|
|
2021-07-11 07:52:41 +00:00
|
|
|
bool hadOverlay;
|
2021-07-11 01:20:08 +00:00
|
|
|
_Atomic(struct DesktopDamage *) desktopDamage;
|
2018-09-22 06:26:10 +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,
|
[client] fix hang in eglSwapBuffers when exiting while not visible
eglSwapBuffers is allowed to block when called with a nonzero interval
parameter. On Wayland, Mesa will block until a frame callback arrives.
If an application is not visible, a compositor is free to not schedule
frame callbacks (in order to save CPU time rendering something that is
entirely invisible).
Currently, starting Looking Glass from a terminal, hiding it
entirely, and sending ^C will cause Looking Glass to hang joining the
render thread until the window is made visible again.
Calling eglDestroySurface is insufficient to unblock eglSwapBuffers, as
it attempts to grab the same underlying mutex.
Instead, this commit makes it so that we pass a 0 interval to
eglSwapBuffers when running on Wayland, such that we don't block waiting
for a frame callback. This is not entirely ideal as it *does* mean
Looking Glass submits buffers while hidden, but it seems better than
hanging on exit.
It also forces opengl:vsync and egl:vsync flags to off when running on
Wayland, as they are meaningless there.
2021-01-04 02:09:55 +00:00
|
|
|
.value.x_bool = false,
|
2019-05-21 05:03:59 +00:00
|
|
|
},
|
2019-05-27 08:39:21 +00:00
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "doubleBuffer",
|
|
|
|
.description = "Enable double buffering",
|
|
|
|
.type = OPTION_TYPE_BOOL,
|
2020-05-19 07:34:24 +00:00
|
|
|
.value.x_bool = false
|
2019-05-27 08:39:21 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.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
|
|
|
|
},
|
2020-11-08 19:59:54 +00:00
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "cbMode",
|
2020-11-08 20:42:59 +00:00
|
|
|
.description = "Color Blind Mode (0 = Off, 1 = Protanope, 2 = Deuteranope, 3 = Tritanope)",
|
2020-11-08 19:59:54 +00:00
|
|
|
.type = OPTION_TYPE_INT,
|
|
|
|
.value.x_int = 0
|
|
|
|
},
|
2021-02-22 05:03:50 +00:00
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "scale",
|
|
|
|
.description = "Set the scale algorithm (0 = auto, 1 = nearest, 2 = linear)",
|
|
|
|
.type = OPTION_TYPE_INT,
|
|
|
|
.validator = egl_desktop_scale_validate,
|
|
|
|
.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);
|
|
|
|
|
2021-01-14 06:05:26 +00:00
|
|
|
const char * egl_get_name(void)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
|
|
|
return "EGL";
|
|
|
|
}
|
|
|
|
|
2021-01-14 06:05:26 +00:00
|
|
|
void egl_setup(void)
|
2019-05-21 05:03:59 +00:00
|
|
|
{
|
|
|
|
option_register(egl_options);
|
|
|
|
}
|
|
|
|
|
2021-02-21 06:25:54 +00:00
|
|
|
static bool egl_update_font(struct Inst * this)
|
|
|
|
{
|
|
|
|
unsigned size = round(16.0f * this->uiScale);
|
|
|
|
if (size == this->fontSize)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
LG_FontObj fontObj;
|
|
|
|
if (!this->font->create(&fontObj, NULL, size))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to create a font instance");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->alert)
|
|
|
|
egl_alert_set_font(this->alert, fontObj);
|
|
|
|
|
|
|
|
if (this->fps)
|
|
|
|
egl_fps_set_font(this->fps, fontObj);
|
|
|
|
|
|
|
|
if (this->fontObj)
|
|
|
|
this->font->destroy(this->fontObj);
|
|
|
|
this->fontObj = fontObj;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool egl_update_help_font(struct Inst * this)
|
|
|
|
{
|
|
|
|
unsigned size = round(14.0f * this->uiScale);
|
|
|
|
if (size == this->helpFontSize)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
LG_FontObj fontObj;
|
|
|
|
if (!this->font->create(&fontObj, NULL, size))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to create a font instance");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->help)
|
|
|
|
egl_help_set_font(this->help, fontObj);
|
|
|
|
|
|
|
|
if (this->helpFontObj)
|
|
|
|
this->font->destroy(this->helpFontObj);
|
|
|
|
this->helpFontObj = fontObj;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-27 08:38:34 +00:00
|
|
|
bool egl_create(void ** opaque, const LG_RendererParams params, bool * needsOpenGL)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
2020-11-29 10:43:28 +00:00
|
|
|
// check if EGL is even available
|
|
|
|
if (!eglQueryString(EGL_NO_DISPLAY, EGL_VERSION))
|
|
|
|
return false;
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
// create our local storage
|
2021-02-21 14:38:26 +00:00
|
|
|
*opaque = calloc(1, sizeof(struct Inst));
|
2018-09-22 06:26:10 +00:00
|
|
|
if (!*opaque)
|
|
|
|
{
|
|
|
|
DEBUG_INFO("Failed to allocate %lu bytes", sizeof(struct Inst));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
2020-12-31 04:31:24 +00:00
|
|
|
this->opt.vsync = option_get_bool("egl", "vsync");
|
|
|
|
this->opt.doubleBuffer = option_get_bool("egl", "doubleBuffer");
|
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;
|
2021-02-21 06:25:54 +00:00
|
|
|
this->uiScale = 1.0;
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2021-07-11 01:20:08 +00:00
|
|
|
atomic_init(&this->desktopDamage, NULL);
|
|
|
|
|
2018-11-19 22:50:09 +00:00
|
|
|
this->font = LG_Fonts[0];
|
2021-02-21 06:25:54 +00:00
|
|
|
if (!egl_update_font(this))
|
2018-11-19 22:50:09 +00:00
|
|
|
return false;
|
|
|
|
|
2021-02-21 06:25:54 +00:00
|
|
|
if (!egl_update_help_font(this))
|
2021-01-31 11:13:34 +00:00
|
|
|
return false;
|
|
|
|
|
2021-01-27 08:38:34 +00:00
|
|
|
*needsOpenGL = false;
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-26 10:46:30 +00:00
|
|
|
bool egl_initialize(void * opaque)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
2020-12-31 04:31:24 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
DEBUG_INFO("Double buffering is %s", this->opt.doubleBuffer ? "on" : "off");
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_deinitialize(void * opaque)
|
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
2021-07-08 01:45:54 +00:00
|
|
|
if (this->imgui)
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
|
2021-01-31 11:13:34 +00:00
|
|
|
if (this->font)
|
|
|
|
{
|
|
|
|
if (this->fontObj)
|
|
|
|
this->font->destroy(this->fontObj);
|
|
|
|
|
|
|
|
if (this->helpFontObj)
|
|
|
|
this->font->destroy(this->helpFontObj);
|
|
|
|
}
|
|
|
|
|
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 );
|
2021-01-30 22:06:57 +00:00
|
|
|
egl_help_free (&this->help);
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2020-05-21 01:44:56 +00:00
|
|
|
LG_LOCK_FREE(this->lock);
|
|
|
|
|
2021-01-24 08:39:00 +00:00
|
|
|
eglMakeCurrent(this->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
if (this->frameContext)
|
|
|
|
eglDestroyContext(this->display, this->frameContext);
|
|
|
|
|
|
|
|
if (this->context)
|
|
|
|
eglDestroyContext(this->display, this->context);
|
|
|
|
|
|
|
|
eglTerminate(this->display);
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2020-10-29 15:32:25 +00:00
|
|
|
bool egl_supports(void * opaque, LG_RendererSupport flag)
|
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
|
|
|
switch(flag)
|
|
|
|
{
|
|
|
|
case LG_SUPPORTS_DMABUF:
|
|
|
|
return this->dmaSupport;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 04:30:44 +00:00
|
|
|
void egl_on_restart(void * opaque)
|
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
|
|
|
eglDestroyContext(this->display, this->frameContext);
|
|
|
|
this->frameContext = NULL;
|
2020-08-11 04:45:08 +00:00
|
|
|
this->start = false;
|
2020-08-11 04:30:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 15:44:56 +00:00
|
|
|
static void egl_calc_mouse_size(struct Inst * this)
|
|
|
|
{
|
2021-01-19 09:36:43 +00:00
|
|
|
if (!this->formatValid)
|
|
|
|
return;
|
|
|
|
|
2021-02-23 09:25:30 +00:00
|
|
|
int w = 0, h = 0;
|
|
|
|
|
2021-01-18 15:44:56 +00:00
|
|
|
switch(this->format.rotate)
|
|
|
|
{
|
|
|
|
case LG_ROTATE_0:
|
|
|
|
case LG_ROTATE_180:
|
|
|
|
this->mouseScaleX = 2.0f / this->format.width;
|
|
|
|
this->mouseScaleY = 2.0f / this->format.height;
|
|
|
|
w = this->format.width;
|
|
|
|
h = this->format.height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LG_ROTATE_90:
|
|
|
|
case LG_ROTATE_270:
|
|
|
|
this->mouseScaleX = 2.0f / this->format.height;
|
|
|
|
this->mouseScaleY = 2.0f / this->format.width;
|
|
|
|
w = this->format.height;
|
|
|
|
h = this->format.width;
|
|
|
|
break;
|
2021-01-19 15:06:49 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
assert(!"unreachable");
|
2021-01-18 15:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch((this->format.rotate + this->rotate) % LG_ROTATE_MAX)
|
|
|
|
{
|
|
|
|
case LG_ROTATE_0:
|
|
|
|
case LG_ROTATE_180:
|
|
|
|
egl_cursor_set_size(this->cursor,
|
|
|
|
(this->mouseWidth * (1.0f / w)) * this->scaleX,
|
|
|
|
(this->mouseHeight * (1.0f / h)) * this->scaleY
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LG_ROTATE_90:
|
|
|
|
case LG_ROTATE_270:
|
|
|
|
egl_cursor_set_size(this->cursor,
|
|
|
|
(this->mouseWidth * (1.0f / w)) * this->scaleY,
|
|
|
|
(this->mouseHeight * (1.0f / h)) * this->scaleX
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void egl_calc_mouse_state(struct Inst * this)
|
|
|
|
{
|
2021-01-19 09:36:43 +00:00
|
|
|
if (!this->formatValid)
|
|
|
|
return;
|
|
|
|
|
2021-01-18 15:44:56 +00:00
|
|
|
switch((this->format.rotate + this->rotate) % LG_ROTATE_MAX)
|
|
|
|
{
|
|
|
|
case LG_ROTATE_0:
|
|
|
|
case LG_ROTATE_180:
|
|
|
|
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
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LG_ROTATE_90:
|
|
|
|
case LG_ROTATE_270:
|
|
|
|
egl_cursor_set_state(
|
|
|
|
this->cursor,
|
|
|
|
this->cursorVisible,
|
|
|
|
(((float)this->cursorX * this->mouseScaleX) - 1.0f) * this->scaleY,
|
|
|
|
(((float)this->cursorY * this->mouseScaleY) - 1.0f) * this->scaleX
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-21 00:50:59 +00:00
|
|
|
static void egl_update_scale_type(struct Inst * this)
|
|
|
|
{
|
2021-02-21 14:38:26 +00:00
|
|
|
int width = 0, height = 0;
|
2021-02-21 00:50:59 +00:00
|
|
|
|
|
|
|
switch (this->rotate)
|
|
|
|
{
|
|
|
|
case LG_ROTATE_0:
|
|
|
|
case LG_ROTATE_180:
|
|
|
|
width = this->format.width;
|
|
|
|
height = this->format.height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LG_ROTATE_90:
|
|
|
|
case LG_ROTATE_270:
|
|
|
|
width = this->format.height;
|
|
|
|
height = this->format.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width == this->viewportWidth || height == this->viewportHeight)
|
|
|
|
this->scaleType = EGL_DESKTOP_NOSCALE;
|
|
|
|
else if (width > this->viewportWidth || height > this->viewportHeight)
|
|
|
|
this->scaleType = EGL_DESKTOP_DOWNSCALE;
|
|
|
|
else
|
|
|
|
this->scaleType = EGL_DESKTOP_UPSCALE;
|
|
|
|
}
|
|
|
|
|
2021-02-21 05:08:52 +00:00
|
|
|
void egl_on_resize(void * opaque, const int width, const int height, const double scale,
|
2021-01-18 15:44:56 +00:00
|
|
|
const LG_RendererRect destRect, LG_RendererRotate rotate)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
2018-09-24 09:48:11 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
2021-02-21 06:25:54 +00:00
|
|
|
this->width = width * scale;
|
|
|
|
this->height = height * scale;
|
|
|
|
this->uiScale = (float) scale;
|
|
|
|
this->rotate = rotate;
|
2021-01-18 15:44:56 +00:00
|
|
|
|
2021-02-21 05:47:38 +00:00
|
|
|
this->destRect.x = destRect.x * scale;
|
|
|
|
this->destRect.y = destRect.y * scale;
|
|
|
|
this->destRect.w = destRect.w * scale;
|
|
|
|
this->destRect.h = destRect.h * scale;
|
2018-11-19 22:50:09 +00:00
|
|
|
|
2021-02-21 05:47:38 +00:00
|
|
|
glViewport(0, 0, this->width, this->height);
|
2018-09-24 09:48:11 +00:00
|
|
|
|
2018-10-03 16:31:37 +00:00
|
|
|
if (destRect.valid)
|
|
|
|
{
|
2021-02-21 05:47:38 +00:00
|
|
|
this->translateX = 1.0f - (((this->destRect.w / 2) + this->destRect.x) * 2) / (float)this->width;
|
|
|
|
this->translateY = 1.0f - (((this->destRect.h / 2) + this->destRect.y) * 2) / (float)this->height;
|
|
|
|
this->scaleX = (float)this->destRect.w / (float)this->width;
|
|
|
|
this->scaleY = (float)this->destRect.h / (float)this->height;
|
|
|
|
this->viewportWidth = this->destRect.w;
|
|
|
|
this->viewportHeight = this->destRect.h;
|
2018-10-03 16:31:37 +00:00
|
|
|
}
|
|
|
|
|
2021-02-21 00:50:59 +00:00
|
|
|
egl_update_scale_type(this);
|
2021-01-18 15:44:56 +00:00
|
|
|
egl_calc_mouse_size(this);
|
2018-12-15 13:54:37 +00:00
|
|
|
|
2018-12-15 23:57:01 +00:00
|
|
|
this->splashRatio = (float)width / (float)height;
|
2021-02-21 05:47:38 +00:00
|
|
|
this->screenScaleX = 1.0f / this->width;
|
|
|
|
this->screenScaleY = 1.0f / this->height;
|
2019-05-28 04:06:15 +00:00
|
|
|
|
2021-01-18 15:44:56 +00:00
|
|
|
egl_calc_mouse_state(this);
|
2021-02-21 06:25:54 +00:00
|
|
|
egl_update_font(this);
|
|
|
|
egl_update_help_font(this);
|
2021-05-11 20:49:39 +00:00
|
|
|
|
|
|
|
this->cursorLastValid = false;
|
2021-07-11 01:20:08 +00:00
|
|
|
|
|
|
|
struct DesktopDamage * damage = malloc(sizeof(struct DesktopDamage));
|
|
|
|
if (!damage)
|
|
|
|
{
|
|
|
|
DEBUG_FATAL("Out of memory");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
damage->count = 0;
|
|
|
|
free(atomic_exchange(&this->desktopDamage, damage));
|
2018-09-22 06:26:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 01:40:59 +00:00
|
|
|
bool egl_on_mouse_shape(void * opaque, const LG_RendererCursor cursor,
|
2021-01-18 15:44:56 +00:00
|
|
|
const int width, const int height,
|
2021-01-15 01:40:59 +00:00
|
|
|
const int pitch, const uint8_t * data)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
2018-09-24 09:48:11 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
2021-01-18 15:44:56 +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;
|
2021-01-18 15:44:56 +00:00
|
|
|
egl_calc_mouse_size(this);
|
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;
|
2021-01-18 15:44:56 +00:00
|
|
|
egl_calc_mouse_state(this);
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-29 15:32:25 +00:00
|
|
|
bool egl_on_frame_format(void * opaque, const LG_RendererFormat format, bool useDMA)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
2020-10-12 08:43:29 +00:00
|
|
|
memcpy(&this->format, &format, sizeof(LG_RendererFormat));
|
2021-01-19 09:36:43 +00:00
|
|
|
this->formatValid = true;
|
2019-04-19 01:23:51 +00:00
|
|
|
|
2020-05-22 07:47:19 +00:00
|
|
|
/* this event runs in a second thread so we need to init it here */
|
|
|
|
if (!this->frameContext)
|
|
|
|
{
|
|
|
|
static EGLint attrs[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!(this->frameContext = eglCreateContext(this->display, this->configs, this->context, attrs)))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to create the frame context");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglMakeCurrent(this->display, EGL_NO_SURFACE, EGL_NO_SURFACE, this->frameContext))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to make the frame context current");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-21 00:50:59 +00:00
|
|
|
egl_update_scale_type(this);
|
2020-10-29 15:32:25 +00:00
|
|
|
return egl_desktop_setup(this->desktop, format, useDMA);
|
2020-10-12 08:43:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 01:20:08 +00:00
|
|
|
bool egl_on_frame(void * opaque, const FrameBuffer * frame, int dmaFd,
|
|
|
|
const FrameDamageRect * damageRects, int damageRectsCount)
|
2020-10-12 08:43:29 +00:00
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
2020-10-29 15:32:25 +00:00
|
|
|
if (!egl_desktop_update(this->desktop, frame, dmaFd))
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
2020-05-21 01:44:56 +00:00
|
|
|
DEBUG_INFO("Failed to to update the desktop");
|
2018-12-12 10:41:51 +00:00
|
|
|
return false;
|
2018-09-23 05:48:44 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 04:45:08 +00:00
|
|
|
this->start = true;
|
2021-05-11 20:49:39 +00:00
|
|
|
this->cursorLastValid = false;
|
2021-07-11 01:20:08 +00:00
|
|
|
|
|
|
|
struct DesktopDamage * damage = malloc(sizeof(struct DesktopDamage));
|
|
|
|
if (!damage)
|
|
|
|
{
|
|
|
|
DEBUG_FATAL("Out of memory");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
damage->count = damageRectsCount;
|
|
|
|
memcpy(damage->rects, damageRects, damageRectsCount * sizeof(FrameDamageRect));
|
|
|
|
free(atomic_exchange(&this->desktopDamage, damage));
|
|
|
|
|
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;
|
2021-05-11 20:49:39 +00:00
|
|
|
this->cursorLastValid = false;
|
2018-09-22 06:26:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 09:38:52 +00:00
|
|
|
void egl_on_help(void * opaque, const char * message)
|
|
|
|
{
|
2021-01-30 22:06:57 +00:00
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
egl_help_set_text(this->help, message);
|
2021-05-11 20:49:39 +00:00
|
|
|
this->cursorLastValid = false;
|
2021-01-30 09:38:52 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 03:09:03 +00:00
|
|
|
void egl_on_show_fps(void * opaque, bool showFPS)
|
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
egl_fps_set_display(this->fps, showFPS);
|
|
|
|
}
|
|
|
|
|
2021-01-26 10:46:30 +00:00
|
|
|
bool egl_render_startup(void * opaque)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
2021-01-26 10:46:30 +00:00
|
|
|
this->nativeWind = app_getEGLNativeWindow();
|
|
|
|
if (!this->nativeWind)
|
2018-09-22 06:26:10 +00:00
|
|
|
return false;
|
2021-01-25 05:04:33 +00:00
|
|
|
|
2021-01-26 10:46:30 +00:00
|
|
|
this->display = app_getEGLDisplay();
|
2018-09-22 06:26:10 +00:00
|
|
|
if (this->display == EGL_NO_DISPLAY)
|
|
|
|
return false;
|
|
|
|
|
2020-10-29 15:32:25 +00:00
|
|
|
int maj, min;
|
|
|
|
if (!eglInitialize(this->display, &maj, &min))
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Unable to initialize EGL");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-15 09:30:03 +00:00
|
|
|
int maxSamples = 1;
|
|
|
|
if (option_get_bool("egl", "multisample"))
|
|
|
|
{
|
|
|
|
if (app_getProp(LG_DS_MAX_MULTISAMPLE, &maxSamples) && maxSamples > 1)
|
|
|
|
{
|
|
|
|
if (maxSamples > 4)
|
|
|
|
maxSamples = 4;
|
|
|
|
|
|
|
|
DEBUG_INFO("Multisampling enabled, max samples: %d", maxSamples);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
EGLint attr[] =
|
|
|
|
{
|
2021-01-31 04:56:12 +00:00
|
|
|
EGL_BUFFER_SIZE , 24,
|
2018-09-25 13:04:29 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
2021-01-15 09:30:03 +00:00
|
|
|
EGL_SAMPLE_BUFFERS , maxSamples > 0 ? 1 : 0,
|
|
|
|
EGL_SAMPLES , maxSamples,
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-31 04:31:24 +00:00
|
|
|
const EGLint surfattr[] =
|
|
|
|
{
|
|
|
|
EGL_RENDER_BUFFER, this->opt.doubleBuffer ? EGL_BACK_BUFFER : EGL_SINGLE_BUFFER,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
this->surface = eglCreateWindowSurface(this->display, this->configs, this->nativeWind, surfattr);
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-31 04:31:24 +00:00
|
|
|
EGLint rb = 0;
|
|
|
|
eglQuerySurface(this->display, this->surface, EGL_RENDER_BUFFER, &rb);
|
|
|
|
switch(rb)
|
|
|
|
{
|
|
|
|
case EGL_SINGLE_BUFFER:
|
|
|
|
DEBUG_INFO("Single buffer mode");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EGL_BACK_BUFFER:
|
|
|
|
DEBUG_INFO("Back buffer mode");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_WARN("Unknown render buffer mode: %d", rb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
eglMakeCurrent(this->display, this->surface, this->surface, this->context);
|
2020-10-29 15:32:25 +00:00
|
|
|
const char *client_exts = eglQueryString(this->display, EGL_EXTENSIONS);
|
2021-01-09 10:25:41 +00:00
|
|
|
const char *vendor = (const char *)glGetString(GL_VENDOR);
|
2020-10-29 15:32:25 +00:00
|
|
|
|
|
|
|
DEBUG_INFO("EGL : %d.%d", maj, min);
|
2021-01-09 10:25:41 +00:00
|
|
|
DEBUG_INFO("Vendor : %s", vendor);
|
2020-10-29 15:32:25 +00:00
|
|
|
DEBUG_INFO("Renderer : %s", glGetString(GL_RENDERER));
|
|
|
|
DEBUG_INFO("Version : %s", glGetString(GL_VERSION ));
|
|
|
|
DEBUG_INFO("EGL APIs : %s", eglQueryString(this->display, EGL_CLIENT_APIS));
|
|
|
|
DEBUG_INFO("Extensions: %s", client_exts);
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2021-01-26 10:46:30 +00:00
|
|
|
if (g_egl_dynProcs.glEGLImageTargetTexture2DOES)
|
2021-01-24 01:05:18 +00:00
|
|
|
{
|
2021-05-13 20:36:01 +00:00
|
|
|
if (util_hasGLExt(client_exts, "EGL_EXT_image_dma_buf_import"))
|
2021-01-24 01:05:18 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* As of version 455.45.01 NVidia started advertising support for this
|
|
|
|
* feature, however even on the latest version 460.27.04 this is still
|
|
|
|
* broken and does not work, until this is fixed and we have way to detect
|
|
|
|
* this early just disable dma for all NVIDIA devices.
|
|
|
|
*
|
|
|
|
* ref: https://forums.developer.nvidia.com/t/egl-ext-image-dma-buf-import-broken-egl-bad-alloc-with-tons-of-free-ram/165552
|
|
|
|
*/
|
2021-01-24 08:19:43 +00:00
|
|
|
if (strstr(vendor, "NVIDIA") != NULL)
|
|
|
|
DEBUG_WARN("NVIDIA driver detected, ignoring broken DMA support");
|
|
|
|
else
|
2021-01-24 01:05:18 +00:00
|
|
|
this->dmaSupport = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUG_INFO("glEGLImageTargetTexture2DOES unavilable, DMA support disabled");
|
2021-01-09 10:25:41 +00:00
|
|
|
}
|
2018-09-22 06:26:10 +00:00
|
|
|
|
2018-12-12 10:41:51 +00:00
|
|
|
eglSwapInterval(this->display, this->opt.vsync ? 1 : 0);
|
2018-09-23 05:48:44 +00:00
|
|
|
|
2020-10-29 15:32:25 +00:00
|
|
|
if (!egl_desktop_init(&this->desktop, this->display))
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-01-31 11:13:34 +00:00
|
|
|
if (!egl_help_init(&this->help, this->font, this->helpFontObj))
|
2021-01-30 22:06:57 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the alert display");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-08 01:45:54 +00:00
|
|
|
// glew is needed for imgui
|
|
|
|
if (!glewInit())
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("GLEW failed to initialize");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ImGui_ImplOpenGL3_Init("#version 100"))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize ImGui");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->imgui = true;
|
2018-09-22 06:26:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-26 10:46:30 +00:00
|
|
|
bool egl_render(void * opaque, LG_RendererRotate rotate)
|
2018-09-22 06:26:10 +00:00
|
|
|
{
|
|
|
|
struct Inst * this = (struct Inst *)opaque;
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
2021-05-11 20:49:39 +00:00
|
|
|
bool hasLastCursor = this->cursorLastValid;
|
|
|
|
bool cursorRendered = false;
|
2021-07-11 07:52:41 +00:00
|
|
|
bool hasOverlay = false;
|
2021-05-11 20:49:39 +00:00
|
|
|
struct CursorState cursorState;
|
2021-07-11 01:20:08 +00:00
|
|
|
struct DesktopDamage * desktopDamage = NULL;
|
2021-05-11 20:49:39 +00:00
|
|
|
|
2021-07-11 01:20:08 +00:00
|
|
|
if (this->start)
|
|
|
|
{
|
|
|
|
desktopDamage = atomic_exchange(&this->desktopDamage, NULL);
|
|
|
|
if (egl_desktop_render(this->desktop,
|
2020-08-11 04:45:08 +00:00
|
|
|
this->translateX, this->translateY,
|
|
|
|
this->scaleX , this->scaleY ,
|
2021-02-21 00:50:59 +00:00
|
|
|
this->scaleType , rotate))
|
2020-07-19 04:29:29 +00:00
|
|
|
{
|
2021-07-11 01:20:08 +00:00
|
|
|
if (!this->waitFadeTime)
|
|
|
|
{
|
|
|
|
if (!this->params.quickSplash)
|
|
|
|
this->waitFadeTime = microtime() + SPLASH_FADE_TIME;
|
|
|
|
else
|
|
|
|
this->waitDone = true;
|
|
|
|
}
|
2021-01-18 15:44:56 +00:00
|
|
|
|
2021-07-11 01:20:08 +00:00
|
|
|
cursorRendered = true;
|
|
|
|
cursorState = egl_cursor_get_state(this->cursor, this->width, this->height);
|
|
|
|
egl_cursor_render(this->cursor,
|
|
|
|
(this->format.rotate + rotate) % LG_ROTATE_MAX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
desktopDamage->count = 0;
|
2019-06-12 12:36:00 +00:00
|
|
|
}
|
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)
|
2021-07-11 07:52:41 +00:00
|
|
|
{
|
2019-01-01 23:36:17 +00:00
|
|
|
egl_splash_render(this->splash, a, this->splashRatio);
|
2021-07-11 07:52:41 +00:00
|
|
|
hasOverlay = true;
|
|
|
|
}
|
2018-12-15 23:57:01 +00:00
|
|
|
}
|
2021-07-11 07:52:41 +00:00
|
|
|
else if (!this->start)
|
2020-08-11 04:54:48 +00:00
|
|
|
{
|
2021-07-11 07:52:41 +00:00
|
|
|
egl_splash_render(this->splash, 1.0f, this->splashRatio);
|
|
|
|
hasOverlay = true;
|
2020-08-11 04:54:48 +00:00
|
|
|
}
|
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)
|
2021-05-11 20:49:39 +00:00
|
|
|
{
|
2018-12-15 23:57:01 +00:00
|
|
|
this->showAlert = false;
|
2021-05-11 20:49:39 +00:00
|
|
|
this->cursorLastValid = false;
|
|
|
|
}
|
2018-12-15 23:57:01 +00:00
|
|
|
else
|
2021-07-11 07:52:41 +00:00
|
|
|
{
|
2018-12-15 23:57:01 +00:00
|
|
|
egl_alert_render(this->alert, this->screenScaleX, this->screenScaleY);
|
2021-07-11 07:52:41 +00:00
|
|
|
hasOverlay = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hasOverlay |= egl_fps_render(this->fps, this->screenScaleX, this->screenScaleY);
|
|
|
|
hasOverlay |= egl_help_render(this->help, this->screenScaleX, this->screenScaleY);
|
|
|
|
|
|
|
|
if (app_renderImGui())
|
|
|
|
{
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());
|
|
|
|
hasOverlay = true;
|
2018-12-15 13:54:37 +00:00
|
|
|
}
|
|
|
|
|
2021-07-11 01:20:08 +00:00
|
|
|
struct Rect damage[KVMFR_MAX_DAMAGE_RECTS + 2];
|
2021-05-11 20:49:39 +00:00
|
|
|
int damageIdx = 0;
|
|
|
|
|
2021-07-11 07:52:41 +00:00
|
|
|
if (!hasOverlay && !this->hadOverlay)
|
2021-05-11 20:49:39 +00:00
|
|
|
{
|
|
|
|
if (cursorRendered && hasLastCursor)
|
|
|
|
{
|
|
|
|
if (this->cursorLast.visible)
|
|
|
|
damage[damageIdx++] = this->cursorLast.rect;
|
|
|
|
|
|
|
|
if (cursorState.visible)
|
|
|
|
damage[damageIdx++] = cursorState.rect;
|
|
|
|
|
|
|
|
this->cursorLast = cursorState;
|
|
|
|
}
|
|
|
|
else if (cursorRendered)
|
|
|
|
{
|
|
|
|
this->cursorLast = cursorState;
|
|
|
|
this->cursorLastValid = true;
|
2021-07-11 01:20:08 +00:00
|
|
|
|
|
|
|
if (cursorState.visible)
|
|
|
|
damage[damageIdx++] = cursorState.rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desktopDamage)
|
|
|
|
{
|
|
|
|
if (desktopDamage->count == 0)
|
|
|
|
// Zero damage count means invalidating entire window.
|
|
|
|
damageIdx = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double scaleX = (double) this->destRect.w / this->format.width;
|
|
|
|
double scaleY = (double) this->destRect.h / this->format.height;
|
|
|
|
for (int i = 0; i < desktopDamage->count; ++i)
|
|
|
|
{
|
|
|
|
FrameDamageRect rect = desktopDamage->rects[i];
|
|
|
|
int x1 = (int) (rect.x * scaleX);
|
|
|
|
int y1 = (int) (rect.y * scaleY);
|
|
|
|
int x2 = (int) ceil((rect.x + rect.width) * scaleX);
|
|
|
|
int y2 = (int) ceil((rect.y + rect.height) * scaleY);
|
|
|
|
damage[damageIdx++] = (struct Rect) {
|
|
|
|
.x = this->destRect.x + x1,
|
|
|
|
.y = this->height - (this->destRect.y + y2),
|
|
|
|
.w = x2 - x1,
|
|
|
|
.h = y2 - y1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 20:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-11 07:52:41 +00:00
|
|
|
this->hadOverlay = hasOverlay;
|
2021-07-08 01:45:54 +00:00
|
|
|
|
2021-05-11 20:49:39 +00:00
|
|
|
app_eglSwapBuffers(this->display, this->surface, damage, damageIdx);
|
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;
|
2018-12-12 12:59:22 +00:00
|
|
|
egl_fps_update(this->fps, avgUPS, avgFPS);
|
2021-05-11 20:49:39 +00:00
|
|
|
this->cursorLastValid = false;
|
2018-11-19 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 06:26:10 +00:00
|
|
|
struct LG_Renderer LGR_EGL =
|
|
|
|
{
|
2020-10-12 08:43:29 +00:00
|
|
|
.get_name = egl_get_name,
|
|
|
|
.setup = egl_setup,
|
|
|
|
.create = egl_create,
|
|
|
|
.initialize = egl_initialize,
|
|
|
|
.deinitialize = egl_deinitialize,
|
2020-10-29 15:32:25 +00:00
|
|
|
.supports = egl_supports,
|
2020-10-12 08:43:29 +00:00
|
|
|
.on_restart = egl_on_restart,
|
|
|
|
.on_resize = egl_on_resize,
|
|
|
|
.on_mouse_shape = egl_on_mouse_shape,
|
|
|
|
.on_mouse_event = egl_on_mouse_event,
|
|
|
|
.on_frame_format = egl_on_frame_format,
|
|
|
|
.on_frame = egl_on_frame,
|
|
|
|
.on_alert = egl_on_alert,
|
2021-01-30 09:38:52 +00:00
|
|
|
.on_help = egl_on_help,
|
2021-02-01 03:09:03 +00:00
|
|
|
.on_show_fps = egl_on_show_fps,
|
2020-10-12 08:43:29 +00:00
|
|
|
.render_startup = egl_render_startup,
|
|
|
|
.render = egl_render,
|
|
|
|
.update_fps = egl_update_fps
|
2020-01-17 00:50:00 +00:00
|
|
|
};
|