Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/interface_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() | |
| 42 : binding_(this), weak_ptr_factory_(this) {} | |
| 43 | |
| 44 ScreenManagerForwarding::~ScreenManagerForwarding() { | |
| 45 if (native_display_delegate_) | |
| 46 native_display_delegate_->RemoveObserver(this); | |
| 47 } | |
| 48 | |
| 49 void ScreenManagerForwarding::AddInterfaces( | |
| 50 service_manager::InterfaceRegistry* registry) { | |
| 51 registry->AddInterface<mojom::NativeDisplayDelegate>(this); | |
| 52 } | |
| 53 | |
| 54 void ScreenManagerForwarding::Init(ScreenManagerDelegate* delegate) { | |
| 55 // Done in NativeDisplayDelegate::Initialize() instead. | |
| 56 } | |
| 57 | |
| 58 void ScreenManagerForwarding::RequestCloseDisplay(int64_t display_id) {} | |
| 59 | |
| 60 void ScreenManagerForwarding::OnConfigurationChanged() { | |
| 61 if (observer_.is_bound()) | |
| 62 observer_->OnConfigurationChanged(); | |
| 63 } | |
| 64 | |
| 65 void ScreenManagerForwarding::OnDisplaySnapshotsInvalidated() { | |
| 66 snapshot_map_.clear(); | |
| 67 } | |
| 68 | |
| 69 void ScreenManagerForwarding::RegisterObserver( | |
| 70 mojom::NativeDisplayObserverPtr observer) { | |
| 71 observer_ = std::move(observer); | |
| 72 } | |
| 73 | |
| 74 void ScreenManagerForwarding::Initialize() { | |
| 75 DCHECK(!native_display_delegate_); | |
| 76 native_display_delegate_ = | |
| 77 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); | |
| 78 native_display_delegate_->AddObserver(this); | |
| 79 native_display_delegate_->Initialize(); | |
| 80 } | |
| 81 | |
| 82 void ScreenManagerForwarding::TakeDisplayControl( | |
| 83 const TakeDisplayControlCallback& callback) { | |
| 84 DCHECK(native_display_delegate_); | |
| 85 native_display_delegate_->TakeDisplayControl(callback); | |
| 86 } | |
| 87 | |
| 88 void ScreenManagerForwarding::RelinquishDisplayControl( | |
| 89 const RelinquishDisplayControlCallback& callback) { | |
| 90 DCHECK(native_display_delegate_); | |
| 91 native_display_delegate_->RelinquishDisplayControl(callback); | |
| 92 } | |
| 93 | |
| 94 void ScreenManagerForwarding::GetDisplays(const GetDisplaysCallback& callback) { | |
| 95 DCHECK(native_display_delegate_); | |
| 96 native_display_delegate_->GetDisplays( | |
| 97 base::Bind(&ScreenManagerForwarding::ForwardGetDisplays, | |
| 98 weak_ptr_factory_.GetWeakPtr(), callback)); | |
|
sky
2017/04/06 20:30:20
Similar comment here about not needing a weak_ptr_
kylechar
2017/04/07 13:52:16
Done.
| |
| 99 } | |
| 100 | |
| 101 void ScreenManagerForwarding::Configure( | |
| 102 int64_t display_id, | |
| 103 std::unique_ptr<display::DisplayMode> mode, | |
| 104 const gfx::Point& origin, | |
| 105 const ConfigureCallback& callback) { | |
| 106 DCHECK(native_display_delegate_); | |
| 107 DisplaySnapshot* snapshot = snapshot_map_[display_id]; | |
| 108 if (!snapshot) { | |
| 109 callback.Run(false); | |
| 110 return; | |
| 111 } | |
| 112 | |
| 113 // We need a pointer to the mode in |snapshot|, not the equivalent mode we | |
| 114 // received over Mojo. | |
| 115 const DisplayMode* snapshot_mode = | |
| 116 GetCorrespondingMode(*snapshot, mode.get()); | |
| 117 native_display_delegate_->Configure( | |
| 118 *snapshot, snapshot_mode, origin, | |
| 119 base::Bind(&ScreenManagerForwarding::ForwardConfigure, | |
| 120 weak_ptr_factory_.GetWeakPtr(), snapshot, snapshot_mode, | |
| 121 origin, callback)); | |
| 122 } | |
| 123 | |
| 124 void ScreenManagerForwarding::GetHDCPState( | |
| 125 int64_t display_id, | |
| 126 const GetHDCPStateCallback& callback) { | |
| 127 DCHECK(native_display_delegate_); | |
| 128 const DisplaySnapshot* snapshot = snapshot_map_[display_id]; | |
| 129 if (!snapshot) { | |
| 130 callback.Run(false, HDCP_STATE_UNDESIRED); | |
| 131 return; | |
| 132 } | |
| 133 | |
| 134 native_display_delegate_->GetHDCPState(*snapshot, callback); | |
| 135 } | |
| 136 | |
| 137 void ScreenManagerForwarding::SetHDCPState( | |
| 138 int64_t display_id, | |
| 139 display::HDCPState state, | |
| 140 const SetHDCPStateCallback& callback) { | |
| 141 DCHECK(native_display_delegate_); | |
| 142 const DisplaySnapshot* snapshot = snapshot_map_[display_id]; | |
| 143 if (!snapshot) { | |
| 144 callback.Run(false); | |
| 145 return; | |
| 146 } | |
| 147 | |
| 148 native_display_delegate_->SetHDCPState(*snapshot, state, callback); | |
| 149 } | |
| 150 | |
| 151 void ScreenManagerForwarding::SetColorCorrection( | |
| 152 int64_t display_id, | |
| 153 const std::vector<display::GammaRampRGBEntry>& degamma_lut, | |
| 154 const std::vector<display::GammaRampRGBEntry>& gamma_lut, | |
| 155 const std::vector<float>& correction_matrix) { | |
| 156 DCHECK(native_display_delegate_); | |
| 157 const DisplaySnapshot* snapshot = snapshot_map_[display_id]; | |
| 158 if (!snapshot) | |
| 159 return; | |
| 160 | |
| 161 native_display_delegate_->SetColorCorrection(*snapshot, degamma_lut, | |
| 162 gamma_lut, correction_matrix); | |
| 163 } | |
| 164 | |
| 165 void ScreenManagerForwarding::Create( | |
| 166 const service_manager::Identity& remote_identity, | |
| 167 mojom::NativeDisplayDelegateRequest request) { | |
| 168 DCHECK(!binding_.is_bound()); | |
| 169 binding_.Bind(std::move(request)); | |
| 170 } | |
| 171 | |
| 172 void ScreenManagerForwarding::ForwardGetDisplays( | |
| 173 const mojom::NativeDisplayDelegate::GetDisplaysCallback& callback, | |
| 174 const std::vector<DisplaySnapshot*>& snapshots) { | |
| 175 snapshot_map_.clear(); | |
| 176 | |
| 177 // Convert the DisplaySnapshots to MojoDisplaySnapshots to allow sending | |
| 178 // over Mojo. Also caches the snapshots for lookup later. | |
| 179 std::vector<std::unique_ptr<DisplaySnapshotMojo>> mojo_snapshots; | |
| 180 for (auto* snapshot : snapshots) { | |
| 181 snapshot_map_[snapshot->display_id()] = snapshot; | |
| 182 mojo_snapshots.push_back(DisplaySnapshotMojo::CreateFrom(*snapshot)); | |
| 183 } | |
| 184 | |
| 185 callback.Run(std::move(mojo_snapshots)); | |
| 186 } | |
| 187 | |
| 188 void ScreenManagerForwarding::ForwardConfigure( | |
| 189 DisplaySnapshot* snapshot, | |
| 190 const DisplayMode* mode, | |
| 191 const gfx::Point& origin, | |
| 192 const mojom::NativeDisplayDelegate::ConfigureCallback& callback, | |
| 193 bool status) { | |
| 194 if (status) { | |
| 195 // Modify display snapshot similar to how ConfigureDisplaysTask would. Ozone | |
| 196 // DRM needs these to be changed and ConfigureDisplaysTasks can't do it. | |
| 197 snapshot->set_current_mode(mode); | |
| 198 snapshot->set_origin(origin); | |
| 199 } | |
| 200 callback.Run(status); | |
| 201 } | |
| 202 | |
| 203 } // namespace display | |
| OLD | NEW |