| 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..07ea3eb340118f44aa792343ecaebd418683b054
|
| --- /dev/null
|
| +++ b/components/mus/ws/platform_screen_ozone.cc
|
| @@ -0,0 +1,127 @@
|
| +// 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(
|
| + const 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())
|
| + return;
|
| + if (is_configuring_)
|
| + should_configure_ = true;
|
| + is_configuring_ = true;
|
| + native_display_delegate_->GrabServer();
|
| + native_display_delegate_->GetDisplays(
|
| + base::Bind(&PlatformScreen::OnDisplaysAquired,
|
| + weak_ptr_factory_.GetWeakPtr(), callback_));
|
| +}
|
| +
|
| +// The display subsystem calls |OnDisplaysAquired| to deliver |displays|
|
| +// describing the attached displays.
|
| +void PlatformScreen::OnDisplaysAquired(
|
| + const 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(
|
| + const 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
|
|
|