| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "ui/display/manager/forwarding_display_delegate.h" | 5 #include "ui/display/manager/forwarding_display_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" |
| 10 #include "ui/display/types/display_snapshot_mojo.h" | 11 #include "ui/display/types/display_snapshot_mojo.h" |
| 11 | 12 |
| 12 namespace display { | 13 namespace display { |
| 13 | 14 |
| 14 ForwardingDisplayDelegate::ForwardingDisplayDelegate( | 15 ForwardingDisplayDelegate::ForwardingDisplayDelegate( |
| 15 mojom::NativeDisplayDelegatePtr delegate) | 16 mojom::NativeDisplayDelegatePtr delegate) |
| 16 : delegate_(std::move(delegate)), binding_(this) {} | 17 : delegate_(std::move(delegate)), binding_(this) {} |
| 17 | 18 |
| 18 ForwardingDisplayDelegate::~ForwardingDisplayDelegate() {} | 19 ForwardingDisplayDelegate::~ForwardingDisplayDelegate() {} |
| 19 | 20 |
| 20 void ForwardingDisplayDelegate::Initialize() { | 21 void ForwardingDisplayDelegate::Initialize() { |
| 21 delegate_->Initialize(binding_.CreateInterfacePtrAndBind()); | 22 // TODO(kylechar/sky): Figure out how to make this not synchronous. |
| 23 mojo::SyncCallRestrictions::ScopedAllowSyncCall scoped_sync; |
| 24 |
| 25 // This is a synchronous call to Initialize() because ash depends on |
| 26 // NativeDisplayDelegate being synchronous during it's initialization. Calls |
| 27 // to GetDisplays() and Configure() will return early starting now using |
| 28 // whatever is in |snapshots_|. |
| 29 delegate_->Initialize(binding_.CreateInterfacePtrAndBind(), &snapshots_); |
| 22 } | 30 } |
| 23 | 31 |
| 24 void ForwardingDisplayDelegate::GrabServer() {} | 32 void ForwardingDisplayDelegate::GrabServer() {} |
| 25 | 33 |
| 26 void ForwardingDisplayDelegate::UngrabServer() {} | 34 void ForwardingDisplayDelegate::UngrabServer() {} |
| 27 | 35 |
| 28 void ForwardingDisplayDelegate::TakeDisplayControl( | 36 void ForwardingDisplayDelegate::TakeDisplayControl( |
| 29 const DisplayControlCallback& callback) { | 37 const DisplayControlCallback& callback) { |
| 30 delegate_->TakeDisplayControl(callback); | 38 delegate_->TakeDisplayControl(callback); |
| 31 } | 39 } |
| 32 | 40 |
| 33 void ForwardingDisplayDelegate::RelinquishDisplayControl( | 41 void ForwardingDisplayDelegate::RelinquishDisplayControl( |
| 34 const DisplayControlCallback& callback) { | 42 const DisplayControlCallback& callback) { |
| 35 delegate_->TakeDisplayControl(callback); | 43 delegate_->TakeDisplayControl(callback); |
| 36 } | 44 } |
| 37 | 45 |
| 38 void ForwardingDisplayDelegate::SyncWithServer() {} | 46 void ForwardingDisplayDelegate::SyncWithServer() {} |
| 39 | 47 |
| 40 void ForwardingDisplayDelegate::SetBackgroundColor(uint32_t color_argb) {} | 48 void ForwardingDisplayDelegate::SetBackgroundColor(uint32_t color_argb) {} |
| 41 | 49 |
| 42 void ForwardingDisplayDelegate::ForceDPMSOn() {} | 50 void ForwardingDisplayDelegate::ForceDPMSOn() {} |
| 43 | 51 |
| 44 void ForwardingDisplayDelegate::GetDisplays( | 52 void ForwardingDisplayDelegate::GetDisplays( |
| 45 const GetDisplaysCallback& callback) { | 53 const GetDisplaysCallback& callback) { |
| 54 if (!use_delegate_) { |
| 55 ForwardDisplays(callback); |
| 56 return; |
| 57 } |
| 58 |
| 46 delegate_->GetDisplays( | 59 delegate_->GetDisplays( |
| 47 base::Bind(&ForwardingDisplayDelegate::StoreAndForwardDisplays, | 60 base::Bind(&ForwardingDisplayDelegate::StoreAndForwardDisplays, |
| 48 base::Unretained(this), callback)); | 61 base::Unretained(this), callback)); |
| 49 } | 62 } |
| 50 | 63 |
| 51 void ForwardingDisplayDelegate::AddMode(const DisplaySnapshot& snapshot, | 64 void ForwardingDisplayDelegate::AddMode(const DisplaySnapshot& snapshot, |
| 52 const DisplayMode* mode) {} | 65 const DisplayMode* mode) {} |
| 53 | 66 |
| 54 void ForwardingDisplayDelegate::Configure(const DisplaySnapshot& snapshot, | 67 void ForwardingDisplayDelegate::Configure(const DisplaySnapshot& snapshot, |
| 55 const DisplayMode* mode, | 68 const DisplayMode* mode, |
| 56 const gfx::Point& origin, | 69 const gfx::Point& origin, |
| 57 const ConfigureCallback& callback) { | 70 const ConfigureCallback& callback) { |
| 71 if (!use_delegate_) { |
| 72 // Pretend configuration succeeded. When the first OnConfigurationChanged() |
| 73 // is received this will run again and actually happen. |
| 74 callback.Run(true); |
| 75 return; |
| 76 } |
| 77 |
| 58 delegate_->Configure(snapshot.display_id(), mode->Clone(), origin, callback); | 78 delegate_->Configure(snapshot.display_id(), mode->Clone(), origin, callback); |
| 59 } | 79 } |
| 60 | 80 |
| 61 void ForwardingDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {} | 81 void ForwardingDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {} |
| 62 | 82 |
| 63 void ForwardingDisplayDelegate::GetHDCPState( | 83 void ForwardingDisplayDelegate::GetHDCPState( |
| 64 const DisplaySnapshot& snapshot, | 84 const DisplaySnapshot& snapshot, |
| 65 const GetHDCPStateCallback& callback) { | 85 const GetHDCPStateCallback& callback) { |
| 66 delegate_->GetHDCPState(snapshot.display_id(), callback); | 86 delegate_->GetHDCPState(snapshot.display_id(), callback); |
| 67 } | 87 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void ForwardingDisplayDelegate::RemoveObserver( | 124 void ForwardingDisplayDelegate::RemoveObserver( |
| 105 display::NativeDisplayObserver* observer) { | 125 display::NativeDisplayObserver* observer) { |
| 106 observers_.RemoveObserver(observer); | 126 observers_.RemoveObserver(observer); |
| 107 } | 127 } |
| 108 | 128 |
| 109 FakeDisplayController* ForwardingDisplayDelegate::GetFakeDisplayController() { | 129 FakeDisplayController* ForwardingDisplayDelegate::GetFakeDisplayController() { |
| 110 return nullptr; | 130 return nullptr; |
| 111 } | 131 } |
| 112 | 132 |
| 113 void ForwardingDisplayDelegate::OnConfigurationChanged() { | 133 void ForwardingDisplayDelegate::OnConfigurationChanged() { |
| 134 // Start asynchronous operation once the first OnConfigurationChanged() |
| 135 // arrives. We know |delegate_| is usable at this point. |
| 136 use_delegate_ = true; |
| 137 |
| 114 // Forward OnConfigurationChanged received over Mojo to local observers. | 138 // Forward OnConfigurationChanged received over Mojo to local observers. |
| 115 for (auto& observer : observers_) | 139 for (auto& observer : observers_) |
| 116 observer.OnConfigurationChanged(); | 140 observer.OnConfigurationChanged(); |
| 117 } | 141 } |
| 118 | 142 |
| 119 void ForwardingDisplayDelegate::StoreAndForwardDisplays( | 143 void ForwardingDisplayDelegate::StoreAndForwardDisplays( |
| 120 const GetDisplaysCallback& callback, | 144 const GetDisplaysCallback& callback, |
| 121 std::vector<std::unique_ptr<DisplaySnapshotMojo>> snapshots) { | 145 std::vector<std::unique_ptr<DisplaySnapshotMojo>> snapshots) { |
| 122 for (auto& observer : observers_) | 146 for (auto& observer : observers_) |
| 123 observer.OnDisplaySnapshotsInvalidated(); | 147 observer.OnDisplaySnapshotsInvalidated(); |
| 124 snapshots_ = std::move(snapshots); | 148 snapshots_ = std::move(snapshots); |
| 125 | 149 |
| 150 ForwardDisplays(callback); |
| 151 } |
| 152 |
| 153 void ForwardingDisplayDelegate::ForwardDisplays( |
| 154 const GetDisplaysCallback& callback) { |
| 126 std::vector<DisplaySnapshot*> snapshot_ptrs; | 155 std::vector<DisplaySnapshot*> snapshot_ptrs; |
| 127 for (auto& snapshot : snapshots_) | 156 for (auto& snapshot : snapshots_) |
| 128 snapshot_ptrs.push_back(snapshot.get()); | 157 snapshot_ptrs.push_back(snapshot.get()); |
| 129 callback.Run(snapshot_ptrs); | 158 callback.Run(snapshot_ptrs); |
| 130 } | 159 } |
| 131 | 160 |
| 132 } // namespace display | 161 } // namespace display |
| OLD | NEW |