2021-06-06 01:26:18 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2022-01-05 08:42:46 +00:00
|
|
|
* Copyright © 2017-2022 The Looking Glass Authors
|
2021-06-06 01:26:18 +00:00
|
|
|
* 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-12-12 10:41:51 +00:00
|
|
|
|
|
|
|
#include "desktop.h"
|
2019-04-11 01:12:59 +00:00
|
|
|
#include "common/debug.h"
|
2019-05-23 06:32:18 +00:00
|
|
|
#include "common/option.h"
|
2020-01-17 03:35:08 +00:00
|
|
|
#include "common/locking.h"
|
2021-08-09 04:08:10 +00:00
|
|
|
#include "common/array.h"
|
2018-12-12 10:41:51 +00:00
|
|
|
|
2021-01-25 15:33:28 +00:00
|
|
|
#include "app.h"
|
2018-12-12 10:41:51 +00:00
|
|
|
#include "texture.h"
|
|
|
|
#include "shader.h"
|
2021-08-03 00:45:47 +00:00
|
|
|
#include "desktop_rects.h"
|
2021-08-06 07:48:07 +00:00
|
|
|
#include "cimgui.h"
|
2018-12-12 10:41:51 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-03-28 03:59:54 +00:00
|
|
|
// these headers are auto generated by cmake
|
|
|
|
#include "desktop.vert.h"
|
|
|
|
#include "desktop_rgb.frag.h"
|
2021-02-22 04:56:51 +00:00
|
|
|
#include "desktop_rgb.def.h"
|
2021-02-21 00:50:59 +00:00
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
#include "postprocess.h"
|
|
|
|
#include "filters.h"
|
2021-08-09 12:42:51 +00:00
|
|
|
|
2019-05-22 01:36:18 +00:00
|
|
|
struct DesktopShader
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
2019-05-22 01:36:18 +00:00
|
|
|
EGL_Shader * shader;
|
2021-08-03 00:45:47 +00:00
|
|
|
GLint uTransform;
|
2019-04-19 01:23:51 +00:00
|
|
|
GLint uDesktopSize;
|
2021-02-21 00:50:59 +00:00
|
|
|
GLint uScaleAlgo;
|
2021-08-09 04:08:10 +00:00
|
|
|
GLint uNVGain;
|
2020-11-08 19:59:54 +00:00
|
|
|
GLint uCBMode;
|
2019-05-22 01:36:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct EGL_Desktop
|
|
|
|
{
|
2021-08-09 04:08:10 +00:00
|
|
|
EGL * egl;
|
2020-10-29 15:32:25 +00:00
|
|
|
EGLDisplay * display;
|
2020-05-21 01:44:56 +00:00
|
|
|
|
2019-05-22 01:36:18 +00:00
|
|
|
EGL_Texture * texture;
|
2021-08-09 04:08:10 +00:00
|
|
|
struct DesktopShader shader;
|
2021-08-03 00:45:47 +00:00
|
|
|
EGL_DesktopRects * mesh;
|
2021-08-09 04:08:10 +00:00
|
|
|
CountedBuffer * matrix;
|
2019-05-22 01:36:18 +00:00
|
|
|
|
2020-05-21 01:44:56 +00:00
|
|
|
// internals
|
2021-01-15 01:40:59 +00:00
|
|
|
int width, height;
|
|
|
|
LG_RendererRotate rotate;
|
2020-05-21 01:44:56 +00:00
|
|
|
|
2021-02-22 04:56:51 +00:00
|
|
|
// scale algorithm
|
|
|
|
int scaleAlgo;
|
|
|
|
|
2019-03-28 13:15:14 +00:00
|
|
|
// night vision
|
2021-01-25 15:33:28 +00:00
|
|
|
int nvMax;
|
|
|
|
int nvGain;
|
2020-11-08 19:59:54 +00:00
|
|
|
|
|
|
|
// colorblind mode
|
2021-01-25 15:33:28 +00:00
|
|
|
int cbMode;
|
2021-08-07 23:49:55 +00:00
|
|
|
|
|
|
|
bool useDMA;
|
|
|
|
LG_RendererFormat format;
|
2021-08-09 12:42:51 +00:00
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
EGL_PostProcess * pp;
|
|
|
|
_Atomic(bool) processFrame;
|
2018-12-12 10:41:51 +00:00
|
|
|
};
|
|
|
|
|
2019-03-28 13:15:14 +00:00
|
|
|
// forwards
|
2021-08-10 03:10:51 +00:00
|
|
|
void toggleNV(int key, void * opaque);
|
2019-03-28 13:15:14 +00:00
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
static bool egl_initDesktopShader(
|
2019-05-22 01:36:18 +00:00
|
|
|
struct DesktopShader * shader,
|
|
|
|
const char * vertex_code , size_t vertex_size,
|
|
|
|
const char * fragment_code, size_t fragment_size
|
|
|
|
)
|
|
|
|
{
|
2021-08-08 07:16:10 +00:00
|
|
|
if (!egl_shaderInit(&shader->shader))
|
2019-05-22 01:36:18 +00:00
|
|
|
return false;
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
if (!egl_shaderCompile(shader->shader,
|
2019-05-22 01:36:18 +00:00
|
|
|
vertex_code , vertex_size,
|
|
|
|
fragment_code, fragment_size))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-10 03:08:54 +00:00
|
|
|
shader->uTransform = egl_shaderGetUniform(shader->shader, "transform" );
|
|
|
|
shader->uDesktopSize = egl_shaderGetUniform(shader->shader, "desktopSize");
|
|
|
|
shader->uScaleAlgo = egl_shaderGetUniform(shader->shader, "scaleAlgo" );
|
|
|
|
shader->uNVGain = egl_shaderGetUniform(shader->shader, "nvGain" );
|
|
|
|
shader->uCBMode = egl_shaderGetUniform(shader->shader, "cbMode" );
|
2019-05-22 01:36:18 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:48:41 +00:00
|
|
|
bool egl_desktopInit(EGL * egl, EGL_Desktop ** desktop_, EGLDisplay * display,
|
2021-08-09 04:08:10 +00:00
|
|
|
bool useDMA, int maxRects)
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
2021-08-15 22:55:19 +00:00
|
|
|
EGL_Desktop * desktop = calloc(1, sizeof(EGL_Desktop));
|
2021-08-09 14:48:41 +00:00
|
|
|
if (!desktop)
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to malloc EGL_Desktop");
|
|
|
|
return false;
|
|
|
|
}
|
2021-08-09 14:48:41 +00:00
|
|
|
*desktop_ = desktop;
|
2018-12-12 10:41:51 +00:00
|
|
|
|
2021-08-09 14:48:41 +00:00
|
|
|
desktop->egl = egl;
|
|
|
|
desktop->display = display;
|
2018-12-12 10:41:51 +00:00
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
if (!egl_textureInit(&desktop->texture, display,
|
2021-08-02 13:37:33 +00:00
|
|
|
useDMA ? EGL_TEXTYPE_DMABUF : EGL_TEXTYPE_FRAMEBUFFER, true))
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the desktop texture");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
if (!egl_initDesktopShader(
|
2021-08-09 14:48:41 +00:00
|
|
|
&desktop->shader,
|
2019-05-22 01:36:18 +00:00
|
|
|
b_shader_desktop_vert , b_shader_desktop_vert_size,
|
|
|
|
b_shader_desktop_rgb_frag, b_shader_desktop_rgb_frag_size))
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the generic desktop shader");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:48:41 +00:00
|
|
|
if (!egl_desktopRectsInit(&desktop->mesh, maxRects))
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
2021-08-03 00:45:47 +00:00
|
|
|
DEBUG_ERROR("Failed to initialize the desktop mesh");
|
2018-12-12 10:41:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:48:41 +00:00
|
|
|
desktop->matrix = countedBufferNew(6 * sizeof(GLfloat));
|
|
|
|
if (!desktop->matrix)
|
2021-08-09 04:08:10 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate the desktop matrix buffer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-10 03:10:51 +00:00
|
|
|
app_registerKeybind(KEY_N, toggleNV, desktop,
|
2021-08-09 14:48:41 +00:00
|
|
|
"Toggle night vision mode");
|
2019-03-28 13:15:14 +00:00
|
|
|
|
2021-08-09 14:48:41 +00:00
|
|
|
desktop->nvMax = option_get_int("egl", "nvGainMax");
|
|
|
|
desktop->nvGain = option_get_int("egl", "nvGain" );
|
|
|
|
desktop->cbMode = option_get_int("egl", "cbMode" );
|
|
|
|
desktop->scaleAlgo = option_get_int("egl", "scale" );
|
|
|
|
desktop->useDMA = useDMA;
|
2019-05-23 06:32:18 +00:00
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
if (!egl_postProcessInit(&desktop->pp))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the post process manager");
|
|
|
|
return false;
|
|
|
|
}
|
2021-08-09 12:42:51 +00:00
|
|
|
|
2021-08-12 05:53:35 +00:00
|
|
|
egl_postProcessAdd(desktop->pp, &egl_filterDownscaleOps);
|
|
|
|
egl_postProcessAdd(desktop->pp, &egl_filterFFXCASOps );
|
|
|
|
egl_postProcessAdd(desktop->pp, &egl_filterFFXFSR1Ops );
|
2018-12-12 10:41:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-10 03:10:51 +00:00
|
|
|
void toggleNV(int key, void * opaque)
|
2019-03-28 13:15:14 +00:00
|
|
|
{
|
|
|
|
EGL_Desktop * desktop = (EGL_Desktop *)opaque;
|
2019-05-23 06:32:18 +00:00
|
|
|
if (desktop->nvGain++ == desktop->nvMax)
|
2019-03-28 13:15:14 +00:00
|
|
|
desktop->nvGain = 0;
|
2019-03-30 01:26:06 +00:00
|
|
|
|
2019-03-30 13:08:52 +00:00
|
|
|
if (desktop->nvGain == 0) app_alert(LG_ALERT_INFO, "NV Disabled");
|
|
|
|
else if (desktop->nvGain == 1) app_alert(LG_ALERT_INFO, "NV Enabled");
|
|
|
|
else app_alert(LG_ALERT_INFO, "NV Gain + %d", desktop->nvGain - 1);
|
2021-08-07 22:41:08 +00:00
|
|
|
|
|
|
|
app_invalidateWindow(true);
|
2019-03-28 13:15:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
bool egl_desktopScaleValidate(struct Option * opt, const char ** error)
|
2021-02-22 05:03:50 +00:00
|
|
|
{
|
|
|
|
if (opt->value.x_int >= 0 && opt->value.x_int < EGL_SCALE_MAX)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
*error = "Invalid scale algorithm number";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
void egl_desktopFree(EGL_Desktop ** desktop)
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
|
|
|
if (!*desktop)
|
|
|
|
return;
|
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
egl_textureFree (&(*desktop)->texture );
|
|
|
|
egl_shaderFree (&(*desktop)->shader.shader);
|
|
|
|
egl_desktopRectsFree(&(*desktop)->mesh );
|
|
|
|
countedBufferRelease(&(*desktop)->matrix );
|
2021-08-10 03:08:54 +00:00
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
egl_postProcessFree(&(*desktop)->pp);
|
2018-12-12 10:41:51 +00:00
|
|
|
|
|
|
|
free(*desktop);
|
|
|
|
*desktop = NULL;
|
|
|
|
}
|
|
|
|
|
2021-08-06 07:48:07 +00:00
|
|
|
static const char * algorithmNames[EGL_SCALE_MAX] = {
|
|
|
|
[EGL_SCALE_AUTO] = "Automatic (downscale: linear, upscale: nearest)",
|
|
|
|
[EGL_SCALE_NEAREST] = "Nearest",
|
|
|
|
[EGL_SCALE_LINEAR] = "Linear",
|
|
|
|
};
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
void egl_desktopConfigUI(EGL_Desktop * desktop)
|
2021-08-06 07:48:07 +00:00
|
|
|
{
|
|
|
|
igText("Scale algorithm:");
|
|
|
|
igPushItemWidth(igGetWindowWidth() - igGetStyle()->WindowPadding.x * 2);
|
|
|
|
if (igBeginCombo("##scale", algorithmNames[desktop->scaleAlgo], 0))
|
|
|
|
{
|
|
|
|
for (int i = 0; i < EGL_SCALE_MAX; ++i)
|
|
|
|
{
|
|
|
|
bool selected = i == desktop->scaleAlgo;
|
2022-01-07 13:26:12 +00:00
|
|
|
if (igSelectable_Bool(algorithmNames[i], selected, 0,
|
|
|
|
(ImVec2) { 0.0f, 0.0f }))
|
2021-08-06 07:48:07 +00:00
|
|
|
desktop->scaleAlgo = i;
|
|
|
|
if (selected)
|
|
|
|
igSetItemDefaultFocus();
|
|
|
|
}
|
|
|
|
igEndCombo();
|
|
|
|
}
|
|
|
|
igPopItemWidth();
|
2021-08-07 10:31:05 +00:00
|
|
|
|
|
|
|
igText("Night vision mode:");
|
|
|
|
igSameLine(0.0f, -1.0f);
|
|
|
|
igPushItemWidth(igGetWindowWidth() - igGetCursorPosX() - igGetStyle()->WindowPadding.x);
|
|
|
|
|
|
|
|
const char * format;
|
|
|
|
switch (desktop->nvGain)
|
|
|
|
{
|
|
|
|
case 0: format = "off"; break;
|
|
|
|
case 1: format = "on"; break;
|
|
|
|
default: format = "gain: %d";
|
|
|
|
}
|
|
|
|
igSliderInt("##nvgain", &desktop->nvGain, 0, desktop->nvMax, format, 0);
|
|
|
|
igPopItemWidth();
|
2021-08-06 07:48:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
bool egl_desktopSetup(EGL_Desktop * desktop, const LG_RendererFormat format)
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
2021-08-07 23:49:55 +00:00
|
|
|
memcpy(&desktop->format, &format, sizeof(LG_RendererFormat));
|
|
|
|
|
2020-10-12 08:43:29 +00:00
|
|
|
enum EGL_PixelFormat pixFmt;
|
|
|
|
switch(format.type)
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
2020-10-12 08:43:29 +00:00
|
|
|
case FRAME_TYPE_BGRA:
|
|
|
|
pixFmt = EGL_PF_BGRA;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRAME_TYPE_RGBA:
|
|
|
|
pixFmt = EGL_PF_RGBA;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRAME_TYPE_RGBA10:
|
|
|
|
pixFmt = EGL_PF_RGBA10;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRAME_TYPE_RGBA16F:
|
|
|
|
pixFmt = EGL_PF_RGBA16F;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_ERROR("Unsupported frame format");
|
2020-05-21 01:44:56 +00:00
|
|
|
return false;
|
2018-12-12 10:41:51 +00:00
|
|
|
}
|
|
|
|
|
2022-05-01 09:41:46 +00:00
|
|
|
desktop->width = format.frameWidth;
|
|
|
|
desktop->height = format.frameHeight;
|
2020-10-12 08:43:29 +00:00
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
if (!egl_textureSetup(
|
2020-10-12 08:43:29 +00:00
|
|
|
desktop->texture,
|
|
|
|
pixFmt,
|
2022-05-01 09:41:46 +00:00
|
|
|
format.frameWidth,
|
|
|
|
format.frameHeight,
|
2021-08-02 13:37:33 +00:00
|
|
|
format.pitch
|
2020-10-12 08:43:29 +00:00
|
|
|
))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to setup the desktop texture");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-10 03:10:51 +00:00
|
|
|
bool egl_desktopUpdate(EGL_Desktop * desktop, const FrameBuffer * frame, int dmaFd,
|
2021-08-07 06:10:30 +00:00
|
|
|
const FrameDamageRect * damageRects, int damageRectsCount)
|
2020-10-12 08:43:29 +00:00
|
|
|
{
|
2021-08-07 23:49:55 +00:00
|
|
|
if (desktop->useDMA && dmaFd >= 0)
|
2020-10-29 15:32:25 +00:00
|
|
|
{
|
2021-08-08 07:16:10 +00:00
|
|
|
if (egl_textureUpdateFromDMA(desktop->texture, frame, dmaFd))
|
2021-08-11 08:53:36 +00:00
|
|
|
{
|
|
|
|
atomic_store(&desktop->processFrame, true);
|
2021-08-07 23:49:55 +00:00
|
|
|
return true;
|
2021-08-11 08:53:36 +00:00
|
|
|
}
|
2021-08-07 23:49:55 +00:00
|
|
|
|
|
|
|
DEBUG_WARN("DMA update failed, disabling DMABUF imports");
|
2021-10-20 00:28:29 +00:00
|
|
|
|
|
|
|
const char * vendor = (const char *)glGetString(GL_VENDOR);
|
|
|
|
if (strstr(vendor, "NVIDIA"))
|
|
|
|
{
|
|
|
|
DEBUG_WARN("NVIDIA's DMABUF support is incomplete, please direct your complaints to NVIDIA");
|
|
|
|
DEBUG_WARN("This is not a bug in Looking Glass");
|
|
|
|
}
|
|
|
|
|
2021-08-07 23:49:55 +00:00
|
|
|
desktop->useDMA = false;
|
|
|
|
|
2021-12-14 19:10:30 +00:00
|
|
|
const char * gl_exts = (const char *)glGetString(GL_EXTENSIONS);
|
|
|
|
if (!util_hasGLExt(gl_exts, "GL_EXT_buffer_storage"))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("GL_EXT_buffer_storage is needed to use EGL backend");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-08 07:52:13 +00:00
|
|
|
egl_textureFree(&desktop->texture);
|
2021-08-11 08:53:36 +00:00
|
|
|
if (!egl_textureInit(&desktop->texture, desktop->display,
|
2021-08-09 04:08:10 +00:00
|
|
|
EGL_TEXTYPE_FRAMEBUFFER, true))
|
2021-08-07 23:49:55 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the desktop texture");
|
2020-10-29 15:32:25 +00:00
|
|
|
return false;
|
2021-08-07 23:49:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 07:16:10 +00:00
|
|
|
if (!egl_desktopSetup(desktop, desktop->format))
|
2020-10-29 15:32:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-21 01:44:56 +00:00
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
if (egl_textureUpdateFromFrame(desktop->texture, frame,
|
|
|
|
damageRects, damageRectsCount))
|
|
|
|
{
|
|
|
|
atomic_store(&desktop->processFrame, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-12-12 10:41:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 03:08:54 +00:00
|
|
|
void egl_desktopResize(EGL_Desktop * desktop, int width, int height)
|
|
|
|
{
|
2021-08-11 08:53:36 +00:00
|
|
|
atomic_store(&desktop->processFrame, true);
|
2021-08-10 03:08:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
bool egl_desktopRender(EGL_Desktop * desktop, unsigned int outputWidth,
|
|
|
|
unsigned int outputHeight, const float x, const float y,
|
2021-02-21 00:50:59 +00:00
|
|
|
const float scaleX, const float scaleY, enum EGL_DesktopScaleType scaleType,
|
2021-08-03 00:45:47 +00:00
|
|
|
LG_RendererRotate rotate, const struct DamageRects * rects)
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
2021-10-20 00:17:29 +00:00
|
|
|
if (outputWidth == 0 && outputHeight == 0)
|
|
|
|
DEBUG_FATAL("outputWidth || outputHeight == 0");
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
enum EGL_TexStatus status;
|
2021-08-08 07:16:10 +00:00
|
|
|
if ((status = egl_textureProcess(desktop->texture)) != EGL_TEX_STATUS_OK)
|
2021-08-02 13:37:33 +00:00
|
|
|
{
|
|
|
|
if (status != EGL_TEX_STATUS_NOTREADY)
|
|
|
|
DEBUG_ERROR("Failed to process the desktop texture");
|
|
|
|
}
|
|
|
|
|
2021-02-22 04:56:51 +00:00
|
|
|
int scaleAlgo = EGL_SCALE_NEAREST;
|
2021-02-21 00:50:59 +00:00
|
|
|
|
2021-09-02 02:27:36 +00:00
|
|
|
egl_desktopRectsMatrix((float *)desktop->matrix->data,
|
|
|
|
desktop->width, desktop->height, x, y, scaleX, scaleY, rotate);
|
|
|
|
egl_desktopRectsUpdate(desktop->mesh, rects, desktop->width, desktop->height);
|
|
|
|
|
2021-08-11 23:04:45 +00:00
|
|
|
if (atomic_exchange(&desktop->processFrame, false) ||
|
|
|
|
egl_postProcessConfigModified(desktop->pp))
|
2021-09-02 02:27:36 +00:00
|
|
|
egl_postProcessRun(desktop->pp, desktop->texture, desktop->mesh,
|
|
|
|
desktop->width, desktop->height, outputWidth, outputHeight);
|
2021-08-11 08:53:36 +00:00
|
|
|
|
|
|
|
unsigned int finalSizeX, finalSizeY;
|
|
|
|
GLuint texture = egl_postProcessGetOutput(desktop->pp,
|
|
|
|
&finalSizeX, &finalSizeY);
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
egl_resetViewport(desktop->egl);
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
2022-02-08 00:00:57 +00:00
|
|
|
glBindSampler(0, desktop->texture->sampler);
|
2021-08-11 08:53:36 +00:00
|
|
|
|
|
|
|
if (finalSizeX > desktop->width || finalSizeY > desktop->height)
|
2021-08-10 20:31:01 +00:00
|
|
|
scaleType = EGL_DESKTOP_DOWNSCALE;
|
|
|
|
|
2021-02-22 04:56:51 +00:00
|
|
|
switch (desktop->scaleAlgo)
|
2021-01-18 17:26:59 +00:00
|
|
|
{
|
2021-02-22 04:56:51 +00:00
|
|
|
case EGL_SCALE_AUTO:
|
|
|
|
switch (scaleType)
|
|
|
|
{
|
|
|
|
case EGL_DESKTOP_UPSCALE:
|
|
|
|
scaleAlgo = EGL_SCALE_NEAREST;
|
|
|
|
break;
|
|
|
|
|
2021-11-11 04:27:31 +00:00
|
|
|
case EGL_DESKTOP_NOSCALE:
|
2021-02-22 04:56:51 +00:00
|
|
|
case EGL_DESKTOP_DOWNSCALE:
|
|
|
|
scaleAlgo = EGL_SCALE_LINEAR;
|
|
|
|
break;
|
|
|
|
}
|
2021-02-21 00:50:59 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-22 04:56:51 +00:00
|
|
|
default:
|
|
|
|
scaleAlgo = desktop->scaleAlgo;
|
2021-01-18 17:26:59 +00:00
|
|
|
}
|
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
const struct DesktopShader * shader = &desktop->shader;
|
|
|
|
EGL_Uniform uniforms[] =
|
2019-03-28 13:15:14 +00:00
|
|
|
{
|
2021-08-09 04:08:10 +00:00
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_1I,
|
|
|
|
.location = shader->uScaleAlgo,
|
|
|
|
.i = { scaleAlgo },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_2F,
|
|
|
|
.location = shader->uDesktopSize,
|
|
|
|
.f = { desktop->width, desktop->height },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_M3x2FV,
|
|
|
|
.location = shader->uTransform,
|
|
|
|
.m.transpose = GL_FALSE,
|
|
|
|
.m.v = desktop->matrix
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_1F,
|
|
|
|
.location = shader->uNVGain,
|
|
|
|
.f = { (float)desktop->nvGain }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_1I,
|
|
|
|
.location = shader->uCBMode,
|
|
|
|
.f = { desktop->cbMode }
|
|
|
|
}
|
|
|
|
};
|
2021-08-03 00:45:47 +00:00
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
egl_shaderSetUniforms(shader->shader, uniforms, ARRAY_LENGTH(uniforms));
|
|
|
|
egl_shaderUse(shader->shader);
|
2021-08-03 00:45:47 +00:00
|
|
|
egl_desktopRectsRender(desktop->mesh);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2019-06-12 12:36:00 +00:00
|
|
|
return true;
|
2020-01-17 03:35:08 +00:00
|
|
|
}
|