Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_impl_ozone.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/location.h" | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "base/sys_info.h" | |
| 11 #include "base/thread_task_runner_handle.h" | |
| 12 #include "ui/display/types/display_snapshot.h" | |
| 13 #include "ui/display/types/native_display_delegate.h" | |
| 14 #include "ui/ozone/public/ozone_platform.h" | |
| 15 | |
| 16 namespace mus { | |
| 17 namespace ws { | |
| 18 | |
| 19 // static | |
| 20 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { | |
| 21 return base::WrapUnique(new PlatformScreenImplOzone); | |
| 22 } | |
| 23 | |
| 24 PlatformScreenImplOzone::PlatformScreenImplOzone() | |
| 25 : is_configuring_(false), | |
| 26 should_configure_(false), | |
| 27 weak_ptr_factory_(this) {} | |
| 28 | |
| 29 PlatformScreenImplOzone::~PlatformScreenImplOzone() {} | |
| 30 | |
| 31 void PlatformScreenImplOzone::Init() { | |
| 32 native_display_delegate_ = | |
| 33 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); | |
| 34 native_display_delegate_->AddObserver(this); | |
| 35 native_display_delegate_->Initialize(); | |
| 36 } | |
| 37 | |
| 38 void PlatformScreenImplOzone::ConfigurePhysicalDisplay( | |
| 39 const PlatformScreen::ConfiguredDisplayCallback& callback) { | |
| 40 callback_ = callback; | |
| 41 | |
| 42 if (base::SysInfo::IsRunningOnChromeOS()) { | |
| 43 // Kick off the configuration of the physical displays comprising the | |
| 44 // |PlatformScreenImplOzone| | |
| 45 OnConfigurationChanged(); | |
| 46 } else { | |
| 47 // PostTask()ed to maximize control flow similarity with the ChromeOS case. | |
| 48 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 49 FROM_HERE, | |
| 50 base::Bind(&PlatformScreenImplOzone::FixedSizeScreenConfiguration, | |
|
sky
2016/05/04 17:05:45
Again, you shouldn't need a member function and th
rjkroege
2016/05/04 22:50:13
Done.
| |
| 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 PlatformScreenImplOzone::OnConfigurationChanged() { | |
| 60 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | |
| 61 "OnConfigurationChanged requires a " | |
| 62 "native_display_delegate_ to work."; | |
| 63 if (callback_.is_null()) | |
|
sky
2016/05/04 17:05:45
AFAICT you never reset the callback, so it will ne
rjkroege
2016/05/04 22:50:13
No longer applicable.
| |
| 64 return; | |
| 65 if (is_configuring_) | |
|
sky
2016/05/04 17:05:45
How come you don't early out if is_configuring_ is
rjkroege
2016/05/04 22:50:13
Doh. Thanks for catching this. I had deleted that
| |
| 66 should_configure_ = true; | |
| 67 is_configuring_ = true; | |
| 68 native_display_delegate_->GrabServer(); | |
| 69 native_display_delegate_->GetDisplays( | |
| 70 base::Bind(&PlatformScreenImplOzone::OnDisplaysAquired, | |
| 71 weak_ptr_factory_.GetWeakPtr(), callback_)); | |
| 72 } | |
| 73 | |
| 74 // TODO(rjkroege): Remove this code once ozone oxygen has the same | |
| 75 // display creation semantics as ozone drm. | |
| 76 void PlatformScreenImplOzone::FixedSizeScreenConfiguration( | |
| 77 ConfiguredDisplayCallback callback) { | |
| 78 callback.Run(1, gfx::Rect(1024, 768)); | |
| 79 } | |
| 80 | |
| 81 // The display subsystem calls |OnDisplaysAquired| to deliver |displays| | |
| 82 // describing the attached displays. | |
| 83 void PlatformScreenImplOzone::OnDisplaysAquired( | |
| 84 const ConfiguredDisplayCallback& callback, | |
| 85 const std::vector<ui::DisplaySnapshot*>& displays) { | |
| 86 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | |
| 87 "OnConfigurationChanged requires a " | |
| 88 "native_display_delegate_ to work."; | |
| 89 CHECK(displays.size() == 1) << "Mus only supports one 1 display\n"; | |
| 90 gfx::Point origin; | |
| 91 for (auto display : displays) { | |
| 92 if (!display->native_mode()) { | |
| 93 LOG(ERROR) << "Display " << display->display_id() | |
| 94 << " doesn't have a native mode"; | |
| 95 continue; | |
| 96 } | |
| 97 // Setup each native display. This places a task on the DRM thread's | |
| 98 // runqueue that configures the window size correctly before the call to | |
| 99 // Configure. | |
| 100 native_display_delegate_->Configure( | |
| 101 *display, display->native_mode(), origin, | |
| 102 base::Bind(&PlatformScreenImplOzone::OnDisplayConfigured, | |
| 103 weak_ptr_factory_.GetWeakPtr(), callback, | |
| 104 display->display_id(), | |
| 105 gfx::Rect(origin, display->native_mode()->size()))); | |
| 106 origin.Offset(display->native_mode()->size().width(), 0); | |
| 107 } | |
| 108 native_display_delegate_->UngrabServer(); | |
| 109 is_configuring_ = false; | |
| 110 if (should_configure_) { | |
| 111 should_configure_ = false; | |
| 112 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 113 FROM_HERE, base::Bind(&PlatformScreenImplOzone::OnConfigurationChanged, | |
| 114 weak_ptr_factory_.GetWeakPtr())); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 // The display subsystem calls |OnDisplayConfigured| for each display that has | |
| 119 // been successfully configured. This in turn calls |callback_| with the | |
| 120 // identity and bounds of each physical display. | |
| 121 void PlatformScreenImplOzone::OnDisplayConfigured( | |
| 122 const ConfiguredDisplayCallback& callback, | |
|
sky
2016/05/04 17:05:45
Why do you pass callback here and have callback as
rjkroege
2016/05/04 22:50:13
Seemed like an easy way to ensure that I only call
| |
| 123 int64_t id, | |
| 124 const gfx::Rect& bounds, | |
| 125 bool success) { | |
| 126 if (success) | |
| 127 callback.Run(id, bounds); | |
| 128 else | |
| 129 LOG(FATAL) << "Failed to configure display at " << bounds.ToString(); | |
| 130 } | |
| 131 | |
| 132 } // namespace ws | |
| 133 } // namespace mus | |
| OLD | NEW |