Updating PESQ binary to one that does not require a side-by-side config.
[chromium-blink-merge.git] / ash / display / display_manager.h
blob092d2b002961288a666af8254c5029df6edf93e5
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.
5 #ifndef ASH_DISPLAY_DISPLAY_MANAGER_H_
6 #define ASH_DISPLAY_DISPLAY_MANAGER_H_
8 #include <string>
9 #include <vector>
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 "base/memory/weak_ptr.h"
18 #include "ui/gfx/display.h"
20 #if defined(OS_CHROMEOS)
21 #include "ui/display/chromeos/display_configurator.h"
22 #endif
24 namespace gfx {
25 class Display;
26 class Insets;
27 class Rect;
28 class Screen;
31 namespace ash {
32 class AcceleratorControllerTest;
33 class DisplayController;
34 class DisplayLayoutStore;
35 class ScreenAsh;
37 namespace test {
38 class AshTestBase;
39 class DisplayManagerTestApi;
40 class SystemGestureEventFilterTest;
43 // DisplayManager maintains the current display configurations,
44 // and notifies observers when configuration changes.
46 // TODO(oshima): Make this non internal.
47 class ASH_EXPORT DisplayManager
48 #if defined(OS_CHROMEOS)
49 : public ui::DisplayConfigurator::SoftwareMirroringController
50 #endif
52 public:
53 class ASH_EXPORT Delegate {
54 public:
55 virtual ~Delegate() {}
57 // Create or updates the mirroring window with |display_info|.
58 virtual void CreateOrUpdateMirroringDisplay(
59 const DisplayInfo& display_info) = 0;
61 // Closes the mirror window if exists.
62 virtual void CloseMirroringDisplay() = 0;
64 // Called before and after the display configuration changes.
65 // When |clear_focus| is true, the implementation should
66 // deactivate the active window and set the focus window to NULL.
67 virtual void PreDisplayConfigurationChange(bool clear_focus) = 0;
68 virtual void PostDisplayConfigurationChange() = 0;
71 // How the second display will be used.
72 // 1) EXTENDED mode extends the desktop to the second dislpay.
73 // 2) MIRRORING mode copies the content of the primary display to
74 // the 2nd display. (Software Mirroring).
75 enum SecondDisplayMode {
76 EXTENDED,
77 MIRRORING
80 DisplayManager();
81 #if defined(OS_CHROMEOS)
82 ~DisplayManager() override;
83 #else
84 virtual ~DisplayManager();
85 #endif
87 DisplayLayoutStore* layout_store() {
88 return layout_store_.get();
91 gfx::Screen* screen() {
92 return screen_;
95 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
97 // When set to true, the MonitorManager calls OnDisplayMetricsChanged
98 // even if the display's bounds didn't change. Used to swap primary
99 // display.
100 void set_force_bounds_changed(bool force_bounds_changed) {
101 force_bounds_changed_ = force_bounds_changed;
104 // Returns the display id of the first display in the outupt list.
105 int64 first_display_id() const { return first_display_id_; }
107 // Initializes displays using command line flag. Returns false
108 // if no command line flag was provided.
109 bool InitFromCommandLine();
111 // Initialize default display.
112 void InitDefaultDisplay();
114 // Initializes font related params that depends on display
115 // configuration.
116 void RefreshFontParams();
118 // True if the given |display| is currently connected.
119 bool IsActiveDisplay(const gfx::Display& display) const;
121 // True if there is an internal display.
122 bool HasInternalDisplay() const;
124 bool IsInternalDisplayId(int64 id) const;
126 // Returns the display layout used for current displays.
127 DisplayLayout GetCurrentDisplayLayout();
129 // Returns the current display pair.
130 DisplayIdPair GetCurrentDisplayIdPair() const;
132 // Sets the layout for the current display pair. The |layout| specifies
133 // the locaion of the secondary display relative to the primary.
134 void SetLayoutForCurrentDisplays(
135 const DisplayLayout& layout_relative_to_primary);
137 // Returns display for given |id|;
138 const gfx::Display& GetDisplayForId(int64 id) const;
140 // Finds the display that contains |point| in screeen coordinates.
141 // Returns invalid display if there is no display that can satisfy
142 // the condition.
143 const gfx::Display& FindDisplayContainingPoint(
144 const gfx::Point& point_in_screen) const;
146 // Sets the work area's |insets| to the display given by |display_id|.
147 bool UpdateWorkAreaOfDisplay(int64 display_id, const gfx::Insets& insets);
149 // Registers the overscan insets for the display of the specified ID. Note
150 // that the insets size should be specified in DIP size. It also triggers the
151 // display's bounds change.
152 void SetOverscanInsets(int64 display_id, const gfx::Insets& insets_in_dip);
154 // Sets the display's rotation.
155 void SetDisplayRotation(int64 display_id, gfx::Display::Rotation rotation);
157 // Sets the display's ui scale. Returns true if it's successful, or
158 // false otherwise. TODO(mukai): remove this and merge into
159 // SetDisplayMode.
160 bool SetDisplayUIScale(int64 display_id, float ui_scale);
162 // Sets the display's resolution.
163 // TODO(mukai): remove this and merge into SetDisplayMode.
164 void SetDisplayResolution(int64 display_id, const gfx::Size& resolution);
166 // Sets the external display's configuration, including resolution change,
167 // ui-scale change, and device scale factor change. Returns true if it changes
168 // the display resolution so that the caller needs to show a notification in
169 // case the new resolution actually doesn't work.
170 bool SetDisplayMode(int64 display_id, const DisplayMode& display_mode);
172 // Register per display properties. |overscan_insets| is NULL if
173 // the display has no custom overscan insets.
174 void RegisterDisplayProperty(int64 display_id,
175 gfx::Display::Rotation rotation,
176 float ui_scale,
177 const gfx::Insets* overscan_insets,
178 const gfx::Size& resolution_in_pixels,
179 float device_scale_factor,
180 ui::ColorCalibrationProfile color_profile);
182 // Register stored rotation properties for the internal display.
183 void RegisterDisplayRotationProperties(bool rotation_lock,
184 gfx::Display::Rotation rotation);
186 // Returns the stored rotation lock preference if it has been loaded,
187 // otherwise false.
188 bool registered_internal_display_rotation_lock() const {
189 return registered_internal_display_rotation_lock_;
192 // Returns the stored rotation preference for the internal display if it has
193 // been loaded, otherwise |gfx::Display::Rotate_0|.
194 gfx::Display::Rotation registered_internal_display_rotation() const {
195 return registered_internal_display_rotation_;
198 // Returns the display mode of |display_id| which is currently used.
199 DisplayMode GetActiveModeForDisplayId(int64 display_id) const;
201 // Returns the display's selected mode. This returns false and doesn't
202 // set |mode_out| if the display mode is in default.
203 bool GetSelectedModeForDisplayId(int64 display_id,
204 DisplayMode* mode_out) const;
206 // Tells if the virtual resolution feature is enabled.
207 bool IsDisplayUIScalingEnabled() const;
209 // Returns the current overscan insets for the specified |display_id|.
210 // Returns an empty insets (0, 0, 0, 0) if no insets are specified for
211 // the display.
212 gfx::Insets GetOverscanInsets(int64 display_id) const;
214 // Sets the color calibration of the display to |profile|.
215 void SetColorCalibrationProfile(int64 display_id,
216 ui::ColorCalibrationProfile profile);
218 // Called when display configuration has changed. The new display
219 // configurations is passed as a vector of Display object, which
220 // contains each display's new infomration.
221 void OnNativeDisplaysChanged(
222 const std::vector<DisplayInfo>& display_info_list);
224 // Updates the internal display data and notifies observers about the changes.
225 void UpdateDisplays(const std::vector<DisplayInfo>& display_info_list);
227 // Updates current displays using current |display_info_|.
228 void UpdateDisplays();
230 // Returns the display at |index|. The display at 0 is
231 // no longer considered "primary".
232 const gfx::Display& GetDisplayAt(size_t index) const;
234 const gfx::Display& GetPrimaryDisplayCandidate() const;
236 // Returns the logical number of displays. This returns 1
237 // when displays are mirrored.
238 size_t GetNumDisplays() const;
240 const std::vector<gfx::Display>& displays() const { return displays_; }
242 // Returns the number of connected displays. This returns 2
243 // when displays are mirrored.
244 size_t num_connected_displays() const { return num_connected_displays_; }
246 // Returns the mirroring status.
247 bool IsMirrored() const;
248 int64 mirrored_display_id() const { return mirrored_display_id_; }
250 // Returns the display used for software mirrroring.
251 const gfx::Display& mirroring_display() const {
252 return mirroring_display_;
255 // Retuns the display info associated with |display_id|.
256 const DisplayInfo& GetDisplayInfo(int64 display_id) const;
258 // Returns the human-readable name for the display |id|.
259 std::string GetDisplayNameForId(int64 id);
261 // Returns the display id that is capable of UI scaling. On device,
262 // this returns internal display's ID if its device scale factor is 2,
263 // or invalid ID if such internal display doesn't exist. On linux
264 // desktop, this returns the first display ID.
265 int64 GetDisplayIdForUIScaling() const;
267 // Change the mirror mode.
268 void SetMirrorMode(bool mirrored);
270 // Used to emulate display change when run in a desktop environment instead
271 // of on a device.
272 void AddRemoveDisplay();
273 void ToggleDisplayScaleFactor();
275 // SoftwareMirroringController override:
276 #if defined(OS_CHROMEOS)
277 void SetSoftwareMirroring(bool enabled) override;
278 bool SoftwareMirroringEnabled() const override;
279 #endif
280 bool software_mirroring_enabled() const {
281 return second_display_mode_ == MIRRORING;
284 // Sets/gets second display mode.
285 void SetSecondDisplayMode(SecondDisplayMode mode);
286 SecondDisplayMode second_display_mode() const {
287 return second_display_mode_;
290 // Update the bounds of the display given by |display_id|.
291 bool UpdateDisplayBounds(int64 display_id,
292 const gfx::Rect& new_bounds);
294 // Creates mirror window asynchronously if the software mirror mode
295 // is enabled.
296 void CreateMirrorWindowAsyncIfAny();
298 // Create a screen instance to be used during shutdown.
299 void CreateScreenForShutdown() const;
301 // A unit test may change the internal display id (which never happens on
302 // a real device). This will update the mode list for internal display
303 // for this test scenario.
304 void UpdateInternalDisplayModeListForTest();
306 private:
307 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint);
308 FRIEND_TEST_ALL_PREFIXES(DisplayManagerTest, TestNativeDisplaysChanged);
309 FRIEND_TEST_ALL_PREFIXES(DisplayManagerTest,
310 NativeDisplaysChangedAfterPrimaryChange);
311 FRIEND_TEST_ALL_PREFIXES(DisplayManagerTest, AutomaticOverscanInsets);
312 friend class AcceleratorControllerTest;
313 friend class DisplayManagerTest;
314 friend class test::AshTestBase;
315 friend class test::DisplayManagerTestApi;
316 friend class test::SystemGestureEventFilterTest;
318 typedef std::vector<gfx::Display> DisplayList;
320 void set_change_display_upon_host_resize(bool value) {
321 change_display_upon_host_resize_ = value;
324 gfx::Display* FindDisplayForId(int64 id);
326 // Add the mirror display's display info if the software based
327 // mirroring is in use.
328 void AddMirrorDisplayInfoIfAny(std::vector<DisplayInfo>* display_info_list);
330 // Inserts and update the DisplayInfo according to the overscan
331 // state. Note that The DisplayInfo stored in the |internal_display_info_|
332 // can be different from |new_info| (due to overscan state), so
333 // you must use |GetDisplayInfo| to get the correct DisplayInfo for
334 // a display.
335 void InsertAndUpdateDisplayInfo(const DisplayInfo& new_info);
337 // Called when the display info is updated through InsertAndUpdateDisplayInfo.
338 void OnDisplayInfoUpdated(const DisplayInfo& display_info);
340 // Creates a display object from the DisplayInfo for |display_id|.
341 gfx::Display CreateDisplayFromDisplayInfoById(int64 display_id);
343 // Updates the bounds of all non-primary displays in |display_list| and
344 // append the indices of displays updated to |updated_indices|.
345 // When the size of |display_list| equals 2, the bounds are updated using
346 // the layout registered for the display pair. For more than 2 displays,
347 // the bounds are updated using horizontal layout.
348 // Returns true if any of the non-primary display's bounds has been changed
349 // from current value, or false otherwise.
350 bool UpdateNonPrimaryDisplayBoundsForLayout(
351 DisplayList* display_list, std::vector<size_t>* updated_indices) const;
353 void CreateMirrorWindowIfAny();
355 bool HasSoftwareMirroringDisplay();
357 static void UpdateDisplayBoundsForLayout(
358 const DisplayLayout& layout,
359 const gfx::Display& primary_display,
360 gfx::Display* secondary_display);
362 Delegate* delegate_; // not owned.
364 scoped_ptr<ScreenAsh> screen_ash_;
365 // This is to have an accessor without ScreenAsh definition.
366 gfx::Screen* screen_;
368 scoped_ptr<DisplayLayoutStore> layout_store_;
370 int64 first_display_id_;
372 // List of current active displays.
373 DisplayList displays_;
375 int num_connected_displays_;
377 bool force_bounds_changed_;
379 // The mapping from the display ID to its internal data.
380 std::map<int64, DisplayInfo> display_info_;
382 // Selected display modes for displays. Key is the displays' ID.
383 std::map<int64, DisplayMode> display_modes_;
385 // When set to true, the host window's resize event updates
386 // the display's size. This is set to true when running on
387 // desktop environment (for debugging) so that resizing the host
388 // window will update the display properly. This is set to false
389 // on device as well as during the unit tests.
390 bool change_display_upon_host_resize_;
392 SecondDisplayMode second_display_mode_;
393 int64 mirrored_display_id_;
394 gfx::Display mirroring_display_;
396 // User preference for rotation lock of the internal display.
397 bool registered_internal_display_rotation_lock_;
399 // User preference for the rotation of the internal display.
400 gfx::Display::Rotation registered_internal_display_rotation_;
402 base::WeakPtrFactory<DisplayManager> weak_ptr_factory_;
404 DISALLOW_COPY_AND_ASSIGN(DisplayManager);
407 } // namespace ash
409 #endif // ASH_DISPLAY_DISPLAY_MANAGER_H_