mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-08 23:55:10 +00:00
engines: fine-tune scene effect performance
Skip scene effects whenever possible, based on predefined conditions.
This commit is contained in:
parent
3f9adf2270
commit
c216805a87
7 changed files with 46 additions and 34 deletions
|
@ -954,7 +954,7 @@ void GlRenderer::effectGaussianBlurUpdate(RenderEffectGaussianBlur* effect, cons
|
||||||
blur->scale = std::sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12);
|
blur->scale = std::sqrt(transform.e11 * transform.e11 + transform.e12 * transform.e12);
|
||||||
blur->extend = 2 * blur->sigma * blur->scale;
|
blur->extend = 2 * blur->sigma * blur->scale;
|
||||||
effect->rd = blur;
|
effect->rd = blur;
|
||||||
effect->valid = true;
|
effect->valid = (blur->extend > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -980,7 +980,7 @@ void GlRenderer::effectDropShadowUpdate(RenderEffectDropShadow* effect, const Ma
|
||||||
dropShadow->offset[1] = offset.y;
|
dropShadow->offset[1] = offset.y;
|
||||||
dropShadow->extend = 2 * std::max(sigma * scale + std::abs(offset.x), sigma * scale + std::abs(offset.y));
|
dropShadow->extend = 2 * std::max(sigma * scale + std::abs(offset.x), sigma * scale + std::abs(offset.y));
|
||||||
effect->rd = dropShadow;
|
effect->rd = dropShadow;
|
||||||
effect->valid = true;
|
effect->valid = (dropShadow->extend > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1011,7 +1011,7 @@ void GlRenderer::effectTintUpdate(RenderEffectTint* effect, const Matrix& transf
|
||||||
params->params[7] = 0.0f;
|
params->params[7] = 0.0f;
|
||||||
params->params[8] = effect->intensity / 255.0f;
|
params->params[8] = effect->intensity / 255.0f;
|
||||||
effect->rd = params;
|
effect->rd = params;
|
||||||
effect->valid = true;
|
effect->valid = (effect->intensity > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1076,7 +1076,6 @@ void GlRenderer::prepare(RenderEffect* effect, const Matrix& transform)
|
||||||
case SceneEffect::Tritone: effectTritoneUpdate(static_cast<RenderEffectTritone*>(effect), transform); break;
|
case SceneEffect::Tritone: effectTritoneUpdate(static_cast<RenderEffectTritone*>(effect), transform); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
effect->valid = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -469,7 +469,7 @@ bool effectFill(SwCompositor* cmp, const RenderEffectFill* params, bool direct)
|
||||||
|
|
||||||
void effectTintUpdate(RenderEffectTint* params)
|
void effectTintUpdate(RenderEffectTint* params)
|
||||||
{
|
{
|
||||||
params->valid = true;
|
params->valid = (params->intensity > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -511,7 +511,7 @@ void WgRenderDataViewportPool::release(WgContext& context)
|
||||||
// WgRenderDataEffectParams
|
// WgRenderDataEffectParams
|
||||||
//***********************************************************************
|
//***********************************************************************
|
||||||
|
|
||||||
void WgRenderDataEffectParams::update(WgContext& context, const WgShaderTypeEffectParams& effectParams)
|
void WgRenderDataEffectParams::update(WgContext& context, WgShaderTypeEffectParams& effectParams)
|
||||||
{
|
{
|
||||||
if (context.allocateBufferUniform(bufferParams, &effectParams.params, sizeof(effectParams.params))) {
|
if (context.allocateBufferUniform(bufferParams, &effectParams.params, sizeof(effectParams.params))) {
|
||||||
context.layouts.releaseBindGroup(bindGroupParams);
|
context.layouts.releaseBindGroup(bindGroupParams);
|
||||||
|
@ -520,22 +520,22 @@ void WgRenderDataEffectParams::update(WgContext& context, const WgShaderTypeEffe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgRenderDataEffectParams::update(WgContext& context, const RenderEffectGaussianBlur* gaussian, const Matrix& transform)
|
void WgRenderDataEffectParams::update(WgContext& context, RenderEffectGaussianBlur* gaussian, const Matrix& transform)
|
||||||
{
|
{
|
||||||
assert(gaussian);
|
assert(gaussian);
|
||||||
WgShaderTypeEffectParams effectParams;
|
WgShaderTypeEffectParams effectParams;
|
||||||
effectParams.update(gaussian, transform);
|
if (!effectParams.update(gaussian, transform)) return;
|
||||||
update(context, effectParams);
|
update(context, effectParams);
|
||||||
level = int(WG_GAUSSIAN_MAX_LEVEL * ((gaussian->quality - 1) * 0.01f)) + 1;
|
level = int(WG_GAUSSIAN_MAX_LEVEL * ((gaussian->quality - 1) * 0.01f)) + 1;
|
||||||
extend = effectParams.extend;
|
extend = effectParams.extend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgRenderDataEffectParams::update(WgContext& context, const RenderEffectDropShadow* dropShadow, const Matrix& transform)
|
void WgRenderDataEffectParams::update(WgContext& context, RenderEffectDropShadow* dropShadow, const Matrix& transform)
|
||||||
{
|
{
|
||||||
assert(dropShadow);
|
assert(dropShadow);
|
||||||
WgShaderTypeEffectParams effectParams;
|
WgShaderTypeEffectParams effectParams;
|
||||||
effectParams.update(dropShadow, transform);
|
if (!effectParams.update(dropShadow, transform)) return;
|
||||||
update(context, effectParams);
|
update(context, effectParams);
|
||||||
level = int(WG_GAUSSIAN_MAX_LEVEL * ((dropShadow->quality - 1) * 0.01f)) + 1;
|
level = int(WG_GAUSSIAN_MAX_LEVEL * ((dropShadow->quality - 1) * 0.01f)) + 1;
|
||||||
extend = effectParams.extend;
|
extend = effectParams.extend;
|
||||||
|
@ -543,29 +543,29 @@ void WgRenderDataEffectParams::update(WgContext& context, const RenderEffectDrop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgRenderDataEffectParams::update(WgContext& context, const RenderEffectFill* fill)
|
void WgRenderDataEffectParams::update(WgContext& context, RenderEffectFill* fill)
|
||||||
{
|
{
|
||||||
assert(fill);
|
assert(fill);
|
||||||
WgShaderTypeEffectParams effectParams;
|
WgShaderTypeEffectParams effectParams;
|
||||||
effectParams.update(fill);
|
if (!effectParams.update(fill)) return;
|
||||||
update(context, effectParams);
|
update(context, effectParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgRenderDataEffectParams::update(WgContext& context, const RenderEffectTint* tint)
|
void WgRenderDataEffectParams::update(WgContext& context, RenderEffectTint* tint)
|
||||||
{
|
{
|
||||||
assert(tint);
|
assert(tint);
|
||||||
WgShaderTypeEffectParams effectParams;
|
WgShaderTypeEffectParams effectParams;
|
||||||
effectParams.update(tint);
|
if (!effectParams.update(tint)) return;
|
||||||
update(context, effectParams);
|
update(context, effectParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgRenderDataEffectParams::update(WgContext& context, const RenderEffectTritone* tritone)
|
void WgRenderDataEffectParams::update(WgContext& context, RenderEffectTritone* tritone)
|
||||||
{
|
{
|
||||||
assert(tritone);
|
assert(tritone);
|
||||||
WgShaderTypeEffectParams effectParams;
|
WgShaderTypeEffectParams effectParams;
|
||||||
effectParams.update(tritone);
|
if (!effectParams.update(tritone)) return;
|
||||||
update(context, effectParams);
|
update(context, effectParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,12 +180,12 @@ struct WgRenderDataEffectParams
|
||||||
uint32_t level{};
|
uint32_t level{};
|
||||||
Point offset{};
|
Point offset{};
|
||||||
|
|
||||||
void update(WgContext& context, const WgShaderTypeEffectParams& effectParams);
|
void update(WgContext& context, WgShaderTypeEffectParams& effectParams);
|
||||||
void update(WgContext& context, const RenderEffectGaussianBlur* gaussian, const Matrix& transform);
|
void update(WgContext& context, RenderEffectGaussianBlur* gaussian, const Matrix& transform);
|
||||||
void update(WgContext& context, const RenderEffectDropShadow* dropShadow, const Matrix& transform);
|
void update(WgContext& context, RenderEffectDropShadow* dropShadow, const Matrix& transform);
|
||||||
void update(WgContext& context, const RenderEffectFill* fill);
|
void update(WgContext& context, RenderEffectFill* fill);
|
||||||
void update(WgContext& context, const RenderEffectTint* tint);
|
void update(WgContext& context, RenderEffectTint* tint);
|
||||||
void update(WgContext& context, const RenderEffectTritone* tritone);
|
void update(WgContext& context, RenderEffectTritone* tritone);
|
||||||
void release(WgContext& context);
|
void release(WgContext& context);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -520,8 +520,6 @@ void WgRenderer::prepare(RenderEffect* effect, const Matrix& transform)
|
||||||
TVGERR("WG_ENGINE", "Missing effect type? = %d", (int) effect->type);
|
TVGERR("WG_ENGINE", "Missing effect type? = %d", (int) effect->type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
effect->valid = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ void WgShaderTypeGradientData::update(const Fill* fill)
|
||||||
// WgShaderTypeEffectParams
|
// WgShaderTypeEffectParams
|
||||||
//************************************************************************
|
//************************************************************************
|
||||||
|
|
||||||
void WgShaderTypeEffectParams::update(const RenderEffectGaussianBlur* gaussian, const Matrix& transform)
|
bool WgShaderTypeEffectParams::update(RenderEffectGaussianBlur* gaussian, const Matrix& transform)
|
||||||
{
|
{
|
||||||
assert(gaussian);
|
assert(gaussian);
|
||||||
const float sigma = gaussian->sigma;
|
const float sigma = gaussian->sigma;
|
||||||
|
@ -214,10 +214,13 @@ void WgShaderTypeEffectParams::update(const RenderEffectGaussianBlur* gaussian,
|
||||||
params[2] = kernel;
|
params[2] = kernel;
|
||||||
params[3] = 0.0f;
|
params[3] = 0.0f;
|
||||||
extend = params[2] * 2; // kernel
|
extend = params[2] * 2; // kernel
|
||||||
|
|
||||||
|
gaussian->valid = (extend > 0);
|
||||||
|
return gaussian->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgShaderTypeEffectParams::update(const RenderEffectDropShadow* dropShadow, const Matrix& transform)
|
bool WgShaderTypeEffectParams::update(RenderEffectDropShadow* dropShadow, const Matrix& transform)
|
||||||
{
|
{
|
||||||
assert(dropShadow);
|
assert(dropShadow);
|
||||||
const float radian = tvg::deg2rad(90.0f - dropShadow->angle);
|
const float radian = tvg::deg2rad(90.0f - dropShadow->angle);
|
||||||
|
@ -243,19 +246,25 @@ void WgShaderTypeEffectParams::update(const RenderEffectDropShadow* dropShadow,
|
||||||
params[8] = offset.x;
|
params[8] = offset.x;
|
||||||
params[9] = offset.y;
|
params[9] = offset.y;
|
||||||
extend = params[2] * 2; // kernel
|
extend = params[2] * 2; // kernel
|
||||||
|
|
||||||
|
dropShadow->valid = (extend > 0);
|
||||||
|
return dropShadow->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgShaderTypeEffectParams::update(const RenderEffectFill* fill)
|
bool WgShaderTypeEffectParams::update(RenderEffectFill* fill)
|
||||||
{
|
{
|
||||||
params[0] = fill->color[0] / 255.0f;
|
params[0] = fill->color[0] / 255.0f;
|
||||||
params[1] = fill->color[1] / 255.0f;
|
params[1] = fill->color[1] / 255.0f;
|
||||||
params[2] = fill->color[2] / 255.0f;
|
params[2] = fill->color[2] / 255.0f;
|
||||||
params[3] = fill->color[3] / 255.0f;
|
params[3] = fill->color[3] / 255.0f;
|
||||||
|
|
||||||
|
fill->valid = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgShaderTypeEffectParams::update(const RenderEffectTint* tint)
|
bool WgShaderTypeEffectParams::update(RenderEffectTint* tint)
|
||||||
{
|
{
|
||||||
params[0] = tint->black[0] / 255.0f;
|
params[0] = tint->black[0] / 255.0f;
|
||||||
params[1] = tint->black[1] / 255.0f;
|
params[1] = tint->black[1] / 255.0f;
|
||||||
|
@ -266,10 +275,13 @@ void WgShaderTypeEffectParams::update(const RenderEffectTint* tint)
|
||||||
params[6] = tint->white[2] / 255.0f;
|
params[6] = tint->white[2] / 255.0f;
|
||||||
params[7] = 0.0f;
|
params[7] = 0.0f;
|
||||||
params[8] = tint->intensity / 255.0f;
|
params[8] = tint->intensity / 255.0f;
|
||||||
|
|
||||||
|
tint->valid = (tint->intensity > 0);
|
||||||
|
return tint->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgShaderTypeEffectParams::update(const RenderEffectTritone* tritone)
|
bool WgShaderTypeEffectParams::update(RenderEffectTritone* tritone)
|
||||||
{
|
{
|
||||||
params[0] = tritone->shadow[0] / 255.0f;
|
params[0] = tritone->shadow[0] / 255.0f;
|
||||||
params[1] = tritone->shadow[1] / 255.0f;
|
params[1] = tritone->shadow[1] / 255.0f;
|
||||||
|
@ -283,4 +295,7 @@ void WgShaderTypeEffectParams::update(const RenderEffectTritone* tritone)
|
||||||
params[9] = tritone->highlight[1] / 255.0f;
|
params[9] = tritone->highlight[1] / 255.0f;
|
||||||
params[10] = tritone->highlight[2] / 255.0f;
|
params[10] = tritone->highlight[2] / 255.0f;
|
||||||
params[11] = 0.0f;
|
params[11] = 0.0f;
|
||||||
|
|
||||||
|
tritone->valid = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,11 +109,11 @@ struct WgShaderTypeEffectParams
|
||||||
uint32_t extend{}; // gaussian blur extend
|
uint32_t extend{}; // gaussian blur extend
|
||||||
Point offset{}; // drop shadow offset
|
Point offset{}; // drop shadow offset
|
||||||
|
|
||||||
void update(const RenderEffectGaussianBlur* gaussian, const Matrix& transform);
|
bool update(RenderEffectGaussianBlur* gaussian, const Matrix& transform);
|
||||||
void update(const RenderEffectDropShadow* dropShadow, const Matrix& transform);
|
bool update(RenderEffectDropShadow* dropShadow, const Matrix& transform);
|
||||||
void update(const RenderEffectFill* fill);
|
bool update(RenderEffectFill* fill);
|
||||||
void update(const RenderEffectTint* tint);
|
bool update(RenderEffectTint* tint);
|
||||||
void update(const RenderEffectTritone* tritone);
|
bool update(RenderEffectTritone* tritone);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _TVG_WG_SHADER_TYPES_H_
|
#endif // _TVG_WG_SHADER_TYPES_H_
|
||||||
|
|
Loading…
Add table
Reference in a new issue