@@ -486,8 +486,8 @@ class HtmlViewEmbedder {
486486 skiaSceneHost.insertBefore (platformViewRoot, elementToInsertBefore);
487487 final Surface ? overlay = _overlays[viewId];
488488 if (overlay != null ) {
489- skiaSceneHost
490- . insertBefore ( overlay.htmlElement, elementToInsertBefore);
489+ skiaSceneHost. insertBefore (
490+ overlay.htmlElement, elementToInsertBefore);
491491 }
492492 } else {
493493 final DomElement platformViewRoot = _viewClipChains[viewId]! .root;
@@ -601,8 +601,15 @@ class HtmlViewEmbedder {
601601 return ;
602602 }
603603 final List <List <int >> overlayGroups = getOverlayGroups (_compositionOrder);
604- final Iterable <int > viewsNeedingOverlays =
605- overlayGroups.map ((List <int > group) => group.last);
604+ final List <int > viewsNeedingOverlays =
605+ overlayGroups.map ((List <int > group) => group.last).toList ();
606+ // If there were more visible views than overlays, then the last group
607+ // doesn't have an overlay.
608+ if (viewsNeedingOverlays.length > SurfaceFactory .instance.maximumOverlays) {
609+ assert (viewsNeedingOverlays.length ==
610+ SurfaceFactory .instance.maximumOverlays + 1 );
611+ viewsNeedingOverlays.removeLast ();
612+ }
606613 if (diffResult == null ) {
607614 // Everything is going to be explicitly recomposited anyway. Release all
608615 // the surfaces and assign an overlay to all the surfaces needing one.
@@ -631,33 +638,39 @@ class HtmlViewEmbedder {
631638 // of the composition order which can share the same overlay. Every overlay
632639 // group is a list containing a visible view followed by zero or more
633640 // invisible views.
641+ //
642+ // If there are more visible views than overlays, then the views which cannot
643+ // be assigned an overlay are grouped together and will be rendered on top of
644+ // the rest of the scene.
634645 List <List <int >> getOverlayGroups (List <int > views) {
635646 // Visibility groups are typically a visible view followed by zero or more
636647 // invisible views. However, if the view list begins with one or more
637648 // invisible views, we can group them with the first visible view.
638- final int maxGroups = SurfaceFactory .instance.maximumOverlays;
639- if (maxGroups == 0 ) {
649+ final int maxOverlays = SurfaceFactory .instance.maximumOverlays;
650+ if (maxOverlays == 0 ) {
640651 return const < List <int >> [];
641652 }
642653 bool foundFirstVisibleView = false ;
643654 final List <List <int >> result = < List <int >> [];
644655 List <int > currentGroup = < int > [];
645656 int i = 0 ;
646657 for (; i < views.length; i++ ) {
647- // If we're on the last group, then break and just add all the rest of the
648- // views to current group.
649- if (result.length == maxGroups - 1 ) {
650- break ;
651- }
652658 final int view = views[i];
653659 if (platformViewManager.isInvisible (view)) {
654660 currentGroup.add (view);
655661 } else {
656662 if (foundFirstVisibleView) {
657- // We hit this case if this is the first visible view.
658663 result.add (currentGroup);
659- currentGroup = < int > [view];
664+ // If we are out of overlays, then break let the rest of the views be
665+ // added to an extra group that will be rendered on top of the scene.
666+ if (result.length == maxOverlays) {
667+ currentGroup = < int > [];
668+ break ;
669+ } else {
670+ currentGroup = < int > [view];
671+ }
660672 } else {
673+ // We hit this case if this is the first visible view.
661674 foundFirstVisibleView = true ;
662675 currentGroup.add (view);
663676 }
0 commit comments