Skip to content

Commit

Permalink
Rename clip mode to clip behavior (flutter#5853)
Browse files Browse the repository at this point in the history
* Rename clip mode to clip behavior

So we're consistent across flutter/flutter and flutter/engine

* Clang format
  • Loading branch information
liyuqian authored Jul 25, 2018
1 parent 42bd86d commit f50e218
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 81 deletions.
15 changes: 8 additions & 7 deletions flow/layers/clip_path_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/clip_path_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -26,7 +26,7 @@ class ClipPathLayer : public ContainerLayer {

private:
SkPath clip_path_;
ClipMode clip_mode_;
Clip clip_behavior_;

FXL_DISALLOW_COPY_AND_ASSIGN(ClipPathLayer);
};
Expand Down
15 changes: 8 additions & 7 deletions flow/layers/clip_rect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/clip_rect_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -25,7 +25,7 @@ class ClipRectLayer : public ContainerLayer {

private:
SkRect clip_rect_;
ClipMode clip_mode_;
Clip clip_behavior_;

FXL_DISALLOW_COPY_AND_ASSIGN(ClipRectLayer);
};
Expand Down
11 changes: 6 additions & 5 deletions flow/layers/clip_rrect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/clip_rrect_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -26,7 +26,7 @@ class ClipRRectLayer : public ContainerLayer {

private:
SkRRect clip_rrect_;
ClipMode clip_mode_;
Clip clip_behavior_;

FXL_DISALLOW_COPY_AND_ASSIGN(ClipRRectLayer);
};
Expand Down
22 changes: 12 additions & 10 deletions flow/layers/default_layer_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions flow/layers/default_layer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
16 changes: 3 additions & 13 deletions flow/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 7 additions & 4 deletions flow/layers/layer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
24 changes: 13 additions & 11 deletions flow/layers/physical_shape_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions flow/layers/physical_shape_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -44,7 +44,7 @@ class PhysicalShapeLayer : public ContainerLayer {
SkPath path_;
bool isRect_;
SkRRect frameRRect_;
ClipMode clip_mode_;
Clip clip_behavior_;
};

} // namespace flow
Expand Down
Loading

0 comments on commit f50e218

Please sign in to comment.