mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 13:37:22 +00:00
[host] all: make the downsample rule matching common
This commit is contained in:
parent
6c7f3c4197
commit
30c577beeb
@ -37,6 +37,8 @@ extern Vector downsampleRules;
|
|||||||
|
|
||||||
bool downsampleParser(struct Option * opt, const char * str);
|
bool downsampleParser(struct Option * opt, const char * str);
|
||||||
|
|
||||||
|
DownsampleRule * downsampleRule_match(int x, int y);
|
||||||
|
|
||||||
#define DOWNSAMPLE_PARSER(moduleName) \
|
#define DOWNSAMPLE_PARSER(moduleName) \
|
||||||
{ \
|
{ \
|
||||||
.module = moduleName, \
|
.module = moduleName, \
|
||||||
|
@ -91,14 +91,6 @@ static bool d3d12_create(struct DXGIInterface * intf)
|
|||||||
if (!d3d12)
|
if (!d3d12)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (dxgi->downsampleLevel > 0)
|
|
||||||
{
|
|
||||||
DEBUG_WARN("The D3D12 backend does not support downsampling yet");
|
|
||||||
dxgi->downsampleLevel = 0;
|
|
||||||
dxgi->outputWidth = dxgi->width;
|
|
||||||
dxgi->outputHeight = dxgi->height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dxgi->debug)
|
if (dxgi->debug)
|
||||||
{
|
{
|
||||||
D3D12GetDebugInterface_t D3D12GetDebugInterface = (D3D12GetDebugInterface_t)
|
D3D12GetDebugInterface_t D3D12GetDebugInterface = (D3D12GetDebugInterface_t)
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "interface/capture.h"
|
#include "interface/capture.h"
|
||||||
#include "interface/platform.h"
|
#include "interface/platform.h"
|
||||||
|
#include "downsample_parser.h"
|
||||||
#include "common/array.h"
|
#include "common/array.h"
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/windebug.h"
|
#include "common/windebug.h"
|
||||||
@ -65,18 +66,6 @@ typedef struct
|
|||||||
}
|
}
|
||||||
PostProcessInstance;
|
PostProcessInstance;
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
unsigned int id;
|
|
||||||
bool greater;
|
|
||||||
unsigned int x;
|
|
||||||
unsigned int y;
|
|
||||||
unsigned int level;
|
|
||||||
}
|
|
||||||
DownsampleRule;
|
|
||||||
|
|
||||||
static Vector downsampleRules = {0};
|
|
||||||
|
|
||||||
// locals
|
// locals
|
||||||
static struct DXGIInterface * this = NULL;
|
static struct DXGIInterface * this = NULL;
|
||||||
|
|
||||||
@ -112,58 +101,6 @@ static const char * dxgi_getName(void)
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool downsampleOptParser(struct Option * opt, const char * str)
|
|
||||||
{
|
|
||||||
if (!str)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
opt->value.x_string = strdup(str);
|
|
||||||
|
|
||||||
if (downsampleRules.data)
|
|
||||||
vector_destroy(&downsampleRules);
|
|
||||||
|
|
||||||
if (!vector_create(&downsampleRules, sizeof(DownsampleRule), 10))
|
|
||||||
{
|
|
||||||
DEBUG_ERROR("Failed to allocate ram");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char * tmp = strdup(str);
|
|
||||||
char * token = strtok(tmp, ",");
|
|
||||||
int count = 0;
|
|
||||||
while(token)
|
|
||||||
{
|
|
||||||
DownsampleRule rule = {0};
|
|
||||||
if (token[0] == '>')
|
|
||||||
{
|
|
||||||
rule.greater = true;
|
|
||||||
++token;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sscanf(token, "%ux%u:%u", &rule.x, &rule.y, &rule.level) != 3)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
rule.id = count++;
|
|
||||||
|
|
||||||
DEBUG_INFO(
|
|
||||||
"Rule %u: %u%% IF X %s %4u %s Y %s %4u",
|
|
||||||
rule.id,
|
|
||||||
100 / (1 << rule.level),
|
|
||||||
rule.greater ? "> " : "==",
|
|
||||||
rule.x,
|
|
||||||
rule.greater ? "OR " : "AND",
|
|
||||||
rule.greater ? "> " : "==",
|
|
||||||
rule.y
|
|
||||||
);
|
|
||||||
vector_push(&downsampleRules, &rule);
|
|
||||||
|
|
||||||
token = strtok(NULL, ",");
|
|
||||||
}
|
|
||||||
free(tmp);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dxgi_initOptions(void)
|
static void dxgi_initOptions(void)
|
||||||
{
|
{
|
||||||
struct Option options[] =
|
struct Option options[] =
|
||||||
@ -182,14 +119,7 @@ static void dxgi_initOptions(void)
|
|||||||
.type = OPTION_TYPE_STRING,
|
.type = OPTION_TYPE_STRING,
|
||||||
.value.x_string = NULL
|
.value.x_string = NULL
|
||||||
},
|
},
|
||||||
{
|
DOWNSAMPLE_PARSER("dxgi"),
|
||||||
.module = "dxgi",
|
|
||||||
.name = "downsample", //dxgi:downsample=1920x1200:1,
|
|
||||||
.description = "Downsample conditions and levels, format: [>](width)x(height):level",
|
|
||||||
.type = OPTION_TYPE_STRING,
|
|
||||||
.value.x_string = NULL,
|
|
||||||
.parser = downsampleOptParser
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.module = "dxgi",
|
.module = "dxgi",
|
||||||
.name = "maxTextures",
|
.name = "maxTextures",
|
||||||
@ -761,27 +691,13 @@ static bool dxgi_init(void)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->downsampleLevel = 0;
|
|
||||||
this->outputWidth = this->width;
|
this->outputWidth = this->width;
|
||||||
this->outputHeight = this->height;
|
this->outputHeight = this->height;
|
||||||
|
DownsampleRule * rule = downsampleRule_match(this->width, this->height);
|
||||||
DownsampleRule * rule, * match = NULL;
|
if (rule)
|
||||||
vector_forEachRef(rule, &downsampleRules)
|
|
||||||
{
|
{
|
||||||
if (
|
this->outputWidth = rule->targetX;
|
||||||
( rule->greater && (this->width > rule->x || this->height > rule->y)) ||
|
this->outputHeight = rule->targetY;
|
||||||
(!rule->greater && (this->width == rule->x && this->height == rule->y)))
|
|
||||||
{
|
|
||||||
match = rule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match)
|
|
||||||
{
|
|
||||||
DEBUG_INFO("Matched downsample rule %d", rule->id);
|
|
||||||
this->downsampleLevel = match->level;
|
|
||||||
this->outputWidth >>= match->level;
|
|
||||||
this->outputHeight >>= match->level;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_INFO("Request Size : %u x %u", this->outputWidth, this->outputHeight);
|
DEBUG_INFO("Request Size : %u x %u", this->outputWidth, this->outputHeight);
|
||||||
@ -940,10 +856,10 @@ static void rectToFrameDamageRect(RECT * src, FrameDamageRect * dst)
|
|||||||
{
|
{
|
||||||
*dst = (FrameDamageRect)
|
*dst = (FrameDamageRect)
|
||||||
{
|
{
|
||||||
.x = src->left >> this->downsampleLevel,
|
.x = src->left ,
|
||||||
.y = src->top >> this->downsampleLevel,
|
.y = src->top ,
|
||||||
.width = (src->right - src->left) >> this->downsampleLevel,
|
.width = (src->right - src->left),
|
||||||
.height = (src->bottom - src->top) >> this->downsampleLevel
|
.height = (src->bottom - src->top)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,6 @@ struct DXGIInterface
|
|||||||
unsigned int formatVer;
|
unsigned int formatVer;
|
||||||
unsigned int width , outputWidth , dataWidth;
|
unsigned int width , outputWidth , dataWidth;
|
||||||
unsigned int height, outputHeight, dataHeight;
|
unsigned int height, outputHeight, dataHeight;
|
||||||
unsigned int downsampleLevel;
|
|
||||||
unsigned int pitch;
|
unsigned int pitch;
|
||||||
unsigned int stride;
|
unsigned int stride;
|
||||||
unsigned int padding;
|
unsigned int padding;
|
||||||
|
@ -191,23 +191,12 @@ static bool nvfbc_create(
|
|||||||
|
|
||||||
static void updateScale(void)
|
static void updateScale(void)
|
||||||
{
|
{
|
||||||
DownsampleRule * rule, * match = NULL;
|
DownsampleRule * rule = downsampleRule_match(this->width, this->height);
|
||||||
vector_forEachRef(rule, &downsampleRules)
|
if (rule)
|
||||||
{
|
{
|
||||||
if (
|
|
||||||
( rule->greater && (this->width > rule->x || this->height > rule->y)) ||
|
|
||||||
(!rule->greater && (this->width == rule->x && this->height == rule->y)))
|
|
||||||
{
|
|
||||||
match = rule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match)
|
|
||||||
{
|
|
||||||
DEBUG_INFO("Matched downsample rule %d", rule->id);
|
|
||||||
this->scale = true;
|
this->scale = true;
|
||||||
this->targetWidth = match->targetX;
|
this->targetWidth = rule->targetX;
|
||||||
this->targetHeight = match->targetY;
|
this->targetHeight = rule->targetY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,3 +84,22 @@ bool downsampleParser(struct Option * opt, const char * str)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DownsampleRule * downsampleRule_match(int x, int y)
|
||||||
|
{
|
||||||
|
DownsampleRule * rule, * match = NULL;
|
||||||
|
vector_forEachRef(rule, &downsampleRules)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
( rule->greater && (x > rule->x || y > rule->y)) ||
|
||||||
|
(!rule->greater && (x == rule->x && y == rule->y)))
|
||||||
|
{
|
||||||
|
match = rule;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match)
|
||||||
|
DEBUG_INFO("Matched downsample rule %d", rule->id);
|
||||||
|
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user