Skip to content

[Unblock Lint Headers] Make DlColor(uint32_t argb) explicit #135057

@matanlurey

Description

@matanlurey

Blocks #134969.

I'm requesting help if anyone could use a simple~ish task to work on in the background.


The work required is roughly the following:

--- a/display_list/dl_color.h
+++ b/display_list/dl_color.h
@@ -12,7 +12,7 @@ namespace flutter {
 struct DlColor {
  public:
   constexpr DlColor() : argb(0xFF000000) {}
-  constexpr DlColor(uint32_t argb) : argb(argb) {}
+  constexpr explicit DlColor(uint32_t argb) : argb(argb) {}
 
   static constexpr uint8_t toAlpha(SkScalar opacity) { return toC(opacity); }
   static constexpr SkScalar toOpacity(uint8_t alpha) { return toF(alpha); }
@@ -77,7 +77,7 @@ struct DlColor {
                           : withAlpha(round(getAlpha() * opacity));
   }
 
-  operator uint32_t() const { return argb; }
+  explicit operator uint32_t() const { return argb; }
   bool operator==(DlColor const& other) const { return argb == other.argb; }
   bool operator!=(DlColor const& other) const { return argb != other.argb; }
   bool operator==(uint32_t const& other) const { return argb == other; }

... and then changing the rest of the repository to use DlColor(int_color) explicitly.

For going the other way, i.e. DlColor -> uint32_t(), I'd probably recommend just deleting the operator above, and adding into dl_sk_conversions something like:

inline SkColor ToSk(DlColor color) {
  return static_cast<SkColor>(color);
}

... for consistency.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: tech-debtTechnical debt, code quality, testing, etc.engineflutter/engine related. See also e: labels.team-engineOwned by Engine team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions