Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Reland: "fuchsia: Remove dead code / break dependencies" #20532

Merged
merged 9 commits into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions flow/layers/child_scene_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "flutter/flow/layers/child_scene_layer.h"

#include "flutter/flow/view_holder.h"

namespace flutter {

ChildSceneLayer::ChildSceneLayer(zx_koid_t layer_id,
Expand All @@ -19,11 +17,9 @@ ChildSceneLayer::ChildSceneLayer(zx_koid_t layer_id,

void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
TRACE_EVENT0("flutter", "ChildSceneLayer::Preroll");
set_needs_system_composite(true);

CheckForChildLayerBelow(context);

context->child_scene_layer_exists_below = true;
CheckForChildLayerBelow(context);

// An alpha "hole punch" is required if the frame behind us is not opaque.
if (!context->is_opaque) {
Expand All @@ -49,15 +45,7 @@ void ChildSceneLayer::Paint(PaintContext& context) const {
void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) {
TRACE_EVENT0("flutter", "ChildSceneLayer::UpdateScene");
FML_DCHECK(needs_system_composite());

Layer::UpdateScene(context);

auto* view_holder = ViewHolder::FromId(layer_id_);
FML_DCHECK(view_holder);

view_holder->UpdateScene(context, offset_, size_,
SkScalarRoundToInt(context.alphaf() * 255),
hit_testable_);
context.UpdateView(layer_id_, offset_, size_, hit_testable_);
}

} // namespace flutter
68 changes: 15 additions & 53 deletions flow/layers/container_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "flutter/flow/layers/container_layer.h"

#include <optional>

namespace flutter {

ContainerLayer::ContainerLayer() {}
Expand All @@ -30,6 +32,9 @@ void ContainerLayer::PrerollChildren(PrerollContext* context,
const SkMatrix& child_matrix,
SkRect* child_paint_bounds) {
#if defined(LEGACY_FUCHSIA_EMBEDDER)
// If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
// Layers that appear above the embedded content will be turned into their own
// Scenic layers.
child_layer_exists_below_ = context->child_scene_layer_exists_below;
context->child_scene_layer_exists_below = false;
#endif
Expand Down Expand Up @@ -98,63 +103,20 @@ void ContainerLayer::UpdateScene(SceneUpdateContext& context) {
}

void ContainerLayer::UpdateSceneChildren(SceneUpdateContext& context) {
auto update_scene_layers = [&] {
// Paint all of the layers which need to be drawn into the container.
// These may be flattened down to a containing Scenic Frame.
for (auto& layer : layers_) {
if (layer->needs_system_composite()) {
layer->UpdateScene(context);
}
}
};

FML_DCHECK(needs_system_composite());

// If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
// PhysicalShapeLayers that appear above the embedded content will be turned
// into their own Scenic layers.
std::optional<SceneUpdateContext::Frame> frame;
if (child_layer_exists_below_) {
float global_scenic_elevation =
context.GetGlobalElevationForNextScenicLayer();
float local_scenic_elevation =
global_scenic_elevation - context.scenic_elevation();
float z_translation = -local_scenic_elevation;

// Retained rendering: speedup by reusing a retained entity node if
// possible. When an entity node is reused, no paint layer is added to the
// frame so we won't call PhysicalShapeLayer::Paint.
LayerRasterCacheKey key(unique_id(), context.Matrix());
if (context.HasRetainedNode(key)) {
TRACE_EVENT_INSTANT0("flutter", "retained layer cache hit");
scenic::EntityNode* retained_node = context.GetRetainedNode(key);
FML_DCHECK(context.top_entity());
FML_DCHECK(retained_node->session() == context.session());

// Re-adjust the elevation.
retained_node->SetTranslation(0.f, 0.f, z_translation);

context.top_entity()->entity_node().AddChild(*retained_node);
return;
}

TRACE_EVENT_INSTANT0("flutter", "cache miss, creating");
// If we can't find an existing retained surface, create one.
SceneUpdateContext::Frame frame(
frame.emplace(
context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT,
SkScalarRoundToInt(context.alphaf() * 255),
"flutter::PhysicalShapeLayer", z_translation, this);

frame.AddPaintLayer(this);

// Node: UpdateSceneChildren needs to be called here so that |frame| is
// still in scope (and therefore alive) while UpdateSceneChildren is being
// called.
float scenic_elevation = context.scenic_elevation();
context.set_scenic_elevation(scenic_elevation + local_scenic_elevation);
update_scene_layers();
context.set_scenic_elevation(scenic_elevation);
} else {
update_scene_layers();
SkScalarRoundToInt(context.alphaf() * 255), "flutter::ContainerLayer");
frame->AddPaintLayer(this);
}

for (auto& layer : layers_) {
if (layer->needs_system_composite()) {
layer->UpdateScene(context);
}
}
}

Expand Down
74 changes: 15 additions & 59 deletions flow/layers/fuchsia_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,57 +238,17 @@ class MockSession : public fuchsia::ui::scenic::testing::Session_TestBase {
fuchsia::ui::scenic::SessionListenerPtr listener_;
};

class MockSurfaceProducerSurface
: public SceneUpdateContext::SurfaceProducerSurface {
class MockSessionWrapper : public flutter::SessionWrapper {
public:
MockSurfaceProducerSurface(scenic::Session* session, const SkISize& size)
: image_(session, 0, 0, {}), size_(size) {}
MockSessionWrapper(fuchsia::ui::scenic::SessionPtr session_ptr)
: session_(std::move(session_ptr)) {}
~MockSessionWrapper() override = default;

size_t AdvanceAndGetAge() override { return 0; }

bool FlushSessionAcquireAndReleaseEvents() override { return false; }

bool IsValid() const override { return false; }

SkISize GetSize() const override { return size_; }

void SignalWritesFinished(
const std::function<void(void)>& on_writes_committed) override {}

scenic::Image* GetImage() override { return &image_; };

sk_sp<SkSurface> GetSkiaSurface() const override { return nullptr; };
scenic::Session* get() override { return &session_; }
void Present() override { session_.Flush(); }

private:
scenic::Image image_;
SkISize size_;
};

class MockSurfaceProducer : public SceneUpdateContext::SurfaceProducer {
public:
MockSurfaceProducer(scenic::Session* session) : session_(session) {}
std::unique_ptr<SceneUpdateContext::SurfaceProducerSurface> ProduceSurface(
const SkISize& size,
const LayerRasterCacheKey& layer_key,
std::unique_ptr<scenic::EntityNode> entity_node) override {
return std::make_unique<MockSurfaceProducerSurface>(session_, size);
}

// Query a retained entity node (owned by a retained surface) for retained
// rendering.
bool HasRetainedNode(const LayerRasterCacheKey& key) const override {
return false;
}

scenic::EntityNode* GetRetainedNode(const LayerRasterCacheKey& key) override {
return nullptr;
}

void SubmitSurface(std::unique_ptr<SceneUpdateContext::SurfaceProducerSurface>
surface) override {}

private:
scenic::Session* session_;
scenic::Session session_;
};

struct TestContext {
Expand All @@ -297,12 +257,11 @@ struct TestContext {
fml::RefPtr<fml::TaskRunner> task_runner;

// Session.
MockSession mock_session;
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> listener_request;
std::unique_ptr<scenic::Session> session;
MockSession mock_session;
std::unique_ptr<MockSessionWrapper> mock_session_wrapper;

// SceneUpdateContext.
std::unique_ptr<MockSurfaceProducer> mock_surface_producer;
std::unique_ptr<SceneUpdateContext> scene_update_context;

// PrerollContext.
Expand All @@ -324,15 +283,13 @@ std::unique_ptr<TestContext> InitTest() {
fuchsia::ui::scenic::SessionListenerPtr listener;
context->listener_request = listener.NewRequest();
context->mock_session.Bind(session_ptr.NewRequest(), std::move(listener));
context->session = std::make_unique<scenic::Session>(std::move(session_ptr));
context->mock_session_wrapper =
std::make_unique<MockSessionWrapper>(std::move(session_ptr));

// Init SceneUpdateContext.
context->mock_surface_producer =
std::make_unique<MockSurfaceProducer>(context->session.get());
context->scene_update_context = std::make_unique<SceneUpdateContext>(
context->session.get(), context->mock_surface_producer.get());
context->scene_update_context->set_metrics(
fidl::MakeOptional(fuchsia::ui::gfx::Metrics{1.f, 1.f, 1.f}));
"fuchsia_layer_unittest", fuchsia::ui::views::ViewToken(),
scenic::ViewRefPair::New(), *(context->mock_session_wrapper));

// Init PrerollContext.
context->preroll_context = std::unique_ptr<PrerollContext>(new PrerollContext{
Expand All @@ -348,7 +305,6 @@ std::unique_ptr<TestContext> InitTest() {
context->unused_texture_registry, // texture registry (not
// supported)
false, // checkerboard_offscreen_layers
100.f, // maximum depth allowed for rendering
1.f // ratio between logical and physical
});

Expand Down Expand Up @@ -602,7 +558,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_PhysicalShapeLayersAndChildSceneLayers) {
// against the list above.
root->UpdateScene(*(test_context->scene_update_context));

test_context->session->Flush();
test_context->mock_session_wrapper->Present();

// Run loop until idle, so that the Session receives and processes
// its method calls.
Expand Down Expand Up @@ -784,7 +740,7 @@ TEST_F(FuchsiaLayerTest, DISABLED_OpacityAndTransformLayer) {
// commands against the list above.
root->UpdateScene(*(test_context->scene_update_context));

test_context->session->Flush();
test_context->mock_session_wrapper->Present();

// Run loop until idle, so that the Session receives and processes
// its method calls.
Expand Down
47 changes: 11 additions & 36 deletions flow/layers/layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,49 +58,24 @@ Layer::AutoPrerollSaveLayerState::~AutoPrerollSaveLayerState() {
#if defined(LEGACY_FUCHSIA_EMBEDDER)

void Layer::CheckForChildLayerBelow(PrerollContext* context) {
// If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
// PhysicalShapeLayers that appear above the embedded content will be turned
// into their own Scenic layers.
child_layer_exists_below_ = context->child_scene_layer_exists_below;
if (child_layer_exists_below_) {
set_needs_system_composite(true);
}
}

void Layer::UpdateScene(SceneUpdateContext& context) {
// If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
// PhysicalShapeLayers that appear above the embedded content will be turned
// into their own Scenic layers.
if (child_layer_exists_below_) {
float global_scenic_elevation =
context.GetGlobalElevationForNextScenicLayer();
float local_scenic_elevation =
global_scenic_elevation - context.scenic_elevation();
float z_translation = -local_scenic_elevation;

// Retained rendering: speedup by reusing a retained entity node if
// possible. When an entity node is reused, no paint layer is added to the
// frame so we won't call PhysicalShapeLayer::Paint.
LayerRasterCacheKey key(unique_id(), context.Matrix());
if (context.HasRetainedNode(key)) {
TRACE_EVENT_INSTANT0("flutter", "retained layer cache hit");
scenic::EntityNode* retained_node = context.GetRetainedNode(key);
FML_DCHECK(context.top_entity());
FML_DCHECK(retained_node->session() == context.session());

// Re-adjust the elevation.
retained_node->SetTranslation(0.f, 0.f, z_translation);

context.top_entity()->entity_node().AddChild(*retained_node);
return;
}

TRACE_EVENT_INSTANT0("flutter", "cache miss, creating");
// If we can't find an existing retained surface, create one.
SceneUpdateContext::Frame frame(
context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT,
SkScalarRoundToInt(context.alphaf() * 255),
"flutter::PhysicalShapeLayer", z_translation, this);

frame.AddPaintLayer(this);
}
FML_DCHECK(needs_system_composite());
FML_DCHECK(child_layer_exists_below_);

SceneUpdateContext::Frame frame(
context, SkRRect::MakeRect(paint_bounds()), SK_ColorTRANSPARENT,
SkScalarRoundToInt(context.alphaf() * 255), "flutter::Layer");

frame.AddPaintLayer(this);
}

#endif
Expand Down
11 changes: 2 additions & 9 deletions flow/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ struct PrerollContext {
const Stopwatch& ui_time;
TextureRegistry& texture_registry;
const bool checkerboard_offscreen_layers;

// These allow us to make use of the scene metrics during Preroll.
float frame_physical_depth;
float frame_device_pixel_ratio;
const float frame_device_pixel_ratio;

// These allow us to track properties like elevation, opacity, and the
// prescence of a platform view during Preroll.
float total_elevation = 0.0f;
bool has_platform_view = false;
bool is_opaque = true;
#if defined(LEGACY_FUCHSIA_EMBEDDER)
Expand Down Expand Up @@ -128,10 +124,7 @@ class Layer {
TextureRegistry& texture_registry;
const RasterCache* raster_cache;
const bool checkerboard_offscreen_layers;

// These allow us to make use of the scene metrics during Paint.
float frame_physical_depth;
float frame_device_pixel_ratio;
const float frame_device_pixel_ratio;
};

// Calls SkCanvas::saveLayer and restores the layer upon destruction. Also
Expand Down
Loading