8 #include "flutter/fml/logging.h"
13 std::vector<PlatformViewLayerWithIndex> CopyPlatformViewLayers(
const FlutterLayer** layers,
15 std::vector<PlatformViewLayerWithIndex> platform_views;
16 for (
size_t i = 0; i < layer_count; i++) {
17 if (layers[i]->type == kFlutterLayerContentTypePlatformView) {
18 platform_views.push_back(std::make_pair(PlatformViewLayer(layers[i]), i));
21 return platform_views;
28 : view_provider_(view_provider),
29 time_converter_(time_converter),
30 platform_view_controller_(platform_view_controller),
31 mutator_views_([NSMapTable strongToStrongObjectsMapTable]) {
32 FML_CHECK(view_provider !=
nullptr) <<
"view_provider cannot be nullptr";
36 FlutterBackingStore* backing_store_out) {
45 CGSize size = CGSizeMake(config->size.width, config->size.height);
47 memset(backing_store_out, 0,
sizeof(FlutterBackingStore));
48 backing_store_out->struct_size =
sizeof(FlutterBackingStore);
49 backing_store_out->type = kFlutterBackingStoreTypeMetal;
50 backing_store_out->metal.struct_size =
sizeof(FlutterMetalBackingStore);
56 const FlutterLayer** layers,
57 size_t layers_count) {
58 FlutterView* view = [view_provider_ viewForId:view_id];
63 NSMutableArray* surfaces = [NSMutableArray array];
64 for (
size_t i = 0; i < layers_count; i++) {
65 const FlutterLayer* layer = layers[i];
66 if (layer->type == kFlutterLayerContentTypeBackingStore) {
68 [
FlutterSurface fromFlutterMetalTexture:&layer->backing_store->metal.texture];
73 info.
offset = CGPointMake(layer->offset.x, layer->offset.y);
75 FlutterBackingStorePresentInfo* present_info = layer->backing_store_present_info;
76 if (present_info !=
nullptr && present_info->paint_region !=
nullptr) {
77 auto paint_region = present_info->paint_region;
80 paint_region->rects, paint_region->rects + paint_region->rects_count);
82 [surfaces addObject:info];
87 CFTimeInterval presentation_time = 0;
89 if (layers_count > 0 && layers[0]->presentation_time != 0) {
90 presentation_time = [time_converter_ engineTimeToCAMediaTime:layers[0]->presentation_time];
95 auto platform_views_layers = std::make_shared<std::vector<PlatformViewLayerWithIndex>>(
96 CopyPlatformViewLayers(layers, layers_count));
99 atTime:presentation_time
101 PresentPlatformViews(view, *platform_views_layers);
107 void FlutterCompositor::PresentPlatformViews(
109 const std::vector<PlatformViewLayerWithIndex>& platform_views) {
110 FML_DCHECK([[NSThread currentThread] isMainThread])
111 <<
"Must be on the main thread to present platform views";
114 NSMutableArray<FlutterMutatorView*>* present_mutators = [NSMutableArray array];
116 for (
const auto& platform_view : platform_views) {
117 [present_mutators addObject:PresentPlatformView(default_base_view, platform_view.first,
118 platform_view.second)];
121 NSMutableArray<FlutterMutatorView*>* obsolete_mutators =
122 [NSMutableArray arrayWithArray:[mutator_views_ objectEnumerator].allObjects];
123 [obsolete_mutators removeObjectsInArray:present_mutators];
126 [mutator_views_ removeObjectForKey:mutator.platformView];
127 [mutator removeFromSuperview];
130 [platform_view_controller_ disposePlatformViews];
134 const PlatformViewLayer& layer,
136 FML_DCHECK([[NSThread currentThread] isMainThread])
137 <<
"Must be on the main thread to present platform views";
139 int64_t platform_view_id = layer.identifier();
140 NSView* platform_view = [platform_view_controller_ platformViewWithID:platform_view_id];
142 FML_DCHECK(platform_view) <<
"Platform view not found for id: " << platform_view_id;
148 [mutator_views_ setObject:container forKey:platform_view];
149 [default_base_view addSubview:container];
152 container.layer.zPosition = index;
153 [container applyFlutterLayer:&layer];