This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[fuchsia] embedding-flutter test #37052
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bb62e43
Add embedding-flutter test
lin-erik 2c47fab
Lint CC files
lin-erik 80c7624
GN formatting
lin-erik 88334b7
Remove changes to embedder
lin-erik 4e94503
Minor refactor
lin-erik b8956ff
Remove unused dependencies
lin-erik 5e6a55a
Lint CC files
lin-erik 816efc6
Remove comments
lin-erik de300d9
Merge branch 'main' into embedding-flutter-test
lin-erik de075cf
Rename pubspec
lin-erik 972cb74
Merge branch 'main' into embedding-flutter-test
lin-erik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
shell/platform/fuchsia/flutter/tests/integration/touch-input/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
shell/platform/fuchsia/flutter/tests/integration/touch-input/embedding-flutter-view/BUILD.gn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # 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. | ||
|
|
||
| import("//build/fuchsia/sdk.gni") | ||
| import("//flutter/tools/fuchsia/dart/dart_library.gni") | ||
| import("//flutter/tools/fuchsia/flutter/flutter_component.gni") | ||
| import("//flutter/tools/fuchsia/gn-sdk/component.gni") | ||
| import("//flutter/tools/fuchsia/gn-sdk/package.gni") | ||
|
|
||
| dart_library("lib") { | ||
| package_name = "embedding-flutter-view" | ||
| sources = [ "embedding-flutter-view.dart" ] | ||
|
|
||
| deps = [ | ||
| "//flutter/tools/fuchsia/dart:fuchsia_services", | ||
| "//flutter/tools/fuchsia/dart:zircon", | ||
| "//flutter/tools/fuchsia/fidl:fuchsia.ui.app", | ||
| "//flutter/tools/fuchsia/fidl:fuchsia.ui.scenic", | ||
| "//flutter/tools/fuchsia/fidl:fuchsia.ui.test.input", | ||
| "//flutter/tools/fuchsia/fidl:fuchsia.ui.views", | ||
| ] | ||
| } | ||
|
|
||
| flutter_component("component") { | ||
| testonly = true | ||
| component_name = "embedding-flutter-view" | ||
| manifest = rebase_path("meta/embedding-flutter-view.cml") | ||
| main_package = "embedding-flutter-view" | ||
| main_dart = "embedding-flutter-view.dart" | ||
|
|
||
| deps = [ ":lib" ] | ||
| } | ||
|
|
||
| fuchsia_package("package") { | ||
| testonly = true | ||
| package_name = "embedding-flutter-view" | ||
|
|
||
| deps = [ ":component" ] | ||
| } |
175 changes: 175 additions & 0 deletions
175
...tter/tests/integration/touch-input/embedding-flutter-view/lib/embedding-flutter-view.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| // 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. | ||
|
|
||
| import 'dart:convert'; | ||
| import 'dart:typed_data'; | ||
| import 'dart:io'; | ||
| import 'dart:ui'; | ||
|
|
||
| import 'package:fidl_fuchsia_ui_app/fidl_async.dart'; | ||
| import 'package:fidl_fuchsia_ui_views/fidl_async.dart'; | ||
| import 'package:fidl_fuchsia_ui_test_input/fidl_async.dart' as test_touch; | ||
| import 'package:fuchsia_services/services.dart'; | ||
| import 'package:zircon/zircon.dart'; | ||
|
|
||
| void main(List<String> args) { | ||
| print('Launching embedding-flutter-view'); | ||
| TestApp app = TestApp(ChildView.gfx(_launchGfxChildView())); | ||
| app.run(); | ||
| } | ||
|
|
||
| class TestApp { | ||
| static const _black = Color.fromARGB(255, 0, 0, 0); | ||
| static const _blue = Color.fromARGB(255, 0, 0, 255); | ||
|
|
||
| final ChildView childView; | ||
| final _responseListener = test_touch.TouchInputListenerProxy(); | ||
|
|
||
| Color _backgroundColor = _blue; | ||
|
|
||
| TestApp(this.childView) {} | ||
|
|
||
| void run() { | ||
| childView.create((ByteData reply) { | ||
| // Set up window callbacks. | ||
| window.onPointerDataPacket = (PointerDataPacket packet) { | ||
| this.pointerDataPacket(packet); | ||
| }; | ||
| window.onMetricsChanged = () { | ||
| window.scheduleFrame(); | ||
| }; | ||
| window.onBeginFrame = (Duration duration) { | ||
| this.beginFrame(duration); | ||
| }; | ||
|
|
||
| // The child view should be attached to Scenic now. | ||
| // Ready to build the scene. | ||
| window.scheduleFrame(); | ||
| }); | ||
| } | ||
|
|
||
| void beginFrame(Duration duration) { | ||
| // Convert physical screen size of device to values | ||
| final pixelRatio = window.devicePixelRatio; | ||
| final size = window.physicalSize / pixelRatio; | ||
| final physicalBounds = Offset.zero & window.physicalSize; | ||
| final windowBounds = Offset.zero & size; | ||
| // Set up a Canvas that uses the screen size | ||
| final recorder = PictureRecorder(); | ||
| final canvas = Canvas(recorder, physicalBounds); | ||
| canvas.scale(pixelRatio); | ||
| // Draw something | ||
| final paint = Paint()..color = this._backgroundColor; | ||
| canvas.drawRect(windowBounds, paint); | ||
| final picture = recorder.endRecording(); | ||
| // Build the scene | ||
| final sceneBuilder = SceneBuilder() | ||
| ..pushClipRect(physicalBounds) | ||
| ..addPicture(Offset.zero, picture); | ||
| // Child view should take up half the screen | ||
| final childPhysicalSize = window.physicalSize * 0.5; | ||
| sceneBuilder | ||
| ..addPlatformView(childView.viewId, | ||
| width: childPhysicalSize.width, | ||
| height: size.height) | ||
| ..pop(); | ||
| sceneBuilder.pop(); | ||
| window.render(sceneBuilder.build()); | ||
| } | ||
|
|
||
| void pointerDataPacket(PointerDataPacket packet) async { | ||
| int nowNanos = System.clockGetMonotonic(); | ||
|
|
||
| for (PointerData data in packet.data) { | ||
| print('embedding-flutter-view received tap: ${data.toStringFull()}'); | ||
|
|
||
| if (data.change == PointerChange.down) { | ||
| this._backgroundColor = _black; | ||
| } | ||
|
|
||
| if (data.change == PointerChange.down || data.change == PointerChange.move) { | ||
| Incoming.fromSvcPath() | ||
| ..connectToService(_responseListener) | ||
| ..close(); | ||
|
|
||
| _respond(test_touch.TouchInputListenerReportTouchInputRequest( | ||
| localX: data.physicalX, | ||
| localY: data.physicalY, | ||
| timeReceived: nowNanos, | ||
| componentName: 'embedding-flutter-view', | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| window.scheduleFrame(); | ||
| } | ||
|
|
||
| void _respond(test_touch.TouchInputListenerReportTouchInputRequest request) async { | ||
| print('embedding-flutter-view reporting touch input to TouchInputListener'); | ||
| await _responseListener.reportTouchInput(request); | ||
| } | ||
| } | ||
|
|
||
| class ChildView { | ||
| final ViewHolderToken viewHolderToken; | ||
| final ViewportCreationToken viewportCreationToken; | ||
| final int viewId; | ||
|
|
||
| ChildView(this.viewportCreationToken) : viewHolderToken = null, viewId = viewportCreationToken.value.handle.handle { | ||
| assert(viewId != null); | ||
| } | ||
|
|
||
| ChildView.gfx(this.viewHolderToken) : viewportCreationToken = null, viewId = viewHolderToken.value.handle.handle { | ||
| assert(viewId != null); | ||
| } | ||
|
|
||
| void create(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 | ||
| // to embed the child view in the scene. | ||
| final viewOcclusionHint = Rect.zero; | ||
| final Map<String, dynamic> args = <String, dynamic>{ | ||
| 'viewId': viewId, | ||
| 'hitTestable': true, | ||
| 'focusable': true, | ||
| 'viewOcclusionHintLTRB': <double>[ | ||
| viewOcclusionHint.left, | ||
| viewOcclusionHint.top, | ||
| viewOcclusionHint.right, | ||
| viewOcclusionHint.bottom | ||
| ], | ||
| }; | ||
|
|
||
| final ByteData createViewMessage = utf8.encoder.convert( | ||
| json.encode(<String, Object>{ | ||
| 'method': 'View.create', | ||
| 'args': args, | ||
| }) | ||
| ).buffer.asByteData(); | ||
|
|
||
| final platformViewsChannel = 'flutter/platform_views'; | ||
|
|
||
| PlatformDispatcher.instance.sendPlatformMessage( | ||
| platformViewsChannel, | ||
| createViewMessage, | ||
| callback); | ||
| } | ||
| } | ||
|
|
||
| ViewHolderToken _launchGfxChildView() { | ||
| ViewProviderProxy viewProvider = ViewProviderProxy(); | ||
| Incoming.fromSvcPath() | ||
| ..connectToService(viewProvider) | ||
| ..close(); | ||
|
|
||
| final viewTokens = EventPairPair(); | ||
| assert(viewTokens.status == ZX.OK); | ||
| final viewHolderToken = ViewHolderToken(value: viewTokens.first); | ||
| final viewToken = ViewToken(value: viewTokens.second); | ||
|
|
||
| viewProvider.createView(viewToken.value, null, null); | ||
| viewProvider.ctrl.close(); | ||
|
|
||
| return viewHolderToken; | ||
| } |
38 changes: 38 additions & 0 deletions
38
...tter/tests/integration/touch-input/embedding-flutter-view/meta/embedding-flutter-view.cml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // 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: [ "syslog/client.shard.cml" ], | ||
| program: { | ||
| data: "data/embedding-flutter-view", | ||
|
|
||
| // Always use the jit runner for now. | ||
| // TODO(fxbug.dev/106577): Implement manifest merging build rules for V2 components. | ||
| runner: "flutter_jit_runner", | ||
| }, | ||
| capabilities: [ | ||
| { | ||
| protocol: [ "fuchsia.ui.app.ViewProvider" ], | ||
| }, | ||
| ], | ||
| expose: [ | ||
| { | ||
| protocol: [ "fuchsia.ui.app.ViewProvider" ], | ||
| from: "self", | ||
| }, | ||
| ], | ||
| use: [ | ||
| { | ||
| protocol: [ | ||
| "fuchsia.ui.app.ViewProvider", | ||
| "fuchsia.ui.scenic.Scenic", | ||
| "fuchsia.ui.test.input.TouchInputListener", | ||
| ] | ||
| }, | ||
| { | ||
| directory: "config-data", | ||
| rights: [ "r*" ], | ||
| path: "/config/data", | ||
| }, | ||
| ] | ||
| } |
8 changes: 8 additions & 0 deletions
8
...latform/fuchsia/flutter/tests/integration/touch-input/embedding-flutter-view/pubspec.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # 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. | ||
|
|
||
| name: touch-input-view | ||
|
|
||
| environment: | ||
| sdk: '>=2.18.0 <3.0.0' | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.