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
This commit is contained in:
liyuqian
2018-07-25 09:57:10 -07:00
committed by GitHub
parent b2d92b2c9f
commit 2c526e8068
14 changed files with 84 additions and 81 deletions

View File

@@ -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();
}
}

View File

@@ -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);
};

View File

@@ -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();
}
}

View File

@@ -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);
};

View File

@@ -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();
}
}

View File

@@ -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);
};

View File

@@ -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<flow::ClipRectLayer>(clip_mode);
auto layer = std::make_unique<flow::ClipRectLayer>(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<flow::ClipRRectLayer>(clip_mode);
auto layer = std::make_unique<flow::ClipRRectLayer>(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<flow::ClipPathLayer>(clip_mode);
auto layer = std::make_unique<flow::ClipPathLayer>(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<flow::PhysicalShapeLayer>(clip_mode);
auto layer = std::make_unique<flow::PhysicalShapeLayer>(clip_behavior);
layer->set_path(sk_path);
layer->set_elevation(elevation);
layer->set_color(color);

View File

@@ -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,

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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<flow::ClipMode>(clipMode));
static_cast<flow::Clip>(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<flow::ClipMode>(clipMode));
static_cast<flow::Clip>(clipBehavior));
}
void SceneBuilder::pushClipPath(const CanvasPath* path, int clipMode) {
void SceneBuilder::pushClipPath(const CanvasPath* path, int clipBehavior) {
layer_builder_->PushClipPath(path->path(),
static_cast<flow::ClipMode>(clipMode));
static_cast<flow::Clip>(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<SkColor>(color), //
static_cast<SkColor>(shadow_color),
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio,
static_cast<flow::ClipMode>(clip_mode));
static_cast<flow::Clip>(clip_behavior));
}
void SceneBuilder::pop() {

View File

@@ -38,9 +38,9 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
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<SceneBuilder> {
double elevation,
int color,
int shadowColor,
int clipMode);
int clipBehavior);
void pop();