8 #include "flutter/fml/logging.h"
14 : view_provider_(view_provider),
15 platform_view_controller_(platform_view_controller),
16 mutator_views_([NSMapTable strongToStrongObjectsMapTable]) {
17 FML_CHECK(view_provider !=
nullptr) <<
"view_provider cannot be nullptr";
21 FlutterBackingStore* backing_store_out) {
30 CGSize size = CGSizeMake(config->size.width, config->size.height);
32 memset(backing_store_out, 0,
sizeof(FlutterBackingStore));
33 backing_store_out->struct_size =
sizeof(FlutterBackingStore);
34 backing_store_out->type = kFlutterBackingStoreTypeMetal;
35 backing_store_out->metal.struct_size =
sizeof(FlutterMetalBackingStore);
41 const FlutterLayer** layers,
42 size_t layers_count) {
43 FlutterView* view = [view_provider_ viewForId:view_id];
48 NSMutableArray* surfaces = [NSMutableArray array];
49 for (
size_t i = 0; i < layers_count; i++) {
50 const FlutterLayer* layer = layers[i];
51 if (layer->type == kFlutterLayerContentTypeBackingStore) {
53 [
FlutterSurface fromFlutterMetalTexture:&layer->backing_store->metal.texture];
58 info.
offset = CGPointMake(layer->offset.x, layer->offset.y);
60 FlutterBackingStorePresentInfo* present_info = layer->backing_store_present_info;
61 if (present_info !=
nullptr && present_info->paint_region !=
nullptr) {
62 auto paint_region = present_info->paint_region;
65 paint_region->rects, paint_region->rects + paint_region->rects_count);
67 [surfaces addObject:info];
74 PresentPlatformViews(view, layers, layers_count);
80 void FlutterCompositor::PresentPlatformViews(
FlutterView* default_base_view,
81 const FlutterLayer** layers,
82 size_t layers_count) {
83 FML_DCHECK([[NSThread currentThread] isMainThread])
84 <<
"Must be on the main thread to present platform views";
87 NSMutableArray<FlutterMutatorView*>* present_mutators = [NSMutableArray array];
89 for (
size_t i = 0; i < layers_count; i++) {
90 FlutterLayer* layer = (FlutterLayer*)layers[i];
91 if (layer->type == kFlutterLayerContentTypePlatformView) {
92 [present_mutators addObject:PresentPlatformView(default_base_view, layer, i)];
96 NSMutableArray<FlutterMutatorView*>* obsolete_mutators =
97 [NSMutableArray arrayWithArray:[mutator_views_ objectEnumerator].allObjects];
98 [obsolete_mutators removeObjectsInArray:present_mutators];
101 [mutator_views_ removeObjectForKey:mutator.platformView];
102 [mutator removeFromSuperview];
105 [platform_view_controller_ disposePlatformViews];
109 const FlutterLayer* layer,
110 size_t layer_position) {
111 FML_DCHECK([[NSThread currentThread] isMainThread])
112 <<
"Must be on the main thread to present platform views";
114 int64_t platform_view_id = layer->platform_view->identifier;
115 NSView* platform_view = [platform_view_controller_ platformViewWithID:platform_view_id];
117 FML_DCHECK(platform_view) <<
"Platform view not found for id: " << platform_view_id;
123 [mutator_views_ setObject:container forKey:platform_view];
124 [default_base_view addSubview:container];
127 container.layer.zPosition = layer_position;
128 [container applyFlutterLayer:layer];