[fuchsia] flutter-embedder-test and touch-input-test use Flatland Test UI Stack (flutter/engine#43562)
This change also: - removes reliance from both tests on `fuchsia.ui.scenic.Scenic` protocols - migrates `touch-input-test` to get display info from `fuchsia.ui.display.singleton.Info` instead of `fuchsia.ui.gfx.DisplayInfo` - adds support for `fuchsia.ui.display.singleton.Info` in `portable_ui_test` to support the above - migrates `flutter-embedder-test` to capture screenshots using `fuchsia.ui.composition.Screenshot` instead of `fuchsia.ui.scenic.Screenshot` - updates screenshot tooling accordingly - removes the embedding view hit test disabled case from `touch-input test`, since disabling the hit region is not currently supported in Flutter's integration with Flatland afaict ([this logic](4f384979af/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc (L411-L434)) appears to set hit regions to the full view size by default, and Flatland appears to drop the value [here](4f384979af/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc (L578))) - removes hit test configurability on `touch-input-test` and `flutter-embedder-test` embedding views Bug: fxbug.dev/125514
This commit is contained in:
@@ -27,6 +27,7 @@ executable("flutter-embedder-test-bin") {
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.tracing.provider",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.app",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.composition",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.display.singleton",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.observation.geometry",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.scenic",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.test.input",
|
||||
@@ -39,7 +40,6 @@ executable("flutter-embedder-test-bin") {
|
||||
"$fuchsia_sdk_root/pkg:zx",
|
||||
"//flutter/fml",
|
||||
"//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:check_view",
|
||||
"//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:color",
|
||||
"//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:screenshot",
|
||||
"//third_party/googletest:gtest",
|
||||
"//third_party/googletest:gtest_main",
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <fuchsia/tracing/provider/cpp/fidl.h>
|
||||
#include <fuchsia/ui/app/cpp/fidl.h>
|
||||
#include <fuchsia/ui/composition/cpp/fidl.h>
|
||||
#include <fuchsia/ui/display/singleton/cpp/fidl.h>
|
||||
#include <fuchsia/ui/observation/geometry/cpp/fidl.h>
|
||||
#include <fuchsia/ui/scenic/cpp/fidl.h>
|
||||
#include <fuchsia/ui/test/input/cpp/fidl.h>
|
||||
#include <fuchsia/ui/test/scene/cpp/fidl.h>
|
||||
#include <lib/async-loop/testing/cpp/real_loop.h>
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <lib/fidl/cpp/binding_set.h>
|
||||
#include <lib/sys/component/cpp/testing/realm_builder.h>
|
||||
#include <lib/sys/component/cpp/testing/realm_builder_types.h>
|
||||
#include <lib/ui/scenic/cpp/view_ref_pair.h>
|
||||
#include <lib/zx/clock.h>
|
||||
#include <zircon/status.h>
|
||||
#include <zircon/time.h>
|
||||
@@ -27,7 +26,6 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "flutter/shell/platform/fuchsia/flutter/tests/integration/utils/check_view.h"
|
||||
#include "flutter/shell/platform/fuchsia/flutter/tests/integration/utils/color.h"
|
||||
#include "flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.h"
|
||||
|
||||
namespace flutter_embedder_test {
|
||||
@@ -66,7 +64,8 @@ constexpr char kChildViewUrl[] =
|
||||
constexpr char kParentViewUrl[] =
|
||||
"fuchsia-pkg://fuchsia.com/parent-view#meta/parent-view.cm";
|
||||
static constexpr auto kTestUiStackUrl =
|
||||
"fuchsia-pkg://fuchsia.com/test-ui-stack#meta/test-ui-stack.cm";
|
||||
"fuchsia-pkg://fuchsia.com/flatland-scene-manager-test-ui-stack#meta/"
|
||||
"test-ui-stack.cm";
|
||||
|
||||
constexpr auto kFlutterRunnerEnvironment = "flutter_runner_env";
|
||||
constexpr auto kFlutterJitRunner = "flutter_jit_runner";
|
||||
@@ -84,36 +83,26 @@ constexpr auto kParentViewRef = ChildRef{kParentView};
|
||||
constexpr auto kTestUiStack = "ui";
|
||||
constexpr auto kTestUiStackRef = ChildRef{kTestUiStack};
|
||||
|
||||
constexpr fuchsia_test_utils::Color kParentBackgroundColor = {0x00, 0x00, 0xFF,
|
||||
0xFF}; // Blue
|
||||
constexpr fuchsia_test_utils::Color kChildBackgroundColor = {0xFF, 0x00, 0xFF,
|
||||
0xFF}; // Pink
|
||||
// Background and foreground color values.
|
||||
const fuchsia_test_utils::Pixel kParentBackgroundColor(0xFF,
|
||||
0x00,
|
||||
0x00,
|
||||
0xFF); // Blue
|
||||
const fuchsia_test_utils::Pixel kChildBackgroundColor(0xFF,
|
||||
0x00,
|
||||
0xFF,
|
||||
0xFF); // Pink
|
||||
const fuchsia_test_utils::Pixel kFlatlandOverlayColor(0x00,
|
||||
0xFF,
|
||||
0x00,
|
||||
0xFF); // Green
|
||||
|
||||
// TODO(fxb/64201): Remove forced opacity colors when Flatland is enabled.
|
||||
constexpr fuchsia_test_utils::Color kOverlayBackgroundColor1 = {
|
||||
0x00, 0xFF, 0x0E, 0xFF}; // Green, blended with blue (FEMU local)
|
||||
constexpr fuchsia_test_utils::Color kOverlayBackgroundColor2 = {
|
||||
0x0E, 0xFF, 0x0E, 0xFF}; // Green, blended with pink (FEMU local)
|
||||
constexpr fuchsia_test_utils::Color kOverlayBackgroundColor3 = {
|
||||
0x00, 0xFF, 0x0D, 0xFF}; // Green, blended with blue (AEMU infra)
|
||||
constexpr fuchsia_test_utils::Color kOverlayBackgroundColor4 = {
|
||||
0x0D, 0xFF, 0x0D, 0xFF}; // Green, blended with pink (AEMU infra)
|
||||
constexpr fuchsia_test_utils::Color kOverlayBackgroundColor5 = {
|
||||
0x00, 0xFE, 0x0D, 0xFF}; // Green, blended with blue (NUC)
|
||||
constexpr fuchsia_test_utils::Color kOverlayBackgroundColor6 = {
|
||||
0x0D, 0xFF, 0x00, 0xFF}; // Green, blended with pink (NUC)
|
||||
|
||||
static size_t OverlayPixelCount(
|
||||
std::map<fuchsia_test_utils::Color, size_t>& histogram) {
|
||||
return histogram[kOverlayBackgroundColor1] +
|
||||
histogram[kOverlayBackgroundColor2] +
|
||||
histogram[kOverlayBackgroundColor3] +
|
||||
histogram[kOverlayBackgroundColor4] +
|
||||
histogram[kOverlayBackgroundColor5] +
|
||||
histogram[kOverlayBackgroundColor6];
|
||||
static uint32_t OverlayPixelCount(
|
||||
std::map<fuchsia_test_utils::Pixel, uint32_t>& histogram) {
|
||||
return histogram[kFlatlandOverlayColor];
|
||||
}
|
||||
|
||||
// Timeout for Scenic's |TakeScreenshot| FIDL call.
|
||||
// Timeout for |TakeScreenshot| FIDL call.
|
||||
constexpr zx::duration kScreenshotTimeout = zx::sec(10);
|
||||
// Timeout to fail the test if it goes beyond this duration.
|
||||
constexpr zx::duration kTestTimeout = zx::min(1);
|
||||
@@ -151,23 +140,24 @@ class FlutterEmbedderTest : public ::loop_fixture::RealLoop,
|
||||
fuchsia_test_utils::Screenshot TakeScreenshot();
|
||||
|
||||
bool TakeScreenshotUntil(
|
||||
fuchsia_test_utils::Color color,
|
||||
fit::function<void(std::map<fuchsia_test_utils::Color, size_t>)>
|
||||
fuchsia_test_utils::Pixel color,
|
||||
fit::function<void(std::map<fuchsia_test_utils::Pixel, uint32_t>)>
|
||||
callback = nullptr,
|
||||
zx::duration timeout = kTestTimeout);
|
||||
|
||||
private:
|
||||
fuchsia::ui::scenic::Scenic* scenic() { return scenic_.get(); }
|
||||
|
||||
void SetUpRealmBase();
|
||||
|
||||
fuchsia::ui::scenic::ScenicPtr scenic_;
|
||||
fuchsia::ui::test::scene::ControllerPtr scene_provider_;
|
||||
fuchsia::ui::observation::geometry::ViewTreeWatcherPtr view_tree_watcher_;
|
||||
fuchsia::ui::composition::ScreenshotPtr screenshot_;
|
||||
|
||||
// Wrapped in optional since the view is not created until the middle of SetUp
|
||||
component_testing::RealmBuilder realm_builder_;
|
||||
std::unique_ptr<component_testing::RealmRoot> realm_;
|
||||
|
||||
uint64_t display_width_ = 0;
|
||||
uint64_t display_height_ = 0;
|
||||
};
|
||||
|
||||
void FlutterEmbedderTest::SetUpRealmBase() {
|
||||
@@ -261,19 +251,20 @@ void FlutterEmbedderTest::SetUpRealmBase() {
|
||||
|
||||
// Route UI capabilities from test UI stack to flutter runners.
|
||||
realm_builder_.AddRoute(Route{
|
||||
.capabilities = {Protocol{fuchsia::ui::composition::Flatland::Name_},
|
||||
Protocol{fuchsia::ui::scenic::Scenic::Name_}},
|
||||
.capabilities = {Protocol{fuchsia::ui::composition::Allocator::Name_},
|
||||
Protocol{fuchsia::ui::composition::Flatland::Name_}},
|
||||
.source = kTestUiStackRef,
|
||||
.targets = {kFlutterJitRunnerRef, kFlutterJitProductRunnerRef,
|
||||
kFlutterAotRunnerRef, kFlutterAotProductRunnerRef}});
|
||||
|
||||
// Route test capabilities from test UI stack to test driver.
|
||||
realm_builder_.AddRoute(Route{
|
||||
.capabilities = {Protocol{fuchsia::ui::test::input::Registry::Name_},
|
||||
.capabilities = {Protocol{fuchsia::ui::composition::Screenshot::Name_},
|
||||
Protocol{fuchsia::ui::test::input::Registry::Name_},
|
||||
Protocol{fuchsia::ui::test::scene::Controller::Name_},
|
||||
Protocol{fuchsia::ui::scenic::Scenic::Name_}},
|
||||
Protocol{fuchsia::ui::display::singleton::Info::Name_}},
|
||||
.source = kTestUiStackRef,
|
||||
.targets = {ParentRef{}}});
|
||||
.targets = {ParentRef()}});
|
||||
|
||||
// Route ViewProvider from child to parent, and parent to test.
|
||||
realm_builder_.AddRoute(
|
||||
@@ -328,6 +319,21 @@ void FlutterEmbedderTest::LaunchParentViewInRealm(
|
||||
}
|
||||
realm_ = std::make_unique<RealmRoot>(realm_builder_.Build());
|
||||
|
||||
// Get the display information using the |fuchsia.ui.display.singleton.Info|.
|
||||
std::optional<bool> display_metrics_obtained;
|
||||
fuchsia::ui::display::singleton::InfoPtr display_info =
|
||||
realm_->component().Connect<fuchsia::ui::display::singleton::Info>();
|
||||
display_info->GetMetrics([this, &display_metrics_obtained](auto info) {
|
||||
display_width_ = info.extent_in_px().width;
|
||||
display_height_ = info.extent_in_px().height;
|
||||
display_metrics_obtained = true;
|
||||
});
|
||||
RunLoopUntil([&display_metrics_obtained] {
|
||||
return display_metrics_obtained.has_value();
|
||||
});
|
||||
FML_LOG(INFO) << "Got display_width " << display_width_ << " display_height "
|
||||
<< display_height_;
|
||||
|
||||
// Instruct Test UI Stack to present parent-view's View.
|
||||
std::optional<zx_koid_t> view_ref_koid;
|
||||
scene_provider_ =
|
||||
@@ -357,30 +363,34 @@ void FlutterEmbedderTest::LaunchParentViewInRealm(
|
||||
});
|
||||
FML_LOG(INFO) << "Client view has rendered";
|
||||
|
||||
scenic_ = realm_->component().Connect<fuchsia::ui::scenic::Scenic>();
|
||||
screenshot_ =
|
||||
realm_->component().Connect<fuchsia::ui::composition::Screenshot>();
|
||||
FML_LOG(INFO) << "Launched parent-view";
|
||||
}
|
||||
|
||||
fuchsia_test_utils::Screenshot FlutterEmbedderTest::TakeScreenshot() {
|
||||
FML_LOG(INFO) << "Taking screenshot... ";
|
||||
fuchsia::ui::scenic::ScreenshotData screenshot_out;
|
||||
scenic_->TakeScreenshot(
|
||||
[this, &screenshot_out](fuchsia::ui::scenic::ScreenshotData screenshot,
|
||||
bool status) {
|
||||
EXPECT_TRUE(status) << "Failed to take screenshot";
|
||||
screenshot_out = std::move(screenshot);
|
||||
QuitLoop();
|
||||
});
|
||||
|
||||
fuchsia::ui::composition::ScreenshotTakeRequest request;
|
||||
request.set_format(fuchsia::ui::composition::ScreenshotFormat::BGRA_RAW);
|
||||
|
||||
std::optional<fuchsia::ui::composition::ScreenshotTakeResponse> response;
|
||||
screenshot_->Take(std::move(request), [this, &response](auto screenshot) {
|
||||
response = std::move(screenshot);
|
||||
QuitLoop();
|
||||
});
|
||||
|
||||
EXPECT_FALSE(RunLoopWithTimeout(kScreenshotTimeout))
|
||||
<< "Timed out waiting for screenshot.";
|
||||
FML_LOG(INFO) << "Screenshot captured.";
|
||||
|
||||
return fuchsia_test_utils::Screenshot(screenshot_out);
|
||||
return fuchsia_test_utils::Screenshot(
|
||||
response->vmo(), display_width_, display_height_, /*display_rotation*/ 0);
|
||||
}
|
||||
|
||||
bool FlutterEmbedderTest::TakeScreenshotUntil(
|
||||
fuchsia_test_utils::Color color,
|
||||
fit::function<void(std::map<fuchsia_test_utils::Color, size_t>)> callback,
|
||||
fuchsia_test_utils::Pixel color,
|
||||
fit::function<void(std::map<fuchsia_test_utils::Pixel, uint32_t>)> callback,
|
||||
zx::duration timeout) {
|
||||
return RunLoopWithTimeoutOrUntil(
|
||||
[this, &callback, &color] {
|
||||
@@ -402,7 +412,7 @@ TEST_F(FlutterEmbedderTest, Embedding) {
|
||||
// Take screenshot until we see the child-view's embedded color.
|
||||
ASSERT_TRUE(TakeScreenshotUntil(
|
||||
kChildBackgroundColor,
|
||||
[](std::map<fuchsia_test_utils::Color, size_t> histogram) {
|
||||
[](std::map<fuchsia_test_utils::Pixel, uint32_t> histogram) {
|
||||
// Expect parent and child background colors, with parent color > child
|
||||
// color.
|
||||
EXPECT_GT(histogram[kParentBackgroundColor], 0u);
|
||||
@@ -418,10 +428,10 @@ TEST_F(FlutterEmbedderTest, EmbeddingWithOverlay) {
|
||||
// Take screenshot until we see the child-view's embedded color.
|
||||
ASSERT_TRUE(TakeScreenshotUntil(
|
||||
kChildBackgroundColor,
|
||||
[](std::map<fuchsia_test_utils::Color, size_t> histogram) {
|
||||
[](std::map<fuchsia_test_utils::Pixel, uint32_t> histogram) {
|
||||
// Expect parent, overlay and child background colors.
|
||||
// With parent color > child color and overlay color > child color.
|
||||
const size_t overlay_pixel_count = OverlayPixelCount(histogram);
|
||||
const uint32_t overlay_pixel_count = OverlayPixelCount(histogram);
|
||||
EXPECT_GT(histogram[kParentBackgroundColor], 0u);
|
||||
EXPECT_GT(overlay_pixel_count, 0u);
|
||||
EXPECT_GT(histogram[kChildBackgroundColor], 0u);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"fuchsia.test": {
|
||||
"deprecated-allowed-packages": [
|
||||
"child-view",
|
||||
"flatland-scene-manager-test-ui-stack",
|
||||
"oot_flutter_aot_runner",
|
||||
"oot_flutter_jit_runner",
|
||||
"oot_flutter_jit_product_runner",
|
||||
|
||||
@@ -19,20 +19,16 @@ void main(List<String> args) async {
|
||||
args = args + _GetArgsFromConfigFile();
|
||||
final parser = ArgParser()
|
||||
..addFlag('showOverlay', defaultsTo: false)
|
||||
..addFlag('hitTestable', defaultsTo: true)
|
||||
..addFlag('focusable', defaultsTo: true)
|
||||
..addFlag('useFlatland', defaultsTo: false);
|
||||
..addFlag('focusable', defaultsTo: true);
|
||||
final arguments = parser.parse(args);
|
||||
for (final option in arguments.options) {
|
||||
print('parent-view: $option: ${arguments[option]}');
|
||||
}
|
||||
|
||||
TestApp app;
|
||||
final useFlatland = arguments['useFlatland'];
|
||||
app = TestApp(
|
||||
ChildView(await _launchChildView(useFlatland)),
|
||||
ChildView(await _launchChildView()),
|
||||
showOverlay: arguments['showOverlay'],
|
||||
hitTestable: arguments['hitTestable'],
|
||||
focusable: arguments['focusable'],
|
||||
);
|
||||
|
||||
@@ -45,18 +41,16 @@ class TestApp {
|
||||
|
||||
final ChildView childView;
|
||||
final bool showOverlay;
|
||||
final bool hitTestable;
|
||||
final bool focusable;
|
||||
|
||||
Color _backgroundColor = _blue;
|
||||
|
||||
TestApp(this.childView,
|
||||
{this.showOverlay = false,
|
||||
this.hitTestable = true,
|
||||
this.focusable = true}) {}
|
||||
|
||||
void run() {
|
||||
childView.create(hitTestable, focusable, (ByteData reply) {
|
||||
childView.create(focusable, (ByteData reply) {
|
||||
// Set up window allbacks.
|
||||
window.onPointerDataPacket = (PointerDataPacket packet) {
|
||||
for (final data in packet.data) {
|
||||
@@ -150,7 +144,7 @@ class ChildView {
|
||||
|
||||
ChildView(this.viewId);
|
||||
|
||||
void create(bool hitTestable, bool focusable,
|
||||
void create(bool focusable,
|
||||
PlatformMessageResponseCallback callback) {
|
||||
// Construct the dart:ui platform message to create the view, and when the
|
||||
// return callback is invoked, build the scene. At that point, it is safe
|
||||
@@ -159,7 +153,8 @@ class ChildView {
|
||||
|
||||
final Map<String, dynamic> args = <String, dynamic>{
|
||||
'viewId': viewId,
|
||||
'hitTestable': hitTestable,
|
||||
// Flatland doesn't support disabling hit testing.
|
||||
'hitTestable': true,
|
||||
'focusable': focusable,
|
||||
'viewOcclusionHintLTRB': <double>[
|
||||
viewOcclusionHint.left,
|
||||
@@ -182,8 +177,8 @@ class ChildView {
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> _launchChildView(bool useFlatland) async {
|
||||
final message = Int8List.fromList([useFlatland ? 0x31 : 0x30]);
|
||||
Future<int> _launchChildView() async {
|
||||
final message = Int8List.fromList([0x31]);
|
||||
final completer = new Completer<ByteData>();
|
||||
PlatformDispatcher.instance.sendPlatformMessage(
|
||||
'fuchsia/child_view', ByteData.sublistView(message), (ByteData reply) {
|
||||
|
||||
@@ -44,9 +44,7 @@ executable("text-input-test-bin") {
|
||||
"//build/fuchsia/fidl:fuchsia.ui.gfx",
|
||||
"//flutter/fml",
|
||||
"//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:check_view",
|
||||
"//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:color",
|
||||
"//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:portable_ui_test",
|
||||
"//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:screenshot",
|
||||
"//third_party/googletest:gtest",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
@@ -33,6 +33,7 @@ executable("touch-input-test-bin") {
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.net.interfaces",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.tracing.provider",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.app",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.display.singleton",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.input",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.pointerinjector",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.policy",
|
||||
|
||||
@@ -20,7 +20,6 @@ void main(List<String> args) async {
|
||||
args = args + _GetArgsFromConfigFile();
|
||||
final parser = ArgParser()
|
||||
..addFlag('showOverlay', defaultsTo: false)
|
||||
..addFlag('hitTestable', defaultsTo: true)
|
||||
..addFlag('focusable', defaultsTo: true);
|
||||
|
||||
final arguments = parser.parse(args);
|
||||
@@ -28,11 +27,9 @@ void main(List<String> args) async {
|
||||
print('embedding-flutter-view args: $option: ${arguments[option]}');
|
||||
}
|
||||
|
||||
// TODO(fxbug.dev/125514): Support Flatland Child View.
|
||||
TestApp app = TestApp(
|
||||
ChildView(await _launchChildView(false)),
|
||||
ChildView(await _launchChildView()),
|
||||
showOverlay: arguments['showOverlay'],
|
||||
hitTestable: arguments['hitTestable'],
|
||||
focusable: arguments['focusable'],
|
||||
);
|
||||
|
||||
@@ -45,7 +42,6 @@ class TestApp {
|
||||
|
||||
final ChildView childView;
|
||||
final bool showOverlay;
|
||||
final bool hitTestable;
|
||||
final bool focusable;
|
||||
|
||||
Color _backgroundColor = _blue;
|
||||
@@ -53,12 +49,11 @@ class TestApp {
|
||||
TestApp(
|
||||
this.childView,
|
||||
{this.showOverlay = false,
|
||||
this.hitTestable = true,
|
||||
this.focusable = true}) {
|
||||
}
|
||||
|
||||
void run() {
|
||||
childView.create(hitTestable, focusable, (ByteData reply) {
|
||||
childView.create(focusable, (ByteData reply) {
|
||||
// Set up window callbacks.
|
||||
window.onPointerDataPacket = (PointerDataPacket packet) {
|
||||
this.pointerDataPacket(packet);
|
||||
@@ -185,7 +180,6 @@ class ChildView {
|
||||
ChildView(this.viewId);
|
||||
|
||||
void create(
|
||||
bool hitTestable,
|
||||
bool focusable,
|
||||
PlatformMessageResponseCallback callback) {
|
||||
// Construct the dart:ui platform message to create the view, and when the
|
||||
@@ -194,7 +188,8 @@ class ChildView {
|
||||
final viewOcclusionHint = Rect.zero;
|
||||
final Map<String, dynamic> args = <String, dynamic>{
|
||||
'viewId': viewId,
|
||||
'hitTestable': hitTestable,
|
||||
// Flatland doesn't support disabling hit testing.
|
||||
'hitTestable': true,
|
||||
'focusable': focusable,
|
||||
'viewOcclusionHintLTRB': <double>[
|
||||
viewOcclusionHint.left,
|
||||
@@ -220,8 +215,8 @@ class ChildView {
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> _launchChildView(bool useFlatland) async {
|
||||
final message = Int8List.fromList([useFlatland ? 0x31 : 0x30]);
|
||||
Future<int> _launchChildView() async {
|
||||
final message = Int8List.fromList([0x31]);
|
||||
final completer = new Completer<ByteData>();
|
||||
PlatformDispatcher.instance.sendPlatformMessage(
|
||||
'fuchsia/child_view', ByteData.sublistView(message), (ByteData reply) {
|
||||
|
||||
@@ -55,7 +55,6 @@
|
||||
"fuchsia.test": {
|
||||
"deprecated-allowed-packages": [
|
||||
"embedding-flutter-view",
|
||||
"gfx-scene-manager-test-ui-stack",
|
||||
"flatland-scene-manager-test-ui-stack",
|
||||
"oot_flutter_aot_runner",
|
||||
"oot_flutter_jit_runner",
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include <fuchsia/sysmem/cpp/fidl.h>
|
||||
#include <fuchsia/tracing/provider/cpp/fidl.h>
|
||||
#include <fuchsia/ui/app/cpp/fidl.h>
|
||||
#include <fuchsia/ui/display/singleton/cpp/fidl.h>
|
||||
#include <fuchsia/ui/input/cpp/fidl.h>
|
||||
#include <fuchsia/ui/policy/cpp/fidl.h>
|
||||
#include <fuchsia/ui/scenic/cpp/fidl.h>
|
||||
#include <fuchsia/ui/test/input/cpp/fidl.h>
|
||||
#include <fuchsia/ui/test/scene/cpp/fidl.h>
|
||||
#include <fuchsia/web/cpp/fidl.h>
|
||||
@@ -26,9 +26,6 @@
|
||||
#include <lib/sys/component/cpp/testing/realm_builder.h>
|
||||
#include <lib/sys/component/cpp/testing/realm_builder_types.h>
|
||||
#include <lib/sys/cpp/component_context.h>
|
||||
#include <lib/ui/scenic/cpp/resources.h>
|
||||
#include <lib/ui/scenic/cpp/session.h>
|
||||
#include <lib/ui/scenic/cpp/view_token_pair.h>
|
||||
#include <lib/zx/clock.h>
|
||||
#include <lib/zx/time.h>
|
||||
#include <zircon/status.h>
|
||||
@@ -127,9 +124,6 @@ using RealmBuilder = component_testing::RealmBuilder;
|
||||
// Set this as low as you can that still works across all test platforms.
|
||||
constexpr zx::duration kTimeout = zx::min(1);
|
||||
|
||||
constexpr auto kGfxTestUIStackUrl =
|
||||
"fuchsia-pkg://fuchsia.com/gfx-scene-manager-test-ui-stack#meta/"
|
||||
"test-ui-stack.cm";
|
||||
constexpr auto kTestUIStackUrl =
|
||||
"fuchsia-pkg://fuchsia.com/flatland-scene-manager-test-ui-stack#meta/"
|
||||
"test-ui-stack.cm";
|
||||
@@ -205,9 +199,7 @@ class TouchInputListenerServer
|
||||
events_received_;
|
||||
};
|
||||
|
||||
class FlutterTapTestBase : public PortableUITest,
|
||||
public ::testing::Test,
|
||||
public ::testing::WithParamInterface<std::string> {
|
||||
class FlutterTapTestBase : public PortableUITest, public ::testing::Test {
|
||||
protected:
|
||||
~FlutterTapTestBase() override {
|
||||
FML_CHECK(touch_injection_request_count() > 0)
|
||||
@@ -226,17 +218,22 @@ class FlutterTapTestBase : public PortableUITest,
|
||||
},
|
||||
kTimeout);
|
||||
|
||||
// Get the display dimensions.
|
||||
// Get the display information using the
|
||||
// |fuchsia.ui.display.singleton.Info|.
|
||||
FML_LOG(INFO) << "Waiting for scenic display info";
|
||||
scenic_ = realm_root()->component().Connect<fuchsia::ui::scenic::Scenic>();
|
||||
scenic_->GetDisplayInfo([this](fuchsia::ui::gfx::DisplayInfo display_info) {
|
||||
display_width_ = display_info.width_in_px;
|
||||
display_height_ = display_info.height_in_px;
|
||||
FML_LOG(INFO) << "Got display_width = " << display_width_
|
||||
<< " and display_height = " << display_height_;
|
||||
std::optional<bool> display_metrics_obtained;
|
||||
fuchsia::ui::display::singleton::InfoPtr display_info =
|
||||
realm_root()
|
||||
->component()
|
||||
.Connect<fuchsia::ui::display::singleton::Info>();
|
||||
display_info->GetMetrics([this, &display_metrics_obtained](auto info) {
|
||||
display_width_ = info.extent_in_px().width;
|
||||
display_height_ = info.extent_in_px().height;
|
||||
display_metrics_obtained = true;
|
||||
});
|
||||
RunLoopUntil([&display_metrics_obtained] {
|
||||
return display_metrics_obtained.has_value();
|
||||
});
|
||||
RunLoopUntil(
|
||||
[this] { return display_width_ != 0 && display_height_ != 0; });
|
||||
|
||||
// Register input injection device.
|
||||
FML_LOG(INFO) << "Registering input injection device";
|
||||
@@ -287,7 +284,7 @@ class FlutterTapTestBase : public PortableUITest,
|
||||
uint32_t display_width() const { return display_width_; }
|
||||
uint32_t display_height() const { return display_height_; }
|
||||
|
||||
ParamType GetTestUIStackUrl() override { return GetParam(); };
|
||||
std::string GetTestUIStackUrl() override { return kTestUIStackUrl; };
|
||||
|
||||
TouchInputListenerServer* touch_input_listener_server_;
|
||||
};
|
||||
@@ -345,17 +342,22 @@ class FlutterEmbedTapTest : public FlutterTapTestBase {
|
||||
void LaunchClientWithEmbeddedView() {
|
||||
BuildRealm();
|
||||
|
||||
// Get the display dimensions.
|
||||
// Get the display information using the
|
||||
// |fuchsia.ui.display.singleton.Info|.
|
||||
FML_LOG(INFO) << "Waiting for scenic display info";
|
||||
scenic_ = realm_root()->component().Connect<fuchsia::ui::scenic::Scenic>();
|
||||
scenic_->GetDisplayInfo([this](fuchsia::ui::gfx::DisplayInfo display_info) {
|
||||
display_width_ = display_info.width_in_px;
|
||||
display_height_ = display_info.height_in_px;
|
||||
FML_LOG(INFO) << "Got display_width = " << display_width_
|
||||
<< " and display_height = " << display_height_;
|
||||
std::optional<bool> display_metrics_obtained;
|
||||
fuchsia::ui::display::singleton::InfoPtr display_info =
|
||||
realm_root()
|
||||
->component()
|
||||
.Connect<fuchsia::ui::display::singleton::Info>();
|
||||
display_info->GetMetrics([this, &display_metrics_obtained](auto info) {
|
||||
display_width_ = info.extent_in_px().width;
|
||||
display_height_ = info.extent_in_px().height;
|
||||
display_metrics_obtained = true;
|
||||
});
|
||||
RunLoopUntil([&display_metrics_obtained] {
|
||||
return display_metrics_obtained.has_value();
|
||||
});
|
||||
RunLoopUntil(
|
||||
[this] { return display_width_ != 0 && display_height_ != 0; });
|
||||
|
||||
// Register input injection device.
|
||||
FML_LOG(INFO) << "Registering input injection device";
|
||||
@@ -424,16 +426,7 @@ class FlutterEmbedTapTest : public FlutterTapTestBase {
|
||||
}
|
||||
};
|
||||
|
||||
// Makes use of gtest's parameterized testing, allowing us
|
||||
// to test different combinations of test-ui-stack + runners. Currently, there
|
||||
// are both GFX and Flatland variants. Documentation:
|
||||
// http://go/gunitadvanced#value-parameterized-tests
|
||||
INSTANTIATE_TEST_SUITE_P(FlutterTapTestParameterized,
|
||||
FlutterTapTest,
|
||||
::testing::Values(kGfxTestUIStackUrl,
|
||||
kTestUIStackUrl));
|
||||
|
||||
TEST_P(FlutterTapTest, FlutterTap) {
|
||||
TEST_F(FlutterTapTest, FlutterTap) {
|
||||
// Launch client view, and wait until it's rendering to proceed with the test.
|
||||
FML_LOG(INFO) << "Initializing scene";
|
||||
LaunchClient();
|
||||
@@ -457,13 +450,7 @@ TEST_P(FlutterTapTest, FlutterTap) {
|
||||
ASSERT_EQ(touch_injection_request_count(), 1);
|
||||
}
|
||||
|
||||
// TODO(fxbug.dev/125514): Embedded Child View needs to support Flatland.
|
||||
// Only test GFX Test UI stack for embedded test cases for now.
|
||||
INSTANTIATE_TEST_SUITE_P(FlutterEmbedTapTestParameterized,
|
||||
FlutterEmbedTapTest,
|
||||
::testing::Values(kGfxTestUIStackUrl));
|
||||
|
||||
TEST_P(FlutterEmbedTapTest, FlutterEmbedTap) {
|
||||
TEST_F(FlutterEmbedTapTest, FlutterEmbedTap) {
|
||||
// Launch view
|
||||
FML_LOG(INFO) << "Initializing scene";
|
||||
LaunchClientWithEmbeddedView();
|
||||
@@ -497,29 +484,7 @@ TEST_P(FlutterEmbedTapTest, FlutterEmbedTap) {
|
||||
ASSERT_EQ(touch_injection_request_count(), 2);
|
||||
}
|
||||
|
||||
TEST_P(FlutterEmbedTapTest, FlutterEmbedHittestDisabled) {
|
||||
FML_LOG(INFO) << "Initializing scene";
|
||||
AddComponentArgument("--no-hitTestable");
|
||||
LaunchClientWithEmbeddedView();
|
||||
FML_LOG(INFO) << "Client launched";
|
||||
|
||||
// Embedded child view takes up the center of the screen
|
||||
// hitTestable is turned off for the embedded child view
|
||||
// Expect the parent (embedding-flutter-view) to respond if we inject a tap
|
||||
// there
|
||||
InjectTap(0, 0);
|
||||
RunLoopUntil([this] {
|
||||
return LastEventReceivedMatches(
|
||||
/*expected_x=*/static_cast<float>(display_width() / 2.0f),
|
||||
/*expected_y=*/static_cast<float>(display_height() / 2.0f),
|
||||
/*component_name=*/"embedding-flutter-view");
|
||||
});
|
||||
|
||||
// There should be 1 injected tap
|
||||
ASSERT_EQ(touch_injection_request_count(), 1);
|
||||
}
|
||||
|
||||
TEST_P(FlutterEmbedTapTest, FlutterEmbedOverlayEnabled) {
|
||||
TEST_F(FlutterEmbedTapTest, FlutterEmbedOverlayEnabled) {
|
||||
FML_LOG(INFO) << "Initializing scene";
|
||||
AddComponentArgument("--showOverlay");
|
||||
LaunchClientWithEmbeddedView();
|
||||
|
||||
@@ -19,13 +19,6 @@ source_set("check_view") {
|
||||
]
|
||||
}
|
||||
|
||||
source_set("color") {
|
||||
sources = [
|
||||
"color.cc",
|
||||
"color.h",
|
||||
]
|
||||
}
|
||||
|
||||
source_set("screenshot") {
|
||||
sources = [
|
||||
"screenshot.cc",
|
||||
@@ -33,9 +26,7 @@ source_set("screenshot") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
":color",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.logger",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.scenic",
|
||||
"$fuchsia_sdk_root/pkg:zx",
|
||||
"//flutter/fml",
|
||||
]
|
||||
@@ -50,7 +41,9 @@ source_set("portable_ui_test") {
|
||||
|
||||
deps = [
|
||||
":check_view",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.logger",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.app",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.display.singleton",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.input",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.observation.geometry",
|
||||
"$fuchsia_sdk_root/fidl:fuchsia.ui.policy",
|
||||
|
||||
@@ -1,17 +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 "color.h"
|
||||
|
||||
namespace fuchsia_test_utils {
|
||||
|
||||
// RGBA hex dump
|
||||
std::ostream& operator<<(std::ostream& os, const Color& c) {
|
||||
char rgba[9] = {};
|
||||
snprintf(rgba, (sizeof(rgba) / sizeof(char)), "%02X%02X%02X%02X", c.r, c.g,
|
||||
c.b, c.a);
|
||||
return os << rgba;
|
||||
}
|
||||
|
||||
} // namespace fuchsia_test_utils
|
||||
@@ -1,38 +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_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_COLOR_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_COLOR_H_
|
||||
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <tuple>
|
||||
|
||||
namespace fuchsia_test_utils {
|
||||
|
||||
struct Color {
|
||||
// Constructor is idiomatic RGBA, but memory layout is native BGRA.
|
||||
constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||
: b(b), g(g), r(r), a(a) {}
|
||||
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
uint8_t a;
|
||||
};
|
||||
|
||||
inline bool operator==(const Color& a, const Color& b) {
|
||||
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
||||
}
|
||||
|
||||
inline bool operator<(const Color& a, const Color& b) {
|
||||
return std::tie(a.r, a.g, a.b, a.a) < std::tie(b.r, b.g, b.b, b.a);
|
||||
}
|
||||
|
||||
// RGBA hex dump. Note that this differs from the internal BGRA memory layout.
|
||||
std::ostream& operator<<(std::ostream& os, const Color& c);
|
||||
|
||||
} // namespace fuchsia_test_utils
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_COLOR_H_
|
||||
@@ -93,6 +93,7 @@ void PortableUITest::SetUpRealmBase() {
|
||||
Protocol{fuchsia::ui::scenic::Scenic::Name_},
|
||||
Protocol{fuchsia::ui::test::input::Registry::Name_},
|
||||
Protocol{fuchsia::ui::test::scene::Controller::Name_},
|
||||
Protocol{fuchsia::ui::display::singleton::Info::Name_},
|
||||
Protocol{kPointerInjectorRegistryName}},
|
||||
.source = kTestUIStackRef,
|
||||
.targets = {ParentRef(), kFlutterJitRunnerRef}});
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <fuchsia/sysmem/cpp/fidl.h>
|
||||
#include <fuchsia/ui/app/cpp/fidl.h>
|
||||
#include <fuchsia/ui/display/singleton/cpp/fidl.h>
|
||||
#include <fuchsia/ui/input/cpp/fidl.h>
|
||||
#include <fuchsia/ui/policy/cpp/fidl.h>
|
||||
#include <fuchsia/ui/scenic/cpp/fidl.h>
|
||||
|
||||
@@ -4,67 +4,102 @@
|
||||
|
||||
#include "screenshot.h"
|
||||
|
||||
#include <zircon/status.h>
|
||||
#include <lib/zx/vmar.h>
|
||||
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace fuchsia_test_utils {
|
||||
namespace {
|
||||
constexpr uint64_t kBytesPerPixel = 4;
|
||||
} // namespace
|
||||
|
||||
Screenshot::Screenshot(
|
||||
const fuchsia::ui::scenic::ScreenshotData& screenshot_data)
|
||||
: width_(screenshot_data.info.width), height_(screenshot_data.info.height) {
|
||||
FML_CHECK(screenshot_data.info.pixel_format ==
|
||||
fuchsia::images::PixelFormat::BGRA_8)
|
||||
<< "Non-BGRA_8 pixel formats not supported";
|
||||
|
||||
const auto& buffer = screenshot_data.data.vmo;
|
||||
const auto num_bytes = screenshot_data.data.size;
|
||||
|
||||
data_.resize(num_bytes);
|
||||
|
||||
if (num_bytes == 0) {
|
||||
return;
|
||||
Screenshot::Screenshot(const zx::vmo& screenshot_vmo,
|
||||
uint64_t width,
|
||||
uint64_t height,
|
||||
int rotation)
|
||||
: width_(width), height_(height) {
|
||||
FML_CHECK(rotation == 0 || rotation == 90 || rotation == 270);
|
||||
if (rotation == 90 || rotation == 270) {
|
||||
std::swap(width_, height_);
|
||||
}
|
||||
// Populate |screenshot_| from |screenshot_vmo|.
|
||||
uint64_t vmo_size;
|
||||
screenshot_vmo.get_prop_content_size(&vmo_size);
|
||||
FML_CHECK(vmo_size == kBytesPerPixel * width_ * height_);
|
||||
uint8_t* vmo_host = nullptr;
|
||||
auto status = zx::vmar::root_self()->map(
|
||||
ZX_VM_PERM_READ, /*vmar_offset*/ 0, screenshot_vmo,
|
||||
/*vmo_offset*/ 0, vmo_size, reinterpret_cast<uintptr_t*>(&vmo_host));
|
||||
FML_CHECK(status == ZX_OK);
|
||||
ExtractScreenshotFromVMO(vmo_host);
|
||||
// map the pointer.
|
||||
uintptr_t address = reinterpret_cast<uintptr_t>(vmo_host);
|
||||
status = zx::vmar::root_self()->unmap(address, vmo_size);
|
||||
FML_CHECK(status == ZX_OK);
|
||||
}
|
||||
|
||||
zx_status_t status = buffer.read(&data_[0], 0, num_bytes);
|
||||
if (status < 0) {
|
||||
FML_LOG(WARNING) << "zx::vmo::read failed " << zx_status_get_string(status);
|
||||
std::ostream& operator<<(std::ostream& stream, const Pixel& pixel) {
|
||||
return stream << "{Pixel:"
|
||||
<< " r:" << static_cast<unsigned int>(pixel.red)
|
||||
<< " g:" << static_cast<unsigned int>(pixel.green)
|
||||
<< " b:" << static_cast<unsigned int>(pixel.blue)
|
||||
<< " a:" << static_cast<unsigned int>(pixel.alpha) << "}";
|
||||
}
|
||||
|
||||
Pixel Screenshot::GetPixelAt(uint64_t x, uint64_t y) const {
|
||||
FML_CHECK(x >= 0 && x < width_ && y >= 0 && y < height_)
|
||||
<< "Index out of bounds";
|
||||
return screenshot_[y][x];
|
||||
}
|
||||
|
||||
std::map<Pixel, uint32_t> Screenshot::Histogram() const {
|
||||
std::map<Pixel, uint32_t> histogram;
|
||||
FML_CHECK(screenshot_.size() == height_ && screenshot_[0].size() == width_);
|
||||
for (size_t i = 0; i < height_; i++) {
|
||||
for (size_t j = 0; j < width_; j++) {
|
||||
histogram[screenshot_[i][j]]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Color* Screenshot::operator[](size_t row) const {
|
||||
return &begin()[row * width_];
|
||||
}
|
||||
|
||||
const Color& Screenshot::ColorAt(float x, float y) const {
|
||||
FML_CHECK(x >= 0 && x < 1 && y >= 0 && y < 1)
|
||||
<< "(" << x << ", " << y << ") is out of bounds [0, 1) x [0, 1)";
|
||||
const size_t ix = static_cast<size_t>(x * static_cast<float>(width_));
|
||||
const size_t iy = static_cast<size_t>(y * static_cast<float>(height_));
|
||||
return (*this)[iy][ix];
|
||||
}
|
||||
|
||||
const Color& Screenshot::ColorAtPixelXY(size_t ix, size_t iy) const {
|
||||
FML_CHECK(ix < width_ && iy < height_);
|
||||
return (*this)[iy][ix];
|
||||
}
|
||||
|
||||
const Color* Screenshot::begin() const {
|
||||
return reinterpret_cast<const Color*>(data_.data());
|
||||
}
|
||||
|
||||
const Color* Screenshot::end() const {
|
||||
return &begin()[width_ * height_];
|
||||
}
|
||||
|
||||
std::map<Color, size_t> Screenshot::Histogram() const {
|
||||
std::map<Color, size_t> histogram;
|
||||
|
||||
for (const auto color : *this) {
|
||||
++histogram[color];
|
||||
}
|
||||
|
||||
return histogram;
|
||||
}
|
||||
|
||||
void Screenshot::ExtractScreenshotFromVMO(uint8_t* screenshot_vmo) {
|
||||
FML_CHECK(screenshot_vmo);
|
||||
for (size_t i = 0; i < height_; i++) {
|
||||
// The head index of the ith row in the screenshot is |i* width_*
|
||||
// KbytesPerPixel|.
|
||||
screenshot_.push_back(GetPixelsInRow(screenshot_vmo, i));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Pixel> Screenshot::GetPixelsInRow(uint8_t* screenshot_vmo,
|
||||
size_t row_index) {
|
||||
std::vector<Pixel> row;
|
||||
for (size_t col_idx = 0;
|
||||
col_idx < static_cast<size_t>(width_ * kBytesPerPixel);
|
||||
col_idx += kBytesPerPixel) {
|
||||
// Each row in the screenshot has |kBytesPerPixel * width_| elements.
|
||||
// Therefore in order to reach the first pixel of the |row_index| row, we
|
||||
// have to jump |row_index * width_ * kBytesPerPixel| positions.
|
||||
auto pixel_start_index = row_index * width_ * kBytesPerPixel;
|
||||
// Every |kBytesPerPixel| bytes represents the BGRA values of a pixel. Skip
|
||||
// |kBytesPerPixel| bytes to get to the BGRA values of the next pixel. Each
|
||||
// row in a screenshot has |kBytesPerPixel * width_| bytes of data.
|
||||
// Example:-
|
||||
// auto data = TakeScreenshot();
|
||||
// data[0-3] -> RGBA of pixel 0.
|
||||
// data[4-7] -> RGBA pf pixel 1.
|
||||
row.emplace_back(screenshot_vmo[pixel_start_index + col_idx],
|
||||
screenshot_vmo[pixel_start_index + col_idx + 1],
|
||||
screenshot_vmo[pixel_start_index + col_idx + 2],
|
||||
screenshot_vmo[pixel_start_index + col_idx + 3]);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
} // namespace fuchsia_test_utils
|
||||
|
||||
@@ -5,52 +5,106 @@
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_SCREENSHOT_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_SCREENSHOT_H_
|
||||
|
||||
#include <fuchsia/ui/scenic/cpp/fidl.h>
|
||||
#include <lib/zx/vmo.h>
|
||||
#include <zircon/status.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <tuple>
|
||||
|
||||
#include "color.h"
|
||||
#include <vector>
|
||||
|
||||
namespace fuchsia_test_utils {
|
||||
// Represents a Pixel in BGRA format.
|
||||
// Uses the sRGB color space.
|
||||
struct Pixel {
|
||||
uint8_t blue = 0;
|
||||
uint8_t green = 0;
|
||||
uint8_t red = 0;
|
||||
uint8_t alpha = 0;
|
||||
|
||||
/// A screenshot that has been taken from a Fuchsia device.
|
||||
Pixel(uint8_t blue, uint8_t green, uint8_t red, uint8_t alpha)
|
||||
: blue(blue), green(green), red(red), alpha(alpha) {}
|
||||
|
||||
bool operator==(const Pixel& rhs) const {
|
||||
return blue == rhs.blue && green == rhs.green && red == rhs.red &&
|
||||
alpha == rhs.alpha;
|
||||
}
|
||||
|
||||
inline bool operator!=(const Pixel& rhs) const { return !(*this == rhs); }
|
||||
|
||||
bool operator<(const Pixel& other) const {
|
||||
return std::tie(blue, green, red, alpha) <
|
||||
std::tie(other.blue, other.green, other.red, other.alpha);
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Pixel& pixel);
|
||||
|
||||
// Helper class to get information about a screenshot returned by
|
||||
// |fuchsia.ui.composition.Screenshot| protocol.
|
||||
class Screenshot {
|
||||
public:
|
||||
Screenshot(const fuchsia::ui::scenic::ScreenshotData& screenshot_data);
|
||||
// BGRA format.
|
||||
inline static const Pixel kBlack = Pixel(0, 0, 0, 255);
|
||||
inline static const Pixel kBlue = Pixel(255, 0, 0, 255);
|
||||
inline static const Pixel kRed = Pixel(0, 0, 255, 255);
|
||||
inline static const Pixel kMagenta = Pixel(255, 0, 255, 255);
|
||||
inline static const Pixel kGreen = Pixel(0, 255, 0, 255);
|
||||
|
||||
size_t width() const { return width_; }
|
||||
size_t height() const { return height_; }
|
||||
bool empty() const { return width_ == 0 || height_ == 0; }
|
||||
// Params:-
|
||||
// |screenshot_vmo| - The VMO returned by
|
||||
// fuchsia.ui.composition.Screenshot.Take representing the screenshot data.
|
||||
// |width|, |height| - Width and height of the physical display in pixels as
|
||||
// returned by |fuchsia.ui.display.singleton.Info|.
|
||||
// |rotation| - The display rotation value in degrees. The width and the
|
||||
// height of the screenshot are flipped if this value is 90 or 270 degrees,
|
||||
// as the screenshot shows how content is seen by the user.
|
||||
Screenshot(const zx::vmo& screenshot_vmo,
|
||||
uint64_t width,
|
||||
uint64_t height,
|
||||
int rotation);
|
||||
|
||||
// Notably the indexer behaves like a row-major matrix, whereas the iterator
|
||||
// behaves like a flat array. *IMPORTANT*: Use caution because index values
|
||||
// are not validated, and out of bounds indexes can introduce memory errors.
|
||||
// Also when indexing a specific pixel with |screenshot[a][b]|, note that
|
||||
// the order of the indexes is non-traditional. The first index is for the
|
||||
// |y| position (the row), followed by the |x| position. Consider using
|
||||
// |ColorAtPixelXY()| instead.
|
||||
const Color* operator[](size_t row) const;
|
||||
|
||||
// Coordinates are in the range [0, 1).
|
||||
const Color& ColorAt(float x, float y) const;
|
||||
|
||||
// Returns the color of a pixel at the integer x and y indexes, after
|
||||
// asserting that the indexes are in range.
|
||||
const Color& ColorAtPixelXY(size_t ix, size_t iy) const;
|
||||
|
||||
// Notably the iterator behaves like a flat array, whereas the indexer behaves
|
||||
// like a row-major matrix.
|
||||
const Color* begin() const;
|
||||
const Color* end() const;
|
||||
// Returns the |Pixel| located at (x,y) coordinates. |x| and |y| should range
|
||||
// from [0,width_) and [0,height_) respectively.
|
||||
//
|
||||
// (0,0)________________width_____________(w-1,0)
|
||||
// | | |
|
||||
// | | y |h
|
||||
// | x | |e
|
||||
// |-----------------------X |i
|
||||
// | |g
|
||||
// | |h
|
||||
// | |t
|
||||
// |_________________________________|
|
||||
// (0,h-1) screenshot (w-1,h-1)
|
||||
//
|
||||
// Clients should only use this function to get the pixel data.
|
||||
Pixel GetPixelAt(uint64_t x, uint64_t y) const;
|
||||
|
||||
// Counts the frequencies of each color in a screenshot.
|
||||
std::map<Color, size_t> Histogram() const;
|
||||
std::map<Pixel, uint32_t> Histogram() const;
|
||||
|
||||
// Returns a 2D vector of size |height_ * width_|. Each value in the vector
|
||||
// corresponds to a pixel in the screenshot.
|
||||
std::vector<std::vector<Pixel>> screenshot() const { return screenshot_; }
|
||||
|
||||
uint64_t width() const { return width_; }
|
||||
|
||||
uint64_t height() const { return height_; }
|
||||
|
||||
private:
|
||||
const size_t width_, height_;
|
||||
std::vector<uint8_t> data_;
|
||||
// Populates |screenshot_| by converting the linear array of bytes in
|
||||
// |screenshot_vmo| of size |kBytesPerPixel * width_ * height_| to a 2D vector
|
||||
// of |Pixel|s of size |height_ * width_|.
|
||||
void ExtractScreenshotFromVMO(uint8_t* screenshot_vmo);
|
||||
|
||||
// Returns the |Pixel|s in the |row_index| row of the screenshot.
|
||||
std::vector<Pixel> GetPixelsInRow(uint8_t* screenshot_vmo, size_t row_index);
|
||||
|
||||
uint64_t width_ = 0;
|
||||
uint64_t height_ = 0;
|
||||
std::vector<std::vector<Pixel>> screenshot_;
|
||||
};
|
||||
|
||||
} // namespace fuchsia_test_utils
|
||||
|
||||
Reference in New Issue
Block a user