Skip to content

Commit 9438fd4

Browse files
Jonah Williamsmatanlurey
andauthored
[Android] add runtime flag to determine if HCPP is supported. (flutter#163004)
Developers will need to _conditionally_ use HCPP (or the framework will need to handle it automatically). This requires the ability to query at runtime whether HCPP mode is enabled + supported. Add a message channel to do so, and add the usage of this to the android_engine_test. Does not yet add any automatic selection. --------- Co-authored-by: Matan Lurey <[email protected]>
1 parent 5e37c96 commit 9438fd4

File tree

13 files changed

+95
-4
lines changed

13 files changed

+95
-4
lines changed

dev/integration_tests/android_engine_test/lib/hcpp/platform_view_main.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:convert';
6+
57
import 'package:android_driver_extensions/extension.dart';
68
import 'package:flutter/foundation.dart';
79
import 'package:flutter/gestures.dart';
@@ -14,7 +16,14 @@ import '../src/allow_list_devices.dart';
1416

1517
void main() async {
1618
ensureAndroidDevice();
17-
enableFlutterDriverExtension(commands: <CommandExtension>[nativeDriverCommands]);
19+
enableFlutterDriverExtension(
20+
handler: (String? command) async {
21+
return json.encode(<String, Object?>{
22+
'supported': await HybridAndroidViewController.checkIfSupported(),
23+
});
24+
},
25+
commands: <CommandExtension>[nativeDriverCommands],
26+
);
1827

1928
// Run on full screen.
2029
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);

dev/integration_tests/android_engine_test/test_driver/hcpp/platform_view_main_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:convert';
6+
57
import 'package:android_driver_extensions/native_driver.dart';
68
import 'package:android_driver_extensions/skia_gold.dart';
79
import 'package:flutter_driver/flutter_driver.dart';
@@ -43,6 +45,13 @@ void main() async {
4345
await flutterDriver.close();
4446
});
4547

48+
test('verify that HCPP is supported and enabled', () async {
49+
final Map<String, Object?> response =
50+
json.decode(await flutterDriver.requestData('')) as Map<String, Object?>;
51+
52+
expect(response['supported'], true);
53+
}, timeout: Timeout.none);
54+
4655
test('should screenshot an HCPP platform view', () async {
4756
await expectLater(
4857
nativeDriver.screenshot(),

engine/src/flutter/shell/platform/android/android_shell_holder.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <string>
1717
#include <utility>
1818

19+
#include "common/settings.h"
1920
#include "flutter/fml/cpu_affinity.h"
2021
#include "flutter/fml/logging.h"
2122
#include "flutter/fml/make_copyable.h"
@@ -261,8 +262,6 @@ std::unique_ptr<AndroidShellHolder> AndroidShellHolder::Spawn(
261262
return std::make_unique<Rasterizer>(shell);
262263
};
263264

264-
// TODO(xster): could be worth tracing this to investigate whether
265-
// the IsolateConfiguration could be cached somewhere.
266265
auto config = BuildRunConfiguration(entrypoint, libraryUrl, entrypoint_args);
267266
if (!config) {
268267
// If the RunConfiguration was null, the kernel blob wasn't readable.
@@ -358,4 +357,8 @@ void AndroidShellHolder::UpdateDisplayMetrics() {
358357
shell_->OnDisplayUpdates(std::move(displays));
359358
}
360359

360+
bool AndroidShellHolder::IsSurfaceControlEnabled() {
361+
return GetPlatformView()->IsSurfaceControlEnabled();
362+
}
363+
361364
} // namespace flutter

engine/src/flutter/shell/platform/android/android_shell_holder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class AndroidShellHolder {
9393

9494
fml::WeakPtr<PlatformViewAndroid> GetPlatformView();
9595

96+
bool IsSurfaceControlEnabled();
97+
9698
Rasterizer::Screenshot Screenshot(Rasterizer::ScreenshotType type,
9799
bool base64_encode);
98100

engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ public FlutterEngine(
365365

366366
PlatformViewsController2 platformViewsController2 = new PlatformViewsController2();
367367
platformViewsController2.setRegistry(platformViewsController.getRegistry());
368+
platformViewsController2.setFlutterJNI(flutterJNI);
368369

369370
flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
370371
flutterJNI.setPlatformViewsController(platformViewsController);

engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,4 +1624,11 @@ public boolean ShouldDisableAHB() {
16241624
}
16251625

16261626
private native boolean nativeShouldDisableAHB();
1627+
1628+
/** Whether the SurfaceControl swapchain required for hcpp is enabled and active. */
1629+
public boolean IsSurfaceControlEnabled() {
1630+
return nativeIsSurfaceControlEnabled(nativeShellHolderId);
1631+
}
1632+
1633+
private native boolean nativeIsSurfaceControlEnabled(long nativeShellHolderId);
16271634
}

engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel2.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
7979
case "clearFocus":
8080
clearFocus(call, result);
8181
break;
82+
case "isSurfaceControlEnabled":
83+
isSurfaceControlEnabled(call, result);
84+
break;
8285
default:
8386
result.notImplemented();
8487
}
@@ -171,6 +174,11 @@ private void clearFocus(@NonNull MethodCall call, @NonNull MethodChannel.Result
171174
result.error("error", detailedExceptionString(exception), null);
172175
}
173176
}
177+
178+
private void isSurfaceControlEnabled(
179+
@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
180+
result.success(handler.isSurfaceControlEnabled());
181+
}
174182
};
175183

176184
/**
@@ -213,6 +221,9 @@ public interface PlatformViewsHandler {
213221

214222
/** Clears the focus from the platform view with a give id if it is currently focused. */
215223
void clearFocus(int viewId);
224+
225+
/** Whether the SurfaceControl swapchain is enabled. */
226+
boolean isSurfaceControlEnabled();
216227
}
217228

