From 367ac5f331383eea978f07131c64e54fee3f8e58 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 12 Oct 2024 12:25:29 +0900 Subject: [PATCH] api: removed redundant CompisiteMethod::ClipPath issue: https://github.com/thorvg/thorvg/issues/1372 --- inc/thorvg.h | 1 - src/bindings/capi/thorvg_capi.h | 1 - src/renderer/sw_engine/tvgSwCommon.h | 2 +- src/renderer/sw_engine/tvgSwRaster.cpp | 2 +- src/renderer/tvgPaint.cpp | 8 -------- src/renderer/tvgPicture.cpp | 6 ++---- src/renderer/tvgScene.h | 7 ++----- src/renderer/tvgShape.h | 23 +++++++++++------------ src/renderer/wg_engine/tvgWgPipelines.cpp | 4 ---- src/renderer/wg_engine/tvgWgPipelines.h | 2 +- 10 files changed, 18 insertions(+), 38 deletions(-) diff --git a/inc/thorvg.h b/inc/thorvg.h index 1482e8c5..b5787042 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -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 diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index ebb35cf0..154758ad 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -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 diff --git a/src/renderer/sw_engine/tvgSwCommon.h b/src/renderer/sw_engine/tvgSwCommon.h index 0ff21a66..aba7f844 100644 --- a/src/renderer/sw_engine/tvgSwCommon.h +++ b/src/renderer/sw_engine/tvgSwCommon.h @@ -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. } diff --git a/src/renderer/sw_engine/tvgSwRaster.cpp b/src/renderer/sw_engine/tvgSwRaster.cpp index 142ae8ac..d1fecd55 100644 --- a/src/renderer/sw_engine/tvgSwRaster.cpp +++ b/src/renderer/sw_engine/tvgSwRaster.cpp @@ -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; } diff --git a/src/renderer/tvgPaint.cpp b/src/renderer/tvgPaint.cpp index 74515478..ca4c0977 100644 --- a/src/renderer/tvgPaint.cpp +++ b/src/renderer/tvgPaint.cpp @@ -457,9 +457,6 @@ Result Paint::clip(std::unique_ptr clipper) noexcept Result Paint::composite(std::unique_ptr 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; } diff --git a/src/renderer/tvgPicture.cpp b/src/renderer/tvgPicture.cpp index d6a8b571..737aba46 100644 --- a/src/renderer/tvgPicture.cpp +++ b/src/renderer/tvgPicture.cpp @@ -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; } diff --git a/src/renderer/tvgScene.h b/src/renderer/tvgScene.h index cb2ef7f6..cb95f602 100644 --- a/src/renderer/tvgScene.h +++ b/src/renderer/tvgScene.h @@ -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. diff --git a/src/renderer/tvgShape.h b/src/renderer/tvgShape.h index 8107b484..734aa97b 100644 --- a/src/renderer/tvgShape.h +++ b/src/renderer/tvgShape.h @@ -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(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(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; } } } diff --git a/src/renderer/wg_engine/tvgWgPipelines.cpp b/src/renderer/wg_engine/tvgWgPipelines.cpp index 0bb78328..30180a1c 100755 --- a/src/renderer/wg_engine/tvgWgPipelines.cpp +++ b/src/renderer/wg_engine/tvgWgPipelines.cpp @@ -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 diff --git a/src/renderer/wg_engine/tvgWgPipelines.h b/src/renderer/wg_engine/tvgWgPipelines.h index bba7d864..39be0f4c 100755 --- a/src/renderer/wg_engine/tvgWgPipelines.h +++ b/src/renderer/wg_engine/tvgWgPipelines.h @@ -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{};