Flutter macOS Embedder
flutter::FlutterCompositor Class Reference

#include <FlutterCompositor.h>

Public Member Functions

 FlutterCompositor (id< FlutterViewProvider > view_provider, 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 25 of file FlutterCompositor.h.

Constructor & Destructor Documentation

◆ FlutterCompositor()

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

Definition at line 12 of file FlutterCompositor.mm.

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

◆ ~FlutterCompositor()

flutter::FlutterCompositor::~FlutterCompositor ( )
default

Member Function Documentation

◆ CreateBackingStore()

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

Definition at line 20 of file FlutterCompositor.mm.

21  {
22  // TODO(dkwingsmt): This class only supports single-view for now. As more
23  // classes are gradually converted to multi-view, it should get the view ID
24  // from somewhere.
25  FlutterView* view = [view_provider_ viewForId:kFlutterImplicitViewId];
26  if (!view) {
27  return false;
28  }
29 
30  CGSize size = CGSizeMake(config->size.width, config->size.height);
31  FlutterSurface* surface = [view.surfaceManager surfaceForSize:size];
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);
36  backing_store_out->metal.texture = surface.asFlutterMetalTexture;
37  return true;
38 }

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 40 of file FlutterCompositor.mm.

42  {
43  FlutterView* view = [view_provider_ viewForId:view_id];
44  if (!view) {
45  return false;
46  }
47 
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) {
52  FlutterSurface* surface =
53  [FlutterSurface fromFlutterMetalTexture:&layer->backing_store->metal.texture];
54 
55  if (surface) {
57  info.surface = surface;
58  info.offset = CGPointMake(layer->offset.x, layer->offset.y);
59  info.zIndex = i;
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;
63  // Safe because the size of FlutterRect is not expected to change.
64  info.paintRegion = std::vector<FlutterRect>(
65  paint_region->rects, paint_region->rects + paint_region->rects_count);
66  }
67  [surfaces addObject:info];
68  }
69  }
70  }
71 
72  [view.surfaceManager present:surfaces
73  notify:^{
74  PresentPlatformViews(view, layers, layers_count);
75  }];
76 
77  return true;
78 }

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:66
-[FlutterSurface asFlutterMetalTexture]
FlutterMetalTexture asFlutterMetalTexture()
Definition: FlutterSurface.mm:45
kFlutterImplicitViewId
constexpr FlutterViewId kFlutterImplicitViewId
Definition: FlutterView.h:23
FlutterSurface
Definition: FlutterSurface.h:13
FlutterSurfacePresentInfo::surface
FlutterSurface * surface
Definition: FlutterSurfaceManager.h:17
FlutterSurfacePresentInfo::offset
CGPoint offset
Definition: FlutterSurfaceManager.h:18
FlutterSurfacePresentInfo
Definition: FlutterSurfaceManager.h:15
FlutterSurfacePresentInfo::zIndex
size_t zIndex
Definition: FlutterSurfaceManager.h:19
FlutterView
Definition: FlutterView.h:45
FlutterSurfacePresentInfo::paintRegion
std::vector< FlutterRect > paintRegion
Definition: FlutterSurfaceManager.h:20