Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: components/mus/ws/platform_screen_impl_ozone.cc

Issue 1899923002: Basic display management for mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: refactored differently Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/mus/ws/platform_screen_impl_ozone.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/ws/platform_screen_impl_ozone.cc
diff --git a/components/mus/ws/platform_screen_impl_ozone.cc b/components/mus/ws/platform_screen_impl_ozone.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea0357b0e5d3460c15efde487223236a53aebde4
--- /dev/null
+++ b/components/mus/ws/platform_screen_impl_ozone.cc
@@ -0,0 +1,118 @@
+// 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_impl_ozone.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/memory/ptr_util.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 {
+namespace {
+
+// TODO(rjkroege): Remove this code once ozone oxygen has the same
+// display creation semantics as ozone drm.
+// Some ozone platforms do not configure physical displays and so do not
+// callback into this class via the implementation of NativeDisplayObserver.
+// FixedSizeScreenConfiguration() short-circuits the implementation of display
+// configuration in this case by calling the |callback| provided to
+// ConfigurePhysicalDisplay() with a hard-coded |id| and |bounds|.
+void FixedSizeScreenConfiguration(
+ const PlatformScreen::ConfiguredDisplayCallback& callback) {
+ callback.Run(1, gfx::Rect(1024, 768));
+}
+
+// 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 OnDisplayConfigured(
+ const PlatformScreen::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
+
+// static
+std::unique_ptr<PlatformScreen> PlatformScreen::Create() {
+ return base::WrapUnique(new PlatformScreenImplOzone);
+}
+
+PlatformScreenImplOzone::PlatformScreenImplOzone() : weak_ptr_factory_(this) {}
+
+PlatformScreenImplOzone::~PlatformScreenImplOzone() {}
+
+void PlatformScreenImplOzone::Init() {
+ native_display_delegate_ =
+ ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate();
+ native_display_delegate_->AddObserver(this);
+ native_display_delegate_->Initialize();
+}
+
+void PlatformScreenImplOzone::ConfigurePhysicalDisplay(
+ const PlatformScreen::ConfiguredDisplayCallback& callback) {
+ if (base::SysInfo::IsRunningOnChromeOS()) {
+ // Kick off the configuration of the physical displays comprising the
+ // |PlatformScreenImplOzone|
+
+ DCHECK(native_display_delegate_) << "DefaultDisplayManager::"
+ "OnConfigurationChanged requires a "
+ "native_display_delegate_ to work.";
+
+ native_display_delegate_->GrabServer();
+ native_display_delegate_->GetDisplays(
+ base::Bind(&PlatformScreenImplOzone::OnDisplaysAquired,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+
+ } else {
+ // PostTask()ed to maximize control flow similarity with the ChromeOS case.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&FixedSizeScreenConfiguration, callback));
+ }
+}
+
+void PlatformScreenImplOzone::OnConfigurationChanged() {}
+
+// The display subsystem calls |OnDisplaysAquired| to deliver |displays|
+// describing the attached displays.
+void PlatformScreenImplOzone::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(&OnDisplayConfigured, callback, display->display_id(),
+ gfx::Rect(origin, display->native_mode()->size())));
+ origin.Offset(display->native_mode()->size().width(), 0);
+ }
+ native_display_delegate_->UngrabServer();
sky 2016/05/04 23:48:07 If this is destroyed between ConfigurePhysicalDisp
rjkroege 2016/05/05 00:55:43 Probably not. I should have removed the cals to Gr
+}
+
+} // namespace ws
+} // namespace mus
« no previous file with comments | « components/mus/ws/platform_screen_impl_ozone.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698