1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_DISPLAY_MANAGER_UTIL_DISPLAY_MANAGER_UTIL_H_
#define UI_DISPLAY_MANAGER_UTIL_DISPLAY_MANAGER_UTIL_H_
#include <functional>
#include <string>
#include <vector>
#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/display/display.h"
#include "ui/display/display_layout.h"
#include "ui/display/manager/display_manager_export.h"
#include "ui/display/manager/managed_display_info.h"
#include "ui/display/types/display_constants.h"
namespace gfx {
class Rect;
class Size;
} // namespace gfx
namespace display {
class DisplaySnapshot;
class ManagedDisplayMode;
class ManagedDisplayInfo;
using DisplayInfoList = std::vector<ManagedDisplayInfo>;
// Returns a string describing |state|.
std::string DisplayPowerStateToString(chromeos::DisplayPowerState state);
// Returns a string describing |state|.
std::string VrrStateToString(const base::flat_set<int64_t>& state);
std::string RefreshRateOverrideToString(
const std::unordered_map<int64_t, float>& refresh_rate_override);
// Returns the number of displays in |displays| that should be turned on, per
// |state|. If |display_power| is non-NULL, it is updated to contain the
// on/off state of each corresponding entry in |displays|.
DISPLAY_MANAGER_EXPORT int GetDisplayPower(
const std::vector<raw_ptr<DisplaySnapshot, VectorExperimental>>& displays,
chromeos::DisplayPowerState state,
std::vector<bool>* display_power);
// Determines whether |a| is within an epsilon of |b|.
bool WithinEpsilon(float a, float b);
// Returns a string describing |state|.
std::string MultipleDisplayStateToString(MultipleDisplayState state);
// Sets bits in |protection_mask| for each ContentProtectionMethod supported by
// the display |type|. Returns false for unknown display types.
bool GetContentProtectionMethods(DisplayConnectionType type,
uint32_t* protection_mask);
// Returns a list of display zooms supported by the given |mode|.
DISPLAY_MANAGER_EXPORT std::vector<float> GetDisplayZoomFactors(
const ManagedDisplayMode& mode);
// Returns a list of display zooms supported by the given |display_width|.
DISPLAY_MANAGER_EXPORT std::vector<float> GetDisplayZoomFactorsByDisplayWidth(
const int display_width);
// Returns a list of display zooms based on the provided |dsf| of the display.
// This is useful for displays that have a non unity device scale factors
// applied to them.
DISPLAY_MANAGER_EXPORT std::vector<float> GetDisplayZoomFactorForDsf(float dsf);
// Creates the display mode list for internal display
// based on |native_mode|.
DISPLAY_MANAGER_EXPORT ManagedDisplayInfo::ManagedDisplayModeList
CreateInternalManagedDisplayModeList(const ManagedDisplayMode& native_mode);
// Defines parameters needed to construct a ManagedDisplayMode for Unified
// Desktop.
struct UnifiedDisplayModeParam {
UnifiedDisplayModeParam(float dsf, float scale, bool is_default);
float device_scale_factor = 1.0f;
float display_bounds_scale = 1.0f;
bool is_default_mode = false;
};
// Creates the display mode list for unified display
// based on |native_mode| and |scales|.
DISPLAY_MANAGER_EXPORT ManagedDisplayInfo::ManagedDisplayModeList
CreateUnifiedManagedDisplayModeList(
const ManagedDisplayMode& native_mode,
const std::vector<UnifiedDisplayModeParam>& modes_param_list);
// Returns true if the first display should unconditionally be considered an
// internal display.
bool ForceFirstDisplayInternal();
// If |a_bounds| and |b_bounds| share an edge, the shared edges are computed and
// filled in |a_edge| and |b_edge|, and true is returned. Otherwise, it returns
// false.
DISPLAY_MANAGER_EXPORT bool ComputeBoundary(const gfx::Rect& a_bounds,
const gfx::Rect& b_bounds,
gfx::Rect* a_edge,
gfx::Rect* b_edge);
// If |display_a| and |display_b| share an edge, the shared edges are computed
// and filled in |a_edge_in_screen| and |b_edge_in_screen|, and true is
// returned. Otherwise, it returns false.
DISPLAY_MANAGER_EXPORT bool ComputeBoundary(const Display& display_a,
const Display& display_b,
gfx::Rect* a_edge_in_screen,
gfx::Rect* b_edge_in_screen);
// Sorts id list using `CompareDisplayIds()` in display.h.
DISPLAY_MANAGER_EXPORT void SortDisplayIdList(DisplayIdList* list);
// Check if the list is sorted using `CompareDisplayIds()` in display.h.
DISPLAY_MANAGER_EXPORT bool IsDisplayIdListSorted(const DisplayIdList& list);
// Generate sorted DisplayIdList from iterators.
template <typename Range, typename UnaryOperation = std::identity>
DisplayIdList GenerateDisplayIdList(Range&& range, UnaryOperation op = {}) {
DisplayIdList list;
std::ranges::transform(range, std::back_inserter(list), op);
SortDisplayIdList(&list);
return list;
}
// Creates sorted DisplayIdList.
DISPLAY_MANAGER_EXPORT DisplayIdList CreateDisplayIdList(const Displays& list);
DISPLAY_MANAGER_EXPORT DisplayIdList
CreateDisplayIdList(const DisplayInfoList& updated_displays);
DISPLAY_MANAGER_EXPORT std::string DisplayIdListToString(
const DisplayIdList& list);
// Get the display id after the output index (8 bits) is masked out.
DISPLAY_MANAGER_EXPORT int64_t GetDisplayIdWithoutOutputIndex(int64_t id);
// Defines parameters needed to set mixed mirror mode.
struct DISPLAY_MANAGER_EXPORT MixedMirrorModeParams {
MixedMirrorModeParams(int64_t src_id, const DisplayIdList& dst_ids);
MixedMirrorModeParams(const MixedMirrorModeParams& mixed_params);
~MixedMirrorModeParams();
int64_t source_id; // Id of the mirroring source display
DisplayIdList destination_ids; // Ids of the mirroring destination displays.
};
// Defines mirror modes used to change the display mode.
enum class MirrorMode {
kOff = 0,
// Normal mode, with one display mirrored to all other connected displays.
kNormal,
// Mixed mode, with one display mirrored to one or more other displays, and
// the rest of the displays are in EXTENDED mode.
kMixed,
};
// Defines the error types of mixed mirror mode parameters.
enum class MixedMirrorModeParamsErrors {
kSuccess = 0,
kErrorSingleDisplay,
kErrorSourceIdNotFound,
kErrorDestinationIdsEmpty,
kErrorDestinationIdNotFound,
kErrorDuplicateId,
};
// Verifies whether the mixed mirror mode parameters are valid.
// |connected_display_ids| is the id list for all connected displays. Returns
// error type for the parameters.
DISPLAY_MANAGER_EXPORT MixedMirrorModeParamsErrors
ValidateParamsForMixedMirrorMode(
const DisplayIdList& connected_display_ids,
const MixedMirrorModeParams& mixed_mode_params);
} // namespace display
#endif // UI_DISPLAY_MANAGER_UTIL_DISPLAY_MANAGER_UTIL_H_
|