Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'package:ui/ui.dart' as ui;

import '../../engine.dart' show platformViewManager;
import '../../engine.dart' show PlatformViewManager;
import '../configuration.dart';
import '../dom.dart';
import '../html/path_to_svg_clip.dart';
Expand Down Expand Up @@ -136,7 +136,7 @@ class HtmlViewEmbedder {
}
// We need an overlay for each visible platform view. Invisible platform
// views will be grouped with (at most) one visible platform view later.
final bool needNewOverlay = platformViewManager.isVisible(viewId);
final bool needNewOverlay = PlatformViewManager.instance.isVisible(viewId);
if (needNewOverlay && hasAvailableOverlay) {
final CkPictureRecorder pictureRecorder = CkPictureRecorder();
pictureRecorder.beginRecording(ui.Offset.zero & _frameSize);
Expand Down Expand Up @@ -164,11 +164,11 @@ class HtmlViewEmbedder {
final int overlayIndex = _context.visibleViewCount;
_compositionOrder.add(viewId);
// Keep track of the number of visible platform views.
if (platformViewManager.isVisible(viewId)) {
if (PlatformViewManager.instance.isVisible(viewId)) {
_context.visibleViewCount++;
}
// We need a new overlay if this is a visible view.
final bool needNewOverlay = platformViewManager.isVisible(viewId);
final bool needNewOverlay = PlatformViewManager.instance.isVisible(viewId);
CkPictureRecorder? recorderToUseForRendering;
if (needNewOverlay) {
if (overlayIndex < _context.pictureRecordersCreatedDuringPreroll.length) {
Expand Down Expand Up @@ -467,7 +467,7 @@ class HtmlViewEmbedder {
for (final int viewId in diffResult.viewsToAdd) {
bool isViewInvalid = false;
assert(() {
isViewInvalid = !platformViewManager.knowsViewId(viewId);
isViewInvalid = !PlatformViewManager.instance.knowsViewId(viewId);
if (isViewInvalid) {
debugInvalidViewIds ??= <int>[];
debugInvalidViewIds!.add(viewId);
Expand Down Expand Up @@ -520,7 +520,7 @@ class HtmlViewEmbedder {

bool isViewInvalid = false;
assert(() {
isViewInvalid = !platformViewManager.knowsViewId(viewId);
isViewInvalid = !PlatformViewManager.instance.knowsViewId(viewId);
if (isViewInvalid) {
debugInvalidViewIds ??= <int>[];
debugInvalidViewIds!.add(viewId);
Expand Down Expand Up @@ -655,7 +655,7 @@ class HtmlViewEmbedder {

for (int i = 0; i < views.length; i++) {
final int view = views[i];
if (platformViewManager.isInvisible(view)) {
if (PlatformViewManager.instance.isInvisible(view)) {
// We add as many invisible views as we find to the current group.
currentGroup.add(view);
} else {
Expand Down Expand Up @@ -720,7 +720,7 @@ class HtmlViewEmbedder {

/// Clears the state of this view embedder. Used in tests.
void debugClear() {
final Set<int> allViews = platformViewManager.debugClear();
final Set<int> allViews = PlatformViewManager.instance.debugClear();
disposeViews(allViews);
_context = EmbedderFrameContext();
_currentCompositionParams.clear();
Expand Down
5 changes: 0 additions & 5 deletions lib/web_ui/lib/src/engine/initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,3 @@ set debugDisableFontFallbacks(bool value) {
_debugDisableFontFallbacks = value;
}
bool _debugDisableFontFallbacks = false;

/// The shared instance of PlatformViewManager shared across the engine to handle
/// rendering of PlatformViews into the web app.
// TODO(dit): How to make this overridable from tests?
final PlatformViewManager platformViewManager = PlatformViewManager();
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {

case 'flutter/platform_views':
_platformViewMessageHandler ??= PlatformViewMessageHandler(
contentManager: platformViewManager,
contentManager: PlatformViewManager.instance,
contentHandler: (DomElement content) {
flutterViewEmbedder.glassPaneElement.append(content);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class PlatformViewManager {
);
}

/// The shared instance of PlatformViewManager shared across the engine to handle
/// rendering of PlatformViews into the web app.
// TODO(dit): How to make this overridable from tests?
static final PlatformViewManager instance = PlatformViewManager();
Comment on lines +43 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now very easy to override for tests! When we need that, this just needs to be non-final and have a setter for the testing environment. (Same as all the other singletons!)


// The factory functions, indexed by the viewType
final Map<String, Function> _factories = <String, Function>{};

Expand All @@ -49,7 +54,7 @@ class PlatformViewManager {

/// Returns `true` if the passed in `viewType` has been registered before.
///
/// See [registerViewFactory] to understand how factories are registered.
/// See [registerFactory] to understand how factories are registered.
bool knowsViewType(String viewType) {
return _factories.containsKey(viewType);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/ui_web/src/ui_web/platform_view_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PlatformViewRegistry {
Function viewFactory, {
bool isVisible = true,
}) {
return platformViewManager.registerFactory(
return PlatformViewManager.instance.registerFactory(
viewType,
viewFactory,
isVisible: isVisible,
Expand All @@ -53,6 +53,6 @@ class PlatformViewRegistry {
///
/// Throws if no view has been created for [viewId].
Object getViewById(int viewId) {
return platformViewManager.getViewById(viewId);
return PlatformViewManager.instance.getViewById(viewId);
}
}
4 changes: 2 additions & 2 deletions lib/web_ui/test/canvaskit/embedded_views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,8 @@ void testMain() {
await createPlatformView(5, 'test-invisible-view');
await createPlatformView(6, 'test-invisible-view');

expect(platformViewManager.isInvisible(0), isFalse);
expect(platformViewManager.isInvisible(1), isTrue);
expect(PlatformViewManager.instance.isInvisible(0), isFalse);
expect(PlatformViewManager.instance.isInvisible(1), isTrue);

LayerSceneBuilder sb = LayerSceneBuilder();
sb.pushOffset(0, 0);
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/ui/platform_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Future<void> testMain() async {
});

tearDown(() {
platformViewManager.debugClear();
PlatformViewManager.instance.debugClear();
});

test('picture + overlapping platformView', () async {
Expand Down