forked from firka/flutter
[engine] remove raster stats feature. (flutter/engine#54187)
This debugging tool does not give accurate measurements and we've decided to remove it. See also: https://github.com/flutter/flutter/issues/131941
This commit is contained in:
@@ -41667,8 +41667,6 @@ ORIGIN: ../../../flutter/flow/flow_test_utils.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/flow/flow_test_utils.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/flow/frame_timings.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/flow/frame_timings.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/flow/layer_snapshot_store.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/flow/layer_snapshot_store.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/flow/layers/backdrop_filter_layer.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/flow/layers/backdrop_filter_layer.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/flow/layers/cacheable_layer.cc + ../../../flutter/LICENSE
|
||||
@@ -44551,8 +44549,6 @@ FILE: ../../../flutter/flow/flow_test_utils.cc
|
||||
FILE: ../../../flutter/flow/flow_test_utils.h
|
||||
FILE: ../../../flutter/flow/frame_timings.cc
|
||||
FILE: ../../../flutter/flow/frame_timings.h
|
||||
FILE: ../../../flutter/flow/layer_snapshot_store.cc
|
||||
FILE: ../../../flutter/flow/layer_snapshot_store.h
|
||||
FILE: ../../../flutter/flow/layers/backdrop_filter_layer.cc
|
||||
FILE: ../../../flutter/flow/layers/backdrop_filter_layer.h
|
||||
FILE: ../../../flutter/flow/layers/cacheable_layer.cc
|
||||
|
||||
@@ -21,8 +21,6 @@ source_set("flow") {
|
||||
"embedded_views.h",
|
||||
"frame_timings.cc",
|
||||
"frame_timings.h",
|
||||
"layer_snapshot_store.cc",
|
||||
"layer_snapshot_store.h",
|
||||
"layers/backdrop_filter_layer.cc",
|
||||
"layers/backdrop_filter_layer.h",
|
||||
"layers/cacheable_layer.cc",
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "flutter/common/macros.h"
|
||||
#include "flutter/flow/diff_context.h"
|
||||
#include "flutter/flow/embedded_views.h"
|
||||
#include "flutter/flow/layer_snapshot_store.h"
|
||||
#include "flutter/flow/raster_cache.h"
|
||||
#include "flutter/flow/stopwatch.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
@@ -195,14 +194,11 @@ class CompositorContext {
|
||||
|
||||
Stopwatch& ui_time() { return ui_time_; }
|
||||
|
||||
LayerSnapshotStore& snapshot_store() { return layer_snapshot_store_; }
|
||||
|
||||
private:
|
||||
NOT_SLIMPELLER(RasterCache raster_cache_);
|
||||
std::shared_ptr<TextureRegistry> texture_registry_;
|
||||
Stopwatch raster_time_;
|
||||
Stopwatch ui_time_;
|
||||
LayerSnapshotStore layer_snapshot_store_;
|
||||
|
||||
/// Only used by default constructor of `CompositorContext`.
|
||||
FixedRefreshRateUpdater fixed_refresh_rate_updater_;
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/flow/layer_snapshot_store.h"
|
||||
|
||||
#include "flutter/fml/time/time_delta.h"
|
||||
#include "flutter/fml/time/time_point.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
LayerSnapshotData::LayerSnapshotData(int64_t layer_unique_id,
|
||||
const fml::TimeDelta& duration,
|
||||
const sk_sp<SkData>& snapshot,
|
||||
const SkRect& bounds)
|
||||
: layer_unique_id_(layer_unique_id),
|
||||
duration_(duration),
|
||||
snapshot_(snapshot),
|
||||
bounds_(bounds) {}
|
||||
|
||||
void LayerSnapshotStore::Clear() {
|
||||
layer_snapshots_.clear();
|
||||
}
|
||||
|
||||
void LayerSnapshotStore::Add(const LayerSnapshotData& data) {
|
||||
layer_snapshots_.push_back(data);
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
@@ -1,76 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_FLOW_LAYER_SNAPSHOT_STORE_H_
|
||||
#define FLUTTER_FLOW_LAYER_SNAPSHOT_STORE_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/time/time_delta.h"
|
||||
|
||||
#include "third_party/skia/include/core/SkData.h"
|
||||
#include "third_party/skia/include/core/SkRect.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
/// Container for snapshot data pertaining to a given layer. A layer is
|
||||
/// identified by it's unique id.
|
||||
class LayerSnapshotData {
|
||||
public:
|
||||
LayerSnapshotData(int64_t layer_unique_id,
|
||||
const fml::TimeDelta& duration,
|
||||
const sk_sp<SkData>& snapshot,
|
||||
const SkRect& bounds);
|
||||
|
||||
~LayerSnapshotData() = default;
|
||||
|
||||
int64_t GetLayerUniqueId() const { return layer_unique_id_; }
|
||||
|
||||
fml::TimeDelta GetDuration() const { return duration_; }
|
||||
|
||||
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.
|
||||
class LayerSnapshotStore {
|
||||
public:
|
||||
typedef std::vector<LayerSnapshotData> Snapshots;
|
||||
|
||||
LayerSnapshotStore() = default;
|
||||
|
||||
~LayerSnapshotStore() = default;
|
||||
|
||||
/// Clears all the stored snapshots.
|
||||
void Clear();
|
||||
|
||||
/// Adds snapshots for a given layer. `duration` marks the time taken to
|
||||
/// rasterize this one layer.
|
||||
void Add(const LayerSnapshotData& data);
|
||||
|
||||
// Returns the number of snapshots collected.
|
||||
size_t Size() const { return layer_snapshots_.size(); }
|
||||
|
||||
// make this class iterable
|
||||
Snapshots::iterator begin() { return layer_snapshots_.begin(); }
|
||||
Snapshots::iterator end() { return layer_snapshots_.end(); }
|
||||
|
||||
private:
|
||||
Snapshots layer_snapshots_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(LayerSnapshotStore);
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_FLOW_LAYER_SNAPSHOT_STORE_H_
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/display_list/dl_builder.h"
|
||||
#include "flutter/flow/layer_snapshot_store.h"
|
||||
#include "flutter/flow/layers/cacheable_layer.h"
|
||||
#include "flutter/flow/layers/offscreen_surface.h"
|
||||
#include "flutter/flow/raster_cache.h"
|
||||
@@ -132,40 +131,6 @@ void DisplayListLayer::Paint(PaintContext& context) const {
|
||||
#endif // !SLIMPELLER
|
||||
|
||||
SkScalar opacity = context.state_stack.outstanding_opacity();
|
||||
|
||||
#if !SLIMPELLER
|
||||
// Leaf layer tracing was never supported in the Impeller backend.
|
||||
if (context.enable_leaf_layer_tracing) {
|
||||
const auto canvas_size = context.canvas->GetBaseLayerSize();
|
||||
auto offscreen_surface =
|
||||
std::make_unique<OffscreenSurface>(context.gr_context, canvas_size);
|
||||
|
||||
const auto& ctm = context.canvas->GetTransform();
|
||||
|
||||
const auto start_time = fml::TimePoint::Now();
|
||||
{
|
||||
// render display list to offscreen surface.
|
||||
auto* canvas = offscreen_surface->GetCanvas();
|
||||
{
|
||||
DlAutoCanvasRestore save(canvas, true);
|
||||
canvas->Clear(DlColor::kTransparent());
|
||||
canvas->SetTransform(ctm);
|
||||
canvas->DrawDisplayList(display_list_, opacity);
|
||||
}
|
||||
canvas->Flush();
|
||||
}
|
||||
const fml::TimeDelta offscreen_render_time =
|
||||
fml::TimePoint::Now() - start_time;
|
||||
|
||||
const SkRect device_bounds =
|
||||
RasterCacheUtil::GetDeviceBounds(paint_bounds(), ctm);
|
||||
sk_sp<SkData> raster_data = offscreen_surface->GetRasterData(true);
|
||||
LayerSnapshotData snapshot_data(unique_id(), offscreen_render_time,
|
||||
raster_data, device_bounds);
|
||||
context.layer_snapshot_store->Add(snapshot_data);
|
||||
}
|
||||
#endif // !SLIMPELLER
|
||||
|
||||
context.canvas->DrawDisplayList(display_list_, opacity);
|
||||
}
|
||||
|
||||
|
||||
@@ -439,41 +439,6 @@ TEST_F(DisplayListLayerDiffTest, DisplayListCompare) {
|
||||
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(20, 20, 70, 70));
|
||||
}
|
||||
|
||||
TEST_F(DisplayListLayerTest, LayerTreeSnapshotsWhenEnabled) {
|
||||
const SkPoint layer_offset = SkPoint::Make(1.5f, -0.5f);
|
||||
const SkRect picture_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f);
|
||||
DisplayListBuilder builder;
|
||||
builder.DrawRect(picture_bounds, DlPaint());
|
||||
auto display_list = builder.Build();
|
||||
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
|
||||
false, false);
|
||||
|
||||
layer->Preroll(preroll_context());
|
||||
|
||||
enable_leaf_layer_tracing();
|
||||
layer->Paint(paint_context());
|
||||
disable_leaf_layer_tracing();
|
||||
|
||||
auto& snapshot_store = layer_snapshot_store();
|
||||
EXPECT_EQ(1u, snapshot_store.Size());
|
||||
}
|
||||
|
||||
TEST_F(DisplayListLayerTest, NoLayerTreeSnapshotsWhenDisabledByDefault) {
|
||||
const SkPoint layer_offset = SkPoint::Make(1.5f, -0.5f);
|
||||
const SkRect picture_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f);
|
||||
DisplayListBuilder builder;
|
||||
builder.DrawRect(picture_bounds, DlPaint());
|
||||
auto display_list = builder.Build();
|
||||
auto layer = std::make_shared<DisplayListLayer>(layer_offset, display_list,
|
||||
false, false);
|
||||
|
||||
layer->Preroll(preroll_context());
|
||||
layer->Paint(paint_context());
|
||||
|
||||
auto& snapshot_store = layer_snapshot_store();
|
||||
EXPECT_EQ(0u, snapshot_store.Size());
|
||||
}
|
||||
|
||||
TEST_F(DisplayListLayerTest, DisplayListAccessCountDependsOnVisibility) {
|
||||
const SkPoint layer_offset = SkPoint::Make(1.5f, -0.5f);
|
||||
const SkRect picture_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "flutter/display_list/dl_canvas.h"
|
||||
#include "flutter/flow/diff_context.h"
|
||||
#include "flutter/flow/embedded_views.h"
|
||||
#include "flutter/flow/layer_snapshot_store.h"
|
||||
#include "flutter/flow/layers/layer_state_stack.h"
|
||||
#include "flutter/flow/raster_cache.h"
|
||||
#include "flutter/flow/stopwatch.h"
|
||||
@@ -114,10 +113,6 @@ struct PaintContext {
|
||||
std::shared_ptr<TextureRegistry> texture_registry;
|
||||
NOT_SLIMPELLER(const RasterCache* raster_cache);
|
||||
|
||||
// Snapshot store to collect leaf layer snapshots. The store is non-null
|
||||
// only when leaf layer tracing is enabled.
|
||||
LayerSnapshotStore* layer_snapshot_store = nullptr;
|
||||
bool enable_leaf_layer_tracing = false;
|
||||
bool impeller_enabled = false;
|
||||
impeller::AiksContext* aiks_context;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "flutter/display_list/skia/dl_sk_canvas.h"
|
||||
#include "flutter/flow/embedded_views.h"
|
||||
#include "flutter/flow/frame_timings.h"
|
||||
#include "flutter/flow/layer_snapshot_store.h"
|
||||
#include "flutter/flow/layers/layer.h"
|
||||
#include "flutter/flow/paint_utils.h"
|
||||
#include "flutter/flow/raster_cache.h"
|
||||
@@ -108,13 +107,6 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
|
||||
DlCanvas* canvas = frame.canvas();
|
||||
state_stack.set_delegate(canvas);
|
||||
|
||||
// clear the previous snapshots.
|
||||
LayerSnapshotStore* snapshot_store = nullptr;
|
||||
if (enable_leaf_layer_tracing_) {
|
||||
frame.context().snapshot_store().Clear();
|
||||
snapshot_store = &frame.context().snapshot_store();
|
||||
}
|
||||
|
||||
SkColorSpace* color_space = GetColorSpace(frame.canvas());
|
||||
|
||||
#if !SLIMPELLER
|
||||
@@ -135,8 +127,6 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
|
||||
#if !SLIMPELLER
|
||||
.raster_cache = cache,
|
||||
#endif // !SLIMPELLER
|
||||
.layer_snapshot_store = snapshot_store,
|
||||
.enable_leaf_layer_tracing = enable_leaf_layer_tracing_,
|
||||
.impeller_enabled = !!frame.aiks_context(),
|
||||
.aiks_context = frame.aiks_context(),
|
||||
// clang-format on
|
||||
@@ -198,8 +188,6 @@ sk_sp<DisplayList> LayerTree::Flatten(
|
||||
#if !SLIMPELLER
|
||||
.raster_cache = nullptr,
|
||||
#endif // !SLIMPELLER
|
||||
.layer_snapshot_store = nullptr,
|
||||
.enable_leaf_layer_tracing = false,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
|
||||
@@ -56,24 +56,9 @@ class LayerTree {
|
||||
const PaintRegionMap& paint_region_map() const { return paint_region_map_; }
|
||||
PaintRegionMap& paint_region_map() { return paint_region_map_; }
|
||||
|
||||
/// When `Paint` is called, if leaf layer tracing is enabled, additional
|
||||
/// metadata around rasterization of leaf layers is collected.
|
||||
///
|
||||
/// This is not supported in the Impeller backend.
|
||||
///
|
||||
/// See: `LayerSnapshotStore`
|
||||
void enable_leaf_layer_tracing(bool enable) {
|
||||
enable_leaf_layer_tracing_ = enable;
|
||||
}
|
||||
|
||||
bool is_leaf_layer_tracing_enabled() const {
|
||||
return enable_leaf_layer_tracing_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Layer> root_layer_;
|
||||
SkISize frame_size_ = SkISize::MakeEmpty(); // Physical pixels.
|
||||
bool enable_leaf_layer_tracing_ = false;
|
||||
|
||||
PaintRegionMap paint_region_map_;
|
||||
|
||||
|
||||
@@ -250,9 +250,6 @@ TEST_F(LayerTreeTest, PaintContextInitialization) {
|
||||
EXPECT_EQ(&context.ui_time, &mock_ui_time);
|
||||
EXPECT_EQ(context.texture_registry.get(), mock_registry.get());
|
||||
EXPECT_EQ(context.raster_cache, nullptr);
|
||||
|
||||
EXPECT_EQ(context.enable_leaf_layer_tracing, false);
|
||||
EXPECT_EQ(context.layer_snapshot_store, nullptr);
|
||||
};
|
||||
|
||||
// These 4 initializers are required because they are handled by reference
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define FLUTTER_FLOW_TESTING_LAYER_TEST_H_
|
||||
|
||||
#include "display_list/dl_color.h"
|
||||
#include "flutter/flow/layer_snapshot_store.h"
|
||||
#include "flutter/flow/layers/layer.h"
|
||||
|
||||
#include <optional>
|
||||
@@ -153,7 +152,6 @@ class LayerTestBase : public CanvasTestBase<BaseT> {
|
||||
PaintContext& display_list_paint_context() {
|
||||
return display_list_paint_context_;
|
||||
}
|
||||
LayerSnapshotStore& layer_snapshot_store() { return snapshot_store_; }
|
||||
|
||||
sk_sp<DisplayList> display_list() {
|
||||
if (display_list_ == nullptr) {
|
||||
@@ -170,16 +168,6 @@ class LayerTestBase : public CanvasTestBase<BaseT> {
|
||||
FML_DCHECK(display_list_state_stack_.is_empty());
|
||||
}
|
||||
|
||||
void enable_leaf_layer_tracing() {
|
||||
paint_context_.enable_leaf_layer_tracing = true;
|
||||
paint_context_.layer_snapshot_store = &snapshot_store_;
|
||||
}
|
||||
|
||||
void disable_leaf_layer_tracing() {
|
||||
paint_context_.enable_leaf_layer_tracing = false;
|
||||
paint_context_.layer_snapshot_store = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
void set_raster_cache_(std::unique_ptr<RasterCache> raster_cache) {
|
||||
raster_cache_ = std::move(raster_cache);
|
||||
@@ -201,7 +189,6 @@ class LayerTestBase : public CanvasTestBase<BaseT> {
|
||||
LayerStateStack display_list_state_stack_;
|
||||
sk_sp<DisplayList> display_list_;
|
||||
PaintContext display_list_paint_context_;
|
||||
LayerSnapshotStore snapshot_store_;
|
||||
|
||||
std::vector<RasterCacheItem*> cacheable_items_;
|
||||
|
||||
|
||||
@@ -37,9 +37,6 @@ const std::string_view ServiceProtocol::kGetSkSLsExtensionName =
|
||||
const std::string_view
|
||||
ServiceProtocol::kEstimateRasterCacheMemoryExtensionName =
|
||||
"_flutter.estimateRasterCacheMemory";
|
||||
const std::string_view
|
||||
ServiceProtocol::kRenderFrameWithRasterStatsExtensionName =
|
||||
"_flutter.renderFrameWithRasterStats";
|
||||
const std::string_view ServiceProtocol::kReloadAssetFonts =
|
||||
"_flutter.reloadAssetFonts";
|
||||
|
||||
@@ -61,7 +58,6 @@ ServiceProtocol::ServiceProtocol()
|
||||
kGetDisplayRefreshRateExtensionName,
|
||||
kGetSkSLsExtensionName,
|
||||
kEstimateRasterCacheMemoryExtensionName,
|
||||
kRenderFrameWithRasterStatsExtensionName,
|
||||
kReloadAssetFonts,
|
||||
}),
|
||||
handlers_mutex_(fml::SharedMutex::Create()) {}
|
||||
|
||||
@@ -29,7 +29,6 @@ class ServiceProtocol {
|
||||
static const std::string_view kGetDisplayRefreshRateExtensionName;
|
||||
static const std::string_view kGetSkSLsExtensionName;
|
||||
static const std::string_view kEstimateRasterCacheMemoryExtensionName;
|
||||
static const std::string_view kRenderFrameWithRasterStatsExtensionName;
|
||||
static const std::string_view kReloadAssetFonts;
|
||||
|
||||
class Handler {
|
||||
|
||||
@@ -742,8 +742,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe(
|
||||
std::unique_ptr<FrameDamage> damage;
|
||||
// when leaf layer tracing is enabled we wish to repaint the whole frame
|
||||
// for accurate performance metrics.
|
||||
if (frame->framebuffer_info().supports_partial_repaint &&
|
||||
!layer_tree.is_leaf_layer_tracing_enabled()) {
|
||||
if (frame->framebuffer_info().supports_partial_repaint) {
|
||||
// Disable partial repaint if external_view_embedder_ SubmitFlutterView is
|
||||
// involved - ExternalViewEmbedder unconditionally clears the entire
|
||||
// surface and also partial repaint with platform view present is
|
||||
@@ -764,8 +763,7 @@ DrawSurfaceStatus Rasterizer::DrawToSurfaceUnsafe(
|
||||
}
|
||||
|
||||
bool ignore_raster_cache = true;
|
||||
if (surface_->EnableRasterCache() &&
|
||||
!layer_tree.is_leaf_layer_tracing_enabled()) {
|
||||
if (surface_->EnableRasterCache()) {
|
||||
ignore_raster_cache = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -515,11 +515,6 @@ Shell::Shell(DartVMRef vm,
|
||||
task_runners_.GetRasterTaskRunner(),
|
||||
std::bind(&Shell::OnServiceProtocolEstimateRasterCacheMemory, this,
|
||||
std::placeholders::_1, std::placeholders::_2)};
|
||||
service_protocol_handlers_
|
||||
[ServiceProtocol::kRenderFrameWithRasterStatsExtensionName] = {
|
||||
task_runners_.GetRasterTaskRunner(),
|
||||
std::bind(&Shell::OnServiceProtocolRenderFrameWithRasterStats, this,
|
||||
std::placeholders::_1, std::placeholders::_2)};
|
||||
service_protocol_handlers_[ServiceProtocol::kReloadAssetFonts] = {
|
||||
task_runners_.GetPlatformTaskRunner(),
|
||||
std::bind(&Shell::OnServiceProtocolReloadAssetFonts, this,
|
||||
@@ -2007,101 +2002,6 @@ bool Shell::OnServiceProtocolSetAssetBundlePath(
|
||||
return false;
|
||||
}
|
||||
|
||||
static rapidjson::Value SerializeLayerSnapshot(
|
||||
double device_pixel_ratio,
|
||||
const LayerSnapshotData& snapshot,
|
||||
rapidjson::Document* response) {
|
||||
auto& allocator = response->GetAllocator();
|
||||
rapidjson::Value result;
|
||||
result.SetObject();
|
||||
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;
|
||||
image.SetArray();
|
||||
const uint8_t* data =
|
||||
reinterpret_cast<const uint8_t*>(snapshot_bytes->data());
|
||||
for (size_t i = 0; i < snapshot_bytes->size(); i++) {
|
||||
image.PushBack(data[i], allocator);
|
||||
}
|
||||
result.AddMember("snapshot", image, allocator);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Shell::OnServiceProtocolRenderFrameWithRasterStats(
|
||||
const ServiceProtocol::Handler::ServiceProtocolMap& params,
|
||||
rapidjson::Document* response) {
|
||||
FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
|
||||
|
||||
// Impeller does not support this protocol method.
|
||||
if (io_manager_->GetImpellerContext()) {
|
||||
const char* error = "Raster status not supported on Impeller backend.";
|
||||
ServiceProtocolFailureError(response, error);
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(dkwingsmt): This method only handles view #0, including the snapshot
|
||||
// and the frame size. We need to adapt this method to multi-view.
|
||||
// https://github.com/flutter/flutter/issues/131892
|
||||
int64_t view_id = kFlutterImplicitViewId;
|
||||
if (auto last_layer_tree = rasterizer_->GetLastLayerTree(view_id)) {
|
||||
auto& allocator = response->GetAllocator();
|
||||
response->SetObject();
|
||||
response->AddMember("type", "RenderFrameWithRasterStats", allocator);
|
||||
|
||||
// When rendering the last layer tree, we do not need to build a frame,
|
||||
// invariants in FrameTimingRecorder enforce that raster timings can not be
|
||||
// set before build-end.
|
||||
auto frame_timings_recorder = std::make_unique<FrameTimingsRecorder>();
|
||||
const auto now = fml::TimePoint::Now();
|
||||
frame_timings_recorder->RecordVsync(now, now);
|
||||
frame_timings_recorder->RecordBuildStart(now);
|
||||
frame_timings_recorder->RecordBuildEnd(now);
|
||||
|
||||
last_layer_tree->enable_leaf_layer_tracing(true);
|
||||
rasterizer_->DrawLastLayerTrees(std::move(frame_timings_recorder));
|
||||
last_layer_tree->enable_leaf_layer_tracing(false);
|
||||
|
||||
rapidjson::Value snapshots;
|
||||
snapshots.SetArray();
|
||||
|
||||
LayerSnapshotStore& store =
|
||||
rasterizer_->compositor_context()->snapshot_store();
|
||||
for (const LayerSnapshotData& data : store) {
|
||||
snapshots.PushBack(
|
||||
SerializeLayerSnapshot(device_pixel_ratio_, data, response),
|
||||
allocator);
|
||||
}
|
||||
|
||||
response->AddMember("snapshots", snapshots, allocator);
|
||||
|
||||
const auto& frame_size = ExpectedFrameSize(view_id);
|
||||
response->AddMember("frame_width", frame_size.width(), allocator);
|
||||
response->AddMember("frame_height", frame_size.height(), allocator);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
const char* error =
|
||||
"Failed to render the last frame with raster stats."
|
||||
" Rasterizer does not hold a valid last layer tree."
|
||||
" This could happen if this method was invoked before a frame was "
|
||||
"rendered";
|
||||
FML_DLOG(ERROR) << error;
|
||||
ServiceProtocolFailureError(response, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Shell::SendFontChangeNotification() {
|
||||
// After system fonts are reloaded, we send a system channel message
|
||||
// to notify flutter framework.
|
||||
|
||||
@@ -755,15 +755,6 @@ class Shell final : public PlatformView::Delegate,
|
||||
const ServiceProtocol::Handler::ServiceProtocolMap& params,
|
||||
rapidjson::Document* response);
|
||||
|
||||
// Service protocol handler
|
||||
//
|
||||
// Renders a frame and responds with various statistics pertaining to the
|
||||
// raster call. These include time taken to raster every leaf layer and also
|
||||
// leaf layer snapshots.
|
||||
bool OnServiceProtocolRenderFrameWithRasterStats(
|
||||
const ServiceProtocol::Handler::ServiceProtocolMap& params,
|
||||
rapidjson::Document* response);
|
||||
|
||||
// Service protocol handler
|
||||
//
|
||||
// Forces the FontCollection to reload the font manifest. Used to support
|
||||
|
||||
@@ -304,27 +304,24 @@ void ShellTest::OnServiceProtocol(
|
||||
const ServiceProtocol::Handler::ServiceProtocolMap& params,
|
||||
rapidjson::Document* response) {
|
||||
std::promise<bool> finished;
|
||||
fml::TaskRunner::RunNowOrPostTask(task_runner, [shell, some_protocol, params,
|
||||
response, &finished]() {
|
||||
switch (some_protocol) {
|
||||
case ServiceProtocolEnum::kGetSkSLs:
|
||||
shell->OnServiceProtocolGetSkSLs(params, response);
|
||||
break;
|
||||
case ServiceProtocolEnum::kEstimateRasterCacheMemory:
|
||||
shell->OnServiceProtocolEstimateRasterCacheMemory(params, response);
|
||||
break;
|
||||
case ServiceProtocolEnum::kSetAssetBundlePath:
|
||||
shell->OnServiceProtocolSetAssetBundlePath(params, response);
|
||||
break;
|
||||
case ServiceProtocolEnum::kRunInView:
|
||||
shell->OnServiceProtocolRunInView(params, response);
|
||||
break;
|
||||
case ServiceProtocolEnum::kRenderFrameWithRasterStats:
|
||||
shell->OnServiceProtocolRenderFrameWithRasterStats(params, response);
|
||||
break;
|
||||
}
|
||||
finished.set_value(true);
|
||||
});
|
||||
fml::TaskRunner::RunNowOrPostTask(
|
||||
task_runner, [shell, some_protocol, params, response, &finished]() {
|
||||
switch (some_protocol) {
|
||||
case ServiceProtocolEnum::kGetSkSLs:
|
||||
shell->OnServiceProtocolGetSkSLs(params, response);
|
||||
break;
|
||||
case ServiceProtocolEnum::kEstimateRasterCacheMemory:
|
||||
shell->OnServiceProtocolEstimateRasterCacheMemory(params, response);
|
||||
break;
|
||||
case ServiceProtocolEnum::kSetAssetBundlePath:
|
||||
shell->OnServiceProtocolSetAssetBundlePath(params, response);
|
||||
break;
|
||||
case ServiceProtocolEnum::kRunInView:
|
||||
shell->OnServiceProtocolRunInView(params, response);
|
||||
break;
|
||||
}
|
||||
finished.set_value(true);
|
||||
});
|
||||
finished.get_future().wait();
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,6 @@ class ShellTest : public FixtureTest {
|
||||
kEstimateRasterCacheMemory,
|
||||
kSetAssetBundlePath,
|
||||
kRunInView,
|
||||
kRenderFrameWithRasterStats,
|
||||
};
|
||||
|
||||
// Helper method to test private method Shell::OnServiceProtocolGetSkSLs.
|
||||
|
||||
@@ -2566,158 +2566,6 @@ TEST_F(ShellTest, OnServiceProtocolEstimateRasterCacheMemoryWorks) {
|
||||
DestroyShell(std::move(shell));
|
||||
}
|
||||
|
||||
// ktz
|
||||
TEST_F(ShellTest, OnServiceProtocolRenderFrameWithRasterStatsWorks) {
|
||||
auto settings = CreateSettingsForFixture();
|
||||
std::unique_ptr<Shell> shell = CreateShell(settings);
|
||||
|
||||
// Create the surface needed by rasterizer
|
||||
PlatformViewNotifyCreated(shell.get());
|
||||
|
||||
auto configuration = RunConfiguration::InferFromSettings(settings);
|
||||
configuration.SetEntrypoint("scene_with_red_box");
|
||||
|
||||
RunEngine(shell.get(), std::move(configuration));
|
||||
// Set a non-zero viewport metrics, otherwise the scene would be discarded.
|
||||
PostSync(shell->GetTaskRunners().GetUITaskRunner(),
|
||||
[engine = shell->GetEngine()]() {
|
||||
engine->SetViewportMetrics(kImplicitViewId,
|
||||
ViewportMetrics{1, 1, 1, 22, 0});
|
||||
});
|
||||
PumpOneFrame(shell.get(), ViewContent::NoViews());
|
||||
|
||||
ServiceProtocol::Handler::ServiceProtocolMap empty_params;
|
||||
rapidjson::Document document;
|
||||
OnServiceProtocol(
|
||||
shell.get(), ServiceProtocolEnum::kRenderFrameWithRasterStats,
|
||||
shell->GetTaskRunners().GetRasterTaskRunner(), empty_params, &document);
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
document.Accept(writer);
|
||||
|
||||
// It would be better to parse out the json and check for the validity of
|
||||
// fields. Below checks approximate what needs to be checked, this can not be
|
||||
// an exact check since duration will not exactly match.
|
||||
#ifdef SHELL_ENABLE_METAL
|
||||
std::string expected_json =
|
||||
"\"snapshot\":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,3,32,0,"
|
||||
"0,2,88,8,6,0,0,0,154,118,130,112,0,0,0,1,115,82,71,66,0,174,206,28,233,"
|
||||
"0,0,0,4,115,66,73,84,8,8,8,8,124,8,100,136,0,0,7,103,73,68,65,84,120,"
|
||||
"156,237,206,65,13,192,48,0,3,177,211,248,115,78,73,172,234,199,70,224,"
|
||||
"86,91,45,0,0,128,203,190,215,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
|
||||
"0,224,47,7,195,182,3,255,101,111,186,90,0,0,0,0,73,69,78,68,174,66,96,"
|
||||
"130]";
|
||||
#else
|
||||
std::string expected_json =
|
||||
"\"snapshot\":[137,80,78,71,13,10,26,10,0,"
|
||||
"0,0,13,73,72,68,82,0,0,0,1,0,0,0,1,8,6,0,0,0,31,21,196,137,0,0,0,1,115,"
|
||||
"82,71,66,0,174,206,28,233,0,0,0,4,115,66,73,84,8,8,8,8,124,8,100,136,0,"
|
||||
"0,0,13,73,68,65,84,8,153,99,248,207,192,240,31,0,5,0,1,255,171,206,54,"
|
||||
"137,0,0,0,0,73,69,78,68,174,66,96,130]";
|
||||
#endif
|
||||
std::string actual_json = buffer.GetString();
|
||||
|
||||
EXPECT_THAT(actual_json, ::testing::HasSubstr(expected_json));
|
||||
EXPECT_THAT(actual_json,
|
||||
::testing::HasSubstr("{\"type\":\"RenderFrameWithRasterStats\""));
|
||||
EXPECT_THAT(actual_json, ::testing::HasSubstr("\"duration_micros\""));
|
||||
|
||||
PlatformViewNotifyDestroyed(shell.get());
|
||||
DestroyShell(std::move(shell));
|
||||
}
|
||||
|
||||
#if defined(FML_OS_MACOSX)
|
||||
TEST_F(ShellTest, OnServiceProtocolRenderFrameWithRasterStatsDisableImpeller) {
|
||||
auto settings = CreateSettingsForFixture();
|
||||
settings.enable_impeller = true;
|
||||
std::unique_ptr<Shell> shell = CreateShell({
|
||||
.settings = settings,
|
||||
.platform_view_create_callback = ShellTestPlatformViewBuilder({
|
||||
.rendering_backend =
|
||||
ShellTestPlatformView::BackendType::kMetalBackend,
|
||||
}),
|
||||
});
|
||||
|
||||
// Create the surface needed by rasterizer
|
||||
PlatformViewNotifyCreated(shell.get());
|
||||
|
||||
auto configuration = RunConfiguration::InferFromSettings(settings);
|
||||
configuration.SetEntrypoint("scene_with_red_box");
|
||||
|
||||
RunEngine(shell.get(), std::move(configuration));
|
||||
PumpOneFrame(shell.get(), ViewContent::NoViews());
|
||||
|
||||
ServiceProtocol::Handler::ServiceProtocolMap empty_params;
|
||||
rapidjson::Document document;
|
||||
OnServiceProtocol(
|
||||
shell.get(), ServiceProtocolEnum::kRenderFrameWithRasterStats,
|
||||
shell->GetTaskRunners().GetRasterTaskRunner(), empty_params, &document);
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
document.Accept(writer);
|
||||
std::string actual_json = buffer.GetString();
|
||||
std::string expected_json =
|
||||
"{\"code\":-32000,\"message\":\"Raster status not supported on Impeller "
|
||||
"backend.\"}";
|
||||
|
||||
ASSERT_EQ(actual_json, expected_json);
|
||||
|
||||
PlatformViewNotifyDestroyed(shell.get());
|
||||
DestroyShell(std::move(shell));
|
||||
}
|
||||
#endif // FML_OS_MACOSX
|
||||
|
||||
// TODO(https://github.com/flutter/flutter/issues/100273): Disabled due to
|
||||
// flakiness.
|
||||
// TODO(https://github.com/flutter/flutter/issues/100299): Fix it when
|
||||
|
||||
Reference in New Issue
Block a user