Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions flow/layers/clip_path_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace flow {

ClipPathLayer::ClipPathLayer() = default;
ClipPathLayer::ClipPathLayer(ClipMode clip_mode) : clip_mode_(clip_mode) {}

ClipPathLayer::~ClipPathLayer() = default;

Expand All @@ -38,6 +38,7 @@ void ClipPathLayer::UpdateScene(SceneUpdateContext& context) {
bounds.height() // height
);

// TODO(liyuqian): respect clip_mode_
SceneUpdateContext::Clip clip(context, shape, bounds);
UpdateSceneChildren(context);
}
Expand All @@ -49,8 +50,14 @@ void ClipPathLayer::Paint(PaintContext& context) const {
FXL_DCHECK(needs_painting());

SkAutoCanvasRestore save(&context.canvas, true);
context.canvas.clipPath(clip_path_, true);
context.canvas.clipPath(clip_path_, clip_mode_ != ClipMode::hardEdge);
if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) {
context.canvas.saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);
if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) {
context.canvas.restore();
}
}

} // namespace flow
3 changes: 2 additions & 1 deletion 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();
ClipPathLayer(ClipMode clip_mode = ClipMode::antiAlias);
~ClipPathLayer() override;

void set_clip_path(const SkPath& clip_path) { clip_path_ = clip_path; }
Expand All @@ -26,6 +26,7 @@ class ClipPathLayer : public ContainerLayer {

private:
SkPath clip_path_;
ClipMode clip_mode_;

FXL_DISALLOW_COPY_AND_ASSIGN(ClipPathLayer);
};
Expand Down
11 changes: 9 additions & 2 deletions flow/layers/clip_rect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace flow {

ClipRectLayer::ClipRectLayer() = default;
ClipRectLayer::ClipRectLayer(ClipMode clip_mode) : clip_mode_(clip_mode) {}

ClipRectLayer::~ClipRectLayer() = default;

Expand All @@ -29,6 +29,7 @@ void ClipRectLayer::UpdateScene(SceneUpdateContext& context) {
clip_rect_.height() // height
);

// TODO(liyuqian): respect clip_mode_
SceneUpdateContext::Clip clip(context, shape, clip_rect_);
UpdateSceneChildren(context);
}
Expand All @@ -39,9 +40,15 @@ void ClipRectLayer::Paint(PaintContext& context) const {
TRACE_EVENT0("flutter", "ClipRectLayer::Paint");
FXL_DCHECK(needs_painting());

SkAutoCanvasRestore save(&context.canvas, true);
SkAutoCanvasRestore save(&context.canvas, clip_mode_ != ClipMode::hardEdge);
context.canvas.clipRect(paint_bounds());
if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) {
context.canvas.saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);
if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) {
context.canvas.restore();
}
}

} // namespace flow
3 changes: 2 additions & 1 deletion 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();
ClipRectLayer(ClipMode clip_mode);
~ClipRectLayer() override;

void set_clip_rect(const SkRect& clip_rect) { clip_rect_ = clip_rect; }
Expand All @@ -25,6 +25,7 @@ class ClipRectLayer : public ContainerLayer {

private:
SkRect clip_rect_;
ClipMode clip_mode_;

FXL_DISALLOW_COPY_AND_ASSIGN(ClipRectLayer);
};
Expand Down
11 changes: 9 additions & 2 deletions flow/layers/clip_rrect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace flow {

ClipRRectLayer::ClipRRectLayer() = default;
ClipRRectLayer::ClipRRectLayer(ClipMode clip_mode) : clip_mode_(clip_mode) {}

ClipRRectLayer::~ClipRRectLayer() = default;

Expand Down Expand Up @@ -36,6 +36,7 @@ void ClipRRectLayer::UpdateScene(SceneUpdateContext& context) {
clip_rrect_.radii(SkRRect::kLowerLeft_Corner).x() // bottom_left_radius
);

// TODO(liyuqian): respect clip_mode_
SceneUpdateContext::Clip clip(context, shape, clip_rrect_.getBounds());
UpdateSceneChildren(context);
}
Expand All @@ -47,8 +48,14 @@ void ClipRRectLayer::Paint(PaintContext& context) const {
FXL_DCHECK(needs_painting());

SkAutoCanvasRestore save(&context.canvas, true);
context.canvas.clipRRect(clip_rrect_, true);
context.canvas.clipRRect(clip_rrect_, clip_mode_ != ClipMode::hardEdge);
if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) {
context.canvas.saveLayer(paint_bounds(), nullptr);
}
PaintChildren(context);
if (clip_mode_ == ClipMode::antiAliasWithSaveLayer) {
context.canvas.restore();
}
}

} // namespace flow
3 changes: 2 additions & 1 deletion 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();
ClipRRectLayer(ClipMode clip_mode);
~ClipRRectLayer() override;

