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

Side by Side Diff: services/ui/display/platform_screen_impl_ozone.cc

Issue 2230963003: Fix window/display bounds with multiple windows in mus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes. Created 4 years, 4 months 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 | « services/ui/display/platform_screen_impl_ozone.h ('k') | services/ui/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "services/ui/display/platform_screen_impl_ozone.h" 5 #include "services/ui/display/platform_screen_impl_ozone.h"
6 6
7 #include <memory>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
9 #include "base/sys_info.h" 11 #include "base/sys_info.h"
10 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
11 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/display/types/display_constants.h" 14 #include "ui/display/types/display_constants.h"
13 #include "ui/display/types/display_snapshot.h" 15 #include "ui/display/types/display_snapshot.h"
14 #include "ui/display/types/native_display_delegate.h" 16 #include "ui/display/types/native_display_delegate.h"
15 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
16 #include "ui/ozone/public/ozone_platform.h" 18 #include "ui/ozone/public/ozone_platform.h"
17 19
18 namespace display { 20 namespace display {
19 namespace { 21 namespace {
20 22
21 // TODO(rjkroege): Remove this code once ozone headless has the same
22 // display creation semantics as ozone drm.
23 // Some ozone platforms do not configure physical displays and so do not
24 // callback into this class via the implementation of NativeDisplayObserver.
25 // FixedSizeScreenConfiguration() short-circuits the implementation of display
26 // configuration in this case by calling the |callback| provided to
27 // ConfigurePhysicalDisplay() with a hard-coded |id| and |bounds|.
28 void FixedSizeScreenConfiguration(
29 const PlatformScreen::ConfiguredDisplayCallback& callback) {
30 if (base::CommandLine::ForCurrentProcess()->HasSwitch("multi-display")) {
31 // This really doesn't work properly. Use at your own risk.
32 callback.Run(100, gfx::Rect(800, 800));
33 callback.Run(200, gfx::Rect(800, 0, 800, 800));
34 } else {
35 callback.Run(100, gfx::Rect(0, 0, 1024, 768));
36 }
37 }
38
39 // Needed for DisplayConfigurator::ForceInitialConfigure. 23 // Needed for DisplayConfigurator::ForceInitialConfigure.
40 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); 24 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe);
41 25
42 } // namespace 26 } // namespace
43 27
44 // static 28 // static
45 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { 29 std::unique_ptr<PlatformScreen> PlatformScreen::Create() {
46 return base::MakeUnique<PlatformScreenImplOzone>(); 30 return base::MakeUnique<PlatformScreenImplOzone>();
47 } 31 }
48 32
49 PlatformScreenImplOzone::PlatformScreenImplOzone() {} 33 PlatformScreenImplOzone::PlatformScreenImplOzone() {}
50 34
51 PlatformScreenImplOzone::~PlatformScreenImplOzone() { 35 PlatformScreenImplOzone::~PlatformScreenImplOzone() {
52 display_configurator_.RemoveObserver(this); 36 display_configurator_.RemoveObserver(this);
53 } 37 }
54 38
55 void PlatformScreenImplOzone::Init() { 39 void PlatformScreenImplOzone::Init() {
40 // We want display configuration to happen even off device to keep the control
41 // flow similar.
42 display_configurator_.set_configure_display(true);
56 display_configurator_.AddObserver(this); 43 display_configurator_.AddObserver(this);
57 display_configurator_.Init( 44 display_configurator_.Init(
58 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false); 45 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false);
59 } 46 }
60 47
61 void PlatformScreenImplOzone::ConfigurePhysicalDisplay( 48 void PlatformScreenImplOzone::ConfigurePhysicalDisplay(
62 const PlatformScreen::ConfiguredDisplayCallback& callback) { 49 const PlatformScreen::ConfiguredDisplayCallback& callback) {
50 callback_ = callback;
51
63 if (base::SysInfo::IsRunningOnChromeOS()) { 52 if (base::SysInfo::IsRunningOnChromeOS()) {
64 callback_ = callback;
65 display_configurator_.ForceInitialConfigure(kChromeOsBootColor); 53 display_configurator_.ForceInitialConfigure(kChromeOsBootColor);
66 } else { 54 } else {
67 // PostTask()ed to maximize control flow similarity with the ChromeOS case. 55 if (base::CommandLine::ForCurrentProcess()->HasSwitch("multi-display")) {
68 base::ThreadTaskRunnerHandle::Get()->PostTask( 56 // This really doesn't work properly. Use at your own risk.
69 FROM_HERE, base::Bind(&FixedSizeScreenConfiguration, callback)); 57 display_configurator_.AddVirtualDisplay(gfx::Size(800, 800));
58 display_configurator_.AddVirtualDisplay(gfx::Size(800, 800));
59 } else {
60 display_configurator_.AddVirtualDisplay(gfx::Size(1024, 768));
61 }
70 } 62 }
71 } 63 }
72 64
65 int64_t PlatformScreenImplOzone::GetPrimaryDisplayId() const {
66 return primary_display_id_;
67 }
68
73 void PlatformScreenImplOzone::OnDisplayModeChanged( 69 void PlatformScreenImplOzone::OnDisplayModeChanged(
74 const ui::DisplayConfigurator::DisplayStateList& displays) { 70 const ui::DisplayConfigurator::DisplayStateList& displays) {
75 // TODO(kylechar): Remove check when adding/removing displays is supported.
76 CHECK(!callback_.is_null());
77
78 if (displays.size() > 1) { 71 if (displays.size() > 1) {
79 LOG(ERROR) 72 LOG(ERROR)
80 << "Mus doesn't really support multiple displays, expect it to crash"; 73 << "Mus doesn't really support multiple displays, expect it to crash";
81 } 74 }
82 75
83 gfx::Point origin; 76 // TODO(kylechar): Use DisplayLayout/DisplayLayoutStore here when possible.
84 for (auto* display : displays) { 77 std::set<uint64_t> all_displays;
78 for (ui::DisplaySnapshot* display : displays) {
79 const int64_t id = display->display_id();
80
81 all_displays.insert(id);
82
83 if (displays_.find(id) != displays_.end())
84 continue;
85
85 const ui::DisplayMode* current_mode = display->current_mode(); 86 const ui::DisplayMode* current_mode = display->current_mode();
86 gfx::Rect bounds(origin, current_mode->size()); 87 gfx::Rect bounds(next_display_origin_, current_mode->size());
87
88 callback_.Run(display->display_id(), bounds);
89 88
90 // Move the origin so that next display is to the right of current display. 89 // Move the origin so that next display is to the right of current display.
91 origin.Offset(current_mode->size().width(), 0); 90 next_display_origin_.Offset(current_mode->size().width(), 0);
91
92 // The first display added will be our primary display.
93 if (displays_.empty())
94 primary_display_id_ = id;
95
96 // Keep track of what displays have already been added.
97 displays_.insert(display->display_id());
98
99 callback_.Run(id, bounds);
92 } 100 }
93 101
94 callback_.Reset(); 102 DCHECK(displays_ == all_displays) << "Removing displays is not supported.";
95 } 103 }
96 104
97 void PlatformScreenImplOzone::OnDisplayModeChangeFailed( 105 void PlatformScreenImplOzone::OnDisplayModeChangeFailed(
98 const ui::DisplayConfigurator::DisplayStateList& displays, 106 const ui::DisplayConfigurator::DisplayStateList& displays,
99 ui::MultipleDisplayState failed_new_state) { 107 ui::MultipleDisplayState failed_new_state) {
100 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; 108 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator";
101 callback_.Reset();
102 } 109 }
103 110
104 } // namespace display 111 } // namespace display
OLDNEW
« no previous file with comments | « services/ui/display/platform_screen_impl_ozone.h ('k') | services/ui/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698