diff --git a/display_list/geometry/dl_geometry_types.h b/display_list/geometry/dl_geometry_types.h index 0021a2b90964d..6ee6c38385c36 100644 --- a/display_list/geometry/dl_geometry_types.h +++ b/display_list/geometry/dl_geometry_types.h @@ -42,6 +42,7 @@ static_assert(sizeof(SkIRect) == sizeof(DlIRect)); static_assert(sizeof(SkVector) == sizeof(DlSize)); static constexpr DlScalar kEhCloseEnough = impeller::kEhCloseEnough; +static constexpr DlScalar kPi = impeller::kPi; constexpr inline bool DlScalarNearlyZero(DlScalar x, DlScalar tolerance = kEhCloseEnough) { @@ -142,6 +143,11 @@ inline const SkIRect& ToSkIRect(const DlIRect& rect) { return *reinterpret_cast(&rect); } +inline std::optional ToOptSkIRect( + std::optional rect) { + return rect.has_value() ? std::optional(ToSkIRect(*rect)) : std::nullopt; +} + inline const SkRect* ToSkRect(const DlRect* rect) { return rect == nullptr ? nullptr : reinterpret_cast(rect); } @@ -158,6 +164,10 @@ inline const SkRect* ToSkRects(const DlRect* rects) { return rects == nullptr ? nullptr : reinterpret_cast(rects); } +inline const SkSize& ToSkSize(const DlSize& size) { + return *reinterpret_cast(&size); +} + inline const SkISize& ToSkISize(const DlISize& size) { return *reinterpret_cast(&size); } diff --git a/display_list/geometry/dl_path.cc b/display_list/geometry/dl_path.cc index e0d708999560d..bd0a83bf1bb55 100644 --- a/display_list/geometry/dl_path.cc +++ b/display_list/geometry/dl_path.cc @@ -10,6 +10,35 @@ namespace flutter { +DlPath DlPath::MakeRect(DlRect rect) { + return DlPath(SkPath::Rect(ToSkRect(rect))); +} + +DlPath DlPath::MakeRectLTRB(DlScalar left, + DlScalar top, + DlScalar right, + DlScalar bottom) { + return DlPath(SkPath().addRect(left, top, right, bottom)); +} + +DlPath DlPath::MakeRectXYWH(DlScalar x, + DlScalar y, + DlScalar width, + DlScalar height) { + return DlPath(SkPath().addRect(SkRect::MakeXYWH(x, y, width, height))); +} + +DlPath DlPath::MakeOval(DlRect bounds) { + return DlPath(SkPath::Oval(ToSkRect(bounds))); +} + +DlPath DlPath::MakeOvalLTRB(DlScalar left, + DlScalar top, + DlScalar right, + DlScalar bottom) { + return DlPath(SkPath::Oval(SkRect::MakeLTRB(left, top, right, bottom))); +} + const SkPath& DlPath::GetSkPath() const { return data_->sk_path; } @@ -76,6 +105,12 @@ bool DlPath::IsVolatile() const { return data_->sk_path.isVolatile(); } +DlPath DlPath::operator+(const DlPath& other) const { + SkPath path = data_->sk_path; + path.addPath(other.data_->sk_path); + return DlPath(path); +} + using Path = impeller::Path; using PathBuilder = impeller::PathBuilder; using FillType = impeller::FillType; diff --git a/display_list/geometry/dl_path.h b/display_list/geometry/dl_path.h index 1bdcfcb192c39..f7d6ebe870948 100644 --- a/display_list/geometry/dl_path.h +++ b/display_list/geometry/dl_path.h @@ -15,6 +15,22 @@ class DlPath { public: static constexpr uint32_t kMaxVolatileUses = 2; + static DlPath MakeRect(DlRect rect); + static DlPath MakeRectLTRB(DlScalar left, + DlScalar top, + DlScalar right, + DlScalar bottom); + static DlPath MakeRectXYWH(DlScalar x, + DlScalar y, + DlScalar width, + DlScalar height); + + static DlPath MakeOval(DlRect bounds); + static DlPath MakeOvalLTRB(DlScalar left, + DlScalar top, + DlScalar right, + DlScalar bottom); + DlPath() : data_(std::make_shared(SkPath())) {} explicit DlPath(const SkPath& path) : data_(std::make_shared(path)) {} @@ -50,6 +66,8 @@ class DlPath { bool IsConverted() const; bool IsVolatile() const; + DlPath operator+(const DlPath& other) const; + private: struct Data { explicit Data(const SkPath& path) : sk_path(path) {} diff --git a/flow/compositor_context.cc b/flow/compositor_context.cc index 0a94e0f530a20..de083e18118c4 100644 --- a/flow/compositor_context.cc +++ b/flow/compositor_context.cc @@ -11,7 +11,7 @@ namespace flutter { -std::optional FrameDamage::ComputeClipRect( +std::optional FrameDamage::ComputeClipRect( flutter::LayerTree& layer_tree, bool has_raster_cache, bool impeller_enabled) { @@ -21,8 +21,7 @@ std::optional FrameDamage::ComputeClipRect( prev_layer_tree_ ? prev_layer_tree_->paint_region_map() : empty_paint_region_map, has_raster_cache, impeller_enabled); - context.PushCullRect(SkRect::MakeIWH(layer_tree.frame_size().width(), - layer_tree.frame_size().height())); + context.PushCullRect(DlRect::MakeSize(layer_tree.frame_size())); { DiffContext::AutoSubtreeRestore subtree(&context); const Layer* prev_root_layer = nullptr; @@ -30,8 +29,7 @@ std::optional FrameDamage::ComputeClipRect( prev_layer_tree_->frame_size() != layer_tree.frame_size()) { // If there is no previous layer tree assume the entire frame must be // repainted. - context.MarkSubtreeDirty(SkRect::MakeIWH( - layer_tree.frame_size().width(), layer_tree.frame_size().height())); + context.MarkSubtreeDirty(DlRect::MakeSize(layer_tree.frame_size())); } else { prev_root_layer = prev_layer_tree_->root_layer(); } @@ -41,7 +39,7 @@ std::optional FrameDamage::ComputeClipRect( damage_ = context.ComputeDamage(additional_damage_, horizontal_clip_alignment_, vertical_clip_alignment_); - return SkRect::Make(damage_->buffer_damage); + return DlRect::Make(damage_->buffer_damage); } return std::nullopt; } @@ -120,7 +118,7 @@ RasterStatus CompositorContext::ScopedFrame::Raster( FrameDamage* frame_damage) { TRACE_EVENT0("flutter", "CompositorContext::ScopedFrame::Raster"); - std::optional clip_rect; + std::optional clip_rect; if (frame_damage) { clip_rect = frame_damage->ComputeClipRect(layer_tree, !ignore_raster_cache, !gr_context_); @@ -159,7 +157,7 @@ RasterStatus CompositorContext::ScopedFrame::Raster( void CompositorContext::ScopedFrame::PaintLayerTreeSkia( flutter::LayerTree& layer_tree, - std::optional clip_rect, + std::optional clip_rect, bool needs_save_layer, bool ignore_raster_cache) { DlAutoCanvasRestore restore(canvas(), clip_rect.has_value()); @@ -171,7 +169,7 @@ void CompositorContext::ScopedFrame::PaintLayerTreeSkia( if (needs_save_layer) { TRACE_EVENT0("flutter", "Canvas::saveLayer"); - SkRect bounds = SkRect::Make(layer_tree.frame_size()); + SkRect bounds = SkRect::Make(ToSkISize(layer_tree.frame_size())); DlPaint paint; paint.setBlendMode(DlBlendMode::kSrc); canvas()->SaveLayer(&bounds, &paint); @@ -185,10 +183,10 @@ void CompositorContext::ScopedFrame::PaintLayerTreeSkia( void CompositorContext::ScopedFrame::PaintLayerTreeImpeller( flutter::LayerTree& layer_tree, - std::optional clip_rect, + std::optional clip_rect, bool ignore_raster_cache) { if (canvas() && clip_rect) { - canvas()->Translate(-clip_rect->x(), -clip_rect->y()); + canvas()->Translate(-clip_rect->GetX(), -clip_rect->GetY()); } layer_tree.Paint(*this, ignore_raster_cache); @@ -208,17 +206,17 @@ void CompositorContext::ScopedFrame::PaintLayerTreeImpeller( constexpr float kImpellerRepaintRatio = 0.7f; bool CompositorContext::ShouldPerformPartialRepaint( - std::optional damage_rect, - SkISize layer_tree_size) { + std::optional damage_rect, + DlISize layer_tree_size) { if (!damage_rect.has_value()) { return false; } - if (damage_rect->width() >= layer_tree_size.width() && - damage_rect->height() >= layer_tree_size.height()) { + if (damage_rect->GetWidth() >= layer_tree_size.width && + damage_rect->GetHeight() >= layer_tree_size.height) { return false; } - auto rx = damage_rect->width() / layer_tree_size.width(); - auto ry = damage_rect->height() / layer_tree_size.height(); + auto rx = damage_rect->GetWidth() / layer_tree_size.width; + auto ry = damage_rect->GetHeight() / layer_tree_size.height; return rx <= kImpellerRepaintRatio || ry <= kImpellerRepaintRatio; } diff --git a/flow/compositor_context.h b/flow/compositor_context.h index cf3c139c819ef..0cd4c5862b44a 100644 --- a/flow/compositor_context.h +++ b/flow/compositor_context.h @@ -57,8 +57,8 @@ class FrameDamage { // Adds additional damage (accumulated for double / triple buffering). // This is area that will be repainted alongside any changed part. - void AddAdditionalDamage(const SkIRect& damage) { - additional_damage_.join(damage); + void AddAdditionalDamage(const DlIRect& damage) { + additional_damage_ = additional_damage_.Union(damage); } // Specifies clip rect alignment. @@ -72,17 +72,17 @@ class FrameDamage { // If previous layer tree is not specified, clip rect will be nullopt, // but the paint region of layer_tree will be calculated so that it can be // used for diffing of subsequent frames. - std::optional ComputeClipRect(flutter::LayerTree& layer_tree, + std::optional ComputeClipRect(flutter::LayerTree& layer_tree, bool has_raster_cache, bool impeller_enabled); // See Damage::frame_damage. - std::optional GetFrameDamage() const { + std::optional GetFrameDamage() const { return damage_ ? std::make_optional(damage_->frame_damage) : std::nullopt; } // See Damage::buffer_damage. - std::optional GetBufferDamage() { + std::optional GetBufferDamage() { return (damage_ && !ignore_damage_) ? std::make_optional(damage_->buffer_damage) : std::nullopt; @@ -95,7 +95,7 @@ class FrameDamage { void Reset() { ignore_damage_ = true; } private: - SkIRect additional_damage_ = SkIRect::MakeEmpty(); + DlIRect additional_damage_; std::optional damage_; const LayerTree* prev_layer_tree_ = nullptr; int vertical_clip_alignment_ = 1; @@ -141,12 +141,12 @@ class CompositorContext { private: void PaintLayerTreeSkia(flutter::LayerTree& layer_tree, - std::optional clip_rect, + std::optional clip_rect, bool needs_save_layer, bool ignore_raster_cache); void PaintLayerTreeImpeller(flutter::LayerTree& layer_tree, - std::optional clip_rect, + std::optional clip_rect, bool ignore_raster_cache); CompositorContext& context_; @@ -154,7 +154,7 @@ class CompositorContext { DlCanvas* canvas_; impeller::AiksContext* aiks_context_; ExternalViewEmbedder* view_embedder_; - const SkMatrix& root_surface_transformation_; + const SkMatrix root_surface_transformation_; const bool instrumentation_enabled_; const bool surface_supports_readback_; fml::RefPtr raster_thread_merger_; @@ -210,8 +210,8 @@ class CompositorContext { /// @brief Whether Impeller shouild attempt a partial repaint. /// The Impeller backend requires an additional blit pass, which may /// not be worthwhile if the damage region is large. - static bool ShouldPerformPartialRepaint(std::optional damage_rect, - SkISize layer_tree_size); + static bool ShouldPerformPartialRepaint(std::optional damage_rect, + DlISize layer_tree_size); FML_DISALLOW_COPY_AND_ASSIGN(CompositorContext); }; diff --git a/flow/diff_context.cc b/flow/diff_context.cc index aca12f6e8538b..2fa21ab12588f 100644 --- a/flow/diff_context.cc +++ b/flow/diff_context.cc @@ -9,12 +9,12 @@ namespace flutter { -DiffContext::DiffContext(SkISize frame_size, +DiffContext::DiffContext(DlISize frame_size, PaintRegionMap& this_frame_paint_region_map, const PaintRegionMap& last_frame_paint_region_map, bool has_raster_cache, bool impeller_enabled) - : rects_(std::make_shared>()), + : rects_(std::make_shared>()), frame_size_(frame_size), this_frame_paint_region_map_(this_frame_paint_region_map), last_frame_paint_region_map_(last_frame_paint_region_map), @@ -44,13 +44,9 @@ void DiffContext::EndSubtree() { state_stack_.pop_back(); } -DiffContext::State::State() : matrix_clip(kGiantRect, SkMatrix::I()) {} +DiffContext::State::State() : matrix_clip(kGiantRect, DlMatrix()) {} -void DiffContext::PushTransform(const SkMatrix& transform) { - state_.matrix_clip.transform(transform); -} - -void DiffContext::PushTransform(const SkM44& transform) { +void DiffContext::PushTransform(const DlMatrix& transform) { state_.matrix_clip.transform(transform); } @@ -58,18 +54,10 @@ void DiffContext::MakeTransformIntegral( DisplayListMatrixClipState& matrix_clip) { // TODO(knopp): This is duplicated from LayerStack. Maybe should be part of // clip tracker? - if (matrix_clip.using_4x4_matrix()) { - SkM44 integral; - if (RasterCacheUtil::ComputeIntegralTransCTM(matrix_clip.matrix_4x4(), - &integral)) { - matrix_clip.setTransform(integral); - } - } else { - SkMatrix integral; - if (RasterCacheUtil::ComputeIntegralTransCTM(matrix_clip.matrix_3x3(), - &integral)) { - matrix_clip.setTransform(integral); - } + DlMatrix integral; + if (RasterCacheUtil::ComputeIntegralTransCTM(matrix_clip.matrix(), + &integral)) { + matrix_clip.setTransform(integral); } } @@ -80,7 +68,7 @@ void DiffContext::PushFilterBoundsAdjustment( filter_bounds_adjustment_stack_.push_back(filter); } -SkRect DiffContext::ApplyFilterBoundsAdjustment(SkRect rect) const { +DlRect DiffContext::ApplyFilterBoundsAdjustment(DlRect rect) const { // Apply filter bounds adjustment in reverse order for (auto i = filter_bounds_adjustment_stack_.rbegin(); i != filter_bounds_adjustment_stack_.rend(); ++i) { @@ -89,13 +77,13 @@ SkRect DiffContext::ApplyFilterBoundsAdjustment(SkRect rect) const { return rect; } -void DiffContext::AlignRect(SkIRect& rect, +void DiffContext::AlignRect(DlIRect& rect, int horizontal_alignment, int vertical_alignment) const { - auto top = rect.top(); - auto left = rect.left(); - auto right = rect.right(); - auto bottom = rect.bottom(); + auto top = rect.GetTop(); + auto left = rect.GetLeft(); + auto right = rect.GetRight(); + auto bottom = rect.GetBottom(); if (top % vertical_alignment != 0) { top -= top % vertical_alignment; } @@ -108,43 +96,36 @@ void DiffContext::AlignRect(SkIRect& rect, if (bottom % vertical_alignment != 0) { bottom += vertical_alignment - bottom % vertical_alignment; } - right = std::min(right, frame_size_.width()); - bottom = std::min(bottom, frame_size_.height()); - rect = SkIRect::MakeLTRB(left, top, right, bottom); + right = std::min(right, frame_size_.width); + bottom = std::min(bottom, frame_size_.height); + rect = DlIRect::MakeLTRB(left, top, right, bottom); } -Damage DiffContext::ComputeDamage(const SkIRect& accumulated_buffer_damage, +Damage DiffContext::ComputeDamage(const DlIRect& accumulated_buffer_damage, int horizontal_clip_alignment, int vertical_clip_alignment) const { - SkRect buffer_damage = SkRect::Make(accumulated_buffer_damage); - buffer_damage.join(damage_); - SkRect frame_damage(damage_); + DlRect buffer_damage = DlRect::Make(accumulated_buffer_damage).Union(damage_); + DlRect frame_damage(damage_); for (const auto& r : readbacks_) { - SkRect paint_rect = SkRect::Make(r.paint_rect); - SkRect readback_rect = SkRect::Make(r.readback_rect); + DlRect paint_rect = DlRect::Make(r.paint_rect); + DlRect readback_rect = DlRect::Make(r.readback_rect); // Changes either in readback or paint rect require repainting both readback // and paint rect. - if (paint_rect.intersects(frame_damage) || - readback_rect.intersects(frame_damage)) { - frame_damage.join(readback_rect); - frame_damage.join(paint_rect); - buffer_damage.join(readback_rect); - buffer_damage.join(paint_rect); + if (paint_rect.IntersectsWithRect(frame_damage) || + readback_rect.IntersectsWithRect(frame_damage)) { + frame_damage = frame_damage.Union(readback_rect).Union(paint_rect); + buffer_damage = buffer_damage.Union(readback_rect).Union(paint_rect); } } - Damage res; - buffer_damage.roundOut(&res.buffer_damage); - frame_damage.roundOut(&res.frame_damage); + DlIRect frame_clip = DlIRect::MakeSize(frame_size_); - SkIRect frame_clip = SkIRect::MakeSize(frame_size_); - if (!res.buffer_damage.intersect(frame_clip)) { - res.buffer_damage.setEmpty(); - } - if (!res.frame_damage.intersect(frame_clip)) { - res.frame_damage.setEmpty(); - } + Damage res; + res.buffer_damage = + DlIRect::RoundOut(buffer_damage).IntersectionOrEmpty(frame_clip); + res.frame_damage = + DlIRect::RoundOut(frame_damage).IntersectionOrEmpty(frame_clip); if (horizontal_clip_alignment > 1 || vertical_clip_alignment > 1) { AlignRect(res.buffer_damage, horizontal_clip_alignment, @@ -155,13 +136,13 @@ Damage DiffContext::ComputeDamage(const SkIRect& accumulated_buffer_damage, return res; } -SkRect DiffContext::MapRect(const SkRect& rect) { - SkRect mapped_rect(rect); +DlRect DiffContext::MapRect(const DlRect& rect) { + DlRect mapped_rect(rect); state_.matrix_clip.mapRect(&mapped_rect); return mapped_rect; } -bool DiffContext::PushCullRect(const SkRect& clip) { +bool DiffContext::PushCullRect(const DlRect& clip) { state_.matrix_clip.clipRect(clip, DlCanvas::ClipOp::kIntersect, false); return !state_.matrix_clip.device_cull_rect().isEmpty(); } @@ -170,12 +151,8 @@ const DlMatrix& DiffContext::GetMatrix() const { return state_.matrix_clip.matrix(); } -SkMatrix DiffContext::GetTransform3x3() const { - return state_.matrix_clip.matrix_3x3(); -} - -SkRect DiffContext::GetCullRect() const { - return state_.matrix_clip.local_cull_rect(); +DlRect DiffContext::GetCullRect() const { + return state_.matrix_clip.GetLocalCullCoverage(); } void DiffContext::MarkSubtreeDirty(const PaintRegion& previous_paint_region) { @@ -186,18 +163,19 @@ void DiffContext::MarkSubtreeDirty(const PaintRegion& previous_paint_region) { state_.dirty = true; } -void DiffContext::MarkSubtreeDirty(const SkRect& previous_paint_region) { +void DiffContext::MarkSubtreeDirty(const DlRect& previous_paint_region) { FML_DCHECK(!IsSubtreeDirty()); AddDamage(previous_paint_region); state_.dirty = true; } -void DiffContext::AddLayerBounds(const SkRect& rect) { +void DiffContext::AddLayerBounds(const DlRect& rect) { // During painting we cull based on non-overriden transform and then // override the transform right before paint. Do the same thing here to get // identical paint rect. auto transformed_rect = ApplyFilterBoundsAdjustment(MapRect(rect)); - if (transformed_rect.intersects(state_.matrix_clip.device_cull_rect())) { + if (transformed_rect.IntersectsWithRect( + state_.matrix_clip.GetDeviceCullCoverage())) { if (state_.integral_transform) { DisplayListMatrixClipState temp_state = state_.matrix_clip; MakeTransformIntegral(temp_state); @@ -230,14 +208,14 @@ void DiffContext::AddExistingPaintRegion(const PaintRegion& region) { } } -void DiffContext::AddReadbackRegion(const SkIRect& paint_rect, - const SkIRect& readback_rect) { +void DiffContext::AddReadbackRegion(const DlIRect& paint_rect, + const DlIRect& readback_rect) { Readback readback; readback.paint_rect = paint_rect; readback.readback_rect = readback_rect; readback.position = rects_->size(); // Push empty rect as a placeholder for position in current subtree - rects_->push_back(SkRect::MakeEmpty()); + rects_->push_back(DlRect()); readbacks_.push_back(readback); } @@ -252,12 +230,12 @@ PaintRegion DiffContext::CurrentSubtreeRegion() const { void DiffContext::AddDamage(const PaintRegion& damage) { FML_DCHECK(damage.is_valid()); for (const auto& r : damage) { - damage_.join(r); + damage_ = damage_.Union(r); } } -void DiffContext::AddDamage(const SkRect& rect) { - damage_.join(rect); +void DiffContext::AddDamage(const DlRect& rect) { + damage_ = damage_.Union(rect); } void DiffContext::SetLayerPaintRegion(const Layer* layer, diff --git a/flow/diff_context.h b/flow/diff_context.h index 9195ce0af7237..d51778186edb0 100644 --- a/flow/diff_context.h +++ b/flow/diff_context.h @@ -12,9 +12,6 @@ #include "display_list/utils/dl_matrix_clip_tracker.h" #include "flutter/flow/paint_region.h" #include "flutter/fml/macros.h" -#include "third_party/skia/include/core/SkM44.h" -#include "third_party/skia/include/core/SkMatrix.h" -#include "third_party/skia/include/core/SkRect.h" namespace flutter { @@ -27,14 +24,14 @@ struct Damage { // If embedder supports partial update, this is the region that needs to be // repainted. // Corresponds to "surface damage" from EGL_KHR_partial_update. - SkIRect frame_damage; + DlIRect frame_damage; // Reflects actual change to target framebuffer; This is frame_damage + // damage previously acumulated for target framebuffer. // All drawing will be clipped to this region. Knowing the affected area // upfront may be useful for tile based GPUs. // Corresponds to "buffer damage" from EGL_KHR_partial_update. - SkIRect buffer_damage; + DlIRect buffer_damage; }; // Layer Unique Id to PaintRegion @@ -43,7 +40,7 @@ using PaintRegionMap = std::map; // Tracks state during tree diffing process and computes resulting damage class DiffContext { public: - explicit DiffContext(SkISize frame_size, + explicit DiffContext(DlISize frame_size, PaintRegionMap& this_frame_paint_region_map, const PaintRegionMap& last_frame_paint_region_map, bool has_raster_cache, @@ -71,15 +68,14 @@ class DiffContext { }; // Pushes additional transform for current subtree - void PushTransform(const SkMatrix& transform); - void PushTransform(const SkM44& transform); + void PushTransform(const DlMatrix& transform); // Pushes cull rect for current subtree - bool PushCullRect(const SkRect& clip); + bool PushCullRect(const DlRect& clip); // Function that adjusts layer bounds (in device coordinates) depending // on filter. - using FilterBoundsAdjustment = std::function; + using FilterBoundsAdjustment = std::function; // Pushes filter bounds adjustment to current subtree. Every layer in this // subtree will have bounds adjusted by this function. @@ -91,11 +87,8 @@ class DiffContext { // Returns current transform as DlMatrix. const DlMatrix& GetMatrix() const; - // Returns current transform as SkMatrix. - SkMatrix GetTransform3x3() const; - // Return cull rect for current subtree (in local coordinates). - SkRect GetCullRect() const; + DlRect GetCullRect() const; // Sets the dirty flag on current subtree. // @@ -106,7 +99,7 @@ class DiffContext { // added to damage. void MarkSubtreeDirty( const PaintRegion& previous_paint_region = PaintRegion()); - void MarkSubtreeDirty(const SkRect& previous_paint_region); + void MarkSubtreeDirty(const DlRect& previous_paint_region); bool IsSubtreeDirty() const { return state_.dirty; } @@ -116,7 +109,7 @@ class DiffContext { // Add layer bounds to current paint region; rect is in "local" (layer) // coordinates. - void AddLayerBounds(const SkRect& rect); + void AddLayerBounds(const DlRect& rect); // Add entire paint region of retained layer for current subtree. This can // only be used in subtrees that are not dirty, otherwise ancestor transforms @@ -130,8 +123,8 @@ class DiffContext { // coordinates) // readback_rect - rectangle where the filter samples from (in screen // coordinates) - void AddReadbackRegion(const SkIRect& paint_rect, - const SkIRect& readback_rect); + void AddReadbackRegion(const DlIRect& paint_rect, + const DlIRect& readback_rect); // Returns the paint region for current subtree; Each rect in paint region is // in screen coordinates; Once a layer accumulates the paint regions of its @@ -146,7 +139,7 @@ class DiffContext { // // clip_alignment controls the alignment of resulting frame and surface // damage. - Damage ComputeDamage(const SkIRect& additional_damage, + Damage ComputeDamage(const DlIRect& additional_damage, int horizontal_clip_alignment = 0, int vertical_clip_alignment = 0) const; @@ -205,7 +198,7 @@ class DiffContext { Statistics& statistics() { return statistics_; } - SkRect MapRect(const SkRect& rect); + DlRect MapRect(const DlRect& rect); private: struct State { @@ -239,26 +232,26 @@ class DiffContext { void MakeTransformIntegral(DisplayListMatrixClipState& matrix_clip); - std::shared_ptr> rects_; + std::shared_ptr> rects_; State state_; - SkISize frame_size_; + DlISize frame_size_; std::vector state_stack_; std::vector filter_bounds_adjustment_stack_; // Applies the filter bounds adjustment stack on provided rect. // Rect must be in device coordinates. - SkRect ApplyFilterBoundsAdjustment(SkRect rect) const; + DlRect ApplyFilterBoundsAdjustment(DlRect rect) const; - SkRect damage_ = SkRect::MakeEmpty(); + DlRect damage_; PaintRegionMap& this_frame_paint_region_map_; const PaintRegionMap& last_frame_paint_region_map_; bool has_raster_cache_; bool impeller_enabled_; - void AddDamage(const SkRect& rect); + void AddDamage(const DlRect& rect); - void AlignRect(SkIRect& rect, + void AlignRect(DlIRect& rect, int horizontal_alignment, int vertical_clip_alignment) const; @@ -268,10 +261,10 @@ class DiffContext { size_t position; // Paint region of the filter performing readback, in screen coordinates. - SkIRect paint_rect; + DlIRect paint_rect; // Readback area of the filter, in screen coordinates. - SkIRect readback_rect; + DlIRect readback_rect; }; std::vector readbacks_; diff --git a/flow/diff_context_unittests.cc b/flow/diff_context_unittests.cc index 7628c8f1876e3..42e02600b96a6 100644 --- a/flow/diff_context_unittests.cc +++ b/flow/diff_context_unittests.cc @@ -10,32 +10,32 @@ namespace testing { TEST_F(DiffContextTest, ClipAlignment) { MockLayerTree t1; t1.root()->Add(CreateDisplayListLayer( - CreateDisplayList(SkRect::MakeLTRB(30, 30, 50, 50)))); - auto damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 0, 0); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(30, 30, 50, 50)); - EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(30, 30, 50, 50)); + CreateDisplayList(DlRect::MakeLTRB(30, 30, 50, 50)))); + auto damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 0, 0); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(30, 30, 50, 50)); + EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(30, 30, 50, 50)); - damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 1, 1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(30, 30, 50, 50)); - EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(30, 30, 50, 50)); + damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 1, 1); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(30, 30, 50, 50)); + EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(30, 30, 50, 50)); - damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 8, 1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(24, 30, 56, 50)); - EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(24, 30, 56, 50)); + damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 8, 1); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(24, 30, 56, 50)); + EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(24, 30, 56, 50)); - damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 1, 8); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(30, 24, 50, 56)); - EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(30, 24, 50, 56)); + damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 1, 8); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(30, 24, 50, 56)); + EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(30, 24, 50, 56)); - damage = DiffLayerTree(t1, MockLayerTree(), SkIRect::MakeEmpty(), 16, 16); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(16, 16, 64, 64)); - EXPECT_EQ(damage.buffer_damage, SkIRect::MakeLTRB(16, 16, 64, 64)); + damage = DiffLayerTree(t1, MockLayerTree(), DlIRect(), 16, 16); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(16, 16, 64, 64)); + EXPECT_EQ(damage.buffer_damage, DlIRect::MakeLTRB(16, 16, 64, 64)); } TEST_F(DiffContextTest, DisjointDamage) { - SkISize frame_size = SkISize::Make(90, 90); - auto in_bounds_dl = CreateDisplayList(SkRect::MakeLTRB(30, 30, 50, 50)); - auto out_bounds_dl = CreateDisplayList(SkRect::MakeLTRB(100, 100, 120, 120)); + DlISize frame_size = DlISize(90, 90); + auto in_bounds_dl = CreateDisplayList(DlRect::MakeLTRB(30, 30, 50, 50)); + auto out_bounds_dl = CreateDisplayList(DlRect::MakeLTRB(100, 100, 120, 120)); // We need both DisplayLists to be non-empty. ASSERT_FALSE(in_bounds_dl->bounds().isEmpty()); @@ -43,8 +43,9 @@ TEST_F(DiffContextTest, DisjointDamage) { // We need the in_bounds DisplayList to be inside the frame size. // We need the out_bounds DisplayList to be completely outside the frame. - ASSERT_TRUE(SkRect::Make(frame_size).contains(in_bounds_dl->bounds())); - ASSERT_FALSE(SkRect::Make(frame_size).intersects(out_bounds_dl->bounds())); + ASSERT_TRUE(DlRect::MakeSize(frame_size).Contains(in_bounds_dl->GetBounds())); + ASSERT_FALSE(DlRect::MakeSize(frame_size) + .IntersectsWithRect(out_bounds_dl->GetBounds())); MockLayerTree t1(frame_size); t1.root()->Add(CreateDisplayListLayer(in_bounds_dl)); @@ -58,14 +59,14 @@ TEST_F(DiffContextTest, DisjointDamage) { // Cannot use DiffLayerTree because it implicitly adds a clip layer // around the tree, but we want the out of bounds dl to not be pruned // to test the intersection code inside layer::Diff/ComputeDamage - // damage = DiffLayerTree(t2, t1, SkIRect::MakeEmpty(), 0, 0); + // damage = DiffLayerTree(t2, t1, DlIRect(), 0, 0); DiffContext dc(frame_size, t2.paint_region_map(), t1.paint_region_map(), true, false); t2.root()->Diff(&dc, t1.root()); - auto damage = dc.ComputeDamage(SkIRect::MakeEmpty(), 0, 0); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeEmpty()); - EXPECT_EQ(damage.buffer_damage, SkIRect::MakeEmpty()); + auto damage = dc.ComputeDamage(DlIRect(), 0, 0); + EXPECT_EQ(damage.frame_damage, DlIRect()); + EXPECT_EQ(damage.buffer_damage, DlIRect()); } } // namespace testing diff --git a/flow/embedded_views.h b/flow/embedded_views.h index 594ef93cdaa68..fc77f14f87d7b 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -117,6 +117,14 @@ class Mutator { filter_mutation_( std::make_shared(filter, filter_rect)) {} + explicit Mutator(const DlRect& rect) : Mutator(ToSkRect(rect)) {} + explicit Mutator(const DlRoundRect& rrect) : Mutator(ToSkRRect(rrect)) {} + explicit Mutator(const DlPath& path) : Mutator(path.GetSkPath()) {} + explicit Mutator(const DlMatrix& matrix) : Mutator(ToSkMatrix(matrix)) {} + explicit Mutator(const std::shared_ptr& filter, + const DlRect& filter_rect) + : Mutator(filter, ToSkRect(filter_rect)) {} + const MutatorType& GetType() const { return type_; } const SkRect& GetRect() const { return rect_; } const SkRRect& GetRRect() const { return rrect_; } diff --git a/flow/layers/backdrop_filter_layer.cc b/flow/layers/backdrop_filter_layer.cc index 7941101202416..57c469a7638b0 100644 --- a/flow/layers/backdrop_filter_layer.cc +++ b/flow/layers/backdrop_filter_layer.cc @@ -28,12 +28,11 @@ void BackdropFilterLayer::Diff(DiffContext* context, const Layer* old_layer) { if (filter_) { paint_bounds = context->MapRect(paint_bounds); - auto filter_target_bounds = paint_bounds.roundOut(); + auto filter_target_bounds = DlIRect::RoundOut(paint_bounds); DlIRect filter_input_bounds; // in screen coordinates - filter_->get_input_device_bounds(ToDlIRect(filter_target_bounds), - context->GetMatrix(), filter_input_bounds); - context->AddReadbackRegion(filter_target_bounds, - ToSkIRect(filter_input_bounds)); + filter_->get_input_device_bounds(filter_target_bounds, context->GetMatrix(), + filter_input_bounds); + context->AddReadbackRegion(filter_target_bounds, filter_input_bounds); } DiffChildren(context, prev); @@ -46,11 +45,12 @@ void BackdropFilterLayer::Preroll(PrerollContext* context) { Layer::AutoPrerollSaveLayerState::Create(context, true, bool(filter_)); if (filter_ && context->view_embedder != nullptr) { context->view_embedder->PushFilterToVisitedPlatformViews( - filter_, context->state_stack.device_cull_rect()); + filter_, ToSkRect(context->state_stack.device_cull_rect())); } - SkRect child_paint_bounds = SkRect::MakeEmpty(); + DlRect child_paint_bounds; PrerollChildren(context, &child_paint_bounds); - child_paint_bounds.join(context->state_stack.local_cull_rect()); + child_paint_bounds = + child_paint_bounds.Union(context->state_stack.local_cull_rect()); set_paint_bounds(child_paint_bounds); context->renderable_state_flags = kSaveLayerRenderFlags; } diff --git a/flow/layers/backdrop_filter_layer_unittests.cc b/flow/layers/backdrop_filter_layer_unittests.cc index 01a6b54cadc26..489a5c28aae3e 100644 --- a/flow/layers/backdrop_filter_layer_unittests.cc +++ b/flow/layers/backdrop_filter_layer_unittests.cc @@ -22,12 +22,12 @@ TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies) { auto filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp); auto layer = std::make_shared(filter, DlBlendMode::kSrcOver); - auto parent = std::make_shared(kEmptyRect, Clip::kHardEdge); + auto parent = std::make_shared(DlRect(), Clip::kHardEdge); parent->Add(layer); parent->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -35,25 +35,25 @@ TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies) { } TEST_F(BackdropFilterLayerTest, PaintBeforePrerollDies) { - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); auto mock_layer = std::make_shared(child_path); auto filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp); auto layer = std::make_shared(filter, DlBlendMode::kSrcOver); layer->Add(mock_layer); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), "needs_painting\\(context\\)"); } #endif TEST_F(BackdropFilterLayerTest, EmptyFilter) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = @@ -79,7 +79,7 @@ TEST_F(BackdropFilterLayerTest, EmptyFilter) { /* (BackdropFilter)layer::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&child_bounds, nullptr, nullptr); + expected_builder.SaveLayer(child_bounds, nullptr, nullptr); { /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); @@ -96,9 +96,9 @@ TEST_F(BackdropFilterLayerTest, EmptyFilter) { } TEST_F(BackdropFilterLayerTest, SimpleFilter) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto layer_filter = DlImageFilter::MakeBlur(2.5, 3.2, DlTileMode::kClamp); auto mock_layer = std::make_shared(child_path, child_paint); @@ -125,8 +125,7 @@ TEST_F(BackdropFilterLayerTest, SimpleFilter) { /* (BackdropFilter)layer::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&child_bounds, nullptr, - layer_filter.get()); + expected_builder.SaveLayer(child_bounds, nullptr, layer_filter.get()); { /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); @@ -143,9 +142,9 @@ TEST_F(BackdropFilterLayerTest, SimpleFilter) { } TEST_F(BackdropFilterLayerTest, NonSrcOverBlend) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto layer_filter = DlImageFilter::MakeBlur(2.5, 3.2, DlTileMode::kClamp); auto mock_layer = std::make_shared(child_path, child_paint); @@ -176,7 +175,7 @@ TEST_F(BackdropFilterLayerTest, NonSrcOverBlend) { expected_builder.Save(); { DlPaint save_paint = DlPaint().setBlendMode(DlBlendMode::kSrc); - expected_builder.SaveLayer(&child_bounds, &save_paint, + expected_builder.SaveLayer(child_bounds, &save_paint, layer_filter.get()); { /* mock_layer::Paint */ { @@ -194,15 +193,14 @@ TEST_F(BackdropFilterLayerTest, NonSrcOverBlend) { } TEST_F(BackdropFilterLayerTest, MultipleChildren) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); - const SkPath child_path1 = SkPath().addRect(child_bounds); - const SkPath child_path2 = - SkPath().addRect(child_bounds.makeOffset(3.0f, 0.0f)); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); + const DlPath child_path1 = DlPath::MakeRect(child_bounds); + const DlPath child_path2 = DlPath::MakeRect(child_bounds.Shift(3.0f, 0.0f)); const DlPaint child_paint1 = DlPaint(DlColor::kYellow()); const DlPaint child_paint2 = DlPaint(DlColor::kCyan()); - SkRect children_bounds = child_path1.getBounds(); - children_bounds.join(child_path2.getBounds()); + const DlRect children_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); auto layer_filter = DlImageFilter::MakeBlur(2.5, 3.2, DlTileMode::kClamp); auto mock_layer1 = std::make_shared(child_path1, child_paint1); auto mock_layer2 = std::make_shared(child_path2, child_paint2); @@ -216,8 +214,8 @@ TEST_F(BackdropFilterLayerTest, MultipleChildren) { preroll_context()->state_stack.set_preroll_delegate(initial_transform); parent->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer->paint_bounds(), children_bounds); EXPECT_EQ(layer->child_paint_bounds(), children_bounds); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); @@ -236,7 +234,7 @@ TEST_F(BackdropFilterLayerTest, MultipleChildren) { /* (BackdropFilter)layer::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&children_bounds, nullptr, + expected_builder.SaveLayer(children_bounds, nullptr, layer_filter.get()); { /* mock_layer1::Paint */ { @@ -257,15 +255,14 @@ TEST_F(BackdropFilterLayerTest, MultipleChildren) { } TEST_F(BackdropFilterLayerTest, Nested) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); - const SkPath child_path1 = SkPath().addRect(child_bounds); - const SkPath child_path2 = - SkPath().addRect(child_bounds.makeOffset(3.0f, 0.0f)); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); + const DlPath child_path1 = DlPath::MakeRect(child_bounds); + const DlPath child_path2 = DlPath::MakeRect(child_bounds.Shift(3.0f, 0.0f)); const DlPaint child_paint1 = DlPaint(DlColor::kYellow()); const DlPaint child_paint2 = DlPaint(DlColor::kCyan()); - SkRect children_bounds = child_path1.getBounds(); - children_bounds.join(child_path2.getBounds()); + const DlRect children_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); auto layer_filter1 = DlImageFilter::MakeBlur(2.5, 3.2, DlTileMode::kClamp); auto layer_filter2 = DlImageFilter::MakeBlur(2.7, 3.1, DlTileMode::kDecal); auto mock_layer1 = std::make_shared(child_path1, child_paint1); @@ -284,8 +281,8 @@ TEST_F(BackdropFilterLayerTest, Nested) { preroll_context()->state_stack.set_preroll_delegate(initial_transform); parent->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer1->paint_bounds(), children_bounds); EXPECT_EQ(layer2->paint_bounds(), children_bounds); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); @@ -305,7 +302,7 @@ TEST_F(BackdropFilterLayerTest, Nested) { /* (BackdropFilter)layer1::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&children_bounds, nullptr, + expected_builder.SaveLayer(children_bounds, nullptr, layer_filter1.get()); { /* mock_layer1::Paint */ { @@ -314,7 +311,7 @@ TEST_F(BackdropFilterLayerTest, Nested) { /* (BackdropFilter)layer2::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&children_bounds, nullptr, + expected_builder.SaveLayer(children_bounds, nullptr, layer_filter2.get()); { /* mock_layer2::Paint */ { @@ -339,7 +336,7 @@ TEST_F(BackdropFilterLayerTest, Nested) { TEST_F(BackdropFilterLayerTest, Readback) { std::shared_ptr no_filter; auto layer_filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp); - auto initial_transform = SkMatrix(); + auto initial_transform = DlMatrix(); // BDF with filter always reads from surface auto layer1 = std::make_shared(layer_filter, @@ -362,7 +359,7 @@ TEST_F(BackdropFilterLayerTest, Readback) { EXPECT_TRUE(preroll_context()->surface_needs_readback); // BDF with no filter blocks child with readback - auto mock_layer = std::make_shared(SkPath(), DlPaint()); + auto mock_layer = std::make_shared(DlPath(), DlPaint()); mock_layer->set_fake_reads_surface(true); layer2->Add(mock_layer); preroll_context()->surface_needs_readback = false; @@ -372,12 +369,12 @@ TEST_F(BackdropFilterLayerTest, Readback) { TEST_F(BackdropFilterLayerTest, OpacityInheritance) { auto backdrop_filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp); - const SkPath mock_path = SkPath().addRect(SkRect::MakeLTRB(0, 0, 10, 10)); + const DlPath mock_path = DlPath::MakeRectLTRB(0, 0, 10, 10); const DlPaint mock_paint = DlPaint(DlColor::kRed()); - const SkRect clip_rect = SkRect::MakeLTRB(0, 0, 100, 100); + const DlRect clip_rect = DlRect::MakeLTRB(0, 0, 100, 100); auto clip = std::make_shared(clip_rect, Clip::kHardEdge); - auto parent = std::make_shared(128, SkPoint::Make(0, 0)); + auto parent = std::make_shared(128, DlPoint()); auto layer = std::make_shared(backdrop_filter, DlBlendMode::kSrcOver); auto child = std::make_shared(mock_path, mock_paint); @@ -399,7 +396,7 @@ TEST_F(BackdropFilterLayerTest, OpacityInheritance) { /* BackdropFilterLayer::Paint */ { DlPaint save_paint; save_paint.setAlpha(128); - expected_builder.SaveLayer(&clip_rect, &save_paint, + expected_builder.SaveLayer(clip_rect, &save_paint, backdrop_filter.get()); { /* MockLayer::Paint */ { @@ -431,75 +428,76 @@ TEST_F(BackdropLayerDiffTest, BackdropLayer) { EXPECT_EQ(readback, DlIRect::MakeLTRB(-30, -30, 40, 40)); } - MockLayerTree l1(SkISize::Make(100, 100)); + MockLayerTree l1(DlISize(100, 100)); l1.root()->Add( std::make_shared(filter, DlBlendMode::kSrcOver)); // no clip, effect over entire surface - auto damage = DiffLayerTree(l1, MockLayerTree(SkISize::Make(100, 100))); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeWH(100, 100)); + auto damage = DiffLayerTree(l1, MockLayerTree(DlISize(100, 100))); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeWH(100, 100)); - MockLayerTree l2(SkISize::Make(100, 100)); + MockLayerTree l2(DlISize(100, 100)); - auto clip = std::make_shared(SkRect::MakeLTRB(20, 20, 60, 60), + auto clip = std::make_shared(DlRect::MakeLTRB(20, 20, 60, 60), Clip::kHardEdge); clip->Add( std::make_shared(filter, DlBlendMode::kSrcOver)); l2.root()->Add(clip); - damage = DiffLayerTree(l2, MockLayerTree(SkISize::Make(100, 100))); + damage = DiffLayerTree(l2, MockLayerTree(DlISize(100, 100))); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 90, 90)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 90, 90)); MockLayerTree l3; - auto scale = std::make_shared(SkMatrix::Scale(2.0, 2.0)); + auto scale = + std::make_shared(DlMatrix::MakeScale({2.0, 2.0, 1.0f})); scale->Add(clip); l3.root()->Add(scale); damage = DiffLayerTree(l3, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 180, 180)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 180, 180)); MockLayerTree l4; l4.root()->Add(scale); // path just outside of readback region, doesn't affect blur - auto path1 = SkPath().addRect(SkRect::MakeLTRB(180, 180, 190, 190)); + auto path1 = DlPath::MakeRectLTRB(180, 180, 190, 190); l4.root()->Add(std::make_shared(path1)); damage = DiffLayerTree(l4, l3); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(180, 180, 190, 190)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(180, 180, 190, 190)); MockLayerTree l5; l5.root()->Add(scale); // path just inside of readback region, must trigger backdrop repaint - auto path2 = SkPath().addRect(SkRect::MakeLTRB(179, 179, 189, 189)); + auto path2 = DlPath::MakeRectLTRB(179, 179, 189, 189); l5.root()->Add(std::make_shared(path2)); damage = DiffLayerTree(l5, l4); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 190, 190)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 190, 190)); } TEST_F(BackdropLayerDiffTest, ReadbackOutsideOfPaintArea) { auto filter = DlImageFilter::MakeMatrix(DlMatrix::MakeTranslation({50, 50}), DlImageSampling::kLinear); - MockLayerTree l1(SkISize::Make(100, 100)); + MockLayerTree l1(DlISize(100, 100)); - auto clip = std::make_shared(SkRect::MakeLTRB(60, 60, 80, 80), + auto clip = std::make_shared(DlRect::MakeLTRB(60, 60, 80, 80), Clip::kHardEdge); clip->Add( std::make_shared(filter, DlBlendMode::kSrcOver)); l1.root()->Add(clip); - auto damage = DiffLayerTree(l1, MockLayerTree(SkISize::Make(100, 100))); + auto damage = DiffLayerTree(l1, MockLayerTree(DlISize(100, 100))); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(60 - 50, 60 - 50, 80, 80)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(60 - 50, 60 - 50, 80, 80)); - MockLayerTree l2(SkISize::Make(100, 100)); + MockLayerTree l2(DlISize(100, 100)); // path inside readback area must trigger whole readback repaint + filter // repaint. - auto path2 = SkPath().addRect(SkRect::MakeXYWH(60 - 50, 60 - 50, 10, 10)); + auto path2 = DlPath::MakeRectXYWH(60 - 50, 60 - 50, 10, 10); l2.root()->Add(clip); l2.root()->Add(std::make_shared(path2)); damage = DiffLayerTree(l2, l1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(60 - 50, 60 - 50, 80, 80)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(60 - 50, 60 - 50, 80, 80)); } TEST_F(BackdropLayerDiffTest, BackdropLayerInvalidTransform) { @@ -514,18 +512,23 @@ TEST_F(BackdropLayerDiffTest, BackdropLayerInvalidTransform) { EXPECT_EQ(readback, DlIRect::MakeLTRB(-30, -30, 40, 40)); } - MockLayerTree l1(SkISize::Make(100, 100)); - SkMatrix transform; - transform.setPerspX(0.1); - transform.setPerspY(0.1); + MockLayerTree l1(DlISize(100, 100)); + // clang-format off + DlMatrix transform( + 1, 0, 0, 0.1f, + 0, 1, 0, 0.1f, + 0, 0, 1, 0, + 0, 0, 0, 1 + ); + // clang-format on auto transform_layer = std::make_shared(transform); l1.root()->Add(transform_layer); transform_layer->Add( std::make_shared(filter, DlBlendMode::kSrcOver)); - auto damage = DiffLayerTree(l1, MockLayerTree(SkISize::Make(100, 100))); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeWH(100, 100)); + auto damage = DiffLayerTree(l1, MockLayerTree(DlISize(100, 100))); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeWH(100, 100)); } } // namespace testing diff --git a/flow/layers/cacheable_layer.cc b/flow/layers/cacheable_layer.cc index 19d53f8ff2a10..0a1f37a9deb3c 100644 --- a/flow/layers/cacheable_layer.cc +++ b/flow/layers/cacheable_layer.cc @@ -8,7 +8,7 @@ namespace flutter { AutoCache::AutoCache(RasterCacheItem* raster_cache_item, PrerollContext* context, - const SkMatrix& matrix) + const DlMatrix& matrix) : raster_cache_item_(raster_cache_item), context_(context), matrix_(matrix) { diff --git a/flow/layers/cacheable_layer.h b/flow/layers/cacheable_layer.h index db62edde6fa44..0a8f6182e3713 100644 --- a/flow/layers/cacheable_layer.h +++ b/flow/layers/cacheable_layer.h @@ -17,7 +17,7 @@ class AutoCache { public: AutoCache(RasterCacheItem* raster_cache_item, PrerollContext* context, - const SkMatrix& matrix); + const DlMatrix& matrix); void ShouldNotBeCached() { raster_cache_item_ = nullptr; } @@ -27,7 +27,7 @@ class AutoCache { inline bool IsCacheEnabled(); RasterCacheItem* raster_cache_item_ = nullptr; [[maybe_unused]] PrerollContext* context_ = nullptr; - const SkMatrix matrix_; + const DlMatrix matrix_; }; class CacheableContainerLayer : public ContainerLayer { diff --git a/flow/layers/clip_path_layer.cc b/flow/layers/clip_path_layer.cc index a5fb68449957d..c3153349d2df5 100644 --- a/flow/layers/clip_path_layer.cc +++ b/flow/layers/clip_path_layer.cc @@ -9,14 +9,13 @@ namespace flutter { ClipPathLayer::ClipPathLayer(const DlPath& clip_path, Clip clip_behavior) : ClipShapeLayer(clip_path, clip_behavior) {} -const SkRect& ClipPathLayer::clip_shape_bounds() const { - return clip_shape().GetSkPath().getBounds(); +const DlRect ClipPathLayer::clip_shape_bounds() const { + return clip_shape().GetBounds(); } void ClipPathLayer::ApplyClip(LayerStateStack::MutatorContext& mutator) const { clip_shape().WillRenderSkPath(); - mutator.clipPath(clip_shape().GetSkPath(), - clip_behavior() != Clip::kHardEdge); + mutator.clipPath(clip_shape(), clip_behavior() != Clip::kHardEdge); } } // namespace flutter diff --git a/flow/layers/clip_path_layer.h b/flow/layers/clip_path_layer.h index d03c829fd1245..5ac6de725398e 100644 --- a/flow/layers/clip_path_layer.h +++ b/flow/layers/clip_path_layer.h @@ -17,7 +17,7 @@ class ClipPathLayer : public ClipShapeLayer { Clip clip_behavior = Clip::kAntiAlias); protected: - const SkRect& clip_shape_bounds() const override; + const DlRect clip_shape_bounds() const override; void ApplyClip(LayerStateStack::MutatorContext& mutator) const override; diff --git a/flow/layers/clip_path_layer_unittests.cc b/flow/layers/clip_path_layer_unittests.cc index a8589ac6cec05..fc5079d77349e 100644 --- a/flow/layers/clip_path_layer_unittests.cc +++ b/flow/layers/clip_path_layer_unittests.cc @@ -39,8 +39,8 @@ TEST_F(ClipPathLayerTest, PaintingEmptyLayerDies) { EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(), kGiantRect); EXPECT_TRUE(preroll_context()->state_stack.is_empty()); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -48,12 +48,11 @@ TEST_F(ClipPathLayerTest, PaintingEmptyLayerDies) { } TEST_F(ClipPathLayerTest, PaintBeforePrerollDies) { - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath layer_path = SkPath().addRect(layer_bounds); - auto layer = - std::make_shared(DlPath(layer_path), Clip::kHardEdge); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath layer_path = DlPath::MakeRect(layer_bounds); + auto layer = std::make_shared(layer_path, Clip::kHardEdge); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -61,15 +60,14 @@ TEST_F(ClipPathLayerTest, PaintBeforePrerollDies) { } TEST_F(ClipPathLayerTest, PaintingCulledLayerDies) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkRect distant_bounds = SkRect::MakeXYWH(100.0, 100.0, 10.0, 10.0); - const SkPath child_path = SkPath().addRect(child_bounds); - const SkPath layer_path = SkPath().addRect(layer_bounds); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlRect distant_bounds = DlRect::MakeXYWH(100.0, 100.0, 10.0, 10.0); + const DlPath child_path = DlPath::MakeRect(child_bounds); + const DlPath layer_path = DlPath::MakeRect(layer_bounds); auto mock_layer = std::make_shared(child_path); - auto layer = - std::make_shared(DlPath(layer_path), Clip::kHardEdge); + auto layer = std::make_shared(layer_path, Clip::kHardEdge); layer->Add(mock_layer); // Cull these children @@ -86,7 +84,7 @@ TEST_F(ClipPathLayerTest, PaintingCulledLayerDies) { EXPECT_EQ(layer->child_paint_bounds(), child_bounds); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_cull_rect(), kEmptyRect); + EXPECT_EQ(mock_layer->parent_cull_rect(), DlRect()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_path)})); @@ -100,23 +98,23 @@ TEST_F(ClipPathLayerTest, PaintingCulledLayerDies) { #endif TEST_F(ClipPathLayerTest, ChildOutsideBounds) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect local_cull_bounds = SkRect::MakeXYWH(0.0, 0.0, 2.0, 4.0); - const SkRect device_cull_bounds = initial_matrix.mapRect(local_cull_bounds); - const SkRect child_bounds = SkRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); - const SkRect clip_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = SkPath().addRect(child_bounds); - const SkPath clip_path = SkPath().addRect(clip_bounds); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect local_cull_bounds = DlRect::MakeXYWH(0.0, 0.0, 2.0, 4.0); + const DlRect device_cull_bounds = + local_cull_bounds.TransformAndClipBounds(initial_matrix); + const DlRect child_bounds = DlRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); + const DlRect clip_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds); + const DlPath clip_path = DlPath::MakeRect(clip_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = - std::make_shared(DlPath(clip_path), Clip::kHardEdge); + auto layer = std::make_shared(clip_path, Clip::kHardEdge); layer->Add(mock_layer); - SkRect clip_cull_rect = local_cull_bounds; - ASSERT_TRUE(clip_cull_rect.intersect(clip_bounds)); - SkRect clip_layer_bounds = child_bounds; - ASSERT_TRUE(clip_layer_bounds.intersect(clip_bounds)); + auto clip_cull_rect = local_cull_bounds.Intersection(clip_bounds); + ASSERT_TRUE(clip_cull_rect.has_value()); + auto clip_layer_bounds = child_bounds.Intersection(clip_bounds); + ASSERT_TRUE(clip_layer_bounds.has_value()); // Set up both contexts to cull clipped child preroll_context()->state_stack.set_preroll_delegate(device_cull_bounds, @@ -133,9 +131,9 @@ TEST_F(ClipPathLayerTest, ChildOutsideBounds) { EXPECT_TRUE(preroll_context()->state_stack.is_empty()); EXPECT_EQ(mock_layer->paint_bounds(), child_bounds); - EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds); + EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds.value()); EXPECT_EQ(layer->child_paint_bounds(), child_bounds); - EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect); + EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect.value()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(clip_path)})); @@ -146,17 +144,16 @@ TEST_F(ClipPathLayerTest, ChildOutsideBounds) { } TEST_F(ClipPathLayerTest, FullyContainedChild) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = - SkPath().addRect(child_bounds).addOval(child_bounds.makeInset(0.1, 0.1)); - const SkPath layer_path = - SkPath().addRect(layer_bounds).addOval(layer_bounds.makeInset(0.1, 0.1)); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds) + + DlPath::MakeOval(child_bounds.Expand(-0.1f)); + const DlPath layer_path = DlPath::MakeRect(layer_bounds) + + DlPath::MakeOval(layer_bounds.Expand(-0.1f)); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = - std::make_shared(DlPath(layer_path), Clip::kHardEdge); + auto layer = std::make_shared(layer_path, Clip::kHardEdge); layer->Add(mock_layer); preroll_context()->state_stack.set_preroll_delegate(initial_matrix); @@ -191,25 +188,25 @@ TEST_F(ClipPathLayerTest, FullyContainedChild) { } TEST_F(ClipPathLayerTest, PartiallyContainedChild) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect local_cull_bounds = SkRect::MakeXYWH(0.0, 0.0, 4.0, 5.5); - const SkRect device_cull_bounds = initial_matrix.mapRect(local_cull_bounds); - const SkRect child_bounds = SkRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); - const SkRect clip_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = - SkPath().addRect(child_bounds).addOval(child_bounds.makeInset(0.1, 0.1)); - const SkPath clip_path = - SkPath().addRect(clip_bounds).addOval(clip_bounds.makeInset(0.1, 0.1)); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect local_cull_bounds = DlRect::MakeXYWH(0.0, 0.0, 4.0, 5.5); + const DlRect device_cull_bounds = + local_cull_bounds.TransformAndClipBounds(initial_matrix); + const DlRect child_bounds = DlRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); + const DlRect clip_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds) + + DlPath::MakeOval(child_bounds.Expand(-0.1f)); + const DlPath clip_path = DlPath::MakeRect(clip_bounds) + + DlPath::MakeOval(clip_bounds.Expand(-0.1f)); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = - std::make_shared(DlPath(clip_path), Clip::kHardEdge); + auto layer = std::make_shared(clip_path, Clip::kHardEdge); layer->Add(mock_layer); - SkRect clip_cull_rect = local_cull_bounds; - ASSERT_TRUE(clip_cull_rect.intersect(clip_bounds)); - SkRect clip_layer_bounds = child_bounds; - ASSERT_TRUE(clip_layer_bounds.intersect(clip_bounds)); + auto clip_cull_rect = local_cull_bounds.Intersection(clip_bounds); + ASSERT_TRUE(clip_cull_rect.has_value()); + auto clip_layer_bounds = child_bounds.Intersection(clip_bounds); + ASSERT_TRUE(clip_layer_bounds.has_value()); // Cull child preroll_context()->state_stack.set_preroll_delegate(device_cull_bounds, @@ -224,11 +221,11 @@ TEST_F(ClipPathLayerTest, PartiallyContainedChild) { EXPECT_TRUE(preroll_context()->state_stack.is_empty()); EXPECT_EQ(mock_layer->paint_bounds(), child_bounds); - EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds); + EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds.value()); EXPECT_EQ(layer->child_paint_bounds(), child_bounds); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect); + EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect.value()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(clip_path)})); @@ -251,10 +248,9 @@ static bool ReadbackResult(PrerollContext* context, Clip clip_behavior, const std::shared_ptr& child, bool before) { - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath layer_path = SkPath().addRect(layer_bounds); - auto layer = - std::make_shared(DlPath(layer_path), clip_behavior); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath layer_path = DlPath::MakeRect(layer_bounds); + auto layer = std::make_shared(layer_path, clip_behavior); if (child != nullptr) { layer->Add(child); } @@ -265,7 +261,7 @@ static bool ReadbackResult(PrerollContext* context, TEST_F(ClipPathLayerTest, Readback) { PrerollContext* context = preroll_context(); - SkPath path; + DlPath path; DlPaint paint; const Clip hard = Clip::kHardEdge; @@ -309,13 +305,12 @@ TEST_F(ClipPathLayerTest, Readback) { } TEST_F(ClipPathLayerTest, OpacityInheritance) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto layer_clip = SkPath() - .addRect(SkRect::MakeLTRB(5, 5, 25, 25)) - .addOval(SkRect::MakeLTRB(20, 20, 40, 50)); + auto layer_clip = + DlPath::MakeRectLTRB(5, 5, 25, 25) + DlPath::MakeOvalLTRB(20, 20, 40, 50); auto clip_path_layer = - std::make_shared(DlPath(layer_clip), Clip::kHardEdge); + std::make_shared(layer_clip, Clip::kHardEdge); clip_path_layer->Add(mock1); // ClipRectLayer will pass through compatibility from a compatible child @@ -324,7 +319,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); clip_path_layer->Add(mock2); @@ -334,7 +329,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path3 = SkPath().addRect({20, 20, 40, 40}); + auto path3 = DlPath::MakeRectLTRB(20, 20, 40, 40); auto mock3 = MockLayer::MakeOpacityCompatible(path3); clip_path_layer->Add(mock3); @@ -346,7 +341,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { { // ClipRectLayer(aa with saveLayer) will always be compatible auto clip_path_savelayer = std::make_shared( - DlPath(layer_clip), Clip::kAntiAliasWithSaveLayer); + layer_clip, Clip::kAntiAliasWithSaveLayer); clip_path_savelayer->Add(mock1); clip_path_savelayer->Add(mock2); @@ -361,13 +356,13 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { } // An incompatible, but non-overlapping child for the following tests - auto path4 = SkPath().addRect({60, 60, 70, 70}); + auto path4 = DlPath::MakeRectLTRB(60, 60, 70, 70); auto mock4 = MockLayer::Make(path4); { // ClipRectLayer with incompatible child will not be compatible auto clip_path_bad_child = - std::make_shared(DlPath(layer_clip), Clip::kHardEdge); + std::make_shared(layer_clip, Clip::kHardEdge); clip_path_bad_child->Add(mock1); clip_path_bad_child->Add(mock2); @@ -387,7 +382,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { { // ClipRectLayer(aa with saveLayer) will always be compatible auto clip_path_savelayer_bad_child = std::make_shared( - DlPath(layer_clip), Clip::kAntiAliasWithSaveLayer); + layer_clip, Clip::kAntiAliasWithSaveLayer); clip_path_savelayer_bad_child->Add(mock1); clip_path_savelayer_bad_child->Add(mock2); @@ -403,15 +398,14 @@ TEST_F(ClipPathLayerTest, OpacityInheritance) { } TEST_F(ClipPathLayerTest, OpacityInheritancePainting) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); - auto layer_clip = SkPath() - .addRect(SkRect::MakeLTRB(5, 5, 25, 25)) - .addOval(SkRect::MakeLTRB(45, 45, 55, 55)); + auto layer_clip = + DlPath::MakeRectLTRB(5, 5, 25, 25) + DlPath::MakeOvalLTRB(45, 45, 55, 55); auto clip_path_layer = - std::make_shared(DlPath(layer_clip), Clip::kAntiAlias); + std::make_shared(layer_clip, Clip::kAntiAlias); clip_path_layer->Add(mock1); clip_path_layer->Add(mock2); @@ -423,7 +417,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritancePainting) { LayerStateStack::kCallerCanApplyOpacity); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(clip_path_layer); opacity_layer->Preroll(context); @@ -433,7 +427,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritancePainting) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ClipRectLayer::Paint() */ { expected_builder.Save(); expected_builder.ClipPath(layer_clip, ClipOp::kIntersect, true); @@ -454,17 +448,15 @@ TEST_F(ClipPathLayerTest, OpacityInheritancePainting) { } TEST_F(ClipPathLayerTest, OpacityInheritanceSaveLayerPainting) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto path2 = SkPath().addRect({20, 20, 40, 40}); + auto path2 = DlPath::MakeRectLTRB(20, 20, 40, 40); auto mock2 = MockLayer::MakeOpacityCompatible(path2); - auto children_bounds = path1.getBounds(); - children_bounds.join(path2.getBounds()); - auto layer_clip = SkPath() - .addRect(SkRect::MakeLTRB(5, 5, 25, 25)) - .addOval(SkRect::MakeLTRB(20, 20, 40, 50)); + auto children_bounds = path1.GetBounds().Union(path2.GetBounds()); + auto layer_clip = + DlPath::MakeRectLTRB(5, 5, 25, 25) + DlPath::MakeOvalLTRB(20, 20, 40, 50); auto clip_path_layer = std::make_shared( - DlPath(layer_clip), Clip::kAntiAliasWithSaveLayer); + layer_clip, Clip::kAntiAliasWithSaveLayer); clip_path_layer->Add(mock1); clip_path_layer->Add(mock2); @@ -475,7 +467,7 @@ TEST_F(ClipPathLayerTest, OpacityInheritanceSaveLayerPainting) { EXPECT_EQ(context->renderable_state_flags, Layer::kSaveLayerRenderFlags); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(clip_path_layer); opacity_layer->Preroll(context); @@ -485,11 +477,11 @@ TEST_F(ClipPathLayerTest, OpacityInheritanceSaveLayerPainting) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ClipRectLayer::Paint() */ { expected_builder.Save(); expected_builder.ClipPath(layer_clip, ClipOp::kIntersect, true); - expected_builder.SaveLayer(&children_bounds, + expected_builder.SaveLayer(children_bounds, &DlPaint().setAlpha(opacity_alpha)); /* child layer1 paint */ { expected_builder.DrawPath(path1, DlPaint()); @@ -508,17 +500,16 @@ TEST_F(ClipPathLayerTest, OpacityInheritanceSaveLayerPainting) { } TEST_F(ClipPathLayerTest, LayerCached) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto layer_clip = SkPath() - .addRect(SkRect::MakeLTRB(5, 5, 25, 25)) - .addOval(SkRect::MakeLTRB(20, 20, 40, 50)); - auto layer = std::make_shared(DlPath(layer_clip), + auto layer_clip = + DlPath::MakeRectLTRB(5, 5, 25, 25) + DlPath::MakeOvalLTRB(20, 20, 40, 50); + auto layer = std::make_shared(layer_clip, Clip::kAntiAliasWithSaveLayer); layer->Add(mock1); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - SkMatrix cache_ctm = initial_transform; + auto initial_transform = DlMatrix::MakeTranslation({50.0, 25.5}); + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); @@ -551,14 +542,14 @@ TEST_F(ClipPathLayerTest, LayerCached) { } TEST_F(ClipPathLayerTest, EmptyClipDoesNotCullPlatformView) { - const SkPoint view_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize view_size = SkSize::Make(8.0f, 8.0f); + const DlPoint view_offset = DlPoint(0.0f, 0.0f); + const DlSize view_size = DlSize(8.0f, 8.0f); const int64_t view_id = 42; auto platform_view = std::make_shared(view_offset, view_size, view_id); - auto layer_clip = SkPath().addRect(kEmptyRect); - auto clip = std::make_shared(DlPath(layer_clip), + auto layer_clip = DlPath::MakeRect(DlRect()); + auto clip = std::make_shared(layer_clip, Clip::kAntiAliasWithSaveLayer); clip->Add(platform_view); diff --git a/flow/layers/clip_rect_layer.cc b/flow/layers/clip_rect_layer.cc index dfb0293f76c42..f67518696a070 100644 --- a/flow/layers/clip_rect_layer.cc +++ b/flow/layers/clip_rect_layer.cc @@ -6,10 +6,10 @@ namespace flutter { -ClipRectLayer::ClipRectLayer(const SkRect& clip_rect, Clip clip_behavior) +ClipRectLayer::ClipRectLayer(const DlRect& clip_rect, Clip clip_behavior) : ClipShapeLayer(clip_rect, clip_behavior) {} -const SkRect& ClipRectLayer::clip_shape_bounds() const { +const DlRect ClipRectLayer::clip_shape_bounds() const { return clip_shape(); } diff --git a/flow/layers/clip_rect_layer.h b/flow/layers/clip_rect_layer.h index 5f8f11d2bf023..b35401a32147b 100644 --- a/flow/layers/clip_rect_layer.h +++ b/flow/layers/clip_rect_layer.h @@ -9,12 +9,12 @@ namespace flutter { -class ClipRectLayer : public ClipShapeLayer { +class ClipRectLayer : public ClipShapeLayer { public: - ClipRectLayer(const SkRect& clip_rect, Clip clip_behavior); + ClipRectLayer(const DlRect& clip_rect, Clip clip_behavior); protected: - const SkRect& clip_shape_bounds() const override; + const DlRect clip_shape_bounds() const override; void ApplyClip(LayerStateStack::MutatorContext& mutator) const override; diff --git a/flow/layers/clip_rect_layer_unittests.cc b/flow/layers/clip_rect_layer_unittests.cc index c1d0d80a2b57e..b7c34ac19e040 100644 --- a/flow/layers/clip_rect_layer_unittests.cc +++ b/flow/layers/clip_rect_layer_unittests.cc @@ -25,12 +25,12 @@ using ClipOp = DlCanvas::ClipOp; #ifndef NDEBUG TEST_F(ClipRectLayerTest, ClipNoneBehaviorDies) { EXPECT_DEATH_IF_SUPPORTED( - auto clip = std::make_shared(kEmptyRect, Clip::kNone), + auto clip = std::make_shared(DlRect(), Clip::kNone), "clip_behavior != Clip::kNone"); } TEST_F(ClipRectLayerTest, PaintingEmptyLayerDies) { - auto layer = std::make_shared(kEmptyRect, Clip::kHardEdge); + auto layer = std::make_shared(DlRect(), Clip::kHardEdge); layer->Preroll(preroll_context()); @@ -38,8 +38,8 @@ TEST_F(ClipRectLayerTest, PaintingEmptyLayerDies) { EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(), kGiantRect); EXPECT_TRUE(preroll_context()->state_stack.is_empty()); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -47,10 +47,10 @@ TEST_F(ClipRectLayerTest, PaintingEmptyLayerDies) { } TEST_F(ClipRectLayerTest, PaintBeforePrerollDies) { - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); auto layer = std::make_shared(layer_bounds, Clip::kHardEdge); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -58,11 +58,11 @@ TEST_F(ClipRectLayerTest, PaintBeforePrerollDies) { } TEST_F(ClipRectLayerTest, PaintingCulledLayerDies) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkRect distant_bounds = SkRect::MakeXYWH(100.0, 100.0, 10.0, 10.0); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlRect distant_bounds = DlRect::MakeXYWH(100.0, 100.0, 10.0, 10.0); + const DlPath child_path = DlPath::MakeRect(child_bounds); auto mock_layer = std::make_shared(child_path); auto layer = std::make_shared(layer_bounds, Clip::kHardEdge); layer->Add(mock_layer); @@ -81,7 +81,7 @@ TEST_F(ClipRectLayerTest, PaintingCulledLayerDies) { EXPECT_EQ(layer->child_paint_bounds(), child_bounds); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_cull_rect(), kEmptyRect); + EXPECT_EQ(mock_layer->parent_cull_rect(), DlRect()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_bounds)})); @@ -96,21 +96,22 @@ TEST_F(ClipRectLayerTest, PaintingCulledLayerDies) { #endif TEST_F(ClipRectLayerTest, ChildOutsideBounds) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect local_cull_bounds = SkRect::MakeXYWH(0.0, 0.0, 2.0, 4.0); - const SkRect device_cull_bounds = initial_matrix.mapRect(local_cull_bounds); - const SkRect child_bounds = SkRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); - const SkRect clip_rect = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect local_cull_bounds = DlRect::MakeXYWH(0.0, 0.0, 2.0, 4.0); + const DlRect device_cull_bounds = + local_cull_bounds.TransformAndClipBounds(initial_matrix); + const DlRect child_bounds = DlRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); + const DlRect clip_rect = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(clip_rect, Clip::kHardEdge); layer->Add(mock_layer); - SkRect clip_cull_rect = local_cull_bounds; - ASSERT_TRUE(clip_cull_rect.intersect(clip_rect)); - SkRect clip_layer_bounds = child_bounds; - ASSERT_TRUE(clip_layer_bounds.intersect(clip_rect)); + auto clip_cull_rect = local_cull_bounds.Intersection(clip_rect); + ASSERT_TRUE(clip_cull_rect.has_value()); + auto clip_layer_bounds = child_bounds.Intersection(clip_rect); + ASSERT_TRUE(clip_layer_bounds.has_value()); // Set up both contexts to cull clipped child preroll_context()->state_stack.set_preroll_delegate(device_cull_bounds, @@ -127,9 +128,9 @@ TEST_F(ClipRectLayerTest, ChildOutsideBounds) { EXPECT_TRUE(preroll_context()->state_stack.is_empty()); EXPECT_EQ(mock_layer->paint_bounds(), child_bounds); - EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds); + EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds.value()); EXPECT_EQ(layer->child_paint_bounds(), child_bounds); - EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect); + EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect.value()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(clip_rect)})); @@ -140,10 +141,10 @@ TEST_F(ClipRectLayerTest, ChildOutsideBounds) { } TEST_F(ClipRectLayerTest, FullyContainedChild) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(layer_bounds, Clip::kHardEdge); @@ -182,21 +183,22 @@ TEST_F(ClipRectLayerTest, FullyContainedChild) { } TEST_F(ClipRectLayerTest, PartiallyContainedChild) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect local_cull_bounds = SkRect::MakeXYWH(0.0, 0.0, 4.0, 5.5); - const SkRect device_cull_bounds = initial_matrix.mapRect(local_cull_bounds); - const SkRect child_bounds = SkRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); - const SkRect clip_rect = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect local_cull_bounds = DlRect::MakeXYWH(0.0, 0.0, 4.0, 5.5); + const DlRect device_cull_bounds = + local_cull_bounds.TransformAndClipBounds(initial_matrix); + const DlRect child_bounds = DlRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); + const DlRect clip_rect = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(clip_rect, Clip::kHardEdge); layer->Add(mock_layer); - SkRect clip_cull_rect = clip_rect; - ASSERT_TRUE(clip_cull_rect.intersect(local_cull_bounds)); - SkRect clip_layer_bounds = clip_rect; - ASSERT_TRUE(clip_layer_bounds.intersect(child_bounds)); + auto clip_cull_rect = clip_rect.Intersection(local_cull_bounds); + ASSERT_TRUE(clip_cull_rect.has_value()); + auto clip_layer_bounds = clip_rect.Intersection(child_bounds); + ASSERT_TRUE(clip_layer_bounds.has_value()); // Cull child preroll_context()->state_stack.set_preroll_delegate(device_cull_bounds, @@ -209,11 +211,11 @@ TEST_F(ClipRectLayerTest, PartiallyContainedChild) { EXPECT_TRUE(preroll_context()->state_stack.is_empty()); EXPECT_EQ(mock_layer->paint_bounds(), child_bounds); - EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds); + EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds.value()); EXPECT_EQ(layer->child_paint_bounds(), child_bounds); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect); + EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect.value()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(clip_rect)})); @@ -236,7 +238,7 @@ static bool ReadbackResult(PrerollContext* context, Clip clip_behavior, const std::shared_ptr& child, bool before) { - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); auto layer = std::make_shared(layer_bounds, clip_behavior); if (child != nullptr) { layer->Add(child); @@ -248,7 +250,7 @@ static bool ReadbackResult(PrerollContext* context, TEST_F(ClipRectLayerTest, Readback) { PrerollContext* context = preroll_context(); - SkPath path; + DlPath path; DlPaint paint; const Clip hard = Clip::kHardEdge; @@ -292,9 +294,9 @@ TEST_F(ClipRectLayerTest, Readback) { } TEST_F(ClipRectLayerTest, OpacityInheritance) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - SkRect clip_rect = SkRect::MakeWH(500, 500); + DlRect clip_rect = DlRect::MakeWH(500, 500); auto clip_rect_layer = std::make_shared(clip_rect, Clip::kHardEdge); clip_rect_layer->Add(mock1); @@ -305,7 +307,7 @@ TEST_F(ClipRectLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); clip_rect_layer->Add(mock2); @@ -315,7 +317,7 @@ TEST_F(ClipRectLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path3 = SkPath().addRect({20, 20, 40, 40}); + auto path3 = DlPath::MakeRectLTRB(20, 20, 40, 40); auto mock3 = MockLayer::MakeOpacityCompatible(path3); clip_rect_layer->Add(mock3); @@ -342,7 +344,7 @@ TEST_F(ClipRectLayerTest, OpacityInheritance) { } // An incompatible, but non-overlapping child for the following tests - auto path4 = SkPath().addRect({60, 60, 70, 70}); + auto path4 = DlPath::MakeRectLTRB(60, 60, 70, 70); auto mock4 = MockLayer::Make(path4); { @@ -384,11 +386,11 @@ TEST_F(ClipRectLayerTest, OpacityInheritance) { } TEST_F(ClipRectLayerTest, OpacityInheritancePainting) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); - SkRect clip_rect = SkRect::MakeWH(500, 500); + DlRect clip_rect = DlRect::MakeWH(500, 500); auto clip_rect_layer = std::make_shared(clip_rect, Clip::kAntiAlias); clip_rect_layer->Add(mock1); @@ -402,7 +404,7 @@ TEST_F(ClipRectLayerTest, OpacityInheritancePainting) { LayerStateStack::kCallerCanApplyOpacity); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(clip_rect_layer); opacity_layer->Preroll(context); @@ -412,7 +414,7 @@ TEST_F(ClipRectLayerTest, OpacityInheritancePainting) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ClipRectLayer::Paint() */ { expected_builder.Save(); expected_builder.ClipRect(clip_rect, ClipOp::kIntersect, true); @@ -433,13 +435,12 @@ TEST_F(ClipRectLayerTest, OpacityInheritancePainting) { } TEST_F(ClipRectLayerTest, OpacityInheritanceSaveLayerPainting) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto path2 = SkPath().addRect({20, 20, 40, 40}); + auto path2 = DlPath::MakeRectLTRB(20, 20, 40, 40); auto mock2 = MockLayer::MakeOpacityCompatible(path2); - auto children_bounds = path1.getBounds(); - children_bounds.join(path2.getBounds()); - SkRect clip_rect = SkRect::MakeWH(500, 500); + auto children_bounds = path1.GetBounds().Union(path2.GetBounds()); + DlRect clip_rect = DlRect::MakeWH(500, 500); auto clip_rect_layer = std::make_shared(clip_rect, Clip::kAntiAliasWithSaveLayer); clip_rect_layer->Add(mock1); @@ -452,7 +453,7 @@ TEST_F(ClipRectLayerTest, OpacityInheritanceSaveLayerPainting) { EXPECT_EQ(context->renderable_state_flags, Layer::kSaveLayerRenderFlags); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(clip_rect_layer); opacity_layer->Preroll(context); @@ -462,11 +463,11 @@ TEST_F(ClipRectLayerTest, OpacityInheritanceSaveLayerPainting) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ClipRectLayer::Paint() */ { expected_builder.Save(); expected_builder.ClipRect(clip_rect, ClipOp::kIntersect, true); - expected_builder.SaveLayer(&children_bounds, + expected_builder.SaveLayer(children_bounds, &DlPaint().setAlpha(opacity_alpha)); /* child layer1 paint */ { expected_builder.DrawPath(path1, DlPaint()); @@ -485,15 +486,15 @@ TEST_F(ClipRectLayerTest, OpacityInheritanceSaveLayerPainting) { } TEST_F(ClipRectLayerTest, LayerCached) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - SkRect clip_rect = SkRect::MakeWH(500, 500); + DlRect clip_rect = DlRect::MakeWH(500, 500); auto layer = std::make_shared(clip_rect, Clip::kAntiAliasWithSaveLayer); layer->Add(mock1); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - SkMatrix cache_ctm = initial_transform; + auto initial_transform = DlMatrix::MakeTranslation({50.0, 25.5}); + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); @@ -524,13 +525,13 @@ TEST_F(ClipRectLayerTest, LayerCached) { } TEST_F(ClipRectLayerTest, EmptyClipDoesNotCullPlatformView) { - const SkPoint view_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize view_size = SkSize::Make(8.0f, 8.0f); + const DlPoint view_offset = DlPoint(0.0f, 0.0f); + const DlSize view_size = DlSize(8.0f, 8.0f); const int64_t view_id = 42; auto platform_view = std::make_shared(view_offset, view_size, view_id); - auto clip = std::make_shared(kEmptyRect, Clip::kHardEdge); + auto clip = std::make_shared(DlRect(), Clip::kHardEdge); clip->Add(platform_view); auto embedder = MockViewEmbedder(); diff --git a/flow/layers/clip_rrect_layer.cc b/flow/layers/clip_rrect_layer.cc index 87262cba5662d..134972b80e19d 100644 --- a/flow/layers/clip_rrect_layer.cc +++ b/flow/layers/clip_rrect_layer.cc @@ -6,11 +6,12 @@ namespace flutter { -ClipRRectLayer::ClipRRectLayer(const SkRRect& clip_rrect, Clip clip_behavior) +ClipRRectLayer::ClipRRectLayer(const DlRoundRect& clip_rrect, + Clip clip_behavior) : ClipShapeLayer(clip_rrect, clip_behavior) {} -const SkRect& ClipRRectLayer::clip_shape_bounds() const { - return clip_shape().getBounds(); +const DlRect ClipRRectLayer::clip_shape_bounds() const { + return clip_shape().GetBounds(); } void ClipRRectLayer::ApplyClip(LayerStateStack::MutatorContext& mutator) const { diff --git a/flow/layers/clip_rrect_layer.h b/flow/layers/clip_rrect_layer.h index 53b240abe2975..091eaf0e0f756 100644 --- a/flow/layers/clip_rrect_layer.h +++ b/flow/layers/clip_rrect_layer.h @@ -9,12 +9,12 @@ namespace flutter { -class ClipRRectLayer : public ClipShapeLayer { +class ClipRRectLayer : public ClipShapeLayer { public: - ClipRRectLayer(const SkRRect& clip_rrect, Clip clip_behavior); + ClipRRectLayer(const DlRoundRect& clip_rrect, Clip clip_behavior); protected: - const SkRect& clip_shape_bounds() const override; + const DlRect clip_shape_bounds() const override; void ApplyClip(LayerStateStack::MutatorContext& mutator) const override; diff --git a/flow/layers/clip_rrect_layer_unittests.cc b/flow/layers/clip_rrect_layer_unittests.cc index 3fc556d53b657..4b8ec8191e209 100644 --- a/flow/layers/clip_rrect_layer_unittests.cc +++ b/flow/layers/clip_rrect_layer_unittests.cc @@ -24,14 +24,14 @@ using ClipOp = DlCanvas::ClipOp; #ifndef NDEBUG TEST_F(ClipRRectLayerTest, ClipNoneBehaviorDies) { - const SkRRect layer_rrect = SkRRect::MakeEmpty(); + const DlRoundRect layer_rrect = DlRoundRect(); EXPECT_DEATH_IF_SUPPORTED( auto clip = std::make_shared(layer_rrect, Clip::kNone), "clip_behavior != Clip::kNone"); } TEST_F(ClipRRectLayerTest, PaintingEmptyLayerDies) { - const SkRRect layer_rrect = SkRRect::MakeEmpty(); + const DlRoundRect layer_rrect = DlRoundRect(); auto layer = std::make_shared(layer_rrect, Clip::kHardEdge); layer->Preroll(preroll_context()); @@ -40,8 +40,8 @@ TEST_F(ClipRRectLayerTest, PaintingEmptyLayerDies) { EXPECT_EQ(preroll_context()->state_stack.device_cull_rect(), kGiantRect); EXPECT_TRUE(preroll_context()->state_stack.is_empty()); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -49,11 +49,11 @@ TEST_F(ClipRRectLayerTest, PaintingEmptyLayerDies) { } TEST_F(ClipRRectLayerTest, PaintBeforePrerollDies) { - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkRRect layer_rrect = SkRRect::MakeRect(layer_bounds); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlRoundRect layer_rrect = DlRoundRect::MakeRect(layer_bounds); auto layer = std::make_shared(layer_rrect, Clip::kHardEdge); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -61,12 +61,12 @@ TEST_F(ClipRRectLayerTest, PaintBeforePrerollDies) { } TEST_F(ClipRRectLayerTest, PaintingCulledLayerDies) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkRect distant_bounds = SkRect::MakeXYWH(100.0, 100.0, 10.0, 10.0); - const SkPath child_path = SkPath().addRect(child_bounds); - const SkRRect layer_rrect = SkRRect::MakeRect(layer_bounds); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlRect distant_bounds = DlRect::MakeXYWH(100.0, 100.0, 10.0, 10.0); + const DlPath child_path = DlPath::MakeRect(child_bounds); + const DlRoundRect layer_rrect = DlRoundRect::MakeRect(layer_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(layer_rrect, Clip::kHardEdge); @@ -86,7 +86,7 @@ TEST_F(ClipRRectLayerTest, PaintingCulledLayerDies) { EXPECT_EQ(layer->child_paint_bounds(), child_bounds); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_cull_rect(), kEmptyRect); + EXPECT_EQ(mock_layer->parent_cull_rect(), DlRect()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_rrect)})); @@ -100,22 +100,23 @@ TEST_F(ClipRRectLayerTest, PaintingCulledLayerDies) { #endif TEST_F(ClipRRectLayerTest, ChildOutsideBounds) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect local_cull_bounds = SkRect::MakeXYWH(0.0, 0.0, 2.0, 4.0); - const SkRect device_cull_bounds = initial_matrix.mapRect(local_cull_bounds); - const SkRect child_bounds = SkRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); - const SkRect clip_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = SkPath().addRect(child_bounds); - const SkRRect clip_rrect = SkRRect::MakeRect(clip_bounds); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect local_cull_bounds = DlRect::MakeXYWH(0.0, 0.0, 2.0, 4.0); + const DlRect device_cull_bounds = + local_cull_bounds.TransformAndClipBounds(initial_matrix); + const DlRect child_bounds = DlRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); + const DlRect clip_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds); + const DlRoundRect clip_rrect = DlRoundRect::MakeRect(clip_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(clip_rrect, Clip::kHardEdge); layer->Add(mock_layer); - SkRect clip_cull_rect = clip_bounds; - ASSERT_TRUE(clip_cull_rect.intersect(local_cull_bounds)); - SkRect clip_layer_bounds = child_bounds; - ASSERT_TRUE(clip_layer_bounds.intersect(clip_bounds)); + auto clip_cull_rect = clip_bounds.Intersection(local_cull_bounds); + ASSERT_TRUE(clip_cull_rect.has_value()); + auto clip_layer_bounds = child_bounds.Intersection(clip_bounds); + ASSERT_TRUE(clip_layer_bounds.has_value()); // Set up both contexts to cull clipped child preroll_context()->state_stack.set_preroll_delegate(device_cull_bounds, @@ -132,9 +133,9 @@ TEST_F(ClipRRectLayerTest, ChildOutsideBounds) { EXPECT_TRUE(preroll_context()->state_stack.is_empty()); EXPECT_EQ(mock_layer->paint_bounds(), child_bounds); - EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds); + EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds.value()); EXPECT_EQ(layer->child_paint_bounds(), child_bounds); - EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect); + EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect.value()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(clip_rrect)})); @@ -145,12 +146,13 @@ TEST_F(ClipRRectLayerTest, ChildOutsideBounds) { } TEST_F(ClipRRectLayerTest, FullyContainedChild) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = - SkPath().addRect(child_bounds).addOval(child_bounds.makeInset(0.1, 0.1)); - const SkRRect layer_rrect = SkRRect::MakeRectXY(layer_bounds, 0.1, 0.1); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeXYWH(1.0, 2.0, 2.0, 2.0); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds) + + DlPath::MakeOval(child_bounds.Expand(-0.1f)); + const DlRoundRect layer_rrect = + DlRoundRect::MakeRectXY(layer_bounds, 0.1, 0.1); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(layer_rrect, Clip::kHardEdge); @@ -177,7 +179,7 @@ TEST_F(ClipRRectLayerTest, FullyContainedChild) { /* (ClipRRect)layer::Paint */ { expected_builder.Save(); { - expected_builder.ClipRRect(layer_rrect); + expected_builder.ClipRoundRect(layer_rrect); /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); } @@ -188,23 +190,24 @@ TEST_F(ClipRRectLayerTest, FullyContainedChild) { } TEST_F(ClipRRectLayerTest, PartiallyContainedChild) { - const SkMatrix initial_matrix = SkMatrix::Translate(0.5f, 1.0f); - const SkRect local_cull_bounds = SkRect::MakeXYWH(0.0, 0.0, 4.0, 5.5); - const SkRect device_cull_bounds = initial_matrix.mapRect(local_cull_bounds); - const SkRect child_bounds = SkRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); - const SkRect clip_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkPath child_path = - SkPath().addRect(child_bounds).addOval(child_bounds.makeInset(0.1, 0.1)); - const SkRRect clip_rrect = SkRRect::MakeRectXY(clip_bounds, 0.1, 0.1); + const DlMatrix initial_matrix = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect local_cull_bounds = DlRect::MakeXYWH(0.0, 0.0, 4.0, 5.5); + const DlRect device_cull_bounds = + local_cull_bounds.TransformAndClipBounds(initial_matrix); + const DlRect child_bounds = DlRect::MakeXYWH(2.5, 5.0, 4.5, 4.0); + const DlRect clip_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlPath child_path = DlPath::MakeRect(child_bounds) + + DlPath::MakeOval(child_bounds.Expand(-0.1f)); + const DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_bounds, 0.1, 0.1); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(clip_rrect, Clip::kHardEdge); layer->Add(mock_layer); - SkRect clip_cull_rect = clip_bounds; - ASSERT_TRUE(clip_cull_rect.intersect(local_cull_bounds)); - SkRect clip_layer_bounds = child_bounds; - ASSERT_TRUE(clip_layer_bounds.intersect(clip_bounds)); + auto clip_cull_rect = clip_bounds.Intersection(local_cull_bounds); + ASSERT_TRUE(clip_cull_rect.has_value()); + auto clip_layer_bounds = child_bounds.Intersection(clip_bounds); + ASSERT_TRUE(clip_layer_bounds.has_value()); preroll_context()->state_stack.set_preroll_delegate(device_cull_bounds, initial_matrix); @@ -218,9 +221,9 @@ TEST_F(ClipRRectLayerTest, PartiallyContainedChild) { EXPECT_TRUE(preroll_context()->state_stack.is_empty()); EXPECT_EQ(mock_layer->paint_bounds(), child_bounds); - EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds); + EXPECT_EQ(layer->paint_bounds(), clip_layer_bounds.value()); EXPECT_EQ(layer->child_paint_bounds(), child_bounds); - EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect); + EXPECT_EQ(mock_layer->parent_cull_rect(), clip_cull_rect.value()); EXPECT_EQ(mock_layer->parent_matrix(), initial_matrix); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(clip_rrect)})); @@ -229,7 +232,7 @@ TEST_F(ClipRRectLayerTest, PartiallyContainedChild) { /* (ClipRRect)layer::Paint */ { expected_builder.Save(); { - expected_builder.ClipRRect(clip_rrect); + expected_builder.ClipRoundRect(clip_rrect); /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); } @@ -243,8 +246,8 @@ static bool ReadbackResult(PrerollContext* context, Clip clip_behavior, const std::shared_ptr& child, bool before) { - const SkRect layer_bounds = SkRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); - const SkRRect layer_rrect = SkRRect::MakeRect(layer_bounds); + const DlRect layer_bounds = DlRect::MakeXYWH(0.5, 1.0, 5.0, 6.0); + const DlRoundRect layer_rrect = DlRoundRect::MakeRect(layer_bounds); auto layer = std::make_shared(layer_rrect, clip_behavior); if (child != nullptr) { layer->Add(child); @@ -256,7 +259,7 @@ static bool ReadbackResult(PrerollContext* context, TEST_F(ClipRRectLayerTest, Readback) { PrerollContext* context = preroll_context(); - SkPath path; + DlPath path; DlPaint paint; const Clip hard = Clip::kHardEdge; @@ -300,10 +303,10 @@ TEST_F(ClipRRectLayerTest, Readback) { } TEST_F(ClipRRectLayerTest, OpacityInheritance) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - SkRect clip_rect = SkRect::MakeWH(500, 500); - SkRRect clip_rrect = SkRRect::MakeRectXY(clip_rect, 20, 20); + DlRect clip_rect = DlRect::MakeWH(500, 500); + DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 20, 20); auto clip_rrect_layer = std::make_shared(clip_rrect, Clip::kHardEdge); clip_rrect_layer->Add(mock1); @@ -314,7 +317,7 @@ TEST_F(ClipRRectLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); clip_rrect_layer->Add(mock2); @@ -324,7 +327,7 @@ TEST_F(ClipRRectLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path3 = SkPath().addRect({20, 20, 40, 40}); + auto path3 = DlPath::MakeRectLTRB(20, 20, 40, 40); auto mock3 = MockLayer::MakeOpacityCompatible(path3); clip_rrect_layer->Add(mock3); @@ -351,7 +354,7 @@ TEST_F(ClipRRectLayerTest, OpacityInheritance) { } // An incompatible, but non-overlapping child for the following tests - auto path4 = SkPath().addRect({60, 60, 70, 70}); + auto path4 = DlPath::MakeRectLTRB(60, 60, 70, 70); auto mock4 = MockLayer::Make(path4); { @@ -393,12 +396,12 @@ TEST_F(ClipRRectLayerTest, OpacityInheritance) { } TEST_F(ClipRRectLayerTest, OpacityInheritancePainting) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); - SkRect clip_rect = SkRect::MakeWH(500, 500); - SkRRect clip_rrect = SkRRect::MakeRectXY(clip_rect, 20, 20); + DlRect clip_rect = DlRect::MakeWH(500, 500); + DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 20, 20); auto clip_rect_layer = std::make_shared(clip_rrect, Clip::kAntiAlias); clip_rect_layer->Add(mock1); @@ -412,7 +415,7 @@ TEST_F(ClipRRectLayerTest, OpacityInheritancePainting) { LayerStateStack::kCallerCanApplyOpacity); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(clip_rect_layer); opacity_layer->Preroll(context); @@ -422,10 +425,10 @@ TEST_F(ClipRRectLayerTest, OpacityInheritancePainting) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ClipRectLayer::Paint() */ { expected_builder.Save(); - expected_builder.ClipRRect(clip_rrect, ClipOp::kIntersect, true); + expected_builder.ClipRoundRect(clip_rrect, ClipOp::kIntersect, true); /* child layer1 paint */ { expected_builder.DrawPath(path1, DlPaint().setAlpha(opacity_alpha)); } @@ -443,14 +446,13 @@ TEST_F(ClipRRectLayerTest, OpacityInheritancePainting) { } TEST_F(ClipRRectLayerTest, OpacityInheritanceSaveLayerPainting) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto path2 = SkPath().addRect({20, 20, 40, 40}); + auto path2 = DlPath::MakeRectLTRB(20, 20, 40, 40); auto mock2 = MockLayer::MakeOpacityCompatible(path2); - auto children_bounds = path1.getBounds(); - children_bounds.join(path2.getBounds()); - SkRect clip_rect = SkRect::MakeWH(500, 500); - SkRRect clip_rrect = SkRRect::MakeRectXY(clip_rect, 20, 20); + auto children_bounds = path1.GetBounds().Union(path2.GetBounds()); + DlRect clip_rect = DlRect::MakeWH(500, 500); + DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 20, 20); auto clip_rrect_layer = std::make_shared( clip_rrect, Clip::kAntiAliasWithSaveLayer); clip_rrect_layer->Add(mock1); @@ -463,7 +465,7 @@ TEST_F(ClipRRectLayerTest, OpacityInheritanceSaveLayerPainting) { EXPECT_EQ(context->renderable_state_flags, Layer::kSaveLayerRenderFlags); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(clip_rrect_layer); opacity_layer->Preroll(context); @@ -473,11 +475,11 @@ TEST_F(ClipRRectLayerTest, OpacityInheritanceSaveLayerPainting) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ClipRectLayer::Paint() */ { expected_builder.Save(); - expected_builder.ClipRRect(clip_rrect, ClipOp::kIntersect, true); - expected_builder.SaveLayer(&children_bounds, + expected_builder.ClipRoundRect(clip_rrect, ClipOp::kIntersect, true); + expected_builder.SaveLayer(children_bounds, &DlPaint().setAlpha(opacity_alpha)); /* child layer1 paint */ { expected_builder.DrawPath(path1, DlPaint()); @@ -496,17 +498,17 @@ TEST_F(ClipRRectLayerTest, OpacityInheritanceSaveLayerPainting) { } TEST_F(ClipRRectLayerTest, LayerCached) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); DlPaint paint = DlPaint(); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - SkRect clip_rect = SkRect::MakeWH(500, 500); - SkRRect clip_rrect = SkRRect::MakeRectXY(clip_rect, 20, 20); + DlRect clip_rect = DlRect::MakeWH(500, 500); + DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 20, 20); auto layer = std::make_shared(clip_rrect, Clip::kAntiAliasWithSaveLayer); layer->Add(mock1); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - SkMatrix cache_ctm = initial_transform; + auto initial_transform = DlMatrix::MakeTranslation({50.0, 25.5}); + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); @@ -536,18 +538,15 @@ TEST_F(ClipRRectLayerTest, LayerCached) { } TEST_F(ClipRRectLayerTest, NoSaveLayerShouldNotCache) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - SkRect clip_rect = SkRect::MakeWH(500, 500); - SkRRect clip_rrect = SkRRect::MakeRectXY(clip_rect, 20, 20); + DlRect clip_rect = DlRect::MakeWH(500, 500); + DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(clip_rect, 20, 20); auto layer = std::make_shared(clip_rrect, Clip::kAntiAlias); layer->Add(mock1); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - SkMatrix cache_ctm = initial_transform; - SkCanvas cache_canvas; - cache_canvas.setMatrix(cache_ctm); + auto initial_transform = DlMatrix::MakeTranslation({50.0, 25.5}); use_mock_raster_cache(); preroll_context()->state_stack.set_preroll_delegate(initial_transform); @@ -572,13 +571,13 @@ TEST_F(ClipRRectLayerTest, NoSaveLayerShouldNotCache) { } TEST_F(ClipRRectLayerTest, EmptyClipDoesNotCullPlatformView) { - const SkPoint view_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize view_size = SkSize::Make(8.0f, 8.0f); + const DlPoint view_offset = DlPoint(0.0f, 0.0f); + const DlSize view_size = DlSize(8.0f, 8.0f); const int64_t view_id = 42; auto platform_view = std::make_shared(view_offset, view_size, view_id); - SkRRect clip_rrect = SkRRect::MakeRectXY(kEmptyRect, 20, 20); + DlRoundRect clip_rrect = DlRoundRect::MakeRectXY(DlRect(), 20, 20); auto clip = std::make_shared(clip_rrect, Clip::kAntiAlias); clip->Add(platform_view); diff --git a/flow/layers/clip_shape_layer.h b/flow/layers/clip_shape_layer.h index 8f26bf4229ed9..d2baa33b4272c 100644 --- a/flow/layers/clip_shape_layer.h +++ b/flow/layers/clip_shape_layer.h @@ -50,7 +50,7 @@ class ClipShapeLayer : public CacheableContainerLayer { // nullptr which mean we don't do raster cache logic. AutoCache cache = AutoCache(uses_save_layer ? layer_raster_cache_item_.get() : nullptr, - context, context->state_stack.transform_3x3()); + context, context->state_stack.matrix()); #endif // !SLIMPELLER Layer::AutoPrerollSaveLayerState save = @@ -59,13 +59,10 @@ class ClipShapeLayer : public CacheableContainerLayer { auto mutator = context->state_stack.save(); ApplyClip(mutator); - SkRect child_paint_bounds = SkRect::MakeEmpty(); + DlRect child_paint_bounds; PrerollChildren(context, &child_paint_bounds); - if (child_paint_bounds.intersect(clip_shape_bounds())) { - set_paint_bounds(child_paint_bounds); - } else { - set_paint_bounds(SkRect::MakeEmpty()); - } + set_paint_bounds( + child_paint_bounds.IntersectionOrEmpty(clip_shape_bounds())); // If we use a SaveLayer then we can accept opacity on behalf // of our children and apply it in the saveLayer. @@ -108,7 +105,7 @@ class ClipShapeLayer : public CacheableContainerLayer { } protected: - virtual const SkRect& clip_shape_bounds() const = 0; + virtual const DlRect clip_shape_bounds() const = 0; virtual void ApplyClip(LayerStateStack::MutatorContext& mutator) const = 0; virtual ~ClipShapeLayer() = default; diff --git a/flow/layers/color_filter_layer.cc b/flow/layers/color_filter_layer.cc index 19173b088db8f..d312fa8a2d20d 100644 --- a/flow/layers/color_filter_layer.cc +++ b/flow/layers/color_filter_layer.cc @@ -41,7 +41,7 @@ void ColorFilterLayer::Preroll(PrerollContext* context) { Layer::AutoPrerollSaveLayerState::Create(context); #if !SLIMPELLER AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, - context->state_stack.transform_3x3()); + context->state_stack.matrix()); #endif // !SLIMPELLER ContainerLayer::Preroll(context); diff --git a/flow/layers/color_filter_layer_unittests.cc b/flow/layers/color_filter_layer_unittests.cc index c43ca5d6f9ac6..73bee53eaa895 100644 --- a/flow/layers/color_filter_layer_unittests.cc +++ b/flow/layers/color_filter_layer_unittests.cc @@ -30,8 +30,8 @@ TEST_F(ColorFilterLayerTest, PaintingEmptyLayerDies) { auto layer = std::make_shared(nullptr); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -39,24 +39,24 @@ TEST_F(ColorFilterLayerTest, PaintingEmptyLayerDies) { } TEST_F(ColorFilterLayerTest, PaintBeforePrerollDies) { - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); auto mock_layer = std::make_shared(child_path); auto layer = std::make_shared(nullptr); layer->Add(mock_layer); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), "needs_painting\\(context\\)"); } #endif TEST_F(ColorFilterLayerTest, EmptyFilter) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(nullptr); @@ -84,9 +84,9 @@ TEST_F(ColorFilterLayerTest, EmptyFilter) { } TEST_F(ColorFilterLayerTest, SimpleFilter) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto dl_color_filter = DlColorFilter::MakeLinearToSrgbGamma(); @@ -105,7 +105,7 @@ TEST_F(ColorFilterLayerTest, SimpleFilter) { /* ColorFilterLayer::Paint() */ { DlPaint dl_paint; dl_paint.setColorFilter(dl_color_filter.get()); - expected_builder.SaveLayer(&child_bounds, &dl_paint); + expected_builder.SaveLayer(child_bounds, &dl_paint); { /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path, DlPaint(DlColor::kYellow())); @@ -120,11 +120,10 @@ TEST_F(ColorFilterLayerTest, SimpleFilter) { } TEST_F(ColorFilterLayerTest, MultipleChildren) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); - const SkPath child_path1 = SkPath().addRect(child_bounds); - const SkPath child_path2 = - SkPath().addRect(child_bounds.makeOffset(3.0f, 0.0f)); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); + const DlPath child_path1 = DlPath::MakeRect(child_bounds); + const DlPath child_path2 = DlPath::MakeRect(child_bounds.Shift(3.0f, 0.0f)); const DlPaint child_paint1 = DlPaint(DlColor::kYellow()); const DlPaint child_paint2 = DlPaint(DlColor::kCyan()); auto mock_layer1 = std::make_shared(child_path1, child_paint1); @@ -134,12 +133,12 @@ TEST_F(ColorFilterLayerTest, MultipleChildren) { layer->Add(mock_layer1); layer->Add(mock_layer2); - SkRect children_bounds = child_path1.getBounds(); - children_bounds.join(child_path2.getBounds()); + DlRect children_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer->paint_bounds(), children_bounds); EXPECT_EQ(layer->child_paint_bounds(), children_bounds); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); @@ -152,7 +151,7 @@ TEST_F(ColorFilterLayerTest, MultipleChildren) { /* ColorFilterLayer::Paint() */ { DlPaint dl_paint; dl_paint.setColorFilter(dl_color_filter.get()); - expected_builder.SaveLayer(&children_bounds, &dl_paint); + expected_builder.SaveLayer(children_bounds, &dl_paint); { /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path1, DlPaint(DlColor::kYellow())); @@ -170,11 +169,10 @@ TEST_F(ColorFilterLayerTest, MultipleChildren) { } TEST_F(ColorFilterLayerTest, Nested) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); - const SkPath child_path1 = SkPath().addRect(child_bounds); - const SkPath child_path2 = - SkPath().addRect(child_bounds.makeOffset(3.0f, 0.0f)); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); + const DlPath child_path1 = DlPath::MakeRect(child_bounds); + const DlPath child_path2 = DlPath::MakeRect(child_bounds.Shift(3.0f, 0.0f)); const DlPaint child_paint1 = DlPaint(DlColor::kYellow()); const DlPaint child_paint2 = DlPaint(DlColor::kCyan()); auto mock_layer1 = std::make_shared(child_path1, child_paint1); @@ -187,12 +185,12 @@ TEST_F(ColorFilterLayerTest, Nested) { layer1->Add(mock_layer1); layer1->Add(layer2); - SkRect children_bounds = child_path1.getBounds(); - children_bounds.join(child_path2.getBounds()); + const DlRect children_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer1->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer1->paint_bounds(), children_bounds); EXPECT_EQ(layer1->child_paint_bounds(), children_bounds); EXPECT_EQ(layer2->paint_bounds(), mock_layer2->paint_bounds()); @@ -208,7 +206,7 @@ TEST_F(ColorFilterLayerTest, Nested) { /* ColorFilterLayer::Paint() */ { DlPaint dl_paint; dl_paint.setColorFilter(dl_color_filter.get()); - expected_builder.SaveLayer(&children_bounds, &dl_paint); + expected_builder.SaveLayer(children_bounds, &dl_paint); { /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path1, DlPaint(DlColor::kYellow())); @@ -217,7 +215,7 @@ TEST_F(ColorFilterLayerTest, Nested) { DlPaint child_dl_paint; child_dl_paint.setColor(DlColor::kBlack()); child_dl_paint.setColorFilter(dl_color_filter.get()); - expected_builder.SaveLayer(&child_path2.getBounds(), &child_dl_paint); + expected_builder.SaveLayer(child_path2.GetBounds(), &child_dl_paint); /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path2, DlPaint(DlColor::kCyan())); @@ -235,7 +233,7 @@ TEST_F(ColorFilterLayerTest, Nested) { } TEST_F(ColorFilterLayerTest, Readback) { - auto initial_transform = SkMatrix(); + DlMatrix initial_transform; // ColorFilterLayer does not read from surface auto layer = std::make_shared( @@ -246,7 +244,7 @@ TEST_F(ColorFilterLayerTest, Readback) { EXPECT_FALSE(preroll_context()->surface_needs_readback); // ColorFilterLayer blocks child with readback - auto mock_layer = std::make_shared(SkPath(), DlPaint()); + auto mock_layer = std::make_shared(DlPath(), DlPaint()); mock_layer->set_fake_reads_surface(true); layer->Add(mock_layer); preroll_context()->surface_needs_readback = false; @@ -256,15 +254,15 @@ TEST_F(ColorFilterLayerTest, Readback) { TEST_F(ColorFilterLayerTest, CacheChild) { auto layer_filter = DlColorFilter::MakeSrgbToLinearGamma(); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - auto other_transform = SkMatrix::Scale(1.0, 2.0); - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + auto initial_transform = DlMatrix::MakeTranslation({50.0f, 25.5f}); + auto other_transform = DlMatrix::MakeScale({1.0f, 2.0f, 1.0f}); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); DlPaint paint = DlPaint(); auto mock_layer = std::make_shared(child_path); auto layer = std::make_shared(layer_filter); layer->Add(mock_layer); - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); DisplayListBuilder other_canvas; @@ -297,10 +295,10 @@ TEST_F(ColorFilterLayerTest, CacheChild) { TEST_F(ColorFilterLayerTest, CacheChildren) { auto layer_filter = DlColorFilter::MakeSrgbToLinearGamma(); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - auto other_transform = SkMatrix::Scale(1.0, 2.0); - const SkPath child_path1 = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); - const SkPath child_path2 = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + auto initial_transform = DlMatrix::MakeTranslation({50.0f, 25.5f}); + auto other_transform = DlMatrix::MakeScale({1.0f, 2.0f, 1.0f}); + const DlPath child_path1 = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); + const DlPath child_path2 = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); auto mock_layer1 = std::make_shared(child_path1); auto mock_layer2 = std::make_shared(child_path2); auto layer = std::make_shared(layer_filter); @@ -308,7 +306,7 @@ TEST_F(ColorFilterLayerTest, CacheChildren) { layer->Add(mock_layer2); DlPaint paint = DlPaint(); - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); DisplayListBuilder other_canvas; @@ -343,10 +341,10 @@ TEST_F(ColorFilterLayerTest, CacheChildren) { TEST_F(ColorFilterLayerTest, CacheColorFilterLayerSelf) { auto layer_filter = DlColorFilter::MakeSrgbToLinearGamma(); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - auto other_transform = SkMatrix::Scale(1.0, 2.0); - const SkPath child_path1 = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); - const SkPath child_path2 = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + auto initial_transform = DlMatrix::MakeTranslation({50.0, 25.5}); + auto other_transform = DlMatrix::MakeScale({1.0, 2.0, 1.0f}); + const DlPath child_path1 = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); + const DlPath child_path2 = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); auto mock_layer1 = std::make_shared(child_path1); auto mock_layer2 = std::make_shared(child_path2); auto layer = std::make_shared(layer_filter); @@ -354,7 +352,7 @@ TEST_F(ColorFilterLayerTest, CacheColorFilterLayerSelf) { layer->Add(mock_layer2); DlPaint paint = DlPaint(); - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); DisplayListBuilder other_canvas; @@ -409,8 +407,8 @@ TEST_F(ColorFilterLayerTest, OpacityInheritance) { }; // clang-format on auto layer_filter = DlColorFilter::MakeMatrix(matrix); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + auto initial_transform = DlMatrix::MakeTranslation({50.0, 25.5}); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); auto mock_layer = std::make_shared(child_path); auto color_filter_layer = std::make_shared(DlColorFilter::MakeMatrix(matrix)); @@ -425,10 +423,10 @@ TEST_F(ColorFilterLayerTest, OpacityInheritance) { LayerStateStack::kCallerCanApplyOpacity); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(color_filter_layer); - preroll_context()->state_stack.set_preroll_delegate(SkMatrix::I()); + preroll_context()->state_stack.set_preroll_delegate(DlMatrix()); opacity_layer->Preroll(context); EXPECT_TRUE(opacity_layer->children_can_accept_opacity()); @@ -436,12 +434,12 @@ TEST_F(ColorFilterLayerTest, OpacityInheritance) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ColorFilterLayer::Paint() */ { DlPaint dl_paint; dl_paint.setColor(DlColor(opacity_alpha << 24)); dl_paint.setColorFilter(layer_filter); - expected_builder.SaveLayer(&child_path.getBounds(), &dl_paint); + expected_builder.SaveLayer(child_path.GetBounds(), &dl_paint); /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path, DlPaint(DlColor(0xFF000000))); } diff --git a/flow/layers/container_layer.cc b/flow/layers/container_layer.cc index 74829417f2432..4554255cf0549 100644 --- a/flow/layers/container_layer.cc +++ b/flow/layers/container_layer.cc @@ -8,7 +8,7 @@ namespace flutter { -ContainerLayer::ContainerLayer() : child_paint_bounds_(SkRect::MakeEmpty()) {} +ContainerLayer::ContainerLayer() {} void ContainerLayer::Diff(DiffContext* context, const Layer* old_layer) { auto old_container = static_cast(old_layer); @@ -108,7 +108,7 @@ void ContainerLayer::Add(std::shared_ptr layer) { } void ContainerLayer::Preroll(PrerollContext* context) { - SkRect child_paint_bounds = SkRect::MakeEmpty(); + DlRect child_paint_bounds; PrerollChildren(context, &child_paint_bounds); set_paint_bounds(child_paint_bounds); } @@ -119,15 +119,8 @@ void ContainerLayer::Paint(PaintContext& context) const { PaintChildren(context); } -static bool safe_intersection_test(const SkRect* rect1, const SkRect& rect2) { - if (rect1->isEmpty() || rect2.isEmpty()) { - return false; - } - return rect1->intersects(rect2); -} - void ContainerLayer::PrerollChildren(PrerollContext* context, - SkRect* child_paint_bounds) { + DlRect* child_paint_bounds) { // Platform views have no children, so context->has_platform_view should // always be false. FML_DCHECK(!context->has_platform_view); @@ -151,13 +144,13 @@ void ContainerLayer::PrerollChildren(PrerollContext* context, layer->Preroll(context); all_renderable_state_flags &= context->renderable_state_flags; - if (safe_intersection_test(child_paint_bounds, layer->paint_bounds())) { + if (child_paint_bounds->IntersectsWithRect(layer->paint_bounds())) { // This will allow inheritance by a linear sequence of non-overlapping // children, but will fail with a grid or other arbitrary 2D layout. // See https://github.com/flutter/flutter/issues/93899 all_renderable_state_flags = 0; } - child_paint_bounds->join(layer->paint_bounds()); + *child_paint_bounds = child_paint_bounds->Union(layer->paint_bounds()); child_has_platform_view = child_has_platform_view || context->has_platform_view; diff --git a/flow/layers/container_layer.h b/flow/layers/container_layer.h index 638d951e1568f..1cfbfb8786d85 100644 --- a/flow/layers/container_layer.h +++ b/flow/layers/container_layer.h @@ -32,8 +32,8 @@ class ContainerLayer : public Layer { const ContainerLayer* as_container_layer() const override { return this; } - const SkRect& child_paint_bounds() const { return child_paint_bounds_; } - void set_child_paint_bounds(const SkRect& bounds) { + const DlRect& child_paint_bounds() const { return child_paint_bounds_; } + void set_child_paint_bounds(const DlRect& bounds) { child_paint_bounds_ = bounds; } @@ -45,11 +45,11 @@ class ContainerLayer : public Layer { } protected: - void PrerollChildren(PrerollContext* context, SkRect* child_paint_bounds); + void PrerollChildren(PrerollContext* context, DlRect* child_paint_bounds); private: std::vector> layers_; - SkRect child_paint_bounds_; + DlRect child_paint_bounds_; int children_renderable_state_flags_ = 0; FML_DISALLOW_COPY_AND_ASSIGN(ContainerLayer); diff --git a/flow/layers/container_layer_unittests.cc b/flow/layers/container_layer_unittests.cc index 206be009966a7..75daed0f693e9 100644 --- a/flow/layers/container_layer_unittests.cc +++ b/flow/layers/container_layer_unittests.cc @@ -11,7 +11,6 @@ #include "flutter/flow/testing/mock_layer.h" #include "flutter/fml/macros.h" #include "gtest/gtest.h" -#include "include/core/SkMatrix.h" // TODO(zanderso): https://github.com/flutter/flutter/issues/127701 // NOLINTBEGIN(bugprone-unchecked-optional-access) @@ -42,8 +41,8 @@ TEST_F(ContainerLayerTest, PaintingEmptyLayerDies) { auto layer = std::make_shared(); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty()); - EXPECT_EQ(layer->child_paint_bounds(), SkRect::MakeEmpty()); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -51,24 +50,21 @@ TEST_F(ContainerLayerTest, PaintingEmptyLayerDies) { } TEST_F(ContainerLayerTest, PaintBeforePrerollDies) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); + DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); auto mock_layer = std::make_shared(child_path); auto layer = std::make_shared(); layer->Add(mock_layer); - EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty()); - EXPECT_EQ(layer->child_paint_bounds(), SkRect::MakeEmpty()); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), "needs_painting\\(context\\)"); } #endif TEST_F(ContainerLayerTest, LayerWithParentHasTextureLayerNeedsResetFlag) { - SkPath child_path1; - child_path1.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkPath child_path2; - child_path2.addRect(8.0f, 2.0f, 16.5f, 14.5f); + DlPath child_path1 = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlPath child_path2 = DlPath::MakeRectLTRB(8.0f, 2.0f, 16.5f, 14.5f); DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); DlPaint child_paint2 = DlPaint(DlColor::kGreen()); @@ -92,10 +88,9 @@ TEST_F(ContainerLayerTest, LayerWithParentHasTextureLayerNeedsResetFlag) { } TEST_F(ContainerLayerTest, Simple) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); + DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); DlPaint child_paint = DlPaint(DlColor::kGreen()); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-0.5f, -0.5f}); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(); @@ -104,8 +99,8 @@ TEST_F(ContainerLayerTest, Simple) { preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); EXPECT_FALSE(preroll_context()->has_platform_view); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); - EXPECT_EQ(layer->paint_bounds(), child_path.getBounds()); + EXPECT_EQ(mock_layer->paint_bounds(), child_path.GetBounds()); + EXPECT_EQ(layer->paint_bounds(), child_path.GetBounds()); EXPECT_EQ(layer->child_paint_bounds(), layer->paint_bounds()); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); @@ -123,13 +118,11 @@ TEST_F(ContainerLayerTest, Simple) { } TEST_F(ContainerLayerTest, Multiple) { - SkPath child_path1; - child_path1.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkPath child_path2; - child_path2.addRect(8.0f, 2.0f, 16.5f, 14.5f); + DlPath child_path1 = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlPath child_path2 = DlPath::MakeRectLTRB(8.0f, 2.0f, 16.5f, 14.5f); DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); DlPaint child_paint2 = DlPaint(DlColor::kGreen()); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-0.5f, -0.5f}); auto mock_layer1 = std::make_shared(child_path1, child_paint1); mock_layer1->set_fake_has_platform_view(true); @@ -138,13 +131,13 @@ TEST_F(ContainerLayerTest, Multiple) { layer->Add(mock_layer1); layer->Add(mock_layer2); - SkRect expected_total_bounds = child_path1.getBounds(); - expected_total_bounds.join(child_path2.getBounds()); + DlRect expected_total_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); EXPECT_TRUE(preroll_context()->has_platform_view); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer->paint_bounds(), expected_total_bounds); EXPECT_EQ(layer->child_paint_bounds(), layer->paint_bounds()); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); @@ -170,14 +163,13 @@ TEST_F(ContainerLayerTest, Multiple) { } TEST_F(ContainerLayerTest, MultipleWithEmpty) { - SkPath child_path1; - child_path1.addRect(5.0f, 6.0f, 20.5f, 21.5f); + DlPath child_path1 = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); DlPaint child_paint2 = DlPaint(DlColor::kGreen()); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-0.5f, -0.5f}); auto mock_layer1 = std::make_shared(child_path1, child_paint1); - auto mock_layer2 = std::make_shared(SkPath(), child_paint2); + auto mock_layer2 = std::make_shared(DlPath(), child_paint2); auto layer = std::make_shared(); layer->Add(mock_layer1); layer->Add(mock_layer2); @@ -185,9 +177,9 @@ TEST_F(ContainerLayerTest, MultipleWithEmpty) { preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); EXPECT_FALSE(preroll_context()->has_platform_view); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), SkPath().getBounds()); - EXPECT_EQ(layer->paint_bounds(), child_path1.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), DlPath().GetBounds()); + EXPECT_EQ(layer->paint_bounds(), child_path1.GetBounds()); EXPECT_EQ(layer->child_paint_bounds(), layer->paint_bounds()); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); EXPECT_FALSE(mock_layer2->needs_painting(paint_context())); @@ -209,13 +201,11 @@ TEST_F(ContainerLayerTest, MultipleWithEmpty) { } TEST_F(ContainerLayerTest, NeedsSystemComposite) { - SkPath child_path1; - child_path1.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkPath child_path2; - child_path2.addRect(8.0f, 2.0f, 16.5f, 14.5f); + DlPath child_path1 = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlPath child_path2 = DlPath::MakeRectLTRB(8.0f, 2.0f, 16.5f, 14.5f); DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); DlPaint child_paint2 = DlPaint(DlColor::kGreen()); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-0.5f, -0.5f}); auto mock_layer1 = std::make_shared(child_path1, child_paint1); mock_layer1->set_fake_has_platform_view(false); @@ -224,13 +214,13 @@ TEST_F(ContainerLayerTest, NeedsSystemComposite) { layer->Add(mock_layer1); layer->Add(mock_layer2); - SkRect expected_total_bounds = child_path1.getBounds(); - expected_total_bounds.join(child_path2.getBounds()); + DlRect expected_total_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); EXPECT_FALSE(preroll_context()->has_platform_view); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer->paint_bounds(), expected_total_bounds); EXPECT_EQ(layer->child_paint_bounds(), layer->paint_bounds()); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); @@ -256,9 +246,9 @@ TEST_F(ContainerLayerTest, NeedsSystemComposite) { TEST_F(ContainerLayerTest, RasterCacheTest) { // LTRB - const SkPath child_path1 = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path2 = SkPath().addRect(21.0f, 6.0f, 25.5f, 21.5f); - const SkPath child_path3 = SkPath().addRect(26.0f, 6.0f, 30.5f, 21.5f); + const DlPath child_path1 = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path2 = DlPath::MakeRectLTRB(21.0f, 6.0f, 25.5f, 21.5f); + const DlPath child_path3 = DlPath::MakeRectLTRB(26.0f, 6.0f, 30.5f, 21.5f); const DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); const DlPaint child_paint2 = DlPaint(DlColor::kGreen()); const DlPaint paint; @@ -289,7 +279,7 @@ TEST_F(ContainerLayerTest, RasterCacheTest) { // clang-format on auto mock_layer1 = std::make_shared(child_path1, child_paint1); - auto mock_layer2 = std::make_shared(SkPath(), child_paint2); + auto mock_layer2 = std::make_shared(DlPath(), child_paint2); auto mock_layer3 = std::make_shared(child_path2, paint); cacheable_container_layer1->Add(mock_layer1); @@ -311,13 +301,13 @@ TEST_F(ContainerLayerTest, RasterCacheTest) { layer->Preroll(preroll_context()); EXPECT_EQ(mock_layer1->paint_bounds(), - SkRect::MakeLTRB(5.f, 6.f, 20.5f, 21.5f)); + DlRect::MakeLTRB(5.f, 6.f, 20.5f, 21.5f)); EXPECT_EQ(mock_layer3->paint_bounds(), - SkRect::MakeLTRB(21.0f, 6.0f, 25.5f, 21.5f)); + DlRect::MakeLTRB(21.0f, 6.0f, 25.5f, 21.5f)); EXPECT_EQ(cacheable_layer111->paint_bounds(), - SkRect::MakeLTRB(26.0f, 6.0f, 30.5f, 21.5f)); + DlRect::MakeLTRB(26.0f, 6.0f, 30.5f, 21.5f)); EXPECT_EQ(cacheable_container_layer1->paint_bounds(), - SkRect::MakeLTRB(5.f, 6.f, 30.5f, 21.5f)); + DlRect::MakeLTRB(5.f, 6.f, 30.5f, 21.5f)); // the preroll context's raster cache is nullptr EXPECT_EQ(preroll_context()->raster_cached_entries->size(), @@ -476,7 +466,7 @@ TEST_F(ContainerLayerTest, RasterCacheTest) { } TEST_F(ContainerLayerTest, OpacityInheritance) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); auto container1 = std::make_shared(); container1->Add(mock1); @@ -487,7 +477,7 @@ TEST_F(ContainerLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); container1->Add(mock2); @@ -497,7 +487,7 @@ TEST_F(ContainerLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path3 = SkPath().addRect({20, 20, 40, 40}); + auto path3 = DlPath::MakeRectLTRB(20, 20, 40, 40); auto mock3 = MockLayer::MakeOpacityCompatible(path3); container1->Add(mock3); @@ -515,7 +505,7 @@ TEST_F(ContainerLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path4 = SkPath().addRect({60, 60, 70, 70}); + auto path4 = DlPath::MakeRectLTRB(60, 60, 70, 70); auto mock4 = MockLayer::Make(path4); container2->Add(mock4); @@ -526,12 +516,11 @@ TEST_F(ContainerLayerTest, OpacityInheritance) { } TEST_F(ContainerLayerTest, CollectionCacheableLayer) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); + DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); DlPaint child_paint = DlPaint(DlColor::kGreen()); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-0.5f, -0.5f}); - auto mock_layer1 = std::make_shared(SkPath(), child_paint); + auto mock_layer1 = std::make_shared(DlPath(), child_paint); auto mock_cacheable_container_layer1 = std::make_shared(); auto mock_container_layer = std::make_shared(); @@ -564,9 +553,9 @@ using ContainerLayerDiffTest = DiffContextTest; // Insert PictureLayer amongst container layers TEST_F(ContainerLayerDiffTest, PictureLayerInsertion) { - auto pic1 = CreateDisplayList(SkRect::MakeLTRB(0, 0, 50, 50)); - auto pic2 = CreateDisplayList(SkRect::MakeLTRB(100, 0, 150, 50)); - auto pic3 = CreateDisplayList(SkRect::MakeLTRB(200, 0, 250, 50)); + auto pic1 = CreateDisplayList(DlRect::MakeLTRB(0, 0, 50, 50)); + auto pic2 = CreateDisplayList(DlRect::MakeLTRB(100, 0, 150, 50)); + auto pic3 = CreateDisplayList(DlRect::MakeLTRB(200, 0, 250, 50)); MockLayerTree t1; @@ -577,7 +566,7 @@ TEST_F(ContainerLayerDiffTest, PictureLayerInsertion) { t1.root()->Add(t1_c2); auto damage = DiffLayerTree(t1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 150, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 150, 50)); // Add in the middle @@ -593,7 +582,7 @@ TEST_F(ContainerLayerDiffTest, PictureLayerInsertion) { t2.root()->Add(t2_c2); damage = DiffLayerTree(t2, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 0, 250, 50)); // Add in the beginning @@ -602,7 +591,7 @@ TEST_F(ContainerLayerDiffTest, PictureLayerInsertion) { t2.root()->Add(t2_c1); t2.root()->Add(t2_c2); damage = DiffLayerTree(t2, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 0, 250, 50)); // Add at the end @@ -611,21 +600,21 @@ TEST_F(ContainerLayerDiffTest, PictureLayerInsertion) { t2.root()->Add(t2_c2); t2.root()->Add(CreateDisplayListLayer(pic3)); damage = DiffLayerTree(t2, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 0, 250, 50)); } // Insert picture layer amongst other picture layers TEST_F(ContainerLayerDiffTest, PictureInsertion) { - auto pic1 = CreateDisplayList(SkRect::MakeLTRB(0, 0, 50, 50)); - auto pic2 = CreateDisplayList(SkRect::MakeLTRB(100, 0, 150, 50)); - auto pic3 = CreateDisplayList(SkRect::MakeLTRB(200, 0, 250, 50)); + auto pic1 = CreateDisplayList(DlRect::MakeLTRB(0, 0, 50, 50)); + auto pic2 = CreateDisplayList(DlRect::MakeLTRB(100, 0, 150, 50)); + auto pic3 = CreateDisplayList(DlRect::MakeLTRB(200, 0, 250, 50)); MockLayerTree t1; t1.root()->Add(CreateDisplayListLayer(pic1)); t1.root()->Add(CreateDisplayListLayer(pic2)); auto damage = DiffLayerTree(t1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 150, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 150, 50)); MockLayerTree t2; t2.root()->Add(CreateDisplayListLayer(pic3)); @@ -633,7 +622,7 @@ TEST_F(ContainerLayerDiffTest, PictureInsertion) { t2.root()->Add(CreateDisplayListLayer(pic2)); damage = DiffLayerTree(t2, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 0, 250, 50)); MockLayerTree t3; t3.root()->Add(CreateDisplayListLayer(pic1)); @@ -641,7 +630,7 @@ TEST_F(ContainerLayerDiffTest, PictureInsertion) { t3.root()->Add(CreateDisplayListLayer(pic2)); damage = DiffLayerTree(t3, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 0, 250, 50)); MockLayerTree t4; t4.root()->Add(CreateDisplayListLayer(pic1)); @@ -649,13 +638,13 @@ TEST_F(ContainerLayerDiffTest, PictureInsertion) { t4.root()->Add(CreateDisplayListLayer(pic3)); damage = DiffLayerTree(t4, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 0, 250, 50)); } TEST_F(ContainerLayerDiffTest, LayerDeletion) { - auto path1 = SkPath().addRect(SkRect::MakeLTRB(0, 0, 50, 50)); - auto path2 = SkPath().addRect(SkRect::MakeLTRB(100, 0, 150, 50)); - auto path3 = SkPath().addRect(SkRect::MakeLTRB(200, 0, 250, 50)); + auto path1 = DlPath::MakeRectLTRB(0, 0, 50, 50); + auto path2 = DlPath::MakeRectLTRB(100, 0, 150, 50); + auto path3 = DlPath::MakeRectLTRB(200, 0, 250, 50); auto c1 = CreateContainerLayer(std::make_shared(path1)); auto c2 = CreateContainerLayer(std::make_shared(path2)); @@ -667,56 +656,56 @@ TEST_F(ContainerLayerDiffTest, LayerDeletion) { t1.root()->Add(c3); auto damage = DiffLayerTree(t1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 250, 50)); MockLayerTree t2; t2.root()->Add(c2); t2.root()->Add(c3); damage = DiffLayerTree(t2, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 50, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 50, 50)); MockLayerTree t3; t3.root()->Add(c1); t3.root()->Add(c3); damage = DiffLayerTree(t3, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(100, 0, 150, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(100, 0, 150, 50)); MockLayerTree t4; t4.root()->Add(c1); t4.root()->Add(c2); damage = DiffLayerTree(t4, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 0, 250, 50)); MockLayerTree t5; t5.root()->Add(c1); damage = DiffLayerTree(t5, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(100, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(100, 0, 250, 50)); MockLayerTree t6; t6.root()->Add(c2); damage = DiffLayerTree(t6, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 250, 50)); MockLayerTree t7; t7.root()->Add(c3); damage = DiffLayerTree(t7, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 150, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 150, 50)); } TEST_F(ContainerLayerDiffTest, ReplaceLayer) { - auto path1 = SkPath().addRect(SkRect::MakeLTRB(0, 0, 50, 50)); - auto path2 = SkPath().addRect(SkRect::MakeLTRB(100, 0, 150, 50)); - auto path3 = SkPath().addRect(SkRect::MakeLTRB(200, 0, 250, 50)); + auto path1 = DlPath::MakeRectLTRB(0, 0, 50, 50); + auto path2 = DlPath::MakeRectLTRB(100, 0, 150, 50); + auto path3 = DlPath::MakeRectLTRB(200, 0, 250, 50); - auto path1a = SkPath().addRect(SkRect::MakeLTRB(0, 100, 50, 150)); - auto path2a = SkPath().addRect(SkRect::MakeLTRB(100, 100, 150, 150)); - auto path3a = SkPath().addRect(SkRect::MakeLTRB(200, 100, 250, 150)); + auto path1a = DlPath::MakeRectLTRB(0, 100, 50, 150); + auto path2a = DlPath::MakeRectLTRB(100, 100, 150, 150); + auto path3a = DlPath::MakeRectLTRB(200, 100, 250, 150); auto c1 = CreateContainerLayer(std::make_shared(path1)); auto c2 = CreateContainerLayer(std::make_shared(path2)); @@ -728,7 +717,7 @@ TEST_F(ContainerLayerDiffTest, ReplaceLayer) { t1.root()->Add(c3); auto damage = DiffLayerTree(t1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 250, 50)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 250, 50)); MockLayerTree t2; t2.root()->Add(c1); @@ -736,7 +725,7 @@ TEST_F(ContainerLayerDiffTest, ReplaceLayer) { t2.root()->Add(c3); damage = DiffLayerTree(t2, t1); - EXPECT_TRUE(damage.frame_damage.isEmpty()); + EXPECT_TRUE(damage.frame_damage.IsEmpty()); MockLayerTree t3; t3.root()->Add(CreateContainerLayer({std::make_shared(path1a)})); @@ -744,7 +733,7 @@ TEST_F(ContainerLayerDiffTest, ReplaceLayer) { t3.root()->Add(c3); damage = DiffLayerTree(t3, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 50, 150)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 50, 150)); MockLayerTree t4; t4.root()->Add(c1); @@ -752,7 +741,7 @@ TEST_F(ContainerLayerDiffTest, ReplaceLayer) { t4.root()->Add(c3); damage = DiffLayerTree(t4, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(100, 0, 150, 150)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(100, 0, 150, 150)); MockLayerTree t5; t5.root()->Add(c1); @@ -760,7 +749,7 @@ TEST_F(ContainerLayerDiffTest, ReplaceLayer) { t5.root()->Add(CreateContainerLayer(std::make_shared(path3a))); damage = DiffLayerTree(t5, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 0, 250, 150)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 0, 250, 150)); } } // namespace testing diff --git a/flow/layers/display_list_layer.cc b/flow/layers/display_list_layer.cc index abff99c607245..593d5c3afc458 100644 --- a/flow/layers/display_list_layer.cc +++ b/flow/layers/display_list_layer.cc @@ -14,16 +14,16 @@ namespace flutter { -DisplayListLayer::DisplayListLayer(const SkPoint& offset, +DisplayListLayer::DisplayListLayer(const DlPoint& offset, sk_sp display_list, bool is_complex, bool will_change) : offset_(offset), display_list_(std::move(display_list)) { if (display_list_) { - bounds_ = display_list_->bounds().makeOffset(offset_.x(), offset_.y()); + bounds_ = display_list_->GetBounds().Shift(offset_.x, offset_.y); #if !SLIMPELLER display_list_raster_cache_item_ = DisplayListRasterCacheItem::Make( - display_list_, offset_, is_complex, will_change); + display_list_, ToSkPoint(offset_), is_complex, will_change); #endif // !SLIMPELLER } } @@ -50,11 +50,11 @@ void DisplayListLayer::Diff(DiffContext* context, const Layer* old_layer) { Compare(dummy_statistics, this, prev)); #endif } - context->PushTransform(SkMatrix::Translate(offset_.x(), offset_.y())); + context->PushTransform(DlMatrix::MakeTranslation(offset_)); if (context->has_raster_cache()) { context->WillPaintWithIntegralTransform(); } - context->AddLayerBounds(display_list()->bounds()); + context->AddLayerBounds(display_list()->GetBounds()); context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion()); } @@ -98,7 +98,7 @@ void DisplayListLayer::Preroll(PrerollContext* context) { #if !SLIMPELLER AutoCache cache = AutoCache(display_list_raster_cache_item_.get(), context, - context->state_stack.transform_3x3()); + context->state_stack.matrix()); #endif // !SLIMPELLER if (disp_list->can_apply_group_opacity()) { context->renderable_state_flags = LayerStateStack::kCallerCanApplyOpacity; @@ -111,7 +111,7 @@ void DisplayListLayer::Paint(PaintContext& context) const { FML_DCHECK(needs_painting(context)); auto mutator = context.state_stack.save(); - mutator.translate(offset_.x(), offset_.y()); + mutator.translate(offset_.x, offset_.y); #if !SLIMPELLER if (context.raster_cache) { @@ -130,7 +130,7 @@ void DisplayListLayer::Paint(PaintContext& context) const { } #endif // !SLIMPELLER - SkScalar opacity = context.state_stack.outstanding_opacity(); + DlScalar opacity = context.state_stack.outstanding_opacity(); context.canvas->DrawDisplayList(display_list_, opacity); } diff --git a/flow/layers/display_list_layer.h b/flow/layers/display_list_layer.h index 71c54c852e4e8..48af63f82c20d 100644 --- a/flow/layers/display_list_layer.h +++ b/flow/layers/display_list_layer.h @@ -19,7 +19,7 @@ class DisplayListLayer : public Layer { public: static constexpr size_t kMaxBytesToCompare = 10000; - DisplayListLayer(const SkPoint& offset, + DisplayListLayer(const DlPoint& offset, sk_sp display_list, bool is_complex, bool will_change); @@ -53,8 +53,8 @@ class DisplayListLayer : public Layer { NOT_SLIMPELLER(std::unique_ptr display_list_raster_cache_item_); - SkPoint offset_; - SkRect bounds_; + DlPoint offset_; + DlRect bounds_; sk_sp display_list_; diff --git a/flow/layers/display_list_layer_unittests.cc b/flow/layers/display_list_layer_unittests.cc index 9414d4c90286c..34a01c6d2c097 100644 --- a/flow/layers/display_list_layer_unittests.cc +++ b/flow/layers/display_list_layer_unittests.cc @@ -21,7 +21,7 @@ using DisplayListLayerTest = LayerTest; #ifndef NDEBUG TEST_F(DisplayListLayerTest, PaintBeforePrerollInvalidDisplayListDies) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); auto layer = std::make_shared( layer_offset, sk_sp(), false, false); @@ -29,22 +29,22 @@ TEST_F(DisplayListLayerTest, PaintBeforePrerollInvalidDisplayListDies) { } TEST_F(DisplayListLayerTest, PaintBeforePrerollDies) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkRect picture_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); + const DlRect picture_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); DisplayListBuilder builder; builder.DrawRect(picture_bounds, DlPaint()); auto display_list = builder.Build(); auto layer = std::make_shared(layer_offset, display_list, false, false); - EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty()); + EXPECT_EQ(layer->paint_bounds(), DlRect()); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), "needs_painting\\(context\\)"); } TEST_F(DisplayListLayerTest, PaintingEmptyLayerDies) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkRect picture_bounds = SkRect::MakeEmpty(); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); + const DlRect picture_bounds; DisplayListBuilder builder; builder.DrawRect(picture_bounds, DlPaint()); auto display_list = builder.Build(); @@ -52,7 +52,7 @@ TEST_F(DisplayListLayerTest, PaintingEmptyLayerDies) { false, false); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty()); + EXPECT_EQ(layer->paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -60,7 +60,7 @@ TEST_F(DisplayListLayerTest, PaintingEmptyLayerDies) { } TEST_F(DisplayListLayerTest, InvalidDisplayListDies) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); auto layer = std::make_shared( layer_offset, sk_sp(), false, false); @@ -70,8 +70,8 @@ TEST_F(DisplayListLayerTest, InvalidDisplayListDies) { #endif TEST_F(DisplayListLayerTest, SimpleDisplayList) { - const SkPoint layer_offset = SkPoint::Make(1.5f, -0.5f); - const SkRect picture_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPoint layer_offset = DlPoint(1.5f, -0.5f); + const DlRect picture_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); DisplayListBuilder builder; builder.DrawRect(picture_bounds, DlPaint()); auto display_list = builder.Build(); @@ -80,7 +80,7 @@ TEST_F(DisplayListLayerTest, SimpleDisplayList) { layer->Preroll(preroll_context()); EXPECT_EQ(layer->paint_bounds(), - picture_bounds.makeOffset(layer_offset.fX, layer_offset.fY)); + picture_bounds.Shift(layer_offset.x, layer_offset.y)); EXPECT_EQ(layer->display_list(), display_list.get()); EXPECT_TRUE(layer->needs_painting(paint_context())); @@ -89,7 +89,7 @@ TEST_F(DisplayListLayerTest, SimpleDisplayList) { /* (DisplayList)layer::Paint */ { expected_builder.Save(); { - expected_builder.Translate(layer_offset.fX, layer_offset.fY); + expected_builder.Translate(layer_offset.x, layer_offset.y); expected_builder.DrawDisplayList(display_list); } expected_builder.Restore(); @@ -99,14 +99,14 @@ TEST_F(DisplayListLayerTest, SimpleDisplayList) { } TEST_F(DisplayListLayerTest, CachingDoesNotChangeCullRect) { - const SkPoint layer_offset = SkPoint::Make(10, 10); + const DlPoint layer_offset = DlPoint(10, 10); DisplayListBuilder builder; - builder.DrawRect(SkRect{10, 10, 20, 20}, DlPaint()); + builder.DrawRect(DlRect::MakeLTRB(10, 10, 20, 20), DlPaint()); auto display_list = builder.Build(); auto layer = std::make_shared(layer_offset, display_list, true, false); - SkRect original_cull_rect = preroll_context()->state_stack.device_cull_rect(); + DlRect original_cull_rect = preroll_context()->state_stack.device_cull_rect(); use_mock_raster_cache(); layer->Preroll(preroll_context()); ASSERT_EQ(preroll_context()->state_stack.device_cull_rect(), @@ -114,8 +114,8 @@ TEST_F(DisplayListLayerTest, CachingDoesNotChangeCullRect) { } TEST_F(DisplayListLayerTest, SimpleDisplayListOpacityInheritance) { - const SkPoint layer_offset = SkPoint::Make(1.5f, -0.5f); - const SkRect picture_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPoint layer_offset = DlPoint(1.5f, -0.5f); + const DlRect picture_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); DisplayListBuilder builder; builder.DrawRect(picture_bounds, DlPaint()); auto display_list = builder.Build(); @@ -129,8 +129,8 @@ TEST_F(DisplayListLayerTest, SimpleDisplayListOpacityInheritance) { LayerStateStack::kCallerCanApplyOpacity); int opacity_alpha = 0x7F; - SkScalar opacity = opacity_alpha / 255.0; - SkPoint opacity_offset = SkPoint::Make(10, 10); + DlScalar opacity = DlColor::toOpacity(opacity_alpha); + DlPoint opacity_offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, opacity_offset); opacity_layer->Add(display_list_layer); @@ -145,11 +145,11 @@ TEST_F(DisplayListLayerTest, SimpleDisplayListOpacityInheritance) { /* opacity_layer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(opacity_offset.fX, opacity_offset.fY); + expected_builder.Translate(opacity_offset.x, opacity_offset.y); /* display_list_layer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(layer_offset.fX, layer_offset.fY); + expected_builder.Translate(layer_offset.x, layer_offset.y); expected_builder.DrawDisplayList(child_display_list, opacity); } expected_builder.Restore(); @@ -164,9 +164,9 @@ TEST_F(DisplayListLayerTest, SimpleDisplayListOpacityInheritance) { } TEST_F(DisplayListLayerTest, IncompatibleDisplayListOpacityInheritance) { - const SkPoint layer_offset = SkPoint::Make(1.5f, -0.5f); - const SkRect picture1_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkRect picture2_bounds = SkRect::MakeLTRB(10.0f, 15.0f, 30.0f, 35.0f); + const DlPoint layer_offset = DlPoint(1.5f, -0.5f); + const DlRect picture1_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlRect picture2_bounds = DlRect::MakeLTRB(10.0f, 15.0f, 30.0f, 35.0f); DisplayListBuilder builder; builder.DrawRect(picture1_bounds, DlPaint()); builder.DrawRect(picture2_bounds, DlPaint()); @@ -180,7 +180,7 @@ TEST_F(DisplayListLayerTest, IncompatibleDisplayListOpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, 0); int opacity_alpha = 0x7F; - SkPoint opacity_offset = SkPoint::Make(10, 10); + DlPoint opacity_offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, opacity_offset); opacity_layer->Add(display_list_layer); @@ -192,22 +192,21 @@ TEST_F(DisplayListLayerTest, IncompatibleDisplayListOpacityInheritance) { child_builder.DrawRect(picture2_bounds, DlPaint()); auto child_display_list = child_builder.Build(); - auto display_list_bounds = picture1_bounds; - display_list_bounds.join(picture2_bounds); + auto display_list_bounds = picture1_bounds.Union(picture2_bounds); auto save_layer_bounds = - display_list_bounds.makeOffset(layer_offset.fX, layer_offset.fY); + display_list_bounds.Shift(layer_offset.x, layer_offset.y); DisplayListBuilder expected_builder; /* opacity_layer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(opacity_offset.fX, opacity_offset.fY); - expected_builder.SaveLayer(&save_layer_bounds, + expected_builder.Translate(opacity_offset.x, opacity_offset.y); + expected_builder.SaveLayer(save_layer_bounds, &DlPaint().setAlpha(opacity_alpha)); { /* display_list_layer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(layer_offset.fX, layer_offset.fY); + expected_builder.Translate(layer_offset.x, layer_offset.y); expected_builder.DrawDisplayList(child_display_list); } expected_builder.Restore(); @@ -224,9 +223,9 @@ TEST_F(DisplayListLayerTest, IncompatibleDisplayListOpacityInheritance) { } TEST_F(DisplayListLayerTest, CachedIncompatibleDisplayListOpacityInheritance) { - const SkPoint layer_offset = SkPoint::Make(1.5f, -0.5f); - const SkRect picture1_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkRect picture2_bounds = SkRect::MakeLTRB(10.0f, 15.0f, 30.0f, 35.0f); + const DlPoint layer_offset = DlPoint(1.5f, -0.5f); + const DlRect picture1_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlRect picture2_bounds = DlRect::MakeLTRB(10.0f, 15.0f, 30.0f, 35.0f); DisplayListBuilder builder; builder.DrawRect(picture1_bounds, DlPaint()); builder.DrawRect(picture2_bounds, DlPaint()); @@ -249,35 +248,30 @@ TEST_F(DisplayListLayerTest, CachedIncompatibleDisplayListOpacityInheritance) { &paint_context(), false); int opacity_alpha = 0x7F; - SkPoint opacity_offset = SkPoint::Make(10.2, 10.2); + DlPoint opacity_offset = DlPoint(10.2, 10.2); auto opacity_layer = std::make_shared(opacity_alpha, opacity_offset); opacity_layer->Add(display_list_layer); opacity_layer->Preroll(context); EXPECT_TRUE(opacity_layer->children_can_accept_opacity()); - auto display_list_bounds = picture1_bounds; - display_list_bounds.join(picture2_bounds); - auto save_layer_bounds = - display_list_bounds.makeOffset(layer_offset.fX, layer_offset.fY); - save_layer_bounds.roundOut(&save_layer_bounds); - auto opacity_integral_matrix = - RasterCacheUtil::GetIntegralTransCTM(SkMatrix::Translate(opacity_offset)); - SkMatrix layer_offset_matrix = opacity_integral_matrix; - layer_offset_matrix.postTranslate(layer_offset.fX, layer_offset.fY); + auto opacity_integral_matrix = RasterCacheUtil::GetIntegralTransCTM( + DlMatrix::MakeTranslation(opacity_offset)); + DlMatrix layer_offset_matrix = + DlMatrix::MakeTranslation(layer_offset) * opacity_integral_matrix; auto layer_offset_integral_matrix = RasterCacheUtil::GetIntegralTransCTM(layer_offset_matrix); - DisplayListBuilder expected(SkRect::MakeWH(1000, 1000)); + DisplayListBuilder expected(DlRect::MakeWH(1000, 1000)); /* opacity_layer::Paint() */ { expected.Save(); { - expected.Translate(opacity_offset.fX, opacity_offset.fY); + expected.Translate(opacity_offset.x, opacity_offset.y); expected.TransformReset(); expected.Transform(opacity_integral_matrix); /* display_list_layer::Paint() */ { expected.Save(); { - expected.Translate(layer_offset.fX, layer_offset.fY); + expected.Translate(layer_offset.x, layer_offset.y); expected.TransformReset(); expected.Transform(layer_offset_integral_matrix); context->raster_cache->Draw(display_list_layer->caching_key_id(), @@ -295,21 +289,21 @@ TEST_F(DisplayListLayerTest, CachedIncompatibleDisplayListOpacityInheritance) { } TEST_F(DisplayListLayerTest, RasterCachePreservesRTree) { - const SkRect picture1_bounds = SkRect::MakeXYWH(10, 10, 10, 10); - const SkRect picture2_bounds = SkRect::MakeXYWH(15, 15, 10, 10); + const DlRect picture1_bounds = DlRect::MakeXYWH(10, 10, 10, 10); + const DlRect picture2_bounds = DlRect::MakeXYWH(15, 15, 10, 10); DisplayListBuilder builder(true); builder.DrawRect(picture1_bounds, DlPaint()); builder.DrawRect(picture2_bounds, DlPaint()); auto display_list = builder.Build(); auto display_list_layer = std::make_shared( - SkPoint::Make(3, 3), display_list, true, false); + DlPoint(3, 3), display_list, true, false); use_skia_raster_cache(); auto context = preroll_context(); { auto mutator = context->state_stack.save(); - mutator.transform(SkMatrix::Scale(2.0, 2.0)); + mutator.transform(DlMatrix::MakeScale({2.0f, 2.0f, 1.0f})); display_list_layer->Preroll(preroll_context()); EXPECT_EQ(context->renderable_state_flags, 0); @@ -328,7 +322,8 @@ TEST_F(DisplayListLayerTest, RasterCachePreservesRTree) { false)); auto root_canvas_dl = expected_root_canvas.Build(); const auto root_canvas_rects = - root_canvas_dl->rtree()->searchAndConsolidateRects(kGiantRect, true); + root_canvas_dl->rtree()->searchAndConsolidateRects(ToSkRect(kGiantRect), + true); std::list root_canvas_rects_expected = { SkRect::MakeLTRB(26, 26, 56, 56), }; @@ -341,7 +336,8 @@ TEST_F(DisplayListLayerTest, RasterCachePreservesRTree) { true)); auto overlay_canvas_dl = expected_overlay_canvas.Build(); const auto overlay_canvas_rects = - overlay_canvas_dl->rtree()->searchAndConsolidateRects(kGiantRect, true); + overlay_canvas_dl->rtree()->searchAndConsolidateRects( + ToSkRect(kGiantRect), true); // Same bounds as root canvas, but preserves individual rects. std::list overlay_canvas_rects_expected = { @@ -355,95 +351,89 @@ TEST_F(DisplayListLayerTest, RasterCachePreservesRTree) { using DisplayListLayerDiffTest = DiffContextTest; TEST_F(DisplayListLayerDiffTest, SimpleDisplayList) { - auto display_list = CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60)); + auto display_list = CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60)); MockLayerTree tree1; tree1.root()->Add(CreateDisplayListLayer(display_list)); auto damage = DiffLayerTree(tree1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(10, 10, 60, 60)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(10, 10, 60, 60)); MockLayerTree tree2; tree2.root()->Add(CreateDisplayListLayer(display_list)); damage = DiffLayerTree(tree2, tree1); - EXPECT_TRUE(damage.frame_damage.isEmpty()); + EXPECT_TRUE(damage.frame_damage.IsEmpty()); MockLayerTree tree3; damage = DiffLayerTree(tree3, tree2); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(10, 10, 60, 60)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(10, 10, 60, 60)); } TEST_F(DisplayListLayerDiffTest, FractionalTranslation) { - auto display_list = CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60)); + auto display_list = CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60)); MockLayerTree tree1; - tree1.root()->Add( - CreateDisplayListLayer(display_list, SkPoint::Make(0.5, 0.5))); + tree1.root()->Add(CreateDisplayListLayer(display_list, DlPoint(0.5f, 0.5f))); - auto damage = - DiffLayerTree(tree1, MockLayerTree(), SkIRect::MakeEmpty(), 0, 0, - /*use_raster_cache=*/false); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(10, 10, 61, 61)); + auto damage = DiffLayerTree(tree1, MockLayerTree(), DlIRect(), 0, 0, + /*use_raster_cache=*/false); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(10, 10, 61, 61)); } TEST_F(DisplayListLayerDiffTest, FractionalTranslationWithRasterCache) { - auto display_list = CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60)); + auto display_list = CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60)); MockLayerTree tree1; - tree1.root()->Add( - CreateDisplayListLayer(display_list, SkPoint::Make(0.5, 0.5))); + tree1.root()->Add(CreateDisplayListLayer(display_list, DlPoint(0.5f, 0.5f))); - auto damage = - DiffLayerTree(tree1, MockLayerTree(), SkIRect::MakeEmpty(), 0, 0, - /*use_raster_cache=*/true); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(11, 11, 61, 61)); + auto damage = DiffLayerTree(tree1, MockLayerTree(), DlIRect(), 0, 0, + /*use_raster_cache=*/true); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(11, 11, 61, 61)); } TEST_F(DisplayListLayerDiffTest, DisplayListCompare) { MockLayerTree tree1; auto display_list1 = - CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60), DlColor::kGreen()); + CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60), DlColor::kGreen()); tree1.root()->Add(CreateDisplayListLayer(display_list1)); auto damage = DiffLayerTree(tree1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(10, 10, 60, 60)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(10, 10, 60, 60)); MockLayerTree tree2; // same DL, same offset auto display_list2 = - CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60), DlColor::kGreen()); + CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60), DlColor::kGreen()); tree2.root()->Add(CreateDisplayListLayer(display_list2)); damage = DiffLayerTree(tree2, tree1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeEmpty()); + EXPECT_EQ(damage.frame_damage, DlIRect()); MockLayerTree tree3; auto display_list3 = - CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60), DlColor::kGreen()); + CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60), DlColor::kGreen()); // add offset - tree3.root()->Add( - CreateDisplayListLayer(display_list3, SkPoint::Make(10, 10))); + tree3.root()->Add(CreateDisplayListLayer(display_list3, DlPoint(10, 10))); damage = DiffLayerTree(tree3, tree2); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(10, 10, 70, 70)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(10, 10, 70, 70)); MockLayerTree tree4; // different color auto display_list4 = - CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60), DlColor::kRed()); - tree4.root()->Add( - CreateDisplayListLayer(display_list4, SkPoint::Make(10, 10))); + CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60), DlColor::kRed()); + tree4.root()->Add(CreateDisplayListLayer(display_list4, DlPoint(10, 10))); damage = DiffLayerTree(tree4, tree3); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(20, 20, 70, 70)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(20, 20, 70, 70)); } TEST_F(DisplayListLayerTest, DisplayListAccessCountDependsOnVisibility) { - const SkPoint layer_offset = SkPoint::Make(1.5f, -0.5f); - const SkRect picture_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkRect missed_cull_rect = SkRect::MakeLTRB(100, 100, 200, 200); - const SkRect hit_cull_rect = SkRect::MakeLTRB(0, 0, 200, 200); + const DlPoint layer_offset = DlPoint(1.5f, -0.5f); + const DlRect picture_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlRect missed_cull_rect = DlRect::MakeLTRB(100, 100, 200, 200); + const DlRect hit_cull_rect = DlRect::MakeLTRB(0, 0, 200, 200); DisplayListBuilder builder; builder.DrawRect(picture_bounds, DlPaint()); auto display_list = builder.Build(); @@ -541,16 +531,16 @@ TEST_F(DisplayListLayerTest, OverflowCachedDisplayListOpacityInheritance) { int per_frame = RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame; int layer_count = per_frame + 1; - SkPoint opacity_offset = {10, 10}; + DlPoint opacity_offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(0.5f, opacity_offset); std::vector> layers; for (int i = 0; i < layer_count; i++) { DisplayListBuilder builder(false); - builder.DrawRect(SkRect{0, 0, 100, 100}, DlPaint()); - builder.DrawRect(SkRect{50, 50, 100, 100}, DlPaint()); + builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), DlPaint()); + builder.DrawRect(DlRect::MakeLTRB(50, 50, 100, 100), DlPaint()); auto display_list = builder.Build(); ASSERT_FALSE(display_list->can_apply_group_opacity()); - SkPoint offset = {i * 200.0f, 0}; + DlPoint offset = DlPoint(i * 200.0f, 0); layers.push_back( std::make_shared(offset, display_list, true, false)); diff --git a/flow/layers/display_list_raster_cache_item.cc b/flow/layers/display_list_raster_cache_item.cc index 303c5117a3f9e..930bbfd541cd3 100644 --- a/flow/layers/display_list_raster_cache_item.cc +++ b/flow/layers/display_list_raster_cache_item.cc @@ -71,7 +71,7 @@ std::unique_ptr DisplayListRasterCacheItem::Make( } void DisplayListRasterCacheItem::PrerollSetup(PrerollContext* context, - const SkMatrix& matrix) { + const DlMatrix& matrix) { cache_state_ = CacheState::kNone; DisplayListComplexityCalculator* complexity_calculator = context->gr_context ? DisplayListComplexityCalculator::GetForBackend( @@ -84,7 +84,7 @@ void DisplayListRasterCacheItem::PrerollSetup(PrerollContext* context, return; } - transformation_matrix_ = matrix; + transformation_matrix_ = ToSkMatrix(matrix); transformation_matrix_.preTranslate(offset_.x(), offset_.y()); if (!transformation_matrix_.invert(nullptr)) { @@ -100,16 +100,16 @@ void DisplayListRasterCacheItem::PrerollSetup(PrerollContext* context, } void DisplayListRasterCacheItem::PrerollFinalize(PrerollContext* context, - const SkMatrix& matrix) { + const DlMatrix& matrix) { if (cache_state_ == CacheState::kNone || !context->raster_cache || !context->raster_cached_entries) { return; } auto* raster_cache = context->raster_cache; - SkRect bounds = display_list_->bounds().makeOffset(offset_.x(), offset_.y()); + DlRect bounds = display_list_->GetBounds().Shift(offset_.x(), offset_.y()); bool visible = !context->state_stack.content_culled(bounds); RasterCache::CacheInfo cache_info = - raster_cache->MarkSeen(key_id_, matrix, visible); + raster_cache->MarkSeen(key_id_, ToSkMatrix(matrix), visible); if (!visible || cache_info.accesses_since_visible <= raster_cache->access_threshold()) { cache_state_ = kNone; diff --git a/flow/layers/display_list_raster_cache_item.h b/flow/layers/display_list_raster_cache_item.h index 4bb59d705ed2d..05b7d52ad128e 100644 --- a/flow/layers/display_list_raster_cache_item.h +++ b/flow/layers/display_list_raster_cache_item.h @@ -31,10 +31,10 @@ class DisplayListRasterCacheItem : public RasterCacheItem { bool is_complex, bool will_change); - void PrerollSetup(PrerollContext* context, const SkMatrix& matrix) override; + void PrerollSetup(PrerollContext* context, const DlMatrix& matrix) override; void PrerollFinalize(PrerollContext* context, - const SkMatrix& matrix) override; + const DlMatrix& matrix) override; bool Draw(const PaintContext& context, const DlPaint* paint) const override; diff --git a/flow/layers/image_filter_layer.cc b/flow/layers/image_filter_layer.cc index 1fa13acd47d6c..f845a7f35075b 100644 --- a/flow/layers/image_filter_layer.cc +++ b/flow/layers/image_filter_layer.cc @@ -11,7 +11,7 @@ namespace flutter { ImageFilterLayer::ImageFilterLayer(const std::shared_ptr& filter, - const SkPoint& offset) + const DlPoint& offset) : CacheableContainerLayer( RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer), offset_(offset), @@ -28,7 +28,7 @@ void ImageFilterLayer::Diff(DiffContext* context, const Layer* old_layer) { } } - context->PushTransform(SkMatrix::Translate(offset_.fX, offset_.fY)); + context->PushTransform(DlMatrix::MakeTranslation(offset_)); if (context->has_raster_cache()) { context->WillPaintWithIntegralTransform(); } @@ -37,11 +37,11 @@ void ImageFilterLayer::Diff(DiffContext* context, const Layer* old_layer) { auto filter = filter_->makeWithLocalMatrix(context->GetMatrix()); if (filter) { // This transform will be applied to every child rect in the subtree - context->PushFilterBoundsAdjustment([filter](SkRect rect) { + context->PushFilterBoundsAdjustment([filter](DlRect rect) { DlIRect filter_out_bounds; - filter->map_device_bounds(ToDlIRect(rect.roundOut()), DlMatrix(), + filter->map_device_bounds(DlIRect::RoundOut(rect), DlMatrix(), filter_out_bounds); - return SkRect::Make(ToSkIRect(filter_out_bounds)); + return DlRect::Make(filter_out_bounds); }); } } @@ -58,15 +58,15 @@ void ImageFilterLayer::Preroll(PrerollContext* context) { #if !SLIMPELLER AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, - context->state_stack.transform_3x3()); + context->state_stack.matrix()); #endif // !SLIMPELLER - SkRect child_bounds = SkRect::MakeEmpty(); + DlRect child_bounds; PrerollChildren(context, &child_bounds); if (!filter_) { - child_bounds.offset(offset_); + child_bounds = child_bounds.Shift(offset_); set_paint_bounds(child_bounds); return; } @@ -78,11 +78,10 @@ void ImageFilterLayer::Preroll(PrerollContext* context) { (LayerStateStack::kCallerCanApplyOpacity | LayerStateStack::kCallerCanApplyColorFilter); - const DlIRect filter_in_bounds = ToDlIRect(child_bounds.roundOut()); + const DlIRect filter_in_bounds = DlIRect::RoundOut(child_bounds); DlIRect filter_out_bounds; filter_->map_device_bounds(filter_in_bounds, DlMatrix(), filter_out_bounds); - child_bounds.set(ToSkIRect(filter_out_bounds)); - child_bounds.offset(offset_); + child_bounds = DlRect::Make(filter_out_bounds).Shift(offset_); set_paint_bounds(child_bounds); diff --git a/flow/layers/image_filter_layer.h b/flow/layers/image_filter_layer.h index bd8172c295e13..bca1c62c97916 100644 --- a/flow/layers/image_filter_layer.h +++ b/flow/layers/image_filter_layer.h @@ -13,7 +13,7 @@ namespace flutter { class ImageFilterLayer : public CacheableContainerLayer { public: explicit ImageFilterLayer(const std::shared_ptr& filter, - const SkPoint& offset = SkPoint::Make(0, 0)); + const DlPoint& offset = DlPoint()); void Diff(DiffContext* context, const Layer* old_layer) override; @@ -22,7 +22,7 @@ class ImageFilterLayer : public CacheableContainerLayer { void Paint(PaintContext& context) const override; private: - SkPoint offset_; + DlPoint offset_; const std::shared_ptr filter_; std::shared_ptr transformed_filter_; diff --git a/flow/layers/image_filter_layer_unittests.cc b/flow/layers/image_filter_layer_unittests.cc index cfbeb17ba2f8b..f275ad70ee30c 100644 --- a/flow/layers/image_filter_layer_unittests.cc +++ b/flow/layers/image_filter_layer_unittests.cc @@ -13,8 +13,6 @@ #include "flutter/flow/testing/mock_layer.h" #include "flutter/fml/macros.h" #include "gtest/gtest.h" -#include "include/core/SkPath.h" -#include "third_party/skia/include/effects/SkImageFilters.h" // TODO(zanderso): https://github.com/flutter/flutter/issues/127701 // NOLINTBEGIN(bugprone-unchecked-optional-access) @@ -29,7 +27,7 @@ TEST_F(ImageFilterLayerTest, PaintingEmptyLayerDies) { auto layer = std::make_shared(nullptr); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -37,23 +35,23 @@ TEST_F(ImageFilterLayerTest, PaintingEmptyLayerDies) { } TEST_F(ImageFilterLayerTest, PaintBeforePrerollDies) { - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); auto mock_layer = std::make_shared(child_path); auto layer = std::make_shared(nullptr); layer->Add(mock_layer); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), "needs_painting\\(context\\)"); } #endif TEST_F(ImageFilterLayerTest, EmptyFilter) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(nullptr); @@ -79,9 +77,9 @@ TEST_F(ImageFilterLayerTest, EmptyFilter) { } TEST_F(ImageFilterLayerTest, SimpleFilter) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto dl_image_filter = DlImageFilter::MakeMatrix( DlMatrix::MakeTranslation({1.0, 2.0}), DlImageSampling::kMipmapLinear); @@ -89,8 +87,8 @@ TEST_F(ImageFilterLayerTest, SimpleFilter) { auto layer = std::make_shared(dl_image_filter); layer->Add(mock_layer); - const SkRect child_rounded_bounds = - SkRect::MakeLTRB(6.0f, 8.0f, 22.0f, 24.0f); + const DlRect child_rounded_bounds = + DlRect::MakeLTRB(6.0f, 8.0f, 22.0f, 24.0f); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); @@ -103,7 +101,7 @@ TEST_F(ImageFilterLayerTest, SimpleFilter) { /* ImageFilterLayer::Paint() */ { DlPaint dl_paint; dl_paint.setImageFilter(dl_image_filter.get()); - expected_builder.SaveLayer(&child_bounds, &dl_paint); + expected_builder.SaveLayer(child_bounds, &dl_paint); { /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path, DlPaint(DlColor::kYellow())); @@ -118,12 +116,12 @@ TEST_F(ImageFilterLayerTest, SimpleFilter) { } TEST_F(ImageFilterLayerTest, SimpleFilterWithOffset) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect initial_cull_rect = SkRect::MakeLTRB(0, 0, 100, 100); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect initial_cull_rect = DlRect::MakeLTRB(0, 0, 100, 100); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); - const SkPoint layer_offset = SkPoint::Make(5.5, 6.5); + const DlPoint layer_offset = DlPoint(5.5, 6.5); auto dl_image_filter = DlImageFilter::MakeMatrix( DlMatrix::MakeTranslation({1.0, 2.0}), DlImageSampling::kMipmapLinear); auto mock_layer = std::make_shared(child_path, child_paint); @@ -131,10 +129,10 @@ TEST_F(ImageFilterLayerTest, SimpleFilterWithOffset) { std::make_shared(dl_image_filter, layer_offset); layer->Add(mock_layer); - SkMatrix child_matrix = initial_transform; - child_matrix.preTranslate(layer_offset.fX, layer_offset.fY); - const SkRect child_rounded_bounds = - SkRect::MakeLTRB(11.5f, 14.5f, 27.5f, 30.5f); + DlMatrix child_matrix = + DlMatrix::MakeTranslation(layer_offset) * initial_transform; + const DlRect child_rounded_bounds = + DlRect::MakeLTRB(11.5f, 14.5f, 27.5f, 30.5f); preroll_context()->state_stack.set_preroll_delegate(initial_cull_rect, initial_transform); @@ -150,10 +148,10 @@ TEST_F(ImageFilterLayerTest, SimpleFilterWithOffset) { /* ImageFilterLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(layer_offset.fX, layer_offset.fY); + expected_builder.Translate(layer_offset.x, layer_offset.y); DlPaint dl_paint; dl_paint.setImageFilter(dl_image_filter.get()); - expected_builder.SaveLayer(&child_bounds, &dl_paint); + expected_builder.SaveLayer(child_bounds, &dl_paint); { /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path, DlPaint(DlColor::kYellow())); @@ -170,9 +168,9 @@ TEST_F(ImageFilterLayerTest, SimpleFilterWithOffset) { } TEST_F(ImageFilterLayerTest, SimpleFilterBounds) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); const DlMatrix filter_transform = DlMatrix::MakeScale({2.0, 2.0, 1}); @@ -182,7 +180,7 @@ TEST_F(ImageFilterLayerTest, SimpleFilterBounds) { auto layer = std::make_shared(dl_image_filter); layer->Add(mock_layer); - const SkRect filter_bounds = SkRect::MakeLTRB(10.0f, 12.0f, 42.0f, 44.0f); + const DlRect filter_bounds = DlRect::MakeLTRB(10.0f, 12.0f, 42.0f, 44.0f); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); @@ -195,7 +193,7 @@ TEST_F(ImageFilterLayerTest, SimpleFilterBounds) { /* ImageFilterLayer::Paint() */ { DlPaint dl_paint; dl_paint.setImageFilter(dl_image_filter.get()); - expected_builder.SaveLayer(&child_bounds, &dl_paint); + expected_builder.SaveLayer(child_bounds, &dl_paint); { /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path, DlPaint(DlColor::kYellow())); @@ -210,11 +208,10 @@ TEST_F(ImageFilterLayerTest, SimpleFilterBounds) { } TEST_F(ImageFilterLayerTest, MultipleChildren) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); - const SkPath child_path1 = SkPath().addRect(child_bounds); - const SkPath child_path2 = - SkPath().addRect(child_bounds.makeOffset(3.0f, 0.0f)); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); + const DlPath child_path1 = DlPath::MakeRect(child_bounds); + const DlPath child_path2 = DlPath::MakeRect(child_bounds.Shift(3.0f, 0.0f)); const DlPaint child_paint1 = DlPaint(DlColor::kYellow()); const DlPaint child_paint2 = DlPaint(DlColor::kCyan()); auto dl_image_filter = DlImageFilter::MakeMatrix( @@ -225,15 +222,15 @@ TEST_F(ImageFilterLayerTest, MultipleChildren) { layer->Add(mock_layer1); layer->Add(mock_layer2); - SkRect children_bounds = child_path1.getBounds(); - children_bounds.join(child_path2.getBounds()); - SkRect children_rounded_bounds = - SkRect::Make(children_bounds.roundOut()).makeOffset(1.0f, 2.0f); + const DlRect children_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); + DlRect children_rounded_bounds = + DlRect::RoundOut(children_bounds).Shift(1.0f, 2.0f); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer->paint_bounds(), children_rounded_bounds); EXPECT_EQ(layer->child_paint_bounds(), children_bounds); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); @@ -246,7 +243,7 @@ TEST_F(ImageFilterLayerTest, MultipleChildren) { /* ImageFilterLayer::Paint() */ { DlPaint dl_paint; dl_paint.setImageFilter(dl_image_filter.get()); - expected_builder.SaveLayer(&children_bounds, &dl_paint); + expected_builder.SaveLayer(children_bounds, &dl_paint); { /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path1, DlPaint(DlColor::kYellow())); @@ -264,11 +261,10 @@ TEST_F(ImageFilterLayerTest, MultipleChildren) { } TEST_F(ImageFilterLayerTest, Nested) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); - const SkPath child_path1 = SkPath().addRect(child_bounds); - const SkPath child_path2 = - SkPath().addRect(child_bounds.makeOffset(3.0f, 0.0f)); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f); + const DlPath child_path1 = DlPath::MakeRect(child_bounds); + const DlPath child_path2 = DlPath::MakeRect(child_bounds.Shift(3.0f, 0.0f)); const DlPaint child_paint1 = DlPaint(DlColor::kYellow()); const DlPaint child_paint2 = DlPaint(DlColor::kCyan()); auto dl_image_filter1 = DlImageFilter::MakeMatrix( @@ -283,32 +279,32 @@ TEST_F(ImageFilterLayerTest, Nested) { layer1->Add(mock_layer1); layer1->Add(layer2); - // Filter(translate by 1, 2) - // / | + // Filter(translate by 1, 2) + // / | // Mock(child_path1) Filter(translate by 3, 4) // | // Mock(child_path2 (shifted (3, 0))) - SkRect filter2_bounds = SkRect::Make( // + DlRect filter2_bounds = DlRect::RoundOut( // child_path2 - .getBounds() // includes shift(3, 0) on child_path2 - .makeOffset(3.0, 4.0) // filter2 translation - .roundOut()); - SkRect filter1_child_bounds = child_path1.getBounds(); - filter1_child_bounds.join(filter2_bounds); - SkRect filter1_bounds = SkRect::Make( // - filter1_child_bounds // no shift on child_path1 - .makeOffset(1.0, 2.0) // filter1 translation - .roundOut()); + .GetBounds() // includes shift(3, 0) on child_path2 + .Shift(3.0, 4.0) // filter2 translation + ); + const DlRect filter1_child_bounds = + child_path1.GetBounds().Union(filter2_bounds); + DlRect filter1_bounds = DlRect::RoundOut( // + filter1_child_bounds // no shift on child_path1 + .Shift(1.0, 2.0) // filter1 translation + ); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer1->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer1->paint_bounds(), filter1_bounds); EXPECT_EQ(layer1->child_paint_bounds(), filter1_child_bounds); EXPECT_EQ(layer2->paint_bounds(), filter2_bounds); - EXPECT_EQ(layer2->child_paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(layer2->child_paint_bounds(), child_path2.GetBounds()); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); EXPECT_TRUE(mock_layer2->needs_painting(paint_context())); EXPECT_TRUE(layer1->needs_painting(paint_context())); @@ -320,7 +316,7 @@ TEST_F(ImageFilterLayerTest, Nested) { /* ImageFilterLayer::Paint() */ { DlPaint dl_paint; dl_paint.setImageFilter(dl_image_filter1.get()); - expected_builder.SaveLayer(&filter1_child_bounds, &dl_paint); + expected_builder.SaveLayer(filter1_child_bounds, &dl_paint); { /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path1, DlPaint(DlColor::kYellow())); @@ -328,7 +324,7 @@ TEST_F(ImageFilterLayerTest, Nested) { /* ImageFilterLayer::Paint() */ { DlPaint child_paint; child_paint.setImageFilter(dl_image_filter2.get()); - expected_builder.SaveLayer(&child_path2.getBounds(), &child_paint); + expected_builder.SaveLayer(child_path2.GetBounds(), &child_paint); /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path2, DlPaint(DlColor::kCyan())); } @@ -354,7 +350,7 @@ TEST_F(ImageFilterLayerTest, Readback) { EXPECT_FALSE(preroll_context()->surface_needs_readback); // ImageFilterLayer blocks child with readback - auto mock_layer = std::make_shared(SkPath(), DlPaint()); + auto mock_layer = std::make_shared(DlPath(), DlPaint()); mock_layer->set_fake_reads_surface(true); layer->Add(mock_layer); preroll_context()->surface_needs_readback = false; @@ -364,15 +360,15 @@ TEST_F(ImageFilterLayerTest, Readback) { TEST_F(ImageFilterLayerTest, CacheChild) { auto dl_image_filter = DlImageFilter::MakeMatrix( - DlMatrix::MakeTranslation({1.0, 2.0}), DlImageSampling::kMipmapLinear); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - auto other_transform = SkMatrix::Scale(1.0, 2.0); - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + DlMatrix::MakeTranslation({1.0f, 2.0f}), DlImageSampling::kMipmapLinear); + auto initial_transform = DlMatrix::MakeTranslation({50.0f, 25.5f}); + auto other_transform = DlMatrix::MakeScale({1.0f, 2.0f, 1.0f}); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); auto mock_layer = std::make_shared(child_path); auto layer = std::make_shared(dl_image_filter); layer->Add(mock_layer); - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); DisplayListBuilder other_canvas; @@ -408,20 +404,20 @@ TEST_F(ImageFilterLayerTest, CacheChild) { TEST_F(ImageFilterLayerTest, CacheChildren) { auto dl_image_filter = DlImageFilter::MakeMatrix( - DlMatrix::MakeTranslation({1.0, 2.0}), DlImageSampling::kMipmapLinear); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - auto other_transform = SkMatrix::Scale(1.0, 2.0); + DlMatrix::MakeTranslation({1.0f, 2.0f}), DlImageSampling::kMipmapLinear); + auto initial_transform = DlMatrix::MakeTranslation({50.0f, 25.5f}); + auto other_transform = DlMatrix::MakeScale({1.0f, 2.0f, 1.0f}); DlPaint paint; - const SkPath child_path1 = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); - const SkPath child_path2 = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + const DlPath child_path1 = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); + const DlPath child_path2 = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); auto mock_layer1 = std::make_shared(child_path1); auto mock_layer2 = std::make_shared(child_path2); - auto offset = SkPoint::Make(54, 24); + auto offset = DlPoint(54, 24); auto layer = std::make_shared(dl_image_filter, offset); layer->Add(mock_layer1); layer->Add(mock_layer2); - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); DisplayListBuilder other_canvas; @@ -457,23 +453,16 @@ TEST_F(ImageFilterLayerTest, CacheChildren) { layer->Preroll(preroll_context()); - SkRect children_bounds = child_path1.getBounds(); - children_bounds.join(child_path2.getBounds()); - SkMatrix snapped_matrix = SkMatrix::MakeAll( // - 1, 0, SkScalarRoundToScalar(offset.fX), // - 0, 1, SkScalarRoundToScalar(offset.fY), // - 0, 0, 1); - SkMatrix cache_matrix = initial_transform; - cache_matrix.preConcat(snapped_matrix); - auto transformed_filter = - dl_image_filter->makeWithLocalMatrix(ToDlMatrix(cache_matrix)); + DlMatrix snapped_matrix = DlMatrix::MakeTranslation(offset.Round()); + DlMatrix cache_matrix = snapped_matrix * initial_transform; + auto transformed_filter = dl_image_filter->makeWithLocalMatrix(cache_matrix); layer->Paint(display_list_paint_context()); DisplayListBuilder expected_builder; /* (ImageFilter)layer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); // translation components already snapped to pixels, intent to // use raster cache won't change them DlPaint dl_paint; @@ -491,26 +480,23 @@ TEST_F(ImageFilterLayerTest, CacheImageFilterLayerSelf) { auto dl_image_filter = DlImageFilter::MakeMatrix( DlMatrix::MakeTranslation({1.0, 2.0}), DlImageSampling::kMipmapLinear); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - auto other_transform = SkMatrix::Scale(1.0, 2.0); - auto child_rect = SkRect::MakeWH(5.0f, 5.0f); - const SkPath child_path = SkPath().addRect(child_rect); + auto initial_transform = DlMatrix::MakeTranslation({50.0f, 25.5f}); + auto other_transform = DlMatrix::MakeScale({1.0f, 2.0f, 1.0f}); + auto child_rect = DlRect::MakeWH(5.0f, 5.0f); + const DlPath child_path = DlPath::MakeRect(child_rect); auto mock_layer = std::make_shared(child_path); - auto offset = SkPoint::Make(53.8, 24.4); + auto offset = DlPoint(53.8, 24.4); auto layer = std::make_shared(dl_image_filter, offset); layer->Add(mock_layer); - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); DisplayListBuilder other_canvas; other_canvas.Transform(other_transform); DlPaint paint; - SkMatrix snapped_matrix = SkMatrix::MakeAll( // - 1, 0, SkScalarRoundToScalar(offset.fX), // - 0, 1, SkScalarRoundToScalar(offset.fY), // - 0, 0, 1); + DlMatrix snapped_matrix = DlMatrix::MakeTranslation(offset.Round()); use_mock_raster_cache(); preroll_context()->state_stack.set_preroll_delegate(initial_transform); @@ -524,12 +510,12 @@ TEST_F(ImageFilterLayerTest, CacheImageFilterLayerSelf) { /* (ImageFilter)layer::Paint */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); // Snap to pixel translation due to use of raster cache expected_builder.TransformReset(); expected_builder.Transform(snapped_matrix); DlPaint save_paint = DlPaint().setImageFilter(dl_image_filter); - expected_builder.SaveLayer(&child_rect, &save_paint); + expected_builder.SaveLayer(child_rect, &save_paint); { /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, DlPaint()); @@ -586,9 +572,9 @@ TEST_F(ImageFilterLayerTest, CacheImageFilterLayerSelf) { } TEST_F(ImageFilterLayerTest, OpacityInheritance) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto dl_image_filter = DlImageFilter::MakeMatrix( DlMatrix::MakeTranslation({1.0, 2.0}), DlImageSampling::kMipmapLinear); @@ -608,10 +594,10 @@ TEST_F(ImageFilterLayerTest, OpacityInheritance) { LayerStateStack::kCallerCanApplyColorFilter); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(image_filter_layer); - context->state_stack.set_preroll_delegate(SkMatrix::I()); + context->state_stack.set_preroll_delegate(DlMatrix()); opacity_layer->Preroll(context); EXPECT_TRUE(opacity_layer->children_can_accept_opacity()); @@ -619,13 +605,12 @@ TEST_F(ImageFilterLayerTest, OpacityInheritance) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ImageFilterLayer::Paint() */ { DlPaint image_filter_paint; image_filter_paint.setColor(DlColor(opacity_alpha << 24)); image_filter_paint.setImageFilter(dl_image_filter.get()); - expected_builder.SaveLayer(&child_path.getBounds(), - &image_filter_paint); + expected_builder.SaveLayer(child_path.GetBounds(), &image_filter_paint); /* MockLayer::Paint() */ { expected_builder.DrawPath(child_path, DlPaint(child_paint.getColor())); @@ -654,38 +639,39 @@ TEST_F(ImageFilterLayerDiffTest, ImageFilterLayer) { MockLayerTree l1; auto filter_layer = std::make_shared(dl_blur_filter); - auto path = SkPath().addRect(SkRect::MakeLTRB(100, 100, 110, 110)); + auto path = DlPath::MakeRectLTRB(100, 100, 110, 110); filter_layer->Add(std::make_shared(path)); l1.root()->Add(filter_layer); auto damage = DiffLayerTree(l1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(70, 70, 140, 140)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(70, 70, 140, 140)); MockLayerTree l2; - auto scale = std::make_shared(SkMatrix::Scale(2.0, 2.0)); + auto scale = + std::make_shared(DlMatrix::MakeScale({2.0f, 2.0f, 1.0f})); scale->Add(filter_layer); l2.root()->Add(scale); damage = DiffLayerTree(l2, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(140, 140, 280, 280)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(140, 140, 280, 280)); MockLayerTree l3; l3.root()->Add(scale); // path outside of ImageFilterLayer - auto path1 = SkPath().addRect(SkRect::MakeLTRB(130, 130, 140, 140)); + auto path1 = DlPath::MakeRectLTRB(130, 130, 140, 140); l3.root()->Add(std::make_shared(path1)); damage = DiffLayerTree(l3, l2); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(130, 130, 140, 140)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(130, 130, 140, 140)); // path intersecting ImageFilterLayer, shouldn't trigger entire // ImageFilterLayer repaint MockLayerTree l4; l4.root()->Add(scale); - auto path2 = SkPath().addRect(SkRect::MakeLTRB(130, 130, 141, 141)); + auto path2 = DlPath::MakeRectLTRB(130, 130, 141, 141); l4.root()->Add(std::make_shared(path2)); damage = DiffLayerTree(l4, l3); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(130, 130, 141, 141)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(130, 130, 141, 141)); } TEST_F(ImageFilterLayerDiffTest, ImageFilterLayerInflatestChildSize) { @@ -705,7 +691,7 @@ TEST_F(ImageFilterLayerDiffTest, ImageFilterLayerInflatestChildSize) { auto filter_layer_1_1 = std::make_shared(dl_blur_filter); auto filter_layer_1_2 = std::make_shared(dl_blur_filter); filter_layer_1_1->Add(filter_layer_1_2); - auto path = SkPath().addRect(SkRect::MakeLTRB(100, 100, 110, 110)); + auto path = DlPath::MakeRectLTRB(100, 100, 110, 110); filter_layer_1_2->Add( std::make_shared(path, DlPaint(DlColor::kYellow()))); l1.root()->Add(filter_layer_1_1); @@ -725,20 +711,20 @@ TEST_F(ImageFilterLayerDiffTest, ImageFilterLayerInflatestChildSize) { auto damage = DiffLayerTree(l2, l1); // ensure that filter properly inflated child size - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(40, 40, 170, 170)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(40, 40, 170, 170)); } TEST_F(ImageFilterLayerTest, EmptyFilterWithOffset) { - const SkRect child_bounds = SkRect::MakeLTRB(10.0f, 11.0f, 19.0f, 20.0f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlRect child_bounds = DlRect::MakeLTRB(10.0f, 11.0f, 19.0f, 20.0f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); - const SkPoint offset = SkPoint::Make(5.0f, 6.0f); + const DlPoint offset = DlPoint(5.0f, 6.0f); auto layer = std::make_shared(nullptr, offset); layer->Add(mock_layer); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), child_bounds.makeOffset(offset)); + EXPECT_EQ(layer->paint_bounds(), child_bounds.Shift(offset)); } } // namespace testing diff --git a/flow/layers/layer.cc b/flow/layers/layer.cc index d673bf0f383b5..3f712fb041f71 100644 --- a/flow/layers/layer.cc +++ b/flow/layers/layer.cc @@ -8,10 +8,7 @@ namespace flutter { -Layer::Layer() - : paint_bounds_(SkRect::MakeEmpty()), - unique_id_(NextUniqueID()), - original_layer_id_(unique_id_) {} +Layer::Layer() : unique_id_(NextUniqueID()), original_layer_id_(unique_id_) {} Layer::~Layer() = default; diff --git a/flow/layers/layer.h b/flow/layers/layer.h index c64f69633de95..f3e9cb284596b 100644 --- a/flow/layers/layer.h +++ b/flow/layers/layer.h @@ -22,14 +22,6 @@ #include "flutter/fml/logging.h" #include "flutter/fml/macros.h" #include "flutter/fml/trace_event.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkColor.h" -#include "third_party/skia/include/core/SkColorFilter.h" -#include "third_party/skia/include/core/SkMatrix.h" -#include "third_party/skia/include/core/SkPath.h" -#include "third_party/skia/include/core/SkRRect.h" -#include "third_party/skia/include/core/SkRect.h" -#include "third_party/skia/include/utils/SkNWayCanvas.h" class GrDirectContext; @@ -45,7 +37,7 @@ class PerformanceOverlayLayer; class TextureLayer; class RasterCacheItem; -static constexpr SkRect kGiantRect = SkRect::MakeLTRB(-1E9F, -1E9F, 1E9F, 1E9F); +static constexpr DlRect kGiantRect = DlRect::MakeLTRB(-1E9F, -1E9F, 1E9F, 1E9F); // This should be an exact copy of the Clip enum in painting.dart. enum Clip { kNone, kHardEdge, kAntiAlias, kAntiAliasWithSaveLayer }; @@ -201,7 +193,7 @@ class Layer { // as determined during Preroll(). The bounds should include any // transform, clip or distortions performed by the layer itself, // but not any similar modifications inherited from its ancestors. - const SkRect& paint_bounds() const { return paint_bounds_; } + const DlRect& paint_bounds() const { return paint_bounds_; } // This must be set by the time Preroll() returns otherwise the layer will // be assumed to have empty paint bounds (paints no content). @@ -214,12 +206,12 @@ class Layer { // paint operation that arises due to the caching, the clip will // be the bounds of the layer needing caching, not the cull_rect // that we saw in the overall Preroll operation. - void set_paint_bounds(const SkRect& paint_bounds) { + void set_paint_bounds(const DlRect& paint_bounds) { paint_bounds_ = paint_bounds; } // Determines if the layer has any content. - bool is_empty() const { return paint_bounds_.isEmpty(); } + bool is_empty() const { return paint_bounds_.IsEmpty(); } // Determines if the Paint() method is necessary based on the properties // of the indicated PaintContext object. @@ -260,7 +252,7 @@ class Layer { virtual const testing::MockLayer* as_mock_layer() const { return nullptr; } private: - SkRect paint_bounds_; + DlRect paint_bounds_; uint64_t unique_id_; uint64_t original_layer_id_; bool subtree_has_platform_view_ = false; diff --git a/flow/layers/layer_raster_cache_item.cc b/flow/layers/layer_raster_cache_item.cc index 59c375db2a8f1..9a5b93c852b95 100644 --- a/flow/layers/layer_raster_cache_item.cc +++ b/flow/layers/layer_raster_cache_item.cc @@ -24,12 +24,12 @@ LayerRasterCacheItem::LayerRasterCacheItem(Layer* layer, can_cache_children_(can_cache_children) {} void LayerRasterCacheItem::PrerollSetup(PrerollContext* context, - const SkMatrix& matrix) { + const DlMatrix& matrix) { cache_state_ = CacheState::kNone; if (context->raster_cache && context->raster_cached_entries) { context->raster_cached_entries->push_back(this); child_items_ = context->raster_cached_entries->size(); - matrix_ = matrix; + set_matrix(matrix); } } @@ -42,7 +42,7 @@ std::unique_ptr LayerRasterCacheItem::Make( } void LayerRasterCacheItem::PrerollFinalize(PrerollContext* context, - const SkMatrix& matrix) { + const DlMatrix& matrix) { if (!context->raster_cache || !context->raster_cached_entries) { return; } @@ -91,10 +91,10 @@ std::optional LayerRasterCacheItem::GetId() const { const SkRect* LayerRasterCacheItem::GetPaintBoundsFromLayer() const { switch (cache_state_) { case CacheState::kCurrent: - return &(layer_->paint_bounds()); + return &ToSkRect(layer_->paint_bounds()); case CacheState::kChildren: FML_DCHECK(layer_->as_container_layer()); - return &(layer_->as_container_layer()->child_paint_bounds()); + return &ToSkRect(layer_->as_container_layer()->child_paint_bounds()); default: FML_DCHECK(cache_state_ != CacheState::kNone); return nullptr; diff --git a/flow/layers/layer_raster_cache_item.h b/flow/layers/layer_raster_cache_item.h index 5e2dddfae03d0..0aba77e9198af 100644 --- a/flow/layers/layer_raster_cache_item.h +++ b/flow/layers/layer_raster_cache_item.h @@ -33,10 +33,10 @@ class LayerRasterCacheItem : public RasterCacheItem { std::optional GetId() const override; - void PrerollSetup(PrerollContext* context, const SkMatrix& matrix) override; + void PrerollSetup(PrerollContext* context, const DlMatrix& matrix) override; void PrerollFinalize(PrerollContext* context, - const SkMatrix& matrix) override; + const DlMatrix& matrix) override; bool Draw(const PaintContext& context, const DlPaint* paint) const override; diff --git a/flow/layers/layer_state_stack.cc b/flow/layers/layer_state_stack.cc index 07ab3cc864b18..7f0e7b126a319 100644 --- a/flow/layers/layer_state_stack.cc +++ b/flow/layers/layer_state_stack.cc @@ -27,11 +27,11 @@ class DummyDelegate : public LayerStateStack::Delegate { void decommission() override {} - SkRect local_cull_rect() const override { + DlRect local_cull_rect() const override { error(); return {}; } - SkRect device_cull_rect() const override { + DlRect device_cull_rect() const override { error(); return {}; } @@ -39,35 +39,26 @@ class DummyDelegate : public LayerStateStack::Delegate { error(); return dummy_matrix_; } - SkM44 matrix_4x4() const override { - error(); - return {}; - } - SkMatrix matrix_3x3() const override { - error(); - return {}; - } - bool content_culled(const SkRect& content_bounds) const override { + bool content_culled(const DlRect& content_bounds) const override { error(); return true; } void save() override {} - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, LayerStateStack::RenderingAttributes& attributes, DlBlendMode blend, const DlImageFilter* backdrop, std::optional backdrop_id) override {} void restore() override {} - void translate(SkScalar tx, SkScalar ty) override {} - void transform(const SkM44& m44) override {} - void transform(const SkMatrix& matrix) override {} + void translate(DlScalar tx, DlScalar ty) override {} + void transform(const DlMatrix& matrix) override {} void integralTransform() override {} - void clipRect(const SkRect& rect, ClipOp op, bool is_aa) override {} - void clipRRect(const SkRRect& rrect, ClipOp op, bool is_aa) override {} - void clipPath(const SkPath& path, ClipOp op, bool is_aa) override {} + void clipRect(const DlRect& rect, ClipOp op, bool is_aa) override {} + void clipRRect(const DlRoundRect& rrect, ClipOp op, bool is_aa) override {} + void clipPath(const DlPath& path, ClipOp op, bool is_aa) override {} private: static void error() { @@ -87,56 +78,50 @@ class DlCanvasDelegate : public LayerStateStack::Delegate { DlCanvas* canvas() const override { return canvas_; } - SkRect local_cull_rect() const override { - return canvas_->GetLocalClipBounds(); + DlRect local_cull_rect() const override { + return canvas_->GetLocalClipCoverage(); } - SkRect device_cull_rect() const override { - return canvas_->GetDestinationClipBounds(); + DlRect device_cull_rect() const override { + return canvas_->GetDestinationClipCoverage(); } DlMatrix matrix() const override { return canvas_->GetMatrix(); } - SkM44 matrix_4x4() const override { - return canvas_->GetTransformFullPerspective(); - } - SkMatrix matrix_3x3() const override { return canvas_->GetTransform(); } - bool content_culled(const SkRect& content_bounds) const override { + bool content_culled(const DlRect& content_bounds) const override { return canvas_->QuickReject(content_bounds); } void save() override { canvas_->Save(); } - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, LayerStateStack::RenderingAttributes& attributes, DlBlendMode blend_mode, const DlImageFilter* backdrop, std::optional backdrop_id) override { TRACE_EVENT0("flutter", "Canvas::saveLayer"); DlPaint paint; - std::optional rect = ToDlRect(bounds); - canvas_->SaveLayer(rect, attributes.fill(paint, blend_mode), backdrop, + canvas_->SaveLayer(bounds, attributes.fill(paint, blend_mode), backdrop, backdrop_id); } void restore() override { canvas_->Restore(); } - void translate(SkScalar tx, SkScalar ty) override { + void translate(DlScalar tx, DlScalar ty) override { canvas_->Translate(tx, ty); } - void transform(const SkM44& m44) override { canvas_->Transform(m44); } - void transform(const SkMatrix& matrix) override { + void transform(const DlMatrix& matrix) override { canvas_->Transform(matrix); } void integralTransform() override { - SkM44 integral; - if (RasterCacheUtil::ComputeIntegralTransCTM(matrix_4x4(), &integral)) { + DlMatrix integral; + if (RasterCacheUtil::ComputeIntegralTransCTM(matrix(), &integral)) { canvas_->SetTransform(integral); } } - void clipRect(const SkRect& rect, ClipOp op, bool is_aa) override { + void clipRect(const DlRect& rect, ClipOp op, bool is_aa) override { canvas_->ClipRect(rect, op, is_aa); } - void clipRRect(const SkRRect& rrect, ClipOp op, bool is_aa) override { - canvas_->ClipRRect(rrect, op, is_aa); + void clipRRect(const DlRoundRect& rrect, ClipOp op, bool is_aa) override { + canvas_->ClipRoundRect(rrect, op, is_aa); } - void clipPath(const SkPath& path, ClipOp op, bool is_aa) override { + void clipPath(const DlPath& path, ClipOp op, bool is_aa) override { canvas_->ClipPath(path, op, is_aa); } @@ -147,25 +132,25 @@ class DlCanvasDelegate : public LayerStateStack::Delegate { class PrerollDelegate : public LayerStateStack::Delegate { public: - PrerollDelegate(const SkRect& cull_rect, const SkMatrix& matrix) { + PrerollDelegate(const DlRect& cull_rect, const DlMatrix& matrix) { save_stack_.emplace_back(cull_rect, matrix); } void decommission() override {} DlMatrix matrix() const override { return state().matrix(); } - SkM44 matrix_4x4() const override { return state().matrix_4x4(); } - SkMatrix matrix_3x3() const override { return state().matrix_3x3(); } - SkRect local_cull_rect() const override { return state().local_cull_rect(); } - SkRect device_cull_rect() const override { - return state().device_cull_rect(); + DlRect local_cull_rect() const override { + return state().GetLocalCullCoverage(); } - bool content_culled(const SkRect& content_bounds) const override { + DlRect device_cull_rect() const override { + return state().GetDeviceCullCoverage(); + } + bool content_culled(const DlRect& content_bounds) const override { return state().content_culled(content_bounds); } void save() override { save_stack_.emplace_back(state()); } - void saveLayer(const SkRect& bounds, + void saveLayer(const DlRect& bounds, LayerStateStack::RenderingAttributes& attributes, DlBlendMode blend, const DlImageFilter* backdrop, @@ -174,34 +159,24 @@ class PrerollDelegate : public LayerStateStack::Delegate { } void restore() override { save_stack_.pop_back(); } - void translate(SkScalar tx, SkScalar ty) override { + void translate(DlScalar tx, DlScalar ty) override { state().translate(tx, ty); } - void transform(const SkM44& m44) override { state().transform(m44); } - void transform(const SkMatrix& matrix) override { state().transform(matrix); } + void transform(const DlMatrix& matrix) override { state().transform(matrix); } void integralTransform() override { - if (state().using_4x4_matrix()) { - SkM44 integral; - if (RasterCacheUtil::ComputeIntegralTransCTM(state().matrix_4x4(), - &integral)) { - state().setTransform(integral); - } - } else { - SkMatrix integral; - if (RasterCacheUtil::ComputeIntegralTransCTM(state().matrix_3x3(), - &integral)) { - state().setTransform(integral); - } + DlMatrix integral; + if (RasterCacheUtil::ComputeIntegralTransCTM(state().matrix(), &integral)) { + state().setTransform(integral); } } - void clipRect(const SkRect& rect, ClipOp op, bool is_aa) override { + void clipRect(const DlRect& rect, ClipOp op, bool is_aa) override { state().clipRect(rect, op, is_aa); } - void clipRRect(const SkRRect& rrect, ClipOp op, bool is_aa) override { + void clipRRect(const DlRoundRect& rrect, ClipOp op, bool is_aa) override { state().clipRRect(rrect, op, is_aa); } - void clipPath(const SkPath& path, ClipOp op, bool is_aa) override { + void clipPath(const DlPath& path, ClipOp op, bool is_aa) override { state().clipPath(path, op, is_aa); } @@ -232,7 +207,7 @@ class SaveEntry : public LayerStateStack::StateEntry { class SaveLayerEntry : public LayerStateStack::StateEntry { public: - SaveLayerEntry(const SkRect& bounds, + SaveLayerEntry(const DlRect& bounds, DlBlendMode blend_mode, const LayerStateStack::RenderingAttributes& prev) : bounds_(bounds), blend_mode_(blend_mode), old_attributes_(prev) {} @@ -248,7 +223,7 @@ class SaveLayerEntry : public LayerStateStack::StateEntry { } protected: - const SkRect bounds_; + const DlRect bounds_; const DlBlendMode blend_mode_; const LayerStateStack::RenderingAttributes old_attributes_; @@ -257,7 +232,7 @@ class SaveLayerEntry : public LayerStateStack::StateEntry { class OpacityEntry : public LayerStateStack::StateEntry { public: - OpacityEntry(const SkRect& bounds, + OpacityEntry(const DlRect& bounds, SkScalar opacity, const LayerStateStack::RenderingAttributes& prev) : bounds_(bounds), @@ -278,17 +253,17 @@ class OpacityEntry : public LayerStateStack::StateEntry { } private: - const SkRect bounds_; - const SkScalar opacity_; - const SkScalar old_opacity_; - const SkRect old_bounds_; + const DlRect bounds_; + const DlScalar opacity_; + const DlScalar old_opacity_; + const DlRect old_bounds_; FML_DISALLOW_COPY_ASSIGN_AND_MOVE(OpacityEntry); }; class ImageFilterEntry : public LayerStateStack::StateEntry { public: - ImageFilterEntry(const SkRect& bounds, + ImageFilterEntry(const DlRect& bounds, const std::shared_ptr& filter, const LayerStateStack::RenderingAttributes& prev) : bounds_(bounds), @@ -310,17 +285,17 @@ class ImageFilterEntry : public LayerStateStack::StateEntry { // void update_mutators(MutatorsStack* mutators_stack) const override; private: - const SkRect bounds_; + const DlRect bounds_; const std::shared_ptr filter_; const std::shared_ptr old_filter_; - const SkRect old_bounds_; + const DlRect old_bounds_; FML_DISALLOW_COPY_ASSIGN_AND_MOVE(ImageFilterEntry); }; class ColorFilterEntry : public LayerStateStack::StateEntry { public: - ColorFilterEntry(const SkRect& bounds, + ColorFilterEntry(const DlRect& bounds, const std::shared_ptr& filter, const LayerStateStack::RenderingAttributes& prev) : bounds_(bounds), @@ -342,17 +317,17 @@ class ColorFilterEntry : public LayerStateStack::StateEntry { // void update_mutators(MutatorsStack* mutators_stack) const override; private: - const SkRect bounds_; + const DlRect bounds_; const std::shared_ptr filter_; const std::shared_ptr old_filter_; - const SkRect old_bounds_; + const DlRect old_bounds_; FML_DISALLOW_COPY_ASSIGN_AND_MOVE(ColorFilterEntry); }; class BackdropFilterEntry : public SaveLayerEntry { public: - BackdropFilterEntry(const SkRect& bounds, + BackdropFilterEntry(const DlRect& bounds, const std::shared_ptr& filter, DlBlendMode blend_mode, std::optional backdrop_id, @@ -406,38 +381,21 @@ class TranslateEntry : public LayerStateStack::StateEntry { class TransformMatrixEntry : public LayerStateStack::StateEntry { public: - explicit TransformMatrixEntry(const SkMatrix& matrix) : matrix_(matrix) {} + explicit TransformMatrixEntry(const DlMatrix& matrix) : matrix_(matrix) {} void apply(LayerStateStack* stack) const override { stack->delegate_->transform(matrix_); } void update_mutators(MutatorsStack* mutators_stack) const override { - mutators_stack->PushTransform(matrix_); + mutators_stack->PushTransform(ToSkMatrix(matrix_)); } private: - const SkMatrix matrix_; + const DlMatrix matrix_; FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TransformMatrixEntry); }; -class TransformM44Entry : public LayerStateStack::StateEntry { - public: - explicit TransformM44Entry(const SkM44& m44) : m44_(m44) {} - - void apply(LayerStateStack* stack) const override { - stack->delegate_->transform(m44_); - } - void update_mutators(MutatorsStack* mutators_stack) const override { - mutators_stack->PushTransform(m44_.asM33()); - } - - private: - const SkM44 m44_; - - FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TransformM44Entry); -}; - class IntegralTransformEntry : public LayerStateStack::StateEntry { public: IntegralTransformEntry() = default; @@ -452,7 +410,7 @@ class IntegralTransformEntry : public LayerStateStack::StateEntry { class ClipRectEntry : public LayerStateStack::StateEntry { public: - ClipRectEntry(const SkRect& clip_rect, bool is_aa) + ClipRectEntry(const DlRect& clip_rect, bool is_aa) : clip_rect_(clip_rect), is_aa_(is_aa) {} void apply(LayerStateStack* stack) const override { @@ -460,11 +418,11 @@ class ClipRectEntry : public LayerStateStack::StateEntry { is_aa_); } void update_mutators(MutatorsStack* mutators_stack) const override { - mutators_stack->PushClipRect(clip_rect_); + mutators_stack->PushClipRect(ToSkRect(clip_rect_)); } private: - const SkRect clip_rect_; + const DlRect clip_rect_; const bool is_aa_; FML_DISALLOW_COPY_ASSIGN_AND_MOVE(ClipRectEntry); @@ -472,7 +430,7 @@ class ClipRectEntry : public LayerStateStack::StateEntry { class ClipRRectEntry : public LayerStateStack::StateEntry { public: - ClipRRectEntry(const SkRRect& clip_rrect, bool is_aa) + ClipRRectEntry(const DlRoundRect& clip_rrect, bool is_aa) : clip_rrect_(clip_rrect), is_aa_(is_aa) {} void apply(LayerStateStack* stack) const override { @@ -480,11 +438,11 @@ class ClipRRectEntry : public LayerStateStack::StateEntry { is_aa_); } void update_mutators(MutatorsStack* mutators_stack) const override { - mutators_stack->PushClipRRect(clip_rrect_); + mutators_stack->PushClipRRect(ToSkRRect(clip_rrect_)); } private: - const SkRRect clip_rrect_; + const DlRoundRect clip_rrect_; const bool is_aa_; FML_DISALLOW_COPY_ASSIGN_AND_MOVE(ClipRRectEntry); @@ -492,7 +450,7 @@ class ClipRRectEntry : public LayerStateStack::StateEntry { class ClipPathEntry : public LayerStateStack::StateEntry { public: - ClipPathEntry(const SkPath& clip_path, bool is_aa) + ClipPathEntry(const DlPath& clip_path, bool is_aa) : clip_path_(clip_path), is_aa_(is_aa) {} ~ClipPathEntry() override = default; @@ -501,11 +459,11 @@ class ClipPathEntry : public LayerStateStack::StateEntry { is_aa_); } void update_mutators(MutatorsStack* mutators_stack) const override { - mutators_stack->PushClipPath(clip_path_); + mutators_stack->PushClipPath(clip_path_.GetSkPath()); } private: - const SkPath clip_path_; + const DlPath clip_path_; const bool is_aa_; FML_DISALLOW_COPY_ASSIGN_AND_MOVE(ClipPathEntry); @@ -545,18 +503,18 @@ DlPaint* LayerStateStack::RenderingAttributes::fill(DlPaint& paint, using MutatorContext = LayerStateStack::MutatorContext; -void MutatorContext::saveLayer(const SkRect& bounds) { +void MutatorContext::saveLayer(const DlRect& bounds) { layer_state_stack_->save_layer(bounds); } -void MutatorContext::applyOpacity(const SkRect& bounds, SkScalar opacity) { +void MutatorContext::applyOpacity(const DlRect& bounds, DlScalar opacity) { if (opacity < SK_Scalar1) { layer_state_stack_->push_opacity(bounds, opacity); } } void MutatorContext::applyImageFilter( - const SkRect& bounds, + const DlRect& bounds, const std::shared_ptr& filter) { if (filter) { layer_state_stack_->push_image_filter(bounds, filter); @@ -564,7 +522,7 @@ void MutatorContext::applyImageFilter( } void MutatorContext::applyColorFilter( - const SkRect& bounds, + const DlRect& bounds, const std::shared_ptr& filter) { if (filter) { layer_state_stack_->push_color_filter(bounds, filter); @@ -572,7 +530,7 @@ void MutatorContext::applyColorFilter( } void MutatorContext::applyBackdropFilter( - const SkRect& bounds, + const DlRect& bounds, const std::shared_ptr& filter, DlBlendMode blend_mode, std::optional backdrop_id) { @@ -587,45 +545,35 @@ void MutatorContext::translate(SkScalar tx, SkScalar ty) { } } -void MutatorContext::transform(const SkMatrix& matrix) { - if (matrix.isTranslate()) { - translate(matrix.getTranslateX(), matrix.getTranslateY()); - } else if (!matrix.isIdentity()) { +void MutatorContext::transform(const DlMatrix& matrix) { + if (matrix.IsTranslationOnly()) { + translate(matrix.m[12], matrix.m[13]); + } else if (!matrix.IsIdentity()) { layer_state_stack_->maybe_save_layer_for_transform(save_needed_); save_needed_ = false; layer_state_stack_->push_transform(matrix); } } -void MutatorContext::transform(const SkM44& m44) { - if (DisplayListMatrixClipState::is_3x3(m44)) { - transform(m44.asM33()); - } else { - layer_state_stack_->maybe_save_layer_for_transform(save_needed_); - save_needed_ = false; - layer_state_stack_->push_transform(m44); - } -} - void MutatorContext::integralTransform() { layer_state_stack_->maybe_save_layer_for_transform(save_needed_); save_needed_ = false; layer_state_stack_->push_integral_transform(); } -void MutatorContext::clipRect(const SkRect& rect, bool is_aa) { +void MutatorContext::clipRect(const DlRect& rect, bool is_aa) { layer_state_stack_->maybe_save_layer_for_clip(save_needed_); save_needed_ = false; layer_state_stack_->push_clip_rect(rect, is_aa); } -void MutatorContext::clipRRect(const SkRRect& rrect, bool is_aa) { +void MutatorContext::clipRRect(const DlRoundRect& rrect, bool is_aa) { layer_state_stack_->maybe_save_layer_for_clip(save_needed_); save_needed_ = false; layer_state_stack_->push_clip_rrect(rrect, is_aa); } -void MutatorContext::clipPath(const SkPath& path, bool is_aa) { +void MutatorContext::clipPath(const DlPath& path, bool is_aa) { layer_state_stack_->maybe_save_layer_for_clip(save_needed_); save_needed_ = false; layer_state_stack_->push_clip_path(path, is_aa); @@ -655,14 +603,14 @@ void LayerStateStack::set_delegate(DlCanvas* canvas) { } } -void LayerStateStack::set_preroll_delegate(const SkRect& cull_rect) { - set_preroll_delegate(cull_rect, SkMatrix::I()); +void LayerStateStack::set_preroll_delegate(const DlRect& cull_rect) { + set_preroll_delegate(cull_rect, DlMatrix()); } -void LayerStateStack::set_preroll_delegate(const SkMatrix& matrix) { +void LayerStateStack::set_preroll_delegate(const DlMatrix& matrix) { set_preroll_delegate(kGiantRect, matrix); } -void LayerStateStack::set_preroll_delegate(const SkRect& cull_rect, - const SkMatrix& matrix) { +void LayerStateStack::set_preroll_delegate(const DlRect& cull_rect, + const DlMatrix& matrix) { clear_delegate(); delegate_ = std::make_shared(cull_rect, matrix); reapply_all(); @@ -695,7 +643,7 @@ void LayerStateStack::restore_to_count(size_t restore_count) { } } -void LayerStateStack::push_opacity(const SkRect& bounds, SkScalar opacity) { +void LayerStateStack::push_opacity(const DlRect& bounds, DlScalar opacity) { maybe_save_layer(opacity); state_stack_.emplace_back( std::make_unique(bounds, opacity, outstanding_)); @@ -703,7 +651,7 @@ void LayerStateStack::push_opacity(const SkRect& bounds, SkScalar opacity) { } void LayerStateStack::push_color_filter( - const SkRect& bounds, + const DlRect& bounds, const std::shared_ptr& filter) { maybe_save_layer(filter); state_stack_.emplace_back( @@ -712,7 +660,7 @@ void LayerStateStack::push_color_filter( } void LayerStateStack::push_image_filter( - const SkRect& bounds, + const DlRect& bounds, const std::shared_ptr& filter) { maybe_save_layer(filter); state_stack_.emplace_back( @@ -721,7 +669,7 @@ void LayerStateStack::push_image_filter( } void LayerStateStack::push_backdrop( - const SkRect& bounds, + const DlRect& bounds, const std::shared_ptr& filter, DlBlendMode blend_mode, std::optional backdrop_id) { @@ -735,12 +683,7 @@ void LayerStateStack::push_translate(SkScalar tx, SkScalar ty) { apply_last_entry(); } -void LayerStateStack::push_transform(const SkM44& m44) { - state_stack_.emplace_back(std::make_unique(m44)); - apply_last_entry(); -} - -void LayerStateStack::push_transform(const SkMatrix& matrix) { +void LayerStateStack::push_transform(const DlMatrix& matrix) { state_stack_.emplace_back(std::make_unique(matrix)); apply_last_entry(); } @@ -750,17 +693,17 @@ void LayerStateStack::push_integral_transform() { apply_last_entry(); } -void LayerStateStack::push_clip_rect(const SkRect& rect, bool is_aa) { +void LayerStateStack::push_clip_rect(const DlRect& rect, bool is_aa) { state_stack_.emplace_back(std::make_unique(rect, is_aa)); apply_last_entry(); } -void LayerStateStack::push_clip_rrect(const SkRRect& rrect, bool is_aa) { +void LayerStateStack::push_clip_rrect(const DlRoundRect& rrect, bool is_aa) { state_stack_.emplace_back(std::make_unique(rrect, is_aa)); apply_last_entry(); } -void LayerStateStack::push_clip_path(const SkPath& path, bool is_aa) { +void LayerStateStack::push_clip_path(const DlPath& path, bool is_aa) { state_stack_.emplace_back(std::make_unique(path, is_aa)); apply_last_entry(); } @@ -786,7 +729,7 @@ void LayerStateStack::do_save() { apply_last_entry(); } -void LayerStateStack::save_layer(const SkRect& bounds) { +void LayerStateStack::save_layer(const DlRect& bounds) { state_stack_.emplace_back(std::make_unique( bounds, DlBlendMode::kSrcOver, outstanding_)); apply_last_entry(); diff --git a/flow/layers/layer_state_stack.h b/flow/layers/layer_state_stack.h index ad505c09340aa..0582183a7ab0d 100644 --- a/flow/layers/layer_state_stack.h +++ b/flow/layers/layer_state_stack.h @@ -123,9 +123,9 @@ class LayerStateStack { // clip and transform information for a Preroll phase. This ensures // that only one delegate - either a DlCanvas or a preroll accumulator - // is present at any one time. - void set_preroll_delegate(const SkRect& cull_rect, const SkMatrix& matrix); - void set_preroll_delegate(const SkRect& cull_rect); - void set_preroll_delegate(const SkMatrix& matrix); + void set_preroll_delegate(const DlRect& cull_rect, const DlMatrix& matrix); + void set_preroll_delegate(const DlRect& cull_rect); + void set_preroll_delegate(const DlMatrix& matrix); // Fills the supplied MatatorsStack object with the mutations recorded // by this LayerStateStack in the order encountered. @@ -138,7 +138,7 @@ class LayerStateStack { } private: - AutoRestore(LayerStateStack* stack, const SkRect& bounds, int flags) + AutoRestore(LayerStateStack* stack, const DlRect& bounds, int flags) : layer_state_stack_(stack), stack_restore_count_(stack->stack_count()) { if (stack->needs_save_layer(flags)) { @@ -163,20 +163,20 @@ class LayerStateStack { // onto the canvas or builder to be applied at the next matching // restore. A saveLayer is always executed by this method even if // there are no outstanding attributes. - void saveLayer(const SkRect& bounds); + void saveLayer(const DlRect& bounds); // Records the opacity for application at the next call to // saveLayer or applyState. A saveLayer may be executed at // this time if the opacity cannot be batched with other // outstanding attributes. - void applyOpacity(const SkRect& bounds, SkScalar opacity); + void applyOpacity(const DlRect& bounds, DlScalar opacity); // Records the image filter for application at the next call to // saveLayer or applyState. A saveLayer may be executed at // this time if the image filter cannot be batched with other // outstanding attributes. // (Currently only opacity is recorded for batching) - void applyImageFilter(const SkRect& bounds, + void applyImageFilter(const DlRect& bounds, const std::shared_ptr& filter); // Records the color filter for application at the next call to @@ -184,7 +184,7 @@ class LayerStateStack { // this time if the color filter cannot be batched with other // outstanding attributes. // (Currently only opacity is recorded for batching) - void applyColorFilter(const SkRect& bounds, + void applyColorFilter(const DlRect& bounds, const std::shared_ptr& filter); // Saves the state stack and immediately executes a saveLayer @@ -195,20 +195,19 @@ class LayerStateStack { // builder installed at the time that this call is made, and // subsequent canvas or builder objects that are made delegates // will only see a saveLayer with the indicated blend_mode. - void applyBackdropFilter(const SkRect& bounds, + void applyBackdropFilter(const DlRect& bounds, const std::shared_ptr& filter, DlBlendMode blend_mode, std::optional backdrop_id); - void translate(SkScalar tx, SkScalar ty); - void translate(SkPoint tp) { translate(tp.fX, tp.fY); } - void transform(const SkM44& m44); - void transform(const SkMatrix& matrix); + void translate(DlScalar tx, DlScalar ty); + void translate(const DlPoint& tp) { translate(tp.x, tp.y); } + void transform(const DlMatrix& matrix); void integralTransform(); - void clipRect(const SkRect& rect, bool is_aa); - void clipRRect(const SkRRect& rrect, bool is_aa); - void clipPath(const SkPath& path, bool is_aa); + void clipRect(const DlRect& rect, bool is_aa); + void clipRRect(const DlRoundRect& rrect, bool is_aa); + void clipPath(const DlPath& path, bool is_aa); private: explicit MutatorContext(LayerStateStack* stack) @@ -241,12 +240,12 @@ class LayerStateStack { // // An AutoRestore instance will always be returned even if there // was no saveLayer applied. - [[nodiscard]] inline AutoRestore applyState(const SkRect& bounds, + [[nodiscard]] inline AutoRestore applyState(const DlRect& bounds, int can_apply_flags) { return AutoRestore(this, bounds, can_apply_flags); } - SkScalar outstanding_opacity() const { return outstanding_.opacity; } + DlScalar outstanding_opacity() const { return outstanding_.opacity; } std::shared_ptr outstanding_color_filter() const { return outstanding_.color_filter; @@ -263,7 +262,7 @@ class LayerStateStack { // of any outstanding attributes will include the output bounds of // applying any nested attributes. Thus, only the innermost content // bounds received will be sufficient to apply all outstanding attributes. - SkRect outstanding_bounds() const { return outstanding_.save_layer_bounds; } + DlRect outstanding_bounds() const { return outstanding_.save_layer_bounds; } // Fill the provided paint object with any oustanding attributes and // return a pointer to it, or return a nullptr if there were no @@ -272,11 +271,11 @@ class LayerStateStack { // The cull_rect (not the exact clip) relative to the device pixels. // This rectangle may be a conservative estimate of the true clip region. - SkRect device_cull_rect() const { return delegate_->device_cull_rect(); } + DlRect device_cull_rect() const { return delegate_->device_cull_rect(); } // The cull_rect (not the exact clip) relative to the local coordinates. // This rectangle may be a conservative estimate of the true clip region. - SkRect local_cull_rect() const { return delegate_->local_cull_rect(); } + DlRect local_cull_rect() const { return delegate_->local_cull_rect(); } // The transform from the local coordinates to the device coordinates // in 4x4 DlMatrix representation. This matrix provides all information @@ -284,21 +283,6 @@ class LayerStateStack { // accurately concatenate with other 4x4 matrices without losing information. const DlMatrix matrix() const { return delegate_->matrix(); } - // The transform from the local coordinates to the device coordinates - // in the most capable 4x4 matrix representation. This matrix may be - // more information than is needed to compute bounds for a 2D rendering - // primitive, but it will accurately concatenate with other 4x4 matrices - // without losing information. - SkM44 transform_4x4() const { return delegate_->matrix_4x4(); } - - // The transform from the local coordinates to the device coordinates - // in a more compact 3x3 matrix represenation that provides enough - // information to accurately transform 2D primitives into their - // resulting 2D bounds. This matrix also has enough information to - // concat with other 2D affine transforms, but does not carry enough - // information to accurately concat with fully perspective matrics. - SkMatrix transform_3x3() const { return delegate_->matrix_3x3(); } - // Tests if painting content with the current outstanding attributes // will produce any content. This method does not check the current // transform or clip for being singular or empty. @@ -309,7 +293,7 @@ class LayerStateStack { // This method does not check the outstanding attributes to verify that // they produce visible results. // See |painting_is_nop| - bool content_culled(const SkRect& content_bounds) const { + bool content_culled(const DlRect& content_bounds) const { return delegate_->content_culled(content_bounds); } @@ -334,24 +318,23 @@ class LayerStateStack { // and then apply it to the current canvas and builder. // --------------------- // void push_attributes(); - void push_opacity(const SkRect& rect, SkScalar opacity); - void push_color_filter(const SkRect& bounds, + void push_opacity(const DlRect& rect, DlScalar opacity); + void push_color_filter(const DlRect& bounds, const std::shared_ptr& filter); - void push_image_filter(const SkRect& bounds, + void push_image_filter(const DlRect& bounds, const std::shared_ptr& filter); - void push_backdrop(const SkRect& bounds, + void push_backdrop(const DlRect& bounds, const std::shared_ptr& filter, DlBlendMode blend_mode, std::optional backdrop_id); - void push_translate(SkScalar tx, SkScalar ty); - void push_transform(const SkM44& matrix); - void push_transform(const SkMatrix& matrix); + void push_translate(DlScalar tx, DlScalar ty); + void push_transform(const DlMatrix& matrix); void push_integral_transform(); - void push_clip_rect(const SkRect& rect, bool is_aa); - void push_clip_rrect(const SkRRect& rrect, bool is_aa); - void push_clip_path(const SkPath& path, bool is_aa); + void push_clip_rect(const DlRect& rect, bool is_aa); + void push_clip_rrect(const DlRoundRect& rrect, bool is_aa); + void push_clip_path(const DlPath& path, bool is_aa); // --------------------- // The maybe/needs_save_layer methods will determine if the indicated @@ -362,11 +345,11 @@ class LayerStateStack { // --------------------- bool needs_save_layer(int flags) const; void do_save(); - void save_layer(const SkRect& bounds); + void save_layer(const DlRect& bounds); void maybe_save_layer_for_transform(bool needs_save); void maybe_save_layer_for_clip(bool needs_save); void maybe_save_layer(int apply_flags); - void maybe_save_layer(SkScalar opacity); + void maybe_save_layer(DlScalar opacity); void maybe_save_layer(const std::shared_ptr& filter); void maybe_save_layer(const std::shared_ptr& filter); // --------------------- @@ -381,9 +364,9 @@ class LayerStateStack { // the existing outstanding attributes - thus we need to record // the bounds that were supplied with the most recent previous // attribute to be applied. - SkRect save_layer_bounds{0, 0, 0, 0}; + DlRect save_layer_bounds; - SkScalar opacity = SK_Scalar1; + DlScalar opacity = SK_Scalar1; std::shared_ptr color_filter; std::shared_ptr image_filter; @@ -445,30 +428,27 @@ class LayerStateStack { virtual DlCanvas* canvas() const { return nullptr; } - virtual SkRect local_cull_rect() const = 0; - virtual SkRect device_cull_rect() const = 0; + virtual DlRect local_cull_rect() const = 0; + virtual DlRect device_cull_rect() const = 0; virtual DlMatrix matrix() const = 0; - virtual SkM44 matrix_4x4() const = 0; - virtual SkMatrix matrix_3x3() const = 0; - virtual bool content_culled(const SkRect& content_bounds) const = 0; + virtual bool content_culled(const DlRect& content_bounds) const = 0; virtual void save() = 0; virtual void saveLayer( - const SkRect& bounds, + const DlRect& bounds, RenderingAttributes& attributes, DlBlendMode blend, const DlImageFilter* backdrop, std::optional backdrop_id = std::nullopt) = 0; virtual void restore() = 0; - virtual void translate(SkScalar tx, SkScalar ty) = 0; - virtual void transform(const SkM44& m44) = 0; - virtual void transform(const SkMatrix& matrix) = 0; + virtual void translate(DlScalar tx, DlScalar ty) = 0; + virtual void transform(const DlMatrix& matrix) = 0; virtual void integralTransform() = 0; - virtual void clipRect(const SkRect& rect, ClipOp op, bool is_aa) = 0; - virtual void clipRRect(const SkRRect& rrect, ClipOp op, bool is_aa) = 0; - virtual void clipPath(const SkPath& path, ClipOp op, bool is_aa) = 0; + virtual void clipRect(const DlRect& rect, ClipOp op, bool is_aa) = 0; + virtual void clipRRect(const DlRoundRect& rrect, ClipOp op, bool is_aa) = 0; + virtual void clipPath(const DlPath& path, ClipOp op, bool is_aa) = 0; }; friend class DummyDelegate; friend class DlCanvasDelegate; diff --git a/flow/layers/layer_state_stack_unittests.cc b/flow/layers/layer_state_stack_unittests.cc index bffe21ccf7750..68de74bd22ddc 100644 --- a/flow/layers/layer_state_stack_unittests.cc +++ b/flow/layers/layer_state_stack_unittests.cc @@ -21,14 +21,12 @@ TEST(LayerStateStack, AccessorsDieWithoutDelegate) { "LayerStateStack state queried without a delegate"); EXPECT_DEATH_IF_SUPPORTED(state_stack.local_cull_rect(), "LayerStateStack state queried without a delegate"); - EXPECT_DEATH_IF_SUPPORTED(state_stack.transform_3x3(), - "LayerStateStack state queried without a delegate"); - EXPECT_DEATH_IF_SUPPORTED(state_stack.transform_4x4(), + EXPECT_DEATH_IF_SUPPORTED(state_stack.matrix(), "LayerStateStack state queried without a delegate"); EXPECT_DEATH_IF_SUPPORTED(state_stack.content_culled({}), "LayerStateStack state queried without a delegate"); { - // state_stack.set_preroll_delegate(kGiantRect, SkMatrix::I()); + // state_stack.set_preroll_delegate(kGiantRect, DlMatrix()); auto mutator = state_stack.save(); mutator.applyOpacity({}, 0.5); state_stack.clear_delegate(); @@ -41,16 +39,15 @@ TEST(LayerStateStack, Defaults) { LayerStateStack state_stack; ASSERT_EQ(state_stack.canvas_delegate(), nullptr); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); ASSERT_EQ(state_stack.outstanding_color_filter(), nullptr); ASSERT_EQ(state_stack.outstanding_image_filter(), nullptr); - ASSERT_EQ(state_stack.outstanding_bounds(), SkRect()); + ASSERT_EQ(state_stack.outstanding_bounds(), DlRect()); - state_stack.set_preroll_delegate(kGiantRect, SkMatrix::I()); + state_stack.set_preroll_delegate(kGiantRect, DlMatrix()); ASSERT_EQ(state_stack.device_cull_rect(), kGiantRect); ASSERT_EQ(state_stack.local_cull_rect(), kGiantRect); - ASSERT_EQ(state_stack.transform_3x3(), SkMatrix::I()); - ASSERT_EQ(state_stack.transform_4x4(), SkM44()); + ASSERT_EQ(state_stack.matrix(), DlMatrix()); DlPaint dl_paint; state_stack.fill(dl_paint); @@ -113,7 +110,7 @@ TEST(LayerStateStack, OldDelegateIsRolledBack) { ASSERT_TRUE(builder.GetTransform().isIdentity()); ASSERT_EQ(canvas.GetTransform(), SkMatrix::Translate(10, 10)); - state_stack.set_preroll_delegate(SkRect::MakeWH(100, 100)); + state_stack.set_preroll_delegate(DlRect::MakeWH(100, 100)); ASSERT_TRUE(builder.GetTransform().isIdentity()); ASSERT_TRUE(canvas.GetTransform().isIdentity()); @@ -132,10 +129,10 @@ TEST(LayerStateStack, OldDelegateIsRolledBack) { } TEST(LayerStateStack, Opacity) { - SkRect rect = {10, 10, 20, 20}; + DlRect rect = DlRect::MakeLTRB(10, 10, 20, 20); LayerStateStack state_stack; - state_stack.set_preroll_delegate(SkRect::MakeLTRB(0, 0, 50, 50)); + state_stack.set_preroll_delegate(DlRect::MakeLTRB(0, 0, 50, 50)); { auto mutator = state_stack.save(); mutator.applyOpacity(rect, 0.5f); @@ -157,8 +154,8 @@ TEST(LayerStateStack, Opacity) { state_stack.set_delegate(&builder); { auto restore = state_stack.applyState(rect, 0); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); - ASSERT_EQ(state_stack.outstanding_bounds(), SkRect()); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); + ASSERT_EQ(state_stack.outstanding_bounds(), DlRect()); DlPaint paint; state_stack.fill(paint); @@ -169,7 +166,7 @@ TEST(LayerStateStack, Opacity) { DisplayListBuilder expected; DlPaint save_paint = DlPaint().setOpacity(state_stack.outstanding_opacity()); - expected.SaveLayer(&rect, &save_paint); + expected.SaveLayer(rect, &save_paint); expected.DrawRect(rect, DlPaint()); expected.Restore(); ASSERT_TRUE(DisplayListsEQ_Verbose(builder.Build(), expected.Build())); @@ -201,19 +198,19 @@ TEST(LayerStateStack, Opacity) { ASSERT_EQ(state_stack.outstanding_bounds(), rect); } - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); - ASSERT_EQ(state_stack.outstanding_bounds(), SkRect()); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); + ASSERT_EQ(state_stack.outstanding_bounds(), DlRect()); } TEST(LayerStateStack, ColorFilter) { - SkRect rect = {10, 10, 20, 20}; + DlRect rect = DlRect::MakeLTRB(10, 10, 20, 20); auto outer_filter = DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kColorBurn); auto inner_filter = DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kColorBurn); LayerStateStack state_stack; - state_stack.set_preroll_delegate(SkRect::MakeLTRB(0, 0, 50, 50)); + state_stack.set_preroll_delegate(DlRect::MakeLTRB(0, 0, 50, 50)); { auto mutator = state_stack.save(); mutator.applyColorFilter(rect, outer_filter); @@ -244,8 +241,8 @@ TEST(LayerStateStack, ColorFilter) { DisplayListBuilder expected; DlPaint outer_save_paint = DlPaint().setColorFilter(outer_filter); DlPaint inner_save_paint = DlPaint().setColorFilter(inner_filter); - expected.SaveLayer(&rect, &outer_save_paint); - expected.SaveLayer(&rect, &inner_save_paint); + expected.SaveLayer(rect, &outer_save_paint); + expected.SaveLayer(rect, &inner_save_paint); expected.DrawRect(rect, DlPaint()); expected.Restore(); expected.Restore(); @@ -254,7 +251,7 @@ TEST(LayerStateStack, ColorFilter) { // Verify output with applyState that accepts color filters { - SkRect rect = {10, 10, 20, 20}; + DlRect rect = DlRect::MakeLTRB(10, 10, 20, 20); DisplayListBuilder builder; state_stack.set_delegate(&builder); { @@ -271,7 +268,7 @@ TEST(LayerStateStack, ColorFilter) { DisplayListBuilder expected; DlPaint save_paint = DlPaint().setColorFilter(outer_filter); DlPaint draw_paint = DlPaint().setColorFilter(inner_filter); - expected.SaveLayer(&rect, &save_paint); + expected.SaveLayer(rect, &save_paint); expected.DrawRect(rect, draw_paint); ASSERT_TRUE(DisplayListsEQ_Verbose(builder.Build(), expected.Build())); } @@ -284,19 +281,19 @@ TEST(LayerStateStack, ColorFilter) { } TEST(LayerStateStack, ImageFilter) { - SkRect rect = {10, 10, 20, 20}; + DlRect rect = DlRect::MakeLTRB(10, 10, 20, 20); std::shared_ptr outer_filter = DlImageFilter::MakeBlur(2.0f, 2.0f, DlTileMode::kClamp); std::shared_ptr inner_filter = DlImageFilter::MakeBlur(3.0f, 3.0f, DlTileMode::kClamp); - SkRect inner_src_rect = rect; + DlRect inner_src_rect = rect; DlRect dl_outer_src_rect; - ASSERT_EQ(inner_filter->map_local_bounds(ToDlRect(rect), dl_outer_src_rect), + ASSERT_EQ(inner_filter->map_local_bounds(rect, dl_outer_src_rect), &dl_outer_src_rect); - SkRect outer_src_rect = ToSkRect(dl_outer_src_rect); + DlRect outer_src_rect = dl_outer_src_rect; LayerStateStack state_stack; - state_stack.set_preroll_delegate(SkRect::MakeLTRB(0, 0, 50, 50)); + state_stack.set_preroll_delegate(DlRect::MakeLTRB(0, 0, 50, 50)); { auto mutator = state_stack.save(); mutator.applyImageFilter(outer_src_rect, outer_filter); @@ -327,8 +324,8 @@ TEST(LayerStateStack, ImageFilter) { DisplayListBuilder expected; DlPaint outer_save_paint = DlPaint().setImageFilter(outer_filter); DlPaint inner_save_paint = DlPaint().setImageFilter(inner_filter); - expected.SaveLayer(&outer_src_rect, &outer_save_paint); - expected.SaveLayer(&inner_src_rect, &inner_save_paint); + expected.SaveLayer(outer_src_rect, &outer_save_paint); + expected.SaveLayer(inner_src_rect, &inner_save_paint); expected.DrawRect(rect, DlPaint()); expected.Restore(); expected.Restore(); @@ -337,7 +334,7 @@ TEST(LayerStateStack, ImageFilter) { // Verify output with applyState that accepts color filters { - SkRect rect = {10, 10, 20, 20}; + DlRect rect = DlRect::MakeLTRB(10, 10, 20, 20); DisplayListBuilder builder; state_stack.set_delegate(&builder); { @@ -354,7 +351,7 @@ TEST(LayerStateStack, ImageFilter) { DisplayListBuilder expected; DlPaint save_paint = DlPaint().setImageFilter(outer_filter); DlPaint draw_paint = DlPaint().setImageFilter(inner_filter); - expected.SaveLayer(&outer_src_rect, &save_paint); + expected.SaveLayer(outer_src_rect, &save_paint); expected.DrawRect(rect, draw_paint); ASSERT_TRUE(DisplayListsEQ_Verbose(builder.Build(), expected.Build())); } @@ -367,7 +364,7 @@ TEST(LayerStateStack, ImageFilter) { } TEST(LayerStateStack, OpacityAndColorFilterInteraction) { - SkRect rect = {10, 10, 20, 20}; + DlRect rect = DlRect::MakeLTRB(10, 10, 20, 20); auto color_filter = DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kColorBurn); @@ -390,7 +387,7 @@ TEST(LayerStateStack, OpacityAndColorFilterInteraction) { // The opacity will have been resolved by a saveLayer ASSERT_EQ(builder.GetSaveCount(), 2); ASSERT_EQ(state_stack.outstanding_color_filter(), color_filter); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); } ASSERT_EQ(builder.GetSaveCount(), 1); ASSERT_EQ(state_stack.outstanding_color_filter(), nullptr); @@ -398,7 +395,7 @@ TEST(LayerStateStack, OpacityAndColorFilterInteraction) { } ASSERT_EQ(builder.GetSaveCount(), 1); ASSERT_EQ(state_stack.outstanding_color_filter(), nullptr); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); { auto mutator1 = state_stack.save(); @@ -418,15 +415,15 @@ TEST(LayerStateStack, OpacityAndColorFilterInteraction) { } ASSERT_EQ(builder.GetSaveCount(), 1); ASSERT_EQ(state_stack.outstanding_color_filter(), color_filter); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); } ASSERT_EQ(builder.GetSaveCount(), 1); ASSERT_EQ(state_stack.outstanding_color_filter(), nullptr); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); } TEST(LayerStateStack, OpacityAndImageFilterInteraction) { - SkRect rect = {10, 10, 20, 20}; + DlRect rect = DlRect::MakeLTRB(10, 10, 20, 20); std::shared_ptr image_filter = DlImageFilter::MakeBlur(2.0f, 2.0f, DlTileMode::kClamp); @@ -457,7 +454,7 @@ TEST(LayerStateStack, OpacityAndImageFilterInteraction) { } ASSERT_EQ(builder.GetSaveCount(), 1); ASSERT_EQ(state_stack.outstanding_image_filter(), nullptr); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); { auto mutator1 = state_stack.save(); @@ -477,15 +474,15 @@ TEST(LayerStateStack, OpacityAndImageFilterInteraction) { } ASSERT_EQ(builder.GetSaveCount(), 1); ASSERT_EQ(state_stack.outstanding_image_filter(), image_filter); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); } ASSERT_EQ(builder.GetSaveCount(), 1); ASSERT_EQ(state_stack.outstanding_image_filter(), nullptr); - ASSERT_EQ(state_stack.outstanding_opacity(), SK_Scalar1); + ASSERT_EQ(state_stack.outstanding_opacity(), 1.0f); } TEST(LayerStateStack, ColorFilterAndImageFilterInteraction) { - SkRect rect = {10, 10, 20, 20}; + DlRect rect = DlRect::MakeLTRB(10, 10, 20, 20); auto color_filter = DlColorFilter::MakeBlend(DlColor::kYellow(), DlBlendMode::kColorBurn); auto image_filter = DlImageFilter::MakeBlur(2.0f, 2.0f, DlTileMode::kClamp); diff --git a/flow/layers/layer_tree.cc b/flow/layers/layer_tree.cc index 7f051d9aef107..871e192bd38c1 100644 --- a/flow/layers/layer_tree.cc +++ b/flow/layers/layer_tree.cc @@ -18,7 +18,7 @@ namespace flutter { LayerTree::LayerTree(const std::shared_ptr& root_layer, - const SkISize& frame_size) + const DlISize& frame_size) : root_layer_(root_layer), frame_size_(frame_size) {} inline SkColorSpace* GetColorSpace(DlCanvas* canvas) { @@ -27,7 +27,7 @@ inline SkColorSpace* GetColorSpace(DlCanvas* canvas) { bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame, bool ignore_raster_cache, - SkRect cull_rect) { + DlRect cull_rect) { TRACE_EVENT0("flutter", "LayerTree::Preroll"); if (!root_layer_) { @@ -37,8 +37,8 @@ bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame, SkColorSpace* color_space = GetColorSpace(frame.canvas()); LayerStateStack state_stack; - state_stack.set_preroll_delegate(cull_rect, - frame.root_surface_transformation()); + state_stack.set_preroll_delegate( + cull_rect, ToDlMatrix(frame.root_surface_transformation())); raster_cache_items_.clear(); @@ -145,7 +145,7 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame, } sk_sp LayerTree::Flatten( - const SkRect& bounds, + const DlRect& bounds, const std::shared_ptr& texture_registry, GrDirectContext* gr_context) { TRACE_EVENT0("flutter", "LayerTree::Flatten"); diff --git a/flow/layers/layer_tree.h b/flow/layers/layer_tree.h index 5cde23279ba63..430f836ba4147 100644 --- a/flow/layers/layer_tree.h +++ b/flow/layers/layer_tree.h @@ -22,7 +22,7 @@ namespace flutter { class LayerTree { public: LayerTree(const std::shared_ptr& root_layer, - const SkISize& frame_size); + const DlISize& frame_size); // Perform a preroll pass on the tree and return information about // the tree that affects rendering this frame. @@ -33,7 +33,7 @@ class LayerTree { // from the root surface. bool Preroll(CompositorContext::ScopedFrame& frame, bool ignore_raster_cache = false, - SkRect cull_rect = kGiantRect); + DlRect cull_rect = kGiantRect); #if !SLIMPELLER static void TryToRasterCache( @@ -46,19 +46,19 @@ class LayerTree { bool ignore_raster_cache = false) const; sk_sp Flatten( - const SkRect& bounds, + const DlRect& bounds, const std::shared_ptr& texture_registry = nullptr, GrDirectContext* gr_context = nullptr); Layer* root_layer() const { return root_layer_.get(); } - const SkISize& frame_size() const { return frame_size_; } + const DlISize& frame_size() const { return frame_size_; } const PaintRegionMap& paint_region_map() const { return paint_region_map_; } PaintRegionMap& paint_region_map() { return paint_region_map_; } private: std::shared_ptr root_layer_; - SkISize frame_size_ = SkISize::MakeEmpty(); // Physical pixels. + DlISize frame_size_; // Physical pixels. PaintRegionMap paint_region_map_; diff --git a/flow/layers/layer_tree_unittests.cc b/flow/layers/layer_tree_unittests.cc index 2d8952823eb2a..7708b736d30c4 100644 --- a/flow/layers/layer_tree_unittests.cc +++ b/flow/layers/layer_tree_unittests.cc @@ -20,29 +20,30 @@ namespace testing { class LayerTreeTest : public CanvasTest { public: LayerTreeTest() - : root_transform_(SkMatrix::Translate(1.0f, 1.0f)), + : root_transform_(DlMatrix::MakeTranslation({1.0f, 1.0f})), builder_(DisplayListBuilder::kMaxCullRect), - scoped_frame_(compositor_context_.AcquireFrame(nullptr, - &builder_, - nullptr, - root_transform_, - false, - true, - nullptr, - nullptr)) {} + scoped_frame_( + compositor_context_.AcquireFrame(nullptr, + &builder_, + nullptr, + ToSkMatrix(root_transform_), + false, + true, + nullptr, + nullptr)) {} CompositorContext::ScopedFrame& frame() { return *scoped_frame_.get(); } - const SkMatrix& root_transform() { return root_transform_; } + const DlMatrix& root_transform() { return root_transform_; } sk_sp display_list() { return builder_.Build(); } std::unique_ptr BuildLayerTree( const std::shared_ptr& root_layer) { - return std::make_unique(root_layer, SkISize::Make(64, 64)); + return std::make_unique(root_layer, DlISize(64, 64)); } private: CompositorContext compositor_context_; - SkMatrix root_transform_; + DlMatrix root_transform_; DisplayListBuilder builder_; std::unique_ptr scoped_frame_; }; @@ -51,23 +52,22 @@ TEST_F(LayerTreeTest, PaintingEmptyLayerDies) { auto layer = std::make_shared(); auto layer_tree = BuildLayerTree(layer); layer_tree->Preroll(frame()); - EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty()); + EXPECT_EQ(layer->paint_bounds(), DlRect()); EXPECT_TRUE(layer->is_empty()); layer_tree->Paint(frame()); } TEST_F(LayerTreeTest, PaintBeforePrerollDies) { - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - SkPath child_path; - child_path.addRect(child_bounds); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlPath child_path = DlPath::MakeRect(child_bounds); auto mock_layer = std::make_shared(child_path); auto layer = std::make_shared(); layer->Add(mock_layer); auto layer_tree = BuildLayerTree(layer); - EXPECT_EQ(mock_layer->paint_bounds(), SkRect::MakeEmpty()); - EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty()); + EXPECT_EQ(mock_layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->paint_bounds(), DlRect()); EXPECT_TRUE(mock_layer->is_empty()); EXPECT_TRUE(layer->is_empty()); @@ -80,8 +80,8 @@ TEST_F(LayerTreeTest, PaintBeforePrerollDies) { } TEST_F(LayerTreeTest, Simple) { - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kCyan()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(); @@ -98,15 +98,15 @@ TEST_F(LayerTreeTest, Simple) { layer_tree->Paint(frame()); DisplayListBuilder expected_builder; - expected_builder.DrawPath(DlPath(child_path), child_paint); + expected_builder.DrawPath(child_path, child_paint); auto expected_dl = expected_builder.Build(); EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_dl)); } TEST_F(LayerTreeTest, Multiple) { - const SkPath child_path1 = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path2 = SkPath().addRect(8.0f, 2.0f, 16.5f, 14.5f); + const DlPath child_path1 = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path2 = DlPath::MakeRectLTRB(8.0f, 2.0f, 16.5f, 14.5f); const DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); const DlPaint child_paint2 = DlPaint(DlColor::kGreen()); auto mock_layer1 = std::make_shared(child_path1, child_paint1); @@ -116,12 +116,12 @@ TEST_F(LayerTreeTest, Multiple) { layer->Add(mock_layer1); layer->Add(mock_layer2); - SkRect expected_total_bounds = child_path1.getBounds(); - expected_total_bounds.join(child_path2.getBounds()); + const DlRect expected_total_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); auto layer_tree = BuildLayerTree(layer); layer_tree->Preroll(frame()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer->paint_bounds(), expected_total_bounds); EXPECT_FALSE(mock_layer1->is_empty()); EXPECT_FALSE(mock_layer2->is_empty()); @@ -135,28 +135,28 @@ TEST_F(LayerTreeTest, Multiple) { layer_tree->Paint(frame()); DisplayListBuilder expected_builder; - expected_builder.DrawPath(DlPath(child_path1), child_paint1); - expected_builder.DrawPath(DlPath(child_path2), child_paint2); + expected_builder.DrawPath(child_path1, child_paint1); + expected_builder.DrawPath(child_path2, child_paint2); auto expected_dl = expected_builder.Build(); EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_dl)); } TEST_F(LayerTreeTest, MultipleWithEmpty) { - const SkPath child_path1 = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path1 = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); const DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); const DlPaint child_paint2 = DlPaint(DlColor::kGreen()); auto mock_layer1 = std::make_shared(child_path1, child_paint1); - auto mock_layer2 = std::make_shared(SkPath(), child_paint2); + auto mock_layer2 = std::make_shared(DlPath(), child_paint2); auto layer = std::make_shared(); layer->Add(mock_layer1); layer->Add(mock_layer2); auto layer_tree = BuildLayerTree(layer); layer_tree->Preroll(frame()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), SkPath().getBounds()); - EXPECT_EQ(layer->paint_bounds(), child_path1.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), DlPath().GetBounds()); + EXPECT_EQ(layer->paint_bounds(), child_path1.GetBounds()); EXPECT_FALSE(mock_layer1->is_empty()); EXPECT_TRUE(mock_layer2->is_empty()); EXPECT_FALSE(layer->is_empty()); @@ -168,15 +168,15 @@ TEST_F(LayerTreeTest, MultipleWithEmpty) { layer_tree->Paint(frame()); DisplayListBuilder expected_builder; - expected_builder.DrawPath(DlPath(child_path1), child_paint1); + expected_builder.DrawPath(child_path1, child_paint1); auto expected_dl = expected_builder.Build(); EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_dl)); } TEST_F(LayerTreeTest, NeedsSystemComposite) { - const SkPath child_path1 = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path2 = SkPath().addRect(8.0f, 2.0f, 16.5f, 14.5f); + const DlPath child_path1 = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path2 = DlPath::MakeRectLTRB(8.0f, 2.0f, 16.5f, 14.5f); const DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); const DlPaint child_paint2 = DlPaint(DlColor::kGreen()); auto mock_layer1 = std::make_shared(child_path1, child_paint1); @@ -185,12 +185,12 @@ TEST_F(LayerTreeTest, NeedsSystemComposite) { layer->Add(mock_layer1); layer->Add(mock_layer2); - SkRect expected_total_bounds = child_path1.getBounds(); - expected_total_bounds.join(child_path2.getBounds()); + DlRect expected_total_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); auto layer_tree = BuildLayerTree(layer); layer_tree->Preroll(frame()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer->paint_bounds(), expected_total_bounds); EXPECT_FALSE(mock_layer1->is_empty()); EXPECT_FALSE(mock_layer2->is_empty()); @@ -203,8 +203,8 @@ TEST_F(LayerTreeTest, NeedsSystemComposite) { layer_tree->Paint(frame()); DisplayListBuilder expected_builder; - expected_builder.DrawPath(DlPath(child_path1), child_paint1); - expected_builder.DrawPath(DlPath(child_path2), child_paint2); + expected_builder.DrawPath(child_path1, child_paint1); + expected_builder.DrawPath(child_path2, child_paint2); auto expected_dl = expected_builder.Build(); EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_dl)); @@ -212,7 +212,7 @@ TEST_F(LayerTreeTest, NeedsSystemComposite) { TEST_F(LayerTreeTest, PrerollContextInitialization) { LayerStateStack state_stack; - state_stack.set_preroll_delegate(kGiantRect, SkMatrix::I()); + state_stack.set_preroll_delegate(kGiantRect, DlMatrix()); FixedRefreshRateStopwatch mock_raster_time; FixedRefreshRateStopwatch mock_ui_time; std::shared_ptr mock_registry; @@ -225,8 +225,8 @@ TEST_F(LayerTreeTest, PrerollContextInitialization) { EXPECT_EQ(&context.state_stack, &state_stack); EXPECT_EQ(context.dst_color_space, nullptr); EXPECT_EQ(context.state_stack.device_cull_rect(), kGiantRect); - EXPECT_EQ(context.state_stack.transform_3x3(), SkMatrix::I()); - EXPECT_EQ(context.state_stack.transform_4x4(), SkM44()); + EXPECT_EQ(context.state_stack.matrix(), DlMatrix()); + EXPECT_TRUE(context.state_stack.matrix().IsIdentity()); EXPECT_EQ(context.surface_needs_readback, false); EXPECT_EQ(&context.raster_time, &mock_raster_time); diff --git a/flow/layers/offscreen_surface.cc b/flow/layers/offscreen_surface.cc index 7a29b3fae3ebd..5e3b9c7424091 100644 --- a/flow/layers/offscreen_surface.cc +++ b/flow/layers/offscreen_surface.cc @@ -18,9 +18,9 @@ namespace flutter { static sk_sp CreateSnapshotSurface(GrDirectContext* surface_context, - const SkISize& size) { - const auto image_info = SkImageInfo::MakeN32Premul( - size.width(), size.height(), SkColorSpace::MakeSRGB()); + const DlISize& size) { + const auto image_info = SkImageInfo::MakeN32Premul(size.width, size.height, + SkColorSpace::MakeSRGB()); if (surface_context) { // There is a rendering surface that may contain textures that are going to // be referenced in the layer tree about to be drawn. @@ -69,7 +69,7 @@ static sk_sp GetRasterData(const sk_sp& offscreen_surface, } OffscreenSurface::OffscreenSurface(GrDirectContext* surface_context, - const SkISize& size) { + const DlISize& size) { offscreen_surface_ = CreateSnapshotSurface(surface_context, size); if (offscreen_surface_) { adapter_.set_canvas(offscreen_surface_->getCanvas()); diff --git a/flow/layers/offscreen_surface.h b/flow/layers/offscreen_surface.h index 6e84307b8140d..2d56d288fe583 100644 --- a/flow/layers/offscreen_surface.h +++ b/flow/layers/offscreen_surface.h @@ -13,8 +13,6 @@ #include "flutter/display_list/dl_canvas.h" #include "flutter/display_list/skia/dl_sk_canvas.h" #include "third_party/skia/include/core/SkData.h" -#include "third_party/skia/include/core/SkRefCnt.h" -#include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSurface.h" class GrDirectContext; @@ -24,7 +22,7 @@ namespace flutter { class OffscreenSurface { public: explicit OffscreenSurface(GrDirectContext* surface_context, - const SkISize& size); + const DlISize& size); ~OffscreenSurface() = default; diff --git a/flow/layers/offscreen_surface_unittests.cc b/flow/layers/offscreen_surface_unittests.cc index 780ea310009c3..86653134106b3 100644 --- a/flow/layers/offscreen_surface_unittests.cc +++ b/flow/layers/offscreen_surface_unittests.cc @@ -7,27 +7,21 @@ #include #include "gtest/gtest.h" -#include "include/core/SkColor.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkData.h" namespace flutter::testing { TEST(OffscreenSurfaceTest, EmptySurfaceIsInvalid) { - auto surface = - std::make_unique(nullptr, SkISize::MakeEmpty()); + auto surface = std::make_unique(nullptr, DlISize()); ASSERT_FALSE(surface->IsValid()); } TEST(OffscreenSurfaceTest, OnexOneSurfaceIsValid) { - auto surface = - std::make_unique(nullptr, SkISize::Make(1, 1)); + auto surface = std::make_unique(nullptr, DlISize(1, 1)); ASSERT_TRUE(surface->IsValid()); } TEST(OffscreenSurfaceTest, PaintSurfaceBlack) { - auto surface = - std::make_unique(nullptr, SkISize::Make(1, 1)); + auto surface = std::make_unique(nullptr, DlISize(1, 1)); DlCanvas* canvas = surface->GetCanvas(); canvas->Clear(DlColor::kBlack()); diff --git a/flow/layers/opacity_layer.cc b/flow/layers/opacity_layer.cc index 303df631922d7..a478d6b670ff0 100644 --- a/flow/layers/opacity_layer.cc +++ b/flow/layers/opacity_layer.cc @@ -6,13 +6,12 @@ #include "flutter/flow/layers/cacheable_layer.h" #include "flutter/flow/raster_cache_util.h" -#include "third_party/skia/include/core/SkPaint.h" namespace flutter { // the opacity_layer couldn't cache itself, so the cache_threshold is the // max_int -OpacityLayer::OpacityLayer(SkAlpha alpha, const SkPoint& offset) +OpacityLayer::OpacityLayer(uint8_t alpha, const DlPoint& offset) : CacheableContainerLayer(std::numeric_limits::max(), true), alpha_(alpha), offset_(offset) {} @@ -26,7 +25,7 @@ void OpacityLayer::Diff(DiffContext* context, const Layer* old_layer) { context->MarkSubtreeDirty(context->GetOldLayerPaintRegion(old_layer)); } } - context->PushTransform(SkMatrix::Translate(offset_.fX, offset_.fY)); + context->PushTransform(DlMatrix::MakeTranslation(offset_)); if (context->has_raster_cache()) { context->WillPaintWithIntegralTransform(); } @@ -37,11 +36,11 @@ void OpacityLayer::Diff(DiffContext* context, const Layer* old_layer) { void OpacityLayer::Preroll(PrerollContext* context) { auto mutator = context->state_stack.save(); mutator.translate(offset_); - mutator.applyOpacity(SkRect(), DlColor::toOpacity(alpha_)); + mutator.applyOpacity(DlRect(), opacity()); #if !SLIMPELLER AutoCache auto_cache = AutoCache(layer_raster_cache_item_.get(), context, - context->state_stack.transform_3x3()); + context->state_stack.matrix()); #endif // !SLIMPELLER Layer::AutoPrerollSaveLayerState save = @@ -57,7 +56,7 @@ void OpacityLayer::Preroll(PrerollContext* context) { // regardless of what our children are capable of context->renderable_state_flags |= LayerStateStack::kCallerCanApplyOpacity; - set_paint_bounds(paint_bounds().makeOffset(offset_.fX, offset_.fY)); + set_paint_bounds(paint_bounds().Shift(offset_)); #if !SLIMPELLER if (children_can_accept_opacity()) { @@ -73,7 +72,7 @@ void OpacityLayer::Paint(PaintContext& context) const { FML_DCHECK(needs_painting(context)); auto mutator = context.state_stack.save(); - mutator.translate(offset_.fX, offset_.fY); + mutator.translate(offset_.x, offset_.y); #if !SLIMPELLER if (context.raster_cache) { diff --git a/flow/layers/opacity_layer.h b/flow/layers/opacity_layer.h index 52131b1fec98b..444f05ca579df 100644 --- a/flow/layers/opacity_layer.h +++ b/flow/layers/opacity_layer.h @@ -7,7 +7,6 @@ #include "flutter/flow/layers/cacheable_layer.h" #include "flutter/flow/layers/layer.h" -#include "include/core/SkMatrix.h" namespace flutter { @@ -27,7 +26,7 @@ class OpacityLayer : public CacheableContainerLayer { // the retained rendering inefficient as a small offset change could propagate // to many leaf layers. Therefore we try to capture that offset here to stop // the propagation as repainting the OpacityLayer is expensive. - OpacityLayer(SkAlpha alpha, const SkPoint& offset); + OpacityLayer(uint8_t alpha, const DlPoint& offset); void Diff(DiffContext* context, const Layer* old_layer) override; @@ -45,11 +44,11 @@ class OpacityLayer : public CacheableContainerLayer { children_can_accept_opacity_ = value; } - SkScalar opacity() const { return alpha_ * 1.0f / SK_AlphaOPAQUE; } + DlScalar opacity() const { return DlColor::toOpacity(alpha_); } private: - SkAlpha alpha_; - SkPoint offset_; + uint8_t alpha_; + DlPoint offset_; bool children_can_accept_opacity_ = false; FML_DISALLOW_COPY_AND_ASSIGN(OpacityLayer); diff --git a/flow/layers/opacity_layer_unittests.cc b/flow/layers/opacity_layer_unittests.cc index 0993fb13b5077..6838bc96de922 100644 --- a/flow/layers/opacity_layer_unittests.cc +++ b/flow/layers/opacity_layer_unittests.cc @@ -29,13 +29,13 @@ using OpacityLayerTest = LayerTest; #ifndef NDEBUG TEST_F(OpacityLayerTest, PaintingEmptyLayerDies) { - auto mock_layer = std::make_shared(SkPath()); + auto mock_layer = std::make_shared(DlPath()); auto layer = - std::make_shared(SK_AlphaOPAQUE, SkPoint::Make(0.0f, 0.0f)); + std::make_shared(DlColor::toAlpha(1.0f), DlPoint()); layer->Add(mock_layer); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), SkPath().getBounds()); + EXPECT_EQ(mock_layer->paint_bounds(), DlPath().GetBounds()); EXPECT_EQ(layer->paint_bounds(), mock_layer->paint_bounds()); EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds()); EXPECT_FALSE(mock_layer->needs_painting(paint_context())); @@ -46,11 +46,10 @@ TEST_F(OpacityLayerTest, PaintingEmptyLayerDies) { } TEST_F(OpacityLayerTest, PaintBeforePrerollDies) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); auto mock_layer = std::make_shared(child_path); auto layer = - std::make_shared(SK_AlphaOPAQUE, SkPoint::Make(0.0f, 0.0f)); + std::make_shared(DlColor::toAlpha(1.0f), DlPoint()); layer->Add(mock_layer); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -59,35 +58,34 @@ TEST_F(OpacityLayerTest, PaintBeforePrerollDies) { #endif TEST_F(OpacityLayerTest, TranslateChildren) { - SkPath child_path1; - child_path1.addRect(10.0f, 10.0f, 20.0f, 20.f); + const DlPath child_path1 = DlPath::MakeRectLTRB(10.0f, 10.0f, 20.0f, 20.f); DlPaint child_paint1 = DlPaint(DlColor::kMidGrey()); - auto layer = std::make_shared(0.5, SkPoint::Make(10, 10)); + auto layer = + std::make_shared(DlColor::toAlpha(0.5f), DlPoint(10, 10)); auto mock_layer1 = std::make_shared(child_path1, child_paint1); layer->Add(mock_layer1); - auto initial_transform = SkMatrix::Scale(2.0, 2.0); + auto initial_transform = DlMatrix::MakeScale({2.0f, 2.0f, 1.0f}); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); - SkRect layer_bounds = mock_layer1->paint_bounds(); - mock_layer1->parent_matrix().mapRect(&layer_bounds); + DlRect layer_bounds = mock_layer1->paint_bounds().TransformAndClipBounds( + mock_layer1->parent_matrix()); - EXPECT_EQ(layer_bounds, SkRect::MakeXYWH(40, 40, 20, 20)); + EXPECT_EQ(layer_bounds, DlRect::MakeXYWH(40, 40, 20, 20)); } TEST_F(OpacityLayerTest, CacheChild) { - const SkAlpha alpha_half = 255 / 2; - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - auto other_transform = SkMatrix::Scale(1.0, 2.0); - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + const uint8_t alpha_half = DlColor::toAlpha(0.5f); + auto initial_transform = DlMatrix::MakeTranslation({50.0f, 25.5f}); + auto other_transform = DlMatrix::MakeScale({1.0f, 2.0f, 1.0f}); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); auto mock_layer = std::make_shared(child_path); - auto layer = - std::make_shared(alpha_half, SkPoint::Make(0.0f, 0.0f)); + auto layer = std::make_shared(alpha_half, DlPoint()); layer->Add(mock_layer); DlPaint paint; - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); DisplayListBuilder other_canvas; @@ -123,20 +121,19 @@ TEST_F(OpacityLayerTest, CacheChild) { } TEST_F(OpacityLayerTest, CacheChildren) { - const SkAlpha alpha_half = 255 / 2; - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - auto other_transform = SkMatrix::Scale(1.0, 2.0); - const SkPath child_path1 = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); - const SkPath child_path2 = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + const uint8_t alpha_half = DlColor::toAlpha(0.5f); + auto initial_transform = DlMatrix::MakeTranslation({50.0f, 25.5f}); + auto other_transform = DlMatrix::MakeScale({1.0f, 2.0f, 1.0f}); + const DlPath child_path1 = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); + const DlPath child_path2 = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); DlPaint paint; auto mock_layer1 = std::make_shared(child_path1); auto mock_layer2 = std::make_shared(child_path2); - auto layer = - std::make_shared(alpha_half, SkPoint::Make(0.0f, 0.0f)); + auto layer = std::make_shared(alpha_half, DlPoint()); layer->Add(mock_layer1); layer->Add(mock_layer2); - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); DisplayListBuilder other_canvas; @@ -173,9 +170,8 @@ TEST_F(OpacityLayerTest, CacheChildren) { TEST_F(OpacityLayerTest, ShouldNotCacheChildren) { DlPaint paint; - auto opacity_layer = - std::make_shared(128, SkPoint::Make(20, 20)); - auto mock_layer = MockLayer::MakeOpacityCompatible(SkPath()); + auto opacity_layer = std::make_shared(128, DlPoint(20, 20)); + auto mock_layer = MockLayer::MakeOpacityCompatible(DlPath()); opacity_layer->Add(mock_layer); PrerollContext* context = preroll_context(); @@ -204,27 +200,26 @@ TEST_F(OpacityLayerTest, ShouldNotCacheChildren) { } TEST_F(OpacityLayerTest, FullyOpaque) { - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); - const SkPoint layer_offset = SkPoint::Make(0.5f, 1.5f); - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 0.5f); - const SkMatrix layer_transform = - SkMatrix::Translate(layer_offset.fX, layer_offset.fY); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); + const DlPoint layer_offset = DlPoint(0.5f, 1.5f); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 0.5f}); + const DlMatrix layer_transform = DlMatrix::MakeTranslation(layer_offset); const DlPaint child_paint = DlPaint(DlColor::kGreen()); - const SkRect expected_layer_bounds = - layer_transform.mapRect(child_path.getBounds()); + const DlRect expected_layer_bounds = + child_path.GetBounds().TransformAndClipBounds(layer_transform); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = std::make_shared(SK_AlphaOPAQUE, layer_offset); + auto layer = + std::make_shared(DlColor::toAlpha(1.0f), layer_offset); layer->Add(mock_layer); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); + EXPECT_EQ(mock_layer->paint_bounds(), child_path.GetBounds()); EXPECT_EQ(layer->paint_bounds(), expected_layer_bounds); - EXPECT_EQ(layer->child_paint_bounds(), child_path.getBounds()); + EXPECT_EQ(layer->child_paint_bounds(), child_path.GetBounds()); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_matrix(), - SkMatrix::Concat(initial_transform, layer_transform)); + EXPECT_EQ(mock_layer->parent_matrix(), initial_transform * layer_transform); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_transform)})); @@ -232,7 +227,7 @@ TEST_F(OpacityLayerTest, FullyOpaque) { /* (Opacity)layer::Paint */ { expected_builder.Save(); { - expected_builder.Translate(layer_offset.fX, layer_offset.fY); + expected_builder.Translate(layer_offset.x, layer_offset.y); // Opaque alpha needs no SaveLayer, just recurse into painting mock_layer /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); @@ -245,41 +240,37 @@ TEST_F(OpacityLayerTest, FullyOpaque) { } TEST_F(OpacityLayerTest, FullyTransparent) { - const SkRect child_bounds = SkRect::MakeWH(5.0f, 5.0f); - const SkPath child_path = SkPath().addRect(child_bounds); - const SkPoint layer_offset = SkPoint::Make(0.5f, 1.5f); - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 0.5f); - const SkMatrix layer_transform = - SkMatrix::Translate(layer_offset.fX, layer_offset.fY); + const DlRect child_bounds = DlRect::MakeWH(5.0f, 5.0f); + const DlPath child_path = DlPath::MakeRect(child_bounds); + const DlPoint layer_offset = DlPoint(0.5f, 1.5f); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 0.5f}); + const DlMatrix layer_transform = DlMatrix::MakeTranslation(layer_offset); const DlPaint child_paint = DlPaint(DlColor::kGreen()); - const SkRect expected_layer_bounds = - layer_transform.mapRect(child_path.getBounds()); + const DlRect expected_layer_bounds = + child_path.GetBounds().TransformAndClipBounds(layer_transform); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = - std::make_shared(SK_AlphaTRANSPARENT, layer_offset); + auto layer = std::make_shared(0u, layer_offset); layer->Add(mock_layer); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); + EXPECT_EQ(mock_layer->paint_bounds(), child_path.GetBounds()); EXPECT_EQ(layer->paint_bounds(), expected_layer_bounds); - EXPECT_EQ(layer->child_paint_bounds(), child_path.getBounds()); + EXPECT_EQ(layer->child_paint_bounds(), child_path.GetBounds()); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_matrix(), - SkMatrix::Concat(initial_transform, layer_transform)); - EXPECT_EQ( - mock_layer->parent_mutators(), - std::vector({Mutator(layer_transform), Mutator(SK_AlphaTRANSPARENT)})); + EXPECT_EQ(mock_layer->parent_matrix(), initial_transform * layer_transform); + EXPECT_EQ(mock_layer->parent_mutators(), + std::vector({Mutator(layer_transform), Mutator(0u)})); DisplayListBuilder expected_builder; /* (Opacity)layer::Paint */ { expected_builder.Save(); { - expected_builder.Translate(layer_offset.fX, layer_offset.fY); + expected_builder.Translate(layer_offset.x, layer_offset.y); /* (Opacity)layer::PaintChildren */ { DlPaint save_paint(DlPaint().setOpacity(layer->opacity())); - expected_builder.SaveLayer(&child_bounds, &save_paint); + expected_builder.SaveLayer(child_bounds, &save_paint); /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); } @@ -293,43 +284,40 @@ TEST_F(OpacityLayerTest, FullyTransparent) { } TEST_F(OpacityLayerTest, HalfTransparent) { - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); - const SkPoint layer_offset = SkPoint::Make(0.5f, 1.5f); - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 0.5f); - const SkMatrix layer_transform = - SkMatrix::Translate(layer_offset.fX, layer_offset.fY); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); + const DlPoint layer_offset = DlPoint(0.5f, 1.5f); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 0.5f}); + const DlMatrix layer_transform = DlMatrix::MakeTranslation(layer_offset); const DlPaint child_paint = DlPaint(DlColor::kGreen()); - const SkRect expected_layer_bounds = - layer_transform.mapRect(child_path.getBounds()); - const SkAlpha alpha_half = 255 / 2; + const DlRect expected_layer_bounds = + child_path.GetBounds().TransformAndClipBounds(layer_transform); + const uint8_t alpha_half = DlColor::toAlpha(0.5f); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(alpha_half, layer_offset); layer->Add(mock_layer); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); + EXPECT_EQ(mock_layer->paint_bounds(), child_path.GetBounds()); EXPECT_EQ(layer->paint_bounds(), expected_layer_bounds); - EXPECT_EQ(layer->child_paint_bounds(), child_path.getBounds()); + EXPECT_EQ(layer->child_paint_bounds(), child_path.GetBounds()); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_matrix(), - SkMatrix::Concat(initial_transform, layer_transform)); + EXPECT_EQ(mock_layer->parent_matrix(), initial_transform * layer_transform); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_transform), Mutator(alpha_half)})); - SkRect opacity_bounds; - expected_layer_bounds.makeOffset(-layer_offset.fX, -layer_offset.fY) - .roundOut(&opacity_bounds); + DlRect opacity_bounds = + DlRect::RoundOut(expected_layer_bounds.Shift(-layer_offset)); DlPaint save_paint = DlPaint().setAlpha(alpha_half); DlPaint child_dl_paint = DlPaint(DlColor::kGreen()); auto expected_builder = DisplayListBuilder(); /* (Opacity)layer::Paint */ { expected_builder.Save(); - expected_builder.Translate(layer_offset.fX, layer_offset.fY); + expected_builder.Translate(layer_offset.x, layer_offset.y); /* (Opacity)layer::PaintChildren */ { - expected_builder.SaveLayer(&opacity_bounds, &save_paint); + expected_builder.SaveLayer(opacity_bounds, &save_paint); /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_dl_paint); } @@ -344,21 +332,19 @@ TEST_F(OpacityLayerTest, HalfTransparent) { } TEST_F(OpacityLayerTest, Nested) { - const SkPath child1_path = SkPath().addRect(SkRect::MakeWH(5.0f, 6.0f)); - const SkPath child2_path = SkPath().addRect(SkRect::MakeWH(2.0f, 7.0f)); - const SkPath child3_path = SkPath().addRect(SkRect::MakeWH(6.0f, 6.0f)); - const SkPoint layer1_offset = SkPoint::Make(0.5f, 1.5f); - const SkPoint layer2_offset = SkPoint::Make(2.5f, 0.5f); - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 0.5f); - const SkMatrix layer1_transform = - SkMatrix::Translate(layer1_offset.fX, layer1_offset.fY); - const SkMatrix layer2_transform = - SkMatrix::Translate(layer2_offset.fX, layer2_offset.fY); + const DlPath child1_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 6.0f)); + const DlPath child2_path = DlPath::MakeRect(DlRect::MakeWH(2.0f, 7.0f)); + const DlPath child3_path = DlPath::MakeRect(DlRect::MakeWH(6.0f, 6.0f)); + const DlPoint layer1_offset = DlPoint(0.5f, 1.5f); + const DlPoint layer2_offset = DlPoint(2.5f, 0.5f); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 0.5f}); + const DlMatrix layer1_transform = DlMatrix::MakeTranslation(layer1_offset); + const DlMatrix layer2_transform = DlMatrix::MakeTranslation(layer2_offset); const DlPaint child1_paint = DlPaint(DlColor::kRed()); const DlPaint child2_paint = DlPaint(DlColor::kBlue()); const DlPaint child3_paint = DlPaint(DlColor::kGreen()); - const SkAlpha alpha1 = 155; - const SkAlpha alpha2 = 224; + const uint8_t alpha1 = 155u; + const uint8_t alpha2 = 224u; auto mock_layer1 = std::make_shared(child1_path, child1_paint); auto mock_layer2 = std::make_shared(child2_path, child2_paint); auto mock_layer3 = std::make_shared(child3_path, child3_paint); @@ -369,67 +355,61 @@ TEST_F(OpacityLayerTest, Nested) { layer1->Add(layer2); layer1->Add(mock_layer3); // Ensure something is processed after recursion - const SkRect expected_layer2_bounds = - layer2_transform.mapRect(child2_path.getBounds()); - SkRect layer1_child_bounds = expected_layer2_bounds; - layer1_child_bounds.join(child1_path.getBounds()); - layer1_child_bounds.join(child3_path.getBounds()); - SkRect expected_layer1_bounds = layer1_transform.mapRect(layer1_child_bounds); + const DlRect expected_layer2_bounds = + child2_path.GetBounds().TransformAndClipBounds(layer2_transform); + const DlRect layer1_child_bounds = // + expected_layer2_bounds // + .Union(child1_path.GetBounds()) // + .Union(child3_path.GetBounds()); + const DlRect expected_layer1_bounds = + layer1_child_bounds.TransformAndClipBounds(layer1_transform); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer1->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child1_path.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child2_path.getBounds()); - EXPECT_EQ(mock_layer3->paint_bounds(), child3_path.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child1_path.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child2_path.GetBounds()); + EXPECT_EQ(mock_layer3->paint_bounds(), child3_path.GetBounds()); EXPECT_EQ(layer1->paint_bounds(), expected_layer1_bounds); EXPECT_EQ(layer1->child_paint_bounds(), layer1_child_bounds); EXPECT_EQ(layer2->paint_bounds(), expected_layer2_bounds); - EXPECT_EQ(layer2->child_paint_bounds(), child2_path.getBounds()); + EXPECT_EQ(layer2->child_paint_bounds(), child2_path.GetBounds()); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); EXPECT_TRUE(mock_layer2->needs_painting(paint_context())); EXPECT_TRUE(mock_layer3->needs_painting(paint_context())); EXPECT_TRUE(layer1->needs_painting(paint_context())); EXPECT_TRUE(layer2->needs_painting(paint_context())); - EXPECT_EQ(mock_layer1->parent_matrix(), - SkMatrix::Concat(initial_transform, layer1_transform)); + EXPECT_EQ(mock_layer1->parent_matrix(), initial_transform * layer1_transform); EXPECT_EQ(mock_layer1->parent_mutators(), std::vector({Mutator(layer1_transform), Mutator(alpha1)})); - EXPECT_EQ( - mock_layer2->parent_matrix(), - SkMatrix::Concat(SkMatrix::Concat(initial_transform, layer1_transform), - layer2_transform)); + EXPECT_EQ(mock_layer2->parent_matrix(), + (initial_transform * layer1_transform) * layer2_transform); EXPECT_EQ(mock_layer2->parent_mutators(), std::vector({Mutator(layer1_transform), Mutator(alpha1), Mutator(layer2_transform), Mutator(alpha2)})); - EXPECT_EQ(mock_layer3->parent_matrix(), - SkMatrix::Concat(initial_transform, layer1_transform)); + EXPECT_EQ(mock_layer3->parent_matrix(), initial_transform * layer1_transform); EXPECT_EQ(mock_layer3->parent_mutators(), std::vector({Mutator(layer1_transform), Mutator(alpha1)})); - SkRect opacity1_bounds = - expected_layer1_bounds.makeOffset(-layer1_offset.fX, -layer1_offset.fY); - SkRect opacity2_bounds = - expected_layer2_bounds.makeOffset(-layer2_offset.fX, -layer2_offset.fY); - DlPaint opacity1_paint; - opacity1_paint.setOpacity(alpha1 * (1.0 / SK_AlphaOPAQUE)); - DlPaint opacity2_paint; - opacity2_paint.setOpacity(alpha2 * (1.0 / SK_AlphaOPAQUE)); + DlRect opacity1_bounds = expected_layer1_bounds.Shift(-layer1_offset); + DlRect opacity2_bounds = expected_layer2_bounds.Shift(-layer2_offset); + DlPaint opacity1_paint = DlPaint().setAlpha(alpha1); + DlPaint opacity2_paint = DlPaint().setAlpha(alpha2); DisplayListBuilder expected_builder; /* (Opacity)layer1::Paint */ { expected_builder.Save(); { - expected_builder.Translate(layer1_offset.fX, layer1_offset.fY); + expected_builder.Translate(layer1_offset.x, layer1_offset.y); /* (Opacity)layer1::PaintChildren */ { - expected_builder.SaveLayer(&opacity1_bounds, &opacity1_paint); + expected_builder.SaveLayer(opacity1_bounds, &opacity1_paint); /* mock_layer1::Paint */ { expected_builder.DrawPath(child1_path, child1_paint); } /* (Opacity)layer2::Paint */ { expected_builder.Save(); { - expected_builder.Translate(layer2_offset.fX, layer2_offset.fY); + expected_builder.Translate(layer2_offset.x, layer2_offset.y); /* (Opacity)layer2::PaintChidren */ { - expected_builder.SaveLayer(&opacity2_bounds, &opacity2_paint); + expected_builder.SaveLayer(opacity2_bounds, &opacity2_paint); { /* mock_layer2::Paint */ { expected_builder.DrawPath(child2_path, child2_paint); @@ -453,8 +433,8 @@ TEST_F(OpacityLayerTest, Nested) { } TEST_F(OpacityLayerTest, Readback) { - auto layer = std::make_shared(kOpaque_SkAlphaType, SkPoint()); - layer->Add(std::make_shared(SkPath())); + auto layer = std::make_shared(0xff, DlPoint()); + layer->Add(std::make_shared(DlPath())); // OpacityLayer does not read from surface preroll_context()->surface_needs_readback = false; @@ -462,7 +442,7 @@ TEST_F(OpacityLayerTest, Readback) { EXPECT_FALSE(preroll_context()->surface_needs_readback); // OpacityLayer blocks child with readback - auto mock_layer = std::make_shared(SkPath(), DlPaint()); + auto mock_layer = std::make_shared(DlPath(), DlPaint()); mock_layer->set_fake_reads_surface(true); layer->Add(mock_layer); preroll_context()->surface_needs_readback = false; @@ -472,21 +452,19 @@ TEST_F(OpacityLayerTest, Readback) { TEST_F(OpacityLayerTest, CullRectIsTransformed) { auto clip_rect_layer = std::make_shared( - SkRect::MakeLTRB(0, 0, 10, 10), Clip::kHardEdge); - auto opacity_layer = - std::make_shared(128, SkPoint::Make(20, 20)); - auto mock_layer = std::make_shared(SkPath()); + DlRect::MakeLTRB(0, 0, 10, 10), Clip::kHardEdge); + auto opacity_layer = std::make_shared(128u, DlPoint(20, 20)); + auto mock_layer = std::make_shared(DlPath()); clip_rect_layer->Add(opacity_layer); opacity_layer->Add(mock_layer); clip_rect_layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->parent_cull_rect().fLeft, -20); - EXPECT_EQ(mock_layer->parent_cull_rect().fTop, -20); + EXPECT_EQ(mock_layer->parent_cull_rect().GetLeft(), -20); + EXPECT_EQ(mock_layer->parent_cull_rect().GetTop(), -20); } TEST_F(OpacityLayerTest, OpacityInheritanceCompatibleChild) { - auto opacity_layer = - std::make_shared(128, SkPoint::Make(20, 20)); - auto mock_layer = MockLayer::MakeOpacityCompatible(SkPath()); + auto opacity_layer = std::make_shared(128u, DlPoint(20, 20)); + auto mock_layer = MockLayer::MakeOpacityCompatible(DlPath()); opacity_layer->Add(mock_layer); PrerollContext* context = preroll_context(); @@ -497,9 +475,8 @@ TEST_F(OpacityLayerTest, OpacityInheritanceCompatibleChild) { } TEST_F(OpacityLayerTest, OpacityInheritanceIncompatibleChild) { - auto opacity_layer = - std::make_shared(128, SkPoint::Make(20, 20)); - auto mock_layer = MockLayer::Make(SkPath()); + auto opacity_layer = std::make_shared(128u, DlPoint(20, 20)); + auto mock_layer = MockLayer::Make(DlPath()); opacity_layer->Add(mock_layer); PrerollContext* context = preroll_context(); @@ -510,10 +487,9 @@ TEST_F(OpacityLayerTest, OpacityInheritanceIncompatibleChild) { } TEST_F(OpacityLayerTest, OpacityInheritanceThroughContainer) { - auto opacity_layer = - std::make_shared(128, SkPoint::Make(20, 20)); + auto opacity_layer = std::make_shared(128u, DlPoint(20, 20)); auto container_layer = std::make_shared(); - auto mock_layer = MockLayer::MakeOpacityCompatible(SkPath()); + auto mock_layer = MockLayer::MakeOpacityCompatible(DlPath()); container_layer->Add(mock_layer); opacity_layer->Add(container_layer); @@ -525,10 +501,10 @@ TEST_F(OpacityLayerTest, OpacityInheritanceThroughContainer) { } TEST_F(OpacityLayerTest, OpacityInheritanceThroughTransform) { - auto opacity_layer = - std::make_shared(128, SkPoint::Make(20, 20)); - auto transformLayer = std::make_shared(SkMatrix::Scale(2, 2)); - auto mock_layer = MockLayer::MakeOpacityCompatible(SkPath()); + auto opacity_layer = std::make_shared(128u, DlPoint(20, 20)); + auto transformLayer = + std::make_shared(DlMatrix::MakeScale({2.0f, 2.0f, 1.0f})); + auto mock_layer = MockLayer::MakeOpacityCompatible(DlPath()); transformLayer->Add(mock_layer); opacity_layer->Add(transformLayer); @@ -540,11 +516,10 @@ TEST_F(OpacityLayerTest, OpacityInheritanceThroughTransform) { } TEST_F(OpacityLayerTest, OpacityInheritanceThroughImageFilter) { - auto opacity_layer = - std::make_shared(128, SkPoint::Make(20, 20)); + auto opacity_layer = std::make_shared(128u, DlPoint(20, 20)); auto filter_layer = std::make_shared( DlImageFilter::MakeBlur(5.0, 5.0, DlTileMode::kClamp)); - auto mock_layer = MockLayer::MakeOpacityCompatible(SkPath()); + auto mock_layer = MockLayer::MakeOpacityCompatible(DlPath()); filter_layer->Add(mock_layer); opacity_layer->Add(filter_layer); @@ -556,11 +531,11 @@ TEST_F(OpacityLayerTest, OpacityInheritanceThroughImageFilter) { } TEST_F(OpacityLayerTest, OpacityInheritanceNestedWithCompatibleChild) { - SkPoint offset1 = SkPoint::Make(10, 20); - SkPoint offset2 = SkPoint::Make(20, 10); - SkPath mock_path = SkPath::Rect({10, 10, 20, 20}); - auto opacity_layer_1 = std::make_shared(128, offset1); - auto opacity_layer_2 = std::make_shared(64, offset2); + DlPoint offset1 = DlPoint(10, 20); + DlPoint offset2 = DlPoint(20, 10); + DlPath mock_path = DlPath::MakeRectLTRB(10, 10, 20, 20); + auto opacity_layer_1 = std::make_shared(128u, offset1); + auto opacity_layer_2 = std::make_shared(64u, offset2); auto mock_layer = MockLayer::MakeOpacityCompatible(mock_path); opacity_layer_2->Add(mock_layer); opacity_layer_1->Add(opacity_layer_2); @@ -573,19 +548,19 @@ TEST_F(OpacityLayerTest, OpacityInheritanceNestedWithCompatibleChild) { EXPECT_TRUE(opacity_layer_2->children_can_accept_opacity()); DlPaint savelayer_paint; - SkScalar inherited_opacity = 128 * 1.0 / SK_AlphaOPAQUE; - inherited_opacity *= 64 * 1.0 / SK_AlphaOPAQUE; + DlScalar inherited_opacity = DlColor::toOpacity(128u); + inherited_opacity *= DlColor::toOpacity(64u); savelayer_paint.setOpacity(inherited_opacity); DisplayListBuilder expected_builder; /* opacity_layer_1::Paint */ { expected_builder.Save(); { - expected_builder.Translate(offset1.fX, offset1.fY); + expected_builder.Translate(offset1.x, offset1.y); /* opacity_layer_2::Paint */ { expected_builder.Save(); { - expected_builder.Translate(offset2.fX, offset2.fY); + expected_builder.Translate(offset2.x, offset2.y); /* mock_layer::Paint */ { expected_builder.DrawPath(mock_path, DlPaint().setOpacity(inherited_opacity)); @@ -602,11 +577,11 @@ TEST_F(OpacityLayerTest, OpacityInheritanceNestedWithCompatibleChild) { } TEST_F(OpacityLayerTest, OpacityInheritanceNestedWithIncompatibleChild) { - SkPoint offset1 = SkPoint::Make(10, 20); - SkPoint offset2 = SkPoint::Make(20, 10); - SkPath mock_path = SkPath::Rect({10, 10, 20, 20}); - auto opacity_layer_1 = std::make_shared(128, offset1); - auto opacity_layer_2 = std::make_shared(64, offset2); + DlPoint offset1 = DlPoint(10, 20); + DlPoint offset2 = DlPoint(20, 10); + DlPath mock_path = DlPath::MakeRectLTRB(10, 10, 20, 20); + auto opacity_layer_1 = std::make_shared(128u, offset1); + auto opacity_layer_2 = std::make_shared(64u, offset2); auto mock_layer = MockLayer::Make(mock_path); opacity_layer_2->Add(mock_layer); opacity_layer_1->Add(opacity_layer_2); @@ -619,20 +594,20 @@ TEST_F(OpacityLayerTest, OpacityInheritanceNestedWithIncompatibleChild) { EXPECT_FALSE(opacity_layer_2->children_can_accept_opacity()); DlPaint savelayer_paint; - SkScalar inherited_opacity = 128 * 1.0 / SK_AlphaOPAQUE; - inherited_opacity *= 64 * 1.0 / SK_AlphaOPAQUE; + DlScalar inherited_opacity = DlColor::toOpacity(128); + inherited_opacity *= DlColor::toOpacity(64u); savelayer_paint.setOpacity(inherited_opacity); DisplayListBuilder expected_builder; /* opacity_layer_1::Paint */ { expected_builder.Save(); { - expected_builder.Translate(offset1.fX, offset1.fY); + expected_builder.Translate(offset1.x, offset1.y); /* opacity_layer_2::Paint */ { expected_builder.Save(); { - expected_builder.Translate(offset2.fX, offset2.fY); - expected_builder.SaveLayer(&mock_layer->paint_bounds(), + expected_builder.Translate(offset2.x, offset2.y); + expected_builder.SaveLayer(mock_layer->paint_bounds(), &savelayer_paint); /* mock_layer::Paint */ { expected_builder.DrawPath(mock_path, DlPaint()); @@ -652,39 +627,39 @@ using OpacityLayerDiffTest = DiffContextTest; TEST_F(OpacityLayerDiffTest, FractionalTranslation) { auto picture = CreateDisplayListLayer( - CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60))); - auto layer = CreateOpacityLater({picture}, 128, SkPoint::Make(0.5, 0.5)); + CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60))); + auto layer = CreateOpacityLater({picture}, 128u, DlPoint(0.5f, 0.5f)); MockLayerTree tree1; tree1.root()->Add(layer); - auto damage = DiffLayerTree(tree1, MockLayerTree(), SkIRect::MakeEmpty(), 0, - 0, /*use_raster_cache=*/false); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(10, 10, 61, 61)); + auto damage = DiffLayerTree(tree1, MockLayerTree(), DlIRect(), 0, 0, + /*use_raster_cache=*/false); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(10, 10, 61, 61)); } TEST_F(OpacityLayerDiffTest, FractionalTranslationWithRasterCache) { auto picture = CreateDisplayListLayer( - CreateDisplayList(SkRect::MakeLTRB(10, 10, 60, 60))); - auto layer = CreateOpacityLater({picture}, 128, SkPoint::Make(0.5, 0.5)); + CreateDisplayList(DlRect::MakeLTRB(10, 10, 60, 60))); + auto layer = CreateOpacityLater({picture}, 128u, DlPoint(0.5f, 0.5f)); MockLayerTree tree1; tree1.root()->Add(layer); - auto damage = DiffLayerTree(tree1, MockLayerTree(), SkIRect::MakeEmpty(), 0, - 0, /*use_raster_cache=*/true); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(11, 11, 61, 61)); + auto damage = DiffLayerTree(tree1, MockLayerTree(), DlIRect(), 0, 0, + /*use_raster_cache=*/true); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(11, 11, 61, 61)); } TEST_F(OpacityLayerTest, FullyOpaqueWithFractionalValues) { use_mock_raster_cache(); // Ensure pixel-snapped alignment. - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); - const SkPoint layer_offset = SkPoint::Make(0.5f, 1.5f); - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 0.5f); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); + const DlPoint layer_offset = DlPoint(0.5f, 1.5f); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 0.5f}); const DlPaint child_paint = DlPaint(DlColor::kGreen()); auto mock_layer = std::make_shared(child_path, child_paint); - auto layer = std::make_shared(SK_AlphaOPAQUE, layer_offset); + auto layer = std::make_shared(0xff, layer_offset); layer->Add(mock_layer); preroll_context()->state_stack.set_preroll_delegate(initial_transform); @@ -693,13 +668,12 @@ TEST_F(OpacityLayerTest, FullyOpaqueWithFractionalValues) { auto expected_builder = DisplayListBuilder(); /* (Opacity)layer::Paint */ { expected_builder.Save(); - expected_builder.Translate(layer_offset.fX, layer_offset.fY); + expected_builder.Translate(layer_offset.x, layer_offset.y); // Opaque alpha needs no SaveLayer, just recurse into painting mock_layer // but since we use the mock raster cache we pixel snap the transform expected_builder.TransformReset(); - expected_builder.Transform2DAffine( - 1, 0, SkScalarRoundToScalar(layer_offset.fX), // - 0, 1, SkScalarRoundToScalar(layer_offset.fY)); + expected_builder.Transform2DAffine(1, 0, std::round(layer_offset.x), // + 0, 1, std::round(layer_offset.y)); /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); } @@ -712,15 +686,14 @@ TEST_F(OpacityLayerTest, FullyOpaqueWithFractionalValues) { } TEST_F(OpacityLayerTest, FullyTransparentDoesNotCullPlatformView) { - const SkPoint opacity_offset = SkPoint::Make(0.5f, 1.5f); - const SkPoint view_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize view_size = SkSize::Make(8.0f, 8.0f); + const DlPoint opacity_offset = DlPoint(0.5f, 1.5f); + const DlPoint view_offset = DlPoint(0.0f, 0.0f); + const DlSize view_size = DlSize(8.0f, 8.0f); const int64_t view_id = 42; auto platform_view = std::make_shared(view_offset, view_size, view_id); - auto opacity = - std::make_shared(SK_AlphaTRANSPARENT, opacity_offset); + auto opacity = std::make_shared(0u, opacity_offset); opacity->Add(platform_view); auto embedder = MockViewEmbedder(); diff --git a/flow/layers/performance_overlay_layer.cc b/flow/layers/performance_overlay_layer.cc index 7761fafe6fc6f..f8b67aee206e1 100644 --- a/flow/layers/performance_overlay_layer.cc +++ b/flow/layers/performance_overlay_layer.cc @@ -132,10 +132,10 @@ void PerformanceOverlayLayer::Paint(PaintContext& context) const { return; } - SkScalar x = paint_bounds().x() + padding; - SkScalar y = paint_bounds().y() + padding; - SkScalar width = paint_bounds().width() - (padding * 2); - SkScalar height = paint_bounds().height() / 2; + DlScalar x = paint_bounds().GetX() + padding; + DlScalar y = paint_bounds().GetY() + padding; + DlScalar width = paint_bounds().GetWidth() - (padding * 2); + DlScalar height = paint_bounds().GetHeight() / 2; auto mutator = context.state_stack.save(); // Cached storage for vertex output. std::vector vertices_storage; diff --git a/flow/layers/performance_overlay_layer_unittests.cc b/flow/layers/performance_overlay_layer_unittests.cc index dafe53c46e500..ba17e80f53f1a 100644 --- a/flow/layers/performance_overlay_layer_unittests.cc +++ b/flow/layers/performance_overlay_layer_unittests.cc @@ -84,7 +84,7 @@ static void TestPerformanceOverlayLayerGold(int refresh_rate) { flutter::kDisplayEngineStatistics | flutter::kVisualizeEngineStatistics, flutter::GetFontFile().c_str()); - layer.set_paint_bounds(SkRect::MakeWH(1000, 400)); + layer.set_paint_bounds(DlRect::MakeWH(1000, 400)); surface->getCanvas()->clear(SK_ColorTRANSPARENT); layer.Paint(paint_context); @@ -166,7 +166,7 @@ TEST_F(PerformanceOverlayLayerTest, PaintingEmptyLayerDies) { auto layer = std::make_shared(overlay_opts); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty()); + EXPECT_EQ(layer->paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); // Crashes reading a nullptr. @@ -174,7 +174,7 @@ TEST_F(PerformanceOverlayLayerTest, PaintingEmptyLayerDies) { } TEST_F(PerformanceOverlayLayerTest, InvalidOptions) { - const SkRect layer_bounds = SkRect::MakeLTRB(0.0f, 0.0f, 64.0f, 64.0f); + const DlRect layer_bounds = DlRect::MakeLTRB(0.0f, 0.0f, 64.0f, 64.0f); const uint64_t overlay_opts = 0; auto layer = std::make_shared(overlay_opts); @@ -196,7 +196,7 @@ TEST_F(PerformanceOverlayLayerTest, InvalidOptions) { } TEST_F(PerformanceOverlayLayerTest, SimpleRasterizerStatistics) { - const SkRect layer_bounds = SkRect::MakeLTRB(0.0f, 0.0f, 64.0f, 64.0f); + const DlRect layer_bounds = DlRect::MakeLTRB(0.0f, 0.0f, 64.0f, 64.0f); const uint64_t overlay_opts = kDisplayRasterizerStatistics; auto layer = std::make_shared(overlay_opts); auto font = PerformanceOverlayLayer::MakeStatisticsFont(""); @@ -239,7 +239,7 @@ TEST_F(PerformanceOverlayLayerTest, MarkAsDirtyWhenResized) { // Create a PerformanceOverlayLayer. const uint64_t overlay_opts = kVisualizeRasterizerStatistics; auto layer = std::make_shared(overlay_opts); - layer->set_paint_bounds(SkRect::MakeLTRB(0.0f, 0.0f, 48.0f, 48.0f)); + layer->set_paint_bounds(DlRect::MakeLTRB(0.0f, 0.0f, 48.0f, 48.0f)); layer->Preroll(preroll_context()); layer->Paint(display_list_paint_context()); DlISize first_draw_size; @@ -254,7 +254,7 @@ TEST_F(PerformanceOverlayLayerTest, MarkAsDirtyWhenResized) { // Create a second PerformanceOverlayLayer with different bounds. layer = std::make_shared(overlay_opts); - layer->set_paint_bounds(SkRect::MakeLTRB(0.0f, 0.0f, 64.0f, 64.0f)); + layer->set_paint_bounds(DlRect::MakeLTRB(0.0f, 0.0f, 64.0f, 64.0f)); layer->Preroll(preroll_context()); reset_display_list(); layer->Paint(display_list_paint_context()); diff --git a/flow/layers/platform_view_layer.cc b/flow/layers/platform_view_layer.cc index d641a12665d38..572ff68a2936c 100644 --- a/flow/layers/platform_view_layer.cc +++ b/flow/layers/platform_view_layer.cc @@ -8,14 +8,13 @@ namespace flutter { -PlatformViewLayer::PlatformViewLayer(const SkPoint& offset, - const SkSize& size, +PlatformViewLayer::PlatformViewLayer(const DlPoint& offset, + const DlSize& size, int64_t view_id) : offset_(offset), size_(size), view_id_(view_id) {} void PlatformViewLayer::Preroll(PrerollContext* context) { - set_paint_bounds(SkRect::MakeXYWH(offset_.x(), offset_.y(), size_.width(), - size_.height())); + set_paint_bounds(DlRect::MakeOriginSize(offset_, size_)); if (context->view_embedder == nullptr) { FML_DLOG(ERROR) << "Trying to embed a platform view but the PrerollContext " @@ -27,8 +26,8 @@ void PlatformViewLayer::Preroll(PrerollContext* context) { MutatorsStack mutators; context->state_stack.fill(&mutators); std::unique_ptr params = - std::make_unique(context->state_stack.transform_3x3(), - size_, mutators); + std::make_unique( + ToSkMatrix(context->state_stack.matrix()), ToSkSize(size_), mutators); context->view_embedder->PrerollCompositeEmbeddedView(view_id_, std::move(params)); context->view_embedder->PushVisitedPlatformView(view_id_); diff --git a/flow/layers/platform_view_layer.h b/flow/layers/platform_view_layer.h index ac5792af55872..923843febf98d 100644 --- a/flow/layers/platform_view_layer.h +++ b/flow/layers/platform_view_layer.h @@ -14,14 +14,14 @@ namespace flutter { class PlatformViewLayer : public Layer { public: - PlatformViewLayer(const SkPoint& offset, const SkSize& size, int64_t view_id); + PlatformViewLayer(const DlPoint& offset, const DlSize& size, int64_t view_id); void Preroll(PrerollContext* context) override; void Paint(PaintContext& context) const override; private: - SkPoint offset_; - SkSize size_; + DlPoint offset_; + DlSize size_; int64_t view_id_; FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewLayer); diff --git a/flow/layers/platform_view_layer_unittests.cc b/flow/layers/platform_view_layer_unittests.cc index df8ccfc30c609..460989a6c1176 100644 --- a/flow/layers/platform_view_layer_unittests.cc +++ b/flow/layers/platform_view_layer_unittests.cc @@ -19,8 +19,8 @@ using PlatformViewLayerTest = LayerTest; using ClipOp = DlCanvas::ClipOp; TEST_F(PlatformViewLayerTest, NullViewEmbedderDoesntPrerollCompositeOrPaint) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(8.0f, 8.0f); + const DlPoint layer_offset = DlPoint(); + const DlSize layer_size = DlSize(8.0f, 8.0f); const int64_t view_id = 0; auto layer = std::make_shared(layer_offset, layer_size, view_id); @@ -28,8 +28,7 @@ TEST_F(PlatformViewLayerTest, NullViewEmbedderDoesntPrerollCompositeOrPaint) { layer->Preroll(preroll_context()); EXPECT_FALSE(preroll_context()->has_platform_view); EXPECT_EQ(layer->paint_bounds(), - SkRect::MakeSize(layer_size) - .makeOffset(layer_offset.fX, layer_offset.fY)); + DlRect::MakeOriginSize(layer_offset, layer_size)); EXPECT_TRUE(layer->needs_painting(paint_context())); EXPECT_FALSE(layer->subtree_has_platform_view()); @@ -42,10 +41,10 @@ TEST_F(PlatformViewLayerTest, NullViewEmbedderDoesntPrerollCompositeOrPaint) { } TEST_F(PlatformViewLayerTest, ClippedPlatformViewPrerollsAndPaintsNothing) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(8.0f, 8.0f); - const SkRect child_clip = SkRect::MakeLTRB(20.0f, 20.0f, 40.0f, 40.0f); - const SkRect parent_clip = SkRect::MakeLTRB(50.0f, 50.0f, 80.0f, 80.0f); + const DlPoint layer_offset = DlPoint(); + const DlSize layer_size = DlSize(8.0f, 8.0f); + const DlRect child_clip = DlRect::MakeLTRB(20.0f, 20.0f, 40.0f, 40.0f); + const DlRect parent_clip = DlRect::MakeLTRB(50.0f, 50.0f, 80.0f, 80.0f); const int64_t view_id = 0; auto layer = std::make_shared(layer_offset, layer_size, view_id); @@ -62,8 +61,7 @@ TEST_F(PlatformViewLayerTest, ClippedPlatformViewPrerollsAndPaintsNothing) { parent_clip_layer->Preroll(preroll_context()); EXPECT_TRUE(preroll_context()->has_platform_view); EXPECT_EQ(layer->paint_bounds(), - SkRect::MakeSize(layer_size) - .makeOffset(layer_offset.fX, layer_offset.fY)); + DlRect::MakeOriginSize(layer_offset, layer_size)); EXPECT_TRUE(layer->needs_painting(paint_context())); EXPECT_TRUE(child_clip_layer->needs_painting(paint_context())); EXPECT_TRUE(parent_clip_layer->needs_painting(paint_context())); @@ -92,8 +90,8 @@ TEST_F(PlatformViewLayerTest, ClippedPlatformViewPrerollsAndPaintsNothing) { } TEST_F(PlatformViewLayerTest, OpacityInheritance) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(8.0f, 8.0f); + const DlPoint layer_offset = DlPoint(); + const DlSize layer_size = DlSize(8.0f, 8.0f); const int64_t view_id = 0; auto layer = std::make_shared(layer_offset, layer_size, view_id); @@ -104,14 +102,14 @@ TEST_F(PlatformViewLayerTest, OpacityInheritance) { } TEST_F(PlatformViewLayerTest, StateTransfer) { - const SkMatrix transform1 = SkMatrix::Translate(5, 5); - const SkMatrix transform2 = SkMatrix::Translate(15, 15); - const SkMatrix combined_transform = SkMatrix::Translate(20, 20); - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(8.0f, 8.0f); + const DlMatrix transform1 = DlMatrix::MakeTranslation({5.0f, 5.0f}); + const DlMatrix transform2 = DlMatrix::MakeTranslation({15.0f, 15.0f}); + const DlMatrix combined_transform = DlMatrix::MakeTranslation({20.0f, 20.0f}); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); + const DlSize layer_size = DlSize(8.0f, 8.0f); const int64_t view_id = 0; - const SkPath path1 = SkPath().addOval({10, 10, 20, 20}); - const SkPath path2 = SkPath().addOval({15, 15, 30, 30}); + const DlPath path1 = DlPath::MakeOvalLTRB(10, 10, 20, 20); + const DlPath path2 = DlPath::MakeOvalLTRB(15, 15, 30, 30); // transform_layer1 // |- child1 diff --git a/flow/layers/shader_mask_layer.cc b/flow/layers/shader_mask_layer.cc index b2953d2aa5f58..32e14c2e8e755 100644 --- a/flow/layers/shader_mask_layer.cc +++ b/flow/layers/shader_mask_layer.cc @@ -8,7 +8,7 @@ namespace flutter { ShaderMaskLayer::ShaderMaskLayer(std::shared_ptr color_source, - const SkRect& mask_rect, + const DlRect& mask_rect, DlBlendMode blend_mode) : CacheableContainerLayer( RasterCacheUtil::kMinimumRendersBeforeCachingFilterLayer), @@ -39,7 +39,7 @@ void ShaderMaskLayer::Preroll(PrerollContext* context) { Layer::AutoPrerollSaveLayerState::Create(context); #if !SLIMPELLER AutoCache cache = AutoCache(layer_raster_cache_item_.get(), context, - context->state_stack.transform_3x3()); + context->state_stack.matrix()); #endif // !SLIMPELLER ContainerLayer::Preroll(context); // We always paint with a saveLayer (or a cached rendering), @@ -63,7 +63,7 @@ void ShaderMaskLayer::Paint(PaintContext& context) const { } } #endif // !SLIMPELLER - auto shader_rect = SkRect::MakeWH(mask_rect_.width(), mask_rect_.height()); + auto shader_rect = DlRect::MakeSize(mask_rect_.GetSize()); mutator.saveLayer(paint_bounds()); @@ -74,7 +74,7 @@ void ShaderMaskLayer::Paint(PaintContext& context) const { if (color_source_) { dl_paint.setColorSource(color_source_.get()); } - context.canvas->Translate(mask_rect_.left(), mask_rect_.top()); + context.canvas->Translate(mask_rect_.GetLeft(), mask_rect_.GetTop()); context.canvas->DrawRect(shader_rect, dl_paint); } diff --git a/flow/layers/shader_mask_layer.h b/flow/layers/shader_mask_layer.h index fadb5d12d1d5a..6100ba504d8ba 100644 --- a/flow/layers/shader_mask_layer.h +++ b/flow/layers/shader_mask_layer.h @@ -13,7 +13,7 @@ namespace flutter { class ShaderMaskLayer : public CacheableContainerLayer { public: ShaderMaskLayer(std::shared_ptr color_source, - const SkRect& mask_rect, + const DlRect& mask_rect, DlBlendMode blend_mode); void Diff(DiffContext* context, const Layer* old_layer) override; @@ -24,7 +24,7 @@ class ShaderMaskLayer : public CacheableContainerLayer { private: std::shared_ptr color_source_; - SkRect mask_rect_; + DlRect mask_rect_; DlBlendMode blend_mode_; FML_DISALLOW_COPY_AND_ASSIGN(ShaderMaskLayer); diff --git a/flow/layers/shader_mask_layer_unittests.cc b/flow/layers/shader_mask_layer_unittests.cc index 5cd676e485e98..ce5d87fdcfda8 100644 --- a/flow/layers/shader_mask_layer_unittests.cc +++ b/flow/layers/shader_mask_layer_unittests.cc @@ -37,11 +37,11 @@ static std::shared_ptr MakeFilter(DlColor color) { #ifndef NDEBUG TEST_F(ShaderMaskLayerTest, PaintingEmptyLayerDies) { auto layer = - std::make_shared(nullptr, kEmptyRect, DlBlendMode::kSrc); + std::make_shared(nullptr, DlRect(), DlBlendMode::kSrc); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -49,25 +49,25 @@ TEST_F(ShaderMaskLayerTest, PaintingEmptyLayerDies) { } TEST_F(ShaderMaskLayerTest, PaintBeforePrerollDies) { - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); auto mock_layer = std::make_shared(child_path); auto layer = - std::make_shared(nullptr, kEmptyRect, DlBlendMode::kSrc); + std::make_shared(nullptr, DlRect(), DlBlendMode::kSrc); layer->Add(mock_layer); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); - EXPECT_EQ(layer->child_paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), "needs_painting\\(context\\)"); } #endif TEST_F(ShaderMaskLayerTest, EmptyFilter) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkRect layer_bounds = SkRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlRect layer_bounds = DlRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto mock_layer = std::make_shared(child_path, child_paint); auto layer = std::make_shared(nullptr, layer_bounds, @@ -92,15 +92,15 @@ TEST_F(ShaderMaskLayerTest, EmptyFilter) { /* (ShaderMask)layer::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&child_bounds); + expected_builder.SaveLayer(child_bounds); { /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); } - expected_builder.Translate(layer_bounds.fLeft, layer_bounds.fTop); - expected_builder.DrawRect( - SkRect::MakeWH(layer_bounds.width(), layer_bounds.height()), - filter_paint); + expected_builder.Translate(layer_bounds.GetLeft(), + layer_bounds.GetTop()); + expected_builder.DrawRect(DlRect::MakeSize(layer_bounds.GetSize()), + filter_paint); } expected_builder.Restore(); } @@ -110,10 +110,10 @@ TEST_F(ShaderMaskLayerTest, EmptyFilter) { } TEST_F(ShaderMaskLayerTest, SimpleFilter) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkRect layer_bounds = SkRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlRect layer_bounds = DlRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto dl_filter = MakeFilter(DlColor::kBlue()); auto mock_layer = std::make_shared(child_path, child_paint); @@ -137,15 +137,15 @@ TEST_F(ShaderMaskLayerTest, SimpleFilter) { /* (ShaderMask)layer::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&child_bounds); + expected_builder.SaveLayer(child_bounds); { /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); } - expected_builder.Translate(layer_bounds.fLeft, layer_bounds.fTop); - expected_builder.DrawRect( - SkRect::MakeWH(layer_bounds.width(), layer_bounds.height()), - filter_paint); + expected_builder.Translate(layer_bounds.GetLeft(), + layer_bounds.GetTop()); + expected_builder.DrawRect(DlRect::MakeSize(layer_bounds.GetSize()), + filter_paint); } expected_builder.Restore(); } @@ -155,12 +155,11 @@ TEST_F(ShaderMaskLayerTest, SimpleFilter) { } TEST_F(ShaderMaskLayerTest, MultipleChildren) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkRect layer_bounds = SkRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f); - const SkPath child_path1 = SkPath().addRect(child_bounds); - const SkPath child_path2 = - SkPath().addRect(child_bounds.makeOffset(3.0f, 0.0f)); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlRect layer_bounds = DlRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f); + const DlPath child_path1 = DlPath::MakeRect(child_bounds); + const DlPath child_path2 = DlPath::MakeRect(child_bounds.Shift(3.0f, 0.0f)); const DlPaint child_paint1 = DlPaint(DlColor::kYellow()); const DlPaint child_paint2 = DlPaint(DlColor::kCyan()); auto dl_filter = MakeFilter(DlColor::kBlue()); @@ -171,12 +170,12 @@ TEST_F(ShaderMaskLayerTest, MultipleChildren) { layer->Add(mock_layer1); layer->Add(mock_layer2); - SkRect children_bounds = child_path1.getBounds(); - children_bounds.join(child_path2.getBounds()); + const DlRect children_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer->paint_bounds(), children_bounds); EXPECT_EQ(layer->child_paint_bounds(), children_bounds); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); @@ -194,7 +193,7 @@ TEST_F(ShaderMaskLayerTest, MultipleChildren) { /* (ShaderMask)layer::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&children_bounds); + expected_builder.SaveLayer(children_bounds); { /* mock_layer1::Paint */ { expected_builder.DrawPath(child_path1, child_paint1); @@ -202,10 +201,10 @@ TEST_F(ShaderMaskLayerTest, MultipleChildren) { /* mock_layer2::Paint */ { expected_builder.DrawPath(child_path2, child_paint2); } - expected_builder.Translate(layer_bounds.fLeft, layer_bounds.fTop); - expected_builder.DrawRect( - SkRect::MakeWH(layer_bounds.width(), layer_bounds.height()), - filter_paint); + expected_builder.Translate(layer_bounds.GetLeft(), + layer_bounds.GetTop()); + expected_builder.DrawRect(DlRect::MakeSize(layer_bounds.GetSize()), + filter_paint); } expected_builder.Restore(); } @@ -215,12 +214,11 @@ TEST_F(ShaderMaskLayerTest, MultipleChildren) { } TEST_F(ShaderMaskLayerTest, Nested) { - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 7.5f, 8.5f); - const SkRect layer_bounds = SkRect::MakeLTRB(2.0f, 4.0f, 20.5f, 20.5f); - const SkPath child_path1 = SkPath().addRect(child_bounds); - const SkPath child_path2 = - SkPath().addRect(child_bounds.makeOffset(3.0f, 0.0f)); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 7.5f, 8.5f); + const DlRect layer_bounds = DlRect::MakeLTRB(2.0f, 4.0f, 20.5f, 20.5f); + const DlPath child_path1 = DlPath::MakeRect(child_bounds); + const DlPath child_path2 = DlPath::MakeRect(child_bounds.Shift(3.0f, 0.0f)); const DlPaint child_paint1 = DlPaint(DlColor::kYellow()); const DlPaint child_paint2 = DlPaint(DlColor::kCyan()); auto dl_filter1 = MakeFilter(DlColor::kGreen()); @@ -235,12 +233,12 @@ TEST_F(ShaderMaskLayerTest, Nested) { layer1->Add(mock_layer1); layer1->Add(layer2); - SkRect children_bounds = child_path1.getBounds(); - children_bounds.join(child_path2.getBounds()); + const DlRect children_bounds = + child_path1.GetBounds().Union(child_path2.GetBounds()); preroll_context()->state_stack.set_preroll_delegate(initial_transform); layer1->Preroll(preroll_context()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds()); - EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.GetBounds()); + EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.GetBounds()); EXPECT_EQ(layer1->paint_bounds(), children_bounds); EXPECT_EQ(layer1->child_paint_bounds(), children_bounds); EXPECT_EQ(layer2->paint_bounds(), mock_layer2->paint_bounds()); @@ -263,7 +261,7 @@ TEST_F(ShaderMaskLayerTest, Nested) { /* (ShaderMask)layer1::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&children_bounds); + expected_builder.SaveLayer(children_bounds); { /* mock_layer1::Paint */ { expected_builder.DrawPath(child_path1, child_paint1); @@ -271,24 +269,24 @@ TEST_F(ShaderMaskLayerTest, Nested) { /* (ShaderMask)layer2::Paint */ { expected_builder.Save(); { - expected_builder.SaveLayer(&child_path2.getBounds()); + expected_builder.SaveLayer(child_path2.GetBounds()); { /* mock_layer2::Paint */ { expected_builder.DrawPath(child_path2, child_paint2); } - expected_builder.Translate(layer_bounds.fLeft, layer_bounds.fTop); + expected_builder.Translate(layer_bounds.GetLeft(), + layer_bounds.GetTop()); expected_builder.DrawRect( - SkRect::MakeWH(layer_bounds.width(), layer_bounds.height()), - filter_paint2); + DlRect::MakeSize(layer_bounds.GetSize()), filter_paint2); } expected_builder.Restore(); } expected_builder.Restore(); } - expected_builder.Translate(layer_bounds.fLeft, layer_bounds.fTop); - expected_builder.DrawRect( - SkRect::MakeWH(layer_bounds.width(), layer_bounds.height()), - filter_paint1); + expected_builder.Translate(layer_bounds.GetLeft(), + layer_bounds.GetTop()); + expected_builder.DrawRect(DlRect::MakeSize(layer_bounds.GetSize()), + filter_paint1); } expected_builder.Restore(); } @@ -298,7 +296,7 @@ TEST_F(ShaderMaskLayerTest, Nested) { } TEST_F(ShaderMaskLayerTest, Readback) { - const SkRect layer_bounds = SkRect::MakeLTRB(2.0f, 4.0f, 20.5f, 20.5f); + const DlRect layer_bounds = DlRect::MakeLTRB(2.0f, 4.0f, 20.5f, 20.5f); auto dl_filter = MakeFilter(DlColor::kBlue()); auto layer = std::make_shared(dl_filter, layer_bounds, DlBlendMode::kSrc); @@ -309,7 +307,7 @@ TEST_F(ShaderMaskLayerTest, Readback) { EXPECT_FALSE(preroll_context()->surface_needs_readback); // ShaderMaskLayer blocks child with readback - auto mock_layer = std::make_shared(SkPath(), DlPaint()); + auto mock_layer = std::make_shared(DlPath(), DlPaint()); mock_layer->set_fake_reads_surface(true); layer->Add(mock_layer); preroll_context()->surface_needs_readback = false; @@ -320,15 +318,15 @@ TEST_F(ShaderMaskLayerTest, Readback) { TEST_F(ShaderMaskLayerTest, LayerCached) { auto dl_filter = MakeFilter(DlColor::kBlue()); DlPaint paint; - const SkRect layer_bounds = SkRect::MakeLTRB(2.0f, 4.0f, 20.5f, 20.5f); - auto initial_transform = SkMatrix::Translate(50.0, 25.5); - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + const DlRect layer_bounds = DlRect::MakeLTRB(2.0f, 4.0f, 20.5f, 20.5f); + auto initial_transform = DlMatrix::MakeTranslation({50.0f, 25.5f}); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); auto mock_layer = std::make_shared(child_path); auto layer = std::make_shared(dl_filter, layer_bounds, DlBlendMode::kSrc); layer->Add(mock_layer); - SkMatrix cache_ctm = initial_transform; + DlMatrix cache_ctm = initial_transform; DisplayListBuilder cache_canvas; cache_canvas.Transform(cache_ctm); @@ -370,10 +368,10 @@ TEST_F(ShaderMaskLayerTest, LayerCached) { } TEST_F(ShaderMaskLayerTest, OpacityInheritance) { - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); auto mock_layer = MockLayer::Make(child_path); - const SkRect mask_rect = SkRect::MakeLTRB(10, 10, 20, 20); + const DlRect mask_rect = DlRect::MakeLTRB(10, 10, 20, 20); auto shader_mask_layer = std::make_shared(nullptr, mask_rect, DlBlendMode::kSrc); shader_mask_layer->Add(mock_layer); @@ -384,7 +382,7 @@ TEST_F(ShaderMaskLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, Layer::kSaveLayerRenderFlags); int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(shader_mask_layer); opacity_layer->Preroll(context); @@ -394,18 +392,17 @@ TEST_F(ShaderMaskLayerTest, OpacityInheritance) { /* OpacityLayer::Paint() */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* ShaderMaskLayer::Paint() */ { DlPaint sl_paint = DlPaint(DlColor(opacity_alpha << 24)); - expected_builder.SaveLayer(&child_path.getBounds(), &sl_paint); + expected_builder.SaveLayer(child_path.GetBounds(), &sl_paint); { /* child layer paint */ { expected_builder.DrawPath(child_path, DlPaint()); } - expected_builder.Translate(mask_rect.fLeft, mask_rect.fTop); - expected_builder.DrawRect( - SkRect::MakeWH(mask_rect.width(), mask_rect.height()), - DlPaint().setBlendMode(DlBlendMode::kSrc)); + expected_builder.Translate(mask_rect.GetLeft(), mask_rect.GetTop()); + expected_builder.DrawRect(DlRect::MakeSize(mask_rect.GetSize()), + DlPaint().setBlendMode(DlBlendMode::kSrc)); } expected_builder.Restore(); } @@ -420,10 +417,10 @@ TEST_F(ShaderMaskLayerTest, OpacityInheritance) { TEST_F(ShaderMaskLayerTest, SimpleFilterWithRasterCacheLayerNotCached) { use_mock_raster_cache(); // Ensure non-fractional alignment. - const SkMatrix initial_transform = SkMatrix::Translate(0.5f, 1.0f); - const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); - const SkRect layer_bounds = SkRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f); - const SkPath child_path = SkPath().addRect(child_bounds); + const DlMatrix initial_transform = DlMatrix::MakeTranslation({0.5f, 1.0f}); + const DlRect child_bounds = DlRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f); + const DlRect layer_bounds = DlRect::MakeLTRB(2.0f, 4.0f, 6.5f, 6.5f); + const DlPath child_path = DlPath::MakeRect(child_bounds); const DlPaint child_paint = DlPaint(DlColor::kYellow()); auto dl_filter = MakeFilter(DlColor::kBlue()); auto mock_layer = std::make_shared(child_path, child_paint); @@ -446,16 +443,16 @@ TEST_F(ShaderMaskLayerTest, SimpleFilterWithRasterCacheLayerNotCached) { // The layer will notice that the CTM is already an integer matrix // and will not perform an Integral CTM operation. // expected_builder.TransformReset(); - // expected_builder.Transform(SkMatrix()); - expected_builder.SaveLayer(&child_bounds); + // expected_builder.Transform(DlMatrix()); + expected_builder.SaveLayer(child_bounds); { /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, child_paint); } - expected_builder.Translate(layer_bounds.fLeft, layer_bounds.fTop); - expected_builder.DrawRect( - SkRect::MakeWH(layer_bounds.width(), layer_bounds.height()), - filter_paint); + expected_builder.Translate(layer_bounds.GetLeft(), + layer_bounds.GetTop()); + expected_builder.DrawRect(DlRect::MakeSize(layer_bounds.GetSize()), + filter_paint); } expected_builder.Restore(); } diff --git a/flow/layers/texture_layer.cc b/flow/layers/texture_layer.cc index c36a5eb6274d4..045ffffd759aa 100644 --- a/flow/layers/texture_layer.cc +++ b/flow/layers/texture_layer.cc @@ -8,8 +8,8 @@ namespace flutter { -TextureLayer::TextureLayer(const SkPoint& offset, - const SkSize& size, +TextureLayer::TextureLayer(const DlPoint& offset, + const DlSize& size, int64_t texture_id, bool freeze, DlImageSampling sampling) @@ -35,14 +35,12 @@ void TextureLayer::Diff(DiffContext* context, const Layer* old_layer) { // See ContainerLayer::DiffChildren // https://github.com/flutter/flutter/issues/92925 context->MarkSubtreeHasTextureLayer(); - context->AddLayerBounds(SkRect::MakeXYWH(offset_.x(), offset_.y(), - size_.width(), size_.height())); + context->AddLayerBounds(DlRect::MakeOriginSize(offset_, size_)); context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion()); } void TextureLayer::Preroll(PrerollContext* context) { - set_paint_bounds(SkRect::MakeXYWH(offset_.x(), offset_.y(), size_.width(), - size_.height())); + set_paint_bounds(DlRect::MakeOriginSize(offset_, size_)); context->has_texture_layer = true; context->renderable_state_flags = LayerStateStack::kCallerCanApplyOpacity; } @@ -65,7 +63,7 @@ void TextureLayer::Paint(PaintContext& context) const { .aiks_context = context.aiks_context, .paint = context.state_stack.fill(paint), }; - texture->Paint(ctx, paint_bounds(), freeze_, sampling_); + texture->Paint(ctx, ToSkRect(paint_bounds()), freeze_, sampling_); } } // namespace flutter diff --git a/flow/layers/texture_layer.h b/flow/layers/texture_layer.h index 460e6a7fec12f..22e75e3acc7c9 100644 --- a/flow/layers/texture_layer.h +++ b/flow/layers/texture_layer.h @@ -6,15 +6,13 @@ #define FLUTTER_FLOW_LAYERS_TEXTURE_LAYER_H_ #include "flutter/flow/layers/layer.h" -#include "third_party/skia/include/core/SkPoint.h" -#include "third_party/skia/include/core/SkSize.h" namespace flutter { class TextureLayer : public Layer { public: - TextureLayer(const SkPoint& offset, - const SkSize& size, + TextureLayer(const DlPoint& offset, + const DlSize& size, int64_t texture_id, bool freeze, DlImageSampling sampling); @@ -31,8 +29,8 @@ class TextureLayer : public Layer { void Paint(PaintContext& context) const override; private: - SkPoint offset_; - SkSize size_; + DlPoint offset_; + DlSize size_; int64_t texture_id_; bool freeze_; DlImageSampling sampling_; diff --git a/flow/layers/texture_layer_unittests.cc b/flow/layers/texture_layer_unittests.cc index 01da461eb77c4..ba6332c225646 100644 --- a/flow/layers/texture_layer_unittests.cc +++ b/flow/layers/texture_layer_unittests.cc @@ -17,15 +17,14 @@ namespace testing { using TextureLayerTest = LayerTest; TEST_F(TextureLayerTest, InvalidTexture) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(8.0f, 8.0f); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); + const DlSize layer_size = DlSize(8.0f, 8.0f); auto layer = std::make_shared( layer_offset, layer_size, 0, false, DlImageSampling::kNearestNeighbor); layer->Preroll(preroll_context()); EXPECT_EQ(layer->paint_bounds(), - (SkRect::MakeSize(layer_size) - .makeOffset(layer_offset.fX, layer_offset.fY))); + DlRect::MakeOriginSize(layer_offset, layer_size)); EXPECT_TRUE(layer->needs_painting(paint_context())); layer->Paint(display_list_paint_context()); @@ -34,8 +33,8 @@ TEST_F(TextureLayerTest, InvalidTexture) { #ifndef NDEBUG TEST_F(TextureLayerTest, PaintingEmptyLayerDies) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(0.0f, 0.0f); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); + const DlSize layer_size = DlSize(0.0f, 0.0f); const int64_t texture_id = 0; auto mock_texture = std::make_shared(texture_id); auto layer = @@ -46,7 +45,7 @@ TEST_F(TextureLayerTest, PaintingEmptyLayerDies) { preroll_context()->texture_registry->RegisterTexture(mock_texture); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), kEmptyRect); + EXPECT_EQ(layer->paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -54,8 +53,8 @@ TEST_F(TextureLayerTest, PaintingEmptyLayerDies) { } TEST_F(TextureLayerTest, PaintBeforePrerollDies) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(8.0f, 8.0f); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); + const DlSize layer_size = DlSize(8.0f, 8.0f); const int64_t texture_id = 0; auto mock_texture = std::make_shared(texture_id); auto layer = std::make_shared( @@ -70,10 +69,9 @@ TEST_F(TextureLayerTest, PaintBeforePrerollDies) { #endif TEST_F(TextureLayerTest, PaintingWithLinearSampling) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(8.0f, 8.0f); - const SkRect layer_bounds = - SkRect::MakeSize(layer_size).makeOffset(layer_offset.fX, layer_offset.fY); + const DlPoint layer_offset = DlPoint(0.0f, 0.0f); + const DlSize layer_size = DlSize(8.0f, 8.0f); + const DlRect layer_bounds = DlRect::MakeOriginSize(layer_offset, layer_size); const int64_t texture_id = 0; const auto texture_image = MockTexture::MakeTestTexture(20, 20, 5); auto mock_texture = std::make_shared(texture_id, texture_image); @@ -102,33 +100,31 @@ TEST_F(TextureLayerDiffTest, TextureInRetainedLayer) { MockLayerTree tree1; auto container = std::make_shared(); tree1.root()->Add(container); - auto layer = std::make_shared(SkPoint::Make(0, 0), - SkSize::Make(100, 100), 0, false, - DlImageSampling::kLinear); + auto layer = std::make_shared(DlPoint(), DlSize(100, 100), 0, + false, DlImageSampling::kLinear); container->Add(layer); MockLayerTree tree2; tree2.root()->Add(container); // retained layer auto damage = DiffLayerTree(tree1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 100, 100)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 100, 100)); damage = DiffLayerTree(tree2, tree1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 100, 100)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(0, 0, 100, 100)); } TEST_F(TextureLayerTest, OpacityInheritance) { - const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f); - const SkSize layer_size = SkSize::Make(8.0f, 8.0f); - const SkRect layer_bounds = - SkRect::MakeSize(layer_size).makeOffset(layer_offset.fX, layer_offset.fY); + const DlPoint layer_offset = DlPoint(); + const DlSize layer_size = DlSize(8.0f, 8.0f); + const DlRect layer_bounds = DlRect::MakeOriginSize(layer_offset, layer_size); const int64_t texture_id = 0; const auto texture_image = MockTexture::MakeTestTexture(20, 20, 5); auto mock_texture = std::make_shared(texture_id, texture_image); - SkAlpha alpha = 0x7f; + uint8_t alpha = 0x7f; auto texture_layer = std::make_shared( layer_offset, layer_size, texture_id, false, DlImageSampling::kLinear); - auto layer = std::make_shared(alpha, SkPoint::Make(0.0f, 0.0f)); + auto layer = std::make_shared(alpha, DlPoint()); layer->Add(texture_layer); // Ensure the texture is located by the Layer. diff --git a/flow/layers/transform_layer.cc b/flow/layers/transform_layer.cc index ec371a06099ec..3f237e00b00ba 100644 --- a/flow/layers/transform_layer.cc +++ b/flow/layers/transform_layer.cc @@ -8,20 +8,12 @@ namespace flutter { -TransformLayer::TransformLayer(const SkM44& transform) : transform_(transform) { - // Checks (in some degree) that SkM44 transform_ is valid and initialized. - // - // If transform_ is uninitialized, this assert may look flaky as it doesn't - // fail all the time, and some rerun may make it pass. But don't ignore it and - // just rerun the test if this is triggered, since even a flaky failure here - // may signify a potentially big problem in the code. - // - // We have to write this flaky test because there is no reliable way to test - // whether a variable is initialized or not in C++. - FML_DCHECK(transform_.isFinite()); - if (!transform_.isFinite()) { +TransformLayer::TransformLayer(const DlMatrix& transform) + : transform_(transform) { + FML_DCHECK(transform_.IsFinite()); + if (!transform_.IsFinite()) { FML_LOG(ERROR) << "TransformLayer is constructed with an invalid matrix."; - transform_.setIdentity(); + transform_ = {}; } } @@ -43,25 +35,10 @@ void TransformLayer::Preroll(PrerollContext* context) { auto mutator = context->state_stack.save(); mutator.transform(transform_); - SkRect child_paint_bounds = SkRect::MakeEmpty(); + DlRect child_paint_bounds; PrerollChildren(context, &child_paint_bounds); - // We convert to a 3x3 matrix here primarily because the SkM44 object - // does not support a mapRect operation. - // https://bugs.chromium.org/p/skia/issues/detail?id=11720&q=mapRect&can=2 - // - // All geometry is X,Y only which means the 3rd row of the 4x4 matrix - // is ignored and the output of the 3rd column is also ignored. - // So we can transform the rectangle using just the 3x3 SkMatrix - // equivalent without any loss of information. - // - // Performance consideration: - // Skia has an internal mapRect for their SkM44 object that is faster - // than what SkMatrix does when it has perspective elements. But SkMatrix - // is otherwise optimal for non-perspective matrices. If SkM44 ever exposes - // a mapRect operation, or if SkMatrix ever optimizes its handling of - // the perspective elements, this issue will become moot. - transform_.asM33().mapRect(&child_paint_bounds); + child_paint_bounds = child_paint_bounds.TransformAndClipBounds(transform_); set_paint_bounds(child_paint_bounds); } diff --git a/flow/layers/transform_layer.h b/flow/layers/transform_layer.h index 6403a02dc2ade..a87243036739b 100644 --- a/flow/layers/transform_layer.h +++ b/flow/layers/transform_layer.h @@ -9,13 +9,9 @@ namespace flutter { -// Be careful that SkMatrix's default constructor doesn't initialize the matrix -// at all. Hence |set_transform| must be called with an initialized SkMatrix. class TransformLayer : public ContainerLayer { public: - explicit TransformLayer(const SkMatrix& transform) - : TransformLayer(SkM44(transform)) {} - explicit TransformLayer(const SkM44& transform); + explicit TransformLayer(const DlMatrix& transform); void Diff(DiffContext* context, const Layer* old_layer) override; @@ -24,7 +20,7 @@ class TransformLayer : public ContainerLayer { void Paint(PaintContext& context) const override; private: - SkM44 transform_; + DlMatrix transform_; FML_DISALLOW_COPY_AND_ASSIGN(TransformLayer); }; diff --git a/flow/layers/transform_layer_unittests.cc b/flow/layers/transform_layer_unittests.cc index 312859b48397e..0c3be0069123c 100644 --- a/flow/layers/transform_layer_unittests.cc +++ b/flow/layers/transform_layer_unittests.cc @@ -16,11 +16,11 @@ using TransformLayerTest = LayerTest; #ifndef NDEBUG TEST_F(TransformLayerTest, PaintingEmptyLayerDies) { - auto layer = std::make_shared(SkMatrix()); // identity + auto layer = std::make_shared(DlMatrix()); // identity layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), SkRect::MakeEmpty()); - EXPECT_EQ(layer->child_paint_bounds(), SkRect::MakeEmpty()); + EXPECT_EQ(layer->paint_bounds(), DlRect()); + EXPECT_EQ(layer->child_paint_bounds(), DlRect()); EXPECT_FALSE(layer->needs_painting(paint_context())); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -28,10 +28,9 @@ TEST_F(TransformLayerTest, PaintingEmptyLayerDies) { } TEST_F(TransformLayerTest, PaintBeforePrerollDies) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); auto mock_layer = std::make_shared(child_path, DlPaint()); - auto layer = std::make_shared(SkMatrix()); // identity + auto layer = std::make_shared(DlMatrix()); // identity layer->Add(mock_layer); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -40,21 +39,20 @@ TEST_F(TransformLayerTest, PaintBeforePrerollDies) { #endif TEST_F(TransformLayerTest, Identity) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkRect cull_rect = SkRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); + const DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlRect cull_rect = DlRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); auto mock_layer = std::make_shared(child_path, DlPaint()); - auto layer = std::make_shared(SkMatrix()); // identity + auto layer = std::make_shared(DlMatrix()); // identity layer->Add(mock_layer); preroll_context()->state_stack.set_preroll_delegate(cull_rect); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); + EXPECT_EQ(mock_layer->paint_bounds(), child_path.GetBounds()); EXPECT_EQ(layer->paint_bounds(), mock_layer->paint_bounds()); EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds()); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_matrix(), SkMatrix()); // identity + EXPECT_EQ(mock_layer->parent_matrix(), DlMatrix()); // identity EXPECT_EQ(mock_layer->parent_cull_rect(), cull_rect); EXPECT_EQ(mock_layer->parent_mutators().stack_count(), 0u); EXPECT_EQ(mock_layer->parent_mutators(), MutatorsStack()); @@ -64,7 +62,7 @@ TEST_F(TransformLayerTest, Identity) { /* (Transform)layer::Paint */ { expected_builder.Save(); { - expected_builder.Transform(SkMatrix()); + expected_builder.Transform(DlMatrix()); /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, DlPaint()); } @@ -75,14 +73,14 @@ TEST_F(TransformLayerTest, Identity) { } TEST_F(TransformLayerTest, Simple) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); - SkRect local_cull_rect = SkRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); - SkRect device_cull_rect = initial_transform.mapRect(local_cull_rect); - SkMatrix layer_transform = SkMatrix::Translate(2.5f, 2.5f); - SkMatrix inverse_layer_transform; - EXPECT_TRUE(layer_transform.invert(&inverse_layer_transform)); + const DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-0.5f, -0.5f}); + DlRect local_cull_rect = DlRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); + DlRect device_cull_rect = + local_cull_rect.TransformAndClipBounds(initial_transform); + DlMatrix layer_transform = DlMatrix::MakeTranslation({2.5f, 2.5f}); + EXPECT_TRUE(layer_transform.IsInvertible()); + DlMatrix inverse_layer_transform = layer_transform.Invert(); auto mock_layer = std::make_shared(child_path, DlPaint()); auto layer = std::make_shared(layer_transform); @@ -91,16 +89,15 @@ TEST_F(TransformLayerTest, Simple) { preroll_context()->state_stack.set_preroll_delegate(device_cull_rect, initial_transform); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); + EXPECT_EQ(mock_layer->paint_bounds(), child_path.GetBounds()); EXPECT_EQ(layer->paint_bounds(), - layer_transform.mapRect(mock_layer->paint_bounds())); + mock_layer->paint_bounds().TransformAndClipBounds(layer_transform)); EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds()); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_matrix(), - SkMatrix::Concat(initial_transform, layer_transform)); + EXPECT_EQ(mock_layer->parent_matrix(), initial_transform * layer_transform); EXPECT_EQ(mock_layer->parent_cull_rect(), - inverse_layer_transform.mapRect(local_cull_rect)); + local_cull_rect.TransformAndClipBounds(inverse_layer_transform)); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_transform)})); @@ -119,95 +116,49 @@ TEST_F(TransformLayerTest, Simple) { EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_builder.Build())); } -TEST_F(TransformLayerTest, SimpleM44) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); - SkRect local_cull_rect = SkRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); - SkRect device_cull_rect = initial_transform.mapRect(local_cull_rect); - SkMatrix layer_transform = SkMatrix::Translate(2.5f, 3.5f); - SkMatrix inverse_layer_transform; - EXPECT_TRUE(layer_transform.invert(&inverse_layer_transform)); - - auto mock_layer = std::make_shared(child_path, DlPaint()); - auto layer = std::make_shared(SkM44::Translate(2.5f, 3.5f)); - layer->Add(mock_layer); - - preroll_context()->state_stack.set_preroll_delegate(device_cull_rect, - initial_transform); - layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); - EXPECT_EQ(layer->paint_bounds(), - layer_transform.mapRect(mock_layer->paint_bounds())); - EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds()); - EXPECT_TRUE(mock_layer->needs_painting(paint_context())); - EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_matrix(), - SkMatrix::Concat(initial_transform, layer_transform)); - EXPECT_EQ(mock_layer->parent_cull_rect(), - inverse_layer_transform.mapRect(local_cull_rect)); - EXPECT_EQ(mock_layer->parent_mutators(), - std::vector({Mutator(layer_transform)})); - - layer->Paint(display_list_paint_context()); - DisplayListBuilder expected_builder; - /* (Transform)layer::Paint */ { - expected_builder.Save(); - { - expected_builder.Transform(layer_transform); - /* mock_layer::Paint */ { - expected_builder.DrawPath(child_path, DlPaint()); - } - } - expected_builder.Restore(); - } - EXPECT_TRUE(DisplayListsEQ_Verbose(display_list(), expected_builder.Build())); -} +TEST_F(TransformLayerTest, ComplexMatrix) { + const DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-2.0f, -2.0f}); + DlRect local_cull_rect = DlRect::MakeXYWH(4.0f, 4.0f, 16.0f, 16.0f); + DlRect device_cull_rect = + local_cull_rect.TransformAndClipBounds(initial_transform); + DlMatrix layer_transform = (DlMatrix::MakeTranslation({1.0f, 1.0f}) * + DlMatrix::MakeRotationX(DlDegrees(20.0f))) * + DlMatrix::MakeRotationY(DlDegrees(10.0f)); -TEST_F(TransformLayerTest, ComplexM44) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkMatrix initial_transform = SkMatrix::Translate(-2.0f, -2.0f); - SkRect local_cull_rect = SkRect::MakeXYWH(4.0f, 4.0f, 16.0f, 16.0f); - SkRect device_cull_rect = initial_transform.mapRect(local_cull_rect); - SkM44 layer_transform44 = SkM44(); - layer_transform44.preTranslate(1.0f, 1.0f); - // 20 degrees around the X axis - layer_transform44.preConcat(SkM44::Rotate({1.0f, 0.0f, 0.0f}, M_PI / 9.0f)); - // 10 degrees around the Y axis - layer_transform44.preConcat(SkM44::Rotate({0.0f, 1.0f, 0.0f}, M_PI / 18.0f)); - SkM44 inverse_layer_transform44; - EXPECT_TRUE(layer_transform44.invert(&inverse_layer_transform44)); - SkMatrix layer_transform = layer_transform44.asM33(); - SkMatrix inverse_layer_transform = inverse_layer_transform44.asM33(); + EXPECT_TRUE(layer_transform.IsInvertible()); + DlMatrix inverse_layer_transform = layer_transform.Invert(); auto mock_layer = std::make_shared(child_path, DlPaint()); - auto layer = std::make_shared(layer_transform44); + auto layer = std::make_shared(layer_transform); layer->Add(mock_layer); preroll_context()->state_stack.set_preroll_delegate(device_cull_rect, initial_transform); layer->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); + EXPECT_EQ(mock_layer->paint_bounds(), child_path.GetBounds()); EXPECT_EQ(layer->paint_bounds(), - layer_transform.mapRect(mock_layer->paint_bounds())); + mock_layer->paint_bounds().TransformAndClipBounds(layer_transform)); EXPECT_EQ(layer->child_paint_bounds(), mock_layer->paint_bounds()); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(mock_layer->parent_matrix(), - SkMatrix::Concat(initial_transform, layer_transform)); + EXPECT_EQ(mock_layer->parent_matrix(), initial_transform * layer_transform); // Even having switched to binary-ieee friendly numbers for the // initial conditions, these numbers which are based on a matrix // concatenation and inversion still aren't exact, so we are using // fuzzy float comparisons to check them. - SkRect parent_cull_rect = mock_layer->parent_cull_rect(); - SkRect expect_parent_cull_rect = - inverse_layer_transform.mapRect(local_cull_rect); - EXPECT_FLOAT_EQ(parent_cull_rect.fLeft, expect_parent_cull_rect.fLeft); - EXPECT_FLOAT_EQ(parent_cull_rect.fTop, expect_parent_cull_rect.fTop); - EXPECT_FLOAT_EQ(parent_cull_rect.fRight, expect_parent_cull_rect.fRight); - EXPECT_FLOAT_EQ(parent_cull_rect.fBottom, expect_parent_cull_rect.fBottom); + DlRect parent_cull_rect = mock_layer->parent_cull_rect(); + DlRect expect_parent_cull_rect = + local_cull_rect.TransformAndClipBounds(inverse_layer_transform); + EXPECT_FLOAT_EQ(parent_cull_rect.GetLeft(), + expect_parent_cull_rect.GetLeft()); + EXPECT_FLOAT_EQ(parent_cull_rect.GetTop(), // + expect_parent_cull_rect.GetTop()); + EXPECT_FLOAT_EQ(parent_cull_rect.GetRight(), + expect_parent_cull_rect.GetRight()); + EXPECT_FLOAT_EQ(parent_cull_rect.GetBottom(), + expect_parent_cull_rect.GetBottom()); EXPECT_EQ(mock_layer->parent_mutators(), std::vector({Mutator(layer_transform)})); @@ -217,7 +168,7 @@ TEST_F(TransformLayerTest, ComplexM44) { /* (Transform)layer::Paint */ { expected_builder.Save(); { - expected_builder.Transform(layer_transform44); + expected_builder.Transform(layer_transform); /* mock_layer::Paint */ { expected_builder.DrawPath(child_path, DlPaint()); } @@ -228,16 +179,17 @@ TEST_F(TransformLayerTest, ComplexM44) { } TEST_F(TransformLayerTest, Nested) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); - SkRect local_cull_rect = SkRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); - SkRect device_cull_rect = initial_transform.mapRect(local_cull_rect); - SkMatrix layer1_transform = SkMatrix::Translate(2.5f, 2.5f); - SkMatrix layer2_transform = SkMatrix::Translate(3.5f, 3.5f); - SkMatrix inverse_layer1_transform, inverse_layer2_transform; - EXPECT_TRUE(layer1_transform.invert(&inverse_layer1_transform)); - EXPECT_TRUE(layer2_transform.invert(&inverse_layer2_transform)); + DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-0.5f, -0.5f}); + DlRect local_cull_rect = DlRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); + DlRect device_cull_rect = + local_cull_rect.TransformAndClipBounds(initial_transform); + DlMatrix layer1_transform = DlMatrix::MakeTranslation({2.5f, 2.5f}); + DlMatrix layer2_transform = DlMatrix::MakeTranslation({3.5f, 3.5f}); + EXPECT_TRUE(layer1_transform.IsInvertible()); + EXPECT_TRUE(layer2_transform.IsInvertible()); + DlMatrix inverse_layer1_transform = layer1_transform.Invert(); + DlMatrix inverse_layer2_transform = layer2_transform.Invert(); auto mock_layer = std::make_shared(child_path, DlPaint()); auto layer1 = std::make_shared(layer1_transform); @@ -248,23 +200,22 @@ TEST_F(TransformLayerTest, Nested) { preroll_context()->state_stack.set_preroll_delegate(device_cull_rect, initial_transform); layer1->Preroll(preroll_context()); - EXPECT_EQ(mock_layer->paint_bounds(), child_path.getBounds()); - EXPECT_EQ(layer2->paint_bounds(), - layer2_transform.mapRect(mock_layer->paint_bounds())); + EXPECT_EQ(mock_layer->paint_bounds(), child_path.GetBounds()); + EXPECT_EQ( + layer2->paint_bounds(), + mock_layer->paint_bounds().TransformAndClipBounds(layer2_transform)); EXPECT_EQ(layer2->child_paint_bounds(), mock_layer->paint_bounds()); EXPECT_EQ(layer1->paint_bounds(), - layer1_transform.mapRect(layer2->paint_bounds())); + layer2->paint_bounds().TransformAndClipBounds(layer1_transform)); EXPECT_EQ(layer1->child_paint_bounds(), layer2->paint_bounds()); EXPECT_TRUE(mock_layer->needs_painting(paint_context())); EXPECT_TRUE(layer2->needs_painting(paint_context())); EXPECT_TRUE(layer1->needs_painting(paint_context())); - EXPECT_EQ( - mock_layer->parent_matrix(), - SkMatrix::Concat(SkMatrix::Concat(initial_transform, layer1_transform), - layer2_transform)); + EXPECT_EQ(mock_layer->parent_matrix(), + (initial_transform * layer1_transform) * layer2_transform); EXPECT_EQ(mock_layer->parent_cull_rect(), - inverse_layer2_transform.mapRect( - inverse_layer1_transform.mapRect(local_cull_rect))); + local_cull_rect.TransformAndClipBounds(inverse_layer1_transform) + .TransformAndClipBounds(inverse_layer2_transform)); EXPECT_EQ( mock_layer->parent_mutators(), std::vector({Mutator(layer1_transform), Mutator(layer2_transform)})); @@ -292,16 +243,17 @@ TEST_F(TransformLayerTest, Nested) { } TEST_F(TransformLayerTest, NestedSeparated) { - SkPath child_path; - child_path.addRect(5.0f, 6.0f, 20.5f, 21.5f); - SkMatrix initial_transform = SkMatrix::Translate(-0.5f, -0.5f); - SkRect local_cull_rect = SkRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); - SkRect device_cull_rect = initial_transform.mapRect(local_cull_rect); - SkMatrix layer1_transform = SkMatrix::Translate(2.5f, 2.5f); - SkMatrix layer2_transform = SkMatrix::Translate(3.5f, 3.5f); - SkMatrix inverse_layer1_transform, inverse_layer2_transform; - EXPECT_TRUE(layer1_transform.invert(&inverse_layer1_transform)); - EXPECT_TRUE(layer2_transform.invert(&inverse_layer2_transform)); + DlPath child_path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); + DlMatrix initial_transform = DlMatrix::MakeTranslation({-0.5f, -0.5f}); + DlRect local_cull_rect = DlRect::MakeXYWH(2.0f, 2.0f, 14.0f, 14.0f); + DlRect device_cull_rect = + local_cull_rect.TransformAndClipBounds(initial_transform); + DlMatrix layer1_transform = DlMatrix::MakeTranslation({2.5f, 2.5f}); + DlMatrix layer2_transform = DlMatrix::MakeTranslation({3.5f, 3.5f}); + EXPECT_TRUE(layer1_transform.IsInvertible()); + EXPECT_TRUE(layer2_transform.IsInvertible()); + DlMatrix inverse_layer1_transform = layer1_transform.Invert(); + DlMatrix inverse_layer2_transform = layer2_transform.Invert(); DlPaint child_paint1(DlColor::kBlue()); DlPaint child_paint2(DlColor::kGreen()); @@ -316,33 +268,31 @@ TEST_F(TransformLayerTest, NestedSeparated) { preroll_context()->state_stack.set_preroll_delegate(device_cull_rect, initial_transform); layer1->Preroll(preroll_context()); - SkRect layer1_child_bounds = layer2->paint_bounds(); - layer1_child_bounds.join(mock_layer1->paint_bounds()); - SkRect expected_layer1_bounds = layer1_child_bounds; - layer1_transform.mapRect(&expected_layer1_bounds); - - EXPECT_EQ(mock_layer2->paint_bounds(), child_path.getBounds()); - EXPECT_EQ(layer2->paint_bounds(), - layer2_transform.mapRect(mock_layer2->paint_bounds())); + DlRect layer1_child_bounds = + layer2->paint_bounds().Union(mock_layer1->paint_bounds()); + DlRect expected_layer1_bounds = + layer1_child_bounds.TransformAndClipBounds(layer1_transform); + + EXPECT_EQ(mock_layer2->paint_bounds(), child_path.GetBounds()); + EXPECT_EQ( + layer2->paint_bounds(), + mock_layer2->paint_bounds().TransformAndClipBounds(layer2_transform)); EXPECT_EQ(layer2->child_paint_bounds(), mock_layer2->paint_bounds()); - EXPECT_EQ(mock_layer1->paint_bounds(), child_path.getBounds()); + EXPECT_EQ(mock_layer1->paint_bounds(), child_path.GetBounds()); EXPECT_EQ(layer1->paint_bounds(), expected_layer1_bounds); EXPECT_EQ(layer1->child_paint_bounds(), layer1_child_bounds); EXPECT_TRUE(mock_layer2->needs_painting(paint_context())); EXPECT_TRUE(layer2->needs_painting(paint_context())); EXPECT_TRUE(mock_layer1->needs_painting(paint_context())); EXPECT_TRUE(layer1->needs_painting(paint_context())); - EXPECT_EQ(mock_layer1->parent_matrix(), - SkMatrix::Concat(initial_transform, layer1_transform)); - EXPECT_EQ( - mock_layer2->parent_matrix(), - SkMatrix::Concat(SkMatrix::Concat(initial_transform, layer1_transform), - layer2_transform)); + EXPECT_EQ(mock_layer1->parent_matrix(), initial_transform * layer1_transform); + EXPECT_EQ(mock_layer2->parent_matrix(), + (initial_transform * layer1_transform) * layer2_transform); EXPECT_EQ(mock_layer1->parent_cull_rect(), - inverse_layer1_transform.mapRect(local_cull_rect)); + local_cull_rect.TransformAndClipBounds(inverse_layer1_transform)); EXPECT_EQ(mock_layer2->parent_cull_rect(), - inverse_layer2_transform.mapRect( - inverse_layer1_transform.mapRect(local_cull_rect))); + local_cull_rect.TransformAndClipBounds(inverse_layer1_transform) + .TransformAndClipBounds(inverse_layer2_transform)); EXPECT_EQ(mock_layer1->parent_mutators(), std::vector({Mutator(layer1_transform)})); EXPECT_EQ( @@ -375,9 +325,10 @@ TEST_F(TransformLayerTest, NestedSeparated) { } TEST_F(TransformLayerTest, OpacityInheritance) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto transform1 = std::make_shared(SkMatrix::Scale(2, 2)); + auto transform1 = + std::make_shared(DlMatrix::MakeScale({2.0f, 2.0f, 1.0f})); transform1->Add(mock1); // TransformLayer will pass through compatibility from a compatible child @@ -386,7 +337,7 @@ TEST_F(TransformLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); transform1->Add(mock2); @@ -396,7 +347,7 @@ TEST_F(TransformLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path3 = SkPath().addRect({20, 20, 40, 40}); + auto path3 = DlPath::MakeRectLTRB(20, 20, 40, 40); auto mock3 = MockLayer::MakeOpacityCompatible(path3); transform1->Add(mock3); @@ -405,7 +356,8 @@ TEST_F(TransformLayerTest, OpacityInheritance) { transform1->Preroll(context); EXPECT_EQ(context->renderable_state_flags, 0); - auto transform2 = std::make_shared(SkMatrix::Scale(2, 2)); + auto transform2 = + std::make_shared(DlMatrix::MakeScale({2.0f, 2.0f, 1.0f})); transform2->Add(mock1); transform2->Add(mock2); @@ -414,7 +366,7 @@ TEST_F(TransformLayerTest, OpacityInheritance) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - auto path4 = SkPath().addRect({60, 60, 70, 70}); + auto path4 = DlPath::MakeRectLTRB(60, 60, 70, 70); auto mock4 = MockLayer::Make(path4); transform2->Add(mock4); @@ -425,11 +377,11 @@ TEST_F(TransformLayerTest, OpacityInheritance) { } TEST_F(TransformLayerTest, OpacityInheritancePainting) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); auto mock1 = MockLayer::MakeOpacityCompatible(path1); - auto path2 = SkPath().addRect({40, 40, 50, 50}); + auto path2 = DlPath::MakeRectLTRB(40, 40, 50, 50); auto mock2 = MockLayer::MakeOpacityCompatible(path2); - auto transform = SkMatrix::Scale(2, 2); + auto transform = DlMatrix::MakeScale({2.0f, 2.0f, 1.0f}); auto transform_layer = std::make_shared(transform); transform_layer->Add(mock1); transform_layer->Add(mock2); @@ -441,8 +393,8 @@ TEST_F(TransformLayerTest, OpacityInheritancePainting) { EXPECT_EQ(context->renderable_state_flags, LayerStateStack::kCallerCanApplyOpacity); - int opacity_alpha = 0x7F; - SkPoint offset = SkPoint::Make(10, 10); + uint8_t opacity_alpha = 0x7F; + DlPoint offset = DlPoint(10, 10); auto opacity_layer = std::make_shared(opacity_alpha, offset); opacity_layer->Add(transform_layer); opacity_layer->Preroll(context); @@ -452,7 +404,7 @@ TEST_F(TransformLayerTest, OpacityInheritancePainting) { /* opacity_layer paint */ { expected_builder.Save(); { - expected_builder.Translate(offset.fX, offset.fY); + expected_builder.Translate(offset.x, offset.y); /* transform_layer paint */ { expected_builder.Save(); expected_builder.Transform(transform); @@ -475,21 +427,21 @@ TEST_F(TransformLayerTest, OpacityInheritancePainting) { using TransformLayerLayerDiffTest = DiffContextTest; TEST_F(TransformLayerLayerDiffTest, Transform) { - auto path1 = SkPath().addRect(SkRect::MakeLTRB(0, 0, 50, 50)); + auto path1 = DlPath::MakeRectLTRB(0, 0, 50, 50); auto m1 = std::make_shared(path1); auto transform1 = - std::make_shared(SkMatrix::Translate(10, 10)); + std::make_shared(DlMatrix::MakeTranslation({10, 10})); transform1->Add(m1); MockLayerTree t1; t1.root()->Add(transform1); auto damage = DiffLayerTree(t1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(10, 10, 60, 60)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(10, 10, 60, 60)); auto transform2 = - std::make_shared(SkMatrix::Translate(20, 20)); + std::make_shared(DlMatrix::MakeTranslation({20, 20})); transform2->Add(m1); transform2->AssignOldLayer(transform1.get()); @@ -497,10 +449,10 @@ TEST_F(TransformLayerLayerDiffTest, Transform) { t2.root()->Add(transform2); damage = DiffLayerTree(t2, t1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(10, 10, 70, 70)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(10, 10, 70, 70)); auto transform3 = - std::make_shared(SkMatrix::Translate(20, 20)); + std::make_shared(DlMatrix::MakeTranslation({20, 20})); transform3->Add(m1); transform3->AssignOldLayer(transform2.get()); @@ -508,29 +460,30 @@ TEST_F(TransformLayerLayerDiffTest, Transform) { t3.root()->Add(transform3); damage = DiffLayerTree(t3, t2); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeEmpty()); + EXPECT_EQ(damage.frame_damage, DlIRect()); } TEST_F(TransformLayerLayerDiffTest, TransformNested) { - auto path1 = SkPath().addRect(SkRect::MakeLTRB(0, 0, 50, 50)); + auto path1 = DlPath::MakeRectLTRB(0, 0, 50, 50); auto m1 = CreateContainerLayer(std::make_shared(path1)); auto m2 = CreateContainerLayer(std::make_shared(path1)); auto m3 = CreateContainerLayer(std::make_shared(path1)); - auto transform1 = std::make_shared(SkMatrix::Scale(2.0, 2.0)); + auto transform1 = + std::make_shared(DlMatrix::MakeScale({2.0f, 2.0f, 1.0f})); auto transform1_1 = - std::make_shared(SkMatrix::Translate(10, 10)); + std::make_shared(DlMatrix::MakeTranslation({10, 10})); transform1_1->Add(m1); transform1->Add(transform1_1); auto transform1_2 = - std::make_shared(SkMatrix::Translate(100, 100)); + std::make_shared(DlMatrix::MakeTranslation({100, 100})); transform1_2->Add(m2); transform1->Add(transform1_2); auto transform1_3 = - std::make_shared(SkMatrix::Translate(200, 200)); + std::make_shared(DlMatrix::MakeTranslation({200, 200})); transform1_3->Add(m3); transform1->Add(transform1_3); @@ -538,25 +491,26 @@ TEST_F(TransformLayerLayerDiffTest, TransformNested) { l1.root()->Add(transform1); auto damage = DiffLayerTree(l1, MockLayerTree()); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(20, 20, 500, 500)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(20, 20, 500, 500)); - auto transform2 = std::make_shared(SkMatrix::Scale(2.0, 2.0)); + auto transform2 = + std::make_shared(DlMatrix::MakeScale({2.0f, 2.0f, 1.0f})); auto transform2_1 = - std::make_shared(SkMatrix::Translate(10, 10)); + std::make_shared(DlMatrix::MakeTranslation({10, 10})); transform2_1->Add(m1); transform2_1->AssignOldLayer(transform1_1.get()); transform2->Add(transform2_1); // Offset 1px from transform1_2 so that they're not the same auto transform2_2 = - std::make_shared(SkMatrix::Translate(100, 101)); + std::make_shared(DlMatrix::MakeTranslation({100, 101})); transform2_2->Add(m2); transform2_2->AssignOldLayer(transform1_2.get()); transform2->Add(transform2_2); auto transform2_3 = - std::make_shared(SkMatrix::Translate(200, 200)); + std::make_shared(DlMatrix::MakeTranslation({200, 200})); transform2_3->Add(m3); transform2_3->AssignOldLayer(transform1_3.get()); transform2->Add(transform2_3); @@ -568,14 +522,14 @@ TEST_F(TransformLayerLayerDiffTest, TransformNested) { // transform2 has not transform1 assigned as old layer, so it should be // invalidated completely - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(20, 20, 500, 500)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(20, 20, 500, 500)); // now diff the tree properly, the only difference being transform2_2 and // transform_2_1 transform2->AssignOldLayer(transform1.get()); damage = DiffLayerTree(l2, l1); - EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(200, 200, 300, 302)); + EXPECT_EQ(damage.frame_damage, DlIRect::MakeLTRB(200, 200, 300, 302)); } } // namespace testing diff --git a/flow/paint_region.cc b/flow/paint_region.cc index 9b836edd13ffd..1e2e75c4e1473 100644 --- a/flow/paint_region.cc +++ b/flow/paint_region.cc @@ -6,10 +6,10 @@ namespace flutter { -SkRect PaintRegion::ComputeBounds() const { - SkRect res = SkRect::MakeEmpty(); +DlRect PaintRegion::ComputeBounds() const { + DlRect res; for (const auto& r : *this) { - res.join(r); + res = res.Union(r); } return res; } diff --git a/flow/paint_region.h b/flow/paint_region.h index 34b7ac1e9bbeb..7524e0197a4c6 100644 --- a/flow/paint_region.h +++ b/flow/paint_region.h @@ -8,8 +8,9 @@ #include #include #include + +#include "flutter/display_list/geometry/dl_geometry_types.h" #include "flutter/fml/logging.h" -#include "third_party/skia/include/core/SkRect.h" namespace flutter { @@ -27,7 +28,7 @@ namespace flutter { class PaintRegion { public: PaintRegion() = default; - PaintRegion(std::shared_ptr> rects, + PaintRegion(std::shared_ptr> rects, size_t from, size_t to, bool has_readback, @@ -38,18 +39,18 @@ class PaintRegion { has_readback_(has_readback), has_texture_(has_texture) {} - std::vector::const_iterator begin() const { + std::vector::const_iterator begin() const { FML_DCHECK(is_valid()); return rects_->begin() + from_; } - std::vector::const_iterator end() const { + std::vector::const_iterator end() const { FML_DCHECK(is_valid()); return rects_->begin() + to_; } // Compute bounds for this region - SkRect ComputeBounds() const; + DlRect ComputeBounds() const; bool is_valid() const { return rects_ != nullptr; } @@ -62,7 +63,7 @@ class PaintRegion { bool has_texture() const { return has_texture_; } private: - std::shared_ptr> rects_; + std::shared_ptr> rects_; size_t from_ = 0; size_t to_ = 0; bool has_readback_ = false; diff --git a/flow/raster_cache_item.h b/flow/raster_cache_item.h index 664fd6180b629..cc5ef3a107aca 100644 --- a/flow/raster_cache_item.h +++ b/flow/raster_cache_item.h @@ -39,10 +39,10 @@ class RasterCacheItem { child_items_(child_entries) {} virtual void PrerollSetup(PrerollContext* context, - const SkMatrix& matrix) = 0; + const DlMatrix& matrix) = 0; virtual void PrerollFinalize(PrerollContext* context, - const SkMatrix& matrix) = 0; + const DlMatrix& matrix) = 0; virtual bool Draw(const PaintContext& context, const DlPaint* paint) const = 0; @@ -58,6 +58,7 @@ class RasterCacheItem { unsigned child_items() const { return child_items_; } + void set_matrix(const DlMatrix& matrix) { matrix_ = ToSkMatrix(matrix); } void set_matrix(const SkMatrix& matrix) { matrix_ = matrix; } CacheState cache_state() const { return cache_state_; } diff --git a/flow/raster_cache_key.h b/flow/raster_cache_key.h index 6ca1db2905d9a..a5ae755defd35 100644 --- a/flow/raster_cache_key.h +++ b/flow/raster_cache_key.h @@ -12,6 +12,7 @@ #include #include +#include "flutter/display_list/geometry/dl_geometry_types.h" #include "flutter/fml/hash_combine.h" #include "flutter/fml/logging.h" #include "third_party/skia/include/core/SkMatrix.h" diff --git a/flow/raster_cache_unittests.cc b/flow/raster_cache_unittests.cc index ea814184fa0ca..18ecf2956f3aa 100644 --- a/flow/raster_cache_unittests.cc +++ b/flow/raster_cache_unittests.cc @@ -35,7 +35,7 @@ TEST(RasterCache, MetricsOmitUnpopulatedEntries) { size_t threshold = 2; flutter::RasterCache cache(threshold); - SkMatrix matrix = SkMatrix::I(); + DlMatrix matrix; auto display_list = GetSampleDisplayList(); @@ -95,7 +95,7 @@ TEST(RasterCache, ThresholdIsRespectedForDisplayList) { size_t threshold = 2; flutter::RasterCache cache(threshold); - SkMatrix matrix = SkMatrix::I(); + DlMatrix matrix; auto display_list = GetSampleDisplayList(); @@ -147,7 +147,7 @@ TEST(RasterCache, AccessThresholdOfZeroDisablesCachingForDisplayList) { size_t threshold = 0; flutter::RasterCache cache(threshold); - SkMatrix matrix = SkMatrix::I(); + DlMatrix matrix; auto display_list = GetSampleDisplayList(); @@ -181,7 +181,7 @@ TEST(RasterCache, PictureCacheLimitPerFrameIsRespectedWhenZeroForDisplayList) { size_t picture_cache_limit_per_frame = 0; flutter::RasterCache cache(3, picture_cache_limit_per_frame); - SkMatrix matrix = SkMatrix::I(); + DlMatrix matrix; auto display_list = GetSampleDisplayList(); @@ -224,7 +224,7 @@ TEST(RasterCache, EvictUnusedCacheEntries) { size_t threshold = 1; flutter::RasterCache cache(threshold); - SkMatrix matrix = SkMatrix::I(); + DlMatrix matrix; auto display_list_1 = GetSampleDisplayList(); auto display_list_2 = GetSampleDisplayList(); @@ -339,7 +339,14 @@ TEST(RasterCache, DeviceRectRoundOutForDisplayList) { builder.DrawRect(logical_rect, DlPaint(DlColor::kRed())); sk_sp display_list = builder.Build(); - SkMatrix ctm = SkMatrix::MakeAll(1.3312, 0, 233, 0, 1.3312, 206, 0, 0, 1); + // clang-format off + DlMatrix ctm( + 1.3312, 0, 0, 0, + 0, 1.3312, 0, 0, + 0, 0, 1, 0, + 233, 206, 0, 1 + ); + // clang-format on DlPaint paint; DisplayListBuilder canvas(1000, 1000); @@ -383,7 +390,7 @@ TEST(RasterCache, NestedOpCountMetricUsedForDisplayList) { size_t threshold = 1; flutter::RasterCache cache(threshold); - SkMatrix matrix = SkMatrix::I(); + DlMatrix matrix; auto display_list = GetSampleNestedDisplayList(); ASSERT_EQ(display_list->op_count(), 1u); @@ -430,7 +437,7 @@ TEST(RasterCache, NaiveComplexityScoringDisplayList) { size_t threshold = 1; flutter::RasterCache cache(threshold); - SkMatrix matrix = SkMatrix::I(); + DlMatrix matrix; // Five raster ops will not be cached auto display_list = GetSampleDisplayList(5); @@ -501,10 +508,10 @@ TEST(RasterCache, DisplayListWithSingularMatrixIsNotCached) { size_t threshold = 2; flutter::RasterCache cache(threshold); - SkMatrix matrices[] = { - SkMatrix::Scale(0, 1), - SkMatrix::Scale(1, 0), - SkMatrix::Skew(1, 1), + DlMatrix matrices[] = { + DlMatrix::MakeScale({0.0f, 1.0f, 1.0f}), + DlMatrix::MakeScale({1.0f, 0.0f, 1.0f}), + DlMatrix::MakeSkew(1, 1), }; int matrix_count = sizeof(matrices) / sizeof(matrices[0]); @@ -514,7 +521,7 @@ TEST(RasterCache, DisplayListWithSingularMatrixIsNotCached) { DlPaint paint; LayerStateStack preroll_state_stack; - preroll_state_stack.set_preroll_delegate(kGiantRect, SkMatrix::I()); + preroll_state_stack.set_preroll_delegate(kGiantRect, DlMatrix()); LayerStateStack paint_state_stack; preroll_state_stack.set_delegate(&dummy_canvas); @@ -550,15 +557,14 @@ TEST(RasterCache, DisplayListWithSingularMatrixIsNotCached) { } TEST(RasterCache, PrepareLayerTransform) { - SkRect child_bounds = SkRect::MakeLTRB(10, 10, 50, 50); - SkPath child_path = SkPath().addOval(child_bounds); + DlRect child_bounds = DlRect::MakeLTRB(10, 10, 50, 50); + DlPath child_path = DlPath::MakeOval(child_bounds); auto child_layer = MockLayer::Make(child_path); auto blur_filter = DlBlurImageFilter::Make(5, 5, DlTileMode::kClamp); auto blur_layer = std::make_shared(blur_filter); - SkMatrix matrix = SkMatrix::Scale(2, 2); + DlMatrix matrix = DlMatrix::MakeScale({2.0f, 2.0f, 1.0f}); auto transform_layer = std::make_shared(matrix); - SkMatrix cache_matrix = SkMatrix::Translate(-20, -20); - cache_matrix.preConcat(matrix); + DlMatrix cache_matrix = DlMatrix::MakeTranslation({-20.0f, -20.0f}) * matrix; child_layer->set_expected_paint_matrix(cache_matrix); blur_layer->Add(child_layer); @@ -749,13 +755,13 @@ using RasterCacheTest = LayerTest; TEST_F(RasterCacheTest, RasterCacheKeyIDLayerChildrenIds) { auto layer = std::make_shared(); - const SkPath child_path = SkPath().addRect(SkRect::MakeWH(5.0f, 5.0f)); + const DlPath child_path = DlPath::MakeRect(DlRect::MakeWH(5.0f, 5.0f)); auto mock_layer = std::make_shared(child_path); layer->Add(mock_layer); auto display_list = GetSampleDisplayList(); - auto display_list_layer = std::make_shared( - SkPoint::Make(0.0f, 0.0f), display_list, false, false); + auto display_list_layer = + std::make_shared(DlPoint(), display_list, false, false); layer->Add(display_list_layer); auto ids = RasterCacheKeyID::LayerChildrenIds(layer.get()).value(); diff --git a/flow/raster_cache_util.cc b/flow/raster_cache_util.cc index 8fbd19cb1a2a2..5efca2553ec64 100644 --- a/flow/raster_cache_util.cc +++ b/flow/raster_cache_util.cc @@ -67,4 +67,30 @@ bool RasterCacheUtil::ComputeIntegralTransCTM(const SkM44& in, SkM44* out) { return false; } +bool RasterCacheUtil::ComputeIntegralTransCTM(const DlMatrix& in, + DlMatrix* out) { + // Avoid integral snapping if the matrix has complex transformation to avoid + // the artifact observed in https://github.com/flutter/flutter/issues/41654. + if (!in.IsTranslationScaleOnly()) { + return false; + } + + DlScalar in_tx = in.m[12]; + DlScalar in_ty = in.m[13]; + DlScalar out_tx = std::round(in_tx); + DlScalar out_ty = std::round(in_ty); + if (out_tx != in_tx || out_ty != in_ty) { + // As a side effect of those tests we also know that neither translation + // component was a NaN + *out = in; + out->m[12] = out_tx; + out->m[13] = out_ty; + // No need to worry about Z translation because it has no effect + // without perspective entries... + return true; + } + + return false; +} + } // namespace flutter diff --git a/flow/raster_cache_util.h b/flow/raster_cache_util.h index 4df70494cb4f5..4489822cff3d0 100644 --- a/flow/raster_cache_util.h +++ b/flow/raster_cache_util.h @@ -5,6 +5,7 @@ #ifndef FLUTTER_FLOW_RASTER_CACHE_UTIL_H_ #define FLUTTER_FLOW_RASTER_CACHE_UTIL_H_ +#include "flutter/display_list/geometry/dl_geometry_types.h" #include "flutter/fml/logging.h" #include "include/core/SkM44.h" #include "include/core/SkMatrix.h" @@ -82,6 +83,24 @@ struct RasterCacheUtil { return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm; } + /** + * @brief Snap the translation components of the matrix to integers. + * + * The snapping will only happen if the matrix only has scale and translation + * transformations. This is used, along with GetRoundedOutDeviceBounds, to + * ensure that the textures drawn by the raster cache are exactly aligned to + * physical pixels. Any layers that participate in raster caching must align + * themselves to physical pixels even when not cached to prevent a change in + * apparent location if caching is later applied. + * + * @param ctm the current transformation matrix. + * @return SkMatrix the snapped transformation matrix. + */ + static DlMatrix GetIntegralTransCTM(const DlMatrix& ctm) { + DlMatrix integral; + return ComputeIntegralTransCTM(ctm, &integral) ? integral : ctm; + } + /** * @brief Snap the translation components of the |in| matrix to integers * and store the snapped matrix in |out|. @@ -137,6 +156,25 @@ struct RasterCacheUtil { * @return true if the integral modification was needed, false otherwise. */ static bool ComputeIntegralTransCTM(const SkM44& in, SkM44* out); + + /** + * @brief Snap the translation components of the |in| matrix to integers + * and store the snapped matrix in |out|. + * + * The snapping will only happen if the matrix only has scale and translation + * transformations. This is used, along with GetRoundedOutDeviceBounds, to + * ensure that the textures drawn by the raster cache are exactly aligned to + * physical pixels. Any layers that participate in raster caching must align + * themselves to physical pixels even when not cached to prevent a change in + * apparent location if caching is later applied. + * + * The |out| matrix will not be modified if this method returns false. + * + * @param in the current transformation matrix. + * @param out the storage for the snapped matrix. + * @return true if the integral modification was needed, false otherwise. + */ + static bool ComputeIntegralTransCTM(const DlMatrix& in, DlMatrix* out); }; } // namespace flutter diff --git a/flow/testing/diff_context_test.cc b/flow/testing/diff_context_test.cc index 26b2a67f28d09..5298c910a6012 100644 --- a/flow/testing/diff_context_test.cc +++ b/flow/testing/diff_context_test.cc @@ -14,7 +14,7 @@ DiffContextTest::DiffContextTest() {} Damage DiffContextTest::DiffLayerTree(MockLayerTree& layer_tree, const MockLayerTree& old_layer_tree, - const SkIRect& additional_damage, + const DlIRect& additional_damage, int horizontal_clip_alignment, int vertical_clip_alignment, bool use_raster_cache, @@ -24,14 +24,13 @@ Damage DiffContextTest::DiffLayerTree(MockLayerTree& layer_tree, DiffContext dc(layer_tree.size(), layer_tree.paint_region_map(), old_layer_tree.paint_region_map(), use_raster_cache, impeller_enabled); - dc.PushCullRect( - SkRect::MakeIWH(layer_tree.size().width(), layer_tree.size().height())); + dc.PushCullRect(DlRect::MakeSize(layer_tree.size())); layer_tree.root()->Diff(&dc, old_layer_tree.root()); return dc.ComputeDamage(additional_damage, horizontal_clip_alignment, vertical_clip_alignment); } -sk_sp DiffContextTest::CreateDisplayList(const SkRect& bounds, +sk_sp DiffContextTest::CreateDisplayList(const DlRect& bounds, DlColor color) { DisplayListBuilder builder; builder.DrawRect(bounds, DlPaint().setColor(color)); @@ -40,7 +39,7 @@ sk_sp DiffContextTest::CreateDisplayList(const SkRect& bounds, std::shared_ptr DiffContextTest::CreateDisplayListLayer( const sk_sp& display_list, - const SkPoint& offset) { + const DlPoint& offset) { return std::make_shared(offset, display_list, false, false); } @@ -55,8 +54,8 @@ std::shared_ptr DiffContextTest::CreateContainerLayer( std::shared_ptr DiffContextTest::CreateOpacityLater( std::initializer_list> layers, - SkAlpha alpha, - const SkPoint& offset) { + uint8_t alpha, + const DlPoint& offset) { auto res = std::make_shared(alpha, offset); for (const auto& l : layers) { res->Add(l); diff --git a/flow/testing/diff_context_test.h b/flow/testing/diff_context_test.h index d626be1523910..84de5fd175483 100644 --- a/flow/testing/diff_context_test.h +++ b/flow/testing/diff_context_test.h @@ -7,6 +7,7 @@ #include +#include "flutter/display_list/geometry/dl_geometry_types.h" #include "flutter/flow/layers/container_layer.h" #include "flutter/flow/layers/display_list_layer.h" #include "flutter/flow/layers/opacity_layer.h" @@ -17,7 +18,7 @@ namespace testing { class MockLayerTree { public: - explicit MockLayerTree(SkISize size = SkISize::Make(1000, 1000)) + explicit MockLayerTree(DlISize size = DlISize(1000, 1000)) : root_(std::make_shared()), size_(size) {} ContainerLayer* root() { return root_.get(); } @@ -26,12 +27,12 @@ class MockLayerTree { PaintRegionMap& paint_region_map() { return paint_region_map_; } const PaintRegionMap& paint_region_map() const { return paint_region_map_; } - const SkISize& size() const { return size_; } + const DlISize& size() const { return size_; } private: std::shared_ptr root_; PaintRegionMap paint_region_map_; - SkISize size_; + DlISize size_; }; class DiffContextTest : public LayerTest { @@ -40,7 +41,7 @@ class DiffContextTest : public LayerTest { Damage DiffLayerTree(MockLayerTree& layer_tree, const MockLayerTree& old_layer_tree, - const SkIRect& additional_damage = SkIRect::MakeEmpty(), + const DlIRect& additional_damage = DlIRect(), int horizontal_clip_alignment = 0, int vertical_alignment = 0, bool use_raster_cache = true, @@ -48,12 +49,12 @@ class DiffContextTest : public LayerTest { // Create display list consisting of filled rect with given color; Being able // to specify different color is useful to test deep comparison of pictures - sk_sp CreateDisplayList(const SkRect& bounds, + sk_sp CreateDisplayList(const DlRect& bounds, DlColor color = DlColor::kBlack()); std::shared_ptr CreateDisplayListLayer( const sk_sp& display_list, - const SkPoint& offset = SkPoint::Make(0, 0)); + const DlPoint& offset = DlPoint(0, 0)); std::shared_ptr CreateContainerLayer( std::initializer_list> layers); @@ -65,8 +66,8 @@ class DiffContextTest : public LayerTest { std::shared_ptr CreateOpacityLater( std::initializer_list> layers, - SkAlpha alpha, - const SkPoint& offset = SkPoint::Make(0, 0)); + uint8_t alpha, + const DlPoint& offset = DlPoint(0, 0)); }; } // namespace testing diff --git a/flow/testing/layer_test.h b/flow/testing/layer_test.h index 44906b16f155c..573083af88f52 100644 --- a/flow/testing/layer_test.h +++ b/flow/testing/layer_test.h @@ -24,8 +24,6 @@ namespace flutter { namespace testing { -static constexpr SkRect kEmptyRect = SkRect::MakeEmpty(); - // This fixture allows generating tests which can |Paint()| and |Preroll()| // |Layer|'s. // |LayerTest| is a default implementation based on |::testing::Test|. @@ -76,7 +74,7 @@ class LayerTestBase : public CanvasTestBase { // clang-format on } { use_null_raster_cache(); - preroll_state_stack_.set_preroll_delegate(kGiantRect, SkMatrix::I()); + preroll_state_stack_.set_preroll_delegate(kGiantRect, DlMatrix()); display_list_state_stack_.set_delegate(&display_list_builder_); } diff --git a/flow/testing/mock_layer.cc b/flow/testing/mock_layer.cc index 324227d607a89..13031833dbbbc 100644 --- a/flow/testing/mock_layer.cc +++ b/flow/testing/mock_layer.cc @@ -14,7 +14,7 @@ namespace flutter { namespace testing { -MockLayer::MockLayer(const SkPath& path, DlPaint paint) +MockLayer::MockLayer(const DlPath& path, DlPaint paint) : fake_paint_path_(path), fake_paint_(std::move(paint)) {} bool MockLayer::IsReplacing(DiffContext* context, const Layer* layer) const { @@ -28,13 +28,13 @@ bool MockLayer::IsReplacing(DiffContext* context, const Layer* layer) const { void MockLayer::Diff(DiffContext* context, const Layer* old_layer) { DiffContext::AutoSubtreeRestore subtree(context); - context->AddLayerBounds(fake_paint_path_.getBounds()); + context->AddLayerBounds(fake_paint_path_.GetBounds()); context->SetLayerPaintRegion(this, context->CurrentSubtreeRegion()); } void MockLayer::Preroll(PrerollContext* context) { context->state_stack.fill(&parent_mutators_); - parent_matrix_ = context->state_stack.transform_3x3(); + parent_matrix_ = context->state_stack.matrix(); parent_cull_rect_ = context->state_stack.local_cull_rect(); set_parent_has_platform_view(context->has_platform_view); @@ -42,7 +42,7 @@ void MockLayer::Preroll(PrerollContext* context) { context->has_platform_view = fake_has_platform_view(); context->has_texture_layer = fake_has_texture_layer(); - set_paint_bounds(fake_paint_path_.getBounds()); + set_paint_bounds(fake_paint_path_.GetBounds()); if (fake_reads_surface()) { context->surface_needs_readback = true; } @@ -55,9 +55,7 @@ void MockLayer::Paint(PaintContext& context) const { FML_DCHECK(needs_painting(context)); if (expected_paint_matrix_.has_value()) { - SkMatrix matrix = context.canvas->GetTransform(); - - EXPECT_EQ(matrix, expected_paint_matrix_.value()); + EXPECT_EQ(context.canvas->GetMatrix(), expected_paint_matrix_.value()); } DlPaint paint = fake_paint_; @@ -69,7 +67,7 @@ void MockCacheableContainerLayer::Preroll(PrerollContext* context) { Layer::AutoPrerollSaveLayerState save = Layer::AutoPrerollSaveLayerState::Create(context); auto cache = AutoCache(layer_raster_cache_item_.get(), context, - context->state_stack.transform_3x3()); + context->state_stack.matrix()); ContainerLayer::Preroll(context); } @@ -78,7 +76,7 @@ void MockCacheableLayer::Preroll(PrerollContext* context) { Layer::AutoPrerollSaveLayerState save = Layer::AutoPrerollSaveLayerState::Create(context); auto cache = AutoCache(raster_cache_item_.get(), context, - context->state_stack.transform_3x3()); + context->state_stack.matrix()); MockLayer::Preroll(context); } diff --git a/flow/testing/mock_layer.h b/flow/testing/mock_layer.h index 953a8860bda43..0bb5bd8861834 100644 --- a/flow/testing/mock_layer.h +++ b/flow/testing/mock_layer.h @@ -25,14 +25,14 @@ namespace testing { // verify the data against expected values. class MockLayer : public Layer { public: - explicit MockLayer(const SkPath& path, DlPaint paint = DlPaint()); + explicit MockLayer(const DlPath& path, DlPaint paint = DlPaint()); - static std::shared_ptr Make(const SkPath& path, + static std::shared_ptr Make(const DlPath& path, DlPaint paint = DlPaint()) { return std::make_shared(path, std::move(paint)); } - static std::shared_ptr MakeOpacityCompatible(const SkPath& path) { + static std::shared_ptr MakeOpacityCompatible(const DlPath& path) { auto mock_layer = std::make_shared(path, DlPaint()); mock_layer->set_fake_opacity_compatible(true); return mock_layer; @@ -42,8 +42,8 @@ class MockLayer : public Layer { void Paint(PaintContext& context) const override; const MutatorsStack& parent_mutators() { return parent_mutators_; } - const SkMatrix& parent_matrix() { return parent_matrix_; } - const SkRect& parent_cull_rect() { return parent_cull_rect_; } + const DlMatrix& parent_matrix() { return parent_matrix_; } + const DlRect& parent_cull_rect() { return parent_cull_rect_; } bool IsReplacing(DiffContext* context, const Layer* layer) const override; void Diff(DiffContext* context, const Layer* old_layer) override; @@ -103,17 +103,17 @@ class MockLayer : public Layer { return *this; } - void set_expected_paint_matrix(const SkMatrix& matrix) { + void set_expected_paint_matrix(const DlMatrix& matrix) { expected_paint_matrix_ = matrix; } private: MutatorsStack parent_mutators_; - SkMatrix parent_matrix_; - SkRect parent_cull_rect_ = SkRect::MakeEmpty(); - SkPath fake_paint_path_; + DlMatrix parent_matrix_; + DlRect parent_cull_rect_; + DlPath fake_paint_path_; DlPaint fake_paint_; - std::optional expected_paint_matrix_; + std::optional expected_paint_matrix_; static constexpr int kParentHasPlatformView = 1 << 0; static constexpr int kParentHasTextureLayer = 1 << 1; @@ -153,7 +153,7 @@ class MockLayerCacheableItem : public LayerRasterCacheItem { }; class MockCacheableLayer : public MockLayer { public: - explicit MockCacheableLayer(const SkPath& path, + explicit MockCacheableLayer(const DlPath& path, DlPaint paint = DlPaint(), int render_limit = 3) : MockLayer(path, std::move(paint)) { diff --git a/flow/testing/mock_layer_unittests.cc b/flow/testing/mock_layer_unittests.cc index 26bd2f4069387..0dc409233761d 100644 --- a/flow/testing/mock_layer_unittests.cc +++ b/flow/testing/mock_layer_unittests.cc @@ -14,7 +14,7 @@ using MockLayerTest = LayerTest; #ifndef NDEBUG TEST_F(MockLayerTest, PaintBeforePrerollDies) { - SkPath path = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f); + DlPath path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); auto layer = std::make_shared(path, DlPaint()); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), @@ -22,10 +22,10 @@ TEST_F(MockLayerTest, PaintBeforePrerollDies) { } TEST_F(MockLayerTest, PaintingEmptyLayerDies) { - auto layer = std::make_shared(SkPath(), DlPaint()); + auto layer = std::make_shared(DlPath(), DlPaint()); layer->Preroll(preroll_context()); - EXPECT_EQ(layer->paint_bounds(), SkPath().getBounds()); + EXPECT_EQ(layer->paint_bounds(), DlPath().GetBounds()); EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()), "needs_painting\\(context\\)"); @@ -33,13 +33,14 @@ TEST_F(MockLayerTest, PaintingEmptyLayerDies) { #endif TEST_F(MockLayerTest, SimpleParams) { - const SkPath path = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f); + const DlPath path = DlPath::MakeRectLTRB(5.0f, 6.0f, 20.5f, 21.5f); const DlPaint paint = DlPaint(DlColor::kBlue()); - const SkMatrix start_matrix = SkMatrix::Translate(1.0f, 2.0f); - const SkMatrix scale_matrix = SkMatrix::Scale(0.5f, 0.5f); - const SkMatrix combined_matrix = SkMatrix::Concat(start_matrix, scale_matrix); - const SkRect local_cull_rect = SkRect::MakeWH(5.0f, 5.0f); - const SkRect device_cull_rect = combined_matrix.mapRect(local_cull_rect); + const DlMatrix start_matrix = DlMatrix::MakeTranslation({1.0f, 2.0f}); + const DlMatrix scale_matrix = DlMatrix::MakeScale({0.5f, 0.5f, 1.0f}); + const DlMatrix combined_matrix = start_matrix * scale_matrix; + const DlRect local_cull_rect = DlRect::MakeWH(5.0f, 5.0f); + const DlRect device_cull_rect = + local_cull_rect.TransformBounds(combined_matrix); const bool parent_has_platform_view = true; auto layer = std::make_shared(path, paint); @@ -50,9 +51,10 @@ TEST_F(MockLayerTest, SimpleParams) { preroll_context()->has_platform_view = parent_has_platform_view; layer->Preroll(preroll_context()); EXPECT_EQ(preroll_context()->has_platform_view, false); - EXPECT_EQ(layer->paint_bounds(), path.getBounds()); + EXPECT_EQ(layer->paint_bounds(), path.GetBounds()); EXPECT_TRUE(layer->needs_painting(paint_context())); - EXPECT_EQ(layer->parent_mutators(), std::vector{Mutator(scale_matrix)}); + EXPECT_EQ(layer->parent_mutators(), + std::vector{Mutator(ToSkMatrix(scale_matrix))}); EXPECT_EQ(layer->parent_matrix(), combined_matrix); EXPECT_EQ(layer->parent_cull_rect(), local_cull_rect); EXPECT_EQ(layer->parent_has_platform_view(), parent_has_platform_view); @@ -67,7 +69,7 @@ TEST_F(MockLayerTest, SimpleParams) { } TEST_F(MockLayerTest, FakePlatformView) { - auto layer = std::make_shared(SkPath(), DlPaint()); + auto layer = std::make_shared(DlPath(), DlPaint()); layer->set_fake_has_platform_view(true); EXPECT_EQ(preroll_context()->has_platform_view, false); @@ -76,7 +78,7 @@ TEST_F(MockLayerTest, FakePlatformView) { } TEST_F(MockLayerTest, SaveLayerOnLeafNodesCanvas) { - auto layer = std::make_shared(SkPath(), DlPaint()); + auto layer = std::make_shared(DlPath(), DlPaint()); layer->set_fake_has_platform_view(true); EXPECT_EQ(preroll_context()->has_platform_view, false); @@ -85,7 +87,7 @@ TEST_F(MockLayerTest, SaveLayerOnLeafNodesCanvas) { } TEST_F(MockLayerTest, OpacityInheritance) { - auto path1 = SkPath().addRect({10, 10, 30, 30}); + auto path1 = DlPath::MakeRectLTRB(10, 10, 30, 30); PrerollContext* context = preroll_context(); auto mock1 = std::make_shared(path1); @@ -99,7 +101,7 @@ TEST_F(MockLayerTest, OpacityInheritance) { } TEST_F(MockLayerTest, FlagGetSet) { - auto mock_layer = std::make_shared(SkPath()); + auto mock_layer = std::make_shared(DlPath()); EXPECT_EQ(mock_layer->parent_has_platform_view(), false); mock_layer->set_parent_has_platform_view(true); diff --git a/flow/testing/mock_raster_cache.cc b/flow/testing/mock_raster_cache.cc index aa99f25434a3b..187c31fa8076a 100644 --- a/flow/testing/mock_raster_cache.cc +++ b/flow/testing/mock_raster_cache.cc @@ -19,8 +19,7 @@ MockRasterCacheResult::MockRasterCacheResult(SkRect device_rect) void MockRasterCache::AddMockLayer(int width, int height) { SkMatrix ctm = SkMatrix::I(); - SkPath path; - path.addRect(100, 100, 100 + width, 100 + height); + DlPath path = DlPath::MakeRectLTRB(100, 100, 100 + width, 100 + height); int layer_cached_threshold = 1; MockCacheableLayer layer = MockCacheableLayer(path, DlPaint(), layer_cached_threshold); @@ -31,7 +30,7 @@ void MockRasterCache::AddMockLayer(int width, int height) { .gr_context = preroll_context_.gr_context, .dst_color_space = preroll_context_.dst_color_space, .matrix = ctm, - .logical_rect = layer.paint_bounds(), + .logical_rect = ToSkRect(layer.paint_bounds()), // clang-format on }; UpdateCacheEntry( @@ -62,7 +61,7 @@ void MockRasterCache::AddMockPicture(int width, int height) { DisplayListRasterCacheItem display_list_item(display_list, SkPoint(), true, false); for (size_t i = 0; i < access_threshold(); i++) { - AutoCache(&display_list_item, &preroll_context_, ctm); + AutoCache(&display_list_item, &preroll_context_, ToDlMatrix(ctm)); } RasterCache::Context r_context = { // clang-format off @@ -138,7 +137,7 @@ bool RasterCacheItemPrerollAndTryToRasterCache( DisplayListRasterCacheItem& display_list_item, PrerollContext& context, PaintContext& paint_context, - const SkMatrix& matrix) { + const DlMatrix& matrix) { RasterCacheItemPreroll(display_list_item, context, matrix); context.raster_cache->EvictUnusedCacheEntries(); return RasterCacheItemTryToRasterCache(display_list_item, paint_context); @@ -146,7 +145,7 @@ bool RasterCacheItemPrerollAndTryToRasterCache( void RasterCacheItemPreroll(DisplayListRasterCacheItem& display_list_item, PrerollContext& context, - const SkMatrix& matrix) { + const DlMatrix& matrix) { display_list_item.PrerollSetup(&context, matrix); display_list_item.PrerollFinalize(&context, matrix); } diff --git a/flow/testing/mock_raster_cache.h b/flow/testing/mock_raster_cache.h index 0a29b2f36b3f2..5e3a63cc6d017 100644 --- a/flow/testing/mock_raster_cache.h +++ b/flow/testing/mock_raster_cache.h @@ -11,7 +11,6 @@ #include "flutter/flow/raster_cache_item.h" #include "flutter/flow/testing/mock_layer.h" #include "third_party/skia/include/core/SkColorSpace.h" -#include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkSize.h" namespace flutter { @@ -61,7 +60,7 @@ class MockRasterCache : public RasterCache { RasterCacheUtil::kDefaultPictureAndDisplayListCacheLimitPerFrame) : RasterCache(access_threshold, picture_and_display_list_cache_limit_per_frame) { - preroll_state_stack_.set_preroll_delegate(SkMatrix::I()); + preroll_state_stack_.set_preroll_delegate(DlMatrix()); paint_state_stack_.set_delegate(&builder_); } @@ -135,11 +134,11 @@ bool RasterCacheItemPrerollAndTryToRasterCache( DisplayListRasterCacheItem& display_list_item, PrerollContext& context, PaintContext& paint_context, - const SkMatrix& matrix); + const DlMatrix& matrix); void RasterCacheItemPreroll(DisplayListRasterCacheItem& display_list_item, PrerollContext& context, - const SkMatrix& matrix); + const DlMatrix& matrix); bool RasterCacheItemTryToRasterCache( DisplayListRasterCacheItem& display_list_item, diff --git a/impeller/geometry/round_rect.h b/impeller/geometry/round_rect.h index 3e4e7742d0bb1..013a31861e189 100644 --- a/impeller/geometry/round_rect.h +++ b/impeller/geometry/round_rect.h @@ -182,8 +182,8 @@ struct RoundRect { constexpr RoundRect(const Rect& bounds, const RoundingRadii& radii) : bounds_(bounds), radii_(radii) {} - const Rect bounds_; - const RoundingRadii radii_; + Rect bounds_; + RoundingRadii radii_; }; } // namespace impeller diff --git a/lib/ui/compositing/scene.cc b/lib/ui/compositing/scene.cc index 7cdd7295cf1b3..220802327467d 100644 --- a/lib/ui/compositing/scene.cc +++ b/lib/ui/compositing/scene.cc @@ -91,7 +91,7 @@ static sk_sp CreateDeferredImage( #else // SLIMPELLER const auto& frame_size = layer_tree->frame_size(); const SkImageInfo image_info = - SkImageInfo::Make(frame_size.width(), frame_size.height(), + SkImageInfo::Make(frame_size.width, frame_size.height, kRGBA_8888_SkColorType, kPremul_SkAlphaType); return DlDeferredImageGPUSkia::MakeFromLayerTree( image_info, std::move(layer_tree), std::move(snapshot_delegate), @@ -130,7 +130,7 @@ std::unique_ptr Scene::BuildLayerTree(uint32_t width, return nullptr; } return std::make_unique(layer_tree_root_layer_, - SkISize::Make(width, height)); + DlISize(width, height)); } } // namespace flutter diff --git a/lib/ui/compositing/scene_builder.cc b/lib/ui/compositing/scene_builder.cc index 93651ade387ca..656c94f507b63 100644 --- a/lib/ui/compositing/scene_builder.cc +++ b/lib/ui/compositing/scene_builder.cc @@ -42,8 +42,8 @@ SceneBuilder::~SceneBuilder() = default; void SceneBuilder::pushTransform(Dart_Handle layer_handle, tonic::Float64List& matrix4, const fml::RefPtr& old_layer) { - SkM44 sk_matrix = ToSkM44(matrix4); - auto layer = std::make_shared(sk_matrix); + DlMatrix matrix = ToDlMatrix(matrix4); + auto layer = std::make_shared(matrix); PushLayer(layer); // matrix4 has to be released before we can return another Dart object matrix4.Release(); @@ -58,8 +58,8 @@ void SceneBuilder::pushOffset(Dart_Handle layer_handle, double dx, double dy, const fml::RefPtr& old_layer) { - SkMatrix sk_matrix = SkMatrix::Translate(SafeNarrow(dx), SafeNarrow(dy)); - auto layer = std::make_shared(sk_matrix); + DlMatrix matrix = DlMatrix::MakeTranslation({SafeNarrow(dx), SafeNarrow(dy)}); + auto layer = std::make_shared(matrix); PushLayer(layer); EngineLayer::MakeRetained(layer_handle, layer); @@ -75,7 +75,7 @@ void SceneBuilder::pushClipRect(Dart_Handle layer_handle, double bottom, int clip_behavior, const fml::RefPtr& old_layer) { - SkRect clip_rect = SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + DlRect clip_rect = DlRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), SafeNarrow(bottom)); auto layer = std::make_shared( clip_rect, static_cast(clip_behavior)); @@ -92,7 +92,7 @@ void SceneBuilder::pushClipRRect(Dart_Handle layer_handle, int clip_behavior, const fml::RefPtr& old_layer) { auto layer = std::make_shared( - rrect.sk_rrect, static_cast(clip_behavior)); + rrect.rrect, static_cast(clip_behavior)); PushLayer(layer); EngineLayer::MakeRetained(layer_handle, layer); @@ -124,7 +124,7 @@ void SceneBuilder::pushOpacity(Dart_Handle layer_handle, double dy, const fml::RefPtr& old_layer) { auto layer = std::make_shared( - alpha, SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy))); + alpha, DlPoint(SafeNarrow(dx), SafeNarrow(dy))); PushLayer(layer); EngineLayer::MakeRetained(layer_handle, layer); @@ -153,7 +153,7 @@ void SceneBuilder::pushImageFilter(Dart_Handle layer_handle, const fml::RefPtr& old_layer) { auto layer = std::make_shared( image_filter->filter(DlTileMode::kDecal), - SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy))); + DlPoint(SafeNarrow(dx), SafeNarrow(dy))); PushLayer(layer); EngineLayer::MakeRetained(layer_handle, layer); @@ -195,7 +195,7 @@ void SceneBuilder::pushShaderMask(Dart_Handle layer_handle, int blend_mode, int filter_quality_index, const fml::RefPtr& old_layer) { - SkRect rect = SkRect::MakeLTRB( + DlRect rect = DlRect::MakeLTRB( SafeNarrow(mask_rect_left), SafeNarrow(mask_rect_top), SafeNarrow(mask_rect_right), SafeNarrow(mask_rect_bottom)); auto sampling = ImageFilter::SamplingFromIndex(filter_quality_index); @@ -230,7 +230,7 @@ void SceneBuilder::addPicture(double dx, // been disposed but not collected yet, but the display list is null. if (picture->display_list()) { auto layer = std::make_unique( - SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy)), picture->display_list(), + DlPoint(SafeNarrow(dx), SafeNarrow(dy)), picture->display_list(), !!(hints & 1), !!(hints & 2)); AddLayer(std::move(layer)); } @@ -245,8 +245,8 @@ void SceneBuilder::addTexture(double dx, int filter_quality_index) { auto sampling = ImageFilter::SamplingFromIndex(filter_quality_index); auto layer = std::make_unique( - SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy)), - SkSize::Make(SafeNarrow(width), SafeNarrow(height)), texture_id, freeze, + DlPoint(SafeNarrow(dx), SafeNarrow(dy)), + DlSize(SafeNarrow(width), SafeNarrow(height)), texture_id, freeze, sampling); AddLayer(std::move(layer)); } @@ -257,8 +257,8 @@ void SceneBuilder::addPlatformView(double dx, double height, int64_t view_id) { auto layer = std::make_unique( - SkPoint::Make(SafeNarrow(dx), SafeNarrow(dy)), - SkSize::Make(SafeNarrow(width), SafeNarrow(height)), view_id); + DlPoint(SafeNarrow(dx), SafeNarrow(dy)), + DlSize(SafeNarrow(width), SafeNarrow(height)), view_id); AddLayer(std::move(layer)); } @@ -267,7 +267,7 @@ void SceneBuilder::addPerformanceOverlay(uint64_t enabled_options, double right, double top, double bottom) { - SkRect rect = SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + DlRect rect = DlRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), SafeNarrow(bottom)); auto layer = std::make_unique(enabled_options); diff --git a/lib/ui/painting/canvas.cc b/lib/ui/painting/canvas.cc index 217854d93b293..121cb0270fc42 100644 --- a/lib/ui/painting/canvas.cc +++ b/lib/ui/painting/canvas.cc @@ -36,7 +36,7 @@ void Canvas::Create(Dart_Handle wrapper, fml::RefPtr canvas = fml::MakeRefCounted(recorder->BeginRecording( - SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), + DlRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), SafeNarrow(bottom)))); recorder->set_canvas(canvas); canvas->AssociateWithDartWrapper(wrapper); @@ -77,7 +77,7 @@ void Canvas::saveLayer(double left, Paint paint(paint_objects, paint_data); FML_DCHECK(paint.isNotNull()); - SkRect bounds = SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + DlRect bounds = DlRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), SafeNarrow(bottom)); if (display_list_builder_) { DlPaint dl_paint; @@ -85,7 +85,7 @@ void Canvas::saveLayer(double left, paint.paint(dl_paint, kSaveLayerWithPaintFlags, DlTileMode::kDecal); FML_DCHECK(save_paint); TRACE_EVENT0("flutter", "ui.Canvas::saveLayer (Recorded)"); - builder()->SaveLayer(&bounds, save_paint); + builder()->SaveLayer(bounds, save_paint); } } @@ -135,7 +135,7 @@ void Canvas::skew(double sx, double sy) { void Canvas::transform(const tonic::Float64List& matrix4) { // The Float array stored by Dart Matrix4 is in column-major order - // Both DisplayList and SkM44 constructor take row-major matrix order + // DisplayList TransformFullPerspective takes row-major matrix order if (display_list_builder_) { // clang-format off builder()->TransformFullPerspective( @@ -149,13 +149,11 @@ void Canvas::transform(const tonic::Float64List& matrix4) { void Canvas::getTransform(Dart_Handle matrix4_handle) { if (display_list_builder_) { - SkM44 sk_m44 = builder()->GetTransformFullPerspective(); - SkScalar m44_values[16]; - // The Float array stored by Dart Matrix4 is in column-major order - sk_m44.getColMajor(m44_values); + // The Float array stored by DlMatrix is in column-major order + DlMatrix matrix = builder()->GetMatrix(); auto matrix4 = tonic::Float64List(matrix4_handle); for (int i = 0; i < 16; i++) { - matrix4[i] = m44_values[i]; + matrix4[i] = matrix.m[i]; } } } @@ -167,7 +165,7 @@ void Canvas::clipRect(double left, DlCanvas::ClipOp clipOp, bool doAntiAlias) { if (display_list_builder_) { - builder()->ClipRect(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + builder()->ClipRect(DlRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), SafeNarrow(bottom)), clipOp, doAntiAlias); } @@ -175,8 +173,8 @@ void Canvas::clipRect(double left, void Canvas::clipRRect(const RRect& rrect, bool doAntiAlias) { if (display_list_builder_) { - builder()->ClipRRect(rrect.sk_rrect, DlCanvas::ClipOp::kIntersect, - doAntiAlias); + builder()->ClipRoundRect(rrect.rrect, DlCanvas::ClipOp::kIntersect, + doAntiAlias); } } @@ -195,26 +193,26 @@ void Canvas::clipPath(const CanvasPath* path, bool doAntiAlias) { void Canvas::getDestinationClipBounds(Dart_Handle rect_handle) { if (display_list_builder_) { auto rect = tonic::Float64List(rect_handle); - SkRect bounds = builder()->GetDestinationClipBounds(); - rect[0] = bounds.fLeft; - rect[1] = bounds.fTop; - rect[2] = bounds.fRight; - rect[3] = bounds.fBottom; + DlRect bounds = builder()->GetDestinationClipCoverage(); + rect[0] = bounds.GetLeft(); + rect[1] = bounds.GetTop(); + rect[2] = bounds.GetRight(); + rect[3] = bounds.GetBottom(); } } void Canvas::getLocalClipBounds(Dart_Handle rect_handle) { if (display_list_builder_) { auto rect = tonic::Float64List(rect_handle); - SkRect bounds = builder()->GetLocalClipBounds(); - rect[0] = bounds.fLeft; - rect[1] = bounds.fTop; - rect[2] = bounds.fRight; - rect[3] = bounds.fBottom; + DlRect bounds = builder()->GetLocalClipCoverage(); + rect[0] = bounds.GetLeft(); + rect[1] = bounds.GetTop(); + rect[2] = bounds.GetRight(); + rect[3] = bounds.GetBottom(); } } -void Canvas::drawColor(SkColor color, DlBlendMode blend_mode) { +void Canvas::drawColor(uint32_t color, DlBlendMode blend_mode) { if (display_list_builder_) { builder()->DrawColor(DlColor(color), blend_mode); } @@ -232,9 +230,8 @@ void Canvas::drawLine(double x1, if (display_list_builder_) { DlPaint dl_paint; paint.paint(dl_paint, kDrawLineFlags, DlTileMode::kDecal); - builder()->DrawLine(SkPoint::Make(SafeNarrow(x1), SafeNarrow(y1)), - SkPoint::Make(SafeNarrow(x2), SafeNarrow(y2)), - dl_paint); + builder()->DrawLine(DlPoint(SafeNarrow(x1), SafeNarrow(y1)), + DlPoint(SafeNarrow(x2), SafeNarrow(y2)), dl_paint); } } @@ -247,8 +244,8 @@ void Canvas::drawPaint(Dart_Handle paint_objects, Dart_Handle paint_data) { paint.paint(dl_paint, kDrawPaintFlags, DlTileMode::kClamp); std::shared_ptr filter = dl_paint.getImageFilter(); if (filter && !filter->asColorFilter()) { - // drawPaint does an implicit saveLayer if an SkImageFilter is - // present that cannot be replaced by an SkColorFilter. + // drawPaint does an implicit saveLayer if an DlImageFilter is + // present that cannot be replaced by an DlColorFilter. TRACE_EVENT0("flutter", "ui.Canvas::saveLayer (Recorded)"); } builder()->DrawPaint(dl_paint); @@ -267,7 +264,7 @@ void Canvas::drawRect(double left, if (display_list_builder_) { DlPaint dl_paint; paint.paint(dl_paint, kDrawRectFlags, DlTileMode::kDecal); - builder()->DrawRect(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + builder()->DrawRect(DlRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), SafeNarrow(bottom)), dl_paint); } @@ -282,7 +279,7 @@ void Canvas::drawRRect(const RRect& rrect, if (display_list_builder_) { DlPaint dl_paint; paint.paint(dl_paint, kDrawRRectFlags, DlTileMode::kDecal); - builder()->DrawRRect(rrect.sk_rrect, dl_paint); + builder()->DrawRoundRect(rrect.rrect, dl_paint); } } @@ -296,7 +293,7 @@ void Canvas::drawDRRect(const RRect& outer, if (display_list_builder_) { DlPaint dl_paint; paint.paint(dl_paint, kDrawDRRectFlags, DlTileMode::kDecal); - builder()->DrawDRRect(outer.sk_rrect, inner.sk_rrect, dl_paint); + builder()->DrawDiffRoundRect(outer.rrect, inner.rrect, dl_paint); } } @@ -312,7 +309,7 @@ void Canvas::drawOval(double left, if (display_list_builder_) { DlPaint dl_paint; paint.paint(dl_paint, kDrawOvalFlags, DlTileMode::kDecal); - builder()->DrawOval(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), + builder()->DrawOval(DlRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), SafeNarrow(bottom)), dl_paint); } @@ -329,7 +326,7 @@ void Canvas::drawCircle(double x, if (display_list_builder_) { DlPaint dl_paint; paint.paint(dl_paint, kDrawCircleFlags, DlTileMode::kDecal); - builder()->DrawCircle(SkPoint::Make(SafeNarrow(x), SafeNarrow(y)), + builder()->DrawCircle(DlPoint(SafeNarrow(x), SafeNarrow(y)), SafeNarrow(radius), dl_paint); } } @@ -352,7 +349,7 @@ void Canvas::drawArc(double left, useCenter ? kDrawArcWithCenterFlags : kDrawArcNoCenterFlags, DlTileMode::kDecal); builder()->DrawArc( - SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), + DlRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top), SafeNarrow(right), SafeNarrow(bottom)), SafeNarrow(startAngle) * 180.0f / static_cast(M_PI), SafeNarrow(sweepAngle) * 180.0f / static_cast(M_PI), useCenter, @@ -405,7 +402,7 @@ Dart_Handle Canvas::drawImage(const CanvasImage* image, DlPaint dl_paint; const DlPaint* opt_paint = paint.paint(dl_paint, kDrawImageWithPaintFlags, DlTileMode::kClamp); - builder()->DrawImage(dl_image, SkPoint::Make(SafeNarrow(x), SafeNarrow(y)), + builder()->DrawImage(dl_image, DlPoint(SafeNarrow(x), SafeNarrow(y)), sampling, opt_paint); } return Dart_Null(); @@ -439,9 +436,9 @@ Dart_Handle Canvas::drawImageRect(const CanvasImage* image, return ToDart(error.value()); } - SkRect src = SkRect::MakeLTRB(SafeNarrow(src_left), SafeNarrow(src_top), + DlRect src = DlRect::MakeLTRB(SafeNarrow(src_left), SafeNarrow(src_top), SafeNarrow(src_right), SafeNarrow(src_bottom)); - SkRect dst = SkRect::MakeLTRB(SafeNarrow(dst_left), SafeNarrow(dst_top), + DlRect dst = DlRect::MakeLTRB(SafeNarrow(dst_left), SafeNarrow(dst_top), SafeNarrow(dst_right), SafeNarrow(dst_bottom)); auto sampling = ImageFilter::SamplingFromIndex(filterQualityIndex); if (display_list_builder_) { @@ -481,12 +478,11 @@ Dart_Handle Canvas::drawImageNine(const CanvasImage* image, return ToDart(error.value()); } - SkRect center = - SkRect::MakeLTRB(SafeNarrow(center_left), SafeNarrow(center_top), + DlRect center = + DlRect::MakeLTRB(SafeNarrow(center_left), SafeNarrow(center_top), SafeNarrow(center_right), SafeNarrow(center_bottom)); - SkIRect icenter; - center.round(&icenter); - SkRect dst = SkRect::MakeLTRB(SafeNarrow(dst_left), SafeNarrow(dst_top), + DlIRect icenter = DlIRect::Round(center); + DlRect dst = DlRect::MakeLTRB(SafeNarrow(dst_left), SafeNarrow(dst_top), SafeNarrow(dst_right), SafeNarrow(dst_bottom)); auto filter = ImageFilter::FilterModeFromIndex(bitmapSamplingIndex); if (display_list_builder_) { @@ -519,8 +515,8 @@ void Canvas::drawPoints(Dart_Handle paint_objects, const tonic::Float32List& points) { Paint paint(paint_objects, paint_data); - static_assert(sizeof(SkPoint) == sizeof(float) * 2, - "SkPoint doesn't use floats."); + static_assert(sizeof(DlPoint) == sizeof(float) * 2, + "DlPoint doesn't use floats."); FML_DCHECK(paint.isNotNull()); if (display_list_builder_) { @@ -537,8 +533,8 @@ void Canvas::drawPoints(Dart_Handle paint_objects, break; } builder()->DrawPoints(point_mode, - points.num_elements() / 2, // SkPoints have 2 floats - reinterpret_cast(points.data()), + points.num_elements() / 2, // DlPoints have 2 floats + reinterpret_cast(points.data()), dl_paint); } } @@ -587,8 +583,8 @@ Dart_Handle Canvas::drawAtlas(Dart_Handle paint_objects, static_assert(sizeof(SkRSXform) == sizeof(float) * 4, "SkRSXform doesn't use floats."); - static_assert(sizeof(SkRect) == sizeof(float) * 4, - "SkRect doesn't use floats."); + static_assert(sizeof(DlRect) == sizeof(float) * 4, + "DlRect doesn't use floats."); auto sampling = ImageFilter::SamplingFromIndex(filterQualityIndex); @@ -610,16 +606,16 @@ Dart_Handle Canvas::drawAtlas(Dart_Handle paint_objects, paint.paint(dl_paint, kDrawAtlasWithPaintFlags, DlTileMode::kClamp); builder()->DrawAtlas( dl_image, reinterpret_cast(transforms.data()), - reinterpret_cast(rects.data()), dl_color.data(), - rects.num_elements() / 4, // SkRect have four floats. - blend_mode, sampling, reinterpret_cast(cull_rect.data()), + reinterpret_cast(rects.data()), dl_color.data(), + rects.num_elements() / 4, // DlRect have four floats. + blend_mode, sampling, reinterpret_cast(cull_rect.data()), opt_paint); } return Dart_Null(); } void Canvas::drawShadow(const CanvasPath* path, - SkColor color, + uint32_t color, double elevation, bool transparentOccluder) { if (!path) { @@ -631,7 +627,7 @@ void Canvas::drawShadow(const CanvasPath* path, // Not using SafeNarrow because DPR will always be a relatively small number. const ViewportMetrics* metrics = UIDartState::Current()->platform_configuration()->GetMetrics(0); - SkScalar dpr; + DlScalar dpr; // TODO(dkwingsmt): We should support rendering shadows on non-implicit views. // However, currently this method has no way to get the target view ID. if (metrics == nullptr) { @@ -640,13 +636,6 @@ void Canvas::drawShadow(const CanvasPath* path, dpr = static_cast(metrics->device_pixel_ratio); } if (display_list_builder_) { - // The DrawShadow mechanism results in non-public operations to be - // performed on the canvas involving an SkDrawShadowRec. Since we - // cannot include the header that defines that structure, we cannot - // record an operation that it injects into an SkCanvas. To prevent - // that situation we bypass the canvas interface and inject the - // shadow parameters directly into the underlying DisplayList. - // See: https://bugs.chromium.org/p/skia/issues/detail?id=12125 builder()->DrawShadow(path->path(), DlColor(color), SafeNarrow(elevation), transparentOccluder, dpr); } diff --git a/lib/ui/painting/canvas.h b/lib/ui/painting/canvas.h index 20ab1c9eafa9d..9e805dfec533a 100644 --- a/lib/ui/painting/canvas.h +++ b/lib/ui/painting/canvas.h @@ -65,7 +65,7 @@ class Canvas : public RefCountedDartWrappable, DisplayListOpFlags { void getDestinationClipBounds(Dart_Handle rect_handle); void getLocalClipBounds(Dart_Handle rect_handle); - void drawColor(SkColor color, DlBlendMode blend_mode); + void drawColor(uint32_t color, DlBlendMode blend_mode); void drawLine(double x1, double y1, @@ -180,7 +180,7 @@ class Canvas : public RefCountedDartWrappable, DisplayListOpFlags { Dart_Handle cull_rect_handle); void drawShadow(const CanvasPath* path, - SkColor color, + uint32_t color, double elevation, bool transparentOccluder); diff --git a/lib/ui/painting/display_list_deferred_image_gpu_impeller.cc b/lib/ui/painting/display_list_deferred_image_gpu_impeller.cc index 9e07fba58280e..1881e7058e3c8 100644 --- a/lib/ui/painting/display_list_deferred_image_gpu_impeller.cc +++ b/lib/ui/painting/display_list_deferred_image_gpu_impeller.cc @@ -110,8 +110,8 @@ DlDeferredImageGPUImpeller::ImageWrapper::Make( fml::TaskRunnerAffineWeakPtr snapshot_delegate, fml::RefPtr raster_task_runner) { auto wrapper = std::shared_ptr(new ImageWrapper( - nullptr, layer_tree->frame_size(), std::move(snapshot_delegate), - std::move(raster_task_runner))); + nullptr, ToSkISize(layer_tree->frame_size()), + std::move(snapshot_delegate), std::move(raster_task_runner))); wrapper->SnapshotDisplayList(std::move(layer_tree)); return wrapper; } @@ -172,7 +172,7 @@ void DlDeferredImageGPUImpeller::ImageWrapper::SnapshotDisplayList( if (layer_tree) { wrapper->display_list_ = layer_tree->Flatten( - SkRect::MakeWH(wrapper->size_.width(), wrapper->size_.height()), + DlRect::MakeWH(wrapper->size_.width(), wrapper->size_.height()), wrapper->texture_registry_); } auto snapshot = snapshot_delegate->MakeRasterSnapshotSync( diff --git a/lib/ui/painting/display_list_deferred_image_gpu_skia.cc b/lib/ui/painting/display_list_deferred_image_gpu_skia.cc index 3e13ae4cd56c5..634e44f7f07f9 100644 --- a/lib/ui/painting/display_list_deferred_image_gpu_skia.cc +++ b/lib/ui/painting/display_list_deferred_image_gpu_skia.cc @@ -182,7 +182,7 @@ void DlDeferredImageGPUSkia::ImageWrapper::SnapshotDisplayList( } if (layer_tree) { auto display_list = - layer_tree->Flatten(SkRect::MakeWH(wrapper->image_info_.width(), + layer_tree->Flatten(DlRect::MakeWH(wrapper->image_info_.width(), wrapper->image_info_.height()), snapshot_delegate->GetTextureRegistry(), snapshot_delegate->GetGrContext()); diff --git a/lib/ui/painting/path.cc b/lib/ui/painting/path.cc index e04004f77ecee..be93ad02b5ada 100644 --- a/lib/ui/painting/path.cc +++ b/lib/ui/painting/path.cc @@ -198,7 +198,7 @@ void CanvasPath::addPolygon(const tonic::Float32List& points, bool close) { } void CanvasPath::addRRect(const RRect& rrect) { - sk_path_.addRRect(rrect.sk_rrect); + sk_path_.addRRect(ToSkRRect(rrect.rrect)); resetVolatility(); } diff --git a/lib/ui/painting/picture.cc b/lib/ui/painting/picture.cc index a8a0e957a828d..6f2a0cd5b6166 100644 --- a/lib/ui/painting/picture.cc +++ b/lib/ui/painting/picture.cc @@ -131,8 +131,8 @@ Dart_Handle Picture::RasterizeLayerTreeToImage( Dart_Handle raw_image_callback) { FML_DCHECK(layer_tree != nullptr); auto frame_size = layer_tree->frame_size(); - return DoRasterizeToImage(nullptr, std::move(layer_tree), frame_size.width(), - frame_size.height(), raw_image_callback); + return DoRasterizeToImage(nullptr, std::move(layer_tree), frame_size.width, + frame_size.height, raw_image_callback); } Dart_Handle Picture::DoRasterizeToImage(const sk_sp& display_list, @@ -206,17 +206,17 @@ Dart_Handle Picture::DoRasterizeToImage(const sk_sp& display_list, fml::MakeCopyable([ui_task_runner, snapshot_delegate, display_list, width, height, ui_task, layer_tree = std::move(layer_tree)]() mutable { - auto picture_bounds = SkISize::Make(width, height); + auto picture_bounds = DlISize(width, height); sk_sp snapshot_display_list = display_list; if (layer_tree) { FML_DCHECK(picture_bounds == layer_tree->frame_size()); snapshot_display_list = - layer_tree->Flatten(SkRect::MakeWH(width, height), + layer_tree->Flatten(DlRect::MakeWH(width, height), snapshot_delegate->GetTextureRegistry(), snapshot_delegate->GetGrContext()); } snapshot_delegate->MakeRasterSnapshot( - snapshot_display_list, picture_bounds, + snapshot_display_list, ToSkISize(picture_bounds), [ui_task_runner, ui_task](const sk_sp& image) { fml::TaskRunner::RunNowOrPostTask( ui_task_runner, [ui_task, image]() { ui_task(image); }); diff --git a/lib/ui/painting/picture_recorder.cc b/lib/ui/painting/picture_recorder.cc index 58d9d86632a7d..fc57254250a50 100644 --- a/lib/ui/painting/picture_recorder.cc +++ b/lib/ui/painting/picture_recorder.cc @@ -25,7 +25,7 @@ PictureRecorder::PictureRecorder() {} PictureRecorder::~PictureRecorder() {} -sk_sp PictureRecorder::BeginRecording(SkRect bounds) { +sk_sp PictureRecorder::BeginRecording(DlRect bounds) { display_list_builder_ = sk_make_sp(bounds, /*prepare_rtree=*/true); return display_list_builder_; diff --git a/lib/ui/painting/picture_recorder.h b/lib/ui/painting/picture_recorder.h index ccbc8d030e3e7..a0903962f620b 100644 --- a/lib/ui/painting/picture_recorder.h +++ b/lib/ui/painting/picture_recorder.h @@ -21,7 +21,7 @@ class PictureRecorder : public RefCountedDartWrappable { ~PictureRecorder() override; - sk_sp BeginRecording(SkRect bounds); + sk_sp BeginRecording(DlRect bounds); void endRecording(Dart_Handle dart_picture); void set_canvas(fml::RefPtr canvas) { canvas_ = std::move(canvas); } diff --git a/lib/ui/painting/rrect.cc b/lib/ui/painting/rrect.cc index 39889060e9cf3..038826344569b 100644 --- a/lib/ui/painting/rrect.cc +++ b/lib/ui/painting/rrect.cc @@ -12,7 +12,7 @@ using flutter::RRect; namespace tonic { -// Construct an SkRRect from a Dart RRect object. +// Construct an DlRoundRect from a Dart RRect object. // The Dart RRect is a Float32List containing // [left, top, right, bottom, xRadius, yRadius] RRect DartConverter::FromDart(Dart_Handle value) { @@ -24,13 +24,14 @@ RRect DartConverter::FromDart(Dart_Handle value) { return result; } - SkVector radii[4] = {{buffer[4], buffer[5]}, - {buffer[6], buffer[7]}, - {buffer[8], buffer[9]}, - {buffer[10], buffer[11]}}; + impeller::RoundingRadii radii = {{buffer[4], buffer[5]}, + {buffer[6], buffer[7]}, + {buffer[10], buffer[11]}, + {buffer[8], buffer[9]}}; - result.sk_rrect.setRectRadii( - SkRect::MakeLTRB(buffer[0], buffer[1], buffer[2], buffer[3]), radii); + result.rrect = flutter::DlRoundRect::MakeRectRadii( + flutter::DlRect::MakeLTRB(buffer[0], buffer[1], buffer[2], buffer[3]), + radii); result.is_null = false; return result; diff --git a/lib/ui/painting/rrect.h b/lib/ui/painting/rrect.h index df250a2e855c6..4a2912ecc340f 100644 --- a/lib/ui/painting/rrect.h +++ b/lib/ui/painting/rrect.h @@ -5,6 +5,7 @@ #ifndef FLUTTER_LIB_UI_PAINTING_RRECT_H_ #define FLUTTER_LIB_UI_PAINTING_RRECT_H_ +#include "flutter/display_list/geometry/dl_geometry_types.h" #include "third_party/dart/runtime/include/dart_api.h" #include "third_party/skia/include/core/SkRRect.h" #include "third_party/tonic/converter/dart_converter.h" @@ -13,7 +14,7 @@ namespace flutter { class RRect { public: - SkRRect sk_rrect; + DlRoundRect rrect; bool is_null; }; diff --git a/shell/common/animator_unittests.cc b/shell/common/animator_unittests.cc index 1f8bb22db642c..f5f71ae341f72 100644 --- a/shell/common/animator_unittests.cc +++ b/shell/common/animator_unittests.cc @@ -167,7 +167,7 @@ TEST_F(ShellTest, AnimatorDoesNotNotifyIdleBeforeRender) { ASSERT_FALSE(delegate.notify_idle_called_); EXPECT_CALL(delegate, OnAnimatorBeginFrame).WillOnce([&] { auto layer_tree = - std::make_unique(nullptr, SkISize::Make(600, 800)); + std::make_unique(nullptr, DlISize(600, 800)); animator->Render(kImplicitViewId, std::move(layer_tree), 1.0); render_latch.Signal(); }); @@ -248,7 +248,7 @@ TEST_F(ShellTest, AnimatorDoesNotNotifyDelegateIfPipelineIsNotEmpty) { task_runners.GetUITaskRunner()->PostTask([&] { EXPECT_CALL(delegate, OnAnimatorBeginFrame).WillOnce([&] { auto layer_tree = - std::make_unique(nullptr, SkISize::Make(600, 800)); + std::make_unique(nullptr, DlISize(600, 800)); animator->Render(kImplicitViewId, std::move(layer_tree), 1.0); begin_frame_latch.Signal(); }); diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 770f778759925..6cfe415392c08 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -483,7 +483,7 @@ void Engine::Render(int64_t view_id, } // Ensure frame dimensions are sane. - if (layer_tree->frame_size().isEmpty() || device_pixel_ratio <= 0.0f) { + if (layer_tree->frame_size().IsEmpty() || device_pixel_ratio <= 0.0f) { return; } diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index ab20229496ed3..cc0b06b1084a4 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -702,8 +702,8 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( DlCanvas* embedder_root_canvas = nullptr; if (external_view_embedder_) { - external_view_embedder_->PrepareFlutterView(layer_tree.frame_size(), - device_pixel_ratio); + external_view_embedder_->PrepareFlutterView( + ToSkISize(layer_tree.frame_size()), device_pixel_ratio); // TODO(dkwingsmt): Add view ID here. embedder_root_canvas = external_view_embedder_->GetRootCanvas(); } @@ -712,7 +712,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( // // Deleting a surface also clears the GL context. Therefore, acquire the // frame after calling `BeginFrame` as this operation resets the GL context. - auto frame = surface_->AcquireFrame(layer_tree.frame_size()); + auto frame = surface_->AcquireFrame(ToSkISize(layer_tree.frame_size())); if (frame == nullptr) { return DrawSurfaceStatus::kFailed; } @@ -755,7 +755,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( auto existing_damage = frame->framebuffer_info().existing_damage; if (existing_damage.has_value() && !force_full_repaint) { damage->SetPreviousLayerTree(GetLastLayerTree(view_id)); - damage->AddAdditionalDamage(existing_damage.value()); + damage->AddAdditionalDamage(ToDlIRect(existing_damage.value())); damage->SetClipAlignment( frame->framebuffer_info().horizontal_clip_alignment, frame->framebuffer_info().vertical_clip_alignment); @@ -779,8 +779,8 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe( SurfaceFrame::SubmitInfo submit_info; submit_info.presentation_time = presentation_time; if (damage) { - submit_info.frame_damage = damage->GetFrameDamage(); - submit_info.buffer_damage = damage->GetBufferDamage(); + submit_info.frame_damage = ToOptSkIRect(damage->GetFrameDamage()); + submit_info.buffer_damage = ToOptSkIRect(damage->GetBufferDamage()); } frame->set_submit_info(submit_info); @@ -827,7 +827,7 @@ static sk_sp ScreenshotLayerTreeAsPicture( FML_DCHECK(tree != nullptr); SkPictureRecorder recorder; recorder.beginRecording( - SkRect::MakeWH(tree->frame_size().width(), tree->frame_size().height())); + SkRect::MakeWH(tree->frame_size().width, tree->frame_size().height)); SkMatrix root_surface_transformation; root_surface_transformation.reset(); @@ -919,16 +919,13 @@ ScreenshotLayerTreeAsImageImpeller( return {nullptr, Rasterizer::ScreenshotFormat::kUnknown}; } - DisplayListBuilder builder(SkRect::MakeSize( - SkSize::Make(tree->frame_size().fWidth, tree->frame_size().fHeight))); + DisplayListBuilder builder(DlRect::MakeSize(tree->frame_size())); RenderFrameForScreenshot(compositor_context, &builder, tree, nullptr, aiks_context); std::shared_ptr texture = impeller::DisplayListToTexture( - builder.Build(), - impeller::ISize(tree->frame_size().fWidth, tree->frame_size().fHeight), - *aiks_context); + builder.Build(), impeller::ISize(tree->frame_size()), *aiks_context); if (!texture) { FML_LOG(ERROR) << "Failed to render to texture"; return {nullptr, Rasterizer::ScreenshotFormat::kUnknown}; @@ -1074,12 +1071,12 @@ Rasterizer::Screenshot Rasterizer::ScreenshotLastLayerTree( auto b64_data = SkData::MakeUninitialized(b64_size); Base64::Encode(data.first->data(), data.first->size(), b64_data->writable_data()); - return Rasterizer::Screenshot{b64_data, layer_tree->frame_size(), format, - data.second}; + return Rasterizer::Screenshot{b64_data, ToSkISize(layer_tree->frame_size()), + format, data.second}; } - return Rasterizer::Screenshot{data.first, layer_tree->frame_size(), format, - data.second}; + return Rasterizer::Screenshot{data.first, ToSkISize(layer_tree->frame_size()), + format, data.second}; } void Rasterizer::SetNextFrameCallback(const fml::closure& callback) { diff --git a/shell/common/rasterizer_unittests.cc b/shell/common/rasterizer_unittests.cc index b8ae39c9157f7..0cb44c143b716 100644 --- a/shell/common/rasterizer_unittests.cc +++ b/shell/common/rasterizer_unittests.cc @@ -243,7 +243,7 @@ TEST(RasterizerTest, thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique(/*root_layer=*/nullptr, - /*frame_size=*/SkISize()); + /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -317,7 +317,7 @@ TEST( thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -397,7 +397,7 @@ TEST( auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique(/*root_layer=*/nullptr, - /*frame_size=*/SkISize()); + /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -482,7 +482,7 @@ TEST(RasterizerTest, auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique(/*root_layer=*/nullptr, - /*frame_size=*/SkISize()); + /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -534,7 +534,7 @@ TEST(RasterizerTest, externalViewEmbedderDoesntEndFrameWhenNoSurfaceIsSet) { thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -598,7 +598,7 @@ TEST(RasterizerTest, externalViewEmbedderDoesntEndFrameWhenNotUsedThisFrame) { thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -728,9 +728,9 @@ TEST(RasterizerTest, drawMultipleViewsWithExternalViewEmbedder) { auto pipeline = std::make_shared(/*depth=*/10); std::vector> tasks; tasks.push_back(std::make_unique( - 0, std::make_unique(nullptr, SkISize()), 1.5)); + 0, std::make_unique(nullptr, DlISize()), 1.5)); tasks.push_back(std::make_unique( - 1, std::make_unique(nullptr, SkISize()), 2.0)); + 1, std::make_unique(nullptr, DlISize()), 2.0)); auto layer_tree_item = std::make_unique( std::move(tasks), CreateFinishedBuildRecorder()); PipelineProduceResult result = @@ -789,7 +789,7 @@ TEST(RasterizerTest, thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -851,7 +851,7 @@ TEST( thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -913,7 +913,7 @@ TEST( thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -974,7 +974,7 @@ TEST( thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -1032,7 +1032,7 @@ TEST( thread_host.raster_thread->GetTaskRunner()->PostTask([&] { auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -1117,7 +1117,7 @@ TEST(RasterizerTest, auto pipeline = std::make_shared(/*depth=*/10); for (int i = 0; i < 2; i++) { auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -1291,7 +1291,7 @@ TEST(RasterizerTest, presentationTimeSetWhenVsyncTargetInFuture) { auto pipeline = std::make_shared(/*depth=*/10); for (int i = 0; i < 2; i++) { auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), @@ -1374,7 +1374,7 @@ TEST(RasterizerTest, presentationTimeNotSetWhenVsyncTargetInPast) { rasterizer->Setup(std::move(surface)); auto pipeline = std::make_shared(/*depth=*/10); auto layer_tree = std::make_unique( - /*root_layer=*/nullptr, /*frame_size=*/SkISize()); + /*root_layer=*/nullptr, /*frame_size=*/DlISize()); auto layer_tree_item = std::make_unique( SingleLayerTreeList(kImplicitViewId, std::move(layer_tree), kDevicePixelRatio), diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 8bd6403fbda3c..378524986552b 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -1661,7 +1661,7 @@ bool Shell::ShouldDiscardLayerTree(int64_t view_id, std::scoped_lock lock(resize_mutex_); auto expected_frame_size = ExpectedFrameSize(view_id); return !expected_frame_size.isEmpty() && - tree.frame_size() != expected_frame_size; + ToSkISize(tree.frame_size()) != expected_frame_size; } // |ServiceProtocol::Handler| diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index 800d3d11c6d5c..1ee1aecc175f9 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -245,13 +245,11 @@ void ShellTest::PumpOneFrame(Shell* shell, FrameContent frame_content) { // causing flaky assertion errors. for (auto& [view_id, view_content] : frame_content) { - SkMatrix identity; - identity.setIdentity(); - auto root_layer = std::make_shared(identity); + auto root_layer = std::make_shared(DlMatrix()); auto layer_tree = std::make_unique( root_layer, - SkISize::Make(view_content.viewport_metrics.physical_width, - view_content.viewport_metrics.physical_height)); + DlISize(view_content.viewport_metrics.physical_width, + view_content.viewport_metrics.physical_height)); float device_pixel_ratio = static_cast( view_content.viewport_metrics.device_pixel_ratio); if (view_content.builder) { diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index a38994120cba2..f6d9751bb4718 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -416,8 +416,8 @@ static void PostSync(const fml::RefPtr& task_runner, } static sk_sp MakeSizedDisplayList(int width, int height) { - DisplayListBuilder builder(SkRect::MakeXYWH(0, 0, width, height)); - builder.DrawRect(SkRect::MakeXYWH(0, 0, width, height), + DisplayListBuilder builder(DlRect::MakeXYWH(0, 0, width, height)); + builder.DrawRect(DlRect::MakeXYWH(0, 0, width, height), DlPaint(DlColor::kRed())); return builder.Build(); } @@ -920,7 +920,7 @@ TEST_F(ShellTest, ExternalEmbedderNoThreadMerger) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; @@ -981,20 +981,20 @@ TEST_F(ShellTest, PushBackdropFilterToVisitedPlatformViews) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto platform_view_layer = std::make_shared( - SkPoint::Make(10, 10), SkSize::Make(10, 10), 50); + DlPoint(10, 10), DlSize(10, 10), 50); root->Add(platform_view_layer); - auto transform_layer = - std::make_shared(SkMatrix::Translate(1, 1)); + auto transform_layer = std::make_shared( + DlMatrix::MakeTranslation({1.0f, 1.0f})); root->Add(transform_layer); auto clip_rect_layer = std::make_shared( - SkRect::MakeLTRB(0, 0, 30, 30), Clip::kHardEdge); + DlRect::MakeLTRB(0, 0, 30, 30), Clip::kHardEdge); transform_layer->Add(clip_rect_layer); auto filter = DlImageFilter::MakeBlur(5, 5, DlTileMode::kClamp); auto backdrop_filter_layer = std::make_shared(filter, DlBlendMode::kSrcOver); clip_rect_layer->Add(backdrop_filter_layer); auto platform_view_layer2 = std::make_shared( - SkPoint::Make(10, 10), SkSize::Make(10, 10), 75); + DlPoint(10, 10), DlSize(10, 10), 75); backdrop_filter_layer->Add(platform_view_layer2); }; @@ -1055,7 +1055,7 @@ TEST_F(ShellTest, LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; @@ -1101,7 +1101,7 @@ TEST_F(ShellTest, OnPlatformViewDestroyDisablesThreadMerger) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; @@ -1171,7 +1171,7 @@ TEST_F(ShellTest, OnPlatformViewDestroyAfterMergingThreads) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; @@ -1240,7 +1240,7 @@ TEST_F(ShellTest, OnPlatformViewDestroyWhenThreadsAreMerging) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; @@ -1308,7 +1308,7 @@ TEST_F(ShellTest, LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; PumpOneFrame(shell.get(), ViewContent::ImplicitView(100, 100, builder)); @@ -1347,7 +1347,7 @@ TEST_F(ShellTest, OnPlatformViewDestroyWithoutRasterThreadMerger) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; PumpOneFrame(shell.get(), ViewContent::ImplicitView(100, 100, builder)); @@ -1413,7 +1413,7 @@ TEST_F(ShellTest, OnPlatformViewDestroyWithStaticThreadMerging) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; PumpOneFrame(shell.get(), ViewContent::ImplicitView(100, 100, builder)); @@ -1459,7 +1459,7 @@ TEST_F(ShellTest, GetUsedThisFrameShouldBeSetBeforeEndFrame) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; PumpOneFrame(shell.get(), ViewContent::ImplicitView(100, 100, builder)); @@ -2216,7 +2216,7 @@ TEST_F(ShellTest, Screenshot) { LayerTreeBuilder builder = [&](const std::shared_ptr& root) { auto display_list_layer = std::make_shared( - SkPoint::Make(10, 10), MakeSizedDisplayList(80, 80), false, false); + DlPoint(10, 10), MakeSizedDisplayList(80, 80), false, false); root->Add(display_list_layer); }; @@ -2494,8 +2494,8 @@ TEST_F(ShellTest, OnServiceProtocolEstimateRasterCacheMemoryWorks) { // 1. Construct a picture and a picture layer to be raster cached. sk_sp display_list = MakeSizedDisplayList(10, 10); auto display_list_layer = std::make_shared( - SkPoint::Make(0, 0), MakeSizedDisplayList(100, 100), false, false); - display_list_layer->set_paint_bounds(SkRect::MakeWH(100, 100)); + DlPoint(0, 0), MakeSizedDisplayList(100, 100), false, false); + display_list_layer->set_paint_bounds(DlRect::MakeWH(100, 100)); // 2. Rasterize the picture and the picture layer in the raster cache. std::promise rasterized; @@ -2548,7 +2548,7 @@ TEST_F(ShellTest, OnServiceProtocolEstimateRasterCacheMemoryWorks) { DisplayListRasterCacheItem display_list_raster_cache_item( display_list, SkPoint(), true, false); for (int i = 0; i < 4; i += 1) { - SkMatrix matrix = SkMatrix::I(); + DlMatrix matrix; state_stack.set_preroll_delegate(matrix); display_list_raster_cache_item.PrerollSetup(&preroll_context, matrix); display_list_raster_cache_item.PrerollFinalize(&preroll_context, @@ -2564,10 +2564,9 @@ TEST_F(ShellTest, OnServiceProtocolEstimateRasterCacheMemoryWorks) { // 2.2. Rasterize the picture layer. LayerRasterCacheItem layer_raster_cache_item(display_list_layer.get()); - state_stack.set_preroll_delegate(SkMatrix::I()); - layer_raster_cache_item.PrerollSetup(&preroll_context, SkMatrix::I()); - layer_raster_cache_item.PrerollFinalize(&preroll_context, - SkMatrix::I()); + state_stack.set_preroll_delegate(DlMatrix()); + layer_raster_cache_item.PrerollSetup(&preroll_context, DlMatrix()); + layer_raster_cache_item.PrerollFinalize(&preroll_context, DlMatrix()); state_stack.set_delegate(&dummy_canvas); layer_raster_cache_item.TryToPrepareRasterCache(paint_context); layer_raster_cache_item.Draw(paint_context, &dummy_canvas, &paint);