OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CHROMEOS_DISPLAY_CONFIGURATOR_H_ | 5 #ifndef UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ |
6 #define UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ | 6 #define UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/event_types.h" | 14 #include "base/event_types.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | |
16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
17 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
18 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
19 #include "ui/display/chromeos/configure_displays_task.h" | |
20 #include "ui/display/display_export.h" | 20 #include "ui/display/display_export.h" |
21 #include "ui/display/types/display_constants.h" | 21 #include "ui/display/types/display_constants.h" |
22 #include "ui/display/types/native_display_observer.h" | 22 #include "ui/display/types/native_display_observer.h" |
23 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
24 | 24 |
25 namespace gfx { | 25 namespace gfx { |
26 class Point; | 26 class Point; |
27 class Size; | 27 class Size; |
28 } | 28 } |
29 | 29 |
30 namespace ui { | 30 namespace ui { |
31 struct DisplayConfigureRequest; | |
31 class DisplayMode; | 32 class DisplayMode; |
32 class DisplaySnapshot; | 33 class DisplaySnapshot; |
33 class NativeDisplayDelegate; | 34 class NativeDisplayDelegate; |
35 class UpdateDisplayConfigurationTask; | |
34 | 36 |
35 // This class interacts directly with the system display configurator. | 37 // This class interacts directly with the system display configurator. |
36 class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { | 38 class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { |
37 public: | 39 public: |
38 typedef uint64_t ContentProtectionClientId; | 40 typedef uint64_t ContentProtectionClientId; |
39 static const ContentProtectionClientId kInvalidClientId = 0; | 41 static const ContentProtectionClientId kInvalidClientId = 0; |
40 | 42 |
41 struct DisplayState { | 43 struct DisplayState { |
42 DisplayState(); | 44 DisplayState(); |
43 | 45 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 | 167 |
166 // Returns the mode within |display| that matches the given size with highest | 168 // Returns the mode within |display| that matches the given size with highest |
167 // refresh rate. Returns None if no matching display was found. | 169 // refresh rate. Returns None if no matching display was found. |
168 static const DisplayMode* FindDisplayModeMatchingSize( | 170 static const DisplayMode* FindDisplayModeMatchingSize( |
169 const DisplaySnapshot& display, | 171 const DisplaySnapshot& display, |
170 const gfx::Size& size); | 172 const gfx::Size& size); |
171 | 173 |
172 DisplayConfigurator(); | 174 DisplayConfigurator(); |
173 virtual ~DisplayConfigurator(); | 175 virtual ~DisplayConfigurator(); |
174 | 176 |
175 MultipleDisplayState display_state() const { return display_state_; } | 177 MultipleDisplayState display_state() const { return current_display_state_; } |
176 chromeos::DisplayPowerState requested_power_state() const { | 178 chromeos::DisplayPowerState requested_power_state() const { |
177 return requested_power_state_; | 179 return requested_power_state_; |
178 } | 180 } |
179 const gfx::Size framebuffer_size() const { return framebuffer_size_; } | 181 const gfx::Size framebuffer_size() const { return framebuffer_size_; } |
180 const std::vector<DisplayState>& cached_displays() const { | 182 const std::vector<DisplayState>& cached_displays() const { |
181 return cached_displays_; | 183 return cached_displays_; |
182 } | 184 } |
183 | 185 |
184 // Called when an external process no longer needs to control the display | 186 // Called when an external process no longer needs to control the display |
185 // and Chrome can take control. | 187 // and Chrome can take control. |
(...skipping 29 matching lines...) Expand all Loading... | |
215 void ForceInitialConfigure(uint32_t background_color_argb); | 217 void ForceInitialConfigure(uint32_t background_color_argb); |
216 | 218 |
217 // Stop handling display configuration events/requests. | 219 // Stop handling display configuration events/requests. |
218 void PrepareForExit(); | 220 void PrepareForExit(); |
219 | 221 |
220 // Called when powerd notifies us that some set of displays should be turned | 222 // Called when powerd notifies us that some set of displays should be turned |
221 // on or off. This requires enabling or disabling the CRTC associated with | 223 // on or off. This requires enabling or disabling the CRTC associated with |
222 // the display(s) in question so that the low power state is engaged. | 224 // the display(s) in question so that the low power state is engaged. |
223 // |flags| contains bitwise-or-ed kSetDisplayPower* values. Returns true if | 225 // |flags| contains bitwise-or-ed kSetDisplayPower* values. Returns true if |
224 // the system successfully enters (or was already in) |power_state|. | 226 // the system successfully enters (or was already in) |power_state|. |
225 bool SetDisplayPower(chromeos::DisplayPowerState power_state, int flags); | 227 void SetDisplayPower(chromeos::DisplayPowerState power_state, int flags); |
226 | 228 |
227 // Force switching the display mode to |new_state|. Returns false if | 229 // Force switching the display mode to |new_state|. Returns false if |
228 // switching failed (possibly because |new_state| is invalid for the | 230 // switching failed (possibly because |new_state| is invalid for the |
229 // current set of connected displays). | 231 // current set of connected displays). |
230 bool SetDisplayMode(MultipleDisplayState new_state); | 232 void SetDisplayMode(MultipleDisplayState new_state); |
231 | 233 |
232 // NativeDisplayDelegate::Observer overrides: | 234 // NativeDisplayDelegate::Observer overrides: |
233 virtual void OnConfigurationChanged() override; | 235 virtual void OnConfigurationChanged() override; |
234 | 236 |
235 void AddObserver(Observer* observer); | 237 void AddObserver(Observer* observer); |
236 void RemoveObserver(Observer* observer); | 238 void RemoveObserver(Observer* observer); |
237 | 239 |
238 // Sets all the displays into pre-suspend mode; usually this means | 240 // Sets all the displays into pre-suspend mode; usually this means |
239 // configure them for their resume state. This allows faster resume on | 241 // configure them for their resume state. This allows faster resume on |
240 // machines where display configuration is slow. | 242 // machines where display configuration is slow. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 // Checks the available color profiles for |display_id| and fills the result | 274 // Checks the available color profiles for |display_id| and fills the result |
273 // into |profiles|. | 275 // into |profiles|. |
274 std::vector<ui::ColorCalibrationProfile> GetAvailableColorCalibrationProfiles( | 276 std::vector<ui::ColorCalibrationProfile> GetAvailableColorCalibrationProfiles( |
275 int64_t display_id); | 277 int64_t display_id); |
276 | 278 |
277 // Updates the color calibration to |new_profile|. | 279 // Updates the color calibration to |new_profile|. |
278 bool SetColorCalibrationProfile(int64_t display_id, | 280 bool SetColorCalibrationProfile(int64_t display_id, |
279 ui::ColorCalibrationProfile new_profile); | 281 ui::ColorCalibrationProfile new_profile); |
280 | 282 |
281 private: | 283 private: |
284 class DisplayLayoutManagerImpl; | |
285 | |
282 // Mapping a display_id to a protection request bitmask. | 286 // Mapping a display_id to a protection request bitmask. |
283 typedef std::map<int64_t, uint32_t> ContentProtections; | 287 typedef std::map<int64_t, uint32_t> ContentProtections; |
284 // Mapping a client to its protection request. | 288 // Mapping a client to its protection request. |
285 typedef std::map<ContentProtectionClientId, ContentProtections> | 289 typedef std::map<ContentProtectionClientId, ContentProtections> |
286 ProtectionRequests; | 290 ProtectionRequests; |
287 | 291 |
288 // Performs platform specific delegate initialization. | 292 // Performs platform specific delegate initialization. |
289 scoped_ptr<NativeDisplayDelegate> CreatePlatformNativeDisplayDelegate(); | 293 scoped_ptr<NativeDisplayDelegate> CreatePlatformNativeDisplayDelegate(); |
290 | 294 |
291 // Updates |cached_displays_| to contain currently-connected displays. Calls | |
292 // |delegate_->GetDisplays()| and then does additional work, like finding the | |
293 // mirror mode and setting user-preferred modes. Note that the server must be | |
294 // grabbed via |delegate_->GrabServer()| first. | |
295 void UpdateCachedDisplays(); | |
296 | |
297 // Helper method for UpdateCachedDisplays() that initializes the passed-in | |
298 // displays' |mirror_mode| fields by looking for a mode in |internal_display| | |
299 // and |external_display| having the same resolution. Returns false if a | |
300 // shared | |
301 // mode wasn't found or created. | |
302 // | |
303 // |try_panel_fitting| allows creating a panel-fitting mode for | |
304 // |internal_display| instead of only searching for a matching mode (note that | |
305 // it may lead to a crash if |internal_info| is not capable of panel fitting). | |
306 // | |
307 // |preserve_aspect| limits the search/creation only to the modes having the | |
308 // native aspect ratio of |external_display|. | |
309 bool FindMirrorMode(DisplayState* internal_display, | |
310 DisplayState* external_display, | |
311 bool try_panel_fitting, | |
312 bool preserve_aspect); | |
313 | |
314 // Configures displays. Invoked by |configure_timer_|. | 295 // Configures displays. Invoked by |configure_timer_|. |
315 void ConfigureDisplays(); | 296 void ConfigureDisplays(); |
316 | 297 |
317 // Restores |requested_power_state_| after the system has resumed, | 298 // Restores |requested_power_state_| after the system has resumed, |
318 // additionally forcing a probe. Invoked by |configure_timer_|. | 299 // additionally forcing a probe. Invoked by |configure_timer_|. |
319 void RestoreRequestedPowerStateAfterResume(); | 300 void RestoreRequestedPowerStateAfterResume(); |
320 | 301 |
321 // Notifies observers about an attempted state change. | 302 // Notifies observers about an attempted state change. |
322 void NotifyObservers(bool success, MultipleDisplayState attempted_state); | 303 void NotifyObservers(bool success, MultipleDisplayState attempted_state); |
323 | 304 |
324 // Switches to the state specified in |display_state| and |power_state|. | |
325 // If the hardware mirroring failed and |mirroring_controller_| is set, | |
326 // it switches to |STATE_DUAL_EXTENDED| and calls |SetSoftwareMirroring()| | |
327 // to enable software based mirroring. | |
328 // On success, updates |display_state_|, |power_state_|, and | |
329 // |cached_displays_| and returns true. | |
330 bool EnterStateOrFallBackToSoftwareMirroring( | |
331 MultipleDisplayState display_state, | |
332 chromeos::DisplayPowerState power_state); | |
333 | |
334 // Switches to the state specified in |display_state| and |power_state|. | |
335 // On success, updates |display_state_|, |power_state_|, and | |
336 // |cached_displays_| and returns true. | |
337 bool EnterState(MultipleDisplayState display_state, | |
338 chromeos::DisplayPowerState power_state); | |
339 | |
340 // Returns the display state that should be used with |cached_displays_| while | 305 // Returns the display state that should be used with |cached_displays_| while |
341 // in |power_state|. | 306 // in |power_state|. |
342 MultipleDisplayState ChooseDisplayState( | 307 MultipleDisplayState ChooseDisplayState( |
343 chromeos::DisplayPowerState power_state) const; | 308 chromeos::DisplayPowerState power_state) const; |
344 | 309 |
345 // Returns the ratio between mirrored mode area and native mode area: | 310 // Returns the ratio between mirrored mode area and native mode area: |
346 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) | 311 // (mirror_mode_width * mirrow_mode_height) / (native_width * native_height) |
347 float GetMirroredDisplayAreaRatio(const DisplayState& display); | 312 float GetMirroredDisplayAreaRatio(const DisplayState& display); |
348 | 313 |
349 // Returns true if in either hardware or software mirroring mode. | 314 // Returns true if in either hardware or software mirroring mode. |
350 bool IsMirroring() const; | 315 bool IsMirroring() const; |
351 | 316 |
352 // Applies display protections according to requests. | 317 // Applies display protections according to requests. |
353 bool ApplyProtections(const ContentProtections& requests); | 318 bool ApplyProtections(const ContentProtections& requests); |
354 | 319 |
320 void RunPendingConfiguration(); | |
Daniel Erat
2014/12/12 16:25:29
please add comments describing these new methods
dnicoara
2014/12/12 17:45:09
Done.
| |
321 | |
322 void OnConfigured(bool success, | |
323 const std::vector<DisplayState>& displays, | |
324 const gfx::Size& framebuffer_size, | |
325 MultipleDisplayState new_display_state, | |
326 chromeos::DisplayPowerState new_power_state); | |
327 | |
328 bool ShouldScheduleConfigurationTask() const; | |
329 | |
355 StateController* state_controller_; | 330 StateController* state_controller_; |
356 SoftwareMirroringController* mirroring_controller_; | 331 SoftwareMirroringController* mirroring_controller_; |
357 scoped_ptr<NativeDisplayDelegate> native_display_delegate_; | 332 scoped_ptr<NativeDisplayDelegate> native_display_delegate_; |
358 | 333 |
359 // Used to enable modes which rely on panel fitting. | 334 // Used to enable modes which rely on panel fitting. |
360 bool is_panel_fitting_enabled_; | 335 bool is_panel_fitting_enabled_; |
361 | 336 |
362 // This is detected by the constructor to determine whether or not we should | 337 // This is detected by the constructor to determine whether or not we should |
363 // be enabled. If we aren't running on ChromeOS, we can't assume that the | 338 // be enabled. If we aren't running on ChromeOS, we can't assume that the |
364 // Xrandr X11 extension is supported. | 339 // Xrandr X11 extension is supported. |
365 // If this flag is set to false, any attempts to change the display | 340 // If this flag is set to false, any attempts to change the display |
366 // configuration to immediately fail without changing the state. | 341 // configuration to immediately fail without changing the state. |
367 bool configure_display_; | 342 bool configure_display_; |
368 | 343 |
369 // The current display state. | 344 // Current configuration state. |
370 MultipleDisplayState display_state_; | 345 MultipleDisplayState current_display_state_; |
346 chromeos::DisplayPowerState current_power_state_; | |
371 | 347 |
372 gfx::Size framebuffer_size_; | 348 // Pending requests. These values are used when triggering the next display |
349 // configuration. | |
350 // | |
351 // Stores the user requested state or INVALID if nothing was requested. | |
352 MultipleDisplayState requested_display_state_; | |
373 | 353 |
374 // The last-requested and current power state. These may differ if | 354 // Stores the requested power state. |
375 // configuration fails: SetDisplayMode() needs the last-requested state while | |
376 // SetDisplayPower() needs the current state. | |
377 chromeos::DisplayPowerState requested_power_state_; | 355 chromeos::DisplayPowerState requested_power_state_; |
378 chromeos::DisplayPowerState current_power_state_; | 356 |
357 // True if |requested_power_state_| has been changed due to a user request. | |
358 bool requested_power_state_change_; | |
359 | |
360 int requested_power_flags_; | |
Daniel Erat
2014/12/12 16:25:29
add a comment describing where the flag values are
dnicoara
2014/12/12 17:45:09
Done.
| |
361 | |
362 // True if the caller wants to force the display configuration process. | |
363 bool force_configure_; | |
379 | 364 |
380 // Most-recently-used display configuration. Note that the actual | 365 // Most-recently-used display configuration. Note that the actual |
381 // configuration changes asynchronously. | 366 // configuration changes asynchronously. |
382 DisplayStateList cached_displays_; | 367 DisplayStateList cached_displays_; |
383 | 368 |
369 gfx::Size framebuffer_size_; | |
Daniel Erat
2014/12/12 16:25:29
is this the current framebuffer size?
dnicoara
2014/12/12 17:45:09
Yes, I've added a comment.
| |
370 | |
384 ObserverList<Observer> observers_; | 371 ObserverList<Observer> observers_; |
385 | 372 |
386 // The timer to delay configuring displays. This is used to aggregate multiple | 373 // The timer to delay configuring displays. This is used to aggregate multiple |
387 // display configuration events when they are reported in short time spans. | 374 // display configuration events when they are reported in short time spans. |
388 // See comment for NativeDisplayEventDispatcherX11 for more details. | 375 // See comment for NativeDisplayEventDispatcherX11 for more details. |
389 base::OneShotTimer<DisplayConfigurator> configure_timer_; | 376 base::OneShotTimer<DisplayConfigurator> configure_timer_; |
390 | 377 |
391 // Id for next display protection client. | 378 // Id for next display protection client. |
392 ContentProtectionClientId next_display_protection_client_id_; | 379 ContentProtectionClientId next_display_protection_client_id_; |
393 | 380 |
394 // Display protection requests of each client. | 381 // Display protection requests of each client. |
395 ProtectionRequests client_protection_requests_; | 382 ProtectionRequests client_protection_requests_; |
396 | 383 |
397 // Display controlled by an external entity. | 384 // Display controlled by an external entity. |
398 bool display_externally_controlled_; | 385 bool display_externally_controlled_; |
399 | 386 |
387 scoped_ptr<DisplayLayoutManager> layout_manager_; | |
388 | |
389 scoped_ptr<UpdateDisplayConfigurationTask> configuration_task_; | |
390 | |
391 // This must be the last variable. | |
392 base::WeakPtrFactory<DisplayConfigurator> weak_ptr_factory_; | |
393 | |
400 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurator); | 394 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurator); |
401 }; | 395 }; |
402 | 396 |
403 } // namespace ui | 397 } // namespace ui |
404 | 398 |
405 #endif // UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ | 399 #endif // UI_DISPLAY_CHROMEOS_DISPLAY_CONFIGURATOR_H_ |
OLD | NEW |