From 6f17ca29d7097c00f308328ba48fdbb0997a8ecc Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 15 Jun 2021 00:59:02 +0200 Subject: [PATCH] Make Layer::AssignOldLayer non virtual (flutter/engine#26740) --- .../flutter/flow/layers/container_layer.cc | 20 +++++++++++++++---- .../src/flutter/flow/layers/container_layer.h | 12 +++++++---- engine/src/flutter/flow/layers/layer.h | 2 +- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/flow/layers/container_layer.cc b/engine/src/flutter/flow/layers/container_layer.cc index 925f6154e7..91ce868a62 100644 --- a/engine/src/flutter/flow/layers/container_layer.cc +++ b/engine/src/flutter/flow/layers/container_layer.cc @@ -242,11 +242,23 @@ MergedContainerLayer::MergedContainerLayer() { ContainerLayer::Add(std::make_shared()); } -void MergedContainerLayer::AssignOldLayer(Layer* old_layer) { - ContainerLayer::AssignOldLayer(old_layer); - auto layer = static_cast(old_layer); - GetChildContainer()->AssignOldLayer(layer->GetChildContainer()); +#ifdef FLUTTER_ENABLE_DIFF_CONTEXT +void MergedContainerLayer::DiffChildren(DiffContext* context, + const ContainerLayer* old_layer) { + if (context->IsSubtreeDirty()) { + GetChildContainer()->Diff(context, nullptr); + return; + } + FML_DCHECK(old_layer); + + // For MergedContainerLayer we want to diff children of ChildContainer + // instead of the ChildContainer itself. This works around the fact + // that ChildContainerLayer is ephemeral and its original_layer_id_ is always + // different. + auto layer = static_cast(old_layer); + GetChildContainer()->DiffChildren(context, layer->GetChildContainer()); } +#endif void MergedContainerLayer::Add(std::shared_ptr layer) { GetChildContainer()->Add(std::move(layer)); diff --git a/engine/src/flutter/flow/layers/container_layer.h b/engine/src/flutter/flow/layers/container_layer.h index 4bd8e2d7bc..de1548fb17 100644 --- a/engine/src/flutter/flow/layers/container_layer.h +++ b/engine/src/flutter/flow/layers/container_layer.h @@ -33,13 +33,14 @@ class ContainerLayer : public Layer { const std::vector>& layers() const { return layers_; } - protected: #ifdef FLUTTER_ENABLE_DIFF_CONTEXT - void DiffChildren(DiffContext* context, const ContainerLayer* old_layer); + virtual void DiffChildren(DiffContext* context, + const ContainerLayer* old_layer); #endif // FLUTTER_ENABLE_DIFF_CONTEXT + protected: void PrerollChildren(PrerollContext* context, const SkMatrix& child_matrix, SkRect* child_paint_bounds); @@ -114,10 +115,13 @@ class MergedContainerLayer : public ContainerLayer { public: MergedContainerLayer(); - void AssignOldLayer(Layer* old_layer) override; - void Add(std::shared_ptr layer) override; +#ifdef FLUTTER_ENABLE_DIFF_CONTEXT + void DiffChildren(DiffContext* context, + const ContainerLayer* old_layer) override; +#endif + protected: /** * @brief Returns the ContainerLayer used to hold all of the children of the diff --git a/engine/src/flutter/flow/layers/layer.h b/engine/src/flutter/flow/layers/layer.h index c3a38a9089..78625cea90 100644 --- a/engine/src/flutter/flow/layers/layer.h +++ b/engine/src/flutter/flow/layers/layer.h @@ -85,7 +85,7 @@ class Layer { Layer(); virtual ~Layer(); - virtual void AssignOldLayer(Layer* old_layer) { + void AssignOldLayer(Layer* old_layer) { original_layer_id_ = old_layer->original_layer_id_; }