From 2c526e8068ebb3f5a725d0797c17c513840685e0 Mon Sep 17 00:00:00 2001 From: liyuqian Date: Wed, 25 Jul 2018 09:57:10 -0700 Subject: [PATCH] Rename clip mode to clip behavior (flutter/engine#5853) * Rename clip mode to clip behavior So we're consistent across flutter/flutter and flutter/engine * Clang format --- .../flutter/flow/layers/clip_path_layer.cc | 15 ++++++------ .../src/flutter/flow/layers/clip_path_layer.h | 4 ++-- .../flutter/flow/layers/clip_rect_layer.cc | 15 ++++++------ .../src/flutter/flow/layers/clip_rect_layer.h | 4 ++-- .../flutter/flow/layers/clip_rrect_layer.cc | 11 +++++---- .../flutter/flow/layers/clip_rrect_layer.h | 4 ++-- .../flow/layers/default_layer_builder.cc | 22 +++++++++-------- .../flow/layers/default_layer_builder.h | 11 +++++---- engine/src/flutter/flow/layers/layer.h | 16 +++---------- .../src/flutter/flow/layers/layer_builder.h | 11 +++++---- .../flow/layers/physical_shape_layer.cc | 24 ++++++++++--------- .../flow/layers/physical_shape_layer.h | 4 ++-- .../lib/ui/compositing/scene_builder.cc | 16 ++++++------- .../lib/ui/compositing/scene_builder.h | 8 +++---- 14 files changed, 84 insertions(+), 81 deletions(-) diff --git a/engine/src/flutter/flow/layers/clip_path_layer.cc b/engine/src/flutter/flow/layers/clip_path_layer.cc index d6c091ee15..5a234aa5ee 100644 --- a/engine/src/flutter/flow/layers/clip_path_layer.cc +++ b/engine/src/flutter/flow/layers/clip_path_layer.cc @@ -12,7 +12,8 @@ namespace flow { -ClipPathLayer::ClipPathLayer(ClipMode clip_mode) : clip_mode_(clip_mode) {} +ClipPathLayer::ClipPathLayer(Clip clip_behavior) + : clip_behavior_(clip_behavior) {} ClipPathLayer::~ClipPathLayer() = default; @@ -34,11 +35,11 @@ void ClipPathLayer::UpdateScene(SceneUpdateContext& context) { // Treating the shape as a rectangle for now. auto bounds = clip_path_.getBounds(); scenic::Rectangle shape(context.session(), // session - bounds.width(), // width - bounds.height() // height + bounds.width(), // width + bounds.height() // height ); - // TODO(liyuqian): respect clip_mode_ + // TODO(liyuqian): respect clip_behavior_ SceneUpdateContext::Clip clip(context, shape, bounds); UpdateSceneChildren(context); } @@ -50,12 +51,12 @@ void ClipPathLayer::Paint(PaintContext& context) const { FXL_DCHECK(needs_painting()); SkAutoCanvasRestore save(&context.canvas, true); - context.canvas.clipPath(clip_path_, clip_mode_ != ClipMode::hardEdge); - if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) { + context.canvas.clipPath(clip_path_, clip_behavior_ != Clip::hardEdge); + if (clip_behavior_ == Clip::antiAliasWithSaveLayer) { context.canvas.saveLayer(paint_bounds(), nullptr); } PaintChildren(context); - if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) { + if (clip_behavior_ == Clip::antiAliasWithSaveLayer) { context.canvas.restore(); } } diff --git a/engine/src/flutter/flow/layers/clip_path_layer.h b/engine/src/flutter/flow/layers/clip_path_layer.h index 78017144ed..818285af8d 100644 --- a/engine/src/flutter/flow/layers/clip_path_layer.h +++ b/engine/src/flutter/flow/layers/clip_path_layer.h @@ -11,7 +11,7 @@ namespace flow { class ClipPathLayer : public ContainerLayer { public: - ClipPathLayer(ClipMode clip_mode = ClipMode::antiAlias); + ClipPathLayer(Clip clip_behavior = Clip::antiAlias); ~ClipPathLayer() override; void set_clip_path(const SkPath& clip_path) { clip_path_ = clip_path; } @@ -26,7 +26,7 @@ class ClipPathLayer : public ContainerLayer { private: SkPath clip_path_; - ClipMode clip_mode_; + Clip clip_behavior_; FXL_DISALLOW_COPY_AND_ASSIGN(ClipPathLayer); }; diff --git a/engine/src/flutter/flow/layers/clip_rect_layer.cc b/engine/src/flutter/flow/layers/clip_rect_layer.cc index 0fca7ab821..6f345678f8 100644 --- a/engine/src/flutter/flow/layers/clip_rect_layer.cc +++ b/engine/src/flutter/flow/layers/clip_rect_layer.cc @@ -6,7 +6,8 @@ namespace flow { -ClipRectLayer::ClipRectLayer(ClipMode clip_mode) : clip_mode_(clip_mode) {} +ClipRectLayer::ClipRectLayer(Clip clip_behavior) + : clip_behavior_(clip_behavior) {} ClipRectLayer::~ClipRectLayer() = default; @@ -25,11 +26,11 @@ void ClipRectLayer::UpdateScene(SceneUpdateContext& context) { FXL_DCHECK(needs_system_composite()); scenic::Rectangle shape(context.session(), // session - clip_rect_.width(), // width - clip_rect_.height() // height + clip_rect_.width(), // width + clip_rect_.height() // height ); - // TODO(liyuqian): respect clip_mode_ + // TODO(liyuqian): respect clip_behavior_ SceneUpdateContext::Clip clip(context, shape, clip_rect_); UpdateSceneChildren(context); } @@ -40,13 +41,13 @@ void ClipRectLayer::Paint(PaintContext& context) const { TRACE_EVENT0("flutter", "ClipRectLayer::Paint"); FXL_DCHECK(needs_painting()); - SkAutoCanvasRestore save(&context.canvas, clip_mode_ != ClipMode::hardEdge); + SkAutoCanvasRestore save(&context.canvas, clip_behavior_ != Clip::hardEdge); context.canvas.clipRect(paint_bounds()); - if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) { + if (clip_behavior_ == Clip::antiAliasWithSaveLayer) { context.canvas.saveLayer(paint_bounds(), nullptr); } PaintChildren(context); - if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) { + if (clip_behavior_ == Clip::antiAliasWithSaveLayer) { context.canvas.restore(); } } diff --git a/engine/src/flutter/flow/layers/clip_rect_layer.h b/engine/src/flutter/flow/layers/clip_rect_layer.h index 6e50856359..0744076ec4 100644 --- a/engine/src/flutter/flow/layers/clip_rect_layer.h +++ b/engine/src/flutter/flow/layers/clip_rect_layer.h @@ -11,7 +11,7 @@ namespace flow { class ClipRectLayer : public ContainerLayer { public: - ClipRectLayer(ClipMode clip_mode); + ClipRectLayer(Clip clip_behavior); ~ClipRectLayer() override; void set_clip_rect(const SkRect& clip_rect) { clip_rect_ = clip_rect; } @@ -25,7 +25,7 @@ class ClipRectLayer : public ContainerLayer { private: SkRect clip_rect_; - ClipMode clip_mode_; + Clip clip_behavior_; FXL_DISALLOW_COPY_AND_ASSIGN(ClipRectLayer); }; diff --git a/engine/src/flutter/flow/layers/clip_rrect_layer.cc b/engine/src/flutter/flow/layers/clip_rrect_layer.cc index 0a7ce3864a..d21ce637f7 100644 --- a/engine/src/flutter/flow/layers/clip_rrect_layer.cc +++ b/engine/src/flutter/flow/layers/clip_rrect_layer.cc @@ -6,7 +6,8 @@ namespace flow { -ClipRRectLayer::ClipRRectLayer(ClipMode clip_mode) : clip_mode_(clip_mode) {} +ClipRRectLayer::ClipRRectLayer(Clip clip_behavior) + : clip_behavior_(clip_behavior) {} ClipRRectLayer::~ClipRRectLayer() = default; @@ -36,7 +37,7 @@ void ClipRRectLayer::UpdateScene(SceneUpdateContext& context) { clip_rrect_.radii(SkRRect::kLowerLeft_Corner).x() // bottom_left_radius ); - // TODO(liyuqian): respect clip_mode_ + // TODO(liyuqian): respect clip_behavior_ SceneUpdateContext::Clip clip(context, shape, clip_rrect_.getBounds()); UpdateSceneChildren(context); } @@ -48,12 +49,12 @@ void ClipRRectLayer::Paint(PaintContext& context) const { FXL_DCHECK(needs_painting()); SkAutoCanvasRestore save(&context.canvas, true); - context.canvas.clipRRect(clip_rrect_, clip_mode_ != ClipMode::hardEdge); - if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) { + context.canvas.clipRRect(clip_rrect_, clip_behavior_ != Clip::hardEdge); + if (clip_behavior_ == Clip::antiAliasWithSaveLayer) { context.canvas.saveLayer(paint_bounds(), nullptr); } PaintChildren(context); - if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) { + if (clip_behavior_ == Clip::antiAliasWithSaveLayer) { context.canvas.restore(); } } diff --git a/engine/src/flutter/flow/layers/clip_rrect_layer.h b/engine/src/flutter/flow/layers/clip_rrect_layer.h index 24c7badf9b..7888a15ef8 100644 --- a/engine/src/flutter/flow/layers/clip_rrect_layer.h +++ b/engine/src/flutter/flow/layers/clip_rrect_layer.h @@ -11,7 +11,7 @@ namespace flow { class ClipRRectLayer : public ContainerLayer { public: - ClipRRectLayer(ClipMode clip_mode); + ClipRRectLayer(Clip clip_behavior); ~ClipRRectLayer() override; void set_clip_rrect(const SkRRect& clip_rrect) { clip_rrect_ = clip_rrect; } @@ -26,7 +26,7 @@ class ClipRRectLayer : public ContainerLayer { private: SkRRect clip_rrect_; - ClipMode clip_mode_; + Clip clip_behavior_; FXL_DISALLOW_COPY_AND_ASSIGN(ClipRRectLayer); }; diff --git a/engine/src/flutter/flow/layers/default_layer_builder.cc b/engine/src/flutter/flow/layers/default_layer_builder.cc index c17f77cc14..031bf24d9b 100644 --- a/engine/src/flutter/flow/layers/default_layer_builder.cc +++ b/engine/src/flutter/flow/layers/default_layer_builder.cc @@ -26,7 +26,7 @@ namespace flow { -static const SkRect kGiantRect = SkRect::MakeLTRB( -1E9F, -1E9F, 1E9F, 1E9F ); +static const SkRect kGiantRect = SkRect::MakeLTRB(-1E9F, -1E9F, 1E9F, 1E9F); DefaultLayerBuilder::DefaultLayerBuilder() { cull_rects_.push(kGiantRect); @@ -49,33 +49,35 @@ void DefaultLayerBuilder::PushTransform(const SkMatrix& sk_matrix) { PushLayer(std::move(layer), cullRect); } -void DefaultLayerBuilder::PushClipRect(const SkRect& clipRect, ClipMode clip_mode) { +void DefaultLayerBuilder::PushClipRect(const SkRect& clipRect, + Clip clip_behavior) { SkRect cullRect; if (!cullRect.intersect(clipRect, cull_rects_.top())) { cullRect = SkRect::MakeEmpty(); } - auto layer = std::make_unique(clip_mode); + auto layer = std::make_unique(clip_behavior); layer->set_clip_rect(clipRect); PushLayer(std::move(layer), cullRect); } -void DefaultLayerBuilder::PushClipRoundedRect(const SkRRect& rrect, ClipMode clip_mode) { +void DefaultLayerBuilder::PushClipRoundedRect(const SkRRect& rrect, + Clip clip_behavior) { SkRect cullRect; if (!cullRect.intersect(rrect.rect(), cull_rects_.top())) { cullRect = SkRect::MakeEmpty(); } - auto layer = std::make_unique(clip_mode); + auto layer = std::make_unique(clip_behavior); layer->set_clip_rrect(rrect); PushLayer(std::move(layer), cullRect); } -void DefaultLayerBuilder::PushClipPath(const SkPath& path, ClipMode clip_mode) { - FXL_DCHECK(clip_mode != ClipMode::none); +void DefaultLayerBuilder::PushClipPath(const SkPath& path, Clip clip_behavior) { + FXL_DCHECK(clip_behavior != Clip::none); SkRect cullRect; if (!cullRect.intersect(path.getBounds(), cull_rects_.top())) { cullRect = SkRect::MakeEmpty(); } - auto layer = std::make_unique(clip_mode); + auto layer = std::make_unique(clip_behavior); layer->set_clip_path(path); PushLayer(std::move(layer), cullRect); } @@ -115,12 +117,12 @@ void DefaultLayerBuilder::PushPhysicalShape(const SkPath& sk_path, SkColor color, SkColor shadow_color, SkScalar device_pixel_ratio, - ClipMode clip_mode) { + Clip clip_behavior) { SkRect cullRect; if (!cullRect.intersect(sk_path.getBounds(), cull_rects_.top())) { cullRect = SkRect::MakeEmpty(); } - auto layer = std::make_unique(clip_mode); + auto layer = std::make_unique(clip_behavior); layer->set_path(sk_path); layer->set_elevation(elevation); layer->set_color(color); diff --git a/engine/src/flutter/flow/layers/default_layer_builder.h b/engine/src/flutter/flow/layers/default_layer_builder.h index 267eaad83f..d5a2643a5a 100644 --- a/engine/src/flutter/flow/layers/default_layer_builder.h +++ b/engine/src/flutter/flow/layers/default_layer_builder.h @@ -24,13 +24,16 @@ class DefaultLayerBuilder final : public LayerBuilder { void PushTransform(const SkMatrix& matrix) override; // |flow::LayerBuilder| - void PushClipRect(const SkRect& rect, ClipMode clip_mode = ClipMode::antiAlias) override; + void PushClipRect(const SkRect& rect, + Clip clip_behavior = Clip::antiAlias) override; // |flow::LayerBuilder| - void PushClipRoundedRect(const SkRRect& rect, ClipMode clip_mode = ClipMode::antiAlias) override; + void PushClipRoundedRect(const SkRRect& rect, + Clip clip_behavior = Clip::antiAlias) override; // |flow::LayerBuilder| - void PushClipPath(const SkPath& path, ClipMode clip_mode = ClipMode::antiAlias) override; + void PushClipPath(const SkPath& path, + Clip clip_behavior = Clip::antiAlias) override; // |flow::LayerBuilder| void PushOpacity(int alpha) override; @@ -52,7 +55,7 @@ class DefaultLayerBuilder final : public LayerBuilder { SkColor color, SkColor shadow_color, SkScalar device_pixel_ratio, - ClipMode clip_mode) override; + Clip clip_behavior) override; // |flow::LayerBuilder| void PushPerformanceOverlay(uint64_t enabled_options, diff --git a/engine/src/flutter/flow/layers/layer.h b/engine/src/flutter/flow/layers/layer.h index 464787ebda..06ea2b2e67 100644 --- a/engine/src/flutter/flow/layers/layer.h +++ b/engine/src/flutter/flow/layers/layer.h @@ -27,25 +27,15 @@ #if defined(OS_FUCHSIA) #include "flutter/flow/scene_update_context.h" //nogncheck -#include "lib/ui/scenic/cpp/resources.h" //nogncheck -#include "lib/ui/scenic/cpp/session.h" //nogncheck +#include "lib/ui/scenic/cpp/resources.h" //nogncheck +#include "lib/ui/scenic/cpp/session.h" //nogncheck #endif // defined(OS_FUCHSIA) namespace flow { // This should be an exact copy of the Clip enum in painting.dart. -// -// We call it Clip in public Dart API to provide our developers the shortest -// name and the best experience. We call it ClipMode in C++ because we want to -// avoid name conflicts and refactoring C++ names without a nice IDE function -// is tedious. -enum ClipMode { - none, - hardEdge, - antiAlias, - antiAliasWithSaveLayer -}; +enum Clip { none, hardEdge, antiAlias, antiAliasWithSaveLayer }; class ContainerLayer; diff --git a/engine/src/flutter/flow/layers/layer_builder.h b/engine/src/flutter/flow/layers/layer_builder.h index 93195b0364..3cb6ea1fb4 100644 --- a/engine/src/flutter/flow/layers/layer_builder.h +++ b/engine/src/flutter/flow/layers/layer_builder.h @@ -32,11 +32,14 @@ class LayerBuilder { virtual void PushTransform(const SkMatrix& matrix) = 0; - virtual void PushClipRect(const SkRect& rect, ClipMode clip_mode = ClipMode::antiAlias) = 0; + virtual void PushClipRect(const SkRect& rect, + Clip clip_behavior = Clip::antiAlias) = 0; - virtual void PushClipRoundedRect(const SkRRect& rect, ClipMode clip_mode = ClipMode::antiAlias) = 0; + virtual void PushClipRoundedRect(const SkRRect& rect, + Clip clip_behavior = Clip::antiAlias) = 0; - virtual void PushClipPath(const SkPath& path, ClipMode clip_mode = ClipMode::antiAlias) = 0; + virtual void PushClipPath(const SkPath& path, + Clip clip_behavior = Clip::antiAlias) = 0; virtual void PushOpacity(int alpha) = 0; @@ -53,7 +56,7 @@ class LayerBuilder { SkColor color, SkColor shadow_color, SkScalar device_pixel_ratio, - ClipMode clip_mode) = 0; + Clip clip_behavior) = 0; virtual void PushPerformanceOverlay(uint64_t enabled_options, const SkRect& rect) = 0; diff --git a/engine/src/flutter/flow/layers/physical_shape_layer.cc b/engine/src/flutter/flow/layers/physical_shape_layer.cc index a60b38dc5e..8f9e59d6f1 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer.cc +++ b/engine/src/flutter/flow/layers/physical_shape_layer.cc @@ -9,7 +9,8 @@ namespace flow { -PhysicalShapeLayer::PhysicalShapeLayer(ClipMode clip_mode) : isRect_(false), clip_mode_(clip_mode) {} +PhysicalShapeLayer::PhysicalShapeLayer(Clip clip_behavior) + : isRect_(false), clip_behavior_(clip_behavior) {} PhysicalShapeLayer::~PhysicalShapeLayer() = default; @@ -91,18 +92,18 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const { context.canvas.drawPath(path_, paint); int saveCount = context.canvas.save(); - switch(clip_mode_) { - case ClipMode::hardEdge: + switch (clip_behavior_) { + case Clip::hardEdge: context.canvas.clipPath(path_, false); break; - case ClipMode::antiAlias: + case Clip::antiAlias: context.canvas.clipPath(path_, true); break; - case ClipMode::antiAliasWithSaveLayer: + case Clip::antiAliasWithSaveLayer: context.canvas.clipPath(path_, true); context.canvas.saveLayer(paint_bounds(), nullptr); break; - case ClipMode::none: + case Clip::none: break; } @@ -131,11 +132,12 @@ void PhysicalShapeLayer::DrawShadow(SkCanvas* canvas, SkColor inAmbient = SkColorSetA(color, kAmbientAlpha * SkColorGetA(color)); SkColor inSpot = SkColorSetA(color, kSpotAlpha * SkColorGetA(color)); SkColor ambientColor, spotColor; - SkShadowUtils::ComputeTonalColors(inAmbient, inSpot, - &ambientColor, &spotColor); - SkShadowUtils::DrawShadow(canvas, path, SkPoint3::Make(0, 0, dpr * elevation), - SkPoint3::Make(shadow_x, shadow_y, dpr * kLightHeight), - dpr * kLightRadius, ambientColor, spotColor, flags); + SkShadowUtils::ComputeTonalColors(inAmbient, inSpot, &ambientColor, + &spotColor); + SkShadowUtils::DrawShadow( + canvas, path, SkPoint3::Make(0, 0, dpr * elevation), + SkPoint3::Make(shadow_x, shadow_y, dpr * kLightHeight), + dpr * kLightRadius, ambientColor, spotColor, flags); } } // namespace flow diff --git a/engine/src/flutter/flow/layers/physical_shape_layer.h b/engine/src/flutter/flow/layers/physical_shape_layer.h index 9ed4e3a50e..344656c662 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer.h +++ b/engine/src/flutter/flow/layers/physical_shape_layer.h @@ -11,7 +11,7 @@ namespace flow { class PhysicalShapeLayer : public ContainerLayer { public: - PhysicalShapeLayer(ClipMode clip_mode); + PhysicalShapeLayer(Clip clip_behavior); ~PhysicalShapeLayer() override; void set_path(const SkPath& path); @@ -44,7 +44,7 @@ class PhysicalShapeLayer : public ContainerLayer { SkPath path_; bool isRect_; SkRRect frameRRect_; - ClipMode clip_mode_; + Clip clip_behavior_; }; } // namespace flow diff --git a/engine/src/flutter/lib/ui/compositing/scene_builder.cc b/engine/src/flutter/lib/ui/compositing/scene_builder.cc index f10690b5b3..543b397597 100644 --- a/engine/src/flutter/lib/ui/compositing/scene_builder.cc +++ b/engine/src/flutter/lib/ui/compositing/scene_builder.cc @@ -63,19 +63,19 @@ void SceneBuilder::pushClipRect(double left, double right, double top, double bottom, - int clipMode) { + int clipBehavior) { layer_builder_->PushClipRect(SkRect::MakeLTRB(left, top, right, bottom), - static_cast(clipMode)); + static_cast(clipBehavior)); } -void SceneBuilder::pushClipRRect(const RRect& rrect, int clipMode) { +void SceneBuilder::pushClipRRect(const RRect& rrect, int clipBehavior) { layer_builder_->PushClipRoundedRect(rrect.sk_rrect, - static_cast(clipMode)); + static_cast(clipBehavior)); } -void SceneBuilder::pushClipPath(const CanvasPath* path, int clipMode) { +void SceneBuilder::pushClipPath(const CanvasPath* path, int clipBehavior) { layer_builder_->PushClipPath(path->path(), - static_cast(clipMode)); + static_cast(clipBehavior)); } void SceneBuilder::pushOpacity(int alpha) { @@ -108,14 +108,14 @@ void SceneBuilder::pushPhysicalShape(const CanvasPath* path, double elevation, int color, int shadow_color, - int clip_mode) { + int clip_behavior) { layer_builder_->PushPhysicalShape( path->path(), // elevation, // static_cast(color), // static_cast(shadow_color), UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio, - static_cast(clip_mode)); + static_cast(clip_behavior)); } void SceneBuilder::pop() { diff --git a/engine/src/flutter/lib/ui/compositing/scene_builder.h b/engine/src/flutter/lib/ui/compositing/scene_builder.h index b26dbf6803..081396425a 100644 --- a/engine/src/flutter/lib/ui/compositing/scene_builder.h +++ b/engine/src/flutter/lib/ui/compositing/scene_builder.h @@ -38,9 +38,9 @@ class SceneBuilder : public RefCountedDartWrappable { double right, double top, double bottom, - int clipMode); - void pushClipRRect(const RRect& rrect, int clipMode); - void pushClipPath(const CanvasPath* path, int clipMode); + int clipBehavior); + void pushClipRRect(const RRect& rrect, int clipBehavior); + void pushClipPath(const CanvasPath* path, int clipBehavior); void pushOpacity(int alpha); void pushColorFilter(int color, int blendMode); void pushBackdropFilter(ImageFilter* filter); @@ -54,7 +54,7 @@ class SceneBuilder : public RefCountedDartWrappable { double elevation, int color, int shadowColor, - int clipMode); + int clipBehavior); void pop();