2021-06-06 01:26:18 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2024-02-01 06:16:31 +00:00
|
|
|
* Copyright © 2017-2024 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;
|
2023-03-08 22:20:01 +00:00
|
|
|
GLint uSamplerType;
|
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;
|
2023-04-26 06:26:33 +00:00
|
|
|
GLint uIsHDR;
|
2023-10-20 04:26:27 +00:00
|
|
|
GLint uMapHDRtoSDR;
|
|
|
|
GLint uMapHDRGain;
|
2023-10-26 14:03:22 +00:00
|
|
|
GLint uMapHDRPQ;
|
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;
|
2023-03-08 22:20:01 +00:00
|
|
|
struct DesktopShader dmaShader, 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;
|
2023-04-26 06:26:33 +00:00
|
|
|
bool hdr;
|
2023-10-26 14:03:22 +00:00
|
|
|
bool hdrPQ;
|
2021-01-15 01:40:59 +00:00
|
|
|
LG_RendererRotate rotate;
|
2020-05-21 01:44:56 +00:00
|
|
|
|
2022-05-22 08:19:58 +00:00
|
|
|
bool useSpice;
|
|
|
|
int spiceWidth, spiceHeight;
|
|
|
|
EGL_Texture * spiceTexture;
|
|
|
|
|
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
|
|
|
|
2023-10-20 04:26:27 +00:00
|
|
|
// map HDR content to SDR
|
|
|
|
bool mapHDRtoSDR;
|
|
|
|
int peakLuminance;
|
|
|
|
int maxCLL;
|
|
|
|
|
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,
|
2023-03-08 22:20:01 +00:00
|
|
|
const char * fragment_code, size_t fragment_size,
|
|
|
|
bool useDMA
|
2019-05-22 01:36:18 +00:00
|
|
|
)
|
|
|
|
{
|
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,
|
2023-03-08 22:20:01 +00:00
|
|
|
fragment_code, fragment_size,
|
2023-11-08 09:29:42 +00:00
|
|
|
useDMA, NULL))
|
2019-05-22 01:36:18 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-10-20 04:26:27 +00:00
|
|
|
shader->uDesktopSize = egl_shaderGetUniform(shader->shader, "desktopSize" );
|
2023-11-02 20:03:32 +00:00
|
|
|
shader->uTransform = egl_shaderGetUniform(shader->shader, "transform" );
|
2023-10-20 04:26:27 +00:00
|
|
|
shader->uScaleAlgo = egl_shaderGetUniform(shader->shader, "scaleAlgo" );
|
|
|
|
shader->uNVGain = egl_shaderGetUniform(shader->shader, "nvGain" );
|
|
|
|
shader->uCBMode = egl_shaderGetUniform(shader->shader, "cbMode" );
|
|
|
|
shader->uIsHDR = egl_shaderGetUniform(shader->shader, "isHDR" );
|
|
|
|
shader->uMapHDRtoSDR = egl_shaderGetUniform(shader->shader, "mapHDRtoSDR" );
|
|
|
|
shader->uMapHDRGain = egl_shaderGetUniform(shader->shader, "mapHDRGain" );
|
2023-10-26 14:03:22 +00:00
|
|
|
shader->uMapHDRPQ = egl_shaderGetUniform(shader->shader, "mapHDRPQ" );
|
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,
|
2022-05-22 08:19:58 +00:00
|
|
|
useDMA ? EGL_TEXTYPE_DMABUF : EGL_TEXTYPE_FRAMEBUFFER))
|
2018-12-12 10:41:51 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the desktop texture");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-03-08 22:20:01 +00:00
|
|
|
if (!egl_initDesktopShader(
|
|
|
|
&desktop->shader,
|
|
|
|
b_shader_desktop_vert , b_shader_desktop_vert_size,
|
|
|
|
b_shader_desktop_rgb_frag, b_shader_desktop_rgb_frag_size,
|
|
|
|
false))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the desktop shader");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useDMA)
|
|
|
|
if (!egl_initDesktopShader(
|
|
|
|
&desktop->dmaShader,
|
|
|
|
b_shader_desktop_vert , b_shader_desktop_vert_size,
|
|
|
|
b_shader_desktop_rgb_frag, b_shader_desktop_rgb_frag_size,
|
|
|
|
true))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the desktop DMA shader");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-29 08:24:53 +00:00
|
|
|
app_registerKeybind(0, '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
|
|
|
|
2023-10-20 04:26:27 +00:00
|
|
|
desktop->mapHDRtoSDR = option_get_bool("egl", "mapHDRtoSDR" );
|
|
|
|
desktop->peakLuminance = option_get_int ("egl", "peakLuminance");
|
|
|
|
desktop->maxCLL = option_get_int ("egl", "maxCLL" );
|
|
|
|
|
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
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
// this MUST be first
|
2023-11-08 09:29:42 +00:00
|
|
|
egl_postProcessAdd(desktop->pp, &egl_filter24bitOps);
|
2023-11-02 20:03:32 +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;
|
|
|
|
|
2023-03-08 22:20:01 +00:00
|
|
|
egl_textureFree (&(*desktop)->texture );
|
|
|
|
egl_textureFree (&(*desktop)->spiceTexture );
|
|
|
|
egl_shaderFree (&(*desktop)->shader .shader);
|
|
|
|
egl_shaderFree (&(*desktop)->dmaShader.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();
|
2023-10-20 04:26:27 +00:00
|
|
|
|
2023-10-24 02:46:51 +00:00
|
|
|
bool mapHDRtoSDR = desktop->mapHDRtoSDR;
|
|
|
|
int peakLuminance = desktop->peakLuminance;
|
|
|
|
int maxCLL = desktop->maxCLL;
|
|
|
|
|
2023-10-20 04:26:27 +00:00
|
|
|
igSeparator();
|
2023-10-24 02:46:51 +00:00
|
|
|
igCheckbox("Map HDR content to SDR", &mapHDRtoSDR);
|
|
|
|
igSliderInt("Peak Luminance", &peakLuminance, 1, 10000,
|
2023-10-20 04:26:27 +00:00
|
|
|
"%d nits",
|
|
|
|
ImGuiInputTextFlags_CharsDecimal);
|
2023-10-24 02:46:51 +00:00
|
|
|
igSliderInt("Max content light level", &maxCLL, 1, 10000,
|
2023-10-20 04:26:27 +00:00
|
|
|
"%d nits", ImGuiInputTextFlags_CharsDecimal);
|
2023-10-24 02:46:51 +00:00
|
|
|
|
|
|
|
if (mapHDRtoSDR != desktop->mapHDRtoSDR ||
|
|
|
|
peakLuminance != desktop->peakLuminance ||
|
|
|
|
maxCLL != desktop->maxCLL)
|
|
|
|
{
|
|
|
|
desktop->mapHDRtoSDR = mapHDRtoSDR;
|
|
|
|
desktop->peakLuminance = max(1, peakLuminance);
|
|
|
|
desktop->maxCLL = max(1, maxCLL);
|
|
|
|
app_invalidateWindow(true);
|
|
|
|
}
|
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;
|
|
|
|
|
2023-11-08 05:04:58 +00:00
|
|
|
case FRAME_TYPE_BGR_32:
|
|
|
|
pixFmt = EGL_PF_BGR_32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FRAME_TYPE_RGB_24:
|
2023-11-08 05:06:32 +00:00
|
|
|
pixFmt = EGL_PF_RGB_24;
|
2023-11-02 20:03:32 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-12 08:43:29 +00:00
|
|
|
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;
|
2023-04-26 06:26:33 +00:00
|
|
|
desktop->hdr = format.hdr;
|
2023-10-26 14:03:22 +00:00
|
|
|
desktop->hdrPQ = format.hdrPQ;
|
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,
|
2023-11-08 07:58:12 +00:00
|
|
|
desktop->format.dataWidth,
|
|
|
|
desktop->format.dataHeight,
|
|
|
|
desktop->format.stride,
|
|
|
|
desktop->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
|
|
|
{
|
2023-11-12 07:26:08 +00:00
|
|
|
if (likely(desktop->useDMA && dmaFd >= 0))
|
2020-10-29 15:32:25 +00:00
|
|
|
{
|
2023-11-12 07:26:08 +00:00
|
|
|
if (likely(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,
|
2022-05-22 08:19:58 +00:00
|
|
|
EGL_TEXTYPE_FRAMEBUFFER))
|
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
|
|
|
|
2023-11-12 07:26:08 +00:00
|
|
|
if (likely(egl_textureUpdateFromFrame(desktop->texture, frame,
|
|
|
|
damageRects, damageRectsCount)))
|
2021-08-11 08:53:36 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2022-05-22 08:19:58 +00:00
|
|
|
EGL_Texture * tex;
|
|
|
|
int width, height;
|
|
|
|
|
2023-11-12 07:26:08 +00:00
|
|
|
if (unlikely(desktop->useSpice))
|
2022-05-22 08:19:58 +00:00
|
|
|
{
|
|
|
|
tex = desktop->spiceTexture;
|
|
|
|
width = desktop->spiceWidth;
|
|
|
|
height = desktop->spiceHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tex = desktop->texture;
|
|
|
|
width = desktop->width;
|
|
|
|
height = desktop->height;
|
|
|
|
}
|
|
|
|
|
2023-11-12 07:26:08 +00:00
|
|
|
if (unlikely(outputWidth == 0 && outputHeight == 0))
|
2021-10-20 00:17:29 +00:00
|
|
|
DEBUG_FATAL("outputWidth || outputHeight == 0");
|
|
|
|
|
2021-08-02 13:37:33 +00:00
|
|
|
enum EGL_TexStatus status;
|
2023-11-12 07:26:08 +00:00
|
|
|
if (unlikely((status = egl_textureProcess(tex)) != 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,
|
2022-05-22 08:19:58 +00:00
|
|
|
width, height, x, y, scaleX, scaleY, rotate);
|
|
|
|
egl_desktopRectsUpdate(desktop->mesh, rects, width, height);
|
2021-09-02 02:27:36 +00:00
|
|
|
|
2021-08-11 23:04:45 +00:00
|
|
|
if (atomic_exchange(&desktop->processFrame, false) ||
|
|
|
|
egl_postProcessConfigModified(desktop->pp))
|
2022-05-22 08:19:58 +00:00
|
|
|
egl_postProcessRun(desktop->pp, tex, desktop->mesh,
|
2023-03-08 22:20:01 +00:00
|
|
|
width, height, outputWidth, outputHeight, desktop->useDMA);
|
2021-08-11 08:53:36 +00:00
|
|
|
|
|
|
|
unsigned int finalSizeX, finalSizeY;
|
2023-03-08 22:20:01 +00:00
|
|
|
EGL_Texture * texture = egl_postProcessGetOutput(desktop->pp,
|
2021-08-11 08:53:36 +00:00
|
|
|
&finalSizeX, &finalSizeY);
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
egl_resetViewport(desktop->egl);
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2023-03-08 22:20:01 +00:00
|
|
|
egl_textureBind(texture);
|
2021-08-11 08:53:36 +00:00
|
|
|
|
2022-05-22 08:19:58 +00:00
|
|
|
if (finalSizeX > width || finalSizeY > 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
|
|
|
}
|
|
|
|
|
2023-03-08 22:20:01 +00:00
|
|
|
const struct DesktopShader * shader =
|
|
|
|
desktop->useDMA && texture == desktop->texture ?
|
|
|
|
&desktop->dmaShader : &desktop->shader;
|
|
|
|
|
2023-10-20 04:26:27 +00:00
|
|
|
const float mapHDRGain =
|
2023-11-11 00:43:21 +00:00
|
|
|
(float)desktop->maxCLL / desktop->peakLuminance;
|
2023-10-20 04:26:27 +00:00
|
|
|
|
2021-08-09 04:08:10 +00:00
|
|
|
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,
|
2022-05-22 08:19:58 +00:00
|
|
|
.f = { width, height },
|
2021-08-09 04:08:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.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 }
|
2023-04-26 06:26:33 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_1I,
|
|
|
|
.location = shader->uIsHDR,
|
|
|
|
.i = { desktop->hdr }
|
2023-10-20 04:26:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_1I,
|
|
|
|
.location = shader->uMapHDRtoSDR,
|
|
|
|
.i = { desktop->mapHDRtoSDR }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_1F,
|
|
|
|
.location = shader->uMapHDRGain,
|
|
|
|
.f = { mapHDRGain }
|
2023-10-26 14:03:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.type = EGL_UNIFORM_TYPE_1I,
|
|
|
|
.location = shader->uMapHDRPQ,
|
|
|
|
.f = { desktop->hdrPQ }
|
2021-08-09 04:08:10 +00:00
|
|
|
}
|
|
|
|
};
|
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
|
|
|
}
|
2022-05-22 08:19:58 +00:00
|
|
|
|
|
|
|
void egl_desktopSpiceConfigure(EGL_Desktop * desktop, int width, int height)
|
|
|
|
{
|
|
|
|
if (!desktop->spiceTexture)
|
|
|
|
if (!egl_textureInit(&desktop->spiceTexture, desktop->display,
|
|
|
|
EGL_TEXTYPE_BUFFER_MAP))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to initialize the spice desktop texture");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!egl_textureSetup(
|
|
|
|
desktop->spiceTexture,
|
|
|
|
EGL_PF_BGRA,
|
|
|
|
width,
|
|
|
|
height,
|
2023-11-02 20:03:32 +00:00
|
|
|
width,
|
2022-05-22 08:19:58 +00:00
|
|
|
width * 4
|
|
|
|
))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to setup the spice desktop texture");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
desktop->spiceWidth = width;
|
|
|
|
desktop->spiceHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_desktopSpiceDrawFill(EGL_Desktop * desktop, int x, int y, int width,
|
|
|
|
int height, uint32_t color)
|
|
|
|
{
|
2022-05-23 14:17:08 +00:00
|
|
|
/* this is a fairly hacky way to do this, but since it's only for the fallback
|
|
|
|
* spice display it's not really an issue */
|
|
|
|
|
|
|
|
uint32_t line[width];
|
|
|
|
for(int x = 0; x < width; ++x)
|
|
|
|
line[x] = color;
|
|
|
|
|
|
|
|
for(; y < height; ++y)
|
|
|
|
egl_textureUpdateRect(desktop->spiceTexture,
|
2023-11-02 20:03:32 +00:00
|
|
|
x, y, width, 1, width, sizeof(line), (uint8_t *)line, false);
|
2022-05-23 14:17:08 +00:00
|
|
|
|
|
|
|
atomic_store(&desktop->processFrame, true);
|
2022-05-22 08:19:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void egl_desktopSpiceDrawBitmap(EGL_Desktop * desktop, int x, int y, int width,
|
|
|
|
int height, int stride, uint8_t * data, bool topDown)
|
|
|
|
{
|
|
|
|
egl_textureUpdateRect(desktop->spiceTexture,
|
2023-11-02 20:03:32 +00:00
|
|
|
x, y, width, height, width, stride, data, topDown);
|
2022-05-22 08:19:58 +00:00
|
|
|
atomic_store(&desktop->processFrame, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_desktopSpiceShow(EGL_Desktop * desktop, bool show)
|
|
|
|
{
|
|
|
|
desktop->useSpice = show;
|
2024-03-12 00:58:16 +00:00
|
|
|
atomic_store(&desktop->processFrame, true);
|
2022-05-22 08:19:58 +00:00
|
|
|
}
|