diff --git a/src/common/tvgArray.h b/src/common/tvgArray.h index b96db9b3..08eb2532 100644 --- a/src/common/tvgArray.h +++ b/src/common/tvgArray.h @@ -74,11 +74,36 @@ struct Array return reserve(count + size); } - T* end() const + const T& operator[](size_t idx) const + { + return data[idx]; + } + + T& operator[](size_t idx) + { + return data[idx]; + } + + T* end() { return data + count; } + const T* end() const + { + return data + count; + } + + const T& last() const + { + return data[count - 1]; + } + + const T& first() const + { + return data[0]; + } + T& last() { return data[count - 1]; diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index bc537ece..b166d80b 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -174,7 +174,7 @@ struct LottieProperty LottieScalarFrame& nextFrame() { - return frames->data[frames->count]; + return (*frames)[frames->count]; } T operator()(int32_t frameNo) @@ -242,7 +242,7 @@ struct LottiePathSet LottieScalarFrame& nextFrame() { - return frames->data[frames->count]; + return (*frames)[frames->count]; } bool operator()(int32_t frameNo, Array& cmds, Array& pts) @@ -336,7 +336,7 @@ struct LottieColorStop LottieScalarFrame& nextFrame() { - return frames->data[frames->count]; + return (*frames)[frames->count]; } void operator()(int32_t frameNo, Fill* fill) @@ -425,7 +425,7 @@ struct LottiePosition LottieVectorFrame& nextFrame() { - return frames->data[frames->count]; + return (*frames)[frames->count]; } Point operator()(int32_t frameNo) diff --git a/src/loaders/svg/tvgSvgCssStyle.cpp b/src/loaders/svg/tvgSvgCssStyle.cpp index 6fdb6412..c3c477a2 100644 --- a/src/loaders/svg/tvgSvgCssStyle.cpp +++ b/src/loaders/svg/tvgSvgCssStyle.cpp @@ -123,7 +123,7 @@ static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from) to->stroke.dash.array.clear(); to->stroke.dash.array.reserve(from->stroke.dash.array.count); for (uint32_t i = 0; i < from->stroke.dash.array.count; ++i) { - to->stroke.dash.array.push(from->stroke.dash.array.data[i]); + to->stroke.dash.array.push(from->stroke.dash.array[i]); } to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Dash); to->flags = (to->flags | SvgStyleFlags::StrokeDashArray); @@ -236,7 +236,7 @@ void cssUpdateStyle(SvgNode* doc, SvgNode* style) void cssApplyStyleToPostponeds(Array& postponeds, SvgNode* style) { for (uint32_t i = 0; i < postponeds.count; ++i) { - auto nodeIdPair = postponeds.data[i]; + auto nodeIdPair = postponeds[i]; //css styling: tag.name has higher priority than .name if (auto cssNode = cssFindStyleNode(style, nodeIdPair.id, nodeIdPair.node->type)) { diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index f5cc0dfe..457fe285 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -371,7 +371,7 @@ static void _parseDashArray(SvgLoaderData* loader, const char *str, SvgDash* das str = end; } //If dash array size is 1, it means that dash and gap size are the same. - if ((*dash).array.count == 1) (*dash).array.push((*dash).array.data[0]); + if ((*dash).array.count == 1) (*dash).array.push((*dash).array[0]); } @@ -2622,7 +2622,7 @@ static GradientFactoryMethod _findGradientFactory(const char* name) static void _cloneGradStops(Array& dst, const Array& src) { for (uint32_t i = 0; i < src.count; ++i) { - dst.push(src.data[i]); + dst.push(src[i]); } } @@ -2776,7 +2776,7 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren child->stroke.dash.array.clear(); child->stroke.dash.array.reserve(parent->stroke.dash.array.count); for (uint32_t i = 0; i < parent->stroke.dash.array.count; ++i) { - child->stroke.dash.array.push(parent->stroke.dash.array.data[i]); + child->stroke.dash.array.push(parent->stroke.dash.array[i]); } } } @@ -2845,7 +2845,7 @@ static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from) to->stroke.dash.array.clear(); to->stroke.dash.array.reserve(from->stroke.dash.array.count); for (uint32_t i = 0; i < from->stroke.dash.array.count; ++i) { - to->stroke.dash.array.push(from->stroke.dash.array.data[i]); + to->stroke.dash.array.push(from->stroke.dash.array[i]); } } } @@ -2991,7 +2991,7 @@ static void _cloneNode(SvgNode* from, SvgNode* parent, int depth) static void _clonePostponedNodes(Array* cloneNodes, SvgNode* doc) { for (uint32_t i = 0; i < cloneNodes->count; ++i) { - auto nodeIdPair = cloneNodes->data[i]; + auto nodeIdPair = (*cloneNodes)[i]; auto defs = _getDefsNode(nodeIdPair.node); auto nodeFrom = _findNodeById(defs, nodeIdPair.id); if (!nodeFrom) nodeFrom = _findNodeById(doc, nodeIdPair.id); @@ -3072,7 +3072,7 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content, loader->doc = node; } else { if (!strcmp(tagName, "svg")) return; //Already loaded (SvgNodeType::Doc) tag - if (loader->stack.count > 0) parent = loader->stack.data[loader->stack.count - 1]; + if (loader->stack.count > 0) parent = loader->stack.last(); else parent = loader->doc; if (!strcmp(tagName, "style")) { // TODO: For now only the first style node is saved. After the css id selector @@ -3093,7 +3093,7 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content, loader->stack.push(node); } } else if ((method = _findGraphicsFactory(tagName))) { - if (loader->stack.count > 0) parent = loader->stack.data[loader->stack.count - 1]; + if (loader->stack.count > 0) parent = loader->stack.last(); else parent = loader->doc; node = method(loader, parent, attrs, attrsLength, simpleXmlParseAttributes); } else if ((gradientMethod = _findGradientFactory(tagName))) { diff --git a/src/loaders/svg/tvgSvgPath.cpp b/src/loaders/svg/tvgSvgPath.cpp index c05521ab..79a9c077 100644 --- a/src/loaders/svg/tvgSvgPath.cpp +++ b/src/loaders/svg/tvgSvgPath.cpp @@ -382,7 +382,7 @@ static bool _processCommand(Array* cmds, Array* pts, char cm case 's': case 'S': { Point p[3], ctrl; - if ((cmds->count > 1) && (cmds->data[cmds->count - 1] == PathCommand::CubicTo) && + if ((cmds->count > 1) && (cmds->last() == PathCommand::CubicTo) && !(*isQuadratic)) { ctrl.x = 2 * cur->x - curCtl->x; ctrl.y = 2 * cur->y - curCtl->y; @@ -423,7 +423,7 @@ static bool _processCommand(Array* cmds, Array* pts, char cm case 't': case 'T': { Point p[3], ctrl; - if ((cmds->count > 1) && (cmds->data[cmds->count - 1] == PathCommand::CubicTo) && + if ((cmds->count > 1) && (cmds->last() == PathCommand::CubicTo) && *isQuadratic) { ctrl.x = 2 * cur->x - curCtl->x; ctrl.y = 2 * cur->y - curCtl->y; diff --git a/src/loaders/svg/tvgSvgSceneBuilder.cpp b/src/loaders/svg/tvgSvgSceneBuilder.cpp index d27ae55d..b04a81df 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -114,7 +114,7 @@ static unique_ptr _applyLinearGradientProperty(SvgStyleGradient* if (!stops) return fillGrad; auto prevOffset = 0.0f; for (uint32_t i = 0; i < g->stops.count; ++i) { - auto colorStop = &g->stops.data[i]; + auto colorStop = &g->stops[i]; //Use premultiplied color stops[i].r = colorStop->r; stops[i].g = colorStop->g; @@ -176,7 +176,7 @@ static unique_ptr _applyRadialGradientProperty(SvgStyleGradient* if (!stops) return fillGrad; auto prevOffset = 0.0f; for (uint32_t i = 0; i < g->stops.count; ++i) { - auto colorStop = &g->stops.data[i]; + auto colorStop = &g->stops[i]; //Use premultiplied color stops[i].r = colorStop->r; stops[i].g = colorStop->g; diff --git a/src/renderer/gl_engine/tvgGlTessellator.cpp b/src/renderer/gl_engine/tvgGlTessellator.cpp index 47b14be0..993d5785 100644 --- a/src/renderer/gl_engine/tvgGlTessellator.cpp +++ b/src/renderer/gl_engine/tvgGlTessellator.cpp @@ -108,7 +108,7 @@ struct Vertex : public Object Vertex() = default; - Vertex(const GlPoint &p) : point(std::ceilf(p.x * 100.f) / 100.f, std::ceilf(p.y * 100.f) / 100.f) + Vertex(const GlPoint &p) : point(ceilf(p.x * 100.f) / 100.f, ceilf(p.y * 100.f) / 100.f) { } @@ -888,7 +888,7 @@ Tessellator::~Tessellator() auto count = outlines.count; for (uint32_t i = 0; i < count; i++) { - delete outlines.data[i]; + delete outlines[i]; } } @@ -942,10 +942,10 @@ void Tessellator::tessellate(const Array &shapes) this->fillRule = FillRule::Winding; for (uint32_t i = 0; i < shapes.count; i++) { - auto cmds = shapes.data[i]->path.cmds.data; - auto cmdCnt = shapes.data[i]->path.cmds.count; - auto pts = shapes.data[i]->path.pts.data; - auto ptsCnt = shapes.data[i]->path.pts.count; + auto cmds = shapes[i]->path.cmds.data; + auto cmdCnt = shapes[i]->path.cmds.count; + auto pts = shapes[i]->path.pts.data; + auto ptsCnt = shapes[i]->path.pts.count; this->visitShape(cmds, cmdCnt, pts, ptsCnt); } @@ -1047,7 +1047,7 @@ void Tessellator::buildMesh() Array temp{}; for (uint32_t i = 0; i < outlines.count; i++) { - auto list = outlines.data[i]; + auto list = outlines[i]; auto prev = list->tail; auto v = list->head; @@ -1072,7 +1072,7 @@ void Tessellator::buildMesh() temp.sort(); for (uint32_t i = 0; i < temp.count; i++) { - this->pMesh->append(temp.data[i]); + this->pMesh->append(temp[i]); } } @@ -1643,7 +1643,7 @@ void Stroker::stroke(const RenderShape *rshape) auto ptsCnt = rshape->path.pts.count; const float *dash_pattern = nullptr; - auto dash_count = rshape->strokeDash(&dash_pattern); + auto dash_count = rshape->strokeDash(&dash_pattern, nullptr); if (dash_count == 0) { doStroke(cmds, cmdCnt, pts, ptsCnt); diff --git a/src/renderer/sw_engine/tvgSwImage.cpp b/src/renderer/sw_engine/tvgSwImage.cpp index 4829a8c8..fb8581b4 100644 --- a/src/renderer/sw_engine/tvgSwImage.cpp +++ b/src/renderer/sw_engine/tvgSwImage.cpp @@ -93,7 +93,7 @@ static bool _genOutline(SwImage* image, const RenderMesh* mesh, const Matrix* tr outline->types.push(SW_CURVE_TYPE_POINT); } - outline->pts.push(outline->pts.data[0]); + outline->pts.push(outline->pts[0]); outline->types.push(SW_CURVE_TYPE_POINT); outline->cntrs.push(outline->pts.count - 1); outline->closed.push(true); diff --git a/src/renderer/sw_engine/tvgSwRle.cpp b/src/renderer/sw_engine/tvgSwRle.cpp index f7e8ab7a..a97a693a 100644 --- a/src/renderer/sw_engine/tvgSwRle.cpp +++ b/src/renderer/sw_engine/tvgSwRle.cpp @@ -716,11 +716,11 @@ static void _decomposeOutline(RleWorker& rw) for (auto cntr = outline->cntrs.data; cntr < outline->cntrs.end(); ++cntr) { auto last = *cntr; auto limit = outline->pts.data + last; - auto start = UPSCALE(outline->pts.data[first]); + auto start = UPSCALE(outline->pts[first]); auto pt = outline->pts.data + first; auto types = outline->types.data + first; - _moveTo(rw, UPSCALE(outline->pts.data[first])); + _moveTo(rw, UPSCALE(outline->pts[first])); while (pt < limit) { ++pt; diff --git a/src/renderer/sw_engine/tvgSwShape.cpp b/src/renderer/sw_engine/tvgSwShape.cpp index cbdf92a7..ffff8347 100644 --- a/src/renderer/sw_engine/tvgSwShape.cpp +++ b/src/renderer/sw_engine/tvgSwShape.cpp @@ -108,7 +108,7 @@ static void _outlineClose(SwOutline& outline) if (outline.pts.count == i) return; //Close the path - outline.pts.push(outline.pts.data[i]); + outline.pts.push(outline.pts[i]); outline.types.push(SW_CURVE_TYPE_POINT); outline.closed.push(true); } diff --git a/src/renderer/sw_engine/tvgSwStroke.cpp b/src/renderer/sw_engine/tvgSwStroke.cpp index 38626cb4..2e320d45 100644 --- a/src/renderer/sw_engine/tvgSwStroke.cpp +++ b/src/renderer/sw_engine/tvgSwStroke.cpp @@ -852,7 +852,7 @@ bool strokeParseOutline(SwStroke* stroke, const SwOutline& outline) continue; } - auto start = outline.pts.data[first]; + auto start = outline.pts[first]; auto pt = outline.pts.data + first; auto types = outline.types.data + first; auto type = types[0];