void set_clip_rrect(const SkRRect& clip_rrect) { clip_rrect_ = clip_rrect; }
Expand All @@ -26,6 +26,7 @@ class ClipRRectLayer : public ContainerLayer {

private:
SkRRect clip_rrect_;
ClipMode clip_mode_;

FXL_DISALLOW_COPY_AND_ASSIGN(ClipRRectLayer);
};
Expand Down
18 changes: 10 additions & 8 deletions flow/layers/default_layer_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,33 @@ void DefaultLayerBuilder::PushTransform(const SkMatrix& sk_matrix) {
PushLayer(std::move(layer), cullRect);
}

void DefaultLayerBuilder::PushClipRect(const SkRect& clipRect) {
void DefaultLayerBuilder::PushClipRect(const SkRect& clipRect, ClipMode clip_mode) {
SkRect cullRect;
if (!cullRect.intersect(clipRect, cull_rects_.top())) {
cullRect = SkRect::MakeEmpty();
}
auto layer = std::make_unique<flow::ClipRectLayer>();
auto layer = std::make_unique<flow::ClipRectLayer>(clip_mode);
layer->set_clip_rect(clipRect);
PushLayer(std::move(layer), cullRect);
}

void DefaultLayerBuilder::PushClipRoundedRect(const SkRRect& rrect) {
void DefaultLayerBuilder::PushClipRoundedRect(const SkRRect& rrect, ClipMode clip_mode) {
SkRect cullRect;
if (!cullRect.intersect(rrect.rect(), cull_rects_.top())) {
cullRect = SkRect::MakeEmpty();
}
auto layer = std::make_unique<flow::ClipRRectLayer>();
auto layer = std::make_unique<flow::ClipRRectLayer>(clip_mode);
layer->set_clip_rrect(rrect);
PushLayer(std::move(layer), cullRect);
}

void DefaultLayerBuilder::PushClipPath(const SkPath& path) {
void DefaultLayerBuilder::PushClipPath(const SkPath& path, ClipMode clip_mode) {
FXL_DCHECK(clip_mode != ClipMode::none);
SkRect cullRect;
if (!cullRect.intersect(path.getBounds(), cull_rects_.top())) {
cullRect = SkRect::MakeEmpty();
}
auto layer = std::make_unique<flow::ClipPathLayer>();
auto layer = std::make_unique<flow::ClipPathLayer>(clip_mode);
layer->set_clip_path(path);
PushLayer(std::move(layer), cullRect);
}
Expand Down Expand Up @@ -113,12 +114,13 @@ void DefaultLayerBuilder::PushPhysicalShape(const SkPath& sk_path,
double elevation,
SkColor color,
SkColor shadow_color,
SkScalar device_pixel_ratio) {
SkScalar device_pixel_ratio,
ClipMode clip_mode) {
SkRect cullRect;
if (!cullRect.intersect(sk_path.getBounds(), cull_rects_.top())) {
cullRect = SkRect::MakeEmpty();
}
auto layer = std::make_unique<flow::PhysicalShapeLayer>();
auto layer = std::make_unique<flow::PhysicalShapeLayer>(clip_mode);
layer->set_path(sk_path);
layer->set_elevation(elevation);
layer->set_color(color);
Expand Down
9 changes: 5 additions & 4 deletions flow/layers/default_layer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class DefaultLayerBuilder final : public LayerBuilder {
void PushTransform(const SkMatrix& matrix) override;

// |flow::LayerBuilder|
void PushClipRect(const SkRect& rect) override;
void PushClipRect(const SkRect& rect, ClipMode clip_mode = ClipMode::antiAlias) override;

// |flow::LayerBuilder|
void PushClipRoundedRect(const SkRRect& rect) override;
void PushClipRoundedRect(const SkRRect& rect, ClipMode clip_mode = ClipMode::antiAlias) override;

// |flow::LayerBuilder|
void PushClipPath(const SkPath& path) override;
void PushClipPath(const SkPath& path, ClipMode clip_mode = ClipMode::antiAlias) override;

// |flow::LayerBuilder|
void PushOpacity(int alpha) override;
Expand All @@ -51,7 +51,8 @@ class DefaultLayerBuilder final : public LayerBuilder {
double elevation,
SkColor color,
SkColor shadow_color,
SkScalar device_pixel_ratio) override;
SkScalar device_pixel_ratio,
ClipMode clip_mode) override;

// |flow::LayerBuilder|
void PushPerformanceOverlay(uint64_t enabled_options,
Expand Down
13 changes: 13 additions & 0 deletions flow/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@

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

class ContainerLayer;

// Represents a single composited layer. Created on the UI thread but then
Expand Down
9 changes: 5 additions & 4 deletions flow/layers/layer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class LayerBuilder {

virtual void PushTransform(const SkMatrix& matrix) = 0;

virtual void PushClipRect(const SkRect& rect) = 0;
virtual void PushClipRect(const SkRect& rect, ClipMode clip_mode = ClipMode::antiAlias) = 0;

virtual void PushClipRoundedRect(const SkRRect& rect) = 0;
virtual void PushClipRoundedRect(const SkRRect& rect, ClipMode clip_mode = ClipMode::antiAlias) = 0;

virtual void PushClipPath(const SkPath& path) = 0;
virtual void PushClipPath(const SkPath& path, ClipMode clip_mode = ClipMode::antiAlias) = 0;

virtual void PushOpacity(int alpha) = 0;

Expand All @@ -52,7 +52,8 @@ class LayerBuilder {
double elevation,
SkColor color,
SkColor shadow_color,
SkScalar device_pixel_ratio) = 0;
SkScalar device_pixel_ratio,
ClipMode clip_mode) = 0;

virtual void PushPerformanceOverlay(uint64_t enabled_options,
const SkRect& rect) = 0;
Expand Down
25 changes: 19 additions & 6 deletions flow/layers/physical_shape_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace flow {

PhysicalShapeLayer::PhysicalShapeLayer() : isRect_(false) {}
PhysicalShapeLayer::PhysicalShapeLayer(ClipMode clip_mode) : isRect_(false), clip_mode_(clip_mode) {}

PhysicalShapeLayer::~PhysicalShapeLayer() = default;

Expand Down Expand Up @@ -90,12 +90,25 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
paint.setColor(color_);
context.canvas.drawPath(path_, paint);

SkAutoCanvasRestore save(&context.canvas, false);
context.canvas.save();
context.canvas.clipPath(path_, true);
int saveCount = context.canvas.save();
switch(clip_mode_) {
case ClipMode::hardEdge:
context.canvas.clipPath(path_, false);
break;
case ClipMode::antiAlias:
context.canvas.clipPath(path_, true);
break;
case ClipMode::antiAliasWithSaveLayer:
context.canvas.clipPath(path_, true);
context.canvas.saveLayer(paint_bounds(), nullptr);
break;
case ClipMode::none:
break;
}

PaintChildren(context);
if (context.checkerboard_offscreen_layers && !isRect_)
DrawCheckerboard(&context.canvas, path_.getBounds());

context.canvas.restoreToCount(saveCount);
}

void PhysicalShapeLayer::DrawShadow(SkCanvas* canvas,
Expand Down
3 changes: 2 additions & 1 deletion 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();
PhysicalShapeLayer(ClipMode clip_mode);
~PhysicalShapeLayer() override;

void set_path(const SkPath& path);
Expand Down Expand Up @@ -44,6 +44,7 @@ class PhysicalShapeLayer : public ContainerLayer {
SkPath path_;
bool isRect_;
SkRRect frameRRect_;
ClipMode clip_mode_;
};

} // namespace flow
Expand Down
Loading