218229
/** Request sent from Flutter to create a new platform view. */

engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.flutter.embedding.android.AndroidTouchProcessor;
2828
import io.flutter.embedding.android.FlutterView;
2929
import io.flutter.embedding.android.MotionEventTracker;
30+
import io.flutter.embedding.engine.FlutterJNI;
3031
import io.flutter.embedding.engine.FlutterOverlaySurface;
3132
import io.flutter.embedding.engine.dart.DartExecutor;
3233
import io.flutter.embedding.engine.mutatorsstack.*;
@@ -50,6 +51,7 @@ public class PlatformViewsController2 implements PlatformViewsAccessibilityDeleg
5051
private AndroidTouchProcessor androidTouchProcessor;
5152
private Context context;
5253
private FlutterView flutterView;
54+
private FlutterJNI flutterJNI = null;
5355

5456
@Nullable private TextInputPlugin textInputPlugin;
5557

@@ -77,6 +79,11 @@ public void setRegistry(@NonNull PlatformViewRegistry registry) {
7779
this.registry = (PlatformViewRegistryImpl) registry;
7880
}
7981

82+
/** Whether the SurfaceControl swapchain mode is enabled. */
83+
public void setFlutterJNI(FlutterJNI flutterJNI) {
84+
this.flutterJNI = flutterJNI;
85+
}
86+
8087
@Override
8188
public boolean usesVirtualDisplay(int id) {
8289
return false;
@@ -679,5 +686,13 @@ public void clearFocus(int viewId) {
679686
}
680687
embeddedView.clearFocus();
681688
}
689+
690+
@Override
691+
public boolean isSurfaceControlEnabled() {
692+
if (flutterJNI == null) {
693+
return false;
694+
}
695+
return flutterJNI.IsSurfaceControlEnabled();
696+
}
682697
};
683698
}

engine/src/flutter/shell/platform/android/io/flutter/view/TextureRegistry.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import androidx.annotation.NonNull;
1212
import androidx.annotation.Nullable;
1313

14-
// TODO(mattcarroll): re-evalute docs in this class and add nullability annotations.
1514
/**
1615
* Registry of backend textures used with a single {@link io.flutter.embedding.android.FlutterView}
1716
* instance. Entries may be embedded into the Flutter view using the <a

engine/src/flutter/shell/platform/android/platform_view_android.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,9 @@ double PlatformViewAndroid::GetScaledFontSize(double unscaled_font_size,
498498
return jni_facade_->FlutterViewGetScaledFontSize(unscaled_font_size,
499499
configuration_id);
500500
}
501+
502+
bool PlatformViewAndroid::IsSurfaceControlEnabled() const {
503+
return android_use_new_platform_view_;
504+
}
505+
501506
} // namespace flutter

0 commit comments

Comments
 (0)