From 8ee1910ca9b20874022a7e931fdb9e7bb1baa62a Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Mon, 24 Jul 2017 19:17:55 -0700 Subject: [PATCH] Use metrics provided by scene events. (#3922) Compute the necessary texture resolution using more accurate scaling information provided by Mozart scene node metrics events instead of the device pixel ratio provided by the Mozart view properties (which we might remove in the future). This allows us to allocate smaller textures when a Flutter view is being scaled down. --- content_handler/rasterizer.h | 6 +- content_handler/runtime_holder.cc | 60 ++++++++++++++----- content_handler/runtime_holder.h | 1 + content_handler/session_connection.cc | 35 +++++++++-- content_handler/session_connection.h | 12 +++- content_handler/vulkan_rasterizer.cc | 18 ++++-- content_handler/vulkan_rasterizer.h | 5 +- flow/export_node.cc | 2 - flow/export_node.h | 1 - flow/layers/child_scene_layer.cc | 9 +-- flow/layers/child_scene_layer.h | 11 +--- flow/layers/layer_tree.cc | 9 ++- flow/layers/layer_tree.h | 8 +++ flow/layers/physical_model_layer.cc | 10 +--- flow/layers/physical_model_layer.h | 5 -- flow/scene_update_context.cc | 86 +++++++++++++++++---------- flow/scene_update_context.h | 40 ++++++++----- lib/ui/compositing.dart | 15 ++--- lib/ui/compositing/scene_builder.cc | 11 ++-- lib/ui/compositing/scene_builder.h | 5 +- 20 files changed, 216 insertions(+), 133 deletions(-) diff --git a/content_handler/rasterizer.h b/content_handler/rasterizer.h index aeb2687afc..0a913ea9ff 100644 --- a/content_handler/rasterizer.h +++ b/content_handler/rasterizer.h @@ -21,8 +21,10 @@ class Rasterizer { static std::unique_ptr Create(); - virtual void SetSession(fidl::InterfaceHandle session, - mx::eventpair import_token) = 0; + virtual void SetScene( + fidl::InterfaceHandle scene_manager, + mx::eventpair import_token, + ftl::Closure metrics_changed_callback) = 0; virtual void Draw(std::unique_ptr layer_tree, ftl::Closure callback) = 0; diff --git a/content_handler/runtime_holder.cc b/content_handler/runtime_holder.cc index ea30e7f6c5..37d68a43a4 100644 --- a/content_handler/runtime_holder.cc +++ b/content_handler/runtime_holder.cc @@ -206,20 +206,36 @@ void RuntimeHolder::CreateView( input_connection_->SetEventListener(std::move(input_listener)); // Setup the session. - mozart2::SessionPtr session; - mozart2::SceneManagerPtr scene_manager; + fidl::InterfaceHandle scene_manager; view_manager_->GetSceneManager(scene_manager.NewRequest()); - scene_manager->CreateSession(session.NewRequest(), - nullptr /* session listener */); + blink::Threads::Gpu()->PostTask(ftl::MakeCopyable([ - rasterizer = rasterizer_.get(), // - session = session.PassInterfaceHandle(), // - import_token = std::move(import_token) // + rasterizer = rasterizer_.get(), // + scene_manager = std::move(scene_manager), // + import_token = std::move(import_token), // + weak_runtime_holder = GetWeakPtr() ]() mutable { ASSERT_IS_GPU_THREAD; - rasterizer->SetSession(std::move(session), std::move(import_token)); + rasterizer->SetScene( + std::move(scene_manager), std::move(import_token), + // TODO(MZ-222): Ideally we would immediately redraw the previous layer + // tree when the metrics change since there's no need to rerecord it. + // However, we want to make sure there's only one outstanding frame. + // We should improve the frame scheduling so that the rasterizer thread + // can self-schedule re-rasterization. + [weak_runtime_holder] { + // This is on the GPU thread thread. Post to the Platform/UI + // thread for the completion callback. + ASSERT_IS_GPU_THREAD; + blink::Threads::Platform()->PostTask([weak_runtime_holder]() { + // On the Platform/UI thread. + ASSERT_IS_UI_THREAD; + if (weak_runtime_holder) { + weak_runtime_holder->OnRedrawFrame(); + } + }); + }); })); - runtime_ = blink::RuntimeController::Create(this); const uint8_t* isolate_snapshot_data; @@ -290,6 +306,7 @@ void RuntimeHolder::Render(std::unique_ptr layer_tree) { last_begin_frame_time_); layer_tree->set_frame_size(SkISize::Make(viewport_metrics_.physical_width, viewport_metrics_.physical_height)); + layer_tree->set_device_pixel_ratio(viewport_metrics_.device_pixel_ratio); // We are on the Platform/UI thread. Post to the GPU thread to render. ASSERT_IS_PLATFORM_THREAD; @@ -301,8 +318,8 @@ void RuntimeHolder::Render(std::unique_ptr layer_tree) { // On the GPU Thread. ASSERT_IS_GPU_THREAD; rasterizer->Draw(std::move(layer_tree), [weak_runtime_holder]() { - // This is on the GPU thread thread. Post to the Platform/UI thread for - // the completion callback. + // This is on the GPU thread thread. Post to the Platform/UI thread + // for the completion callback. ASSERT_IS_GPU_THREAD; blink::Threads::Platform()->PostTask([weak_runtime_holder]() { // On the Platform/UI thread. @@ -516,8 +533,8 @@ void RuntimeHolder::OnEvent(mozart::InputEventPtr event, pointer_data.change = GetChangeFromPointerEventPhase(pointer->phase); pointer_data.kind = GetKindFromPointerType(pointer->type); pointer_data.device = pointer->pointer_id; - pointer_data.physical_x = pointer->x; - pointer_data.physical_y = pointer->y; + pointer_data.physical_x = pointer->x * viewport_metrics_.device_pixel_ratio; + pointer_data.physical_y = pointer->y * viewport_metrics_.device_pixel_ratio; switch (pointer_data.change) { case blink::PointerData::Change::kDown: @@ -585,15 +602,21 @@ void RuntimeHolder::OnPropertiesChanged( FTL_DCHECK(properties); // Attempt to read the device pixel ratio. - float pixel_ratio = 1.0; + float pixel_ratio = 1.f; if (auto& metrics = properties->display_metrics) { pixel_ratio = metrics->device_pixel_ratio; } // Apply view property changes. if (auto& layout = properties->view_layout) { - viewport_metrics_.physical_width = layout->size->width; - viewport_metrics_.physical_height = layout->size->height; + viewport_metrics_.physical_width = layout->size->width * pixel_ratio; + viewport_metrics_.physical_height = layout->size->height * pixel_ratio; + viewport_metrics_.physical_padding_top = layout->inset->top * pixel_ratio; + viewport_metrics_.physical_padding_right = + layout->inset->right * pixel_ratio; + viewport_metrics_.physical_padding_bottom = + layout->inset->bottom * pixel_ratio; + viewport_metrics_.physical_padding_left = layout->inset->left * pixel_ratio; viewport_metrics_.device_pixel_ratio = pixel_ratio; runtime_->SetViewportMetrics(viewport_metrics_); } @@ -706,4 +729,9 @@ void RuntimeHolder::OnFrameComplete() { PostBeginFrame(); } +void RuntimeHolder::OnRedrawFrame() { + if (!frame_outstanding_) + ScheduleFrame(); +} + } // namespace flutter_runner diff --git a/content_handler/runtime_holder.h b/content_handler/runtime_holder.h index 1f650aa98d..e667af02b4 100644 --- a/content_handler/runtime_holder.h +++ b/content_handler/runtime_holder.h @@ -89,6 +89,7 @@ class RuntimeHolder : public blink::RuntimeDelegate, void PostBeginFrame(); void BeginFrame(); void OnFrameComplete(); + void OnRedrawFrame(); void Invalidate(); std::unique_ptr context_; diff --git a/content_handler/session_connection.cc b/content_handler/session_connection.cc index 915717aba8..6e647c79d1 100644 --- a/content_handler/session_connection.cc +++ b/content_handler/session_connection.cc @@ -7,17 +7,24 @@ namespace flutter_runner { -SessionConnection::SessionConnection( - fidl::InterfaceHandle session_handle, - mx::eventpair import_token) - : session_(mozart2::SessionPtr::Create(std::move(session_handle))), +SessionConnection::SessionConnection(mozart2::SceneManagerPtr scene_manager, + mx::eventpair import_token) + : session_(scene_manager.get()), root_node_(&session_), surface_producer_(std::make_unique(&session_)), scene_update_context_(&session_, surface_producer_.get()) { ASSERT_IS_GPU_THREAD; - root_node_.Bind(std::move(import_token)); + session_.set_connection_error_handler( std::bind(&SessionConnection::OnSessionError, this)); + session_.set_event_handler(std::bind(&SessionConnection::OnSessionEvents, + this, std::placeholders::_1, + std::placeholders::_2)); + + root_node_.Bind(std::move(import_token)); + root_node_.SetEventMask(mozart2::kMetricsEventMask); + session_.Present(0, [](mozart2::PresentationInfoPtr info) {}); + present_callback_ = std::bind(&SessionConnection::OnPresent, this, std::placeholders::_1); } @@ -32,6 +39,24 @@ void SessionConnection::OnSessionError() { FTL_CHECK(false) << "Session connection was terminated."; } +void SessionConnection::OnSessionEvents(uint64_t presentation_time, + fidl::Array events) { + mozart2::MetricsPtr new_metrics; + for (const auto& event : events) { + if (event->is_metrics() && + event->get_metrics()->node_id == root_node_.id()) { + new_metrics = std::move(event->get_metrics()->metrics); + } + } + if (!new_metrics) + return; + + scene_update_context_.set_metrics(std::move(new_metrics)); + + if (metrics_changed_callback_) + metrics_changed_callback_(); +} + void SessionConnection::Present(flow::CompositorContext::ScopedFrame& frame, ftl::Closure on_present_callback) { ASSERT_IS_GPU_THREAD; diff --git a/content_handler/session_connection.h b/content_handler/session_connection.h index 2b6ca38b3f..2bd191609f 100644 --- a/content_handler/session_connection.h +++ b/content_handler/session_connection.h @@ -12,6 +12,7 @@ #include "flutter/flow/compositor_context.h" #include "flutter/flow/scene_update_context.h" #include "lib/fidl/cpp/bindings/interface_handle.h" +#include "lib/ftl/functional/closure.h" #include "lib/ftl/macros.h" #include "magenta/system/ulib/mx/include/mx/eventpair.h" @@ -19,11 +20,17 @@ namespace flutter_runner { class SessionConnection { public: - SessionConnection(fidl::InterfaceHandle session_handle, + SessionConnection(mozart2::SceneManagerPtr scene_manager, mx::eventpair import_token); ~SessionConnection(); + bool has_metrics() const { return scene_update_context_.has_metrics(); } + + void set_metrics_changed_callback(ftl::Closure callback) { + metrics_changed_callback_ = std::move(callback); + } + flow::SceneUpdateContext& scene_update_context() { return scene_update_context_; } @@ -43,8 +50,11 @@ class SessionConnection { ftl::Closure pending_on_present_callback_; std::unique_ptr surface_producer_; flow::SceneUpdateContext scene_update_context_; + ftl::Closure metrics_changed_callback_; void OnSessionError(); + void OnSessionEvents(uint64_t presentation_time, + fidl::Array events); void EnqueueClearOps(); diff --git a/content_handler/vulkan_rasterizer.cc b/content_handler/vulkan_rasterizer.cc index a4ef81291b..ac7a9f8074 100644 --- a/content_handler/vulkan_rasterizer.cc +++ b/content_handler/vulkan_rasterizer.cc @@ -53,13 +53,17 @@ bool VulkanRasterizer::IsValid() const { return valid_; } -void VulkanRasterizer::SetSession( - fidl::InterfaceHandle session, - mx::eventpair import_token) { +void VulkanRasterizer::SetScene( + fidl::InterfaceHandle scene_manager, + mx::eventpair import_token, + ftl::Closure metrics_changed_callback) { ASSERT_IS_GPU_THREAD; FTL_DCHECK(valid_ && !session_connection_); session_connection_ = std::make_unique( - std::move(session), std::move(import_token)); + mozart2::SceneManagerPtr::Create(std::move(scene_manager)), + std::move(import_token)); + session_connection_->set_metrics_changed_callback( + std::move(metrics_changed_callback)); } void VulkanRasterizer::Draw(std::unique_ptr layer_tree, @@ -79,6 +83,12 @@ void VulkanRasterizer::Draw(std::unique_ptr layer_tree, return; } + if (!session_connection_->has_metrics()) { + // Still awaiting metrics. Will redraw when we get them. + callback(); + return; + } + compositor_context_.engine_time().SetLapTime(layer_tree->construction_time()); flow::CompositorContext::ScopedFrame frame = compositor_context_.AcquireFrame( diff --git a/content_handler/vulkan_rasterizer.h b/content_handler/vulkan_rasterizer.h index 9d0ddc0c68..768e0293db 100644 --- a/content_handler/vulkan_rasterizer.h +++ b/content_handler/vulkan_rasterizer.h @@ -22,8 +22,9 @@ class VulkanRasterizer : public Rasterizer { bool IsValid() const; - void SetSession(fidl::InterfaceHandle session, - mx::eventpair import_token) override; + void SetScene(fidl::InterfaceHandle scene_manager, + mx::eventpair import_token, + ftl::Closure metrics_changed_callback) override; void Draw(std::unique_ptr layer_tree, ftl::Closure callback) override; diff --git a/flow/export_node.cc b/flow/export_node.cc index be4a1cea1d..a5462ac3c0 100644 --- a/flow/export_node.cc +++ b/flow/export_node.cc @@ -17,7 +17,6 @@ ExportNode::~ExportNode() { void ExportNode::Bind(SceneUpdateContext& context, mozart::client::ContainerNode& container, const SkPoint& offset, - float scale, bool hit_testable) { ftl::MutexLocker lock(&mutex_); @@ -29,7 +28,6 @@ void ExportNode::Bind(SceneUpdateContext& context, if (node_) { container.AddChild(*node_); node_->SetTranslation(offset.x(), offset.y(), 0.f); - node_->SetScale(scale, scale, 1.f); node_->SetHitTestBehavior(hit_testable ? mozart2::HitTestBehavior::kDefault : mozart2::HitTestBehavior::kSuppress); diff --git a/flow/export_node.h b/flow/export_node.h index da46794188..7183e05ac3 100644 --- a/flow/export_node.h +++ b/flow/export_node.h @@ -34,7 +34,6 @@ class ExportNode : public ftl::RefCountedThreadSafe { void Bind(SceneUpdateContext& context, mozart::client::ContainerNode& container, const SkPoint& offset, - float scale, bool hit_testable); private: diff --git a/flow/layers/child_scene_layer.cc b/flow/layers/child_scene_layer.cc index b5f3d5dc12..b64875d76b 100644 --- a/flow/layers/child_scene_layer.cc +++ b/flow/layers/child_scene_layer.cc @@ -26,15 +26,8 @@ void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) { // or whether we should leave this up to the Flutter application to decide. // In some situations, it might be useful to allow children to draw // outside of their layout bounds. - // - // float inverse_device_pixel_ratio = 1.f / 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); if (export_node_) { - context.AddChildScene(export_node_.get(), offset_, device_pixel_ratio_, - hit_testable_); + context.AddChildScene(export_node_.get(), offset_, hit_testable_); } } diff --git a/flow/layers/child_scene_layer.h b/flow/layers/child_scene_layer.h index 9d66ad5b37..3ae15fa694 100644 --- a/flow/layers/child_scene_layer.h +++ b/flow/layers/child_scene_layer.h @@ -17,13 +17,7 @@ class ChildSceneLayer : public Layer { void set_offset(const SkPoint& offset) { offset_ = offset; } - void set_device_pixel_ratio(float device_pixel_ratio) { - device_pixel_ratio_ = device_pixel_ratio; - } - - void set_physical_size(const SkISize& physical_size) { - physical_size_ = physical_size; - } + void set_size(const SkSize& size) { size_ = size; } void set_export_node(ftl::RefPtr export_node) { export_node_ = std::move(export_node); @@ -39,8 +33,7 @@ class ChildSceneLayer : public Layer { private: SkPoint offset_; - float device_pixel_ratio_ = 1.0; - SkISize physical_size_; + SkSize size_; ftl::RefPtr export_node_; bool hit_testable_ = true; diff --git a/flow/layers/layer_tree.cc b/flow/layers/layer_tree.cc index 20dd342327..23716102ba 100644 --- a/flow/layers/layer_tree.cc +++ b/flow/layers/layer_tree.cc @@ -34,6 +34,7 @@ void LayerTree::Preroll(CompositorContext::ScopedFrame& frame, ignore_raster_cache ? nullptr : &frame.context().raster_cache(), frame.gr_context(), color_space, SkRect::MakeEmpty(), }; + root_layer_->Preroll(&context, SkMatrix::I()); } @@ -42,18 +43,20 @@ void LayerTree::UpdateScene(SceneUpdateContext& context, mozart::client::ContainerNode& container) { TRACE_EVENT0("flutter", "LayerTree::UpdateScene"); + SceneUpdateContext::Transform transform(context, 1.f / device_pixel_ratio_, + 1.f / device_pixel_ratio_, 1.f); SceneUpdateContext::Frame frame( context, SkRRect::MakeRect( - SkRect::MakeIWH(frame_size_.width(), frame_size_.height())), - SK_ColorTRANSPARENT, 0.f, 1.f, 1.f); + SkRect::MakeWH(frame_size_.width(), frame_size_.height())), + SK_ColorTRANSPARENT, 0.f); if (root_layer_->needs_system_composite()) { root_layer_->UpdateScene(context); } if (root_layer_->needs_painting()) { frame.AddPaintedLayer(root_layer_.get()); } - container.AddChild(frame.entity_node()); + container.AddChild(transform.entity_node()); } #endif diff --git a/flow/layers/layer_tree.h b/flow/layers/layer_tree.h index 1b7e8fcaca..e85f8165e5 100644 --- a/flow/layers/layer_tree.h +++ b/flow/layers/layer_tree.h @@ -31,6 +31,10 @@ class LayerTree { bool ignore_raster_cache = false); #if defined(OS_FUCHSIA) + void set_device_pixel_ratio(float device_pixel_ratio) { + device_pixel_ratio_ = device_pixel_ratio; + } + void UpdateScene(SceneUpdateContext& context, mozart::client::ContainerNode& container); #endif @@ -80,6 +84,10 @@ class LayerTree { bool checkerboard_raster_cache_images_; bool checkerboard_offscreen_layers_; +#if defined(OS_FUCHSIA) + float device_pixel_ratio_ = 1.f; +#endif + FTL_DISALLOW_COPY_AND_ASSIGN(LayerTree); }; diff --git a/flow/layers/physical_model_layer.cc b/flow/layers/physical_model_layer.cc index 7d7f9102ab..9ac3a565da 100644 --- a/flow/layers/physical_model_layer.cc +++ b/flow/layers/physical_model_layer.cc @@ -34,13 +34,6 @@ void PhysicalModelLayer::Preroll(PrerollContext* context, set_paint_bounds(bounds); #endif // defined(OS_FUCHSIA) } - -#if defined(OS_FUCHSIA) - if (needs_system_composite()) { - scale_x_ = matrix.getScaleX(); - scale_y_ = matrix.getScaleY(); - } -#endif // defined(OS_FUCHSIA) } #if defined(OS_FUCHSIA) @@ -48,8 +41,7 @@ void PhysicalModelLayer::Preroll(PrerollContext* context, void PhysicalModelLayer::UpdateScene(SceneUpdateContext& context) { FTL_DCHECK(needs_system_composite()); - SceneUpdateContext::Frame frame(context, rrect_, color_, elevation_, scale_x_, - scale_y_); + SceneUpdateContext::Frame frame(context, rrect_, color_, elevation_); for (auto& layer : layers()) { if (layer->needs_painting()) { frame.AddPaintedLayer(layer.get()); diff --git a/flow/layers/physical_model_layer.h b/flow/layers/physical_model_layer.h index 1c15f444d2..2f14c89b97 100644 --- a/flow/layers/physical_model_layer.h +++ b/flow/layers/physical_model_layer.h @@ -38,11 +38,6 @@ class PhysicalModelLayer : public ContainerLayer { float elevation_; SkColor color_; SkScalar device_pixel_ratio_; - -#if defined(OS_FUCHSIA) - SkScalar scale_x_; - SkScalar scale_y_; -#endif // defined(OS_FUCHSIA) }; } // namespace flow diff --git a/flow/scene_update_context.cc b/flow/scene_update_context.cc index 822851227d..1a741e19ac 100644 --- a/flow/scene_update_context.cc +++ b/flow/scene_update_context.cc @@ -21,19 +21,15 @@ SceneUpdateContext::~SceneUpdateContext() = default; void SceneUpdateContext::AddChildScene(ExportNode* export_node, SkPoint offset, - float device_pixel_ratio, bool hit_testable) { FTL_DCHECK(top_entity_); - export_node->Bind(*this, top_entity_->entity_node(), offset, - 1.f / device_pixel_ratio, hit_testable); + export_node->Bind(*this, top_entity_->entity_node(), offset, hit_testable); } void SceneUpdateContext::CreateFrame(mozart::client::EntityNode& entity_node, const SkRRect& rrect, SkColor color, - SkScalar scale_x, - SkScalar scale_y, const SkRect& paint_bounds, std::vector paint_layers) { // Frames always clip their children. @@ -73,6 +69,10 @@ void SceneUpdateContext::CreateFrame(mozart::client::EntityNode& entity_node, return; } + // Apply current metrics and transformation scale factors. + const float scale_x = metrics_->scale_x * top_scale_x_; + const float scale_y = metrics_->scale_y * top_scale_y_; + // If the painted area only covers a portion of the frame then we can // reduce the texture size by drawing just that smaller area. SkRect inner_bounds = shape_bounds; @@ -223,47 +223,69 @@ SceneUpdateContext::Clip::~Clip() = default; SceneUpdateContext::Transform::Transform(SceneUpdateContext& context, const SkMatrix& transform) - : Entity(context) { - // TODO(MZ-192): The perspective and shear components in the matrix - // are not handled correctly. - MatrixDecomposition decomposition(transform); - if (decomposition.IsValid()) { - entity_node().SetTranslation(decomposition.translation().x(), // - decomposition.translation().y(), // - decomposition.translation().z() // - ); - entity_node().SetScale(decomposition.scale().x(), // - decomposition.scale().y(), // - decomposition.scale().z() // - ); - entity_node().SetRotation(decomposition.rotation().fData[0], // - decomposition.rotation().fData[1], // - decomposition.rotation().fData[2], // - decomposition.rotation().fData[3] // - ); + : Entity(context), + previous_scale_x_(context.top_scale_x_), + previous_scale_y_(context.top_scale_y_) { + if (!transform.isIdentity()) { + // TODO(MZ-192): The perspective and shear components in the matrix + // are not handled correctly. + MatrixDecomposition decomposition(transform); + if (decomposition.IsValid()) { + entity_node().SetTranslation(decomposition.translation().x(), // + decomposition.translation().y(), // + decomposition.translation().z() // + ); + + entity_node().SetScale(decomposition.scale().x(), // + decomposition.scale().y(), // + decomposition.scale().z() // + ); + context.top_scale_x_ *= decomposition.scale().x(); + context.top_scale_y_ *= decomposition.scale().y(); + + entity_node().SetRotation(decomposition.rotation().fData[0], // + decomposition.rotation().fData[1], // + decomposition.rotation().fData[2], // + decomposition.rotation().fData[3] // + ); + } + } +} + +SceneUpdateContext::Transform::Transform(SceneUpdateContext& context, + float scale_x, + float scale_y, + float scale_z) + : Entity(context), + previous_scale_x_(context.top_scale_x_), + previous_scale_y_(context.top_scale_y_) { + if (scale_x != 1.f || scale_y != 1.f || scale_z != 1.f) { + entity_node().SetScale(scale_x, scale_y, scale_z); + context.top_scale_x_ *= scale_x; + context.top_scale_y_ *= scale_y; } } -SceneUpdateContext::Transform::~Transform() = default; +SceneUpdateContext::Transform::~Transform() { + context().top_scale_x_ = previous_scale_x_; + context().top_scale_y_ = previous_scale_y_; +} SceneUpdateContext::Frame::Frame(SceneUpdateContext& context, const SkRRect& rrect, SkColor color, - float elevation, - SkScalar scale_x, - SkScalar scale_y) + float elevation) : Entity(context), rrect_(rrect), color_(color), - scale_x_(scale_x), - scale_y_(scale_y), paint_bounds_(SkRect::MakeEmpty()) { - entity_node().SetTranslation(0.f, 0.f, elevation); + if (elevation != 0.0) + entity_node().SetTranslation(0.f, 0.f, elevation); } SceneUpdateContext::Frame::~Frame() { - context().CreateFrame(entity_node(), rrect_, color_, scale_x_, scale_y_, - paint_bounds_, std::move(paint_layers_)); + context().CreateFrame(entity_node(), rrect_, color_, paint_bounds_, + std::move(paint_layers_)); } void SceneUpdateContext::Frame::AddPaintedLayer(Layer* layer) { diff --git a/flow/scene_update_context.h b/flow/scene_update_context.h index 539ceae29e..bfcd785409 100644 --- a/flow/scene_update_context.h +++ b/flow/scene_update_context.h @@ -52,13 +52,6 @@ class SceneUpdateContext { std::unique_ptr surface) = 0; }; - SceneUpdateContext(mozart::client::Session* session, - SurfaceProducer* surface_producer); - - ~SceneUpdateContext(); - - mozart::client::Session* session() { return session_; } - class Entity { public: Entity(SceneUpdateContext& context); @@ -85,7 +78,15 @@ class SceneUpdateContext { class Transform : public Entity { public: Transform(SceneUpdateContext& context, const SkMatrix& transform); + Transform(SceneUpdateContext& context, + float scale_x, + float scale_y, + float scale_z); ~Transform(); + + private: + float const previous_scale_x_; + float const previous_scale_y_; }; class Frame : public Entity { @@ -93,9 +94,7 @@ class SceneUpdateContext { Frame(SceneUpdateContext& context, const SkRRect& rrect, SkColor color, - float elevation, - SkScalar scale_x, - SkScalar scale_y); + float elevation); ~Frame(); void AddPaintedLayer(Layer* layer); @@ -103,16 +102,25 @@ class SceneUpdateContext { private: const SkRRect& rrect_; SkColor const color_; - SkScalar const scale_x_; - SkScalar const scale_y_; std::vector paint_layers_; SkRect paint_bounds_; }; + SceneUpdateContext(mozart::client::Session* session, + SurfaceProducer* surface_producer); + + ~SceneUpdateContext(); + + mozart::client::Session* session() { return session_; } + + bool has_metrics() const { return !!metrics_; } + void set_metrics(mozart2::MetricsPtr metrics) { + metrics_ = std::move(metrics); + } + void AddChildScene(ExportNode* export_node, SkPoint offset, - float device_pixel_ratio, bool hit_testable); // TODO(chinmaygarde): This method must submit the surfaces as soon as paint @@ -139,8 +147,6 @@ class SceneUpdateContext { void CreateFrame(mozart::client::EntityNode& entity_node, const SkRRect& rrect, SkColor color, - SkScalar scale_x, - SkScalar scale_y, const SkRect& paint_bounds, std::vector paint_layers); void SetShapeTextureOrColor(mozart::client::ShapeNode& shape_node, @@ -158,10 +164,14 @@ class SceneUpdateContext { std::vector paint_layers); Entity* top_entity_ = nullptr; + float top_scale_x_ = 1.f; + float top_scale_y_ = 1.f; mozart::client::Session* const session_; SurfaceProducer* const surface_producer_; + mozart2::MetricsPtr metrics_; + std::vector paint_tasks_; FTL_DISALLOW_COPY_AND_ASSIGN(SceneUpdateContext); diff --git a/lib/ui/compositing.dart b/lib/ui/compositing.dart index b97c12d08a..fef66bcb9f 100644 --- a/lib/ui/compositing.dart +++ b/lib/ui/compositing.dart @@ -201,25 +201,22 @@ class SceneBuilder extends NativeFieldWrapperClass2 { /// for this application. void addChildScene({ Offset offset: Offset.zero, - double devicePixelRatio: 1.0, - int physicalWidth: 0, - int physicalHeight: 0, + double width: 0.0, + double height: 0.0, SceneHost sceneHost, bool hitTestable: true }) { _addChildScene(offset.dx, offset.dy, - devicePixelRatio, - physicalWidth, - physicalHeight, + width, + height, sceneHost, hitTestable); } void _addChildScene(double dx, double dy, - double devicePixelRatio, - int physicalWidth, - int physicalHeight, + double width, + double height, SceneHost sceneHost, bool hitTestable) native "SceneBuilder_addChildScene"; diff --git a/lib/ui/compositing/scene_builder.cc b/lib/ui/compositing/scene_builder.cc index cb8b158e26..b5961c8bfa 100644 --- a/lib/ui/compositing/scene_builder.cc +++ b/lib/ui/compositing/scene_builder.cc @@ -224,24 +224,21 @@ void SceneBuilder::addPicture(double dx, void SceneBuilder::addChildScene(double dx, double dy, - double devicePixelRatio, - int physicalWidth, - int physicalHeight, + double width, + double height, SceneHost* sceneHost, bool hitTestable) { #if defined(OS_FUCHSIA) if (!m_currentLayer) return; - SkRect sceneRect = SkRect::MakeXYWH(dx, dy, physicalWidth / devicePixelRatio, - physicalHeight / devicePixelRatio); + SkRect sceneRect = SkRect::MakeXYWH(dx, dy, width, height); if (!SkRect::Intersects(sceneRect, m_cullRects.top())) return; std::unique_ptr layer(new flow::ChildSceneLayer()); layer->set_offset(SkPoint::Make(dx, dy)); - layer->set_device_pixel_ratio(devicePixelRatio); - layer->set_physical_size(SkISize::Make(physicalWidth, physicalHeight)); + layer->set_size(SkSize::Make(width, height)); layer->set_export_node(sceneHost->exportNode()); layer->set_hit_testable(hitTestable); m_currentLayer->Add(std::move(layer)); diff --git a/lib/ui/compositing/scene_builder.h b/lib/ui/compositing/scene_builder.h index 95d43b8087..43008d41f3 100644 --- a/lib/ui/compositing/scene_builder.h +++ b/lib/ui/compositing/scene_builder.h @@ -59,9 +59,8 @@ class SceneBuilder : public ftl::RefCountedThreadSafe, void addPicture(double dx, double dy, Picture* picture, int hints); void addChildScene(double dx, double dy, - double devicePixelRatio, - int physicalWidth, - int physicalHeight, + double width, + double height, SceneHost* sceneHost, bool hitTestable); -- GitLab