|
11 | 11 | #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
|
12 | 12 | #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureGL.h"
|
13 | 13 | #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h"
|
| 14 | +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController_Internal.h" |
14 | 15 | #import "flutter/shell/platform/embedder/embedder.h"
|
15 | 16 |
|
16 | 17 | /**
|
@@ -204,6 +205,11 @@ @implementation FlutterEngine {
|
204 | 205 |
|
205 | 206 | // FlutterCompositor is copied and used in embedder.cc.
|
206 | 207 | FlutterCompositor _compositor;
|
| 208 | + |
| 209 | + // A method channel for platform view functionality. |
| 210 | + FlutterMethodChannel* _platformViewsChannel; |
| 211 | + |
| 212 | + FlutterPlatformViewController* _platformViewController; |
207 | 213 | }
|
208 | 214 |
|
209 | 215 | - (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)project {
|
@@ -313,6 +319,9 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
|
313 | 319 | flutterArguments.aot_data = _aotData;
|
314 | 320 | }
|
315 | 321 |
|
| 322 | + [self setupPlatformViewChannel]; |
| 323 | + [self createPlatformViewController]; |
| 324 | + |
316 | 325 | flutterArguments.compositor = [self createFlutterCompositor];
|
317 | 326 |
|
318 | 327 | FlutterEngineResult result = _embedderAPI.Initialize(
|
@@ -369,54 +378,6 @@ - (void)setViewController:(FlutterViewController*)controller {
|
369 | 378 | }
|
370 | 379 | }
|
371 | 380 |
|
372 |
| -- (FlutterCompositor*)createFlutterCompositor { |
373 |
| - // TODO(richardjcai): Add support for creating a FlutterGLCompositor |
374 |
| - // with a nil _viewController for headless engines. |
375 |
| - // https://github.com/flutter/flutter/issues/71606 |
376 |
| - if (_viewController == nullptr) { |
377 |
| - return nullptr; |
378 |
| - } |
379 |
| - |
380 |
| - [_mainOpenGLContext makeCurrentContext]; |
381 |
| - |
382 |
| - _macOSGLCompositor = std::make_unique<flutter::FlutterGLCompositor>(_viewController); |
383 |
| - |
384 |
| - _compositor = {}; |
385 |
| - _compositor.struct_size = sizeof(FlutterCompositor); |
386 |
| - _compositor.user_data = _macOSGLCompositor.get(); |
387 |
| - |
388 |
| - _compositor.create_backing_store_callback = [](const FlutterBackingStoreConfig* config, // |
389 |
| - FlutterBackingStore* backing_store_out, // |
390 |
| - void* user_data // |
391 |
| - ) { |
392 |
| - return reinterpret_cast<flutter::FlutterGLCompositor*>(user_data)->CreateBackingStore( |
393 |
| - config, backing_store_out); |
394 |
| - }; |
395 |
| - |
396 |
| - _compositor.collect_backing_store_callback = [](const FlutterBackingStore* backing_store, // |
397 |
| - void* user_data // |
398 |
| - ) { |
399 |
| - return reinterpret_cast<flutter::FlutterGLCompositor*>(user_data)->CollectBackingStore( |
400 |
| - backing_store); |
401 |
| - }; |
402 |
| - |
403 |
| - _compositor.present_layers_callback = [](const FlutterLayer** layers, // |
404 |
| - size_t layers_count, // |
405 |
| - void* user_data // |
406 |
| - ) { |
407 |
| - return reinterpret_cast<flutter::FlutterGLCompositor*>(user_data)->Present(layers, |
408 |
| - layers_count); |
409 |
| - }; |
410 |
| - |
411 |
| - __weak FlutterEngine* weak_self = self; |
412 |
| - _macOSGLCompositor->SetPresentCallback( |
413 |
| - [weak_self]() { return [weak_self engineCallbackOnPresent]; }); |
414 |
| - |
415 |
| - _compositor.avoid_backing_store_cache = true; |
416 |
| - |
417 |
| - return &_compositor; |
418 |
| -} |
419 |
| - |
420 | 381 | - (id<FlutterBinaryMessenger>)binaryMessenger {
|
421 | 382 | // TODO(stuartmorgan): Switch to FlutterBinaryMessengerRelay to avoid plugins
|
422 | 383 | // keeping the engine alive.
|
@@ -493,6 +454,10 @@ - (void)sendPointerEvent:(const FlutterPointerEvent&)event {
|
493 | 454 | _embedderAPI.SendPointerEvent(_engine, &event, 1);
|
494 | 455 | }
|
495 | 456 |
|
| 457 | +- (FlutterPlatformViewController*)platformViewController { |
| 458 | + return _platformViewController; |
| 459 | +} |
| 460 | + |
496 | 461 | #pragma mark - Private methods
|
497 | 462 |
|
498 | 463 | - (void)sendUserLocales {
|
@@ -600,6 +565,72 @@ - (void)shutDownEngine {
|
600 | 565 | _engine = nullptr;
|
601 | 566 | }
|
602 | 567 |
|
| 568 | +- (FlutterCompositor*)createFlutterCompositor { |
| 569 | + // TODO(richardjcai): Add support for creating a FlutterGLCompositor |
| 570 | + // with a nil _viewController for headless engines. |
| 571 | + // https://github.com/flutter/flutter/issues/71606 |
| 572 | + if (_viewController == nullptr) { |
| 573 | + return nullptr; |
| 574 | + } |
| 575 | + |
| 576 | + [_mainOpenGLContext makeCurrentContext]; |
| 577 | + |
| 578 | + _macOSGLCompositor = |
| 579 | + std::make_unique<flutter::FlutterGLCompositor>(_viewController, _platformViewController); |
| 580 | + |
| 581 | + _compositor = {}; |
| 582 | + _compositor.struct_size = sizeof(FlutterCompositor); |
| 583 | + _compositor.user_data = _macOSGLCompositor.get(); |
| 584 | + |
| 585 | + _compositor.create_backing_store_callback = [](const FlutterBackingStoreConfig* config, // |
| 586 | + FlutterBackingStore* backing_store_out, // |
| 587 | + void* user_data // |
| 588 | + ) { |
| 589 | + return reinterpret_cast<flutter::FlutterGLCompositor*>(user_data)->CreateBackingStore( |
| 590 | + config, backing_store_out); |
| 591 | + }; |
| 592 | + |
| 593 | + _compositor.collect_backing_store_callback = [](const FlutterBackingStore* backing_store, // |
| 594 | + void* user_data // |
| 595 | + ) { |
| 596 | + return reinterpret_cast<flutter::FlutterGLCompositor*>(user_data)->CollectBackingStore( |
| 597 | + backing_store); |
| 598 | + }; |
| 599 | + |
| 600 | + _compositor.present_layers_callback = [](const FlutterLayer** layers, // |
| 601 | + size_t layers_count, // |
| 602 | + void* user_data // |
| 603 | + ) { |
| 604 | + return reinterpret_cast<flutter::FlutterGLCompositor*>(user_data)->Present(layers, |
| 605 | + layers_count); |
| 606 | + }; |
| 607 | + |
| 608 | + __weak FlutterEngine* weak_self = self; |
| 609 | + _macOSGLCompositor->SetPresentCallback( |
| 610 | + [weak_self]() { return [weak_self engineCallbackOnPresent]; }); |
| 611 | + |
| 612 | + _compositor.avoid_backing_store_cache = true; |
| 613 | + |
| 614 | + return &_compositor; |
| 615 | +} |
| 616 | + |
| 617 | +- (void)createPlatformViewController { |
| 618 | + _platformViewController = [[FlutterPlatformViewController alloc] init]; |
| 619 | +} |
| 620 | + |
| 621 | +- (void)setupPlatformViewChannel { |
| 622 | + _platformViewsChannel = |
| 623 | + [FlutterMethodChannel methodChannelWithName:@"flutter/platform_views" |
| 624 | + binaryMessenger:self.binaryMessenger |
| 625 | + codec:[FlutterStandardMethodCodec sharedInstance]]; |
| 626 | + |
| 627 | + __weak FlutterEngine* weak_self = self; |
| 628 | + [_platformViewsChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { |
| 629 | + NSLog(@"FlutterEngine::handleMethodCall"); |
| 630 | + [[weak_self platformViewController] handleMethodCall:call result:result]; |
| 631 | + }]; |
| 632 | +} |
| 633 | + |
603 | 634 | #pragma mark - FlutterBinaryMessenger
|
604 | 635 |
|
605 | 636 | - (void)sendOnChannel:(nonnull NSString*)channel message:(nullable NSData*)message {
|
|
0 commit comments