flutter_flutter/shell/common/display_manager.cc
Kaushik Iska 67fdd7eded
Embedder API Support for display settings (#21355)
Embedders can now notify shell during startup about the various displays and their corresponding settings.
Adds a notion of Display update type which can later include chages to displays during runtime such as addition / removal / reconfiguration of displays.

We also remove the responsibility of providing the refresh rate from `vsync_waiter` to `DisplayManager`.
Rewires existing platform implementations of the said API to use `Shell::OnDisplayUpdate` to notify the display manager of the startup configuration.

DisplayManager is also thread-safe to account for rasterizer and UI thread accesses.
2020-09-25 11:04:10 -07:00

50 lines
1.3 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/common/display_manager.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/macros.h"
namespace flutter {
DisplayManager::DisplayManager() = default;
DisplayManager::~DisplayManager() = default;
double DisplayManager::GetMainDisplayRefreshRate() const {
std::scoped_lock lock(displays_mutex_);
if (displays_.empty()) {
return kUnknownDisplayRefreshRate;
} else {
return displays_[0].GetRefreshRate();
}
}
void DisplayManager::HandleDisplayUpdates(DisplayUpdateType update_type,
std::vector<Display> displays) {
std::scoped_lock lock(displays_mutex_);
CheckDisplayConfiguration(displays);
switch (update_type) {
case DisplayUpdateType::kStartup:
FML_CHECK(displays_.empty());
displays_ = displays;
return;
default:
FML_CHECK(false) << "Unknown DisplayUpdateType.";
}
}
void DisplayManager::CheckDisplayConfiguration(
std::vector<Display> displays) const {
FML_CHECK(!displays.empty());
if (displays.size() > 1) {
for (auto& display : displays) {
FML_CHECK(display.GetDisplayId().has_value());
}
}
}
} // namespace flutter