diff --git a/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm b/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm index def813ef48..25fbb49c66 100644 --- a/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm +++ b/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm @@ -134,9 +134,7 @@ static std::optional getRenderNodeGlobalRect(std::shared_ptrposition().x + -node->bounds().x, node->position().y + -node->bounds().y); Transform3D localTransform = node->transform(); - localTransform = localTransform.translated(localTranslation); currentTransform = localTransform * currentTransform; std::optional globalRect; @@ -145,7 +143,7 @@ static std::optional getRenderNodeGlobalRect(std::shared_ptrbounds().applyingTransform(currentTransform); + CGRect globalBounds = CGRect(0.0f, 0.0f, node->size().x, node->size().y).applyingTransform(currentTransform); if (globalRect) { globalRect = globalRect->unionWith(globalBounds); } else { @@ -467,9 +465,7 @@ static void renderLottieRenderNode(std::shared_ptr node, } auto currentTransform = parentTransform; - lottie::Vector2D localTranslation(node->position().x + -node->bounds().x, node->position().y + -node->bounds().y); lottie::Transform3D localTransform = node->transform(); - localTransform = localTransform.translated(localTranslation); currentTransform = localTransform * currentTransform; std::shared_ptr maskContext; @@ -478,7 +474,7 @@ static void renderLottieRenderNode(std::shared_ptr node, bool masksToBounds = node->masksToBounds(); if (masksToBounds) { - lottie::CGRect effectiveGlobalBounds = node->bounds().applyingTransform(currentTransform); + lottie::CGRect effectiveGlobalBounds = lottie::CGRect(0.0f, 0.0f, node->size().x, node->size().y).applyingTransform(currentTransform); if (effectiveGlobalBounds.width <= 0.0f || effectiveGlobalBounds.height <= 0.0f) { return; } @@ -515,7 +511,7 @@ static void renderLottieRenderNode(std::shared_ptr node, maskBackingStorage->concatenate(currentTransform); if (masksToBounds) { - maskBackingStorage->fill(lottie::CGRect(node->bounds().x, node->bounds().y, node->bounds().width, node->bounds().height), lottie::Color(1.0, 1.0, 1.0, 1.0)); + maskBackingStorage->fill(lottie::CGRect(0.0f, 0.0f, node->size().x, node->size().y), lottie::Color(1.0f, 1.0f, 1.0f, 1.0f)); } if (node->mask() && !node->mask()->isHidden() && node->mask()->alpha() >= minVisibleAlpha) { renderLottieRenderNode(node->mask(), maskBackingStorage, globalSize, currentTransform, 1.0, node->invertMask(), bezierPathsBoundingBoxContext); @@ -536,13 +532,11 @@ static void renderLottieRenderNode(std::shared_ptr node, currentContext = parentContext; } - parentContext->concatenate(lottie::Transform3D::identity().translated(lottie::Vector2D(node->position().x, node->position().y))); - parentContext->concatenate(lottie::Transform3D::identity().translated(lottie::Vector2D(-node->bounds().x, -node->bounds().y))); parentContext->concatenate(node->transform()); - float renderAlpha = 1.0; + float renderAlpha = 1.0f; if (tempContext) { - renderAlpha = 1.0; + renderAlpha = 1.0f; } else { renderAlpha = layerAlpha; } @@ -552,7 +546,7 @@ static void renderLottieRenderNode(std::shared_ptr node, } if (isInvertedMatte) { - currentContext->fill(lottie::CGRect(node->bounds().x, node->bounds().y, node->bounds().width, node->bounds().height), lottie::Color(0.0, 0.0, 0.0, 1.0)); + currentContext->fill(lottie::CGRect(0.0f, 0.0f, node->size().x, node->size().y), lottie::Color(0.0f, 0.0f, 0.0f, 1.0f)); currentContext->setBlendMode(lottieRendering::BlendMode::DestinationOut); } diff --git a/submodules/TelegramUI/Components/LottieCpp/PublicHeaders/LottieCpp/RenderTreeNode.h b/submodules/TelegramUI/Components/LottieCpp/PublicHeaders/LottieCpp/RenderTreeNode.h index 5dec74814f..9d08581009 100644 --- a/submodules/TelegramUI/Components/LottieCpp/PublicHeaders/LottieCpp/RenderTreeNode.h +++ b/submodules/TelegramUI/Components/LottieCpp/PublicHeaders/LottieCpp/RenderTreeNode.h @@ -391,8 +391,7 @@ public: class RenderTreeNode { public: RenderTreeNode( - CGRect bounds_, - Vector2D position_, + Vector2D size_, Transform3D transform_, float alpha_, bool masksToBounds_, @@ -401,8 +400,7 @@ public: std::shared_ptr mask_, bool invertMask_ ) : - _bounds(bounds_), - _position(position_), + _size(size_), _transform(transform_), _alpha(alpha_), _masksToBounds(masksToBounds_), @@ -419,12 +417,8 @@ public: } public: - CGRect const &bounds() const { - return _bounds; - } - - Vector2D const &position() const { - return _position; + Vector2D const &size() const { + return _size; } Transform3D const &transform() const { @@ -456,8 +450,7 @@ public: } public: - CGRect _bounds; - Vector2D _position; + Vector2D _size; Transform3D _transform = Transform3D::identity(); float _alpha = 1.0f; bool _masksToBounds = false; diff --git a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/CompositionLayer.cpp b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/CompositionLayer.cpp index 1a87942244..53f850f090 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/CompositionLayer.cpp +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/CompositionLayer.cpp @@ -4,7 +4,7 @@ namespace lottie { InvertedMatteLayer::InvertedMatteLayer(std::shared_ptr inputMatte) : _inputMatte(inputMatte) { - setBounds(inputMatte->bounds()); + setSize(inputMatte->size()); addSublayer(_inputMatte); } diff --git a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/CompositionLayer.hpp b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/CompositionLayer.hpp index 13e275dfdd..e82b9c8b33 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/CompositionLayer.hpp +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/CompositionLayer.hpp @@ -57,7 +57,7 @@ public: _childKeypaths.push_back(_transformNode->transformProperties()); - _contentsLayer->setBounds(CGRect(0.0, 0.0, size.x, size.y)); + _contentsLayer->setSize(size); if (layer->blendMode.has_value() && layer->blendMode.value() != BlendMode::Normal) { setCompositingFilter(layer->blendMode); diff --git a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/PreCompositionLayer.hpp b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/PreCompositionLayer.hpp index e1538ec1a9..af69491fa3 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/PreCompositionLayer.hpp +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/PreCompositionLayer.hpp @@ -30,9 +30,9 @@ public: } _frameRate = frameRate; - setBounds(CGRect(0.0, 0.0, precomp->width, precomp->height)); + setSize(Vector2D(precomp->width, precomp->height)); contentsLayer()->setMasksToBounds(true); - contentsLayer()->setBounds(bounds()); + contentsLayer()->setSize(size()); auto layers = initializeCompositionLayers( asset.layers, @@ -49,7 +49,7 @@ public: for (auto layerIt = layers.rbegin(); layerIt != layers.rend(); layerIt++) { std::shared_ptr layer = *layerIt; - layer->setBounds(bounds()); + layer->setSize(size()); _animationLayers.push_back(layer); if (layer->isImageCompositionLayer()) { @@ -121,7 +121,6 @@ public: std::vector> renderTreeValue; auto renderTreeContentItem = std::make_shared( - CGRect(0.0, 0.0, 0.0, 0.0), Vector2D(0.0, 0.0), Transform3D::identity(), 1.0, @@ -136,7 +135,6 @@ public: } _contentsTreeNode = std::make_shared( - CGRect(0.0, 0.0, 0.0, 0.0), Vector2D(0.0, 0.0), Transform3D::identity(), 1.0, @@ -160,7 +158,6 @@ public: } _renderTreeNode = std::make_shared( - CGRect(0.0, 0.0, 0.0, 0.0), Vector2D(0.0, 0.0), Transform3D::identity(), 1.0, @@ -172,12 +169,10 @@ public: ); } - _contentsTreeNode->_bounds = _contentsLayer->bounds(); - _contentsTreeNode->_position = _contentsLayer->position(); + _contentsTreeNode->_size = _contentsLayer->size(); _contentsTreeNode->_masksToBounds = _contentsLayer->masksToBounds(); - _renderTreeNode->_bounds = bounds(); - _renderTreeNode->_position = position(); + _renderTreeNode->_size = size(); _renderTreeNode->_transform = transform(); _renderTreeNode->_alpha = opacity(); _renderTreeNode->_masksToBounds = masksToBounds(); diff --git a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/ShapeCompositionLayer.cpp b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/ShapeCompositionLayer.cpp index 7f3968b1c8..19f244e0ee 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/ShapeCompositionLayer.cpp +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/ShapeCompositionLayer.cpp @@ -1323,7 +1323,6 @@ std::shared_ptr ShapeCompositionLayer::renderTreeNode(BezierPath if (!_renderTreeNode) { _contentRenderTreeNode = std::make_shared( - CGRect(0.0, 0.0, 0.0, 0.0), Vector2D(0.0, 0.0), Transform3D::identity(), 1.0, @@ -1349,7 +1348,6 @@ std::shared_ptr ShapeCompositionLayer::renderTreeNode(BezierPath } _renderTreeNode = std::make_shared( - CGRect(0.0, 0.0, 0.0, 0.0), Vector2D(0.0, 0.0), Transform3D::identity(), 1.0, @@ -1361,14 +1359,12 @@ std::shared_ptr ShapeCompositionLayer::renderTreeNode(BezierPath ); } - _contentRenderTreeNode->_bounds = _contentsLayer->bounds(); - _contentRenderTreeNode->_position = _contentsLayer->position(); + _contentRenderTreeNode->_size = _contentsLayer->size(); _contentRenderTreeNode->_masksToBounds = _contentsLayer->masksToBounds(); _renderTreeNode->_masksToBounds = masksToBounds(); - _renderTreeNode->_bounds = bounds(); - _renderTreeNode->_position = position(); + _renderTreeNode->_size = size(); return _renderTreeNode; } diff --git a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/MainThreadAnimationLayer.hpp b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/MainThreadAnimationLayer.hpp index 2d080d80d6..b8b288307f 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/MainThreadAnimationLayer.hpp +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/MainThreadAnimationLayer.hpp @@ -42,7 +42,7 @@ public: _layerTextProvider = std::make_shared(textProvider); _layerFontProvider = std::make_shared(fontProvider); - setBounds(CGRect(0.0, 0.0, animation.width, animation.height)); + setSize(Vector2D(animation.width, animation.height)); auto layers = initializeCompositionLayers( animation.layers, @@ -60,7 +60,7 @@ public: for (auto layerIt = layers.rbegin(); layerIt != layers.rend(); layerIt++) { std::shared_ptr const &layer = *layerIt; - layer->setBounds(bounds()); + layer->setSize(size()); _animationLayers.push_back(layer); if (layer->isImageCompositionLayer()) { @@ -237,8 +237,7 @@ public: } } _renderTreeNode = std::make_shared( - bounds(), - position(), + size(), Transform3D::identity(), 1.0, false, diff --git a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Public/Primitives/CALayer.hpp b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Public/Primitives/CALayer.hpp index 5a26454a94..2c40c5667e 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Public/Primitives/CALayer.hpp +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Public/Primitives/CALayer.hpp @@ -24,27 +24,13 @@ public: virtual ~CALayer() = default; void addSublayer(std::shared_ptr layer) { - if (layer->_superlayer) { - layer->_superlayer->removeSublayer(layer.get()); - } - layer->_superlayer = this; _sublayers.push_back(layer); } void insertSublayer(std::shared_ptr layer, int index) { - if (layer->_superlayer) { - layer->_superlayer->removeSublayer(layer.get()); - } - layer->_superlayer = this; _sublayers.insert(_sublayers.begin() + index, layer); } - void removeFromSuperlayer() { - if (_superlayer) { - _superlayer->removeSublayer(this); - } - } - virtual bool implementsDraw() const { return false; } @@ -71,22 +57,11 @@ public: _opacity = opacity; } - Vector2D const &position() const { - return _position; + Vector2D const &size() const { + return _size; } - void setPosition(Vector2D const &position) { - _position = position; - } - - CGRect const &bounds() const { - return _bounds; - } - void setBounds(CGRect const &bounds) { - _bounds = bounds; - } - - virtual CGRect effectiveBounds() const { - return bounds(); + void setSize(Vector2D const &size) { + _size = size; } Transform3D const &transform() const { @@ -131,7 +106,6 @@ private: void removeSublayer(CALayer *layer) { for (auto it = _sublayers.begin(); it != _sublayers.end(); it++) { if (it->get() == layer) { - layer->_superlayer = nullptr; _sublayers.erase(it); break; } @@ -139,12 +113,10 @@ private: } private: - CALayer *_superlayer = nullptr; std::vector> _sublayers; bool _isHidden = false; float _opacity = 1.0; - Vector2D _position = Vector2D(0.0, 0.0); - CGRect _bounds = CGRect(0.0, 0.0, 0.0, 0.0); + Vector2D _size = Vector2D(0.0, 0.0); Transform3D _transform = Transform3D::identity(); std::shared_ptr _mask; bool _masksToBounds = false; @@ -221,21 +193,6 @@ public: _dashPattern = dashPattern; } - virtual CGRect effectiveBounds() const override { - if (_path) { - CGRect boundingBox = _path->boundingBox(); - if (_strokeColor) { - boundingBox.x -= _lineWidth / 2.0; - boundingBox.y -= _lineWidth / 2.0; - boundingBox.width += _lineWidth; - boundingBox.height += _lineWidth; - } - return boundingBox; - } else { - return CGRect(0.0, 0.0, 0.0, 0.0); - } - } - std::shared_ptr renderableItem() override; private: diff --git a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Public/Primitives/Vectors.mm b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Public/Primitives/Vectors.mm index b6f8276bf7..9618e9e289 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Public/Primitives/Vectors.mm +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Public/Primitives/Vectors.mm @@ -468,10 +468,8 @@ Transform3D fromNativeTransform(::CATransform3D const &value) { } Transform3D Transform3D::makeRotation(float radians, float x, float y, float z) { - return fromNativeTransform(CATransform3DMakeRotation(radians, x, y, z)); - - /*if (x == 0.0 && y == 0.0 && z == 0.0) { - return CATransform3D::identity(); + if (std::abs(radians) <= FLT_EPSILON || (x == 0.0 && y == 0.0 && z == 0.0)) { + return Transform3D::identity(); } float s = sin(radians); @@ -480,43 +478,41 @@ Transform3D Transform3D::makeRotation(float radians, float x, float y, float z) float len = sqrt(x*x + y*y + z*z); x /= len; y /= len; z /= len; - CATransform3D returnValue = CATransform3D::identity(); + Transform3D returnValue = Transform3D::identity(); - returnValue.m11 = c + (1-c) * x*x; - returnValue.m12 = (1-c) * x*y + s*z; - returnValue.m13 = (1-c) * x*z - s*y; - returnValue.m14 = 0; + returnValue.m11 = c + (1.0f - c) * x * x; + returnValue.m12 = (1.0f - c) * x*y + s * z; + returnValue.m13 = (1.0f - c) * x*z - s * y; + returnValue.m14 = 0.0f; - returnValue.m21 = (1-c) * y*x - s*z; - returnValue.m22 = c + (1-c) * y*y; - returnValue.m23 = (1-c) * y*z + s*x; - returnValue.m24 = 0; + returnValue.m21 = (1.0f - c) * y * x - s * z; + returnValue.m22 = c + (1.0f - c) * y * y; + returnValue.m23 = (1.0f - c) * y * z + s * x; + returnValue.m24 = 0.0f; - returnValue.m31 = (1-c) * z*x + s*y; - returnValue.m32 = (1-c) * y*z - s*x; - returnValue.m33 = c + (1-c) * z*z; - returnValue.m34 = 0; + returnValue.m31 = (1.0f - c) * z * x + s * y; + returnValue.m32 = (1.0f - c) * y * z - s * x; + returnValue.m33 = c + (1.0f - c) * z * z; + returnValue.m34 = 0.0f; - returnValue.m41 = 0; - returnValue.m42 = 0; - returnValue.m43 = 0; - returnValue.m44 = 1; + returnValue.m41 = 0.0f; + returnValue.m42 = 0.0f; + returnValue.m43 = 0.0f; + returnValue.m44 = 1.0f; - return returnValue;*/ + return returnValue; } Transform3D Transform3D::rotated(float degrees) const { - 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 Transform3D::makeRotation(degreesToRadians(degrees), 0.0, 0.0, 1.0) * (*this); } Transform3D Transform3D::translated(Vector2D const &translation) const { - return fromNativeTransform(CATransform3DTranslate(nativeTransform(*this), translation.x, translation.y, 0.0)); + return Transform3D::makeTranslation(translation.x, translation.y, 0.0f) * (*this); } Transform3D Transform3D::scaled(Vector2D const &scale) const { - return fromNativeTransform(CATransform3DScale(nativeTransform(*this), scale.x, scale.y, 1.0)); - //return CATransform3D::makeScale(scale.x, scale.y, 1.0) * (*this); + return Transform3D::makeScale(scale.x, scale.y, 1.0) * (*this); } Transform3D Transform3D::operator*(Transform3D const &b) const {