Skip to content

Commit

Permalink
Add test to verify coordinate space consistency between custom compos…
Browse files Browse the repository at this point in the history
…ition and root surface composition.
  • Loading branch information
chinmaygarde committed Aug 23, 2019
1 parent 38502f7 commit c015c41
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 4 deletions.
2 changes: 2 additions & 0 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ test_fixtures("fixtures") {
"fixtures/compositor.png",
"fixtures/compositor_with_root_layer_only.png",
"fixtures/compositor_root_surface_xformation.png",
"fixtures/scene_without_custom_compositor.png",
"fixtures/scene_without_custom_compositor_with_xform.png",
]
}

Expand Down
32 changes: 32 additions & 0 deletions shell/platform/embedder/fixtures/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,35 @@ void can_composite_platform_views_with_platform_layer_on_bottom() {
signalNativeTest(); // Signal 1
window.scheduleFrame();
}

@pragma('vm:entry-point')
void can_render_scene_without_custom_compositor() {
window.onBeginFrame = (Duration duration) {
Color red = Color.fromARGB(127, 255, 0, 0);
Color green = Color.fromARGB(127, 0, 255, 0);
Color blue = Color.fromARGB(127, 0, 0, 255);
Color magenta = Color.fromARGB(127, 255, 0, 255);
Color gray = Color.fromARGB(127, 127, 127, 127);

Size size = Size(50.0, 150.0);

SceneBuilder builder = SceneBuilder();

builder.pushOffset(0.0, 0.0);

builder.addPicture(Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter

builder.addPicture(Offset(20.0, 20.0), CreateColoredBox(green, size)); // green - flutter

builder.addPicture(Offset(30.0, 30.0), CreateColoredBox(blue, size)); // blue - flutter

builder.addPicture(Offset(40.0, 40.0), CreateColoredBox(magenta, size)); // magenta - flutter

builder.addPicture(Offset(50.0, 50.0), CreateColoredBox(gray, size)); // gray - flutter

builder.pop();

window.render(builder.build());
};
window.scheduleFrame();
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions shell/platform/embedder/tests/embedder_test_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const fml::Mapping* EmbedderTestContext::GetIsolateSnapshotInstructions()
return isolate_snapshot_instructions_.get();
}

void EmbedderTestContext::SetRootSurfaceTransformation(SkMatrix matrix) {
root_surface_transformation_ = matrix;
}

void EmbedderTestContext::AddIsolateCreateCallback(fml::closure closure) {
if (closure) {
isolate_create_callbacks_.push_back(closure);
Expand Down Expand Up @@ -177,10 +181,10 @@ void* EmbedderTestContext::GLGetProcAddress(const char* name) {
}

FlutterTransformation EmbedderTestContext::GetRootSurfaceTransformation() {
SkMatrix transformation;
if (compositor_) {
transformation = compositor_->GetRootSurfaceTransformation();
}
const auto transformation = compositor_
? compositor_->GetRootSurfaceTransformation()
: root_surface_transformation_;

return FlutterTransformationMake(transformation);
}

Expand Down
3 changes: 3 additions & 0 deletions shell/platform/embedder/tests/embedder_test_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class EmbedderTestContext {

const fml::Mapping* GetIsolateSnapshotInstructions() const;

void SetRootSurfaceTransformation(SkMatrix matrix);

void AddIsolateCreateCallback(fml::closure closure);

void AddNativeCallback(const char* name, Dart_NativeFunction function);
Expand Down Expand Up @@ -78,6 +80,7 @@ class EmbedderTestContext {
std::unique_ptr<TestGLSurface> gl_surface_;
std::unique_ptr<EmbedderTestCompositor> compositor_;
NextSceneCallback next_scene_callback_;
SkMatrix root_surface_transformation_;

static VoidCallback GetIsolateCreateCallbackHook();

Expand Down
75 changes: 75 additions & 0 deletions shell/platform/embedder/tests/embedder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1596,5 +1596,80 @@ TEST_F(EmbedderTest,
scene_image));
}

TEST_F(EmbedderTest, CanRenderSceneWithoutCustomCompositor) {
auto& context = GetEmbedderContext();

EmbedderConfigBuilder builder(context);

builder.SetDartEntrypoint("can_render_scene_without_custom_compositor");
builder.SetOpenGLRendererConfig();
fml::CountDownLatch latch(1);

sk_sp<SkImage> renderered_scene;
context.SetNextSceneCallback([&](auto image) {
renderered_scene = std::move(image);
latch.CountDown();
});

auto engine = builder.LaunchEngine();
ASSERT_TRUE(engine.is_valid());

// Send a window metrics events so frames may be scheduled.
FlutterWindowMetricsEvent event = {};
event.struct_size = sizeof(event);
event.width = 800;
event.height = 600;
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
kSuccess);

latch.Wait();

ASSERT_NE(renderered_scene, nullptr);

ASSERT_TRUE(ImageMatchesFixture("scene_without_custom_compositor.png",
renderered_scene));
}

TEST_F(EmbedderTest, CanRenderSceneWithoutCustomCompositorWithTransformation) {
auto& context = GetEmbedderContext();

SkMatrix root_surface_transformation;
root_surface_transformation.setRotate(-90.0);
root_surface_transformation.setTranslateY(800);

context.SetRootSurfaceTransformation(root_surface_transformation);

EmbedderConfigBuilder builder(context);

builder.SetDartEntrypoint("can_render_scene_without_custom_compositor");
builder.SetOpenGLRendererConfig();

fml::CountDownLatch latch(1);

sk_sp<SkImage> renderered_scene;
context.SetNextSceneCallback([&](auto image) {
renderered_scene = std::move(image);
latch.CountDown();
});

auto engine = builder.LaunchEngine();
ASSERT_TRUE(engine.is_valid());

// Send a window metrics events so frames may be scheduled.
FlutterWindowMetricsEvent event = {};
event.struct_size = sizeof(event);
event.width = 800;
event.height = 600;
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
kSuccess);

latch.Wait();

ASSERT_NE(renderered_scene, nullptr);

ASSERT_TRUE(ImageMatchesFixture(
"scene_without_custom_compositor_with_xform.png", renderered_scene));
}

} // namespace testing
} // namespace flutter

0 comments on commit c015c41

Please sign in to comment.