Flutter macOS Embedder
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 (FlutterViewId view_id, const FlutterLayer **layers, size_t layers_count)
 

Detailed Description

Definition at line 30 of file FlutterCompositor.h.

Constructor & Destructor Documentation

◆ FlutterCompositor()

flutter::FlutterCompositor::FlutterCompositor ( id< FlutterViewProvider view_provider,
FlutterTimeConverter time_converter,
FlutterPlatformViewController platform_views_controller 
)
explicit

Definition at line 25 of file FlutterCompositor.mm.

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";
33 }

◆ ~FlutterCompositor()

flutter::FlutterCompositor::~FlutterCompositor ( )
default

Member Function Documentation

◆ CreateBackingStore()

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

Definition at line 35 of file FlutterCompositor.mm.

36  {
37  // TODO(dkwingsmt): This class only supports single-view for now. As more
38  // classes are gradually converted to multi-view, it should get the view ID
39  // from somewhere.
40  FlutterView* view = [view_provider_ viewForId:kFlutterImplicitViewId];
41  if (!view) {
42  return false;
43  }
44 
45  CGSize size = CGSizeMake(config->size.width, config->size.height);
46  FlutterSurface* surface = [view.surfaceManager surfaceForSize:size];
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);
51  backing_store_out->metal.texture = surface.asFlutterMetalTexture;
52  return true;
53 }

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

◆ Present()

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

Definition at line 55 of file FlutterCompositor.mm.

57  {
58  FlutterView* view = [view_provider_ viewForId:view_id];
59  if (!view) {
60  return false;
61  }
62 
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) {
67  FlutterSurface* surface =
68  [FlutterSurface fromFlutterMetalTexture:&layer->backing_store->metal.texture];
69 
70  if (surface) {
72  info.surface = surface;
73  info.offset = CGPointMake(layer->offset.x, layer->offset.y);
74  info.zIndex = i;
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;
78  // Safe because the size of FlutterRect is not expected to change.
79  info.paintRegion = std::vector<FlutterRect>(
80  paint_region->rects, paint_region->rects + paint_region->rects_count);
81  }
82  [surfaces addObject:info];
83  }
84  }
85  }
86 
87  CFTimeInterval presentation_time = 0;
88 
89  if (layers_count > 0 && layers[0]->presentation_time != 0) {
90  presentation_time = [time_converter_ engineTimeToCAMediaTime:layers[0]->presentation_time];
91  }
92 
93  // Notify block below may be called asynchronously, hence the need to copy
94  // the layer information instead of passing the original pointers from embedder.
95  auto platform_views_layers = std::make_shared<std::vector<PlatformViewLayerWithIndex>>(
96  CopyPlatformViewLayers(layers, layers_count));
97 
98  [view.surfaceManager presentSurfaces:surfaces
99  atTime:presentation_time
100  notify:^{
101  PresentPlatformViews(view, *platform_views_layers);
102  }];
103 
104  return true;
105 }

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


The documentation for this class was generated from the following files:
FlutterView::surfaceManager
FlutterSurfaceManager * surfaceManager
Definition: FlutterView.h:69
-[FlutterSurface asFlutterMetalTexture]
FlutterMetalTexture asFlutterMetalTexture()
Definition: FlutterSurface.mm:45
kFlutterImplicitViewId
constexpr FlutterViewId kFlutterImplicitViewId
Definition: FlutterView.h:26
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:48
FlutterSurfacePresentInfo::paintRegion
std::vector< FlutterRect > paintRegion
Definition: FlutterSurfaceManager.h:23