forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embedder API Support for display settings (flutter#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.
- Loading branch information
1 parent
aa8d5d4
commit 67fdd7e
Showing
27 changed files
with
645 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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. | ||
|
||
#ifndef FLUTTER_SHELL_COMMON_DISPLAY_H_ | ||
#define FLUTTER_SHELL_COMMON_DISPLAY_H_ | ||
|
||
#include <optional> | ||
|
||
namespace flutter { | ||
|
||
/// Unique ID per display that is stable until the Flutter application restarts. | ||
/// See also: `flutter::Display` | ||
typedef uint64_t DisplayId; | ||
|
||
/// To be used when the display refresh rate is unknown. | ||
static constexpr double kUnknownDisplayRefreshRate = 0; | ||
|
||
/// Display refers to a graphics hardware system consisting of a framebuffer, | ||
/// typically a monitor or a screen. This class holds the various display | ||
/// settings. | ||
class Display { | ||
public: | ||
//------------------------------------------------------------------------------ | ||
/// @brief Construct a new Display object in case where the display id of the | ||
/// display is known. In cases where there is more than one display, every | ||
/// display is expected to have a display id. | ||
/// | ||
Display(DisplayId display_id, double refresh_rate) | ||
: display_id_(display_id), refresh_rate_(refresh_rate) {} | ||
|
||
//------------------------------------------------------------------------------ | ||
/// @brief Construct a new Display object when there is only a single display. | ||
/// When there are multiple displays, every display must have a display id. | ||
/// | ||
explicit Display(double refresh_rate) | ||
: display_id_({}), refresh_rate_(refresh_rate) {} | ||
|
||
~Display() = default; | ||
|
||
// Get the display's maximum refresh rate in the unit of frame per second. | ||
// Return `kUnknownDisplayRefreshRate` if the refresh rate is unknown. | ||
double GetRefreshRate() const { return refresh_rate_; } | ||
|
||
/// Returns the `DisplayId` of the display. | ||
std::optional<DisplayId> GetDisplayId() const { return display_id_; } | ||
|
||
private: | ||
std::optional<DisplayId> display_id_; | ||
double refresh_rate_; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // FLUTTER_SHELL_COMMON_DISPLAY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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. | ||
|
||
#ifndef FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_ | ||
#define FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_ | ||
|
||
#include <mutex> | ||
#include <vector> | ||
|
||
#include "flutter/shell/common/display.h" | ||
|
||
namespace flutter { | ||
|
||
/// The update type parameter that is passed to | ||
/// `DisplayManager::HandleDisplayUpdates`. | ||
enum class DisplayUpdateType { | ||
/// `flutter::Display`s that were active during start-up. A display is | ||
/// considered active if: | ||
/// 1. The frame buffer hardware is connected. | ||
/// 2. The display is drawable, e.g. it isn't being mirrored from another | ||
/// connected display or sleeping. | ||
kStartup | ||
}; | ||
|
||
/// Manages lifecycle of the connected displays. This class is thread-safe. | ||
class DisplayManager { | ||
public: | ||
DisplayManager(); | ||
|
||
~DisplayManager(); | ||
|
||
/// Returns the display refresh rate of the main display. In cases where there | ||
/// is only one display connected, it will return that. We do not yet support | ||
/// cases where there are multiple displays. | ||
/// | ||
/// When there are no registered displays, it returns | ||
/// `kUnknownDisplayRefreshRate`. | ||
double GetMainDisplayRefreshRate() const; | ||
|
||
/// Handles the display updates. | ||
void HandleDisplayUpdates(DisplayUpdateType update_type, | ||
std::vector<Display> displays); | ||
|
||
private: | ||
/// Guards `displays_` vector. | ||
mutable std::mutex displays_mutex_; | ||
std::vector<Display> displays_; | ||
|
||
/// Checks that the provided display configuration is valid. Currently this | ||
/// ensures that all the displays have an id in the case there are multiple | ||
/// displays. In case where there is a single display, it is valid for the | ||
/// display to not have an id. | ||
void CheckDisplayConfiguration(std::vector<Display> displays) const; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.