Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
2 changes: 1 addition & 1 deletion flow/layers/layer_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool LayerTree::Preroll(CompositorContext::ScopedFrame& frame,
.raster_time = frame.context().raster_time(),
.ui_time = frame.context().ui_time(),
.texture_registry = frame.context().texture_registry(),
.impeller_enabled = !frame.gr_context(),
.impeller_enabled = !!frame.aiks_context(),
.raster_cached_entries = &raster_cache_items_,
// clang-format on
};
Expand Down
33 changes: 33 additions & 0 deletions flow/layers/layer_tree_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class LayerTreeTest : public CanvasTest {
return std::make_unique<LayerTree>(config, SkISize::Make(64, 64));
}

CompositorContext& compositor_context() { return compositor_context_; }

private:
CompositorContext compositor_context_;
SkMatrix root_transform_;
Expand Down Expand Up @@ -99,6 +101,37 @@ TEST_F(LayerTreeTest, Simple) {
0, MockCanvas::DrawPathData{child_path, child_paint}}}));
}

TEST_F(LayerTreeTest, NoGrContextNoAiksContext) {
const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f);
const SkPath child_path = SkPath().addRect(child_bounds);
const DlPaint child_paint = DlPaint(DlColor::kCyan());
auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
auto layer = std::make_shared<ContainerLayer>();
layer->Add(mock_layer);

// The default |frame()| object contains these same values, but those
// defaults could change in the future so we manually construct our
// own frame that ensures that both gr_context and aiks_context are null.
auto frame = compositor_context().AcquireFrame(nullptr, &mock_canvas(),
nullptr, root_transform(),
false, true, nullptr, nullptr);

auto layer_tree = BuildLayerTree(LayerTree::Config{
.root_layer = layer,
});
layer_tree->Preroll(*frame.get());
EXPECT_EQ(mock_layer->paint_bounds(), child_bounds);
EXPECT_EQ(layer->paint_bounds(), mock_layer->paint_bounds());
EXPECT_FALSE(mock_layer->is_empty());
EXPECT_FALSE(layer->is_empty());
EXPECT_EQ(mock_layer->parent_matrix(), root_transform());

layer_tree->Paint(*frame.get());
EXPECT_EQ(mock_canvas().draw_calls(),
std::vector({MockCanvas::DrawCall{
0, MockCanvas::DrawPathData{child_path, child_paint}}}));
}

TEST_F(LayerTreeTest, Multiple) {
const SkPath child_path1 = SkPath().addRect(5.0f, 6.0f, 20.5f, 21.5f);
const SkPath child_path2 = SkPath().addRect(8.0f, 2.0f, 16.5f, 14.5f);
Expand Down
2 changes: 2 additions & 0 deletions flow/testing/mock_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void MockLayer::Diff(DiffContext* context, const Layer* old_layer) {
}

void MockLayer::Preroll(PrerollContext* context) {
preroll_context_had_impeller_enabled_ = context->impeller_enabled;
context->state_stack.fill(&parent_mutators_);
parent_matrix_ = context->state_stack.transform_3x3();
parent_cull_rect_ = context->state_stack.local_cull_rect();
Expand All @@ -51,6 +52,7 @@ void MockLayer::Preroll(PrerollContext* context) {

void MockLayer::Paint(PaintContext& context) const {
FML_DCHECK(needs_painting(context));
ASSERT_EQ(context.impeller_enabled, preroll_context_had_impeller_enabled_);

if (expected_paint_matrix_.has_value()) {
SkMatrix matrix = context.canvas->GetTransform();
Expand Down
1 change: 1 addition & 0 deletions flow/testing/mock_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class MockLayer : public Layer {
SkPath fake_paint_path_;
DlPaint fake_paint_;
std::optional<SkMatrix> expected_paint_matrix_;
bool preroll_context_had_impeller_enabled_;

static constexpr int kParentHasPlatformView = 1 << 0;
static constexpr int kParentHasTextureLayer = 1 << 1;
Expand Down