@@ -104,6 +104,8 @@ void AndroidExternalViewEmbedder::SubmitFrame(
104104 overlay_layers.insert ({view_id, {}});
105105
106106 sk_sp<RTree> rtree = view_rtrees_.at (view_id);
107+ SkRect joined_rect;
108+
107109 // Determinate if Flutter UI intersects with any of the previous
108110 // platform views stacked by z position.
109111 //
@@ -116,33 +118,26 @@ void AndroidExternalViewEmbedder::SubmitFrame(
116118 // Each rect corresponds to a native view that renders Flutter UI.
117119 std::list<SkRect> intersection_rects =
118120 rtree->searchNonOverlappingDrawnRects (current_view_rect);
119- auto allocation_size = intersection_rects.size ();
120121
121122 // Limit the number of native views, so it doesn't grow forever.
122123 //
123124 // In this case, the rects are merged into a single one that is the union
124125 // of all the rects.
125- if (allocation_size > kMaxLayerAllocations ) {
126- SkRect joined_rect;
127- for (const SkRect& rect : intersection_rects) {
128- joined_rect.join (rect);
129- }
130- intersection_rects.clear ();
131- intersection_rects.push_back (joined_rect);
132- }
133- for (SkRect& intersection_rect : intersection_rects) {
134- // Subpixels in the platform may not align with the canvas subpixels.
135- //
136- // To workaround it, round the floating point bounds and make the rect
137- // slightly larger. For example, {0.3, 0.5, 3.1, 4.7} becomes {0, 0, 4,
138- // 5}.
139- intersection_rect.set (intersection_rect.roundOut ());
140- overlay_layers.at (view_id).push_back (intersection_rect);
141- // Clip the background canvas, so it doesn't contain any of the pixels
142- // drawn on the overlay layer.
143- background_canvas->clipRect (intersection_rect, SkClipOp::kDifference );
126+ for (const SkRect& rect : intersection_rects) {
127+ joined_rect.join (rect);
144128 }
145129 }
130+
131+ // Subpixels in the platform may not align with the canvas subpixels.
132+ //
133+ // To workaround it, round the floating point bounds and make the rect
134+ // slightly larger. For example, {0.3, 0.5, 3.1, 4.7} becomes {0, 0, 4,
135+ // 5}.
136+ joined_rect.set (joined_rect.roundOut ());
137+ overlay_layers.at (view_id).push_back (joined_rect);
138+ // Clip the background canvas, so it doesn't contain any of the pixels
139+ // drawn on the overlay layer.
140+ background_canvas->clipRect (joined_rect, SkClipOp::kDifference );
146141 background_canvas->drawPicture (pictures.at (view_id));
147142 }
148143 // Submit the background canvas frame before switching the GL context to
0 commit comments