Layer snapshots also contain bounds information (flutter/engine#33615)

This commit is contained in:
Kaushik Iska
2022-05-25 14:43:04 -04:00
committed by GitHub
parent 97bbedec8c
commit 796e65f687
4 changed files with 30 additions and 14 deletions

View File

@@ -10,20 +10,20 @@
namespace flutter {
LayerSnapshotData::LayerSnapshotData(int64_t layer_unique_id,
fml::TimeDelta duration,
sk_sp<SkData> snapshot)
const fml::TimeDelta& duration,
const sk_sp<SkData>& snapshot,
const SkRect& bounds)
: layer_unique_id_(layer_unique_id),
duration_(duration),
snapshot_(snapshot) {}
snapshot_(snapshot),
bounds_(bounds) {}
void LayerSnapshotStore::Clear() {
layer_snapshots_.clear();
}
void LayerSnapshotStore::Add(int64_t layer_unique_id,
fml::TimeDelta duration,
sk_sp<SkData> snapshot) {
layer_snapshots_.emplace_back(layer_unique_id, duration, snapshot);
void LayerSnapshotStore::Add(const LayerSnapshotData& data) {
layer_snapshots_.push_back(data);
}
} // namespace flutter

View File

@@ -24,8 +24,9 @@ namespace flutter {
class LayerSnapshotData {
public:
LayerSnapshotData(int64_t layer_unique_id,
fml::TimeDelta duration,
sk_sp<SkData> snapshot);
const fml::TimeDelta& duration,
const sk_sp<SkData>& snapshot,
const SkRect& bounds);
~LayerSnapshotData() = default;
@@ -35,10 +36,13 @@ class LayerSnapshotData {
sk_sp<SkData> GetSnapshot() const { return snapshot_; }
SkRect GetBounds() const { return bounds_; }
private:
const int64_t layer_unique_id_;
const fml::TimeDelta duration_;
const sk_sp<SkData> snapshot_;
const SkRect bounds_;
};
/// Collects snapshots of layers during frame rasterization.
@@ -55,9 +59,7 @@ class LayerSnapshotStore {
/// Adds snapshots for a given layer. `duration` marks the time taken to
/// rasterize this one layer.
void Add(int64_t layer_unique_id,
fml::TimeDelta duration,
sk_sp<SkData> base64_png_snapshot);
void Add(const LayerSnapshotData& data);
// Returns the number of snapshots collected.
size_t Size() const { return layer_snapshots_.size(); }

View File

@@ -6,6 +6,7 @@
#include "flutter/display_list/display_list_builder.h"
#include "flutter/display_list/display_list_flags.h"
#include "flutter/flow/layer_snapshot_store.h"
#include "flutter/flow/layers/offscreen_surface.h"
namespace flutter {
@@ -152,8 +153,9 @@ void DisplayListLayer::Paint(PaintContext& context) const {
fml::TimePoint::Now() - start_time;
sk_sp<SkData> raster_data = offscreen_surface->GetRasterData(true);
context.layer_snapshot_store->Add(unique_id(), offscreen_render_time,
raster_data);
LayerSnapshotData snapshot_data(unique_id(), offscreen_render_time,
raster_data, paint_bounds());
context.layer_snapshot_store->Add(snapshot_data);
}
if (context.leaf_nodes_builder) {

View File

@@ -1820,6 +1820,13 @@ static rapidjson::Value SerializeLayerSnapshot(
result.AddMember("layer_unique_id", snapshot.GetLayerUniqueId(), allocator);
result.AddMember("duration_micros", snapshot.GetDuration().ToMicroseconds(),
allocator);
const SkRect 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<SkData> snapshot_bytes = snapshot.GetSnapshot();
if (snapshot_bytes) {
rapidjson::Value image;
@@ -1867,6 +1874,11 @@ bool Shell::OnServiceProtocolRenderFrameWithRasterStats(
}
response->AddMember("snapshots", snapshots, allocator);
const auto& frame_size = last_layer_tree->frame_size();
response->AddMember("frame_width", frame_size.width(), allocator);
response->AddMember("frame_height", frame_size.height(), allocator);
return true;
} else {
const char* error =