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

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

Issue 2805633004: Add Mojo NativeDisplayDelegate / NativeDisplayObserver. (Closed)
Patch Set: s/InterfaceRegistry/BinderRegistry Created 3 years, 8 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/screen_manager_forwarding.h ('k') | services/ui/manifest.json » ('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 2017 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 "services/ui/display/screen_manager_forwarding.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "services/service_manager/public/cpp/binder_registry.h"
11 #include "ui/display/types/display_constants.h"
12 #include "ui/display/types/display_snapshot_mojo.h"
13 #include "ui/display/types/native_display_delegate.h"
14 #include "ui/ozone/public/ozone_platform.h"
15
16 namespace display {
17 namespace {
18
19 // Finds the display mode in |snapshot| that corresponds to |mode_to_find|.
20 const DisplayMode* GetCorrespondingMode(const DisplaySnapshot& snapshot,
21 const DisplayMode* mode_to_find) {
22 if (!mode_to_find)
23 return nullptr;
24
25 for (auto& mode : snapshot.modes()) {
26 if (mode->size() == mode_to_find->size() &&
27 mode->is_interlaced() == mode_to_find->is_interlaced() &&
28 mode->refresh_rate() == mode_to_find->refresh_rate()) {
29 return mode.get();
30 }
31 }
32 NOTREACHED();
33 return nullptr;
34 }
35
36 } // namespace
37
38 // TODO(sky/kylechar): Change ScreenManager::Create() to make a
39 // ScreenManagerForwarding in mus mode.
40
41 ScreenManagerForwarding::ScreenManagerForwarding() : binding_(this) {}
42
43 ScreenManagerForwarding::~ScreenManagerForwarding() {
44 if (native_display_delegate_)
45 native_display_delegate_->RemoveObserver(this);
46 }
47
48 void ScreenManagerForwarding::AddInterfaces(
49 service_manager::BinderRegistry* registry) {
50 registry->AddInterface<mojom::NativeDisplayDelegate>(this);
51 }
52
53 void ScreenManagerForwarding::Init(ScreenManagerDelegate* delegate) {
54 // Done in NativeDisplayDelegate::Initialize() instead.
55 }
56
57 void ScreenManagerForwarding::RequestCloseDisplay(int64_t display_id) {}
58
59 void ScreenManagerForwarding::OnConfigurationChanged() {
60 if (observer_.is_bound())
61 observer_->OnConfigurationChanged();
62 }
63
64 void ScreenManagerForwarding::OnDisplaySnapshotsInvalidated() {
65 snapshot_map_.clear();
66 }
67
68 void ScreenManagerForwarding::Initialize(
69 mojom::NativeDisplayObserverPtr observer) {
70 DCHECK(!native_display_delegate_);
71 observer_ = std::move(observer);
72
73 native_display_delegate_ =
74 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate();
75 native_display_delegate_->AddObserver(this);
76 native_display_delegate_->Initialize();
77 }
78
79 void ScreenManagerForwarding::TakeDisplayControl(
80 const TakeDisplayControlCallback& callback) {
81 DCHECK(native_display_delegate_);
82 native_display_delegate_->TakeDisplayControl(callback);
83 }
84
85 void ScreenManagerForwarding::RelinquishDisplayControl(
86 const RelinquishDisplayControlCallback& callback) {
87 DCHECK(native_display_delegate_);
88 native_display_delegate_->RelinquishDisplayControl(callback);
89 }
90
91 void ScreenManagerForwarding::GetDisplays(const GetDisplaysCallback& callback) {
92 DCHECK(native_display_delegate_);
93 native_display_delegate_->GetDisplays(
94 base::Bind(&ScreenManagerForwarding::ForwardGetDisplays,
95 base::Unretained(this), callback));
96 }
97
98 void ScreenManagerForwarding::Configure(
99 int64_t display_id,
100 std::unique_ptr<display::DisplayMode> mode,
101 const gfx::Point& origin,
102 const ConfigureCallback& callback) {
103 DCHECK(native_display_delegate_);
104 DisplaySnapshot* snapshot = snapshot_map_[display_id];
105 if (!snapshot) {
106 callback.Run(false);
107 return;
108 }
109
110 // We need a pointer to the mode in |snapshot|, not the equivalent mode we
111 // received over Mojo.
112 const DisplayMode* snapshot_mode =
113 GetCorrespondingMode(*snapshot, mode.get());
114 native_display_delegate_->Configure(
115 *snapshot, snapshot_mode, origin,
116 base::Bind(&ScreenManagerForwarding::ForwardConfigure,
117 base::Unretained(this), snapshot, snapshot_mode, origin,
118 callback));
119 }
120
121 void ScreenManagerForwarding::GetHDCPState(
122 int64_t display_id,
123 const GetHDCPStateCallback& callback) {
124 DCHECK(native_display_delegate_);
125 const DisplaySnapshot* snapshot = snapshot_map_[display_id];
126 if (!snapshot) {
127 callback.Run(false, HDCP_STATE_UNDESIRED);
128 return;
129 }
130
131 native_display_delegate_->GetHDCPState(*snapshot, callback);
132 }
133
134 void ScreenManagerForwarding::SetHDCPState(
135 int64_t display_id,
136 display::HDCPState state,
137 const SetHDCPStateCallback& callback) {
138 DCHECK(native_display_delegate_);
139 const DisplaySnapshot* snapshot = snapshot_map_[display_id];
140 if (!snapshot) {
141 callback.Run(false);
142 return;
143 }
144
145 native_display_delegate_->SetHDCPState(*snapshot, state, callback);
146 }
147
148 void ScreenManagerForwarding::SetColorCorrection(
149 int64_t display_id,
150 const std::vector<display::GammaRampRGBEntry>& degamma_lut,
151 const std::vector<display::GammaRampRGBEntry>& gamma_lut,
152 const std::vector<float>& correction_matrix) {
153 DCHECK(native_display_delegate_);
154 const DisplaySnapshot* snapshot = snapshot_map_[display_id];
155 if (!snapshot)
156 return;
157
158 native_display_delegate_->SetColorCorrection(*snapshot, degamma_lut,
159 gamma_lut, correction_matrix);
160 }
161
162 void ScreenManagerForwarding::Create(
163 const service_manager::Identity& remote_identity,
164 mojom::NativeDisplayDelegateRequest request) {
165 DCHECK(!binding_.is_bound());
166 binding_.Bind(std::move(request));
167 }
168
169 void ScreenManagerForwarding::ForwardGetDisplays(
170 const mojom::NativeDisplayDelegate::GetDisplaysCallback& callback,
171 const std::vector<DisplaySnapshot*>& snapshots) {
172 snapshot_map_.clear();
173
174 // Convert the DisplaySnapshots to MojoDisplaySnapshots to allow sending
175 // over Mojo. Also caches the snapshots for lookup later.
176 std::vector<std::unique_ptr<DisplaySnapshotMojo>> mojo_snapshots;
177 for (auto* snapshot : snapshots) {
178 snapshot_map_[snapshot->display_id()] = snapshot;
179 mojo_snapshots.push_back(DisplaySnapshotMojo::CreateFrom(*snapshot));
180 }
181
182 callback.Run(std::move(mojo_snapshots));
183 }
184
185 void ScreenManagerForwarding::ForwardConfigure(
186 DisplaySnapshot* snapshot,
187 const DisplayMode* mode,
188 const gfx::Point& origin,
189 const mojom::NativeDisplayDelegate::ConfigureCallback& callback,
190 bool status) {
191 if (status) {
192 // Modify display snapshot similar to how ConfigureDisplaysTask would. Ozone
193 // DRM needs these to be changed and ConfigureDisplaysTasks can't do it.
194 snapshot->set_current_mode(mode);
195 snapshot->set_origin(origin);
196 }
197 callback.Run(status);
198 }
199
200 } // namespace display
OLDNEW
« no previous file with comments | « services/ui/display/screen_manager_forwarding.h ('k') | services/ui/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698