Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: ash/display/display_manager.h

Issue 2445583002: Relocate display_manager from ash to ui (Closed)
Patch Set: fix windows build Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/display/display_configuration_controller.cc ('k') | ash/display/display_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12 #include <string>
13 #include <vector>
14
15 #include "ash/ash_export.h"
16 #include "base/compiler_specific.h"
17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h"
19 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h"
21 #include "base/observer_list.h"
22 #include "ui/display/display.h"
23 #include "ui/display/display_observer.h"
24 #include "ui/display/manager/display_layout.h"
25 #include "ui/display/manager/managed_display_info.h"
26
27 #if defined(OS_CHROMEOS)
28 #include "ui/display/chromeos/display_configurator.h"
29 #endif
30
31 namespace display {
32 class DisplayLayoutStore;
33 class DisplayObserver;
34 class Screen;
35 }
36
37 namespace gfx {
38 class Insets;
39 class Rect;
40 }
41
42 namespace ash {
43 using DisplayInfoList = std::vector<display::ManagedDisplayInfo>;
44
45 namespace test {
46 class DisplayManagerTestApi;
47 }
48
49 // DisplayManager maintains the current display configurations,
50 // and notifies observers when configuration changes.
51 //
52 // TODO(oshima): Make this non internal.
53 class ASH_EXPORT DisplayManager
54 #if defined(OS_CHROMEOS)
55 : public ui::DisplayConfigurator::SoftwareMirroringController
56 #endif
57 {
58 public:
59 class ASH_EXPORT Delegate {
60 public:
61 virtual ~Delegate() {}
62
63 // Create or updates the mirroring window with |display_info_list|.
64 virtual void CreateOrUpdateMirroringDisplay(
65 const DisplayInfoList& display_info_list) = 0;
66
67 // Closes the mirror window if not necessary.
68 virtual void CloseMirroringDisplayIfNotNecessary() = 0;
69
70 // Called before and after the display configuration changes.
71 // When |clear_focus| is true, the implementation should
72 // deactivate the active window and set the focus window to NULL.
73 virtual void PreDisplayConfigurationChange(bool clear_focus) = 0;
74 virtual void PostDisplayConfigurationChange() = 0;
75
76 #if defined(OS_CHROMEOS)
77 // Get the ui::DisplayConfigurator.
78 virtual ui::DisplayConfigurator* display_configurator() = 0;
79 #endif
80
81 virtual std::string GetInternalDisplayNameString() = 0;
82 virtual std::string GetUnknownDisplayNameString() = 0;
83 };
84
85 // How the second display will be used.
86 // 1) EXTENDED mode extends the desktop to the second dislpay.
87 // 2) MIRRORING mode copies the content of the primary display to
88 // the 2nd display. (Software Mirroring).
89 // 3) UNIFIED mode creates single desktop across multiple displays.
90 enum MultiDisplayMode {
91 EXTENDED = 0,
92 MIRRORING,
93 UNIFIED,
94 };
95
96 // The display ID for a virtual display assigned to a unified desktop.
97 static int64_t kUnifiedDisplayId;
98
99 explicit DisplayManager(std::unique_ptr<display::Screen> screen);
100 #if defined(OS_CHROMEOS)
101 ~DisplayManager() override;
102 #else
103 virtual ~DisplayManager();
104 #endif
105
106 display::DisplayLayoutStore* layout_store() { return layout_store_.get(); }
107
108 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
109
110 // When set to true, the DisplayManager calls OnDisplayMetricsChanged
111 // even if the display's bounds didn't change. Used to swap primary
112 // display.
113 void set_force_bounds_changed(bool force_bounds_changed) {
114 force_bounds_changed_ = force_bounds_changed;
115 }
116
117 // Returns the display id of the first display in the outupt list.
118 int64_t first_display_id() const { return first_display_id_; }
119
120 // Initializes displays using command line flag. Returns false
121 // if no command line flag was provided.
122 bool InitFromCommandLine();
123
124 // Initialize default display.
125 void InitDefaultDisplay();
126
127 // Initializes font related params that depends on display
128 // configuration.
129 void RefreshFontParams();
130
131 // Returns the display layout used for current displays.
132 const display::DisplayLayout& GetCurrentDisplayLayout() const;
133
134 // Returns the current display list.
135 display::DisplayIdList GetCurrentDisplayIdList() const;
136
137 // Sets the layout for the current display pair. The |layout| specifies
138 // the locaion of the displays relative to their parents.
139 void SetLayoutForCurrentDisplays(
140 std::unique_ptr<display::DisplayLayout> layout);
141
142 // Returns display for given |id|;
143 const display::Display& GetDisplayForId(int64_t id) const;
144
145 // Finds the display that contains |point| in screeen coordinates.
146 // Returns invalid display if there is no display that can satisfy
147 // the condition.
148 const display::Display& FindDisplayContainingPoint(
149 const gfx::Point& point_in_screen) const;
150
151 // Sets the work area's |insets| to the display given by |display_id|.
152 bool UpdateWorkAreaOfDisplay(int64_t display_id, const gfx::Insets& insets);
153
154 // Registers the overscan insets for the display of the specified ID. Note
155 // that the insets size should be specified in DIP size. It also triggers the
156 // display's bounds change.
157 void SetOverscanInsets(int64_t display_id, const gfx::Insets& insets_in_dip);
158
159 // Sets the display's rotation for the given |source|. The new |rotation| will
160 // also become active.
161 void SetDisplayRotation(int64_t display_id,
162 display::Display::Rotation rotation,
163 display::Display::RotationSource source);
164
165 // Resets the UI scale of the display with |display_id| to the one defined in
166 // the default mode.
167 bool ResetDisplayToDefaultMode(int64_t display_id);
168
169 // Sets the external display's configuration, including resolution change,
170 // ui-scale change, and device scale factor change. Returns true if it changes
171 // the display resolution so that the caller needs to show a notification in
172 // case the new resolution actually doesn't work.
173 bool SetDisplayMode(
174 int64_t display_id,
175 const scoped_refptr<display::ManagedDisplayMode>& display_mode);
176
177 // Register per display properties. |overscan_insets| is NULL if
178 // the display has no custom overscan insets.
179 void RegisterDisplayProperty(int64_t display_id,
180 display::Display::Rotation rotation,
181 float ui_scale,
182 const gfx::Insets* overscan_insets,
183 const gfx::Size& resolution_in_pixels,
184 float device_scale_factor,
185 ui::ColorCalibrationProfile color_profile);
186
187 // Register stored rotation properties for the internal display.
188 void RegisterDisplayRotationProperties(bool rotation_lock,
189 display::Display::Rotation rotation);
190
191 // Returns the stored rotation lock preference if it has been loaded,
192 // otherwise false.
193 bool registered_internal_display_rotation_lock() const {
194 return registered_internal_display_rotation_lock_;
195 }
196
197 // Returns the stored rotation preference for the internal display if it has
198 // been loaded, otherwise |display::Display::Rotate_0|.
199 display::Display::Rotation registered_internal_display_rotation() const {
200 return registered_internal_display_rotation_;
201 }
202
203 // Returns the display mode of |display_id| which is currently used.
204 scoped_refptr<display::ManagedDisplayMode> GetActiveModeForDisplayId(
205 int64_t display_id) const;
206
207 // Returns the display's selected mode. This returns false and doesn't
208 // set |mode_out| if the display mode is in default.
209 scoped_refptr<display::ManagedDisplayMode> GetSelectedModeForDisplayId(
210 int64_t display_id) const;
211
212 // Tells if the virtual resolution feature is enabled.
213 bool IsDisplayUIScalingEnabled() const;
214
215 // Returns the current overscan insets for the specified |display_id|.
216 // Returns an empty insets (0, 0, 0, 0) if no insets are specified for
217 // the display.
218 gfx::Insets GetOverscanInsets(int64_t display_id) const;
219
220 // Sets the color calibration of the display to |profile|.
221 void SetColorCalibrationProfile(int64_t display_id,
222 ui::ColorCalibrationProfile profile);
223
224 // Called when display configuration has changed. The new display
225 // configurations is passed as a vector of Display object, which
226 // contains each display's new infomration.
227 void OnNativeDisplaysChanged(
228 const std::vector<display::ManagedDisplayInfo>& display_info_list);
229
230 // Updates the internal display data and notifies observers about the changes.
231 void UpdateDisplaysWith(
232 const std::vector<display::ManagedDisplayInfo>& display_info_list);
233
234 // Updates current displays using current |display_info_|.
235 void UpdateDisplays();
236
237 // Returns the display at |index|. The display at 0 is
238 // no longer considered "primary".
239 const display::Display& GetDisplayAt(size_t index) const;
240
241 const display::Display& GetPrimaryDisplayCandidate() const;
242
243 // Returns the logical number of displays. This returns 1
244 // when displays are mirrored.
245 size_t GetNumDisplays() const;
246
247 // Returns only the currently active displays. This list does not include the
248 // displays that will be removed if |UpdateDisplaysWith| is currently
249 // executing.
250 // See https://crbug.com/632755
251 const display::Displays& active_only_display_list() const {
252 return is_updating_display_list_ ? active_only_display_list_
253 : active_display_list();
254 }
255
256 const display::Displays& active_display_list() const {
257 return active_display_list_;
258 }
259
260 // Returns true if the display specified by |display_id| is currently
261 // connected and active. (mirroring display isn't active, for example).
262 bool IsActiveDisplayId(int64_t display_id) const;
263
264 // Returns the number of connected displays. This returns 2
265 // when displays are mirrored.
266 size_t num_connected_displays() const { return num_connected_displays_; }
267
268 // Returns the mirroring status.
269 bool IsInMirrorMode() const;
270 int64_t mirroring_display_id() const { return mirroring_display_id_; }
271 const display::Displays& software_mirroring_display_list() const {
272 return software_mirroring_display_list_;
273 }
274
275 // Sets/gets if the unified desktop feature is enabled.
276 void SetUnifiedDesktopEnabled(bool enabled);
277 bool unified_desktop_enabled() const { return unified_desktop_enabled_; }
278
279 // Returns true if it's in unified desktop mode.
280 bool IsInUnifiedMode() const;
281
282 // Returns the display used for software mirrroring. Returns invalid
283 // display if not found.
284 const display::Display GetMirroringDisplayById(int64_t id) const;
285
286 // Retuns the display info associated with |display_id|.
287 const display::ManagedDisplayInfo& GetDisplayInfo(int64_t display_id) const;
288
289 // Returns the human-readable name for the display |id|.
290 std::string GetDisplayNameForId(int64_t id);
291
292 // Returns the display id that is capable of UI scaling. On device,
293 // this returns internal display's ID if its device scale factor is 2,
294 // or invalid ID if such internal display doesn't exist. On linux
295 // desktop, this returns the first display ID.
296 int64_t GetDisplayIdForUIScaling() const;
297
298 // Change the mirror mode.
299 void SetMirrorMode(bool mirrored);
300
301 // Used to emulate display change when run in a desktop environment instead
302 // of on a device.
303 void AddRemoveDisplay();
304 void ToggleDisplayScaleFactor();
305
306 // SoftwareMirroringController override:
307 #if defined(OS_CHROMEOS)
308 void SetSoftwareMirroring(bool enabled) override;
309 bool SoftwareMirroringEnabled() const override;
310 #endif
311
312 // Sets/gets default multi display mode.
313 void SetDefaultMultiDisplayModeForCurrentDisplays(MultiDisplayMode mode);
314 MultiDisplayMode current_default_multi_display_mode() const {
315 return current_default_multi_display_mode_;
316 }
317
318 // Sets multi display mode.
319 void SetMultiDisplayMode(MultiDisplayMode mode);
320
321 // Reconfigure display configuration using the same
322 // physical display. TODO(oshima): Refactor and move this
323 // impl to |SetDefaultMultiDisplayMode|.
324 void ReconfigureDisplays();
325
326 // Update the bounds of the display given by |display_id|.
327 bool UpdateDisplayBounds(int64_t display_id, const gfx::Rect& new_bounds);
328
329 // Creates mirror window asynchronously if the software mirror mode
330 // is enabled.
331 void CreateMirrorWindowAsyncIfAny();
332
333 // A unit test may change the internal display id (which never happens on
334 // a real device). This will update the mode list for internal display
335 // for this test scenario.
336 void UpdateInternalManagedDisplayModeListForTest();
337
338 // Zoom the internal display.
339 bool ZoomInternalDisplay(bool up);
340
341 // Reset the internal display zoom.
342 void ResetInternalDisplayZoom();
343
344 // Notifies observers of display configuration changes.
345 void NotifyMetricsChanged(const display::Display& display, uint32_t metrics);
346 void NotifyDisplayAdded(const display::Display& display);
347 void NotifyDisplayRemoved(const display::Display& display);
348
349 // Delegated from the Screen implementation.
350 void AddObserver(display::DisplayObserver* observer);
351 void RemoveObserver(display::DisplayObserver* observer);
352
353 // Returns a display::Display object for a secondary display if it exists
354 // or returns invalid display if there is no secondary display.
355 // TODO(rjkroege): Display swapping is an obsolete feature pre-dating
356 // multi-display support so remove it.
357 const display::Display& GetSecondaryDisplay() const;
358
359 private:
360 friend class test::DisplayManagerTestApi;
361
362 bool software_mirroring_enabled() const {
363 return multi_display_mode_ == MIRRORING;
364 };
365
366 void set_change_display_upon_host_resize(bool value) {
367 change_display_upon_host_resize_ = value;
368 }
369
370 // Creates software mirroring display related information. The display
371 // used to mirror the content is removed from the |display_info_list|.
372 void CreateSoftwareMirroringDisplayInfo(DisplayInfoList* display_info_list);
373
374 display::Display* FindDisplayForId(int64_t id);
375
376 // Add the mirror display's display info if the software based
377 // mirroring is in use.
378 void AddMirrorDisplayInfoIfAny(DisplayInfoList* display_info_list);
379
380 // Inserts and update the display::ManagedDisplayInfo according to the
381 // overscan
382 // state. Note that The display::ManagedDisplayInfo stored in the
383 // |internal_display_info_|
384 // can be different from |new_info| (due to overscan state), so
385 // you must use |GetDisplayInfo| to get the correct
386 // display::ManagedDisplayInfo for
387 // a display.
388 void InsertAndUpdateDisplayInfo(const display::ManagedDisplayInfo& new_info);
389
390 // Called when the display info is updated through InsertAndUpdateDisplayInfo.
391 void OnDisplayInfoUpdated(const display::ManagedDisplayInfo& display_info);
392
393 // Creates a display object from the display::ManagedDisplayInfo for
394 // |display_id|.
395 display::Display CreateDisplayFromDisplayInfoById(int64_t display_id);
396
397 // Creates a display object from the display::ManagedDisplayInfo for
398 // |display_id|
399 // for
400 // mirroring. The size of the display will be scaled using |scale|
401 // with the offset using |origin|.
402 display::Display CreateMirroringDisplayFromDisplayInfoById(
403 int64_t display_id,
404 const gfx::Point& origin,
405 float scale);
406
407 // Updates the bounds of all non-primary displays in |display_list| and
408 // append the indices of displays updated to |updated_indices|.
409 // When the size of |display_list| equals 2, the bounds are updated using
410 // the layout registered for the display pair. For more than 2 displays,
411 // the bounds are updated using horizontal layout.
412 void UpdateNonPrimaryDisplayBoundsForLayout(
413 display::Displays* display_list,
414 std::vector<size_t>* updated_indices);
415
416 void CreateMirrorWindowIfAny();
417
418 void RunPendingTasksForTest();
419
420 // Applies the |layout| and updates the bounds of displays in |display_list|.
421 // |updated_ids| contains the ids for displays whose bounds have changed.
422 void ApplyDisplayLayout(const display::DisplayLayout& layout,
423 display::Displays* display_list,
424 std::vector<int64_t>* updated_ids);
425
426 Delegate* delegate_; // not owned.
427
428 std::unique_ptr<display::Screen> screen_;
429
430 std::unique_ptr<display::DisplayLayoutStore> layout_store_;
431
432 int64_t first_display_id_;
433
434 // List of current active displays.
435 display::Displays active_display_list_;
436 // This list does not include the displays that will be removed if
437 // |UpdateDisplaysWith| is under execution.
438 // See https://crbug.com/632755
439 display::Displays active_only_display_list_;
440
441 // True if active_display_list is being modified and has displays that are not
442 // presently active.
443 // See https://crbug.com/632755
444 bool is_updating_display_list_;
445
446 int num_connected_displays_;
447
448 bool force_bounds_changed_;
449
450 // The mapping from the display ID to its internal data.
451 std::map<int64_t, display::ManagedDisplayInfo> display_info_;
452
453 // Selected display modes for displays. Key is the displays' ID.
454 std::map<int64_t, scoped_refptr<display::ManagedDisplayMode>> display_modes_;
455
456 // When set to true, the host window's resize event updates
457 // the display's size. This is set to true when running on
458 // desktop environment (for debugging) so that resizing the host
459 // window will update the display properly. This is set to false
460 // on device as well as during the unit tests.
461 bool change_display_upon_host_resize_;
462
463 MultiDisplayMode multi_display_mode_;
464 MultiDisplayMode current_default_multi_display_mode_;
465
466 int64_t mirroring_display_id_;
467 display::Displays software_mirroring_display_list_;
468
469 // User preference for rotation lock of the internal display.
470 bool registered_internal_display_rotation_lock_;
471
472 // User preference for the rotation of the internal display.
473 display::Display::Rotation registered_internal_display_rotation_;
474
475 bool unified_desktop_enabled_;
476
477 base::ObserverList<display::DisplayObserver> observers_;
478
479 base::WeakPtrFactory<DisplayManager> weak_ptr_factory_;
480
481 DISALLOW_COPY_AND_ASSIGN(DisplayManager);
482 };
483
484 } // namespace ash
485
486 #endif // ASH_DISPLAY_DISPLAY_MANAGER_H_
OLDNEW
« no previous file with comments | « ash/display/display_configuration_controller.cc ('k') | ash/display/display_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698