api: Add Composition blend mode

The composition mode enables intermediate blending. When a scene
 uses Composition mode, it generates an intermediate buffer to
render the scene image first. This image can then be blended
with the canvas afterward.

Please avoid to use this, unless you really need to composite
the precomposite scene. This feature is relatively expensive
at performance.

C++ API:
+BlendMethod::Composition

C API:
+Tvg_Blend_Method::TVG_BLEND_METHOD_COMPOSITION
This commit is contained in:
Hermet Park 2025-07-17 11:49:29 +09:00
parent a80b0aa188
commit 5ae97c7f1a
4 changed files with 11 additions and 5 deletions

View file

@ -214,7 +214,8 @@ enum class BlendMethod : uint8_t
Color, ///< Reserved. Not supported.
Luminosity, ///< Reserved. Not supported.
Add, ///< Simply adds pixel values of one layer with the other. (S + D)
HardMix ///< Reserved. Not supported.
HardMix, ///< Reserved. Not supported.
Composition = 255 ///< Used for intermediate composition. @since 1.0
};

View file

@ -164,7 +164,8 @@ typedef enum {
TVG_BLEND_METHOD_COLOR, ///< Reserved. Not supported.
TVG_BLEND_METHOD_LUMINOSITY, ///< Reserved. Not supported.
TVG_BLEND_METHOD_ADD, ///< Simply adds pixel values of one layer with the other. (S + D)
TVG_BLEND_METHOD_HARDMIX ///< Reserved. Not supported.
TVG_BLEND_METHOD_HARDMIX, ///< Reserved. Not supported.
TVG_BLEND_METHOD_COMPOSITION = 255 ///< Used for intermediate composition. @since 1.0
} Tvg_Blend_Method;

View file

@ -528,6 +528,7 @@ bool SwRenderer::blend(BlendMethod method)
switch (method) {
case BlendMethod::Normal:
case BlendMethod::Composition:
surface->blender = nullptr;
break;
case BlendMethod::Multiply:

View file

@ -429,11 +429,14 @@ uint8_t Paint::opacity() const noexcept
Result Paint::blend(BlendMethod method) noexcept
{
if (method > BlendMethod::HardMix) return Result::InvalidArguments;
//TODO: Remove later
if (method == BlendMethod::Hue || method == BlendMethod::Saturation || method == BlendMethod::Color || method == BlendMethod::Luminosity || method == BlendMethod::HardMix) return Result::NonSupport;
pImpl->blend(method);
return Result::Success;
if (method == BlendMethod::Composition || method <= BlendMethod::HardMix) {
pImpl->blend(method);
return Result::Success;
}
return Result::InvalidArguments;
}