[Android] fix hcpp overlay layer intersection. (#163024)

Since we only have a single overlay layer, we need to diff out the
platform views that _would_ intersect if we did the correct layering.
This commit is contained in:
Jonah Williams
2025-02-11 09:13:19 -08:00
committed by GitHub
parent e7e5480a57
commit 761c1623ca
3 changed files with 203 additions and 3 deletions

View File

@@ -0,0 +1,125 @@
// Copyright 2014 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 'package:android_driver_extensions/extension.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_driver/driver_extension.dart';
import '../src/allow_list_devices.dart';
void main() async {
ensureAndroidDevice();
enableFlutterDriverExtension(
handler: (String? command) async {
return json.encode(<String, Object?>{
'supported': await HybridAndroidViewController.checkIfSupported(),
});
},
commands: <CommandExtension>[nativeDriverCommands],
);
// Run on full screen.
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
runApp(const MainApp());
}
// This should appear as the yellow line over a blue box. The
// green box should not be visible unless the platform view has not loaded yet.
final class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Stack(
children: <Widget>[
Positioned.directional(
top: 100,
textDirection: TextDirection.ltr,
child: const SizedBox(
width: 200,
height: 200,
child: _HybridCompositionAndroidPlatformView(viewType: 'box_platform_view'),
),
),
Positioned.directional(
top: 200,
textDirection: TextDirection.ltr,
child: const SizedBox(width: 800, height: 200, child: ColoredBox(color: Colors.yellow)),
),
Positioned.directional(
top: 300,
textDirection: TextDirection.ltr,
child: const SizedBox(
width: 200,
height: 200,
child: _HybridCompositionAndroidPlatformView(viewType: 'box_platform_view'),
),
),
Positioned.directional(
top: 400,
textDirection: TextDirection.ltr,
child: const SizedBox(width: 800, height: 200, child: ColoredBox(color: Colors.red)),
),
Positioned.directional(
top: 500,
textDirection: TextDirection.ltr,
child: const SizedBox(
width: 200,
height: 200,
child: _HybridCompositionAndroidPlatformView(viewType: 'box_platform_view'),
),
),
Positioned.directional(
top: 600,
textDirection: TextDirection.ltr,
child: const SizedBox(width: 800, height: 200, child: ColoredBox(color: Colors.orange)),
),
],
),
);
}
}
final class _HybridCompositionAndroidPlatformView extends StatelessWidget {
const _HybridCompositionAndroidPlatformView({required this.viewType});
final String viewType;
@override
Widget build(BuildContext context) {
return PlatformViewLink(
viewType: viewType,
surfaceFactory: (BuildContext context, PlatformViewController controller) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
);
},
onCreatePlatformView: (PlatformViewCreationParams params) {
return PlatformViewsService.initHybridAndroidView(
id: params.id,
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParamsCodec: const StandardMessageCodec(),
)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..create();
},
);
}
}

View File

@@ -0,0 +1,61 @@
// Copyright 2014 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 'package:android_driver_extensions/native_driver.dart';
import 'package:android_driver_extensions/skia_gold.dart';
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
import '../_luci_skia_gold_prelude.dart';
/// For local debugging, a (local) golden-file is required as a baseline:
///
/// ```sh
/// # Checkout HEAD, i.e. *before* changes you want to test.
/// UPDATE_GOLDENS=1 flutter drive lib/platform_view/hcpp/platform_view_overlapping_main.dart
///
/// # Make your changes.
///
/// # Run the test against baseline.
/// flutter drive lib/platform_view/hcpp/platform_view_overlapping_main.dart
/// ```
///
/// For a convenient way to deflake a test, see `tool/deflake.dart`.
void main() async {
const String goldenPrefix = 'hybrid_composition_pp_overlapping_platform_view';
late final FlutterDriver flutterDriver;
late final NativeDriver nativeDriver;
setUpAll(() async {
if (isLuci) {
await enableSkiaGoldComparator(namePrefix: 'android_engine_test$goldenVariant');
}
flutterDriver = await FlutterDriver.connect();
nativeDriver = await AndroidNativeDriver.connect(flutterDriver);
await nativeDriver.configureForScreenshotTesting();
await flutterDriver.waitUntilFirstFrameRasterized();
});
tearDownAll(() async {
await nativeDriver.close();
await flutterDriver.close();
});
test('verify that HCPP is supported and enabled', () async {
final Map<String, Object?> response =
json.decode(await flutterDriver.requestData('')) as Map<String, Object?>;
expect(response['supported'], true);
}, timeout: Timeout.none);
test('should screenshot multiple HCPP platform view with overlays', () async {
await expectLater(
nativeDriver.screenshot(),
matchesGoldenFile('$goldenPrefix.multiple_overlays.png'),
);
}, timeout: Timeout.none);
}