Chromium Code Reviews| Index: components/mus/ws/platform_screen_ozone.cc |
| diff --git a/components/mus/ws/platform_screen_ozone.cc b/components/mus/ws/platform_screen_ozone.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e57a6b7436fc27d421fd4ca0c15ae4ff14906c86 |
| --- /dev/null |
| +++ b/components/mus/ws/platform_screen_ozone.cc |
| @@ -0,0 +1,128 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/mus/ws/platform_screen.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/location.h" |
| +#include "base/sys_info.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#include "ui/display/types/display_snapshot.h" |
| +#include "ui/display/types/native_display_delegate.h" |
| +#include "ui/ozone/public/ozone_platform.h" |
| + |
| +namespace mus { |
| +namespace ws { |
| + |
| +PlatformScreen::PlatformScreen() |
| + : is_configuring_(false), |
| + should_configure_(false), |
| + weak_ptr_factory_(this) {} |
| + |
| +PlatformScreen::~PlatformScreen() {} |
| + |
| +void PlatformScreen::Init() { |
| + native_display_delegate_ = |
| + ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); |
| + native_display_delegate_->AddObserver(this); |
| + native_display_delegate_->Initialize(); |
| +} |
| + |
| +// TODO(rjkroege): Remove this code once ozone oxygen has the same |
| +// display creation semantics as ozone drm. |
| +void PlatformScreen::FixedSizeScreenConfiguration( |
| + ConfiguredDisplayCallback callback) { |
| + callback.Run(1, gfx::Rect(1024, 768)); |
| +} |
| + |
| +void PlatformScreen::ConfigurePhysicalDisplay( |
| + ConfiguredDisplayCallback callback) { |
| + callback_ = callback; |
| + |
| + if (base::SysInfo::IsRunningOnChromeOS()) { |
| + // Kick off the configuration of the physical displays comprising the |
| + // |PlatformScreen| |
| + OnConfigurationChanged(); |
| + } else { |
| + // PostTask()ed to maximize control flow similarity with the ChromeOS case. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&PlatformScreen::FixedSizeScreenConfiguration, |
| + weak_ptr_factory_.GetWeakPtr(), callback)); |
| + } |
| +} |
| + |
| +// TODO(rjkroege): Support multiple displays. |
| +// The display subsystem tells us that the display configuration has changed on |
| +// the first and subsequent change in display parameters. We have to kick this |
| +// off manually the first time. |
| +void PlatformScreen::OnConfigurationChanged() { |
| + DCHECK(native_display_delegate_) << "DefaultDisplayManager::" |
| + "OnConfigurationChanged requires a " |
| + "native_display_delegate_ to work."; |
| + if (callback_.is_null()) { |
|
sky
2016/05/03 02:39:51
nit: no {}
rjkroege
2016/05/03 21:03:04
Done.
|
| + return; |
| + } |
| + if (is_configuring_) { |
|
sky
2016/05/03 02:39:51
nit: no {}
rjkroege
2016/05/03 21:03:04
Done.
|
| + should_configure_ = true; |
| + } |
| + is_configuring_ = true; |
| + native_display_delegate_->GrabServer(); |
| + native_display_delegate_->GetDisplays( |
| + base::Bind(&PlatformScreen::OnDisplaysAquired, |
| + 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
|
| +} |
| + |
| +// The display subsystem calls |OnDisplaysAquired| to deliver |displays| |
| +// describing the attached displays. |
| +void PlatformScreen::OnDisplaysAquired( |
| + ConfiguredDisplayCallback callback, |
| + const std::vector<ui::DisplaySnapshot*>& displays) { |
| + DCHECK(native_display_delegate_) << "DefaultDisplayManager::" |
| + "OnConfigurationChanged requires a " |
| + "native_display_delegate_ to work."; |
| + CHECK(displays.size() == 1) << "Mus only supports one 1 display\n"; |
| + gfx::Point origin; |
| + for (auto display : displays) { |
| + if (!display->native_mode()) { |
| + LOG(ERROR) << "Display " << display->display_id() |
| + << " doesn't have a native mode"; |
| + continue; |
| + } |
| + // Setup each native display. This places a task on the DRM thread's |
| + // runqueue that configures the window size correctly before the call to |
| + // Configure. |
| + native_display_delegate_->Configure( |
| + *display, display->native_mode(), origin, |
| + base::Bind(&PlatformScreen::OnDisplayConfigured, |
| + weak_ptr_factory_.GetWeakPtr(), callback, |
| + display->display_id(), |
| + gfx::Rect(origin, display->native_mode()->size()))); |
| + origin.Offset(display->native_mode()->size().width(), 0); |
| + } |
| + native_display_delegate_->UngrabServer(); |
| + is_configuring_ = false; |
| + if (should_configure_) { |
| + should_configure_ = false; |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&PlatformScreen::OnConfigurationChanged, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
| +} |
| + |
| +// The display subsystem calls |OnDisplayConfigured| for each display that has |
| +// been successfully configured. This in turn calls |callback_| with the |
| +// identity |
| +// and bounds of each physical display. |
| +void PlatformScreen::OnDisplayConfigured(ConfiguredDisplayCallback callback, |
| + int64_t id, |
| + const gfx::Rect& bounds, |
| + bool success) { |
| + if (success) |
| + callback.Run(id, bounds); |
| + else |
| + LOG(FATAL) << "Failed to configure display at " << bounds.ToString(); |
| +} |
| + |
| +} // namespace ws |
| +} // namespace mus |