2021-08-11 08:53:36 +00:00
|
|
|
/**
|
|
|
|
* Looking Glass
|
2024-02-01 06:16:31 +00:00
|
|
|
* Copyright © 2017-2024 The Looking Glass Authors
|
2021-08-11 08:53:36 +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
|
|
|
|
*/
|
|
|
|
|
2021-08-28 22:08:46 +00:00
|
|
|
#define _GNU_SOURCE
|
2021-08-11 08:53:36 +00:00
|
|
|
#include "postprocess.h"
|
|
|
|
#include "filters.h"
|
2021-08-11 23:04:45 +00:00
|
|
|
#include "app.h"
|
|
|
|
#include "cimgui.h"
|
|
|
|
|
2021-08-28 11:26:21 +00:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
2021-08-28 22:08:46 +00:00
|
|
|
#include <limits.h>
|
2021-08-28 11:26:21 +00:00
|
|
|
#include <unistd.h>
|
2021-08-11 23:04:45 +00:00
|
|
|
#include <stdatomic.h>
|
2021-08-28 11:26:21 +00:00
|
|
|
#include <sys/stat.h>
|
2021-08-11 08:53:36 +00:00
|
|
|
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/array.h"
|
2021-08-28 20:08:48 +00:00
|
|
|
#include "common/option.h"
|
2021-08-28 11:26:21 +00:00
|
|
|
#include "common/paths.h"
|
|
|
|
#include "common/stringlist.h"
|
|
|
|
#include "common/stringutils.h"
|
2021-08-22 06:22:27 +00:00
|
|
|
#include "common/vector.h"
|
2021-08-11 08:53:36 +00:00
|
|
|
|
|
|
|
static const EGL_FilterOps * EGL_Filters[] =
|
|
|
|
{
|
2021-08-12 05:53:35 +00:00
|
|
|
&egl_filterDownscaleOps,
|
2021-08-11 08:53:36 +00:00
|
|
|
&egl_filterFFXFSR1Ops,
|
|
|
|
&egl_filterFFXCASOps
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EGL_PostProcess
|
|
|
|
{
|
2023-11-02 20:03:32 +00:00
|
|
|
Vector filters, internalFilters;
|
2023-03-08 22:20:01 +00:00
|
|
|
EGL_Texture * output;
|
2021-08-11 08:53:36 +00:00
|
|
|
unsigned int outputX, outputY;
|
2021-08-11 23:04:45 +00:00
|
|
|
_Atomic(bool) modified;
|
2021-08-11 08:53:36 +00:00
|
|
|
|
2021-09-02 02:27:36 +00:00
|
|
|
EGL_DesktopRects * rects;
|
2021-08-28 11:26:21 +00:00
|
|
|
|
|
|
|
StringList presets;
|
|
|
|
char * presetDir;
|
|
|
|
int activePreset;
|
|
|
|
char presetEdit[128];
|
2021-08-28 20:18:52 +00:00
|
|
|
char * presetError;
|
2021-08-11 08:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void egl_postProcessEarlyInit(void)
|
|
|
|
{
|
2021-08-28 22:08:46 +00:00
|
|
|
static struct Option options[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.module = "eglFilter",
|
|
|
|
.name = "order",
|
|
|
|
.description = "The order of filters to use",
|
2021-08-30 08:17:25 +00:00
|
|
|
.preset = true,
|
2021-08-28 22:08:46 +00:00
|
|
|
.type = OPTION_TYPE_STRING,
|
|
|
|
.value.x_string = ""
|
|
|
|
},
|
2022-01-26 05:00:07 +00:00
|
|
|
{
|
|
|
|
.module = "egl",
|
|
|
|
.name = "preset",
|
|
|
|
.description = "The initial filter preset to load",
|
|
|
|
.type = OPTION_TYPE_STRING
|
|
|
|
},
|
2021-08-28 22:08:46 +00:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
option_register(options);
|
|
|
|
|
|
|
|
for (int i = 0; i < ARRAY_LENGTH(EGL_Filters); ++i)
|
2023-11-02 20:03:32 +00:00
|
|
|
egl_filterEarlyInit(EGL_Filters[i]);
|
2021-08-11 08:53:36 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 05:00:07 +00:00
|
|
|
static void loadPreset(struct EGL_PostProcess * this, const char * name);
|
|
|
|
|
2021-08-28 11:26:21 +00:00
|
|
|
static void loadPresetList(struct EGL_PostProcess * this)
|
|
|
|
{
|
|
|
|
DIR * dir = NULL;
|
|
|
|
|
|
|
|
alloc_sprintf(&this->presetDir, "%s/presets", lgConfigDir());
|
|
|
|
if (!this->presetDir)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory for presets");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mkdir(this->presetDir, S_IRWXU) < 0 && errno != EEXIST)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to create presets directory: %s", this->presetDir);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
dir = opendir(this->presetDir);
|
|
|
|
if (!dir)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to open presets directory: %s", this->presetDir);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->presets = stringlist_new(true);
|
|
|
|
if (!this->presets)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory for preset list");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dirent * entry;
|
2022-01-26 05:00:07 +00:00
|
|
|
const char * preset = option_get_string("egl", "preset");
|
2022-01-26 05:07:17 +00:00
|
|
|
this->activePreset = -1;
|
|
|
|
|
2021-08-28 11:26:21 +00:00
|
|
|
while ((entry = readdir(dir)) != NULL)
|
|
|
|
{
|
|
|
|
if (entry->d_type != DT_REG)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
DEBUG_INFO("Found preset: %s", entry->d_name);
|
|
|
|
char * name = strdup(entry->d_name);
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
stringlist_push(this->presets, name);
|
2022-01-26 05:00:07 +00:00
|
|
|
|
2022-01-26 05:04:15 +00:00
|
|
|
if (preset && strcmp(preset, name) == 0)
|
2022-01-26 05:07:17 +00:00
|
|
|
this->activePreset = stringlist_count(this->presets) - 1;
|
2021-08-28 11:26:21 +00:00
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
|
2022-01-26 05:00:07 +00:00
|
|
|
|
|
|
|
if (preset)
|
|
|
|
{
|
2022-01-26 05:07:17 +00:00
|
|
|
if (this->activePreset > -1)
|
2022-01-26 05:00:07 +00:00
|
|
|
loadPreset(this, preset);
|
|
|
|
else
|
|
|
|
DEBUG_WARN("egl:preset '%s' does not exist", preset);
|
|
|
|
}
|
|
|
|
|
2021-08-28 11:26:21 +00:00
|
|
|
return;
|
|
|
|
|
2021-10-20 00:17:29 +00:00
|
|
|
fail:
|
2021-08-28 11:26:21 +00:00
|
|
|
free(this->presetDir);
|
|
|
|
this->presetDir = NULL;
|
|
|
|
if (dir)
|
|
|
|
closedir(dir);
|
|
|
|
if (this->presets)
|
|
|
|
stringlist_free(&this->presets);
|
|
|
|
}
|
|
|
|
|
2021-08-28 20:18:52 +00:00
|
|
|
static void presetError(struct EGL_PostProcess * this, char * message)
|
|
|
|
{
|
|
|
|
free(this->presetError);
|
|
|
|
this->presetError = message;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool savePreset(struct EGL_PostProcess * this, const char * name)
|
2021-08-28 20:08:48 +00:00
|
|
|
{
|
|
|
|
EGL_Filter * filter;
|
|
|
|
vector_forEach(filter, &this->filters)
|
|
|
|
egl_filterSaveState(filter);
|
|
|
|
|
2021-08-28 22:08:46 +00:00
|
|
|
size_t orderLen = 0;
|
|
|
|
vector_forEach(filter, &this->filters)
|
|
|
|
orderLen += strlen(filter->ops.id) + 1;
|
|
|
|
|
|
|
|
char order[orderLen];
|
|
|
|
char * p = order;
|
|
|
|
vector_forEach(filter, &this->filters)
|
|
|
|
{
|
|
|
|
strcpy(p, filter->ops.id);
|
|
|
|
p += strlen(filter->ops.id);
|
|
|
|
*p++ = ';';
|
|
|
|
}
|
|
|
|
if (p > order)
|
|
|
|
p[-1] = '\0';
|
|
|
|
option_set_string("eglFilter", "order", order);
|
|
|
|
|
2021-08-28 20:08:48 +00:00
|
|
|
char * path;
|
|
|
|
alloc_sprintf(&path, "%s/%s", this->presetDir, name);
|
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory");
|
2021-08-28 20:18:52 +00:00
|
|
|
return false;
|
2021-08-28 20:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE * file = fopen(path, "w");
|
|
|
|
if (!file)
|
|
|
|
{
|
2021-08-28 20:18:52 +00:00
|
|
|
const char * strError = strerror(errno);
|
|
|
|
DEBUG_ERROR("Failed to open preset \"%s\" for writing: %s", name, strError);
|
2021-08-28 20:08:48 +00:00
|
|
|
free(path);
|
2021-08-28 20:18:52 +00:00
|
|
|
|
|
|
|
char * error;
|
|
|
|
alloc_sprintf(&error, "Failed to save preset: %s\nError: %s", name, strError);
|
|
|
|
if (error)
|
|
|
|
presetError(this, error);
|
|
|
|
return false;
|
2021-08-28 20:08:48 +00:00
|
|
|
}
|
|
|
|
free(path);
|
|
|
|
|
|
|
|
DEBUG_INFO("Saving preset: %s", name);
|
2021-08-30 08:23:09 +00:00
|
|
|
option_dump_preset(file);
|
2021-08-28 20:08:48 +00:00
|
|
|
fclose(file);
|
2021-08-28 20:18:52 +00:00
|
|
|
return true;
|
2021-08-28 20:08:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 22:08:46 +00:00
|
|
|
static int stringListIndex(StringList list, const char * str)
|
|
|
|
{
|
|
|
|
unsigned int count = stringlist_count(list);
|
|
|
|
for (unsigned int i = 0; i < count; ++i)
|
|
|
|
if (strcmp(stringlist_at(list, i), str) == 0)
|
|
|
|
return i;
|
|
|
|
return INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compareFilterOrder(const void * a_, const void * b_, void * opaque)
|
|
|
|
{
|
|
|
|
const EGL_Filter * a = *(const EGL_Filter **)a_;
|
|
|
|
const EGL_Filter * b = *(const EGL_Filter **)b_;
|
|
|
|
StringList order = opaque;
|
|
|
|
|
|
|
|
return stringListIndex(order, a->ops.id) - stringListIndex(order, b->ops.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reorderFilters(struct EGL_PostProcess * this)
|
|
|
|
{
|
|
|
|
StringList order = stringlist_new(false);
|
|
|
|
if (!order)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * orderStr = strdup(option_get_string("eglFilter", "order"));
|
|
|
|
if (!orderStr)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory");
|
|
|
|
stringlist_free(&order);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * p = orderStr;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
stringlist_push(order, p);
|
|
|
|
char * end = strchr(p, ';');
|
|
|
|
if (!end)
|
|
|
|
break;
|
|
|
|
*end = '\0';
|
|
|
|
p = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort_r(vector_data(&this->filters), vector_size(&this->filters),
|
|
|
|
sizeof(EGL_Filter *), compareFilterOrder, order);
|
|
|
|
|
|
|
|
stringlist_free(&order);
|
|
|
|
free(orderStr);
|
|
|
|
}
|
|
|
|
|
2021-08-28 20:08:48 +00:00
|
|
|
static void loadPreset(struct EGL_PostProcess * this, const char * name)
|
|
|
|
{
|
|
|
|
char * path;
|
|
|
|
alloc_sprintf(&path, "%s/%s", this->presetDir, name);
|
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!option_load(path))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to load preset: %s", name);
|
|
|
|
free(path);
|
2021-08-28 20:18:52 +00:00
|
|
|
|
|
|
|
char * error;
|
|
|
|
alloc_sprintf(&error, "Failed to load preset: %s", name);
|
|
|
|
if (error)
|
|
|
|
presetError(this, error);
|
2021-08-28 20:08:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(path);
|
|
|
|
|
|
|
|
DEBUG_INFO("Loading preset: %s", name);
|
|
|
|
EGL_Filter * filter;
|
|
|
|
vector_forEach(filter, &this->filters)
|
|
|
|
egl_filterLoadState(filter);
|
2021-08-28 22:08:46 +00:00
|
|
|
reorderFilters(this);
|
2021-08-28 20:08:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 08:39:15 +00:00
|
|
|
static void savePresetAs(struct EGL_PostProcess * this)
|
2021-08-28 11:26:21 +00:00
|
|
|
{
|
2021-08-28 20:18:52 +00:00
|
|
|
if (!savePreset(this, this->presetEdit))
|
|
|
|
return;
|
2021-08-30 08:41:22 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < stringlist_count(this->presets); ++i)
|
|
|
|
{
|
|
|
|
DEBUG_INFO("Saw preset: %s", stringlist_at(this->presets, i));
|
|
|
|
if (strcmp(stringlist_at(this->presets, i), this->presetEdit) == 0)
|
|
|
|
{
|
|
|
|
this->activePreset = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-28 20:18:52 +00:00
|
|
|
this->activePreset = stringlist_push(this->presets, strdup(this->presetEdit));
|
2021-08-28 11:26:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 22:27:28 +00:00
|
|
|
static void deletePreset(struct EGL_PostProcess * this)
|
|
|
|
{
|
|
|
|
char * path;
|
|
|
|
alloc_sprintf(&path, "%s/%s", this->presetDir,
|
|
|
|
stringlist_at(this->presets, this->activePreset));
|
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unlink(path);
|
|
|
|
free(path);
|
|
|
|
stringlist_remove(this->presets, this->activePreset);
|
|
|
|
if (this->activePreset >= stringlist_count(this->presets))
|
|
|
|
this->activePreset = stringlist_count(this->presets) - 1;
|
|
|
|
}
|
|
|
|
|
2021-08-28 11:26:21 +00:00
|
|
|
static bool presetsUI(struct EGL_PostProcess * this)
|
|
|
|
{
|
|
|
|
if (!this->presets)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool redraw = false;
|
|
|
|
const char * active = "<none>";
|
|
|
|
|
|
|
|
if (this->activePreset >= 0)
|
|
|
|
active = stringlist_at(this->presets, this->activePreset);
|
|
|
|
|
|
|
|
if (igBeginCombo("Preset name", active, 0))
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < stringlist_count(this->presets); ++i)
|
|
|
|
{
|
|
|
|
bool selected = i == this->activePreset;
|
2022-01-07 13:26:12 +00:00
|
|
|
if (igSelectable_Bool(stringlist_at(this->presets, i), selected, 0,
|
|
|
|
(ImVec2) { 0.0f, 0.0f }))
|
2021-08-30 08:39:15 +00:00
|
|
|
{
|
2021-08-28 11:26:21 +00:00
|
|
|
this->activePreset = i;
|
2021-08-30 08:39:15 +00:00
|
|
|
redraw = true;
|
|
|
|
loadPreset(this, stringlist_at(this->presets, this->activePreset));
|
|
|
|
}
|
2021-08-28 11:26:21 +00:00
|
|
|
if (selected)
|
|
|
|
igSetItemDefaultFocus();
|
|
|
|
}
|
|
|
|
igEndCombo();
|
|
|
|
}
|
2021-08-30 08:47:00 +00:00
|
|
|
if (igIsItemHovered(ImGuiHoveredFlags_None))
|
|
|
|
igSetTooltip("Selecting a preset will load it");
|
2021-08-28 11:26:21 +00:00
|
|
|
|
2021-08-28 22:32:26 +00:00
|
|
|
if (igButton("Save preset", (ImVec2) { 0.0f, 0.0f }))
|
|
|
|
{
|
|
|
|
if (this->activePreset >= 0)
|
|
|
|
savePreset(this, stringlist_at(this->presets, this->activePreset));
|
|
|
|
else
|
|
|
|
presetError(this, strdup("You must select a preset to save."));
|
|
|
|
}
|
2021-08-28 11:26:21 +00:00
|
|
|
|
|
|
|
if (igIsItemHovered(ImGuiHoveredFlags_None) && this->activePreset >= 0)
|
|
|
|
igSetTooltip("This will overwrite the preset named: %s",
|
|
|
|
stringlist_at(this->presets, this->activePreset));
|
|
|
|
|
|
|
|
igSameLine(0.0f, -1.0f);
|
|
|
|
|
2021-08-30 08:39:15 +00:00
|
|
|
if (igButton("Save preset as...", (ImVec2) { 0.0f, 0.0f }))
|
2021-08-28 11:26:21 +00:00
|
|
|
{
|
|
|
|
this->presetEdit[0] = '\0';
|
2022-01-07 13:26:12 +00:00
|
|
|
igOpenPopup_Str("Save preset as...", ImGuiPopupFlags_None);
|
2021-08-28 11:26:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 22:27:28 +00:00
|
|
|
igSameLine(0.0f, -1.0f);
|
|
|
|
|
|
|
|
if (igButton("Delete preset", (ImVec2) { 0.0f, 0.0f }) && this->activePreset >= 0)
|
|
|
|
deletePreset(this);
|
|
|
|
|
2021-08-30 08:39:15 +00:00
|
|
|
if (igBeginPopupModal("Save preset as...", NULL, ImGuiWindowFlags_AlwaysAutoResize))
|
2021-08-28 11:26:21 +00:00
|
|
|
{
|
|
|
|
igText("Enter a name for the new preset:");
|
|
|
|
|
|
|
|
if (!igIsAnyItemActive())
|
|
|
|
igSetKeyboardFocusHere(0);
|
|
|
|
|
|
|
|
if (igInputText("##name", this->presetEdit, sizeof(this->presetEdit),
|
|
|
|
ImGuiInputTextFlags_EnterReturnsTrue, NULL, NULL))
|
|
|
|
{
|
2021-08-30 08:39:15 +00:00
|
|
|
savePresetAs(this);
|
2021-08-28 11:26:21 +00:00
|
|
|
igCloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
2021-08-30 08:39:15 +00:00
|
|
|
if (igButton("Save", (ImVec2) { 0.0f, 0.0f }))
|
2021-08-28 11:26:21 +00:00
|
|
|
{
|
2021-08-30 08:39:15 +00:00
|
|
|
savePresetAs(this);
|
2021-08-28 11:26:21 +00:00
|
|
|
igCloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
igSameLine(0.0f, -1.0f);
|
|
|
|
if (igButton("Cancel", (ImVec2) { 0.0f, 0.0f }))
|
|
|
|
igCloseCurrentPopup();
|
|
|
|
|
|
|
|
igEndPopup();
|
|
|
|
}
|
|
|
|
|
2021-08-28 20:18:52 +00:00
|
|
|
if (this->presetError)
|
2022-01-07 13:26:12 +00:00
|
|
|
igOpenPopup_Str("Preset error", ImGuiPopupFlags_None);
|
2021-08-28 20:18:52 +00:00
|
|
|
|
|
|
|
if (igBeginPopupModal("Preset error", NULL, ImGuiWindowFlags_AlwaysAutoResize))
|
|
|
|
{
|
|
|
|
igText("%s", this->presetError);
|
|
|
|
|
|
|
|
if (!igIsAnyItemActive())
|
|
|
|
igSetKeyboardFocusHere(0);
|
|
|
|
|
|
|
|
if (igButton("OK", (ImVec2) { 0.0f, 0.0f }))
|
|
|
|
{
|
|
|
|
free(this->presetError);
|
|
|
|
this->presetError = NULL;
|
|
|
|
igCloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
igEndPopup();
|
|
|
|
}
|
|
|
|
|
2021-08-28 11:26:21 +00:00
|
|
|
return redraw;
|
|
|
|
}
|
|
|
|
|
2021-08-24 12:05:46 +00:00
|
|
|
static void drawDropTarget(void)
|
|
|
|
{
|
2022-01-07 13:26:12 +00:00
|
|
|
igPushStyleColor_Vec4(ImGuiCol_Separator, (ImVec4) { 1.0f, 1.0f, 0.0f, 1.0f });
|
2021-08-24 12:05:46 +00:00
|
|
|
igSeparator();
|
|
|
|
igPopStyleColor(1);
|
|
|
|
}
|
|
|
|
|
2021-08-11 23:04:45 +00:00
|
|
|
static void configUI(void * opaque, int * id)
|
|
|
|
{
|
|
|
|
struct EGL_PostProcess * this = opaque;
|
|
|
|
|
|
|
|
bool redraw = false;
|
2021-08-28 11:26:21 +00:00
|
|
|
redraw |= presetsUI(this);
|
2021-08-30 08:44:20 +00:00
|
|
|
igSeparator();
|
2021-08-22 06:22:27 +00:00
|
|
|
|
2021-08-24 12:05:46 +00:00
|
|
|
static size_t mouseIdx = -1;
|
|
|
|
static bool moving = false;
|
|
|
|
static size_t moveIdx = 0;
|
2023-11-02 20:03:32 +00:00
|
|
|
|
|
|
|
bool doMove = false;
|
2021-08-24 12:05:46 +00:00
|
|
|
|
|
|
|
ImVec2 window, pos;
|
2021-08-22 07:52:28 +00:00
|
|
|
igGetWindowPos(&window);
|
2021-08-24 12:05:46 +00:00
|
|
|
igGetMousePos(&pos);
|
2021-08-22 07:52:28 +00:00
|
|
|
|
2021-08-27 04:27:16 +00:00
|
|
|
EGL_Filter ** filters = vector_data(&this->filters);
|
|
|
|
size_t count = vector_size(&this->filters);
|
2021-08-22 07:52:28 +00:00
|
|
|
for (size_t i = 0; i < count; ++i)
|
2021-08-11 23:04:45 +00:00
|
|
|
{
|
2021-08-22 07:52:28 +00:00
|
|
|
EGL_Filter * filter = filters[i];
|
2021-08-24 12:05:46 +00:00
|
|
|
|
|
|
|
if (moving && mouseIdx < moveIdx && i == mouseIdx)
|
|
|
|
drawDropTarget();
|
2021-08-22 07:52:28 +00:00
|
|
|
|
2022-01-07 13:26:12 +00:00
|
|
|
igPushID_Ptr(filter);
|
|
|
|
bool draw = igCollapsingHeader_BoolPtr(filter->ops.name, NULL, 0);
|
2021-08-24 12:05:46 +00:00
|
|
|
if (igIsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
|
|
|
|
mouseIdx = i;
|
|
|
|
|
2021-08-22 07:52:28 +00:00
|
|
|
bool active = igIsItemActive();
|
|
|
|
if (draw)
|
2021-08-11 23:04:45 +00:00
|
|
|
redraw |= egl_filterImguiConfig(filter);
|
|
|
|
igPopID();
|
2021-08-22 07:52:28 +00:00
|
|
|
|
2021-08-24 12:05:46 +00:00
|
|
|
if (moving)
|
2021-08-22 07:52:28 +00:00
|
|
|
{
|
2021-08-24 12:05:46 +00:00
|
|
|
if (!igIsMouseDragging(ImGuiMouseButton_Left, -1.0f))
|
|
|
|
{
|
|
|
|
moving = false;
|
|
|
|
doMove = true;
|
|
|
|
}
|
2021-08-22 07:52:28 +00:00
|
|
|
}
|
2021-08-24 12:05:46 +00:00
|
|
|
else
|
|
|
|
if (active && igIsMouseDragging(ImGuiMouseButton_Left, -1.0f))
|
|
|
|
{
|
|
|
|
moveIdx = mouseIdx;
|
|
|
|
moving = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (moving && mouseIdx > moveIdx && i == mouseIdx)
|
|
|
|
drawDropTarget();
|
|
|
|
}
|
2021-08-22 07:52:28 +00:00
|
|
|
|
2021-08-24 12:05:46 +00:00
|
|
|
if (moving)
|
|
|
|
{
|
|
|
|
igSetMouseCursor(ImGuiMouseCursor_Hand);
|
|
|
|
igSetTooltip(filters[moveIdx]->ops.name);
|
2021-08-22 07:52:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 12:05:46 +00:00
|
|
|
if (doMove)
|
2021-08-22 07:52:28 +00:00
|
|
|
{
|
2021-08-24 19:26:32 +00:00
|
|
|
EGL_Filter * tmp = filters[moveIdx];
|
|
|
|
if (mouseIdx > moveIdx) // moving down
|
2023-11-02 20:03:32 +00:00
|
|
|
memmove(
|
|
|
|
filters + moveIdx,
|
|
|
|
filters + moveIdx + 1,
|
|
|
|
(mouseIdx - moveIdx) * sizeof(EGL_Filter *));
|
2021-08-24 19:26:32 +00:00
|
|
|
else // moving up
|
2023-11-02 20:03:32 +00:00
|
|
|
memmove(
|
|
|
|
filters + mouseIdx + 1,
|
|
|
|
filters + mouseIdx,
|
|
|
|
(moveIdx - mouseIdx) * sizeof(EGL_Filter *));
|
|
|
|
|
2021-08-24 19:26:32 +00:00
|
|
|
filters[mouseIdx] = tmp;
|
2021-08-11 23:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (redraw)
|
|
|
|
{
|
|
|
|
atomic_store(&this->modified, true);
|
2022-05-27 01:40:20 +00:00
|
|
|
app_invalidateWindow(true);
|
2021-08-11 23:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
bool egl_postProcessInit(EGL_PostProcess ** pp)
|
|
|
|
{
|
|
|
|
EGL_PostProcess * this = calloc(1, sizeof(*this));
|
|
|
|
if (!this)
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate memory");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
if (!vector_create(&this->filters,
|
|
|
|
sizeof(EGL_Filter *), ARRAY_LENGTH(EGL_Filters)))
|
2021-08-11 08:53:36 +00:00
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate the filter list");
|
|
|
|
goto error_this;
|
|
|
|
}
|
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
if (!vector_create(&this->internalFilters,
|
|
|
|
sizeof(EGL_Filter *), ARRAY_LENGTH(EGL_Filters)))
|
|
|
|
{
|
|
|
|
DEBUG_ERROR("Failed to allocate the filter list");
|
|
|
|
goto error_filters;
|
|
|
|
}
|
|
|
|
|
2021-09-02 02:27:36 +00:00
|
|
|
if (!egl_desktopRectsInit(&this->rects, 1))
|
2021-08-11 08:53:36 +00:00
|
|
|
{
|
2021-09-02 02:27:36 +00:00
|
|
|
DEBUG_ERROR("Failed to initialize the desktop rects");
|
2023-11-02 20:03:32 +00:00
|
|
|
goto error_internal;
|
2021-08-11 08:53:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 11:26:21 +00:00
|
|
|
loadPresetList(this);
|
2021-08-28 22:08:46 +00:00
|
|
|
reorderFilters(this);
|
2021-08-11 23:04:45 +00:00
|
|
|
app_overlayConfigRegisterTab("EGL Filters", configUI, this);
|
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
*pp = this;
|
|
|
|
return true;
|
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
error_internal:
|
|
|
|
vector_destroy(&this->internalFilters);
|
|
|
|
|
2021-08-11 08:53:36 +00:00
|
|
|
error_filters:
|
2021-08-27 04:27:16 +00:00
|
|
|
vector_destroy(&this->filters);
|
2021-08-11 08:53:36 +00:00
|
|
|
|
|
|
|
error_this:
|
|
|
|
free(this);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_postProcessFree(EGL_PostProcess ** pp)
|
|
|
|
{
|
|
|
|
if (!*pp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
EGL_PostProcess * this = *pp;
|
|
|
|
|
2021-08-27 04:27:16 +00:00
|
|
|
EGL_Filter ** filter;
|
|
|
|
vector_forEachRef(filter, &this->filters)
|
|
|
|
egl_filterFree(filter);
|
|
|
|
vector_destroy(&this->filters);
|
2021-08-11 08:53:36 +00:00
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
vector_forEachRef(filter, &this->internalFilters)
|
|
|
|
egl_filterFree(filter);
|
|
|
|
vector_destroy(&this->internalFilters);
|
|
|
|
|
2021-08-28 11:26:21 +00:00
|
|
|
free(this->presetDir);
|
|
|
|
if (this->presets)
|
|
|
|
stringlist_free(&this->presets);
|
|
|
|
|
2021-09-02 02:27:36 +00:00
|
|
|
egl_desktopRectsFree(&this->rects);
|
2021-08-28 20:18:52 +00:00
|
|
|
free(this->presetError);
|
2021-08-11 08:53:36 +00:00
|
|
|
free(this);
|
|
|
|
*pp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool egl_postProcessAdd(EGL_PostProcess * this, const EGL_FilterOps * ops)
|
|
|
|
{
|
|
|
|
EGL_Filter * filter;
|
|
|
|
if (!egl_filterInit(ops, &filter))
|
|
|
|
return false;
|
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
if (ops->type == EGL_FILTER_TYPE_INTERNAL)
|
|
|
|
vector_push(&this->internalFilters, &filter);
|
|
|
|
else
|
|
|
|
vector_push(&this->filters, &filter);
|
2021-08-11 08:53:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-11 23:04:45 +00:00
|
|
|
bool egl_postProcessConfigModified(EGL_PostProcess * this)
|
2021-08-11 08:53:36 +00:00
|
|
|
{
|
2021-08-11 23:04:45 +00:00
|
|
|
return atomic_load(&this->modified);
|
2021-08-11 08:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool egl_postProcessRun(EGL_PostProcess * this, EGL_Texture * tex,
|
2021-09-02 02:27:36 +00:00
|
|
|
EGL_DesktopRects * rects, int desktopWidth, int desktopHeight,
|
2023-03-08 22:20:01 +00:00
|
|
|
unsigned int targetX, unsigned int targetY, bool useDMA)
|
2021-08-11 08:53:36 +00:00
|
|
|
{
|
2021-10-20 00:17:29 +00:00
|
|
|
if (targetX == 0 && targetY == 0)
|
|
|
|
DEBUG_FATAL("targetX || targetY == 0");
|
|
|
|
|
2021-08-22 06:22:27 +00:00
|
|
|
EGL_Filter * lastFilter = NULL;
|
2021-08-11 08:53:36 +00:00
|
|
|
unsigned int sizeX, sizeY;
|
|
|
|
|
2023-03-08 22:20:01 +00:00
|
|
|
//TODO: clean this up
|
|
|
|
GLuint _unused;
|
2023-11-21 00:57:25 +00:00
|
|
|
EGL_PixelFormat pixFmt;
|
|
|
|
if (egl_textureGet(tex, &_unused,
|
|
|
|
&sizeX, &sizeY, &pixFmt) != EGL_TEX_STATUS_OK)
|
2021-08-11 08:53:36 +00:00
|
|
|
return false;
|
|
|
|
|
2021-09-02 02:27:36 +00:00
|
|
|
if (atomic_exchange(&this->modified, false))
|
|
|
|
{
|
|
|
|
rects = this->rects;
|
|
|
|
egl_desktopRectsUpdate(rects, NULL, desktopWidth, desktopHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLfloat matrix[6];
|
|
|
|
egl_desktopRectsMatrix(matrix, desktopWidth, desktopHeight, 0.0f, 0.0f,
|
|
|
|
1.0f, 1.0f, LG_ROTATE_0);
|
|
|
|
|
|
|
|
EGL_FilterRects filterRects = {
|
|
|
|
.rects = rects,
|
|
|
|
.matrix = matrix,
|
|
|
|
.width = desktopWidth,
|
|
|
|
.height = desktopHeight,
|
|
|
|
};
|
2021-08-22 06:22:27 +00:00
|
|
|
|
|
|
|
EGL_Filter * filter;
|
2023-03-08 22:20:01 +00:00
|
|
|
EGL_Texture * texture = tex;
|
2023-11-02 20:03:32 +00:00
|
|
|
|
|
|
|
const Vector * lists[] =
|
2021-08-11 08:53:36 +00:00
|
|
|
{
|
2023-11-02 20:03:32 +00:00
|
|
|
&this->internalFilters,
|
|
|
|
&this->filters,
|
|
|
|
NULL
|
|
|
|
};
|
2021-08-11 08:53:36 +00:00
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
for(const Vector ** filters = lists; *filters; ++filters)
|
|
|
|
vector_forEach(filter, *filters)
|
|
|
|
{
|
|
|
|
egl_filterSetOutputResHint(filter, targetX, targetY);
|
2021-08-11 08:53:36 +00:00
|
|
|
|
2023-11-21 00:57:25 +00:00
|
|
|
if (!egl_filterSetup(filter, pixFmt, sizeX, sizeY,
|
2023-11-02 20:03:32 +00:00
|
|
|
desktopWidth, desktopHeight, useDMA) ||
|
|
|
|
!egl_filterPrepare(filter))
|
|
|
|
continue;
|
2021-08-11 08:53:36 +00:00
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
texture = egl_filterRun(filter, &filterRects, texture);
|
2024-01-25 06:51:06 +00:00
|
|
|
egl_filterGetOutputRes(filter, &sizeX, &sizeY, &pixFmt);
|
2021-08-11 08:53:36 +00:00
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
if (lastFilter)
|
|
|
|
egl_filterRelease(lastFilter);
|
2023-03-08 22:20:01 +00:00
|
|
|
|
2023-11-02 20:03:32 +00:00
|
|
|
lastFilter = filter;
|
|
|
|
|
|
|
|
// the first filter to run will convert to a normal texture
|
|
|
|
useDMA = false;
|
|
|
|
}
|
2021-08-11 08:53:36 +00:00
|
|
|
|
|
|
|
this->output = texture;
|
|
|
|
this->outputX = sizeX;
|
|
|
|
this->outputY = sizeY;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-08 22:20:01 +00:00
|
|
|
EGL_Texture * egl_postProcessGetOutput(EGL_PostProcess * this,
|
2021-08-11 08:53:36 +00:00
|
|
|
unsigned int * outputX, unsigned int * outputY)
|
|
|
|
{
|
|
|
|
*outputX = this->outputX;
|
|
|
|
*outputY = this->outputY;
|
|
|
|
return this->output;
|
|
|
|
}
|