From 670329e1bfd0e5fccad3905cfd5aeb0ef897cb96 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 28 Nov 2016 12:28:18 -0800 Subject: [PATCH] Add prune to child scene layers (flutter/engine#3272) Also, change the hit testing geometry so that we get our hits at the root. --- .../flutter/flow/layers/child_scene_layer.cc | 16 ++++++++++------ .../flutter/flow/layers/child_scene_layer.h | 7 +++++-- .../src/flutter/flow/scene_update_context.cc | 1 - engine/src/flutter/lib/ui/compositing.dart | 19 ++++++++++++------- .../lib/ui/compositing/scene_builder.cc | 4 +++- .../lib/ui/compositing/scene_builder.h | 3 ++- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/engine/src/flutter/flow/layers/child_scene_layer.cc b/engine/src/flutter/flow/layers/child_scene_layer.cc index 62510b69dc..d840305e56 100644 --- a/engine/src/flutter/flow/layers/child_scene_layer.cc +++ b/engine/src/flutter/flow/layers/child_scene_layer.cc @@ -9,9 +9,9 @@ namespace flow { -ChildSceneLayer::ChildSceneLayer() : device_pixel_ratio_(1.0f) {} +ChildSceneLayer::ChildSceneLayer() = default; -ChildSceneLayer::~ChildSceneLayer() {} +ChildSceneLayer::~ChildSceneLayer() = default; void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { set_needs_system_composite(true); @@ -20,10 +20,10 @@ void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { float inverse_device_pixel_ratio = 1.f / device_pixel_ratio_; transform_.preScale(inverse_device_pixel_ratio, inverse_device_pixel_ratio); - SkRect bounds = SkRect::MakeXYWH( - offset_.x(), offset_.y(), - physical_size_.width() * inverse_device_pixel_ratio, - physical_size_.height() * inverse_device_pixel_ratio); + SkRect bounds = + SkRect::MakeXYWH(offset_.x(), offset_.y(), + physical_size_.width() * inverse_device_pixel_ratio, + physical_size_.height() * inverse_device_pixel_ratio); set_paint_bounds(bounds); context->child_paint_bounds = bounds; } @@ -42,6 +42,10 @@ void ChildSceneLayer::UpdateScene(SceneUpdateContext& context, resource->get_scene()->scene_token->value = scene_token_; auto node = mozart::Node::New(); + if (!hittable_) { + node->hit_test_behavior = mozart::HitTestBehavior::New(); + node->hit_test_behavior->prune = true; + } node->op = mozart::NodeOp::New(); node->op->set_scene(mozart::SceneNodeOp::New()); node->op->get_scene()->scene_resource_id = diff --git a/engine/src/flutter/flow/layers/child_scene_layer.h b/engine/src/flutter/flow/layers/child_scene_layer.h index ffd18b2a0e..917707c25b 100644 --- a/engine/src/flutter/flow/layers/child_scene_layer.h +++ b/engine/src/flutter/flow/layers/child_scene_layer.h @@ -27,6 +27,8 @@ class ChildSceneLayer : public Layer { void set_scene_token(uint32_t scene_token) { scene_token_ = scene_token; } + void set_hittable(bool hittable) { hittable_ = hittable; } + void Preroll(PrerollContext* context, const SkMatrix& matrix) override; void Paint(PaintContext& context) override; void UpdateScene(SceneUpdateContext& context, @@ -34,9 +36,10 @@ class ChildSceneLayer : public Layer { private: SkPoint offset_; - float device_pixel_ratio_; + float device_pixel_ratio_ = 1.0; SkISize physical_size_; - uint32_t scene_token_; + uint32_t scene_token_ = 0; + bool hittable_ = true; SkMatrix transform_; FTL_DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer); diff --git a/engine/src/flutter/flow/scene_update_context.cc b/engine/src/flutter/flow/scene_update_context.cc index 06661e072a..9378389135 100644 --- a/engine/src/flutter/flow/scene_update_context.cc +++ b/engine/src/flutter/flow/scene_update_context.cc @@ -78,7 +78,6 @@ mozart::NodePtr SceneUpdateContext::FinalizeCurrentPaintTask( resource->get_image()->image = std::move(image); auto node = mozart::Node::New(); - node->hit_test_behavior = mozart::HitTestBehavior::New(); node->op = mozart::NodeOp::New(); node->op->set_image(mozart::ImageNodeOp::New()); node->op->get_image()->content_rect = mozart::RectF::From(bounds); diff --git a/engine/src/flutter/lib/ui/compositing.dart b/engine/src/flutter/lib/ui/compositing.dart index 207e4e6bc1..3fd96bfd8d 100644 --- a/engine/src/flutter/lib/ui/compositing.dart +++ b/engine/src/flutter/lib/ui/compositing.dart @@ -191,24 +191,29 @@ class SceneBuilder extends NativeFieldWrapperClass2 { /// Applications typically obtain scene tokens when embedding other views via /// the Fuchsia view manager, but this function is agnostic as to the source /// of scene token. - void addChildScene(Offset offset, - double devicePixelRatio, - int physicalWidth, - int physicalHeight, - int sceneToken) { + void addChildScene({ + Offset offset: Offset.zero, + double devicePixelRatio: 1.0, + int physicalWidth: 0, + int physicalHeight: 0, + int sceneToken, + bool hittable: true, + }) { _addChildScene(offset.dx, offset.dy, devicePixelRatio, physicalWidth, physicalHeight, - sceneToken); + sceneToken, + hittable); } void _addChildScene(double dx, double dy, double devicePixelRatio, int physicalWidth, int physicalHeight, - int sceneToken) native "SceneBuilder_addChildScene"; + int sceneToken, + bool hittable) native "SceneBuilder_addChildScene"; /// Sets a threshold after which additional debugging information should be recorded. /// diff --git a/engine/src/flutter/lib/ui/compositing/scene_builder.cc b/engine/src/flutter/lib/ui/compositing/scene_builder.cc index 817aa08444..a9309fcf56 100644 --- a/engine/src/flutter/lib/ui/compositing/scene_builder.cc +++ b/engine/src/flutter/lib/ui/compositing/scene_builder.cc @@ -203,7 +203,8 @@ void SceneBuilder::addChildScene(double dx, double devicePixelRatio, int physicalWidth, int physicalHeight, - uint32_t sceneToken) { + uint32_t sceneToken, + bool hittable) { #if defined(OS_FUCHSIA) if (!m_currentLayer) return; @@ -218,6 +219,7 @@ void SceneBuilder::addChildScene(double dx, layer->set_device_pixel_ratio(devicePixelRatio); layer->set_physical_size(SkISize::Make(physicalWidth, physicalHeight)); layer->set_scene_token(sceneToken); + layer->set_hittable(hittable); m_currentLayer->Add(std::move(layer)); #endif } diff --git a/engine/src/flutter/lib/ui/compositing/scene_builder.h b/engine/src/flutter/lib/ui/compositing/scene_builder.h index 3c42808b58..7129833d34 100644 --- a/engine/src/flutter/lib/ui/compositing/scene_builder.h +++ b/engine/src/flutter/lib/ui/compositing/scene_builder.h @@ -59,7 +59,8 @@ class SceneBuilder : public ftl::RefCountedThreadSafe, double devicePixelRatio, int physicalWidth, int physicalHeight, - uint32_t sceneToken); + uint32_t sceneToken, + bool hittable); void setRasterizerTracingThreshold(uint32_t frameInterval);