diff --git a/engine/src/flutter/impeller/.clang-tidy b/engine/src/flutter/impeller/.clang-tidy new file mode 100644 index 0000000000..17cf0e2daf --- /dev/null +++ b/engine/src/flutter/impeller/.clang-tidy @@ -0,0 +1,20 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,google-*,readability-identifier-naming,-google-explicit-constructor,cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init' +WarningsAsErrors: '' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: none +CheckOptions: + - key: readability-identifier-naming.PrivateMemberCase + value: 'lower_case' + - key: readability-identifier-naming.PrivateMemberSuffix + value: '_' + - key: readability-identifier-naming.PublicMethodCase + value: 'CamelCase' + - key: readability-identifier-naming.PrivateMethodCase + value: 'CamelCase' + - key: cppcoreguidelines-prefer-member-initializer.UseAssignment + value: true + - key: modernize-use-default-member-init.UseAssignment + value: true +... diff --git a/engine/src/flutter/impeller/impeller/entity/Color.cc b/engine/src/flutter/impeller/impeller/entity/Color.cc index 311d1ab517..175a327a30 100644 --- a/engine/src/flutter/impeller/impeller/entity/Color.cc +++ b/engine/src/flutter/impeller/impeller/entity/Color.cc @@ -94,13 +94,13 @@ std::string ColorHSB::toString() const { Color::Color(const ColorHSB& hsbColor) : Color(hsbColor.toRGBA()) {} -std::string Color::toString() const { +std::string Color::ToString() const { std::stringstream stream; stream << red << "," << green << "," << blue << "," << alpha; return stream.str(); } -void Color::fromString(const std::string& str) { +void Color::FromString(const std::string& str) { std::stringstream stream(str); stream >> red; stream.ignore(); diff --git a/engine/src/flutter/impeller/impeller/entity/Color.h b/engine/src/flutter/impeller/impeller/entity/Color.h index e00d8e428d..ab53f60f15 100644 --- a/engine/src/flutter/impeller/impeller/entity/Color.h +++ b/engine/src/flutter/impeller/impeller/entity/Color.h @@ -19,24 +19,24 @@ struct Color { /** * The red color component (0 to 1) */ - double red; + double red = 0.0; /** * The green color component (0 to 1) */ - double green; + double green = 0.0; /** * The blue color component (0 to 1) */ - double blue; + double blue = 0.0; /** * The alpha component of the color (0 to 1) */ - double alpha; + double alpha = 0.0; - Color() : red(0.0), green(0.0), blue(0.0), alpha(0.0) {} + Color() {} Color(const ColorHSB& hsbColor); @@ -50,9 +50,9 @@ struct Color { Color operator+(const Color& other) const; - std::string toString() const; + std::string ToString() const; - void fromString(const std::string& str); + void FromString(const std::string& str); static Color White() { return {1.0, 1.0, 1.0, 1.0}; } diff --git a/engine/src/flutter/impeller/impeller/geometry/Path.cc b/engine/src/flutter/impeller/impeller/geometry/Path.cc index 2b6dee74da..f5ac80ecd6 100644 --- a/engine/src/flutter/impeller/impeller/geometry/Path.cc +++ b/engine/src/flutter/impeller/impeller/geometry/Path.cc @@ -11,47 +11,47 @@ Path::Path() = default; Path::~Path() = default; -size_t Path::componentCount() const { - return _components.size(); +size_t Path::GetComponentCount() const { + return components_.size(); } -Path& Path::addLinearComponent(Point p1, Point p2) { - _linears.emplace_back(p1, p2); - _components.emplace_back(ComponentType::Linear, _linears.size() - 1); +Path& Path::AddLinearComponent(Point p1, Point p2) { + linears_.emplace_back(p1, p2); + components_.emplace_back(ComponentType::Linear, linears_.size() - 1); return *this; } -Path& Path::addQuadraticComponent(Point p1, Point cp, Point p2) { - _quads.emplace_back(p1, cp, p2); - _components.emplace_back(ComponentType::Quadratic, _quads.size() - 1); +Path& Path::AddQuadraticComponent(Point p1, Point cp, Point p2) { + quads_.emplace_back(p1, cp, p2); + components_.emplace_back(ComponentType::Quadratic, quads_.size() - 1); return *this; } -Path& Path::addCubicComponent(Point p1, Point cp1, Point cp2, Point p2) { - _cubics.emplace_back(p1, cp1, cp2, p2); - _components.emplace_back(ComponentType::Cubic, _cubics.size() - 1); +Path& Path::AddCubicComponent(Point p1, Point cp1, Point cp2, Point p2) { + cubics_.emplace_back(p1, cp1, cp2, p2); + components_.emplace_back(ComponentType::Cubic, cubics_.size() - 1); return *this; } -void Path::enumerateComponents(Applier linearApplier, +void Path::EnumerateComponents(Applier linearApplier, Applier quadApplier, Applier cubicApplier) const { size_t currentIndex = 0; - for (const auto& component : _components) { + for (const auto& component : components_) { switch (component.type) { case ComponentType::Linear: if (linearApplier) { - linearApplier(currentIndex, _linears[component.index]); + linearApplier(currentIndex, linears_[component.index]); } break; case ComponentType::Quadratic: if (quadApplier) { - quadApplier(currentIndex, _quads[component.index]); + quadApplier(currentIndex, quads_[component.index]); } break; case ComponentType::Cubic: if (cubicApplier) { - cubicApplier(currentIndex, _cubics[component.index]); + cubicApplier(currentIndex, cubics_[component.index]); } break; } @@ -59,111 +59,113 @@ void Path::enumerateComponents(Applier linearApplier, } } -bool Path::linearComponentAtIndex(size_t index, - LinearPathComponent& linear) const { - if (index >= _components.size()) { +bool Path::GetLinearComponentAtIndex(size_t index, + LinearPathComponent& linear) const { + if (index >= components_.size()) { return false; } - if (_components[index].type != ComponentType::Linear) { + if (components_[index].type != ComponentType::Linear) { return false; } - linear = _linears[_components[index].index]; + linear = linears_[components_[index].index]; return true; } -bool Path::quadraticComponentAtIndex(size_t index, - QuadraticPathComponent& quadratic) const { - if (index >= _components.size()) { +bool Path::GetQuadraticComponentAtIndex( + size_t index, + QuadraticPathComponent& quadratic) const { + if (index >= components_.size()) { return false; } - if (_components[index].type != ComponentType::Quadratic) { + if (components_[index].type != ComponentType::Quadratic) { return false; } - quadratic = _quads[_components[index].index]; + quadratic = quads_[components_[index].index]; return true; } -bool Path::cubicComponentAtIndex(size_t index, - CubicPathComponent& cubic) const { - if (index >= _components.size()) { +bool Path::GetCubicComponentAtIndex(size_t index, + CubicPathComponent& cubic) const { + if (index >= components_.size()) { return false; } - if (_components[index].type != ComponentType::Cubic) { + if (components_[index].type != ComponentType::Cubic) { return false; } - cubic = _cubics[_components[index].index]; + cubic = cubics_[components_[index].index]; return true; } -bool Path::updateLinearComponentAtIndex(size_t index, +bool Path::UpdateLinearComponentAtIndex(size_t index, const LinearPathComponent& linear) { - if (index >= _components.size()) { + if (index >= components_.size()) { return false; } - if (_components[index].type != ComponentType::Linear) { + if (components_[index].type != ComponentType::Linear) { return false; } - _linears[_components[index].index] = linear; + linears_[components_[index].index] = linear; return true; } -bool Path::updateQuadraticComponentAtIndex( +bool Path::UpdateQuadraticComponentAtIndex( size_t index, const QuadraticPathComponent& quadratic) { - if (index >= _components.size()) { + if (index >= components_.size()) { return false; } - if (_components[index].type != ComponentType::Quadratic) { + if (components_[index].type != ComponentType::Quadratic) { return false; } - _quads[_components[index].index] = quadratic; + quads_[components_[index].index] = quadratic; return true; } -bool Path::updateCubicComponentAtIndex(size_t index, +bool Path::UpdateCubicComponentAtIndex(size_t index, CubicPathComponent& cubic) { - if (index >= _components.size()) { + if (index >= components_.size()) { return false; } - if (_components[index].type != ComponentType::Cubic) { + if (components_[index].type != ComponentType::Cubic) { return false; } - _cubics[_components[index].index] = cubic; + cubics_[components_[index].index] = cubic; return true; } -void Path::smoothPoints(SmoothPointsEnumerator enumerator, - const SmoothingApproximation& approximation) const { +void Path::EnumerateSmoothPoints( + SmoothPointsEnumerator enumerator, + const SmoothingApproximation& approximation) const { if (enumerator == nullptr) { return; } - for (const auto& component : _components) { + for (const auto& component : components_) { switch (component.type) { case ComponentType::Linear: { - if (!enumerator(_linears[component.index].SmoothPoints())) { + if (!enumerator(linears_[component.index].SmoothPoints())) { return; } } break; case ComponentType::Quadratic: { - if (!enumerator(_quads[component.index].SmoothPoints(approximation))) { + if (!enumerator(quads_[component.index].SmoothPoints(approximation))) { return; } } break; case ComponentType::Cubic: { - if (!enumerator(_cubics[component.index].SmoothPoints(approximation))) { + if (!enumerator(cubics_[component.index].SmoothPoints(approximation))) { return; } } break; @@ -171,18 +173,18 @@ void Path::smoothPoints(SmoothPointsEnumerator enumerator, } } -Rect Path::boundingBox() const { +Rect Path::GetBoundingBox() const { Rect box; - for (const auto& linear : _linears) { + for (const auto& linear : linears_) { box = box.WithPoints(linear.Extrema()); } - for (const auto& quad : _quads) { + for (const auto& quad : quads_) { box = box.WithPoints(quad.Sxtrema()); } - for (const auto& cubic : _cubics) { + for (const auto& cubic : cubics_) { box = box.WithPoints(cubic.Extrema()); } diff --git a/engine/src/flutter/impeller/impeller/geometry/Path.h b/engine/src/flutter/impeller/impeller/geometry/Path.h index 8d2abcacae..66839563af 100644 --- a/engine/src/flutter/impeller/impeller/geometry/Path.h +++ b/engine/src/flutter/impeller/impeller/geometry/Path.h @@ -23,56 +23,57 @@ class Path { ~Path(); - size_t componentCount() const; + size_t GetComponentCount() const; - Path& addLinearComponent(Point p1, Point p2); + Path& AddLinearComponent(Point p1, Point p2); - Path& addQuadraticComponent(Point p1, Point cp, Point p2); + Path& AddQuadraticComponent(Point p1, Point cp, Point p2); - Path& addCubicComponent(Point p1, Point cp1, Point cp2, Point p2); + Path& AddCubicComponent(Point p1, Point cp1, Point cp2, Point p2); template using Applier = std::function; - void enumerateComponents(Applier linearApplier, + void EnumerateComponents(Applier linearApplier, Applier quadApplier, Applier cubicApplier) const; - bool linearComponentAtIndex(size_t index, LinearPathComponent& linear) const; + bool GetLinearComponentAtIndex(size_t index, + LinearPathComponent& linear) const; - bool quadraticComponentAtIndex(size_t index, - QuadraticPathComponent& quadratic) const; + bool GetQuadraticComponentAtIndex(size_t index, + QuadraticPathComponent& quadratic) const; - bool cubicComponentAtIndex(size_t index, CubicPathComponent& cubic) const; + bool GetCubicComponentAtIndex(size_t index, CubicPathComponent& cubic) const; - bool updateLinearComponentAtIndex(size_t index, + bool UpdateLinearComponentAtIndex(size_t index, const LinearPathComponent& linear); - bool updateQuadraticComponentAtIndex(size_t index, + bool UpdateQuadraticComponentAtIndex(size_t index, const QuadraticPathComponent& quadratic); - bool updateCubicComponentAtIndex(size_t index, CubicPathComponent& cubic); + bool UpdateCubicComponentAtIndex(size_t index, CubicPathComponent& cubic); using SmoothPointsEnumerator = std::function points)>; - void smoothPoints(SmoothPointsEnumerator enumerator, - const SmoothingApproximation& approximation) const; + void EnumerateSmoothPoints(SmoothPointsEnumerator enumerator, + const SmoothingApproximation& approximation) const; - Rect boundingBox() const; + Rect GetBoundingBox() const; private: struct ComponentIndexPair { - ComponentType type; - size_t index; + ComponentType type = ComponentType::Linear; + size_t index = 0; - ComponentIndexPair() : type(ComponentType::Linear), index(0) {} + ComponentIndexPair() {} ComponentIndexPair(ComponentType aType, size_t aIndex) : type(aType), index(aIndex) {} }; - std::vector _components; - std::vector _linears; - std::vector _quads; - std::vector _cubics; + std::vector components_; + std::vector linears_; + std::vector quads_; + std::vector cubics_; }; } // namespace geom diff --git a/engine/src/flutter/impeller/impeller/geometry/PathBuilder.cc b/engine/src/flutter/impeller/impeller/geometry/PathBuilder.cc index 3f85ef9dce..f2ad2a9890 100644 --- a/engine/src/flutter/impeller/impeller/geometry/PathBuilder.cc +++ b/engine/src/flutter/impeller/impeller/geometry/PathBuilder.cc @@ -30,7 +30,7 @@ PathBuilder& PathBuilder::Close() { PathBuilder& PathBuilder::LineTo(Point point, bool relative) { point = relative ? current_ + point : point; - prototype_.addLinearComponent(current_, point); + prototype_.AddLinearComponent(current_, point); current_ = point; return *this; } @@ -38,7 +38,7 @@ PathBuilder& PathBuilder::LineTo(Point point, bool relative) { PathBuilder& PathBuilder::HorizontalLineTo(double x, bool relative) { Point endpoint = relative ? Point{current_.x + x, current_.y} : Point{x, current_.y}; - prototype_.addLinearComponent(current_, endpoint); + prototype_.AddLinearComponent(current_, endpoint); current_ = endpoint; return *this; } @@ -46,7 +46,7 @@ PathBuilder& PathBuilder::HorizontalLineTo(double x, bool relative) { PathBuilder& PathBuilder::VerticalLineTo(double y, bool relative) { Point endpoint = relative ? Point{current_.x, current_.y + y} : Point{current_.x, y}; - prototype_.addLinearComponent(current_, endpoint); + prototype_.AddLinearComponent(current_, endpoint); current_ = endpoint; return *this; } @@ -56,7 +56,7 @@ PathBuilder& PathBuilder::QuadraticCurveTo(Point point, bool relative) { point = relative ? current_ + point : point; controlPoint = relative ? current_ + controlPoint : controlPoint; - prototype_.addQuadraticComponent(current_, controlPoint, point); + prototype_.AddQuadraticComponent(current_, controlPoint, point); current_ = point; return *this; } @@ -66,13 +66,13 @@ Point PathBuilder::ReflectedQuadraticControlPoint1() const { * If there is no previous command or if the previous command was not a * quadratic, assume the control point is coincident with the current point. */ - if (prototype_.componentCount() == 0) { + if (prototype_.GetComponentCount() == 0) { return current_; } QuadraticPathComponent quad; - if (!prototype_.quadraticComponentAtIndex(prototype_.componentCount() - 1, - quad)) { + if (!prototype_.GetQuadraticComponentAtIndex( + prototype_.GetComponentCount() - 1, quad)) { return current_; } @@ -100,7 +100,7 @@ PathBuilder& PathBuilder::CubicCurveTo(Point point, controlPoint1 = relative ? current_ + controlPoint1 : controlPoint1; controlPoint2 = relative ? current_ + controlPoint2 : controlPoint2; point = relative ? current_ + point : point; - prototype_.addCubicComponent(current_, controlPoint1, controlPoint2, point); + prototype_.AddCubicComponent(current_, controlPoint1, controlPoint2, point); current_ = point; return *this; } @@ -111,13 +111,13 @@ Point PathBuilder::ReflectedCubicControlPoint1() const { * cubic, assume the first control point is coincident with the current * point. */ - if (prototype_.componentCount() == 0) { + if (prototype_.GetComponentCount() == 0) { return current_; } CubicPathComponent cubic; - if (!prototype_.cubicComponentAtIndex(prototype_.componentCount() - 1, - cubic)) { + if (!prototype_.GetCubicComponentAtIndex(prototype_.GetComponentCount() - 1, + cubic)) { return current_; } @@ -151,10 +151,10 @@ PathBuilder& PathBuilder::AddRect(Rect rect) { auto bottomRight = rect.origin + Point{rect.size.width, rect.size.height}; auto topRight = rect.origin + Point{rect.size.width, 0.0}; - prototype_.addLinearComponent(topLeft, bottomLeft) - .addLinearComponent(bottomLeft, bottomRight) - .addLinearComponent(bottomRight, topRight) - .addLinearComponent(topRight, topLeft); + prototype_.AddLinearComponent(topLeft, bottomLeft) + .AddLinearComponent(bottomLeft, bottomRight) + .AddLinearComponent(bottomRight, topRight) + .AddLinearComponent(topRight, topLeft); return *this; } @@ -165,28 +165,28 @@ PathBuilder& PathBuilder::AddCircle(const Point& center, double radius) { const double diameter = radius * 2.0; const double magic = kArcApproximationMagic * radius; - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {center.x + radius, center.y}, // {center.x + radius + magic, center.y}, // {center.x + diameter, center.y + radius - magic}, // {center.x + diameter, center.y + radius} // ); - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {center.x + diameter, center.y + radius}, // {center.x + diameter, center.y + radius + magic}, // {center.x + radius + magic, center.y + diameter}, // {center.x + radius, center.y + diameter} // ); - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {center.x + radius, center.y + diameter}, // {center.x + radius - magic, center.y + diameter}, // {center.x, center.y + radius + magic}, // {center.x, center.y + radius} // ); - prototype_.addCubicComponent({center.x, center.y + radius}, // + prototype_.AddCubicComponent({center.x, center.y + radius}, // {center.x, center.y + radius - magic}, // {center.x + radius - magic, center.y}, // {center.x + radius, center.y} // @@ -211,14 +211,14 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { /* * Top line. */ - prototype_.addLinearComponent( + prototype_.AddLinearComponent( {rect.origin.x + radii.topLeft, rect.origin.y}, {rect.origin.x + rect.size.width - radii.topRight, rect.origin.y}); /* * Top right arc. */ - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {rect.origin.x + rect.size.width - radii.topRight, rect.origin.y}, {rect.origin.x + rect.size.width - radii.topRight + magicTopRight, rect.origin.y}, @@ -229,7 +229,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { /* * Right line. */ - prototype_.addLinearComponent( + prototype_.AddLinearComponent( {rect.origin.x + rect.size.width, rect.origin.y + radii.topRight}, {rect.origin.x + rect.size.width, rect.origin.y + rect.size.height - radii.bottomRight}); @@ -237,7 +237,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { /* * Bottom right arc. */ - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {rect.origin.x + rect.size.width, rect.origin.y + rect.size.height - radii.bottomRight}, {rect.origin.x + rect.size.width, @@ -250,7 +250,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { /* * Bottom line. */ - prototype_.addLinearComponent( + prototype_.AddLinearComponent( {rect.origin.x + rect.size.width - radii.bottomRight, rect.origin.y + rect.size.height}, {rect.origin.x + radii.bottomLeft, rect.origin.y + rect.size.height}); @@ -258,7 +258,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { /* * Bottom left arc. */ - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {rect.origin.x + radii.bottomLeft, rect.origin.y + rect.size.height}, {rect.origin.x + radii.bottomLeft - magicBottomLeft, rect.origin.y + rect.size.height}, @@ -269,14 +269,14 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { /* * Left line. */ - prototype_.addLinearComponent( + prototype_.AddLinearComponent( {rect.origin.x, rect.origin.y + rect.size.height - radii.bottomLeft}, {rect.origin.x, rect.origin.y + radii.topLeft}); /* * Top left arc. */ - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {rect.origin.x, rect.origin.y + radii.topLeft}, {rect.origin.x, rect.origin.y + radii.topLeft - magicTopLeft}, {rect.origin.x + radii.topLeft - magicTopLeft, rect.origin.y}, @@ -292,28 +292,28 @@ PathBuilder& PathBuilder::AddEllipse(const Point& center, const Size& radius) { const Size magic = {kArcApproximationMagic * radius.width, kArcApproximationMagic * radius.height}; - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {center.x + radius.width, center.y}, // {center.x + radius.width + magic.width, center.y}, // {center.x + diameter.width, center.y + radius.height - magic.height}, // {center.x + diameter.width, center.y + radius.height} // ); - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {center.x + diameter.width, center.y + radius.height}, // {center.x + diameter.width, center.y + radius.height + magic.height}, // {center.x + radius.width + magic.width, center.y + diameter.height}, // {center.x + radius.width, center.y + diameter.height} // ); - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {center.x + radius.width, center.y + diameter.height}, // {center.x + radius.width - magic.width, center.y + diameter.height}, // {center.x, center.y + radius.height + magic.height}, // {center.x, center.y + radius.height} // ); - prototype_.addCubicComponent( + prototype_.AddCubicComponent( {center.x, center.y + radius.height}, // {center.x, center.y + radius.height - magic.height}, // {center.x + radius.width - magic.width, center.y}, //