api: renamed FillRule::Winding to NonZero

aligned the name with the web standard.
This commit is contained in:
Hermet Park 2024-12-27 18:11:45 +09:00 committed by Hermet Park
parent f2883a31da
commit 0e9bc74603
18 changed files with 31 additions and 37 deletions

View file

@ -41,7 +41,7 @@ struct UserExample : tvgexam::Example
shape1->lineTo(80, 355); shape1->lineTo(80, 355);
shape1->close(); shape1->close();
shape1->fill(255, 255, 255); shape1->fill(255, 255, 255);
shape1->fill(tvg::FillRule::Winding); //Fill all winding shapes shape1->fill(tvg::FillRule::NonZero); //Fill all winding shapes
canvas->push(shape1); canvas->push(shape1);

View file

@ -156,7 +156,7 @@ enum class FillSpread : uint8_t
*/ */
enum class FillRule : uint8_t enum class FillRule : uint8_t
{ {
Winding = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape. NonZero = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape.
EvenOdd ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape. EvenOdd ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape.
}; };
@ -1136,7 +1136,7 @@ public:
/** /**
* @brief Sets the fill rule for the Shape object. * @brief Sets the fill rule for the Shape object.
* *
* @param[in] r The fill rule value. The default value is @c FillRule::Winding. * @param[in] r The fill rule value. The default value is @c FillRule::NonZero.
*/ */
Result fill(FillRule r) noexcept; Result fill(FillRule r) noexcept;

View file

@ -275,7 +275,7 @@ typedef enum {
* @brief Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape. * @brief Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape.
*/ */
typedef enum { typedef enum {
TVG_FILL_RULE_WINDING = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape. TVG_FILL_RULE_NON_ZERO = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape.
TVG_FILL_RULE_EVEN_ODD ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape. TVG_FILL_RULE_EVEN_ODD ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape.
} Tvg_Fill_Rule; } Tvg_Fill_Rule;
@ -1509,7 +1509,7 @@ TVG_API Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint* paint, uint8_t* r,
* @brief Sets the shape's fill rule. * @brief Sets the shape's fill rule.
* *
* @param[in] paint A Tvg_Paint pointer to the shape object. * @param[in] paint A Tvg_Paint pointer to the shape object.
* @param[in] rule The fill rule value. The default value is @c TVG_FILL_RULE_WINDING. * @param[in] rule The fill rule value. The default value is @c TVG_FILL_RULE_NON_ZERO.
* *
* @return Tvg_Result enumeration. * @return Tvg_Result enumeration.
* @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer.

View file

@ -621,7 +621,7 @@ struct LottieSolidFill : LottieSolid
} }
} }
FillRule rule = FillRule::Winding; FillRule rule = FillRule::NonZero;
}; };
@ -682,7 +682,7 @@ struct LottieGradientFill : LottieGradient
LottieObject::type = LottieObject::GradientFill; LottieObject::type = LottieObject::GradientFill;
} }
FillRule rule = FillRule::Winding; FillRule rule = FillRule::NonZero;
}; };

View file

@ -122,7 +122,7 @@ RGB24 LottieParser::getColor(const char *str)
FillRule LottieParser::getFillRule() FillRule LottieParser::getFillRule()
{ {
switch (getInt()) { switch (getInt()) {
case 1: return FillRule::Winding; case 1: return FillRule::NonZero;
default: return FillRule::EvenOdd; default: return FillRule::EvenOdd;
} }
} }

View file

