@@ -93,8 +93,9 @@ void FlatlandExternalViewEmbedder::PrerollCompositeEmbeddedView(
9393 zx_handle_t handle = static_cast <zx_handle_t >(view_id);
9494 FML_CHECK (frame_layers_.count (handle) == 0 );
9595
96- frame_layers_.emplace (std::make_pair (EmbedderLayerId{handle},
97- EmbedderLayer (frame_size_, *params)));
96+ frame_layers_.emplace (std::make_pair (
97+ EmbedderLayerId{handle},
98+ EmbedderLayer (frame_size_, *params, flutter::RTreeFactory ())));
9899 frame_composition_order_.push_back (handle);
99100}
100101
@@ -125,8 +126,9 @@ void FlatlandExternalViewEmbedder::BeginFrame(
125126 frame_dpr_ = device_pixel_ratio;
126127
127128 // Create the root layer.
128- frame_layers_.emplace (
129- std::make_pair (kRootLayerId , EmbedderLayer (frame_size, std::nullopt )));
129+ frame_layers_.emplace (std::make_pair (
130+ kRootLayerId ,
131+ EmbedderLayer (frame_size, std::nullopt , flutter::RTreeFactory ())));
130132 frame_composition_order_.push_back (kRootLayerId );
131133}
132134
@@ -193,6 +195,19 @@ void FlatlandExternalViewEmbedder::SubmitFrame(
193195 }
194196 }
195197
198+ // Finish recording SkPictures.
199+ {
200+ TRACE_EVENT0 (" flutter" , " FinishRecordingPictures" );
201+
202+ for (const auto & surface_index : frame_surface_indices) {
203+ const auto & layer = frame_layers_.find (surface_index.first );
204+ FML_CHECK (layer != frame_layers_.end ());
205+ layer->second .picture =
206+ layer->second .recorder ->finishRecordingAsPicture ();
207+ FML_CHECK (layer->second .picture != nullptr );
208+ }
209+ }
210+
196211 // Submit layers and platform views to Scenic in composition order.
197212 {
198213 TRACE_EVENT0 (" flutter" , " SubmitLayers" );
@@ -334,30 +349,43 @@ void FlatlandExternalViewEmbedder::SubmitFrame(
334349 ? fuchsia::ui::composition::BlendMode::SRC
335350 : fuchsia::ui::composition::BlendMode::SRC_OVER);
336351
352+ // Set hit regions for this layer; these hit regions correspond to the
353+ // portions of the layer on which skia drew content.
354+ {
355+ FML_CHECK (layer->second .rtree );
356+ std::list<SkRect> intersection_rects =
357+ layer->second .rtree ->searchNonOverlappingDrawnRects (
358+ SkRect::Make (layer->second .surface_size ));
359+
360+ std::vector<fuchsia::ui::composition::HitRegion> hit_regions;
361+ for (const SkRect& rect : intersection_rects) {
362+ hit_regions.emplace_back ();
363+ auto & new_hit_region = hit_regions.back ();
364+ new_hit_region.region .x = rect.x ();
365+ new_hit_region.region .y = rect.y ();
366+ new_hit_region.region .width = rect.width ();
367+ new_hit_region.region .height = rect.height ();
368+ new_hit_region.hit_test =
369+ fuchsia::ui::composition::HitTestInteraction::DEFAULT;
370+ }
371+
372+ flatland_->flatland ()->SetHitRegions (
373+ flatland_layers_[flatland_layer_index].transform_id ,
374+ std::move (hit_regions));
375+ }
376+
337377 // Attach the FlatlandLayer to the main scene graph.
338378 flatland_->flatland ()->AddChild (
339379 root_transform_id_,
340380 flatland_layers_[flatland_layer_index].transform_id );
341381 child_transforms_.emplace_back (
342382 flatland_layers_[flatland_layer_index].transform_id );
343-
344- // Attach full-screen hit testing shield. Note that since the hit-region
345- // may be transformed (translated, rotated), we do not want to set
346- // width/height to FLT_MAX. This will cause a numeric overflow.
347- flatland_->flatland ()->SetHitRegions (
348- flatland_layers_[flatland_layer_index].transform_id ,
349- {{{0 , 0 , kMaxHitRegionSize , kMaxHitRegionSize },
350- fuchsia::ui::composition::HitTestInteraction::
351- SEMANTICALLY_INVISIBLE}});
352383 }
353384
354385 // Reset for the next pass:
355386 flatland_layer_index++;
356387 }
357388
358- // TODO(fxbug.dev/104956): Setting per-layer overlay hit region for Flatland
359- // external view embedder should match with what is being done in GFX
360- // external view embedder.
361389 // Set up the input interceptor at the top of the
362390 // scene, if applicable. It will capture all input, and any unwanted input
363391 // will be reinjected into embedded views.
@@ -396,13 +424,10 @@ void FlatlandExternalViewEmbedder::SubmitFrame(
396424
397425 const auto & layer = frame_layers_.find (surface_index.first );
398426 FML_CHECK (layer != frame_layers_.end ());
399- sk_sp<SkPicture> picture =
400- layer->second .recorder ->finishRecordingAsPicture ();
401- FML_CHECK (picture != nullptr );
402427
403428 canvas->setMatrix (SkMatrix::I ());
404429 canvas->clear (SK_ColorTRANSPARENT);
405- canvas->drawPicture (picture);
430+ canvas->drawPicture (layer-> second . picture );
406431 canvas->flush ();
407432 }
408433 }
0 commit comments