From d5be7dccbc0c1bc229cc4287679d652e20484e39 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Mon, 6 Jun 2022 17:28:04 -0400 Subject: [PATCH] transform bounds to device space before sending to vmservice (flutter/engine#33853) --- engine/src/flutter/flow/layer_snapshot_store.cc | 2 +- engine/src/flutter/flow/layer_snapshot_store.h | 6 +++--- engine/src/flutter/flow/layers/display_list_layer.cc | 9 +++++++-- engine/src/flutter/shell/common/shell.cc | 10 +++++----- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/flow/layer_snapshot_store.cc b/engine/src/flutter/flow/layer_snapshot_store.cc index 00f0ed94637..7e3cc8e6f84 100644 --- a/engine/src/flutter/flow/layer_snapshot_store.cc +++ b/engine/src/flutter/flow/layer_snapshot_store.cc @@ -12,7 +12,7 @@ namespace flutter { LayerSnapshotData::LayerSnapshotData(int64_t layer_unique_id, const fml::TimeDelta& duration, const sk_sp& snapshot, - const SkRect& bounds) + const SkIRect& bounds) : layer_unique_id_(layer_unique_id), duration_(duration), snapshot_(snapshot), diff --git a/engine/src/flutter/flow/layer_snapshot_store.h b/engine/src/flutter/flow/layer_snapshot_store.h index eb444d2dcc3..fd255b5186d 100644 --- a/engine/src/flutter/flow/layer_snapshot_store.h +++ b/engine/src/flutter/flow/layer_snapshot_store.h @@ -26,7 +26,7 @@ class LayerSnapshotData { LayerSnapshotData(int64_t layer_unique_id, const fml::TimeDelta& duration, const sk_sp& snapshot, - const SkRect& bounds); + const SkIRect& bounds); ~LayerSnapshotData() = default; @@ -36,13 +36,13 @@ class LayerSnapshotData { sk_sp GetSnapshot() const { return snapshot_; } - SkRect GetBounds() const { return bounds_; } + SkIRect GetBounds() const { return bounds_; } private: const int64_t layer_unique_id_; const fml::TimeDelta duration_; const sk_sp snapshot_; - const SkRect bounds_; + const SkIRect bounds_; }; /// Collects snapshots of layers during frame rasterization. diff --git a/engine/src/flutter/flow/layers/display_list_layer.cc b/engine/src/flutter/flow/layers/display_list_layer.cc index b5d58d06d70..5c02735da54 100644 --- a/engine/src/flutter/flow/layers/display_list_layer.cc +++ b/engine/src/flutter/flow/layers/display_list_layer.cc @@ -8,6 +8,7 @@ #include "flutter/display_list/display_list_flags.h" #include "flutter/flow/layer_snapshot_store.h" #include "flutter/flow/layers/offscreen_surface.h" +#include "flutter/flow/raster_cache.h" namespace flutter { @@ -139,22 +140,26 @@ void DisplayListLayer::Paint(PaintContext& context) const { auto offscreen_surface = std::make_unique(context.gr_context, canvas_size); + const auto& ctm = context.leaf_nodes_canvas->getTotalMatrix(); + const auto start_time = fml::TimePoint::Now(); { // render display list to offscreen surface. auto* canvas = offscreen_surface->GetCanvas(); SkAutoCanvasRestore save(canvas, true); canvas->clear(SK_ColorTRANSPARENT); - canvas->setMatrix(context.leaf_nodes_canvas->getTotalMatrix()); + canvas->setMatrix(ctm); display_list()->RenderTo(canvas, context.inherited_opacity); canvas->flush(); } const fml::TimeDelta offscreen_render_time = fml::TimePoint::Now() - start_time; + const SkIRect device_bounds = + RasterCache::GetDeviceBounds(paint_bounds(), ctm); sk_sp raster_data = offscreen_surface->GetRasterData(true); LayerSnapshotData snapshot_data(unique_id(), offscreen_render_time, - raster_data, paint_bounds()); + raster_data, device_bounds); context.layer_snapshot_store->Add(snapshot_data); } diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index 05c608fd96d..faa84613a7e 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -1819,11 +1819,11 @@ static rapidjson::Value SerializeLayerSnapshot( result.AddMember("duration_micros", snapshot.GetDuration().ToMicroseconds(), allocator); - const SkRect bounds = snapshot.GetBounds(); - result.AddMember("top", bounds.top() * device_pixel_ratio, allocator); - result.AddMember("left", bounds.left() * device_pixel_ratio, allocator); - result.AddMember("width", bounds.width() * device_pixel_ratio, allocator); - result.AddMember("height", bounds.height() * device_pixel_ratio, allocator); + const SkIRect bounds = snapshot.GetBounds(); + result.AddMember("top", bounds.top(), allocator); + result.AddMember("left", bounds.left(), allocator); + result.AddMember("width", bounds.width(), allocator); + result.AddMember("height", bounds.height(), allocator); sk_sp snapshot_bytes = snapshot.GetSnapshot(); if (snapshot_bytes) {