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

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

Issue 2121053002: Have PlatformScreen use DisplayConfigurator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/ws/platform_screen_impl_ozone.h ('k') | no next file » | 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/ws/platform_screen_impl_ozone.h" 5 #include "services/ui/ws/platform_screen_impl_ozone.h"
6 6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
10 #include "base/sys_info.h" 8 #include "base/sys_info.h"
11 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/display/types/display_constants.h"
12 #include "ui/display/types/display_snapshot.h" 12 #include "ui/display/types/display_snapshot.h"
13 #include "ui/display/types/native_display_delegate.h" 13 #include "ui/display/types/native_display_delegate.h"
14 #include "ui/gfx/geometry/rect.h"
14 #include "ui/ozone/public/ozone_platform.h" 15 #include "ui/ozone/public/ozone_platform.h"
15 16
16 namespace ui { 17 namespace ui {
17 18
18 namespace ws { 19 namespace ws {
19 namespace { 20 namespace {
20 21
21 // TODO(rjkroege): Remove this code once ozone oxygen has the same 22 // TODO(rjkroege): Remove this code once ozone headless has the same
22 // display creation semantics as ozone drm. 23 // display creation semantics as ozone drm.
23 // Some ozone platforms do not configure physical displays and so do not 24 // Some ozone platforms do not configure physical displays and so do not
24 // callback into this class via the implementation of NativeDisplayObserver. 25 // callback into this class via the implementation of NativeDisplayObserver.
25 // FixedSizeScreenConfiguration() short-circuits the implementation of display 26 // FixedSizeScreenConfiguration() short-circuits the implementation of display
26 // configuration in this case by calling the |callback| provided to 27 // configuration in this case by calling the |callback| provided to
27 // ConfigurePhysicalDisplay() with a hard-coded |id| and |bounds|. 28 // ConfigurePhysicalDisplay() with a hard-coded |id| and |bounds|.
28 void FixedSizeScreenConfiguration( 29 void FixedSizeScreenConfiguration(
29 const PlatformScreen::ConfiguredDisplayCallback& callback) { 30 const PlatformScreen::ConfiguredDisplayCallback& callback) {
30 callback.Run(1, gfx::Rect(1024, 768)); 31 callback.Run(1, gfx::Rect(1024, 768));
31 } 32 }
32 33
33 void GetDisplaysFinished(const std::vector<ui::DisplaySnapshot*>& displays) { 34 // Needed for DisplayConfigurator::ForceInitialConfigure.
34 // We don't really care about list of displays, we just want the snapshots 35 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe);
35 // held by DrmDisplayManager to be updated. This only only happens when we
36 // call NativeDisplayDelegate::GetDisplays(). Although, this would be a good
37 // place to have PlatformScreen cache the snapshots if need be.
38 }
39 36
40 } // namespace 37 } // namespace
41 38
42 // static 39 // static
43 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { 40 std::unique_ptr<PlatformScreen> PlatformScreen::Create() {
44 return base::WrapUnique(new PlatformScreenImplOzone); 41 return base::MakeUnique<PlatformScreenImplOzone>();
45 } 42 }
46 43
47 PlatformScreenImplOzone::PlatformScreenImplOzone() : weak_ptr_factory_(this) {} 44 PlatformScreenImplOzone::PlatformScreenImplOzone() {}
48 45
49 PlatformScreenImplOzone::~PlatformScreenImplOzone() {} 46 PlatformScreenImplOzone::~PlatformScreenImplOzone() {
47 display_configurator_.RemoveObserver(this);
48 }
50 49
51 void PlatformScreenImplOzone::Init() { 50 void PlatformScreenImplOzone::Init() {
52 native_display_delegate_ = 51 display_configurator_.AddObserver(this);
53 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); 52 display_configurator_.Init(
54 native_display_delegate_->AddObserver(this); 53 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false);
55 native_display_delegate_->Initialize();
56 } 54 }
57 55
58 void PlatformScreenImplOzone::ConfigurePhysicalDisplay( 56 void PlatformScreenImplOzone::ConfigurePhysicalDisplay(
59 const PlatformScreen::ConfiguredDisplayCallback& callback) { 57 const PlatformScreen::ConfiguredDisplayCallback& callback) {
60 #if defined(OS_CHROMEOS)
61 if (base::SysInfo::IsRunningOnChromeOS()) { 58 if (base::SysInfo::IsRunningOnChromeOS()) {
62 // Kick off the configuration of the physical displays comprising the 59 callback_ = callback;
63 // |PlatformScreenImplOzone| 60 display_configurator_.ForceInitialConfigure(kChromeOsBootColor);
64 61 } else {
65 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" 62 // PostTask()ed to maximize control flow similarity with the ChromeOS case.
66 "OnConfigurationChanged requires a " 63 base::ThreadTaskRunnerHandle::Get()->PostTask(
67 "native_display_delegate_ to work."; 64 FROM_HERE, base::Bind(&FixedSizeScreenConfiguration, callback));
68
69 native_display_delegate_->GetDisplays(
70 base::Bind(&PlatformScreenImplOzone::OnDisplaysAquired,
71 weak_ptr_factory_.GetWeakPtr(), callback));
72
73 return;
74 }
75 #endif // defined(OS_CHROMEOS)
76 // PostTask()ed to maximize control flow similarity with the ChromeOS case.
77 base::ThreadTaskRunnerHandle::Get()->PostTask(
78 FROM_HERE, base::Bind(&FixedSizeScreenConfiguration, callback));
79 }
80
81 void PlatformScreenImplOzone::OnConfigurationChanged() {}
82
83 // The display subsystem calls |OnDisplaysAquired| to deliver |displays|
84 // describing the attached displays.
85 void PlatformScreenImplOzone::OnDisplaysAquired(
86 const ConfiguredDisplayCallback& callback,
87 const std::vector<ui::DisplaySnapshot*>& displays) {
88 DCHECK(native_display_delegate_) << "DefaultDisplayManager::"
89 "OnConfigurationChanged requires a "
90 "native_display_delegate_ to work.";
91 CHECK(displays.size() == 1) << "Mus only supports one 1 display\n";
92 gfx::Point origin;
93 for (auto display : displays) {
94 if (!display->native_mode()) {
95 LOG(ERROR) << "Display " << display->display_id()
96 << " doesn't have a native mode";
97 continue;
98 }
99 // Setup each native display. This places a task on the DRM thread's
100 // runqueue that configures the window size correctly before the call to
101 // Configure.
102 native_display_delegate_->Configure(
103 *display, display->native_mode(), origin,
104 base::Bind(&PlatformScreenImplOzone::OnDisplayConfigured,
105 weak_ptr_factory_.GetWeakPtr(), callback,
106 display->display_id(),
107 gfx::Rect(origin, display->native_mode()->size())));
108 origin.Offset(display->native_mode()->size().width(), 0);
109 } 65 }
110 } 66 }
111 67
112 void PlatformScreenImplOzone::OnDisplayConfigured( 68 void PlatformScreenImplOzone::OnDisplayModeChanged(
113 const ConfiguredDisplayCallback& callback, 69 const ui::DisplayConfigurator::DisplayStateList& displays) {
114 int64_t id, 70 // TODO(kylechar): Remove checks when multiple display support is added.
115 const gfx::Rect& bounds, 71 CHECK(displays.size() == 1) << "Mus only supports one 1 display";
116 bool success) { 72 CHECK(!callback_.is_null());
117 if (success) { 73
118 native_display_delegate_->GetDisplays(base::Bind(&GetDisplaysFinished)); 74 gfx::Point origin(0, 0);
msw 2016/07/06 18:18:36 nit: use default dtor
kylechar 2016/07/06 18:43:21 Done.
119 callback.Run(id, bounds); 75 for (auto display : displays) {
120 } else { 76 const ui::DisplayMode* current_mode = display->current_mode();
121 LOG(FATAL) << "Failed to configure display at " << bounds.ToString(); 77 gfx::Rect bounds(origin, current_mode->size());
78
79 callback_.Run(display->display_id(), bounds);
80
81 // Move origin so that next display is to right of current display.
msw 2016/07/06 18:18:36 nit: 'the origin', 'to the right' or 'is right', a
kylechar 2016/07/06 18:43:21 Done.
82 origin.Offset(current_mode->size().width(), 0);
122 } 83 }
84
85 callback_.Reset();
86 }
87
88 void PlatformScreenImplOzone::OnDisplayModeChangeFailed(
89 const ui::DisplayConfigurator::DisplayStateList& displays,
90 MultipleDisplayState failed_new_state) {
91 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator";
92 callback_.Reset();
123 } 93 }
124 94
125 } // namespace ws 95 } // namespace ws
126 } // namespace ui 96 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/platform_screen_impl_ozone.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698