|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +#ifndef FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_ |
| 6 | +#define FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_ |
| 7 | + |
| 8 | +#include <mutex> |
| 9 | +#include <vector> |
| 10 | + |
| 11 | +#include "flutter/shell/common/display.h" |
| 12 | + |
| 13 | +namespace flutter { |
| 14 | + |
| 15 | +/// The update type parameter that is passed to |
| 16 | +/// `DisplayManager::HandleDisplayUpdates`. |
| 17 | +enum class DisplayUpdateType { |
| 18 | + /// `flutter::Display`s that were active during start-up. A display is |
| 19 | + /// considered active if: |
| 20 | + /// 1. The frame buffer hardware is connected. |
| 21 | + /// 2. The display is drawable, e.g. it isn't being mirrored from another |
| 22 | + /// connected display or sleeping. |
| 23 | + kStartup |
| 24 | +}; |
| 25 | + |
| 26 | +/// Manages lifecycle of the connected displays. This class is thread-safe. |
| 27 | +class DisplayManager { |
| 28 | + public: |
| 29 | + DisplayManager(); |
| 30 | + |
| 31 | + ~DisplayManager(); |
| 32 | + |
| 33 | + /// Returns the display refresh rate of the main display. In cases where there |
| 34 | + /// is only one display connected, it will return that. We do not yet support |
| 35 | + /// cases where there are multiple displays. |
| 36 | + /// |
| 37 | + /// When there are no registered displays, it returns |
| 38 | + /// `kUnknownDisplayRefreshRate`. |
| 39 | + double GetMainDisplayRefreshRate() const; |
| 40 | + |
| 41 | + /// Handles the display updates. |
| 42 | + void HandleDisplayUpdates(DisplayUpdateType update_type, |
| 43 | + std::vector<Display> displays); |
| 44 | + |
| 45 | + private: |
| 46 | + /// Guards `displays_` vector. |
| 47 | + mutable std::mutex displays_mutex_; |
| 48 | + std::vector<Display> displays_; |
| 49 | + |
| 50 | + /// Checks that the provided display configuration is valid. Currently this |
| 51 | + /// ensures that all the displays have an id in the case there are multiple |
| 52 | + /// displays. In case where there is a single display, it is valid for the |
| 53 | + /// display to not have an id. |
| 54 | + void CheckDisplayConfiguration(std::vector<Display> displays) const; |
| 55 | +}; |
| 56 | + |
| 57 | +} // namespace flutter |
| 58 | + |
| 59 | +#endif // FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_ |
0 commit comments