7
7
#include " flutter/lib/ui/compositing/scene.h"
8
8
#include " flutter/lib/ui/ui_dart_state.h"
9
9
#include " flutter/lib/ui/window/platform_message_response_dart.h"
10
+ #include " flutter/lib/ui/window/screen.h"
10
11
#include " flutter/lib/ui/window/window.h"
12
+ #include " lib/ui/window/screen_metrics.h"
11
13
#include " third_party/tonic/converter/dart_converter.h"
12
14
#include " third_party/tonic/dart_args.h"
13
15
#include " third_party/tonic/dart_library_natives.h"
@@ -188,7 +190,7 @@ PlatformConfigurationClient::~PlatformConfigurationClient() {}
188
190
189
191
PlatformConfiguration::PlatformConfiguration (
190
192
PlatformConfigurationClient* client)
191
- : client_(client), window_( new Window({ 1.0 , 0.0 , 0.0 })) {}
193
+ : client_(client) {}
192
194
193
195
PlatformConfiguration::~PlatformConfiguration () {}
194
196
@@ -197,11 +199,6 @@ void PlatformConfiguration::DidCreateIsolate() {
197
199
Dart_LookupLibrary (tonic::ToDart (" dart:ui" )));
198
200
}
199
201
200
- void PlatformConfiguration::SetWindowMetrics (
201
- const ViewportMetrics& window_metrics) {
202
- window_->UpdateWindowMetrics (library_, window_metrics);
203
- }
204
-
205
202
void PlatformConfiguration::UpdateLocales (
206
203
const std::vector<std::string>& locales) {
207
204
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state ().lock ();
@@ -439,4 +436,102 @@ void PlatformConfiguration::RegisterNatives(
439
436
});
440
437
}
441
438
439
+ void PlatformConfiguration::SetWindowMetrics (
440
+ const std::vector<ViewportMetrics>& window_metrics) {
441
+ WindowMap updated;
442
+ for (const auto & metrics : window_metrics) {
443
+ WindowMap::iterator found = windows_.find (metrics.view_id );
444
+ if (found == windows_.end ()) {
445
+ // A new window that needs to be added
446
+ std::shared_ptr<Window> new_window = std::make_shared<Window>(metrics);
447
+ updated.insert (std::make_pair (metrics.view_id , new_window));
448
+ new_window->UpdateWindowMetrics (library_, metrics);
449
+ } else {
450
+ // An existing window that needs to be updated, add it to the updated
451
+ // list, and remove it from the existing screens.
452
+ (*found).second ->UpdateWindowMetrics (library_, metrics);
453
+ updated.insert (*found);
454
+ windows_.erase (found);
455
+ }
456
+ }
457
+
458
+ // Anything left in windows_ didn't exist in the window_metrics supplied, and
459
+ // so will be removed.
460
+ std::vector<int64_t > removed_ids;
461
+ for (const auto & entry : windows_) {
462
+ removed_ids.push_back (entry.first );
463
+ }
464
+
465
+ windows_.swap (updated);
466
+
467
+ std::shared_ptr<tonic::DartState> dart_state = library_.dart_state ().lock ();
468
+ if (!dart_state) {
469
+ return ;
470
+ }
471
+ tonic::DartState::Scope scope (dart_state);
472
+ if (!removed_ids.empty ()) {
473
+ tonic::LogIfError (tonic::DartInvokeField (library_.value (), " _removeWindows" ,
474
+ {
475
+ tonic::ToDart (removed_ids),
476
+ }));
477
+ }
478
+ }
479
+
480
+ void PlatformConfiguration::SetScreenMetrics (
481
+ const std::vector<ScreenMetrics>& screen_metrics) {
482
+ ScreenMap updated;
483
+ for (const auto & metrics : screen_metrics) {
484
+ ScreenMap::iterator found = screens_.find (metrics.screen_id );
485
+ if (found == screens_.end ()) {
486
+ // A new screen that needs to be added
487
+ std::shared_ptr<Screen> new_screen = std::make_shared<Screen>(metrics);
488
+ updated.insert (std::make_pair (metrics.screen_id , new_screen));
489
+ new_screen->UpdateScreenMetrics (library_, metrics);
490
+ } else {
491
+ // An existing screen that needs to be updated, add it to the updated
492
+ // list, and remove it from the existing screens.
493
+ (*found).second ->UpdateScreenMetrics (library_, metrics);
494
+ updated.insert (*found);
495
+ screens_.erase (found);
496
+ }
497
+ }
498
+
499
+ // Anything left in screens_ didn't exist in the screen_metrics supplied, and
500
+ // so will be removed.
501
+ std::vector<int64_t > removed_ids;
502
+ for (const auto & entry : screens_) {
503
+ removed_ids.push_back (entry.first );
504
+ }
505
+
506
+ screens_.swap (updated);
507
+
508
+ std::shared_ptr<tonic::DartState> dart_state = library_.dart_state ().lock ();
509
+ if (!dart_state) {
510
+ return ;
511
+ }
512
+ tonic::DartState::Scope scope (dart_state);
513
+ if (!removed_ids.empty ()) {
514
+ tonic::LogIfError (tonic::DartInvokeField (library_.value (), " _removeScreens" ,
515
+ {
516
+ tonic::ToDart (removed_ids),
517
+ }));
518
+ }
519
+ }
520
+
521
+ std::shared_ptr<Window> PlatformConfiguration::get_window (int64_t window_id) {
522
+ if (windows_.find (window_id) == windows_.end ()) {
523
+ FML_DLOG (WARNING) << " Unable to find window with id " << window_id;
524
+ return nullptr ;
525
+ }
526
+ return windows_.at (window_id);
527
+ }
528
+
529
+ std::shared_ptr<Screen> PlatformConfiguration::get_screen (int64_t screen_id) {
530
+ if (screens_.find (screen_id) == screens_.end ()) {
531
+ FML_DLOG (WARNING) << " Unable to find screen with id " << screen_id;
532
+ return nullptr ;
533
+ }
534
+ return screens_.at (screen_id);
535
+ }
536
+
442
537
} // namespace flutter
0 commit comments