mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Refactoring
This commit is contained in:
parent
814852d902
commit
59d8d311d4
@ -81,7 +81,7 @@ public:
|
|||||||
|
|
||||||
virtual void setAlpha(float alpha) = 0;
|
virtual void setAlpha(float alpha) = 0;
|
||||||
|
|
||||||
virtual void concatenate(lottie::CATransform3D const &transform) = 0;
|
virtual void concatenate(lottie::Transform3D const &transform) = 0;
|
||||||
|
|
||||||
virtual void draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) = 0;
|
virtual void draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) = 0;
|
||||||
};
|
};
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
virtual void fill(lottie::CGRect const &rect, lottie::Color const &fillColor) override;
|
virtual void fill(lottie::CGRect const &rect, lottie::Color const &fillColor) override;
|
||||||
virtual void setBlendMode(BlendMode blendMode) override;
|
virtual void setBlendMode(BlendMode blendMode) override;
|
||||||
virtual void setAlpha(float alpha) override;
|
virtual void setAlpha(float alpha) override;
|
||||||
virtual void concatenate(lottie::CATransform3D const &transform) override;
|
virtual void concatenate(lottie::Transform3D const &transform) override;
|
||||||
|
|
||||||
virtual std::shared_ptr<Image> makeImage() const;
|
virtual std::shared_ptr<Image> makeImage() const;
|
||||||
virtual void draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) override;
|
virtual void draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) override;
|
||||||
|
@ -509,7 +509,7 @@ void CanvasImpl::setAlpha(float alpha) {
|
|||||||
CGContextSetAlpha(_context, alpha);
|
CGContextSetAlpha(_context, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanvasImpl::concatenate(lottie::CATransform3D const &transform) {
|
void CanvasImpl::concatenate(lottie::Transform3D const &transform) {
|
||||||
CGContextConcatCTM(_context, CATransform3DGetAffineTransform(nativeTransform(transform)));
|
CGContextConcatCTM(_context, CATransform3DGetAffineTransform(nativeTransform(transform)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
|
|
||||||
virtual void setAlpha(float alpha) override;
|
virtual void setAlpha(float alpha) override;
|
||||||
|
|
||||||
virtual void concatenate(lottie::CATransform3D const &transform) override;
|
virtual void concatenate(lottie::Transform3D const &transform) override;
|
||||||
|
|
||||||
virtual void draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) override;
|
virtual void draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) override;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
float _width = 0.0f;
|
float _width = 0.0f;
|
||||||
float _height = 0.0f;
|
float _height = 0.0f;
|
||||||
lottie::CATransform3D _transform;
|
lottie::Transform3D _transform;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ void addEnumeratedPath(CanvasPathEnumerator const &enumeratePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NullCanvasImpl::NullCanvasImpl(int width, int height) :
|
NullCanvasImpl::NullCanvasImpl(int width, int height) :
|
||||||
_width(width), _height(height), _transform(lottie::CATransform3D::identity()) {
|
_width(width), _height(height), _transform(lottie::Transform3D::identity()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
NullCanvasImpl::~NullCanvasImpl() {
|
NullCanvasImpl::~NullCanvasImpl() {
|
||||||
@ -69,7 +69,7 @@ void NullCanvasImpl::setBlendMode(BlendMode blendMode) {
|
|||||||
void NullCanvasImpl::setAlpha(float alpha) {
|
void NullCanvasImpl::setAlpha(float alpha) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NullCanvasImpl::concatenate(lottie::CATransform3D const &transform) {
|
void NullCanvasImpl::concatenate(lottie::Transform3D const &transform) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NullCanvasImpl::draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) {
|
void NullCanvasImpl::draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) {
|
||||||
|
@ -15,17 +15,17 @@ static constexpr float minGlobalRectCalculationSize = 200.0f;
|
|||||||
|
|
||||||
struct TransformedPath {
|
struct TransformedPath {
|
||||||
lottie::BezierPath path;
|
lottie::BezierPath path;
|
||||||
lottie::CATransform3D transform;
|
lottie::Transform3D transform;
|
||||||
|
|
||||||
TransformedPath(lottie::BezierPath const &path_, lottie::CATransform3D const &transform_) :
|
TransformedPath(lottie::BezierPath const &path_, lottie::Transform3D const &transform_) :
|
||||||
path(path_),
|
path(path_),
|
||||||
transform(transform_) {
|
transform(transform_) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static lottie::CGRect collectPathBoundingBoxes(std::shared_ptr<lottie::RenderTreeNodeContentItem> item, size_t subItemLimit, lottie::CATransform3D const &parentTransform, bool skipApplyTransform, lottie::BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
static lottie::CGRect collectPathBoundingBoxes(std::shared_ptr<lottie::RenderTreeNodeContentItem> item, size_t subItemLimit, lottie::Transform3D const &parentTransform, bool skipApplyTransform, lottie::BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
||||||
//TODO:remove skipApplyTransform
|
//TODO:remove skipApplyTransform
|
||||||
lottie::CATransform3D effectiveTransform = parentTransform;
|
lottie::Transform3D effectiveTransform = parentTransform;
|
||||||
if (!skipApplyTransform && item->isGroup) {
|
if (!skipApplyTransform && item->isGroup) {
|
||||||
effectiveTransform = item->transform * effectiveTransform;
|
effectiveTransform = item->transform * effectiveTransform;
|
||||||
}
|
}
|
||||||
@ -56,9 +56,9 @@ static lottie::CGRect collectPathBoundingBoxes(std::shared_ptr<lottie::RenderTre
|
|||||||
return boundingBox;
|
return boundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enumeratePaths(std::shared_ptr<lottie::RenderTreeNodeContentItem> item, size_t subItemLimit, lottie::CATransform3D const &parentTransform, bool skipApplyTransform, std::function<void(lottie::BezierPath const &path, lottie::CATransform3D const &transform)> const &onPath) {
|
static void enumeratePaths(std::shared_ptr<lottie::RenderTreeNodeContentItem> item, size_t subItemLimit, lottie::Transform3D const &parentTransform, bool skipApplyTransform, std::function<void(lottie::BezierPath const &path, lottie::Transform3D const &transform)> const &onPath) {
|
||||||
//TODO:remove skipApplyTransform
|
//TODO:remove skipApplyTransform
|
||||||
lottie::CATransform3D effectiveTransform = parentTransform;
|
lottie::Transform3D effectiveTransform = parentTransform;
|
||||||
if (!skipApplyTransform && item->isGroup) {
|
if (!skipApplyTransform && item->isGroup) {
|
||||||
effectiveTransform = item->transform * effectiveTransform;
|
effectiveTransform = item->transform * effectiveTransform;
|
||||||
}
|
}
|
||||||
@ -80,14 +80,14 @@ static void enumeratePaths(std::shared_ptr<lottie::RenderTreeNodeContentItem> it
|
|||||||
|
|
||||||
namespace lottie {
|
namespace lottie {
|
||||||
|
|
||||||
static std::optional<CGRect> getRenderContentItemGlobalRect(std::shared_ptr<RenderTreeNodeContentItem> const &contentItem, lottie::Vector2D const &globalSize, lottie::CATransform3D const &parentTransform, BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
static std::optional<CGRect> getRenderContentItemGlobalRect(std::shared_ptr<RenderTreeNodeContentItem> const &contentItem, lottie::Vector2D const &globalSize, lottie::Transform3D const &parentTransform, BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
||||||
auto currentTransform = parentTransform;
|
auto currentTransform = parentTransform;
|
||||||
CATransform3D localTransform = contentItem->transform;
|
Transform3D localTransform = contentItem->transform;
|
||||||
currentTransform = localTransform * currentTransform;
|
currentTransform = localTransform * currentTransform;
|
||||||
|
|
||||||
std::optional<CGRect> globalRect;
|
std::optional<CGRect> globalRect;
|
||||||
for (const auto &shadingVariant : contentItem->shadings) {
|
for (const auto &shadingVariant : contentItem->shadings) {
|
||||||
lottie::CGRect shapeBounds = collectPathBoundingBoxes(contentItem, shadingVariant->subItemLimit, lottie::CATransform3D::identity(), true, bezierPathsBoundingBoxContext);
|
lottie::CGRect shapeBounds = collectPathBoundingBoxes(contentItem, shadingVariant->subItemLimit, lottie::Transform3D::identity(), true, bezierPathsBoundingBoxContext);
|
||||||
|
|
||||||
if (shadingVariant->stroke) {
|
if (shadingVariant->stroke) {
|
||||||
shapeBounds = shapeBounds.insetBy(-shadingVariant->stroke->lineWidth / 2.0, -shadingVariant->stroke->lineWidth / 2.0);
|
shapeBounds = shapeBounds.insetBy(-shadingVariant->stroke->lineWidth / 2.0, -shadingVariant->stroke->lineWidth / 2.0);
|
||||||
@ -128,14 +128,14 @@ static std::optional<CGRect> getRenderContentItemGlobalRect(std::shared_ptr<Rend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::optional<CGRect> getRenderNodeGlobalRect(std::shared_ptr<RenderTreeNode> const &node, lottie::Vector2D const &globalSize, lottie::CATransform3D const &parentTransform, bool isInvertedMatte, BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
static std::optional<CGRect> getRenderNodeGlobalRect(std::shared_ptr<RenderTreeNode> const &node, lottie::Vector2D const &globalSize, lottie::Transform3D const &parentTransform, bool isInvertedMatte, BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
||||||
if (node->isHidden() || node->alpha() < minVisibleAlpha) {
|
if (node->isHidden() || node->alpha() < minVisibleAlpha) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto currentTransform = parentTransform;
|
auto currentTransform = parentTransform;
|
||||||
Vector2D localTranslation(node->position().x + -node->bounds().x, node->position().y + -node->bounds().y);
|
Vector2D localTranslation(node->position().x + -node->bounds().x, node->position().y + -node->bounds().y);
|
||||||
CATransform3D localTransform = node->transform();
|
Transform3D localTransform = node->transform();
|
||||||
localTransform = localTransform.translated(localTranslation);
|
localTransform = localTransform.translated(localTranslation);
|
||||||
currentTransform = localTransform * currentTransform;
|
currentTransform = localTransform * currentTransform;
|
||||||
|
|
||||||
@ -181,9 +181,9 @@ static std::optional<CGRect> getRenderNodeGlobalRect(std::shared_ptr<RenderTreeN
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> const &parentContext, std::shared_ptr<lottie::RenderTreeNodeContentItem> item, float parentAlpha, lottie::Vector2D const &globalSize, lottie::CATransform3D const &parentTransform, lottie::BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> const &parentContext, std::shared_ptr<lottie::RenderTreeNodeContentItem> item, float parentAlpha, lottie::Vector2D const &globalSize, lottie::Transform3D const &parentTransform, lottie::BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
||||||
auto currentTransform = parentTransform;
|
auto currentTransform = parentTransform;
|
||||||
lottie::CATransform3D localTransform = item->transform;
|
lottie::Transform3D localTransform = item->transform;
|
||||||
currentTransform = localTransform * currentTransform;
|
currentTransform = localTransform * currentTransform;
|
||||||
|
|
||||||
float normalizedOpacity = item->alpha;
|
float normalizedOpacity = item->alpha;
|
||||||
@ -217,7 +217,7 @@ static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> const
|
|||||||
tempContext = tempContextValue;
|
tempContext = tempContextValue;
|
||||||
|
|
||||||
currentContext = &tempContext;
|
currentContext = &tempContext;
|
||||||
(*currentContext)->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(-globalRect->x, -globalRect->y)));
|
(*currentContext)->concatenate(lottie::Transform3D::identity().translated(lottie::Vector2D(-globalRect->x, -globalRect->y)));
|
||||||
|
|
||||||
(*currentContext)->saveState();
|
(*currentContext)->saveState();
|
||||||
(*currentContext)->concatenate(currentTransform);
|
(*currentContext)->concatenate(currentTransform);
|
||||||
@ -270,7 +270,7 @@ static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> const
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
iteratePaths = [&](std::function<void(lottieRendering::PathCommand const &)> iterate) {
|
iteratePaths = [&](std::function<void(lottieRendering::PathCommand const &)> iterate) {
|
||||||
enumeratePaths(item, shading->subItemLimit, lottie::CATransform3D::identity(), true, [&](lottie::BezierPath const &sourcePath, lottie::CATransform3D const &transform) {
|
enumeratePaths(item, shading->subItemLimit, lottie::Transform3D::identity(), true, [&](lottie::BezierPath const &sourcePath, lottie::Transform3D const &transform) {
|
||||||
auto path = sourcePath.copyUsingTransform(transform);
|
auto path = sourcePath.copyUsingTransform(transform);
|
||||||
|
|
||||||
lottieRendering::PathCommand pathCommand;
|
lottieRendering::PathCommand pathCommand;
|
||||||
@ -458,7 +458,7 @@ static void drawLottieContentItem(std::shared_ptr<lottieRendering::Canvas> const
|
|||||||
parentContext->restoreState();
|
parentContext->restoreState();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node, std::shared_ptr<lottieRendering::Canvas> const &parentContext, lottie::Vector2D const &globalSize, lottie::CATransform3D const &parentTransform, float parentAlpha, bool isInvertedMatte, lottie::BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node, std::shared_ptr<lottieRendering::Canvas> const &parentContext, lottie::Vector2D const &globalSize, lottie::Transform3D const &parentTransform, float parentAlpha, bool isInvertedMatte, lottie::BezierPathsBoundingBoxContext &bezierPathsBoundingBoxContext) {
|
||||||
float normalizedOpacity = node->alpha();
|
float normalizedOpacity = node->alpha();
|
||||||
float layerAlpha = ((float)normalizedOpacity) * parentAlpha;
|
float layerAlpha = ((float)normalizedOpacity) * parentAlpha;
|
||||||
|
|
||||||
@ -468,7 +468,7 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
|
|||||||
|
|
||||||
auto currentTransform = parentTransform;
|
auto currentTransform = parentTransform;
|
||||||
lottie::Vector2D localTranslation(node->position().x + -node->bounds().x, node->position().y + -node->bounds().y);
|
lottie::Vector2D localTranslation(node->position().x + -node->bounds().x, node->position().y + -node->bounds().y);
|
||||||
lottie::CATransform3D localTransform = node->transform();
|
lottie::Transform3D localTransform = node->transform();
|
||||||
localTransform = localTransform.translated(localTranslation);
|
localTransform = localTransform.translated(localTranslation);
|
||||||
currentTransform = localTransform * currentTransform;
|
currentTransform = localTransform * currentTransform;
|
||||||
|
|
||||||
@ -511,7 +511,7 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
|
|||||||
if ((node->mask() && !node->mask()->isHidden() && node->mask()->alpha() >= minVisibleAlpha) || masksToBounds) {
|
if ((node->mask() && !node->mask()->isHidden() && node->mask()->alpha() >= minVisibleAlpha) || masksToBounds) {
|
||||||
auto maskBackingStorage = parentContext->makeLayer((int)(globalRect->width), (int)(globalRect->height));
|
auto maskBackingStorage = parentContext->makeLayer((int)(globalRect->width), (int)(globalRect->height));
|
||||||
|
|
||||||
maskBackingStorage->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(-globalRect->x, -globalRect->y)));
|
maskBackingStorage->concatenate(lottie::Transform3D::identity().translated(lottie::Vector2D(-globalRect->x, -globalRect->y)));
|
||||||
maskBackingStorage->concatenate(currentTransform);
|
maskBackingStorage->concatenate(currentTransform);
|
||||||
|
|
||||||
if (masksToBounds) {
|
if (masksToBounds) {
|
||||||
@ -528,7 +528,7 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
|
|||||||
tempContext = tempContextValue;
|
tempContext = tempContextValue;
|
||||||
|
|
||||||
currentContext = tempContextValue;
|
currentContext = tempContextValue;
|
||||||
currentContext->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(-globalRect->x, -globalRect->y)));
|
currentContext->concatenate(lottie::Transform3D::identity().translated(lottie::Vector2D(-globalRect->x, -globalRect->y)));
|
||||||
|
|
||||||
currentContext->saveState();
|
currentContext->saveState();
|
||||||
currentContext->concatenate(currentTransform);
|
currentContext->concatenate(currentTransform);
|
||||||
@ -536,8 +536,8 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
|
|||||||
currentContext = parentContext;
|
currentContext = parentContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
parentContext->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(node->position().x, node->position().y)));
|
parentContext->concatenate(lottie::Transform3D::identity().translated(lottie::Vector2D(node->position().x, node->position().y)));
|
||||||
parentContext->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(-node->bounds().x, -node->bounds().y)));
|
parentContext->concatenate(lottie::Transform3D::identity().translated(lottie::Vector2D(-node->bounds().x, -node->bounds().y)));
|
||||||
parentContext->concatenate(node->transform());
|
parentContext->concatenate(node->transform());
|
||||||
|
|
||||||
float renderAlpha = 1.0;
|
float renderAlpha = 1.0;
|
||||||
@ -608,13 +608,13 @@ CGRect getPathNativeBoundingBox(CGPathRef _Nonnull path) {
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
lottie::CATransform3D rootTransform = lottie::CATransform3D::identity().scaled(lottie::Vector2D(size.width / (float)animation.size.width, size.height / (float)animation.size.height));
|
lottie::Transform3D rootTransform = lottie::Transform3D::identity().scaled(lottie::Vector2D(size.width / (float)animation.size.width, size.height / (float)animation.size.height));
|
||||||
|
|
||||||
if (useReferenceRendering) {
|
if (useReferenceRendering) {
|
||||||
auto context = std::make_shared<lottieRendering::CanvasImpl>((int)size.width, (int)size.height);
|
auto context = std::make_shared<lottieRendering::CanvasImpl>((int)size.width, (int)size.height);
|
||||||
|
|
||||||
CGPoint scale = CGPointMake(size.width / (CGFloat)animation.size.width, size.height / (CGFloat)animation.size.height);
|
CGPoint scale = CGPointMake(size.width / (CGFloat)animation.size.width, size.height / (CGFloat)animation.size.height);
|
||||||
context->concatenate(lottie::CATransform3D::makeScale(scale.x, scale.y, 1.0));
|
context->concatenate(lottie::Transform3D::makeScale(scale.x, scale.y, 1.0));
|
||||||
|
|
||||||
renderLottieRenderNode(renderNode, context, lottie::Vector2D(context->width(), context->height()), rootTransform, 1.0, false, *_bezierPathsBoundingBoxContext.get());
|
renderLottieRenderNode(renderNode, context, lottie::Vector2D(context->width(), context->height()), rootTransform, 1.0, false, *_bezierPathsBoundingBoxContext.get());
|
||||||
|
|
||||||
@ -626,7 +626,7 @@ CGRect getPathNativeBoundingBox(CGPathRef _Nonnull path) {
|
|||||||
auto context = std::make_shared<lottieRendering::NullCanvasImpl>((int)size.width, (int)size.height);
|
auto context = std::make_shared<lottieRendering::NullCanvasImpl>((int)size.width, (int)size.height);
|
||||||
|
|
||||||
CGPoint scale = CGPointMake(size.width / (CGFloat)animation.size.width, size.height / (CGFloat)animation.size.height);
|
CGPoint scale = CGPointMake(size.width / (CGFloat)animation.size.width, size.height / (CGFloat)animation.size.height);
|
||||||
context->concatenate(lottie::CATransform3D::makeScale(scale.x, scale.y, 1.0));
|
context->concatenate(lottie::Transform3D::makeScale(scale.x, scale.y, 1.0));
|
||||||
|
|
||||||
renderLottieRenderNode(renderNode, context, lottie::Vector2D(context->width(), context->height()), rootTransform, 1.0, false, *_bezierPathsBoundingBoxContext.get());
|
renderLottieRenderNode(renderNode, context, lottie::Vector2D(context->width(), context->height()), rootTransform, 1.0, false, *_bezierPathsBoundingBoxContext.get());
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
virtual void setAlpha(float alpha) override;
|
virtual void setAlpha(float alpha) override;
|
||||||
|
|
||||||
virtual void concatenate(lottie::CATransform3D const &transform) override;
|
virtual void concatenate(lottie::Transform3D const &transform) override;
|
||||||
|
|
||||||
virtual void draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) override;
|
virtual void draw(std::shared_ptr<Canvas> const &other, lottie::CGRect const &rect) override;
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ private:
|
|||||||
std::unique_ptr<tvg::SwCanvas> _canvas;
|
std::unique_ptr<tvg::SwCanvas> _canvas;
|
||||||
|
|
||||||
float _alpha = 1.0;
|
float _alpha = 1.0;
|
||||||
lottie::CATransform3D _transform;
|
lottie::Transform3D _transform;
|
||||||
std::vector<lottie::CATransform3D> _stateStack;
|
std::vector<lottie::Transform3D> _stateStack;
|
||||||
int _bytesPerRow = 0;
|
int _bytesPerRow = 0;
|
||||||
uint32_t *_backingData = nullptr;
|
uint32_t *_backingData = nullptr;
|
||||||
int _statsNumStrokes = 0;
|
int _statsNumStrokes = 0;
|
||||||
|
@ -27,7 +27,7 @@ void tvgPath(CanvasPathEnumerator const &enumeratePath, tvg::Shape *shape) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
tvg::Matrix tvgTransform(lottie::CATransform3D const &transform) {
|
tvg::Matrix tvgTransform(lottie::Transform3D const &transform) {
|
||||||
CGAffineTransform affineTransform = CATransform3DGetAffineTransform(lottie::nativeTransform(transform));
|
CGAffineTransform affineTransform = CATransform3DGetAffineTransform(lottie::nativeTransform(transform));
|
||||||
tvg::Matrix result;
|
tvg::Matrix result;
|
||||||
result.e11 = affineTransform.a;
|
result.e11 = affineTransform.a;
|
||||||
@ -45,7 +45,7 @@ tvg::Matrix tvgTransform(lottie::CATransform3D const &transform) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ThorVGCanvasImpl::ThorVGCanvasImpl(int width, int height) :
|
ThorVGCanvasImpl::ThorVGCanvasImpl(int width, int height) :
|
||||||
_width(width), _height(height), _transform(lottie::CATransform3D::identity()) {
|
_width(width), _height(height), _transform(lottie::Transform3D::identity()) {
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
dispatch_once(&onceToken, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
tvg::Initializer::init(0);
|
tvg::Initializer::init(0);
|
||||||
@ -259,7 +259,7 @@ void ThorVGCanvasImpl::setAlpha(float alpha) {
|
|||||||
_alpha = alpha;
|
_alpha = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThorVGCanvasImpl::concatenate(lottie::CATransform3D const &transform) {
|
void ThorVGCanvasImpl::concatenate(lottie::Transform3D const &transform) {
|
||||||
_transform = transform * _transform;
|
_transform = transform * _transform;
|
||||||
/*_canvas->concat(SkM44(
|
/*_canvas->concat(SkM44(
|
||||||
transform.m11, transform.m21, transform.m31, transform.m41,
|
transform.m11, transform.m21, transform.m31, transform.m41,
|
||||||
|
@ -119,7 +119,7 @@ public final class ViewController: UIViewController {
|
|||||||
|
|
||||||
self.view.layer.addSublayer(MetalEngine.shared.rootLayer)
|
self.view.layer.addSublayer(MetalEngine.shared.rootLayer)
|
||||||
|
|
||||||
if !"".isEmpty {
|
if "".isEmpty {
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
self.test = ReferenceCompareTest(view: self.view)
|
self.test = ReferenceCompareTest(view: self.view)
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public:
|
|||||||
std::optional<bool> const &closed() const;
|
std::optional<bool> const &closed() const;
|
||||||
void setClosed(std::optional<bool> const &closed);
|
void setClosed(std::optional<bool> const &closed);
|
||||||
std::shared_ptr<CGPath> cgPath() const;
|
std::shared_ptr<CGPath> cgPath() const;
|
||||||
BezierPath copyUsingTransform(CATransform3D const &transform) const;
|
BezierPath copyUsingTransform(Transform3D const &transform) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BezierPath(std::shared_ptr<BezierPathContents> contents);
|
BezierPath(std::shared_ptr<BezierPathContents> contents);
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
|
|
||||||
virtual bool empty() const = 0;
|
virtual bool empty() const = 0;
|
||||||
|
|
||||||
virtual std::shared_ptr<CGPath> copyUsingTransform(CATransform3D const &transform) const = 0;
|
virtual std::shared_ptr<CGPath> copyUsingTransform(Transform3D const &transform) const = 0;
|
||||||
|
|
||||||
virtual void addLineTo(Vector2D const &point) = 0;
|
virtual void addLineTo(Vector2D const &point) = 0;
|
||||||
virtual void addCurveTo(Vector2D const &point, Vector2D const &control1, Vector2D const &control2) = 0;
|
virtual void addCurveTo(Vector2D const &point, Vector2D const &control1, Vector2D const &control2) = 0;
|
||||||
@ -71,7 +71,7 @@ public:
|
|||||||
virtual bool isEqual(CGPath *other) const = 0;
|
virtual bool isEqual(CGPath *other) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector2D transformVector(Vector2D const &v, CATransform3D const &m);
|
Vector2D transformVector(Vector2D const &v, Transform3D const &m);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
|
|
||||||
virtual bool empty() const override;
|
virtual bool empty() const override;
|
||||||
|
|
||||||
virtual std::shared_ptr<CGPath> copyUsingTransform(CATransform3D const &transform) const override;
|
virtual std::shared_ptr<CGPath> copyUsingTransform(Transform3D const &transform) const override;
|
||||||
|
|
||||||
virtual void addLineTo(Vector2D const &point) override;
|
virtual void addLineTo(Vector2D const &point) override;
|
||||||
virtual void addCurveTo(Vector2D const &point, Vector2D const &control1, Vector2D const &control2) override;
|
virtual void addCurveTo(Vector2D const &point, Vector2D const &control1, Vector2D const &control2) override;
|
||||||
|
@ -64,7 +64,7 @@ public:
|
|||||||
return CurveVertex(point + translation, inTangent + translation, outTangent + translation, false);
|
return CurveVertex(point + translation, inTangent + translation, outTangent + translation, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurveVertex transformed(CATransform3D const &transform) const {
|
CurveVertex transformed(Transform3D const &transform) const {
|
||||||
return CurveVertex(transformVector(point, transform), transformVector(inTangent, transform), transformVector(outTangent, transform), false);
|
return CurveVertex(transformVector(point, transform), transformVector(inTangent, transform), transformVector(outTangent, transform), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
bool isGroup = false;
|
bool isGroup = false;
|
||||||
CATransform3D transform = CATransform3D::identity();
|
Transform3D transform = Transform3D::identity();
|
||||||
float alpha = 0.0;
|
float alpha = 0.0;
|
||||||
std::optional<TrimParams> trimParams;
|
std::optional<TrimParams> trimParams;
|
||||||
std::shared_ptr<RenderTreeNodeContentPath> path;
|
std::shared_ptr<RenderTreeNodeContentPath> path;
|
||||||
@ -393,7 +393,7 @@ public:
|
|||||||
RenderTreeNode(
|
RenderTreeNode(
|
||||||
CGRect bounds_,
|
CGRect bounds_,
|
||||||
Vector2D position_,
|
Vector2D position_,
|
||||||
CATransform3D transform_,
|
Transform3D transform_,
|
||||||
float alpha_,
|
float alpha_,
|
||||||
bool masksToBounds_,
|
bool masksToBounds_,
|
||||||
bool isHidden_,
|
bool isHidden_,
|
||||||
@ -427,7 +427,7 @@ public:
|
|||||||
return _position;
|
return _position;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D const &transform() const {
|
Transform3D const &transform() const {
|
||||||
return _transform;
|
return _transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
CGRect _bounds;
|
CGRect _bounds;
|
||||||
Vector2D _position;
|
Vector2D _position;
|
||||||
CATransform3D _transform = CATransform3D::identity();
|
Transform3D _transform = Transform3D::identity();
|
||||||
float _alpha = 1.0f;
|
float _alpha = 1.0f;
|
||||||
bool _masksToBounds = false;
|
bool _masksToBounds = false;
|
||||||
bool _isHidden = false;
|
bool _isHidden = false;
|
||||||
|
@ -148,13 +148,13 @@ inline float radiansToDegrees(float value) {
|
|||||||
return value * 180.0f / M_PI;
|
return value * 180.0f / M_PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CATransform3D {
|
struct Transform3D {
|
||||||
float m11, m12, m13, m14;
|
float m11, m12, m13, m14;
|
||||||
float m21, m22, m23, m24;
|
float m21, m22, m23, m24;
|
||||||
float m31, m32, m33, m34;
|
float m31, m32, m33, m34;
|
||||||
float m41, m42, m43, m44;
|
float m41, m42, m43, m44;
|
||||||
|
|
||||||
CATransform3D(
|
Transform3D(
|
||||||
float m11_, float m12_, float m13_, float m14_,
|
float m11_, float m12_, float m13_, float m14_,
|
||||||
float m21_, float m22_, float m23_, float m24_,
|
float m21_, float m22_, float m23_, float m24_,
|
||||||
float m31_, float m32_, float m33_, float m34_,
|
float m31_, float m32_, float m33_, float m34_,
|
||||||
@ -166,14 +166,14 @@ struct CATransform3D {
|
|||||||
m41(m41_), m42(m42_), m43(m43_), m44(m44_) {
|
m41(m41_), m42(m42_), m43(m43_), m44(m44_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(CATransform3D const &rhs) const {
|
bool operator==(Transform3D const &rhs) const {
|
||||||
return m11 == rhs.m11 && m12 == rhs.m12 && m13 == rhs.m13 && m14 == rhs.m14 &&
|
return m11 == rhs.m11 && m12 == rhs.m12 && m13 == rhs.m13 && m14 == rhs.m14 &&
|
||||||
m21 == rhs.m21 && m22 == rhs.m22 && m23 == rhs.m23 && m24 == rhs.m24 &&
|
m21 == rhs.m21 && m22 == rhs.m22 && m23 == rhs.m23 && m24 == rhs.m24 &&
|
||||||
m31 == rhs.m31 && m32 == rhs.m32 && m33 == rhs.m33 && m34 == rhs.m34 &&
|
m31 == rhs.m31 && m32 == rhs.m32 && m33 == rhs.m33 && m34 == rhs.m34 &&
|
||||||
m41 == rhs.m41 && m42 == rhs.m42 && m43 == rhs.m43 && m44 == rhs.m44;
|
m41 == rhs.m41 && m42 == rhs.m42 && m43 == rhs.m43 && m44 == rhs.m44;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(CATransform3D const &rhs) const {
|
bool operator!=(Transform3D const &rhs) const {
|
||||||
return !(*this == rhs);
|
return !(*this == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,8 +184,8 @@ struct CATransform3D {
|
|||||||
m41 == 0.0 && m42 == 0.0 && m43 == 0.0 && m44 == 1.0;
|
m41 == 0.0 && m42 == 0.0 && m43 == 0.0 && m44 == 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CATransform3D makeTranslation(float tx, float ty, float tz) {
|
static Transform3D makeTranslation(float tx, float ty, float tz) {
|
||||||
return CATransform3D(
|
return Transform3D(
|
||||||
1, 0, 0, 0,
|
1, 0, 0, 0,
|
||||||
0, 1, 0, 0,
|
0, 1, 0, 0,
|
||||||
0, 0, 1, 0,
|
0, 0, 1, 0,
|
||||||
@ -193,8 +193,8 @@ struct CATransform3D {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CATransform3D makeScale(float sx, float sy, float sz) {
|
static Transform3D makeScale(float sx, float sy, float sz) {
|
||||||
return CATransform3D(
|
return Transform3D(
|
||||||
sx, 0, 0, 0,
|
sx, 0, 0, 0,
|
||||||
0, sy, 0, 0,
|
0, sy, 0, 0,
|
||||||
0, 0, sz, 0,
|
0, 0, sz, 0,
|
||||||
@ -202,14 +202,14 @@ struct CATransform3D {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CATransform3D makeRotation(float radians, float x, float y, float z);
|
static Transform3D makeRotation(float radians, float x, float y, float z);
|
||||||
|
|
||||||
static CATransform3D makeSkew(float skew, float skewAxis) {
|
static Transform3D makeSkew(float skew, float skewAxis) {
|
||||||
float mCos = cos(degreesToRadians(skewAxis));
|
float mCos = cos(degreesToRadians(skewAxis));
|
||||||
float mSin = sin(degreesToRadians(skewAxis));
|
float mSin = sin(degreesToRadians(skewAxis));
|
||||||
float aTan = tan(degreesToRadians(skew));
|
float aTan = tan(degreesToRadians(skew));
|
||||||
|
|
||||||
CATransform3D transform1(
|
Transform3D transform1(
|
||||||
mCos,
|
mCos,
|
||||||
mSin,
|
mSin,
|
||||||
0.0,
|
0.0,
|
||||||
@ -228,7 +228,7 @@ struct CATransform3D {
|
|||||||
1.0
|
1.0
|
||||||
);
|
);
|
||||||
|
|
||||||
CATransform3D transform2(
|
Transform3D transform2(
|
||||||
1.0,
|
1.0,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
@ -247,7 +247,7 @@ struct CATransform3D {
|
|||||||
1.0
|
1.0
|
||||||
);
|
);
|
||||||
|
|
||||||
CATransform3D transform3(
|
Transform3D transform3(
|
||||||
mCos,
|
mCos,
|
||||||
-mSin,
|
-mSin,
|
||||||
0.0,
|
0.0,
|
||||||
@ -269,7 +269,7 @@ struct CATransform3D {
|
|||||||
return transform3 * transform2 * transform1;
|
return transform3 * transform2 * transform1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CATransform3D makeTransform(
|
static Transform3D makeTransform(
|
||||||
Vector2D const &anchor,
|
Vector2D const &anchor,
|
||||||
Vector2D const &position,
|
Vector2D const &position,
|
||||||
Vector2D const &scale,
|
Vector2D const &scale,
|
||||||
@ -277,38 +277,38 @@ struct CATransform3D {
|
|||||||
std::optional<float> skew,
|
std::optional<float> skew,
|
||||||
std::optional<float> skewAxis
|
std::optional<float> skewAxis
|
||||||
) {
|
) {
|
||||||
CATransform3D result = CATransform3D::identity();
|
Transform3D result = Transform3D::identity();
|
||||||
if (skew.has_value() && skewAxis.has_value()) {
|
if (skew.has_value() && skewAxis.has_value()) {
|
||||||
result = CATransform3D::identity().translated(position).rotated(rotation).skewed(-skew.value(), skewAxis.value()).scaled(Vector2D(scale.x * 0.01, scale.y * 0.01)).translated(Vector2D(-anchor.x, -anchor.y));
|
result = Transform3D::identity().translated(position).rotated(rotation).skewed(-skew.value(), skewAxis.value()).scaled(Vector2D(scale.x * 0.01, scale.y * 0.01)).translated(Vector2D(-anchor.x, -anchor.y));
|
||||||
} else {
|
} else {
|
||||||
result = CATransform3D::identity().translated(position).rotated(rotation).scaled(Vector2D(scale.x * 0.01, scale.y * 0.01)).translated(Vector2D(-anchor.x, -anchor.y));
|
result = Transform3D::identity().translated(position).rotated(rotation).scaled(Vector2D(scale.x * 0.01, scale.y * 0.01)).translated(Vector2D(-anchor.x, -anchor.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D rotated(float degrees) const;
|
Transform3D rotated(float degrees) const;
|
||||||
|
|
||||||
CATransform3D translated(Vector2D const &translation) const;
|
Transform3D translated(Vector2D const &translation) const;
|
||||||
|
|
||||||
CATransform3D scaled(Vector2D const &scale) const;
|
Transform3D scaled(Vector2D const &scale) const;
|
||||||
|
|
||||||
CATransform3D skewed(float skew, float skewAxis) const {
|
Transform3D skewed(float skew, float skewAxis) const {
|
||||||
return CATransform3D::makeSkew(skew, skewAxis) * (*this);
|
return Transform3D::makeSkew(skew, skewAxis) * (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CATransform3D const &identity() {
|
static Transform3D const &identity() {
|
||||||
return _identity;
|
return _identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D operator*(CATransform3D const &b) const;
|
Transform3D operator*(Transform3D const &b) const;
|
||||||
|
|
||||||
bool isInvertible() const;
|
bool isInvertible() const;
|
||||||
|
|
||||||
CATransform3D inverted() const;
|
Transform3D inverted() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static CATransform3D _identity;
|
static Transform3D _identity;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CGRect {
|
struct CGRect {
|
||||||
@ -359,7 +359,7 @@ struct CGRect {
|
|||||||
CGRect intersection(CGRect const &other) const;
|
CGRect intersection(CGRect const &other) const;
|
||||||
CGRect unionWith(CGRect const &other) const;
|
CGRect unionWith(CGRect const &other) const;
|
||||||
|
|
||||||
CGRect applyingTransform(CATransform3D const &transform) const;
|
CGRect applyingTransform(Transform3D const &transform) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool isInRangeOrEqual(float value, float from, float to) {
|
inline bool isInRangeOrEqual(float value, float from, float to) {
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
namespace lottie {
|
namespace lottie {
|
||||||
|
|
||||||
::CATransform3D nativeTransform(CATransform3D const &value);
|
::CATransform3D nativeTransform(Transform3D const &value);
|
||||||
CATransform3D fromNativeTransform(::CATransform3D const &value);
|
Transform3D fromNativeTransform(::CATransform3D const &value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ public:
|
|||||||
auto renderTreeContentItem = std::make_shared<RenderTreeNode>(
|
auto renderTreeContentItem = std::make_shared<RenderTreeNode>(
|
||||||
CGRect(0.0, 0.0, 0.0, 0.0),
|
CGRect(0.0, 0.0, 0.0, 0.0),
|
||||||
Vector2D(0.0, 0.0),
|
Vector2D(0.0, 0.0),
|
||||||
CATransform3D::identity(),
|
Transform3D::identity(),
|
||||||
1.0,
|
1.0,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@ -138,7 +138,7 @@ public:
|
|||||||
_contentsTreeNode = std::make_shared<RenderTreeNode>(
|
_contentsTreeNode = std::make_shared<RenderTreeNode>(
|
||||||
CGRect(0.0, 0.0, 0.0, 0.0),
|
CGRect(0.0, 0.0, 0.0, 0.0),
|
||||||
Vector2D(0.0, 0.0),
|
Vector2D(0.0, 0.0),
|
||||||
CATransform3D::identity(),
|
Transform3D::identity(),
|
||||||
1.0,
|
1.0,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@ -162,7 +162,7 @@ public:
|
|||||||
_renderTreeNode = std::make_shared<RenderTreeNode>(
|
_renderTreeNode = std::make_shared<RenderTreeNode>(
|
||||||
CGRect(0.0, 0.0, 0.0, 0.0),
|
CGRect(0.0, 0.0, 0.0, 0.0),
|
||||||
Vector2D(0.0, 0.0),
|
Vector2D(0.0, 0.0),
|
||||||
CATransform3D::identity(),
|
Transform3D::identity(),
|
||||||
1.0,
|
1.0,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -492,9 +492,9 @@ public:
|
|||||||
|
|
||||||
struct TransformedPath {
|
struct TransformedPath {
|
||||||
BezierPath path;
|
BezierPath path;
|
||||||
CATransform3D transform;
|
Transform3D transform;
|
||||||
|
|
||||||
TransformedPath(BezierPath const &path_, CATransform3D const &transform_) :
|
TransformedPath(BezierPath const &path_, Transform3D const &transform_) :
|
||||||
path(path_),
|
path(path_),
|
||||||
transform(transform_) {
|
transform(transform_) {
|
||||||
}
|
}
|
||||||
@ -853,13 +853,13 @@ public:
|
|||||||
_opacityValue = 1.0;
|
_opacityValue = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_transformValue = CATransform3D::identity().translated(Vector2D(positionValue.x, positionValue.y)).rotated(rotationValue).skewed(-skewValue, skewAxisValue).scaled(Vector2D(scaleValue.x * 0.01, scaleValue.y * 0.01)).translated(Vector2D(-anchorValue.x, -anchorValue.y));
|
_transformValue = Transform3D::identity().translated(Vector2D(positionValue.x, positionValue.y)).rotated(rotationValue).skewed(-skewValue, skewAxisValue).scaled(Vector2D(scaleValue.x * 0.01, scaleValue.y * 0.01)).translated(Vector2D(-anchorValue.x, -anchorValue.y));
|
||||||
|
|
||||||
hasValidData = true;
|
hasValidData = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D const &transform() {
|
Transform3D const &transform() {
|
||||||
return _transformValue;
|
return _transformValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,7 +878,7 @@ public:
|
|||||||
std::unique_ptr<KeyframeInterpolator<Vector1D>> _skewAxis;
|
std::unique_ptr<KeyframeInterpolator<Vector1D>> _skewAxis;
|
||||||
std::unique_ptr<KeyframeInterpolator<Vector1D>> _opacity;
|
std::unique_ptr<KeyframeInterpolator<Vector1D>> _opacity;
|
||||||
|
|
||||||
CATransform3D _transformValue = CATransform3D::identity();
|
Transform3D _transformValue = Transform3D::identity();
|
||||||
float _opacityValue = 1.0;
|
float _opacityValue = 1.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -910,11 +910,11 @@ public:
|
|||||||
std::shared_ptr<RenderTreeNodeContentItem> _contentItem;
|
std::shared_ptr<RenderTreeNodeContentItem> _contentItem;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<TransformedPath> collectPaths(size_t subItemLimit, CATransform3D const &parentTransform, bool skipApplyTransform) {
|
std::vector<TransformedPath> collectPaths(size_t subItemLimit, Transform3D const &parentTransform, bool skipApplyTransform) {
|
||||||
std::vector<TransformedPath> mappedPaths;
|
std::vector<TransformedPath> mappedPaths;
|
||||||
|
|
||||||
//TODO:remove skipApplyTransform
|
//TODO:remove skipApplyTransform
|
||||||
CATransform3D effectiveTransform = parentTransform;
|
Transform3D effectiveTransform = parentTransform;
|
||||||
if (!skipApplyTransform && isGroup && transform) {
|
if (!skipApplyTransform && isGroup && transform) {
|
||||||
effectiveTransform = transform->transform() * effectiveTransform;
|
effectiveTransform = transform->transform() * effectiveTransform;
|
||||||
}
|
}
|
||||||
@ -942,7 +942,7 @@ public:
|
|||||||
}
|
}
|
||||||
CompoundBezierPath trimmedPath = trimCompoundPath(tempPath, currentTrim->start, currentTrim->end, currentTrim->offset, currentTrim->type);
|
CompoundBezierPath trimmedPath = trimCompoundPath(tempPath, currentTrim->start, currentTrim->end, currentTrim->offset, currentTrim->type);
|
||||||
for (auto &path : trimmedPath.paths) {
|
for (auto &path : trimmedPath.paths) {
|
||||||
mappedPaths.emplace_back(path, CATransform3D::identity());
|
mappedPaths.emplace_back(path, Transform3D::identity());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto &path : subItemPaths) {
|
for (auto &path : subItemPaths) {
|
||||||
@ -1061,7 +1061,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateContents(std::optional<TrimParams> parentTrim) {
|
void updateContents(std::optional<TrimParams> parentTrim) {
|
||||||
CATransform3D containerTransform = CATransform3D::identity();
|
Transform3D containerTransform = Transform3D::identity();
|
||||||
float containerOpacity = 1.0;
|
float containerOpacity = 1.0;
|
||||||
if (transform) {
|
if (transform) {
|
||||||
containerTransform = transform->transform();
|
containerTransform = transform->transform();
|
||||||
@ -1089,7 +1089,7 @@ public:
|
|||||||
|
|
||||||
if (parentTrim) {
|
if (parentTrim) {
|
||||||
CompoundBezierPath compoundPath;
|
CompoundBezierPath compoundPath;
|
||||||
auto paths = collectPaths(shadingVariant.subItemLimit, CATransform3D::identity(), true);
|
auto paths = collectPaths(shadingVariant.subItemLimit, Transform3D::identity(), true);
|
||||||
for (const auto &path : paths) {
|
for (const auto &path : paths) {
|
||||||
compoundPath.appendPath(path.path.copyUsingTransform(path.transform));
|
compoundPath.appendPath(path.path.copyUsingTransform(path.transform));
|
||||||
}
|
}
|
||||||
@ -1104,7 +1104,7 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
if (hasTrims()) {
|
if (hasTrims()) {
|
||||||
CompoundBezierPath compoundPath;
|
CompoundBezierPath compoundPath;
|
||||||
auto paths = collectPaths(shadingVariant.subItemLimit, CATransform3D::identity(), true);
|
auto paths = collectPaths(shadingVariant.subItemLimit, Transform3D::identity(), true);
|
||||||
for (const auto &path : paths) {
|
for (const auto &path : paths) {
|
||||||
compoundPath.appendPath(path.path.copyUsingTransform(path.transform));
|
compoundPath.appendPath(path.path.copyUsingTransform(path.transform));
|
||||||
}
|
}
|
||||||
@ -1325,7 +1325,7 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode(BezierPath
|
|||||||
_contentRenderTreeNode = std::make_shared<RenderTreeNode>(
|
_contentRenderTreeNode = std::make_shared<RenderTreeNode>(
|
||||||
CGRect(0.0, 0.0, 0.0, 0.0),
|
CGRect(0.0, 0.0, 0.0, 0.0),
|
||||||
Vector2D(0.0, 0.0),
|
Vector2D(0.0, 0.0),
|
||||||
CATransform3D::identity(),
|
Transform3D::identity(),
|
||||||
1.0,
|
1.0,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@ -1351,7 +1351,7 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode(BezierPath
|
|||||||
_renderTreeNode = std::make_shared<RenderTreeNode>(
|
_renderTreeNode = std::make_shared<RenderTreeNode>(
|
||||||
CGRect(0.0, 0.0, 0.0, 0.0),
|
CGRect(0.0, 0.0, 0.0, 0.0),
|
||||||
Vector2D(0.0, 0.0),
|
Vector2D(0.0, 0.0),
|
||||||
CATransform3D::identity(),
|
Transform3D::identity(),
|
||||||
1.0,
|
1.0,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -239,7 +239,7 @@ public:
|
|||||||
_renderTreeNode = std::make_shared<RenderTreeNode>(
|
_renderTreeNode = std::make_shared<RenderTreeNode>(
|
||||||
bounds(),
|
bounds(),
|
||||||
position(),
|
position(),
|
||||||
CATransform3D::identity(),
|
Transform3D::identity(),
|
||||||
1.0,
|
1.0,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -157,7 +157,7 @@ public:
|
|||||||
|
|
||||||
Vector3D anchor = _transformProperties->anchor()->value();
|
Vector3D anchor = _transformProperties->anchor()->value();
|
||||||
Vector3D scale = _transformProperties->scale()->value();
|
Vector3D scale = _transformProperties->scale()->value();
|
||||||
_localTransform = CATransform3D::makeTransform(
|
_localTransform = Transform3D::makeTransform(
|
||||||
Vector2D(anchor.x, anchor.y),
|
Vector2D(anchor.x, anchor.y),
|
||||||
position,
|
position,
|
||||||
Vector2D(scale.x, scale.y),
|
Vector2D(scale.x, scale.y),
|
||||||
@ -181,7 +181,7 @@ public:
|
|||||||
return _opacity;
|
return _opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D const &globalTransform() {
|
Transform3D const &globalTransform() {
|
||||||
return _globalTransform;
|
return _globalTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,8 +191,8 @@ private:
|
|||||||
std::shared_ptr<LayerTransformProperties> _transformProperties;
|
std::shared_ptr<LayerTransformProperties> _transformProperties;
|
||||||
|
|
||||||
float _opacity = 1.0;
|
float _opacity = 1.0;
|
||||||
CATransform3D _localTransform = CATransform3D::identity();
|
Transform3D _localTransform = Transform3D::identity();
|
||||||
CATransform3D _globalTransform = CATransform3D::identity();
|
Transform3D _globalTransform = Transform3D::identity();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual LayerTransformNode *asLayerTransformNode() override {
|
virtual LayerTransformNode *asLayerTransformNode() override {
|
||||||
|
@ -93,7 +93,7 @@ public:
|
|||||||
return _childKeypaths;
|
return _childKeypaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D caTransform() {
|
Transform3D caTransform() {
|
||||||
Vector2D anchor = Vector2D::Zero();
|
Vector2D anchor = Vector2D::Zero();
|
||||||
if (_anchor) {
|
if (_anchor) {
|
||||||
auto anchor3d = _anchor->value();
|
auto anchor3d = _anchor->value();
|
||||||
@ -126,7 +126,7 @@ public:
|
|||||||
skewAxis = _skewAxis->value().value;
|
skewAxis = _skewAxis->value().value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CATransform3D::makeTransform(
|
return Transform3D::makeTransform(
|
||||||
anchor,
|
anchor,
|
||||||
position,
|
position,
|
||||||
scale,
|
scale,
|
||||||
@ -212,16 +212,16 @@ public:
|
|||||||
return _parentTextNode;
|
return _parentTextNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D xform() {
|
Transform3D xform() {
|
||||||
if (_xform.has_value()) {
|
if (_xform.has_value()) {
|
||||||
return _xform.value();
|
return _xform.value();
|
||||||
} else if (_parentTextNode) {
|
} else if (_parentTextNode) {
|
||||||
return _parentTextNode->xform();
|
return _parentTextNode->xform();
|
||||||
} else {
|
} else {
|
||||||
return CATransform3D::identity();
|
return Transform3D::identity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setXform(CATransform3D const &xform) {
|
void setXform(Transform3D const &xform) {
|
||||||
_xform = xform;
|
_xform = xform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ private:
|
|||||||
|
|
||||||
std::shared_ptr<CGPath> _outputPath;
|
std::shared_ptr<CGPath> _outputPath;
|
||||||
|
|
||||||
std::optional<CATransform3D> _xform;
|
std::optional<Transform3D> _xform;
|
||||||
std::optional<float> _opacity;
|
std::optional<float> _opacity;
|
||||||
std::optional<Color> _strokeColor;
|
std::optional<Color> _strokeColor;
|
||||||
std::optional<Color> _fillColor;
|
std::optional<Color> _fillColor;
|
||||||
|
@ -486,8 +486,8 @@ std::shared_ptr<CGPath> BezierPath::cgPath() const {
|
|||||||
return _contents->cgPath();
|
return _contents->cgPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
BezierPath BezierPath::copyUsingTransform(CATransform3D const &transform) const {
|
BezierPath BezierPath::copyUsingTransform(Transform3D const &transform) const {
|
||||||
if (transform == CATransform3D::identity()) {
|
if (transform == Transform3D::identity()) {
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
BezierPath result;
|
BezierPath result;
|
||||||
|
@ -89,10 +89,10 @@ public:
|
|||||||
return bounds();
|
return bounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D const &transform() const {
|
Transform3D const &transform() const {
|
||||||
return _transform;
|
return _transform;
|
||||||
}
|
}
|
||||||
void setTransform(CATransform3D const &transform) {
|
void setTransform(Transform3D const &transform) {
|
||||||
_transform = transform;
|
_transform = transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ private:
|
|||||||
float _opacity = 1.0;
|
float _opacity = 1.0;
|
||||||
Vector2D _position = Vector2D(0.0, 0.0);
|
Vector2D _position = Vector2D(0.0, 0.0);
|
||||||
CGRect _bounds = CGRect(0.0, 0.0, 0.0, 0.0);
|
CGRect _bounds = CGRect(0.0, 0.0, 0.0, 0.0);
|
||||||
CATransform3D _transform = CATransform3D::identity();
|
Transform3D _transform = Transform3D::identity();
|
||||||
std::shared_ptr<CALayer> _mask;
|
std::shared_ptr<CALayer> _mask;
|
||||||
bool _masksToBounds = false;
|
bool _masksToBounds = false;
|
||||||
std::optional<BlendMode> _compositingFilter;
|
std::optional<BlendMode> _compositingFilter;
|
||||||
|
@ -35,7 +35,7 @@ void addPointToBoundingRect(bool *isFirst, CGRect *rect, Vector2D const *point)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D transformVector(Vector2D const &v, CATransform3D const &m) {
|
Vector2D transformVector(Vector2D const &v, Transform3D const &m) {
|
||||||
return Vector2D(
|
return Vector2D(
|
||||||
m.m11 * v.x + m.m21 * v.y + m.m41 * 1.0,
|
m.m11 * v.x + m.m21 * v.y + m.m41 * 1.0,
|
||||||
m.m12 * v.x + m.m22 * v.y + m.m42 * 1.0
|
m.m12 * v.x + m.m22 * v.y + m.m42 * 1.0
|
||||||
@ -51,7 +51,7 @@ public:
|
|||||||
|
|
||||||
virtual bool empty() const override;
|
virtual bool empty() const override;
|
||||||
|
|
||||||
virtual std::shared_ptr<CGPath> copyUsingTransform(CATransform3D const &transform) const override;
|
virtual std::shared_ptr<CGPath> copyUsingTransform(Transform3D const &transform) const override;
|
||||||
|
|
||||||
virtual void addLineTo(Vector2D const &point) override;
|
virtual void addLineTo(Vector2D const &point) override;
|
||||||
virtual void addCurveTo(Vector2D const &point, Vector2D const &control1, Vector2D const &control2) override;
|
virtual void addCurveTo(Vector2D const &point, Vector2D const &control1, Vector2D const &control2) override;
|
||||||
@ -108,10 +108,10 @@ bool CGPathImpl::empty() const {
|
|||||||
return _items.empty();
|
return _items.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CGPath> CGPathImpl::copyUsingTransform(CATransform3D const &transform) const {
|
std::shared_ptr<CGPath> CGPathImpl::copyUsingTransform(Transform3D const &transform) const {
|
||||||
auto result = std::make_shared<CGPathImpl>();
|
auto result = std::make_shared<CGPathImpl>();
|
||||||
|
|
||||||
if (transform == CATransform3D::identity()) {
|
if (transform == Transform3D::identity()) {
|
||||||
result->_items = _items;
|
result->_items = _items;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ bool CGPathCocoaImpl::empty() const {
|
|||||||
return CGPathIsEmpty(_path);
|
return CGPathIsEmpty(_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CGPath> CGPathCocoaImpl::copyUsingTransform(CATransform3D const &transform) const {
|
std::shared_ptr<CGPath> CGPathCocoaImpl::copyUsingTransform(Transform3D const &transform) const {
|
||||||
::CATransform3D nativeTransform;
|
::CATransform3D nativeTransform;
|
||||||
nativeTransform.m11 = transform.m11;
|
nativeTransform.m11 = transform.m11;
|
||||||
nativeTransform.m12 = transform.m12;
|
nativeTransform.m12 = transform.m12;
|
||||||
|
@ -140,7 +140,7 @@ lottiejson11::Json Vector3D::toJson() const {
|
|||||||
return lottiejson11::Json(result);
|
return lottiejson11::Json(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D CATransform3D::_identity = CATransform3D(
|
Transform3D Transform3D::_identity = Transform3D(
|
||||||
1.0, 0.0, 0.0, 0.0,
|
1.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0, 0.0,
|
0.0, 1.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 1.0, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
||||||
@ -415,7 +415,7 @@ Vector2D Vector2D::interpolate(
|
|||||||
return point.point;
|
return point.point;
|
||||||
}
|
}
|
||||||
|
|
||||||
::CATransform3D nativeTransform(CATransform3D const &value) {
|
::CATransform3D nativeTransform(Transform3D const &value) {
|
||||||
::CATransform3D result;
|
::CATransform3D result;
|
||||||
|
|
||||||
result.m11 = value.m11;
|
result.m11 = value.m11;
|
||||||
@ -441,8 +441,8 @@ Vector2D Vector2D::interpolate(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D fromNativeTransform(::CATransform3D const &value) {
|
Transform3D fromNativeTransform(::CATransform3D const &value) {
|
||||||
CATransform3D result = CATransform3D::identity();
|
Transform3D result = Transform3D::identity();
|
||||||
|
|
||||||
result.m11 = value.m11;
|
result.m11 = value.m11;
|
||||||
result.m12 = value.m12;
|
result.m12 = value.m12;
|
||||||
@ -467,7 +467,7 @@ CATransform3D fromNativeTransform(::CATransform3D const &value) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D CATransform3D::makeRotation(float radians, float x, float y, float z) {
|
Transform3D Transform3D::makeRotation(float radians, float x, float y, float z) {
|
||||||
return fromNativeTransform(CATransform3DMakeRotation(radians, x, y, z));
|
return fromNativeTransform(CATransform3DMakeRotation(radians, x, y, z));
|
||||||
|
|
||||||
/*if (x == 0.0 && y == 0.0 && z == 0.0) {
|
/*if (x == 0.0 && y == 0.0 && z == 0.0) {
|
||||||
@ -505,21 +505,21 @@ CATransform3D CATransform3D::makeRotation(float radians, float x, float y, float
|
|||||||
return returnValue;*/
|
return returnValue;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D CATransform3D::rotated(float degrees) const {
|
Transform3D Transform3D::rotated(float degrees) const {
|
||||||
return fromNativeTransform(CATransform3DRotate(nativeTransform(*this), degreesToRadians(degrees), 0.0, 0.0, 1.0));
|
return fromNativeTransform(CATransform3DRotate(nativeTransform(*this), degreesToRadians(degrees), 0.0, 0.0, 1.0));
|
||||||
//return CATransform3D::makeRotation(degreesToRadians(degrees), 0.0, 0.0, 1.0) * (*this);
|
//return CATransform3D::makeRotation(degreesToRadians(degrees), 0.0, 0.0, 1.0) * (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D CATransform3D::translated(Vector2D const &translation) const {
|
Transform3D Transform3D::translated(Vector2D const &translation) const {
|
||||||
return fromNativeTransform(CATransform3DTranslate(nativeTransform(*this), translation.x, translation.y, 0.0));
|
return fromNativeTransform(CATransform3DTranslate(nativeTransform(*this), translation.x, translation.y, 0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D CATransform3D::scaled(Vector2D const &scale) const {
|
Transform3D Transform3D::scaled(Vector2D const &scale) const {
|
||||||
return fromNativeTransform(CATransform3DScale(nativeTransform(*this), scale.x, scale.y, 1.0));
|
return fromNativeTransform(CATransform3DScale(nativeTransform(*this), scale.x, scale.y, 1.0));
|
||||||
//return CATransform3D::makeScale(scale.x, scale.y, 1.0) * (*this);
|
//return CATransform3D::makeScale(scale.x, scale.y, 1.0) * (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D CATransform3D::operator*(CATransform3D const &b) const {
|
Transform3D Transform3D::operator*(Transform3D const &b) const {
|
||||||
if (isIdentity()) {
|
if (isIdentity()) {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
@ -541,7 +541,7 @@ CATransform3D CATransform3D::operator*(CATransform3D const &b) const {
|
|||||||
};
|
};
|
||||||
|
|
||||||
simd_float4x4 simdResult = simd_mul(simdRhs, simdLhs);
|
simd_float4x4 simdResult = simd_mul(simdRhs, simdLhs);
|
||||||
return CATransform3D(
|
return Transform3D(
|
||||||
simdResult.columns[0][0], simdResult.columns[1][0], simdResult.columns[2][0], simdResult.columns[3][0],
|
simdResult.columns[0][0], simdResult.columns[1][0], simdResult.columns[2][0], simdResult.columns[3][0],
|
||||||
simdResult.columns[0][1], simdResult.columns[1][1], simdResult.columns[2][1], simdResult.columns[3][1],
|
simdResult.columns[0][1], simdResult.columns[1][1], simdResult.columns[2][1], simdResult.columns[3][1],
|
||||||
simdResult.columns[0][2], simdResult.columns[1][2], simdResult.columns[2][2], simdResult.columns[3][2],
|
simdResult.columns[0][2], simdResult.columns[1][2], simdResult.columns[2][2], simdResult.columns[3][2],
|
||||||
@ -549,11 +549,11 @@ CATransform3D CATransform3D::operator*(CATransform3D const &b) const {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CATransform3D::isInvertible() const {
|
bool Transform3D::isInvertible() const {
|
||||||
return std::abs(m11 * m22 - m12 * m21) >= 0.00000001;
|
return std::abs(m11 * m22 - m12 * m21) >= 0.00000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
CATransform3D CATransform3D::inverted() const {
|
Transform3D Transform3D::inverted() const {
|
||||||
simd_float4x4 matrix = {
|
simd_float4x4 matrix = {
|
||||||
simd_make_float4(m11, m21, m31, m41),
|
simd_make_float4(m11, m21, m31, m41),
|
||||||
simd_make_float4(m12, m22, m32, m42),
|
simd_make_float4(m12, m22, m32, m42),
|
||||||
@ -561,7 +561,7 @@ CATransform3D CATransform3D::inverted() const {
|
|||||||
simd_make_float4(m14, m24, m34, m44)
|
simd_make_float4(m14, m24, m34, m44)
|
||||||
};
|
};
|
||||||
simd_float4x4 result = simd_inverse(matrix);
|
simd_float4x4 result = simd_inverse(matrix);
|
||||||
CATransform3D nativeResult = CATransform3D(
|
Transform3D nativeResult = Transform3D(
|
||||||
result.columns[0][0], result.columns[1][0], result.columns[2][0], result.columns[3][0],
|
result.columns[0][0], result.columns[1][0], result.columns[2][0], result.columns[3][0],
|
||||||
result.columns[0][1], result.columns[1][1], result.columns[2][1], result.columns[3][1],
|
result.columns[0][1], result.columns[1][1], result.columns[2][1], result.columns[3][1],
|
||||||
result.columns[0][2], result.columns[1][2], result.columns[2][2], result.columns[3][2],
|
result.columns[0][2], result.columns[1][2], result.columns[2][2], result.columns[3][2],
|
||||||
@ -589,7 +589,7 @@ CGRect CGRect::unionWith(CGRect const &other) const {
|
|||||||
return CGRect(result.origin.x, result.origin.y, result.size.width, result.size.height);
|
return CGRect(result.origin.x, result.origin.y, result.size.width, result.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGRect CGRect::applyingTransform(CATransform3D const &transform) const {
|
CGRect CGRect::applyingTransform(Transform3D const &transform) const {
|
||||||
if (transform.isIdentity()) {
|
if (transform.isIdentity()) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user