@ -318,7 +318,7 @@ static constexpr struct
}; };
_PARSE_TAG(FillRule, fillRule, FillRule, fillRuleTags, FillRule::Winding) _PARSE_TAG(FillRule, fillRule, FillRule, fillRuleTags, FillRule::NonZero)
/* parse the dash pattern used during stroking a path. /* parse the dash pattern used during stroking a path.
@ -1367,7 +1367,7 @@ static SvgNode* _createNode(SvgNode* parent, SvgNodeType type)
node->style->fill.paint.curColor = false; node->style->fill.paint.curColor = false;
node->style->curColorSet = false; node->style->curColorSet = false;
//Default fill rule is nonzero //Default fill rule is nonzero
node->style->fill.fillRule = FillRule::Winding; node->style->fill.fillRule = FillRule::NonZero;
//Default stroke is none //Default stroke is none
node->style->stroke.paint.none = true; node->style->stroke.paint.none = true;

View file

@ -198,12 +198,6 @@ constexpr SvgGradientFlags operator |(SvgGradientFlags a, SvgGradientFlags b)
return SvgGradientFlags(int(a) | int(b)); return SvgGradientFlags(int(a) | int(b));
} }
enum class SvgFillRule
{
Winding = 0,
OddEven = 1
};
enum class SvgMaskType enum class SvgMaskType
{ {
Luminance = 0, Luminance = 0,

View file

@ -64,7 +64,7 @@ static inline float getScaleFactor(const Matrix& m)
enum class GlStencilMode { enum class GlStencilMode {
None, None,
FillWinding, FillNonZero,
FillEvenOdd, FillEvenOdd,
Stroke, Stroke,
}; };

View file

@ -179,7 +179,7 @@ GlStencilMode GlGeometry::getStencilMode(RenderUpdateFlag flag)
if (flag & RenderUpdateFlag::GradientStroke) return GlStencilMode::Stroke; if (flag & RenderUpdateFlag::GradientStroke) return GlStencilMode::Stroke;
if (flag & RenderUpdateFlag::Image) return GlStencilMode::None; if (flag & RenderUpdateFlag::Image) return GlStencilMode::None;
if (mFillRule == FillRule::Winding) return GlStencilMode::FillWinding; if (mFillRule == FillRule::NonZero) return GlStencilMode::FillNonZero;
if (mFillRule == FillRule::EvenOdd) return GlStencilMode::FillEvenOdd; if (mFillRule == FillRule::EvenOdd) return GlStencilMode::FillEvenOdd;
return GlStencilMode::None; return GlStencilMode::None;

View file

@ -108,7 +108,7 @@ private:
Array<uint32_t> strokeIndex = {}; Array<uint32_t> strokeIndex = {};
Matrix mMatrix = {}; Matrix mMatrix = {};
FillRule mFillRule = FillRule::Winding; FillRule mFillRule = FillRule::NonZero;
RenderRegion mBounds = {}; RenderRegion mBounds = {};
}; };

View file

@ -884,7 +884,7 @@ bool Tessellator::tessellate(const RenderShape *rshape, bool antialias)
void Tessellator::tessellate(const Array<const RenderShape *> &shapes) void Tessellator::tessellate(const Array<const RenderShape *> &shapes)
{ {
this->fillRule = FillRule::Winding; this->fillRule = FillRule::NonZero;
for (uint32_t i = 0; i < shapes.count; i++) { for (uint32_t i = 0; i < shapes.count; i++) {
auto cmds = shapes[i]->path.cmds.data; auto cmds = shapes[i]->path.cmds.data;
@ -1247,7 +1247,7 @@ bool Tessellator::tessMesh()
bool Tessellator::matchFillRule(int32_t winding) bool Tessellator::matchFillRule(int32_t winding)
{ {
if (fillRule == FillRule::Winding) { if (fillRule == FillRule::NonZero) {
return winding != 0; return winding != 0;
} else { } else {
return (winding & 0x1) != 0; return (winding & 0x1) != 0;

View file

@ -62,7 +62,7 @@ private:
void emitPoly(MonotonePolygon* poly); void emitPoly(MonotonePolygon* poly);
void emitTriangle(Vertex* p1, Vertex* p2, Vertex* p3); void emitTriangle(Vertex* p1, Vertex* p2, Vertex* p3);
FillRule fillRule = FillRule::Winding; FillRule fillRule = FillRule::NonZero;
std::unique_ptr<ObjectHeap> pHeap; std::unique_ptr<ObjectHeap> pHeap;
Array<VertexList*> outlines; Array<VertexList*> outlines;
VertexList* pMesh; VertexList* pMesh;

View file

@ -181,7 +181,7 @@ struct RenderShape
Fill *fill = nullptr; Fill *fill = nullptr;
RenderColor color{}; RenderColor color{};
RenderStroke *stroke = nullptr; RenderStroke *stroke = nullptr;
FillRule rule = FillRule::Winding; FillRule rule = FillRule::NonZero;
~RenderShape() ~RenderShape()
{ {

View file

@ -479,7 +479,7 @@ struct Shape::Impl : Paint::Impl
rs.path.pts.clear(); rs.path.pts.clear();
rs.color.a = 0; rs.color.a = 0;
rs.rule = FillRule::Winding; rs.rule = FillRule::NonZero;
delete(rs.stroke); delete(rs.stroke);
rs.stroke = nullptr; rs.stroke = nullptr;

View file

@ -271,7 +271,7 @@ void WgCompositor::drawShape(WgContext& context, WgRenderDataShape* renderData)
if ((renderData->viewport.w <= 0) || (renderData->viewport.h <= 0)) return; if ((renderData->viewport.w <= 0) || (renderData->viewport.h <= 0)) return;
wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x, renderData->viewport.y, renderData->viewport.w, renderData->viewport.h); wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x, renderData->viewport.y, renderData->viewport.w, renderData->viewport.h);
// setup stencil rules // setup stencil rules
WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::Winding) ? pipelines.winding : pipelines.evenodd; WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd;
wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0);
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr);
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData->bindGroupPaint, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData->bindGroupPaint, 0, nullptr);
@ -318,7 +318,7 @@ void WgCompositor::blendShape(WgContext& context, WgRenderDataShape* renderData,
// render shape with blend settings // render shape with blend settings
wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x, renderData->viewport.y, renderData->viewport.w, renderData->viewport.h); wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x, renderData->viewport.y, renderData->viewport.w, renderData->viewport.h);
// setup stencil rules // setup stencil rules
WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::Winding) ? pipelines.winding : pipelines.evenodd; WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd;
wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0);
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr);
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData->bindGroupPaint, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData->bindGroupPaint, 0, nullptr);
@ -358,7 +358,7 @@ void WgCompositor::clipShape(WgContext& context, WgRenderDataShape* renderData)
if ((renderData->viewport.w <= 0) || (renderData->viewport.h <= 0)) return; if ((renderData->viewport.w <= 0) || (renderData->viewport.h <= 0)) return;
wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x, renderData->viewport.y, renderData->viewport.w, renderData->viewport.h); wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, renderData->viewport.x, renderData->viewport.y, renderData->viewport.w, renderData->viewport.h);
// setup stencil rules // setup stencil rules
WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::Winding) ? pipelines.winding : pipelines.evenodd; WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd;
wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0);
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr);
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData->bindGroupPaint, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData->bindGroupPaint, 0, nullptr);
@ -658,7 +658,7 @@ void WgCompositor::renderClipPath(WgContext& context, WgRenderDataPaint* paint)
// set transformations // set transformations
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, bindGroupViewMat, 0, nullptr);
// markup stencil // markup stencil
WGPURenderPipeline stencilPipeline = (renderData0->fillRule == FillRule::Winding) ? pipelines.winding : pipelines.evenodd; WGPURenderPipeline stencilPipeline = (renderData0->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd;
wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0);
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData0->bindGroupPaint, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData0->bindGroupPaint, 0, nullptr);
wgpuRenderPassEncoderSetPipeline(renderPassEncoder, stencilPipeline); wgpuRenderPassEncoderSetPipeline(renderPassEncoder, stencilPipeline);
@ -675,7 +675,7 @@ void WgCompositor::renderClipPath(WgContext& context, WgRenderDataPaint* paint)
// get render data // get render data
WgRenderDataShape* renderData = (WgRenderDataShape*)paint->clips[clipIndex]; WgRenderDataShape* renderData = (WgRenderDataShape*)paint->clips[clipIndex];
// markup stencil // markup stencil
WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::Winding) ? pipelines.winding : pipelines.evenodd; WGPURenderPipeline stencilPipeline = (renderData->fillRule == FillRule::NonZero) ? pipelines.nonzero : pipelines.evenodd;
wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0); wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0);
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData->bindGroupPaint, 0, nullptr); wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, renderData->bindGroupPaint, 0, nullptr);
wgpuRenderPassEncoderSetPipeline(renderPassEncoder, stencilPipeline); wgpuRenderPassEncoderSetPipeline(renderPassEncoder, stencilPipeline);

View file

@ -185,7 +185,7 @@ void WgPipelines::initialize(WgContext& context)
const WGPUBindGroupLayout bindGroupLayoutsBlit[] { layouts.layoutTexSampled }; const WGPUBindGroupLayout bindGroupLayoutsBlit[] { layouts.layoutTexSampled };
// depth stencil state markup // depth stencil state markup
const WGPUDepthStencilState depthStencilStateWinding = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_IncrementWrap, WGPUCompareFunction_Always, WGPUStencilOperation_DecrementWrap); const WGPUDepthStencilState depthStencilStateNonZero = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_IncrementWrap, WGPUCompareFunction_Always, WGPUStencilOperation_DecrementWrap);
const WGPUDepthStencilState depthStencilStateEvenOdd = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_Invert); const WGPUDepthStencilState depthStencilStateEvenOdd = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_Invert);
const WGPUDepthStencilState depthStencilStateDirect = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_Replace); const WGPUDepthStencilState depthStencilStateDirect = makeDepthStencilState(WGPUCompareFunction_Always, false, WGPUCompareFunction_Always, WGPUStencilOperation_Replace);
// depth stencil state clip path // depth stencil state clip path
@ -237,13 +237,13 @@ void WgPipelines::initialize(WgContext& context)
// layout blit // layout blit
layout_blit = createPipelineLayout(context.device, bindGroupLayoutsBlit, 1); layout_blit = createPipelineLayout(context.device, bindGroupLayoutsBlit, 1);
// render pipeline winding // render pipeline nonzero
winding = createRenderPipeline( nonzero = createRenderPipeline(
context.device, "The render pipeline winding", context.device, "The render pipeline nonzero",
shader_stencil, "vs_main", "fs_main", shader_stencil, "vs_main", "fs_main",
layout_stencil, vertexBufferLayoutsShape, 1, layout_stencil, vertexBufferLayoutsShape, 1,
WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc, WGPUColorWriteMask_None, offscreenTargetFormat, blendStateSrc,
depthStencilStateWinding, multisampleState); depthStencilStateNonZero, multisampleState);
// render pipeline even-odd // render pipeline even-odd
evenodd = createRenderPipeline( evenodd = createRenderPipeline(
context.device, "The render pipeline even-odd", context.device, "The render pipeline even-odd",
@ -471,7 +471,7 @@ void WgPipelines::releaseGraphicHandles(WgContext& context)
// pipelines stencil markup // pipelines stencil markup
releaseRenderPipeline(direct); releaseRenderPipeline(direct);
releaseRenderPipeline(evenodd); releaseRenderPipeline(evenodd);
releaseRenderPipeline(winding); releaseRenderPipeline(nonzero);
// layouts // layouts
releasePipelineLayout(layout_blit); releasePipelineLayout(layout_blit);
releasePipelineLayout(layout_scene_compose); releasePipelineLayout(layout_scene_compose);

View file

@ -66,7 +66,7 @@ private:
WGPUPipelineLayout layout_blit{}; WGPUPipelineLayout layout_blit{};
public: public:
// pipelines stencil markup // pipelines stencil markup
WGPURenderPipeline winding{}; WGPURenderPipeline nonzero{};
WGPURenderPipeline evenodd{}; WGPURenderPipeline evenodd{};
WGPURenderPipeline direct{}; WGPURenderPipeline direct{};
// pipelines clip path markup // pipelines clip path markup

View file

@ -216,7 +216,7 @@ TEST_CASE("Shape Filling", "[tvgShape]")
REQUIRE(a == 5); REQUIRE(a == 5);
//Fill Rule //Fill Rule
REQUIRE(shape->fillRule() == FillRule::Winding); REQUIRE(shape->fillRule() == FillRule::NonZero);
REQUIRE(shape->fill(FillRule::EvenOdd) == Result::Success); REQUIRE(shape->fill(FillRule::EvenOdd) == Result::Success);
REQUIRE(shape->fillRule() == FillRule::EvenOdd); REQUIRE(shape->fillRule() == FillRule::EvenOdd);
} }