display_manager.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
1// Copyright (c) 2012 The Chromium 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 ASH_DISPLAY_DISPLAY_MANAGER_H_ 6#define ASH_DISPLAY_DISPLAY_MANAGER_H_ 7 8#include <string> 9#include <vector> 10 11#include "ash/ash_export.h" 12#include "ash/display/display_info.h" 13#include "ash/display/display_layout.h" 14#include "base/compiler_specific.h" 15#include "base/gtest_prod_util.h" 16#include "base/memory/scoped_ptr.h" 17#include "ui/gfx/display.h" 18 19#if defined(OS_CHROMEOS) 20#include "chromeos/display/output_configurator.h" 21#endif 22 23namespace gfx { 24class Display; 25class Insets; 26class Rect; 27} 28 29namespace ash { 30class AcceleratorControllerTest; 31class DisplayController; 32 33namespace test { 34class DisplayManagerTestApi; 35class SystemGestureEventFilterTest; 36} 37namespace internal { 38class DisplayLayoutStore; 39 40// DisplayManager maintains the current display configurations, 41// and notifies observers when configuration changes. 42// 43// TODO(oshima): Make this non internal. 44class ASH_EXPORT DisplayManager 45#if defined(OS_CHROMEOS) 46 : public chromeos::OutputConfigurator::SoftwareMirroringController 47#endif 48 { 49 public: 50 class ASH_EXPORT Delegate { 51 public: 52 virtual ~Delegate() {} 53 54 // Create or updates the mirror window with |display_info|. 55 virtual void CreateOrUpdateMirrorWindow( 56 const DisplayInfo& display_info) = 0; 57 58 // Closes the mirror window if exists. 59 virtual void CloseMirrorWindow() = 0; 60 61 // Called before and after the display configuration changes. 62 virtual void PreDisplayConfigurationChange() = 0; 63 virtual void PostDisplayConfigurationChange() = 0; 64 }; 65 66 // Returns the list of possible UI scales for the display. 67 static std::vector<float> GetScalesForDisplay(const DisplayInfo& info); 68 69 // Returns next valid UI scale. 70 static float GetNextUIScale(const DisplayInfo& info, bool up); 71 72 // Updates the bounds of |secondary_display| according to |layout|. 73 static void UpdateDisplayBoundsForLayout( 74 const DisplayLayout& layout, 75 const gfx::Display& primary_display, 76 gfx::Display* secondary_display); 77 78 DisplayManager(); 79 virtual ~DisplayManager(); 80 81 DisplayLayoutStore* layout_store() { 82 return layout_store_.get(); 83 } 84 85 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 86 87 // When set to true, the MonitorManager calls OnDisplayBoundsChanged 88 // even if the display's bounds didn't change. Used to swap primary 89 // display. 90 void set_force_bounds_changed(bool force_bounds_changed) { 91 force_bounds_changed_ = force_bounds_changed; 92 } 93 94 // Returns the display id of the first display in the outupt list. 95 int64 first_display_id() const { return first_display_id_; } 96 97 // Initializes displays using command line flag, or uses 98 // defualt if no options are specified. 99 void InitFromCommandLine(); 100 101 // True if the given |display| is currently connected. 102 bool IsActiveDisplay(const gfx::Display& display) const; 103 104 // True if there is an internal display. 105 bool HasInternalDisplay() const; 106 107 bool IsInternalDisplayId(int64 id) const; 108 109 // Returns display for given |id|; 110 const gfx::Display& GetDisplayForId(int64 id) const; 111 112 // Finds the display that contains |point| in screeen coordinates. 113 // Returns invalid display if there is no display that can satisfy 114 // the condition. 115 const gfx::Display& FindDisplayContainingPoint( 116 const gfx::Point& point_in_screen) const; 117 118 // Registers the overscan insets for the display of the specified ID. Note 119 // that the insets size should be specified in DIP size. It also triggers the 120 // display's bounds change. 121 void SetOverscanInsets(int64 display_id, const gfx::Insets& insets_in_dip); 122 123 // Sets the display's rotation. 124 void SetDisplayRotation(int64 display_id, gfx::Display::Rotation rotation); 125 126 // Sets the display's ui scale. 127 void SetDisplayUIScale(int64 display_id, float ui_scale); 128 129 // Register per display properties. |overscan_insets| is NULL if 130 // the display has no custom overscan insets. 131 void RegisterDisplayProperty(int64 display_id, 132 gfx::Display::Rotation rotation, 133 float ui_scale, 134 const gfx::Insets* overscan_insets); 135 136 // Tells if display rotation/ui scaling features are enabled. 137 bool IsDisplayRotationEnabled() const; 138 bool IsDisplayUIScalingEnabled() const; 139 140 // Returns the current overscan insets for the specified |display_id|. 141 // Returns an empty insets (0, 0, 0, 0) if no insets are specified for 142 // the display. 143 gfx::Insets GetOverscanInsets(int64 display_id) const; 144 145 // Called when display configuration has changed. The new display 146 // configurations is passed as a vector of Display object, which 147 // contains each display's new infomration. 148 void OnNativeDisplaysChanged( 149 const std::vector<DisplayInfo>& display_info_list); 150 151 // Updates the internal display data and notifies observers about the changes. 152 void UpdateDisplays(const std::vector<DisplayInfo>& display_info_list); 153 154 // Updates current displays using current |display_info_|. 155 void UpdateDisplays(); 156 157 // Obsoleted: Do not use in new code. 158 // Returns the display at |index|. The display at 0 is 159 // no longer considered "primary". 160 gfx::Display* GetDisplayAt(size_t index); 161 162 const gfx::Display* GetPrimaryDisplayCandidate() const; 163 164 // Returns the logical number of displays. This returns 1 165 // when displays are mirrored. 166 size_t GetNumDisplays() const; 167 168 // Returns the number of connected displays. This returns 2 169 // when displays are mirrored. 170 size_t num_connected_displays() const { return num_connected_displays_; } 171 172 // Returns the mirroring status. 173 bool IsMirrored() const; 174 const gfx::Display& mirrored_display() const { return mirrored_display_; } 175 176 // Retuns the display info associated with |display_id|. 177 const DisplayInfo& GetDisplayInfo(int64 display_id) const; 178 179 // Returns the human-readable name for the display |id|. 180 std::string GetDisplayNameForId(int64 id); 181 182 // Returns the display id that is capable of UI scaling. On device, 183 // this returns internal display's ID if its device scale factor is 2, 184 // or invalid ID if such internal display doesn't exist. On linux 185 // desktop, this returns the first display ID. 186 int64 GetDisplayIdForUIScaling() const; 187 188 // Change the mirror mode. 189 void SetMirrorMode(bool mirrored); 190 191 // Used to emulate display change when run in a desktop environment instead 192 // of on a device. 193 void AddRemoveDisplay(); 194 void ToggleDisplayScaleFactor(); 195 196 // SoftwareMirroringController override: 197#if defined(OS_CHROMEOS) 198 virtual void SetSoftwareMirroring(bool enabled) OVERRIDE; 199#else 200 void SetSoftwareMirroring(bool enabled); 201#endif 202 203private: 204 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint); 205 FRIEND_TEST_ALL_PREFIXES(DisplayManagerTest, TestNativeDisplaysChanged); 206 FRIEND_TEST_ALL_PREFIXES(DisplayManagerTest, 207 NativeDisplaysChangedAfterPrimaryChange); 208 FRIEND_TEST_ALL_PREFIXES(DisplayManagerTest, AutomaticOverscanInsets); 209 friend class ash::AcceleratorControllerTest; 210 friend class test::DisplayManagerTestApi; 211 friend class test::SystemGestureEventFilterTest; 212 friend class DisplayManagerTest; 213 // This is to allow DisplayController to modify the state of 214 // DisplayManager. TODO(oshima): consider provide separate 215 // interface to modify the state. 216 friend class ash::DisplayController; 217 218 typedef std::vector<gfx::Display> DisplayList; 219 220 void set_change_display_upon_host_resize(bool value) { 221 change_display_upon_host_resize_ = value; 222 } 223 224 gfx::Display& FindDisplayForId(int64 id); 225 226 // Updates the bounds of the display given by |display_id|. 227 bool UpdateDisplayBounds(int64 display_id, const gfx::Rect& new_bounds); 228 229 // Add the mirror display's display info if the software based 230 // mirroring is in use. 231 void AddMirrorDisplayInfoIfAny(std::vector<DisplayInfo>* display_info_list); 232 233 // Inserts and update the DisplayInfo according to the overscan 234 // state. Note that The DisplayInfo stored in the |internal_display_info_| 235 // can be different from |new_info| (due to overscan state), so 236 // you must use |GetDisplayInfo| to get the correct DisplayInfo for 237 // a display. 238 void InsertAndUpdateDisplayInfo(const DisplayInfo& new_info); 239 240 // Creates a display object from the DisplayInfo for |display_id|. 241 gfx::Display CreateDisplayFromDisplayInfoById(int64 display_id); 242 243 // Updates the bounds of the secondary display in |display_list| 244 // using the layout registered for the display pair and set the 245 // index of display updated to |updated_index|. Returns true 246 // if the secondary display's bounds has been changed from current 247 // value, or false otherwise. 248 bool UpdateSecondaryDisplayBoundsForLayout(DisplayList* display_list, 249 size_t* updated_index) const; 250 251 252 Delegate* delegate_; // not owned. 253 254 scoped_ptr<DisplayLayoutStore> layout_store_; 255 256 int64 first_display_id_; 257 258 gfx::Display mirrored_display_; 259 260 // List of current active dispays. 261 DisplayList displays_; 262 263 int num_connected_displays_; 264 265 bool force_bounds_changed_; 266 267 // The mapping from the display ID to its internal data. 268 std::map<int64, DisplayInfo> display_info_; 269 270 // When set to true, the host window's resize event updates 271 // the display's size. This is set to true when running on 272 // desktop environment (for debugging) so that resizing the host 273 // window wil update the display properly. This is set to false 274 // on device as well as during the unit tests. 275 bool change_display_upon_host_resize_; 276 277 bool software_mirroring_enabled_; 278 279 DISALLOW_COPY_AND_ASSIGN(DisplayManager); 280}; 281 282} // namespace internal 283} // namespace ash 284 285#endif // ASH_DISPLAY_DISPLAY_MANAGER_H_ 286