Commit bd58b999 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Simplify the SVGTransformList.consolidate implementation

Since SVGTransformListTearOff::consolidate() is the business logic of
this method, we can implement the specific logic there rather than in
SVGTransformList. With that also drop the IsEmpty() check from

it return the resulting AffineTransform instead of using an out-
variable.

SVGTransformList: :Concatenate() - leaving that to the callers - and have
Change-Id: I25c80f7ae222f48fafecccd876a2cd79d57004e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218021Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#773093}
parent 07f002f9
...@@ -670,15 +670,9 @@ AffineTransform SVGSVGElement::ViewBoxToViewTransform(float view_width, ...@@ -670,15 +670,9 @@ AffineTransform SVGSVGElement::ViewBoxToViewTransform(float view_width,
view_height); view_height);
if (!view_spec_ || !view_spec_->Transform()) if (!view_spec_ || !view_spec_->Transform())
return ctm; return ctm;
const SVGTransformList* transform_list = view_spec_->Transform(); const SVGTransformList* transform_list = view_spec_->Transform();
if (transform_list->IsEmpty()) if (!transform_list->IsEmpty())
return ctm; ctm *= transform_list->Concatenate();
AffineTransform transform;
if (transform_list->Concatenate(transform))
ctm *= transform;
return ctm; return ctm;
} }
......
...@@ -181,22 +181,11 @@ SVGTransformList::SVGTransformList(SVGTransformType transform_type, ...@@ -181,22 +181,11 @@ SVGTransformList::SVGTransformList(SVGTransformType transform_type,
SVGTransformList::~SVGTransformList() = default; SVGTransformList::~SVGTransformList() = default;
SVGTransform* SVGTransformList::Consolidate() { AffineTransform SVGTransformList::Concatenate() const {
AffineTransform matrix; AffineTransform result;
if (!Concatenate(matrix))
return nullptr;
return Initialize(MakeGarbageCollected<SVGTransform>(matrix));
}
bool SVGTransformList::Concatenate(AffineTransform& result) const {
if (IsEmpty())
return false;
for (const auto& item : *this) for (const auto& item : *this)
result *= item->Matrix(); result *= item->Matrix();
return result;
return true;
} }
namespace { namespace {
......
...@@ -50,9 +50,7 @@ class SVGTransformList final ...@@ -50,9 +50,7 @@ class SVGTransformList final
SVGTransformList(SVGTransformType, const String&); SVGTransformList(SVGTransformType, const String&);
~SVGTransformList() override; ~SVGTransformList() override;
SVGTransform* Consolidate(); AffineTransform Concatenate() const;
bool Concatenate(AffineTransform& result) const;
// SVGPropertyBase: // SVGPropertyBase:
SVGPropertyBase* CloneForAnimation(const String&) const override; SVGPropertyBase* CloneForAnimation(const String&) const override;
......
...@@ -57,7 +57,13 @@ SVGTransformTearOff* SVGTransformListTearOff::consolidate( ...@@ -57,7 +57,13 @@ SVGTransformTearOff* SVGTransformListTearOff::consolidate(
ThrowReadOnly(exception_state); ThrowReadOnly(exception_state);
return nullptr; return nullptr;
} }
return CreateItemTearOff(Target()->Consolidate()); SVGTransformList* transform_list = Target();
if (transform_list->IsEmpty())
return nullptr;
auto* concatenated_transform =
MakeGarbageCollected<SVGTransform>(transform_list->Concatenate());
transform_list->Initialize(concatenated_transform);
return CreateItemTearOff(concatenated_transform);
} }
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment