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.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 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()) { | |
|
sky
2016/05/03 02:39:51
nit: no {}
rjkroege
2016/05/03 21:03:04
Done.
| |
| 64 return; | |
| 65 } | |
| 66 if (is_configuring_) { | |
|
sky
2016/05/03 02:39:51
nit: no {}
rjkroege
2016/05/03 21:03:04
Done.
| |
| 67 should_configure_ = true; | |
| 68 } | |
| 69 is_configuring_ = true; | |
| 70 native_display_delegate_->GrabServer(); | |
| 71 native_display_delegate_->GetDisplays( | |
| 72 base::Bind(&PlatformScreen::OnDisplaysAquired, | |
| 73 weak_ptr_factory_.GetWeakPtr(), callback_)); | |
|
sky
2016/05/03 02:39:51
Why do you need both a member for the callback and
rjkroege
2016/05/03 21:03:04
OnConfigurationChanged() implements NativeDisplay
| |
| 74 } | |
| 75 | |
| 76 // The display subsystem calls |OnDisplaysAquired| to deliver |displays| | |
| 77 // describing the attached displays. | |
| 78 void PlatformScreen::OnDisplaysAquired( | |
| 79 ConfiguredDisplayCallback callback, | |
| 80 const std::vector<ui::DisplaySnapshot*>& displays) { | |
| 81 DCHECK(native_display_delegate_) << "DefaultDisplayManager::" | |
| 82 "OnConfigurationChanged requires a " | |
| 83 "native_display_delegate_ to work."; | |
| 84 CHECK(displays.size() == 1) << "Mus only supports one 1 display\n"; | |
| 85 gfx::Point origin; | |
| 86 for (auto display : displays) { | |
| 87 if (!display->native_mode()) { | |
| 88 LOG(ERROR) << "Display " << display->display_id() | |
| 89 << " doesn't have a native mode"; | |
| 90 continue; | |
| 91 } | |
| 92 // Setup each native display. This places a task on the DRM thread's | |
| 93 // runqueue that configures the window size correctly before the call to | |
| 94 // Configure. | |
| 95 native_display_delegate_->Configure( | |
| 96 *display, display->native_mode(), origin, | |
| 97 base::Bind(&PlatformScreen::OnDisplayConfigured, | |
| 98 weak_ptr_factory_.GetWeakPtr(), callback, | |
| 99 display->display_id(), | |
| 100 gfx::Rect(origin, display->native_mode()->size()))); | |
| 101 origin.Offset(display->native_mode()->size().width(), 0); | |
| 102 } | |
| 103 native_display_delegate_->UngrabServer(); | |
| 104 is_configuring_ = false; | |
| 105 if (should_configure_) { | |
| 106 should_configure_ = false; | |
| 107 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 108 FROM_HERE, base::Bind(&PlatformScreen::OnConfigurationChanged, | |
| 109 weak_ptr_factory_.GetWeakPtr())); | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 // The display subsystem calls |OnDisplayConfigured| for each display that has | |
| 114 // been successfully configured. This in turn calls |callback_| with the | |
| 115 // identity | |
| 116 // and bounds of each physical display. | |
| 117 void PlatformScreen::OnDisplayConfigured(ConfiguredDisplayCallback callback, | |
| 118 int64_t id, | |
| 119 const gfx::Rect& bounds, | |
| 120 bool success) { | |
| 121 if (success) | |
| 122 callback.Run(id, bounds); | |
| 123 else | |
| 124 LOG(FATAL) << "Failed to configure display at " << bounds.ToString(); | |
| 125 } | |
| 126 | |
| 127 } // namespace ws | |
| 128 } // namespace mus | |
| OLD | NEW |