From c5d53e56f51fc19bbc8cc724b647ff50d72995dc Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Wed, 20 Sep 2023 13:44:25 -0700 Subject: [PATCH] Tidy up DlPaint and friends. --- display_list/dl_paint.cc | 48 ++++++++-------- display_list/dl_paint.h | 117 ++++++++++++++++++++------------------- 2 files changed, 83 insertions(+), 82 deletions(-) diff --git a/display_list/dl_paint.cc b/display_list/dl_paint.cc index 1389125d8c197..2ce1ec763277a 100644 --- a/display_list/dl_paint.cc +++ b/display_list/dl_paint.cc @@ -7,33 +7,33 @@ namespace flutter { DlPaint::DlPaint(DlColor color) - : blendMode_(static_cast(DlBlendMode::kDefaultMode)), - drawStyle_(static_cast(DlDrawStyle::kDefaultStyle)), - strokeCap_(static_cast(DlStrokeCap::kDefaultCap)), - strokeJoin_(static_cast(DlStrokeJoin::kDefaultJoin)), - isAntiAlias_(false), - isDither_(false), - isInvertColors_(false), + : blend_mode_(static_cast(DlBlendMode::kDefaultMode)), + draw_style_(static_cast(DlDrawStyle::kDefaultStyle)), + stroke_cap_(static_cast(DlStrokeCap::kDefaultCap)), + stroke_join_(static_cast(DlStrokeJoin::kDefaultJoin)), + is_anti_alias_(false), + is_dither_(false), + is_invert_colors_(false), color_(color), - strokeWidth_(kDefaultWidth), - strokeMiter_(kDefaultMiter) {} + stroke_width_(kDefaultWidth), + stroke_miter_(kDefaultMiter) {} bool DlPaint::operator==(DlPaint const& other) const { - return blendMode_ == other.blendMode_ && // - drawStyle_ == other.drawStyle_ && // - strokeCap_ == other.strokeCap_ && // - strokeJoin_ == other.strokeJoin_ && // - isAntiAlias_ == other.isAntiAlias_ && // - isDither_ == other.isDither_ && // - isInvertColors_ == other.isInvertColors_ && // - color_ == other.color_ && // - strokeWidth_ == other.strokeWidth_ && // - strokeMiter_ == other.strokeMiter_ && // - Equals(colorSource_, other.colorSource_) && // - Equals(colorFilter_, other.colorFilter_) && // - Equals(imageFilter_, other.imageFilter_) && // - Equals(maskFilter_, other.maskFilter_) && // - Equals(pathEffect_, other.pathEffect_); + return blend_mode_ == other.blend_mode_ && // + draw_style_ == other.draw_style_ && // + stroke_cap_ == other.stroke_cap_ && // + stroke_join_ == other.stroke_join_ && // + is_anti_alias_ == other.is_anti_alias_ && // + is_dither_ == other.is_dither_ && // + is_invert_colors_ == other.is_invert_colors_ && // + color_ == other.color_ && // + stroke_width_ == other.stroke_width_ && // + stroke_miter_ == other.stroke_miter_ && // + Equals(color_source_, other.color_source_) && // + Equals(color_filter_, other.color_filter_) && // + Equals(image_filter_, other.image_filter_) && // + Equals(mask_filter_, other.mask_filter_) && // + Equals(path_effect_, other.path_effect_); } const DlPaint DlPaint::kDefault; diff --git a/display_list/dl_paint.h b/display_list/dl_paint.h index 3d9220f57e3d6..e49a298fee1aa 100644 --- a/display_list/dl_paint.h +++ b/display_list/dl_paint.h @@ -6,6 +6,7 @@ #define FLUTTER_DISPLAY_LIST_DL_PAINT_H_ #include +#include #include "flutter/display_list/dl_blend_mode.h" #include "flutter/display_list/dl_color.h" #include "flutter/display_list/effects/dl_color_filter.h" @@ -52,23 +53,23 @@ class DlPaint { static const DlPaint kDefault; DlPaint() : DlPaint(DlColor::kBlack()) {} - DlPaint(DlColor color); + explicit DlPaint(DlColor color); - bool isAntiAlias() const { return isAntiAlias_; } + bool isAntiAlias() const { return is_anti_alias_; } DlPaint& setAntiAlias(bool isAntiAlias) { - isAntiAlias_ = isAntiAlias; + is_anti_alias_ = isAntiAlias; return *this; } - bool isDither() const { return isDither_; } + bool isDither() const { return is_dither_; } DlPaint& setDither(bool isDither) { - isDither_ = isDither; + is_dither_ = isDither; return *this; } - bool isInvertColors() const { return isInvertColors_; } + bool isInvertColors() const { return is_invert_colors_; } DlPaint& setInvertColors(bool isInvertColors) { - isInvertColors_ = isInvertColors; + is_invert_colors_ = isInvertColors; return *this; } @@ -90,111 +91,111 @@ class DlPaint { } DlBlendMode getBlendMode() const { - return static_cast(blendMode_); + return static_cast(blend_mode_); } DlPaint& setBlendMode(DlBlendMode mode) { - blendMode_ = static_cast(mode); + blend_mode_ = static_cast(mode); return *this; } DlDrawStyle getDrawStyle() const { - return static_cast(drawStyle_); + return static_cast(draw_style_); } DlPaint& setDrawStyle(DlDrawStyle style) { - drawStyle_ = static_cast(style); + draw_style_ = static_cast(style); return *this; } DlStrokeCap getStrokeCap() const { - return static_cast(strokeCap_); + return static_cast(stroke_cap_); } DlPaint& setStrokeCap(DlStrokeCap cap) { - strokeCap_ = static_cast(cap); + stroke_cap_ = static_cast(cap); return *this; } DlStrokeJoin getStrokeJoin() const { - return static_cast(strokeJoin_); + return static_cast(stroke_join_); } DlPaint& setStrokeJoin(DlStrokeJoin join) { - strokeJoin_ = static_cast(join); + stroke_join_ = static_cast(join); return *this; } - float getStrokeWidth() const { return strokeWidth_; } + float getStrokeWidth() const { return stroke_width_; } DlPaint& setStrokeWidth(float width) { - strokeWidth_ = width; + stroke_width_ = width; return *this; } - float getStrokeMiter() const { return strokeMiter_; } + float getStrokeMiter() const { return stroke_miter_; } DlPaint& setStrokeMiter(float miter) { - strokeMiter_ = miter; + stroke_miter_ = miter; return *this; } std::shared_ptr getColorSource() const { - return colorSource_; + return color_source_; } - const DlColorSource* getColorSourcePtr() const { return colorSource_.get(); } + const DlColorSource* getColorSourcePtr() const { return color_source_.get(); } DlPaint& setColorSource(std::shared_ptr source) { - colorSource_ = source; + color_source_ = std::move(source); return *this; } DlPaint& setColorSource(const DlColorSource* source) { - colorSource_ = source ? source->shared() : nullptr; + color_source_ = source ? source->shared() : nullptr; return *this; } std::shared_ptr getColorFilter() const { - return colorFilter_; + return color_filter_; } - const DlColorFilter* getColorFilterPtr() const { return colorFilter_.get(); } - DlPaint& setColorFilter(const std::shared_ptr filter) { - colorFilter_ = filter; + const DlColorFilter* getColorFilterPtr() const { return color_filter_.get(); } + DlPaint& setColorFilter(const std::shared_ptr& filter) { + color_filter_ = filter; return *this; } DlPaint& setColorFilter(const DlColorFilter* filter) { - colorFilter_ = filter ? filter->shared() : nullptr; + color_filter_ = filter ? filter->shared() : nullptr; return *this; } std::shared_ptr getImageFilter() const { - return imageFilter_; + return image_filter_; } - const DlImageFilter* getImageFilterPtr() const { return imageFilter_.get(); } - DlPaint& setImageFilter(const std::shared_ptr filter) { - imageFilter_ = filter; + const DlImageFilter* getImageFilterPtr() const { return image_filter_.get(); } + DlPaint& setImageFilter(const std::shared_ptr& filter) { + image_filter_ = filter; return *this; } DlPaint& setImageFilter(const DlImageFilter* filter) { - imageFilter_ = filter ? filter->shared() : nullptr; + image_filter_ = filter ? filter->shared() : nullptr; return *this; } std::shared_ptr getMaskFilter() const { - return maskFilter_; + return mask_filter_; } - const DlMaskFilter* getMaskFilterPtr() const { return maskFilter_.get(); } - DlPaint& setMaskFilter(std::shared_ptr filter) { - maskFilter_ = filter; + const DlMaskFilter* getMaskFilterPtr() const { return mask_filter_.get(); } + DlPaint& setMaskFilter(const std::shared_ptr& filter) { + mask_filter_ = filter; return *this; } DlPaint& setMaskFilter(const DlMaskFilter* filter) { - maskFilter_ = filter ? filter->shared() : nullptr; + mask_filter_ = filter ? filter->shared() : nullptr; return *this; } std::shared_ptr getPathEffect() const { - return pathEffect_; + return path_effect_; } - const DlPathEffect* getPathEffectPtr() const { return pathEffect_.get(); } - DlPaint& setPathEffect(std::shared_ptr pathEffect) { - pathEffect_ = pathEffect; + const DlPathEffect* getPathEffectPtr() const { return path_effect_.get(); } + DlPaint& setPathEffect(const std::shared_ptr& pathEffect) { + path_effect_ = pathEffect; return *this; } DlPaint& setPathEffect(const DlPathEffect* effect) { - pathEffect_ = effect ? effect->shared() : nullptr; + path_effect_ = effect ? effect->shared() : nullptr; return *this; } @@ -219,25 +220,25 @@ class DlPaint { union { struct { - unsigned blendMode_ : kBlendModeBits; - unsigned drawStyle_ : kDrawStyleBits; - unsigned strokeCap_ : kStrokeCapBits; - unsigned strokeJoin_ : kStrokeJoinBits; - unsigned isAntiAlias_ : 1; - unsigned isDither_ : 1; - unsigned isInvertColors_ : 1; + unsigned blend_mode_ : kBlendModeBits; + unsigned draw_style_ : kDrawStyleBits; + unsigned stroke_cap_ : kStrokeCapBits; + unsigned stroke_join_ : kStrokeJoinBits; + unsigned is_anti_alias_ : 1; + unsigned is_dither_ : 1; + unsigned is_invert_colors_ : 1; }; }; DlColor color_; - float strokeWidth_; - float strokeMiter_; - - std::shared_ptr colorSource_; - std::shared_ptr colorFilter_; - std::shared_ptr imageFilter_; - std::shared_ptr maskFilter_; - std::shared_ptr pathEffect_; + float stroke_width_; + float stroke_miter_; + + std::shared_ptr color_source_; + std::shared_ptr color_filter_; + std::shared_ptr image_filter_; + std::shared_ptr mask_filter_; + std::shared_ptr path_effect_; }; } // namespace flutter