| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ | 5 #ifndef UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ |
| 6 #define UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ | 6 #define UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "ui/display/display.h" | 10 #include "ui/display/display.h" |
| 11 #include "ui/display/display_export.h" | 11 #include "ui/display/display_export.h" |
| 12 #include "ui/display/manager/display_layout.h" | 12 #include "ui/display/manager/display_layout.h" |
| 13 #include "ui/display/manager/managed_display_info.h" | 13 #include "ui/display/manager/managed_display_info.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 class Point; | 16 class Point; |
| 17 class Rect; | 17 class Rect; |
| 18 class Size; | 18 class Size; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace display { | 21 namespace display { |
| 22 class ManagedDisplayInfo; | 22 class ManagedDisplayInfo; |
| 23 class ManagedDisplayMode; | 23 class ManagedDisplayMode; |
| 24 | 24 |
| 25 // Creates the display mode list for internal display | 25 // Creates the display mode list for internal display |
| 26 // based on |native_mode|. | 26 // based on |native_mode|. |
| 27 DISPLAY_EXPORT ManagedDisplayInfo::ManagedDisplayModeList | 27 DISPLAY_EXPORT ManagedDisplayInfo::ManagedDisplayModeList |
| 28 CreateInternalManagedDisplayModeList( | 28 CreateInternalManagedDisplayModeList( |
| 29 const scoped_refptr<display::ManagedDisplayMode>& native_mode); | 29 const scoped_refptr<ManagedDisplayMode>& native_mode); |
| 30 | 30 |
| 31 // Creates the display mode list for unified display | 31 // Creates the display mode list for unified display |
| 32 // based on |native_mode| and |scales|. | 32 // based on |native_mode| and |scales|. |
| 33 DISPLAY_EXPORT ManagedDisplayInfo::ManagedDisplayModeList | 33 DISPLAY_EXPORT ManagedDisplayInfo::ManagedDisplayModeList |
| 34 CreateUnifiedManagedDisplayModeList( | 34 CreateUnifiedManagedDisplayModeList( |
| 35 const scoped_refptr<display::ManagedDisplayMode>& native_mode, | 35 const scoped_refptr<ManagedDisplayMode>& native_mode, |
| 36 const std::set<std::pair<float, float>>& dsf_scale_list); | 36 const std::set<std::pair<float, float>>& dsf_scale_list); |
| 37 | 37 |
| 38 // Gets the display mode for |resolution|. Returns false if no display | 38 // Gets the display mode for |resolution|. Returns false if no display |
| 39 // mode matches the resolution, or the display is an internal display. | 39 // mode matches the resolution, or the display is an internal display. |
| 40 DISPLAY_EXPORT scoped_refptr<ManagedDisplayMode> GetDisplayModeForResolution( | 40 DISPLAY_EXPORT scoped_refptr<ManagedDisplayMode> GetDisplayModeForResolution( |
| 41 const ManagedDisplayInfo& info, | 41 const ManagedDisplayInfo& info, |
| 42 const gfx::Size& resolution); | 42 const gfx::Size& resolution); |
| 43 | 43 |
| 44 // Gets the display mode for the next valid UI scale. Returns false | 44 // Gets the display mode for the next valid UI scale. Returns false |
| 45 // if the display is not an internal display. | 45 // if the display is not an internal display. |
| 46 DISPLAY_EXPORT scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextUIScale( | 46 DISPLAY_EXPORT scoped_refptr<ManagedDisplayMode> GetDisplayModeForNextUIScale( |
| 47 const ManagedDisplayInfo& info, | 47 const ManagedDisplayInfo& info, |
| 48 bool up); | 48 bool up); |
| 49 | 49 |
| 50 // Gets the display mode for the next valid resolution. Returns false | 50 // Gets the display mode for the next valid resolution. Returns false |
| 51 // if the display is an internal display. | 51 // if the display is an internal display. |
| 52 DISPLAY_EXPORT scoped_refptr<ManagedDisplayMode> | 52 DISPLAY_EXPORT scoped_refptr<ManagedDisplayMode> |
| 53 GetDisplayModeForNextResolution(const ManagedDisplayInfo& info, bool up); | 53 GetDisplayModeForNextResolution(const ManagedDisplayInfo& info, bool up); |
| 54 | 54 |
| 55 // Tests if the |info| has display mode that matches |ui_scale|. | 55 // Tests if the |info| has display mode that matches |ui_scale|. |
| 56 bool HasDisplayModeForUIScale(const display::ManagedDisplayInfo& info, | 56 bool HasDisplayModeForUIScale(const ManagedDisplayInfo& info, float ui_scale); |
| 57 float ui_scale); | |
| 58 | 57 |
| 59 // Computes the bounds that defines the bounds between two displays. | 58 // Computes the bounds that defines the bounds between two displays. |
| 60 // Returns false if two displays do not intersect. | 59 // Returns false if two displays do not intersect. |
| 61 DISPLAY_EXPORT bool ComputeBoundary(const display::Display& primary_display, | 60 DISPLAY_EXPORT bool ComputeBoundary(const Display& primary_display, |
| 62 const display::Display& secondary_display, | 61 const Display& secondary_display, |
| 63 gfx::Rect* primary_edge_in_screen, | 62 gfx::Rect* primary_edge_in_screen, |
| 64 gfx::Rect* secondary_edge_in_screen); | 63 gfx::Rect* secondary_edge_in_screen); |
| 65 | 64 |
| 66 // Returns the index in the displays whose bounds contains |point_in_screen|. | 65 // Returns the index in the displays whose bounds contains |point_in_screen|. |
| 67 // Returns -1 if no such display exist. | 66 // Returns -1 if no such display exist. |
| 68 DISPLAY_EXPORT int FindDisplayIndexContainingPoint( | 67 DISPLAY_EXPORT int FindDisplayIndexContainingPoint( |
| 69 const std::vector<display::Display>& displays, | 68 const std::vector<Display>& displays, |
| 70 const gfx::Point& point_in_screen); | 69 const gfx::Point& point_in_screen); |
| 71 | 70 |
| 72 // Sorts id list using |CompareDisplayIds| below. | 71 // Sorts id list using |CompareDisplayIds| below. |
| 73 DISPLAY_EXPORT void SortDisplayIdList(display::DisplayIdList* list); | 72 DISPLAY_EXPORT void SortDisplayIdList(DisplayIdList* list); |
| 74 | 73 |
| 75 // Default id generator. | 74 // Default id generator. |
| 76 class DefaultDisplayIdGenerator { | 75 class DefaultDisplayIdGenerator { |
| 77 public: | 76 public: |
| 78 int64_t operator()(int64_t id) { return id; } | 77 int64_t operator()(int64_t id) { return id; } |
| 79 }; | 78 }; |
| 80 | 79 |
| 81 // Generate sorted display::DisplayIdList from iterators. | 80 // Generate sorted DisplayIdList from iterators. |
| 82 template <class ForwardIterator, class Generator = DefaultDisplayIdGenerator> | 81 template <class ForwardIterator, class Generator = DefaultDisplayIdGenerator> |
| 83 display::DisplayIdList GenerateDisplayIdList( | 82 DisplayIdList GenerateDisplayIdList(ForwardIterator first, |
| 84 ForwardIterator first, | 83 ForwardIterator last, |
| 85 ForwardIterator last, | 84 Generator generator = Generator()) { |
| 86 Generator generator = Generator()) { | 85 DisplayIdList list; |
| 87 display::DisplayIdList list; | |
| 88 while (first != last) { | 86 while (first != last) { |
| 89 list.push_back(generator(*first)); | 87 list.push_back(generator(*first)); |
| 90 ++first; | 88 ++first; |
| 91 } | 89 } |
| 92 SortDisplayIdList(&list); | 90 SortDisplayIdList(&list); |
| 93 return list; | 91 return list; |
| 94 } | 92 } |
| 95 | 93 |
| 96 // Creates sorted display::DisplayIdList. | 94 // Creates sorted DisplayIdList. |
| 97 DISPLAY_EXPORT display::DisplayIdList CreateDisplayIdList( | 95 DISPLAY_EXPORT DisplayIdList CreateDisplayIdList(const Displays& list); |
| 98 const display::Displays& list); | |
| 99 | 96 |
| 100 DISPLAY_EXPORT std::string DisplayIdListToString( | 97 DISPLAY_EXPORT std::string DisplayIdListToString(const DisplayIdList& list); |
| 101 const display::DisplayIdList& list); | |
| 102 | 98 |
| 103 // Returns true if one of following conditions is met. | 99 // Returns true if one of following conditions is met. |
| 104 // 1) id1 is internal. | 100 // 1) id1 is internal. |
| 105 // 2) output index of id1 < output index of id2 and id2 isn't internal. | 101 // 2) output index of id1 < output index of id2 and id2 isn't internal. |
| 106 DISPLAY_EXPORT bool CompareDisplayIds(int64_t id1, int64_t id2); | 102 DISPLAY_EXPORT bool CompareDisplayIds(int64_t id1, int64_t id2); |
| 107 | 103 |
| 108 } // namespace display | 104 } // namespace display |
| 109 | 105 |
| 110 #endif // UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ | 106 #endif // UI_DISPLAY_MANAGER_DISPLAY_MANAGER_UTILITIES_H_ |
| OLD | NEW |