Flutter Engine
 
Loading...
Searching...
No Matches
flutter::FlutterCompositor Class Reference

#include <FlutterCompositor.h>

Public Member Functions

 FlutterCompositor (id< FlutterViewProvider > view_provider, FlutterTimeConverter *time_converter, FlutterPlatformViewController *platform_views_controller)
 
 ~FlutterCompositor ()=default
 
void AddView (FlutterViewId view_id)
 
void RemoveView (FlutterViewId view_id)
 
bool CreateBackingStore (const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
 
bool Present (FlutterViewIdentifier view_id, const FlutterLayer **layers, size_t layers_count)
 
size_t DebugNumViews ()
 

Detailed Description

Definition at line 36 of file FlutterCompositor.h.

Constructor & Destructor Documentation

◆ FlutterCompositor()

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}
#define FML_CHECK(condition)
Definition logging.h:104

References FML_CHECK.

◆ ~FlutterCompositor()

flutter::FlutterCompositor::~FlutterCompositor ( )
default

Member Function Documentation

◆ AddView()

void FlutterCompositor::AddView ( FlutterViewId  view_id)

Definition at line 44 of file FlutterCompositor.mm.

44 {
45 dispatch_assert_queue(dispatch_get_main_queue());
46 presenters_.try_emplace(view_id);
47}
G_BEGIN_DECLS FlutterViewId view_id

References view_id.

◆ CreateBackingStore()

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

Definition at line 54 of file FlutterCompositor.mm.

55 {
56 FlutterView* view = [view_provider_ viewForIdentifier:config->view_id];
57 if (!view) {
58 return false;
59 }
60
61 CGSize size = CGSizeMake(config->size.width, config->size.height);
62 FlutterSurface* surface = [view.surfaceManager surfaceForSize:size];
63 memset(backing_store_out, 0, sizeof(FlutterBackingStore));
64 backing_store_out->struct_size = sizeof(FlutterBackingStore);
65 backing_store_out->type = kFlutterBackingStoreTypeMetal;
66 backing_store_out->metal.struct_size = sizeof(FlutterMetalBackingStore);
67 backing_store_out->metal.texture = surface.asFlutterMetalTexture;
68 return true;
69}
@ kFlutterBackingStoreTypeMetal
Specifies a Metal backing store. This is backed by a Metal texture.
Definition embedder.h:2055
VkSurfaceKHR surface
Definition main.cc:65
FlView * view
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
FlutterSize size
The size of the render target the engine expects to render into.
Definition embedder.h:2093
FlutterMetalBackingStore metal
Definition embedder.h:2083
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2071
size_t struct_size
The size of this struct. Must be sizeof(FlutterBackingStore).
Definition embedder.h:2065
size_t struct_size
The size of this struct. Must be sizeof(FlutterMetalBackingStore).
Definition embedder.h:1969
FlutterMetalTexture texture
Definition embedder.h:1974
double height
Definition embedder.h:629
double width
Definition embedder.h:628

References FlutterSize::height, kFlutterBackingStoreTypeMetal, FlutterBackingStore::metal, flutter::size, FlutterBackingStoreConfig::size, FlutterMetalBackingStore::struct_size, FlutterBackingStore::struct_size, surface, FlutterMetalBackingStore::texture, FlutterBackingStore::type, view, FlutterBackingStoreConfig::view_id, and FlutterSize::width.

◆ DebugNumViews()

size_t FlutterCompositor::DebugNumViews ( )

Definition at line 134 of file FlutterCompositor.mm.

134 {
135 return presenters_.size();
136}

Referenced by flutter::testing::TEST_F().

◆ Present()

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

Definition at line 71 of file FlutterCompositor.mm.

73 {
74 FlutterView* view = [view_provider_ viewForIdentifier:view_id];
75 if (!view) {
76 return false;
77 }
78
79 NSMutableArray* surfaces = [NSMutableArray array];
80 for (size_t i = 0; i < layers_count; i++) {
81 const FlutterLayer* layer = layers[i];
84 [FlutterSurface fromFlutterMetalTexture:&layer->backing_store->metal.texture];
85
86 if (surface) {
88 info.surface = surface;
89 info.offset = CGPointMake(layer->offset.x, layer->offset.y);
90 info.zIndex = i;
92 if (present_info != nullptr && present_info->paint_region != nullptr) {
93 auto paint_region = present_info->paint_region;
94 // Safe because the size of FlutterRect is not expected to change.
95 info.paintRegion = std::vector<FlutterRect>(
96 paint_region->rects, paint_region->rects + paint_region->rects_count);
97 }
98 [surfaces addObject:info];
99 }
100 }
101 }
102
103 CFTimeInterval presentation_time = 0;
104
105 if (layers_count > 0 && layers[0]->presentation_time != 0) {
106 presentation_time = [time_converter_ engineTimeToCAMediaTime:layers[0]->presentation_time];
107 }
108
109 // Notify block below may be called asynchronously, hence the need to copy
110 // the layer information instead of passing the original pointers from embedder.
111 auto layers_copy = std::make_shared<std::vector<LayerVariant>>(CopyLayers(layers, layers_count));
112
113 [view.surfaceManager presentSurfaces:surfaces
114 atTime:presentation_time
115 notify:^{
116 // Accessing presenters_ here does not need a
117 // lock to avoid race condition against
118 // AddView and RemoveView, since all three
119 // take place on the platform thread. (The
120 // macOS API requires platform view presenting
121 // to take place on the platform thread,
122 // enforced by `FlutterThreadSynchronizer`.)
123 dispatch_assert_queue(dispatch_get_main_queue());
124 auto found_presenter = presenters_.find(view_id);
125 if (found_presenter != presenters_.end()) {
126 found_presenter->second.PresentPlatformViews(
127 view, *layers_copy, platform_view_controller_);
128 }
129 }];
130
131 return true;
132}
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2102
const FlutterLayer size_t layers_count
const FlutterLayer ** layers
std::vector< FlutterRect > paintRegion
FlutterPoint offset
Definition embedder.h:2145
FlutterLayerContentType type
Definition embedder.h:2134
const FlutterBackingStore * backing_store
Definition embedder.h:2138
FlutterBackingStorePresentInfo * backing_store_present_info
Definition embedder.h:2151
uint64_t presentation_time
Definition embedder.h:2155

References FlutterLayer::backing_store, FlutterLayer::backing_store_present_info, i, kFlutterLayerContentTypeBackingStore, layers, layers_count, FlutterBackingStore::metal, FlutterSurfacePresentInfo::offset, FlutterLayer::offset, FlutterBackingStorePresentInfo::paint_region, FlutterSurfacePresentInfo::paintRegion, FlutterLayer::presentation_time, surface, FlutterSurfacePresentInfo::surface, FlutterMetalBackingStore::texture, FlutterLayer::type, view, view_id, FlutterPoint::x, FlutterPoint::y, and FlutterSurfacePresentInfo::zIndex.

◆ RemoveView()

void FlutterCompositor::RemoveView ( FlutterViewId  view_id)

Definition at line 49 of file FlutterCompositor.mm.

49 {
50 dispatch_assert_queue(dispatch_get_main_queue());
51 presenters_.erase(view_id);
52}

References view_id.


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