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

Side by Side Diff: components/mus/ws/platform_screen_ozone.cc

Issue 1899923002: Basic display management for mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed debugging code Created 4 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/mus/ws/platform_screen.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/sys_info.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "ui/display/types/display_snapshot.h"
12 #include "ui/display/types/native_display_delegate.h"
13 #include "ui/ozone/public/ozone_platform.h"
14
15 namespace mus {
16 namespace ws {
17
18 PlatformScreen::PlatformScreen()
19 : is_configuring_(false),
20 should_configure_(false),
21 weak_ptr_factory_(this) {}
22
23 PlatformScreen::~PlatformScreen() {}
24
25 void PlatformScreen::Init() {
26 native_display_delegate_ =
27 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate();
28 native_display_delegate_->AddObserver(this);
29 native_display_delegate_->Initialize();
30 }
31
32 // TODO(rjkroege): Remove this code once ozone oxygen has the same
33 // display creation semantics as ozone drm.
34 void PlatformScreen::FixedSizeScreenConfiguration(
35 ConfiguredDisplayCallback callback) {
36 callback.Run(1, gfx::Rect(1024, 768));
37 }
38
39 void PlatformScreen::ConfigurePhysicalDisplay(
40 const ConfiguredDisplayCallback& callback) {
41 callback_ = callback;
42
43 if (base::SysInfo::IsRunningOnChromeOS()) {
44 // Kick off the configuration of the physical displays comprising the
45 // |PlatformScreen|
46 OnConfigurationChanged();
47 } else {
48 // PostTask()ed to maximize control flow similarity with the ChromeOS case.
49 base::ThreadTaskRunnerHandle::Get()->PostTask(
50 FROM_HERE, base::Bind(&PlatformScreen::FixedSizeScreenConfiguration,
51 weak_ptr_factory_.GetWeakPtr(), callback));
52 }
53 }
54
55 // TODO(rjkroege): Support multiple displays.
56 // The display subsystem tells us that the display configuration has changed on
57 // the first and subsequent change in display parameters. We have to kick this
58 // off manually the first time.
59 void PlatformScreen::OnConfigurationChanged() {
60 DCHECK(native_display_delegate_) << "DefaultDisplayManager::"
61 "OnConfigurationChanged requires a "
62 "native_display_delegate_ to work.";
63 if (callback_.is_null())
64 return;
65 if (is_configuring_)
66 should_configure_ = true;
67 is_configuring_ = true;
68 native_display_delegate_->GrabServer();
69 native_display_delegate_->GetDisplays(
70 base::Bind(&PlatformScreen::OnDisplaysAquired,
71 weak_ptr_factory_.GetWeakPtr(), callback_));
72 }
73
74 // The display subsystem calls |OnDisplaysAquired| to deliver |displays|
75 // describing the attached displays.
76 void PlatformScreen::OnDisplaysAquired(
77 const ConfiguredDisplayCallback& callback,
78 const std::vector<ui::DisplaySnapshot*>& displays) {
79 DCHECK(native_display_delegate_) << "DefaultDisplayManager::"
80 "OnConfigurationChanged requires a "
81 "native_display_delegate_ to work.";
82 CHECK(displays.size() == 1) << "Mus only supports one 1 display\n";
83 gfx::Point origin;
84 for (auto display : displays) {
85 if (!display->native_mode()) {
86 LOG(ERROR) << "Display " << display->display_id()
87 << " doesn't have a native mode";
88 continue;
89 }
90 // Setup each native display. This places a task on the DRM thread's
91 // runqueue that configures the window size correctly before the call to
92 // Configure.
93 native_display_delegate_->Configure(
94 *display, display->native_mode(), origin,
95 base::Bind(&PlatformScreen::OnDisplayConfigured,
96 weak_ptr_factory_.GetWeakPtr(), callback,
97 display->display_id(),
98 gfx::Rect(origin, display->native_mode()->size())));
99 origin.Offset(display->native_mode()->size().width(), 0);
100 }
101 native_display_delegate_->UngrabServer();
102 is_configuring_ = false;
103 if (should_configure_) {
104 should_configure_ = false;
105 base::ThreadTaskRunnerHandle::Get()->PostTask(
106 FROM_HERE, base::Bind(&PlatformScreen::OnConfigurationChanged,
107 weak_ptr_factory_.GetWeakPtr()));
108 }
109 }
110
111 // The display subsystem calls |OnDisplayConfigured| for each display that has
112 // been successfully configured. This in turn calls |callback_| with the
113 // identity
114 // and bounds of each physical display.
115 void PlatformScreen::OnDisplayConfigured(
116 const ConfiguredDisplayCallback& callback,
117 int64_t id,
118 const gfx::Rect& bounds,
119 bool success) {
120 if (success)
121 callback.Run(id, bounds);
122 else
123 LOG(FATAL) << "Failed to configure display at " << bounds.ToString();
124 }
125
126 } // namespace ws
127 } // namespace mus
OLDNEW
« components/mus/ws/platform_screen.h ('K') | « components/mus/ws/platform_screen.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698