| Flutter macOS Embedder |

Classes | Public Member Functions | List of all members
flutter::FlutterCompositor Class Reference

`#include <FlutterCompositor.h>`

## Public Member Functions
| FlutterCompositor (id< FlutterViewProvider > view_provider, FlutterTimeConverter *time_converter, FlutterPlatformViewController *platform_views_controller)
| ~FlutterCompositor ()=default
bool | CreateBackingStore (const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
bool | Present (FlutterViewIdentifier view_id, const FlutterLayer **layers, size_t layers_count)

## Detailed Description

Definition at line 36 of file FlutterCompositor.h.

## Constructor & Destructor Documentation

## ◆ FlutterCompositor()

flutter::FlutterCompositor::FlutterCompositor | ( | id< FlutterViewProvider > | view_provider,
|  | FlutterTimeConverter * | time_converter,
|  | FlutterPlatformViewController * | platform_views_controller
| ) |  |

Definition at line 35 of file FlutterCompositor.mm.

38 : view_provider_(view_provider),
39 time_converter_(time_converter),
40 platform_view_controller_(platform_view_controller) {
41 FML_CHECK(view_provider != nullptr) << "view_provider cannot be nullptr";
42 }

## ◆ ~FlutterCompositor()

flutter::FlutterCompositor::~FlutterCompositor | ( |  | ) |
| default

## Member Function Documentation

## ◆ CreateBackingStore()

bool flutter::FlutterCompositor::CreateBackingStore | ( | const FlutterBackingStoreConfig * | config,
|  | FlutterBackingStore * | backing_store_out
| ) |  |

Definition at line 44 of file FlutterCompositor.mm.

45 {
46 // TODO(dkwingsmt): This class only supports single-view for now. As more
47 // classes are gradually converted to multi-view, it should get the view ID
48 // from somewhere.
49 FlutterView* view = [view_provider_ viewForIdentifier:kFlutterImplicitViewId];
50 if (!view) {
51 return false;
52 }
53
54 CGSize size = CGSizeMake(config->size.width, config->size.height);
55 FlutterSurface* surface = [view.surfaceManager surfaceForSize:size];
56 memset(backing_store_out, 0, sizeof(FlutterBackingStore));
57 backing_store_out->struct_size = sizeof(FlutterBackingStore);
58 backing_store_out->type = kFlutterBackingStoreTypeMetal;
59 backing_store_out->metal.struct_size = sizeof(FlutterMetalBackingStore);
60 backing_store_out->metal.texture = surface.asFlutterMetalTexture;
61 return true;
62 }

References FlutterSurface::asFlutterMetalTexture, and FlutterView::surfaceManager.

## ◆ Present()

bool flutter::FlutterCompositor::Present | ( | FlutterViewIdentifier | view_id,
|  | const FlutterLayer ** | layers,
|  | size_t | layers_count
| ) |  |

Definition at line 64 of file FlutterCompositor.mm.

66 {
67 FlutterView* view = [view_provider_ viewForIdentifier:view_id];
68 if (!view) {
69 return false;
70 }
71
72 NSMutableArray* surfaces = [NSMutableArray array];
73 for (size_t i = 0; i < layers_count; i++) {
74 const FlutterLayer* layer = layers[i];
75 if (layer->type == kFlutterLayerContentTypeBackingStore) {
76 FlutterSurface* surface =
77 [FlutterSurface fromFlutterMetalTexture:&layer->backing_store->metal.texture];
78
79 if (surface) {
80 FlutterSurfacePresentInfo* info = [[FlutterSurfacePresentInfo alloc] init];
81 info.surface = surface;
82 info.offset = CGPointMake(layer->offset.x, layer->offset.y);
83 info.zIndex = i;
84 FlutterBackingStorePresentInfo* present_info = layer->backing_store_present_info;
85 if (present_info != nullptr && present_info->paint_region != nullptr) {
86 auto paint_region = present_info->paint_region;
87 // Safe because the size of FlutterRect is not expected to change.
88 info.paintRegion = std::vector<FlutterRect>(
89 paint_region->rects, paint_region->rects + paint_region->rects_count);
90 }
91 [surfaces addObject:info];
92 }
93 }
94 }
95
96 CFTimeInterval presentation_time = 0;
97
98 if (layers_count > 0 && layers[0]->presentation_time != 0) {
99 presentation_time = [time_converter_ engineTimeToCAMediaTime:layers[0]->presentation_time];
100 }
101
102 // Notify block below may be called asynchronously, hence the need to copy
103 // the layer information instead of passing the original pointers from embedder.
104 auto layers_copy = std::make_shared<std::vector<LayerVariant>>(CopyLayers(layers, layers_count));
105
106 [view.surfaceManager
107 presentSurfaces:surfaces
108 atTime:presentation_time
109 notify:^{
110 // Gets a presenter or create a new one for the view.
111 ViewPresenter& presenter = presenters_[view_id];
112 presenter.PresentPlatformViews(view, *layers_copy, platform_view_controller_);
113 }];
114
115 return true;
116 }

References FlutterSurfacePresentInfo::offset, FlutterSurfacePresentInfo::paintRegion, FlutterSurfacePresentInfo::surface, FlutterView::surfaceManager, and FlutterSurfacePresentInfo::zIndex.

The documentation for this class was generated from the following files:

- shell/platform/darwin/macos/framework/Source/FlutterCompositor.h
- shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

FlutterView::surfaceManager
FlutterSurfaceManager * surfaceManager
Definition: FlutterView.h:57
-[FlutterSurface asFlutterMetalTexture]
FlutterMetalTexture asFlutterMetalTexture()
Definition: FlutterSurface.mm:59
FlutterSurface
Definition: FlutterSurface.h:16
FlutterSurfacePresentInfo::surface
FlutterSurface * surface
Definition: FlutterSurfaceManager.h:20
FlutterSurfacePresentInfo::offset
CGPoint offset
Definition: FlutterSurfaceManager.h:21
FlutterSurfacePresentInfo
Definition: FlutterSurfaceManager.h:18
FlutterSurfacePresentInfo::zIndex
size_t zIndex
Definition: FlutterSurfaceManager.h:22
FlutterView
Definition: FlutterView.h:35
FlutterSurfacePresentInfo::paintRegion
std::vector< FlutterRect > paintRegion
Definition: FlutterSurfaceManager.h:23