5#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h"
7#include "flutter/common/constants.h"
8#include "flutter/fml/logging.h"
13std::vector<LayerVariant> CopyLayers(
const FlutterLayer** layers,
size_t layer_count) {
14 std::vector<LayerVariant> layers_copy;
15 for (
size_t i = 0;
i < layer_count;
i++) {
16 const auto& layer = layers[
i];
18 layers_copy.push_back(PlatformViewLayer(layer));
20 std::vector<FlutterRect> rects;
22 if (present_info !=
nullptr && present_info->paint_region !=
nullptr) {
23 rects.reserve(present_info->paint_region->rects_count);
24 std::copy(present_info->paint_region->rects,
25 present_info->paint_region->rects + present_info->paint_region->rects_count,
26 std::back_inserter(rects));
28 layers_copy.push_back(BackingStoreLayer{rects});
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";
66 size_t layers_count) {
67 FlutterView* view = [view_provider_ viewForIdentifier:view_id];
72 NSMutableArray* surfaces = [NSMutableArray array];
73 for (
size_t i = 0;
i < layers_count;
i++) {
85 if (present_info !=
nullptr && present_info->
paint_region !=
nullptr) {
88 info.paintRegion = std::vector<FlutterRect>(
89 paint_region->rects, paint_region->rects + paint_region->rects_count);
91 [surfaces addObject:
info];
96 CFTimeInterval presentation_time = 0;
98 if (layers_count > 0 && layers[0]->presentation_time != 0) {
99 presentation_time = [time_converter_ engineTimeToCAMediaTime:layers[0]->
presentation_time];
104 auto layers_copy = std::make_shared<std::vector<LayerVariant>>(CopyLayers(layers, layers_count));
107 presentSurfaces:surfaces
108 atTime:presentation_time
111 ViewPresenter& presenter = presenters_[view_id];
112 presenter.PresentPlatformViews(view, *layers_copy, platform_view_controller_);
118FlutterCompositor::ViewPresenter::ViewPresenter()
119 : mutator_views_([NSMapTable strongToStrongObjectsMapTable]) {}
121void FlutterCompositor::ViewPresenter::PresentPlatformViews(
123 const std::vector<LayerVariant>& layers,
125 FML_DCHECK([[NSThread currentThread] isMainThread])
126 <<
"Must be on the main thread to present platform views";
129 NSMutableArray<FlutterMutatorView*>* present_mutators = [NSMutableArray array];
131 for (
size_t i = 0;
i < layers.size();
i++) {
132 const auto& layer = layers[
i];
133 if (!std::holds_alternative<PlatformViewLayer>(layer)) {
136 const auto&
platform_view = std::get<PlatformViewLayer>(layer);
138 PresentPlatformView(default_base_view,
platform_view,
i, platform_view_controller);
139 [present_mutators addObject:mutator_view];
142 [mutator_view resetHitTestRegion];
143 for (
size_t j =
i + 1; j < layers.size(); j++) {
144 const auto& overlay_layer = layers[j];
145 if (!std::holds_alternative<BackingStoreLayer>(overlay_layer)) {
148 const auto& backing_store_layer = std::get<BackingStoreLayer>(overlay_layer);
149 for (
const auto& flutter_rect : backing_store_layer.paint_region) {
150 double scale = default_base_view.layer.contentsScale;
151 CGRect
rect = CGRectMake(flutter_rect.left /
scale, flutter_rect.top /
scale,
152 (flutter_rect.right - flutter_rect.left) /
scale,
153 (flutter_rect.bottom - flutter_rect.top) /
scale);
154 CGRect intersection = CGRectIntersection(
rect, mutator_view.frame);
155 if (!CGRectIsNull(intersection)) {
156 intersection.origin.x -= mutator_view.frame.origin.x;
157 intersection.origin.y -= mutator_view.frame.origin.y;
158 [mutator_view addHitTestIgnoreRegion:intersection];
164 NSMutableArray<FlutterMutatorView*>* obsolete_mutators =
165 [NSMutableArray arrayWithArray:[mutator_views_ objectEnumerator].allObjects];
166 [obsolete_mutators removeObjectsInArray:present_mutators];
169 [mutator_views_ removeObjectForKey:mutator.platformView];
170 [mutator removeFromSuperview];
173 [platform_view_controller disposePlatformViews];
178 const PlatformViewLayer& layer,
181 FML_DCHECK([[NSThread currentThread] isMainThread])
182 <<
"Must be on the main thread to present platform views";
184 int64_t platform_view_id = layer.identifier();
185 NSView*
platform_view = [platform_view_controller platformViewWithID:platform_view_id];
189 if (cursor_coordinator_ == nil) {
197 cursorCoordiator:cursor_coordinator_];
199 [default_base_view addSubview:container];
202 container.layer.zPosition = index;
203 [container applyFlutterLayer:&layer];
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
FlutterCompositor(id< FlutterViewProvider > view_provider, FlutterTimeConverter *time_converter, FlutterPlatformViewController *platform_views_controller)
bool CreateBackingStore(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out)
bool Present(FlutterViewIdentifier view_id, const FlutterLayer **layers, size_t layers_count)
@ kFlutterLayerContentTypePlatformView
Indicates that the contents of this layer are determined by the embedder.
@ kFlutterLayerContentTypeBackingStore
@ kFlutterBackingStoreTypeMetal
Specifies a Metal backing store. This is backed by a Metal texture.
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
Converts between the time representation used by Flutter Engine and CAMediaTime.
sk_sp< SkBlender > blender SkRect rect
constexpr int64_t kFlutterImplicitViewId
it will be possible to load the file into Perfetto s trace viewer 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.
FlutterRegion * paint_region
FlutterMetalBackingStore metal
FlutterBackingStoreType type
Specifies the type of backing store.
size_t struct_size
The size of this struct. Must be sizeof(FlutterBackingStore).
FlutterLayerContentType type
const FlutterBackingStore * backing_store
FlutterBackingStorePresentInfo * backing_store_present_info
uint64_t presentation_time