Index: services/native_viewport/ozone/display_manager.cc |
diff --git a/services/native_viewport/ozone/display_manager.cc b/services/native_viewport/ozone/display_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2f2601868742bbd84fd2339b9609d02cb3549186 |
--- /dev/null |
+++ b/services/native_viewport/ozone/display_manager.cc |
@@ -0,0 +1,76 @@ |
+// Copyright 2015 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 "base/bind.h" |
+#include "base/location.h" |
+#include "base/thread_task_runner_handle.h" |
+#include "services/native_viewport/ozone/display_manager.h" |
+#include "ui/display/types/display_snapshot.h" |
+#include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" |
+#include "ui/ozone/platform/drm/host/drm_window_host.h" |
+#include "ui/ozone/public/ozone_platform.h" |
+ |
+namespace native_viewport { |
+ |
+DisplayManager::DisplayManager() |
+ : delegate_(ui::OzonePlatform::GetInstance() |
+ ->CreateNativeDisplayDelegate()) { |
+ delegate_->AddObserver(this); |
+ delegate_->Initialize(); |
+ OnConfigurationChanged(); |
+} |
+ |
+DisplayManager::~DisplayManager() { |
+ if (delegate_) |
+ delegate_->RemoveObserver(this); |
jamesr
2015/08/25 00:30:28
does this ensure that |delegate_| won't try to cal
cdotstout
2015/08/27 19:10:21
It ensures that OnConfigurationChanged won't be ca
|
+} |
+ |
+void DisplayManager::OnConfigurationChanged() { |
+ if (is_configuring_) { |
+ should_configure_ = true; |
+ return; |
+ } |
+ |
+ is_configuring_ = true; |
+ delegate_->GrabServer(); |
+ delegate_->GetDisplays( |
+ base::Bind(&DisplayManager::OnDisplaysAquired, base::Unretained(this))); |
+} |
+ |
+void DisplayManager::OnDisplaysAquired( |
jamesr
2015/08/25 00:30:28
nit: i think it's spelled 'acquired'
cdotstout
2015/08/27 19:10:21
Done.
|
+ const std::vector<ui::DisplaySnapshot*>& displays) { |
+ gfx::Point origin; |
+ for (auto display : displays) { |
+ if (!display->native_mode()) { |
+ LOG(ERROR) << "Display " << display->display_id() |
+ << " doesn't have a native mode"; |
+ continue; |
+ } |
+ |
+ delegate_->Configure( |
+ *display, display->native_mode(), origin, |
+ base::Bind(&DisplayManager::OnDisplayConfigured, base::Unretained(this), |
+ gfx::Rect(origin, display->native_mode()->size()))); |
+ origin.Offset(display->native_mode()->size().width(), 0); |
+ } |
+ delegate_->UngrabServer(); |
+ is_configuring_ = false; |
+ |
+ if (should_configure_) { |
+ should_configure_ = false; |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(&DisplayManager::OnConfigurationChanged, |
+ base::Unretained(this))); |
+ } |
+} |
+ |
+void DisplayManager::OnDisplayConfigured(const gfx::Rect& bounds, |
+ bool success) { |
+ auto platform_support_host = static_cast<ui::DrmGpuPlatformSupportHost*>( |
+ ui::OzonePlatform::GetInstance()->GetGpuPlatformSupportHost()); |
+ platform_support_host->get_window_manager()->GetPrimaryWindow()->SetBounds( |
+ bounds); |
+} |
+ |
+} // namespace |
jamesr
2015/08/25 00:30:28
ditto
cdotstout
2015/08/27 19:10:21
Done.
|