From b86da443de78a9c7f8b93ae6597d5938533f1c45 Mon Sep 17 00:00:00 2001 From: amirh Date: Mon, 22 Jan 2018 12:15:24 -0800 Subject: [PATCH] Explicitly check if the shape layer is an oval. (flutter/engine#4577) isRRect returns false for RRects that are oval. Fixes flutter/flutter#14186 --- .../flow/layers/physical_shape_layer.cc | 24 +++++++++++++++++++ .../flow/layers/physical_shape_layer.h | 20 +--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/flow/layers/physical_shape_layer.cc b/engine/src/flutter/flow/layers/physical_shape_layer.cc index d4bc69d56f..d1ea5ac9e6 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer.cc +++ b/engine/src/flutter/flow/layers/physical_shape_layer.cc @@ -13,6 +13,30 @@ PhysicalShapeLayer::PhysicalShapeLayer() : isRect_(false) {} PhysicalShapeLayer::~PhysicalShapeLayer() = default; +void PhysicalShapeLayer::set_path(const SkPath& path) { + path_ = path; + isRect_ = false; + SkRect rect; + if (path.isRect(&rect)) { + isRect_ = true; + frameRRect_ = SkRRect::MakeRect(rect); + } else if (path.isRRect(&frameRRect_)) { + isRect_ = frameRRect_.isRect(); + } else if (path.isOval(&rect)) { + // isRRect returns false for ovals, so we need to explicitly check isOval + // as well. + frameRRect_ = SkRRect::MakeOval(rect); + } else { + // Scenic currently doesn't provide an easy way to create shapes from + // arbitrary paths. + // For shapes that cannot be represented as a rounded rectangle we + // default to use the bounding rectangle. + // TODO(amirh): fix this once we have a way to create a Scenic shape from + // an SkPath. + frameRRect_ = SkRRect::MakeRect(path.getBounds()); + } +} + void PhysicalShapeLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { SkRect child_paint_bounds; diff --git a/engine/src/flutter/flow/layers/physical_shape_layer.h b/engine/src/flutter/flow/layers/physical_shape_layer.h index d4c0350797..1976c77b09 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer.h +++ b/engine/src/flutter/flow/layers/physical_shape_layer.h @@ -14,25 +14,7 @@ class PhysicalShapeLayer : public ContainerLayer { PhysicalShapeLayer(); ~PhysicalShapeLayer() override; - void set_path(const SkPath& path) { - path_ = path; - isRect_ = false; - SkRect rect; - if (path.isRect(&rect)) { - isRect_ = true; - frameRRect_ = SkRRect::MakeRect(rect); - } else if (path.isRRect(&frameRRect_)) { - isRect_ = frameRRect_.isRect(); - } else { - // Scenic currently doesn't provide an easy way to create shapes from - // arbitrary paths. - // For shapes that cannot be represented as a rounded rectangle we - // default to use the bounding rectangle. - // TODO(amirh): fix this once we have a way to create a Scenic shape from - // an SkPath. - frameRRect_ = SkRRect::MakeRect(path.getBounds()); - } - } + void set_path(const SkPath& path); void set_elevation(float elevation) { elevation_ = elevation; } void set_color(SkColor color) { color_ = color; }