api: removed redundant CompisiteMethod::ClipPath

issue: https://github.com/thorvg/thorvg/issues/1372
This commit is contained in:
Hermet Park 2024-10-12 12:25:29 +09:00 committed by Hermet Park
parent 9bc900206b
commit 367ac5f331
10 changed files with 18 additions and 38 deletions

View file

@ -171,7 +171,6 @@ enum class FillRule : uint8_t
enum class CompositeMethod : uint8_t
{
None = 0, ///< No composition is applied.
ClipPath, ///< The intersection of the source and the target is determined and only the resulting pixels from the source are rendered. Note that ClipPath only supports the Shape type. @deprecated Use Paint::clip() instead.
AlphaMask, ///< Alpha Masking using the compositing target's pixels as an alpha value.
InvAlphaMask, ///< Alpha Masking using the complement to the compositing target's pixels as an alpha value.
LumaMask, ///< Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the compositing target's pixels. @since 0.9

View file

@ -138,7 +138,6 @@ typedef enum {
*/
typedef enum {
TVG_COMPOSITE_METHOD_NONE = 0, ///< No composition is applied.
TVG_COMPOSITE_METHOD_CLIP_PATH, ///< The intersection of the source and the target is determined and only the resulting pixels from the source are rendered. Note that ClipPath only supports the Shape type. @deprecated Use Paint::clip() instead.
TVG_COMPOSITE_METHOD_ALPHA_MASK, ///< The pixels of the source and the target are alpha blended. As a result, only the part of the source, which intersects with the target is visible.
TVG_COMPOSITE_METHOD_INVERSE_ALPHA_MASK, ///< The pixels of the source and the complement to the target's pixels are alpha blended. As a result, only the part of the source which is not covered by the target is visible.
TVG_COMPOSITE_METHOD_LUMA_MASK, ///< The source pixels are converted to grayscale (luma value) and alpha blended with the target. As a result, only the part of the source which intersects with the target is visible. \since 0.9

View file

@ -250,7 +250,7 @@ struct SwSurface : RenderSurface
SwAlpha alpha(CompositeMethod method)
{
auto idx = (int)(method) - 2; //0: None, 1: ClipPath
auto idx = (int)(method) - 1; //-1 for None
return alphas[idx > 3 ? 0 : idx]; //CompositeMethod has only four Matting methods.
}

View file

@ -154,7 +154,7 @@ static inline bool _blending(const SwSurface* surface)
This would help to enhance the performance by avoiding the unnecessary matting from the composition */
static inline bool _compositing(const SwSurface* surface)
{
if (!surface->compositor || (int)surface->compositor->method <= (int)CompositeMethod::ClipPath) return false;
if (!surface->compositor || surface->compositor->method == CompositeMethod::None) return false;
return true;
}

View file

@ -457,9 +457,6 @@ Result Paint::clip(std::unique_ptr<Paint> clipper) noexcept
Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept
{
//TODO: remove. Keep this for the backward compatibility
if (target && method == CompositeMethod::ClipPath) return clip(std::move(target));
auto p = target.release();
if (pImpl->composite(this, p, method)) return Result::Success;
@ -474,11 +471,6 @@ CompositeMethod Paint::composite(const Paint** target) const noexcept
if (target) *target = pImpl->compData->target;
return pImpl->compData->method;
} else {
//TODO: remove. Keep this for the backward compatibility
if (pImpl->clipper) {
if (target) *target = pImpl->clipper;
return CompositeMethod::ClipPath;
}
if (target) *target = nullptr;
return CompositeMethod::None;
}

View file

@ -63,10 +63,8 @@ bool Picture::Impl::needComposition(uint8_t opacity)
//Composition test
const Paint* target;
auto method = picture->composite(&target);
if (!target || method == tvg::CompositeMethod::ClipPath) return false;
if (target->pImpl->opacity == 255 || target->pImpl->opacity == 0) return false;
picture->composite(&target);
if (!target || target->pImpl->opacity == 255 || target->pImpl->opacity == 0) return false;
return true;
}

View file

@ -89,11 +89,8 @@ struct Scene::Impl
//post effects requires composition
if (effects) return true;
//Masking may require composition (even if opacity == 255)
auto compMethod = scene->composite(nullptr);
if (compMethod != CompositeMethod::None && compMethod != CompositeMethod::ClipPath) return true;
//Blending may require composition (even if opacity == 255)
//Masking / Blending may require composition (even if opacity == 255)
if (scene->composite(nullptr) != CompositeMethod::None) return true;
if (PP(scene)->blendMethod != BlendMethod::Normal) return true;
//Half translucent requires intermediate composition.

View file

@ -81,18 +81,17 @@ struct Shape::Impl
//Composition test
const Paint* target;
auto method = shape->composite(&target);
if (!target || method == CompositeMethod::ClipPath) return false;
if (target->pImpl->opacity == 255 || target->pImpl->opacity == 0) {
if (target->type() == Type::Shape) {
auto shape = static_cast<const Shape*>(target);
if (!shape->fill()) {
uint8_t r, g, b, a;
shape->fillColor(&r, &g, &b, &a);
if (a == 0 || a == 255) {
if (method == CompositeMethod::LumaMask || method == CompositeMethod::InvLumaMask) {
if ((r == 255 && g == 255 && b == 255) || (r == 0 && g == 0 && b == 0)) return false;
} else return false;
}
if (!target) return false;
if ((target->pImpl->opacity == 255 || target->pImpl->opacity == 0) && target->type() == Type::Shape) {
auto shape = static_cast<const Shape*>(target);
if (!shape->fill()) {
uint8_t r, g, b, a;
shape->fillColor(&r, &g, &b, &a);
if (a == 0 || a == 255) {
if (method == CompositeMethod::LumaMask || method == CompositeMethod::InvLumaMask) {
if ((r == 255 && g == 255 && b == 255) || (r == 0 && g == 0 && b == 0)) return false;
} else return false;
}
}
}

View file

@ -343,11 +343,9 @@ void WgPipelines::initialize(WgContext& context)
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
primitiveState, multisampleState, blendStateNrm);
// TODO: remove fs_main_ClipPath shader from list after removing CompositeMethod::ClipPath value
// compose shader names
const char* shaderComposeNames[] {
"fs_main_None",
"fs_main_ClipPath", // TODO: remove after CompositeMethod updated
"fs_main_AlphaMask",
"fs_main_InvAlphaMask",
"fs_main_LumaMask",
@ -360,11 +358,9 @@ void WgPipelines::initialize(WgContext& context)
"fs_main_DarkenMask"
};
// TODO: remove fs_main_ClipPath shader from list after removing CompositeMethod::ClipPath value
// compose shader blend states
const WGPUBlendState composeBlends[] {
blendStateNrm, // None
blendStateNrm, // ClipPath // TODO: remove after CompositeMethod updated
blendStateNrm, // AlphaMask
blendStateNrm, // InvAlphaMask
blendStateNrm, // LumaMask

View file

@ -66,7 +66,7 @@ public:
WGPURenderPipeline linear[2]{};
WGPURenderPipeline image[2]{};
WGPURenderPipeline sceneClip;
WGPURenderPipeline sceneComp[12]; // TODO: update to 11 after removing CompositeMethod::ClipPath enum value
WGPURenderPipeline sceneComp[11];
WGPURenderPipeline sceneBlend;
WGPURenderPipeline blit{};
WGPURenderPipeline clipPath{};